Skip to content

Commit

Permalink
Cleanup options for use of application snapshots
Browse files Browse the repository at this point in the history
 - unified kAppAfterRun and kAppJITAfterRun to kAppJIT
 - adjusted the test configuration to make dart2app and dart2appjit to mean
   the same
 - delete GenerateFullSnapshot function as it is not used anymore

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2429023002 .
  • Loading branch information
a-siva committed Oct 20, 2016
1 parent b85f900 commit af4d246
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 101 deletions.
88 changes: 33 additions & 55 deletions runtime/bin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,20 @@ extern const uint8_t* isolate_snapshot_buffer;

/**
* Global state used to control and store generation of application snapshots
* (script/full).
* A full application snapshot can be generated and run using the following
* commands
* - Generating a full application snapshot :
* dart_bootstrap --full-snapshot-after-run=<filename> --package-root=<dirs>
* <script_uri> [<script_options>]
* - Running the full application snapshot generated above :
* dart --run-full-snapshot=<filename> <script_uri> [<script_options>]
* An application snapshot can be generated and run using the following
* command
* dart --snapshot-kind=app-jit --snapshot=<app_snapshot_filename>
* <script_uri> [<script_options>]
* To Run the application snapshot generated above, use :
* dart <app_snapshot_filename> [<script_options>]
*/
static bool run_app_snapshot = false;
static const char* snapshot_filename = NULL;
enum SnapshotKind {
kNone,
kScript,
kAppAOT,
kAppJITAfterRun,
kAppAfterRun,
kAppJIT,
};
static SnapshotKind gen_snapshot_kind = kNone;

Expand Down Expand Up @@ -360,15 +357,12 @@ static bool ProcessSnapshotKindOption(const char* kind,
} else if (strcmp(kind, "app-aot") == 0) {
gen_snapshot_kind = kAppAOT;
return true;
} else if (strcmp(kind, "app-jit-after-run") == 0) {
gen_snapshot_kind = kAppJITAfterRun;
return true;
} else if (strcmp(kind, "app-after-run") == 0) {
gen_snapshot_kind = kAppAfterRun;
} else if (strcmp(kind, "app-jit") == 0) {
gen_snapshot_kind = kAppJIT;
return true;
}
Log::PrintErr("Unrecognized snapshot kind: '%s'\nValid kinds are: "
"script, app-aot, app-jit-after-run, app-after-run\n", kind);
"script, app-aot, app-jit\n", kind);
return false;
}

Expand Down Expand Up @@ -804,8 +798,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
IsolateData* isolate_data = new IsolateData(script_uri,
package_root,
packages_config);
if ((gen_snapshot_kind == kAppAfterRun) ||
(gen_snapshot_kind == kAppJITAfterRun)) {
if (gen_snapshot_kind == kAppJIT) {
isolate_data->set_exit_hook(SnapshotOnExitHook);
}
Dart_Isolate isolate = Dart_CreateIsolate(script_uri,
Expand Down Expand Up @@ -1159,27 +1152,16 @@ static bool FileModifiedCallback(const char* url, int64_t since) {
}


static void WriteSnapshotFile(const char* snapshot_directory,
const char* filename,
static void WriteSnapshotFile(const char* filename,
bool write_magic_number,
const uint8_t* buffer,
const intptr_t size) {
char* concat = NULL;
const char* qualified_filename;
if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) {
intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename);
concat = new char[len + 1];
snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename);
qualified_filename = concat;
} else {
qualified_filename = filename;
}

File* file = File::Open(qualified_filename, File::kWriteTruncate);
File* file = File::Open(filename, File::kWriteTruncate);
if (file == NULL) {
ErrorExit(kErrorExitCode,
"Unable to open file %s for writing snapshot\n",
qualified_filename);
filename);
}

