Skip to content

Commit

Permalink
Reland "[vm] Turn on entry point checking in JIT mode."
Browse files Browse the repository at this point in the history
This is a reland of commit 982b9fa

Original change's description:
> [vm] Turn on entry point checking in JIT mode.
>
> Now that Flutter tests that access entry points from native code
> have been annotated[1], we can turn on entry point checking in JIT
> mode.
>
> This CL also removes the A flag category from flag_list.h and the
> AOT_FLAG_MACRO definitions and uses from flags.[cc,h], as they were
> created as a temporary measure until this flag could be unconditionally
> defaulted to true.
>
> [1] See the following PRs:
> * flutter/engine#57158
> * flutter/flutter#160158
> * flutter/flutter#160421
>
> TEST=vm/dart/entrypoints_verification_test vm/cc/IRTest
>      vm/cc/StreamingFlowGraphBuilder vm/cc/STC vm/cc/TTS
>
> Issue: #50649
> Issue: flutter/flutter#118608
>
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-appjit-linux-product-x64-try
> Change-Id: Ibe5b21bb74f1a6fb88824b71ff87b9e555216dbf
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400301
> Reviewed-by: Martin Kustermann <[email protected]>
> Commit-Queue: Tess Strickland <[email protected]>

TEST=vm/dart/entrypoints_verification_test vm/cc/IRTest
     vm/cc/StreamingFlowGraphBuilder vm/cc/STC vm/cc/TTS

Change-Id: Ibd5f362f908b4aaa68cda870a387c081537bbc16
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-appjit-linux-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403360
Auto-Submit: Ivan Inozemtsev <[email protected]>
Commit-Queue: Ivan Inozemtsev <[email protected]>
Reviewed-by: Martin Kustermann <[email protected]>
  • Loading branch information
iinozemtsev authored and Commit Queue committed Jan 8, 2025
1 parent 7ec45fa commit 735a739
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 36 deletions.
1 change: 0 additions & 1 deletion runtime/tests/vm/dart/entrypoints_verification_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// VMOptions=--verify-entry-points=true
// SharedObjects=entrypoints_verification_test

