X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/b80e619319b1def83d1e8b4f84042b661be1be7f..14957cd040308e3eeec43d26bae5d76da13fcd85:/bytecode/CodeBlock.cpp?ds=sidebyside diff --git a/bytecode/CodeBlock.cpp b/bytecode/CodeBlock.cpp index 8cefb1b..fc99e90 100644 --- a/bytecode/CodeBlock.cpp +++ b/bytecode/CodeBlock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved. * Copyright (C) 2008 Cameron Zwarich * * Redistribution and use in source and binary forms, with or without @@ -30,13 +30,16 @@ #include "config.h" #include "CodeBlock.h" -#include "JIT.h" -#include "JSValue.h" +#include "BytecodeGenerator.h" +#include "Debugger.h" #include "Interpreter.h" +#include "JIT.h" +#include "JSActivation.h" #include "JSFunction.h" #include "JSStaticScopeObject.h" -#include "Debugger.h" -#include "BytecodeGenerator.h" +#include "JSValue.h" +#include "RepatchBuffer.h" +#include "UStringConcatenate.h" #include #include @@ -49,9 +52,9 @@ namespace JSC { static UString escapeQuotes(const UString& str) { UString result = str; - unsigned pos = 0; - while ((pos = result.find('\"', pos)) != UString::NotFound) { - result = makeString(result.substr(0, pos), "\"\\\"\"", result.substr(pos + 1)); + size_t pos = 0; + while ((pos = result.find('\"', pos)) != notFound) { + result = makeUString(result.substringSharingImpl(0, pos), "\"\\\"\"", result.substringSharingImpl(pos + 1)); pos += 4; } return result; @@ -63,19 +66,19 @@ static UString valueToSourceString(ExecState* exec, JSValue val) return "0"; if (val.isString()) - return makeString("\"", escapeQuotes(val.toString(exec)), "\""); + return makeUString("\"", escapeQuotes(val.toString(exec)), "\""); return val.toString(exec); } static CString constantName(ExecState* exec, int k, JSValue value) { - return makeString(valueToSourceString(exec, value), "(@k", UString::from(k - FirstConstantRegisterIndex), ")").UTF8String(); + return makeUString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")").utf8(); } static CString idName(int id0, const Identifier& ident) { - return makeString(ident.ustring(), "(@id", UString::from(id0), ")").UTF8String(); + return makeUString(ident.ustring(), "(@id", UString::number(id0), ")").utf8(); } CString CodeBlock::registerName(ExecState* exec, int r) const @@ -86,7 +89,7 @@ CString CodeBlock::registerName(ExecState* exec, int r) const if (isConstantRegisterIndex(r)) return constantName(exec, r, getConstant(r)); - return makeString("r", UString::from(r)).UTF8String(); + return makeUString("r", UString::number(r)).utf8(); } static UString regexpToSourceString(RegExp* regExp) @@ -100,12 +103,12 @@ static UString regexpToSourceString(RegExp* regExp) if (regExp->multiline()) postfix[index] = 'm'; - return makeString("/", regExp->pattern(), postfix); + return makeUString("/", regExp->pattern(), postfix); } static CString regexpName(int re, RegExp* regexp) { - return makeString(regexpToSourceString(regexp), "(@re", UString::from(re), ")").UTF8String(); + return makeUString(regexpToSourceString(regexp), "(@re", UString::number(re), ")").utf8(); } static UString pointerToSourceString(void* p) @@ -174,7 +177,7 @@ void CodeBlock::printPutByIdOp(ExecState* exec, int location, Vectoru.operand; int r1 = (++it)->u.operand; printf("[%4d] %s\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data()); - it += 4; + it += 5; } #if ENABLE(JIT) @@ -223,32 +226,32 @@ static unsigned instructionOffsetForNth(ExecState* exec, const VectorgetOpcode(op_get_by_id_proto)) { - printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data()); + printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data()); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) { - printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data(), pointerToSourceString(vPC[6].u.structureChain).UTF8String().data()); + printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data(), pointerToSourceString(vPC[6].u.structureChain).utf8().data()); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain)) { - printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structureChain).UTF8String().data()); + printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structureChain).utf8().data()); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id)) { @@ -352,7 +355,7 @@ void CodeBlock::dump(ExecState* exec) const printf("\nIdentifiers:\n"); size_t i = 0; do { - printf(" id%u = %s\n", static_cast(i), m_identifiers[i].ascii()); + printf(" id%u = %s\n", static_cast(i), m_identifiers[i].ustring().utf8().data()); ++i; } while (i != m_identifiers.size()); } @@ -362,7 +365,7 @@ void CodeBlock::dump(ExecState* exec) const unsigned registerIndex = m_numVars; size_t i = 0; do { - printf(" k%u = %s\n", registerIndex, valueToSourceString(exec, m_constantRegisters[i].jsValue()).ascii()); + printf(" k%u = %s\n", registerIndex, valueToSourceString(exec, m_constantRegisters[i].get()).utf8().data()); ++i; ++registerIndex; } while (i < m_constantRegisters.size()); @@ -372,7 +375,7 @@ void CodeBlock::dump(ExecState* exec) const printf("\nm_regexps:\n"); size_t i = 0; do { - printf(" re%u = %s\n", static_cast(i), regexpToSourceString(m_rareData->m_regexps[i].get()).ascii()); + printf(" re%u = %s\n", static_cast(i), regexpToSourceString(m_rareData->m_regexps[i].get()).utf8().data()); ++i; } while (i < m_rareData->m_regexps.size()); } @@ -395,7 +398,8 @@ void CodeBlock::dump(ExecState* exec) const ++i; } while (i < m_structureStubInfos.size()); } -#else +#endif +#if ENABLE(INTERPRETER) if (!m_globalResolveInstructions.isEmpty() || !m_propertyAccessInstructions.isEmpty()) printf("\nStructures:\n"); @@ -453,7 +457,7 @@ void CodeBlock::dump(ExecState* exec) const continue; ASSERT(!((i + m_rareData->m_characterSwitchJumpTables[i].min) & ~0xFFFF)); UChar ch = static_cast(entry + m_rareData->m_characterSwitchJumpTables[i].min); - printf("\t\t\"%s\" => %04d\n", UString(&ch, 1).ascii(), *iter); + printf("\t\t\"%s\" => %04d\n", UString(&ch, 1).utf8().data(), *iter); } printf(" }\n"); ++i; @@ -467,7 +471,7 @@ void CodeBlock::dump(ExecState* exec) const printf(" %1d = {\n", i); StringJumpTable::StringOffsetTable::const_iterator end = m_rareData->m_stringSwitchJumpTables[i].offsetTable.end(); for (StringJumpTable::StringOffsetTable::const_iterator iter = m_rareData->m_stringSwitchJumpTables[i].offsetTable.begin(); iter != end; ++iter) - printf("\t\t\"%s\" => %04d\n", UString(iter->first).ascii(), iter->second.branchOffset); + printf("\t\t\"%s\" => %04d\n", UString(iter->first).utf8().data(), iter->second.branchOffset); printf(" }\n"); ++i; } while (i < m_rareData->m_stringSwitchJumpTables.size()); @@ -484,17 +488,30 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printf("[%4d] enter\n", location); break; } - case op_enter_with_activation: { + case op_create_activation: { int r0 = (++it)->u.operand; - printf("[%4d] enter_with_activation %s\n", location, registerName(exec, r0).data()); + printf("[%4d] create_activation %s\n", location, registerName(exec, r0).data()); break; } case op_create_arguments: { - printf("[%4d] create_arguments\n", location); + int r0 = (++it)->u.operand; + printf("[%4d] create_arguments\t %s\n", location, registerName(exec, r0).data()); break; } - case op_init_arguments: { - printf("[%4d] init_arguments\n", location); + case op_init_lazy_reg: { + int r0 = (++it)->u.operand; + printf("[%4d] init_lazy_reg\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_get_callee: { + int r0 = (++it)->u.operand; + printf("[%4d] op_get_callee %s\n", location, registerName(exec, r0).data()); + break; + } + case op_create_this: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] create_this %s %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data()); break; } case op_convert_this: { @@ -502,6 +519,11 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printf("[%4d] convert_this %s\n", location, registerName(exec, r0).data()); break; } + case op_convert_this_strict: { + int r0 = (++it)->u.operand; + printf("[%4d] convert_this_strict %s\n", location, registerName(exec, r0).data()); + break; + } case op_new_object: { int r0 = (++it)->u.operand; printf("[%4d] new_object\t %s\n", location, registerName(exec, r0).data()); @@ -514,6 +536,13 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printf("[%4d] new_array\t %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, argv).data(), argc); break; } + case op_new_array_buffer: { + int dst = (++it)->u.operand; + int argv = (++it)->u.operand; + int argc = (++it)->u.operand; + printf("[%4d] new_array_buffer %s, %d, %d\n", location, registerName(exec, dst).data(), argv, argc); + break; + } case op_new_regexp: { int r0 = (++it)->u.operand; int re0 = (++it)->u.operand; @@ -643,6 +672,11 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printUnaryOp(exec, location, it, "bitnot"); break; } + case op_check_has_instance: { + int base = (++it)->u.operand; + printf("[%4d] check_has_instance\t\t %s\n", location, registerName(exec, base).data()); + break; + } case op_instanceof: { int r0 = (++it)->u.operand; int r1 = (++it)->u.operand; @@ -698,19 +732,18 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& } case op_resolve_global: { int r0 = (++it)->u.operand; - JSValue scope = JSValue((++it)->u.jsCell); int id0 = (++it)->u.operand; - printf("[%4d] resolve_global\t %s, %s, %s\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).ascii(), idName(id0, m_identifiers[id0]).data()); + printf("[%4d] resolve_global\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); it += 2; break; } case op_resolve_global_dynamic: { int r0 = (++it)->u.operand; - JSValue scope = JSValue((++it)->u.jsCell); int id0 = (++it)->u.operand; - int depth = it[2].u.operand; - printf("[%4d] resolve_global_dynamic\t %s, %s, %s, %d\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).ascii(), idName(id0, m_identifiers[id0]).data(), depth); - it += 3; + JSValue scope = JSValue((++it)->u.jsCell.get()); + ++it; + int depth = (++it)->u.operand; + printf("[%4d] resolve_global_dynamic\t %s, %s, %s, %d\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).utf8().data(), idName(id0, m_identifiers[id0]).data(), depth); break; } case op_get_scoped_var: { @@ -729,22 +762,27 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& } case op_get_global_var: { int r0 = (++it)->u.operand; - JSValue scope = JSValue((++it)->u.jsCell); int index = (++it)->u.operand; - printf("[%4d] get_global_var\t %s, %s, %d\n", location, registerName(exec, r0).data(), valueToSourceString(exec, scope).ascii(), index); + printf("[%4d] get_global_var\t %s, %d\n", location, registerName(exec, r0).data(), index); break; } case op_put_global_var: { - JSValue scope = JSValue((++it)->u.jsCell); int index = (++it)->u.operand; int r0 = (++it)->u.operand; - printf("[%4d] put_global_var\t %s, %d, %s\n", location, valueToSourceString(exec, scope).ascii(), index, registerName(exec, r0).data()); + printf("[%4d] put_global_var\t %d, %s\n", location, index, registerName(exec, r0).data()); break; } case op_resolve_base: { int r0 = (++it)->u.operand; int id0 = (++it)->u.operand; - printf("[%4d] resolve_base\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); + int isStrict = (++it)->u.operand; + printf("[%4d] resolve_base%s\t %s, %s\n", location, isStrict ? "_strict" : "", registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); + break; + } + case op_ensure_property_exists: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + printf("[%4d] ensure_property_exists\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); break; } case op_resolve_with_base: { @@ -830,6 +868,11 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printGetByIdOp(exec, location, it, "get_string_length"); break; } + case op_get_arguments_length: { + printUnaryOp(exec, location, it, "get_arguments_length"); + it++; + break; + } case op_put_by_id: { printPutByIdOp(exec, location, it, "put_by_id"); break; @@ -878,6 +921,13 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printf("[%4d] get_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data()); break; } + case op_get_argument_by_val: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int r2 = (++it)->u.operand; + printf("[%4d] get_argument_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data()); + break; + } case op_get_by_pname: { int r0 = (++it)->u.operand; int r1 = (++it)->u.operand; @@ -1016,7 +1066,8 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& case op_new_func: { int r0 = (++it)->u.operand; int f0 = (++it)->u.operand; - printf("[%4d] new_func\t\t %s, f%d\n", location, registerName(exec, r0).data(), f0); + int shouldCheck = (++it)->u.operand; + printf("[%4d] new_func\t\t %s, f%d, %s\n", location, registerName(exec, r0).data(), f0, shouldCheck ? "" : ""); break; } case op_new_func_exp: { @@ -1026,27 +1077,24 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& break; } case op_call: { - int dst = (++it)->u.operand; int func = (++it)->u.operand; int argCount = (++it)->u.operand; int registerOffset = (++it)->u.operand; - printf("[%4d] call\t\t %s, %s, %d, %d\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), argCount, registerOffset); + printf("[%4d] call\t\t %s, %d, %d\n", location, registerName(exec, func).data(), argCount, registerOffset); break; } case op_call_eval: { - int dst = (++it)->u.operand; int func = (++it)->u.operand; int argCount = (++it)->u.operand; int registerOffset = (++it)->u.operand; - printf("[%4d] call_eval\t %s, %s, %d, %d\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), argCount, registerOffset); + printf("[%4d] call_eval\t %s, %d, %d\n", location, registerName(exec, func).data(), argCount, registerOffset); break; } case op_call_varargs: { - int dst = (++it)->u.operand; int func = (++it)->u.operand; int argCount = (++it)->u.operand; int registerOffset = (++it)->u.operand; - printf("[%4d] call_varargs\t %s, %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), registerName(exec, argCount).data(), registerOffset); + printf("[%4d] call_varargs\t %s, %s, %d\n", location, registerName(exec, func).data(), registerName(exec, argCount).data(), registerOffset); break; } case op_load_varargs: { @@ -1055,11 +1103,13 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& } case op_tear_off_activation: { int r0 = (++it)->u.operand; - printf("[%4d] tear_off_activation\t %s\n", location, registerName(exec, r0).data()); + int r1 = (++it)->u.operand; + printf("[%4d] tear_off_activation\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data()); break; } case op_tear_off_arguments: { - printf("[%4d] tear_off_arguments\n", location); + int r0 = (++it)->u.operand; + printf("[%4d] tear_off_arguments\t %s\n", location, registerName(exec, r0).data()); break; } case op_ret: { @@ -1067,20 +1117,22 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printf("[%4d] ret\t\t %s\n", location, registerName(exec, r0).data()); break; } - case op_construct: { - int dst = (++it)->u.operand; - int func = (++it)->u.operand; - int argCount = (++it)->u.operand; - int registerOffset = (++it)->u.operand; - int proto = (++it)->u.operand; - int thisRegister = (++it)->u.operand; - printf("[%4d] construct\t %s, %s, %d, %d, %s, %s\n", location, registerName(exec, dst).data(), registerName(exec, func).data(), argCount, registerOffset, registerName(exec, proto).data(), registerName(exec, thisRegister).data()); + case op_call_put_result: { + int r0 = (++it)->u.operand; + printf("[%4d] op_call_put_result\t\t %s\n", location, registerName(exec, r0).data()); break; } - case op_construct_verify: { + case op_ret_object_or_this: { int r0 = (++it)->u.operand; int r1 = (++it)->u.operand; - printf("[%4d] construct_verify\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data()); + printf("[%4d] constructor_ret\t\t %s %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data()); + break; + } + case op_construct: { + int func = (++it)->u.operand; + int argCount = (++it)->u.operand; + int registerOffset = (++it)->u.operand; + printf("[%4d] construct\t %s, %d, %d\n", location, registerName(exec, func).data(), argCount, registerOffset); break; } case op_strcat: { @@ -1108,9 +1160,12 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& } case op_next_pname: { int dest = it[1].u.operand; - int iter = it[4].u.operand; - int offset = it[5].u.operand; - printf("[%4d] next_pname\t %s, %s, %d(->%d)\n", location, registerName(exec, dest).data(), registerName(exec, iter).data(), offset, location + offset); + int base = it[2].u.operand; + int i = it[3].u.operand; + int size = it[4].u.operand; + int iter = it[5].u.operand; + int offset = it[6].u.operand; + printf("[%4d] next_pname\t %s, %s, %s, %s, %s, %d(->%d)\n", location, registerName(exec, dest).data(), registerName(exec, base).data(), registerName(exec, i).data(), registerName(exec, size).data(), registerName(exec, iter).data(), offset, location + offset); it += OPCODE_LENGTH(op_next_pname) - 1; break; } @@ -1146,11 +1201,9 @@ void CodeBlock::dump(ExecState* exec, const Vector::const_iterator& printf("[%4d] throw\t\t %s\n", location, registerName(exec, r0).data()); break; } - case op_new_error: { - int r0 = (++it)->u.operand; - int errorType = (++it)->u.operand; + case op_throw_reference_error: { int k0 = (++it)->u.operand; - printf("[%4d] new_error\t %s, %d, %s\n", location, registerName(exec, r0).data(), errorType, constantName(exec, k0, getConstant(k0)).data()); + printf("[%4d] throw_reference_error\t %s\n", location, constantName(exec, k0, getConstant(k0)).data()); break; } case op_jsr: { @@ -1212,13 +1265,10 @@ static HashSet liveCodeBlockSet; macro(immediateSwitchJumpTables) \ macro(characterSwitchJumpTables) \ macro(stringSwitchJumpTables) \ - macro(functionRegisterInfos) - -#define FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(macro) \ + macro(evalCodeCache) \ macro(expressionInfo) \ macro(lineInfo) \ - macro(getByIdExceptionInfo) \ - macro(pcVector) + macro(callReturnIndexVector) template static size_t sizeInBytes(const Vector& vector) @@ -1232,7 +1282,6 @@ void CodeBlock::dumpStatistics() #define DEFINE_VARS(name) size_t name##IsNotEmpty = 0; size_t name##TotalSize = 0; FOR_EACH_MEMBER_VECTOR(DEFINE_VARS) FOR_EACH_MEMBER_VECTOR_RARE_DATA(DEFINE_VARS) - FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(DEFINE_VARS) #undef DEFINE_VARS // Non-vector data members @@ -1241,7 +1290,6 @@ void CodeBlock::dumpStatistics() size_t symbolTableIsNotEmpty = 0; size_t symbolTableTotalSize = 0; - size_t hasExceptionInfo = 0; size_t hasRareData = 0; size_t isFunctionCode = 0; @@ -1261,13 +1309,6 @@ void CodeBlock::dumpStatistics() symbolTableTotalSize += (codeBlock->m_symbolTable.capacity() * (sizeof(SymbolTable::KeyType) + sizeof(SymbolTable::MappedType))); } - if (codeBlock->m_exceptionInfo) { - hasExceptionInfo++; - #define GET_STATS(name) if (!codeBlock->m_exceptionInfo->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_exceptionInfo->m_##name); } - FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(GET_STATS) - #undef GET_STATS - } - if (codeBlock->m_rareData) { hasRareData++; #define GET_STATS(name) if (!codeBlock->m_rareData->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_rareData->m_##name); } @@ -1296,7 +1337,6 @@ void CodeBlock::dumpStatistics() #define GET_TOTAL_SIZE(name) totalSize += name##TotalSize; FOR_EACH_MEMBER_VECTOR(GET_TOTAL_SIZE) FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_TOTAL_SIZE) - FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(GET_TOTAL_SIZE) #undef GET_TOTAL_SIZE totalSize += symbolTableTotalSize; @@ -1311,13 +1351,11 @@ void CodeBlock::dumpStatistics() printf("Number of GlobalCode CodeBlocks: %zu (%.3f%%)\n", isGlobalCode, static_cast(isGlobalCode) * 100.0 / liveCodeBlockSet.size()); printf("Number of EvalCode CodeBlocks: %zu (%.3f%%)\n", isEvalCode, static_cast(isEvalCode) * 100.0 / liveCodeBlockSet.size()); - printf("Number of CodeBlocks with exception info: %zu (%.3f%%)\n", hasExceptionInfo, static_cast(hasExceptionInfo) * 100.0 / liveCodeBlockSet.size()); printf("Number of CodeBlocks with rare data: %zu (%.3f%%)\n", hasRareData, static_cast(hasRareData) * 100.0 / liveCodeBlockSet.size()); #define PRINT_STATS(name) printf("Number of CodeBlocks with " #name ": %zu\n", name##IsNotEmpty); printf("Size of all " #name ": %zu\n", name##TotalSize); FOR_EACH_MEMBER_VECTOR(PRINT_STATS) FOR_EACH_MEMBER_VECTOR_RARE_DATA(PRINT_STATS) - FOR_EACH_MEMBER_VECTOR_EXCEPTION_INFO(PRINT_STATS) #undef PRINT_STATS printf("Number of CodeBlocks with evalCodeCache: %zu\n", evalCodeCacheIsNotEmpty); @@ -1330,24 +1368,27 @@ void CodeBlock::dumpStatistics() #endif } -CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, PassRefPtr sourceProvider, unsigned sourceOffset, SymbolTable* symTab) - : m_numCalleeRegisters(0) +CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject *globalObject, PassRefPtr sourceProvider, unsigned sourceOffset, SymbolTable* symTab, bool isConstructor) + : m_globalObject(globalObject->globalData(), ownerExecutable, globalObject) + , m_heap(&m_globalObject->globalData().heap) + , m_numCalleeRegisters(0) , m_numVars(0) , m_numParameters(0) - , m_ownerExecutable(ownerExecutable) + , m_isConstructor(isConstructor) + , m_ownerExecutable(globalObject->globalData(), ownerExecutable, ownerExecutable) , m_globalData(0) #ifndef NDEBUG , m_instructionCount(0) #endif + , m_argumentsRegister(-1) , m_needsFullScopeChain(ownerExecutable->needsActivation()) , m_usesEval(ownerExecutable->usesEval()) - , m_usesArguments(false) , m_isNumericCompareFunction(false) + , m_isStrictMode(ownerExecutable->isStrictMode()) , m_codeType(codeType) , m_source(sourceProvider) , m_sourceOffset(sourceOffset) , m_symbolTable(symTab) - , m_exceptionInfo(new ExceptionInfo) { ASSERT(m_source); @@ -1358,41 +1399,9 @@ CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, PassR CodeBlock::~CodeBlock() { -#if ENABLE(INTERPRETER) - for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i) - derefStructures(&m_instructions[m_globalResolveInstructions[i]]); - - for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i) - derefStructures(&m_instructions[m_propertyAccessInstructions[i]]); -#endif #if ENABLE(JIT) - for (size_t size = m_globalResolveInfos.size(), i = 0; i < size; ++i) { - if (m_globalResolveInfos[i].structure) - m_globalResolveInfos[i].structure->deref(); - } - for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i) m_structureStubInfos[i].deref(); - - for (size_t size = m_callLinkInfos.size(), i = 0; i < size; ++i) { - CallLinkInfo* callLinkInfo = &m_callLinkInfos[i]; - if (callLinkInfo->isLinked()) - callLinkInfo->callee->removeCaller(callLinkInfo); - } - - for (size_t size = m_methodCallLinkInfos.size(), i = 0; i < size; ++i) { - if (Structure* structure = m_methodCallLinkInfos[i].cachedStructure) { - structure->deref(); - // Both members must be filled at the same time - ASSERT(!!m_methodCallLinkInfos[i].cachedPrototypeStructure); - m_methodCallLinkInfos[i].cachedPrototypeStructure->deref(); - } - } - -#if ENABLE(JIT_OPTIMIZE_CALL) - unlinkCallers(); -#endif - #endif // ENABLE(JIT) #if DUMP_CODE_BLOCK_STATISTICS @@ -1400,50 +1409,46 @@ CodeBlock::~CodeBlock() #endif } -#if ENABLE(JIT_OPTIMIZE_CALL) -void CodeBlock::unlinkCallers() -{ - size_t size = m_linkedCallerList.size(); - for (size_t i = 0; i < size; ++i) { - CallLinkInfo* currentCaller = m_linkedCallerList[i]; - JIT::unlinkCall(currentCaller); - currentCaller->setUnlinked(); - } - m_linkedCallerList.clear(); -} -#endif - -void CodeBlock::derefStructures(Instruction* vPC) const +void CodeBlock::visitStructures(SlotVisitor& visitor, Instruction* vPC) const { Interpreter* interpreter = m_globalData->interpreter; + if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) && vPC[4].u.structure) { + visitor.append(&vPC[4].u.structure); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_self)) { - vPC[4].u.structure->deref(); + visitor.append(&vPC[4].u.structure); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_proto)) { - vPC[4].u.structure->deref(); - vPC[5].u.structure->deref(); + visitor.append(&vPC[4].u.structure); + visitor.append(&vPC[5].u.structure); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_chain)) { - vPC[4].u.structure->deref(); - vPC[5].u.structureChain->deref(); + visitor.append(&vPC[4].u.structure); + visitor.append(&vPC[5].u.structureChain); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) { - vPC[4].u.structure->deref(); - vPC[5].u.structure->deref(); - vPC[6].u.structureChain->deref(); + visitor.append(&vPC[4].u.structure); + visitor.append(&vPC[5].u.structure); + visitor.append(&vPC[6].u.structureChain); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) && vPC[4].u.structure) { + visitor.append(&vPC[4].u.structure); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) { - vPC[4].u.structure->deref(); + visitor.append(&vPC[4].u.structure); return; } if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global) || vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) { - if(vPC[4].u.structure) - vPC[4].u.structure->deref(); + if (vPC[3].u.structure) + visitor.append(&vPC[3].u.structure); return; } if ((vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto_list)) @@ -1453,7 +1458,7 @@ void CodeBlock::derefStructures(Instruction* vPC) const || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_proto_list)) || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_self_list))) { PolymorphicAccessStructureList* polymorphicStructures = vPC[4].u.polymorphicStructures; - polymorphicStructures->derefStructures(vPC[5].u.operand); + polymorphicStructures->visitAggregate(visitor, vPC[5].u.operand); delete polymorphicStructures; return; } @@ -1462,68 +1467,62 @@ void CodeBlock::derefStructures(Instruction* vPC) const ASSERT(vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_get_array_length) || vPC[0].u.opcode == interpreter->getOpcode(op_get_string_length)); } -void CodeBlock::refStructures(Instruction* vPC) const +void EvalCodeCache::visitAggregate(SlotVisitor& visitor) { - Interpreter* interpreter = m_globalData->interpreter; - - if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_self)) { - vPC[4].u.structure->ref(); - return; - } - if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_proto)) { - vPC[4].u.structure->ref(); - vPC[5].u.structure->ref(); - return; - } - if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_chain)) { - vPC[4].u.structure->ref(); - vPC[5].u.structureChain->ref(); - return; - } - if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) { - vPC[4].u.structure->ref(); - vPC[5].u.structure->ref(); - vPC[6].u.structureChain->ref(); - return; - } - if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) { - vPC[4].u.structure->ref(); - return; - } - - // These instructions don't ref their Structures. - ASSERT(vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_generic)); + EvalCacheMap::iterator end = m_cacheMap.end(); + for (EvalCacheMap::iterator ptr = m_cacheMap.begin(); ptr != end; ++ptr) + visitor.append(&ptr->second); } -void CodeBlock::markAggregate(MarkStack& markStack) +void CodeBlock::visitAggregate(SlotVisitor& visitor) { - for (size_t i = 0; i < m_constantRegisters.size(); ++i) - markStack.append(m_constantRegisters[i].jsValue()); + visitor.append(&m_globalObject); + visitor.append(&m_ownerExecutable); + if (m_rareData) { + m_rareData->m_evalCodeCache.visitAggregate(visitor); + size_t regExpCount = m_rareData->m_regexps.size(); + WriteBarrier* regexps = m_rareData->m_regexps.data(); + for (size_t i = 0; i < regExpCount; i++) + visitor.append(regexps + i); + } + visitor.appendValues(m_constantRegisters.data(), m_constantRegisters.size()); for (size_t i = 0; i < m_functionExprs.size(); ++i) - m_functionExprs[i]->markAggregate(markStack); + visitor.append(&m_functionExprs[i]); for (size_t i = 0; i < m_functionDecls.size(); ++i) - m_functionDecls[i]->markAggregate(markStack); -} + visitor.append(&m_functionDecls[i]); +#if ENABLE(JIT_OPTIMIZE_CALL) + if (visitor.shouldUnlinkCalls()) + unlinkCalls(); + for (unsigned i = 0; i < numberOfCallLinkInfos(); ++i) + if (callLinkInfo(i).isLinked()) + visitor.append(&callLinkInfo(i).callee); +#endif +#if ENABLE(INTERPRETER) + for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i) + visitStructures(visitor, &m_instructions[m_propertyAccessInstructions[i]]); + for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i) + visitStructures(visitor, &m_instructions[m_globalResolveInstructions[i]]); +#endif +#if ENABLE(JIT) + for (size_t size = m_globalResolveInfos.size(), i = 0; i < size; ++i) { + if (m_globalResolveInfos[i].structure) + visitor.append(&m_globalResolveInfos[i].structure); + } -void CodeBlock::reparseForExceptionInfoIfNecessary(CallFrame* callFrame) -{ - if (m_exceptionInfo) - return; + for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i) + m_structureStubInfos[i].visitAggregate(visitor); - ScopeChainNode* scopeChain = callFrame->scopeChain(); - if (m_needsFullScopeChain) { - ScopeChain sc(scopeChain); - int scopeDelta = sc.localDepth(); - if (m_codeType == EvalCode) - scopeDelta -= static_cast(this)->baseScopeDepth(); - else if (m_codeType == FunctionCode) - scopeDelta++; // Compilation of function code assumes activation is not on the scope chain yet. - ASSERT(scopeDelta >= 0); - while (scopeDelta--) - scopeChain = scopeChain->next; + for (size_t size = m_methodCallLinkInfos.size(), i = 0; i < size; ++i) { + if (m_methodCallLinkInfos[i].cachedStructure) { + // Both members must be filled at the same time + visitor.append(&m_methodCallLinkInfos[i].cachedStructure); + ASSERT(!!m_methodCallLinkInfos[i].cachedPrototypeStructure); + visitor.append(&m_methodCallLinkInfos[i].cachedPrototypeStructure); + visitor.append(&m_methodCallLinkInfos[i].cachedFunction); + visitor.append(&m_methodCallLinkInfos[i].cachedPrototype); + } } - - m_exceptionInfo.set(m_ownerExecutable->reparseExceptionInfo(m_globalData, scopeChain, this)); +#endif } HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset) @@ -1544,122 +1543,66 @@ HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset) return 0; } -int CodeBlock::lineNumberForBytecodeOffset(CallFrame* callFrame, unsigned bytecodeOffset) +int CodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset) { ASSERT(bytecodeOffset < m_instructionCount); - reparseForExceptionInfoIfNecessary(callFrame); - ASSERT(m_exceptionInfo); + if (!m_rareData) + return m_ownerExecutable->source().firstLine(); - if (!m_exceptionInfo->m_lineInfo.size()) - return m_ownerExecutable->source().firstLine(); // Empty function + Vector& lineInfo = m_rareData->m_lineInfo; int low = 0; - int high = m_exceptionInfo->m_lineInfo.size(); + int high = lineInfo.size(); while (low < high) { int mid = low + (high - low) / 2; - if (m_exceptionInfo->m_lineInfo[mid].instructionOffset <= bytecodeOffset) + if (lineInfo[mid].instructionOffset <= bytecodeOffset) low = mid + 1; else high = mid; } - + if (!low) return m_ownerExecutable->source().firstLine(); - return m_exceptionInfo->m_lineInfo[low - 1].lineNumber; + return lineInfo[low - 1].lineNumber; } -int CodeBlock::expressionRangeForBytecodeOffset(CallFrame* callFrame, unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset) +void CodeBlock::expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset) { ASSERT(bytecodeOffset < m_instructionCount); - reparseForExceptionInfoIfNecessary(callFrame); - ASSERT(m_exceptionInfo); - - if (!m_exceptionInfo->m_expressionInfo.size()) { - // We didn't think anything could throw. Apparently we were wrong. + if (!m_rareData) { startOffset = 0; endOffset = 0; divot = 0; - return lineNumberForBytecodeOffset(callFrame, bytecodeOffset); + return; } + Vector& expressionInfo = m_rareData->m_expressionInfo; + int low = 0; - int high = m_exceptionInfo->m_expressionInfo.size(); + int high = expressionInfo.size(); while (low < high) { int mid = low + (high - low) / 2; - if (m_exceptionInfo->m_expressionInfo[mid].instructionOffset <= bytecodeOffset) + if (expressionInfo[mid].instructionOffset <= bytecodeOffset) low = mid + 1; else high = mid; } - + ASSERT(low); if (!low) { startOffset = 0; endOffset = 0; divot = 0; - return lineNumberForBytecodeOffset(callFrame, bytecodeOffset); - } - - startOffset = m_exceptionInfo->m_expressionInfo[low - 1].startOffset; - endOffset = m_exceptionInfo->m_expressionInfo[low - 1].endOffset; - divot = m_exceptionInfo->m_expressionInfo[low - 1].divotPoint + m_sourceOffset; - return lineNumberForBytecodeOffset(callFrame, bytecodeOffset); -} - -bool CodeBlock::getByIdExceptionInfoForBytecodeOffset(CallFrame* callFrame, unsigned bytecodeOffset, OpcodeID& opcodeID) -{ - ASSERT(bytecodeOffset < m_instructionCount); - - reparseForExceptionInfoIfNecessary(callFrame); - ASSERT(m_exceptionInfo); - - if (!m_exceptionInfo->m_getByIdExceptionInfo.size()) - return false; - - int low = 0; - int high = m_exceptionInfo->m_getByIdExceptionInfo.size(); - while (low < high) { - int mid = low + (high - low) / 2; - if (m_exceptionInfo->m_getByIdExceptionInfo[mid].bytecodeOffset <= bytecodeOffset) - low = mid + 1; - else - high = mid; - } - - if (!low || m_exceptionInfo->m_getByIdExceptionInfo[low - 1].bytecodeOffset != bytecodeOffset) - return false; - - opcodeID = m_exceptionInfo->m_getByIdExceptionInfo[low - 1].isOpConstruct ? op_construct : op_instanceof; - return true; -} - -#if ENABLE(JIT) -bool CodeBlock::functionRegisterForBytecodeOffset(unsigned bytecodeOffset, int& functionRegisterIndex) -{ - ASSERT(bytecodeOffset < m_instructionCount); - - if (!m_rareData || !m_rareData->m_functionRegisterInfos.size()) - return false; - - int low = 0; - int high = m_rareData->m_functionRegisterInfos.size(); - while (low < high) { - int mid = low + (high - low) / 2; - if (m_rareData->m_functionRegisterInfos[mid].bytecodeOffset <= bytecodeOffset) - low = mid + 1; - else - high = mid; + return; } - if (!low || m_rareData->m_functionRegisterInfos[low - 1].bytecodeOffset != bytecodeOffset) - return false; - - functionRegisterIndex = m_rareData->m_functionRegisterInfos[low - 1].functionRegisterIndex; - return true; + startOffset = expressionInfo[low - 1].startOffset; + endOffset = expressionInfo[low - 1].endOffset; + divot = expressionInfo[low - 1].divotPoint + m_sourceOffset; + return; } -#endif #if ENABLE(INTERPRETER) bool CodeBlock::hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset) @@ -1716,7 +1659,6 @@ void CodeBlock::shrinkToFit() m_structureStubInfos.shrinkToFit(); m_globalResolveInfos.shrinkToFit(); m_callLinkInfos.shrinkToFit(); - m_linkedCallerList.shrinkToFit(); #endif m_identifiers.shrinkToFit(); @@ -1724,22 +1666,49 @@ void CodeBlock::shrinkToFit() m_functionExprs.shrinkToFit(); m_constantRegisters.shrinkToFit(); - if (m_exceptionInfo) { - m_exceptionInfo->m_expressionInfo.shrinkToFit(); - m_exceptionInfo->m_lineInfo.shrinkToFit(); - m_exceptionInfo->m_getByIdExceptionInfo.shrinkToFit(); - } - if (m_rareData) { m_rareData->m_exceptionHandlers.shrinkToFit(); m_rareData->m_regexps.shrinkToFit(); m_rareData->m_immediateSwitchJumpTables.shrinkToFit(); m_rareData->m_characterSwitchJumpTables.shrinkToFit(); m_rareData->m_stringSwitchJumpTables.shrinkToFit(); + m_rareData->m_expressionInfo.shrinkToFit(); + m_rareData->m_lineInfo.shrinkToFit(); + } +} + +void CodeBlock::createActivation(CallFrame* callFrame) +{ + ASSERT(codeType() == FunctionCode); + ASSERT(needsFullScopeChain()); + ASSERT(!callFrame->uncheckedR(activationRegister()).jsValue()); + JSActivation* activation = new (callFrame) JSActivation(callFrame, static_cast(ownerExecutable())); + callFrame->uncheckedR(activationRegister()) = JSValue(activation); + callFrame->setScopeChain(callFrame->scopeChain()->push(activation)); +} + #if ENABLE(JIT) - m_rareData->m_functionRegisterInfos.shrinkToFit(); -#endif +void CodeBlock::unlinkCalls() +{ + if (!(m_callLinkInfos.size() || m_methodCallLinkInfos.size())) + return; + if (!m_globalData->canUseJIT()) + return; + RepatchBuffer repatchBuffer(this); + for (size_t i = 0; i < m_callLinkInfos.size(); i++) { + if (!m_callLinkInfos[i].isLinked()) + continue; + repatchBuffer.relink(m_callLinkInfos[i].callReturnLocation, m_callLinkInfos[i].isCall ? m_globalData->jitStubs->ctiVirtualCallLink() : m_globalData->jitStubs->ctiVirtualConstructLink()); + m_callLinkInfos[i].unlink(); } } +#endif + +void CodeBlock::clearEvalCache() +{ + if (!m_rareData) + return; + m_rareData->m_evalCodeCache.clear(); +} } // namespace JSC