[vm/kernel/aot] Exclude vmservice_io from "product" AOT snapshots.

The `@pragma` annotation on `vmservice_io.main` is modified to only mark it as a
root on non-product builds. Since the annotation is evaluated in the constant
transformation, we need to thread a flag through `gen_kernel.dart` indicating
whether the Kernel produced should target a product precompiler.

# Test Plan

Tested locally on Flutter. Unfortunately it's not possible to test the scenario where
`vmservice_io` is not included, since we don't have any "product" bots. Soon the
flag will be introduced into Flutter, and we will have some coverage from there.

Change-Id: I39f12343038fa221aafe5a55241bff4b8d14ec19
Reviewed-on: https://dart-review.googlesource.com/57501
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
Samir Jindel 2018-06-07 20:22:21 +00:00 committed by commit-bot@chromium.org
parent 4596881c9e
commit 23fff58503
12 changed files with 56 additions and 43 deletions

View file

@ -15,7 +15,7 @@ import 'package:kernel/text/ast_to_text.dart'
show globalDebuggingNames, NameSystem;
import 'package:vm/bytecode/gen_bytecode.dart' show isKernelBytecodeEnabled;
import 'package:vm/kernel_front_end.dart'
show compileToKernel, ErrorDetector, ErrorPrinter;
show compileToKernel, ErrorDetector, ErrorPrinter, parseCommandLineDefines;
final ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
..addOption('platform',
@ -93,7 +93,7 @@ Future<int> compile(List<String> arguments) async {
final bool enableConstantEvaluation = options['enable-constant-evaluation'];
final Map<String, String> environmentDefines = {};
if (!_parseDefines(options['define'], environmentDefines)) {
if (!parseCommandLineDefines(options['define'], environmentDefines, _usage)) {
return _badUsageExitCode;
}
@ -179,22 +179,3 @@ Future runBatchModeCompiler() async {
}
});
}
bool _parseDefines(
List<String> dFlags, Map<String, String> environmentDefines) {
for (final String dflag in dFlags) {
final equalsSignIndex = dflag.indexOf('=');
if (equalsSignIndex < 0) {
environmentDefines[dflag] = '';
} else if (equalsSignIndex > 0) {
final key = dflag.substring(0, equalsSignIndex);
final value = dflag.substring(equalsSignIndex + 1);
environmentDefines[key] = value;
} else {
print('The environment constant options must have a key (was: "$dflag")');
print(_usage);
return false;
}
}
return true;
}

View file

