Prebuild com_sub.m and bc_stub.m

Generate com_stub.m and bc_stub.m in build phase.

Add FATAL log if load stub file failed.

Move run_ark_executable.py to js_runtime/script/ directory

Add --time-out option in run_ark_executable.py.

Signed-off-by: ding <dingding5@huawei.com>
Change-Id: I6136c5f0dc132a086119f9f2cc6eaf934ba0087b
This commit is contained in:
ding 2022-05-09 14:36:24 +08:00
parent 074fee70e4
commit e507c08de0
8 changed files with 73 additions and 57 deletions

View File

@ -47,6 +47,7 @@ group("ark_js_host_linux_tools_packages") {
deps += [
"//ark/js_runtime/ecmascript/compiler:ark_aot_compiler(${host_toolchain})",
"//ark/js_runtime/ecmascript/compiler:ark_stub_compiler(${host_toolchain})",
"//ark/js_runtime/ecmascript/compiler:gen_stub_file(${host_toolchain})",
]
}
}
@ -112,6 +113,7 @@ config("ark_jsruntime_public_config") {
"$ark_root/libpandafile:arkfile_public_config",
"//third_party/icu/icu4c:icu_config",
sdk_libc_secshared_config,
"//ark/js_runtime/ecmascript/compiler:gen_stub_file_dir_config",
]
defines = []

View File

@ -230,3 +230,41 @@ ohos_executable("ark_aot_compiler") {
part_name = "ark_js_runtime"
subsystem_name = "ark"
}
config("gen_stub_file_dir_config") {
stub_file_gen_dir = rebase_path(root_gen_dir) + "/ark/js_runtime"
defines = [ "STUB_FILE_GEN_DIR=\"${stub_file_gen_dir}/\"" ]
}
action("gen_stub_file") {
script = "//ark/js_runtime/script/run_ark_executable.py"
deps = [
"//ark/js_runtime/ecmascript/compiler:ark_stub_compiler(${host_toolchain})",
]
stub_file_gen_dir = "$root_gen_dir/ark/js_runtime"
stub_option = " --com-stub-out=" + rebase_path(stub_file_gen_dir) +
"/com_stub.m --bc-stub-out=" + rebase_path(stub_file_gen_dir) +
"/bc_stub.m"
args = [
"--script-file",
rebase_path(root_out_dir) + "/ark/ark_js_runtime/ark_stub_compiler",
"--script-options",
stub_option,
"--expect-output",
"0",
"--env-path",
rebase_path(root_out_dir) + "/ark/ark:" + rebase_path(root_out_dir) +
"/ark/ark_js_runtime:" + rebase_path(root_out_dir) +
"/thirdparty/icu:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
]
outputs = [
"$stub_file_gen_dir/com_stub.m",
"$stub_file_gen_dir/bc_stub.m",
]
}

View File

@ -199,5 +199,5 @@ int main(const int argc, const char **argv)
bool res = compiler.BuildStubModuleAndSave(tripleString, commonStubFile, bcHandlerFile, optLevel);
COMPILER_LOG(INFO) << "stub compiler run finish, result condition(T/F):" << std::boolalpha << res;
panda::JSNApi::DestroyJSVM(vm);
return 0;
return res ? 0 : -1;
}

View File

