Skip to content

Commit 2e87117

Browse files
[JSC] Use FixedVector in JITConstantPool
https://bugs.webkit.org/show_bug.cgi?id=230937 Reviewed by Keith Miller. This patch changes JITConstantPool to use FixedVector. This allocates exact size of memory and Making sizeof(JITConstantPool) smaller. We also use CompactPointerTuple for JITConstantPool::Value since it is faster for access. To achieve that, in JIT, we append Value to normal Vector. And when finalizing BaselineJITCode we construct JITConstantPool from that Vector. * bytecode/CodeBlock.cpp: (JSC::CodeBlock::setupWithUnlinkedBaselineCode): * jit/BaselineJITCode.h: (JSC::JITConstantPool::JITConstantPool): (JSC::JITConstantPool::add): Deleted. * jit/JIT.cpp: (JSC::JIT::JIT): (JSC::JIT::addToConstantPool): * jit/JIT.h: * jit/JITCall.cpp: (JSC::JIT::compileOpCall): (JSC::JIT::emit_op_iterator_open): (JSC::JIT::emit_op_iterator_next): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_instanceof): (JSC::JIT::emitNewFuncCommon): (JSC::JIT::emitNewFuncExprCommon): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_by_val): (JSC::JIT::emit_op_get_private_name): (JSC::JIT::emit_op_set_private_brand): (JSC::JIT::emit_op_check_private_brand): (JSC::JIT::emit_op_put_by_val): (JSC::JIT::emit_op_put_private_name): (JSC::JIT::emit_op_del_by_id): (JSC::JIT::emit_op_del_by_val): (JSC::JIT::emit_op_try_get_by_id): (JSC::JIT::emit_op_get_by_id_direct): (JSC::JIT::emit_op_get_by_id): (JSC::JIT::emit_op_get_by_id_with_this): (JSC::JIT::emit_op_put_by_id): (JSC::JIT::emit_op_in_by_id): (JSC::JIT::emit_op_in_by_val): (JSC::JIT::emitHasPrivate): (JSC::JIT::emit_op_enumerator_get_by_val): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@283229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 7dbb954 commit 2e87117

File tree

8 files changed

+96
-40
lines changed

8 files changed

+96
-40
lines changed

Source/JavaScriptCore/ChangeLog

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
2021-09-29 Yusuke Suzuki <[email protected]>
2+
3+
[JSC] Use FixedVector in JITConstantPool
4+
https://bugs.webkit.org/show_bug.cgi?id=230937
5+
6+
Reviewed by Keith Miller.
7+
8+
This patch changes JITConstantPool to use FixedVector. This allocates exact size
9+
of memory and Making sizeof(JITConstantPool) smaller. We also use CompactPointerTuple
10+
for JITConstantPool::Value since it is faster for access.
11+
12+
To achieve that, in JIT, we append Value to normal Vector. And when finalizing BaselineJITCode
13+
we construct JITConstantPool from that Vector.
14+
15+
* bytecode/CodeBlock.cpp:
16+
(JSC::CodeBlock::setupWithUnlinkedBaselineCode):
17+
* jit/BaselineJITCode.h:
18+
(JSC::JITConstantPool::JITConstantPool):
19+
(JSC::JITConstantPool::add): Deleted.
20+
* jit/JIT.cpp:
21+
(JSC::JIT::JIT):
22+
(JSC::JIT::addToConstantPool):
23+
* jit/JIT.h:
24+
* jit/JITCall.cpp:
25+
(JSC::JIT::compileOpCall):
26+
(JSC::JIT::emit_op_iterator_open):
27+
(JSC::JIT::emit_op_iterator_next):
28+
* jit/JITOpcodes.cpp:
29+
(JSC::JIT::emit_op_instanceof):
30+
(JSC::JIT::emitNewFuncCommon):
31+
(JSC::JIT::emitNewFuncExprCommon):
32+
* jit/JITPropertyAccess.cpp:
33+
(JSC::JIT::emit_op_get_by_val):
34+
(JSC::JIT::emit_op_get_private_name):
35+
(JSC::JIT::emit_op_set_private_brand):
36+
(JSC::JIT::emit_op_check_private_brand):
37+
(JSC::JIT::emit_op_put_by_val):
38+
(JSC::JIT::emit_op_put_private_name):
39+
(JSC::JIT::emit_op_del_by_id):
40+
(JSC::JIT::emit_op_del_by_val):
41+
(JSC::JIT::emit_op_try_get_by_id):
42+
(JSC::JIT::emit_op_get_by_id_direct):
43+
(JSC::JIT::emit_op_get_by_id):
44+
(JSC::JIT::emit_op_get_by_id_with_this):
45+
(JSC::JIT::emit_op_put_by_id):
46+
(JSC::JIT::emit_op_in_by_id):
47+
(JSC::JIT::emit_op_in_by_val):
48+
(JSC::JIT::emitHasPrivate):
49+
(JSC::JIT::emit_op_enumerator_get_by_val):
50+
151
2021-09-28 Saam Barati <[email protected]>
252

