diff options
author | Steve Block <steveblock@google.com> | 2011-05-13 06:44:40 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-05-13 06:44:40 -0700 |
commit | 08014c20784f3db5df3a89b73cce46037b77eb59 (patch) | |
tree | 47749210d31e19e6e2f64036fa8fae2ad693476f /Source/JavaScriptCore/bytecode | |
parent | 860220379e56aeb66424861ad602b07ee22b4055 (diff) | |
parent | 4c3661f7918f8b3f139f824efb7855bedccb4c94 (diff) | |
download | external_webkit-08014c20784f3db5df3a89b73cce46037b77eb59.zip external_webkit-08014c20784f3db5df3a89b73cce46037b77eb59.tar.gz external_webkit-08014c20784f3db5df3a89b73cce46037b77eb59.tar.bz2 |
Merge changes Ide388898,Ic49f367c,I1158a808,Iacb6ca5d,I2100dd3a,I5c1abe54,Ib0ef9902,I31dbc523,I570314b3
* changes:
Merge WebKit at r75315: Update WebKit version
Merge WebKit at r75315: Add FrameLoaderClient PageCache stubs
Merge WebKit at r75315: Stub out AXObjectCache::remove()
Merge WebKit at r75315: Fix ImageBuffer
Merge WebKit at r75315: Fix PluginData::initPlugins()
Merge WebKit at r75315: Fix conflicts
Merge WebKit at r75315: Fix Makefiles
Merge WebKit at r75315: Move Android-specific WebCore files to Source
Merge WebKit at r75315: Initial merge by git.
Diffstat (limited to 'Source/JavaScriptCore/bytecode')
-rw-r--r-- | Source/JavaScriptCore/bytecode/CodeBlock.cpp | 1708 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/CodeBlock.h | 691 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/EvalCodeCache.h | 78 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/Instruction.h | 169 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/JumpTable.cpp | 47 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/JumpTable.h | 103 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/Opcode.cpp | 191 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/Opcode.h | 276 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/SamplingTool.cpp | 406 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/SamplingTool.h | 414 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/StructureStubInfo.cpp | 80 | ||||
-rw-r--r-- | Source/JavaScriptCore/bytecode/StructureStubInfo.h | 185 |
12 files changed, 4348 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/bytecode/CodeBlock.cpp b/Source/JavaScriptCore/bytecode/CodeBlock.cpp new file mode 100644 index 0000000..cbae990 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/CodeBlock.cpp @@ -0,0 +1,1708 @@ +/* + * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "CodeBlock.h" + +#include "BytecodeGenerator.h" +#include "Debugger.h" +#include "Interpreter.h" +#include "JIT.h" +#include "JSActivation.h" +#include "JSFunction.h" +#include "JSStaticScopeObject.h" +#include "JSValue.h" +#include "UStringConcatenate.h" +#include <stdio.h> +#include <wtf/StringExtras.h> + +#define DUMP_CODE_BLOCK_STATISTICS 0 + +namespace JSC { + +#if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING) + +static UString escapeQuotes(const UString& str) +{ + UString result = str; + size_t pos = 0; + while ((pos = result.find('\"', pos)) != notFound) { + result = makeUString(result.substringSharingImpl(0, pos), "\"\\\"\"", result.substringSharingImpl(pos + 1)); + pos += 4; + } + return result; +} + +static UString valueToSourceString(ExecState* exec, JSValue val) +{ + if (!val) + return "0"; + + if (val.isString()) + return makeUString("\"", escapeQuotes(val.toString(exec)), "\""); + + return val.toString(exec); +} + +static CString constantName(ExecState* exec, int k, JSValue value) +{ + return makeUString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")").utf8(); +} + +static CString idName(int id0, const Identifier& ident) +{ + return makeUString(ident.ustring(), "(@id", UString::number(id0), ")").utf8(); +} + +CString CodeBlock::registerName(ExecState* exec, int r) const +{ + if (r == missingThisObjectMarker()) + return "<null>"; + + if (isConstantRegisterIndex(r)) + return constantName(exec, r, getConstant(r)); + + return makeUString("r", UString::number(r)).utf8(); +} + +static UString regexpToSourceString(RegExp* regExp) +{ + char postfix[5] = { '/', 0, 0, 0, 0 }; + int index = 1; + if (regExp->global()) + postfix[index++] = 'g'; + if (regExp->ignoreCase()) + postfix[index++] = 'i'; + if (regExp->multiline()) + postfix[index] = 'm'; + + return makeUString("/", regExp->pattern(), postfix); +} + +static CString regexpName(int re, RegExp* regexp) +{ + return makeUString(regexpToSourceString(regexp), "(@re", UString::number(re), ")").utf8(); +} + +static UString pointerToSourceString(void* p) +{ + char buffer[2 + 2 * sizeof(void*) + 1]; // 0x [two characters per byte] \0 + snprintf(buffer, sizeof(buffer), "%p", p); + return buffer; +} + +NEVER_INLINE static const char* debugHookName(int debugHookID) +{ + switch (static_cast<DebugHookID>(debugHookID)) { + case DidEnterCallFrame: + return "didEnterCallFrame"; + case WillLeaveCallFrame: + return "willLeaveCallFrame"; + case WillExecuteStatement: + return "willExecuteStatement"; + case WillExecuteProgram: + return "willExecuteProgram"; + case DidExecuteProgram: + return "didExecuteProgram"; + case DidReachBreakpoint: + return "didReachBreakpoint"; + } + + ASSERT_NOT_REACHED(); + return ""; +} + +void CodeBlock::printUnaryOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const +{ + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + + printf("[%4d] %s\t\t %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data()); +} + +void CodeBlock::printBinaryOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const +{ + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int r2 = (++it)->u.operand; + printf("[%4d] %s\t\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data()); +} + +void CodeBlock::printConditionalJump(ExecState* exec, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator& it, int location, const char* op) const +{ + int r0 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] %s\t\t %s, %d(->%d)\n", location, op, registerName(exec, r0).data(), offset, location + offset); +} + +void CodeBlock::printGetByIdOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const +{ + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int id0 = (++it)->u.operand; + printf("[%4d] %s\t %s, %s, %s\n", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data()); + it += 4; +} + +void CodeBlock::printPutByIdOp(ExecState* exec, int location, Vector<Instruction>::const_iterator& it, const char* op) const +{ + int r0 = (++it)->u.operand; + int id0 = (++it)->u.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 += 5; +} + +#if ENABLE(JIT) +static bool isGlobalResolve(OpcodeID opcodeID) +{ + return opcodeID == op_resolve_global || opcodeID == op_resolve_global_dynamic; +} + +static bool isPropertyAccess(OpcodeID opcodeID) +{ + switch (opcodeID) { + case op_get_by_id_self: + case op_get_by_id_proto: + case op_get_by_id_chain: + case op_get_by_id_self_list: + case op_get_by_id_proto_list: + case op_put_by_id_transition: + case op_put_by_id_replace: + case op_get_by_id: + case op_put_by_id: + case op_get_by_id_generic: + case op_put_by_id_generic: + case op_get_array_length: + case op_get_string_length: + return true; + default: + return false; + } +} + +static unsigned instructionOffsetForNth(ExecState* exec, const Vector<Instruction>& instructions, int nth, bool (*predicate)(OpcodeID)) +{ + size_t i = 0; + while (i < instructions.size()) { + OpcodeID currentOpcode = exec->interpreter()->getOpcodeID(instructions[i].u.opcode); + if (predicate(currentOpcode)) { + if (!--nth) + return i; + } + i += opcodeLengths[currentOpcode]; + } + + ASSERT_NOT_REACHED(); + return 0; +} + +static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset) +{ + printf(" [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).utf8().data()); +} + +static void printStructureStubInfo(const StructureStubInfo& stubInfo, unsigned instructionOffset) +{ + switch (stubInfo.accessType) { + case access_get_by_id_self: + printf(" [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).utf8().data()); + return; + case access_get_by_id_proto: + printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(stubInfo.u.getByIdProto.baseObjectStructure).utf8().data(), pointerToSourceString(stubInfo.u.getByIdProto.prototypeStructure).utf8().data()); + return; + case access_get_by_id_chain: + printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(stubInfo.u.getByIdChain.baseObjectStructure).utf8().data(), pointerToSourceString(stubInfo.u.getByIdChain.chain).utf8().data()); + return; + case access_get_by_id_self_list: + printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_self_list", pointerToSourceString(stubInfo.u.getByIdSelfList.structureList).utf8().data(), stubInfo.u.getByIdSelfList.listSize); + return; + case access_get_by_id_proto_list: + printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_proto_list", pointerToSourceString(stubInfo.u.getByIdProtoList.structureList).utf8().data(), stubInfo.u.getByIdProtoList.listSize); + return; + case access_put_by_id_transition: + printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(stubInfo.u.putByIdTransition.previousStructure).utf8().data(), pointerToSourceString(stubInfo.u.putByIdTransition.structure).utf8().data(), pointerToSourceString(stubInfo.u.putByIdTransition.chain).utf8().data()); + return; + case access_put_by_id_replace: + printf(" [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).utf8().data()); + return; + case access_get_by_id: + printf(" [%4d] %s\n", instructionOffset, "get_by_id"); + return; + case access_put_by_id: + printf(" [%4d] %s\n", instructionOffset, "put_by_id"); + return; + case access_get_by_id_generic: + printf(" [%4d] %s\n", instructionOffset, "op_get_by_id_generic"); + return; + case access_put_by_id_generic: + printf(" [%4d] %s\n", instructionOffset, "op_put_by_id_generic"); + return; + case access_get_array_length: + printf(" [%4d] %s\n", instructionOffset, "op_get_array_length"); + return; + case access_get_string_length: + printf(" [%4d] %s\n", instructionOffset, "op_get_string_length"); + return; + default: + ASSERT_NOT_REACHED(); + } +} +#endif + +void CodeBlock::printStructure(const char* name, const Instruction* vPC, int operand) const +{ + unsigned instructionOffset = vPC - m_instructions.begin(); + printf(" [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).utf8().data()); +} + +void CodeBlock::printStructures(const Instruction* vPC) const +{ + Interpreter* interpreter = m_globalData->interpreter; + unsigned instructionOffset = vPC - m_instructions.begin(); + + if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id)) { + printStructure("get_by_id", vPC, 4); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self)) { + printStructure("get_by_id_self", vPC, 4); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto)) { + 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).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).utf8().data(), pointerToSourceString(vPC[5].u.structureChain).utf8().data()); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id)) { + printStructure("put_by_id", vPC, 4); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) { + printStructure("put_by_id_replace", vPC, 4); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global)) { + printStructure("resolve_global", vPC, 4); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) { + printStructure("resolve_global_dynamic", vPC, 4); + return; + } + + // These m_instructions doesn't ref Structures. + ASSERT(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_call) || vPC[0].u.opcode == interpreter->getOpcode(op_call_eval) || vPC[0].u.opcode == interpreter->getOpcode(op_construct)); +} + +void CodeBlock::dump(ExecState* exec) const +{ + if (m_instructions.isEmpty()) { + printf("No instructions available.\n"); + return; + } + + size_t instructionCount = 0; + + for (size_t i = 0; i < m_instructions.size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(m_instructions[i].u.opcode)]) + ++instructionCount; + + printf("%lu m_instructions; %lu bytes at %p; %d parameter(s); %d callee register(s)\n\n", + static_cast<unsigned long>(instructionCount), + static_cast<unsigned long>(m_instructions.size() * sizeof(Instruction)), + this, m_numParameters, m_numCalleeRegisters); + + Vector<Instruction>::const_iterator begin = m_instructions.begin(); + Vector<Instruction>::const_iterator end = m_instructions.end(); + for (Vector<Instruction>::const_iterator it = begin; it != end; ++it) + dump(exec, begin, it); + + if (!m_identifiers.isEmpty()) { + printf("\nIdentifiers:\n"); + size_t i = 0; + do { + printf(" id%u = %s\n", static_cast<unsigned>(i), m_identifiers[i].ustring().utf8().data()); + ++i; + } while (i != m_identifiers.size()); + } + + if (!m_constantRegisters.isEmpty()) { + printf("\nConstants:\n"); + unsigned registerIndex = m_numVars; + size_t i = 0; + do { + printf(" k%u = %s\n", registerIndex, valueToSourceString(exec, m_constantRegisters[i].jsValue()).utf8().data()); + ++i; + ++registerIndex; + } while (i < m_constantRegisters.size()); + } + + if (m_rareData && !m_rareData->m_regexps.isEmpty()) { + printf("\nm_regexps:\n"); + size_t i = 0; + do { + printf(" re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_rareData->m_regexps[i].get()).utf8().data()); + ++i; + } while (i < m_rareData->m_regexps.size()); + } + +#if ENABLE(JIT) + if (!m_globalResolveInfos.isEmpty() || !m_structureStubInfos.isEmpty()) + printf("\nStructures:\n"); + + if (!m_globalResolveInfos.isEmpty()) { + size_t i = 0; + do { + printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isGlobalResolve)); + ++i; + } while (i < m_globalResolveInfos.size()); + } + if (!m_structureStubInfos.isEmpty()) { + size_t i = 0; + do { + printStructureStubInfo(m_structureStubInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isPropertyAccess)); + ++i; + } while (i < m_structureStubInfos.size()); + } +#else + if (!m_globalResolveInstructions.isEmpty() || !m_propertyAccessInstructions.isEmpty()) + printf("\nStructures:\n"); + + if (!m_globalResolveInstructions.isEmpty()) { + size_t i = 0; + do { + printStructures(&m_instructions[m_globalResolveInstructions[i]]); + ++i; + } while (i < m_globalResolveInstructions.size()); + } + if (!m_propertyAccessInstructions.isEmpty()) { + size_t i = 0; + do { + printStructures(&m_instructions[m_propertyAccessInstructions[i]]); + ++i; + } while (i < m_propertyAccessInstructions.size()); + } +#endif + + if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) { + printf("\nException Handlers:\n"); + unsigned i = 0; + do { + printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] }\n", i + 1, m_rareData->m_exceptionHandlers[i].start, m_rareData->m_exceptionHandlers[i].end, m_rareData->m_exceptionHandlers[i].target); + ++i; + } while (i < m_rareData->m_exceptionHandlers.size()); + } + + if (m_rareData && !m_rareData->m_immediateSwitchJumpTables.isEmpty()) { + printf("Immediate Switch Jump Tables:\n"); + unsigned i = 0; + do { + printf(" %1d = {\n", i); + int entry = 0; + Vector<int32_t>::const_iterator end = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.end(); + for (Vector<int32_t>::const_iterator iter = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) { + if (!*iter) + continue; + printf("\t\t%4d => %04d\n", entry + m_rareData->m_immediateSwitchJumpTables[i].min, *iter); + } + printf(" }\n"); + ++i; + } while (i < m_rareData->m_immediateSwitchJumpTables.size()); + } + + if (m_rareData && !m_rareData->m_characterSwitchJumpTables.isEmpty()) { + printf("\nCharacter Switch Jump Tables:\n"); + unsigned i = 0; + do { + printf(" %1d = {\n", i); + int entry = 0; + Vector<int32_t>::const_iterator end = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.end(); + for (Vector<int32_t>::const_iterator iter = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) { + if (!*iter) + continue; + ASSERT(!((i + m_rareData->m_characterSwitchJumpTables[i].min) & ~0xFFFF)); + UChar ch = static_cast<UChar>(entry + m_rareData->m_characterSwitchJumpTables[i].min); + printf("\t\t\"%s\" => %04d\n", UString(&ch, 1).utf8().data(), *iter); + } + printf(" }\n"); + ++i; + } while (i < m_rareData->m_characterSwitchJumpTables.size()); + } + + if (m_rareData && !m_rareData->m_stringSwitchJumpTables.isEmpty()) { + printf("\nString Switch Jump Tables:\n"); + unsigned i = 0; + do { + 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).utf8().data(), iter->second.branchOffset); + printf(" }\n"); + ++i; + } while (i < m_rareData->m_stringSwitchJumpTables.size()); + } + + printf("\n"); +} + +void CodeBlock::dump(ExecState* exec, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator& it) const +{ + int location = it - begin; + switch (exec->interpreter()->getOpcodeID(it->u.opcode)) { + case op_enter: { + printf("[%4d] enter\n", location); + break; + } + case op_create_activation: { + int r0 = (++it)->u.operand; + printf("[%4d] create_activation %s\n", location, registerName(exec, r0).data()); + break; + } + case op_create_arguments: { + int r0 = (++it)->u.operand; + printf("[%4d] create_arguments\t %s\n", location, registerName(exec, r0).data()); + break; + } + 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: { + int r0 = (++it)->u.operand; + 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()); + break; + } + case op_new_array: { + int dst = (++it)->u.operand; + int argv = (++it)->u.operand; + int argc = (++it)->u.operand; + printf("[%4d] new_array\t %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, argv).data(), argc); + break; + } + case op_new_regexp: { + int r0 = (++it)->u.operand; + int re0 = (++it)->u.operand; + printf("[%4d] new_regexp\t %s, %s\n", location, registerName(exec, r0).data(), regexpName(re0, regexp(re0)).data()); + break; + } + case op_mov: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] mov\t\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data()); + break; + } + case op_not: { + printUnaryOp(exec, location, it, "not"); + break; + } + case op_eq: { + printBinaryOp(exec, location, it, "eq"); + break; + } + case op_eq_null: { + printUnaryOp(exec, location, it, "eq_null"); + break; + } + case op_neq: { + printBinaryOp(exec, location, it, "neq"); + break; + } + case op_neq_null: { + printUnaryOp(exec, location, it, "neq_null"); + break; + } + case op_stricteq: { + printBinaryOp(exec, location, it, "stricteq"); + break; + } + case op_nstricteq: { + printBinaryOp(exec, location, it, "nstricteq"); + break; + } + case op_less: { + printBinaryOp(exec, location, it, "less"); + break; + } + case op_lesseq: { + printBinaryOp(exec, location, it, "lesseq"); + break; + } + case op_pre_inc: { + int r0 = (++it)->u.operand; + printf("[%4d] pre_inc\t\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_pre_dec: { + int r0 = (++it)->u.operand; + printf("[%4d] pre_dec\t\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_post_inc: { + printUnaryOp(exec, location, it, "post_inc"); + break; + } + case op_post_dec: { + printUnaryOp(exec, location, it, "post_dec"); + break; + } + case op_to_jsnumber: { + printUnaryOp(exec, location, it, "to_jsnumber"); + break; + } + case op_negate: { + printUnaryOp(exec, location, it, "negate"); + break; + } + case op_add: { + printBinaryOp(exec, location, it, "add"); + ++it; + break; + } + case op_mul: { + printBinaryOp(exec, location, it, "mul"); + ++it; + break; + } + case op_div: { + printBinaryOp(exec, location, it, "div"); + ++it; + break; + } + case op_mod: { + printBinaryOp(exec, location, it, "mod"); + break; + } + case op_sub: { + printBinaryOp(exec, location, it, "sub"); + ++it; + break; + } + case op_lshift: { + printBinaryOp(exec, location, it, "lshift"); + break; + } + case op_rshift: { + printBinaryOp(exec, location, it, "rshift"); + break; + } + case op_urshift: { + printBinaryOp(exec, location, it, "urshift"); + break; + } + case op_bitand: { + printBinaryOp(exec, location, it, "bitand"); + ++it; + break; + } + case op_bitxor: { + printBinaryOp(exec, location, it, "bitxor"); + ++it; + break; + } + case op_bitor: { + printBinaryOp(exec, location, it, "bitor"); + ++it; + break; + } + case op_bitnot: { + 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; + int r2 = (++it)->u.operand; + int r3 = (++it)->u.operand; + printf("[%4d] instanceof\t\t %s, %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data()); + break; + } + case op_typeof: { + printUnaryOp(exec, location, it, "typeof"); + break; + } + case op_is_undefined: { + printUnaryOp(exec, location, it, "is_undefined"); + break; + } + case op_is_boolean: { + printUnaryOp(exec, location, it, "is_boolean"); + break; + } + case op_is_number: { + printUnaryOp(exec, location, it, "is_number"); + break; + } + case op_is_string: { + printUnaryOp(exec, location, it, "is_string"); + break; + } + case op_is_object: { + printUnaryOp(exec, location, it, "is_object"); + break; + } + case op_is_function: { + printUnaryOp(exec, location, it, "is_function"); + break; + } + case op_in: { + printBinaryOp(exec, location, it, "in"); + break; + } + case op_resolve: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + printf("[%4d] resolve\t\t %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data()); + break; + } + case op_resolve_skip: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + int skipLevels = (++it)->u.operand; + printf("[%4d] resolve_skip\t %s, %s, %d\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), skipLevels); + break; + } + case op_resolve_global: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + 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; + int id0 = (++it)->u.operand; + JSValue scope = JSValue((++it)->u.jsCell); + ++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: { + int r0 = (++it)->u.operand; + int index = (++it)->u.operand; + int skipLevels = (++it)->u.operand; + printf("[%4d] get_scoped_var\t %s, %d, %d\n", location, registerName(exec, r0).data(), index, skipLevels); + break; + } + case op_put_scoped_var: { + int index = (++it)->u.operand; + int skipLevels = (++it)->u.operand; + int r0 = (++it)->u.operand; + printf("[%4d] put_scoped_var\t %d, %d, %s\n", location, index, skipLevels, registerName(exec, r0).data()); + break; + } + case op_get_global_var: { + int r0 = (++it)->u.operand; + int index = (++it)->u.operand; + printf("[%4d] get_global_var\t %s, %d\n", location, registerName(exec, r0).data(), index); + break; + } + case op_put_global_var: { + int index = (++it)->u.operand; + int r0 = (++it)->u.operand; + 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; + 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: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int id0 = (++it)->u.operand; + printf("[%4d] resolve_with_base %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data()); + break; + } + case op_get_by_id: { + printGetByIdOp(exec, location, it, "get_by_id"); + break; + } + case op_get_by_id_self: { + printGetByIdOp(exec, location, it, "get_by_id_self"); + break; + } + case op_get_by_id_self_list: { + printGetByIdOp(exec, location, it, "get_by_id_self_list"); + break; + } + case op_get_by_id_proto: { + printGetByIdOp(exec, location, it, "get_by_id_proto"); + break; + } + case op_get_by_id_proto_list: { + printGetByIdOp(exec, location, it, "op_get_by_id_proto_list"); + break; + } + case op_get_by_id_chain: { + printGetByIdOp(exec, location, it, "get_by_id_chain"); + break; + } + case op_get_by_id_getter_self: { + printGetByIdOp(exec, location, it, "get_by_id_getter_self"); + break; + } + case op_get_by_id_getter_self_list: { + printGetByIdOp(exec, location, it, "get_by_id_getter_self_list"); + break; + } + case op_get_by_id_getter_proto: { + printGetByIdOp(exec, location, it, "get_by_id_getter_proto"); + break; + } + case op_get_by_id_getter_proto_list: { + printGetByIdOp(exec, location, it, "get_by_id_getter_proto_list"); + break; + } + case op_get_by_id_getter_chain: { + printGetByIdOp(exec, location, it, "get_by_id_getter_chain"); + break; + } + case op_get_by_id_custom_self: { + printGetByIdOp(exec, location, it, "get_by_id_custom_self"); + break; + } + case op_get_by_id_custom_self_list: { + printGetByIdOp(exec, location, it, "get_by_id_custom_self_list"); + break; + } + case op_get_by_id_custom_proto: { + printGetByIdOp(exec, location, it, "get_by_id_custom_proto"); + break; + } + case op_get_by_id_custom_proto_list: { + printGetByIdOp(exec, location, it, "get_by_id_custom_proto_list"); + break; + } + case op_get_by_id_custom_chain: { + printGetByIdOp(exec, location, it, "get_by_id_custom_chain"); + break; + } + case op_get_by_id_generic: { + printGetByIdOp(exec, location, it, "get_by_id_generic"); + break; + } + case op_get_array_length: { + printGetByIdOp(exec, location, it, "get_array_length"); + break; + } + case op_get_string_length: { + 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; + } + case op_put_by_id_replace: { + printPutByIdOp(exec, location, it, "put_by_id_replace"); + break; + } + case op_put_by_id_transition: { + printPutByIdOp(exec, location, it, "put_by_id_transition"); + break; + } + case op_put_by_id_generic: { + printPutByIdOp(exec, location, it, "put_by_id_generic"); + break; + } + case op_put_getter: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] put_getter\t %s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data()); + break; + } + case op_put_setter: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] put_setter\t %s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data()); + break; + } + case op_method_check: { + printf("[%4d] method_check\n", location); + break; + } + case op_del_by_id: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int id0 = (++it)->u.operand; + printf("[%4d] del_by_id\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data()); + break; + } + case op_get_by_val: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int r2 = (++it)->u.operand; + 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; + int r2 = (++it)->u.operand; + int r3 = (++it)->u.operand; + int r4 = (++it)->u.operand; + int r5 = (++it)->u.operand; + printf("[%4d] get_by_pname\t %s, %s, %s, %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data(), registerName(exec, r4).data(), registerName(exec, r5).data()); + break; + } + case op_put_by_val: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int r2 = (++it)->u.operand; + printf("[%4d] put_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data()); + break; + } + case op_del_by_val: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int r2 = (++it)->u.operand; + printf("[%4d] del_by_val\t %s, %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data()); + break; + } + case op_put_by_index: { + int r0 = (++it)->u.operand; + unsigned n0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] put_by_index\t %s, %u, %s\n", location, registerName(exec, r0).data(), n0, registerName(exec, r1).data()); + break; + } + case op_jmp: { + int offset = (++it)->u.operand; + printf("[%4d] jmp\t\t %d(->%d)\n", location, offset, location + offset); + break; + } + case op_loop: { + int offset = (++it)->u.operand; + printf("[%4d] loop\t\t %d(->%d)\n", location, offset, location + offset); + break; + } + case op_jtrue: { + printConditionalJump(exec, begin, it, location, "jtrue"); + break; + } + case op_loop_if_true: { + printConditionalJump(exec, begin, it, location, "loop_if_true"); + break; + } + case op_loop_if_false: { + printConditionalJump(exec, begin, it, location, "loop_if_false"); + break; + } + case op_jfalse: { + printConditionalJump(exec, begin, it, location, "jfalse"); + break; + } + case op_jeq_null: { + printConditionalJump(exec, begin, it, location, "jeq_null"); + break; + } + case op_jneq_null: { + printConditionalJump(exec, begin, it, location, "jneq_null"); + break; + } + case op_jneq_ptr: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jneq_ptr\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_jnless: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jnless\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_jnlesseq: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jnlesseq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_loop_if_less: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] loop_if_less\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_jless: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jless\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_jlesseq: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jlesseq\t\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_loop_if_lesseq: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] loop_if_lesseq\t %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset); + break; + } + case op_switch_imm: { + int tableIndex = (++it)->u.operand; + int defaultTarget = (++it)->u.operand; + int scrutineeRegister = (++it)->u.operand; + printf("[%4d] switch_imm\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data()); + break; + } + case op_switch_char: { + int tableIndex = (++it)->u.operand; + int defaultTarget = (++it)->u.operand; + int scrutineeRegister = (++it)->u.operand; + printf("[%4d] switch_char\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data()); + break; + } + case op_switch_string: { + int tableIndex = (++it)->u.operand; + int defaultTarget = (++it)->u.operand; + int scrutineeRegister = (++it)->u.operand; + printf("[%4d] switch_string\t %d, %d(->%d), %s\n", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data()); + break; + } + case op_new_func: { + int r0 = (++it)->u.operand; + int f0 = (++it)->u.operand; + int shouldCheck = (++it)->u.operand; + printf("[%4d] new_func\t\t %s, f%d, %s\n", location, registerName(exec, r0).data(), f0, shouldCheck ? "<Checked>" : "<Unchecked>"); + break; + } + case op_new_func_exp: { + int r0 = (++it)->u.operand; + int f0 = (++it)->u.operand; + printf("[%4d] new_func_exp\t %s, f%d\n", location, registerName(exec, r0).data(), f0); + break; + } + case op_call: { + int func = (++it)->u.operand; + int argCount = (++it)->u.operand; + int registerOffset = (++it)->u.operand; + printf("[%4d] call\t\t %s, %d, %d\n", location, registerName(exec, func).data(), argCount, registerOffset); + break; + } + case op_call_eval: { + int func = (++it)->u.operand; + int argCount = (++it)->u.operand; + int registerOffset = (++it)->u.operand; + printf("[%4d] call_eval\t %s, %d, %d\n", location, registerName(exec, func).data(), argCount, registerOffset); + break; + } + case op_call_varargs: { + int func = (++it)->u.operand; + int argCount = (++it)->u.operand; + int registerOffset = (++it)->u.operand; + printf("[%4d] call_varargs\t %s, %s, %d\n", location, registerName(exec, func).data(), registerName(exec, argCount).data(), registerOffset); + break; + } + case op_load_varargs: { + printUnaryOp(exec, location, it, "load_varargs"); + break; + } + case op_tear_off_activation: { + int r0 = (++it)->u.operand; + 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: { + int r0 = (++it)->u.operand; + printf("[%4d] tear_off_arguments\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_ret: { + int r0 = (++it)->u.operand; + printf("[%4d] ret\t\t %s\n", location, registerName(exec, r0).data()); + break; + } + 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_ret_object_or_this: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + 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: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + int count = (++it)->u.operand; + printf("[%4d] strcat\t\t %s, %s, %d\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), count); + break; + } + case op_to_primitive: { + int r0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] to_primitive\t %s, %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data()); + break; + } + case op_get_pnames: { + int r0 = it[1].u.operand; + int r1 = it[2].u.operand; + int r2 = it[3].u.operand; + int r3 = it[4].u.operand; + int offset = it[5].u.operand; + printf("[%4d] get_pnames\t %s, %s, %s, %s, %d(->%d)\n", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data(), offset, location + offset); + it += OPCODE_LENGTH(op_get_pnames) - 1; + break; + } + case op_next_pname: { + int dest = it[1].u.operand; + 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; + } + case op_push_scope: { + int r0 = (++it)->u.operand; + printf("[%4d] push_scope\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_pop_scope: { + printf("[%4d] pop_scope\n", location); + break; + } + case op_push_new_scope: { + int r0 = (++it)->u.operand; + int id0 = (++it)->u.operand; + int r1 = (++it)->u.operand; + printf("[%4d] push_new_scope \t%s, %s, %s\n", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data()); + break; + } + case op_jmp_scopes: { + int scopeDelta = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jmp_scopes\t^%d, %d(->%d)\n", location, scopeDelta, offset, location + offset); + break; + } + case op_catch: { + int r0 = (++it)->u.operand; + printf("[%4d] catch\t\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_throw: { + int r0 = (++it)->u.operand; + printf("[%4d] throw\t\t %s\n", location, registerName(exec, r0).data()); + break; + } + case op_throw_reference_error: { + int k0 = (++it)->u.operand; + printf("[%4d] throw_reference_error\t %s\n", location, constantName(exec, k0, getConstant(k0)).data()); + break; + } + case op_throw_syntax_error: { + int k0 = (++it)->u.operand; + printf("[%4d] throw_syntax_error\t %s\n", location, constantName(exec, k0, getConstant(k0)).data()); + break; + } + case op_jsr: { + int retAddrDst = (++it)->u.operand; + int offset = (++it)->u.operand; + printf("[%4d] jsr\t\t %s, %d(->%d)\n", location, registerName(exec, retAddrDst).data(), offset, location + offset); + break; + } + case op_sret: { + int retAddrSrc = (++it)->u.operand; + printf("[%4d] sret\t\t %s\n", location, registerName(exec, retAddrSrc).data()); + break; + } + case op_debug: { + int debugHookID = (++it)->u.operand; + int firstLine = (++it)->u.operand; + int lastLine = (++it)->u.operand; + printf("[%4d] debug\t\t %s, %d, %d\n", location, debugHookName(debugHookID), firstLine, lastLine); + break; + } + case op_profile_will_call: { + int function = (++it)->u.operand; + printf("[%4d] profile_will_call %s\n", location, registerName(exec, function).data()); + break; + } + case op_profile_did_call: { + int function = (++it)->u.operand; + printf("[%4d] profile_did_call\t %s\n", location, registerName(exec, function).data()); + break; + } + case op_end: { + int r0 = (++it)->u.operand; + printf("[%4d] end\t\t %s\n", location, registerName(exec, r0).data()); + break; + } + } +} + +#endif // !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING) + +#if DUMP_CODE_BLOCK_STATISTICS +static HashSet<CodeBlock*> liveCodeBlockSet; +#endif + +#define FOR_EACH_MEMBER_VECTOR(macro) \ + macro(instructions) \ + macro(globalResolveInfos) \ + macro(structureStubInfos) \ + macro(callLinkInfos) \ + macro(linkedCallerList) \ + macro(identifiers) \ + macro(functionExpressions) \ + macro(constantRegisters) + +#define FOR_EACH_MEMBER_VECTOR_RARE_DATA(macro) \ + macro(regexps) \ + macro(functions) \ + macro(exceptionHandlers) \ + macro(immediateSwitchJumpTables) \ + macro(characterSwitchJumpTables) \ + macro(stringSwitchJumpTables) \ + macro(evalCodeCache) \ + macro(expressionInfo) \ + macro(lineInfo) \ + macro(callReturnIndexVector) + +template<typename T> +static size_t sizeInBytes(const Vector<T>& vector) +{ + return vector.capacity() * sizeof(T); +} + +void CodeBlock::dumpStatistics() +{ +#if DUMP_CODE_BLOCK_STATISTICS + #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) + #undef DEFINE_VARS + + // Non-vector data members + size_t evalCodeCacheIsNotEmpty = 0; + + size_t symbolTableIsNotEmpty = 0; + size_t symbolTableTotalSize = 0; + + size_t hasRareData = 0; + + size_t isFunctionCode = 0; + size_t isGlobalCode = 0; + size_t isEvalCode = 0; + + HashSet<CodeBlock*>::const_iterator end = liveCodeBlockSet.end(); + for (HashSet<CodeBlock*>::const_iterator it = liveCodeBlockSet.begin(); it != end; ++it) { + CodeBlock* codeBlock = *it; + + #define GET_STATS(name) if (!codeBlock->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_##name); } + FOR_EACH_MEMBER_VECTOR(GET_STATS) + #undef GET_STATS + + if (!codeBlock->m_symbolTable.isEmpty()) { + symbolTableIsNotEmpty++; + symbolTableTotalSize += (codeBlock->m_symbolTable.capacity() * (sizeof(SymbolTable::KeyType) + sizeof(SymbolTable::MappedType))); + } + + 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); } + FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_STATS) + #undef GET_STATS + + if (!codeBlock->m_rareData->m_evalCodeCache.isEmpty()) + evalCodeCacheIsNotEmpty++; + } + + switch (codeBlock->codeType()) { + case FunctionCode: + ++isFunctionCode; + break; + case GlobalCode: + ++isGlobalCode; + break; + case EvalCode: + ++isEvalCode; + break; + } + } + + size_t totalSize = 0; + + #define GET_TOTAL_SIZE(name) totalSize += name##TotalSize; + FOR_EACH_MEMBER_VECTOR(GET_TOTAL_SIZE) + FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_TOTAL_SIZE) + #undef GET_TOTAL_SIZE + + totalSize += symbolTableTotalSize; + totalSize += (liveCodeBlockSet.size() * sizeof(CodeBlock)); + + printf("Number of live CodeBlocks: %d\n", liveCodeBlockSet.size()); + printf("Size of a single CodeBlock [sizeof(CodeBlock)]: %zu\n", sizeof(CodeBlock)); + printf("Size of all CodeBlocks: %zu\n", totalSize); + printf("Average size of a CodeBlock: %zu\n", totalSize / liveCodeBlockSet.size()); + + printf("Number of FunctionCode CodeBlocks: %zu (%.3f%%)\n", isFunctionCode, static_cast<double>(isFunctionCode) * 100.0 / liveCodeBlockSet.size()); + printf("Number of GlobalCode CodeBlocks: %zu (%.3f%%)\n", isGlobalCode, static_cast<double>(isGlobalCode) * 100.0 / liveCodeBlockSet.size()); + printf("Number of EvalCode CodeBlocks: %zu (%.3f%%)\n", isEvalCode, static_cast<double>(isEvalCode) * 100.0 / liveCodeBlockSet.size()); + + printf("Number of CodeBlocks with rare data: %zu (%.3f%%)\n", hasRareData, static_cast<double>(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) + #undef PRINT_STATS + + printf("Number of CodeBlocks with evalCodeCache: %zu\n", evalCodeCacheIsNotEmpty); + printf("Number of CodeBlocks with symbolTable: %zu\n", symbolTableIsNotEmpty); + + printf("Size of all symbolTables: %zu\n", symbolTableTotalSize); + +#else + printf("Dumping CodeBlock statistics is not enabled.\n"); +#endif +} + +CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject *globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, SymbolTable* symTab, bool isConstructor) + : m_globalObject(globalObject) + , m_numCalleeRegisters(0) + , m_numVars(0) + , m_numParameters(0) + , m_isConstructor(isConstructor) + , m_ownerExecutable(ownerExecutable) + , m_globalData(0) +#ifndef NDEBUG + , m_instructionCount(0) +#endif + , m_argumentsRegister(-1) + , m_needsFullScopeChain(ownerExecutable->needsActivation()) + , m_usesEval(ownerExecutable->usesEval()) + , m_isNumericCompareFunction(false) + , m_isStrictMode(ownerExecutable->isStrictMode()) + , m_codeType(codeType) + , m_source(sourceProvider) + , m_sourceOffset(sourceOffset) + , m_symbolTable(symTab) +{ + ASSERT(m_source); + +#if DUMP_CODE_BLOCK_STATISTICS + liveCodeBlockSet.add(this); +#endif +} + +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 + liveCodeBlockSet.remove(this); +#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::unlinkCallOrConstruct(currentCaller); + currentCaller->setUnlinked(); + } + m_linkedCallerList.clear(); +} +#endif + +void CodeBlock::derefStructures(Instruction* vPC) const +{ + 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->deref(); + 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(); + 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(); + 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(); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) { + vPC[4].u.structure->deref(); + return; + } + if (vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global) || vPC[0].u.opcode == interpreter->getOpcode(op_resolve_global_dynamic)) { + if (vPC[3].u.structure) + vPC[3].u.structure->deref(); + return; + } + if ((vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto_list)) + || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self_list)) + || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_proto_list)) + || (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_self_list)) + || (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); + delete polymorphicStructures; + 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) || 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 +{ + 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)); +} + +void CodeBlock::markAggregate(MarkStack& markStack) +{ + for (size_t i = 0; i < m_constantRegisters.size(); ++i) + markStack.append(m_constantRegisters[i].jsValue()); + for (size_t i = 0; i < m_functionExprs.size(); ++i) + m_functionExprs[i]->markAggregate(markStack); + for (size_t i = 0; i < m_functionDecls.size(); ++i) + m_functionDecls[i]->markAggregate(markStack); + markStack.append(m_globalObject); +} + +HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset) +{ + ASSERT(bytecodeOffset < m_instructionCount); + + if (!m_rareData) + return 0; + + Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers; + for (size_t i = 0; i < exceptionHandlers.size(); ++i) { + // Handlers are ordered innermost first, so the first handler we encounter + // that contains the source address is the correct handler to use. + if (exceptionHandlers[i].start <= bytecodeOffset && exceptionHandlers[i].end >= bytecodeOffset) + return &exceptionHandlers[i]; + } + + return 0; +} + +int CodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset) +{ + ASSERT(bytecodeOffset < m_instructionCount); + + if (!m_rareData) + return m_ownerExecutable->source().firstLine(); + + Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo; + + int low = 0; + int high = lineInfo.size(); + while (low < high) { + int mid = low + (high - low) / 2; + if (lineInfo[mid].instructionOffset <= bytecodeOffset) + low = mid + 1; + else + high = mid; + } + + if (!low) + return m_ownerExecutable->source().firstLine(); + return lineInfo[low - 1].lineNumber; +} + +void CodeBlock::expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset) +{ + ASSERT(bytecodeOffset < m_instructionCount); + + if (!m_rareData) { + startOffset = 0; + endOffset = 0; + divot = 0; + return; + } + + Vector<ExpressionRangeInfo>& expressionInfo = m_rareData->m_expressionInfo; + + int low = 0; + int high = expressionInfo.size(); + while (low < high) { + int mid = low + (high - low) / 2; + if (expressionInfo[mid].instructionOffset <= bytecodeOffset) + low = mid + 1; + else + high = mid; + } + + ASSERT(low); + if (!low) { + startOffset = 0; + endOffset = 0; + divot = 0; + return; + } + + startOffset = expressionInfo[low - 1].startOffset; + endOffset = expressionInfo[low - 1].endOffset; + divot = expressionInfo[low - 1].divotPoint + m_sourceOffset; + return; +} + +#if ENABLE(INTERPRETER) +bool CodeBlock::hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset) +{ + if (m_globalResolveInstructions.isEmpty()) + return false; + + int low = 0; + int high = m_globalResolveInstructions.size(); + while (low < high) { + int mid = low + (high - low) / 2; + if (m_globalResolveInstructions[mid] <= bytecodeOffset) + low = mid + 1; + else + high = mid; + } + + if (!low || m_globalResolveInstructions[low - 1] != bytecodeOffset) + return false; + return true; +} +#endif +#if ENABLE(JIT) +bool CodeBlock::hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset) +{ + if (m_globalResolveInfos.isEmpty()) + return false; + + int low = 0; + int high = m_globalResolveInfos.size(); + while (low < high) { + int mid = low + (high - low) / 2; + if (m_globalResolveInfos[mid].bytecodeOffset <= bytecodeOffset) + low = mid + 1; + else + high = mid; + } + + if (!low || m_globalResolveInfos[low - 1].bytecodeOffset != bytecodeOffset) + return false; + return true; +} +#endif + +void CodeBlock::shrinkToFit() +{ + m_instructions.shrinkToFit(); + +#if ENABLE(INTERPRETER) + m_propertyAccessInstructions.shrinkToFit(); + m_globalResolveInstructions.shrinkToFit(); +#endif +#if ENABLE(JIT) + m_structureStubInfos.shrinkToFit(); + m_globalResolveInfos.shrinkToFit(); + m_callLinkInfos.shrinkToFit(); + m_linkedCallerList.shrinkToFit(); +#endif + + m_identifiers.shrinkToFit(); + m_functionDecls.shrinkToFit(); + m_functionExprs.shrinkToFit(); + m_constantRegisters.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<FunctionExecutable*>(ownerExecutable())); + callFrame->uncheckedR(activationRegister()) = JSValue(activation); + callFrame->setScopeChain(callFrame->scopeChain()->copy()->push(activation)); +} + +} // namespace JSC diff --git a/Source/JavaScriptCore/bytecode/CodeBlock.h b/Source/JavaScriptCore/bytecode/CodeBlock.h new file mode 100644 index 0000000..7eca72a --- /dev/null +++ b/Source/JavaScriptCore/bytecode/CodeBlock.h @@ -0,0 +1,691 @@ +/* + * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CodeBlock_h +#define CodeBlock_h + +#include "EvalCodeCache.h" +#include "Instruction.h" +#include "JITCode.h" +#include "JSGlobalObject.h" +#include "JumpTable.h" +#include "Nodes.h" +#include "RegExp.h" +#include "UString.h" +#include <wtf/FastAllocBase.h> +#include <wtf/PassOwnPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/Vector.h> + +#if ENABLE(JIT) +#include "StructureStubInfo.h" +#endif + +// Register numbers used in bytecode operations have different meaning according to their ranges: +// 0x80000000-0xFFFFFFFF Negative indices from the CallFrame pointer are entries in the call frame, see RegisterFile.h. +// 0x00000000-0x3FFFFFFF Forwards indices from the CallFrame pointer are local vars and temporaries with the function's callframe. +// 0x40000000-0x7FFFFFFF Positive indices from 0x40000000 specify entries in the constant pool on the CodeBlock. +static const int FirstConstantRegisterIndex = 0x40000000; + +namespace JSC { + + enum HasSeenShouldRepatch { + hasSeenShouldRepatch + }; + + class ExecState; + + enum CodeType { GlobalCode, EvalCode, FunctionCode }; + + inline int unmodifiedArgumentsRegister(int argumentsRegister) { return argumentsRegister - 1; } + + static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); } + + struct HandlerInfo { + uint32_t start; + uint32_t end; + uint32_t target; + uint32_t scopeDepth; +#if ENABLE(JIT) + CodeLocationLabel nativeCode; +#endif + }; + + struct ExpressionRangeInfo { + enum { + MaxOffset = (1 << 7) - 1, + MaxDivot = (1 << 25) - 1 + }; + uint32_t instructionOffset : 25; + uint32_t divotPoint : 25; + uint32_t startOffset : 7; + uint32_t endOffset : 7; + }; + + struct LineInfo { + uint32_t instructionOffset; + int32_t lineNumber; + }; + +#if ENABLE(JIT) + struct CallLinkInfo { + CallLinkInfo() + : callee(0) + , position(0) + , hasSeenShouldRepatch(0) + { + } + + CodeLocationNearCall callReturnLocation; + CodeLocationDataLabelPtr hotPathBegin; + CodeLocationNearCall hotPathOther; + CodeBlock* ownerCodeBlock; + CodeBlock* callee; + unsigned position : 31; + unsigned hasSeenShouldRepatch : 1; + + void setUnlinked() { callee = 0; } + bool isLinked() { return callee; } + + bool seenOnce() + { + return hasSeenShouldRepatch; + } + + void setSeen() + { + hasSeenShouldRepatch = true; + } + }; + + struct MethodCallLinkInfo { + MethodCallLinkInfo() + : cachedStructure(0) + , cachedPrototypeStructure(0) + { + } + + bool seenOnce() + { + ASSERT(!cachedStructure); + return cachedPrototypeStructure; + } + + void setSeen() + { + ASSERT(!cachedStructure && !cachedPrototypeStructure); + // We use the values of cachedStructure & cachedPrototypeStructure to indicate the + // current state. + // - In the initial state, both are null. + // - Once this transition has been taken once, cachedStructure is + // null and cachedPrototypeStructure is set to a nun-null value. + // - Once the call is linked both structures are set to non-null values. + cachedPrototypeStructure = (Structure*)1; + } + + CodeLocationCall callReturnLocation; + CodeLocationDataLabelPtr structureLabel; + Structure* cachedStructure; + Structure* cachedPrototypeStructure; + }; + + struct GlobalResolveInfo { + GlobalResolveInfo(unsigned bytecodeOffset) + : structure(0) + , offset(0) + , bytecodeOffset(bytecodeOffset) + { + } + + Structure* structure; + unsigned offset; + unsigned bytecodeOffset; + }; + + // This structure is used to map from a call return location + // (given as an offset in bytes into the JIT code) back to + // the bytecode index of the corresponding bytecode operation. + // This is then used to look up the corresponding handler. + struct CallReturnOffsetToBytecodeOffset { + CallReturnOffsetToBytecodeOffset(unsigned callReturnOffset, unsigned bytecodeOffset) + : callReturnOffset(callReturnOffset) + , bytecodeOffset(bytecodeOffset) + { + } + + unsigned callReturnOffset; + unsigned bytecodeOffset; + }; + + // valueAtPosition helpers for the binaryChop algorithm below. + + inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo) + { + return structureStubInfo->callReturnLocation.executableAddress(); + } + + inline void* getCallLinkInfoReturnLocation(CallLinkInfo* callLinkInfo) + { + return callLinkInfo->callReturnLocation.executableAddress(); + } + + inline void* getMethodCallLinkInfoReturnLocation(MethodCallLinkInfo* methodCallLinkInfo) + { + return methodCallLinkInfo->callReturnLocation.executableAddress(); + } + + inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeOffset* pc) + { + return pc->callReturnOffset; + } + + // Binary chop algorithm, calls valueAtPosition on pre-sorted elements in array, + // compares result with key (KeyTypes should be comparable with '--', '<', '>'). + // Optimized for cases where the array contains the key, checked by assertions. + template<typename ArrayType, typename KeyType, KeyType(*valueAtPosition)(ArrayType*)> + inline ArrayType* binaryChop(ArrayType* array, size_t size, KeyType key) + { + // The array must contain at least one element (pre-condition, array does conatin key). + // If the array only contains one element, no need to do the comparison. + while (size > 1) { + // Pick an element to check, half way through the array, and read the value. + int pos = (size - 1) >> 1; + KeyType val = valueAtPosition(&array[pos]); + + // If the key matches, success! + if (val == key) + return &array[pos]; + // The item we are looking for is smaller than the item being check; reduce the value of 'size', + // chopping off the right hand half of the array. + else if (key < val) + size = pos; + // Discard all values in the left hand half of the array, up to and including the item at pos. + else { + size -= (pos + 1); + array += (pos + 1); + } + + // 'size' should never reach zero. + ASSERT(size); + } + + // If we reach this point we've chopped down to one element, no need to check it matches + ASSERT(size == 1); + ASSERT(key == valueAtPosition(&array[0])); + return &array[0]; + } +#endif + + class CodeBlock : public FastAllocBase { + friend class JIT; + protected: + CodeBlock(ScriptExecutable* ownerExecutable, CodeType, JSGlobalObject*, PassRefPtr<SourceProvider>, unsigned sourceOffset, SymbolTable* symbolTable, bool isConstructor); + + JSGlobalObject* m_globalObject; + + public: + virtual ~CodeBlock(); + + void markAggregate(MarkStack&); + void refStructures(Instruction* vPC) const; + void derefStructures(Instruction* vPC) const; +#if ENABLE(JIT_OPTIMIZE_CALL) + void unlinkCallers(); +#endif + + static void dumpStatistics(); + +#if !defined(NDEBUG) || ENABLE_OPCODE_SAMPLING + void dump(ExecState*) const; + void printStructures(const Instruction*) const; + void printStructure(const char* name, const Instruction*, int operand) const; +#endif + + bool isStrictMode() const { return m_isStrictMode; } + + inline bool isKnownNotImmediate(int index) + { + if (index == m_thisRegister && !m_isStrictMode) + return true; + + if (isConstantRegisterIndex(index)) + return getConstant(index).isCell(); + + return false; + } + + ALWAYS_INLINE bool isTemporaryRegisterIndex(int index) + { + return index >= m_numVars; + } + + HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset); + int lineNumberForBytecodeOffset(unsigned bytecodeOffset); + void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset); + +#if ENABLE(JIT) + void addCaller(CallLinkInfo* caller) + { + caller->callee = this; + caller->position = m_linkedCallerList.size(); + m_linkedCallerList.append(caller); + } + + void removeCaller(CallLinkInfo* caller) + { + unsigned pos = caller->position; + unsigned lastPos = m_linkedCallerList.size() - 1; + + if (pos != lastPos) { + m_linkedCallerList[pos] = m_linkedCallerList[lastPos]; + m_linkedCallerList[pos]->position = pos; + } + m_linkedCallerList.shrink(lastPos); + } + + StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress) + { + return *(binaryChop<StructureStubInfo, void*, getStructureStubInfoReturnLocation>(m_structureStubInfos.begin(), m_structureStubInfos.size(), returnAddress.value())); + } + + CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress) + { + return *(binaryChop<CallLinkInfo, void*, getCallLinkInfoReturnLocation>(m_callLinkInfos.begin(), m_callLinkInfos.size(), returnAddress.value())); + } + + MethodCallLinkInfo& getMethodCallLinkInfo(ReturnAddressPtr returnAddress) + { + return *(binaryChop<MethodCallLinkInfo, void*, getMethodCallLinkInfoReturnLocation>(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value())); + } + + unsigned bytecodeOffset(ReturnAddressPtr returnAddress) + { + if (!m_rareData) + return 1; + Vector<CallReturnOffsetToBytecodeOffset>& callIndices = m_rareData->m_callReturnIndexVector; + if (!callIndices.size()) + return 1; + return binaryChop<CallReturnOffsetToBytecodeOffset, unsigned, getCallReturnOffset>(callIndices.begin(), callIndices.size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset; + } +#endif +#if ENABLE(INTERPRETER) + unsigned bytecodeOffset(Instruction* returnAddress) + { + return static_cast<Instruction*>(returnAddress) - instructions().begin(); + } +#endif + + void setIsNumericCompareFunction(bool isNumericCompareFunction) { m_isNumericCompareFunction = isNumericCompareFunction; } + bool isNumericCompareFunction() { return m_isNumericCompareFunction; } + + Vector<Instruction>& instructions() { return m_instructions; } + void discardBytecode() { m_instructions.clear(); } + +#ifndef NDEBUG + unsigned instructionCount() { return m_instructionCount; } + void setInstructionCount(unsigned instructionCount) { m_instructionCount = instructionCount; } +#endif + +#if ENABLE(JIT) + JITCode& getJITCode() { return m_isConstructor ? ownerExecutable()->generatedJITCodeForConstruct() : ownerExecutable()->generatedJITCodeForCall(); } + ExecutablePool* executablePool() { return getJITCode().getExecutablePool(); } +#endif + + ScriptExecutable* ownerExecutable() const { return m_ownerExecutable; } + + void setGlobalData(JSGlobalData* globalData) { m_globalData = globalData; } + + void setThisRegister(int thisRegister) { m_thisRegister = thisRegister; } + int thisRegister() const { return m_thisRegister; } + + void setNeedsFullScopeChain(bool needsFullScopeChain) { m_needsFullScopeChain = needsFullScopeChain; } + bool needsFullScopeChain() const { return m_needsFullScopeChain; } + void setUsesEval(bool usesEval) { m_usesEval = usesEval; } + bool usesEval() const { return m_usesEval; } + + void setArgumentsRegister(int argumentsRegister) + { + ASSERT(argumentsRegister != -1); + m_argumentsRegister = argumentsRegister; + ASSERT(usesArguments()); + } + int argumentsRegister() + { + ASSERT(usesArguments()); + return m_argumentsRegister; + } + void setActivationRegister(int activationRegister) + { + m_activationRegister = activationRegister; + } + int activationRegister() + { + ASSERT(needsFullScopeChain()); + return m_activationRegister; + } + bool usesArguments() const { return m_argumentsRegister != -1; } + + CodeType codeType() const { return m_codeType; } + + SourceProvider* source() const { return m_source.get(); } + unsigned sourceOffset() const { return m_sourceOffset; } + + size_t numberOfJumpTargets() const { return m_jumpTargets.size(); } + void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); } + unsigned jumpTarget(int index) const { return m_jumpTargets[index]; } + unsigned lastJumpTarget() const { return m_jumpTargets.last(); } + + void createActivation(CallFrame*); + +#if ENABLE(INTERPRETER) + void addPropertyAccessInstruction(unsigned propertyAccessInstruction) { m_propertyAccessInstructions.append(propertyAccessInstruction); } + void addGlobalResolveInstruction(unsigned globalResolveInstruction) { m_globalResolveInstructions.append(globalResolveInstruction); } + bool hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset); +#endif +#if ENABLE(JIT) + size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); } + void addStructureStubInfo(const StructureStubInfo& stubInfo) { m_structureStubInfos.append(stubInfo); } + StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; } + + void addGlobalResolveInfo(unsigned globalResolveInstruction) { m_globalResolveInfos.append(GlobalResolveInfo(globalResolveInstruction)); } + GlobalResolveInfo& globalResolveInfo(int index) { return m_globalResolveInfos[index]; } + bool hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset); + + size_t numberOfCallLinkInfos() const { return m_callLinkInfos.size(); } + void addCallLinkInfo() { m_callLinkInfos.append(CallLinkInfo()); } + CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; } + + void addMethodCallLinkInfos(unsigned n) { m_methodCallLinkInfos.grow(n); } + MethodCallLinkInfo& methodCallLinkInfo(int index) { return m_methodCallLinkInfos[index]; } +#endif + + // Exception handling support + + size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; } + void addExceptionHandler(const HandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); } + HandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; } + + void addExpressionInfo(const ExpressionRangeInfo& expressionInfo) + { + createRareDataIfNecessary(); + m_rareData->m_expressionInfo.append(expressionInfo); + } + + void addLineInfo(unsigned bytecodeOffset, int lineNo) + { + createRareDataIfNecessary(); + Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo; + if (!lineInfo.size() || lineInfo.last().lineNumber != lineNo) { + LineInfo info = { bytecodeOffset, lineNo }; + lineInfo.append(info); + } + } + + bool hasExpressionInfo() { return m_rareData && m_rareData->m_expressionInfo.size(); } + bool hasLineInfo() { return m_rareData && m_rareData->m_lineInfo.size(); } + bool needsCallReturnIndices() + { + return m_rareData && + (m_rareData->m_expressionInfo.size() || m_rareData->m_lineInfo.size() || m_rareData->m_exceptionHandlers.size()); + } + +#if ENABLE(JIT) + Vector<CallReturnOffsetToBytecodeOffset>& callReturnIndexVector() + { + createRareDataIfNecessary(); + return m_rareData->m_callReturnIndexVector; + } +#endif + + // Constant Pool + + size_t numberOfIdentifiers() const { return m_identifiers.size(); } + void addIdentifier(const Identifier& i) { return m_identifiers.append(i); } + Identifier& identifier(int index) { return m_identifiers[index]; } + + size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); } + void addConstantRegister(const Register& r) { return m_constantRegisters.append(r); } + Register& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; } + ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; } + ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].jsValue(); } + + unsigned addFunctionDecl(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionDecls.size(); m_functionDecls.append(n); return size; } + FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); } + int numberOfFunctionDecls() { return m_functionDecls.size(); } + unsigned addFunctionExpr(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionExprs.size(); m_functionExprs.append(n); return size; } + FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); } + + unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; } + RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); } + + JSGlobalObject* globalObject() { return m_globalObject; } + + // Jump Tables + + size_t numberOfImmediateSwitchJumpTables() const { return m_rareData ? m_rareData->m_immediateSwitchJumpTables.size() : 0; } + SimpleJumpTable& addImmediateSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_immediateSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_immediateSwitchJumpTables.last(); } + SimpleJumpTable& immediateSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_immediateSwitchJumpTables[tableIndex]; } + + size_t numberOfCharacterSwitchJumpTables() const { return m_rareData ? m_rareData->m_characterSwitchJumpTables.size() : 0; } + SimpleJumpTable& addCharacterSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_characterSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_characterSwitchJumpTables.last(); } + SimpleJumpTable& characterSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_characterSwitchJumpTables[tableIndex]; } + + size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; } + StringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(StringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); } + StringJumpTable& stringSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; } + + + SymbolTable* symbolTable() { return m_symbolTable; } + SharedSymbolTable* sharedSymbolTable() { ASSERT(m_codeType == FunctionCode); return static_cast<SharedSymbolTable*>(m_symbolTable); } + + EvalCodeCache& evalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_evalCodeCache; } + + void shrinkToFit(); + + // FIXME: Make these remaining members private. + + int m_numCalleeRegisters; + int m_numVars; + int m_numCapturedVars; + int m_numParameters; + bool m_isConstructor; + + private: +#if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING) + void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const; + + CString registerName(ExecState*, int r) const; + void printUnaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const; + void printBinaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const; + void printConditionalJump(ExecState*, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator&, int location, const char* op) const; + void printGetByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const; + void printPutByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const; +#endif + + void createRareDataIfNecessary() + { + if (!m_rareData) + m_rareData = adoptPtr(new RareData); + } + + ScriptExecutable* m_ownerExecutable; + JSGlobalData* m_globalData; + + Vector<Instruction> m_instructions; +#ifndef NDEBUG + unsigned m_instructionCount; +#endif + + int m_thisRegister; + int m_argumentsRegister; + int m_activationRegister; + + bool m_needsFullScopeChain; + bool m_usesEval; + bool m_isNumericCompareFunction; + bool m_isStrictMode; + + CodeType m_codeType; + + RefPtr<SourceProvider> m_source; + unsigned m_sourceOffset; + +#if ENABLE(INTERPRETER) + Vector<unsigned> m_propertyAccessInstructions; + Vector<unsigned> m_globalResolveInstructions; +#endif +#if ENABLE(JIT) + Vector<StructureStubInfo> m_structureStubInfos; + Vector<GlobalResolveInfo> m_globalResolveInfos; + Vector<CallLinkInfo> m_callLinkInfos; + Vector<MethodCallLinkInfo> m_methodCallLinkInfos; + Vector<CallLinkInfo*> m_linkedCallerList; +#endif + + Vector<unsigned> m_jumpTargets; + + // Constant Pool + Vector<Identifier> m_identifiers; + Vector<Register> m_constantRegisters; + Vector<RefPtr<FunctionExecutable> > m_functionDecls; + Vector<RefPtr<FunctionExecutable> > m_functionExprs; + + SymbolTable* m_symbolTable; + + struct RareData : FastAllocBase { + Vector<HandlerInfo> m_exceptionHandlers; + + // Rare Constants + Vector<RefPtr<RegExp> > m_regexps; + + // Jump Tables + Vector<SimpleJumpTable> m_immediateSwitchJumpTables; + Vector<SimpleJumpTable> m_characterSwitchJumpTables; + Vector<StringJumpTable> m_stringSwitchJumpTables; + + EvalCodeCache m_evalCodeCache; + + // Expression info - present if debugging. + Vector<ExpressionRangeInfo> m_expressionInfo; + // Line info - present if profiling or debugging. + Vector<LineInfo> m_lineInfo; +#if ENABLE(JIT) + Vector<CallReturnOffsetToBytecodeOffset> m_callReturnIndexVector; +#endif + }; + OwnPtr<RareData> m_rareData; + }; + + // Program code is not marked by any function, so we make the global object + // responsible for marking it. + + class GlobalCodeBlock : public CodeBlock { + public: + GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset) + : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, &m_unsharedSymbolTable, false) + { + m_globalObject->codeBlocks().add(this); + } + + ~GlobalCodeBlock() + { + if (m_globalObject) + m_globalObject->codeBlocks().remove(this); + } + + void clearGlobalObject() { m_globalObject = 0; } + + private: + SymbolTable m_unsharedSymbolTable; + }; + + class ProgramCodeBlock : public GlobalCodeBlock { + public: + ProgramCodeBlock(ProgramExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider) + : GlobalCodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, 0) + { + } + }; + + class EvalCodeBlock : public GlobalCodeBlock { + public: + EvalCodeBlock(EvalExecutable* ownerExecutable, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, int baseScopeDepth) + : GlobalCodeBlock(ownerExecutable, EvalCode, globalObject, sourceProvider, 0) + , m_baseScopeDepth(baseScopeDepth) + { + } + + int baseScopeDepth() const { return m_baseScopeDepth; } + + const Identifier& variable(unsigned index) { return m_variables[index]; } + unsigned numVariables() { return m_variables.size(); } + void adoptVariables(Vector<Identifier>& variables) + { + ASSERT(m_variables.isEmpty()); + m_variables.swap(variables); + } + + private: + int m_baseScopeDepth; + Vector<Identifier> m_variables; + }; + + class FunctionCodeBlock : public CodeBlock { + public: + // Rather than using the usual RefCounted::create idiom for SharedSymbolTable we just use new + // as we need to initialise the CodeBlock before we could initialise any RefPtr to hold the shared + // symbol table, so we just pass as a raw pointer with a ref count of 1. We then manually deref + // in the destructor. + FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, bool isConstructor) + : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, SharedSymbolTable::create().leakRef(), isConstructor) + { + } + ~FunctionCodeBlock() + { + sharedSymbolTable()->deref(); + } + }; + + inline Register& ExecState::r(int index) + { + CodeBlock* codeBlock = this->codeBlock(); + if (codeBlock->isConstantRegisterIndex(index)) + return codeBlock->constantRegister(index); + return this[index]; + } + + inline Register& ExecState::uncheckedR(int index) + { + ASSERT(index < FirstConstantRegisterIndex); + return this[index]; + } + +} // namespace JSC + +#endif // CodeBlock_h diff --git a/Source/JavaScriptCore/bytecode/EvalCodeCache.h b/Source/JavaScriptCore/bytecode/EvalCodeCache.h new file mode 100644 index 0000000..edd575f --- /dev/null +++ b/Source/JavaScriptCore/bytecode/EvalCodeCache.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EvalCodeCache_h +#define EvalCodeCache_h + +#include "Executable.h" +#include "JSGlobalObject.h" +#include "Nodes.h" +#include "Parser.h" +#include "SourceCode.h" +#include "UString.h" +#include <wtf/HashMap.h> +#include <wtf/RefPtr.h> +#include <wtf/text/StringHash.h> + +namespace JSC { + + class EvalCodeCache { + public: + PassRefPtr<EvalExecutable> get(ExecState* exec, bool inStrictContext, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue) + { + RefPtr<EvalExecutable> evalExecutable; + + if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject()) + evalExecutable = m_cacheMap.get(evalSource.impl()); + + if (!evalExecutable) { + evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext); + exceptionValue = evalExecutable->compile(exec, scopeChain); + if (exceptionValue) + return 0; + + if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && m_cacheMap.size() < maxCacheEntries) + m_cacheMap.set(evalSource.impl(), evalExecutable); + } + + return evalExecutable.release(); + } + + bool isEmpty() const { return m_cacheMap.isEmpty(); } + + private: + static const unsigned maxCacheableSourceLength = 256; + static const int maxCacheEntries = 64; + + typedef HashMap<RefPtr<StringImpl>, RefPtr<EvalExecutable> > EvalCacheMap; + EvalCacheMap m_cacheMap; + }; + +} // namespace JSC + +#endif // EvalCodeCache_h diff --git a/Source/JavaScriptCore/bytecode/Instruction.h b/Source/JavaScriptCore/bytecode/Instruction.h new file mode 100644 index 0000000..c6468a5 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/Instruction.h @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Instruction_h +#define Instruction_h + +#include "MacroAssembler.h" +#include "Opcode.h" +#include "PropertySlot.h" +#include "Structure.h" +#include <wtf/VectorTraits.h> + +#define POLYMORPHIC_LIST_CACHE_SIZE 8 + +namespace JSC { + + // *Sigh*, If the JIT is enabled we need to track the stubRountine (of type CodeLocationLabel), + // If the JIT is not in use we don't actually need the variable (that said, if the JIT is not in use we don't + // curently actually use PolymorphicAccessStructureLists, which we should). Anyway, this seems like the best + // solution for now - will need to something smarter if/when we actually want mixed-mode operation. +#if ENABLE(JIT) + typedef CodeLocationLabel PolymorphicAccessStructureListStubRoutineType; +#else + typedef void* PolymorphicAccessStructureListStubRoutineType; +#endif + + class JSCell; + class Structure; + class StructureChain; + + // Structure used by op_get_by_id_self_list and op_get_by_id_proto_list instruction to hold data off the main opcode stream. + struct PolymorphicAccessStructureList : FastAllocBase { + struct PolymorphicStubInfo { + bool isChain; + PolymorphicAccessStructureListStubRoutineType stubRoutine; + Structure* base; + union { + Structure* proto; + StructureChain* chain; + } u; + + void set(PolymorphicAccessStructureListStubRoutineType _stubRoutine, Structure* _base) + { + stubRoutine = _stubRoutine; + base = _base; + u.proto = 0; + isChain = false; + } + + void set(PolymorphicAccessStructureListStubRoutineType _stubRoutine, Structure* _base, Structure* _proto) + { + stubRoutine = _stubRoutine; + base = _base; + u.proto = _proto; + isChain = false; + } + + void set(PolymorphicAccessStructureListStubRoutineType _stubRoutine, Structure* _base, StructureChain* _chain) + { + stubRoutine = _stubRoutine; + base = _base; + u.chain = _chain; + isChain = true; + } + } list[POLYMORPHIC_LIST_CACHE_SIZE]; + + PolymorphicAccessStructureList(PolymorphicAccessStructureListStubRoutineType stubRoutine, Structure* firstBase) + { + list[0].set(stubRoutine, firstBase); + } + + PolymorphicAccessStructureList(PolymorphicAccessStructureListStubRoutineType stubRoutine, Structure* firstBase, Structure* firstProto) + { + list[0].set(stubRoutine, firstBase, firstProto); + } + + PolymorphicAccessStructureList(PolymorphicAccessStructureListStubRoutineType stubRoutine, Structure* firstBase, StructureChain* firstChain) + { + list[0].set(stubRoutine, firstBase, firstChain); + } + + void derefStructures(int count) + { + for (int i = 0; i < count; ++i) { + PolymorphicStubInfo& info = list[i]; + + ASSERT(info.base); + info.base->deref(); + + if (info.u.proto) { + if (info.isChain) + info.u.chain->deref(); + else + info.u.proto->deref(); + } + } + } + }; + + struct Instruction { + Instruction(Opcode opcode) + { +#if !ENABLE(COMPUTED_GOTO_INTERPRETER) + // We have to initialize one of the pointer members to ensure that + // the entire struct is initialized, when opcode is not a pointer. + u.jsCell = 0; +#endif + u.opcode = opcode; + } + + Instruction(int operand) + { + // We have to initialize one of the pointer members to ensure that + // the entire struct is initialized in 64-bit. + u.jsCell = 0; + u.operand = operand; + } + + Instruction(Structure* structure) { u.structure = structure; } + Instruction(StructureChain* structureChain) { u.structureChain = structureChain; } + Instruction(JSCell* jsCell) { u.jsCell = jsCell; } + Instruction(PolymorphicAccessStructureList* polymorphicStructures) { u.polymorphicStructures = polymorphicStructures; } + Instruction(PropertySlot::GetValueFunc getterFunc) { u.getterFunc = getterFunc; } + + union { + Opcode opcode; + int operand; + Structure* structure; + StructureChain* structureChain; + JSCell* jsCell; + PolymorphicAccessStructureList* polymorphicStructures; + PropertySlot::GetValueFunc getterFunc; + } u; + }; + +} // namespace JSC + +namespace WTF { + + template<> struct VectorTraits<JSC::Instruction> : VectorTraitsBase<true, JSC::Instruction> { }; + +} // namespace WTF + +#endif // Instruction_h diff --git a/Source/JavaScriptCore/bytecode/JumpTable.cpp b/Source/JavaScriptCore/bytecode/JumpTable.cpp new file mode 100644 index 0000000..ef7098b --- /dev/null +++ b/Source/JavaScriptCore/bytecode/JumpTable.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JumpTable.h" + +#include <wtf/text/StringHash.h> + +namespace JSC { + +int32_t SimpleJumpTable::offsetForValue(int32_t value, int32_t defaultOffset) +{ + if (value >= min && static_cast<uint32_t>(value - min) < branchOffsets.size()) { + int32_t offset = branchOffsets[value - min]; + if (offset) + return offset; + } + return defaultOffset; +} + +} // namespace JSC diff --git a/Source/JavaScriptCore/bytecode/JumpTable.h b/Source/JavaScriptCore/bytecode/JumpTable.h new file mode 100644 index 0000000..5bbe047 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/JumpTable.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JumpTable_h +#define JumpTable_h + +#include "MacroAssembler.h" +#include "UString.h" +#include <wtf/HashMap.h> +#include <wtf/Vector.h> + +namespace JSC { + + struct OffsetLocation { + int32_t branchOffset; +#if ENABLE(JIT) + CodeLocationLabel ctiOffset; +#endif + }; + + struct StringJumpTable { + typedef HashMap<RefPtr<StringImpl>, OffsetLocation> StringOffsetTable; + StringOffsetTable offsetTable; +#if ENABLE(JIT) + CodeLocationLabel ctiDefault; // FIXME: it should not be necessary to store this. +#endif + + inline int32_t offsetForValue(StringImpl* value, int32_t defaultOffset) + { + StringOffsetTable::const_iterator end = offsetTable.end(); + StringOffsetTable::const_iterator loc = offsetTable.find(value); + if (loc == end) + return defaultOffset; + return loc->second.branchOffset; + } + +#if ENABLE(JIT) + inline CodeLocationLabel ctiForValue(StringImpl* value) + { + StringOffsetTable::const_iterator end = offsetTable.end(); + StringOffsetTable::const_iterator loc = offsetTable.find(value); + if (loc == end) + return ctiDefault; + return loc->second.ctiOffset; + } +#endif + }; + + struct SimpleJumpTable { + // FIXME: The two Vectors can be combind into one Vector<OffsetLocation> + Vector<int32_t> branchOffsets; + int32_t min; +#if ENABLE(JIT) + Vector<CodeLocationLabel> ctiOffsets; + CodeLocationLabel ctiDefault; +#endif + + int32_t offsetForValue(int32_t value, int32_t defaultOffset); + void add(int32_t key, int32_t offset) + { + if (!branchOffsets[key]) + branchOffsets[key] = offset; + } + +#if ENABLE(JIT) + inline CodeLocationLabel ctiForValue(int32_t value) + { + if (value >= min && static_cast<uint32_t>(value - min) < ctiOffsets.size()) + return ctiOffsets[value - min]; + return ctiDefault; + } +#endif + }; + +} // namespace JSC + +#endif // JumpTable_h diff --git a/Source/JavaScriptCore/bytecode/Opcode.cpp b/Source/JavaScriptCore/bytecode/Opcode.cpp new file mode 100644 index 0000000..0bb714b --- /dev/null +++ b/Source/JavaScriptCore/bytecode/Opcode.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Opcode.h" + +#if ENABLE(OPCODE_STATS) +#include <stdio.h> +#include <wtf/FixedArray.h> +#endif + +using namespace std; + +namespace JSC { + +#if ENABLE(OPCODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(OPCODE_STATS) + +const char* const opcodeNames[] = { +#define OPCODE_NAME_ENTRY(opcode, size) #opcode, + FOR_EACH_OPCODE_ID(OPCODE_NAME_ENTRY) +#undef OPCODE_NAME_ENTRY +}; + +#endif + +#if ENABLE(OPCODE_STATS) + +long long OpcodeStats::opcodeCounts[numOpcodeIDs]; +long long OpcodeStats::opcodePairCounts[numOpcodeIDs][numOpcodeIDs]; +int OpcodeStats::lastOpcode = -1; + +static OpcodeStats logger; + +OpcodeStats::OpcodeStats() +{ + for (int i = 0; i < numOpcodeIDs; ++i) + opcodeCounts[i] = 0; + + for (int i = 0; i < numOpcodeIDs; ++i) + for (int j = 0; j < numOpcodeIDs; ++j) + opcodePairCounts[i][j] = 0; +} + +static int compareOpcodeIndices(const void* left, const void* right) +{ + long long leftValue = OpcodeStats::opcodeCounts[*(int*) left]; + long long rightValue = OpcodeStats::opcodeCounts[*(int*) right]; + + if (leftValue < rightValue) + return 1; + else if (leftValue > rightValue) + return -1; + else + return 0; +} + +static int compareOpcodePairIndices(const void* left, const void* right) +{ + pair<int, int> leftPair = *(pair<int, int>*) left; + long long leftValue = OpcodeStats::opcodePairCounts[leftPair.first][leftPair.second]; + pair<int, int> rightPair = *(pair<int, int>*) right; + long long rightValue = OpcodeStats::opcodePairCounts[rightPair.first][rightPair.second]; + + if (leftValue < rightValue) + return 1; + else if (leftValue > rightValue) + return -1; + else + return 0; +} + +OpcodeStats::~OpcodeStats() +{ + long long totalInstructions = 0; + for (int i = 0; i < numOpcodeIDs; ++i) + totalInstructions += opcodeCounts[i]; + + long long totalInstructionPairs = 0; + for (int i = 0; i < numOpcodeIDs; ++i) + for (int j = 0; j < numOpcodeIDs; ++j) + totalInstructionPairs += opcodePairCounts[i][j]; + + FixedArray<int, numOpcodeIDs> sortedIndices; + for (int i = 0; i < numOpcodeIDs; ++i) + sortedIndices[i] = i; + qsort(sortedIndices.data(), numOpcodeIDs, sizeof(int), compareOpcodeIndices); + + pair<int, int> sortedPairIndices[numOpcodeIDs * numOpcodeIDs]; + pair<int, int>* currentPairIndex = sortedPairIndices; + for (int i = 0; i < numOpcodeIDs; ++i) + for (int j = 0; j < numOpcodeIDs; ++j) + *(currentPairIndex++) = make_pair(i, j); + qsort(sortedPairIndices, numOpcodeIDs * numOpcodeIDs, sizeof(pair<int, int>), compareOpcodePairIndices); + + printf("\nExecuted opcode statistics\n"); + + printf("Total instructions executed: %lld\n\n", totalInstructions); + + printf("All opcodes by frequency:\n\n"); + + for (int i = 0; i < numOpcodeIDs; ++i) { + int index = sortedIndices[i]; + printf("%s:%s %lld - %.2f%%\n", opcodeNames[index], padOpcodeName((OpcodeID)index, 28), opcodeCounts[index], ((double) opcodeCounts[index]) / ((double) totalInstructions) * 100.0); + } + + printf("\n"); + printf("2-opcode sequences by frequency: %lld\n\n", totalInstructions); + + for (int i = 0; i < numOpcodeIDs * numOpcodeIDs; ++i) { + pair<int, int> indexPair = sortedPairIndices[i]; + long long count = opcodePairCounts[indexPair.first][indexPair.second]; + + if (!count) + break; + + printf("%s%s %s:%s %lld %.2f%%\n", opcodeNames[indexPair.first], padOpcodeName((OpcodeID)indexPair.first, 28), opcodeNames[indexPair.second], padOpcodeName((OpcodeID)indexPair.second, 28), count, ((double) count) / ((double) totalInstructionPairs) * 100.0); + } + + printf("\n"); + printf("Most common opcodes and sequences:\n"); + + for (int i = 0; i < numOpcodeIDs; ++i) { + int index = sortedIndices[i]; + long long opcodeCount = opcodeCounts[index]; + double opcodeProportion = ((double) opcodeCount) / ((double) totalInstructions); + if (opcodeProportion < 0.0001) + break; + printf("\n%s:%s %lld - %.2f%%\n", opcodeNames[index], padOpcodeName((OpcodeID)index, 28), opcodeCount, opcodeProportion * 100.0); + + for (int j = 0; j < numOpcodeIDs * numOpcodeIDs; ++j) { + pair<int, int> indexPair = sortedPairIndices[j]; + long long pairCount = opcodePairCounts[indexPair.first][indexPair.second]; + double pairProportion = ((double) pairCount) / ((double) totalInstructionPairs); + + if (!pairCount || pairProportion < 0.0001 || pairProportion < opcodeProportion / 100) + break; + + if (indexPair.first != index && indexPair.second != index) + continue; + + printf(" %s%s %s:%s %lld - %.2f%%\n", opcodeNames[indexPair.first], padOpcodeName((OpcodeID)indexPair.first, 28), opcodeNames[indexPair.second], padOpcodeName((OpcodeID)indexPair.second, 28), pairCount, pairProportion * 100.0); + } + + } + printf("\n"); +} + +void OpcodeStats::recordInstruction(int opcode) +{ + opcodeCounts[opcode]++; + + if (lastOpcode != -1) + opcodePairCounts[lastOpcode][opcode]++; + + lastOpcode = opcode; +} + +void OpcodeStats::resetLastInstruction() +{ + lastOpcode = -1; +} + +#endif + +} // namespace JSC diff --git a/Source/JavaScriptCore/bytecode/Opcode.h b/Source/JavaScriptCore/bytecode/Opcode.h new file mode 100644 index 0000000..6c1c6b2 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/Opcode.h @@ -0,0 +1,276 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Opcode_h +#define Opcode_h + +#include <algorithm> +#include <string.h> + +#include <wtf/Assertions.h> + +namespace JSC { + + #define FOR_EACH_OPCODE_ID(macro) \ + macro(op_enter, 1) \ + macro(op_create_activation, 2) \ + macro(op_init_lazy_reg, 2) \ + macro(op_create_arguments, 2) \ + macro(op_create_this, 3) \ + macro(op_get_callee, 2) \ + macro(op_convert_this, 2) \ + macro(op_convert_this_strict, 2) \ + \ + macro(op_new_object, 2) \ + macro(op_new_array, 4) \ + macro(op_new_regexp, 3) \ + macro(op_mov, 3) \ + \ + macro(op_not, 3) \ + macro(op_eq, 4) \ + macro(op_eq_null, 3) \ + macro(op_neq, 4) \ + macro(op_neq_null, 3) \ + macro(op_stricteq, 4) \ + macro(op_nstricteq, 4) \ + macro(op_less, 4) \ + macro(op_lesseq, 4) \ + \ + macro(op_pre_inc, 2) \ + macro(op_pre_dec, 2) \ + macro(op_post_inc, 3) \ + macro(op_post_dec, 3) \ + macro(op_to_jsnumber, 3) \ + macro(op_negate, 3) \ + macro(op_add, 5) \ + macro(op_mul, 5) \ + macro(op_div, 5) \ + macro(op_mod, 4) \ + macro(op_sub, 5) \ + \ + macro(op_lshift, 4) \ + macro(op_rshift, 4) \ + macro(op_urshift, 4) \ + macro(op_bitand, 5) \ + macro(op_bitxor, 5) \ + macro(op_bitor, 5) \ + macro(op_bitnot, 3) \ + \ + macro(op_check_has_instance, 2) \ + macro(op_instanceof, 5) \ + macro(op_typeof, 3) \ + macro(op_is_undefined, 3) \ + macro(op_is_boolean, 3) \ + macro(op_is_number, 3) \ + macro(op_is_string, 3) \ + macro(op_is_object, 3) \ + macro(op_is_function, 3) \ + macro(op_in, 4) \ + \ + macro(op_resolve, 3) \ + macro(op_resolve_skip, 4) \ + macro(op_resolve_global, 5) \ + macro(op_resolve_global_dynamic, 6) \ + macro(op_get_scoped_var, 4) \ + macro(op_put_scoped_var, 4) \ + macro(op_get_global_var, 3) \ + macro(op_put_global_var, 3) \ + macro(op_resolve_base, 4) \ + macro(op_ensure_property_exists, 3) \ + macro(op_resolve_with_base, 4) \ + macro(op_get_by_id, 8) \ + macro(op_get_by_id_self, 8) \ + macro(op_get_by_id_self_list, 8) \ + macro(op_get_by_id_proto, 8) \ + macro(op_get_by_id_proto_list, 8) \ + macro(op_get_by_id_chain, 8) \ + macro(op_get_by_id_getter_self, 8) \ + macro(op_get_by_id_getter_self_list, 8) \ + macro(op_get_by_id_getter_proto, 8) \ + macro(op_get_by_id_getter_proto_list, 8) \ + macro(op_get_by_id_getter_chain, 8) \ + macro(op_get_by_id_custom_self, 8) \ + macro(op_get_by_id_custom_self_list, 8) \ + macro(op_get_by_id_custom_proto, 8) \ + macro(op_get_by_id_custom_proto_list, 8) \ + macro(op_get_by_id_custom_chain, 8) \ + macro(op_get_by_id_generic, 8) \ + macro(op_get_array_length, 8) \ + macro(op_get_string_length, 8) \ + macro(op_get_arguments_length, 4) \ + macro(op_put_by_id, 9) \ + macro(op_put_by_id_transition, 9) \ + macro(op_put_by_id_replace, 9) \ + macro(op_put_by_id_generic, 9) \ + macro(op_del_by_id, 4) \ + macro(op_get_by_val, 4) \ + macro(op_get_argument_by_val, 4) \ + macro(op_get_by_pname, 7) \ + macro(op_put_by_val, 4) \ + macro(op_del_by_val, 4) \ + macro(op_put_by_index, 4) \ + macro(op_put_getter, 4) \ + macro(op_put_setter, 4) \ + \ + macro(op_jmp, 2) \ + macro(op_jtrue, 3) \ + macro(op_jfalse, 3) \ + macro(op_jeq_null, 3) \ + macro(op_jneq_null, 3) \ + macro(op_jneq_ptr, 4) \ + macro(op_jnless, 4) \ + macro(op_jnlesseq, 4) \ + macro(op_jless, 4) \ + macro(op_jlesseq, 4) \ + macro(op_jmp_scopes, 3) \ + macro(op_loop, 2) \ + macro(op_loop_if_true, 3) \ + macro(op_loop_if_false, 3) \ + macro(op_loop_if_less, 4) \ + macro(op_loop_if_lesseq, 4) \ + macro(op_switch_imm, 4) \ + macro(op_switch_char, 4) \ + macro(op_switch_string, 4) \ + \ + macro(op_new_func, 4) \ + macro(op_new_func_exp, 3) \ + macro(op_call, 4) \ + macro(op_call_eval, 4) \ + macro(op_call_varargs, 4) \ + macro(op_load_varargs, 4) \ + macro(op_tear_off_activation, 3) \ + macro(op_tear_off_arguments, 2) \ + macro(op_ret, 2) \ + macro(op_call_put_result, 2) \ + macro(op_ret_object_or_this, 3) \ + macro(op_method_check, 1) \ + \ + macro(op_construct, 4) \ + macro(op_strcat, 4) \ + macro(op_to_primitive, 3) \ + \ + macro(op_get_pnames, 6) \ + macro(op_next_pname, 7) \ + \ + macro(op_push_scope, 2) \ + macro(op_pop_scope, 1) \ + macro(op_push_new_scope, 4) \ + \ + macro(op_catch, 2) \ + macro(op_throw, 2) \ + macro(op_throw_reference_error, 2) \ + macro(op_throw_syntax_error, 2) \ + \ + macro(op_jsr, 3) \ + macro(op_sret, 2) \ + \ + macro(op_debug, 4) \ + macro(op_profile_will_call, 2) \ + macro(op_profile_did_call, 2) \ + \ + macro(op_end, 2) // end must be the last opcode in the list + + #define OPCODE_ID_ENUM(opcode, length) opcode, + typedef enum { FOR_EACH_OPCODE_ID(OPCODE_ID_ENUM) } OpcodeID; + #undef OPCODE_ID_ENUM + + const int numOpcodeIDs = op_end + 1; + + #define OPCODE_ID_LENGTHS(id, length) const int id##_length = length; + FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS); + #undef OPCODE_ID_LENGTHS + + #define OPCODE_LENGTH(opcode) opcode##_length + + #define OPCODE_ID_LENGTH_MAP(opcode, length) length, + const int opcodeLengths[numOpcodeIDs] = { FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTH_MAP) }; + #undef OPCODE_ID_LENGTH_MAP + + #define VERIFY_OPCODE_ID(id, size) COMPILE_ASSERT(id <= op_end, ASSERT_THAT_JS_OPCODE_IDS_ARE_VALID); + FOR_EACH_OPCODE_ID(VERIFY_OPCODE_ID); + #undef VERIFY_OPCODE_ID + +#if ENABLE(COMPUTED_GOTO_INTERPRETER) +#if COMPILER(RVCT) || COMPILER(INTEL) + typedef void* Opcode; +#else + typedef const void* Opcode; +#endif +#else + typedef OpcodeID Opcode; +#endif + +#if ENABLE(OPCODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(OPCODE_STATS) + +#define PADDING_STRING " " +#define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING)) + + extern const char* const opcodeNames[]; + + inline const char* padOpcodeName(OpcodeID op, unsigned width) + { + unsigned pad = width - strlen(opcodeNames[op]); + pad = std::min(pad, PADDING_STRING_LENGTH); + return PADDING_STRING + PADDING_STRING_LENGTH - pad; + } + +#undef PADDING_STRING_LENGTH +#undef PADDING_STRING + +#endif + +#if ENABLE(OPCODE_STATS) + + struct OpcodeStats { + OpcodeStats(); + ~OpcodeStats(); + static long long opcodeCounts[numOpcodeIDs]; + static long long opcodePairCounts[numOpcodeIDs][numOpcodeIDs]; + static int lastOpcode; + + static void recordInstruction(int opcode); + static void resetLastInstruction(); + }; + +#endif + + inline size_t opcodeLength(OpcodeID opcode) + { + switch (opcode) { +#define OPCODE_ID_LENGTHS(id, length) case id: return OPCODE_LENGTH(id); + FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS) +#undef OPCODE_ID_LENGTHS + } + ASSERT_NOT_REACHED(); + return 0; + } + +} // namespace JSC + +#endif // Opcode_h diff --git a/Source/JavaScriptCore/bytecode/SamplingTool.cpp b/Source/JavaScriptCore/bytecode/SamplingTool.cpp new file mode 100644 index 0000000..f47e698 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/SamplingTool.cpp @@ -0,0 +1,406 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "SamplingTool.h" + +#include "CodeBlock.h" +#include "Interpreter.h" +#include "Opcode.h" + +#if !OS(WINDOWS) +#include <unistd.h> +#endif + +namespace JSC { + +#if ENABLE(SAMPLING_FLAGS) + +void SamplingFlags::sample() +{ + uint32_t mask = static_cast<uint32_t>(1 << 31); + unsigned index; + + for (index = 0; index < 32; ++index) { + if (mask & s_flags) + break; + mask >>= 1; + } + + s_flagCounts[32 - index]++; +} + +void SamplingFlags::start() +{ + for (unsigned i = 0; i <= 32; ++i) + s_flagCounts[i] = 0; +} +void SamplingFlags::stop() +{ + uint64_t total = 0; + for (unsigned i = 0; i <= 32; ++i) + total += s_flagCounts[i]; + + if (total) { + printf("\nSamplingFlags: sample counts with flags set: (%lld total)\n", total); + for (unsigned i = 0; i <= 32; ++i) { + if (s_flagCounts[i]) + printf(" [ %02d ] : %lld\t\t(%03.2f%%)\n", i, s_flagCounts[i], (100.0 * s_flagCounts[i]) / total); + } + printf("\n"); + } else + printf("\nSamplingFlags: no samples.\n\n"); +} +uint64_t SamplingFlags::s_flagCounts[33]; + +#else +void SamplingFlags::start() {} +void SamplingFlags::stop() {} +#endif + +/* + Start with flag 16 set. + By doing this the monitoring of lower valued flags will be masked out + until flag 16 is explictly cleared. +*/ +uint32_t SamplingFlags::s_flags = 1 << 15; + + +#if OS(WINDOWS) + +static void sleepForMicroseconds(unsigned us) +{ + unsigned ms = us / 1000; + if (us && !ms) + ms = 1; + Sleep(ms); +} + +#else + +static void sleepForMicroseconds(unsigned us) +{ + usleep(us); +} + +#endif + +static inline unsigned hertz2us(unsigned hertz) +{ + return 1000000 / hertz; +} + + +SamplingTool* SamplingTool::s_samplingTool = 0; + + +bool SamplingThread::s_running = false; +unsigned SamplingThread::s_hertz = 10000; +ThreadIdentifier SamplingThread::s_samplingThread; + +void* SamplingThread::threadStartFunc(void*) +{ + while (s_running) { + sleepForMicroseconds(hertz2us(s_hertz)); + +#if ENABLE(SAMPLING_FLAGS) + SamplingFlags::sample(); +#endif +#if ENABLE(OPCODE_SAMPLING) + SamplingTool::sample(); +#endif + } + + return 0; +} + + +void SamplingThread::start(unsigned hertz) +{ + ASSERT(!s_running); + s_running = true; + s_hertz = hertz; + + s_samplingThread = createThread(threadStartFunc, 0, "JavaScriptCore::Sampler"); +} + +void SamplingThread::stop() +{ + ASSERT(s_running); + s_running = false; + waitForThreadCompletion(s_samplingThread, 0); +} + + +void ScriptSampleRecord::sample(CodeBlock* codeBlock, Instruction* vPC) +{ + if (!m_samples) { + m_size = codeBlock->instructions().size(); + m_samples = static_cast<int*>(calloc(m_size, sizeof(int))); + m_codeBlock = codeBlock; + } + + ++m_sampleCount; + + unsigned offest = vPC - codeBlock->instructions().begin(); + // Since we don't read and write codeBlock and vPC atomically, this check + // can fail if we sample mid op_call / op_ret. + if (offest < m_size) { + m_samples[offest]++; + m_opcodeSampleCount++; + } +} + +void SamplingTool::doRun() +{ + Sample sample(m_sample, m_codeBlock); + ++m_sampleCount; + + if (sample.isNull()) + return; + + if (!sample.inHostFunction()) { + unsigned opcodeID = m_interpreter->getOpcodeID(sample.vPC()[0].u.opcode); + + ++m_opcodeSampleCount; + ++m_opcodeSamples[opcodeID]; + + if (sample.inCTIFunction()) + m_opcodeSamplesInCTIFunctions[opcodeID]++; + } + +#if ENABLE(CODEBLOCK_SAMPLING) + if (CodeBlock* codeBlock = sample.codeBlock()) { + MutexLocker locker(m_scriptSampleMapMutex); + ScriptSampleRecord* record = m_scopeSampleMap->get(codeBlock->ownerExecutable()); + ASSERT(record); + record->sample(codeBlock, sample.vPC()); + } +#endif +} + +void SamplingTool::sample() +{ + s_samplingTool->doRun(); +} + +void SamplingTool::notifyOfScope(ScriptExecutable* script) +{ +#if ENABLE(CODEBLOCK_SAMPLING) + MutexLocker locker(m_scriptSampleMapMutex); + m_scopeSampleMap->set(script, new ScriptSampleRecord(script)); +#else + UNUSED_PARAM(script); +#endif +} + +void SamplingTool::setup() +{ + s_samplingTool = this; +} + +#if ENABLE(OPCODE_SAMPLING) + +struct OpcodeSampleInfo { + OpcodeID opcode; + long long count; + long long countInCTIFunctions; +}; + +struct LineCountInfo { + unsigned line; + unsigned count; +}; + +static int compareOpcodeIndicesSampling(const void* left, const void* right) +{ + const OpcodeSampleInfo* leftSampleInfo = reinterpret_cast<const OpcodeSampleInfo*>(left); + const OpcodeSampleInfo* rightSampleInfo = reinterpret_cast<const OpcodeSampleInfo*>(right); + + return (leftSampleInfo->count < rightSampleInfo->count) ? 1 : (leftSampleInfo->count > rightSampleInfo->count) ? -1 : 0; +} + +#if ENABLE(CODEBLOCK_SAMPLING) +static int compareLineCountInfoSampling(const void* left, const void* right) +{ + const LineCountInfo* leftLineCount = reinterpret_cast<const LineCountInfo*>(left); + const LineCountInfo* rightLineCount = reinterpret_cast<const LineCountInfo*>(right); + + return (leftLineCount->line > rightLineCount->line) ? 1 : (leftLineCount->line < rightLineCount->line) ? -1 : 0; +} + +static int compareScriptSampleRecords(const void* left, const void* right) +{ + const ScriptSampleRecord* const leftValue = *static_cast<const ScriptSampleRecord* const *>(left); + const ScriptSampleRecord* const rightValue = *static_cast<const ScriptSampleRecord* const *>(right); + + return (leftValue->m_sampleCount < rightValue->m_sampleCount) ? 1 : (leftValue->m_sampleCount > rightValue->m_sampleCount) ? -1 : 0; +} +#endif + +void SamplingTool::dump(ExecState* exec) +{ + // Tidies up SunSpider output by removing short scripts - such a small number of samples would likely not be useful anyhow. + if (m_sampleCount < 10) + return; + + // (1) Build and sort 'opcodeSampleInfo' array. + + OpcodeSampleInfo opcodeSampleInfo[numOpcodeIDs]; + for (int i = 0; i < numOpcodeIDs; ++i) { + opcodeSampleInfo[i].opcode = static_cast<OpcodeID>(i); + opcodeSampleInfo[i].count = m_opcodeSamples[i]; + opcodeSampleInfo[i].countInCTIFunctions = m_opcodeSamplesInCTIFunctions[i]; + } + + qsort(opcodeSampleInfo, numOpcodeIDs, sizeof(OpcodeSampleInfo), compareOpcodeIndicesSampling); + + // (2) Print Opcode sampling results. + + printf("\nBytecode samples [*]\n"); + printf(" sample %% of %% of | cti cti %%\n"); + printf("opcode count VM total | count of self\n"); + printf("------------------------------------------------------- | ----------------\n"); + + for (int i = 0; i < numOpcodeIDs; ++i) { + long long count = opcodeSampleInfo[i].count; + if (!count) + continue; + + OpcodeID opcodeID = opcodeSampleInfo[i].opcode; + + const char* opcodeName = opcodeNames[opcodeID]; + const char* opcodePadding = padOpcodeName(opcodeID, 28); + double percentOfVM = (static_cast<double>(count) * 100) / m_opcodeSampleCount; + double percentOfTotal = (static_cast<double>(count) * 100) / m_sampleCount; + long long countInCTIFunctions = opcodeSampleInfo[i].countInCTIFunctions; + double percentInCTIFunctions = (static_cast<double>(countInCTIFunctions) * 100) / count; + fprintf(stdout, "%s:%s%-6lld %.3f%%\t%.3f%%\t | %-6lld %.3f%%\n", opcodeName, opcodePadding, count, percentOfVM, percentOfTotal, countInCTIFunctions, percentInCTIFunctions); + } + + printf("\n[*] Samples inside host code are not charged to any Bytecode.\n\n"); + printf("\tSamples inside VM:\t\t%lld / %lld (%.3f%%)\n", m_opcodeSampleCount, m_sampleCount, (static_cast<double>(m_opcodeSampleCount) * 100) / m_sampleCount); + printf("\tSamples inside host code:\t%lld / %lld (%.3f%%)\n\n", m_sampleCount - m_opcodeSampleCount, m_sampleCount, (static_cast<double>(m_sampleCount - m_opcodeSampleCount) * 100) / m_sampleCount); + printf("\tsample count:\tsamples inside this opcode\n"); + printf("\t%% of VM:\tsample count / all opcode samples\n"); + printf("\t%% of total:\tsample count / all samples\n"); + printf("\t--------------\n"); + printf("\tcti count:\tsamples inside a CTI function called by this opcode\n"); + printf("\tcti %% of self:\tcti count / sample count\n"); + +#if ENABLE(CODEBLOCK_SAMPLING) + + // (3) Build and sort 'codeBlockSamples' array. + + int scopeCount = m_scopeSampleMap->size(); + Vector<ScriptSampleRecord*> codeBlockSamples(scopeCount); + ScriptSampleRecordMap::iterator iter = m_scopeSampleMap->begin(); + for (int i = 0; i < scopeCount; ++i, ++iter) + codeBlockSamples[i] = iter->second; + + qsort(codeBlockSamples.begin(), scopeCount, sizeof(ScriptSampleRecord*), compareScriptSampleRecords); + + // (4) Print data from 'codeBlockSamples' array. + + printf("\nCodeBlock samples\n\n"); + + for (int i = 0; i < scopeCount; ++i) { + ScriptSampleRecord* record = codeBlockSamples[i]; + CodeBlock* codeBlock = record->m_codeBlock; + + double blockPercent = (record->m_sampleCount * 100.0) / m_sampleCount; + + if (blockPercent >= 1) { + //Instruction* code = codeBlock->instructions().begin(); + printf("#%d: %s:%d: %d / %lld (%.3f%%)\n", i + 1, record->m_executable->sourceURL().utf8().data(), codeBlock->lineNumberForBytecodeOffset(0), record->m_sampleCount, m_sampleCount, blockPercent); + if (i < 10) { + HashMap<unsigned,unsigned> lineCounts; + codeBlock->dump(exec); + + printf(" Opcode and line number samples [*]\n\n"); + for (unsigned op = 0; op < record->m_size; ++op) { + int count = record->m_samples[op]; + if (count) { + printf(" [% 4d] has sample count: % 4d\n", op, count); + unsigned line = codeBlock->lineNumberForBytecodeOffset(op); + lineCounts.set(line, (lineCounts.contains(line) ? lineCounts.get(line) : 0) + count); + } + } + printf("\n"); + + int linesCount = lineCounts.size(); + Vector<LineCountInfo> lineCountInfo(linesCount); + int lineno = 0; + for (HashMap<unsigned,unsigned>::iterator iter = lineCounts.begin(); iter != lineCounts.end(); ++iter, ++lineno) { + lineCountInfo[lineno].line = iter->first; + lineCountInfo[lineno].count = iter->second; + } + + qsort(lineCountInfo.begin(), linesCount, sizeof(LineCountInfo), compareLineCountInfoSampling); + + for (lineno = 0; lineno < linesCount; ++lineno) { + printf(" Line #%d has sample count %d.\n", lineCountInfo[lineno].line, lineCountInfo[lineno].count); + } + printf("\n"); + printf(" [*] Samples inside host code are charged to the calling Bytecode.\n"); + printf(" Samples on a call / return boundary are not charged to a specific opcode or line.\n\n"); + printf(" Samples on a call / return boundary: %d / %d (%.3f%%)\n\n", record->m_sampleCount - record->m_opcodeSampleCount, record->m_sampleCount, (static_cast<double>(record->m_sampleCount - record->m_opcodeSampleCount) * 100) / record->m_sampleCount); + } + } + } +#else + UNUSED_PARAM(exec); +#endif +} + +#else + +void SamplingTool::dump(ExecState*) +{ +} + +#endif + +void AbstractSamplingCounter::dump() +{ +#if ENABLE(SAMPLING_COUNTERS) + if (s_abstractSamplingCounterChain != &s_abstractSamplingCounterChainEnd) { + printf("\nSampling Counter Values:\n"); + for (AbstractSamplingCounter* currCounter = s_abstractSamplingCounterChain; (currCounter != &s_abstractSamplingCounterChainEnd); currCounter = currCounter->m_next) + printf("\t%s\t: %lld\n", currCounter->m_name, currCounter->m_counter); + printf("\n\n"); + } + s_completed = true; +#endif +} + +AbstractSamplingCounter AbstractSamplingCounter::s_abstractSamplingCounterChainEnd; +AbstractSamplingCounter* AbstractSamplingCounter::s_abstractSamplingCounterChain = &s_abstractSamplingCounterChainEnd; +bool AbstractSamplingCounter::s_completed = false; + +} // namespace JSC diff --git a/Source/JavaScriptCore/bytecode/SamplingTool.h b/Source/JavaScriptCore/bytecode/SamplingTool.h new file mode 100644 index 0000000..8e3ed9e --- /dev/null +++ b/Source/JavaScriptCore/bytecode/SamplingTool.h @@ -0,0 +1,414 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SamplingTool_h +#define SamplingTool_h + +#include <wtf/Assertions.h> +#include <wtf/HashMap.h> +#include <wtf/Threading.h> + +#include "Nodes.h" +#include "Opcode.h" + +namespace JSC { + + class ScriptExecutable; + + class SamplingFlags { + friend class JIT; + public: + static void start(); + static void stop(); + +#if ENABLE(SAMPLING_FLAGS) + static void setFlag(unsigned flag) + { + ASSERT(flag >= 1); + ASSERT(flag <= 32); + s_flags |= 1u << (flag - 1); + } + + static void clearFlag(unsigned flag) + { + ASSERT(flag >= 1); + ASSERT(flag <= 32); + s_flags &= ~(1u << (flag - 1)); + } + + static void sample(); + + class ScopedFlag { + public: + ScopedFlag(int flag) + : m_flag(flag) + { + setFlag(flag); + } + + ~ScopedFlag() + { + clearFlag(m_flag); + } + + private: + int m_flag; + }; + +#endif + private: + static uint32_t s_flags; +#if ENABLE(SAMPLING_FLAGS) + static uint64_t s_flagCounts[33]; +#endif + }; + + class CodeBlock; + class ExecState; + class Interpreter; + class ScopeNode; + struct Instruction; + + struct ScriptSampleRecord { + ScriptSampleRecord(ScriptExecutable* executable) + : m_executable(executable) + , m_codeBlock(0) + , m_sampleCount(0) + , m_opcodeSampleCount(0) + , m_samples(0) + , m_size(0) + { + } + + ~ScriptSampleRecord() + { + if (m_samples) + free(m_samples); + } + + void sample(CodeBlock*, Instruction*); + + RefPtr<ScriptExecutable> m_executable; + CodeBlock* m_codeBlock; + int m_sampleCount; + int m_opcodeSampleCount; + int* m_samples; + unsigned m_size; + }; + + typedef WTF::HashMap<ScriptExecutable*, ScriptSampleRecord*> ScriptSampleRecordMap; + + class SamplingThread { + public: + // Sampling thread state. + static bool s_running; + static unsigned s_hertz; + static ThreadIdentifier s_samplingThread; + + static void start(unsigned hertz=10000); + static void stop(); + + static void* threadStartFunc(void*); + }; + + class SamplingTool { + public: + friend struct CallRecord; + friend class HostCallRecord; + +#if ENABLE(OPCODE_SAMPLING) + class CallRecord : public Noncopyable { + public: + CallRecord(SamplingTool* samplingTool) + : m_samplingTool(samplingTool) + , m_savedSample(samplingTool->m_sample) + , m_savedCodeBlock(samplingTool->m_codeBlock) + { + } + + ~CallRecord() + { + m_samplingTool->m_sample = m_savedSample; + m_samplingTool->m_codeBlock = m_savedCodeBlock; + } + + private: + SamplingTool* m_samplingTool; + intptr_t m_savedSample; + CodeBlock* m_savedCodeBlock; + }; + + class HostCallRecord : public CallRecord { + public: + HostCallRecord(SamplingTool* samplingTool) + : CallRecord(samplingTool) + { + samplingTool->m_sample |= 0x1; + } + }; +#else + class CallRecord : public Noncopyable { + public: + CallRecord(SamplingTool*) + { + } + }; + + class HostCallRecord : public CallRecord { + public: + HostCallRecord(SamplingTool* samplingTool) + : CallRecord(samplingTool) + { + } + }; +#endif + + SamplingTool(Interpreter* interpreter) + : m_interpreter(interpreter) + , m_codeBlock(0) + , m_sample(0) + , m_sampleCount(0) + , m_opcodeSampleCount(0) +#if ENABLE(CODEBLOCK_SAMPLING) + , m_scopeSampleMap(new ScriptSampleRecordMap()) +#endif + { + memset(m_opcodeSamples, 0, sizeof(m_opcodeSamples)); + memset(m_opcodeSamplesInCTIFunctions, 0, sizeof(m_opcodeSamplesInCTIFunctions)); + } + + ~SamplingTool() + { +#if ENABLE(CODEBLOCK_SAMPLING) + deleteAllValues(*m_scopeSampleMap); +#endif + } + + void setup(); + void dump(ExecState*); + + void notifyOfScope(ScriptExecutable* scope); + + void sample(CodeBlock* codeBlock, Instruction* vPC) + { + ASSERT(!(reinterpret_cast<intptr_t>(vPC) & 0x3)); + m_codeBlock = codeBlock; + m_sample = reinterpret_cast<intptr_t>(vPC); + } + + CodeBlock** codeBlockSlot() { return &m_codeBlock; } + intptr_t* sampleSlot() { return &m_sample; } + + void* encodeSample(Instruction* vPC, bool inCTIFunction = false, bool inHostFunction = false) + { + ASSERT(!(reinterpret_cast<intptr_t>(vPC) & 0x3)); + return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(vPC) | (static_cast<intptr_t>(inCTIFunction) << 1) | static_cast<intptr_t>(inHostFunction)); + } + + static void sample(); + + private: + class Sample { + public: + Sample(volatile intptr_t sample, CodeBlock* volatile codeBlock) + : m_sample(sample) + , m_codeBlock(codeBlock) + { + } + + bool isNull() { return !m_sample; } + CodeBlock* codeBlock() { return m_codeBlock; } + Instruction* vPC() { return reinterpret_cast<Instruction*>(m_sample & ~0x3); } + bool inHostFunction() { return m_sample & 0x1; } + bool inCTIFunction() { return m_sample & 0x2; } + + private: + intptr_t m_sample; + CodeBlock* m_codeBlock; + }; + + void doRun(); + static SamplingTool* s_samplingTool; + + Interpreter* m_interpreter; + + // State tracked by the main thread, used by the sampling thread. + CodeBlock* m_codeBlock; + intptr_t m_sample; + + // Gathered sample data. + long long m_sampleCount; + long long m_opcodeSampleCount; + unsigned m_opcodeSamples[numOpcodeIDs]; + unsigned m_opcodeSamplesInCTIFunctions[numOpcodeIDs]; + +#if ENABLE(CODEBLOCK_SAMPLING) + Mutex m_scriptSampleMapMutex; + OwnPtr<ScriptSampleRecordMap> m_scopeSampleMap; +#endif + }; + + // AbstractSamplingCounter: + // + // Implements a named set of counters, printed on exit if ENABLE(SAMPLING_COUNTERS). + // See subclasses below, SamplingCounter, GlobalSamplingCounter and DeletableSamplingCounter. + class AbstractSamplingCounter { + friend class JIT; + friend class DeletableSamplingCounter; + public: + void count(uint32_t count = 1) + { + m_counter += count; + } + + static void dump(); + + protected: + // Effectively the contructor, however called lazily in the case of GlobalSamplingCounter. + void init(const char* name) + { + m_counter = 0; + m_name = name; + + // Set m_next to point to the head of the chain, and inform whatever is + // currently at the head that this node will now hold the pointer to it. + m_next = s_abstractSamplingCounterChain; + s_abstractSamplingCounterChain->m_referer = &m_next; + // Add this node to the head of the list. + s_abstractSamplingCounterChain = this; + m_referer = &s_abstractSamplingCounterChain; + } + + int64_t m_counter; + const char* m_name; + AbstractSamplingCounter* m_next; + // This is a pointer to the pointer to this node in the chain; used to + // allow fast linked list deletion. + AbstractSamplingCounter** m_referer; + // Null object used to detect end of static chain. + static AbstractSamplingCounter s_abstractSamplingCounterChainEnd; + static AbstractSamplingCounter* s_abstractSamplingCounterChain; + static bool s_completed; + }; + +#if ENABLE(SAMPLING_COUNTERS) + // SamplingCounter: + // + // This class is suitable and (hopefully!) convenient for cases where a counter is + // required within the scope of a single function. It can be instantiated as a + // static variable since it contains a constructor but not a destructor (static + // variables in WebKit cannot have destructors). + // + // For example: + // + // void someFunction() + // { + // static SamplingCounter countMe("This is my counter. There are many like it, but this one is mine."); + // countMe.count(); + // // ... + // } + // + class SamplingCounter : public AbstractSamplingCounter { + public: + SamplingCounter(const char* name) { init(name); } + }; + + // GlobalSamplingCounter: + // + // This class is suitable for use where a counter is to be declared globally, + // since it contains neither a constructor nor destructor. Instead, ensure + // that 'name()' is called to provide the counter with a name (and also to + // allow it to be printed out on exit). + // + // GlobalSamplingCounter globalCounter; + // + // void firstFunction() + // { + // // Put this within a function that is definitely called! + // // (Or alternatively alongside all calls to 'count()'). + // globalCounter.name("I Name You Destroyer."); + // globalCounter.count(); + // // ... + // } + // + // void secondFunction() + // { + // globalCounter.count(); + // // ... + // } + // + class GlobalSamplingCounter : public AbstractSamplingCounter { + public: + void name(const char* name) + { + // Global objects should be mapped in zero filled memory, so this should + // be a safe (albeit not necessarily threadsafe) check for 'first call'. + if (!m_next) + init(name); + } + }; + + // DeletableSamplingCounter: + // + // The above classes (SamplingCounter, GlobalSamplingCounter), are intended for + // use within a global or static scope, and as such cannot have a destructor. + // This means there is no convenient way for them to remove themselves from the + // static list of counters, and should an instance of either class be freed + // before 'dump()' has walked over the list it will potentially walk over an + // invalid pointer. + // + // This class is intended for use where the counter may possibly be deleted before + // the program exits. Should this occur, the counter will print it's value to + // stderr, and remove itself from the static list. Example: + // + // DeletableSamplingCounter* counter = new DeletableSamplingCounter("The Counter With No Name"); + // counter->count(); + // delete counter; + // + class DeletableSamplingCounter : public AbstractSamplingCounter { + public: + DeletableSamplingCounter(const char* name) { init(name); } + + ~DeletableSamplingCounter() + { + if (!s_completed) + fprintf(stderr, "DeletableSamplingCounter \"%s\" deleted early (with count %lld)\n", m_name, m_counter); + // Our m_referer pointer should know where the pointer to this node is, + // and m_next should know that this node is the previous node in the list. + ASSERT(*m_referer == this); + ASSERT(m_next->m_referer == &m_next); + // Remove this node from the list, and inform m_next that we have done so. + m_next->m_referer = m_referer; + *m_referer = m_next; + } + }; +#endif + +} // namespace JSC + +#endif // SamplingTool_h diff --git a/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp b/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp new file mode 100644 index 0000000..018d832 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "StructureStubInfo.h" + +namespace JSC { + +#if ENABLE(JIT) +void StructureStubInfo::deref() +{ + switch (accessType) { + case access_get_by_id_self: + u.getByIdSelf.baseObjectStructure->deref(); + return; + case access_get_by_id_proto: + u.getByIdProto.baseObjectStructure->deref(); + u.getByIdProto.prototypeStructure->deref(); + return; + case access_get_by_id_chain: + u.getByIdChain.baseObjectStructure->deref(); + u.getByIdChain.chain->deref(); + return; + case access_get_by_id_self_list: { + PolymorphicAccessStructureList* polymorphicStructures = u.getByIdSelfList.structureList; + polymorphicStructures->derefStructures(u.getByIdSelfList.listSize); + delete polymorphicStructures; + return; + } + case access_get_by_id_proto_list: { + PolymorphicAccessStructureList* polymorphicStructures = u.getByIdProtoList.structureList; + polymorphicStructures->derefStructures(u.getByIdProtoList.listSize); + delete polymorphicStructures; + return; + } + case access_put_by_id_transition: + u.putByIdTransition.previousStructure->deref(); + u.putByIdTransition.structure->deref(); + u.putByIdTransition.chain->deref(); + return; + case access_put_by_id_replace: + u.putByIdReplace.baseObjectStructure->deref(); + return; + case access_get_by_id: + case access_put_by_id: + case access_get_by_id_generic: + case access_put_by_id_generic: + case access_get_array_length: + case access_get_string_length: + // These instructions don't ref their Structures. + return; + default: + ASSERT_NOT_REACHED(); + } +} +#endif + +} // namespace JSC diff --git a/Source/JavaScriptCore/bytecode/StructureStubInfo.h b/Source/JavaScriptCore/bytecode/StructureStubInfo.h new file mode 100644 index 0000000..8e2c489 --- /dev/null +++ b/Source/JavaScriptCore/bytecode/StructureStubInfo.h @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef StructureStubInfo_h +#define StructureStubInfo_h + +#if ENABLE(JIT) + +#include "Instruction.h" +#include "MacroAssembler.h" +#include "Opcode.h" +#include "Structure.h" + +namespace JSC { + + enum AccessType { + access_get_by_id_self, + access_get_by_id_proto, + access_get_by_id_chain, + access_get_by_id_self_list, + access_get_by_id_proto_list, + access_put_by_id_transition, + access_put_by_id_replace, + access_get_by_id, + access_put_by_id, + access_get_by_id_generic, + access_put_by_id_generic, + access_get_array_length, + access_get_string_length, + }; + + struct StructureStubInfo { + StructureStubInfo(AccessType accessType) + : accessType(accessType) + , seen(false) + { + } + + void initGetByIdSelf(Structure* baseObjectStructure) + { + accessType = access_get_by_id_self; + + u.getByIdSelf.baseObjectStructure = baseObjectStructure; + baseObjectStructure->ref(); + } + + void initGetByIdProto(Structure* baseObjectStructure, Structure* prototypeStructure) + { + accessType = access_get_by_id_proto; + + u.getByIdProto.baseObjectStructure = baseObjectStructure; + baseObjectStructure->ref(); + + u.getByIdProto.prototypeStructure = prototypeStructure; + prototypeStructure->ref(); + } + + void initGetByIdChain(Structure* baseObjectStructure, StructureChain* chain) + { + accessType = access_get_by_id_chain; + + u.getByIdChain.baseObjectStructure = baseObjectStructure; + baseObjectStructure->ref(); + + u.getByIdChain.chain = chain; + chain->ref(); + } + + void initGetByIdSelfList(PolymorphicAccessStructureList* structureList, int listSize) + { + accessType = access_get_by_id_self_list; + + u.getByIdProtoList.structureList = structureList; + u.getByIdProtoList.listSize = listSize; + } + + void initGetByIdProtoList(PolymorphicAccessStructureList* structureList, int listSize) + { + accessType = access_get_by_id_proto_list; + + u.getByIdProtoList.structureList = structureList; + u.getByIdProtoList.listSize = listSize; + } + + // PutById* + + void initPutByIdTransition(Structure* previousStructure, Structure* structure, StructureChain* chain) + { + accessType = access_put_by_id_transition; + + u.putByIdTransition.previousStructure = previousStructure; + previousStructure->ref(); + + u.putByIdTransition.structure = structure; + structure->ref(); + + u.putByIdTransition.chain = chain; + chain->ref(); + } + + void initPutByIdReplace(Structure* baseObjectStructure) + { + accessType = access_put_by_id_replace; + + u.putByIdReplace.baseObjectStructure = baseObjectStructure; + baseObjectStructure->ref(); + } + + void deref(); + + bool seenOnce() + { + return seen; + } + + void setSeen() + { + seen = true; + } + + int accessType : 31; + int seen : 1; + + union { + struct { + Structure* baseObjectStructure; + } getByIdSelf; + struct { + Structure* baseObjectStructure; + Structure* prototypeStructure; + } getByIdProto; + struct { + Structure* baseObjectStructure; + StructureChain* chain; + } getByIdChain; + struct { + PolymorphicAccessStructureList* structureList; + int listSize; + } getByIdSelfList; + struct { + PolymorphicAccessStructureList* structureList; + int listSize; + } getByIdProtoList; + struct { + Structure* previousStructure; + Structure* structure; + StructureChain* chain; + } putByIdTransition; + struct { + Structure* baseObjectStructure; + } putByIdReplace; + } u; + + CodeLocationLabel stubRoutine; + CodeLocationCall callReturnLocation; + CodeLocationLabel hotPathBegin; + }; + +} // namespace JSC + +#endif + +#endif // StructureStubInfo_h |