import 'dart:ffi';
Expand Down
5 changes: 5 additions & 0 deletions runtime/vm/compiler/backend/il_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_EliminateWriteBarrier) {
Container<int> x = Container<int>();
@pragma("vm:entry-point", "call")
foo() {
for (int i = 0; i < 10; ++i) {
x[i] = i;
Expand Down Expand Up @@ -689,6 +690,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_LoadThread) {
auto kScript = R"(
import 'dart:ffi';
@pragma("vm:entry-point", "call")
int myFunction() {
return 100;
}
Expand Down Expand Up @@ -780,6 +782,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_CachableIdempotentCall) {
return increment();
}
@pragma("vm:entry-point", "call")
int multipleIncrement() {
int returnValue = 0;
for(int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -943,6 +946,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_FfiCallInstrLeafDoesntSpill) {
void placeholder() {}
// Will call the "doFfiCall" and exercise its code.
@pragma("vm:entry-point", "call")
bool invokeDoFfiCall() {
final double result = doFfiCall(1, 2, 3, 1.0, 2.0, 3.0);
if (result != (2 + 3 + 4 + 2.0 + 3.0 + 4.0)) {
Expand Down Expand Up @@ -971,6 +975,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_FfiCallInstrLeafDoesntSpill) {
typedef NT = Void Function();
typedef DT = void Function();
Pointer<NativeFunction<NT>> ptr = Pointer.fromAddress(0);
@pragma("vm:entry-point", "call")
DT getFfiTrampolineClosure() => ptr.asFunction(isLeaf:true);
)";

Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/compiler/backend/memory_copy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,14 @@ static void RunMemoryCopyInstrTest(intptr_t src_start,
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
import 'dart:ffi';
@pragma("vm:entry-point", "call")
void copyConst() {
final pointer = Pointer<Uint8>.fromAddress(%s%p);
final pointer2 = Pointer<Uint8>.fromAddress(%s%p);
noop();
}
@pragma("vm:entry-point", "call")
void callNonConstCopy() {
final pointer = Pointer<Uint8>.fromAddress(%s%p);
final pointer2 = Pointer<Uint8>.fromAddress(%s%p);
Expand Down
3 changes: 3 additions & 0 deletions runtime/vm/compiler/backend/redundancy_elimination_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ ISOLATE_UNIT_TEST_CASE(DelayAllocations_DelayAcrossCalls) {
@pragma("vm:never-inline")
dynamic use(v) {}
@pragma("vm:entry-point", "call")
void test() {
A a = new A(foo(1), foo(2));
use(a);
Expand Down Expand Up @@ -1738,10 +1739,12 @@ ISOLATE_UNIT_TEST_CASE(AllocationSinking_NoViewDataMaterialization) {
return x is int;
}
@pragma("vm:entry-point", "call")
bool %s() {
return %s(0xABCC);
}
@pragma("vm:entry-point", "call")
bool %s() {
return %s(1.0);
}
Expand Down
7 changes: 4 additions & 3 deletions runtime/vm/compiler/backend/yield_position_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void RunTestInMode(CompilerPass::PipelineMode mode) {
R"(
import 'dart:async';
@pragma("vm:entry-point", "call")
Future foo() async {
print('pos-0');
await 0;
Expand Down Expand Up @@ -81,9 +82,9 @@ void RunTestInMode(CompilerPass::PipelineMode mode) {
auto validate_indices = [](const YieldPoints& yield_points) {
EXPECT_EQ(3, yield_points.length());

EXPECT_EQ(88, yield_points[0].Pos());
EXPECT_EQ(129, yield_points[1].Pos());
EXPECT_EQ(170, yield_points[2].Pos());
EXPECT_EQ(128, yield_points[0].Pos());
EXPECT_EQ(169, yield_points[1].Pos());
EXPECT_EQ(210, yield_points[2].Pos());
};

validate_indices(*GetYieldPointsFromGraph(flow_graph));
Expand Down
4 changes: 4 additions & 0 deletions runtime/vm/compiler/frontend/kernel_binary_flowgraph_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ISOLATE_UNIT_TEST_CASE(StreamingFlowGraphBuilder_ConstFoldStringConcats) {
// "Adjacent strings are implicitly concatenated to form a single string
// literal."
const char* kScript = R"(
@pragma("vm:entry-point", "call")
test() {
var s = 'aaaa'
'bbbb'
Expand Down Expand Up @@ -252,6 +253,7 @@ ISOLATE_UNIT_TEST_CASE(StreamingFlowGraphBuilder_ConcatStringLits) {

ISOLATE_UNIT_TEST_CASE(StreamingFlowGraphBuilder_InvariantFlagInListLiterals) {
const char* kScript = R"(
@pragma("vm:entry-point", "call")
test() {
return [...[], 42];
}
Expand Down Expand Up @@ -314,6 +316,7 @@ ISOLATE_UNIT_TEST_CASE(StreamingFlowGraphBuilder_TypedClosureCall) {
//
const char* kScript = R"(
int callClosure(int Function(int) fun, int value) => fun(value);
@pragma("vm:entry-point", "call")
test() => callClosure((int a) => a + 1, 10);
)";

Expand Down Expand Up @@ -354,6 +357,7 @@ ISOLATE_UNIT_TEST_CASE(
StreamingFlowGraphBuilder_StaticGetFinalFieldWithTrivialInitializer) {
const char* kScript = R"(
final int x = 0xFEEDFEED;
@pragma("vm:entry-point", "call")
test() {
return x;
}
Expand Down
7 changes: 2 additions & 5 deletions runtime/vm/flag_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,15 @@ constexpr bool FLAG_support_il_printer = false;
// * R elease flags: Generally available flags except when building product.
// * pre C ompile flags: Generally available flags except when building product
// or precompiled runtime.
// * A ot flags: Generally available flags except when building precompiled
// runtime. (Unlike C, these flags are available in product mode.)
// * D ebug flags: Can only be set in debug VMs, which also have C++ assertions
// enabled.
//
// Usage:
// P(name, type, default_value, comment)
// R(name, product_value, type, default_value, comment)
// C(name, precompiled_value, product_value, type, default_value, comment)
// A(name, precompiled_value, type, default_value, comment)
// D(name, type, default_value, comment)
#define FLAG_LIST(P, R, C, A, D) \
#define FLAG_LIST(P, R, C, D) \
VM_GLOBAL_FLAG_LIST(P, R, C, D) \
DISASSEMBLE_FLAGS(P, R, C, D) \
P(abort_on_oom, bool, false, \
Expand Down Expand Up @@ -249,7 +246,7 @@ constexpr bool FLAG_support_il_printer = false;
R(eliminate_type_checks, true, bool, true, \
"Eliminate type checks when allowed by static type analysis.") \
D(support_rr, bool, false, "Support running within RR.") \
A(verify_entry_points, true, bool, false, \
P(verify_entry_points, bool, true, \
"Throw API error on invalid member access through native API. See " \
"entry_point_pragma.md") \
C(branch_coverage, false, false, bool, false, "Enable branch coverage") \
Expand Down
12 changes: 0 additions & 12 deletions runtime/vm/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ DEFINE_FLAG(bool,
// Nothing to be done for the precompilation flag definitions.
#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
default_value, comment)
// Nothing to be done for the AOT flag definitions.
#define AOT_FLAG_MACRO(name, pre_value, type, default_value, comment)

#elif defined(PRODUCT) // !PRECOMPILED
// Nothing to be done for the product flag definitions.
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment)
// Nothing to be done for the precompilation flag definitions.
#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
default_value, comment)
#define AOT_FLAG_MACRO(name, pre_value, type, default_value, comment) \
type FLAG_##name = \
Flags::Register_##type(&FLAG_##name, #name, default_value, comment);

#elif defined(DART_PRECOMPILED_RUNTIME) // !PRODUCT
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
Expand All @@ -55,8 +50,6 @@ DEFINE_FLAG(bool,
// Nothing to be done for the precompilation flag definitions.
#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
default_value, comment)
// Nothing to be done for the AOT flag definitions.
#define AOT_FLAG_MACRO(name, pre_value, type, default_value, comment)

#else // !PRODUCT && !PRECOMPILED
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
Expand All @@ -66,22 +59,17 @@ DEFINE_FLAG(bool,
default_value, comment) \
type FLAG_##name = \
Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
#define AOT_FLAG_MACRO(name, pre_value, type, default_value, comment) \
type FLAG_##name = \
Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
#endif

// Define all of the non-product flags here.
FLAG_LIST(PRODUCT_FLAG_MACRO,
RELEASE_FLAG_MACRO,
PRECOMPILE_FLAG_MACRO,
AOT_FLAG_MACRO,
DEBUG_FLAG_MACRO)

#undef PRODUCT_FLAG_MACRO
#undef RELEASE_FLAG_MACRO
#undef PRECOMPILE_FLAG_MACRO
#undef AOT_FLAG_MACRO
#undef DEBUG_FLAG_MACRO

#if defined(DART_PRECOMPILER)
Expand Down
10 changes: 0 additions & 10 deletions runtime/vm/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,49 +124,39 @@ class Flags {
#define PRECOMPILE_FLAG_MACRO(name, precompiled_value, product_value, type, \
default_value, comment) \
const type FLAG_##name = precompiled_value;
#define AOT_FLAG_MACRO(name, precompiled_value, type, default_value, comment) \
const type FLAG_##name = precompiled_value;

#elif defined(PRODUCT) // !PRECOMPILED
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
const type FLAG_##name = product_value;
#define PRECOMPILE_FLAG_MACRO(name, precompiled_value, product_value, type, \
default_value, comment) \
const type FLAG_##name = product_value;
#define AOT_FLAG_MACRO(name, precompiled_value, type, default_value, comment) \
extern type FLAG_##name;

#elif defined(DART_PRECOMPILED_RUNTIME) // !PRODUCT
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
extern type FLAG_##name;
#define PRECOMPILE_FLAG_MACRO(name, precompiled_value, product_value, type, \
default_value, comment) \
const type FLAG_##name = precompiled_value;
#define AOT_FLAG_MACRO(name, precompiled_value, type, default_value, comment) \
const type FLAG_##name = precompiled_value;

#else // !PRODUCT && !PRECOMPILED
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
extern type FLAG_##name;
#define PRECOMPILE_FLAG_MACRO(name, precompiled_value, product_value, type, \
default_value, comment) \
extern type FLAG_##name;
#define AOT_FLAG_MACRO(name, precompiled_value, type, default_value, comment) \
extern type FLAG_##name;

#endif

// Now declare all flags here.
FLAG_LIST(PRODUCT_FLAG_MACRO,
RELEASE_FLAG_MACRO,
PRECOMPILE_FLAG_MACRO,
AOT_FLAG_MACRO,
DEBUG_FLAG_MACRO)

#undef RELEASE_FLAG_MACRO
#undef DEBUG_FLAG_MACRO
#undef PRODUCT_FLAG_MACRO
#undef AOT_FLAG_MACRO
#undef PRECOMPILE_FLAG_MACRO

#if defined(DART_PRECOMPILER)
Expand Down
14 changes: 11 additions & 3 deletions runtime/vm/object_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8436,15 +8436,23 @@ static void SubtypeTestCacheTest(Thread* thread,
intptr_t num_classes,
bool expect_hash) {
TextBuffer buffer(MB);
buffer.AddString("class D {}\n");
buffer.AddString("D createInstanceD() => D();");
buffer.AddString("D Function() createClosureD() => () => D();\n");
buffer.AddString(R"(
class D {}
@pragma('vm:entry-point', 'call')
D createInstanceD() => D();
@pragma('vm:entry-point', 'call')
D Function() createClosureD() => () => D();
)");
for (intptr_t i = 0; i < num_classes; i++) {
buffer.Printf(R"(class C%)" Pd R"( extends D {}
)"
"@pragma('vm:entry-point', 'call')\n"
R"(C%)" Pd R"( createInstanceC%)" Pd R"(() => C%)" Pd
R"(();
)"
"@pragma('vm:entry-point', 'call')\n"
R"(C%)" Pd R"( Function() createClosureC%)" Pd
R"(() => () => C%)" Pd
R"(();
Expand Down
Loading

0 comments on commit 735a739

Please sign in to comment.