Title: [230549] trunk/Source/_javascript_Core
Revision
230549
Author
mark....@apple.com
Date
2018-04-11 15:09:09 -0700 (Wed, 11 Apr 2018)

Log Message

Replace CompactJITCodeMap with JITCodeMap.
https://bugs.webkit.org/show_bug.cgi?id=184512
<rdar://problem/35391728>

Reviewed by Filip Pizlo.

* CMakeLists.txt:
* _javascript_Core.xcodeproj/project.pbxproj:
* bytecode/CodeBlock.h:
(JSC::CodeBlock::setJITCodeMap):
(JSC::CodeBlock::jitCodeMap const):
(JSC::CodeBlock::jitCodeMap): Deleted.
* dfg/DFGOSRExit.cpp:
(JSC::DFG::OSRExit::executeOSRExit):
* dfg/DFGOSRExitCompilerCommon.cpp:
(JSC::DFG::adjustAndJumpToTarget):
* jit/AssemblyHelpers.cpp:
(JSC::AssemblyHelpers::decodedCodeMapFor): Deleted.
* jit/AssemblyHelpers.h:
* jit/CompactJITCodeMap.h: Removed.
* jit/JIT.cpp:
(JSC::JIT::link):
* jit/JITCodeMap.h: Added.
(JSC::JITCodeMap::Entry::Entry):
(JSC::JITCodeMap::Entry::bytecodeIndex const):
(JSC::JITCodeMap::Entry::codeLocation):
(JSC::JITCodeMap::append):
(JSC::JITCodeMap::finish):
(JSC::JITCodeMap::find const):
(JSC::JITCodeMap::operator bool const):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::LLINT_SLOW_PATH_DECL):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (230548 => 230549)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2018-04-11 22:09:09 UTC (rev 230549)
@@ -615,7 +615,6 @@
 
     jit/AssemblyHelpers.h
     jit/CCallHelpers.h
-    jit/CompactJITCodeMap.h
     jit/ExecutableAllocator.h
     jit/FPRInfo.h
     jit/GCAwareJITStubRoutine.h
@@ -622,6 +621,7 @@
     jit/GPRInfo.h
     jit/JITAllocator.h
     jit/JITCode.h
+    jit/JITCodeMap.h
     jit/JITCompilationEffort.h
     jit/JITMathICForwards.h
     jit/JITOperations.h

Modified: trunk/Source/_javascript_Core/ChangeLog (230548 => 230549)


--- trunk/Source/_javascript_Core/ChangeLog	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-04-11 22:09:09 UTC (rev 230549)
@@ -1,3 +1,38 @@
+2018-04-11  Mark Lam  <mark....@apple.com>
+
+        Replace CompactJITCodeMap with JITCodeMap.
+        https://bugs.webkit.org/show_bug.cgi?id=184512
+        <rdar://problem/35391728>
+
+        Reviewed by Filip Pizlo.
+
+        * CMakeLists.txt:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * bytecode/CodeBlock.h:
+        (JSC::CodeBlock::setJITCodeMap):
+        (JSC::CodeBlock::jitCodeMap const):
+        (JSC::CodeBlock::jitCodeMap): Deleted.
+        * dfg/DFGOSRExit.cpp:
+        (JSC::DFG::OSRExit::executeOSRExit):
+        * dfg/DFGOSRExitCompilerCommon.cpp:
+        (JSC::DFG::adjustAndJumpToTarget):
+        * jit/AssemblyHelpers.cpp:
+        (JSC::AssemblyHelpers::decodedCodeMapFor): Deleted.
+        * jit/AssemblyHelpers.h:
+        * jit/CompactJITCodeMap.h: Removed.
+        * jit/JIT.cpp:
+        (JSC::JIT::link):
+        * jit/JITCodeMap.h: Added.
+        (JSC::JITCodeMap::Entry::Entry):
+        (JSC::JITCodeMap::Entry::bytecodeIndex const):
+        (JSC::JITCodeMap::Entry::codeLocation):
+        (JSC::JITCodeMap::append):
+        (JSC::JITCodeMap::finish):
+        (JSC::JITCodeMap::find const):
+        (JSC::JITCodeMap::operator bool const):
+        * llint/LLIntSlowPaths.cpp:
+        (JSC::LLInt::LLINT_SLOW_PATH_DECL):
+
 2018-04-11  Yusuke Suzuki  <utatane....@gmail.com>
 
         [DFG] Remove CompareSlowPathGenerator

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (230548 => 230549)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2018-04-11 22:09:09 UTC (rev 230549)
@@ -549,7 +549,6 @@
 		0FD3E40E1B618B6600C80E1E /* PropertyCondition.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD3E4081B618B6600C80E1E /* PropertyCondition.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FD79A2D1EBBBDBB00DA88D3 /* Synchronousness.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD79A2C1EBBBDB200DA88D3 /* Synchronousness.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FD81AD3154FB4F000983E72 /* DFGDominators.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD81AD0154FB4EB00983E72 /* DFGDominators.h */; };