@ -566,11 +566,13 @@ private:
R"(enable aot of common stub and bc handler stub. Default: false)"};
PandArg<bool> enableTSAot_ {"enable-ts-aot", false, R"(enable aot. Default: false)"};
PandArg<std::string> comStubFile_ {"com-stub-out",
R"(com_stub.m)",
R"(Path of file includes common stubs module compiled by stub compiler. Default: "com_stub.m")"};
STUB_FILE_GEN_DIR R"(com_stub.m)",
R"(Path of file includes common stubs module compiled by stub compiler. Default: )"
STUB_FILE_GEN_DIR R"(com_stub.m)"};
PandArg<std::string> bcStubFile_ {"bc-stub-out",
R"(bc_stub.m)",
R"(Path of file includes bytecode handler stubs module compiled by stub compiler. Default: "bc_stub.m")"};
STUB_FILE_GEN_DIR R"(bc_stub.m)",
R"(Path of file includes bytecode handler stubs module compiled by stub compiler. Default: )"
STUB_FILE_GEN_DIR R"(bc_stub.m)"};
PandArg<bool> enableForceGc_ {"enable-force-gc", true, R"(enable force gc when allocating object)"};
PandArg<bool> forceFullGc_ {"force-full-gc",
true,

View File

@ -47,6 +47,8 @@ bool AotCodeInfo::DeserializeForStub(JSThread *thread, const std::string &filena
// then MachineCode will support movable, code is saved to MachineCode and stackmap is saved
// to different heap which will be freed when stackmap is parsed by EcmaVM is started.
if (!VerifyFilePath(filename)) {
COMPILER_LOG(FATAL) << "Can not load stub file from default path [ " << filename << " ], "
<< "please execute ark_stub_compiler with options --com-stub-out and --bc-stub-out manually.";
return false;
}
std::ifstream modulefile(filename.c_str(), std::ofstream::binary);

View File

@ -54,13 +54,9 @@ HWTEST_F_L0(EcmaVMTest, CreateEcmaVMInTwoWays)
JSRuntimeOptions options2;
options2.SetEnableArkTools(true);
options2.SetEnableStubAot(true);
options2.SetComStubFile("file1");
options2.SetBcStubFile("file2");
options2.SetEnableForceGC(false);
options2.SetForceFullGC(false);
options2.SetEnableCpuprofiler(true);
options2.SetEnableTsAot(true);
options2.SetArkProperties(ArkProperties::GC_STATS_PRINT);
// A non-production gc strategy. Prohibit stw-gc 10 times.
@ -74,13 +70,9 @@ HWTEST_F_L0(EcmaVMTest, CreateEcmaVMInTwoWays)
EXPECT_TRUE(&options1Out != &options2Out);
EXPECT_TRUE(options1Out.IsEnableArkTools() != options2Out.IsEnableArkTools());
EXPECT_TRUE(options1Out.IsEnableStubAot() != options2Out.IsEnableStubAot());
EXPECT_TRUE(options1Out.GetComStubFile() != options2Out.GetComStubFile());
EXPECT_TRUE(options1Out.GetBcStubFile() != options2Out.GetBcStubFile());
EXPECT_TRUE(options1Out.IsEnableForceGC() != options2Out.IsEnableForceGC());
EXPECT_TRUE(options1Out.IsForceFullGC() != options2Out.IsForceFullGC());
EXPECT_TRUE(options1Out.IsEnableCpuProfiler() != options2Out.IsEnableCpuProfiler());
EXPECT_TRUE(options1Out.EnableTSAot() != options2Out.EnableTSAot());
EXPECT_TRUE(options1Out.GetArkProperties() != options2Out.GetArkProperties());
EcmaVM::Destroy(ecmaVm2);

View File

@ -2,7 +2,7 @@
#coding: utf-8
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Copyright (c) 2021-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
@ -36,6 +36,7 @@ def parse_args():
parser.add_argument('--expect-sub-output', help='expect sub output')
parser.add_argument('--expect-file', help='expect file')
parser.add_argument('--env-path', help='LD_LIBRARY_PATH env')
parser.add_argument('--timeout-limit', help='timeout limit')
args = parser.parse_args()
return args
@ -48,10 +49,15 @@ def judge_output(args):
cmd += input_args.script_options
if input_args.script_args:
cmd += " " + input_args.script_args
if input_args.timeout_limit:
timeout_limit = int(input_args.timeout_limit)
else:
timeout_limit = 60 # units: s
print("timeout limit: ", timeout_limit)
subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env={'LD_LIBRARY_PATH': str(input_args.env_path)})
try:
out, err = subp.communicate(timeout=1200) # units: s
out, err = subp.communicate(timeout=timeout_limit)
except subprocess.TimeoutExpired:
subp.kill()
out, err = subp.communicate()

View File

@ -43,7 +43,7 @@ template("host_unittest_action") {
deps = [ _host_test_target_ ]
script = "//ark/js_runtime/test/run_ark_executable.py"
script = "//ark/js_runtime/script/run_ark_executable.py"
args = [
"--script-file",
@ -56,6 +56,8 @@ template("host_unittest_action") {
"/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) + "/test/test:" +
rebase_path(_root_out_dir_) + "/${_icu_path_}:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
"--timeout-limit",
"1200",
]
inputs = [
@ -120,7 +122,7 @@ template("host_moduletest_action") {
]
deps += _deps_
script = "//ark/js_runtime/test/run_ark_executable.py"
script = "//ark/js_runtime/script/run_ark_executable.py"
js_vm_options = " "
if (defined(invoker.is_set_maxNonmovableSpaceCapacity) &&
@ -182,37 +184,6 @@ template("host_aot_test_action") {
_script_args_ = rebase_path(_test_abc_path_)
_stub_out_path_options_ =
" --com-stub-out=" + rebase_path(target_out_dir) +
"/com_stub.m --bc-stub-out=" + rebase_path(target_out_dir) + "/bc_stub.m"
action("gen${_target_name_}StubAction") {
testonly = true
_host_stub_target_ = "//ark/js_runtime/ecmascript/compiler:ark_stub_compiler(${host_toolchain})"
_root_out_dir_ = get_label_info(_host_stub_target_, "root_out_dir")
deps = [ _host_stub_target_ ]
deps += _deps_
script = "//ark/js_runtime/test/run_ark_executable.py"
args = [
"--script-file",
rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_stub_compiler",
"--script-options",
_stub_out_path_options_,
"--expect-sub-output",
"stub compiler run finish, result condition(T/F):true",
"--env-path",
rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) +
"/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) +
"/${_icu_path_}:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
]
outputs = [ "$target_out_dir/" ]
}
action("${_target_name_}AotCompileAction") {
testonly = true
@ -224,11 +195,11 @@ template("host_aot_test_action") {
]
deps += _deps_
script = "//ark/js_runtime/test/run_ark_executable.py"
script = "//ark/js_runtime/script/run_ark_executable.py"
_aot_compile_options_ =
" --aot-output-file=" + rebase_path(_test_m_path_) +
" --snapshot-output-file=" + rebase_path(_test_snapshot_path_)
_aot_compile_options_ = " --aot-output-file=" + rebase_path(_test_m_path_) +
" --snapshot-output-file=" +
rebase_path(_test_snapshot_path_) + " --asmInter=1"
args = [
"--script-file",
@ -248,7 +219,10 @@ template("host_aot_test_action") {
inputs = [ _test_abc_path_ ]
outputs = [ "$target_out_dir/${_target_name_}/compile_${_target_name_}/" ]
outputs = [
_test_m_path_,
_test_snapshot_path_,
]
}
action("${_target_name_}AotAction") {
@ -257,21 +231,21 @@ template("host_aot_test_action") {
_host_jsvm_target_ =
"//ark/js_runtime/ecmascript/js_vm:ark_js_vm(${host_toolchain})"
_root_out_dir_ = get_label_info(_host_jsvm_target_, "root_out_dir")
deps = [
":${_target_name_}AotCompileAction",
":gen${_target_name_}StubAction",
":gen_${_target_name_}_abc",
"//ark/js_runtime/ecmascript/compiler:gen_stub_file(${host_toolchain})",
_host_jsvm_target_,
]
deps += _deps_
script = "//ark/js_runtime/test/run_ark_executable.py"
script = "//ark/js_runtime/script/run_ark_executable.py"
_aot_run_options_ =
" --aot-output-file=" + rebase_path(_test_m_path_) +
" --snapshot-output-file=" + rebase_path(_test_snapshot_path_) +
" --enable-ts-aot=true" + " --enable-stub-aot=true" + " --asmInter=1" +
_stub_out_path_options_
" --enable-ts-aot=true" + " --enable-stub-aot=true" + " --asmInter=1"
args = [
"--script-file",