@ -29,7 +29,8 @@ import 'package:kernel/target/targets.dart';
import 'package:path/path.dart' as path;
import 'package:usage/uuid/uuid.dart';
import 'package:vm/incremental_compiler.dart' show IncrementalCompiler;
import 'package:vm/kernel_front_end.dart' show compileToKernel;
import 'package:vm/kernel_front_end.dart'
show compileToKernel, parseCommandLineDefines;
ArgParser argParser = new ArgParser(allowTrailingOptions: true)
..addFlag('train',
@ -92,7 +93,10 @@ ArgParser argParser = new ArgParser(allowTrailingOptions: true)
help: 'Normally the output dill is used to specify which dill to '
'initialize from, but it can be overwritten here.',
defaultsTo: null,
hide: true);
hide: true)
..addMultiOption('define',
abbr: 'D',
help: 'The values for the environment constants (e.g. -Dkey=value).');
String usage = '''
Usage: server [options] [input.dart]
@ -292,6 +296,12 @@ class FrontendCompiler implements CompilerInterface {
}
}
final Map<String, String> environmentDefines = {};
if (!parseCommandLineDefines(
options['define'], environmentDefines, usage)) {
return false;
}
final TargetFlags targetFlags = new TargetFlags(
strongMode: options['strong'], syncAsync: options['sync-async']);
compilerOptions.target = getTarget(options['target'], targetFlags);
@ -322,7 +332,8 @@ class FrontendCompiler implements CompilerInterface {
_mainSource, compilerOptions,
aot: options['aot'],
useGlobalTypeFlowAnalysis: options['tfa'],
entryPoints: options['entry-points']));
entryPoints: options['entry-points'],
environmentDefines: environmentDefines));
}
if (component != null) {
if (transformer != null) {

View file

@ -330,3 +330,22 @@ class ForwardConstantEvaluationErrors implements constants.ErrorReporter {
return node == null ? TreeNode.noOffset : node.fileOffset;
}
}
bool parseCommandLineDefines(
List<String> dFlags, Map<String, String> environmentDefines, String usage) {
for (final String dflag in dFlags) {
final equalsSignIndex = dflag.indexOf('=');
if (equalsSignIndex < 0) {
environmentDefines[dflag] = '';
} else if (equalsSignIndex > 0) {
final key = dflag.substring(0, equalsSignIndex);
final value = dflag.substring(equalsSignIndex + 1);
environmentDefines[key] = value;
} else {
print('The environment constant options must have a key (was: "$dflag")');
print(usage);
return false;
}
}
return true;
}

View file

@ -37,6 +37,8 @@
#include "bin/gzip.h"
#endif
#include "vm/flags.h"
extern "C" {
extern const uint8_t kDartVmSnapshotData[];
extern const uint8_t kDartVmSnapshotInstructions[];
@ -291,10 +293,12 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
result = DartUtils::PrepareForScriptLoading(false, Options::trace_loading());
CHECK_RESULT(result);
// Set up the load port provided by the service isolate so that we can
// load scripts.
result = DartUtils::SetupServiceLoadPort();
CHECK_RESULT(result);
if (FLAG_support_service || !kDartPrecompiledRuntime) {
// Set up the load port provided by the service isolate so that we can
// load scripts.
result = DartUtils::SetupServiceLoadPort();
CHECK_RESULT(result);
}
// Setup package root if specified.
result = DartUtils::SetupPackageRoot(package_root, packages_config);

View file

@ -220,7 +220,7 @@ _registerSignalHandler() {
_signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal);
}
@pragma("vm.entry_point")
@pragma("vm.entry_point", !const bool.fromEnvironment("dart.vm.product"))
main() {
// Set embedder hooks.
VMServiceEmbedderHooks.cleanup = cleanupCallback;

View file

@ -342,7 +342,6 @@ void Precompiler::DoCompileAll(
I->object_store()->set_future_class(null_class);
I->object_store()->set_pragma_class(null_class);
I->object_store()->set_completer_class(null_class);
I->object_store()->set_stream_iterator_class(null_class);
I->object_store()->set_symbol_class(null_class);
I->object_store()->set_compiletime_error_class(null_class);
I->object_store()->set_simple_instance_of_function(null_function);

View file

@ -307,15 +307,11 @@ char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot,
Service::SetGetServiceAssetsCallback(get_service_assets);
}
#if defined(DART_PRECOMPILED_RUNTIME)
const bool is_precompiled_runtime = true;
#else
const bool is_precompiled_runtime = false;
#endif
const bool is_dart2_aot_precompiler =
FLAG_strong && FLAG_precompiled_mode && !is_precompiled_runtime;
if (!is_dart2_aot_precompiler) {
FLAG_strong && FLAG_precompiled_mode && !kDartPrecompiledRuntime;
if (!is_dart2_aot_precompiler &&
(FLAG_support_service || !kDartPrecompiledRuntime)) {
ServiceIsolate::Run();
}

View file

@ -26,6 +26,12 @@
#define USING_PRODUCT false
#endif
#if defined(DART_PRECOMPILED_RUNTIME)
constexpr bool kDartPrecompiledRuntime = true;
#else
constexpr bool kDartPrecompiledRuntime = false;
#endif
// List of all flags in the VM.
// Flags can be one of three categories:
// * P roduct flags: Can be set in any of the deployment modes, including in

View file

@ -149,9 +149,6 @@ void ObjectStore::InitKnownObjects() {
cls = async_lib.LookupClass(Symbols::Completer());
ASSERT(!cls.IsNull());
set_completer_class(cls);
cls = async_lib.LookupClass(Symbols::StreamIterator());
ASSERT(!cls.IsNull());
set_stream_iterator_class(cls);
String& function_name = String::Handle(zone);
Function& function = Function::Handle(zone);

View file

@ -58,7 +58,6 @@ class ObjectPointerVisitor;
RW(Class, pragma_class) \
RW(Class, future_class) \
RW(Class, completer_class) \
RW(Class, stream_iterator_class) \
RW(Class, symbol_class) \
RW(Class, one_byte_string_class) \
RW(Class, two_byte_string_class) \

View file

@ -9290,7 +9290,7 @@ AstNode* Parser::ParseAwaitForStatement(String* label_name) {
// Build creation of implicit StreamIterator.
// var :for-in-iter = new StreamIterator(stream_expr).
const Class& stream_iterator_cls =
Class::ZoneHandle(Z, I->object_store()->stream_iterator_class());
Class::ZoneHandle(Z, async_lib.LookupClass(Symbols::StreamIterator()));
ASSERT(!stream_iterator_cls.IsNull());
const Function& iterator_ctor = Function::ZoneHandle(
Z,

View file

@ -248,6 +248,7 @@ const Object proxy = const _Proxy();
* function foo is annotated with a pragma 'other-pragma' specific to OtherTool.
*
*/
@pragma('vm.entry_point')
class pragma {
/**
* The name of the hint.