if (write_magic_number) {
Expand All @@ -1190,7 +1172,7 @@ static void WriteSnapshotFile(const char* snapshot_directory,
if (!file->WriteFully(buffer, size)) {
ErrorExit(kErrorExitCode,
"Unable to write file %s for writing snapshot\n",
qualified_filename);
filename);
}
file->Release();
if (concat != NULL) {
Expand Down Expand Up @@ -1410,7 +1392,7 @@ static void GenerateScriptSnapshot() {
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
}

WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size);
WriteSnapshotFile(snapshot_filename, true, buffer, size);
}


Expand Down Expand Up @@ -1455,7 +1437,7 @@ static void GeneratePrecompiledSnapshot() {
rodata_blob_buffer,
rodata_blob_size);
} else {
WriteSnapshotFile(NULL, snapshot_filename,
WriteSnapshotFile(snapshot_filename,
false,
assembly_buffer,
assembly_size);
Expand Down Expand Up @@ -1496,9 +1478,16 @@ static void GeneratePrecompiledJITSnapshot() {
}


static void GenerateFullSnapshot() {
// Create a full snapshot of the script.
static void GenerateAppSnapshot() {
Dart_Handle result;
#if defined(TARGET_ARCH_X64)
result = Dart_PrecompileJIT();
if (Dart_IsError(result)) {
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
}
GeneratePrecompiledJITSnapshot();
#else
// Create an application snapshot of the script.
uint8_t* vm_isolate_buffer = NULL;
intptr_t vm_isolate_size = 0;
uint8_t* isolate_buffer = NULL;
Expand All @@ -1518,9 +1507,11 @@ static void GenerateFullSnapshot() {
isolate_buffer,
isolate_size,
NULL, 0, NULL, 0);
#endif // defined(TARGET_ARCH_X64)
}



#define CHECK_RESULT(result) \
if (Dart_IsError(result)) { \
if (Dart_IsVMRestartRequest(result)) { \
Expand All @@ -1536,12 +1527,7 @@ static void GenerateFullSnapshot() {

static void SnapshotOnExitHook(int64_t exit_code) {
if (exit_code == 0) {
if (gen_snapshot_kind == kAppAfterRun) {
GenerateFullSnapshot();
} else {
Dart_PrecompileJIT();
GeneratePrecompiledJITSnapshot();
}
GenerateAppSnapshot();
}
}

Expand Down Expand Up @@ -1599,9 +1585,8 @@ bool RunMainIsolate(const char* script_name,
result = Dart_LibraryImportLibrary(
isolate_data->builtin_lib(), root_lib, Dart_Null());
if (is_noopt ||
(gen_snapshot_kind == kAppAfterRun) ||
(gen_snapshot_kind == kAppAOT) ||
(gen_snapshot_kind == kAppJITAfterRun)) {
(gen_snapshot_kind == kAppJIT)) {
// Load the embedder's portion of the VM service's Dart code so it will
// be included in the app snapshot.
if (!VmService::LoadForGenPrecompiled()) {
Expand Down Expand Up @@ -1703,17 +1688,10 @@ bool RunMainIsolate(const char* script_name,
// Keep handling messages until the last active receive port is closed.
result = Dart_RunLoop();
// Generate an app snapshot after execution if specified.
if ((gen_snapshot_kind == kAppAfterRun) ||
(gen_snapshot_kind == kAppJITAfterRun)) {
if ((gen_snapshot_kind == kAppJIT)) {
if (!Dart_IsCompilationError(result) &&
!Dart_IsVMRestartRequest(result)) {
if (gen_snapshot_kind == kAppAfterRun) {
GenerateFullSnapshot();
} else {
Dart_Handle prepare_result = Dart_PrecompileJIT();
CHECK_RESULT(prepare_result);
GeneratePrecompiledJITSnapshot();
}
GenerateAppSnapshot();
}
}
CHECK_RESULT(result);
Expand Down Expand Up @@ -1891,7 +1869,7 @@ void main(int argc, char** argv) {
}
#endif

if (gen_snapshot_kind == kAppJITAfterRun) {
if (gen_snapshot_kind == kAppJIT) {
vm_options.AddArgument("--fields_may_be_reset");
}
if ((gen_snapshot_kind == kAppAOT) || is_noopt) {
Expand Down
2 changes: 1 addition & 1 deletion tests/co19/co19-co19.status
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ LibTest/math/log_A01_t01: PASS, FAIL, OK # Issue 26261
[ $runtime == dartium || $compiler == dart2js ]
LibTest/async/Future/Future.delayed_A01_t02: Pass, Fail # Issue 15524

[ ($compiler == none || $compiler == precompiler || $compiler == dart2appjit) && ($runtime == vm || $runtime == drt || $runtime == dartium || $runtime == dart_precompiled || $runtime == dart_app) ]
[ ($compiler == none || $compiler == precompiler || $compiler == dart2app || $compiler == dart2appjit) && ($runtime == vm || $runtime == drt || $runtime == dartium || $runtime == dart_precompiled || $runtime == dart_app) ]
# Optional trailing commas for argument and parameter lists added to language.
# https://github.com/dart-lang/co19/issues/68
Language/Expressions/Function_Invocation/Actual_Argument_List_Evaluation/syntax_t05: Fail, OK
Expand Down
4 changes: 2 additions & 2 deletions tests/co19/co19-runtime.status
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Language/Expressions/Property_Extraction/Super_Closurization: CompileTimeError #
Language/Metadata/*: SkipByDesign # Uses dart:mirrors
Language/Expressions/Null/instance_of_class_null_t01: Skip # Uses dart:mirrors

[ $noopt || $compiler == precompiler || $compiler == dart2appjit || $mode == product ]
[ $noopt || $compiler == precompiler || $compiler == dart2app || $compiler == dart2appjit || $mode == product ]
Language/Libraries_and_Scripts/Imports/deferred_import_t01: Skip # Eager loading
Language/Libraries_and_Scripts/Imports/deferred_import_t02: Skip # Eager loading
Language/Libraries_and_Scripts/Imports/invalid_uri_deferred_t01: Skip # Eager loading
Expand All @@ -179,7 +179,7 @@ LibTest/collection/ListMixin/ListMixin_class_A01_t02: Pass, Timeout
LibTest/core/Map/Map_class_A01_t04: Pass, Timeout
LibTest/core/Uri/encodeQueryComponent_A01_t02: Pass, Timeout

[ $noopt || $compiler == precompiler || $compiler == dart2appjit ]
[ $noopt || $compiler == precompiler || $compiler == dart2app || $compiler == dart2appjit ]
Language/Mixins/Mixin_Application/error_t01: Pass
Language/Mixins/Mixin_Application/error_t02: Pass
Language/Mixins/declaring_constructor_t01: Pass
Expand Down
2 changes: 1 addition & 1 deletion tests/standalone/standalone.status
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ assert_test: Pass, RuntimeError
map_insert_remove_oom_test: Skip # Heap limit too low. Increasing iteration count to make a higher limit a meaningful test makes it too slow for simarm[64] bots.
io/web_socket_test: Pass, RuntimeError # Issue 24674

[ $noopt || $compiler == precompiler || $compiler == dart2appjit ]
[ $noopt || $compiler == precompiler || $compiler == dart2app || $compiler == dart2appjit ]
io/test_extension_test: Skip # Platform.executable
io/test_extension_fail_test: Skip # Platform.executable
io/platform_test: Skip # Platform.executable
Expand Down
47 changes: 9 additions & 38 deletions tools/testing/dart/compiler_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ abstract class CompilerConfiguration {
useFastStartup: useFastStartup,
extraDart2jsOptions:
TestUtils.getExtraOptions(configuration, 'dart2js_options'));
case 'dart2appjit':
case 'dart2app':
return new Dart2AppSnapshotCompilerConfiguration(
isDebug: isDebug, isChecked: isChecked);
case 'dart2appjit':
return new Dart2AppJitSnapshotCompilerConfiguration(
isDebug: isDebug, isChecked: isChecked, useBlobs: useBlobs);
case 'precompiler':
return new PrecompilerCompilerConfiguration(
Expand Down Expand Up @@ -502,8 +500,9 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration {
}

class Dart2AppSnapshotCompilerConfiguration extends CompilerConfiguration {
Dart2AppSnapshotCompilerConfiguration({bool isDebug, bool isChecked})
: super._subclass(isDebug: isDebug, isChecked: isChecked);
final bool useBlobs;
Dart2AppSnapshotCompilerConfiguration({bool isDebug, bool isChecked, bool useBlobs})
: super._subclass(isDebug: isDebug, isChecked: isChecked), this.useBlobs = useBlobs;

int computeTimeoutMultiplier() {
int multiplier = 2;
Expand All @@ -530,10 +529,13 @@ class Dart2AppSnapshotCompilerConfiguration extends CompilerConfiguration {
CommandBuilder commandBuilder,
List arguments,
Map<String, String> environmentOverrides) {
var exec = "$buildDir/dart_bootstrap";
var exec = "$buildDir/dart";
var args = new List();
args.add("--snapshot=$tempDir/out.jitsnapshot");
args.add("--snapshot-kind=app-after-run");
args.add("--snapshot-kind=app-jit");
if (useBlobs) {
args.add("--use-blobs");
}
args.addAll(arguments);

return commandBuilder.getCompilationCommand(
Expand Down Expand Up @@ -579,37 +581,6 @@ class Dart2AppSnapshotCompilerConfiguration extends CompilerConfiguration {
}
}

class Dart2AppJitSnapshotCompilerConfiguration extends Dart2AppSnapshotCompilerConfiguration {
final bool useBlobs;
Dart2AppJitSnapshotCompilerConfiguration({bool isDebug, bool isChecked, bool useBlobs})
: super(isDebug: isDebug, isChecked: isChecked), this.useBlobs = useBlobs;

CompilationCommand computeCompilationCommand(
String tempDir,
String buildDir,
CommandBuilder commandBuilder,
List arguments,
Map<String, String> environmentOverrides) {
var exec = "$buildDir/dart";
var args = new List();
args.add("--snapshot=$tempDir/out.jitsnapshot");
args.add("--snapshot-kind=app-jit-after-run");
if (useBlobs) {
args.add("--use-blobs");
}
args.addAll(arguments);

return commandBuilder.getCompilationCommand(
'dart2snapshot',
tempDir,
!useSdk,
bootstrapDependencies(buildDir),
exec,
args,
environmentOverrides);
}
}

class AnalyzerCompilerConfiguration extends CompilerConfiguration {
AnalyzerCompilerConfiguration(
{bool isDebug, bool isChecked, bool isStrong, bool isHostChecked, bool
Expand Down
7 changes: 3 additions & 4 deletions tools/testing/dart/test_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class TestOptionsParser {
dart2analyzer: Perform static analysis on Dart code by running the analyzer
(only valid with the following runtimes: none)
dart2app: Compile the Dart code into an app snapshot before running the test
(only valid with the following runtimes: dart_app)''',
dart2app:
dart2appjit: Compile the Dart code into an app snapshot before running test
(only valid with dart_app runtime)''',
['-c', '--compiler'],
['none', 'precompiler', 'dart2js', 'dart2analyzer', 'dart2app', 'dart2appjit'],
'none'),
Expand Down Expand Up @@ -670,8 +671,6 @@ Note: currently only implemented for dart2js.''',
validRuntimes = const ['none'];
break;
case 'dart2app':
validRuntimes = const ['dart_app'];
break;
case 'dart2appjit':
validRuntimes = const ['dart_app'];
break;
Expand Down

0 comments on commit af4d246

Please sign in to comment.