From 03b99259ff9defb5cba37343713b39dd905f1aef Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 9 Sep 2022 13:10:45 -0700 Subject: [PATCH] [shared-struct] Support shared objects in v8::Object::GetConstructorName Bug: v8:12547 Change-Id: I6e48ac252361b3f3b495d2feaa5ad4e708e78eb9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3888379 Auto-Submit: Shu-yu Guo Commit-Queue: Shu-yu Guo Commit-Queue: Adam Klein Reviewed-by: Adam Klein Cr-Commit-Position: refs/heads/main@{#83118} --- src/api/api.cc | 11 ++- src/init/heap-symbols.h | 4 ++ src/objects/js-objects.cc | 8 +++ test/cctest/test-api.cc | 101 +++++++++++++-------------- tools/v8heapconst.py | 140 +++++++++++++++++++------------------- 5 files changed, 139 insertions(+), 125 deletions(-) diff --git a/src/api/api.cc b/src/api/api.cc index 6eaea2dc3e..b172a1d07e 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -4736,11 +4736,16 @@ MaybeLocal v8::Object::ObjectProtoToString(Local context) { } Local v8::Object::GetConstructorName() { + // TODO(v8:12547): Consider adding GetConstructorName(Local). auto self = Utils::OpenHandle(this); - // TODO(v8:12547): Support shared objects. - DCHECK(!self->InSharedHeap()); + i::Isolate* i_isolate; + if (self->InSharedWritableHeap()) { + i_isolate = i::Isolate::Current(); + } else { + i_isolate = self->GetIsolate(); + } i::Handle name = - i::JSReceiver::GetConstructorName(self->GetIsolate(), self); + i::JSReceiver::GetConstructorName(i_isolate, self); return Utils::ToLocal(name); } diff --git a/src/init/heap-symbols.h b/src/init/heap-symbols.h index 10312ccc4b..edc998f27e 100644 --- a/src/init/heap-symbols.h +++ b/src/init/heap-symbols.h @@ -157,6 +157,8 @@ V(_, as_string, "as") \ V(_, assert_string, "assert") \ V(_, async_string, "async") \ + V(_, AtomicsCondition_string, "Atomics.Condition") \ + V(_, AtomicsMutex_string, "Atomics.Mutex") \ V(_, auto_string, "auto") \ V(_, await_string, "await") \ V(_, BigInt_string, "BigInt") \ @@ -384,7 +386,9 @@ V(_, SetIterator_string, "Set Iterator") \ V(_, setPrototypeOf_string, "setPrototypeOf") \ V(_, ShadowRealm_string, "ShadowRealm") \ + V(_, SharedArray_string, "SharedArray") \ V(_, SharedArrayBuffer_string, "SharedArrayBuffer") \ + V(_, SharedStruct_string, "SharedStruct") \ V(_, sign_string, "sign") \ V(_, smallestUnit_string, "smallestUnit") \ V(_, source_string, "source") \ diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc index cbf6634797..97fe7dc775 100644 --- a/src/objects/js-objects.cc +++ b/src/objects/js-objects.cc @@ -544,6 +544,14 @@ String JSReceiver::class_name() { if (IsJSWeakMap()) return roots.WeakMap_string(); if (IsJSWeakSet()) return roots.WeakSet_string(); if (IsJSGlobalProxy()) return roots.global_string(); + if (IsShared()) { + if (IsJSSharedStruct()) return roots.SharedStruct_string(); + if (IsJSSharedArray()) return roots.SharedArray_string(); + if (IsJSAtomicsMutex()) return roots.AtomicsMutex_string(); + if (IsJSAtomicsCondition()) return roots.AtomicsCondition_string(); + // Other shared values are primitives. + UNREACHABLE(); + } return roots.Object_string(); } diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 7deba60e23..0fafc70114 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -12879,6 +12879,22 @@ TEST(ObjectProtoToStringES6) { } } +namespace { + +void CheckGetConstructorNameOfVar(LocalContext& context, const char* var_name, + const char* constructor_name) { + Local var = context->Global() + ->Get(context.local(), v8_str(var_name)) + .ToLocalChecked(); + CHECK(var->IsObject() && + var->ToObject(context.local()) + .ToLocalChecked() + ->GetConstructorName() + ->Equals(context.local(), v8_str(constructor_name)) + .FromJust()); +} + +} // namespace THREADED_TEST(ObjectGetConstructorName) { v8::Isolate* isolate = CcTest::isolate(); @@ -12897,41 +12913,10 @@ THREADED_TEST(ObjectGetConstructorName) { ->Run(context.local()) .ToLocalChecked(); - Local p = - context->Global()->Get(context.local(), v8_str("p")).ToLocalChecked(); - CHECK(p->IsObject() && - p->ToObject(context.local()) - .ToLocalChecked() - ->GetConstructorName() - ->Equals(context.local(), v8_str("Parent")) - .FromJust()); - - Local c = - context->Global()->Get(context.local(), v8_str("c")).ToLocalChecked(); - CHECK(c->IsObject() && - c->ToObject(context.local()) - .ToLocalChecked() - ->GetConstructorName() - ->Equals(context.local(), v8_str("Child")) - .FromJust()); - - Local x = - context->Global()->Get(context.local(), v8_str("x")).ToLocalChecked(); - CHECK(x->IsObject() && - x->ToObject(context.local()) - .ToLocalChecked() - ->GetConstructorName() - ->Equals(context.local(), v8_str("outer.inner")) - .FromJust()); - - Local child_prototype = - context->Global()->Get(context.local(), v8_str("proto")).ToLocalChecked(); - CHECK(child_prototype->IsObject() && - child_prototype->ToObject(context.local()) - .ToLocalChecked() - ->GetConstructorName() - ->Equals(context.local(), v8_str("Parent")) - .FromJust()); + CheckGetConstructorNameOfVar(context, "p", "Parent"); + CheckGetConstructorNameOfVar(context, "c", "Child"); + CheckGetConstructorNameOfVar(context, "x", "outer.inner"); + CheckGetConstructorNameOfVar(context, "proto", "Parent"); } @@ -12948,25 +12933,37 @@ THREADED_TEST(SubclassGetConstructorName) { ->Run(context.local()) .ToLocalChecked(); - Local p = - context->Global()->Get(context.local(), v8_str("p")).ToLocalChecked(); - CHECK(p->IsObject() && - p->ToObject(context.local()) - .ToLocalChecked() - ->GetConstructorName() - ->Equals(context.local(), v8_str("Parent")) - .FromJust()); - - Local c = - context->Global()->Get(context.local(), v8_str("c")).ToLocalChecked(); - CHECK(c->IsObject() && - c->ToObject(context.local()) - .ToLocalChecked() - ->GetConstructorName() - ->Equals(context.local(), v8_str("Child")) - .FromJust()); + CheckGetConstructorNameOfVar(context, "p", "Parent"); + CheckGetConstructorNameOfVar(context, "c", "Child"); } +UNINITIALIZED_TEST(SharedObjectGetConstructorName) { + i::FLAG_shared_string_table = true; + i::FLAG_harmony_struct = true; + + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); + { + v8::Isolate::Scope i_scope(isolate); + v8::HandleScope scope(isolate); + LocalContext context(isolate); + + v8_compile( + "var s = new (new SharedStructType(['foo']));" + "var a = new SharedArray(1);" + "var m = new Atomics.Mutex;" + "var c = new Atomics.Condition;") + ->Run(context.local()) + .ToLocalChecked(); + + CheckGetConstructorNameOfVar(context, "s", "SharedStruct"); + CheckGetConstructorNameOfVar(context, "a", "SharedArray"); + CheckGetConstructorNameOfVar(context, "m", "Atomics.Mutex"); + CheckGetConstructorNameOfVar(context, "c", "Atomics.Condition"); + } + isolate->Dispose(); +} bool ApiTestFuzzer::fuzzing_ = false; v8::base::Semaphore ApiTestFuzzer::all_tests_done_(0); diff --git a/tools/v8heapconst.py b/tools/v8heapconst.py index 42d72af3a1..1812c48885 100644 --- a/tools/v8heapconst.py +++ b/tools/v8heapconst.py @@ -393,76 +393,76 @@ KNOWN_MAPS = { ("read_only_space", 0x03491): (131, "BasicBlockCountersMarkerMap"), ("read_only_space", 0x034d5): (146, "ArrayBoilerplateDescriptionMap"), ("read_only_space", 0x035d5): (159, "InterceptorInfoMap"), - ("read_only_space", 0x073e9): (132, "PromiseFulfillReactionJobTaskMap"), - ("read_only_space", 0x07411): (133, "PromiseRejectReactionJobTaskMap"), - ("read_only_space", 0x07439): (134, "CallableTaskMap"), - ("read_only_space", 0x07461): (135, "CallbackTaskMap"), - ("read_only_space", 0x07489): (136, "PromiseResolveThenableJobTaskMap"), - ("read_only_space", 0x074b1): (139, "FunctionTemplateInfoMap"), - ("read_only_space", 0x074d9): (140, "ObjectTemplateInfoMap"), - ("read_only_space", 0x07501): (141, "AccessCheckInfoMap"), - ("read_only_space", 0x07529): (142, "AccessorPairMap"), - ("read_only_space", 0x07551): (143, "AliasedArgumentsEntryMap"), - ("read_only_space", 0x07579): (144, "AllocationMementoMap"), - ("read_only_space", 0x075a1): (147, "AsmWasmDataMap"), - ("read_only_space", 0x075c9): (148, "AsyncGeneratorRequestMap"), - ("read_only_space", 0x075f1): (149, "BreakPointMap"), - ("read_only_space", 0x07619): (150, "BreakPointInfoMap"), - ("read_only_space", 0x07641): (151, "CachedTemplateObjectMap"), - ("read_only_space", 0x07669): (152, "CallSiteInfoMap"), - ("read_only_space", 0x07691): (153, "ClassPositionsMap"), - ("read_only_space", 0x076b9): (154, "DebugInfoMap"), - ("read_only_space", 0x076e1): (156, "ErrorStackDataMap"), - ("read_only_space", 0x07709): (158, "FunctionTemplateRareDataMap"), - ("read_only_space", 0x07731): (160, "InterpreterDataMap"), - ("read_only_space", 0x07759): (161, "ModuleRequestMap"), - ("read_only_space", 0x07781): (162, "PromiseCapabilityMap"), - ("read_only_space", 0x077a9): (163, "PromiseOnStackMap"), - ("read_only_space", 0x077d1): (164, "PromiseReactionMap"), - ("read_only_space", 0x077f9): (165, "PropertyDescriptorObjectMap"), - ("read_only_space", 0x07821): (166, "PrototypeInfoMap"), - ("read_only_space", 0x07849): (167, "RegExpBoilerplateDescriptionMap"), - ("read_only_space", 0x07871): (168, "ScriptMap"), - ("read_only_space", 0x07899): (169, "ScriptOrModuleMap"), - ("read_only_space", 0x078c1): (170, "SourceTextModuleInfoEntryMap"), - ("read_only_space", 0x078e9): (171, "StackFrameInfoMap"), - ("read_only_space", 0x07911): (172, "TemplateObjectDescriptionMap"), - ("read_only_space", 0x07939): (173, "Tuple2Map"), - ("read_only_space", 0x07961): (174, "WasmExceptionTagMap"), - ("read_only_space", 0x07989): (175, "WasmIndirectFunctionTableMap"), - ("read_only_space", 0x079b1): (195, "SloppyArgumentsElementsMap"), - ("read_only_space", 0x079d9): (228, "DescriptorArrayMap"), - ("read_only_space", 0x07a01): (217, "UncompiledDataWithoutPreparseDataMap"), - ("read_only_space", 0x07a29): (215, "UncompiledDataWithPreparseDataMap"), - ("read_only_space", 0x07a51): (218, "UncompiledDataWithoutPreparseDataWithJobMap"), - ("read_only_space", 0x07a79): (216, "UncompiledDataWithPreparseDataAndJobMap"), - ("read_only_space", 0x07aa1): (249, "OnHeapBasicBlockProfilerDataMap"), - ("read_only_space", 0x07ac9): (196, "TurbofanBitsetTypeMap"), - ("read_only_space", 0x07af1): (200, "TurbofanUnionTypeMap"), - ("read_only_space", 0x07b19): (199, "TurbofanRangeTypeMap"), - ("read_only_space", 0x07b41): (197, "TurbofanHeapConstantTypeMap"), - ("read_only_space", 0x07b69): (198, "TurbofanOtherNumberConstantTypeMap"), - ("read_only_space", 0x07b91): (245, "InternalClassMap"), - ("read_only_space", 0x07bb9): (256, "SmiPairMap"), - ("read_only_space", 0x07be1): (255, "SmiBoxMap"), - ("read_only_space", 0x07c09): (201, "ExportedSubClassBaseMap"), - ("read_only_space", 0x07c31): (202, "ExportedSubClassMap"), - ("read_only_space", 0x07c59): (226, "AbstractInternalClassSubclass1Map"), - ("read_only_space", 0x07c81): (227, "AbstractInternalClassSubclass2Map"), - ("read_only_space", 0x07ca9): (194, "InternalClassWithSmiElementsMap"), - ("read_only_space", 0x07cd1): (246, "InternalClassWithStructElementsMap"), - ("read_only_space", 0x07cf9): (203, "ExportedSubClass2Map"), - ("read_only_space", 0x07d21): (257, "SortStateMap"), - ("read_only_space", 0x07d49): (263, "WasmStringViewIterMap"), - ("read_only_space", 0x07d71): (145, "AllocationSiteWithWeakNextMap"), - ("read_only_space", 0x07d99): (145, "AllocationSiteWithoutWeakNextMap"), - ("read_only_space", 0x07e65): (137, "LoadHandler1Map"), - ("read_only_space", 0x07e8d): (137, "LoadHandler2Map"), - ("read_only_space", 0x07eb5): (137, "LoadHandler3Map"), - ("read_only_space", 0x07edd): (138, "StoreHandler0Map"), - ("read_only_space", 0x07f05): (138, "StoreHandler1Map"), - ("read_only_space", 0x07f2d): (138, "StoreHandler2Map"), - ("read_only_space", 0x07f55): (138, "StoreHandler3Map"), + ("read_only_space", 0x07455): (132, "PromiseFulfillReactionJobTaskMap"), + ("read_only_space", 0x0747d): (133, "PromiseRejectReactionJobTaskMap"), + ("read_only_space", 0x074a5): (134, "CallableTaskMap"), + ("read_only_space", 0x074cd): (135, "CallbackTaskMap"), + ("read_only_space", 0x074f5): (136, "PromiseResolveThenableJobTaskMap"), + ("read_only_space", 0x0751d): (139, "FunctionTemplateInfoMap"), + ("read_only_space", 0x07545): (140, "ObjectTemplateInfoMap"), + ("read_only_space", 0x0756d): (141, "AccessCheckInfoMap"), + ("read_only_space", 0x07595): (142, "AccessorPairMap"), + ("read_only_space", 0x075bd): (143, "AliasedArgumentsEntryMap"), + ("read_only_space", 0x075e5): (144, "AllocationMementoMap"), + ("read_only_space", 0x0760d): (147, "AsmWasmDataMap"), + ("read_only_space", 0x07635): (148, "AsyncGeneratorRequestMap"), + ("read_only_space", 0x0765d): (149, "BreakPointMap"), + ("read_only_space", 0x07685): (150, "BreakPointInfoMap"), + ("read_only_space", 0x076ad): (151, "CachedTemplateObjectMap"), + ("read_only_space", 0x076d5): (152, "CallSiteInfoMap"), + ("read_only_space", 0x076fd): (153, "ClassPositionsMap"), + ("read_only_space", 0x07725): (154, "DebugInfoMap"), + ("read_only_space", 0x0774d): (156, "ErrorStackDataMap"), + ("read_only_space", 0x07775): (158, "FunctionTemplateRareDataMap"), + ("read_only_space", 0x0779d): (160, "InterpreterDataMap"), + ("read_only_space", 0x077c5): (161, "ModuleRequestMap"), + ("read_only_space", 0x077ed): (162, "PromiseCapabilityMap"), + ("read_only_space", 0x07815): (163, "PromiseOnStackMap"), + ("read_only_space", 0x0783d): (164, "PromiseReactionMap"), + ("read_only_space", 0x07865): (165, "PropertyDescriptorObjectMap"), + ("read_only_space", 0x0788d): (166, "PrototypeInfoMap"), + ("read_only_space", 0x078b5): (167, "RegExpBoilerplateDescriptionMap"), + ("read_only_space", 0x078dd): (168, "ScriptMap"), + ("read_only_space", 0x07905): (169, "ScriptOrModuleMap"), + ("read_only_space", 0x0792d): (170, "SourceTextModuleInfoEntryMap"), + ("read_only_space", 0x07955): (171, "StackFrameInfoMap"), + ("read_only_space", 0x0797d): (172, "TemplateObjectDescriptionMap"), + ("read_only_space", 0x079a5): (173, "Tuple2Map"), + ("read_only_space", 0x079cd): (174, "WasmExceptionTagMap"), + ("read_only_space", 0x079f5): (175, "WasmIndirectFunctionTableMap"), + ("read_only_space", 0x07a1d): (195, "SloppyArgumentsElementsMap"), + ("read_only_space", 0x07a45): (228, "DescriptorArrayMap"), + ("read_only_space", 0x07a6d): (217, "UncompiledDataWithoutPreparseDataMap"), + ("read_only_space", 0x07a95): (215, "UncompiledDataWithPreparseDataMap"), + ("read_only_space", 0x07abd): (218, "UncompiledDataWithoutPreparseDataWithJobMap"), + ("read_only_space", 0x07ae5): (216, "UncompiledDataWithPreparseDataAndJobMap"), + ("read_only_space", 0x07b0d): (249, "OnHeapBasicBlockProfilerDataMap"), + ("read_only_space", 0x07b35): (196, "TurbofanBitsetTypeMap"), + ("read_only_space", 0x07b5d): (200, "TurbofanUnionTypeMap"), + ("read_only_space", 0x07b85): (199, "TurbofanRangeTypeMap"), + ("read_only_space", 0x07bad): (197, "TurbofanHeapConstantTypeMap"), + ("read_only_space", 0x07bd5): (198, "TurbofanOtherNumberConstantTypeMap"), + ("read_only_space", 0x07bfd): (245, "InternalClassMap"), + ("read_only_space", 0x07c25): (256, "SmiPairMap"), + ("read_only_space", 0x07c4d): (255, "SmiBoxMap"), + ("read_only_space", 0x07c75): (201, "ExportedSubClassBaseMap"), + ("read_only_space", 0x07c9d): (202, "ExportedSubClassMap"), + ("read_only_space", 0x07cc5): (226, "AbstractInternalClassSubclass1Map"), + ("read_only_space", 0x07ced): (227, "AbstractInternalClassSubclass2Map"), + ("read_only_space", 0x07d15): (194, "InternalClassWithSmiElementsMap"), + ("read_only_space", 0x07d3d): (246, "InternalClassWithStructElementsMap"), + ("read_only_space", 0x07d65): (203, "ExportedSubClass2Map"), + ("read_only_space", 0x07d8d): (257, "SortStateMap"), + ("read_only_space", 0x07db5): (263, "WasmStringViewIterMap"), + ("read_only_space", 0x07ddd): (145, "AllocationSiteWithWeakNextMap"), + ("read_only_space", 0x07e05): (145, "AllocationSiteWithoutWeakNextMap"), + ("read_only_space", 0x07ed1): (137, "LoadHandler1Map"), + ("read_only_space", 0x07ef9): (137, "LoadHandler2Map"), + ("read_only_space", 0x07f21): (137, "LoadHandler3Map"), + ("read_only_space", 0x07f49): (138, "StoreHandler0Map"), + ("read_only_space", 0x07f71): (138, "StoreHandler1Map"), + ("read_only_space", 0x07f99): (138, "StoreHandler2Map"), + ("read_only_space", 0x07fc1): (138, "StoreHandler3Map"), ("map_space", 0x02139): (2115, "ExternalMap"), ("map_space", 0x02161): (2119, "JSMessageObjectMap"), }