Alloca internal accessors in shared readonly space

Internal accessors are permanent live, and it only references to the "permanent live" object, so put all of them to readonly space.

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IACO9L

Signed-off-by: ZhouGuangyuan <zhouguangyuan1@huawei.com>
Change-Id: I95d653a6927f7934bfc8bb0cc03ab3a00f1f2e22
This commit is contained in:
zhouguangyuan 2024-08-08 11:07:31 +08:00
parent 42932f8e78
commit a8a434c76a
3 changed files with 43 additions and 4 deletions

View File

@ -870,6 +870,8 @@ public:
size_t nativeBindingsize = 0,
NativeFlag flag = NativeFlag::NO_DIV);
JSHandle<JSNativePointer> NewSReadOnlyJSNativePointer(void *externalPointer);
JSHandle<AccessorData> NewSInternalAccessor(void *setter, void *getter);
JSHandle<JSSymbol> NewSWellKnownSymbol(const JSHandle<JSTaggedValue> &name);

View File

@ -506,20 +506,36 @@ JSHandle<JSNativePointer> ObjectFactory::NewSJSNativePointer(void *externalPoint
return obj;
}
JSHandle<JSNativePointer> ObjectFactory::NewSReadOnlyJSNativePointer(void* externalPointer)
{
NewSObjectHook();
auto jsNativePointerClass =
JSHClass::Cast(thread_->GlobalConstants()->GetSJSNativePointerClass().GetTaggedObject());
jsNativePointerClass->SetIsJSShared(true);
TaggedObject* header = sHeap_->AllocateReadOnlyOrHugeObject(thread_, jsNativePointerClass);
JSHandle<JSNativePointer> obj(thread_, header);
obj->SetExternalPointer(externalPointer);
obj->SetDeleter(nullptr);
obj->SetData(nullptr);
obj->SetBindingSize(0);
obj->SetNativeFlag(NativeFlag::NO_DIV);
return obj;
}
JSHandle<AccessorData> ObjectFactory::NewSInternalAccessor(void *setter, void *getter)
{
NewSObjectHook();
TaggedObject *header = sHeap_->AllocateNonMovableOrHugeObject(thread_,
TaggedObject *header = sHeap_->AllocateReadOnlyOrHugeObject(thread_,
JSHClass::Cast(thread_->GlobalConstants()->GetInternalAccessorClass().GetTaggedObject()));
JSHandle<AccessorData> obj(thread_, AccessorData::Cast(header));
obj->SetGetter(thread_, JSTaggedValue::Undefined());
obj->SetSetter(thread_, JSTaggedValue::Undefined());
if (setter != nullptr) {
JSHandle<JSNativePointer> setFunc = NewSJSNativePointer(setter, nullptr, nullptr, true);
JSHandle<JSNativePointer> setFunc = NewSReadOnlyJSNativePointer(setter);
obj->SetSetter(thread_, setFunc.GetTaggedValue());
}
if (getter != nullptr) {
JSHandle<JSNativePointer> getFunc = NewSJSNativePointer(getter, nullptr, nullptr, true);
JSHandle<JSNativePointer> getFunc = NewSReadOnlyJSNativePointer(getter);
obj->SetGetter(thread_, getFunc);
}
return obj;

View File

@ -81,4 +81,25 @@ HWTEST_F_L0(JSVerificationTest, VerifyHeapObjects)
VerifyObjectVisitor objVerifier(heap, &failCount);
const_cast<SemiSpace *>(heap->GetNewSpace())->IterateOverObjects(objVerifier); // newspace reference the old space
}
} // namespace panda::test
HWTEST_F_L0(JSVerificationTest, NoBarrierInternalAccessor)
{
auto ecmaVm = thread->GetEcmaVM();
auto heap = const_cast<Heap*>(ecmaVm->GetHeap());
auto objectFactory = ecmaVm->GetFactory();
EXPECT_EQ(heap->VerifyHeapObjects(), 0U);
size_t failCount = 0;
{
EcmaHandleScope handleScope(thread);
auto newArray = objectFactory->NewTaggedArray(5, JSTaggedValue::Undefined(), MemSpaceType::SEMI_SPACE);
newArray->Set<false>(thread, 0, thread->GlobalConstants()->GetFunctionNameAccessor());
newArray->Set<false>(thread, 1, thread->GlobalConstants()->GetFunctionPrototypeAccessor());
newArray->Set<false>(thread, 2, thread->GlobalConstants()->GetFunctionLengthAccessor());
newArray->Set<false>(thread, 3, thread->GlobalConstants()->GetArrayLengthAccessor());
newArray->Set<false>(thread, 4, thread->GlobalConstants()->GetSharedArrayLengthAccessor());
VerifyObjectVisitor(heap, &failCount, VerifyKind::VERIFY_MARK_YOUNG)(
newArray.GetTaggedValue().GetTaggedObject());
}
EXPECT_EQ(failCount, 0U);
}
} // namespace panda::test