Skip to content

Commit 4aa820b

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
Reland "[vm/bytecode] Switch kernel service dill to bytecode if building Dart SDK with --bytecode"
This is a reland of https://dart-review.googlesource.com/c/sdk/+/113123 after stack overflow in the interpreter was fixed in https://dart-review.googlesource.com/c/sdk/+/117061 Original change's description: Temporary setting of FLAG_enable_interpreter is avoided in the VM unit tests as this flag is global and used by kernel service isolate while running tests. Flipping this flag causes assertion failures in kernel isolate's background compiler or infinite loop between LazyCompile stub and CompileFunction as AttachBytecode doesn't set entry point to InterpretCall. The less intrusive way to ensure compilation of functions in unit tests is to set FLAG_compilation_counter_threshold to 0. Change-Id: Ibbcf4b5bb0df558851c80cfa40a9a54f949dd187 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117122 Reviewed-by: Régis Crelier <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent f20f619 commit 4aa820b

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

runtime/vm/compiler/backend/il_test_helper.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ RawFunction* GetFunction(const Library& lib, const char* name) {
4646

4747
void Invoke(const Library& lib, const char* name) {
4848
// These tests rely on running unoptimized code to collect type feedback. The
49-
// interpreter does not collect type feedback for interface calls.
50-
SetFlagScope<bool> sfs(&FLAG_enable_interpreter, false);
49+
// interpreter does not collect type feedback for interface calls, so set
50+
// compilation threshold to 0 in order to compile invoked function
51+
// immediately and execute compiled code.
52+
SetFlagScope<int> sfs(&FLAG_compilation_counter_threshold, 0);
5153

5254
Thread* thread = Thread::Current();
5355
Dart_Handle api_lib = Api::NewHandle(thread, lib.raw());

runtime/vm/compiler/jit/compiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ DEFINE_RUNTIME_ENTRY(CompileFunction, 1) {
230230
Exceptions::PropagateError(Error::Cast(result));
231231
}
232232
}
233-
if (function.HasBytecode()) {
233+
if (function.HasBytecode() && (FLAG_compilation_counter_threshold != 0)) {
234234
// If interpreter is enabled and there is bytecode, LazyCompile stub
235235
// (which calls CompileFunction) should proceed to InterpretCall in order
236236
// to enter interpreter. In such case, compilation is postponed and
237237
// triggered by interpreter later via CompileInterpretedFunction.
238238
return;
239239
}
240-
// No bytecode, fall back to compilation.
240+
// Fall back to compilation.
241241
} else {
242242
ASSERT(!function.HasCode());
243243
}

runtime/vm/dart_entry.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ RawObject* DartEntry::InvokeFunction(const Function& function,
152152
}
153153

154154
// If we have bytecode but no native code then invoke the interpreter.
155-
if (function.HasBytecode()) {
155+
if (function.HasBytecode() && (FLAG_compilation_counter_threshold != 0)) {
156156
ASSERT(thread->no_callback_scope_depth() == 0);
157157
SuspendLongJumpScope suspend_long_jump_scope(thread);
158158
TransitionToGenerated transition(thread);
159159
return Interpreter::Current()->Call(function, arguments_descriptor,
160160
arguments, thread);
161161
}
162162

163-
// No bytecode, fall back to compilation.
163+
// Fall back to compilation.
164164
}
165165

166166
const Object& result =

runtime/vm/profiler_test.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ ISOLATE_UNIT_TEST_CASE(Profiler_FunctionInline) {
14131413
DisableNativeProfileScope dnps;
14141414
DisableBackgroundCompilationScope dbcs;
14151415
SetFlagScope<int> sfs(&FLAG_optimization_counter_threshold, 30000);
1416-
SetFlagScope<bool> sfs2(&FLAG_enable_interpreter, false);
1416+
SetFlagScope<int> sfs2(&FLAG_compilation_counter_threshold, 0);
14171417

14181418
const char* kScript =
14191419
"class A {\n"
@@ -1532,7 +1532,7 @@ ISOLATE_UNIT_TEST_CASE(Profiler_InliningIntervalBoundry) {
15321532
DisableNativeProfileScope dnps;
15331533
DisableBackgroundCompilationScope dbcs;
15341534
SetFlagScope<int> sfs(&FLAG_optimization_counter_threshold, 30000);
1535-
SetFlagScope<bool> sfs2(&FLAG_enable_interpreter, false);
1535+
SetFlagScope<int> sfs2(&FLAG_compilation_counter_threshold, 0);
15361536

15371537
const char* kScript =
15381538
"class A {\n"
@@ -1850,8 +1850,8 @@ ISOLATE_UNIT_TEST_CASE(Profiler_BasicSourcePositionOptimized) {
18501850
DisableNativeProfileScope dnps;
18511851
DisableBackgroundCompilationScope dbcs;
18521852
// Optimize quickly.
1853-
SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5);
1854-
SetFlagScope<bool> sfs3(&FLAG_enable_interpreter, false);
1853+
SetFlagScope<int> sfs(&FLAG_optimization_counter_threshold, 5);
1854+
SetFlagScope<int> sfs2(&FLAG_compilation_counter_threshold, 0);
18551855
const char* kScript =
18561856
"class A {\n"
18571857
" var a;\n"
@@ -2020,8 +2020,8 @@ ISOLATE_UNIT_TEST_CASE(Profiler_SourcePositionOptimized) {
20202020
DisableNativeProfileScope dnps;
20212021
DisableBackgroundCompilationScope dbcs;
20222022
// Optimize quickly.
2023-
SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5);
2024-
SetFlagScope<bool> sfs3(&FLAG_enable_interpreter, false);
2023+
SetFlagScope<int> sfs(&FLAG_optimization_counter_threshold, 5);
2024+
SetFlagScope<int> sfs2(&FLAG_compilation_counter_threshold, 0);
20252025

20262026
const char* kScript =
20272027
"class A {\n"
@@ -2225,8 +2225,8 @@ ISOLATE_UNIT_TEST_CASE(Profiler_BinaryOperatorSourcePositionOptimized) {
22252225
DisableNativeProfileScope dnps;
22262226
DisableBackgroundCompilationScope dbcs;
22272227
// Optimize quickly.
2228-
SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5);
2229-
SetFlagScope<bool> sfs3(&FLAG_enable_interpreter, false);
2228+
SetFlagScope<int> sfs(&FLAG_optimization_counter_threshold, 5);
2229+
SetFlagScope<int> sfs2(&FLAG_compilation_counter_threshold, 0);
22302230

22312231
const char* kScript =
22322232
"class A {\n"
@@ -2300,11 +2300,9 @@ ISOLATE_UNIT_TEST_CASE(Profiler_BinaryOperatorSourcePositionOptimized) {
23002300
ProfileStackWalker walker(&profile, true);
23012301

23022302
EXPECT_STREQ("DRT_AllocateObject", walker.VMTagName());
2303-
if (!FLAG_enable_interpreter) {
2304-
EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName());
2305-
EXPECT_EQ(1, walker.CurrentExclusiveTicks());
2306-
EXPECT(walker.Down());
2307-
}
2303+
EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName());
2304+
EXPECT_EQ(1, walker.CurrentExclusiveTicks());
2305+
EXPECT(walker.Down());
23082306
EXPECT_STREQ("B.boo", walker.CurrentName());
23092307
EXPECT_EQ(1, walker.CurrentInclusiveTicks());
23102308
EXPECT_STREQ("A", walker.CurrentToken());

utils/kernel-service/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ template("kernel_service_dill") {
104104
"--output=" + rebase_path(output),
105105
rebase_path(kernel_service_script),
106106
]
107+
108+
if (dart_platform_bytecode) {
109+
args += [
110+
"--gen-bytecode",
111+
"--drop-ast",
112+
]
113+
}
107114
}
108115
}
109116

0 commit comments

Comments
 (0)