-		0FD82E39141AB14D00179C94 /* CompactJITCodeMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD82E37141AB14200179C94 /* CompactJITCodeMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FD82E54141DAEEE00179C94 /* SpeculatedType.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD82E4F141DAEA100179C94 /* SpeculatedType.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FD82E57141DAF1000179C94 /* DFGOSREntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD82E53141DAEDE00179C94 /* DFGOSREntry.h */; };
 		0FD8A31417D4326C00CA2C40 /* CodeBlockSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD8A31217D4326C00CA2C40 /* CodeBlockSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1755,6 +1754,7 @@
 		FE3A06B41C10CB9300390FDD /* JITBitXorGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3A06B01C10CB6F00390FDD /* JITBitXorGenerator.h */; };
 		FE3A06BE1C11041200390FDD /* JITLeftShiftGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3A06B71C1103D900390FDD /* JITLeftShiftGenerator.h */; };
 		FE3A06C01C11041A00390FDD /* JITRightShiftGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3A06B91C1103D900390FDD /* JITRightShiftGenerator.h */; };
+		FE476FF4207E85D50093CA2D /* JITCodeMap.h in Headers */ = {isa = PBXBuildFile; fileRef = FE476FF3207E85D40093CA2D /* JITCodeMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FE48E6381EB118D2005D7A96 /* ObjectInitializationScope.h in Headers */ = {isa = PBXBuildFile; fileRef = FE48E6361EB1188F005D7A96 /* ObjectInitializationScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FE4BFF2C1AD476E700088F87 /* FunctionOverrides.h in Headers */ = {isa = PBXBuildFile; fileRef = FE4BFF2A1AD476E700088F87 /* FunctionOverrides.h */; };
 		FE4D55B81AE716CA0052E459 /* IterationStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = FE4D55B71AE716CA0052E459 /* IterationStatus.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2709,7 +2709,6 @@
 		0FD81AD0154FB4EB00983E72 /* DFGDominators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGDominators.h; path = dfg/DFGDominators.h; sourceTree = "<group>"; };
 		0FD82E1E14172C2F00179C94 /* DFGCapabilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGCapabilities.cpp; path = dfg/DFGCapabilities.cpp; sourceTree = "<group>"; };
 		0FD82E1F14172C2F00179C94 /* DFGCapabilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGCapabilities.h; path = dfg/DFGCapabilities.h; sourceTree = "<group>"; };
-		0FD82E37141AB14200179C94 /* CompactJITCodeMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompactJITCodeMap.h; sourceTree = "<group>"; };
 		0FD82E4F141DAEA100179C94 /* SpeculatedType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeculatedType.h; sourceTree = "<group>"; };
 		0FD82E52141DAEDE00179C94 /* DFGOSREntry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGOSREntry.cpp; path = dfg/DFGOSREntry.cpp; sourceTree = "<group>"; };
 		0FD82E53141DAEDE00179C94 /* DFGOSREntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGOSREntry.h; path = dfg/DFGOSREntry.h; sourceTree = "<group>"; };
@@ -4680,6 +4679,7 @@
 		FE3A06B81C1103D900390FDD /* JITRightShiftGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITRightShiftGenerator.cpp; sourceTree = "<group>"; };
 		FE3A06B91C1103D900390FDD /* JITRightShiftGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITRightShiftGenerator.h; sourceTree = "<group>"; };
 		FE42388F1BE18C1200514737 /* JITSubGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITSubGenerator.cpp; sourceTree = "<group>"; };
+		FE476FF3207E85D40093CA2D /* JITCodeMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITCodeMap.h; sourceTree = "<group>"; };
 		FE48E6361EB1188F005D7A96 /* ObjectInitializationScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectInitializationScope.h; sourceTree = "<group>"; };
 		FE48E6371EB118AD005D7A96 /* ObjectInitializationScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectInitializationScope.cpp; sourceTree = "<group>"; };
 		FE4BFF291AD476E700088F87 /* FunctionOverrides.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionOverrides.cpp; sourceTree = "<group>"; };
@@ -5477,7 +5477,6 @@
 				62D755D31B84FB39001801FA /* CallFrameShuffler64.cpp */,
 				DC17E8161C9C802B008A6AB3 /* CCallHelpers.cpp */,
 				0F24E53D17EA9F5900ABB217 /* CCallHelpers.h */,
-				0FD82E37141AB14200179C94 /* CompactJITCodeMap.h */,
 				0FF054F71AC35B4400E5BE57 /* ExecutableAllocationFuzz.cpp */,
 				0FF054F81AC35B4400E5BE57 /* ExecutableAllocationFuzz.h */,
 				A7B48DB60EE74CFC00DCBDB6 /* ExecutableAllocator.cpp */,
@@ -5510,6 +5509,7 @@
 				146FE51111A710430087AE66 /* JITCall32_64.cpp */,
 				0F8F94431667635200D61971 /* JITCode.cpp */,
 				86CCEFDD0F413F8900FD7F9E /* JITCode.h */,
+				FE476FF3207E85D40093CA2D /* JITCodeMap.h */,
 				0F0776BD14FF002800102332 /* JITCompilationEffort.h */,
 				0FAF7EFA165BA919000C8455 /* JITDisassembler.cpp */,
 				0FAF7EFB165BA919000C8455 /* JITDisassembler.h */,
@@ -8417,7 +8417,6 @@
 				BC18C3F30E16F5CD00B34460 /* CommonIdentifiers.h in Headers */,
 				0F15F15F14B7A73E005DE37D /* CommonSlowPaths.h in Headers */,
 				6553A33217A1F1EE008CF6F3 /* CommonSlowPathsExceptions.h in Headers */,
-				0FD82E39141AB14D00179C94 /* CompactJITCodeMap.h in Headers */,
 				A7E5A3A81797432D00E893C0 /* CompilationResult.h in Headers */,
 				0FDCE12A1FAFA85F006F3901 /* CompleteSubspace.h in Headers */,
 				BC18C3F40E16F5CD00B34460 /* Completion.h in Headers */,
@@ -8737,6 +8736,7 @@
 				0F25F1B4181635F300522F39 /* FTLSlowPathCallKey.h in Headers */,
 				E322E5A71DA644A8006E7709 /* FTLSnippetParams.h in Headers */,
 				0F235BD717178E1C00690C7F /* FTLStackmapArgumentList.h in Headers */,
+				FE476FF4207E85D50093CA2D /* JITCodeMap.h in Headers */,
 				0FEA0A12170513DB00BB722C /* FTLState.h in Headers */,
 				A7FCC26D17A0B6AA00786D1A /* FTLSwitchCase.h in Headers */,
 				0F235BE217178E1C00690C7F /* FTLThunks.h in Headers */,

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.h (230548 => 230549)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2018-04-11 22:09:09 UTC (rev 230549)
@@ -36,7 +36,6 @@
 #include "CodeBlockHash.h"
 #include "CodeOrigin.h"
 #include "CodeType.h"
-#include "CompactJITCodeMap.h"
 #include "CompilationResult.h"
 #include "ConcurrentJSLock.h"
 #include "DFGCommon.h"
@@ -48,6 +47,7 @@
 #include "HandlerInfo.h"
 #include "Instruction.h"
 #include "JITCode.h"
+#include "JITCodeMap.h"
 #include "JITMathICForwards.h"
 #include "JSCPoison.h"
 #include "JSCast.h"
@@ -301,13 +301,13 @@
 
     void linkIncomingCall(ExecState* callerFrame, LLIntCallLinkInfo*);
 
-    void setJITCodeMap(std::unique_ptr<CompactJITCodeMap> jitCodeMap)
+    void setJITCodeMap(JITCodeMap&& jitCodeMap)
     {
         m_jitCodeMap = WTFMove(jitCodeMap);
     }
-    CompactJITCodeMap* jitCodeMap()
+    const JITCodeMap& jitCodeMap() const
     {
-        return m_jitCodeMap.get();
+        return m_jitCodeMap;
     }
     
     typedef JSC::Instruction Instruction;
@@ -987,7 +987,7 @@
     SentinelLinkedList<PolymorphicCallNode, BasicRawSentinelNode<PolymorphicCallNode>> m_incomingPolymorphicCalls;
     std::unique_ptr<PCToCodeOriginMap> m_pcToCodeOriginMap;
 #endif
-    std::unique_ptr<CompactJITCodeMap> m_jitCodeMap;
+    JITCodeMap m_jitCodeMap;
 #if ENABLE(DFG_JIT)
     // This is relevant to non-DFG code blocks that serve as the profiled code block
     // for DFG code blocks.

Modified: trunk/Source/_javascript_Core/dfg/DFGOSRExit.cpp (230548 => 230549)


--- trunk/Source/_javascript_Core/dfg/DFGOSRExit.cpp	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/dfg/DFGOSRExit.cpp	2018-04-11 22:09:09 UTC (rev 230549)
@@ -389,16 +389,13 @@
         adjustedThreshold = BaselineExecutionCounter::clippedThreshold(codeBlock->globalObject(), adjustedThreshold);
 
         CodeBlock* codeBlockForExit = baselineCodeBlockForOriginAndBaselineCodeBlock(exit.m_codeOrigin, baselineCodeBlock);
-        Vector<BytecodeAndMachineOffset> decodedCodeMap;
-        codeBlockForExit->jitCodeMap()->decode(decodedCodeMap);
+        const JITCodeMap& codeMap = codeBlockForExit->jitCodeMap();
+        CodeLocationLabel codeLocation = codeMap.find(exit.m_codeOrigin.bytecodeIndex);
+        ASSERT(codeLocation);
 
-        BytecodeAndMachineOffset* mapping = binarySearch<BytecodeAndMachineOffset, unsigned>(decodedCodeMap, decodedCodeMap.size(), exit.m_codeOrigin.bytecodeIndex, BytecodeAndMachineOffset::getBytecodeIndex);
+        PtrTag locationTag = ptrTag(CodeEntryPtrTag, codeBlockForExit, exit.m_codeOrigin.bytecodeIndex);
+        void* jumpTarget = codeLocation.retagged(locationTag, CodeEntryPtrTag).executableAddress();
 
-        ASSERT(mapping);
-        ASSERT(mapping->m_bytecodeIndex == exit.m_codeOrigin.bytecodeIndex);
-
-        void* jumpTarget = codeBlockForExit->jitCode()->executableAddressAtOffset(mapping->m_machineCodeOffset);
-
         // Compute the value recoveries.
         Operands<ValueRecovery> operands;
         Vector<UndefinedOperandSpan> undefinedOperandSpans;

Modified: trunk/Source/_javascript_Core/dfg/DFGOSRExitCompilerCommon.cpp (230548 => 230549)


--- trunk/Source/_javascript_Core/dfg/DFGOSRExitCompilerCommon.cpp	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/dfg/DFGOSRExitCompilerCommon.cpp	2018-04-11 22:09:09 UTC (rev 230549)
@@ -317,16 +317,14 @@
         jit.addPtr(AssemblyHelpers::TrustedImm32(exit.m_codeOrigin.inlineCallFrame->stackOffset * sizeof(EncodedJSValue)), GPRInfo::callFrameRegister);
 
     CodeBlock* codeBlockForExit = jit.baselineCodeBlockFor(exit.m_codeOrigin);
-    Vector<BytecodeAndMachineOffset>& decodedCodeMap = jit.decodedCodeMapFor(codeBlockForExit);
-    
-    BytecodeAndMachineOffset* mapping = binarySearch<BytecodeAndMachineOffset, unsigned>(decodedCodeMap, decodedCodeMap.size(), exit.m_codeOrigin.bytecodeIndex, BytecodeAndMachineOffset::getBytecodeIndex);
-    
-    ASSERT(mapping);
-    ASSERT(mapping->m_bytecodeIndex == exit.m_codeOrigin.bytecodeIndex);
+    ASSERT(codeBlockForExit == codeBlockForExit->baselineVersion());
+    ASSERT(codeBlockForExit->jitType() == JITCode::BaselineJIT);
+    CodeLocationLabel codeLocation = codeBlockForExit->jitCodeMap().find(exit.m_codeOrigin.bytecodeIndex);
+    ASSERT(codeLocation);
 
+    PtrTag locationTag = ptrTag(CodeEntryPtrTag, codeBlockForExit, exit.m_codeOrigin.bytecodeIndex);
     PtrTag exitTag = ptrTag(DFGOSRExitPtrTag, nextPtrTagID());
-    void* jumpTarget = retagCodePtr(codeBlockForExit->jitCode()->executableAddressAtOffset(mapping->m_machineCodeOffset), CodeEntryPtrTag, exitTag);
-
+    void* jumpTarget = codeLocation.retagged(locationTag, exitTag).executableAddress();
     jit.addPtr(AssemblyHelpers::TrustedImm32(JIT::stackPointerOffsetFor(codeBlockForExit) * sizeof(Register)), GPRInfo::callFrameRegister, AssemblyHelpers::stackPointerRegister);
     if (exit.isExceptionHandler()) {
         // Since we're jumping to op_catch, we need to set callFrameForCatch.

Modified: trunk/Source/_javascript_Core/jit/AssemblyHelpers.cpp (230548 => 230549)


--- trunk/Source/_javascript_Core/jit/AssemblyHelpers.cpp	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/jit/AssemblyHelpers.cpp	2018-04-11 22:09:09 UTC (rev 230549)
@@ -50,20 +50,6 @@
     return codeOrigin.inlineCallFrame->baselineCodeBlock->ownerExecutable();
 }
 
-Vector<BytecodeAndMachineOffset>& AssemblyHelpers::decodedCodeMapFor(CodeBlock* codeBlock)
-{
-    ASSERT(codeBlock == codeBlock->baselineVersion());
-    ASSERT(codeBlock->jitType() == JITCode::BaselineJIT);
-    ASSERT(codeBlock->jitCodeMap());
-    
-    HashMap<CodeBlock*, Vector<BytecodeAndMachineOffset>>::AddResult result = m_decodedCodeMaps.add(codeBlock, Vector<BytecodeAndMachineOffset>());
-    
-    if (result.isNewEntry)
-        codeBlock->jitCodeMap()->decode(result.iterator->value);
-    
-    return result.iterator->value;
-}
-
 AssemblyHelpers::JumpList AssemblyHelpers::branchIfNotType(
     JSValueRegs regs, GPRReg tempGPR, const InferredType::Descriptor& descriptor, TagRegistersMode mode)
 {

Modified: trunk/Source/_javascript_Core/jit/AssemblyHelpers.h (230548 => 230549)


--- trunk/Source/_javascript_Core/jit/AssemblyHelpers.h	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/jit/AssemblyHelpers.h	2018-04-11 22:09:09 UTC (rev 230549)
@@ -1538,8 +1538,6 @@
     
     void emitDumbVirtualCall(VM&, CallLinkInfo*);
     
-    Vector<BytecodeAndMachineOffset>& decodedCodeMapFor(CodeBlock*);
-
     void makeSpaceOnStackForCCall();
     void reclaimSpaceOnStackForCCall();
 
@@ -1661,8 +1659,6 @@
 
     CodeBlock* m_codeBlock;
     CodeBlock* m_baselineCodeBlock;
-
-    HashMap<CodeBlock*, Vector<BytecodeAndMachineOffset>> m_decodedCodeMaps;
 };
 
 } // namespace JSC

Deleted: trunk/Source/_javascript_Core/jit/CompactJITCodeMap.h (230548 => 230549)


--- trunk/Source/_javascript_Core/jit/CompactJITCodeMap.h	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/jit/CompactJITCodeMap.h	2018-04-11 22:09:09 UTC (rev 230549)
@@ -1,292 +0,0 @@
-/*
- * Copyright (C) 2011 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 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.
- */
-
-#pragma once
-
-#include <wtf/Assertions.h>
-#include <wtf/FastMalloc.h>
-#include <wtf/FastMalloc.h>
-#include <wtf/Vector.h>
-
-namespace JSC {
-
-// Gives you a compressed map between between bytecode indices and machine code
-// entry points. The compression simply tries to use either 1, 2, or 4 bytes for
-// any given offset. The largest offset that can be stored is 2^30.
-
-// Example use:
-//
-// CompactJITCodeMap::Encoder encoder(map);
-// encoder.append(a, b);
-// encoder.append(c, d); // preconditions: c >= a, d >= b
-// auto map = encoder.finish();
-//
-// At some later time:
-//
-// Vector<BytecodeAndMachineOffset> decoded;
-// map->decode(decoded);
-
-struct BytecodeAndMachineOffset {
-    BytecodeAndMachineOffset() { }
-    
-    BytecodeAndMachineOffset(unsigned bytecodeIndex, unsigned machineCodeOffset)
-        : m_bytecodeIndex(bytecodeIndex)
-        , m_machineCodeOffset(machineCodeOffset)
-    {
-    }
-    
-    unsigned m_bytecodeIndex;
-    unsigned m_machineCodeOffset;
-    
-    static inline unsigned getBytecodeIndex(BytecodeAndMachineOffset* mapping)
-    {
-        return mapping->m_bytecodeIndex;
-    }
-    
-    static inline unsigned getMachineCodeOffset(BytecodeAndMachineOffset* mapping)
-    {
-        return mapping->m_machineCodeOffset;
-    }
-};
-
-class CompactJITCodeMap {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    CompactJITCodeMap(uint8_t* buffer, unsigned size, unsigned numberOfEntries)
-        : m_buffer(buffer)
-#if !ASSERT_DISABLED
-        , m_size(size)
-#endif
-        , m_numberOfEntries(numberOfEntries)
-    {
-        UNUSED_PARAM(size);
-    }
-
-    ~CompactJITCodeMap()
-    {
-        if (m_buffer)
-            fastFree(m_buffer);
-    }
-    
-    unsigned numberOfEntries() const
-    {
-        return m_numberOfEntries;
-    }
-    
-    void decode(Vector<BytecodeAndMachineOffset>& result) const;
-    
-private:
-    uint8_t at(unsigned index) const
-    {
-        ASSERT(index < m_size);
-        return m_buffer[index];
-    }
-    
-    unsigned decodeNumber(unsigned& index) const
-    {
-        uint8_t headValue = at(index++);
-        if (!(headValue & 128))
-            return headValue;
-        if (!(headValue & 64))
-            return (static_cast<unsigned>(headValue & ~128) << 8) | at(index++);
-        unsigned second = at(index++);
-        unsigned third  = at(index++);
-        unsigned fourth = at(index++);
-        return (static_cast<unsigned>(headValue & ~(128 + 64)) << 24) | (second << 16) | (third << 8) | fourth;
-    }
-    
-    uint8_t* m_buffer;
-#if !ASSERT_DISABLED
-    unsigned m_size;
-#endif
-    unsigned m_numberOfEntries;
-    
-public:
-    class Encoder {
-        WTF_MAKE_NONCOPYABLE(Encoder);
-    public:
-        Encoder();
-        ~Encoder();
-        
-        void ensureCapacityFor(unsigned numberOfEntriesToAdd);
-        void append(unsigned bytecodeIndex, unsigned machineCodeOffset);
-        std::unique_ptr<CompactJITCodeMap> finish();
-
-    private:
-        void appendByte(uint8_t value);
-        void encodeNumber(uint32_t value);
-    
-        uint8_t* m_buffer;
-        unsigned m_size;
-        unsigned m_capacity;
-        unsigned m_numberOfEntries;
-        
-        unsigned m_previousBytecodeIndex;
-        unsigned m_previousMachineCodeOffset;
-    };
-    
-    class Decoder {
-        WTF_MAKE_NONCOPYABLE(Decoder);
-    public:
-        Decoder(const CompactJITCodeMap*);
-        
-        unsigned numberOfEntriesRemaining() const;
-        void read(unsigned& bytecodeIndex, unsigned& machineCodeOffset);
-        
-    private:
-        const CompactJITCodeMap* m_jitCodeMap;
-        unsigned m_previousBytecodeIndex;
-        unsigned m_previousMachineCodeOffset;
-        unsigned m_numberOfEntriesRemaining;
-        unsigned m_bufferIndex;
-    };
-
-private:
-    friend class Encoder;
-    friend class Decoder;
-};
-
-inline void CompactJITCodeMap::decode(Vector<BytecodeAndMachineOffset>& result) const
-{
-    Decoder decoder(this);
-    result.resize(decoder.numberOfEntriesRemaining());
-    for (unsigned i = 0; i < result.size(); ++i)
-        decoder.read(result[i].m_bytecodeIndex, result[i].m_machineCodeOffset);
-    
-    ASSERT(!decoder.numberOfEntriesRemaining());
-}
-
-inline CompactJITCodeMap::Encoder::Encoder()
-    : m_buffer(0)
-    , m_size(0)
-    , m_capacity(0)
-    , m_numberOfEntries(0)
-    , m_previousBytecodeIndex(0)
-    , m_previousMachineCodeOffset(0)
-{
-}
-
-inline CompactJITCodeMap::Encoder::~Encoder()
-{
-    if (m_buffer)
-        fastFree(m_buffer);
-}
-        
-inline void CompactJITCodeMap::Encoder::append(unsigned bytecodeIndex, unsigned machineCodeOffset)
-{
-    ASSERT(bytecodeIndex >= m_previousBytecodeIndex);
-    ASSERT(machineCodeOffset >= m_previousMachineCodeOffset);
-    ensureCapacityFor(1);
-    encodeNumber(bytecodeIndex - m_previousBytecodeIndex);
-    encodeNumber(machineCodeOffset - m_previousMachineCodeOffset);
-    m_previousBytecodeIndex = bytecodeIndex;
-    m_previousMachineCodeOffset = machineCodeOffset;
-    m_numberOfEntries++;
-}
-
-inline std::unique_ptr<CompactJITCodeMap> CompactJITCodeMap::Encoder::finish()
-{
-    m_capacity = m_size;
-    m_buffer = static_cast<uint8_t*>(fastRealloc(m_buffer, m_capacity));
-    auto result = std::make_unique<CompactJITCodeMap>(m_buffer, m_size, m_numberOfEntries);
-    m_buffer = 0;
-    m_size = 0;
-    m_capacity = 0;
-    m_numberOfEntries = 0;
-    m_previousBytecodeIndex = 0;
-    m_previousMachineCodeOffset = 0;
-    return result;
-}
-        
-inline void CompactJITCodeMap::Encoder::appendByte(uint8_t value)
-{
-    ASSERT(m_size + 1 <= m_capacity);
-    m_buffer[m_size++] = value;
-}
-    
-inline void CompactJITCodeMap::Encoder::encodeNumber(uint32_t value)
-{
-    ASSERT(m_size + 4 <= m_capacity);
-    ASSERT(value < (1 << 30));
-    if (value <= 127) {
-        uint8_t headValue = static_cast<uint8_t>(value);
-        ASSERT(!(headValue & 128));
-        appendByte(headValue);
-    } else if (value <= 16383) {
-        uint8_t headValue = static_cast<uint8_t>(value >> 8);
-        ASSERT(!(headValue & 128));
-        ASSERT(!(headValue & 64));
-        appendByte(headValue | 128);
-        appendByte(static_cast<uint8_t>(value));
-    } else {
-        uint8_t headValue = static_cast<uint8_t>(value >> 24);
-        ASSERT(!(headValue & 128));
-        ASSERT(!(headValue & 64));
-        appendByte(headValue | 128 | 64);
-        appendByte(static_cast<uint8_t>(value >> 16));
-        appendByte(static_cast<uint8_t>(value >> 8));
-        appendByte(static_cast<uint8_t>(value));
-    }
-}
-
-inline void CompactJITCodeMap::Encoder::ensureCapacityFor(unsigned numberOfEntriesToAdd)
-{
-    unsigned capacityNeeded = m_size + numberOfEntriesToAdd * 2 * 4;
-    if (capacityNeeded > m_capacity) {
-        m_capacity = capacityNeeded * 2;
-        m_buffer = static_cast<uint8_t*>(fastRealloc(m_buffer, m_capacity));
-    }
-}
-
-inline CompactJITCodeMap::Decoder::Decoder(const CompactJITCodeMap* jitCodeMap)
-    : m_jitCodeMap(jitCodeMap)
-    , m_previousBytecodeIndex(0)
-    , m_previousMachineCodeOffset(0)
-    , m_numberOfEntriesRemaining(jitCodeMap->m_numberOfEntries)
-    , m_bufferIndex(0)
-{
-}
-
-inline unsigned CompactJITCodeMap::Decoder::numberOfEntriesRemaining() const
-{
-    ASSERT(m_numberOfEntriesRemaining || m_bufferIndex == m_jitCodeMap->m_size);
-    return m_numberOfEntriesRemaining;
-}
-
-inline void CompactJITCodeMap::Decoder::read(unsigned& bytecodeIndex, unsigned& machineCodeOffset)
-{
-    ASSERT(numberOfEntriesRemaining());
-    
-    m_previousBytecodeIndex += m_jitCodeMap->decodeNumber(m_bufferIndex);
-    m_previousMachineCodeOffset += m_jitCodeMap->decodeNumber(m_bufferIndex);
-    bytecodeIndex = m_previousBytecodeIndex;
-    machineCodeOffset = m_previousMachineCodeOffset;
-    m_numberOfEntriesRemaining--;
-}
-
-} // namespace JSC

Modified: trunk/Source/_javascript_Core/jit/JIT.cpp (230548 => 230549)


--- trunk/Source/_javascript_Core/jit/JIT.cpp	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/jit/JIT.cpp	2018-04-11 22:09:09 UTC (rev 230549)
@@ -866,12 +866,15 @@
             patchBuffer.locationOfNearCall(compilationInfo.hotPathOther));
     }
 
