14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci#include <fcntl.h> 164514f5e3Sopenharmony_ci#include <unistd.h> 174514f5e3Sopenharmony_ci#include <chrono> 184514f5e3Sopenharmony_ci#include "ecmascript/dfx/hprof/heap_snapshot.h" 194514f5e3Sopenharmony_ci#include "ecmascript/dfx/hprof/heap_profiler.h" 204514f5e3Sopenharmony_ci#include "ecmascript/dfx/hprof/heap_root_visitor.h" 214514f5e3Sopenharmony_ci#include "ecmascript/global_env.h" 224514f5e3Sopenharmony_ci#include "ecmascript/jspandafile/js_pandafile_manager.h" 234514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_arraylist.h" 244514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_arraylist_iterator.h" 254514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_deque.h" 264514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_hashmap.h" 274514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_hashset.h" 284514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_lightweightmap.h" 294514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_lightweightset.h" 304514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_linked_list.h" 314514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_list.h" 324514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_plain_array.h" 334514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_queue.h" 344514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_stack.h" 354514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_tree_map.h" 364514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_tree_set.h" 374514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_vector.h" 384514f5e3Sopenharmony_ci#include "ecmascript/js_date.h" 394514f5e3Sopenharmony_ci#include "ecmascript/js_iterator.h" 404514f5e3Sopenharmony_ci#include "ecmascript/js_map.h" 414514f5e3Sopenharmony_ci#include "ecmascript/js_primitive_ref.h" 424514f5e3Sopenharmony_ci#include "ecmascript/js_promise.h" 434514f5e3Sopenharmony_ci#include "ecmascript/js_regexp.h" 444514f5e3Sopenharmony_ci#include "ecmascript/js_set.h" 454514f5e3Sopenharmony_ci#include "ecmascript/js_string_iterator.h" 464514f5e3Sopenharmony_ci#include "ecmascript/js_typed_array.h" 474514f5e3Sopenharmony_ci#include "ecmascript/js_weak_container.h" 484514f5e3Sopenharmony_ci#include "ecmascript/linked_hash_table.h" 494514f5e3Sopenharmony_ci#include "ecmascript/napi/include/jsnapi.h" 504514f5e3Sopenharmony_ci#include "ecmascript/shared_objects/js_shared_array.h" 514514f5e3Sopenharmony_ci#include "ecmascript/shared_objects/js_shared_map.h" 524514f5e3Sopenharmony_ci#include "ecmascript/shared_objects/js_shared_set.h" 534514f5e3Sopenharmony_ci#include "ecmascript/tagged_hash_array.h" 544514f5e3Sopenharmony_ci#include "ecmascript/tagged_tree.h" 554514f5e3Sopenharmony_ci#include "ecmascript/tests/test_helper.h" 564514f5e3Sopenharmony_ci 574514f5e3Sopenharmony_cinamespace panda::test { 584514f5e3Sopenharmony_ciusing namespace panda::ecmascript; 594514f5e3Sopenharmony_ciusing ErrorType = base::ErrorType; 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ciclass HeapDumpTest : public testing::Test { 624514f5e3Sopenharmony_cipublic: 634514f5e3Sopenharmony_ci void SetUp() override 644514f5e3Sopenharmony_ci { 654514f5e3Sopenharmony_ci TestHelper::CreateEcmaVMWithScope(ecmaVm_, thread_, scope_); 664514f5e3Sopenharmony_ci ecmaVm_->SetEnableForceGC(false); 674514f5e3Sopenharmony_ci } 684514f5e3Sopenharmony_ci 694514f5e3Sopenharmony_ci void TearDown() override 704514f5e3Sopenharmony_ci { 714514f5e3Sopenharmony_ci TestHelper::DestroyEcmaVMWithScope(ecmaVm_, scope_); 724514f5e3Sopenharmony_ci } 734514f5e3Sopenharmony_ci 744514f5e3Sopenharmony_ci EcmaVM *ecmaVm_ {nullptr}; 754514f5e3Sopenharmony_ci EcmaHandleScope *scope_ {nullptr}; 764514f5e3Sopenharmony_ci JSThread *thread_ {nullptr}; 774514f5e3Sopenharmony_ci}; 784514f5e3Sopenharmony_ci 794514f5e3Sopenharmony_ciclass HeapDumpTestHelper { 804514f5e3Sopenharmony_cipublic: 814514f5e3Sopenharmony_ci explicit HeapDumpTestHelper(EcmaVM *vm) : instance(vm) {} 824514f5e3Sopenharmony_ci 834514f5e3Sopenharmony_ci ~HeapDumpTestHelper() 844514f5e3Sopenharmony_ci { 854514f5e3Sopenharmony_ci HeapProfilerInterface::Destroy(instance); 864514f5e3Sopenharmony_ci } 874514f5e3Sopenharmony_ci 884514f5e3Sopenharmony_ci size_t GenerateSnapShot(const std::string &filePath) 894514f5e3Sopenharmony_ci { 904514f5e3Sopenharmony_ci // first generate this file of filePath if not exist, 914514f5e3Sopenharmony_ci // so the function `realpath` of FileStream can not failed on arm/arm64. 924514f5e3Sopenharmony_ci fstream outputString(filePath, std::ios::out); 934514f5e3Sopenharmony_ci outputString.close(); 944514f5e3Sopenharmony_ci outputString.clear(); 954514f5e3Sopenharmony_ci FileStream stream(filePath.c_str()); 964514f5e3Sopenharmony_ci HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(instance); 974514f5e3Sopenharmony_ci DumpSnapShotOption dumpOption; 984514f5e3Sopenharmony_ci dumpOption.dumpFormat = DumpFormat::JSON; 994514f5e3Sopenharmony_ci heapProfile->DumpHeapSnapshot(&stream, dumpOption); 1004514f5e3Sopenharmony_ci return heapProfile->GetIdCount(); 1014514f5e3Sopenharmony_ci } 1024514f5e3Sopenharmony_ci 1034514f5e3Sopenharmony_ci bool GenerateRawHeapSnashot(const std::string &filePath) 1044514f5e3Sopenharmony_ci { 1054514f5e3Sopenharmony_ci HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(instance); 1064514f5e3Sopenharmony_ci DumpSnapShotOption dumpOption; 1074514f5e3Sopenharmony_ci dumpOption.dumpFormat = DumpFormat::BINARY; 1084514f5e3Sopenharmony_ci dumpOption.isDumpOOM = true; 1094514f5e3Sopenharmony_ci fstream outputString(filePath, std::ios::out); 1104514f5e3Sopenharmony_ci outputString.close(); 1114514f5e3Sopenharmony_ci outputString.clear(); 1124514f5e3Sopenharmony_ci int fd = open(filePath.c_str(), O_RDWR | O_CREAT); 1134514f5e3Sopenharmony_ci FileDescriptorStream stream(fd); 1144514f5e3Sopenharmony_ci auto ret = heapProfile->DumpHeapSnapshot(&stream, dumpOption); 1154514f5e3Sopenharmony_ci stream.EndOfStream(); 1164514f5e3Sopenharmony_ci return ret; 1174514f5e3Sopenharmony_ci } 1184514f5e3Sopenharmony_ci 1194514f5e3Sopenharmony_ci bool DecodeRawHeapSnashot(std::string &inputPath, std::string &outputPath) 1204514f5e3Sopenharmony_ci { 1214514f5e3Sopenharmony_ci HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(instance); 1224514f5e3Sopenharmony_ci fstream outputString(outputPath, std::ios::out); 1234514f5e3Sopenharmony_ci outputString.close(); 1244514f5e3Sopenharmony_ci outputString.clear(); 1254514f5e3Sopenharmony_ci auto ret = heapProfile->GenerateHeapSnapshot(inputPath, outputPath); 1264514f5e3Sopenharmony_ci return ret; 1274514f5e3Sopenharmony_ci } 1284514f5e3Sopenharmony_ci 1294514f5e3Sopenharmony_ci bool MatchHeapDumpString(const std::string &filePath, std::string targetStr) 1304514f5e3Sopenharmony_ci { 1314514f5e3Sopenharmony_ci std::string line; 1324514f5e3Sopenharmony_ci std::ifstream inputStream(filePath); 1334514f5e3Sopenharmony_ci std::size_t lineNum = 0; 1344514f5e3Sopenharmony_ci while (getline(inputStream, line)) { 1354514f5e3Sopenharmony_ci lineNum = line.find(targetStr); 1364514f5e3Sopenharmony_ci if (lineNum != line.npos) { 1374514f5e3Sopenharmony_ci return true; 1384514f5e3Sopenharmony_ci } 1394514f5e3Sopenharmony_ci } 1404514f5e3Sopenharmony_ci GTEST_LOG_(INFO) << "_______________" << targetStr << std::to_string(lineNum) <<"_______________ not found"; 1414514f5e3Sopenharmony_ci return false; // Lost the Line 1424514f5e3Sopenharmony_ci } 1434514f5e3Sopenharmony_ci 1444514f5e3Sopenharmony_ci JSHandle<JSTypedArray> CreateNumberTypedArray(JSType jsType) 1454514f5e3Sopenharmony_ci { 1464514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = instance->GetGlobalEnv(); 1474514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 1484514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> handleTagValFunc = env->GetInt8ArrayFunction(); 1494514f5e3Sopenharmony_ci switch (jsType) { 1504514f5e3Sopenharmony_ci case JSType::JS_INT8_ARRAY: 1514514f5e3Sopenharmony_ci break; 1524514f5e3Sopenharmony_ci case JSType::JS_UINT8_ARRAY: 1534514f5e3Sopenharmony_ci handleTagValFunc = env->GetUint8ArrayFunction(); 1544514f5e3Sopenharmony_ci break; 1554514f5e3Sopenharmony_ci case JSType::JS_UINT8_CLAMPED_ARRAY: 1564514f5e3Sopenharmony_ci handleTagValFunc = env->GetUint8ClampedArrayFunction(); 1574514f5e3Sopenharmony_ci break; 1584514f5e3Sopenharmony_ci case JSType::JS_INT16_ARRAY: 1594514f5e3Sopenharmony_ci handleTagValFunc = env->GetInt16ArrayFunction(); 1604514f5e3Sopenharmony_ci break; 1614514f5e3Sopenharmony_ci case JSType::JS_UINT16_ARRAY: 1624514f5e3Sopenharmony_ci handleTagValFunc = env->GetUint16ArrayFunction(); 1634514f5e3Sopenharmony_ci break; 1644514f5e3Sopenharmony_ci case JSType::JS_INT32_ARRAY: 1654514f5e3Sopenharmony_ci handleTagValFunc = env->GetInt32ArrayFunction(); 1664514f5e3Sopenharmony_ci break; 1674514f5e3Sopenharmony_ci case JSType::JS_UINT32_ARRAY: 1684514f5e3Sopenharmony_ci handleTagValFunc = env->GetUint32ArrayFunction(); 1694514f5e3Sopenharmony_ci break; 1704514f5e3Sopenharmony_ci case JSType::JS_FLOAT32_ARRAY: 1714514f5e3Sopenharmony_ci handleTagValFunc = env->GetFloat32ArrayFunction(); 1724514f5e3Sopenharmony_ci break; 1734514f5e3Sopenharmony_ci case JSType::JS_FLOAT64_ARRAY: 1744514f5e3Sopenharmony_ci handleTagValFunc = env->GetFloat64ArrayFunction(); 1754514f5e3Sopenharmony_ci break; 1764514f5e3Sopenharmony_ci case JSType::JS_BIGINT64_ARRAY: 1774514f5e3Sopenharmony_ci handleTagValFunc = env->GetBigInt64ArrayFunction(); 1784514f5e3Sopenharmony_ci break; 1794514f5e3Sopenharmony_ci case JSType::JS_BIGUINT64_ARRAY: 1804514f5e3Sopenharmony_ci handleTagValFunc = env->GetBigUint64ArrayFunction(); 1814514f5e3Sopenharmony_ci break; 1824514f5e3Sopenharmony_ci default: 1834514f5e3Sopenharmony_ci ASSERT_PRINT(false, "wrong jsType used in CreateNumberTypedArray function"); 1844514f5e3Sopenharmony_ci break; 1854514f5e3Sopenharmony_ci } 1864514f5e3Sopenharmony_ci return JSHandle<JSTypedArray>::Cast( 1874514f5e3Sopenharmony_ci factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(handleTagValFunc), handleTagValFunc)); 1884514f5e3Sopenharmony_ci } 1894514f5e3Sopenharmony_ci 1904514f5e3Sopenharmony_ci JSHandle<JSObject> NewObject(uint32_t size, JSType type, JSHandle<JSTaggedValue> proto) 1914514f5e3Sopenharmony_ci { 1924514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 1934514f5e3Sopenharmony_ci JSHandle<JSHClass> hclass = factory->NewEcmaHClass(size, type, proto); 1944514f5e3Sopenharmony_ci return factory->NewJSObjectWithInit(hclass); 1954514f5e3Sopenharmony_ci } 1964514f5e3Sopenharmony_ci 1974514f5e3Sopenharmony_ci JSHandle<JSObject> NewSObject(uint32_t size, JSType type, JSHandle<JSTaggedValue> proto) 1984514f5e3Sopenharmony_ci { 1994514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 2004514f5e3Sopenharmony_ci auto emptySLayout = instance->GetJSThread()->GlobalConstants()->GetHandledEmptySLayoutInfo(); 2014514f5e3Sopenharmony_ci JSHandle<JSHClass> hclass = factory->NewSEcmaHClass(size, 0, type, proto, emptySLayout); 2024514f5e3Sopenharmony_ci return factory->NewJSObjectWithInit(hclass); 2034514f5e3Sopenharmony_ci } 2044514f5e3Sopenharmony_ci 2054514f5e3Sopenharmony_ci // JS_SET 2064514f5e3Sopenharmony_ci JSHandle<JSSet> NewJSSet() 2074514f5e3Sopenharmony_ci { 2084514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2094514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 2104514f5e3Sopenharmony_ci JSHandle<JSObject> jsSetObject = NewObject(JSSet::SIZE, JSType::JS_SET, proto); 2114514f5e3Sopenharmony_ci JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(jsSetObject); 2124514f5e3Sopenharmony_ci JSHandle<LinkedHashSet> linkedSet(LinkedHashSet::Create(thread)); 2134514f5e3Sopenharmony_ci jsSet->SetLinkedSet(thread, linkedSet); 2144514f5e3Sopenharmony_ci return jsSet; 2154514f5e3Sopenharmony_ci } 2164514f5e3Sopenharmony_ci 2174514f5e3Sopenharmony_ci // JS_SHARED_SET 2184514f5e3Sopenharmony_ci JSHandle<JSSharedSet> NewJSSharedSet() 2194514f5e3Sopenharmony_ci { 2204514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2214514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetSFunctionPrototype(); 2224514f5e3Sopenharmony_ci JSHandle<JSObject> jsSSetObject = NewSObject(JSSharedSet::SIZE, JSType::JS_SHARED_SET, proto); 2234514f5e3Sopenharmony_ci JSHandle<JSSharedSet> jsSSet = JSHandle<JSSharedSet>::Cast(jsSSetObject); 2244514f5e3Sopenharmony_ci JSHandle<LinkedHashSet> linkedSet( 2254514f5e3Sopenharmony_ci LinkedHashSet::Create(thread, LinkedHashSet::MIN_CAPACITY, MemSpaceKind::SHARED)); 2264514f5e3Sopenharmony_ci jsSSet->SetLinkedSet(thread, linkedSet); 2274514f5e3Sopenharmony_ci jsSSet->SetModRecord(0); 2284514f5e3Sopenharmony_ci return jsSSet; 2294514f5e3Sopenharmony_ci } 2304514f5e3Sopenharmony_ci 2314514f5e3Sopenharmony_ci // JS_MAP 2324514f5e3Sopenharmony_ci JSHandle<JSMap> NewJSMap() 2334514f5e3Sopenharmony_ci { 2344514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2354514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 2364514f5e3Sopenharmony_ci JSHandle<JSObject> jsMapObject = NewObject(JSMap::SIZE, JSType::JS_MAP, proto); 2374514f5e3Sopenharmony_ci JSHandle<JSMap> jsMap = JSHandle<JSMap>::Cast(jsMapObject); 2384514f5e3Sopenharmony_ci JSHandle<LinkedHashMap> linkedMap(LinkedHashMap::Create(thread)); 2394514f5e3Sopenharmony_ci jsMap->SetLinkedMap(thread, linkedMap); 2404514f5e3Sopenharmony_ci return jsMap; 2414514f5e3Sopenharmony_ci } 2424514f5e3Sopenharmony_ci 2434514f5e3Sopenharmony_ci // JS_SHARED_MAP 2444514f5e3Sopenharmony_ci JSHandle<JSSharedMap> NewJSSharedMap() 2454514f5e3Sopenharmony_ci { 2464514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2474514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetSFunctionPrototype(); 2484514f5e3Sopenharmony_ci JSHandle<JSObject> jsSMapObject = NewSObject(JSSharedMap::SIZE, JSType::JS_SHARED_MAP, proto); 2494514f5e3Sopenharmony_ci JSHandle<JSSharedMap> jsSMap = JSHandle<JSSharedMap>::Cast(jsSMapObject); 2504514f5e3Sopenharmony_ci JSHandle<LinkedHashMap> linkedMap( 2514514f5e3Sopenharmony_ci LinkedHashMap::Create(thread, LinkedHashMap::MIN_CAPACITY, MemSpaceKind::SHARED)); 2524514f5e3Sopenharmony_ci jsSMap->SetLinkedMap(thread, linkedMap); 2534514f5e3Sopenharmony_ci jsSMap->SetModRecord(0); 2544514f5e3Sopenharmony_ci return jsSMap; 2554514f5e3Sopenharmony_ci } 2564514f5e3Sopenharmony_ci 2574514f5e3Sopenharmony_ci //JS_WEAK_SET 2584514f5e3Sopenharmony_ci JSHandle<JSWeakSet> NewJSWeakSet() 2594514f5e3Sopenharmony_ci { 2604514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2614514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 2624514f5e3Sopenharmony_ci JSHandle<JSObject> jsWeakSetObject = NewObject(JSWeakSet::SIZE, JSType::JS_WEAK_SET, proto); 2634514f5e3Sopenharmony_ci JSHandle<JSWeakSet> jsWeakSet = JSHandle<JSWeakSet>::Cast(jsWeakSetObject); 2644514f5e3Sopenharmony_ci JSHandle<LinkedHashSet> weakLinkedSet(LinkedHashSet::Create(thread)); 2654514f5e3Sopenharmony_ci jsWeakSet->SetLinkedSet(thread, weakLinkedSet); 2664514f5e3Sopenharmony_ci return jsWeakSet; 2674514f5e3Sopenharmony_ci } 2684514f5e3Sopenharmony_ci 2694514f5e3Sopenharmony_ci //JS_WEAK_MAP 2704514f5e3Sopenharmony_ci JSHandle<JSWeakMap> NewJSWeakMap() 2714514f5e3Sopenharmony_ci { 2724514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2734514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 2744514f5e3Sopenharmony_ci JSHandle<JSObject> jsWeakMapObject = NewObject(JSWeakMap::SIZE, JSType::JS_WEAK_MAP, proto); 2754514f5e3Sopenharmony_ci JSHandle<JSWeakMap> jsWeakMap = JSHandle<JSWeakMap>::Cast(jsWeakMapObject); 2764514f5e3Sopenharmony_ci JSHandle<LinkedHashMap> weakLinkedMap(LinkedHashMap::Create(thread)); 2774514f5e3Sopenharmony_ci jsWeakMap->SetLinkedMap(thread, weakLinkedMap); 2784514f5e3Sopenharmony_ci return jsWeakMap; 2794514f5e3Sopenharmony_ci } 2804514f5e3Sopenharmony_ci 2814514f5e3Sopenharmony_ci // JS_PROXY 2824514f5e3Sopenharmony_ci JSHandle<JSProxy> NewJSProxy() 2834514f5e3Sopenharmony_ci { 2844514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2854514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 2864514f5e3Sopenharmony_ci JSFunction *newTarget = instance->GetGlobalEnv()->GetObjectFunction().GetObject<JSFunction>(); 2874514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> newTargetHandle(thread, newTarget); 2884514f5e3Sopenharmony_ci JSHandle<JSObject> jsObject = 2894514f5e3Sopenharmony_ci factory->NewJSObjectByConstructor(JSHandle<JSFunction>(newTargetHandle), newTargetHandle); 2904514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> emptyObj(thread, jsObject.GetTaggedValue()); 2914514f5e3Sopenharmony_ci return factory->NewJSProxy(emptyObj, emptyObj); 2924514f5e3Sopenharmony_ci } 2934514f5e3Sopenharmony_ci 2944514f5e3Sopenharmony_ci // JS_FORIN_ITERATOR 2954514f5e3Sopenharmony_ci JSHandle<JSForInIterator> NewJSForInIterator() 2964514f5e3Sopenharmony_ci { 2974514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 2984514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 2994514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arrayEmpty(thread, factory->NewJSArray().GetTaggedValue()); 3004514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> keys(thread, factory->EmptyArray().GetTaggedValue()); 3014514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> hclass(thread, JSTaggedValue::Undefined()); 3024514f5e3Sopenharmony_ci return factory->NewJSForinIterator(arrayEmpty, keys, hclass); 3034514f5e3Sopenharmony_ci } 3044514f5e3Sopenharmony_ci 3054514f5e3Sopenharmony_ci // JS_REG_EXP_ITERATOR 3064514f5e3Sopenharmony_ci JSHandle<JSRegExpIterator> NewJSRegExpIterator() 3074514f5e3Sopenharmony_ci { 3084514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 3094514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 3104514f5e3Sopenharmony_ci JSHandle<EcmaString> emptyString = factory->GetEmptyString(); 3114514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> jsRegExp(NewObject(JSRegExp::SIZE, JSType::JS_REG_EXP, proto)); 3124514f5e3Sopenharmony_ci return factory->NewJSRegExpIterator(jsRegExp, emptyString, false, false); 3134514f5e3Sopenharmony_ci } 3144514f5e3Sopenharmony_ci 3154514f5e3Sopenharmony_ci // PROMISE_ITERATOR_RECORD 3164514f5e3Sopenharmony_ci JSHandle<PromiseIteratorRecord> NewPromiseIteratorRecord() 3174514f5e3Sopenharmony_ci { 3184514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 3194514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 3204514f5e3Sopenharmony_ci JSFunction *newTarget = instance->GetGlobalEnv()->GetObjectFunction().GetObject<JSFunction>(); 3214514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> newTargetHandle(thread, newTarget); 3224514f5e3Sopenharmony_ci JSHandle<JSObject> jsObject = 3234514f5e3Sopenharmony_ci factory->NewJSObjectByConstructor(JSHandle<JSFunction>(newTargetHandle), newTargetHandle); 3244514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> emptyObj(thread, jsObject.GetTaggedValue()); 3254514f5e3Sopenharmony_ci return factory->NewPromiseIteratorRecord(emptyObj, false); 3264514f5e3Sopenharmony_ci } 3274514f5e3Sopenharmony_ci 3284514f5e3Sopenharmony_ci // JS_API_ARRAY_LIST 3294514f5e3Sopenharmony_ci JSHandle<JSAPIArrayList> NewJSAPIArrayList() 3304514f5e3Sopenharmony_ci { 3314514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 3324514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIArrayListObject = NewObject(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto); 3334514f5e3Sopenharmony_ci JSHandle<JSAPIArrayList> jsAPIArrayList = JSHandle<JSAPIArrayList>::Cast(jsAPIArrayListObject); 3344514f5e3Sopenharmony_ci jsAPIArrayList->SetLength(instance->GetJSThread(), JSTaggedValue(0)); 3354514f5e3Sopenharmony_ci return jsAPIArrayList; 3364514f5e3Sopenharmony_ci } 3374514f5e3Sopenharmony_ci 3384514f5e3Sopenharmony_ci // JS_API_HASH_MAP 3394514f5e3Sopenharmony_ci JSHandle<JSAPIHashMap> NewJSAPIHashMap() 3404514f5e3Sopenharmony_ci { 3414514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 3424514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 3434514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIHashMapObject = NewObject(JSAPIHashMap::SIZE, JSType::JS_API_HASH_MAP, proto); 3444514f5e3Sopenharmony_ci JSHandle<JSAPIHashMap> jsAPIHashMap = JSHandle<JSAPIHashMap>::Cast(jsAPIHashMapObject); 3454514f5e3Sopenharmony_ci jsAPIHashMap->SetTable(thread, TaggedHashArray::Create(thread)); 3464514f5e3Sopenharmony_ci jsAPIHashMap->SetSize(0); 3474514f5e3Sopenharmony_ci return jsAPIHashMap; 3484514f5e3Sopenharmony_ci } 3494514f5e3Sopenharmony_ci 3504514f5e3Sopenharmony_ci // JS_API_HASH_SET 3514514f5e3Sopenharmony_ci JSHandle<JSAPIHashSet> NewJSAPIHashSet() 3524514f5e3Sopenharmony_ci { 3534514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 3544514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 3554514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIHashSetObject = NewObject(JSAPIHashSet::SIZE, JSType::JS_API_HASH_SET, proto); 3564514f5e3Sopenharmony_ci JSHandle<JSAPIHashSet> jsAPIHashSet = JSHandle<JSAPIHashSet>::Cast(jsAPIHashSetObject); 3574514f5e3Sopenharmony_ci jsAPIHashSet->SetTable(thread, TaggedHashArray::Create(thread)); 3584514f5e3Sopenharmony_ci jsAPIHashSet->SetSize(0); 3594514f5e3Sopenharmony_ci return jsAPIHashSet; 3604514f5e3Sopenharmony_ci } 3614514f5e3Sopenharmony_ci 3624514f5e3Sopenharmony_ci // JS_API_LIGHT_WEIGHT_MAP 3634514f5e3Sopenharmony_ci JSHandle<JSAPILightWeightMap> NewJSAPILightWeightMap() 3644514f5e3Sopenharmony_ci { 3654514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 3664514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 3674514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 3684514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPILightWeightMapObject = 3694514f5e3Sopenharmony_ci NewObject(JSAPILightWeightMap::SIZE, JSType::JS_API_LIGHT_WEIGHT_MAP, proto); 3704514f5e3Sopenharmony_ci JSHandle<JSAPILightWeightMap> jsAPILightWeightMap = 3714514f5e3Sopenharmony_ci JSHandle<JSAPILightWeightMap>::Cast(jsAPILightWeightMapObject); 3724514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> hashArray = 3734514f5e3Sopenharmony_ci JSHandle<JSTaggedValue>(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH)); 3744514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> keyArray = 3754514f5e3Sopenharmony_ci JSHandle<JSTaggedValue>(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH)); 3764514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> valueArray = 3774514f5e3Sopenharmony_ci JSHandle<JSTaggedValue>(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH)); 3784514f5e3Sopenharmony_ci jsAPILightWeightMap->SetHashes(thread, hashArray); 3794514f5e3Sopenharmony_ci jsAPILightWeightMap->SetKeys(thread, keyArray); 3804514f5e3Sopenharmony_ci jsAPILightWeightMap->SetValues(thread, valueArray); 3814514f5e3Sopenharmony_ci jsAPILightWeightMap->SetLength(0); 3824514f5e3Sopenharmony_ci return jsAPILightWeightMap; 3834514f5e3Sopenharmony_ci } 3844514f5e3Sopenharmony_ci 3854514f5e3Sopenharmony_ci // JS_API_LIGHT_WEIGHT_SET 3864514f5e3Sopenharmony_ci JSHandle<JSAPILightWeightSet> NewJSAPILightWeightSet() 3874514f5e3Sopenharmony_ci { 3884514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 3894514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 3904514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPILightWeightSetObject = 3914514f5e3Sopenharmony_ci NewObject(JSAPILightWeightSet::SIZE, JSType::JS_API_LIGHT_WEIGHT_SET, proto); 3924514f5e3Sopenharmony_ci JSHandle<JSAPILightWeightSet> jsAPILightWeightSet = 3934514f5e3Sopenharmony_ci JSHandle<JSAPILightWeightSet>::Cast(jsAPILightWeightSetObject); 3944514f5e3Sopenharmony_ci JSHandle<TaggedArray> hashes = 3954514f5e3Sopenharmony_ci JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH); 3964514f5e3Sopenharmony_ci JSHandle<TaggedArray> values = 3974514f5e3Sopenharmony_ci JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH); 3984514f5e3Sopenharmony_ci jsAPILightWeightSet->SetHashes(thread, hashes); 3994514f5e3Sopenharmony_ci jsAPILightWeightSet->SetValues(thread, values); 4004514f5e3Sopenharmony_ci jsAPILightWeightSet->SetLength(0); 4014514f5e3Sopenharmony_ci return jsAPILightWeightSet; 4024514f5e3Sopenharmony_ci } 4034514f5e3Sopenharmony_ci 4044514f5e3Sopenharmony_ci // JS_API_TREE_MAP 4054514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> NewJSAPITreeMap() 4064514f5e3Sopenharmony_ci { 4074514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 4084514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 4094514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPITreeMapObject = NewObject(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto); 4104514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> jsAPITreeMap = JSHandle<JSAPITreeMap>::Cast(jsAPITreeMapObject); 4114514f5e3Sopenharmony_ci JSHandle<TaggedTreeMap> treeMap(thread, TaggedTreeMap::Create(thread)); 4124514f5e3Sopenharmony_ci jsAPITreeMap->SetTreeMap(thread, treeMap); 4134514f5e3Sopenharmony_ci return jsAPITreeMap; 4144514f5e3Sopenharmony_ci } 4154514f5e3Sopenharmony_ci 4164514f5e3Sopenharmony_ci // JS_API_TREE_SET 4174514f5e3Sopenharmony_ci JSHandle<JSAPITreeSet> NewJSAPITreeSet() 4184514f5e3Sopenharmony_ci { 4194514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 4204514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 4214514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPITreeSetObject = NewObject(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto); 4224514f5e3Sopenharmony_ci JSHandle<JSAPITreeSet> jsAPITreeSet = JSHandle<JSAPITreeSet>::Cast(jsAPITreeSetObject); 4234514f5e3Sopenharmony_ci JSHandle<TaggedTreeSet> treeSet(thread, TaggedTreeSet::Create(thread)); 4244514f5e3Sopenharmony_ci jsAPITreeSet->SetTreeSet(thread, treeSet); 4254514f5e3Sopenharmony_ci return jsAPITreeSet; 4264514f5e3Sopenharmony_ci } 4274514f5e3Sopenharmony_ci 4284514f5e3Sopenharmony_ci // JS_API_QUEUE 4294514f5e3Sopenharmony_ci JSHandle<JSAPIQueue> NewJSAPIQueue() 4304514f5e3Sopenharmony_ci { 4314514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 4324514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 4334514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 4344514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIQueueObject = NewObject(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto); 4354514f5e3Sopenharmony_ci JSHandle<JSAPIQueue> jsAPIQueue = JSHandle<JSAPIQueue>::Cast(jsAPIQueueObject); 4364514f5e3Sopenharmony_ci JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH); 4374514f5e3Sopenharmony_ci jsAPIQueue->SetLength(thread, JSTaggedValue(0)); 4384514f5e3Sopenharmony_ci jsAPIQueue->SetFront(0); 4394514f5e3Sopenharmony_ci jsAPIQueue->SetTail(0); 4404514f5e3Sopenharmony_ci jsAPIQueue->SetElements(thread, newElements); 4414514f5e3Sopenharmony_ci return jsAPIQueue; 4424514f5e3Sopenharmony_ci } 4434514f5e3Sopenharmony_ci // JS_API_DEQUE 4444514f5e3Sopenharmony_ci JSHandle<JSAPIDeque> NewJSAPIDeque() 4454514f5e3Sopenharmony_ci { 4464514f5e3Sopenharmony_ci ObjectFactory *factory = instance->GetFactory(); 4474514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 4484514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIDequeObject = NewObject(JSAPIDeque::SIZE, JSType::JS_API_DEQUE, proto); 4494514f5e3Sopenharmony_ci JSHandle<JSAPIDeque> jsAPIDeque = JSHandle<JSAPIDeque>::Cast(jsAPIDequeObject); 4504514f5e3Sopenharmony_ci JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIDeque::DEFAULT_CAPACITY_LENGTH); 4514514f5e3Sopenharmony_ci jsAPIDeque->SetFirst(0); 4524514f5e3Sopenharmony_ci jsAPIDeque->SetLast(0); 4534514f5e3Sopenharmony_ci jsAPIDeque->SetElements(instance->GetJSThread(), newElements); 4544514f5e3Sopenharmony_ci return jsAPIDeque; 4554514f5e3Sopenharmony_ci } 4564514f5e3Sopenharmony_ci // JS_API_STACK 4574514f5e3Sopenharmony_ci JSHandle<JSAPIStack> NewJSAPIStack() 4584514f5e3Sopenharmony_ci { 4594514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 4604514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIStackObject = NewObject(JSAPIStack::SIZE, JSType::JS_API_STACK, proto); 4614514f5e3Sopenharmony_ci JSHandle<JSAPIStack> jsAPIStack = JSHandle<JSAPIStack>::Cast(jsAPIStackObject); 4624514f5e3Sopenharmony_ci jsAPIStack->SetTop(0); 4634514f5e3Sopenharmony_ci return jsAPIStack; 4644514f5e3Sopenharmony_ci } 4654514f5e3Sopenharmony_ci 4664514f5e3Sopenharmony_ci // JS_API_PLAIN_ARRAY 4674514f5e3Sopenharmony_ci JSHandle<JSAPIPlainArray> NewJSAPIPlainArray() 4684514f5e3Sopenharmony_ci { 4694514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 4704514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 4714514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIPlainArrayObject = NewObject(JSAPIPlainArray::SIZE, JSType::JS_API_PLAIN_ARRAY, proto); 4724514f5e3Sopenharmony_ci JSHandle<JSAPIPlainArray> jsAPIPlainArray = JSHandle<JSAPIPlainArray>::Cast(jsAPIPlainArrayObject); 4734514f5e3Sopenharmony_ci JSHandle<TaggedArray> keys = 4744514f5e3Sopenharmony_ci JSAPIPlainArray::CreateSlot(thread, JSAPIPlainArray::DEFAULT_CAPACITY_LENGTH); 4754514f5e3Sopenharmony_ci JSHandle<TaggedArray> values = 4764514f5e3Sopenharmony_ci JSAPIPlainArray::CreateSlot(thread, JSAPIPlainArray::DEFAULT_CAPACITY_LENGTH); 4774514f5e3Sopenharmony_ci jsAPIPlainArray->SetKeys(thread, keys); 4784514f5e3Sopenharmony_ci jsAPIPlainArray->SetValues(thread, values); 4794514f5e3Sopenharmony_ci jsAPIPlainArray->SetLength(0); 4804514f5e3Sopenharmony_ci return jsAPIPlainArray; 4814514f5e3Sopenharmony_ci } 4824514f5e3Sopenharmony_ci 4834514f5e3Sopenharmony_ci // JS_API_LIST 4844514f5e3Sopenharmony_ci JSHandle<JSAPIList> NewJSAPIList() 4854514f5e3Sopenharmony_ci { 4864514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 4874514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 4884514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIListObject = NewObject(JSAPIList::SIZE, JSType::JS_API_LIST, proto); 4894514f5e3Sopenharmony_ci JSHandle<JSAPIList> jsAPIList = JSHandle<JSAPIList>::Cast(jsAPIListObject); 4904514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> taggedSingleList(thread, TaggedSingleList::Create(thread)); 4914514f5e3Sopenharmony_ci jsAPIList->SetSingleList(thread, taggedSingleList); 4924514f5e3Sopenharmony_ci return jsAPIList; 4934514f5e3Sopenharmony_ci } 4944514f5e3Sopenharmony_ci 4954514f5e3Sopenharmony_ci // JS_API_LINKED_LIST 4964514f5e3Sopenharmony_ci JSHandle<JSAPILinkedList> NewJSAPILinkedList() 4974514f5e3Sopenharmony_ci { 4984514f5e3Sopenharmony_ci JSThread *thread = instance->GetJSThread(); 4994514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetObjectFunctionPrototype(); 5004514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPILinkedListObject = NewObject(JSAPILinkedList::SIZE, JSType::JS_API_LINKED_LIST, proto); 5014514f5e3Sopenharmony_ci JSHandle<JSAPILinkedList> jsAPILinkedList = JSHandle<JSAPILinkedList>::Cast(jsAPILinkedListObject); 5024514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> linkedlist(thread, TaggedDoubleList::Create(thread)); 5034514f5e3Sopenharmony_ci jsAPILinkedList->SetDoubleList(thread, linkedlist); 5044514f5e3Sopenharmony_ci return jsAPILinkedList; 5054514f5e3Sopenharmony_ci } 5064514f5e3Sopenharmony_ci 5074514f5e3Sopenharmony_ci // JS_API_VECTOR 5084514f5e3Sopenharmony_ci JSHandle<JSAPIVector> NewJSAPIVector() 5094514f5e3Sopenharmony_ci { 5104514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = instance->GetGlobalEnv()->GetFunctionPrototype(); 5114514f5e3Sopenharmony_ci JSHandle<JSObject> jsAPIVectorObject = NewObject(JSAPIVector::SIZE, JSType::JS_API_VECTOR, proto); 5124514f5e3Sopenharmony_ci JSHandle<JSAPIVector> jsAPIVector = JSHandle<JSAPIVector>::Cast(jsAPIVectorObject); 5134514f5e3Sopenharmony_ci jsAPIVector->SetLength(0); 5144514f5e3Sopenharmony_ci return jsAPIVector; 5154514f5e3Sopenharmony_ci } 5164514f5e3Sopenharmony_ci 5174514f5e3Sopenharmony_ciprivate: 5184514f5e3Sopenharmony_ci EcmaVM *instance {nullptr}; 5194514f5e3Sopenharmony_ci}; 5204514f5e3Sopenharmony_ci 5214514f5e3Sopenharmony_ciclass MockHeapProfiler : public HeapProfilerInterface { 5224514f5e3Sopenharmony_cipublic: 5234514f5e3Sopenharmony_ci NO_MOVE_SEMANTIC(MockHeapProfiler); 5244514f5e3Sopenharmony_ci NO_COPY_SEMANTIC(MockHeapProfiler); 5254514f5e3Sopenharmony_ci explicit MockHeapProfiler(HeapProfilerInterface *profiler) : profiler_(profiler) {} 5264514f5e3Sopenharmony_ci ~MockHeapProfiler() override 5274514f5e3Sopenharmony_ci { 5284514f5e3Sopenharmony_ci allocEvtObj_.clear(); 5294514f5e3Sopenharmony_ci }; 5304514f5e3Sopenharmony_ci 5314514f5e3Sopenharmony_ci void AllocationEvent(TaggedObject *address, size_t size) override 5324514f5e3Sopenharmony_ci { 5334514f5e3Sopenharmony_ci allocEvtObj_.emplace(address, true); 5344514f5e3Sopenharmony_ci profiler_->AllocationEvent(address, size); 5354514f5e3Sopenharmony_ci } 5364514f5e3Sopenharmony_ci 5374514f5e3Sopenharmony_ci void MoveEvent(uintptr_t address, TaggedObject *forwardAddress, size_t size) override 5384514f5e3Sopenharmony_ci { 5394514f5e3Sopenharmony_ci return profiler_->MoveEvent(address, forwardAddress, size); 5404514f5e3Sopenharmony_ci } 5414514f5e3Sopenharmony_ci 5424514f5e3Sopenharmony_ci bool DumpHeapSnapshot(Stream *stream, const DumpSnapShotOption &dumpOption, Progress *progress = nullptr) override 5434514f5e3Sopenharmony_ci { 5444514f5e3Sopenharmony_ci return profiler_->DumpHeapSnapshot(stream, dumpOption, progress); 5454514f5e3Sopenharmony_ci } 5464514f5e3Sopenharmony_ci 5474514f5e3Sopenharmony_ci void DumpHeapSnapshot(const DumpSnapShotOption &dumpOption) override 5484514f5e3Sopenharmony_ci { 5494514f5e3Sopenharmony_ci profiler_->DumpHeapSnapshot(dumpOption); 5504514f5e3Sopenharmony_ci } 5514514f5e3Sopenharmony_ci 5524514f5e3Sopenharmony_ci bool GenerateHeapSnapshot(std::string &inputFilePath, std::string &outputPath) override 5534514f5e3Sopenharmony_ci { 5544514f5e3Sopenharmony_ci return profiler_->GenerateHeapSnapshot(inputFilePath, outputPath); 5554514f5e3Sopenharmony_ci } 5564514f5e3Sopenharmony_ci 5574514f5e3Sopenharmony_ci bool StartHeapTracking(double timeInterval, bool isVmMode = true, Stream *stream = nullptr, 5584514f5e3Sopenharmony_ci bool traceAllocation = false, bool newThread = true) override 5594514f5e3Sopenharmony_ci { 5604514f5e3Sopenharmony_ci return profiler_->StartHeapTracking(timeInterval, isVmMode, stream, traceAllocation, newThread); 5614514f5e3Sopenharmony_ci } 5624514f5e3Sopenharmony_ci 5634514f5e3Sopenharmony_ci bool StopHeapTracking(Stream *stream, Progress *progress = nullptr, bool newThread = true) override 5644514f5e3Sopenharmony_ci { 5654514f5e3Sopenharmony_ci return profiler_->StopHeapTracking(stream, progress, newThread); 5664514f5e3Sopenharmony_ci } 5674514f5e3Sopenharmony_ci 5684514f5e3Sopenharmony_ci bool UpdateHeapTracking(Stream *stream) override 5694514f5e3Sopenharmony_ci { 5704514f5e3Sopenharmony_ci return profiler_->UpdateHeapTracking(stream); 5714514f5e3Sopenharmony_ci } 5724514f5e3Sopenharmony_ci 5734514f5e3Sopenharmony_ci bool StartHeapSampling(uint64_t samplingInterval, int stackDepth = 128) override 5744514f5e3Sopenharmony_ci { 5754514f5e3Sopenharmony_ci return profiler_->StartHeapSampling(samplingInterval, stackDepth); 5764514f5e3Sopenharmony_ci } 5774514f5e3Sopenharmony_ci 5784514f5e3Sopenharmony_ci void StopHeapSampling() override 5794514f5e3Sopenharmony_ci { 5804514f5e3Sopenharmony_ci profiler_->StopHeapSampling(); 5814514f5e3Sopenharmony_ci } 5824514f5e3Sopenharmony_ci 5834514f5e3Sopenharmony_ci const struct SamplingInfo *GetAllocationProfile() override 5844514f5e3Sopenharmony_ci { 5854514f5e3Sopenharmony_ci return profiler_->GetAllocationProfile(); 5864514f5e3Sopenharmony_ci } 5874514f5e3Sopenharmony_ci 5884514f5e3Sopenharmony_ci size_t GetIdCount() override 5894514f5e3Sopenharmony_ci { 5904514f5e3Sopenharmony_ci return profiler_->GetIdCount(); 5914514f5e3Sopenharmony_ci } 5924514f5e3Sopenharmony_ci 5934514f5e3Sopenharmony_ci std::unordered_map<TaggedObject *, bool> allocEvtObj_; 5944514f5e3Sopenharmony_ci HeapProfilerInterface *profiler_ {nullptr}; 5954514f5e3Sopenharmony_ci}; 5964514f5e3Sopenharmony_ci 5974514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestAllocationEvent) 5984514f5e3Sopenharmony_ci{ 5994514f5e3Sopenharmony_ci const std::string abcFileName = HPROF_TEST_ABC_FILES_DIR"heapdump.abc"; 6004514f5e3Sopenharmony_ci const std::string jsFileName = HPROF_TEST_JS_FILES_DIR"heapdump.js"; 6014514f5e3Sopenharmony_ci MockHeapProfiler mockHeapProfiler(ecmaVm_->GetOrNewHeapProfile()); 6024514f5e3Sopenharmony_ci ecmaVm_->SetHeapProfile(&mockHeapProfiler); 6034514f5e3Sopenharmony_ci 6044514f5e3Sopenharmony_ci std::unordered_map<TaggedObject *, bool> ObjBeforeExecute; 6054514f5e3Sopenharmony_ci std::unordered_map<TaggedObject *, bool> *ObjMap = &ObjBeforeExecute; 6064514f5e3Sopenharmony_ci auto heap = ecmaVm_->GetHeap(); 6074514f5e3Sopenharmony_ci ASSERT_NE(heap, nullptr); 6084514f5e3Sopenharmony_ci auto countCb = [&ObjMap](TaggedObject *obj) { 6094514f5e3Sopenharmony_ci ObjMap->emplace(obj, true); 6104514f5e3Sopenharmony_ci }; 6114514f5e3Sopenharmony_ci heap->IterateOverObjects(countCb); 6124514f5e3Sopenharmony_ci RootVisitor rootVisitor = [&countCb]([[maybe_unused]] Root type, ObjectSlot slot) { 6134514f5e3Sopenharmony_ci JSTaggedValue value((slot).GetTaggedType()); 6144514f5e3Sopenharmony_ci if (!value.IsHeapObject()) { 6154514f5e3Sopenharmony_ci return; 6164514f5e3Sopenharmony_ci } 6174514f5e3Sopenharmony_ci TaggedObject *root = value.GetTaggedObject(); 6184514f5e3Sopenharmony_ci countCb(root); 6194514f5e3Sopenharmony_ci }; 6204514f5e3Sopenharmony_ci RootRangeVisitor rangeVisitor = [&rootVisitor]([[maybe_unused]] Root type, 6214514f5e3Sopenharmony_ci ObjectSlot start, ObjectSlot end) { 6224514f5e3Sopenharmony_ci for (ObjectSlot slot = start; slot < end; slot++) { 6234514f5e3Sopenharmony_ci rootVisitor(type, slot); 6244514f5e3Sopenharmony_ci } 6254514f5e3Sopenharmony_ci }; 6264514f5e3Sopenharmony_ci RootBaseAndDerivedVisitor derivedVisitor = [] 6274514f5e3Sopenharmony_ci ([[maybe_unused]] Root type, [[maybe_unused]] ObjectSlot base, [[maybe_unused]] ObjectSlot derived, 6284514f5e3Sopenharmony_ci [[maybe_unused]] uintptr_t baseOldObject) {}; 6294514f5e3Sopenharmony_ci ecmaVm_->Iterate(rootVisitor, rangeVisitor, VMRootVisitType::HEAP_SNAPSHOT); 6304514f5e3Sopenharmony_ci thread_->Iterate(rootVisitor, rangeVisitor, derivedVisitor); 6314514f5e3Sopenharmony_ci 6324514f5e3Sopenharmony_ci bool result = JSNApi::Execute(ecmaVm_, abcFileName, "heapdump"); 6334514f5e3Sopenharmony_ci EXPECT_TRUE(result); 6344514f5e3Sopenharmony_ci 6354514f5e3Sopenharmony_ci std::unordered_map<TaggedObject *, bool> ObjAfterExecute; 6364514f5e3Sopenharmony_ci ObjMap = &ObjAfterExecute; 6374514f5e3Sopenharmony_ci heap->IterateOverObjects(countCb); 6384514f5e3Sopenharmony_ci ecmaVm_->Iterate(rootVisitor, rangeVisitor, VMRootVisitType::HEAP_SNAPSHOT); 6394514f5e3Sopenharmony_ci thread_->Iterate(rootVisitor, rangeVisitor, derivedVisitor); 6404514f5e3Sopenharmony_ci ecmaVm_->SetHeapProfile(mockHeapProfiler.profiler_); 6414514f5e3Sopenharmony_ci 6424514f5e3Sopenharmony_ci std::unordered_map<std::string, int> noTraceObjCheck = 6434514f5e3Sopenharmony_ci {{"TaggedArray", 1}, {"AsyncFunction", 2}, {"LexicalEnv", 2}, {"Array", 3}, {"Function", 7}, {"Map", 1}, 6444514f5e3Sopenharmony_ci {"Object", 1}, {"Uint8 Clamped Array", 1}, {"Uint32 Array", 1}, {"Float32 Array", 1}, {"Int32 Array", 1}, 6454514f5e3Sopenharmony_ci {"Int16 Array", 1}, {"BigUint64 Array", 1}, {"Uint8 Array", 1}, {"Float64 Array", 1}, {"ByteArray", 11}, 6464514f5e3Sopenharmony_ci {"Int8 Array", 1}, {"BigInt64 Array", 1}, {"Uint16 Array", 1}}; 6474514f5e3Sopenharmony_ci bool pass = true; 6484514f5e3Sopenharmony_ci std::unordered_map<std::string, int> noTraceObj; 6494514f5e3Sopenharmony_ci for (auto o = ObjAfterExecute.begin(); o != ObjAfterExecute.end(); o++) { 6504514f5e3Sopenharmony_ci if (ObjBeforeExecute.find(o->first) != ObjBeforeExecute.end()) { 6514514f5e3Sopenharmony_ci continue; 6524514f5e3Sopenharmony_ci } 6534514f5e3Sopenharmony_ci if (mockHeapProfiler.allocEvtObj_.find(o->first) != mockHeapProfiler.allocEvtObj_.end()) { 6544514f5e3Sopenharmony_ci continue; 6554514f5e3Sopenharmony_ci } 6564514f5e3Sopenharmony_ci auto objType = o->first->GetClass()->GetObjectType(); 6574514f5e3Sopenharmony_ci std::string typeName = ConvertToStdString(JSHClass::DumpJSType(objType)); 6584514f5e3Sopenharmony_ci if (noTraceObjCheck.size() == 0) { 6594514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "Object not traced, Addr=" << o->first << ", TypeName=" << typeName; 6604514f5e3Sopenharmony_ci pass = false; 6614514f5e3Sopenharmony_ci } 6624514f5e3Sopenharmony_ci if (noTraceObj.find(typeName) == noTraceObj.end()) { 6634514f5e3Sopenharmony_ci noTraceObj.emplace(typeName, 0); 6644514f5e3Sopenharmony_ci } 6654514f5e3Sopenharmony_ci noTraceObj[typeName] += 1; 6664514f5e3Sopenharmony_ci } 6674514f5e3Sopenharmony_ci for (auto o = noTraceObj.begin(); o != noTraceObj.end(); o++) { 6684514f5e3Sopenharmony_ci if (noTraceObjCheck.find(o->first) == noTraceObjCheck.end()) { 6694514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "Object not traced, TypeName=" << o->first << ", count=" << o->second; 6704514f5e3Sopenharmony_ci pass = false; 6714514f5e3Sopenharmony_ci } 6724514f5e3Sopenharmony_ci } 6734514f5e3Sopenharmony_ci ASSERT_TRUE(pass); 6744514f5e3Sopenharmony_ci} 6754514f5e3Sopenharmony_ci 6764514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpFunctionUrl) 6774514f5e3Sopenharmony_ci{ 6784514f5e3Sopenharmony_ci const std::string abcFileName = HPROF_TEST_ABC_FILES_DIR"heapdump.abc"; 6794514f5e3Sopenharmony_ci 6804514f5e3Sopenharmony_ci bool result = JSNApi::Execute(ecmaVm_, abcFileName, "heapdump"); 6814514f5e3Sopenharmony_ci EXPECT_TRUE(result); 6824514f5e3Sopenharmony_ci 6834514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 6844514f5e3Sopenharmony_ci tester.GenerateSnapShot("testFunctionUrl.heapsnapshot"); 6854514f5e3Sopenharmony_ci 6864514f5e3Sopenharmony_ci // match function url 6874514f5e3Sopenharmony_ci std::string line; 6884514f5e3Sopenharmony_ci std::ifstream inputStream("testFunctionUrl.heapsnapshot"); 6894514f5e3Sopenharmony_ci bool strMatched = false; 6904514f5e3Sopenharmony_ci bool funcTempMatched = false; 6914514f5e3Sopenharmony_ci while (getline(inputStream, line)) { 6924514f5e3Sopenharmony_ci if (strMatched && funcTempMatched) { 6934514f5e3Sopenharmony_ci break; 6944514f5e3Sopenharmony_ci } 6954514f5e3Sopenharmony_ci if (line == "\"heapdump greet(line:98)\",") { 6964514f5e3Sopenharmony_ci strMatched = true; 6974514f5e3Sopenharmony_ci continue; 6984514f5e3Sopenharmony_ci } 6994514f5e3Sopenharmony_ci if (line == "\"ArkInternalFunctionTemplate\",") { 7004514f5e3Sopenharmony_ci funcTempMatched = true; 7014514f5e3Sopenharmony_ci continue; 7024514f5e3Sopenharmony_ci } 7034514f5e3Sopenharmony_ci } 7044514f5e3Sopenharmony_ci ASSERT_TRUE(strMatched); 7054514f5e3Sopenharmony_ci ASSERT_TRUE(funcTempMatched); 7064514f5e3Sopenharmony_ci} 7074514f5e3Sopenharmony_ci 7084514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, DISABLED_TestAllocationMassiveMoveNode) 7094514f5e3Sopenharmony_ci{ 7104514f5e3Sopenharmony_ci const std::string abcFileName = HPROF_TEST_ABC_FILES_DIR"allocation.abc"; 7114514f5e3Sopenharmony_ci HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(ecmaVm_); 7124514f5e3Sopenharmony_ci 7134514f5e3Sopenharmony_ci // start allocation 7144514f5e3Sopenharmony_ci bool start = heapProfile->StartHeapTracking(50); 7154514f5e3Sopenharmony_ci EXPECT_TRUE(start); 7164514f5e3Sopenharmony_ci 7174514f5e3Sopenharmony_ci auto currentTime = std::chrono::system_clock::now(); 7184514f5e3Sopenharmony_ci auto currentTimeBeforeMs = 7194514f5e3Sopenharmony_ci std::chrono::time_point_cast<std::chrono::milliseconds>(currentTime).time_since_epoch().count(); 7204514f5e3Sopenharmony_ci 7214514f5e3Sopenharmony_ci bool result = JSNApi::Execute(ecmaVm_, abcFileName, "allocation"); 7224514f5e3Sopenharmony_ci 7234514f5e3Sopenharmony_ci currentTime = std::chrono::system_clock::now(); 7244514f5e3Sopenharmony_ci auto currentTimeAfterMs = 7254514f5e3Sopenharmony_ci std::chrono::time_point_cast<std::chrono::milliseconds>(currentTime).time_since_epoch().count(); 7264514f5e3Sopenharmony_ci EXPECT_TRUE(result); 7274514f5e3Sopenharmony_ci 7284514f5e3Sopenharmony_ci std::string fileName = "test.allocationtime"; 7294514f5e3Sopenharmony_ci fstream outputString(fileName, std::ios::out); 7304514f5e3Sopenharmony_ci outputString.close(); 7314514f5e3Sopenharmony_ci outputString.clear(); 7324514f5e3Sopenharmony_ci 7334514f5e3Sopenharmony_ci // stop allocation 7344514f5e3Sopenharmony_ci FileStream stream(fileName.c_str()); 7354514f5e3Sopenharmony_ci bool stop = heapProfile->StopHeapTracking(&stream, nullptr); 7364514f5e3Sopenharmony_ci EXPECT_TRUE(stop); 7374514f5e3Sopenharmony_ci HeapProfilerInterface::Destroy(ecmaVm_); 7384514f5e3Sopenharmony_ci 7394514f5e3Sopenharmony_ci auto timeSpent = currentTimeAfterMs - currentTimeBeforeMs; 7404514f5e3Sopenharmony_ci long long int limitedTimeMs = 30000; 7414514f5e3Sopenharmony_ci ASSERT_TRUE(timeSpent < limitedTimeMs); 7424514f5e3Sopenharmony_ci} 7434514f5e3Sopenharmony_ci 7444514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName1) 7454514f5e3Sopenharmony_ci{ 7464514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv(); 7474514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 7484514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 7494514f5e3Sopenharmony_ci 7504514f5e3Sopenharmony_ci // TAGGED_ARRAY 7514514f5e3Sopenharmony_ci factory->NewTaggedArray(10); 7524514f5e3Sopenharmony_ci // LEXICAL_ENV 7534514f5e3Sopenharmony_ci factory->NewLexicalEnv(10); 7544514f5e3Sopenharmony_ci // CONSTANT_POOL 7554514f5e3Sopenharmony_ci factory->NewConstantPool(10); 7564514f5e3Sopenharmony_ci // PROFILE_TYPE_INFO 7574514f5e3Sopenharmony_ci factory->NewProfileTypeInfo(10); 7584514f5e3Sopenharmony_ci // TAGGED_DICTIONARY 7594514f5e3Sopenharmony_ci factory->NewDictionaryArray(10); 7604514f5e3Sopenharmony_ci // AOT_LITERAL_INFO 7614514f5e3Sopenharmony_ci factory->NewAOTLiteralInfo(10); 7624514f5e3Sopenharmony_ci // VTABLE 7634514f5e3Sopenharmony_ci factory->NewVTable(10); 7644514f5e3Sopenharmony_ci // COW_TAGGED_ARRAY 7654514f5e3Sopenharmony_ci factory->NewCOWTaggedArray(10); 7664514f5e3Sopenharmony_ci // HCLASS 7674514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = env->GetFunctionPrototype(); 7684514f5e3Sopenharmony_ci factory->NewEcmaHClass(JSHClass::SIZE, JSType::HCLASS, proto); 7694514f5e3Sopenharmony_ci // LINKED_NODE 7704514f5e3Sopenharmony_ci JSHandle<LinkedNode> linkedNode(thread_, JSTaggedValue::Hole()); 7714514f5e3Sopenharmony_ci factory->NewLinkedNode(1, JSHandle<JSTaggedValue>(thread_, JSTaggedValue::Hole()), 7724514f5e3Sopenharmony_ci JSHandle<JSTaggedValue>(thread_, JSTaggedValue::Hole()), linkedNode); 7734514f5e3Sopenharmony_ci // JS_NATIVE_POINTER 7744514f5e3Sopenharmony_ci auto newData = ecmaVm_->GetNativeAreaAllocator()->AllocateBuffer(8); 7754514f5e3Sopenharmony_ci factory->NewJSNativePointer(newData); 7764514f5e3Sopenharmony_ci 7774514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_1.heapsnapshot"); 7784514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalArray[")); 7794514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"LexicalEnv[")); 7804514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalConstantPool[")); 7814514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalProfileTypeInfo[")); 7824514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalDict[")); 7834514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalAOTLiteralInfo[")); 7844514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalVTable[")); 7854514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"ArkInternalCOWArray[")); 7864514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"HiddenClass(NonMovable)")); 7874514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"LinkedNode\"")); 7884514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "\"JSNativePointer\"")); 7894514f5e3Sopenharmony_ci // Test Not Found 7904514f5e3Sopenharmony_ci ASSERT_TRUE(!tester.MatchHeapDumpString("testGenerateNodeName_1.heapsnapshot", "*#@failed case")); 7914514f5e3Sopenharmony_ci} 7924514f5e3Sopenharmony_ci 7934514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName2) 7944514f5e3Sopenharmony_ci{ 7954514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 7964514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 7974514f5e3Sopenharmony_ci 7984514f5e3Sopenharmony_ci // JS_ERROR 7994514f5e3Sopenharmony_ci JSHandle<EcmaString> handleMessage(thread_, EcmaStringAccessor::CreateEmptyString(ecmaVm_)); 8004514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::ERROR, handleMessage); 8014514f5e3Sopenharmony_ci // JS_EVAL_ERROR 8024514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::EVAL_ERROR, handleMessage); 8034514f5e3Sopenharmony_ci // JS_RANGE_ERROR 8044514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::RANGE_ERROR, handleMessage); 8054514f5e3Sopenharmony_ci // JS_TYPE_ERROR 8064514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::TYPE_ERROR, handleMessage); 8074514f5e3Sopenharmony_ci // JS_AGGREGATE_ERROR 8084514f5e3Sopenharmony_ci factory->NewJSAggregateError(); 8094514f5e3Sopenharmony_ci // JS_REFERENCE_ERROR 8104514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::REFERENCE_ERROR, handleMessage); 8114514f5e3Sopenharmony_ci // JS_URI_ERROR 8124514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::URI_ERROR, handleMessage); 8134514f5e3Sopenharmony_ci // JS_SYNTAX_ERROR 8144514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::SYNTAX_ERROR, handleMessage); 8154514f5e3Sopenharmony_ci // JS_OOM_ERROR 8164514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::OOM_ERROR, handleMessage); 8174514f5e3Sopenharmony_ci // JS_TERMINATION_ERROR 8184514f5e3Sopenharmony_ci factory->NewJSError(ErrorType::TERMINATION_ERROR, handleMessage); 8194514f5e3Sopenharmony_ci 8204514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_2.heapsnapshot"); 8214514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Error\"")); 8224514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Eval Error\"")); 8234514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Range Error\"")); 8244514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Type Error\"")); 8254514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Aggregate Error\"")); 8264514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Reference Error\"")); 8274514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Uri Error\"")); 8284514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Syntax Error\"")); 8294514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"OutOfMemory Error\"")); 8304514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_2.heapsnapshot", "\"Termination Error\"")); 8314514f5e3Sopenharmony_ci} 8324514f5e3Sopenharmony_ci 8334514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName3) 8344514f5e3Sopenharmony_ci{ 8354514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 8364514f5e3Sopenharmony_ci 8374514f5e3Sopenharmony_ci // JS_INT8_ARRAY 8384514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_INT8_ARRAY); 8394514f5e3Sopenharmony_ci // JS_UINT8_ARRAY 8404514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_UINT8_ARRAY); 8414514f5e3Sopenharmony_ci // JS_UINT8_CLAMPED_ARRAY 8424514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_UINT8_CLAMPED_ARRAY); 8434514f5e3Sopenharmony_ci // JS_INT16_ARRAY 8444514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_INT16_ARRAY); 8454514f5e3Sopenharmony_ci // JS_UINT16_ARRAY 8464514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_UINT16_ARRAY); 8474514f5e3Sopenharmony_ci // JS_INT32_ARRAY 8484514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_INT32_ARRAY); 8494514f5e3Sopenharmony_ci // JS_UINT32_ARRAY 8504514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_UINT32_ARRAY); 8514514f5e3Sopenharmony_ci // JS_FLOAT32_ARRAY 8524514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_FLOAT32_ARRAY); 8534514f5e3Sopenharmony_ci // JS_FLOAT64_ARRAY 8544514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_FLOAT64_ARRAY); 8554514f5e3Sopenharmony_ci // JS_BIGINT64_ARRAY 8564514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_BIGINT64_ARRAY); 8574514f5e3Sopenharmony_ci // JS_BIGUINT64_ARRAY 8584514f5e3Sopenharmony_ci tester.CreateNumberTypedArray(JSType::JS_BIGUINT64_ARRAY); 8594514f5e3Sopenharmony_ci 8604514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_3.heapsnapshot"); 8614514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Int8 Array\"")); 8624514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Uint8 Array\"")); 8634514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Uint8 Clamped Array\"")); 8644514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Int16 Array\"")); 8654514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Uint16 Array\"")); 8664514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Int32 Array\"")); 8674514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Uint32 Array\"")); 8684514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Float32 Array\"")); 8694514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"Float64 Array\"")); 8704514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"BigInt64 Array\"")); 8714514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_3.heapsnapshot", "\"BigUint64 Array\"")); 8724514f5e3Sopenharmony_ci} 8734514f5e3Sopenharmony_ci 8744514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName4) 8754514f5e3Sopenharmony_ci{ 8764514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 8774514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 8784514f5e3Sopenharmony_ci 8794514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = ecmaVm_->GetGlobalEnv()->GetFunctionPrototype(); 8804514f5e3Sopenharmony_ci // JS_SET 8814514f5e3Sopenharmony_ci tester.NewJSSet(); 8824514f5e3Sopenharmony_ci // JS_SHARED_SET 8834514f5e3Sopenharmony_ci tester.NewJSSharedSet(); 8844514f5e3Sopenharmony_ci // JS_MAP 8854514f5e3Sopenharmony_ci tester.NewJSMap(); 8864514f5e3Sopenharmony_ci // JS_SHARED_MAP 8874514f5e3Sopenharmony_ci tester.NewJSSharedMap(); 8884514f5e3Sopenharmony_ci // JS_WEAK_SET 8894514f5e3Sopenharmony_ci tester.NewJSWeakSet(); 8904514f5e3Sopenharmony_ci // JS_WEAK_MAP 8914514f5e3Sopenharmony_ci tester.NewJSWeakMap(); 8924514f5e3Sopenharmony_ci // JS_ARRAY 8934514f5e3Sopenharmony_ci factory->NewJSArray(); 8944514f5e3Sopenharmony_ci // JS_TYPED_ARRAY 8954514f5e3Sopenharmony_ci tester.NewObject(JSTypedArray::SIZE, JSType::JS_TYPED_ARRAY, proto); 8964514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_4.heapsnapshot"); 8974514f5e3Sopenharmony_ci 8984514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Set\"")); 8994514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"SharedSet\"")); 9004514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Map\"")); 9014514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"SharedMap\"")); 9024514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"WeakSet\"")); 9034514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"WeakMap\"")); 9044514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"JSArray\"")); 9054514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Typed Array\"")); 9064514f5e3Sopenharmony_ci} 9074514f5e3Sopenharmony_ci 9084514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName5) 9094514f5e3Sopenharmony_ci{ 9104514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 9114514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 9124514f5e3Sopenharmony_ci 9134514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = ecmaVm_->GetGlobalEnv()->GetFunctionPrototype(); 9144514f5e3Sopenharmony_ci // JS_REG_EXP 9154514f5e3Sopenharmony_ci tester.NewObject(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); 9164514f5e3Sopenharmony_ci // JS_DATE 9174514f5e3Sopenharmony_ci tester.NewObject(JSDate::SIZE, JSType::JS_DATE, proto); 9184514f5e3Sopenharmony_ci // JS_ARGUMENTS 9194514f5e3Sopenharmony_ci factory->NewJSArguments(); 9204514f5e3Sopenharmony_ci // JS_PROXY 9214514f5e3Sopenharmony_ci tester.NewJSProxy(); 9224514f5e3Sopenharmony_ci // JS_PRIMITIVE_REF 9234514f5e3Sopenharmony_ci tester.NewObject(JSPrimitiveRef::SIZE, JSType::JS_PRIMITIVE_REF, proto); 9244514f5e3Sopenharmony_ci // JS_DATA_VIEW 9254514f5e3Sopenharmony_ci factory->NewJSDataView(factory->NewJSArrayBuffer(10), 5, 5); 9264514f5e3Sopenharmony_ci 9274514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_5.heapsnapshot"); 9284514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_5.heapsnapshot", "\"Regexp\"")); 9294514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_5.heapsnapshot", "\"Date\"")); 9304514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_5.heapsnapshot", "\"Arguments\"")); 9314514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_5.heapsnapshot", "\"Proxy\"")); 9324514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_5.heapsnapshot", "\"Primitive\"")); 9334514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_5.heapsnapshot", "\"DataView\"")); 9344514f5e3Sopenharmony_ci} 9354514f5e3Sopenharmony_ci 9364514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName6) 9374514f5e3Sopenharmony_ci{ 9384514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 9394514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 9404514f5e3Sopenharmony_ci 9414514f5e3Sopenharmony_ci // JS_FORIN_ITERATOR 9424514f5e3Sopenharmony_ci tester.NewJSForInIterator(); 9434514f5e3Sopenharmony_ci // JS_MAP_ITERATOR 9444514f5e3Sopenharmony_ci factory->NewJSMapIterator(tester.NewJSMap(), IterationKind::KEY); 9454514f5e3Sopenharmony_ci // JS_SHARED_MAP_ITERATOR 9464514f5e3Sopenharmony_ci factory->NewJSMapIterator(tester.NewJSSharedMap(), IterationKind::KEY); 9474514f5e3Sopenharmony_ci // JS_SET_ITERATOR 9484514f5e3Sopenharmony_ci factory->NewJSSetIterator(tester.NewJSSet(), IterationKind::KEY); 9494514f5e3Sopenharmony_ci // JS_SHARED_SET_ITERATOR 9504514f5e3Sopenharmony_ci factory->NewJSSetIterator(tester.NewJSSharedSet(), IterationKind::KEY); 9514514f5e3Sopenharmony_ci // JS_REG_EXP_ITERATOR 9524514f5e3Sopenharmony_ci tester.NewJSRegExpIterator(); 9534514f5e3Sopenharmony_ci // JS_ARRAY_ITERATOR 9544514f5e3Sopenharmony_ci factory->NewJSArrayIterator(JSHandle<JSObject>::Cast(factory->NewJSArray()), IterationKind::KEY); 9554514f5e3Sopenharmony_ci // JS_STRING_ITERATOR 9564514f5e3Sopenharmony_ci JSStringIterator::CreateStringIterator(thread_, factory->GetEmptyString()); 9574514f5e3Sopenharmony_ci 9584514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_6.heapsnapshot"); 9594514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"ForinInterator\"")); 9604514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"MapIterator\"")); 9614514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"SharedMapIterator\"")); 9624514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"SetIterator\"")); 9634514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"SharedSetIterator\"")); 9644514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"RegExpIterator\"")); 9654514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"ArrayIterator\"")); 9664514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_6.heapsnapshot", "\"StringIterator\"")); 9674514f5e3Sopenharmony_ci} 9684514f5e3Sopenharmony_ci 9694514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName7) 9704514f5e3Sopenharmony_ci{ 9714514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 9724514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 9734514f5e3Sopenharmony_ci // JS_ARRAY_BUFFER 9744514f5e3Sopenharmony_ci factory->NewJSArrayBuffer(10); 9754514f5e3Sopenharmony_ci // JS_SHARED_ARRAY_BUFFER 9764514f5e3Sopenharmony_ci factory->NewJSSharedArrayBuffer(10); 9774514f5e3Sopenharmony_ci // PROMISE_REACTIONS 9784514f5e3Sopenharmony_ci factory->NewPromiseReaction(); 9794514f5e3Sopenharmony_ci // PROMISE_CAPABILITY 9804514f5e3Sopenharmony_ci factory->NewPromiseCapability(); 9814514f5e3Sopenharmony_ci // PROMISE_ITERATOR_RECORD 9824514f5e3Sopenharmony_ci tester.NewPromiseIteratorRecord(); 9834514f5e3Sopenharmony_ci // PROMISE_RECORD 9844514f5e3Sopenharmony_ci factory->NewPromiseRecord(); 9854514f5e3Sopenharmony_ci // RESOLVING_FUNCTIONS_RECORD 9864514f5e3Sopenharmony_ci factory->NewResolvingFunctionsRecord(); 9874514f5e3Sopenharmony_ci // JS_PROMISE 9884514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = ecmaVm_->GetGlobalEnv()->GetFunctionPrototype(); 9894514f5e3Sopenharmony_ci tester.NewObject(JSPromise::SIZE, JSType::JS_PROMISE, proto); 9904514f5e3Sopenharmony_ci // ASYNC_GENERATOR_REQUEST 9914514f5e3Sopenharmony_ci factory->NewAsyncGeneratorRequest(); 9924514f5e3Sopenharmony_ci 9934514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_7.heapsnapshot"); 9944514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"ArrayBuffer\"")); 9954514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"SharedArrayBuffer\"")); 9964514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"PromiseReaction\"")); 9974514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"PromiseCapability\"")); 9984514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"PromiseIteratorRecord\"")); 9994514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"PromiseRecord\"")); 10004514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"ResolvingFunctionsRecord\"")); 10014514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"Promise\"")); 10024514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_7.heapsnapshot", "\"AsyncGeneratorRequest\"")); 10034514f5e3Sopenharmony_ci} 10044514f5e3Sopenharmony_ci 10054514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName8) 10064514f5e3Sopenharmony_ci{ 10074514f5e3Sopenharmony_ci auto factory = ecmaVm_->GetFactory(); 10084514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 10094514f5e3Sopenharmony_ci // JS_API_ARRAY_LIST 10104514f5e3Sopenharmony_ci auto jsAPIArrayList = tester.NewJSAPIArrayList(); 10114514f5e3Sopenharmony_ci // JS_API_ARRAYLIST_ITERATOR 10124514f5e3Sopenharmony_ci factory->NewJSAPIArrayListIterator(jsAPIArrayList); 10134514f5e3Sopenharmony_ci // JS_API_HASH_MAP 10144514f5e3Sopenharmony_ci auto jsAPIHashMap = tester.NewJSAPIHashMap(); 10154514f5e3Sopenharmony_ci // JS_API_HASHMAP_ITERATOR 10164514f5e3Sopenharmony_ci factory->NewJSAPIHashMapIterator(jsAPIHashMap, IterationKind::KEY); 10174514f5e3Sopenharmony_ci // JS_API_HASH_SET 10184514f5e3Sopenharmony_ci auto jsAPIHashSet = tester.NewJSAPIHashSet(); 10194514f5e3Sopenharmony_ci // JS_API_HASHSET_ITERATOR 10204514f5e3Sopenharmony_ci factory->NewJSAPIHashSetIterator(jsAPIHashSet, IterationKind::KEY); 10214514f5e3Sopenharmony_ci // JS_API_LIGHT_WEIGHT_MAP 10224514f5e3Sopenharmony_ci auto jsAPILightWeightMap = tester.NewJSAPILightWeightMap(); 10234514f5e3Sopenharmony_ci // JS_API_LIGHT_WEIGHT_MAP_ITERATOR 10244514f5e3Sopenharmony_ci factory->NewJSAPILightWeightMapIterator(jsAPILightWeightMap, IterationKind::KEY); 10254514f5e3Sopenharmony_ci // JS_API_LIGHT_WEIGHT_SET 10264514f5e3Sopenharmony_ci auto jsAPILightWeightSet = tester.NewJSAPILightWeightSet(); 10274514f5e3Sopenharmony_ci // JS_API_LIGHT_WEIGHT_SET_ITERATOR 10284514f5e3Sopenharmony_ci factory->NewJSAPILightWeightSetIterator(jsAPILightWeightSet, IterationKind::KEY); 10294514f5e3Sopenharmony_ci 10304514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_8.heapsnapshot"); 10314514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"ArrayList\"")); 10324514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"ArrayListIterator\"")); 10334514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"HashMap\"")); 10344514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"HashSet\"")); 10354514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"HashMapIterator\"")); 10364514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"HashSetIterator\"")); 10374514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"LightWeightMap\"")); 10384514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"LightWeightMapIterator\"")); 10394514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"LightWeightSet\"")); 10404514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_8.heapsnapshot", "\"LightWeightSetIterator\"")); 10414514f5e3Sopenharmony_ci} 10424514f5e3Sopenharmony_ci 10434514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpGenerateNodeName9) 10444514f5e3Sopenharmony_ci{ 10454514f5e3Sopenharmony_ci auto factory = ecmaVm_->GetFactory(); 10464514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 10474514f5e3Sopenharmony_ci // JS_API_TREE_MAP 10484514f5e3Sopenharmony_ci auto jsAPITreeMap = tester.NewJSAPITreeMap(); 10494514f5e3Sopenharmony_ci // JS_API_TREEMAP_ITERATOR 10504514f5e3Sopenharmony_ci factory->NewJSAPITreeMapIterator(jsAPITreeMap, IterationKind::KEY); 10514514f5e3Sopenharmony_ci // JS_API_TREE_SET 10524514f5e3Sopenharmony_ci auto jsAPITreeSet = tester.NewJSAPITreeSet(); 10534514f5e3Sopenharmony_ci // JS_API_TREESET_ITERATOR 10544514f5e3Sopenharmony_ci factory->NewJSAPITreeSetIterator(jsAPITreeSet, IterationKind::KEY); 10554514f5e3Sopenharmony_ci // JS_API_VECTOR 10564514f5e3Sopenharmony_ci auto jsAPIVector = tester.NewJSAPIVector(); 10574514f5e3Sopenharmony_ci // JS_API_VECTOR_ITERATOR 10584514f5e3Sopenharmony_ci factory->NewJSAPIVectorIterator(jsAPIVector); 10594514f5e3Sopenharmony_ci // JS_API_QUEUE 10604514f5e3Sopenharmony_ci auto jsAPIQueue = tester.NewJSAPIQueue(); 10614514f5e3Sopenharmony_ci // JS_API_QUEUE_ITERATOR 10624514f5e3Sopenharmony_ci factory->NewJSAPIQueueIterator(jsAPIQueue); 10634514f5e3Sopenharmony_ci // JS_API_DEQUE 10644514f5e3Sopenharmony_ci auto jsAPIDeque = tester.NewJSAPIDeque(); 10654514f5e3Sopenharmony_ci // JS_API_DEQUE_ITERATOR 10664514f5e3Sopenharmony_ci factory->NewJSAPIDequeIterator(jsAPIDeque); 10674514f5e3Sopenharmony_ci // JS_API_STACK 10684514f5e3Sopenharmony_ci auto jsAPIStack = tester.NewJSAPIStack(); 10694514f5e3Sopenharmony_ci // JS_API_STACK_ITERATOR 10704514f5e3Sopenharmony_ci factory->NewJSAPIStackIterator(jsAPIStack); 10714514f5e3Sopenharmony_ci // JS_API_LIST 10724514f5e3Sopenharmony_ci tester.NewJSAPIList(); 10734514f5e3Sopenharmony_ci // JS_API_LINKED_LIST 10744514f5e3Sopenharmony_ci tester.NewJSAPILinkedList(); 10754514f5e3Sopenharmony_ci // JS_API_PLAIN_ARRAY 10764514f5e3Sopenharmony_ci auto jsAPIPlainArray = tester.NewJSAPIPlainArray(); 10774514f5e3Sopenharmony_ci // JS_API_PLAIN_ARRAY_ITERATOR 10784514f5e3Sopenharmony_ci factory->NewJSAPIPlainArrayIterator(jsAPIPlainArray, IterationKind::KEY); 10794514f5e3Sopenharmony_ci 10804514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_9.heapsnapshot"); 10814514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"TreeMap\"")); 10824514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"TreeMapIterator\"")); 10834514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"TreeSet\"")); 10844514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"TreeSetIterator\"")); 10854514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"Vector\"")); 10864514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"VectorIterator\"")); 10874514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"Queue\"")); 10884514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"QueueIterator\"")); 10894514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"Deque\"")); 10904514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"DequeIterator\"")); 10914514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"Stack\"")); 10924514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"StackIterator\"")); 10934514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"List\"")); 10944514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"LinkedList\"")); 10954514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"PlainArray\"")); 10964514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_9.heapsnapshot", "\"PlainArrayIterator\"")); 10974514f5e3Sopenharmony_ci} 10984514f5e3Sopenharmony_ci 10994514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestHeapDumpBinaryDump) 11004514f5e3Sopenharmony_ci{ 11014514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 11024514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 11034514f5e3Sopenharmony_ci // PROMISE_ITERATOR_RECORD 11044514f5e3Sopenharmony_ci tester.NewPromiseIteratorRecord(); 11054514f5e3Sopenharmony_ci // PROMISE_RECORD 11064514f5e3Sopenharmony_ci factory->NewPromiseRecord(); 11074514f5e3Sopenharmony_ci // JS_ARRAY_BUFFER 11084514f5e3Sopenharmony_ci factory->NewJSArrayBuffer(10); 11094514f5e3Sopenharmony_ci // JS_SHARED_ARRAY_BUFFER 11104514f5e3Sopenharmony_ci factory->NewJSSharedArrayBuffer(10); 11114514f5e3Sopenharmony_ci // PROMISE_REACTIONS 11124514f5e3Sopenharmony_ci factory->NewPromiseReaction(); 11134514f5e3Sopenharmony_ci // PROMISE_CAPABILITY 11144514f5e3Sopenharmony_ci factory->NewPromiseCapability(); 11154514f5e3Sopenharmony_ci // RESOLVING_FUNCTIONS_RECORD 11164514f5e3Sopenharmony_ci factory->NewResolvingFunctionsRecord(); 11174514f5e3Sopenharmony_ci // JS_PROMISE 11184514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = ecmaVm_->GetGlobalEnv()->GetFunctionPrototype(); 11194514f5e3Sopenharmony_ci tester.NewObject(JSPromise::SIZE, JSType::JS_PROMISE, proto); 11204514f5e3Sopenharmony_ci // ASYNC_GENERATOR_REQUEST 11214514f5e3Sopenharmony_ci factory->NewAsyncGeneratorRequest(); 11224514f5e3Sopenharmony_ci // JS_WEAK_SET 11234514f5e3Sopenharmony_ci tester.NewJSWeakSet(); 11244514f5e3Sopenharmony_ci // JS_WEAK_MAP 11254514f5e3Sopenharmony_ci tester.NewJSWeakMap(); 11264514f5e3Sopenharmony_ci std::string rawHeapPath("test_binary_dump.raw"); 11274514f5e3Sopenharmony_ci bool ret = tester.GenerateRawHeapSnashot(rawHeapPath); 11284514f5e3Sopenharmony_ci ASSERT_TRUE(ret); 11294514f5e3Sopenharmony_ci std::ifstream file(rawHeapPath, std::ios::binary); 11304514f5e3Sopenharmony_ci std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); 11314514f5e3Sopenharmony_ci ASSERT_TRUE(content.size() > 0); 11324514f5e3Sopenharmony_ci auto u64Ptr = reinterpret_cast<const uint64_t *>(content.c_str()); 11334514f5e3Sopenharmony_ci ASSERT_TRUE(*u64Ptr > 0); 11344514f5e3Sopenharmony_ci std::string snapshotPath("test_binary_dump.heapsnapshot"); 11354514f5e3Sopenharmony_ci ret = tester.DecodeRawHeapSnashot(rawHeapPath, snapshotPath); 11364514f5e3Sopenharmony_ci ASSERT_TRUE(ret); 11374514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString(snapshotPath, "\"SharedArrayBuffer\"")); 11384514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString(snapshotPath, "\"WeakSet\"")); 11394514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString(snapshotPath, "\"WeakMap\"")); 11404514f5e3Sopenharmony_ci} 11414514f5e3Sopenharmony_ci 11424514f5e3Sopenharmony_ciHWTEST_F_L0(HeapDumpTest, TestSharedFullGCInHeapDump) 11434514f5e3Sopenharmony_ci{ 11444514f5e3Sopenharmony_ci ObjectFactory *factory = ecmaVm_->GetFactory(); 11454514f5e3Sopenharmony_ci HeapDumpTestHelper tester(ecmaVm_); 11464514f5e3Sopenharmony_ci 11474514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = ecmaVm_->GetGlobalEnv()->GetFunctionPrototype(); 11484514f5e3Sopenharmony_ci // JS_SET 11494514f5e3Sopenharmony_ci tester.NewJSSet(); 11504514f5e3Sopenharmony_ci // JS_SHARED_SET 11514514f5e3Sopenharmony_ci tester.NewJSSharedSet(); 11524514f5e3Sopenharmony_ci // JS_MAP 11534514f5e3Sopenharmony_ci tester.NewJSMap(); 11544514f5e3Sopenharmony_ci // JS_SHARED_MAP 11554514f5e3Sopenharmony_ci tester.NewJSSharedMap(); 11564514f5e3Sopenharmony_ci // JS_WEAK_SET 11574514f5e3Sopenharmony_ci tester.NewJSWeakSet(); 11584514f5e3Sopenharmony_ci // JS_WEAK_MAP 11594514f5e3Sopenharmony_ci tester.NewJSWeakMap(); 11604514f5e3Sopenharmony_ci // JS_ARRAY 11614514f5e3Sopenharmony_ci factory->NewJSArray(); 11624514f5e3Sopenharmony_ci // JS_TYPED_ARRAY 11634514f5e3Sopenharmony_ci tester.NewObject(JSTypedArray::SIZE, JSType::JS_TYPED_ARRAY, proto); 11644514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_4.heapsnapshot"); 11654514f5e3Sopenharmony_ci 11664514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Set\"")); 11674514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"SharedSet\"")); 11684514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Map\"")); 11694514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"SharedMap\"")); 11704514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"WeakSet\"")); 11714514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"WeakMap\"")); 11724514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"JSArray\"")); 11734514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Typed Array\"")); 11744514f5e3Sopenharmony_ci 11754514f5e3Sopenharmony_ci auto sHeap = SharedHeap::GetInstance(); 11764514f5e3Sopenharmony_ci sHeap->CollectGarbage<TriggerGCType::SHARED_FULL_GC, GCReason::OTHER>(thread_); 11774514f5e3Sopenharmony_ci 11784514f5e3Sopenharmony_ci tester.GenerateSnapShot("testGenerateNodeName_4.heapsnapshot"); 11794514f5e3Sopenharmony_ci 11804514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Set\"")); 11814514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"SharedSet\"")); 11824514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Map\"")); 11834514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"SharedMap\"")); 11844514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"WeakSet\"")); 11854514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"WeakMap\"")); 11864514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"JSArray\"")); 11874514f5e3Sopenharmony_ci ASSERT_TRUE(tester.MatchHeapDumpString("testGenerateNodeName_4.heapsnapshot", "\"Typed Array\"")); 11884514f5e3Sopenharmony_ci} 11894514f5e3Sopenharmony_ci} 1190