735a73943d
This is a reland of commit 982b9fad44
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:
> * https://github.com/flutter/engine/pull/57158
> * https://github.com/flutter/flutter/pull/160158
> * https://github.com/flutter/flutter/pull/160421
>
> TEST=vm/dart/entrypoints_verification_test vm/cc/IRTest
> vm/cc/StreamingFlowGraphBuilder vm/cc/STC vm/cc/TTS
>
> Issue: https://github.com/dart-lang/sdk/issues/50649
> Issue: https://github.com/flutter/flutter/issues/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 <kustermann@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>
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 <iinozemtsev@google.com>
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
110 lines
3.2 KiB
C++
110 lines
3.2 KiB
C++
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// 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.
|
|
|
|
#include <utility>
|
|
|
|
#include "vm/closure_functions_cache.h"
|
|
#include "vm/compiler/backend/il_test_helper.h"
|
|
#include "vm/compiler/compiler_pass.h"
|
|
#include "vm/object.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
using YieldPoints = ZoneGrowableArray<TokenPosition>;
|
|
|
|
int LowestFirst(const TokenPosition* a, const TokenPosition* b) {
|
|
return a->Pos() - b->Pos();
|
|
}
|
|
|
|
static YieldPoints* GetYieldPointsFromGraph(FlowGraph* flow_graph) {
|
|
auto array = new (flow_graph->zone()) YieldPoints();
|
|
const auto& blocks = flow_graph->reverse_postorder();
|
|
for (auto block : blocks) {
|
|
ForwardInstructionIterator it(block);
|
|
while (!it.Done()) {
|
|
if (auto suspend_instr = it.Current()->AsSuspend()) {
|
|
array->Add(suspend_instr->token_pos());
|
|
}
|
|
it.Advance();
|
|
}
|
|
}
|
|
array->Sort(LowestFirst);
|
|
return array;
|
|
}
|
|
|
|
static YieldPoints* GetYieldPointsFromCode(const Code& code) {
|
|
auto array = new YieldPoints();
|
|
const auto& pc_descriptor = PcDescriptors::Handle(code.pc_descriptors());
|
|
PcDescriptors::Iterator it(pc_descriptor, UntaggedPcDescriptors::kOther);
|
|
while (it.MoveNext()) {
|
|
if (it.YieldIndex() != UntaggedPcDescriptors::kInvalidYieldIndex) {
|
|
array->Add(it.TokenPos());
|
|
}
|
|
}
|
|
array->Sort(LowestFirst);
|
|
return array;
|
|
}
|
|
|
|
void RunTestInMode(CompilerPass::PipelineMode mode) {
|
|
const char* kScript =
|
|
R"(
|
|
import 'dart:async';
|
|
|
|
@pragma("vm:entry-point", "call")
|
|
Future foo() async {
|
|
print('pos-0');
|
|
await 0;
|
|
print('pos-1');
|
|
await 1;
|
|
print('pos-2');
|
|
await 2;
|
|
}
|
|
)";
|
|
|
|
SetupCoreLibrariesForUnitTest();
|
|
|
|
const auto& root_library = Library::Handle(LoadTestScript(kScript));
|
|
// Ensure the outer function was compiled once, ensuring we have a closure
|
|
// function for the inner closure.
|
|
Invoke(root_library, "foo");
|
|
|
|
const auto& function = Function::Handle(GetFunction(root_library, "foo"));
|
|
|
|
// Ensure we have 3 different return instructions with yield indices attached
|
|
// to them.
|
|
TestPipeline pipeline(function, mode);
|
|
FlowGraph* flow_graph = pipeline.RunPasses({
|
|
CompilerPass::kComputeSSA,
|
|
});
|
|
|
|
auto validate_indices = [](const YieldPoints& yield_points) {
|
|
EXPECT_EQ(3, yield_points.length());
|
|
|
|
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));
|
|
|
|
// Ensure we have 3 different yield indices attached to the code via pc
|
|
// descriptors.
|
|
const auto& error = Error::Handle(
|
|
Compiler::EnsureUnoptimizedCode(Thread::Current(), function));
|
|
RELEASE_ASSERT(error.IsNull());
|
|
const auto& code = Code::Handle(function.CurrentCode());
|
|
validate_indices(*GetYieldPointsFromCode(code));
|
|
}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(IRTest_YieldIndexAvailableJIT) {
|
|
RunTestInMode(CompilerPass::kJIT);
|
|
}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(IRTest_YieldIndexAvailableAOT) {
|
|
RunTestInMode(CompilerPass::kAOT);
|
|
}
|
|
|
|
} // namespace dart
|