-    CompactJITCodeMap::Encoder jitCodeMapEncoder;
+    JITCodeMap jitCodeMap;
     for (unsigned bytecodeOffset = 0; bytecodeOffset < m_labels.size(); ++bytecodeOffset) {
-        if (m_labels[bytecodeOffset].isSet())
-            jitCodeMapEncoder.append(bytecodeOffset, patchBuffer.offsetOf(m_labels[bytecodeOffset]));
+        if (m_labels[bytecodeOffset].isSet()) {
+            PtrTag tag = ptrTag(CodeEntryPtrTag, m_codeBlock, bytecodeOffset);
+            jitCodeMap.append(bytecodeOffset, patchBuffer.locationOf(m_labels[bytecodeOffset], tag));
+        }
     }
-    m_codeBlock->setJITCodeMap(jitCodeMapEncoder.finish());
+    jitCodeMap.finish();
+    m_codeBlock->setJITCodeMap(WTFMove(jitCodeMap));
 
     MacroAssemblerCodePtr withArityCheck = patchBuffer.locationOf(m_arityCheck, CodeEntryWithArityCheckPtrTag);
 

Added: trunk/Source/_javascript_Core/jit/JITCodeMap.h (0 => 230549)


--- trunk/Source/_javascript_Core/jit/JITCodeMap.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/jit/JITCodeMap.h	2018-04-11 22:09:09 UTC (rev 230549)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2018 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. 
+ */
+
+#pragma once
+
+#include "CodeLocation.h"
+#include <wtf/StdLibExtras.h>
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+class JITCodeMap {
+private:
+    struct Entry {
+        Entry() { }
+
+        Entry(unsigned bytecodeIndex, CodeLocationLabel codeLocation)
+            : m_bytecodeIndex(bytecodeIndex)
+            , m_codeLocation(codeLocation)
+        { }
+
+        inline unsigned bytecodeIndex() const { return m_bytecodeIndex; }
+        inline CodeLocationLabel codeLocation() { return m_codeLocation; }
+
+    private:
+        unsigned m_bytecodeIndex;
+        CodeLocationLabel m_codeLocation;
+    };
+
+public:
+    void append(unsigned bytecodeIndex, CodeLocationLabel codeLocation)
+    {
+        m_entries.append({ bytecodeIndex, codeLocation });
+    }
+
+    void finish() { m_entries.shrinkToFit(); }
+
+    CodeLocationLabel find(unsigned bytecodeIndex) const
+    {
+        auto* entry =
+            binarySearch<Entry, unsigned>(m_entries,
+                m_entries.size(), bytecodeIndex, [] (Entry* entry) {
+                    return entry->bytecodeIndex();
+                });
+        if (!entry)
+            return CodeLocationLabel();
+        return entry->codeLocation();
+    }
+
+    explicit operator bool() const { return m_entries.size(); }
+
+private:
+    Vector<Entry> m_entries;
+};
+
+} // namespace JSC

