From 7fa718e2351c63333ad4b3155dc880e6b9facc97 Mon Sep 17 00:00:00 2001 From: Evgeniy Nikeytsev Date: Fri, 30 Dec 2022 17:05:56 +0300 Subject: [PATCH] Add test to verify write pre-barrier works correctly with primitive value both in INT and AOT configurations Signed-off-by: Evgeniy Nikeytsev --- tests/runtime/common/gc/CMakeLists.txt | 47 +++++++++++++++++++ .../gc/write_prebarrier_primitive_value.js | 28 +++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/runtime/common/gc/write_prebarrier_primitive_value.js diff --git a/tests/runtime/common/gc/CMakeLists.txt b/tests/runtime/common/gc/CMakeLists.txt index 835be59e7..dde610e69 100644 --- a/tests/runtime/common/gc/CMakeLists.txt +++ b/tests/runtime/common/gc/CMakeLists.txt @@ -50,6 +50,50 @@ function(panda_add_ecma_gc_test) add_dependencies(gc_ecma_common_tests ${TEST_NAME}) endfunction() +function(panda_add_ecma_gc_test_aot) + set(prefix ARG) + set(singleValues FILE) + set(multiValues OPTIONS) + cmake_parse_arguments(${prefix} "" "${singleValues}" "${multiValues}" ${ARGN}) + + get_filename_component(TEST_NAME "${ARG_FILE}" NAME_WE) + get_filename_component(TEST_FILE "${ARG_FILE}" REALPATH) + set(BINARY_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.abc") + + compile_file_ecma(FILE ${TEST_FILE} OPTIONS "--module" OUTPUT_FILE ${BINARY_FILE} WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}) + + set(TEST_AN_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.an") + set(AOT_OPTIONS "--load-runtimes=ecmascript" "${ARG_OPTIONS}" "--paoc-panda-files") + add_custom_target("${TEST_NAME}.an" + COMMAND ${PANDA_RUN_PREFIX} $ + ${AOT_OPTIONS} + ${BINARY_FILE} + "--paoc-output" + ${TEST_AN_FILE} + DEPENDS ${TEST_FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Compiling ${TEST_NAME} test" + DEPENDS ${BINARY_FILE}) + + set(OPTIONS "--load-runtimes=ecmascript" "--compiler-enable-jit=false" "${ARG_OPTIONS}") + + add_custom_target("${TEST_NAME}-aot" + COMMAND ${PANDA_RUN_PREFIX} $ + ${OPTIONS} + "--aot-files" + ${TEST_AN_FILE} + ${BINARY_FILE} + _GLOBAL::func_main_0 + DEPENDS ${TEST_FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Running ${TEST_NAME} test" + DEPENDS "${TEST_NAME}.an" + DEPENDS ${BINARY_FILE}) + + add_dependencies("${TEST_NAME}-aot" gc_common_module) + add_dependencies(gc_ecma_common_tests "${TEST_NAME}-aot") +endfunction() + # Use --gc-trigger-type=debug-never to control GC in the test. # In the test we don't need the runtime triggers GC during allocation. panda_add_ecma_gc_test(FILE startGc.js OPTIONS "--gc-trigger-type=debug-never") @@ -60,3 +104,6 @@ panda_add_ecma_gc_test(FILE hclass_changing_during_concurrent.js OPTIONS "--gc-t panda_add_ecma_gc_test(FILE pinObject.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never") panda_add_ecma_gc_test(FILE copylexenvDynTest.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never" "--gc-use-nth-alloc-trigger=true" "--heap-verifier=fail_on_verification:pre:into:post") panda_add_ecma_gc_test(FILE hclass_collected_before_object.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never" "--g1-track-freed-objects=true") +panda_add_ecma_gc_test(FILE write_prebarrier_primitive_value.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never" "--g1-track-freed-objects=true") +# Running tests in AOT configuration +panda_add_ecma_gc_test_aot(FILE write_prebarrier_primitive_value.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never" "--g1-track-freed-objects=true") diff --git a/tests/runtime/common/gc/write_prebarrier_primitive_value.js b/tests/runtime/common/gc/write_prebarrier_primitive_value.js new file mode 100644 index 000000000..d8778bf3c --- /dev/null +++ b/tests/runtime/common/gc/write_prebarrier_primitive_value.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +/** + * Test verify that write PreBarrier works correctly with primitive value + */ + +let holder = new Object(); +let obj2 = new Array(5).fill('abbcc'); +// assign primitive value to object property +holder.prop = 42; +let gc = startGC("threshold", function(marker) { + // now assign property a reference to heap object + holder.prop = obj2; +}); +waitForFinishGC(gc); \ No newline at end of file -- Gitee