[VM] When --preview-dart-2 option is specified make the options

'--snapshot_kind=script --snapshot=xyz'
produce a kernel dill file which is the equivalent of a script
snapshot in Dart2 world.

Change-Id: I7ba66eb86d9ecdfe1426b8b22b8d673598c4b71f
Reviewed-on: https://dart-review.googlesource.com/52740
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
asiva 2018-05-02 23:19:47 +00:00 committed by commit-bot@chromium.org
parent 384a59595c
commit 4b1180a39d
10 changed files with 89 additions and 47 deletions

View file

@ -33,6 +33,10 @@ intptr_t kPlatformStrongDillSize = 0;
namespace dart {
namespace bin {
#if !defined(DART_PRECOMPILED_RUNTIME)
DFE dfe;
#endif
#if defined(DART_NO_SNAPSHOT) || defined(DART_PRECOMPILER)
const uint8_t* kernel_service_dill = NULL;
const intptr_t kernel_service_dill_size = 0;
@ -213,11 +217,10 @@ class WindowsPathSanitizer {
DISALLOW_COPY_AND_ASSIGN(WindowsPathSanitizer);
};
void* DFE::CompileAndReadScript(const char* script_uri,
char** error,
int* exit_code,
bool strong,
const char* package_config) {
Dart_KernelCompilationResult DFE::CompileScript(const char* script_uri,
bool strong,
bool incremental,
const char* package_config) {
// TODO(aam): When Frontend is ready, VM should be passing vm_outline.dill
// instead of vm_platform.dill to Frontend for compilation.
#if defined(HOST_OS_WINDOWS)
@ -231,8 +234,18 @@ void* DFE::CompileAndReadScript(const char* script_uri,
strong ? platform_strong_dill : platform_dill;
intptr_t platform_binary_size =
strong ? platform_strong_dill_size : platform_dill_size;
Dart_KernelCompilationResult result = Dart_CompileToKernel(
sanitized_uri, platform_binary, platform_binary_size, package_config);
return Dart_CompileToKernel(sanitized_uri, platform_binary,
platform_binary_size, incremental,
package_config);
}
void* DFE::CompileAndReadScript(const char* script_uri,
char** error,
int* exit_code,
bool strong,
const char* package_config) {
Dart_KernelCompilationResult result =
CompileScript(script_uri, strong, true, package_config);
switch (result.status) {
case Dart_KernelCompilationStatus_Ok:
return Dart_ReadKernelBinary(result.kernel, result.kernel_size,

View file

@ -45,7 +45,14 @@ class DFE {
}
void* application_kernel_binary() const { return application_kernel_binary_; }
// Compiles a script and reads the resulting kernel file.
// Compiles specified script.
// Returns result from compiling the script.
Dart_KernelCompilationResult CompileScript(const char* script_uri,
bool strong,
bool incremental,
const char* package_config);
// Compiles specified script and reads the resulting kernel file.
// If the compilation is successful, returns a valid in memory kernel
// representation of the script, NULL otherwise
// 'error' and 'exit_code' have the error values in case of errors.
@ -95,6 +102,10 @@ class DFE {
DISALLOW_COPY_AND_ASSIGN(DFE);
};
#if !defined(DART_PRECOMPILED_RUNTIME)
extern DFE dfe;
#endif
} // namespace bin
} // namespace dart

View file

@ -36,8 +36,6 @@
namespace dart {
namespace bin {
DFE dfe;
// Exit code indicating an API error.
static const int kApiErrorExitCode = 253;
// Exit code indicating a compilation error.

View file

@ -80,10 +80,6 @@ const uint8_t* core_isolate_snapshot_instructions =
* dart <app_snapshot_filename> [<script_options>]
*/
static bool vm_run_app_snapshot = false;
#if !defined(DART_PRECOMPILED_RUNTIME)
DFE dfe;
#endif
static char* app_script_uri = NULL;
static const uint8_t* app_isolate_snapshot_data = NULL;
static const uint8_t* app_isolate_snapshot_instructions = NULL;
@ -261,7 +257,7 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
CHECK_RESULT(result);
#if !defined(DART_PRECOMPILED_RUNTIME)
if (dfe.UseDartFrontend() && !isolate_run_app_snapshot &&
if (Options::preview_dart_2() && !isolate_run_app_snapshot &&
kernel_program == NULL && !Dart_IsKernelIsolate(isolate)) {
if (!dfe.CanUseDartFrontend()) {
const char* format = "Dart frontend unavailable to compile script %s.";
@ -467,7 +463,7 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
ASSERT(flags != NULL);
flags->load_vmservice_library = true;
if (dfe.UseDartFrontend()) {
if (Options::preview_dart_2()) {
// If there is intention to use DFE, then we create the isolate
// from kernel only if we can.
void* platform_program = dfe.platform_program(flags->strong) != NULL
@ -580,7 +576,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
Dart_Isolate isolate = NULL;
#if !defined(DART_PRECOMPILED_RUNTIME)
if (dfe.UseDartFrontend()) {
if (Options::preview_dart_2()) {
void* platform_program = dfe.platform_program(flags->strong) != NULL
? dfe.platform_program(flags->strong)
: kernel_program;
@ -882,7 +878,12 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
// the core snapshot.
Platform::Exit(kErrorExitCode);
}
Snapshot::GenerateScript(Options::snapshot_filename());
if (Options::preview_dart_2()) {
Snapshot::GenerateKernel(Options::snapshot_filename(), script_name,
flags.strong, Options::packages_file());
} else {
Snapshot::GenerateScript(Options::snapshot_filename());
}
} else {
// Lookup the library of the root script.
Dart_Handle root_lib = Dart_RootLibrary();
@ -1161,9 +1162,9 @@ void main(int argc, char** argv) {
if (application_kernel_binary != NULL) {
// Since we loaded the script anyway, save it.
dfe.set_application_kernel_binary(application_kernel_binary);
// Since we saw a dill file, it means we have to use DFE for
// any further source file parsing.
dfe.set_use_dfe();
// Since we saw a dill file, it means we have to turn on all the
// preview_dart_2 options.
Options::SetPreviewDart2Options(&vm_options);
}
#endif

View file

@ -63,20 +63,19 @@ ENUM_OPTIONS_LIST(ENUM_OPTION_DEFINITION)
CB_OPTIONS_LIST(CB_OPTION_DEFINITION)
#undef CB_OPTION_DEFINITION
static bool checked_set = false;
static bool preview_dart_2_set = false;
static void SetPreviewDart2Options(CommandLineOptions* vm_options) {
void Options::SetPreviewDart2Options(CommandLineOptions* vm_options) {
#if !defined(DART_PRECOMPILED_RUNTIME)
Options::dfe()->set_use_dfe();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
preview_dart_2_set = true;
OPTION_FIELD(preview_dart_2) = true;
vm_options->AddArgument("--strong");
vm_options->AddArgument("--reify-generic-functions");
vm_options->AddArgument("--limit-ints-to-64-bits");
}
DEFINE_BOOL_OPTION_CB(preview_dart_2, { SetPreviewDart2Options(vm_options); });
bool OPTION_FIELD(preview_dart_2) = false;
DEFINE_BOOL_OPTION_CB(preview_dart_2,
{ Options::SetPreviewDart2Options(vm_options); });
#if !defined(DART_PRECOMPILED_RUNTIME)
DFE* Options::dfe_ = NULL;
@ -326,6 +325,8 @@ bool Options::ProcessObserveOption(const char* arg,
return true;
}
static bool checked_set = false;
int Options::ParseArguments(int argc,
char** argv,
bool vm_run_app_snapshot,
@ -457,7 +458,7 @@ int Options::ParseArguments(int argc,
" run using a snapshot is invalid.\n");
return -1;
}
if (checked_set && preview_dart_2_set) {
if (checked_set && Options::preview_dart_2()) {
Log::PrintErr("Flags --checked and --preview-dart-2 are not compatible.\n");
return -1;
}

View file

@ -107,6 +107,9 @@ class Options {
CB_OPTIONS_LIST(CB_OPTIONS_DECL)
#undef CB_OPTIONS_DECL
static bool preview_dart_2() { return preview_dart_2_; }
static void SetPreviewDart2Options(CommandLineOptions* vm_options);
static dart::HashMap* environment() { return environment_; }
static const char* vm_service_server_ip() { return vm_service_server_ip_; }
@ -123,34 +126,24 @@ class Options {
static void DestroyEnvironment();
private:
#define STRING_OPTION_DECL(flag, variable) \
static const char* variable##_; \
static bool Process_##variable(const char* arg, \
CommandLineOptions* vm_options);
#define STRING_OPTION_DECL(flag, variable) static const char* variable##_;
STRING_OPTIONS_LIST(STRING_OPTION_DECL)
#undef STRING_OPTION_DECL
#define BOOL_OPTION_DECL(flag, variable) \
static bool variable##_; \
static bool Process_##variable(const char* arg, \
CommandLineOptions* vm_options);
#define BOOL_OPTION_DECL(flag, variable) static bool variable##_;
BOOL_OPTIONS_LIST(BOOL_OPTION_DECL)
#undef BOOL_OPTION_DECL
#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable) \
static bool variable##_; \
static bool Process_##variable(const char* arg, \
CommandLineOptions* vm_options);
static bool variable##_;
SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_DECL)
#undef SHORT_BOOL_OPTION_DECL
#define ENUM_OPTION_DECL(flag, type, variable) \
static type variable##_; \
static bool Process_##variable(const char* arg, \
CommandLineOptions* vm_options);
#define ENUM_OPTION_DECL(flag, type, variable) static type variable##_;
ENUM_OPTIONS_LIST(ENUM_OPTION_DECL)
#undef ENUM_OPTION_DECL
static bool preview_dart_2_;
static dart::HashMap* environment_;
// Frontend argument processing.
@ -170,7 +163,7 @@ class Options {
#define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag;
STRING_OPTIONS_LIST(OPTION_FRIEND)
BOOL_OPTIONS_LIST(OPTION_FRIEND)
#undef STRING_OPTION_FRIEND
#undef OPTION_FRIEND
#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable) \
friend class OptionProcessor_##long_name;
@ -182,6 +175,8 @@ class Options {
ENUM_OPTIONS_LIST(ENUM_OPTION_FRIEND)
#undef ENUM_OPTION_FRIEND
friend class OptionProcessor_preview_dart_2;
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Options);
};

View file

@ -5,6 +5,7 @@
#include "bin/snapshot_utils.h"
#include "bin/dartutils.h"
#include "bin/dfe.h"
#include "bin/error_exit.h"
#include "bin/extensions.h"
#include "bin/file.h"
@ -241,7 +242,7 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_name) {
if (snapshot != NULL) {
return snapshot;
}
#endif // defined(DART_PRECOMPILED_RUNTIME)
#endif // defined(DART_PRECOMPILED_RUNTIME)
return NULL;
}
@ -317,6 +318,22 @@ static void WriteAppSnapshot(const char* filename,
file->Release();
}
void Snapshot::GenerateKernel(const char* snapshot_filename,
const char* script_name,
bool strong,
const char* package_config) {
#if !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING)
Dart_KernelCompilationResult result =
dfe.CompileScript(script_name, strong, false, package_config);
if (result.status != Dart_KernelCompilationStatus_Ok) {
ErrorExit(kErrorExitCode, "%s\n", result.error);
}
WriteSnapshotFile(snapshot_filename, result.kernel, result.kernel_size);
#else
UNREACHABLE();
#endif // !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING)
}
void Snapshot::GenerateScript(const char* snapshot_filename) {
// First create a snapshot.
uint8_t* buffer = NULL;

View file

@ -28,6 +28,10 @@ class AppSnapshot {
class Snapshot {
public:
static void GenerateKernel(const char* snapshot_filename,
const char* script_name,
bool strong,
const char* package_config);
static void GenerateScript(const char* snapshot_filename);
static void GenerateAppJIT(const char* snapshot_filename);
static void GenerateAppAOTAsBlobs(const char* snapshot_filename,

View file

@ -3214,6 +3214,7 @@ DART_EXPORT Dart_KernelCompilationResult
Dart_CompileToKernel(const char* script_uri,
const uint8_t* platform_kernel,
const intptr_t platform_kernel_size,
bool incremental_compile,
const char* package_config);
typedef struct {

View file

@ -6011,6 +6011,7 @@ DART_EXPORT Dart_KernelCompilationResult
Dart_CompileToKernel(const char* script_uri,
const uint8_t* platform_kernel,
intptr_t platform_kernel_size,
bool incremental_compile,
const char* package_config) {
Dart_KernelCompilationResult result;
#if defined(DART_PRECOMPILED_RUNTIME)
@ -6019,8 +6020,8 @@ Dart_CompileToKernel(const char* script_uri,
return result;
#else
result = KernelIsolate::CompileToKernel(script_uri, platform_kernel,
platform_kernel_size, 0, NULL, true,
package_config);
platform_kernel_size, 0, NULL,
incremental_compile, package_config);
if (result.status == Dart_KernelCompilationStatus_Ok) {
if (KernelIsolate::AcceptCompilation().status !=
Dart_KernelCompilationStatus_Ok) {