diff --git a/ecmascript/compiler/circuit_builder.cpp b/ecmascript/compiler/circuit_builder.cpp index 9b591c8091671211cda0056d409494ee1c4c7bc3..5a6c5d2ff719a7ed8cd981c57e70c08eb0dda370 100644 --- a/ecmascript/compiler/circuit_builder.cpp +++ b/ecmascript/compiler/circuit_builder.cpp @@ -644,6 +644,11 @@ GateRef CircuitBuilder::GetConstPoolFromFunction(GateRef glue, GateRef jsFunc) return Load(VariableType::JS_ANY(), glue, method, IntPtr(Method::CONSTANT_POOL_OFFSET)); } +GateRef CircuitBuilder::GetSharedConstpoolFromMethod(GateRef glue, GateRef method) +{ + return Load(VariableType::JS_ANY(), glue, method, IntPtr(Method::CONSTANT_POOL_OFFSET)); +} + GateRef CircuitBuilder::GetUnsharedConstpoolFromGlue(GateRef glue, GateRef constpool) { Label entryPass(env_); @@ -1020,17 +1025,37 @@ GateRef CircuitBuilder::GetObjectFromConstPool(GateRef glue, GateRef hirGate, Ga if (type == ConstPoolType::METHOD) { Label isHeapObj(env_); Label checkInteger(env_); + Label checkCalleeUnsharedConstpool(env_); + Label checkCalleeUnsharedConstpoolNotHole(env_); + Label initCalleeUnsharedConstpool(env_); BRANCH(TaggedIsHeapObject(*result), &isHeapObj, &checkInteger); Bind(&isHeapObj); { Label isAOTLiteralInfo(env_); - BRANCH(IsAOTLiteralInfo(glue, *result), &isAOTLiteralInfo, &exit); + BRANCH(IsAOTLiteralInfo(glue, *result), &isAOTLiteralInfo, &checkCalleeUnsharedConstpool); Bind(&isAOTLiteralInfo); { result = CallRuntime(glue, RTSTUB_ID(GetMethodFromCache), Gate::InvalidGateRef, { sharedConstPool, Int32ToTaggedInt(index) }, hirGate); Jump(&exit); } + Bind(&checkCalleeUnsharedConstpool); + { + GateRef calleeSharedConstpool = GetSharedConstpoolFromMethod(glue, *result); + BRANCH_LIKELY(Equal(calleeSharedConstpool, sharedConstPool), &exit, + &checkCalleeUnsharedConstpoolNotHole); + { + Bind(&checkCalleeUnsharedConstpoolNotHole); + BRANCH(TaggedIsHole(GetUnsharedConstpoolFromGlue(glue, calleeSharedConstpool)), + &initCalleeUnsharedConstpool, &exit); + Bind(&initCalleeUnsharedConstpool); + { + CallRuntime(glue, RTSTUB_ID(CreateUnsharedConstpool), Gate::InvalidGateRef, + {calleeSharedConstpool}, hirGate); + Jump(&exit); + } + } + } } Bind(&checkInteger); { diff --git a/ecmascript/compiler/circuit_builder.h b/ecmascript/compiler/circuit_builder.h index 8a20ae7053ecf9bde2dd5e05ac6d0b5947a6d41c..1484f4294bfd776bd3455706649f29f724da2c6e 100644 --- a/ecmascript/compiler/circuit_builder.h +++ b/ecmascript/compiler/circuit_builder.h @@ -334,6 +334,7 @@ public: // Get GateRef GetConstPoolFromFunction(GateRef glue, GateRef jsFunc); + GateRef GetSharedConstpoolFromMethod(GateRef glue, GateRef method); GateRef GetUnsharedConstpoolFromGlue(GateRef glue, GateRef constpool); GateRef GetUnsharedConstpoolIndex(GateRef glue, GateRef constpool); GateRef GetUnsharedConstpool(GateRef glue, GateRef arrayAddr, GateRef index); diff --git a/ecmascript/compiler/stub_builder.cpp b/ecmascript/compiler/stub_builder.cpp index e057b09874295abd8b71046f204f2a1c403d6299..761c77392c8483c8e84b49ed712cf587e4067076 100644 --- a/ecmascript/compiler/stub_builder.cpp +++ b/ecmascript/compiler/stub_builder.cpp @@ -8803,6 +8803,11 @@ GateRef StubBuilder::GetConstPoolFromFunction(GateRef glue, GateRef jsFunc) return env_->GetBuilder()->GetConstPoolFromFunction(glue, jsFunc); } +GateRef StubBuilder::GetSharedConstpoolFromMethod(GateRef glue, GateRef method) +{ + return env_->GetBuilder()->GetSharedConstpoolFromMethod(glue, method); +} + GateRef StubBuilder::GetStringFromConstPool(GateRef glue, GateRef constpool, GateRef index) { GateRef module = Circuit::NullGate(); diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index 859a205a52c59609b9c39e5118afb315bc2522e7..52d3c94d4667a3be0df8bc5f158b2de286dcb3f1 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -979,6 +979,7 @@ public: inline GateRef GetObjectFromConstPool(GateRef glue, GateRef constpool, GateRef index); GateRef GetConstPoolFromFunction(GateRef glue, GateRef jsFunc); + GateRef GetSharedConstpoolFromMethod(GateRef glue, GateRef method); GateRef GetStringFromConstPool(GateRef glue, GateRef constpool, GateRef index); GateRef GetMethodFromConstPool(GateRef glue, GateRef constpool, GateRef index); GateRef GetArrayLiteralFromConstPool(GateRef glue, GateRef constpool, GateRef index, GateRef module); diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index b8fa05a65b9c3af9c17e2b3a24ab59564cc74e1a..dd0bc6000280ab305eddf1b5dd92294256640124 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -1663,18 +1663,25 @@ JSTaggedValue EcmaVM::FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpoo { JSTaggedValue unsharedConstpool = FindUnsharedConstpool(sharedConstpool); if (unsharedConstpool.IsHole()) { - ConstantPool *shareCp = ConstantPool::Cast(sharedConstpool.GetTaggedObject()); - int32_t constpoolIndex = shareCp->GetUnsharedConstpoolIndex(); - // unshared constpool index is default INT32_MAX. - ASSERT(0 <= constpoolIndex && constpoolIndex != INT32_MAX); - JSHandle unshareCp = ConstantPool::CreateUnSharedConstPoolBySharedConstpool( - thread_->GetEcmaVM(), shareCp->GetJSPandaFile(), shareCp); - unsharedConstpool = unshareCp.GetTaggedValue(); - SetUnsharedConstpool(constpoolIndex, unsharedConstpool); + return CreateUnsharedConstpool(sharedConstpool); } return unsharedConstpool; } +JSTaggedValue EcmaVM::CreateUnsharedConstpool(JSTaggedValue sharedConstpool) +{ + JSTaggedValue unsharedConstpool = JSTaggedValue::Hole(); + ConstantPool *shareCp = ConstantPool::Cast(sharedConstpool.GetTaggedObject()); + int32_t constpoolIndex = shareCp->GetUnsharedConstpoolIndex(); + // unshared constpool index is default INT32_MAX. + ASSERT(0 <= constpoolIndex && constpoolIndex != INT32_MAX); + JSHandle unshareCp = ConstantPool::CreateUnSharedConstPoolBySharedConstpool( + thread_->GetEcmaVM(), shareCp->GetJSPandaFile(), shareCp); + unsharedConstpool = unshareCp.GetTaggedValue(); + SetUnsharedConstpool(constpoolIndex, unsharedConstpool); + return unsharedConstpool; +} + void EcmaVM::EraseUnusedConstpool(const JSPandaFile *jsPandaFile, int32_t index, int32_t constpoolIndex) { // unshared constpool index is default INT32_MAX. diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index 5b44292f677f48f07d7ba97a6ac7cf5a4d3a248e..f7eaf4961f9704eb47d20e7df0a17455d0a4b9e2 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -1177,6 +1177,7 @@ public: } JSTaggedValue PUBLIC_API FindUnsharedConstpool(JSTaggedValue sharedConstpool); JSTaggedValue PUBLIC_API FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool); + JSTaggedValue PUBLIC_API CreateUnsharedConstpool(JSTaggedValue sharedConstpool); void EraseUnusedConstpool(const JSPandaFile *jsPandaFile, int32_t index, int32_t constpoolIndex); JSTaggedValue PUBLIC_API FindConstpool(const JSPandaFile *jsPandaFile, int32_t index); // For new version instruction. diff --git a/ecmascript/stubs/runtime_stub_list.h b/ecmascript/stubs/runtime_stub_list.h index f9dcd9c4f06b3c5bc5c9b67061685cdd4bbf862a..b872540b8986c5e693b0000ecc22f7616177eb5b 100644 --- a/ecmascript/stubs/runtime_stub_list.h +++ b/ecmascript/stubs/runtime_stub_list.h @@ -516,6 +516,7 @@ namespace panda::ecmascript { V(GetArrayLiteralFromCache) \ V(GetObjectLiteralFromCache) \ V(GetStringFromCache) \ + V(CreateUnsharedConstpool) \ V(BigIntEqual) \ V(StringEqual) \ V(StringIndexOf) \ diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index a4b7e002afaf4a91ba3ffe6666b8469d6bfe23e2..fb3b00da2c86730ac8abbd1050f9caef93765cd4 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -1383,6 +1383,15 @@ DEF_RUNTIME_STUBS(GetArrayLiteralFromCache) thread, cp, index.GetInt(), module.GetTaggedValue()).GetRawData(); } +DEF_RUNTIME_STUBS(CreateUnsharedConstpool) +{ + RUNTIME_STUBS_HEADER(CreateUnsharedConstpool); + JSHandle sharedConstpool = GetHArg(argv, argc, 0); // 0: means the first parameter + ASSERT(thread->GetEcmaVM()->FindUnsharedConstpool(sharedConstpool.GetTaggedValue()).IsHole()); + thread->GetEcmaVM()->CreateUnsharedConstpool(sharedConstpool.GetTaggedValue()); + return JSTaggedValue::Undefined().GetRawData(); +} + DEF_RUNTIME_STUBS(StObjByValue) { RUNTIME_STUBS_HEADER(StObjByValue);