Changeset 131516 in webkit for trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp
- Timestamp:
- Oct 16, 2012, 3:28:32 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp
r130726 r131516 440 440 } 441 441 442 #if ENABLE(JIT)443 static bool isGlobalResolve(OpcodeID opcodeID)444 {445 return opcodeID == op_resolve_global || opcodeID == op_resolve_global_dynamic;446 }447 448 static unsigned instructionOffsetForNth(ExecState* exec, const RefCountedArray<Instruction>& instructions, int nth, bool (*predicate)(OpcodeID))449 {450 size_t i = 0;451 while (i < instructions.size()) {452 OpcodeID currentOpcode = exec->interpreter()->getOpcodeID(instructions[i].u.opcode);453 if (predicate(currentOpcode)) {454 if (!--nth)455 return i;456 }457 i += opcodeLengths[currentOpcode];458 }459 460 ASSERT_NOT_REACHED();461 return 0;462 }463 464 static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset)465 {466 dataLog(" [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).utf8().data());467 }468 #endif469 470 442 void CodeBlock::printStructure(const char* name, const Instruction* vPC, int operand) 471 443 { … … 505 477 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) { 506 478 printStructure("put_by_id_replace", vPC, 4); 507 return;508 }509 if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global)) {510 printStructure("resolve_global", vPC, 4);511 return;512 }513 if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) {514 printStructure("resolve_global_dynamic", vPC, 4);515 479 return; 516 480 } … … 578 542 579 543 #if ENABLE(JIT) 580 if (!m_ globalResolveInfos.isEmpty() || !m_structureStubInfos.isEmpty())544 if (!m_structureStubInfos.isEmpty()) 581 545 dataLog("\nStructures:\n"); 582 583 if (!m_globalResolveInfos.isEmpty()) {584 size_t i = 0;585 do {586 printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, instructions(), i + 1, isGlobalResolve));587 ++i;588 } while (i < m_globalResolveInfos.size());589 }590 546 #endif 591 547 … … 903 859 break; 904 860 } 905 case op_resolve: { 906 int r0 = (++it)->u.operand; 861 case op_put_to_base_variable: 862 case op_put_to_base: { 863 int base = (++it)->u.operand; 907 864 int id0 = (++it)->u.operand; 908 dataLog("[%4d] resolve\t\t %s, %s", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); 865 int value = (++it)->u.operand; 866 int resolveInfo = (++it)->u.operand; 867 dataLog("[%4d] put_to_base\t %s, %s, %s, %d", location, registerName(exec, base).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, value).data(), resolveInfo); 868 dumpBytecodeCommentAndNewLine(location); 869 break; 870 } 871 case op_resolve: 872 case op_resolve_global_property: 873 case op_resolve_global_var: 874 case op_resolve_scoped_var: 875 case op_resolve_scoped_var_on_top_scope: 876 case op_resolve_scoped_var_with_top_scope_check: { 877 int r0 = (++it)->u.operand; 878 int id0 = (++it)->u.operand; 879 int resolveInfo = (++it)->u.operand; 880 dataLog("[%4d] resolve\t\t %s, %s, %d", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo); 909 881 dumpBytecodeCommentAndNewLine(location); 910 882 it++; 911 883 break; 912 884 } 913 case op_resolve_skip: { 914 int r0 = (++it)->u.operand; 915 int id0 = (++it)->u.operand; 916 int skipLevels = (++it)->u.operand; 917 dataLog("[%4d] resolve_skip\t %s, %s, %d", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), skipLevels); 918 dumpBytecodeCommentAndNewLine(location); 919 it++; 920 break; 921 } 922 case op_resolve_global: { 923 int r0 = (++it)->u.operand; 924 int id0 = (++it)->u.operand; 925 dataLog("[%4d] resolve_global\t %s, %s", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); 926 dumpBytecodeCommentAndNewLine(location); 927 it += 3; 928 break; 929 } 930 case op_resolve_global_dynamic: { 931 int r0 = (++it)->u.operand; 932 int id0 = (++it)->u.operand; 933 JSValue scope = JSValue((++it)->u.jsCell.get()); 934 ++it; 935 int depth = (++it)->u.operand; 936 dataLog("[%4d] resolve_global_dynamic\t %s, %s, %s, %d", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).utf8().data(), idName(id0, m_identifiers[id0]).data(), depth); 937 dumpBytecodeCommentAndNewLine(location); 938 ++it; 939 break; 940 } 941 case op_get_scoped_var: { 942 int r0 = (++it)->u.operand; 943 int index = (++it)->u.operand; 944 int skipLevels = (++it)->u.operand; 945 dataLog("[%4d] get_scoped_var\t %s, %d, %d", location, registerName(exec, r0).data(), index, skipLevels); 946 dumpBytecodeCommentAndNewLine(location); 947 it++; 948 break; 949 } 950 case op_put_scoped_var: { 951 int index = (++it)->u.operand; 952 int skipLevels = (++it)->u.operand; 953 int r0 = (++it)->u.operand; 954 dataLog("[%4d] put_scoped_var\t %d, %d, %s", location, index, skipLevels, registerName(exec, r0).data()); 955 dumpBytecodeCommentAndNewLine(location); 956 break; 957 } 958 case op_get_global_var: { 959 int r0 = (++it)->u.operand; 885 case op_init_global_const: { 960 886 WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer; 961 dataLog("[%4d] get_global_var\t %s, g%d(%p)", location, registerName(exec, r0).data(), m_globalObject->findRegisterIndex(registerPointer), registerPointer); 962 dumpBytecodeCommentAndNewLine(location); 963 it++; 964 break; 965 } 966 case op_get_global_var_watchable: { 967 int r0 = (++it)->u.operand; 887 int r0 = (++it)->u.operand; 888 dataLog("[%4d] init_global_const\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data()); 889 dumpBytecodeCommentAndNewLine(location); 890 break; 891 } 892 case op_init_global_const_check: { 968 893 WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer; 969 dataLog("[%4d] get_global_var_watchable\t %s, g%d(%p)", location, registerName(exec, r0).data(), m_globalObject->findRegisterIndex(registerPointer), registerPointer); 894 int r0 = (++it)->u.operand; 895 dataLog("[%4d] init_global_const_check\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data()); 970 896 dumpBytecodeCommentAndNewLine(location); 971 897 it++; … … 973 899 break; 974 900 } 975 case op_put_global_var: { 976 WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer; 977 int r0 = (++it)->u.operand; 978 dataLog("[%4d] put_global_var\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data()); 979 dumpBytecodeCommentAndNewLine(location); 980 break; 981 } 982 case op_put_global_var_check: { 983 WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer; 984 int r0 = (++it)->u.operand; 985 dataLog("[%4d] put_global_var_check\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data()); 986 dumpBytecodeCommentAndNewLine(location); 987 it++; 988 it++; 989 break; 990 } 991 case op_init_global_const: { 992 WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer; 993 int r0 = (++it)->u.operand; 994 dataLog("[%4d] init_global_const\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data()); 995 dumpBytecodeCommentAndNewLine(location); 996 break; 997 } 998 case op_init_global_const_check: { 999 WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer; 1000 int r0 = (++it)->u.operand; 1001 dataLog("[%4d] init_global_const_check\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data()); 1002 dumpBytecodeCommentAndNewLine(location); 1003 it++; 1004 it++; 1005 break; 1006 } 901 case op_resolve_base_to_global: 902 case op_resolve_base_to_global_dynamic: 903 case op_resolve_base_to_scope: 904 case op_resolve_base_to_scope_with_top_scope_check: 1007 905 case op_resolve_base: { 1008 906 int r0 = (++it)->u.operand; 1009 907 int id0 = (++it)->u.operand; 1010 908 int isStrict = (++it)->u.operand; 1011 dataLog("[%4d] resolve_base%s\t %s, %s", location, isStrict ? "_strict" : "", registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); 909 int resolveInfo = (++it)->u.operand; 910 int putToBaseInfo = (++it)->u.operand; 911 dataLog("[%4d] resolve_base%s\t %s, %s, %d, %d", location, isStrict ? "_strict" : "", registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo, putToBaseInfo); 1012 912 dumpBytecodeCommentAndNewLine(location); 1013 913 it++; … … 1025 925 int r1 = (++it)->u.operand; 1026 926 int id0 = (++it)->u.operand; 1027 dataLog("[%4d] resolve_with_base %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data()); 927 int resolveInfo = (++it)->u.operand; 928 int putToBaseInfo = (++it)->u.operand; 929 dataLog("[%4d] resolve_with_base %s, %s, %s, %d, %d", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo, putToBaseInfo); 1028 930 dumpBytecodeCommentAndNewLine(location); 1029 931 it++; … … 1034 936 int r1 = (++it)->u.operand; 1035 937 int id0 = (++it)->u.operand; 1036 dataLog("[%4d] resolve_with_this %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data()); 938 int resolveInfo = (++it)->u.operand; 939 dataLog("[%4d] resolve_with_this %s, %s, %s, %d", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo); 1037 940 dumpBytecodeCommentAndNewLine(location); 1038 941 it++; … … 1698 1601 , m_argumentsRegister(other.m_argumentsRegister) 1699 1602 , m_activationRegister(other.m_activationRegister) 1603 , m_globalObjectConstant(other.m_globalObjectConstant) 1700 1604 , m_needsFullScopeChain(other.m_needsFullScopeChain) 1701 1605 , m_usesEval(other.m_usesEval) … … 1705 1609 , m_source(other.m_source) 1706 1610 , m_sourceOffset(other.m_sourceOffset) 1707 #if ENABLE(JIT)1708 , m_globalResolveInfos(other.m_globalResolveInfos.size())1709 #endif1710 1611 #if ENABLE(VALUE_PROFILER) 1711 1612 , m_executionEntryCount(0) … … 1722 1623 , m_reoptimizationRetryCounter(0) 1723 1624 , m_lineInfo(other.m_lineInfo) 1625 , m_resolveOperations(other.m_resolveOperations) 1626 , m_putToBaseOperations(other.m_putToBaseOperations) 1724 1627 #if ENABLE(BYTECODE_COMMENTS) 1725 1628 , m_bytecodeCommentIterator(0) … … 1732 1635 optimizeAfterWarmUp(); 1733 1636 jitAfterWarmUp(); 1734 1735 #if ENABLE(JIT)1736 for (unsigned i = m_globalResolveInfos.size(); i--;)1737 m_globalResolveInfos[i] = GlobalResolveInfo(other.m_globalResolveInfos[i].bytecodeOffset);1738 #endif1739 1637 1740 1638 if (other.m_rareData) { … … 1781 1679 { 1782 1680 ASSERT(m_source); 1783 1681 1784 1682 optimizeAfterWarmUp(); 1785 1683 jitAfterWarmUp(); … … 1788 1686 liveCodeBlockSet.add(this); 1789 1687 #endif 1688 // We have a stub putToBase operation to allow resolve_base to 1689 // remain branchless 1690 m_putToBaseOperations.append(PutToBaseOperation(isStrictMode())); 1790 1691 } 1791 1692 … … 1884 1785 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) { 1885 1786 visitor.append(&vPC[4].u.structure); 1886 return;1887 }1888 if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global) || vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) {1889 if (vPC[3].u.structure)1890 visitor.append(&vPC[3].u.structure);1891 1787 return; 1892 1788 } … … 2042 1938 static const bool verboseUnlinking = false; 2043 1939 #endif 2044 1940 2045 1941 void CodeBlock::finalizeUnconditionally() 2046 1942 { … … 2087 1983 } 2088 1984 } 2089 for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i) { 2090 Instruction* curInstruction = &instructions()[m_globalResolveInstructions[i]]; 2091 ASSERT(interpreter->getOpcodeID(curInstruction[0].u.opcode) == op_resolve_global 2092 || interpreter->getOpcodeID(curInstruction[0].u.opcode) == op_resolve_global_dynamic); 2093 if (!curInstruction[3].u.structure || Heap::isMarked(curInstruction[3].u.structure.get())) 2094 continue; 2095 if (verboseUnlinking) 2096 dataLog("Clearing LLInt global resolve cache with structure %p.\n", curInstruction[3].u.structure.get()); 2097 curInstruction[3].u.structure.clear(); 2098 curInstruction[4].u.operand = 0; 2099 } 1985 2100 1986 for (unsigned i = 0; i < m_llintCallLinkInfos.size(); ++i) { 2101 1987 if (m_llintCallLinkInfos[i].isLinked() && !Heap::isMarked(m_llintCallLinkInfos[i].callee.get())) { … … 2124 2010 } 2125 2011 #endif // ENABLE(DFG_JIT) 2126 2012 2013 for (size_t size = m_putToBaseOperations.size(), i = 0; i < size; ++i) { 2014 if (m_putToBaseOperations[i].m_structure && !Heap::isMarked(m_putToBaseOperations[i].m_structure.get())) { 2015 if (verboseUnlinking) 2016 dataLog("Clearing putToBase info in %p.\n", this); 2017 m_putToBaseOperations[i].m_structure.clear(); 2018 } 2019 } 2020 for (size_t size = m_resolveOperations.size(), i = 0; i < size; ++i) { 2021 if (m_resolveOperations[i].isEmpty()) 2022 continue; 2023 #ifndef NDEBUG 2024 for (size_t insnSize = m_resolveOperations[i].size() - 1, k = 0; k < insnSize; ++k) 2025 ASSERT(!m_resolveOperations[i][k].m_structure); 2026 #endif 2027 m_resolveOperations[i].last().m_structure.clear(); 2028 if (m_resolveOperations[i].last().m_structure && !Heap::isMarked(m_resolveOperations[i].last().m_structure.get())) { 2029 if (verboseUnlinking) 2030 dataLog("Clearing resolve info in %p.\n", this); 2031 m_resolveOperations[i].last().m_structure.clear(); 2032 } 2033 } 2034 2127 2035 #if ENABLE(JIT) 2128 2036 // Handle inline caches. … … 2139 2047 callLinkInfo(i).lastSeenCallee.clear(); 2140 2048 } 2141 for (size_t size = m_globalResolveInfos.size(), i = 0; i < size; ++i) {2142 if (m_globalResolveInfos[i].structure && !Heap::isMarked(m_globalResolveInfos[i].structure.get())) {2143 if (verboseUnlinking)2144 dataLog("Clearing resolve info in %p.\n", this);2145 m_globalResolveInfos[i].structure.clear();2146 }2147 }2148 2149 2049 for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i) { 2150 2050 StructureStubInfo& stubInfo = m_structureStubInfos[i]; … … 2416 2316 } 2417 2317 2418 #if ENABLE(JIT)2419 bool CodeBlock::hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset)2420 {2421 if (m_globalResolveInfos.isEmpty())2422 return false;2423 2424 int low = 0;2425 int high = m_globalResolveInfos.size();2426 while (low < high) {2427 int mid = low + (high - low) / 2;2428 if (m_globalResolveInfos[mid].bytecodeOffset <= bytecodeOffset)2429 low = mid + 1;2430 else2431 high = mid;2432 }2433 2434 if (!low || m_globalResolveInfos[low - 1].bytecodeOffset != bytecodeOffset)2435 return false;2436 return true;2437 }2438 GlobalResolveInfo& CodeBlock::globalResolveInfoForBytecodeOffset(unsigned bytecodeOffset)2439 {2440 return *(binarySearch<GlobalResolveInfo, unsigned, getGlobalResolveInfoBytecodeOffset>(m_globalResolveInfos.begin(), m_globalResolveInfos.size(), bytecodeOffset));2441 }2442 #endif2443 2444 2318 void CodeBlock::shrinkToFit(ShrinkMode shrinkMode) 2445 2319 { 2446 2320 m_propertyAccessInstructions.shrinkToFit(); 2447 m_globalResolveInstructions.shrinkToFit();2448 2321 #if ENABLE(LLINT) 2449 2322 m_llintCallLinkInfos.shrinkToFit(); … … 2451 2324 #if ENABLE(JIT) 2452 2325 m_structureStubInfos.shrinkToFit(); 2453 if (shrinkMode == EarlyShrink)2454 m_globalResolveInfos.shrinkToFit();2455 2326 m_callLinkInfos.shrinkToFit(); 2456 2327 m_methodCallLinkInfos.shrinkToFit(); … … 2471 2342 } // else don't shrink these, because we would have already pointed pointers into these tables. 2472 2343 2344 m_resolveOperations.shrinkToFit(); 2473 2345 m_lineInfo.shrinkToFit(); 2474 2346 if (m_rareData) {
Note:
See TracChangeset
for help on using the changeset viewer.