From fe3c84b7368406af3b84b5ac026372bdd09dd4bf Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Tue, 9 Sep 2025 12:41:02 +0300 Subject: [PATCH 1/2] Sync with master Change-Id: If7add8596329fc9dc1de6ad0bb12e1b816db7584 Signed-off-by: Artem Udovichenko --- codecheck_ignore.json | 3 +- common_interfaces/base/common.h | 2 +- common_interfaces/base_runtime.h | 90 ++++++++++++++-- common_interfaces/heap/heap_allocator.h | 13 +-- common_interfaces/heap/heap_visitor.h | 5 + common_interfaces/objects/base_object.h | 1 + .../objects/base_object_accessor.h | 27 ++++- .../objects/base_object_dispatcher.h | 28 ++--- .../objects/base_object_operator.h | 1 + common_interfaces/objects/base_state_word.h | 1 + common_interfaces/objects/base_type.h | 3 +- .../objects/base_type_converter.h | 12 ++- common_interfaces/objects/field.h | 1 + common_interfaces/objects/ref_field.h | 1 + .../objects/string/line_string-inl.h | 22 ++++ .../objects/string/line_string.h | 6 +- .../profiler/heap_profiler_listener.h | 14 ++- common_interfaces/thread/mutator_base.h | 39 +++++-- common_interfaces/thread/thread_holder.h | 12 ++- static_core/assembler/BUILD.gn | 6 +- static_core/assembler/assembly-emitter.cpp | 4 + static_core/cmake/ClangTidy.cmake | 12 +++ .../compiler/tests/profiling_runner_test.cpp | 29 +++++ .../plugins/ets/runtime/ets_coroutine.h | 3 + .../ets/runtime/interop_js/js_convert_base.h | 3 + .../runtime/intrinsics/std_core_Double.cpp | 5 + .../ets/runtime/intrinsics/std_core_Float.cpp | 5 + ...lass_find_indexable_getter_setter_test.cpp | 22 ++++ ...ss_get_static_field_by_name_float_test.cpp | 15 +++ .../ani/tests/find_ops/find_class_test.cpp | 8 ++ .../ani/tests/find_ops/find_module_test.cpp | 8 ++ .../tests/type_ops/get_super_class_test.cpp | 11 ++ .../type_ops/is_assignable_from_test.cpp | 16 +++ .../01.numeric_types/nt_int_operator_09.ets | 19 +++- .../grow_array_form_one_0.ets | 18 +++- .../03.keyof_types/keyof_example.ets | 20 +++- .../generic_rest_tuple_negative.ets | 10 ++ .../PartialWithGeneric.ets | 18 +++- ...lti_level_inheritance_value_transfer17.ets | 25 +++++ .../abstract_method_inheritance_2.ets | 9 ++ ...thod_declaration_with_keywords.params.yaml | 6 +- .../constructor_declaration_protected2.ets | 18 +++- .../ets_func_tests/escompat/JsonTest.ets | 32 +++--- .../tests/ets_func_tests/regression/20944.ets | 28 ++++- .../ets_func_tests/std/core/DoubleInvoke.ets | 5 + .../core/dateformat/DateTimeFormatTest.ets | 8 ++ .../ets/tests/ets_sdk/fuzztest/fuzzer.gni | 2 +- .../tests/declgen_ets2ts/CMakeLists.txt | 2 +- .../tests/declgen_ets2ts/jsdoc/CMakeLists.txt | 7 ++ .../tests/declgen_ets2ts/jsdoc/jsdoc.ts | 21 ++-- .../tests/declgen_ets2ts/jsdoc/main.ts | 6 ++ .../tests/hybridgref/CMakeLists.txt | 2 +- .../interop_js/tests/interop_isa/test.ets | 5 + .../arg_generic/arg_generic.ets | 9 +- .../arg_generic_negative_result.ets | 6 +- .../arg_interface/arg_interface.ets | 9 +- .../arg_interface_negative_result.ets | 7 +- .../arg_literal/arg_literal.ets | 8 +- .../arg_literal_negative_result.ets | 7 +- .../arg_union/arg_union.ets | 11 +- .../arg_union_negative_result.ets | 6 +- .../tests/perf/benchmarks/caller.ets | 50 ++++----- .../unit-tests/unit-tests-excluded.txt | 1 + .../arkts-classes-abstract-classes.d.ts | 11 ++ .../arkts-classes-async-static-methods.d.ts | 6 ++ .../runtime/global_handle_storage-inl.h | 41 ++++--- static_core/runtime/global_handle_storage.h | 4 + static_core/runtime/handle_storage-inl.h | 102 ++++++++++++------ static_core/runtime/handle_storage.h | 15 +++ .../runtime/include/object_accessor-inl.h | 30 ++++-- static_core/runtime/include/object_accessor.h | 3 + static_core/static_linker/BUILD.gn | 1 + .../runner/test/config_test/data/__init__.py | 8 ++ .../launches_test/data/dependent_test2.ets | 5 + .../src/vmb/plugins/tools/hvigor.py | 11 +- .../src/vmb/resources/hap/EtsRuntime.ts | 44 ++++---- static_core/tools/ark_js_napi_cli/BUILD.gn | 2 + .../ark_js_napi_cli/ark_hz/ark_js_runtime.cpp | 8 ++ 78 files changed, 858 insertions(+), 236 deletions(-) diff --git a/codecheck_ignore.json b/codecheck_ignore.json index ae93045467..402c9991cc 100755 --- a/codecheck_ignore.json +++ b/codecheck_ignore.json @@ -25,5 +25,6 @@ "templates": "*", "tests": "*", "verifier": "*", - "taihe": "*" + "taihe": "*", + "common_interfaces/objects/string/base_string_impl.h": "*" } diff --git a/common_interfaces/base/common.h b/common_interfaces/base/common.h index a4962d670f..ba462ef893 100755 --- a/common_interfaces/base/common.h +++ b/common_interfaces/base/common.h @@ -152,7 +152,7 @@ enum class LOG_LEVEL : uint8_t { }; static constexpr size_t BITS_PER_BYTE = 8; -} // namespace common +} // namespace common #endif // COMMON_INTERFACES_BASE_COMMON_H // NOLINTEND(readability-identifier-naming, cppcoreguidelines-macro-usage, diff --git a/common_interfaces/base_runtime.h b/common_interfaces/base_runtime.h index 586b98ab64..5fc9564949 100644 --- a/common_interfaces/base_runtime.h +++ b/common_interfaces/base_runtime.h @@ -30,24 +30,91 @@ #include #include "base/runtime_param.h" + namespace common { class BaseStringTableImpl; template class BaseStringTableInterface; class BaseObject; class HeapManager; +class Mutator; class MutatorManager; class ThreadHolderManager; class ThreadHolder; class BaseClassRoots; -enum class GcType : uint8_t { - ASYNC, - SYNC, - FULL, // Waiting finish - APPSPAWN, - FULL_WITH_XREF, // Waiting finish +// Used by Collector::RequestGC. +// It tells why GC is triggered. +// +// sync: Caller of Collector::RequestGC will wait until GC completes. +// async: Collector::RequestGC returns immediately and caller continues to run. +enum GCReason : uint32_t { + GC_REASON_BEGIN = 0, + GC_REASON_USER = GC_REASON_BEGIN, // Triggered by user explicitly. + GC_REASON_OOM, // Out of memory. Failed to allocate object. + GC_REASON_BACKUP, // backup gc is triggered if no other reason triggers gc for a long time. + GC_REASON_HEU, // Statistics show it is worth doing GC. Does not have to be immediate. + GC_REASON_YOUNG, // Statistics show it is worth doing Young GC. Does not have to be immediate. + GC_REASON_NATIVE, // Native-Allocation-Registry shows it's worth doing GC. + GC_REASON_HEU_SYNC, // Just wait one gc request to reduce heap fragmentation. + GC_REASON_NATIVE_SYNC, // Just wait one gc request to reduce native heap consumption. + GC_REASON_FORCE, // force gc is triggered when runtime triggers gc actively. + GC_REASON_APPSPAWN, // appspawn gc is triggered when prefork. + GC_REASON_BACKGROUND, // trigger gc caused by switching to background. + GC_REASON_HINT, // trigger gc caused by hint gc. + GC_REASON_IDLE, // When in a low activity state, trigger gc to reduce resicdent memory. + GC_REASON_XREF, // Waiting finish + GC_REASON_END = GC_REASON_IDLE, + GC_REASON_INVALID = std::numeric_limits::max(), +}; + +inline const char* GCREASON_STRING[] = { + "user", + "oom", + "backup", + "heuristic", + "young", + "native_alloc", + "heuristic_sync", + "native_alloc_sync", + "force", + "appspawn", + "backgound", + "hint", + "idle", + "xref", +}; + +inline const char* GCReasonToString(GCReason reason) +{ + if (reason >= GC_REASON_BEGIN && reason <= GC_REASON_END) { + return GCREASON_STRING[reason]; + } + return "UNKNOW_GC_REASON"; +} + +enum GCType : uint32_t { + GC_TYPE_BEGIN = 0, + GC_TYPE_FULL = GC_TYPE_BEGIN, + GC_TYPE_YOUNG, + GC_TYPE_STW, + GC_TYPE_END = GC_TYPE_STW, }; + +inline const char* GCTYPE_STRING[] = { + "FULL", + "YOUNG", + "STW", +}; + +inline const char* GCTypeToString(GCType gcType) +{ + if (gcType >= GC_TYPE_BEGIN && gcType <= GC_TYPE_END) { + return GCTYPE_STRING[gcType]; + } + return "UNKNOW_GC_TYPE"; +} + enum class MemoryReduceDegree : uint8_t { LOW = 0, HIGH, @@ -64,7 +131,7 @@ public: static void DestroyInstance(); void PreFork(ThreadHolder *holder); - void PostFork(); + void PostFork(bool enableWarmStartup); bool HasBeenInitialized(); void Init(const RuntimeParam ¶m); // Support setting custom parameters @@ -74,12 +141,15 @@ public: void FiniFromDynamic(); // Need refactor, move to other file - static void WriteBarrier(void* obj, void* field, void* ref); + static void WriteRoot(void* obj); + static void WriteBarrier(void* obj, void* field, void* ref, Mutator *mutator = nullptr); static void* ReadBarrier(void* obj, void* field); static void* ReadBarrier(void* field); static void* AtomicReadBarrier(void* obj, void* field, std::memory_order order); - static void RequestGC(GcType type); + static void RequestGC(GCReason reason, bool async, GCType gcType); static void WaitForGCFinish(); + static void EnterGCCriticalSection(); + static void ExitGCCriticalSection(); static bool ForEachObj(HeapVisitor& visitor, bool safe); static void NotifyNativeAllocation(size_t bytes); static void NotifyNativeFree(size_t bytes); @@ -87,6 +157,8 @@ public: static size_t GetNotifiedNativeSize(); static void ChangeGCParams(bool isBackground); static bool CheckAndTriggerHintGC(MemoryReduceDegree degree); + static void NotifyHighSensitive(bool isStart); + static void NotifyWarmStart(); HeapParam &GetHeapParam() { diff --git a/common_interfaces/heap/heap_allocator.h b/common_interfaces/heap/heap_allocator.h index 3ecf776b38..46cc66c68e 100644 --- a/common_interfaces/heap/heap_allocator.h +++ b/common_interfaces/heap/heap_allocator.h @@ -27,18 +27,19 @@ using Address = uint64_t; class PUBLIC_API HeapAllocator { public: - static Address Allocate(size_t size, LanguageType language); - static Address AllocateInNonmove(size_t size, LanguageType language); + static Address AllocateInYoungOrHuge(size_t size, LanguageType language); + static Address AllocateInNonmoveOrHuge(size_t size, LanguageType language); static Address32 Allocate32(size_t size, LanguageType language); - static Address AllocateInOld(size_t size, LanguageType language); + static Address AllocateInOldOrHuge(size_t size, LanguageType language); static Address AllocateInHuge(size_t size, LanguageType language); static Address AllocateInReadOnly(size_t size, LanguageType language); static uintptr_t AllocateLargeJitFortRegion(size_t size, LanguageType language); // below are interfaces used for serialize static Address AllocateNoGC(size_t size); - static Address AllocatePinNoGC(size_t size); - static Address AllocateRegion(); - static Address AllocatePinnedRegion(); + static Address AllocateOldOrLargeNoGC(size_t size); + static Address AllocateNonmoveNoGC(size_t size); + static Address AllocateOldRegion(); + static Address AllocateNonMovableRegion(); static Address AllocateLargeRegion(size_t size); }; } // namespace common diff --git a/common_interfaces/heap/heap_visitor.h b/common_interfaces/heap/heap_visitor.h index 44182acaec..8dba89d4d2 100644 --- a/common_interfaces/heap/heap_visitor.h +++ b/common_interfaces/heap/heap_visitor.h @@ -32,13 +32,18 @@ using WeakRefFieldVisitor = std::function &)>; void VisitRoots(const RefFieldVisitor &visitor); void VisitWeakRoots(const WeakRefFieldVisitor &visitorFunc); void UpdateRoots(const RefFieldVisitor &visitor); +void VisitSTWRoots(const RefFieldVisitor &visitor); +void VisitConcurrentRoots(const RefFieldVisitor &visitor); // GlobalRoots are subsets of roots which are shared in all mutator threads. void VisitGlobalRoots(const RefFieldVisitor &visitor); void UpdateGlobalRoots(const RefFieldVisitor &visitor); void VisitWeakGlobalRoots(const WeakRefFieldVisitor &visitorFunc); +void VisitPreforwardRoots(const RefFieldVisitor &visitor); + void VisitMutatorRoot(const RefFieldVisitor &visitor, Mutator &mutator); void VisitWeakMutatorRoot(const WeakRefFieldVisitor &visitor, Mutator &mutator); +void VisitMutatorPreforwardRoot(const RefFieldVisitor &visitor, Mutator &mutator); // Static VM Roots scanning void VisitStaticRoots(const RefFieldVisitor &visitor); void UnmarkAllXRefs(); diff --git a/common_interfaces/objects/base_object.h b/common_interfaces/objects/base_object.h index 40fdfcf2a5..e636cd484f 100644 --- a/common_interfaces/objects/base_object.h +++ b/common_interfaces/objects/base_object.h @@ -33,6 +33,7 @@ #include "objects/base_class.h" #include "objects/base_object_operator.h" #include "objects/base_state_word.h" + namespace common { class PUBLIC_API BaseObject { public: diff --git a/common_interfaces/objects/base_object_accessor.h b/common_interfaces/objects/base_object_accessor.h index e8f948286f..4f0ad4a643 100644 --- a/common_interfaces/objects/base_object_accessor.h +++ b/common_interfaces/objects/base_object_accessor.h @@ -42,5 +42,28 @@ public: // SetElementByIdx is used to set the value of an element in a dynamic object with the given index. virtual bool SetElementByIdx(ThreadHolder *thread, BaseObject *obj, const uint32_t index, JSTaggedValue value) = 0; }; -} // namespace panda -#endif // COMMON_INTERFACES_BASE_OBJECT_ACCESSOR_H \ No newline at end of file + +// The interface will be implemented in the static runtime to provide the ability to access +// properties of static objects. +class StaticObjectAccessorInterface { +public: + // HasProperty is used to check if the static object has a property with the given name. + virtual bool HasProperty(ThreadHolder *thread, const BaseObject *obj, const char *name) = 0; + + // GetProperty is used to get the value of a property from a static object with the given name. + virtual BoxedValue GetProperty(ThreadHolder *thread, const BaseObject *obj, const char *name) = 0; + + // SetProperty is used to set the value of a property in a static object with the given name. + virtual bool SetProperty(ThreadHolder *thread, BaseObject *obj, const char *name, BoxedValue value) = 0; + + // HasElementByIdx is used to check if the static object has an element with the given index. + virtual bool HasElementByIdx(ThreadHolder *thread, const BaseObject *obj, const uint32_t index) = 0; + + // GetElementByIdx is used to get the value of an element from a static object with the given index. + virtual BoxedValue GetElementByIdx(ThreadHolder *thread, const BaseObject *obj, const uint32_t index) = 0; + + // SetElementByIdx is used to set the value of an element in a static object with the given index. + virtual bool SetElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index, const BoxedValue value) = 0; +}; +} // namespace common +#endif // COMMON_INTERFACES_BASE_OBJECT_ACCESSOR_H diff --git a/common_interfaces/objects/base_object_dispatcher.h b/common_interfaces/objects/base_object_dispatcher.h index 5fe79f8b99..fbc640c793 100644 --- a/common_interfaces/objects/base_object_dispatcher.h +++ b/common_interfaces/objects/base_object_dispatcher.h @@ -76,7 +76,7 @@ public: } else if constexpr (objType == ObjectType::STATIC) { BoxedValue value = stcObjAccessor_->GetProperty(thread, obj, name); // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value)); + return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value)); } else { if (obj->IsDynamic()) { // fix(hewei): exceptions may occur, check here and return default value. @@ -84,7 +84,7 @@ public: } else { // NOLINT(readability-else-after-return) BoxedValue value = stcObjAccessor_->GetProperty(thread, obj, name); // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value)); + return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value)); } } } @@ -122,7 +122,7 @@ public: } else if constexpr (objType == ObjectType::STATIC) { BoxedValue value = stcObjAccessor_->GetElementByIdx(thread, obj, index); // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value)); + return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value)); } else { if (obj->IsDynamic()) { // fix(hewei): exceptions may occur, check here and return default value. @@ -130,7 +130,7 @@ public: } else { // NOLINT(readability-else-after-return) BoxedValue value = stcObjAccessor_->GetElementByIdx(thread, obj, index); // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value)); + return dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value)); } } } @@ -187,7 +187,7 @@ public: { if constexpr (objType == ObjectType::DYNAMIC) { // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - auto wrapedValue = dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value)); + auto wrapedValue = dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value)); return dynObjAccessor_->SetProperty(thread, obj, name, wrapedValue); } else if constexpr (objType == ObjectType::STATIC) { // fix(hewei): exceptions may occur, check here and return default value. @@ -195,7 +195,7 @@ public: } else { if (obj->IsDynamic()) { // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - auto wrapedValue = dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value)); + auto wrapedValue = dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value)); return dynObjAccessor_->SetProperty(thread, obj, name, wrapedValue); } else { // NOLINT(readability-else-after-return) // fix(hewei): exceptions may occur, check here and return default value. @@ -213,8 +213,8 @@ public: return dynObjAccessor_->SetElementByIdx(thread, obj, index, value); } else if constexpr (objType == ObjectType::STATIC) { // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return stcObjAccessor_->SetElementByIdx( - thread, obj, index, stcTypeConverter_->WrapBoxed(dynTypeConverter_->UnWrapTagged(value))); + return stcObjAccessor_->SetElementByIdx(thread, obj, index, + stcTypeConverter_->WrapBoxed(dynTypeConverter_->UnWrapTagged(value))); } else { if (obj->IsDynamic()) { // fix(hewei): exceptions may occur, check here and return default value. @@ -233,17 +233,17 @@ public: { if constexpr (objType == ObjectType::DYNAMIC) { // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return dynObjAccessor_->SetElementByIdx( - thread, obj, index, dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value))); + return dynObjAccessor_->SetElementByIdx(thread, obj, index, + dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value))); } else if constexpr (objType == ObjectType::STATIC) { // fix(hewei): exceptions may occur, check here and return default value. return stcObjAccessor_->SetElementByIdx(thread, obj, index, value); } else { if (obj->IsDynamic()) { // fix(hewei): exceptions may occur, check here and return. Also, check exceptions in Wrap functions. - return dynObjAccessor_->SetElementByIdx( - thread, obj, index, dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnwrapBoxed(value))); - } else { // NOLINT(readability-else-after-return) + return dynObjAccessor_->SetElementByIdx(thread, obj, index, + dynTypeConverter_->WrapTagged(thread, stcTypeConverter_->UnWrapBoxed(value))); + } else { // fix(hewei): exceptions may occur, check here and return default value. return stcObjAccessor_->SetElementByIdx(thread, obj, index, value); } @@ -301,4 +301,4 @@ private: StaticObjectDescriptorInterface *stcObjDescriptor_; }; } // namespace common -#endif // COMMON_INTERFACES_OBJECTS_BASE_OBJECT_DISPATCHER_H \ No newline at end of file +#endif // COMMON_INTERFACES_OBJECTS_BASE_OBJECT_DISPATCHER_H diff --git a/common_interfaces/objects/base_object_operator.h b/common_interfaces/objects/base_object_operator.h index c0c51c8a1f..1d5c0998e7 100644 --- a/common_interfaces/objects/base_object_operator.h +++ b/common_interfaces/objects/base_object_operator.h @@ -32,6 +32,7 @@ #include "objects/field.h" #include "objects/ref_field.h" #include "objects/base_state_word.h" + namespace common { class BaseObject; diff --git a/common_interfaces/objects/base_state_word.h b/common_interfaces/objects/base_state_word.h index d339383852..aedeb5c43c 100644 --- a/common_interfaces/objects/base_state_word.h +++ b/common_interfaces/objects/base_state_word.h @@ -27,6 +27,7 @@ #include #include + namespace common { using StateWordType = uint64_t; using MAddress = uint64_t; diff --git a/common_interfaces/objects/base_type.h b/common_interfaces/objects/base_type.h index 9f704bfef7..aef98e1119 100644 --- a/common_interfaces/objects/base_type.h +++ b/common_interfaces/objects/base_type.h @@ -31,7 +31,8 @@ #include #include "objects/base_object.h" -#include "objects/string/base_string.h" +#include "objects/string/base_string_declare.h" + namespace panda::ecmascript { class JSTaggedValue; } diff --git a/common_interfaces/objects/base_type_converter.h b/common_interfaces/objects/base_type_converter.h index cbf11c48f4..9d13eb6b02 100644 --- a/common_interfaces/objects/base_type_converter.h +++ b/common_interfaces/objects/base_type_converter.h @@ -29,5 +29,15 @@ public: // convert JSTaggedValue to BaseType virtual BaseType UnWrapTagged(JSTaggedValue value) = 0; }; + +// Type Converter implemented for static vm. +class StaticTypeConverterInterface { +public: + // convert BaseType to BoxedValue + virtual BoxedValue WrapBoxed(BaseType value) = 0; + + // convert BoxedValue to BaseType + virtual BaseType UnWrapBoxed(BoxedValue value) = 0; +}; } // namespace common -#endif // COMMON_INTERFACES_OBJECTS_BASE_TYPE_CONVERTER_H \ No newline at end of file +#endif // COMMON_INTERFACES_OBJECTS_BASE_TYPE_CONVERTER_H diff --git a/common_interfaces/objects/field.h b/common_interfaces/objects/field.h index 5f20989ad0..f22af63cdd 100644 --- a/common_interfaces/objects/field.h +++ b/common_interfaces/objects/field.h @@ -26,6 +26,7 @@ #define COMMON_INTERFACES_OBJECTS_FIELD_H #include + namespace common { class BaseObject; diff --git a/common_interfaces/objects/ref_field.h b/common_interfaces/objects/ref_field.h index 9870b7fb0a..0f4cb18e09 100644 --- a/common_interfaces/objects/ref_field.h +++ b/common_interfaces/objects/ref_field.h @@ -28,6 +28,7 @@ #include #include #include "objects/base_state_word.h" + namespace common { class BaseObject; diff --git a/common_interfaces/objects/string/line_string-inl.h b/common_interfaces/objects/string/line_string-inl.h index 181f1a3170..f10395ea06 100644 --- a/common_interfaces/objects/string/line_string-inl.h +++ b/common_interfaces/objects/string/line_string-inl.h @@ -178,6 +178,28 @@ void LineString::WriteData(ReadBarrier &&readBarrier, BaseString *src, uint32_t } } +inline void LineString::Trim(uint32_t newLength) +{ + ASSERT(IsLineString()); + uint32_t oldLength = GetLength(); + ASSERT(oldLength >= newLength); + if (newLength == oldLength) return; + bool isUtf8 = IsUtf8(); + size_t sizeNew = isUtf8 ? + LineString::ComputeSizeUtf8(newLength): LineString::ComputeSizeUtf16(newLength); + size_t sizeOld = isUtf8 ? + LineString::ComputeSizeUtf8(oldLength): LineString::ComputeSizeUtf16(oldLength); + sizeNew = common::AlignUp(sizeNew, ALIGNMENT_8_BYTES); + sizeOld = common::AlignUp(sizeOld, ALIGNMENT_8_BYTES); + size_t trimBytes = sizeOld - sizeNew; + if (trimBytes > 0) { + uintptr_t newEndAddr = ToUintPtr(this) + sizeNew; + ASSERT_PRINT((newEndAddr % ALIGNMENT_8_BYTES) == 0, "Alignment failed"); + FillFreeObject(reinterpret_cast(newEndAddr), trimBytes); + } + InitLengthAndFlags(newLength, isUtf8); +} + inline bool LineString::CanBeCompressed(const LineString *string) { if (string->IsUtf8()) { diff --git a/common_interfaces/objects/string/line_string.h b/common_interfaces/objects/string/line_string.h index f959dff76e..30bbcab92a 100644 --- a/common_interfaces/objects/string/line_string.h +++ b/common_interfaces/objects/string/line_string.h @@ -50,7 +50,9 @@ public: NO_MOVE_SEMANTIC_CC(LineString); NO_COPY_SEMANTIC_CC(LineString); - static constexpr uint32_t MAX_LENGTH = 0x0FFFFFF0U; // Maximum of the string, (1 << 28) -16 + static constexpr size_t ALIGNMENT_8_BYTES = 8; + static constexpr uint32_t MAX_LENGTH = (1 << 28) - 16; + static constexpr uint32_t INIT_LENGTH_TIMES = 4; // DATA_OFFSET: the string data stored after the string header. // Data can be stored in utf8 or utf16 form according to compressed bit. static constexpr size_t DATA_OFFSET = BaseString::SIZE; // DATA_OFFSET equal to Empty String size @@ -152,6 +154,8 @@ public: */ void Set(uint32_t index, uint16_t src); + void Trim(uint32_t newLength); + /** * @brief Compute memory size for a UTF-8 encoded string. * @param utf8Len Length in bytes. diff --git a/common_interfaces/profiler/heap_profiler_listener.h b/common_interfaces/profiler/heap_profiler_listener.h index 823bdfe04a..806a422c0d 100644 --- a/common_interfaces/profiler/heap_profiler_listener.h +++ b/common_interfaces/profiler/heap_profiler_listener.h @@ -19,18 +19,26 @@ #include #include #include +#include +#include +#include namespace common { class HeapProfilerListener { public: static HeapProfilerListener &GetInstance(); - void RegisterMoveEventCb(const std::function &cb); - void UnRegisterMoveEventCb(); + uint32_t RegisterMoveEventCb(const std::function &cb); + void UnRegisterMoveEventCb(uint32_t index); void OnMoveEvent(uintptr_t fromObj, uintptr_t toObj, size_t size); + void RegisterOutOfMemoryEventCb(const std::function &cb); + void OnOutOfMemoryEventCb(); private: - std::function moveEventCb_; + std::map> moveEventCbs_; + uint32_t moveEventCbId_ {1}; + std::shared_mutex mutex_; + std::function outOfMemoryEventCb_ = [](void *thread) {}; }; } // namespace common #endif // COMMON_INTERFACES_HEAP_PROFILER_LISTENER_H \ No newline at end of file diff --git a/common_interfaces/thread/mutator_base.h b/common_interfaces/thread/mutator_base.h index 3d9fda06da..acb4160e0f 100644 --- a/common_interfaces/thread/mutator_base.h +++ b/common_interfaces/thread/mutator_base.h @@ -54,13 +54,31 @@ class PUBLIC_API MutatorBase { public: // flag which indicates the reason why mutator should suspend. flag is set by some external thread. enum SuspensionType : uint32_t { - SUSPENSION_FOR_GC_PHASE = 1, - SUSPENSION_FOR_STW = 2, - SUSPENSION_FOR_EXIT = 4, - SUSPENSION_FOR_CPU_PROFILE = 8, - SUSPENSION_FOR_PENDING_CALLBACK = 16, - SUSPENSION_FOR_RUNNING_CALLBACK = 32, - SUSPENSION_FOR_FINALIZE = 64, + SUSPENSION_FOR_GC_PHASE = 1 << 0, + SUSPENSION_FOR_STW = 1 << 1, + SUSPENSION_FOR_EXIT = 1 << 2, + SUSPENSION_FOR_CPU_PROFILE = 1 << 3, + SUSPENSION_FOR_PENDING_CALLBACK = 1 << 4, + SUSPENSION_FOR_RUNNING_CALLBACK = 1 << 5, + /** + * The below ones are not actually suspension request, it's just some callbacks need to process + * at the beginning of transfering to RUNNING + * So This is equivalent to: + * ```` __attribute__((always_inline)) inline void DoLeaveSaferegion() + * ```` { + * ```` SetInSaferegion(SAFE_REGION_FALSE); + * ```` if (UNLIKELY_CC(HasAnySuspensionRequest())) { + * ```` HandleSuspensionRequest(); + * ```` } + * ------> if (UNLIKELY_CC(HasOtherCallback())) { + * ------> ProcessCallback(); + * ------> } + * ```` } + * But this will make `DoLeaveSaferegion` cost more, so we just merge it into suspension request, + * and do some extra process at the end of `HandleSuspensionRequest` + */ + SUSPENSION_FOR_FINALIZE = 1 << 31, + CALLBACKS_TO_PROCESS = SUSPENSION_FOR_FINALIZE, }; enum GCPhaseTransitionState : uint32_t { @@ -208,6 +226,13 @@ public: return (suspensionFlag_.load(std::memory_order_acquire) != 0); } + // Check whether current mutator needs to be suspended for GC or other request, see comments in `SuspensionType` + __attribute__((always_inline)) inline bool HasAnySuspensionRequestExceptCallbacks() const + { + uint32_t flag = suspensionFlag_.load(std::memory_order_acquire); + return (flag & ~CALLBACKS_TO_PROCESS) != 0; + } + __attribute__((always_inline)) inline bool CASSetSuspensionFlag(uint32_t oldFlag, uint32_t newFlag) { return suspensionFlag_.compare_exchange_strong(oldFlag, newFlag); diff --git a/common_interfaces/thread/thread_holder.h b/common_interfaces/thread/thread_holder.h index fa919f78e5..51d9159bdd 100644 --- a/common_interfaces/thread/thread_holder.h +++ b/common_interfaces/thread/thread_holder.h @@ -81,6 +81,11 @@ public: SetCurrent(this); } + ~ThreadHolder() + { + SetCurrent(nullptr); + } + static ThreadHolder *GetCurrent(); static void SetCurrent(ThreadHolder *holder); @@ -144,6 +149,8 @@ public: return allocBuffer_; } + void ReleaseAllocBuffer(); + JSThread* GetJSThread() const { return jsThread_; @@ -177,11 +184,6 @@ public: } private: - ~ThreadHolder() - { - SetCurrent(nullptr); - } - // Return false if thread has already binded mutator. Otherwise bind a mutator. bool TryBindMutator(); diff --git a/static_core/assembler/BUILD.gn b/static_core/assembler/BUILD.gn index b7681ebc24..dfbc1d0403 100644 --- a/static_core/assembler/BUILD.gn +++ b/static_core/assembler/BUILD.gn @@ -22,11 +22,7 @@ if (ark_standalone_build) { ohos_static_library("libarktsassembler_package") { deps = [] if (enable_static_vm) { - if (is_mac) { - deps += [ ":libarktsassembler_frontend_static" ] - } else { - deps += [ ":libarktsassembler" ] - } + deps += [ ":libarktsassembler_frontend_static" ] } part_name = ark_part_name diff --git a/static_core/assembler/assembly-emitter.cpp b/static_core/assembler/assembly-emitter.cpp index 25f31136ee..252c0eea1f 100644 --- a/static_core/assembler/assembly-emitter.cpp +++ b/static_core/assembler/assembly-emitter.cpp @@ -1587,6 +1587,9 @@ bool AsmEmitter::MakeFunctionDebugInfoAndAnnotations(ItemContainer *items, const } auto *method = FindMethod(func, name, entities); + if (method == nullptr) { + return false; + } if (func.metadata->HasImplementation()) { SetCodeAndDebugInfo(items, method, func, emitDebugInfo); @@ -1836,6 +1839,7 @@ std::unique_ptr AsmEmitter::Emit(Program &program, Panda auto writer = MemoryBufferWriter(reinterpret_cast(buffer), size); if (!items.Write(&writer)) { + delete[] buffer; return nullptr; } diff --git a/static_core/cmake/ClangTidy.cmake b/static_core/cmake/ClangTidy.cmake index 0c1e042fd0..98596c2098 100644 --- a/static_core/cmake/ClangTidy.cmake +++ b/static_core/cmake/ClangTidy.cmake @@ -36,6 +36,18 @@ add_custom_target(clang-tidy-ets2panda-check DEPENDS panda_gen_files ) +add_custom_target(clang-tidy-static-core-check + COMMAND ${PANDA_ROOT}/scripts/clang-tidy/clang_tidy_check.py --filename-filter /runtime_core/static_core/ ${PANDA_ROOT} ${PANDA_BINARY_ROOT} + USES_TERMINAL + DEPENDS panda_gen_files +) + +add_custom_target(clang-tidy-ets2panda-check + COMMAND ${PANDA_ROOT}/scripts/clang-tidy/clang_tidy_check.py --filename-filter /ets2panda/ ${PANDA_ROOT} ${PANDA_BINARY_ROOT} + USES_TERMINAL + DEPENDS panda_gen_files +) + add_custom_target(clang-tidy-check COMMAND ${PANDA_ROOT}/scripts/clang-tidy/clang_tidy_check.py ${PANDA_ROOT} ${PANDA_BINARY_ROOT} USES_TERMINAL diff --git a/static_core/compiler/tests/profiling_runner_test.cpp b/static_core/compiler/tests/profiling_runner_test.cpp index 083faf1974..2593db5c22 100644 --- a/static_core/compiler/tests/profiling_runner_test.cpp +++ b/static_core/compiler/tests/profiling_runner_test.cpp @@ -101,6 +101,21 @@ TEST_F(ProfilingRunnerTest, ProfilingDataNullptTestCpp) Runtime::Destroy(); } +TEST_F(ProfilingRunnerTest, ProfilingDataNullptTestCpp) +{ + PandaRunner runner; + runner.GetRuntimeOptions().SetInterpreterType("cpp"); + auto runtime = runner.CreateRuntime(); + runner.Run(runtime, SOURCE, std::vector {}); + auto method = runner.GetMethod("foo"); + auto profilingData = method->GetProfilingData(); + ASSERT_EQ(nullptr, profilingData); + ProfilingSaver saver; + pgo::AotProfilingData profData; + saver.AddMethod(&profData, method, 0); + Runtime::Destroy(); +} + #ifndef PANDA_COMPILER_TARGET_AARCH32 TEST_F(ProfilingRunnerTest, BranchStatistics) { @@ -117,6 +132,20 @@ TEST_F(ProfilingRunnerTest, BranchStatistics) Runtime::Destroy(); } +TEST_F(ProfilingRunnerTest, ProfilingDataNullptTest) +{ + PandaRunner runner; + auto runtime = runner.CreateRuntime(); + runner.Run(runtime, SOURCE, std::vector {}); + auto method = runner.GetMethod("foo"); + auto profilingData = method->GetProfilingData(); + ASSERT_EQ(nullptr, profilingData); + ProfilingSaver saver; + pgo::AotProfilingData profData; + saver.AddMethod(&profData, method, 0); + Runtime::Destroy(); +} + TEST_F(ProfilingRunnerTest, ProfilingDataNullptTest) { PandaRunner runner; diff --git a/static_core/plugins/ets/runtime/ets_coroutine.h b/static_core/plugins/ets/runtime/ets_coroutine.h index 8ad028b3f9..b398ac8f0a 100644 --- a/static_core/plugins/ets/runtime/ets_coroutine.h +++ b/static_core/plugins/ets/runtime/ets_coroutine.h @@ -147,6 +147,9 @@ public: /// @brief print stack and exit the program [[noreturn]] void HandleUncaughtException() override; + /// @brief print stack and exit the program + [[noreturn]] void HandleUncaughtException() override; + static constexpr CoroutinePriority ASYNC_CALL = CoroutinePriority::HIGH_PRIORITY; static constexpr CoroutinePriority PROMISE_CALLBACK = CoroutinePriority::HIGH_PRIORITY; static constexpr CoroutinePriority TIMER_CALLBACK = CoroutinePriority::MEDIUM_PRIORITY; diff --git a/static_core/plugins/ets/runtime/interop_js/js_convert_base.h b/static_core/plugins/ets/runtime/interop_js/js_convert_base.h index 434f4eeb01..b14dda8f5b 100644 --- a/static_core/plugins/ets/runtime/interop_js/js_convert_base.h +++ b/static_core/plugins/ets/runtime/interop_js/js_convert_base.h @@ -130,6 +130,9 @@ struct JSConvertBase { if constexpr (IS_REFTYPE) { // NOTE(kprokopenko) can't assign null to EtsString *, hence fallback into UnwrapImpl if (UNLIKELY(IsUndefined(env, jsVal))) { + if constexpr (IS_JSVALUE) { + return JSValue::CreateUndefined(EtsCoroutine::GetCurrent(), ctx); + } return nullptr; } } diff --git a/static_core/plugins/ets/runtime/intrinsics/std_core_Double.cpp b/static_core/plugins/ets/runtime/intrinsics/std_core_Double.cpp index cb288b99ab..11d0b1bf10 100644 --- a/static_core/plugins/ets/runtime/intrinsics/std_core_Double.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/std_core_Double.cpp @@ -339,4 +339,9 @@ EtsFloat StdCoreDoubleToFloat(EtsDouble val) return static_cast(val); } +EtsChar StdCoreDoubleToChar(EtsDouble val) +{ + return CastFloatToInt(val); +} + } // namespace ark::ets::intrinsics diff --git a/static_core/plugins/ets/runtime/intrinsics/std_core_Float.cpp b/static_core/plugins/ets/runtime/intrinsics/std_core_Float.cpp index 73e9e55c15..0649d11a00 100644 --- a/static_core/plugins/ets/runtime/intrinsics/std_core_Float.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/std_core_Float.cpp @@ -100,4 +100,9 @@ EtsDouble StdCoreFloatToDouble(EtsFloat val) return static_cast(val); } +EtsChar StdCoreFloatToChar(EtsFloat val) +{ + return CastFloatToInt(val); +} + } // namespace ark::ets::intrinsics diff --git a/static_core/plugins/ets/tests/ani/tests/class_ops/class_find_indexable_getter_setter_test.cpp b/static_core/plugins/ets/tests/ani/tests/class_ops/class_find_indexable_getter_setter_test.cpp index 287e345a62..f3885374be 100644 --- a/static_core/plugins/ets/tests/ani/tests/class_ops/class_find_indexable_getter_setter_test.cpp +++ b/static_core/plugins/ets/tests/ani/tests/class_ops/class_find_indexable_getter_setter_test.cpp @@ -83,4 +83,26 @@ TEST_F(FindIndexableSetterTest, check_initialization) ASSERT_FALSE(IsRuntimeClassInitialized("class_find_indexable_getter_setter_test.A")); } +TEST_F(FindIndexableGetterTest, check_initialization) +{ + ani_class cls {}; + ASSERT_EQ(env_->FindClass("class_find_indexable_getter_setter_test.A", &cls), ANI_OK); + + ASSERT_FALSE(IsRuntimeClassInitialized("class_find_indexable_getter_setter_test.A")); + ani_method method {}; + ASSERT_EQ(env_->Class_FindIndexableGetter(cls, "D:Lclass_find_indexable_getter_setter_test/A;", &method), ANI_OK); + ASSERT_FALSE(IsRuntimeClassInitialized("class_find_indexable_getter_setter_test.A")); +} + +TEST_F(FindIndexableSetterTest, check_initialization) +{ + ani_class cls {}; + ASSERT_EQ(env_->FindClass("class_find_indexable_getter_setter_test.A", &cls), ANI_OK); + + ASSERT_FALSE(IsRuntimeClassInitialized("class_find_indexable_getter_setter_test.A")); + ani_method method {}; + ASSERT_EQ(env_->Class_FindIndexableSetter(cls, "DZ:V", &method), ANI_OK); + ASSERT_FALSE(IsRuntimeClassInitialized("class_find_indexable_getter_setter_test.A")); +} + } // namespace ark::ets::ani::testing diff --git a/static_core/plugins/ets/tests/ani/tests/class_ops/class_get_static_field_by_name_float_test.cpp b/static_core/plugins/ets/tests/ani/tests/class_ops/class_get_static_field_by_name_float_test.cpp index 67ad5235ee..3c1136bc36 100644 --- a/static_core/plugins/ets/tests/ani/tests/class_ops/class_get_static_field_by_name_float_test.cpp +++ b/static_core/plugins/ets/tests/ani/tests/class_ops/class_get_static_field_by_name_float_test.cpp @@ -162,6 +162,21 @@ TEST_F(ClassGetStaticFieldByNameFloatTest, check_initialization) ASSERT_TRUE(IsRuntimeClassInitialized("class_get_static_field_by_name_float_test.GetFloatStatic")); } +TEST_F(ClassGetStaticFieldByNameFloatTest, check_initialization) +{ + ani_class cls {}; + ASSERT_EQ(env_->FindClass("class_get_static_field_by_name_float_test.GetFloatStatic", &cls), ANI_OK); + + ASSERT_FALSE(IsRuntimeClassInitialized("class_get_static_field_by_name_float_test.GetFloatStatic")); + ani_float floatValue {}; + + ASSERT_EQ(env_->Class_GetStaticFieldByName_Float(cls, "agex", &floatValue), ANI_NOT_FOUND); + ASSERT_FALSE(IsRuntimeClassInitialized("class_get_static_field_by_name_float_test.GetFloatStatic")); + + ASSERT_EQ(env_->Class_GetStaticFieldByName_Float(cls, "age", &floatValue), ANI_OK); + ASSERT_TRUE(IsRuntimeClassInitialized("class_get_static_field_by_name_float_test.GetFloatStatic")); +} + } // namespace ark::ets::ani::testing // NOLINTEND(cppcoreguidelines-pro-type-vararg, modernize-avoid-c-arrays) diff --git a/static_core/plugins/ets/tests/ani/tests/find_ops/find_class_test.cpp b/static_core/plugins/ets/tests/ani/tests/find_ops/find_class_test.cpp index 10b1d50744..32f1a35351 100644 --- a/static_core/plugins/ets/tests/ani/tests/find_ops/find_class_test.cpp +++ b/static_core/plugins/ets/tests/ani/tests/find_ops/find_class_test.cpp @@ -61,4 +61,12 @@ TEST_F(FindClassTest, check_initialization) ASSERT_FALSE(IsRuntimeClassInitialized("find_class_test.Point")); } +TEST_F(FindClassTest, check_initialization) +{ + ASSERT_FALSE(IsRuntimeClassInitialized("find_class_test.Point")); + ani_class cls {}; + ASSERT_EQ(env_->FindClass("find_class_test.Point", &cls), ANI_OK); + ASSERT_FALSE(IsRuntimeClassInitialized("find_class_test.Point")); +} + } // namespace ark::ets::ani::testing diff --git a/static_core/plugins/ets/tests/ani/tests/find_ops/find_module_test.cpp b/static_core/plugins/ets/tests/ani/tests/find_ops/find_module_test.cpp index 386af623fc..361a9b99a3 100644 --- a/static_core/plugins/ets/tests/ani/tests/find_ops/find_module_test.cpp +++ b/static_core/plugins/ets/tests/ani/tests/find_ops/find_module_test.cpp @@ -58,6 +58,14 @@ TEST_F(FindModuleTest, check_initialization) ASSERT_FALSE(IsRuntimeClassInitialized("@abcModule.find_module_test", false)); } +TEST_F(FindModuleTest, check_initialization) +{ + ASSERT_FALSE(IsRuntimeClassInitialized("@abcModule.find_module_test", false)); + ani_module module {}; + ASSERT_EQ(env_->FindModule("@abcModule.find_module_test", &module), ANI_OK); + ASSERT_FALSE(IsRuntimeClassInitialized("@abcModule.find_module_test", false)); +} + } // namespace ark::ets::ani::testing // NOLINTEND(modernize-avoid-c-arrays) diff --git a/static_core/plugins/ets/tests/ani/tests/type_ops/get_super_class_test.cpp b/static_core/plugins/ets/tests/ani/tests/type_ops/get_super_class_test.cpp index 450bb15fb8..2f5b602f81 100644 --- a/static_core/plugins/ets/tests/ani/tests/type_ops/get_super_class_test.cpp +++ b/static_core/plugins/ets/tests/ani/tests/type_ops/get_super_class_test.cpp @@ -144,6 +144,17 @@ TEST_F(GetSuperClassTest, check_initialization) ASSERT_FALSE(IsRuntimeClassInitialized("get_super_class_test.A")); } +TEST_F(GetSuperClassTest, check_initialization) +{ + ani_class cls; + ASSERT_EQ(env_->FindClass("get_super_class_test.A", &cls), ANI_OK); + + ASSERT_FALSE(IsRuntimeClassInitialized("get_super_class_test.A")); + ani_type typeRef = cls; + ASSERT_EQ(env_->Type_GetSuperClass(typeRef, &cls), ANI_OK); + ASSERT_FALSE(IsRuntimeClassInitialized("get_super_class_test.A")); +} + } // namespace ark::ets::ani::testing // NOLINTEND(cppcoreguidelines-pro-type-vararg, modernize-avoid-c-arrays) diff --git a/static_core/plugins/ets/tests/ani/tests/type_ops/is_assignable_from_test.cpp b/static_core/plugins/ets/tests/ani/tests/type_ops/is_assignable_from_test.cpp index 360cf2d1b1..fba80c3fcc 100644 --- a/static_core/plugins/ets/tests/ani/tests/type_ops/is_assignable_from_test.cpp +++ b/static_core/plugins/ets/tests/ani/tests/type_ops/is_assignable_from_test.cpp @@ -131,6 +131,22 @@ TEST_F(IsAssignableFromTest, check_initialization) ASSERT_FALSE(IsRuntimeClassInitialized("is_assignable_from_test.InterfaceA")); } +TEST_F(IsAssignableFromTest, check_initialization) +{ + ani_class fromCls; + ASSERT_EQ(env_->FindClass("is_assignable_from_test.InterfaceA", &fromCls), ANI_OK); + + ani_class toCls; + ASSERT_EQ(env_->FindClass("is_assignable_from_test.InterfaceB", &toCls), ANI_OK); + + ASSERT_FALSE(IsRuntimeClassInitialized("is_assignable_from_test.InterfaceA")); + ASSERT_FALSE(IsRuntimeClassInitialized("is_assignable_from_test.InterfaceB")); + ani_boolean result; + ASSERT_EQ(env_->Type_IsAssignableFrom(fromCls, toCls, &result), ANI_OK); + ASSERT_FALSE(IsRuntimeClassInitialized("is_assignable_from_test.InterfaceB")); + ASSERT_FALSE(IsRuntimeClassInitialized("is_assignable_from_test.InterfaceA")); +} + } // namespace ark::ets::ani::testing // NOLINTEND(cppcoreguidelines-pro-type-vararg, modernize-avoid-c-arrays) diff --git a/static_core/plugins/ets/tests/ets-templates/03.types/06.value_types/01.numeric_types/nt_int_operator_09.ets b/static_core/plugins/ets/tests/ets-templates/03.types/06.value_types/01.numeric_types/nt_int_operator_09.ets index d0f40cab7f..2cc5cba433 100644 --- a/static_core/plugins/ets/tests/ets-templates/03.types/06.value_types/01.numeric_types/nt_int_operator_09.ets +++ b/static_core/plugins/ets/tests/ets-templates/03.types/06.value_types/01.numeric_types/nt_int_operator_09.ets @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,22 @@ * limitations under the License. */ -/*--- -desc: Test integer operations(/). ----*/ +export class ClassA { + foo() { + return 'this is 1.2 classA ets'; + } +} +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/03.types/06.value_types/01.numeric_types/nt_int_operator_09.ets function main(): void { let a: int = 6; let b: int = 2; arktest.assertTrue((a / b) === 3); -} \ No newline at end of file +} +======== +export let a = 'this is 1.2 classA ets'; +export function foo() { + return 'this is 1.2 foo ets'; +} +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/dynamicimport/ets_to_ts/export12.ets diff --git a/static_core/plugins/ets/tests/ets-templates/03.types/17.array_types/01.resizable_array_types/grow_array_form_one_0.ets b/static_core/plugins/ets/tests/ets-templates/03.types/17.array_types/01.resizable_array_types/grow_array_form_one_0.ets index 7f3d3ab7a2..0b13ba2762 100644 --- a/static_core/plugins/ets/tests/ets-templates/03.types/17.array_types/01.resizable_array_types/grow_array_form_one_0.ets +++ b/static_core/plugins/ets/tests/ets-templates/03.types/17.array_types/01.resizable_array_types/grow_array_form_one_0.ets @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/03.types/17.array_types/01.resizable_array_types/grow_array_form_one_0.ets /*--- desc: Resizable array types @@ -26,3 +27,18 @@ function main() { SyntaxFormOne.length = 5; // CTE: Attempting to increase the length of the array by assignment to length => CTE } +======== +#include +#include "ets_interop_js_gtest.h" + +namespace ark::ets::interop::js::testing { + +class ReturnArrayTsToEtsTest : public EtsInteropTest {}; + +TEST_F(ReturnArrayTsToEtsTest, check_functioin_return_array) +{ + ASSERT_TRUE(RunJsTestSuite("ts_return_array.ts")); +} + +} // namespace ark::ets::interop::js::testing +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/function_return_array_test/ts_to_ets/ts_return_array.cpp diff --git a/static_core/plugins/ets/tests/ets-templates/03.types/20.union_types/03.keyof_types/keyof_example.ets b/static_core/plugins/ets/tests/ets-templates/03.types/20.union_types/03.keyof_types/keyof_example.ets index 173b628db8..e3936c1c08 100644 --- a/static_core/plugins/ets/tests/ets-templates/03.types/20.union_types/03.keyof_types/keyof_example.ets +++ b/static_core/plugins/ets/tests/ets-templates/03.types/20.union_types/03.keyof_types/keyof_example.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/03.types/20.union_types/03.keyof_types/keyof_example.ets /*--- desc: The keyword keyof is applied to the class or interface type (see Classes and Interfaces). @@ -27,4 +28,21 @@ type t = keyof A function main() { let a: t = "field" a = "method" +======== +export interface StringIndexedObject { + [key: string]: number; + length: number; +} + +export interface NumberIndexedObject { + [index: number]: string; + [key: string]: string; +} + +export interface MixedIndexObject { + [key: string]: string | number; + [index: number]: string; + version: number; + name: string; +>>>>>>>> origin/master:static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/arkts-index-signature-interface.ts } diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/07.function_declarations/05.rest_parameter/generic_rest_tuple_negative.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/07.function_declarations/05.rest_parameter/generic_rest_tuple_negative.ets index dac1bc0121..85dcf6257a 100644 --- a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/07.function_declarations/05.rest_parameter/generic_rest_tuple_negative.ets +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/07.function_declarations/05.rest_parameter/generic_rest_tuple_negative.ets @@ -14,6 +14,7 @@ */ /*--- +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/07.function_declarations/05.rest_parameter/generic_rest_tuple_negative.ets desc: static Rest function spread with generic tuple tags: [compile-only, negative] ---*/ @@ -25,4 +26,13 @@ class TH { function main() { let mc = new TH +======== +desc: ES2PANDA_FAIL, TypeError, Structs are only used to define UI components, + it should be translated at 'plugin after parser' phase. +tags: [compile-only, negative] +---*/ + +export declare struct BB { + name: string +>>>>>>>> origin/master:static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/struct_declaration_n_1.ets } diff --git a/static_core/plugins/ets/tests/ets-templates/05.generics/03.utility_types/09.nesting_utility_type/PartialWithGeneric.ets b/static_core/plugins/ets/tests/ets-templates/05.generics/03.utility_types/09.nesting_utility_type/PartialWithGeneric.ets index f13da156bb..7421825320 100644 --- a/static_core/plugins/ets/tests/ets-templates/05.generics/03.utility_types/09.nesting_utility_type/PartialWithGeneric.ets +++ b/static_core/plugins/ets/tests/ets-templates/05.generics/03.utility_types/09.nesting_utility_type/PartialWithGeneric.ets @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/05.generics/03.utility_types/09.nesting_utility_type/PartialWithGeneric.ets /*--- @@ -30,3 +31,18 @@ function main() { let gu: Readonly>>>>> = {id: 0} arktest.assertEQ(gu.generic, undefined) } +======== +export class TestCls { + public static instance?: TestCls; + public foo: number; + private constructor() { + this.foo = 1234; + } + static getInstance() { + if (!TestCls.instance) { + TestCls.instance = new TestCls(); + } + return TestCls.instance; + } +} +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/private_constructor/ets_to_ts/private_constructor.ets diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/02.class_extension_clause/multi_level_inheritance/multi_level_inheritance_value_transfer17.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/02.class_extension_clause/multi_level_inheritance/multi_level_inheritance_value_transfer17.ets index 5be72024d7..961a1ee586 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/02.class_extension_clause/multi_level_inheritance/multi_level_inheritance_value_transfer17.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/02.class_extension_clause/multi_level_inheritance/multi_level_inheritance_value_transfer17.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/09.classes/02.class_extension_clause/multi_level_inheritance/multi_level_inheritance_value_transfer17.ets /*--- desc: >- Verify that the instance of class e can correctly obtain the null value of the variable after multiple layers @@ -48,4 +49,28 @@ class E extends D { function main(): void { let test: E = new E(); arktest.assertEQ(test._publicVar, null); +======== +function main() { + let sab = new ArrayBuffer(1024); + let ab = new ArrayBuffer(256); + + let view6 = new Uint32Array(sab, 32, 20); + let control6 = new Uint32Array(ab, 0, 2); + + view6[3] = -5; + control6[0] = -5; + + arktest.assertEQ(Atomics.or(view6, 3, 0), control6[0]); + + let bsab = new ArrayBuffer(1024); + let bab = new ArrayBuffer(256); + + let bview6 = new Uint32Array(bsab, 32, 20); + let bcontrol6 = new Uint32Array(bab, 0, 2); + + bview6[3] = -5; + bcontrol6[0] = -5; + + arktest.assertEQ(Atomics.or(bview6, 3, 0), bcontrol6[0]); +>>>>>>>> origin/master:static_core/plugins/ets/tests/ets-common-tests/atomics/nonconcurrent_signed_unsigned_test.ets } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/03.class_implementation_clause/abstract_method_inheritance_2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/03.class_implementation_clause/abstract_method_inheritance_2.ets index a7891aef11..bc39836c5a 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/03.class_implementation_clause/abstract_method_inheritance_2.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/03.class_implementation_clause/abstract_method_inheritance_2.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/09.classes/03.class_implementation_clause/abstract_method_inheritance_2.ets /*--- desc: Abstract class inherits default method from superinterface. ---*/ @@ -30,3 +31,11 @@ class C extends A {} function main() { arktest.assertEQ(new C().foo(), 1) } +======== +#ifndef TESTS_FUZZTEST_CHECKSECUREMEM_FUZZER_CHECKSECUREMEM_FUZZER_H +#define TESTS_FUZZTEST_CHECKSECUREMEM_FUZZER_CHECKSECUREMEM_FUZZER_H + +#define FUZZ_PROJECT_NAME "checksecuremem_fuzzer" + +#endif // TESTS_FUZZTEST_CHECKSECUREMEM_FUZZER_CHECKSECUREMEM_FUZZER_H +>>>>>>>> origin/master:tests/fuzztest/checksecuremem_fuzzer/checksecuremem_fuzzer.h diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml index 867833998b..b8170afa8b 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml --- # List of invalid static method modifiers modifiers: - "abstract" @@ -18,3 +19,6 @@ modifiers: - "open" - "synchronized" - 'final' +======== +add_subdirectory(ts_to_ets) +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/function_return_array_test/CMakeLists.txt diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_protected2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_protected2.ets index 2bcd3794c4..92cb105ba1 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_protected2.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_protected2.ets @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_protected2.ets /*--- desc: Class constructor declaration assert: >- @@ -31,3 +32,18 @@ class A { function main() { let b = new A(42) } +======== +#ifndef PANDA_PLUGINS_INTEROP_JS_TIMER_HELPER_H +#define PANDA_PLUGINS_INTEROP_JS_TIMER_HELPER_H + +#include + +namespace ark::ets::interop::js::helper { + +/// @brief Initialize timer module in env +napi_value Init(napi_env env, napi_value exports); + +} // namespace ark::ets::interop::js::helper + +#endif // PANDA_PLUGINS_INTEROP_JS_TIMER_HELPER_H +>>>>>>>> origin/master:static_core/plugins/ets/runtime/interop_js/timer_helper/interop_timer_helper.h diff --git a/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonTest.ets b/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonTest.ets index eb1962869d..0e51591ec4 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonTest.ets @@ -362,39 +362,39 @@ function testStringifyFunction(): int { type Option = T | undefined +class WithOption { + opt: Option = "hello" +} + function testStringifyUnion(): int { const option: Option = "hello" let testResult = test('"hello"' == JSON.stringify(option), "standalone union") testResult += test('["hello"]' == JSON.stringify([option]), "array of unions") - class WithOption { - opt: Option = "hello" - } - testResult += test('{"opt":"hello"}' == JSON.stringify(new WithOption()), "class with union typed field") return testResult } -function testStringifyInterface(): int { - interface Fn { - apply(a: A): R - } +interface Fn { + apply(a: A): R +} - class IdentityFn implements Fn { - apply(a: A): A { - return a - } +class IdentityFn implements Fn { + apply(a: A): A { + return a } +} + +class WithFn { + fn: Fn = new IdentityFn() +} +function testStringifyInterface(): int { const identityNumber: Fn = new IdentityFn() let testResult = test("{}" == JSON.stringify(identityNumber), "standalone interface") - class WithFn { - fn: Fn = new IdentityFn() - } - testResult += test('{"fn":{}}' == JSON.stringify(new WithFn()), "class with interface typed field") return testResult diff --git a/static_core/plugins/ets/tests/ets_func_tests/regression/20944.ets b/static_core/plugins/ets/tests/ets_func_tests/regression/20944.ets index e84265db81..62557c28de 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/regression/20944.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/regression/20944.ets @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/ets_func_tests/regression/20944.ets /*--- desc: Issue 20944. Adding constructor with readonly[] breaks STDLIB compilation tags: [compile-only] @@ -38,3 +39,28 @@ class MySetWithROConstructor1 { class MySetWithROConstructor2 { constructor(input: readonly TX2[]) {} } +======== +#include +#include "ets_interop_js_gtest.h" + +namespace ark::ets::interop::js::testing { + +class ObjectTsToEtsTest : public EtsInteropTest {}; + +TEST_F(ObjectTsToEtsTest, ObjectTestValue) +{ + ASSERT_EQ(true, CallEtsFunction(GetPackageName(), "ObjectTestValue")); +} + +TEST_F(ObjectTsToEtsTest, ObjectStringTestValue) +{ + ASSERT_EQ(true, CallEtsFunction(GetPackageName(), "ObjectStringTestValue")); +} + +TEST_F(ObjectTsToEtsTest, ObjectBooleanTestValue) +{ + ASSERT_EQ(true, CallEtsFunction(GetPackageName(), "ObjectBooleanTestValue")); +} + +} // namespace ark::ets::interop::js::testing +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/object/ts_to_ets/object_test.cpp diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/core/DoubleInvoke.ets b/static_core/plugins/ets/tests/ets_func_tests/std/core/DoubleInvoke.ets index 33bda2c047..ef05588952 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/core/DoubleInvoke.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/core/DoubleInvoke.ets @@ -45,6 +45,11 @@ function testNullInvoke(): void { arktest.assertEQ(tmp.toFixed(2).toString(), '0.00'); } +function testNullInvoke(): void { + let tmp = Number(null); + assertEQ(tmp.toFixed(2).toString(), '0.00'); +} + function main() { testVoidInvoke(); testStringInvoke(); diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/core/dateformat/DateTimeFormatTest.ets b/static_core/plugins/ets/tests/ets_func_tests/std/core/dateformat/DateTimeFormatTest.ets index 3e0792b1cd..79c0d1b291 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/core/dateformat/DateTimeFormatTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/core/dateformat/DateTimeFormatTest.ets @@ -98,6 +98,14 @@ function testConsoleLogNegativeDate() { arktest.assertEQ(res, "Date: \"1969-12-31T23:55:28.178Z\"") } +function testConsoleLogNegativeDate() { + let d = new Date(-271822) + const MAX_CONSOLE_PRINT_DEPTH: int = 10 + // console.log stub + let res = Value.of(d as NullishType).toPrint(MAX_CONSOLE_PRINT_DEPTH) + arktest.assertEQ(res, "Date: \"1969-12-31T23:55:28.178Z\"") +} + function main(): int { initFormatResults() diff --git a/static_core/plugins/ets/tests/ets_sdk/fuzztest/fuzzer.gni b/static_core/plugins/ets/tests/ets_sdk/fuzztest/fuzzer.gni index c9a290439c..c18d20b5e2 100644 --- a/static_core/plugins/ets/tests/ets_sdk/fuzztest/fuzzer.gni +++ b/static_core/plugins/ets/tests/ets_sdk/fuzztest/fuzzer.gni @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -module_output_path = "arkcompiler/runtime_core/static_core/plugins/ets_sdk" +module_output_path = "runtime_core/runtime_core/static_core/plugins/ets_sdk" diff --git a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/CMakeLists.txt b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/CMakeLists.txt index 691a2568b3..4e76a3f507 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/CMakeLists.txt +++ b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/CMakeLists.txt @@ -184,7 +184,7 @@ function(create_declgen_ets2ts_test TARGET) OUTPUT ${JS_FILES} COMMENT "Compile ts files: ${COPIED_TS_SOURCES} ${DECL_FILES} ${GLUE_FILES}" COMMAND ${PANDA_THIRD_PARTY_SOURCES_DIR}/typescript/bin/tsc --target es5 --strict --lib es2020,dom --outDir ${CMAKE_CURRENT_BINARY_DIR} ${COPIED_TS_SOURCES} ${DECL_FILES} - COMMAND ${PANDA_THIRD_PARTY_SOURCES_DIR}/typescript/bin/tsc --target es5 --strict --outDir "${CMAKE_CURRENT_BINARY_DIR}" ${GLUE_FILES} + # COMMAND ${PANDA_THIRD_PARTY_SOURCES_DIR}/typescript/bin/tsc --target es5 --strict --outDir "${CMAKE_CURRENT_BINARY_DIR}" ${GLUE_FILES} DEPENDS es2panda ark_link ${ABC_TARGETS} ${ARKTSCONFIG} ${COPIED_TS_SOURCES} ${DECL_FILES} ) add_custom_target(${TARGET}_tsc diff --git a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/CMakeLists.txt b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/CMakeLists.txt index 27d04e0692..1f393bacd1 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/CMakeLists.txt +++ b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/CMakeLists.txt @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +<<<<<<<< HEAD:static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/CMakeLists.txt create_declgen_ets2ts_test(jsdoc ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} @@ -26,4 +27,10 @@ create_declgen_ets2ts_test(jsdoc ${CMAKE_CURRENT_SOURCE_DIR}/lib.ets DECLS_EXPECTED ${CMAKE_CURRENT_SOURCE_DIR}/lib.expected +======== +panda_ets_interop_js_gtest(ets_interop_js__dynamic_import + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dynamic-import.cpp + ETS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/export12.ets + TS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dynamic-import.ts +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/dynamicimport/ets_to_ts/CMakeLists.txt ) diff --git a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/jsdoc.ts b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/jsdoc.ts index ab4f7c8650..716572ecdc 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/jsdoc.ts +++ b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/jsdoc.ts @@ -12,17 +12,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef PANDA_TOOLING_INSPECTOR_COMMON_H +#define PANDA_TOOLING_INSPECTOR_COMMON_H +<<<<<<<< HEAD:static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/jsdoc.ts import { c3 } from './lib'; +======== +#include +#include +>>>>>>>> origin/master:static_core/runtime/tooling/inspector/common.h -function assertEq(a: T, b: T): void { - // @ts-ignore - print(`assertEq: '${a}' === '${b}'`); - if (a !== b) { - throw new Error(`assertEq failed: '${a}' === '${b}'`); - } -} +namespace ark::tooling::inspector { +using SourceFileFilter = std::function; +} // namespace ark::tooling::inspector +<<<<<<<< HEAD:static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/jsdoc.ts export function main(): void { testJSDoc(); } @@ -33,3 +37,6 @@ function testJSDoc(): void { assertEq(classC3.a, one) assertEq(classC3.b(), one); } +======== +#endif // PANDA_TOOLING_INSPECTOR_COMMON_H +>>>>>>>> origin/master:static_core/runtime/tooling/inspector/common.h diff --git a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/main.ts b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/main.ts index 7f2e5f4a79..c695bcb359 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/main.ts +++ b/static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/main.ts @@ -13,7 +13,13 @@ * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/interop_js/tests/declgen_ets2ts/jsdoc/main.ts import { helper, etsVm } from './ets_vm_launcher'; import { main } from './jsdoc'; main(); +======== +function main() { + return new Double(1.000); +} +>>>>>>>> origin/master:static_core/plugins/ets/tests/runtime/entrypoint_return_test.ets diff --git a/static_core/plugins/ets/tests/interop_js/tests/hybridgref/CMakeLists.txt b/static_core/plugins/ets/tests/interop_js/tests/hybridgref/CMakeLists.txt index 101b8ddda7..0b4f4ffed7 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/hybridgref/CMakeLists.txt +++ b/static_core/plugins/ets/tests/interop_js/tests/hybridgref/CMakeLists.txt @@ -12,4 +12,4 @@ # limitations under the License. add_subdirectory(ets_to_ts) -add_subdirectory(ts_to_ets) \ No newline at end of file +add_subdirectory(ts_to_ets) diff --git a/static_core/plugins/ets/tests/interop_js/tests/interop_isa/test.ets b/static_core/plugins/ets/tests/interop_js/tests/interop_isa/test.ets index 7bef8f491f..097e5fa6bc 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/interop_isa/test.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/interop_isa/test.ets @@ -12,3 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tests/interop_js/tests/interop_isa/test.ets +======== + +export * from './get_module'; +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/getEtsModule/ets_to_ts/entry_module2.ets diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic/arg_generic.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic/arg_generic.ets index a499b71fef..47b2c5a22d 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic/arg_generic.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic/arg_generic.ets @@ -27,12 +27,11 @@ import { instanceChildAgeNameGenericClass, } from 'main_js'; +class TypeClass { + age = tsNumber; + name = tsString; +} function checkArgFuFromSts(): boolean { - class TypeClass { - age = tsNumber; - name = tsString; - } - return checkAgeNameGeneric(new TypeClass()) as boolean; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic_negative_result/arg_generic_negative_result.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic_negative_result/arg_generic_negative_result.ets index 9cc8f2ade6..199cc4e8ac 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic_negative_result/arg_generic_negative_result.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_generic_negative_result/arg_generic_negative_result.ets @@ -23,10 +23,10 @@ import { instanceChildAgeNameGenericClass, } from 'main_js'; +class TypeWrong { + age = tsNumber; +} function checkArgFuFromSts(): boolean { - class TypeWrong { - age = tsNumber; - } return checkAgeNameGeneric(new TypeWrong()) as boolean == false; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface/arg_interface.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface/arg_interface.ets index 4948223cd9..f83c496405 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface/arg_interface.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface/arg_interface.ets @@ -27,12 +27,11 @@ import { instanceChildAgeNameInterfaceClass, } from 'main_js'; +class AgeNameClass { + age = tsNumber; + name = tsString; +} function checkArgFuFromSts(): boolean { - class AgeNameClass { - age = tsNumber; - name = tsString; - } - return checkIntersectionInterface(new AgeNameClass()) as boolean; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface_negative_result/arg_interface_negative_result.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface_negative_result/arg_interface_negative_result.ets index 26964adf4c..2d64cdd752 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface_negative_result/arg_interface_negative_result.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_interface_negative_result/arg_interface_negative_result.ets @@ -23,11 +23,10 @@ import { instanceChildAgeNameInterfaceClass, } from 'main_js'; +class AgeNameWrong { + age = tsNumber; +} function checkArgFuFromSts(): boolean { - class AgeNameWrong { - age = tsNumber; - } - return checkIntersectionInterface(new AgeNameWrong()) as boolean == false; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal/arg_literal.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal/arg_literal.ets index 258898bdde..b517d901e4 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal/arg_literal.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal/arg_literal.ets @@ -28,11 +28,11 @@ import { } from 'main_js'; +class Intersection { + age = tsNumber; + name = tsString; +} function checkArgFuFromSts(): boolean { - class Intersection { - age = tsNumber; - name = tsString; - } return checkLiteralType(new Intersection()) as boolean; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal_negative_result/arg_literal_negative_result.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal_negative_result/arg_literal_negative_result.ets index 092183b142..633995787b 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal_negative_result/arg_literal_negative_result.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_literal_negative_result/arg_literal_negative_result.ets @@ -23,11 +23,10 @@ import { instanceChildAgeNameLiteralClass, } from 'main_js'; +class IntersectionWrong { + age = tsNumber; +} function checkArgFuFromSts(): boolean { - class IntersectionWrong { - age = tsNumber; - } - return checkLiteralType(new IntersectionWrong()) as boolean == false; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union/arg_union.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union/arg_union.ets index 1834aee365..d3f4c646cc 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union/arg_union.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union/arg_union.ets @@ -27,13 +27,12 @@ import { instanceChildAgeNameUnionClass, } from 'main_js'; +class Intersection1 { + age = tsNumber; + name = tsString; +} function checkArgFuFromSts(): boolean { - class Intersection { - age = tsNumber; - name = tsString; - } - - return checkUnionType(new Intersection()) as boolean; + return checkUnionType(new Intersection1()) as boolean; } function checkIntersectionTypeClass(): boolean { diff --git a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union_negative_result/arg_union_negative_result.ets b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union_negative_result/arg_union_negative_result.ets index 03f592398d..f703699272 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union_negative_result/arg_union_negative_result.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/intersection_signature/arg_union_negative_result/arg_union_negative_result.ets @@ -23,10 +23,10 @@ import { instanceChildAgeNameUnionClass, } from 'main_js'; +class IntersectionWrong { + age = tsNumber; +} function checkArgFuFromSts(): boolean { - class IntersectionWrong { - age = tsNumber; - } return checkUnionType(new IntersectionWrong()) as boolean == false; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/perf/benchmarks/caller.ets b/static_core/plugins/ets/tests/interop_js/tests/perf/benchmarks/caller.ets index 1a0cc32525..aa7dcbec5a 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/perf/benchmarks/caller.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/perf/benchmarks/caller.ets @@ -39,33 +39,33 @@ class $jsnew { static Init = JSRuntime.__initJSNewClass(); }; -export function initBenchmarks(isInterop : boolean): Object -{ - class Benchmarks { - voidPasser = voidPasser - numPasser = numPasser - strPasser = strPasser - arrPasser = arrPasser - arrGetter = arrGetter - strGetter = strGetter - objGetter = objGetter - numGetter = numGetter - } +class Benchmarks { + voidPasser = voidPasser + numPasser = numPasser + strPasser = strPasser + arrPasser = arrPasser + arrGetter = arrGetter + strGetter = strGetter + objGetter = objGetter + numGetter = numGetter +} - class InteropBenchmarks { - voidPasser = interop_voidPasser - numPasser = interop_numPasser - strPasser = interop_strPasser - arrPasser = interop_arrPasser - arrGetter = interop_arrGetter - strGetter = interop_strGetter - objGetter = interop_objGetter - numGetter = interop_numGetter - arrAnyGetter = interop_arrAnyGetter - strAnyGetter = interop_strAnyGetter - numAnyGetter = interop_numAnyGetter - } +class InteropBenchmarks { + voidPasser = interop_voidPasser + numPasser = interop_numPasser + strPasser = interop_strPasser + arrPasser = interop_arrPasser + arrGetter = interop_arrGetter + strGetter = interop_strGetter + objGetter = interop_objGetter + numGetter = interop_numGetter + arrAnyGetter = interop_arrAnyGetter + strAnyGetter = interop_strAnyGetter + numAnyGetter = interop_numAnyGetter +} +export function initBenchmarks(isInterop : boolean): Object +{ if (isInterop) { return new InteropBenchmarks; } diff --git a/static_core/plugins/ets/tests/test-lists/unit-tests/unit-tests-excluded.txt b/static_core/plugins/ets/tests/test-lists/unit-tests/unit-tests-excluded.txt index 87161f96f8..fe84b6da50 100644 --- a/static_core/plugins/ets/tests/test-lists/unit-tests/unit-tests-excluded.txt +++ b/static_core/plugins/ets/tests/test-lists/unit-tests/unit-tests-excluded.txt @@ -3,3 +3,4 @@ ets-common-tests/bouncing_peas/bouncing_peas_unit_native.ets ets-common-tests/atomics/skipped_rendezvous_channel.ets ets-common-tests/atomics/skipped_wait_timeout.ets ets-common-tests/atomics/skipped_cyclic_barrier.ets +ets-common-tests/atomics/base_operator_exchange.ets diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-abstract-classes.d.ts b/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-abstract-classes.d.ts index 7a9372f6f6..4e73beee46 100644 --- a/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-abstract-classes.d.ts +++ b/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-abstract-classes.d.ts @@ -12,7 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-abstract-classes.d.ts export declare abstract class Animal { abstract move(): void; +======== +export default declare abstract class A { + a: number; + constructor(a: number); + abstract logs(message: string): string; +} +export declare class B { + a: number; + constructor(a: number); +>>>>>>>> origin/master:static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/arkts-export-default-abstract-class.d.ets } diff --git a/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-async-static-methods.d.ts b/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-async-static-methods.d.ts index 51440457c6..0276230954 100644 --- a/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-async-static-methods.d.ts +++ b/static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-async-static-methods.d.ts @@ -12,7 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +<<<<<<<< HEAD:static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/dts_declarations/arkts-classes-async-static-methods.d.ts export declare class C { static foo(): Promise; } +======== +export type StringIndexedObject = Any; +export type NumberIndexedObject = Any; +export type MixedIndexObject = Any; +>>>>>>>> origin/master:static_core/plugins/ets/tools/declgen_ts2sts/test/cookbook_tests/arkts-index-signature-interface.d.ets diff --git a/static_core/runtime/global_handle_storage-inl.h b/static_core/runtime/global_handle_storage-inl.h index 407b0bd762..7bf01a8885 100644 --- a/static_core/runtime/global_handle_storage-inl.h +++ b/static_core/runtime/global_handle_storage-inl.h @@ -101,6 +101,17 @@ inline void GlobalHandleStorage::DealUpdateObject(std::ar } } +template <> +// CC-OFFNXT(G.FUD.06) solid logic +inline void GlobalHandleStorage::UpdateGCRootsInBlock(std::array *block, + size_t size, + const GCRootUpdater &gcRootUpdater) +{ + for (size_t i = 0; i < size; i++) { + DealUpdateObject(block, i, gcRootUpdater); + } +} + template <> // CC-OFFNXT(G.FUD.06) solid logic inline void GlobalHandleStorage::UpdateHeapObject(const GCRootUpdater &gcRootUpdater) @@ -110,16 +121,10 @@ inline void GlobalHandleStorage::UpdateHeapObject(const G } for (size_t i = 0; i < globalNodes_->size() - 1; i++) { - auto block = globalNodes_->at(i); - for (size_t j = 0; j < GLOBAL_BLOCK_SIZE; j++) { - DealUpdateObject(block, j, gcRootUpdater); - } + UpdateGCRootsInBlock(globalNodes_->at(i), GLOBAL_BLOCK_SIZE, gcRootUpdater); } - auto block = globalNodes_->back(); - for (int32_t i = 0; i < count_; i++) { - DealUpdateObject(block, i, gcRootUpdater); - } + UpdateGCRootsInBlock(globalNodes_->back(), count_, gcRootUpdater); } template <> @@ -132,6 +137,16 @@ inline void GlobalHandleStorage::DealVisitGCRoots(std::ar } } +template <> +// CC-OFFNXT(G.FUD.06) solid logic +inline void GlobalHandleStorage::VisitGCRootsInBlock(std::array *block, + size_t size, const ObjectVisitor &cb) +{ + for (size_t i = 0; i < size; i++) { + DealVisitGCRoots(block, i, cb); + } +} + template <> // CC-OFFNXT(G.FUD.06) solid logic inline void GlobalHandleStorage::VisitGCRoots([[maybe_unused]] const ObjectVisitor &cb) @@ -141,16 +156,10 @@ inline void GlobalHandleStorage::VisitGCRoots([[maybe_unu } for (size_t i = 0; i < globalNodes_->size() - 1; i++) { - auto block = globalNodes_->at(i); - for (size_t j = 0; j < GLOBAL_BLOCK_SIZE; j++) { - DealVisitGCRoots(block, j, cb); - } + VisitGCRootsInBlock(globalNodes_->at(i), GLOBAL_BLOCK_SIZE, cb); } - auto block = globalNodes_->back(); - for (int32_t i = 0; i < count_; i++) { - DealVisitGCRoots(block, i, cb); - } + VisitGCRootsInBlock(globalNodes_->back(), count_, cb); } template class GlobalHandleStorage; diff --git a/static_core/runtime/global_handle_storage.h b/static_core/runtime/global_handle_storage.h index b8c856bd4c..59b17c25cb 100644 --- a/static_core/runtime/global_handle_storage.h +++ b/static_core/runtime/global_handle_storage.h @@ -110,6 +110,10 @@ private: { } + inline void UpdateGCRootsInBlock(std::array *block, size_t size, + const GCRootUpdater &gcRootUpdater); + inline void VisitGCRootsInBlock(std::array *block, size_t size, const ObjectVisitor &cb); + inline void FreeGlobalNodes() { for (auto block : *globalNodes_) { diff --git a/static_core/runtime/handle_storage-inl.h b/static_core/runtime/handle_storage-inl.h index 6f61556228..19713a8531 100644 --- a/static_core/runtime/handle_storage-inl.h +++ b/static_core/runtime/handle_storage-inl.h @@ -47,6 +47,17 @@ inline uintptr_t HandleStorage::NewHandle(T value) return reinterpret_cast(loc); } +template +inline void HandleStorage::FreeExtraNodes(uint32_t nid) +{ + for (size_t i = nid; i < nodes_.size(); ++i) { + allocator_->Delete(nodes_[i]); + } + if (nid < nodes_.size()) { + nodes_.erase(nodes_.begin() + nid, nodes_.end()); + } +} + template inline void HandleStorage::FreeHandles(uint32_t beginIdx) { @@ -57,11 +68,14 @@ inline void HandleStorage::FreeHandles(uint32_t beginIdx) uint32_t nid = lastIndex_ >> NODE_BLOCK_SIZE_LOG2; // reserve at least one block for perf. nid++; - for (size_t i = nid; i < nodes_.size(); ++i) { - allocator_->Delete(nodes_[i]); - } - if (nid < nodes_.size()) { - nodes_.erase(nodes_.begin() + nid, nodes_.end()); + FreeExtraNodes(nid); +} + +template +void HandleStorage::ZapFreedHandlesForNode(std::array *node, uint32_t start) +{ + for (uint32_t j = start; j < NODE_BLOCK_SIZE; ++j) { + node->at(j) = reinterpret_cast(static_cast(0)); } } @@ -73,11 +87,25 @@ void HandleStorage::ZapFreedHandles() for (size_t i = nid; i < nodes_.size(); ++i) { auto node = nodes_.at(i); if (i != nid) { - node->fill(reinterpret_cast(static_cast(0))); + ZapFreedHandlesForNode(node); } else { - for (uint32_t j = offset; j < NODE_BLOCK_SIZE; ++j) { - node->at(j) = reinterpret_cast(static_cast(0)); - } + ZapFreedHandlesForNode(node, offset); + } + } +} + +template <> +inline void HandleStorage::UpdateHeapObjectForNode( + std::array *node, uint32_t size, const GCRootUpdater &gcRootUpdater) +{ + for (uint32_t j = 0; j < size; ++j) { + coretypes::TaggedValue obj(node->at(j)); + if (!obj.IsHeapObject()) { + continue; + } + ObjectHeader *objH = obj.GetHeapObject(); + if (gcRootUpdater(&objH)) { + (*node)[j] = coretypes::TaggedValue(objH).GetRawData(); } } } @@ -94,15 +122,18 @@ inline void HandleStorage::UpdateHeapObject(const GCRootU for (uint32_t i = 0; i <= nid; ++i) { auto node = nodes_.at(i); uint32_t count = (i != nid) ? NODE_BLOCK_SIZE : offset; - for (uint32_t j = 0; j < count; ++j) { - coretypes::TaggedValue obj(node->at(j)); - if (!obj.IsHeapObject()) { - continue; - } - ObjectHeader *objH = obj.GetHeapObject(); - if (gcRootUpdater(&objH)) { - (*node)[j] = coretypes::TaggedValue(objH).GetRawData(); - } + UpdateHeapObjectForNode(node, count, gcRootUpdater); + } +} + +template <> +inline void HandleStorage::VisitGCRootsForNode( + std::array *node, uint32_t size, const ObjectVisitor &cb) +{ + for (uint32_t j = 0; j < size; ++j) { + coretypes::TaggedValue obj(node->at(j)); + if (obj.IsHeapObject()) { + cb(obj.GetHeapObject()); } } } @@ -123,12 +154,16 @@ inline void HandleStorage::VisitGCRoots([[maybe_unused]] for (uint32_t i = 0; i <= nid; ++i) { auto node = nodes_.at(i); uint32_t count = (i != nid) ? NODE_BLOCK_SIZE : offset; - for (uint32_t j = 0; j < count; ++j) { - coretypes::TaggedValue obj(node->at(j)); - if (obj.IsHeapObject()) { - cb(obj.GetHeapObject()); - } - } + VisitGCRootsForNode(node, count, cb); + } +} + +template <> +inline void HandleStorage::UpdateHeapObjectForNode(std::array *node, + uint32_t size, const GCRootUpdater &gcRootUpdater) +{ + for (uint32_t j = 0; j < size; ++j) { + gcRootUpdater(reinterpret_cast(&(*node)[j])); } } @@ -148,9 +183,17 @@ inline void HandleStorage::UpdateHeapObject(const GCRootUpdater for (uint32_t i = 0; i <= nid; ++i) { auto node = nodes_.at(i); uint32_t count = (i != nid) ? NODE_BLOCK_SIZE : offset; - for (uint32_t j = 0; j < count; ++j) { - gcRootUpdater(reinterpret_cast(&(*node)[j])); - } + UpdateHeapObjectForNode(node, count, gcRootUpdater); + } +} + +template <> +inline void HandleStorage::VisitGCRootsForNode(std::array *node, + uint32_t size, const ObjectVisitor &cb) +{ + for (uint32_t j = 0; j < size; ++j) { + auto obj = reinterpret_cast(node->at(j)); + cb(obj); } } @@ -166,10 +209,7 @@ inline void HandleStorage::VisitGCRoots([[maybe_unused]] const O for (uint32_t i = 0; i <= nid; ++i) { auto node = nodes_.at(i); uint32_t count = (i != nid) ? NODE_BLOCK_SIZE : offset; - for (uint32_t j = 0; j < count; ++j) { - auto obj = reinterpret_cast(node->at(j)); - cb(obj); - } + VisitGCRootsForNode(node, count, cb); } } diff --git a/static_core/runtime/handle_storage.h b/static_core/runtime/handle_storage.h index ee1f126c96..dcdad509f8 100644 --- a/static_core/runtime/handle_storage.h +++ b/static_core/runtime/handle_storage.h @@ -58,6 +58,21 @@ private: void ZapFreedHandles(); + void FreeExtraNodes(uint32_t nid); + + void ZapFreedHandlesForNode(std::array *node, uint32_t start = 0); + + void UpdateHeapObjectForNode(std::array *node, uint32_t size, + const GCRootUpdater &gcRootUpdater); + + void VisitGCRootsForNode(std::array *node, uint32_t size, + const ObjectVisitor &cb); + + void UpdateHeapObjectForNode(std::array *node, uint32_t size, + const GCRootUpdater &gcRootUpdater); + + void VisitGCRootsForNode(std::array *node, uint32_t size, const ObjectVisitor &cb); + // TaggedType has been specialized for js, Other types are empty implementation void UpdateHeapObject([[maybe_unused]] const GCRootUpdater &gcRootUpdater) {} diff --git a/static_core/runtime/include/object_accessor-inl.h b/static_core/runtime/include/object_accessor-inl.h index 39ff9d4f5f..e539e7ef68 100644 --- a/static_core/runtime/include/object_accessor-inl.h +++ b/static_core/runtime/include/object_accessor-inl.h @@ -449,6 +449,24 @@ inline T ObjectAccessor::GetAndAddFieldPrimitive([[maybe_unused]] void *obj, [[m } } +/* static */ +template +// CC-OFFNXT(G.FMT.06, G.FUD.06) project code style +T ObjectAccessor::GetAndSubFieldPrimitiveFloat(void *obj, size_t offset, T value, std::memory_order memoryOrder) +{ + // Atmoic fetch_add only defined in the atomic specializations for integral and pointer + uintptr_t rawAddr = reinterpret_cast(obj) + offset; + ASSERT(IsAddressInObjectsHeap(rawAddr)); + auto *atomicAddr = reinterpret_cast *>(rawAddr); + // Atomic with parameterized order reason: memory order passed as argument + T oldValue = atomicAddr->load(memoryOrder); + T newValue; + do { + newValue = oldValue - value; + } while (!atomicAddr->compare_exchange_weak(oldValue, newValue, memoryOrder)); + return oldValue; +} + /* static */ template // CC-OFFNXT(G.FMT.06, G.FUD.06) project code style @@ -459,17 +477,7 @@ inline std::enable_if_t || USE_UBYTE_ARITHMETIC, T> [[maybe_unused]] std::memory_order memoryOrder) { if constexpr (std::is_floating_point_v) { // NOLINT(readability-braces-around-statements) - // Atmoic fetch_add only defined in the atomic specializations for integral and pointer - uintptr_t rawAddr = reinterpret_cast(obj) + offset; - ASSERT(IsAddressInObjectsHeap(rawAddr)); - auto *atomicAddr = reinterpret_cast *>(rawAddr); - // Atomic with parameterized order reason: memory order passed as argument - T oldValue = atomicAddr->load(memoryOrder); - T newValue; - do { - newValue = oldValue - value; - } while (!atomicAddr->compare_exchange_weak(oldValue, newValue, memoryOrder)); - return oldValue; + return GetAndSubFieldPrimitiveFloat(obj, offset, value, memoryOrder); } else { // NOLINT(readability-misleading-indentation, readability-else-after-return) uintptr_t rawAddr = reinterpret_cast(obj) + offset; ASSERT(IsAddressInObjectsHeap(rawAddr)); diff --git a/static_core/runtime/include/object_accessor.h b/static_core/runtime/include/object_accessor.h index 29086cdeea..ae3eea6386 100644 --- a/static_core/runtime/include/object_accessor.h +++ b/static_core/runtime/include/object_accessor.h @@ -206,6 +206,9 @@ private: template static void FillObjsNoBarrier(void *objArr, size_t dataOffset, size_t count, size_t elemSize, ObjectHeader *value); + template + static T GetAndSubFieldPrimitiveFloat(void *obj, size_t offset, T value, std::memory_order memoryOrder); + template static void Set(void *obj, size_t offset, T value) { diff --git a/static_core/static_linker/BUILD.gn b/static_core/static_linker/BUILD.gn index c919778be6..278027157c 100644 --- a/static_core/static_linker/BUILD.gn +++ b/static_core/static_linker/BUILD.gn @@ -139,6 +139,7 @@ ohos_executable("ark_link") { group("static_linker") { deps = [ ":ark_link", + ":ark_link($host_toolchain)", ":arklinker", ] } diff --git a/static_core/tests/tests-u-runner-2/runner/test/config_test/data/__init__.py b/static_core/tests/tests-u-runner-2/runner/test/config_test/data/__init__.py index 9732ca4f2e..9fc9f69e54 100644 --- a/static_core/tests/tests-u-runner-2/runner/test/config_test/data/__init__.py +++ b/static_core/tests/tests-u-runner-2/runner/test/config_test/data/__init__.py @@ -1,6 +1,9 @@ +<<<<<<<< HEAD:static_core/tests/tests-u-runner-2/runner/test/config_test/data/__init__.py #!/usr/bin/env python3 # -*- coding: utf-8 -*- # +======== +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/dynamicimport/CMakeLists.txt # Copyright (c) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,3 +16,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +<<<<<<<< HEAD:static_core/tests/tests-u-runner-2/runner/test/config_test/data/__init__.py +======== + +add_subdirectory(ets_to_ts) +>>>>>>>> origin/master:static_core/plugins/ets/tests/interop_js/tests/dynamicimport/CMakeLists.txt diff --git a/static_core/tests/tests-u-runner-2/runner/test/launches_test/data/dependent_test2.ets b/static_core/tests/tests-u-runner-2/runner/test/launches_test/data/dependent_test2.ets index c8864be8bd..051b5e6a9d 100644 --- a/static_core/tests/tests-u-runner-2/runner/test/launches_test/data/dependent_test2.ets +++ b/static_core/tests/tests-u-runner-2/runner/test/launches_test/data/dependent_test2.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +<<<<<<<< HEAD:static_core/tests/tests-u-runner-2/runner/test/launches_test/data/dependent_test2.ets /*--- tags: [not-a-test, compile-only] @@ -19,4 +20,8 @@ export function foo(): void { return; +======== +interface AniObject { + getGlobalReference(): Opaque; +>>>>>>>> origin/master:taihe/stdlib/taihe.platform.ani.taihe } diff --git a/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/hvigor.py b/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/hvigor.py index d1dea983e2..4310d30d4c 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/hvigor.py +++ b/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/hvigor.py @@ -160,10 +160,13 @@ class Tool(ToolBase): def exec(self, bu: BenchUnit) -> None: if self.signing_config: - build_config['app']['signingConfigs'] = [{ - "name": "default", - "material": load_json(self.signing_config)}] - build_config['app']['products'][0]['signingConfig'] = 'default' + try: + build_config['app']['signingConfigs'] = [{ + "name": "default", + "material": load_json(self.signing_config)}] + build_config['app']['products'][0]['signingConfig'] = 'default' + except KeyError as e: + raise RuntimeError('Corrupted build config') from e Tool.emit_config(build_config, bu.path.joinpath('build-profile.json5')) Tool.emit_config(oh_package, bu.path.joinpath('oh-package.json5')) Tool.emit_config(oh_package, bu.path.joinpath(self.mod_name, 'oh-package.json5')) diff --git a/static_core/tests/vm-benchmarks/src/vmb/resources/hap/EtsRuntime.ts b/static_core/tests/vm-benchmarks/src/vmb/resources/hap/EtsRuntime.ts index e28ead923d..ea167074ed 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/resources/hap/EtsRuntime.ts +++ b/static_core/tests/vm-benchmarks/src/vmb/resources/hap/EtsRuntime.ts @@ -13,36 +13,36 @@ * limitations under the License. */ -import hilog from "@ohos.hilog"; +import hilog from '@ohos.hilog'; export function InitEtsRuntime(bench_file: string, bench_mode: string): void { - globalThis.Panda = globalThis.requireNapi("ets_interop_js_napi", true); - const libs = "/data/storage/el1/bundle/libs/arm64"; - const bench = libs + "/" + bench_file; - const stdlib = libs + "/etsstdlib.abc.so"; + globalThis.Panda = globalThis.requireNapi('ets_interop_js_napi', true); + const libs = '/data/storage/el1/bundle/libs/arm64'; + const bench = libs + '/' + bench_file; + const stdlib = libs + '/etsstdlib.abc.so'; const opts = { - "panda-files": bench, - "boot-panda-files": stdlib + ":" + bench, - "gc-trigger-type": "heap-trigger", - "load-runtimes": "ets", - "compiler-enable-jit": "false", - "run-gc-in-place": "true" + 'panda-files': bench, + 'boot-panda-files': stdlib + ':' + bench, + 'gc-trigger-type': 'heap-trigger', + 'load-runtimes': 'ets', + 'compiler-enable-jit': 'false', + 'run-gc-in-place': 'true' }; - if ("aot" == bench_mode) { - opts["enable-an:force"] = "true"; - opts["aot-file"] = libs + "/aot_file.an.so"; + if ('aot' === bench_mode) { + opts['enable-an:force'] = 'true'; + opts['aot-file'] = libs + '/aot_file.an.so'; } - if ("jit" == bench_mode) { - opts["compiler-enable-jit"] = "true"; - opts["no-async-jit"] = "false"; + if ('jit' === bench_mode) { + opts['compiler-enable-jit'] = 'true'; + opts['no-async-jit'] = 'false'; } - if ("int" == bench_mode) { - opts["compiler-enable-jit"] = "false"; + if ('int' === bench_mode) { + opts['compiler-enable-jit'] = 'false'; } if (!globalThis.Panda.createRuntime(opts)) { - hilog.info(0, "VMB", "%{public}s", "ETS RUNTIME CREATE ERROR"); - throw new Error("ERROR CREATING ETS RUNTIME"); + hilog.info(0, 'VMB', '%{public}s', 'ETS RUNTIME CREATE ERROR'); + throw new Error('ERROR CREATING ETS RUNTIME'); } else { - hilog.info(0, "VMB", "%{public}s", "ETS RUNTIME CREATE OK"); + hilog.info(0, 'VMB', '%{public}s', 'ETS RUNTIME CREATE OK'); } } diff --git a/static_core/tools/ark_js_napi_cli/BUILD.gn b/static_core/tools/ark_js_napi_cli/BUILD.gn index 4a134c9bed..781a310970 100755 --- a/static_core/tools/ark_js_napi_cli/BUILD.gn +++ b/static_core/tools/ark_js_napi_cli/BUILD.gn @@ -17,6 +17,8 @@ if (!ark_standalone_build) { } ark_js_napi_cli_sources = [ + "$ark_root/static_core/plugins/ets/runtime/interop_js/timer_helper/timer.cpp", + "$ark_root/static_core/plugins/ets/runtime/interop_js/timer_helper/interop_timer_helper.cpp", "ark_hz/ark_js_runtime.cpp", "js_runtime.cpp", "main.cpp", diff --git a/static_core/tools/ark_js_napi_cli/ark_hz/ark_js_runtime.cpp b/static_core/tools/ark_js_napi_cli/ark_hz/ark_js_runtime.cpp index 7c4182863f..ca86b0e27d 100644 --- a/static_core/tools/ark_js_napi_cli/ark_hz/ark_js_runtime.cpp +++ b/static_core/tools/ark_js_napi_cli/ark_hz/ark_js_runtime.cpp @@ -71,6 +71,11 @@ bool ArkJsRuntime::ProcessOptions(int argc, const char **argv, arg_list_t *filen return true; } +static napi_value JsValueFromLocalValue(panda::Local local) +{ + return reinterpret_cast(*local); +} + bool ArkJsRuntime::Init() { if (vm_ != nullptr) { @@ -88,6 +93,9 @@ bool ArkJsRuntime::Init() engine_->SetGetAssetFunc(utils::GetAsset); engine_->SetCleanEnv([this] { JSNApi::DestroyJSVM(vm_); }); + auto *engine = GetNativeEngine(); + Local global = panda::JSNApi::GetGlobalObject(vm_); + ark::ets::interop::js::helper::Init(reinterpret_cast(engine), JsValueFromLocalValue(global)); return true; } -- Gitee From 2662aa36cf202c0c5bbbc0b88ed9e802ec450c83 Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Tue, 9 Sep 2025 14:14:55 +0300 Subject: [PATCH 2/2] Revert Trim Change-Id: I160e335b58091d0931d61161bfe543fbd573b805 --- .../objects/string/line_string-inl.h | 22 ------------------- .../objects/string/line_string.h | 2 -- 2 files changed, 24 deletions(-) diff --git a/common_interfaces/objects/string/line_string-inl.h b/common_interfaces/objects/string/line_string-inl.h index f10395ea06..181f1a3170 100644 --- a/common_interfaces/objects/string/line_string-inl.h +++ b/common_interfaces/objects/string/line_string-inl.h @@ -178,28 +178,6 @@ void LineString::WriteData(ReadBarrier &&readBarrier, BaseString *src, uint32_t } } -inline void LineString::Trim(uint32_t newLength) -{ - ASSERT(IsLineString()); - uint32_t oldLength = GetLength(); - ASSERT(oldLength >= newLength); - if (newLength == oldLength) return; - bool isUtf8 = IsUtf8(); - size_t sizeNew = isUtf8 ? - LineString::ComputeSizeUtf8(newLength): LineString::ComputeSizeUtf16(newLength); - size_t sizeOld = isUtf8 ? - LineString::ComputeSizeUtf8(oldLength): LineString::ComputeSizeUtf16(oldLength); - sizeNew = common::AlignUp(sizeNew, ALIGNMENT_8_BYTES); - sizeOld = common::AlignUp(sizeOld, ALIGNMENT_8_BYTES); - size_t trimBytes = sizeOld - sizeNew; - if (trimBytes > 0) { - uintptr_t newEndAddr = ToUintPtr(this) + sizeNew; - ASSERT_PRINT((newEndAddr % ALIGNMENT_8_BYTES) == 0, "Alignment failed"); - FillFreeObject(reinterpret_cast(newEndAddr), trimBytes); - } - InitLengthAndFlags(newLength, isUtf8); -} - inline bool LineString::CanBeCompressed(const LineString *string) { if (string->IsUtf8()) { diff --git a/common_interfaces/objects/string/line_string.h b/common_interfaces/objects/string/line_string.h index 30bbcab92a..9753d0e425 100644 --- a/common_interfaces/objects/string/line_string.h +++ b/common_interfaces/objects/string/line_string.h @@ -154,8 +154,6 @@ public: */ void Set(uint32_t index, uint16_t src); - void Trim(uint32_t newLength); - /** * @brief Compute memory size for a UTF-8 encoded string. * @param utf8Len Length in bytes. -- Gitee