Modified: trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp (230548 => 230549)


--- trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2018-04-11 21:49:28 UTC (rev 230548)
+++ trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2018-04-11 22:09:09 UTC (rev 230549)
@@ -442,14 +442,13 @@
     CODEBLOCK_LOG_EVENT(codeBlock, "osrEntry", ("at bc#", loopOSREntryBytecodeOffset));
 
     ASSERT(codeBlock->jitType() == JITCode::BaselineJIT);
-    
-    Vector<BytecodeAndMachineOffset> map;
-    codeBlock->jitCodeMap()->decode(map);
-    BytecodeAndMachineOffset* mapping = binarySearch<BytecodeAndMachineOffset, unsigned>(map, map.size(), loopOSREntryBytecodeOffset, BytecodeAndMachineOffset::getBytecodeIndex);
-    ASSERT(mapping);
-    ASSERT(mapping->m_bytecodeIndex == loopOSREntryBytecodeOffset);
-    
-    void* jumpTarget = codeBlock->jitCode()->executableAddressAtOffset(mapping->m_machineCodeOffset);
+
+    const JITCodeMap& codeMap = codeBlock->jitCodeMap();
+    CodeLocationLabel codeLocation = codeMap.find(loopOSREntryBytecodeOffset);
+    ASSERT(codeLocation);
+
+    PtrTag locationTag = ptrTag(CodeEntryPtrTag, codeBlock, loopOSREntryBytecodeOffset);
+    void* jumpTarget = codeLocation.retagged(locationTag, CodeEntryPtrTag).executableAddress();
     ASSERT(jumpTarget);
     
     LLINT_RETURN_TWO(jumpTarget, exec->topOfFrame());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to