Changeset 229815 in webkit
- Timestamp:
- Mar 21, 2018 11:23:30 AM (6 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r229810 r229815 1 2018-03-21 Mark Lam <mark.lam@apple.com> 2 3 Use CodeBlock::instructions()[] and CodeBlock::bytecodeOffset() instead of doing own pointer math. 4 https://bugs.webkit.org/show_bug.cgi?id=183857 5 <rdar://problem/38712184> 6 7 Reviewed by JF Bastien. 8 9 We should avoid doing pointer math with CodeBlock::instructions().begin(). 10 Instead, we should use the operator[] that comes with CodeBlock::instructions() 11 for computing an Instruction*, and use CodeBlock::bytecodeOffset() for computing 12 the bytecode offset of a given Instruction*. These methods will do assertions 13 which helps catch bugs sooner, plus they are more descriptive of the operation 14 we're trying to do. 15 16 * bytecode/BytecodeKills.h: 17 (JSC::BytecodeKills::operandIsKilled const): 18 (JSC::BytecodeKills::forEachOperandKilledAt const): 19 * bytecode/CallLinkStatus.cpp: 20 (JSC::CallLinkStatus::computeFromLLInt): 21 * bytecode/CodeBlock.cpp: 22 (JSC::CodeBlock::dumpBytecode): 23 (JSC::CodeBlock::arithProfileForBytecodeOffset): 24 (JSC::CodeBlock::bytecodeOffsetFromCallSiteIndex): 25 * bytecode/GetByIdStatus.cpp: 26 (JSC::GetByIdStatus::computeFromLLInt): 27 * bytecode/PutByIdStatus.cpp: 28 (JSC::PutByIdStatus::computeFromLLInt): 29 * dfg/DFGByteCodeParser.cpp: 30 (JSC::DFG::ByteCodeParser::getPredictionWithoutOSRExit): 31 * dfg/DFGOSRExit.cpp: 32 (JSC::DFG::reifyInlinedCallFrames): 33 * dfg/DFGOSRExitCompilerCommon.cpp: 34 (JSC::DFG::reifyInlinedCallFrames): 35 * interpreter/CallFrame.cpp: 36 (JSC::CallFrame::callSiteBitsAsBytecodeOffset const): 37 (JSC::CallFrame::currentVPC const): 38 (JSC::CallFrame::setCurrentVPC): 39 * jit/JITCall.cpp: 40 (JSC::JIT::compileOpCall): 41 * jit/JITInlines.h: 42 (JSC::JIT::updateTopCallFrame): 43 (JSC::JIT::copiedInstruction): 44 * jit/JITOpcodes.cpp: 45 (JSC::JIT::privateCompileHasIndexedProperty): 46 * jit/JITOpcodes32_64.cpp: 47 (JSC::JIT::privateCompileHasIndexedProperty): 48 * jit/JITPropertyAccess.cpp: 49 (JSC::JIT::privateCompileGetByVal): 50 (JSC::JIT::privateCompileGetByValWithCachedId): 51 (JSC::JIT::privateCompilePutByVal): 52 (JSC::JIT::privateCompilePutByValWithCachedId): 53 * jit/SlowPathCall.h: 54 (JSC::JITSlowPathCall::call): 55 * llint/LLIntSlowPaths.cpp: 56 (JSC::LLInt::llint_trace_operand): 57 (JSC::LLInt::llint_trace_value): 58 (JSC::LLInt::LLINT_SLOW_PATH_DECL): 59 (JSC::LLInt::setupGetByIdPrototypeCache): Deleted. 60 (JSC::LLInt::getByVal): Deleted. 61 (JSC::LLInt::handleHostCall): Deleted. 62 (JSC::LLInt::setUpCall): Deleted. 63 (JSC::LLInt::genericCall): Deleted. 64 (JSC::LLInt::varargsSetup): Deleted. 65 (JSC::LLInt::llint_throw_stack_overflow_error): Deleted. 66 (JSC::LLInt::llint_stack_check_at_vm_entry): Deleted. 67 (JSC::LLInt::llint_write_barrier_slow): Deleted. 68 (JSC::LLInt::llint_crash): Deleted. 69 * runtime/SamplingProfiler.cpp: 70 (JSC::tryGetBytecodeIndex): 71 1 72 2018-03-21 Keith Miller <keith_miller@apple.com> 2 73 -
trunk/Source/JavaScriptCore/bytecode/BytecodeKills.h
r229309 r229815 53 53 bool operandIsKilled(Instruction* instruction, int operand) const 54 54 { 55 return operandIsKilled( instruction - m_codeBlock->instructions().begin(), operand);55 return operandIsKilled(m_codeBlock->bytecodeOffset(instruction), operand); 56 56 } 57 57 … … 69 69 void forEachOperandKilledAt(Instruction* pc, const Functor& functor) const 70 70 { 71 forEachOperandKilledAt( pc - m_codeBlock->instructions().begin(), functor);71 forEachOperandKilledAt(m_codeBlock->bytecodeOffset(pc), functor); 72 72 } 73 73 -
trunk/Source/JavaScriptCore/bytecode/CallLinkStatus.cpp
r226942 r229815 67 67 #endif 68 68 69 Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex;69 Instruction* instruction = &profiledBlock->instructions()[bytecodeIndex]; 70 70 OpcodeID op = Interpreter::getOpcodeID(instruction[0].u.opcode); 71 71 if (op != op_call && op != op_construct && op != op_tail_call) -
trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp
r229413 r229815 254 254 const StubInfoMap& stubInfos, const CallLinkInfoMap& callLinkInfos) 255 255 { 256 const Instruction* it = instructions().begin() + bytecodeOffset;256 const Instruction* it = &instructions()[bytecodeOffset]; 257 257 dumpBytecode(out, instructions().begin(), it, stubInfos, callLinkInfos); 258 258 } … … 2875 2875 ArithProfile* CodeBlock::arithProfileForBytecodeOffset(int bytecodeOffset) 2876 2876 { 2877 return arithProfileForPC( instructions().begin() + bytecodeOffset);2877 return arithProfileForPC(&instructions()[bytecodeOffset]); 2878 2878 } 2879 2879 … … 3022 3022 #else 3023 3023 Instruction* instruction = bitwise_cast<Instruction*>(callSiteIndex.bits()); 3024 bytecodeOffset = instruction - instructions().begin();3024 bytecodeOffset = this->bytecodeOffset(instruction); 3025 3025 #endif 3026 3026 } else if (jitType == JITCode::DFGJIT || jitType == JITCode::FTLJIT) { -
trunk/Source/JavaScriptCore/bytecode/GetByIdStatus.cpp
r226928 r229815 83 83 VM& vm = *profiledBlock->vm(); 84 84 85 Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex;85 Instruction* instruction = &profiledBlock->instructions()[bytecodeIndex]; 86 86 87 87 Opcode opcode = instruction[0].u.opcode; -
trunk/Source/JavaScriptCore/bytecode/PutByIdStatus.cpp
r226928 r229815 73 73 VM& vm = *profiledBlock->vm(); 74 74 75 Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex;75 Instruction* instruction = &profiledBlock->instructions()[bytecodeIndex]; 76 76 77 77 StructureID structureID = instruction[4].u.structureID; -
trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
r229743 r229815 830 830 // inlined tail call frames, we use SpecFullTop 831 831 // to avoid a spurious OSR exit. 832 Instruction* instruction = m_inlineStackTop->m_profiledBlock->instructions().begin() + bytecodeIndex;832 Instruction* instruction = &m_inlineStackTop->m_profiledBlock->instructions()[bytecodeIndex]; 833 833 OpcodeID opcodeID = Interpreter::getOpcodeID(instruction->u.opcode); 834 834 -
trunk/Source/JavaScriptCore/dfg/DFGOSRExit.cpp
r229609 r229815 808 808 frame.setOperand(inlineCallFrame->stackOffset + CallFrameSlot::callee, JSValue(inlineCallFrame->calleeConstant())); 809 809 #else // USE(JSVALUE64) // so this is the 32-bit part 810 Instruction* instruction = baselineCodeBlock->instructions().begin() + codeOrigin->bytecodeIndex;810 Instruction* instruction = &baselineCodeBlock->instructions()[codeOrigin->bytecodeIndex]; 811 811 uint32_t locationBits = CallSiteIndex(instruction).bits(); 812 812 frame.setOperand<uint32_t>(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount, TagOffset, locationBits); … … 822 822 uint32_t locationBits = CallSiteIndex(codeOrigin->bytecodeIndex).bits(); 823 823 #else 824 Instruction* instruction = outermostBaselineCodeBlock->instructions().begin() + codeOrigin->bytecodeIndex;824 Instruction* instruction = &outermostBaselineCodeBlock->instructions()[codeOrigin->bytecodeIndex]; 825 825 uint32_t locationBits = CallSiteIndex(instruction).bits(); 826 826 #endif -
trunk/Source/JavaScriptCore/dfg/DFGOSRExitCompilerCommon.cpp
r229609 r229815 232 232 #else // USE(JSVALUE64) // so this is the 32-bit part 233 233 jit.storePtr(callerFrameGPR, AssemblyHelpers::addressForByteOffset(inlineCallFrame->callerFrameOffset())); 234 Instruction* instruction = baselineCodeBlock->instructions().begin() + codeOrigin->bytecodeIndex;234 Instruction* instruction = &baselineCodeBlock->instructions()[codeOrigin->bytecodeIndex]; 235 235 uint32_t locationBits = CallSiteIndex(instruction).bits(); 236 236 jit.store32(AssemblyHelpers::TrustedImm32(locationBits), AssemblyHelpers::tagFor((VirtualRegister)(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount))); … … 246 246 uint32_t locationBits = CallSiteIndex(codeOrigin->bytecodeIndex).bits(); 247 247 #else 248 Instruction* instruction = jit.baselineCodeBlock()->instructions().begin() + codeOrigin->bytecodeIndex;248 Instruction* instruction = &jit.baselineCodeBlock()->instructions()[codeOrigin->bytecodeIndex]; 249 249 uint32_t locationBits = CallSiteIndex(instruction).bits(); 250 250 #endif -
trunk/Source/JavaScriptCore/interpreter/CallFrame.cpp
r229810 r229815 122 122 ASSERT(codeBlock()); 123 123 ASSERT(callSiteBitsAreBytecodeOffset()); 124 return c urrentVPC() - codeBlock()->instructions().begin();124 return codeBlock()->bytecodeOffset(currentVPC()); 125 125 } 126 126 … … 129 129 { 130 130 ASSERT(callSiteBitsAreBytecodeOffset()); 131 return codeBlock()->instructions().begin() + callSiteBitsAsBytecodeOffset();131 return &codeBlock()->instructions()[callSiteBitsAsBytecodeOffset()]; 132 132 } 133 133 134 134 void CallFrame::setCurrentVPC(Instruction* vpc) 135 135 { 136 CallSiteIndex callSite( vpc - codeBlock()->instructions().begin());136 CallSiteIndex callSite(codeBlock()->bytecodeOffset(vpc)); 137 137 this[CallFrameSlot::argumentCount].tag() = static_cast<int32_t>(callSite.bits()); 138 138 } -
trunk/Source/JavaScriptCore/jit/JITCall.cpp
r229087 r229815 176 176 } // SP holds newCallFrame + sizeof(CallerFrameAndPC), with ArgumentCount initialized. 177 177 178 uint32_t bytecodeOffset = instruction - m_codeBlock->instructions().begin();178 uint32_t bytecodeOffset = m_codeBlock->bytecodeOffset(instruction); 179 179 uint32_t locationBits = CallSiteIndex(bytecodeOffset).bits(); 180 180 store32(TrustedImm32(locationBits), Address(callFrameRegister, CallFrameSlot::argumentCount * static_cast<int>(sizeof(Register)) + TagOffset)); -
trunk/Source/JavaScriptCore/jit/JITInlines.h
r229767 r229815 139 139 ASSERT(static_cast<int>(m_bytecodeOffset) >= 0); 140 140 #if USE(JSVALUE32_64) 141 Instruction* instruction = m_codeBlock->instructions().begin() + m_bytecodeOffset;141 Instruction* instruction = &m_codeBlock->instructions()[m_bytecodeOffset]; 142 142 uint32_t locationBits = CallSiteIndex(instruction).bits(); 143 143 #else … … 741 741 inline Instruction* JIT::copiedInstruction(Instruction* inst) 742 742 { 743 ASSERT(inst >= m_codeBlock->instructions().begin() && inst < m_codeBlock->instructions().end()); 744 return m_instructions.begin() + (inst - m_codeBlock->instructions().begin()); 743 return &m_instructions[m_codeBlock->bytecodeOffset(inst)]; 745 744 } 746 745 -
trunk/Source/JavaScriptCore/jit/JITOpcodes.cpp
r229609 r229815 1064 1064 void JIT::privateCompileHasIndexedProperty(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode) 1065 1065 { 1066 Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;1066 Instruction* currentInstruction = &m_codeBlock->instructions()[byValInfo->bytecodeIndex]; 1067 1067 1068 1068 PatchableJump badType; -
trunk/Source/JavaScriptCore/jit/JITOpcodes32_64.cpp
r229609 r229815 915 915 void JIT::privateCompileHasIndexedProperty(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode) 916 916 { 917 Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;917 Instruction* currentInstruction = &m_codeBlock->instructions()[byValInfo->bytecodeIndex]; 918 918 919 919 PatchableJump badType; -
trunk/Source/JavaScriptCore/jit/JITPropertyAccess.cpp
r229767 r229815 1223 1223 void JIT::privateCompileGetByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode) 1224 1224 { 1225 Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;1225 Instruction* currentInstruction = &m_codeBlock->instructions()[byValInfo->bytecodeIndex]; 1226 1226 1227 1227 PatchableJump badType; … … 1275 1275 void JIT::privateCompileGetByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, const Identifier& propertyName) 1276 1276 { 1277 Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;1277 Instruction* currentInstruction = &m_codeBlock->instructions()[byValInfo->bytecodeIndex]; 1278 1278 1279 1279 Jump fastDoneCase; … … 1308 1308 void JIT::privateCompilePutByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode) 1309 1309 { 1310 Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;1310 Instruction* currentInstruction = &m_codeBlock->instructions()[byValInfo->bytecodeIndex]; 1311 1311 1312 1312 PatchableJump badType; … … 1367 1367 void JIT::privateCompilePutByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, PutKind putKind, const Identifier& propertyName) 1368 1368 { 1369 Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;1369 Instruction* currentInstruction = &m_codeBlock->instructions()[byValInfo->bytecodeIndex]; 1370 1370 1371 1371 JumpList doneCases; -
trunk/Source/JavaScriptCore/jit/SlowPathCall.h
r229767 r229815 47 47 #if ENABLE(OPCODE_SAMPLING) 48 48 if (m_jit->m_bytecodeOffset != std::numeric_limits<unsigned>::max()) 49 m_jit->sampleInstruction( m_jit->m_codeBlock->instructions().begin() + m_jit->m_bytecodeOffset, true);49 m_jit->sampleInstruction(&m_jit->m_codeBlock->instructions()[m_jit->m_bytecodeOffset], true); 50 50 #endif 51 51 m_jit->updateTopCallFrame(); … … 76 76 #if ENABLE(OPCODE_SAMPLING) 77 77 if (m_jit->m_bytecodeOffset != std::numeric_limits<unsigned>::max()) 78 m_jit->sampleInstruction( m_jit->m_codeBlock->instructions().begin() + m_jit->m_bytecodeOffset, false);78 m_jit->sampleInstruction(&m_jit->m_codeBlock->instructions()[m_jit->m_bytecodeOffset], false); 79 79 #endif 80 80 -
trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
r229547 r229815 197 197 exec->codeBlock(), 198 198 exec, 199 static_cast<intptr_t>( pc - exec->codeBlock()->instructions().begin()),199 static_cast<intptr_t>(exec->codeBlock()->bytecodeOffset(pc)), 200 200 Interpreter::getOpcodeID(pc[0].u.opcode), 201 201 fromWhere, … … 221 221 exec->codeBlock(), 222 222 exec, 223 static_cast<intptr_t>( pc - exec->codeBlock()->instructions().begin()),223 static_cast<intptr_t>(exec->codeBlock()->bytecodeOffset(pc)), 224 224 Interpreter::getOpcodeID(pc[0].u.opcode), 225 225 fromWhere, … … 281 281 exec->codeBlock(), 282 282 exec, 283 static_cast<intptr_t>( pc - exec->codeBlock()->instructions().begin()),283 static_cast<intptr_t>(exec->codeBlock()->bytecodeOffset(pc)), 284 284 opcodeNames[opcodeID], pc); 285 285 if (opcodeID == op_enter) { … … 300 300 exec->codeBlock(), 301 301 exec, 302 static_cast<intptr_t>( pc - exec->codeBlock()->instructions().begin()),302 static_cast<intptr_t>(exec->codeBlock()->bytecodeOffset(pc)), 303 303 Interpreter::getOpcodeID(pc[0].u.opcode), 304 304 exec->returnPC().value()); … … 430 430 } 431 431 432 unsigned loopOSREntryBytecodeOffset = pc - codeBlock->instructions().begin();432 unsigned loopOSREntryBytecodeOffset = codeBlock->bytecodeOffset(pc); 433 433 434 434 if (!shouldJIT(codeBlock)) { … … 440 440 LLINT_RETURN_TWO(0, 0); 441 441 442 CODEBLOCK_LOG_EVENT(codeBlock, "osrEntry", ("at bc#", pc - codeBlock->instructions().begin()));442 CODEBLOCK_LOG_EVENT(codeBlock, "osrEntry", ("at bc#", loopOSREntryBytecodeOffset)); 443 443 444 444 ASSERT(codeBlock->jitType() == JITCode::BaselineJIT); … … 446 446 Vector<BytecodeAndMachineOffset> map; 447 447 codeBlock->jitCodeMap()->decode(map); 448 BytecodeAndMachineOffset* mapping = binarySearch<BytecodeAndMachineOffset, unsigned>(map, map.size(), pc - codeBlock->instructions().begin(), BytecodeAndMachineOffset::getBytecodeIndex);448 BytecodeAndMachineOffset* mapping = binarySearch<BytecodeAndMachineOffset, unsigned>(map, map.size(), loopOSREntryBytecodeOffset, BytecodeAndMachineOffset::getBytecodeIndex); 449 449 ASSERT(mapping); 450 ASSERT(mapping->m_bytecodeIndex == static_cast<unsigned>(pc - codeBlock->instructions().begin()));450 ASSERT(mapping->m_bytecodeIndex == loopOSREntryBytecodeOffset); 451 451 452 452 void* jumpTarget = codeBlock->jitCode()->executableAddressAtOffset(mapping->m_machineCodeOffset); … … 715 715 && ident == vm.propertyNames->length) { 716 716 pc[0].u.opcode = LLInt::getOpcode(op_get_array_length); 717 ArrayProfile* arrayProfile = codeBlock->getOrAddArrayProfile( pc - codeBlock->instructions().begin());717 ArrayProfile* arrayProfile = codeBlock->getOrAddArrayProfile(codeBlock->bytecodeOffset(pc)); 718 718 arrayProfile->observeStructure(baseValue.asCell()->structure()); 719 719 pc[4].u.arrayProfile = arrayProfile; -
trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
r229174 r229815 436 436 #else 437 437 Instruction* instruction = bitwise_cast<Instruction*>(llintPC); 438 if (instruction >= codeBlock->instructions().begin() && instruction < codeBlock->instructions(). begin() + codeBlock->instructionCount()) {438 if (instruction >= codeBlock->instructions().begin() && instruction < codeBlock->instructions().end()) { 439 439 isValid = true; 440 unsigned bytecodeIndex = instruction - codeBlock->instructions().begin(); 441 return bytecodeIndex; 440 return codeBlock->bytecodeOffset(instruction); 442 441 } 443 442 isValid = false;
Note: See TracChangeset
for help on using the changeset viewer.