353
DoesGCCheck does not use enough bits for nodeIndex

Source/JavaScriptCore/bytecode/CodeBlock.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,31 +805,31 @@ void CodeBlock::setupWithUnlinkedBaselineCode(Ref<BaselineJITCode> jitCode)
805805
jitData.m_jitConstantPool = FixedVector<void*>(jitCode->m_constantPool.size());
806806
for (size_t i = 0; i < jitCode->m_constantPool.size(); ++i) {
807807
auto entry = jitCode->m_constantPool.at(i);
808-
switch (entry.type) {
808+
switch (entry.type()) {
809809
case JITConstantPool::Type::GlobalObject:
810810
jitData.m_jitConstantPool[i] = m_globalObject.get();
811811
break;
812812
case JITConstantPool::Type::CallLinkInfo: {
813-
UnlinkedCallLinkInfo& unlinkedCallLinkInfo = *static_cast<UnlinkedCallLinkInfo*>(entry.payload.get());
813+
UnlinkedCallLinkInfo& unlinkedCallLinkInfo = *static_cast<UnlinkedCallLinkInfo*>(entry.pointer());
814814
CallLinkInfo* callLinkInfo = jitData.m_callLinkInfos.add(CodeOrigin(unlinkedCallLinkInfo.bytecodeIndex));
815815
callLinkInfo->initializeDataIC(vm(), unlinkedCallLinkInfo, GPRInfo::regT0, GPRInfo::regT2);
816816
jitData.m_jitConstantPool[i] = callLinkInfo;
817817
break;
818818
}
819819
case JITConstantPool::Type::StructureStubInfo: {
820-
UnlinkedStructureStubInfo& unlinkedStubInfo = *static_cast<UnlinkedStructureStubInfo*>(entry.payload.get());
820+
UnlinkedStructureStubInfo& unlinkedStubInfo = *static_cast<UnlinkedStructureStubInfo*>(entry.pointer());
821821
StructureStubInfo* stubInfo = jitData.m_stubInfos.add(unlinkedStubInfo.accessType, CodeOrigin(unlinkedStubInfo.bytecodeIndex));
822822
stubInfo->initializeFromUnlinkedStructureStubInfo(this, unlinkedStubInfo);
823823
jitData.m_jitConstantPool[i] = stubInfo;
824824
break;
825825
}
826826
case JITConstantPool::Type::FunctionDecl: {
827-
unsigned index = bitwise_cast<uintptr_t>(entry.payload.get());
827+
unsigned index = bitwise_cast<uintptr_t>(entry.pointer());
828828
jitData.m_jitConstantPool[i] = functionDecl(index);
829829
break;
830830
}
831831
case JITConstantPool::Type::FunctionExpr: {
832-
unsigned index = bitwise_cast<uintptr_t>(entry.payload.get());
832+
unsigned index = bitwise_cast<uintptr_t>(entry.pointer());
833833
jitData.m_jitConstantPool[i] = functionExpr(index);
834834
break;
835835
}

Source/JavaScriptCore/jit/BaselineJITCode.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "CallLinkInfo.h"
2929
#include "JITCode.h"
3030
#include "JITCodeMap.h"
31+
#include <wtf/CompactPointerTuple.h>
3132

3233
#if ENABLE(JIT)
3334

@@ -55,6 +56,7 @@ class MathICHolder {
5556
};
5657

5758
class JITConstantPool {
59+
WTF_MAKE_NONCOPYABLE(JITConstantPool);
5860
public:
5961
using Constant = unsigned;
6062

@@ -66,27 +68,22 @@ class JITConstantPool {
6668
FunctionExpr,
6769
};
6870

69-
struct Value {
70-
Type type;
71-
PackedPtr<void> payload;
72-
};
71+
using Value = CompactPointerTuple<void*, Type>;
7372

7473
JITConstantPool() = default;
7574
JITConstantPool(JITConstantPool&&) = default;
7675
JITConstantPool& operator=(JITConstantPool&&) = default;
7776

78-
Constant add(Type type, void* payload = nullptr)
77+
JITConstantPool(Vector<Value>&& constants)
78+
: m_constants(WTFMove(constants))
7979
{
80-
unsigned result = m_constants.size();
81-
m_constants.append(Value { type, payload });
82-
return result;
8380
}
8481

8582
size_t size() const { return m_constants.size(); }
8683
Value at(size_t i) const { return m_constants[i]; }
8784

8885
private:
89-
Vector<Value> m_constants;
86+
FixedVector<Value> m_constants;
9087
};
9188

9289

Source/JavaScriptCore/jit/JIT.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ JIT::JIT(VM& vm, CodeBlock* codeBlock, BytecodeIndex loopOSREntryBytecodeIndex)
7777
, m_shouldEmitProfiling(false)
7878
, m_loopOSREntryBytecodeIndex(loopOSREntryBytecodeIndex)
7979
{
80-
m_globalObjectConstant = m_constantPool.add(JITConstantPool::Type::GlobalObject);
80+
m_globalObjectConstant = addToConstantPool(JITConstantPool::Type::GlobalObject);
8181
m_profiledCodeBlock = codeBlock;
8282
m_unlinkedCodeBlock = codeBlock->unlinkedCodeBlock();
8383
}
@@ -86,6 +86,13 @@ JIT::~JIT()
8686
{
8787
}
8888

89+
JITConstantPool::Constant JIT::addToConstantPool(JITConstantPool::Type type, void* payload)
90+
{
91+
unsigned result = m_constantPool.size();
92+
m_constantPool.append(JITConstantPool::Value { payload, type });
93+
return result;
94+
}
95+
8996
#if ENABLE(DFG_JIT)
9097
void JIT::emitEnterOptimizationCheck()
9198
{

Source/JavaScriptCore/jit/JIT.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ namespace JSC {
973973

974974
void resetSP();
975975

976+
JITConstantPool::Constant addToConstantPool(JITConstantPool::Type, void* payload = nullptr);
977+
976978
Interpreter* m_interpreter;
977979

978980
Vector<FarCallRecord> m_farCalls;
@@ -1040,7 +1042,7 @@ namespace JSC {
10401042
MathICHolder m_mathICs;
10411043
RefPtr<BaselineJITCode> m_jitCode;
10421044

1043-
JITConstantPool m_constantPool;
1045+
Vector<JITConstantPool::Value> m_constantPool;
10441046
JITConstantPool::Constant m_globalObjectConstant { std::numeric_limits<unsigned>::max() };
10451047
Bag<UnlinkedCallLinkInfo> m_unlinkedCalls;
10461048
Bag<CallLinkInfo> m_evalCallLinkInfos;

Source/JavaScriptCore/jit/JITCall.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void JIT::compileOpCall(const Instruction* instruction, unsigned callLinkInfoInd
233233
info->bytecodeIndex = m_bytecodeIndex;
234234
info->callType = CallLinkInfo::callTypeFor(opcodeID);
235235

236-
infoConstant = m_constantPool.add(JITConstantPool::Type::CallLinkInfo, info);
236+
infoConstant = addToConstantPool(JITConstantPool::Type::CallLinkInfo, info);
237237

238238
ASSERT(m_callCompilationInfo.size() == callLinkInfoIndex);
239239
m_callCompilationInfo.append(CallCompilationInfo());
@@ -421,7 +421,7 @@ void JIT::emit_op_iterator_open(const Instruction* instruction)
421421
UnlinkedStructureStubInfo* stubInfo = m_unlinkedStubInfos.add();
422422
stubInfo->accessType = AccessType::GetById;
423423
stubInfo->bytecodeIndex = m_bytecodeIndex;
424-
JITConstantPool::Constant stubInfoIndex = m_constantPool.add(JITConstantPool::Type::StructureStubInfo, stubInfo);
424+
JITConstantPool::Constant stubInfoIndex = addToConstantPool(JITConstantPool::Type::StructureStubInfo, stubInfo);
425425
gen.m_unlinkedStubInfoConstantIndex = stubInfoIndex;
426426
gen.m_unlinkedStubInfo = stubInfo;
427427

@@ -518,7 +518,7 @@ void JIT::emit_op_iterator_next(const Instruction* instruction)
518518
UnlinkedStructureStubInfo* stubInfo = m_unlinkedStubInfos.add();
519519
stubInfo->accessType = AccessType::GetById;
520520
stubInfo->bytecodeIndex = m_bytecodeIndex;
521-
JITConstantPool::Constant stubInfoIndex = m_constantPool.add(JITConstantPool::Type::StructureStubInfo, stubInfo);
521+
JITConstantPool::Constant stubInfoIndex = addToConstantPool(JITConstantPool::Type::StructureStubInfo, stubInfo);
522522
gen.m_unlinkedStubInfoConstantIndex = stubInfoIndex;
523523
gen.m_unlinkedStubInfo = stubInfo;
524524

@@ -553,7 +553,7 @@ void JIT::emit_op_iterator_next(const Instruction* instruction)
553553
UnlinkedStructureStubInfo* stubInfo = m_unlinkedStubInfos.add();
554554
stubInfo->accessType = AccessType::GetById;
555555
stubInfo->bytecodeIndex = m_bytecodeIndex;
556-
JITConstantPool::Constant stubInfoIndex = m_constantPool.add(JITConstantPool::Type::StructureStubInfo, stubInfo);
556+
JITConstantPool::Constant stubInfoIndex = addToConstantPool(JITConstantPool::Type::StructureStubInfo, stubInfo);
557557
gen.m_unlinkedStubInfoConstantIndex = stubInfoIndex;
558558
gen.m_unlinkedStubInfo = stubInfo;
559559

Source/JavaScriptCore/jit/JITOpcodes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void JIT::emit_op_instanceof(const Instruction* currentInstruction)
180180
UnlinkedStructureStubInfo* stubInfo = m_unlinkedStubInfos.add();
181181
stubInfo->accessType = AccessType::InstanceOf;
182182
stubInfo->bytecodeIndex = m_bytecodeIndex;
183-
JITConstantPool::Constant stubInfoIndex = m_constantPool.add(JITConstantPool::Type::StructureStubInfo, stubInfo);
183+
JITConstantPool::Constant stubInfoIndex = addToConstantPool(JITConstantPool::Type::StructureStubInfo, stubInfo);
184184
gen.m_unlinkedStubInfoConstantIndex = stubInfoIndex;
185185
gen.m_unlinkedStubInfo = stubInfo;
186186

@@ -1612,7 +1612,7 @@ void JIT::emitNewFuncCommon(const Instruction* currentInstruction)
16121612
#else
16131613
emitLoadPayload(bytecode.m_scope, argumentGPR1);
16141614
#endif
1615-
auto constant = m_constantPool.add(JITConstantPool::Type::FunctionDecl, bitwise_cast<void*>(static_cast<uintptr_t>(bytecode.m_functionDecl)));
1615+
auto constant = addToConstantPool(JITConstantPool::Type::FunctionDecl, bitwise_cast<void*>(static_cast<uintptr_t>(bytecode.m_functionDecl)));
16161616
loadConstant(constant, argumentGPR2);
16171617

16181618
OpcodeID opcodeID = Op::opcodeID;
@@ -1659,7 +1659,7 @@ void JIT::emitNewFuncExprCommon(const Instruction* currentInstruction)
16591659
emitLoadPayload(bytecode.m_scope, argumentGPR1);
16601660
#endif
16611661

1662-
auto constant = m_constantPool.add(JITConstantPool::Type::FunctionExpr, bitwise_cast<void*>(static_cast<uintptr_t>(bytecode.m_functionDecl)));
1662+
auto constant = addToConstantPool(JITConstantPool::Type::FunctionExpr, bitwise_cast<void*>(static_cast<uintptr_t>(bytecode.m_functionDecl)));
16631663
loadConstant(constant, argumentGPR2);
16641664
OpcodeID opcodeID = Op::opcodeID;
16651665

0 commit comments

Comments
 (0)