Refactor snapshots pieces to include a section for loading instructions into the heap of a regular isolate.
Progress toward allowing each isolate to load a different snapshot. R=asiva@google.com Review-Url: https://codereview.chromium.org/2622053002 .
This commit is contained in:
@@ -11,10 +11,11 @@
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
const char* kPrecompiledVMIsolateSymbolName = "_kVmIsolateSnapshot";
|
||||
const char* kPrecompiledIsolateSymbolName = "_kIsolateSnapshot";
|
||||
const char* kPrecompiledInstructionsSymbolName = "_kInstructionsSnapshot";
|
||||
const char* kPrecompiledDataSymbolName = "_kDataSnapshot";
|
||||
const char* kVmSnapshotDataSymbolName = "_kDartVmSnapshotData";
|
||||
const char* kVmSnapshotInstructionsSymbolName = "_kDartVmSnapshotInstructions";
|
||||
const char* kIsolateSnapshotDataSymbolName = "_kDartIsolateSnapshotData";
|
||||
const char* kIsolateSnapshotInstructionsSymbolName =
|
||||
"_kDartIsolateSnapshotInstructions";
|
||||
|
||||
void* Extensions::LoadExtensionLibrary(const char* library_file) {
|
||||
return dlopen(library_file, RTLD_LAZY);
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
const char* kPrecompiledVMIsolateSymbolName = "_kVmIsolateSnapshot";
|
||||
const char* kPrecompiledIsolateSymbolName = "_kIsolateSnapshot";
|
||||
const char* kPrecompiledInstructionsSymbolName = "_kInstructionsSnapshot";
|
||||
const char* kPrecompiledDataSymbolName = "_kDataSnapshot";
|
||||
const char* kVmSnapshotDataSymbolName = "_kDartVmSnapshotData";
|
||||
const char* kVmSnapshotInstructionsSymbolName = "_kDartVmSnapshotInstructions";
|
||||
const char* kIsolateSnapshotDataSymbolName = "_kDartIsolateSnapshotData";
|
||||
const char* kIsolateSnapshotInstructionsSymbolName =
|
||||
"_kDartIsolateSnapshotInstructions";
|
||||
|
||||
void* Extensions::LoadExtensionLibrary(const char* library_file) {
|
||||
return dlopen(library_file, RTLD_LAZY);
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
const char* kPrecompiledVMIsolateSymbolName = "_kVmIsolateSnapshot";
|
||||
const char* kPrecompiledIsolateSymbolName = "_kIsolateSnapshot";
|
||||
const char* kPrecompiledInstructionsSymbolName = "_kInstructionsSnapshot";
|
||||
const char* kPrecompiledDataSymbolName = "_kDataSnapshot";
|
||||
const char* kVmSnapshotDataSymbolName = "_kDartVmSnapshotData";
|
||||
const char* kVmSnapshotInstructionsSymbolName = "_kDartVmSnapshotInstructions";
|
||||
const char* kIsolateSnapshotDataSymbolName = "_kDartIsolateSnapshotData";
|
||||
const char* kIsolateSnapshotInstructionsSymbolName =
|
||||
"_kDartIsolateSnapshotInstructions";
|
||||
|
||||
void* Extensions::LoadExtensionLibrary(const char* library_file) {
|
||||
return dlopen(library_file, RTLD_LAZY);
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
const char* kPrecompiledVMIsolateSymbolName = "kVmIsolateSnapshot";
|
||||
const char* kPrecompiledIsolateSymbolName = "kIsolateSnapshot";
|
||||
const char* kPrecompiledInstructionsSymbolName = "kInstructionsSnapshot";
|
||||
const char* kPrecompiledDataSymbolName = "kDataSnapshot";
|
||||
const char* kVmSnapshotDataSymbolName = "kDartVmSnapshotData";
|
||||
const char* kVmSnapshotInstructionsSymbolName = "kDartVmSnapshotInstructions";
|
||||
const char* kIsolateSnapshotDataSymbolName = "kDartIsolateSnapshotData";
|
||||
const char* kIsolateSnapshotInstructionsSymbolName =
|
||||
"kDartIsolateSnapshotInstructions";
|
||||
|
||||
void* Extensions::LoadExtensionLibrary(const char* library_file) {
|
||||
return dlopen(library_file, RTLD_LAZY);
|
||||
|
||||
@@ -12,10 +12,11 @@
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
const char* kPrecompiledVMIsolateSymbolName = "_kVmIsolateSnapshot";
|
||||
const char* kPrecompiledIsolateSymbolName = "_kIsolateSnapshot";
|
||||
const char* kPrecompiledInstructionsSymbolName = "_kInstructionsSnapshot";
|
||||
const char* kPrecompiledDataSymbolName = "_kDataSnapshot";
|
||||
const char* kVmSnapshotDataSymbolName = "_kDartVmSnapshotData";
|
||||
const char* kVmSnapshotInstructionsSymbolName = "_kDartVmSnapshotInstructions";
|
||||
const char* kIsolateSnapshotDataSymbolName = "_kDartIsolateSnapshotData";
|
||||
const char* kIsolateSnapshotInstructionsSymbolName =
|
||||
"_kDartIsolateSnapshotInstructions";
|
||||
|
||||
void* Extensions::LoadExtensionLibrary(const char* library_file) {
|
||||
SetLastError(0);
|
||||
|
||||
+92
-81
@@ -60,11 +60,11 @@ static const int kRestartRequestExitCode = 1000;
|
||||
|
||||
// Global state that indicates whether a snapshot is to be created and
|
||||
// if so which file to write the snapshot into.
|
||||
static const char* vm_isolate_snapshot_filename = NULL;
|
||||
static const char* isolate_snapshot_filename = NULL;
|
||||
static const char* vm_snapshot_data_filename = NULL;
|
||||
static const char* vm_snapshot_instructions_filename = NULL;
|
||||
static const char* isolate_snapshot_data_filename = NULL;
|
||||
static const char* isolate_snapshot_instructions_filename = NULL;
|
||||
static const char* assembly_filename = NULL;
|
||||
static const char* instructions_blob_filename = NULL;
|
||||
static const char* rodata_blob_filename = NULL;
|
||||
|
||||
|
||||
// Value of the --package-root flag.
|
||||
@@ -189,20 +189,40 @@ static const char* ProcessOption(const char* option, const char* name) {
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessVmIsolateSnapshotOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--vm_isolate_snapshot=");
|
||||
static bool ProcessVmSnapshotDataOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--vm_snapshot_data=");
|
||||
if (name != NULL) {
|
||||
vm_isolate_snapshot_filename = name;
|
||||
vm_snapshot_data_filename = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessIsolateSnapshotOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--isolate_snapshot=");
|
||||
static bool ProcessVmSnapshotInstructionsOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--vm_snapshot_instructions=");
|
||||
if (name != NULL) {
|
||||
isolate_snapshot_filename = name;
|
||||
vm_snapshot_instructions_filename = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessIsolateSnapshotDataOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--isolate_snapshot_data=");
|
||||
if (name != NULL) {
|
||||
isolate_snapshot_data_filename = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessIsolateSnapshotInstructionsOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--isolate_snapshot_instructions=");
|
||||
if (name != NULL) {
|
||||
isolate_snapshot_instructions_filename = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -219,26 +239,6 @@ static bool ProcessAssemblyOption(const char* option) {
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessInstructionsBlobOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--instructions_blob=");
|
||||
if (name != NULL) {
|
||||
instructions_blob_filename = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessRodataBlobOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--rodata_blob=");
|
||||
if (name != NULL) {
|
||||
rodata_blob_filename = name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool ProcessEmbedderEntryPointsManifestOption(const char* option) {
|
||||
const char* name = ProcessOption(option, "--embedder_entry_points_manifest=");
|
||||
if (name != NULL) {
|
||||
@@ -286,7 +286,8 @@ static bool ProcessURLmappingOption(const char* option) {
|
||||
|
||||
|
||||
static bool IsSnapshottingForPrecompilation() {
|
||||
return (assembly_filename != NULL) || (instructions_blob_filename != NULL);
|
||||
return (assembly_filename != NULL) ||
|
||||
(vm_snapshot_instructions_filename != NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -304,11 +305,11 @@ static int ParseArguments(int argc,
|
||||
|
||||
// Parse out the vm options.
|
||||
while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
|
||||
if (ProcessVmIsolateSnapshotOption(argv[i]) ||
|
||||
ProcessIsolateSnapshotOption(argv[i]) ||
|
||||
if (ProcessVmSnapshotDataOption(argv[i]) ||
|
||||
ProcessVmSnapshotInstructionsOption(argv[i]) ||
|
||||
ProcessIsolateSnapshotDataOption(argv[i]) ||
|
||||
ProcessIsolateSnapshotInstructionsOption(argv[i]) ||
|
||||
ProcessAssemblyOption(argv[i]) ||
|
||||
ProcessInstructionsBlobOption(argv[i]) ||
|
||||
ProcessRodataBlobOption(argv[i]) ||
|
||||
ProcessEmbedderEntryPointsManifestOption(argv[i]) ||
|
||||
ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) ||
|
||||
ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) {
|
||||
@@ -336,19 +337,19 @@ static int ParseArguments(int argc,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm_isolate_snapshot_filename == NULL) {
|
||||
Log::PrintErr("No vm isolate snapshot output file specified.\n\n");
|
||||
if (vm_snapshot_data_filename == NULL) {
|
||||
Log::PrintErr("No vm snapshot output file specified.\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isolate_snapshot_filename == NULL) {
|
||||
if (isolate_snapshot_data_filename == NULL) {
|
||||
Log::PrintErr("No isolate snapshot output file specified.\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool precompiled_as_assembly = assembly_filename != NULL;
|
||||
bool precompiled_as_blobs =
|
||||
(instructions_blob_filename != NULL) || (rodata_blob_filename != NULL);
|
||||
bool precompiled_as_blobs = (vm_snapshot_instructions_filename != NULL) ||
|
||||
(isolate_snapshot_instructions_filename != NULL);
|
||||
if (precompiled_as_assembly && precompiled_as_blobs) {
|
||||
Log::PrintErr(
|
||||
"Cannot request a precompiled snapshot simultaneously as "
|
||||
@@ -357,11 +358,12 @@ static int ParseArguments(int argc,
|
||||
"--rodata-blob=<output.file>)\n\n");
|
||||
return -1;
|
||||
}
|
||||
if ((instructions_blob_filename != NULL) != (rodata_blob_filename != NULL)) {
|
||||
if ((vm_snapshot_instructions_filename != NULL) !=
|
||||
(isolate_snapshot_instructions_filename != NULL)) {
|
||||
Log::PrintErr(
|
||||
"Requesting a precompiled snapshot as blobs requires both "
|
||||
"(--instructions-blob=<output.file> and "
|
||||
"--rodata-blob=<output.file>)\n\n");
|
||||
"(--vm_snapshot_instructions=<output.file> and "
|
||||
"--isolate_snapshot_instructions=<output.file>)\n\n");
|
||||
return -1;
|
||||
}
|
||||
if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) {
|
||||
@@ -640,8 +642,8 @@ static void PrintUsage() {
|
||||
" dart:something,SomeClass,doSomething \n"
|
||||
" \n"
|
||||
" Supported options: \n"
|
||||
" --vm_isolate_snapshot=<file> A full snapshot is a compact \n"
|
||||
" --isolate_snapshot=<file> representation of the dart vm isolate \n"
|
||||
" --vm_snapshot_data=<file> A full snapshot is a compact \n"
|
||||
" --isolate_snapshot_data=<file> representation of the dart vm isolate \n"
|
||||
" heap and dart isolate heap states. \n"
|
||||
" Both these options are required \n"
|
||||
" \n"
|
||||
@@ -658,9 +660,10 @@ static void PrintUsage() {
|
||||
" assembly that must be linked into \n"
|
||||
" the target binary \n"
|
||||
" \n"
|
||||
" --instructions_blob=<file> (Precompilation only) Contains the \n"
|
||||
" --rodata_blob=<file> instructions and read-only data that \n"
|
||||
" must be mapped into the target binary \n"
|
||||
" --vm_snapshot_instructions=<file> (Precompilation only) Contains the \n"
|
||||
" --isolate_snapshot_instructions=<file> instructions and read-only data \n"
|
||||
" that must be mapped into the target \n"
|
||||
" binary \n"
|
||||
" \n"
|
||||
" --embedder_entry_points_manifest=<file> (Precompilation or app \n"
|
||||
" snapshots) Contains embedder's entry \n"
|
||||
@@ -1027,21 +1030,23 @@ static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() {
|
||||
static void CreateAndWriteSnapshot() {
|
||||
ASSERT(!IsSnapshottingForPrecompilation());
|
||||
Dart_Handle result;
|
||||
uint8_t* vm_isolate_buffer = NULL;
|
||||
intptr_t vm_isolate_size = 0;
|
||||
uint8_t* isolate_buffer = NULL;
|
||||
intptr_t isolate_size = 0;
|
||||
uint8_t* vm_snapshot_data_buffer = NULL;
|
||||
intptr_t vm_snapshot_data_size = 0;
|
||||
uint8_t* isolate_snapshot_data_buffer = NULL;
|
||||
intptr_t isolate_snapshot_data_size = 0;
|
||||
|
||||
// First create a snapshot.
|
||||
result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size,
|
||||
&isolate_buffer, &isolate_size);
|
||||
result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size,
|
||||
&isolate_snapshot_data_buffer,
|
||||
&isolate_snapshot_data_size);
|
||||
CHECK_RESULT(result);
|
||||
|
||||
// Now write the vm isolate and isolate snapshots out to the
|
||||
// specified file and exit.
|
||||
WriteSnapshotFile(vm_isolate_snapshot_filename, vm_isolate_buffer,
|
||||
vm_isolate_size);
|
||||
WriteSnapshotFile(isolate_snapshot_filename, isolate_buffer, isolate_size);
|
||||
WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer,
|
||||
vm_snapshot_data_size);
|
||||
WriteSnapshotFile(isolate_snapshot_data_filename,
|
||||
isolate_snapshot_data_buffer, isolate_snapshot_data_size);
|
||||
Dart_ExitScope();
|
||||
|
||||
// Shutdown the isolate.
|
||||
@@ -1068,26 +1073,31 @@ static void CreateAndWritePrecompiledSnapshot(
|
||||
CHECK_RESULT(result);
|
||||
WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size);
|
||||
} else {
|
||||
uint8_t* vm_isolate_buffer = NULL;
|
||||
intptr_t vm_isolate_size = 0;
|
||||
uint8_t* isolate_buffer = NULL;
|
||||
intptr_t isolate_size = 0;
|
||||
uint8_t* instructions_blob_buffer = NULL;
|
||||
intptr_t instructions_blob_size = 0;
|
||||
uint8_t* rodata_blob_buffer = NULL;
|
||||
intptr_t rodata_blob_size = 0;
|
||||
uint8_t* vm_snapshot_data_buffer = NULL;
|
||||
intptr_t vm_snapshot_data_size = 0;
|
||||
uint8_t* vm_snapshot_instructions_buffer = NULL;
|
||||
intptr_t vm_snapshot_instructions_size = 0;
|
||||
uint8_t* isolate_snapshot_data_buffer = NULL;
|
||||
intptr_t isolate_snapshot_data_size = 0;
|
||||
uint8_t* isolate_snapshot_instructions_buffer = NULL;
|
||||
intptr_t isolate_snapshot_instructions_size = 0;
|
||||
result = Dart_CreateAppAOTSnapshotAsBlobs(
|
||||
&vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size,
|
||||
&instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer,
|
||||
&rodata_blob_size);
|
||||
&vm_snapshot_data_buffer, &vm_snapshot_data_size,
|
||||
&vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size,
|
||||
&isolate_snapshot_data_buffer, &isolate_snapshot_data_size,
|
||||
&isolate_snapshot_instructions_buffer,
|
||||
&isolate_snapshot_instructions_size);
|
||||
CHECK_RESULT(result);
|
||||
WriteSnapshotFile(vm_isolate_snapshot_filename, vm_isolate_buffer,
|
||||
vm_isolate_size);
|
||||
WriteSnapshotFile(isolate_snapshot_filename, isolate_buffer, isolate_size);
|
||||
WriteSnapshotFile(instructions_blob_filename, instructions_blob_buffer,
|
||||
instructions_blob_size);
|
||||
WriteSnapshotFile(rodata_blob_filename, rodata_blob_buffer,
|
||||
rodata_blob_size);
|
||||
WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer,
|
||||
vm_snapshot_data_size);
|
||||
WriteSnapshotFile(vm_snapshot_instructions_filename,
|
||||
vm_snapshot_instructions_buffer,
|
||||
vm_snapshot_instructions_size);
|
||||
WriteSnapshotFile(isolate_snapshot_data_filename,
|
||||
isolate_snapshot_data_buffer, isolate_snapshot_data_size);
|
||||
WriteSnapshotFile(isolate_snapshot_instructions_filename,
|
||||
isolate_snapshot_instructions_buffer,
|
||||
isolate_snapshot_instructions_size);
|
||||
}
|
||||
|
||||
Dart_ExitScope();
|
||||
@@ -1139,8 +1149,8 @@ static Dart_Isolate CreateServiceIsolate(const char* script_uri,
|
||||
IsolateData* isolate_data =
|
||||
new IsolateData(script_uri, package_root, package_config);
|
||||
Dart_Isolate isolate = NULL;
|
||||
isolate =
|
||||
Dart_CreateIsolate(script_uri, main, NULL, NULL, isolate_data, error);
|
||||
isolate = Dart_CreateIsolate(script_uri, main, NULL, NULL, NULL, isolate_data,
|
||||
error);
|
||||
|
||||
if (isolate == NULL) {
|
||||
Log::PrintErr("Error: Could not create service isolate");
|
||||
@@ -1243,7 +1253,7 @@ int main(int argc, char** argv) {
|
||||
IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root,
|
||||
commandline_packages_file);
|
||||
Dart_Isolate isolate =
|
||||
Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error);
|
||||
Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, &error);
|
||||
if (isolate == NULL) {
|
||||
Log::PrintErr("Error: %s", error);
|
||||
free(error);
|
||||
@@ -1257,8 +1267,8 @@ int main(int argc, char** argv) {
|
||||
result = Dart_SetEnvironmentCallback(EnvironmentCallback);
|
||||
CHECK_RESULT(result);
|
||||
|
||||
ASSERT(vm_isolate_snapshot_filename != NULL);
|
||||
ASSERT(isolate_snapshot_filename != NULL);
|
||||
ASSERT(vm_snapshot_data_filename != NULL);
|
||||
ASSERT(isolate_snapshot_data_filename != NULL);
|
||||
// Load up the script before a snapshot is created.
|
||||
if (app_script_name != NULL) {
|
||||
// This is the case of a custom embedder (e.g: dartium) trying to
|
||||
@@ -1305,7 +1315,8 @@ int main(int argc, char** argv) {
|
||||
is_kernel_file
|
||||
? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL,
|
||||
isolate_data, &error)
|
||||
: Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error);
|
||||
: Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data,
|
||||
&error);
|
||||
if (isolate == NULL) {
|
||||
Log::PrintErr("%s", error);
|
||||
free(error);
|
||||
|
||||
+179
-166
@@ -34,14 +34,11 @@
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
// vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we
|
||||
// link in a snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* vm_isolate_snapshot_buffer;
|
||||
|
||||
// isolate_snapshot_buffer points to a snapshot for an isolate if we link in a
|
||||
// snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* core_isolate_snapshot_buffer;
|
||||
|
||||
// Snapshot pieces if we link in a snapshot, otherwise initialized to NULL.
|
||||
extern const uint8_t* vm_snapshot_data;
|
||||
extern const uint8_t* vm_snapshot_instructions;
|
||||
extern const uint8_t* core_isolate_snapshot_data;
|
||||
extern const uint8_t* core_isolate_snapshot_instructions;
|
||||
|
||||
/**
|
||||
* Global state used to control and store generation of application snapshots
|
||||
@@ -98,10 +95,10 @@ static bool parse_all = false;
|
||||
static bool use_blobs = false;
|
||||
|
||||
|
||||
extern const char* kPrecompiledVMIsolateSymbolName;
|
||||
extern const char* kPrecompiledIsolateSymbolName;
|
||||
extern const char* kPrecompiledInstructionsSymbolName;
|
||||
extern const char* kPrecompiledDataSymbolName;
|
||||
extern const char* kVmSnapshotDataSymbolName;
|
||||
extern const char* kVmSnapshotInstructionsSymbolName;
|
||||
extern const char* kIsolateSnapshotDataSymbolName;
|
||||
extern const char* kIsolateSnapshotInstructionsSymbolName;
|
||||
|
||||
|
||||
// Global flag that is used to indicate that we want to trace resolution of
|
||||
@@ -110,7 +107,8 @@ static bool trace_loading = false;
|
||||
|
||||
|
||||
static char* app_script_uri = NULL;
|
||||
static const uint8_t* app_isolate_snapshot_buffer = NULL;
|
||||
static const uint8_t* app_isolate_snapshot_data = NULL;
|
||||
static const uint8_t* app_isolate_snapshot_instructions = NULL;
|
||||
|
||||
|
||||
static Dart_Isolate main_isolate = NULL;
|
||||
@@ -835,17 +833,22 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
// AOT: All isolates start from the app snapshot.
|
||||
bool isolate_run_app_snapshot = true;
|
||||
const uint8_t* isolate_snapshot_buffer = app_isolate_snapshot_buffer;
|
||||
const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data;
|
||||
const uint8_t* isolate_snapshot_instructions =
|
||||
app_isolate_snapshot_instructions;
|
||||
#else
|
||||
// JIT: Main isolate starts from the app snapshot, if any. Other use the
|
||||
// core libraries snapshot.
|
||||
// JIT: Main isolate starts from the app snapshot, if any. Other isolates
|
||||
// use the core libraries snapshot.
|
||||
bool isolate_run_app_snapshot = false;
|
||||
const uint8_t* isolate_snapshot_buffer = core_isolate_snapshot_buffer;
|
||||
if ((app_isolate_snapshot_buffer != NULL) &&
|
||||
const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data;
|
||||
const uint8_t* isolate_snapshot_instructions =
|
||||
core_isolate_snapshot_instructions;
|
||||
if ((app_isolate_snapshot_data != NULL) &&
|
||||
(is_main_isolate || ((app_script_uri != NULL) &&
|
||||
(strcmp(script_uri, app_script_uri) == 0)))) {
|
||||
isolate_run_app_snapshot = true;
|
||||
isolate_snapshot_buffer = app_isolate_snapshot_buffer;
|
||||
isolate_snapshot_data = app_isolate_snapshot_data;
|
||||
isolate_snapshot_instructions = app_isolate_snapshot_instructions;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -868,8 +871,9 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
||||
Dart_Isolate isolate =
|
||||
is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program,
|
||||
flags, isolate_data, error)
|
||||
: Dart_CreateIsolate(script_uri, main, isolate_snapshot_buffer,
|
||||
flags, isolate_data, error);
|
||||
: Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
|
||||
isolate_snapshot_instructions, flags,
|
||||
isolate_data, error);
|
||||
if (isolate == NULL) {
|
||||
delete isolate_data;
|
||||
return NULL;
|
||||
@@ -885,7 +889,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
|
||||
Dart_Handle result = Dart_LoadKernel(kernel_program);
|
||||
CHECK_RESULT(result);
|
||||
}
|
||||
if (is_kernel || (isolate_snapshot_buffer != NULL)) {
|
||||
if (is_kernel || (isolate_snapshot_data != NULL)) {
|
||||
// Setup the native resolver as the snapshot does not carry it.
|
||||
Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
|
||||
Builtin::SetNativeResolver(Builtin::kIOLibrary);
|
||||
@@ -1290,10 +1294,10 @@ static const int64_t kAppSnapshotPageSize = 4 * KB;
|
||||
|
||||
|
||||
static bool ReadAppSnapshotBlobs(const char* script_name,
|
||||
const uint8_t** vmisolate_buffer,
|
||||
const uint8_t** isolate_buffer,
|
||||
const uint8_t** instructions_buffer,
|
||||
const uint8_t** rodata_buffer) {
|
||||
const uint8_t** vm_data_buffer,
|
||||
const uint8_t** vm_instructions_buffer,
|
||||
const uint8_t** isolate_data_buffer,
|
||||
const uint8_t** isolate_instructions_buffer) {
|
||||
File* file = File::Open(script_name, File::kRead);
|
||||
if (file == NULL) {
|
||||
return false;
|
||||
@@ -1313,51 +1317,58 @@ static bool ReadAppSnapshotBlobs(const char* script_name,
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t vmisolate_size = header[1];
|
||||
int64_t vmisolate_position =
|
||||
int64_t vm_data_size = header[1];
|
||||
int64_t vm_data_position =
|
||||
Utils::RoundUp(file->Position(), kAppSnapshotPageSize);
|
||||
int64_t isolate_size = header[2];
|
||||
int64_t isolate_position =
|
||||
Utils::RoundUp(vmisolate_position + vmisolate_size, kAppSnapshotPageSize);
|
||||
int64_t rodata_size = header[3];
|
||||
int64_t rodata_position = isolate_position + isolate_size;
|
||||
if (rodata_size != 0) {
|
||||
rodata_position = Utils::RoundUp(rodata_position, kAppSnapshotPageSize);
|
||||
int64_t vm_instructions_size = header[2];
|
||||
int64_t vm_instructions_position = vm_data_position + vm_data_size;
|
||||
if (vm_instructions_size != 0) {
|
||||
vm_instructions_position =
|
||||
Utils::RoundUp(vm_instructions_position, kAppSnapshotPageSize);
|
||||
}
|
||||
int64_t instructions_size = header[4];
|
||||
int64_t instructions_position = rodata_position + rodata_size;
|
||||
if (instructions_size != 0) {
|
||||
instructions_position =
|
||||
Utils::RoundUp(instructions_position, kAppSnapshotPageSize);
|
||||
int64_t isolate_data_size = header[3];
|
||||
int64_t isolate_data_position = Utils::RoundUp(
|
||||
vm_instructions_position + vm_instructions_size, kAppSnapshotPageSize);
|
||||
int64_t isolate_instructions_size = header[4];
|
||||
int64_t isolate_instructions_position =
|
||||
isolate_data_position + isolate_data_size;
|
||||
if (isolate_instructions_size != 0) {
|
||||
isolate_instructions_position =
|
||||
Utils::RoundUp(isolate_instructions_position, kAppSnapshotPageSize);
|
||||
}
|
||||
|
||||
void* read_only_buffer =
|
||||
file->Map(File::kReadOnly, vmisolate_position,
|
||||
instructions_position - vmisolate_position);
|
||||
if (read_only_buffer == NULL) {
|
||||
if (vm_data_size != 0) {
|
||||
*vm_data_buffer = reinterpret_cast<const uint8_t*>(
|
||||
file->Map(File::kReadOnly, vm_data_position, vm_data_size));
|
||||
if (vm_data_buffer == NULL) {
|
||||
Log::PrintErr("Failed to memory map snapshot\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (vm_instructions_size != 0) {
|
||||
*vm_instructions_buffer = reinterpret_cast<const uint8_t*>(file->Map(
|
||||
File::kReadExecute, vm_instructions_position, vm_instructions_size));
|
||||
if (*vm_instructions_buffer == NULL) {
|
||||
Log::PrintErr("Failed to memory map snapshot\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
}
|
||||
|
||||
*isolate_data_buffer = reinterpret_cast<const uint8_t*>(
|
||||
file->Map(File::kReadOnly, isolate_data_position, isolate_data_size));
|
||||
if (isolate_data_buffer == NULL) {
|
||||
Log::PrintErr("Failed to memory map snapshot\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
if (vmisolate_size != 0) {
|
||||
*vmisolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) +
|
||||
(vmisolate_position - vmisolate_position);
|
||||
}
|
||||
*isolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) +
|
||||
(isolate_position - vmisolate_position);
|
||||
if (rodata_size == 0) {
|
||||
*rodata_buffer = NULL;
|
||||
if (isolate_instructions_size == 0) {
|
||||
*isolate_instructions_buffer = NULL;
|
||||
} else {
|
||||
*rodata_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) +
|
||||
(rodata_position - vmisolate_position);
|
||||
}
|
||||
|
||||
if (instructions_size == 0) {
|
||||
*instructions_buffer = NULL;
|
||||
} else {
|
||||
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||
file->Map(File::kReadExecute, instructions_position, header[4]));
|
||||
if (*instructions_buffer == NULL) {
|
||||
*isolate_instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||
file->Map(File::kReadExecute, isolate_instructions_position,
|
||||
isolate_instructions_size));
|
||||
if (*isolate_instructions_buffer == NULL) {
|
||||
Log::PrintErr("Failed to memory map snapshot\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
@@ -1369,45 +1380,46 @@ static bool ReadAppSnapshotBlobs(const char* script_name,
|
||||
|
||||
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
static bool ReadAppSnapshotDynamicLibrary(const char* script_name,
|
||||
const uint8_t** vmisolate_buffer,
|
||||
const uint8_t** isolate_buffer,
|
||||
const uint8_t** instructions_buffer,
|
||||
const uint8_t** rodata_buffer) {
|
||||
static bool ReadAppSnapshotDynamicLibrary(
|
||||
const char* script_name,
|
||||
const uint8_t** vm_data_buffer,
|
||||
const uint8_t** vm_instructions_buffer,
|
||||
const uint8_t** isolate_data_buffer,
|
||||
const uint8_t** isolate_instructions_buffer) {
|
||||
void* library = Extensions::LoadExtensionLibrary(script_name);
|
||||
if (library == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*vmisolate_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName));
|
||||
if (*vmisolate_buffer == NULL) {
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledVMIsolateSymbolName);
|
||||
*vm_data_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kVmSnapshotDataSymbolName));
|
||||
if (*vm_data_buffer == NULL) {
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n", kVmSnapshotDataSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*isolate_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName));
|
||||
if (*isolate_buffer == NULL) {
|
||||
*vm_instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kVmSnapshotInstructionsSymbolName));
|
||||
if (*vm_instructions_buffer == NULL) {
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledIsolateSymbolName);
|
||||
kVmSnapshotInstructionsSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName));
|
||||
if (*instructions_buffer == NULL) {
|
||||
*isolate_data_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kIsolateSnapshotDataSymbolName));
|
||||
if (*isolate_data_buffer == NULL) {
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledInstructionsSymbolName);
|
||||
kIsolateSnapshotDataSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*rodata_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName));
|
||||
if (*rodata_buffer == NULL) {
|
||||
*isolate_instructions_buffer =
|
||||
reinterpret_cast<const uint8_t*>(Extensions::ResolveSymbol(
|
||||
library, kIsolateSnapshotInstructionsSymbolName));
|
||||
if (*isolate_instructions_buffer == NULL) {
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledDataSymbolName);
|
||||
kIsolateSnapshotInstructionsSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
@@ -1417,26 +1429,26 @@ static bool ReadAppSnapshotDynamicLibrary(const char* script_name,
|
||||
|
||||
|
||||
static bool ReadAppSnapshot(const char* script_name,
|
||||
const uint8_t** vmisolate_buffer,
|
||||
const uint8_t** isolate_buffer,
|
||||
const uint8_t** instructions_buffer,
|
||||
const uint8_t** rodata_buffer) {
|
||||
const uint8_t** vm_data_buffer,
|
||||
const uint8_t** vm_instructions_buffer,
|
||||
const uint8_t** isolate_data_buffer,
|
||||
const uint8_t** isolate_instructions_buffer) {
|
||||
if (File::GetType(script_name, true) != File::kIsFile) {
|
||||
// If 'script_name' refers to a pipe, don't read to check for an app
|
||||
// snapshot since we cannot rewind if it isn't (and couldn't mmap it in
|
||||
// anyway if it was).
|
||||
return false;
|
||||
}
|
||||
if (ReadAppSnapshotBlobs(script_name, vmisolate_buffer, isolate_buffer,
|
||||
instructions_buffer, rodata_buffer)) {
|
||||
if (ReadAppSnapshotBlobs(script_name, vm_data_buffer, vm_instructions_buffer,
|
||||
isolate_data_buffer, isolate_instructions_buffer)) {
|
||||
return true;
|
||||
}
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
// For testing AOT with the standalone embedder, we also support loading
|
||||
// from a dynamic library to simulate what happens on iOS.
|
||||
return ReadAppSnapshotDynamicLibrary(script_name, vmisolate_buffer,
|
||||
isolate_buffer, instructions_buffer,
|
||||
rodata_buffer);
|
||||
return ReadAppSnapshotDynamicLibrary(
|
||||
script_name, vm_data_buffer, vm_instructions_buffer, isolate_data_buffer,
|
||||
isolate_instructions_buffer);
|
||||
#else
|
||||
return false;
|
||||
#endif // defined(DART_PRECOMPILED_RUNTIME)
|
||||
@@ -1449,47 +1461,48 @@ static bool WriteInt64(File* file, int64_t size) {
|
||||
|
||||
|
||||
static void WriteAppSnapshot(const char* filename,
|
||||
uint8_t* vmisolate_buffer,
|
||||
intptr_t vmisolate_size,
|
||||
uint8_t* isolate_buffer,
|
||||
intptr_t isolate_size,
|
||||
uint8_t* instructions_buffer,
|
||||
intptr_t instructions_size,
|
||||
uint8_t* rodata_buffer,
|
||||
intptr_t rodata_size) {
|
||||
uint8_t* vm_data_buffer,
|
||||
intptr_t vm_data_size,
|
||||
uint8_t* vm_instructions_buffer,
|
||||
intptr_t vm_instructions_size,
|
||||
uint8_t* isolate_data_buffer,
|
||||
intptr_t isolate_data_size,
|
||||
uint8_t* isolate_instructions_buffer,
|
||||
intptr_t isolate_instructions_size) {
|
||||
File* file = File::Open(filename, File::kWriteTruncate);
|
||||
if (file == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
|
||||
}
|
||||
|
||||
file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber));
|
||||
WriteInt64(file, vmisolate_size);
|
||||
WriteInt64(file, isolate_size);
|
||||
WriteInt64(file, rodata_size);
|
||||
WriteInt64(file, instructions_size);
|
||||
WriteInt64(file, vm_data_size);
|
||||
WriteInt64(file, vm_instructions_size);
|
||||
WriteInt64(file, isolate_data_size);
|
||||
WriteInt64(file, isolate_instructions_size);
|
||||
ASSERT(file->Position() == kAppSnapshotHeaderSize);
|
||||
|
||||
file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
|
||||
if (!file->WriteFully(vmisolate_buffer, vmisolate_size)) {
|
||||
if (!file->WriteFully(vm_data_buffer, vm_data_size)) {
|
||||
ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
|
||||
}
|
||||
|
||||
file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
|
||||
if (!file->WriteFully(isolate_buffer, isolate_size)) {
|
||||
ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
|
||||
}
|
||||
|
||||
if (rodata_size != 0) {
|
||||
if (vm_instructions_size != 0) {
|
||||
file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
|
||||
if (!file->WriteFully(rodata_buffer, rodata_size)) {
|
||||
if (!file->WriteFully(vm_instructions_buffer, vm_instructions_size)) {
|
||||
ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n",
|
||||
filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (instructions_size != 0) {
|
||||
file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
|
||||
if (!file->WriteFully(isolate_data_buffer, isolate_data_size)) {
|
||||
ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
|
||||
}
|
||||
|
||||
if (isolate_instructions_size != 0) {
|
||||
file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
|
||||
if (!file->WriteFully(instructions_buffer, instructions_size)) {
|
||||
if (!file->WriteFully(isolate_instructions_buffer,
|
||||
isolate_instructions_size)) {
|
||||
ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n",
|
||||
filename);
|
||||
}
|
||||
@@ -1513,61 +1526,64 @@ static void GenerateScriptSnapshot() {
|
||||
}
|
||||
|
||||
|
||||
static void GeneratePrecompiledSnapshot() {
|
||||
uint8_t* vm_isolate_buffer = NULL;
|
||||
intptr_t vm_isolate_size = 0;
|
||||
uint8_t* isolate_buffer = NULL;
|
||||
intptr_t isolate_size = 0;
|
||||
uint8_t* assembly_buffer = NULL;
|
||||
intptr_t assembly_size = 0;
|
||||
uint8_t* instructions_blob_buffer = NULL;
|
||||
intptr_t instructions_blob_size = 0;
|
||||
uint8_t* rodata_blob_buffer = NULL;
|
||||
intptr_t rodata_blob_size = 0;
|
||||
Dart_Handle result;
|
||||
if (use_blobs) {
|
||||
result = Dart_CreateAppAOTSnapshotAsBlobs(
|
||||
&vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size,
|
||||
&instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer,
|
||||
&rodata_blob_size);
|
||||
} else {
|
||||
result =
|
||||
Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size);
|
||||
}
|
||||
static void GenerateAppAOTSnapshotAsBlobs() {
|
||||
uint8_t* vm_data_buffer = NULL;
|
||||
intptr_t vm_data_size = 0;
|
||||
uint8_t* vm_instructions_buffer = NULL;
|
||||
intptr_t vm_instructions_size = 0;
|
||||
uint8_t* isolate_data_buffer = NULL;
|
||||
intptr_t isolate_data_size = 0;
|
||||
uint8_t* isolate_instructions_buffer = NULL;
|
||||
intptr_t isolate_instructions_size = 0;
|
||||
Dart_Handle result = Dart_CreateAppAOTSnapshotAsBlobs(
|
||||
&vm_data_buffer, &vm_data_size, &vm_instructions_buffer,
|
||||
&vm_instructions_size, &isolate_data_buffer, &isolate_data_size,
|
||||
&isolate_instructions_buffer, &isolate_instructions_size);
|
||||
if (Dart_IsError(result)) {
|
||||
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
|
||||
}
|
||||
WriteAppSnapshot(snapshot_filename, vm_data_buffer, vm_data_size,
|
||||
vm_instructions_buffer, vm_instructions_size,
|
||||
isolate_data_buffer, isolate_data_size,
|
||||
isolate_instructions_buffer, isolate_instructions_size);
|
||||
}
|
||||
|
||||
static void GenerateAppAOTSnapshotAsAssembly() {
|
||||
uint8_t* assembly_buffer = NULL;
|
||||
intptr_t assembly_size = 0;
|
||||
Dart_Handle result =
|
||||
Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size);
|
||||
if (Dart_IsError(result)) {
|
||||
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
|
||||
}
|
||||
WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size);
|
||||
}
|
||||
|
||||
|
||||
static void GenerateAppAOTSnapshot() {
|
||||
if (use_blobs) {
|
||||
WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size,
|
||||
isolate_buffer, isolate_size, instructions_blob_buffer,
|
||||
instructions_blob_size, rodata_blob_buffer,
|
||||
rodata_blob_size);
|
||||
GenerateAppAOTSnapshotAsBlobs();
|
||||
} else {
|
||||
WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size);
|
||||
GenerateAppAOTSnapshotAsAssembly();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void GenerateAppJITSnapshot() {
|
||||
#if defined(TARGET_ARCH_X64)
|
||||
uint8_t* vm_isolate_buffer = NULL;
|
||||
intptr_t vm_isolate_size = 0;
|
||||
uint8_t* isolate_buffer = NULL;
|
||||
intptr_t isolate_size = 0;
|
||||
uint8_t* instructions_blob_buffer = NULL;
|
||||
intptr_t instructions_blob_size = 0;
|
||||
uint8_t* rodata_blob_buffer = NULL;
|
||||
intptr_t rodata_blob_size = 0;
|
||||
uint8_t* isolate_data_buffer = NULL;
|
||||
intptr_t isolate_data_size = 0;
|
||||
uint8_t* isolate_instructions_buffer = NULL;
|
||||
intptr_t isolate_instructions_size = 0;
|
||||
Dart_Handle result = Dart_CreateAppJITSnapshotAsBlobs(
|
||||
&isolate_buffer, &isolate_size, &instructions_blob_buffer,
|
||||
&instructions_blob_size, &rodata_blob_buffer, &rodata_blob_size);
|
||||
&isolate_data_buffer, &isolate_data_size, &isolate_instructions_buffer,
|
||||
&isolate_instructions_size);
|
||||
if (Dart_IsError(result)) {
|
||||
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
|
||||
}
|
||||
WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size,
|
||||
isolate_buffer, isolate_size, instructions_blob_buffer,
|
||||
instructions_blob_size, rodata_blob_buffer,
|
||||
rodata_blob_size);
|
||||
WriteAppSnapshot(snapshot_filename, NULL, 0, NULL, 0, isolate_data_buffer,
|
||||
isolate_data_size, isolate_instructions_buffer,
|
||||
isolate_instructions_size);
|
||||
#else
|
||||
uint8_t* isolate_buffer = NULL;
|
||||
intptr_t isolate_size = 0;
|
||||
@@ -1578,8 +1594,8 @@ static void GenerateAppJITSnapshot() {
|
||||
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
|
||||
}
|
||||
|
||||
WriteAppSnapshot(snapshot_filename, NULL, 0, isolate_buffer, isolate_size,
|
||||
NULL, 0, NULL, 0);
|
||||
WriteAppSnapshot(snapshot_filename, NULL, 0, NULL, 0, isolate_buffer,
|
||||
isolate_size, NULL, 0);
|
||||
#endif // defined(TARGET_ARCH_X64)
|
||||
}
|
||||
|
||||
@@ -1747,7 +1763,7 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
|
||||
}
|
||||
|
||||
if (gen_snapshot_kind == kAppAOT) {
|
||||
GeneratePrecompiledSnapshot();
|
||||
GenerateAppAOTSnapshot();
|
||||
} else {
|
||||
if (Dart_IsNull(root_lib)) {
|
||||
ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n",
|
||||
@@ -1945,11 +1961,9 @@ void main(int argc, char** argv) {
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
const uint8_t* instructions_snapshot = NULL;
|
||||
const uint8_t* data_snapshot = NULL;
|
||||
if (ReadAppSnapshot(script_name, &vm_isolate_snapshot_buffer,
|
||||
&app_isolate_snapshot_buffer, &instructions_snapshot,
|
||||
&data_snapshot)) {
|
||||
if (ReadAppSnapshot(script_name, &vm_snapshot_data, &vm_snapshot_instructions,
|
||||
&app_isolate_snapshot_data,
|
||||
&app_isolate_snapshot_instructions)) {
|
||||
vm_run_app_snapshot = true;
|
||||
}
|
||||
|
||||
@@ -1986,9 +2000,8 @@ void main(int argc, char** argv) {
|
||||
Dart_InitializeParams init_params;
|
||||
memset(&init_params, 0, sizeof(init_params));
|
||||
init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
|
||||
init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer;
|
||||
init_params.instructions_snapshot = instructions_snapshot;
|
||||
init_params.data_snapshot = data_snapshot;
|
||||
init_params.vm_snapshot_data = vm_snapshot_data;
|
||||
init_params.vm_snapshot_instructions = vm_snapshot_instructions;
|
||||
init_params.create = CreateIsolateAndSetup;
|
||||
init_params.shutdown = ShutdownIsolate;
|
||||
init_params.file_open = DartUtils::OpenFile;
|
||||
|
||||
@@ -19,9 +19,10 @@ namespace dart {
|
||||
// Defined in vm/os_thread_win.cc
|
||||
extern bool private_flag_windows_run_tls_destructors;
|
||||
|
||||
// vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we
|
||||
// vm_snapshot_data_buffer points to a snapshot for the vm isolate if we
|
||||
// link in a snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* bin::vm_isolate_snapshot_buffer;
|
||||
extern const uint8_t* bin::vm_snapshot_data;
|
||||
extern const uint8_t* bin::vm_snapshot_instructions;
|
||||
|
||||
// Only run tests that match the filter string. The default does not match any
|
||||
// tests.
|
||||
@@ -108,10 +109,10 @@ static int Main(int argc, const char** argv) {
|
||||
Flags::ProcessCommandLineFlags(dart_argc, dart_argv);
|
||||
ASSERT(set_vm_flags_success);
|
||||
const char* err_msg = Dart::InitOnce(
|
||||
dart::bin::vm_isolate_snapshot_buffer, NULL, NULL, NULL, NULL, NULL,
|
||||
dart::bin::DartUtils::OpenFile, dart::bin::DartUtils::ReadFile,
|
||||
dart::bin::DartUtils::WriteFile, dart::bin::DartUtils::CloseFile, NULL,
|
||||
NULL);
|
||||
dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, NULL,
|
||||
NULL, NULL, dart::bin::DartUtils::OpenFile,
|
||||
dart::bin::DartUtils::ReadFile, dart::bin::DartUtils::WriteFile,
|
||||
dart::bin::DartUtils::CloseFile, NULL, NULL);
|
||||
ASSERT(err_msg == NULL);
|
||||
// Apply the filter to all registered tests.
|
||||
TestCaseBase::RunAll();
|
||||
|
||||
@@ -16,8 +16,10 @@ typedef unsigned __int8 uint8_t;
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
const uint8_t* vm_isolate_snapshot_buffer = NULL;
|
||||
const uint8_t* core_isolate_snapshot_buffer = NULL;
|
||||
const uint8_t* vm_snapshot_data = NULL;
|
||||
const uint8_t* vm_snapshot_instructions = NULL;
|
||||
const uint8_t* core_isolate_snapshot_data = NULL;
|
||||
const uint8_t* core_isolate_snapshot_instructions = NULL;
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
@@ -22,20 +22,22 @@ namespace bin {
|
||||
// generated snapshot binary file for the vm isolate.
|
||||
// This string forms the content of a vm isolate snapshot which is loaded
|
||||
// into the vm isolate.
|
||||
static const uint8_t vm_isolate_snapshot_buffer_[] = {
|
||||
static const uint8_t vm_snapshot_data_[] = {
|
||||
%s
|
||||
};
|
||||
const uint8_t* vm_isolate_snapshot_buffer = vm_isolate_snapshot_buffer_;
|
||||
const uint8_t* vm_snapshot_data = vm_snapshot_data_;
|
||||
const uint8_t* vm_snapshot_instructions = NULL;
|
||||
|
||||
|
||||
// The string on the next line will be filled in with the contents of the
|
||||
// generated snapshot binary file for a regular dart isolate.
|
||||
// This string forms the content of a regular dart isolate snapshot which is
|
||||
// loaded into an isolate when it is created.
|
||||
static const uint8_t core_isolate_snapshot_buffer_[] = {
|
||||
static const uint8_t core_isolate_snapshot_data_[] = {
|
||||
%s
|
||||
};
|
||||
const uint8_t* core_isolate_snapshot_buffer = core_isolate_snapshot_buffer_;
|
||||
const uint8_t* core_isolate_snapshot_data = core_isolate_snapshot_data_;
|
||||
const uint8_t* core_isolate_snapshot_instructions = NULL;
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
@@ -47,7 +47,7 @@ Dart_Isolate VmServiceServer::CreateIsolate(const uint8_t* snapshot_buffer) {
|
||||
char* error = 0;
|
||||
Dart_Isolate isolate =
|
||||
Dart_CreateIsolate(DART_VM_SERVICE_ISOLATE_NAME, "main", snapshot_buffer,
|
||||
NULL, isolate_data, &error);
|
||||
NULL, NULL, isolate_data, &error);
|
||||
if (!isolate) {
|
||||
fprintf(stderr, "Dart_CreateIsolate failed: %s\n", error);
|
||||
return 0;
|
||||
|
||||
+54
-49
@@ -773,7 +773,7 @@ typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)();
|
||||
* The current version of the Dart_InitializeFlags. Should be incremented every
|
||||
* time Dart_InitializeFlags changes in a binary incompatible way.
|
||||
*/
|
||||
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000001)
|
||||
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000002)
|
||||
|
||||
/**
|
||||
* Describes how to initialize the VM. Used with Dart_Initialize.
|
||||
@@ -794,9 +794,8 @@ typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)();
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t version;
|
||||
const uint8_t* vm_isolate_snapshot;
|
||||
const uint8_t* instructions_snapshot;
|
||||
const uint8_t* data_snapshot;
|
||||
const uint8_t* vm_snapshot_data;
|
||||
const uint8_t* vm_snapshot_instructions;
|
||||
Dart_IsolateCreateCallback create;
|
||||
Dart_IsolateShutdownCallback shutdown;
|
||||
Dart_ThreadExitCallback thread_exit;
|
||||
@@ -864,8 +863,9 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
|
||||
* Provided only for advisory purposes to improve debugging messages.
|
||||
* \param main The name of the main entry point this isolate will run.
|
||||
* Provided only for advisory purposes to improve debugging messages.
|
||||
* \param snapshot A buffer containing a snapshot of the isolate or
|
||||
* NULL if no snapshot is provided.
|
||||
* \param isolate_snapshot_data
|
||||
* \param isolate_snapshot_instructions Buffers containing a snapshot of the
|
||||
* isolate or NULL if no snapshot is provided.
|
||||
* \param flags Pointer to VM specific flags or NULL for default flags.
|
||||
* \param callback_data Embedder data. This data will be passed to
|
||||
* the Dart_IsolateCreateCallback when new isolates are spawned from
|
||||
@@ -875,12 +875,14 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
|
||||
* \return The new isolate is returned. May be NULL if an error
|
||||
* occurs during isolate initialization.
|
||||
*/
|
||||
DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri,
|
||||
const char* main,
|
||||
const uint8_t* snapshot,
|
||||
Dart_IsolateFlags* flags,
|
||||
void* callback_data,
|
||||
char** error);
|
||||
DART_EXPORT Dart_Isolate
|
||||
Dart_CreateIsolate(const char* script_uri,
|
||||
const char* main,
|
||||
const uint8_t* isolate_snapshot_data,
|
||||
const uint8_t* isolate_snapshot_instructions,
|
||||
Dart_IsolateFlags* flags,
|
||||
void* callback_data,
|
||||
char** error);
|
||||
/* TODO(turnidge): Document behavior when there is already a current
|
||||
* isolate. */
|
||||
|
||||
@@ -1009,10 +1011,10 @@ DART_EXPORT void Dart_ExitIsolate();
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer,
|
||||
intptr_t* vm_isolate_snapshot_size,
|
||||
uint8_t** isolate_snapshot_buffer,
|
||||
intptr_t* isolate_snapshot_size);
|
||||
Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer,
|
||||
intptr_t* vm_snapshot_data_size,
|
||||
uint8_t** isolate_snapshot_data_buffer,
|
||||
intptr_t* isolate_snapshot_data_size);
|
||||
|
||||
/**
|
||||
* Creates a snapshot of the application script loaded in the isolate.
|
||||
@@ -1030,8 +1032,9 @@ Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer,
|
||||
*
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
|
||||
intptr_t* size);
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer,
|
||||
intptr_t* script_snapshot_size);
|
||||
|
||||
/**
|
||||
* Schedules an interrupt for the specified isolate.
|
||||
@@ -2839,8 +2842,9 @@ DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
|
||||
* \return If no error occurs, the Library object corresponding to the root
|
||||
* script is returned. Otherwise an error handle is returned.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
|
||||
intptr_t buffer_len);
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_LoadScriptFromSnapshot(const uint8_t* script_snapshot_buffer,
|
||||
intptr_t script_snapshot_size);
|
||||
|
||||
/**
|
||||
* Loads a dart application via an in-memory kernel program.
|
||||
@@ -3218,14 +3222,18 @@ Dart_Precompile(Dart_QualifiedFunctionName entry_points[],
|
||||
* - A root library must have been loaded.
|
||||
* - Dart_Precompile must have been called.
|
||||
*
|
||||
* Outputs an assembly file defining the symbols kVmIsolateSnapshot,
|
||||
* kIsolateSnapshot, kInstructionsSnapshot and kDataSnapshot. The assembly
|
||||
* should be compiled as a static or shared library and linked or loaded by the
|
||||
* embedder.
|
||||
* Outputs an assembly file defining the symbols
|
||||
* - kDartVmSnapshotData
|
||||
* - kDartVmSnapshotInstructions
|
||||
* - kDartIsolateSnapshotData
|
||||
* - kDartIsolateSnapshotInstructions
|
||||
*
|
||||
* The assembly should be compiled as a static or shared library and linked or
|
||||
* loaded by the embedder.
|
||||
* Running this snapshot requires a VM compiled with DART_PRECOMPILED_SNAPSHOT.
|
||||
* The kVmIsolateSnapshot, kInstructionsSnapshot and kDataSnapshot should be
|
||||
* passed as arguments to Dart_Initialize. The kIsolateSnapshot snapshot should
|
||||
* be passed to Dart_CreateIsolate.
|
||||
* The kDartVmSnapshotData and kDartVmSnapshotInstructions should be passed to
|
||||
* Dart_Initialize. The kDartIsolateSnapshotData and
|
||||
* kDartIsoalteSnapshotInstructions should be passed to Dart_CreateIsolate.
|
||||
*
|
||||
* The buffers are scope allocated and are only valid until the next call to
|
||||
* Dart_ExitScope.
|
||||
@@ -3240,33 +3248,32 @@ Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer,
|
||||
/**
|
||||
* Same as Dart_CreateAppAOTSnapshotAsAssembly, except all the pieces are
|
||||
* provided directly as bytes that the embedder can load with mmap. The
|
||||
* instructions piece must be loaded with read and execute permissions; the
|
||||
* instructions pieces must be loaded with read and execute permissions; the
|
||||
* other pieces may be loaded as read-only.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer,
|
||||
intptr_t* vm_isolate_snapshot_size,
|
||||
uint8_t** isolate_snapshot_buffer,
|
||||
intptr_t* isolate_snapshot_size,
|
||||
uint8_t** instructions_blob_buffer,
|
||||
intptr_t* instructions_blob_size,
|
||||
uint8_t** rodata_blob_buffer,
|
||||
intptr_t* rodata_blob_size);
|
||||
Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer,
|
||||
intptr_t* vm_snapshot_data_size,
|
||||
uint8_t** vm_snapshot_instructions_buffer,
|
||||
intptr_t* vm_snapshot_instructions_size,
|
||||
uint8_t** isolate_snapshot_data_buffer,
|
||||
intptr_t* isolate_snapshot_data_size,
|
||||
uint8_t** isolate_snapshot_instructions_buffer,
|
||||
intptr_t* isolate_snapshot_instructions_size);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a snapshot that caches unoptimized code and type feedback for faster
|
||||
* Creates a snapshot that caches compiled code and type feedback for faster
|
||||
* startup and quicker warmup in a subsequent process.
|
||||
*
|
||||
* Outputs a snapshot in four pieces. The vm isolate snapshot,
|
||||
* instructions_blob and rodata_blob should be passed as arguments to
|
||||
* Dart_Initialize. The isolate snapshot should be passed to
|
||||
* Dart_CreateIsolate. The instructions piece must be loaded with execute
|
||||
* permissions; the other pieces may loaded as read-only.
|
||||
* Outputs a snapshot in two pieces. The pieces should be passed to
|
||||
* Dart_CreateIsolate in a VM using the same VM snapshot pieces used in the
|
||||
* current VM. The instructions piece must be loaded with read and execute
|
||||
* permissions; the data piece may be loaded as read-only.
|
||||
*
|
||||
* - Requires the VM to have been started with --load-deferred-eagerly.
|
||||
* - Requires the VM to have not been started with --precompilation.
|
||||
* - Not supported when targeting IA32.
|
||||
* - Not supported when targeting IA32 or DBC.
|
||||
* - The VM writing the snapshot and the VM reading the snapshot must be the
|
||||
* same version, must be built in the same DEBUG/RELEASE/PRODUCT mode, must
|
||||
* be targeting the same architecture, and must both be in checked mode or
|
||||
@@ -3278,12 +3285,10 @@ Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer,
|
||||
* \return A valid handle if no error occurs during the operation.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer,
|
||||
intptr_t* isolate_snapshot_size,
|
||||
uint8_t** instructions_blob_buffer,
|
||||
intptr_t* instructions_blob_size,
|
||||
uint8_t** rodata_blob_buffer,
|
||||
intptr_t* rodata_blob_size);
|
||||
Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer,
|
||||
intptr_t* isolate_snapshot_data_size,
|
||||
uint8_t** isolate_snapshot_instructions_buffer,
|
||||
intptr_t* isolate_snapshot_instructions_size);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -340,11 +340,12 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 12) {
|
||||
GET_NATIVE_ARGUMENT(String, packageRoot, arguments->NativeArgAt(10));
|
||||
GET_NATIVE_ARGUMENT(String, packageConfig, arguments->NativeArgAt(11));
|
||||
|
||||
if (Dart::snapshot_kind() == Snapshot::kAppAOT) {
|
||||
if (Dart::vm_snapshot_kind() == Snapshot::kAppAOT) {
|
||||
const Array& args = Array::Handle(Array::New(1));
|
||||
args.SetAt(
|
||||
0, String::Handle(String::New(
|
||||
"Isolate.spawnUri not supported when using AOT compilation")));
|
||||
0,
|
||||
String::Handle(String::New(
|
||||
"Isolate.spawnUri is not supported when using AOT compilation")));
|
||||
Exceptions::ThrowByType(Exceptions::kUnsupported, args);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
@@ -32,10 +32,6 @@ def BuildOptions():
|
||||
action="store", type="string",
|
||||
help="output file name into which isolate snapshot in binary form " +
|
||||
"is generated")
|
||||
result.add_option("--instructions_bin",
|
||||
action="store", type="string",
|
||||
help="output file name into which instructions snapshot in assembly " +
|
||||
"form is generated")
|
||||
result.add_option("--embedder_entry_points_manifest",
|
||||
action="store", type="string",
|
||||
help="input manifest with the vm entry points in a precompiled snapshot")
|
||||
@@ -120,14 +116,8 @@ def Main():
|
||||
script_args.append(''.join([ "--packages=", options.packages]))
|
||||
|
||||
# First setup the vm isolate and regular isolate snapshot output filename.
|
||||
script_args.append(''.join([ "--vm_isolate_snapshot=",
|
||||
options.vm_output_bin ]))
|
||||
script_args.append(''.join([ "--isolate_snapshot=", options.output_bin ]))
|
||||
|
||||
# Setup the instuctions snapshot output filename
|
||||
if options.instructions_bin:
|
||||
script_args.append(''.join([ "--instructions_snapshot=",
|
||||
options.instructions_bin ]))
|
||||
script_args.append(''.join([ "--vm_snapshot_data=", options.vm_output_bin ]))
|
||||
script_args.append(''.join([ "--isolate_snapshot_data=", options.output_bin ]))
|
||||
|
||||
# Specify the embedder entry points snapshot
|
||||
if options.embedder_entry_points_manifest:
|
||||
|
||||
@@ -95,9 +95,11 @@ void Benchmark::RunAll(const char* executable) {
|
||||
}
|
||||
|
||||
|
||||
Dart_Isolate Benchmark::CreateIsolate(const uint8_t* buffer) {
|
||||
Dart_Isolate Benchmark::CreateIsolate(const uint8_t* snapshot_data,
|
||||
const uint8_t* snapshot_instructions) {
|
||||
char* err = NULL;
|
||||
isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, NULL, &err);
|
||||
isolate_ = Dart_CreateIsolate(NULL, NULL, snapshot_data,
|
||||
snapshot_instructions, NULL, NULL, &err);
|
||||
EXPECT(isolate_ != NULL);
|
||||
free(err);
|
||||
return isolate_;
|
||||
@@ -509,24 +511,25 @@ BENCHMARK_SIZE(CoreSnapshotSize) {
|
||||
"\n";
|
||||
|
||||
// Start an Isolate, load a script and create a full snapshot.
|
||||
uint8_t* vm_isolate_snapshot_buffer;
|
||||
uint8_t* isolate_snapshot_buffer;
|
||||
uint8_t* vm_snapshot_data_buffer;
|
||||
uint8_t* isolate_snapshot_data_buffer;
|
||||
// Need to load the script into the dart: core library due to
|
||||
// the import of dart:_internal.
|
||||
TestCase::LoadCoreTestScript(kScriptChars, NULL);
|
||||
Api::CheckAndFinalizePendingClasses(thread);
|
||||
|
||||
// Write snapshot with object content.
|
||||
FullSnapshotWriter writer(Snapshot::kCore, &vm_isolate_snapshot_buffer,
|
||||
&isolate_snapshot_buffer, &malloc_allocator,
|
||||
NULL /* instructions_writer */);
|
||||
FullSnapshotWriter writer(Snapshot::kCore, &vm_snapshot_data_buffer,
|
||||
&isolate_snapshot_data_buffer, &malloc_allocator,
|
||||
NULL, NULL /* instructions_writer */);
|
||||
writer.WriteFullSnapshot();
|
||||
const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer);
|
||||
const Snapshot* snapshot =
|
||||
Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer);
|
||||
ASSERT(snapshot->kind() == Snapshot::kCore);
|
||||
benchmark->set_score(snapshot->length());
|
||||
|
||||
free(vm_isolate_snapshot_buffer);
|
||||
free(isolate_snapshot_buffer);
|
||||
free(vm_snapshot_data_buffer);
|
||||
free(isolate_snapshot_data_buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -546,24 +549,25 @@ BENCHMARK_SIZE(StandaloneSnapshotSize) {
|
||||
"\n";
|
||||
|
||||
// Start an Isolate, load a script and create a full snapshot.
|
||||
uint8_t* vm_isolate_snapshot_buffer;
|
||||
uint8_t* isolate_snapshot_buffer;
|
||||
uint8_t* vm_snapshot_data_buffer;
|
||||
uint8_t* isolate_snapshot_data_buffer;
|
||||
// Need to load the script into the dart: core library due to
|
||||
// the import of dart:_internal.
|
||||
TestCase::LoadCoreTestScript(kScriptChars, NULL);
|
||||
Api::CheckAndFinalizePendingClasses(thread);
|
||||
|
||||
// Write snapshot with object content.
|
||||
FullSnapshotWriter writer(Snapshot::kCore, &vm_isolate_snapshot_buffer,
|
||||
&isolate_snapshot_buffer, &malloc_allocator,
|
||||
NULL /* instructions_writer */);
|
||||
FullSnapshotWriter writer(Snapshot::kCore, &vm_snapshot_data_buffer,
|
||||
&isolate_snapshot_data_buffer, &malloc_allocator,
|
||||
NULL, NULL /* instructions_writer */);
|
||||
writer.WriteFullSnapshot();
|
||||
const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer);
|
||||
const Snapshot* snapshot =
|
||||
Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer);
|
||||
ASSERT(snapshot->kind() == Snapshot::kCore);
|
||||
benchmark->set_score(snapshot->length());
|
||||
|
||||
free(vm_isolate_snapshot_buffer);
|
||||
free(isolate_snapshot_buffer);
|
||||
free(vm_snapshot_data_buffer);
|
||||
free(isolate_snapshot_data_buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,13 +20,11 @@ DECLARE_FLAG(int, code_heap_size);
|
||||
DECLARE_FLAG(int, old_gen_growth_space_ratio);
|
||||
|
||||
namespace bin {
|
||||
// vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we
|
||||
// link in a snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* vm_isolate_snapshot_buffer;
|
||||
|
||||
// isolate_snapshot_buffer points to a snapshot for an isolate if we link in a
|
||||
// snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* core_isolate_snapshot_buffer;
|
||||
// Snapshot pieces if we link in a snapshot, otherwise initialized to NULL.
|
||||
extern const uint8_t* vm_snapshot_data;
|
||||
extern const uint8_t* vm_snapshot_instructions;
|
||||
extern const uint8_t* core_isolate_snapshot_data;
|
||||
extern const uint8_t* core_isolate_snapshot_instructions;
|
||||
}
|
||||
|
||||
// The BENCHMARK macros are used for benchmarking a specific functionality
|
||||
@@ -82,7 +80,8 @@ class Benchmark {
|
||||
int64_t score() const { return score_; }
|
||||
Isolate* isolate() const { return reinterpret_cast<Isolate*>(isolate_); }
|
||||
|
||||
Dart_Isolate CreateIsolate(const uint8_t* buffer);
|
||||
Dart_Isolate CreateIsolate(const uint8_t* snapshot_data,
|
||||
const uint8_t* snapshot_instructions);
|
||||
|
||||
void Run() { (*run_)(this); }
|
||||
void RunBenchmark();
|
||||
@@ -110,7 +109,8 @@ class Benchmark {
|
||||
class BenchmarkIsolateScope {
|
||||
public:
|
||||
explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) {
|
||||
benchmark_->CreateIsolate(bin::core_isolate_snapshot_buffer);
|
||||
benchmark_->CreateIsolate(bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions);
|
||||
Dart_EnterScope(); // Create a Dart API scope for unit benchmarks.
|
||||
}
|
||||
~BenchmarkIsolateScope() {
|
||||
|
||||
@@ -1662,8 +1662,7 @@ class CodeDeserializationCluster : public DeserializationCluster {
|
||||
is_vm_object);
|
||||
|
||||
int32_t text_offset = d->Read<int32_t>();
|
||||
RawInstructions* instr = reinterpret_cast<RawInstructions*>(
|
||||
d->GetInstructionsAt(text_offset) + kHeapObjectTag);
|
||||
RawInstructions* instr = d->GetInstructionsAt(text_offset);
|
||||
|
||||
code->ptr()->entry_point_ = Instructions::UncheckedEntryPoint(instr);
|
||||
code->ptr()->checked_entry_point_ =
|
||||
@@ -1674,8 +1673,7 @@ class CodeDeserializationCluster : public DeserializationCluster {
|
||||
#if !defined(DART_PRECOMPILED_RUNTIME)
|
||||
if (d->kind() == Snapshot::kAppJIT) {
|
||||
int32_t text_offset = d->Read<int32_t>();
|
||||
RawInstructions* instr = reinterpret_cast<RawInstructions*>(
|
||||
d->GetInstructionsAt(text_offset) + kHeapObjectTag);
|
||||
RawInstructions* instr = d->GetInstructionsAt(text_offset);
|
||||
code->ptr()->active_instructions_ = instr;
|
||||
code->ptr()->entry_point_ = Instructions::UncheckedEntryPoint(instr);
|
||||
code->ptr()->checked_entry_point_ =
|
||||
@@ -4795,8 +4793,8 @@ intptr_t Serializer::WriteVMSnapshot(const Array& symbols,
|
||||
}
|
||||
|
||||
|
||||
void Serializer::WriteFullSnapshot(intptr_t num_base_objects,
|
||||
ObjectStore* object_store) {
|
||||
void Serializer::WriteIsolateSnapshot(intptr_t num_base_objects,
|
||||
ObjectStore* object_store) {
|
||||
NoSafepointScope no_safepoint;
|
||||
|
||||
if (num_base_objects == 0) {
|
||||
@@ -5196,7 +5194,7 @@ void Deserializer::ReadVMSnapshot() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Deserializer::ReadFullSnapshot(ObjectStore* object_store) {
|
||||
void Deserializer::ReadIsolateSnapshot(ObjectStore* object_store) {
|
||||
Array& refs = Array::Handle();
|
||||
Prepare();
|
||||
|
||||
@@ -5282,23 +5280,30 @@ class SnapshotTokenStreamVisitor : public ObjectVisitor {
|
||||
};
|
||||
|
||||
|
||||
FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind,
|
||||
uint8_t** vm_isolate_snapshot_buffer,
|
||||
uint8_t** isolate_snapshot_buffer,
|
||||
ReAlloc alloc,
|
||||
InstructionsWriter* instructions_writer)
|
||||
FullSnapshotWriter::FullSnapshotWriter(
|
||||
Snapshot::Kind kind,
|
||||
uint8_t** vm_snapshot_data_buffer,
|
||||
uint8_t** isolate_snapshot_data_buffer,
|
||||
ReAlloc alloc,
|
||||
InstructionsWriter* vm_instructions_writer,
|
||||
InstructionsWriter* isolate_instructions_writer)
|
||||
: thread_(Thread::Current()),
|
||||
kind_(kind),
|
||||
vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer),
|
||||
isolate_snapshot_buffer_(isolate_snapshot_buffer),
|
||||
vm_snapshot_data_buffer_(vm_snapshot_data_buffer),
|
||||
isolate_snapshot_data_buffer_(isolate_snapshot_data_buffer),
|
||||
alloc_(alloc),
|
||||
vm_isolate_snapshot_size_(0),
|
||||
isolate_snapshot_size_(0),
|
||||
instructions_writer_(instructions_writer),
|
||||
vm_instructions_writer_(vm_instructions_writer),
|
||||
isolate_instructions_writer_(isolate_instructions_writer),
|
||||
token_streams_(Array::Handle(zone())),
|
||||
saved_symbol_table_(Array::Handle(zone())),
|
||||
new_vm_symbol_table_(Array::Handle(zone())) {
|
||||
ASSERT(isolate_snapshot_buffer_ != NULL);
|
||||
new_vm_symbol_table_(Array::Handle(zone())),
|
||||
clustered_vm_size_(0),
|
||||
clustered_isolate_size_(0),
|
||||
mapped_data_size_(0),
|
||||
mapped_instructions_size_(0) {
|
||||
ASSERT(isolate_snapshot_data_buffer_ != NULL);
|
||||
ASSERT(alloc_ != NULL);
|
||||
ASSERT(isolate() != NULL);
|
||||
ASSERT(ClassFinalizer::AllClassesFinalized());
|
||||
@@ -5314,7 +5319,7 @@ FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind,
|
||||
// Can't have any mutation happening while we're serializing.
|
||||
ASSERT(isolate()->background_compiler() == NULL);
|
||||
|
||||
if (vm_isolate_snapshot_buffer != NULL) {
|
||||
if (vm_snapshot_data_buffer != NULL) {
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds(
|
||||
thread(), Timeline::GetIsolateStream(), "PrepareNewVMIsolate"));
|
||||
|
||||
@@ -5358,90 +5363,114 @@ FullSnapshotWriter::~FullSnapshotWriter() {
|
||||
}
|
||||
|
||||
|
||||
intptr_t FullSnapshotWriter::WriteVmIsolateSnapshot() {
|
||||
intptr_t FullSnapshotWriter::WriteVMSnapshot() {
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds(
|
||||
thread(), Timeline::GetIsolateStream(), "WriteVmIsolateSnapshot"));
|
||||
thread(), Timeline::GetIsolateStream(), "WriteVMSnapshot"));
|
||||
|
||||
ASSERT(vm_isolate_snapshot_buffer_ != NULL);
|
||||
Serializer serializer(thread(), kind_, vm_isolate_snapshot_buffer_, alloc_,
|
||||
kInitialSize, instructions_writer_);
|
||||
ASSERT(vm_snapshot_data_buffer_ != NULL);
|
||||
Serializer serializer(thread(), kind_, vm_snapshot_data_buffer_, alloc_,
|
||||
kInitialSize, vm_instructions_writer_);
|
||||
|
||||
serializer.ReserveHeader();
|
||||
serializer.WriteVersionAndFeatures();
|
||||
/*
|
||||
* Now Write out the following
|
||||
* - the symbol table
|
||||
* - all the token streams
|
||||
* - the stub code (precompiled snapshots only)
|
||||
**/
|
||||
// VM snapshot roots are:
|
||||
// - the symbol table
|
||||
// - all the token streams
|
||||
// - the stub code (precompiled snapshots only)
|
||||
intptr_t num_objects =
|
||||
serializer.WriteVMSnapshot(new_vm_symbol_table_, token_streams_);
|
||||
serializer.FillHeader(serializer.kind());
|
||||
clustered_vm_size_ = serializer.bytes_written();
|
||||
|
||||
if (Snapshot::IncludesCode(kind_)) {
|
||||
vm_instructions_writer_->Write(serializer.stream(), true);
|
||||
mapped_data_size_ += vm_instructions_writer_->data_size();
|
||||
mapped_instructions_size_ += vm_instructions_writer_->text_size();
|
||||
vm_instructions_writer_->ResetOffsets();
|
||||
}
|
||||
|
||||
// The clustered part + the direct mapped data part.
|
||||
vm_isolate_snapshot_size_ = serializer.bytes_written();
|
||||
return num_objects;
|
||||
}
|
||||
|
||||
|
||||
void FullSnapshotWriter::WriteIsolateFullSnapshot(intptr_t num_base_objects) {
|
||||
void FullSnapshotWriter::WriteIsolateSnapshot(intptr_t num_base_objects) {
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds(
|
||||
thread(), Timeline::GetIsolateStream(), "WriteIsolateFullSnapshot"));
|
||||
thread(), Timeline::GetIsolateStream(), "WriteIsolateSnapshot"));
|
||||
|
||||
Serializer serializer(thread(), kind_, isolate_snapshot_buffer_, alloc_,
|
||||
kInitialSize, instructions_writer_);
|
||||
Serializer serializer(thread(), kind_, isolate_snapshot_data_buffer_, alloc_,
|
||||
kInitialSize, isolate_instructions_writer_);
|
||||
ObjectStore* object_store = isolate()->object_store();
|
||||
ASSERT(object_store != NULL);
|
||||
|
||||
serializer.ReserveHeader();
|
||||
serializer.WriteVersionAndFeatures();
|
||||
serializer.WriteFullSnapshot(num_base_objects, object_store);
|
||||
// Isolate snapshot roots are:
|
||||
// - the object store
|
||||
serializer.WriteIsolateSnapshot(num_base_objects, object_store);
|
||||
serializer.FillHeader(serializer.kind());
|
||||
clustered_isolate_size_ = serializer.bytes_written();
|
||||
|
||||
if (Snapshot::IncludesCode(kind_)) {
|
||||
isolate_instructions_writer_->Write(serializer.stream(), false);
|
||||
mapped_data_size_ += isolate_instructions_writer_->data_size();
|
||||
mapped_instructions_size_ += isolate_instructions_writer_->text_size();
|
||||
isolate_instructions_writer_->ResetOffsets();
|
||||
}
|
||||
|
||||
// The clustered part + the direct mapped data part.
|
||||
isolate_snapshot_size_ = serializer.bytes_written();
|
||||
}
|
||||
|
||||
|
||||
void FullSnapshotWriter::WriteFullSnapshot() {
|
||||
intptr_t num_base_objects;
|
||||
if (vm_isolate_snapshot_buffer() != NULL) {
|
||||
num_base_objects = WriteVmIsolateSnapshot();
|
||||
if (vm_snapshot_data_buffer() != NULL) {
|
||||
num_base_objects = WriteVMSnapshot();
|
||||
ASSERT(num_base_objects != 0);
|
||||
} else {
|
||||
num_base_objects = 0;
|
||||
}
|
||||
|
||||
WriteIsolateFullSnapshot(num_base_objects);
|
||||
WriteIsolateSnapshot(num_base_objects);
|
||||
|
||||
if (FLAG_print_snapshot_sizes) {
|
||||
OS::Print("VMIsolate(CodeSize): %" Pd "\n", VmIsolateSnapshotSize());
|
||||
OS::Print("Isolate(CodeSize): %" Pd "\n", IsolateSnapshotSize());
|
||||
}
|
||||
intptr_t total_size = VmIsolateSnapshotSize() + IsolateSnapshotSize();
|
||||
|
||||
if (Snapshot::IncludesCode(kind_)) {
|
||||
instructions_writer_->Write(
|
||||
vm_isolate_snapshot_buffer_ == NULL ? NULL
|
||||
: *vm_isolate_snapshot_buffer_,
|
||||
vm_isolate_snapshot_size_, *isolate_snapshot_buffer_,
|
||||
isolate_snapshot_size_);
|
||||
|
||||
if (FLAG_print_snapshot_sizes) {
|
||||
OS::Print("ReadOnlyData(CodeSize): %" Pd "\n",
|
||||
instructions_writer_->data_size());
|
||||
OS::Print("Instructions(CodeSize): %" Pd "\n",
|
||||
instructions_writer_->text_size());
|
||||
}
|
||||
total_size +=
|
||||
instructions_writer_->data_size() + instructions_writer_->text_size();
|
||||
}
|
||||
|
||||
if (FLAG_print_snapshot_sizes) {
|
||||
OS::Print("Total(CodeSize): %" Pd "\n", total_size);
|
||||
OS::Print("VMIsolate(CodeSize): %" Pd "\n", clustered_vm_size_);
|
||||
OS::Print("Isolate(CodeSize): %" Pd "\n", clustered_isolate_size_);
|
||||
OS::Print("ReadOnlyData(CodeSize): %" Pd "\n", mapped_data_size_);
|
||||
OS::Print("Instructions(CodeSize): %" Pd "\n", mapped_instructions_size_);
|
||||
OS::Print("Total(CodeSize): %" Pd "\n",
|
||||
clustered_vm_size_ + clustered_isolate_size_ + mapped_data_size_ +
|
||||
mapped_instructions_size_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RawApiError* IsolateSnapshotReader::ReadFullSnapshot() {
|
||||
static const uint8_t* DataBuffer(const Snapshot* snapshot) {
|
||||
if (Snapshot::IncludesCode(snapshot->kind())) {
|
||||
uword offset =
|
||||
Utils::RoundUp(snapshot->length(), OS::kMaxPreferredCodeAlignment);
|
||||
return snapshot->Addr() + offset;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
FullSnapshotReader::FullSnapshotReader(const Snapshot* snapshot,
|
||||
const uint8_t* instructions_buffer,
|
||||
Thread* thread)
|
||||
: kind_(snapshot->kind()),
|
||||
thread_(thread),
|
||||
buffer_(snapshot->content()),
|
||||
size_(snapshot->length()),
|
||||
instructions_buffer_(instructions_buffer),
|
||||
data_buffer_(DataBuffer(snapshot)) {
|
||||
thread->isolate()->set_compilation_allowed(kind_ != Snapshot::kAppAOT);
|
||||
}
|
||||
|
||||
|
||||
RawApiError* FullSnapshotReader::ReadVMSnapshot() {
|
||||
Deserializer deserializer(thread_, kind_, buffer_, size_,
|
||||
instructions_buffer_, data_buffer_);
|
||||
|
||||
@@ -5450,13 +5479,20 @@ RawApiError* IsolateSnapshotReader::ReadFullSnapshot() {
|
||||
return error;
|
||||
}
|
||||
|
||||
deserializer.ReadFullSnapshot(thread_->isolate()->object_store());
|
||||
if (instructions_buffer_ != NULL) {
|
||||
thread_->isolate()->SetupInstructionsSnapshotPage(instructions_buffer_);
|
||||
}
|
||||
if (data_buffer_ != NULL) {
|
||||
thread_->isolate()->SetupDataSnapshotPage(data_buffer_);
|
||||
}
|
||||
|
||||
deserializer.ReadVMSnapshot();
|
||||
|
||||
return ApiError::null();
|
||||
}
|
||||
|
||||
|
||||
RawApiError* VmIsolateSnapshotReader::ReadVmIsolateSnapshot() {
|
||||
RawApiError* FullSnapshotReader::ReadIsolateSnapshot() {
|
||||
Deserializer deserializer(thread_, kind_, buffer_, size_,
|
||||
instructions_buffer_, data_buffer_);
|
||||
|
||||
@@ -5465,10 +5501,14 @@ RawApiError* VmIsolateSnapshotReader::ReadVmIsolateSnapshot() {
|
||||
return error;
|
||||
}
|
||||
|
||||
deserializer.ReadVMSnapshot();
|
||||
if (instructions_buffer_ != NULL) {
|
||||
thread_->isolate()->SetupInstructionsSnapshotPage(instructions_buffer_);
|
||||
}
|
||||
if (data_buffer_ != NULL) {
|
||||
thread_->isolate()->SetupDataSnapshotPage(data_buffer_);
|
||||
}
|
||||
|
||||
Dart::set_instructions_snapshot_buffer(instructions_buffer_);
|
||||
Dart::set_data_snapshot_buffer(data_buffer_);
|
||||
deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store());
|
||||
|
||||
return ApiError::null();
|
||||
}
|
||||
|
||||
@@ -123,7 +123,8 @@ class Serializer : public StackResource {
|
||||
~Serializer();
|
||||
|
||||
intptr_t WriteVMSnapshot(const Array& symbols, const Array& scripts);
|
||||
void WriteFullSnapshot(intptr_t num_base_objects, ObjectStore* object_store);
|
||||
void WriteIsolateSnapshot(intptr_t num_base_objects,
|
||||
ObjectStore* object_store);
|
||||
|
||||
void AddVMIsolateBaseObjects();
|
||||
|
||||
@@ -206,6 +207,7 @@ class Serializer : public StackResource {
|
||||
void WriteVersionAndFeatures();
|
||||
|
||||
void Serialize();
|
||||
WriteStream* stream() { return &stream_; }
|
||||
intptr_t bytes_written() { return stream_.bytes_written(); }
|
||||
|
||||
// Writes raw data to the stream (basic type).
|
||||
@@ -294,7 +296,7 @@ class Deserializer : public StackResource {
|
||||
const uint8_t* data_buffer);
|
||||
~Deserializer();
|
||||
|
||||
void ReadFullSnapshot(ObjectStore* object_store);
|
||||
void ReadIsolateSnapshot(ObjectStore* object_store);
|
||||
void ReadVMSnapshot();
|
||||
|
||||
void AddVMIsolateBaseObjects();
|
||||
@@ -350,7 +352,7 @@ class Deserializer : public StackResource {
|
||||
return Read<int32_t>();
|
||||
}
|
||||
|
||||
uword GetInstructionsAt(int32_t offset) {
|
||||
RawInstructions* GetInstructionsAt(int32_t offset) {
|
||||
return instructions_reader_->GetInstructionsAt(offset);
|
||||
}
|
||||
|
||||
@@ -387,17 +389,18 @@ class FullSnapshotWriter {
|
||||
public:
|
||||
static const intptr_t kInitialSize = 64 * KB;
|
||||
FullSnapshotWriter(Snapshot::Kind kind,
|
||||
uint8_t** vm_isolate_snapshot_buffer,
|
||||
uint8_t** isolate_snapshot_buffer,
|
||||
uint8_t** vm_snapshot_data_buffer,
|
||||
uint8_t** isolate_snapshot_data_buffer,
|
||||
ReAlloc alloc,
|
||||
InstructionsWriter* instructions_writer);
|
||||
InstructionsWriter* vm_instructions_writer,
|
||||
InstructionsWriter* iso_instructions_writer);
|
||||
~FullSnapshotWriter();
|
||||
|
||||
uint8_t** vm_isolate_snapshot_buffer() const {
|
||||
return vm_isolate_snapshot_buffer_;
|
||||
}
|
||||
uint8_t** vm_snapshot_data_buffer() const { return vm_snapshot_data_buffer_; }
|
||||
|
||||
uint8_t** isolate_snapshot_buffer() const { return isolate_snapshot_buffer_; }
|
||||
uint8_t** isolate_snapshot_data_buffer() const {
|
||||
return isolate_snapshot_data_buffer_;
|
||||
}
|
||||
|
||||
Thread* thread() const { return thread_; }
|
||||
Zone* zone() const { return thread_->zone(); }
|
||||
@@ -412,48 +415,44 @@ class FullSnapshotWriter {
|
||||
|
||||
private:
|
||||
// Writes a snapshot of the VM Isolate.
|
||||
intptr_t WriteVmIsolateSnapshot();
|
||||
intptr_t WriteVMSnapshot();
|
||||
|
||||
// Writes a full snapshot of a regular Dart Isolate.
|
||||
void WriteIsolateFullSnapshot(intptr_t num_base_objects);
|
||||
void WriteIsolateSnapshot(intptr_t num_base_objects);
|
||||
|
||||
Thread* thread_;
|
||||
Snapshot::Kind kind_;
|
||||
uint8_t** vm_isolate_snapshot_buffer_;
|
||||
uint8_t** isolate_snapshot_buffer_;
|
||||
uint8_t** vm_snapshot_data_buffer_;
|
||||
uint8_t** isolate_snapshot_data_buffer_;
|
||||
ReAlloc alloc_;
|
||||
intptr_t vm_isolate_snapshot_size_;
|
||||
intptr_t isolate_snapshot_size_;
|
||||
ForwardList* forward_list_;
|
||||
InstructionsWriter* instructions_writer_;
|
||||
InstructionsWriter* vm_instructions_writer_;
|
||||
InstructionsWriter* isolate_instructions_writer_;
|
||||
Array& token_streams_;
|
||||
Array& saved_symbol_table_;
|
||||
Array& new_vm_symbol_table_;
|
||||
|
||||
// Stats for benchmarking.
|
||||
intptr_t clustered_vm_size_;
|
||||
intptr_t clustered_isolate_size_;
|
||||
intptr_t mapped_data_size_;
|
||||
intptr_t mapped_instructions_size_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter);
|
||||
};
|
||||
|
||||
|
||||
class VmIsolateSnapshotReader {
|
||||
class FullSnapshotReader {
|
||||
public:
|
||||
VmIsolateSnapshotReader(Snapshot::Kind kind,
|
||||
const uint8_t* buffer,
|
||||
intptr_t size,
|
||||
const uint8_t* instructions_buffer,
|
||||
const uint8_t* data_buffer,
|
||||
Thread* thread)
|
||||
: kind_(kind),
|
||||
thread_(thread),
|
||||
buffer_(buffer),
|
||||
size_(size),
|
||||
instructions_buffer_(instructions_buffer),
|
||||
data_buffer_(data_buffer) {
|
||||
thread->isolate()->set_compilation_allowed(kind != Snapshot::kAppAOT);
|
||||
}
|
||||
FullSnapshotReader(const Snapshot* snapshot,
|
||||
const uint8_t* instructions_buffer,
|
||||
Thread* thread);
|
||||
~FullSnapshotReader() {}
|
||||
|
||||
~VmIsolateSnapshotReader() {}
|
||||
|
||||
RawApiError* ReadVmIsolateSnapshot();
|
||||
RawApiError* ReadVMSnapshot();
|
||||
RawApiError* ReadIsolateSnapshot();
|
||||
|
||||
private:
|
||||
Snapshot::Kind kind_;
|
||||
@@ -463,40 +462,7 @@ class VmIsolateSnapshotReader {
|
||||
const uint8_t* instructions_buffer_;
|
||||
const uint8_t* data_buffer_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(VmIsolateSnapshotReader);
|
||||
};
|
||||
|
||||
|
||||
class IsolateSnapshotReader {
|
||||
public:
|
||||
IsolateSnapshotReader(Snapshot::Kind kind,
|
||||
const uint8_t* buffer,
|
||||
intptr_t size,
|
||||
const uint8_t* instructions_buffer,
|
||||
const uint8_t* data_buffer,
|
||||
Thread* thread)
|
||||
: kind_(kind),
|
||||
thread_(thread),
|
||||
buffer_(buffer),
|
||||
size_(size),
|
||||
instructions_buffer_(instructions_buffer),
|
||||
data_buffer_(data_buffer) {
|
||||
thread->isolate()->set_compilation_allowed(kind != Snapshot::kAppAOT);
|
||||
}
|
||||
|
||||
~IsolateSnapshotReader() {}
|
||||
|
||||
RawApiError* ReadFullSnapshot();
|
||||
|
||||
private:
|
||||
Snapshot::Kind kind_;
|
||||
Thread* thread_;
|
||||
const uint8_t* buffer_;
|
||||
intptr_t size_;
|
||||
const uint8_t* instructions_buffer_;
|
||||
const uint8_t* data_buffer_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IsolateSnapshotReader);
|
||||
DISALLOW_COPY_AND_ASSIGN(FullSnapshotReader);
|
||||
};
|
||||
|
||||
} // namespace dart
|
||||
|
||||
+30
-39
@@ -48,9 +48,7 @@ int64_t Dart::start_time_micros_ = 0;
|
||||
ThreadPool* Dart::thread_pool_ = NULL;
|
||||
DebugInfo* Dart::pprof_symbol_generator_ = NULL;
|
||||
ReadOnlyHandles* Dart::predefined_handles_ = NULL;
|
||||
Snapshot::Kind Dart::snapshot_kind_ = Snapshot::kInvalid;
|
||||
const uint8_t* Dart::instructions_snapshot_buffer_ = NULL;
|
||||
const uint8_t* Dart::data_snapshot_buffer_ = NULL;
|
||||
Snapshot::Kind Dart::vm_snapshot_kind_ = Snapshot::kInvalid;
|
||||
Dart_ThreadExitCallback Dart::thread_exit_callback_ = NULL;
|
||||
Dart_FileOpenCallback Dart::file_open_callback_ = NULL;
|
||||
Dart_FileReadCallback Dart::file_read_callback_ = NULL;
|
||||
@@ -124,7 +122,6 @@ static void CheckOffsets() {
|
||||
|
||||
char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot,
|
||||
const uint8_t* instructions_snapshot,
|
||||
const uint8_t* data_snapshot,
|
||||
Dart_IsolateCreateCallback create,
|
||||
Dart_IsolateShutdownCallback shutdown,
|
||||
Dart_ThreadExitCallback thread_exit,
|
||||
@@ -213,10 +210,10 @@ char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot,
|
||||
if (snapshot == NULL) {
|
||||
return strdup("Invalid vm isolate snapshot seen");
|
||||
}
|
||||
snapshot_kind_ = snapshot->kind();
|
||||
vm_snapshot_kind_ = snapshot->kind();
|
||||
|
||||
if (Snapshot::IncludesCode(snapshot_kind_)) {
|
||||
if (snapshot_kind_ == Snapshot::kAppAOT) {
|
||||
if (Snapshot::IncludesCode(vm_snapshot_kind_)) {
|
||||
if (vm_snapshot_kind_ == Snapshot::kAppAOT) {
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
vm_isolate_->set_compilation_allowed(false);
|
||||
if (!FLAG_precompiled_runtime) {
|
||||
@@ -229,10 +226,7 @@ char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot,
|
||||
if (instructions_snapshot == NULL) {
|
||||
return strdup("Missing instructions snapshot");
|
||||
}
|
||||
if (data_snapshot == NULL) {
|
||||
return strdup("Missing rodata snapshot");
|
||||
}
|
||||
} else if (Snapshot::IsFull(snapshot_kind_)) {
|
||||
} else if (Snapshot::IsFull(vm_snapshot_kind_)) {
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
return strdup("Precompiled runtime requires a precompiled snapshot");
|
||||
#else
|
||||
@@ -241,16 +235,8 @@ char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot,
|
||||
} else {
|
||||
return strdup("Invalid vm isolate snapshot seen");
|
||||
}
|
||||
if (instructions_snapshot != NULL) {
|
||||
vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot);
|
||||
}
|
||||
if (instructions_snapshot != NULL) {
|
||||
vm_isolate_->SetupDataSnapshotPage(data_snapshot);
|
||||
}
|
||||
VmIsolateSnapshotReader reader(snapshot->kind(), snapshot->content(),
|
||||
snapshot->length(), instructions_snapshot,
|
||||
data_snapshot, T);
|
||||
const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot());
|
||||
FullSnapshotReader reader(snapshot, instructions_snapshot, T);
|
||||
const Error& error = Error::Handle(reader.ReadVMSnapshot());
|
||||
if (!error.IsNull()) {
|
||||
// Must copy before leaving the zone.
|
||||
return strdup(error.ToErrorCString());
|
||||
@@ -281,7 +267,7 @@ char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot,
|
||||
#elif !defined(DART_NO_SNAPSHOT)
|
||||
return strdup("Missing vm isolate snapshot");
|
||||
#else
|
||||
snapshot_kind_ = Snapshot::kNone;
|
||||
vm_snapshot_kind_ = Snapshot::kNone;
|
||||
StubCode::InitOnce();
|
||||
Symbols::InitOnce(vm_isolate_);
|
||||
#endif
|
||||
@@ -504,7 +490,17 @@ Isolate* Dart::CreateIsolate(const char* name_prefix,
|
||||
}
|
||||
|
||||
|
||||
RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer,
|
||||
static bool IsSnapshotCompatible(Snapshot::Kind vm_kind,
|
||||
Snapshot::Kind isolate_kind) {
|
||||
if (vm_kind == isolate_kind) return true;
|
||||
if (vm_kind == Snapshot::kCore && isolate_kind == Snapshot::kAppJIT)
|
||||
return true;
|
||||
return Snapshot::IsFull(isolate_kind);
|
||||
}
|
||||
|
||||
|
||||
RawError* Dart::InitializeIsolate(const uint8_t* snapshot_data,
|
||||
const uint8_t* snapshot_instructions,
|
||||
intptr_t snapshot_length,
|
||||
kernel::Program* kernel_program,
|
||||
void* data) {
|
||||
@@ -529,33 +525,28 @@ RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer,
|
||||
if (!error.IsNull()) {
|
||||
return error.raw();
|
||||
}
|
||||
if ((snapshot_buffer != NULL) && kernel_program == NULL) {
|
||||
if ((snapshot_data != NULL) && kernel_program == NULL) {
|
||||
// Read the snapshot and setup the initial state.
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds(T, Timeline::GetIsolateStream(),
|
||||
"IsolateSnapshotReader"));
|
||||
// TODO(turnidge): Remove once length is not part of the snapshot.
|
||||
const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer);
|
||||
const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_data);
|
||||
if (snapshot == NULL) {
|
||||
const String& message = String::Handle(String::New("Invalid snapshot"));
|
||||
return ApiError::New(message);
|
||||
}
|
||||
if (snapshot->kind() != snapshot_kind_ &&
|
||||
!((snapshot->kind() == Snapshot::kAppJIT) &&
|
||||
(snapshot_kind_ == Snapshot::kCore))) {
|
||||
const String& message = String::Handle(
|
||||
String::NewFormatted("Invalid snapshot kind: got '%s', expected '%s'",
|
||||
Snapshot::KindToCString(snapshot->kind()),
|
||||
Snapshot::KindToCString(snapshot_kind_)));
|
||||
if (!IsSnapshotCompatible(vm_snapshot_kind_, snapshot->kind())) {
|
||||
const String& message = String::Handle(String::NewFormatted(
|
||||
"Incompatible snapshot kinds: vm '%s', isolate '%s'",
|
||||
Snapshot::KindToCString(vm_snapshot_kind_),
|
||||
Snapshot::KindToCString(snapshot->kind())));
|
||||
return ApiError::New(message);
|
||||
}
|
||||
ASSERT(Snapshot::IsFull(snapshot->kind()));
|
||||
if (FLAG_trace_isolates) {
|
||||
OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length());
|
||||
}
|
||||
IsolateSnapshotReader reader(
|
||||
snapshot->kind(), snapshot->content(), snapshot->length(),
|
||||
Dart::instructions_snapshot_buffer(), Dart::data_snapshot_buffer(), T);
|
||||
const Error& error = Error::Handle(reader.ReadFullSnapshot());
|
||||
FullSnapshotReader reader(snapshot, snapshot_instructions, T);
|
||||
const Error& error = Error::Handle(reader.ReadIsolateSnapshot());
|
||||
if (!error.IsNull()) {
|
||||
return error.raw();
|
||||
}
|
||||
@@ -572,7 +563,7 @@ RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer,
|
||||
MegamorphicCacheTable::PrintSizes(I);
|
||||
}
|
||||
} else {
|
||||
if ((snapshot_kind_ != Snapshot::kNone) && kernel_program == NULL) {
|
||||
if ((vm_snapshot_kind_ != Snapshot::kNone) && kernel_program == NULL) {
|
||||
const String& message =
|
||||
String::Handle(String::New("Missing isolate snapshot"));
|
||||
return ApiError::New(message);
|
||||
@@ -603,7 +594,7 @@ RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer,
|
||||
Code::Handle(I->object_store()->megamorphic_miss_code());
|
||||
I->set_ic_miss_code(miss_code);
|
||||
|
||||
if ((snapshot_buffer == NULL) || (kernel_program != NULL)) {
|
||||
if ((snapshot_data == NULL) || (kernel_program != NULL)) {
|
||||
const Error& error = Error::Handle(I->object_store()->PreallocateObjects());
|
||||
if (!error.IsNull()) {
|
||||
return error.raw();
|
||||
|
||||
+6
-19
@@ -24,9 +24,8 @@ class Program;
|
||||
|
||||
class Dart : public AllStatic {
|
||||
public:
|
||||
static char* InitOnce(const uint8_t* vm_isolate_snapshot,
|
||||
const uint8_t* instructions_snapshot,
|
||||
const uint8_t* data_snapshot,
|
||||
static char* InitOnce(const uint8_t* vm_snapshot_data,
|
||||
const uint8_t* vm_snapshot_instructions,
|
||||
Dart_IsolateCreateCallback create,
|
||||
Dart_IsolateShutdownCallback shutdown,
|
||||
Dart_ThreadExitCallback thread_exit,
|
||||
@@ -45,7 +44,8 @@ class Dart : public AllStatic {
|
||||
// from SDK library sources. If the snapshot_buffer is non-NULL,
|
||||
// initialize from a snapshot or a Kernel binary depending on the value of
|
||||
// from_kernel. Otherwise, initialize from sources.
|
||||
static RawError* InitializeIsolate(const uint8_t* snapshot_buffer,
|
||||
static RawError* InitializeIsolate(const uint8_t* snapshot_data,
|
||||
const uint8_t* snapshot_instructions,
|
||||
intptr_t snapshot_length,
|
||||
kernel::Program* kernel_program,
|
||||
void* data);
|
||||
@@ -73,18 +73,7 @@ class Dart : public AllStatic {
|
||||
static bool IsReadOnlyHandle(uword address);
|
||||
|
||||
static const char* FeaturesString(Snapshot::Kind kind);
|
||||
|
||||
static Snapshot::Kind snapshot_kind() { return snapshot_kind_; }
|
||||
static const uint8_t* instructions_snapshot_buffer() {
|
||||
return instructions_snapshot_buffer_;
|
||||
}
|
||||
static void set_instructions_snapshot_buffer(const uint8_t* buffer) {
|
||||
instructions_snapshot_buffer_ = buffer;
|
||||
}
|
||||
static const uint8_t* data_snapshot_buffer() { return data_snapshot_buffer_; }
|
||||
static void set_data_snapshot_buffer(const uint8_t* buffer) {
|
||||
data_snapshot_buffer_ = buffer;
|
||||
}
|
||||
static Snapshot::Kind vm_snapshot_kind() { return vm_snapshot_kind_; }
|
||||
|
||||
static Dart_ThreadExitCallback thread_exit_callback() {
|
||||
return thread_exit_callback_;
|
||||
@@ -131,9 +120,7 @@ class Dart : public AllStatic {
|
||||
static ThreadPool* thread_pool_;
|
||||
static DebugInfo* pprof_symbol_generator_;
|
||||
static ReadOnlyHandles* predefined_handles_;
|
||||
static Snapshot::Kind snapshot_kind_;
|
||||
static const uint8_t* instructions_snapshot_buffer_;
|
||||
static const uint8_t* data_snapshot_buffer_;
|
||||
static Snapshot::Kind vm_snapshot_kind_;
|
||||
static Dart_ThreadExitCallback thread_exit_callback_;
|
||||
static Dart_FileOpenCallback file_open_callback_;
|
||||
static Dart_FileReadCallback file_read_callback_;
|
||||
|
||||
+118
-113
@@ -1188,12 +1188,11 @@ DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) {
|
||||
"Invalid Dart_InitializeParams version.");
|
||||
}
|
||||
|
||||
return Dart::InitOnce(params->vm_isolate_snapshot,
|
||||
params->instructions_snapshot, params->data_snapshot,
|
||||
params->create, params->shutdown, params->thread_exit,
|
||||
params->file_open, params->file_read,
|
||||
params->file_write, params->file_close,
|
||||
params->entropy_source, params->get_service_assets);
|
||||
return Dart::InitOnce(
|
||||
params->vm_snapshot_data, params->vm_snapshot_instructions,
|
||||
params->create, params->shutdown, params->thread_exit, params->file_open,
|
||||
params->file_read, params->file_write, params->file_close,
|
||||
params->entropy_source, params->get_service_assets);
|
||||
}
|
||||
|
||||
|
||||
@@ -1256,7 +1255,8 @@ static char* BuildIsolateName(const char* script_uri, const char* main) {
|
||||
|
||||
static Dart_Isolate CreateIsolate(const char* script_uri,
|
||||
const char* main,
|
||||
const uint8_t* snapshot_buffer,
|
||||
const uint8_t* snapshot_data,
|
||||
const uint8_t* snapshot_instructions,
|
||||
intptr_t snapshot_length,
|
||||
kernel::Program* kernel_program,
|
||||
Dart_IsolateFlags* flags,
|
||||
@@ -1285,9 +1285,10 @@ static Dart_Isolate CreateIsolate(const char* script_uri,
|
||||
// bootstrap library files which call out to a tag handler that may create
|
||||
// Api Handles when an error is encountered.
|
||||
Dart_EnterScope();
|
||||
const Error& error_obj = Error::Handle(
|
||||
Z, Dart::InitializeIsolate(snapshot_buffer, snapshot_length,
|
||||
kernel_program, callback_data));
|
||||
const Error& error_obj =
|
||||
Error::Handle(Z, Dart::InitializeIsolate(
|
||||
snapshot_data, snapshot_instructions,
|
||||
snapshot_length, kernel_program, callback_data));
|
||||
if (error_obj.IsNull()) {
|
||||
#if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT)
|
||||
if (FLAG_check_function_fingerprints && kernel_program == NULL) {
|
||||
@@ -1313,14 +1314,16 @@ static Dart_Isolate CreateIsolate(const char* script_uri,
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri,
|
||||
const char* main,
|
||||
const uint8_t* snapshot_buffer,
|
||||
Dart_IsolateFlags* flags,
|
||||
void* callback_data,
|
||||
char** error) {
|
||||
return CreateIsolate(script_uri, main, snapshot_buffer, -1, NULL, flags,
|
||||
callback_data, error);
|
||||
DART_EXPORT Dart_Isolate
|
||||
Dart_CreateIsolate(const char* script_uri,
|
||||
const char* main,
|
||||
const uint8_t* snapshot_data,
|
||||
const uint8_t* snapshot_instructions,
|
||||
Dart_IsolateFlags* flags,
|
||||
void* callback_data,
|
||||
char** error) {
|
||||
return CreateIsolate(script_uri, main, snapshot_data, snapshot_instructions,
|
||||
-1, NULL, flags, callback_data, error);
|
||||
}
|
||||
|
||||
|
||||
@@ -1330,7 +1333,7 @@ DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri,
|
||||
Dart_IsolateFlags* flags,
|
||||
void* callback_data,
|
||||
char** error) {
|
||||
return CreateIsolate(script_uri, main, NULL, -1,
|
||||
return CreateIsolate(script_uri, main, NULL, NULL, -1,
|
||||
reinterpret_cast<kernel::Program*>(kernel_program),
|
||||
flags, callback_data, error);
|
||||
}
|
||||
@@ -1560,10 +1563,10 @@ static uint8_t* ApiReallocate(uint8_t* ptr,
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer,
|
||||
intptr_t* vm_isolate_snapshot_size,
|
||||
uint8_t** isolate_snapshot_buffer,
|
||||
intptr_t* isolate_snapshot_size) {
|
||||
Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer,
|
||||
intptr_t* vm_snapshot_data_size,
|
||||
uint8_t** isolate_snapshot_data_buffer,
|
||||
intptr_t* isolate_snapshot_data_size) {
|
||||
DARTSCOPE(Thread::Current());
|
||||
API_TIMELINE_DURATION;
|
||||
Isolate* I = T->isolate();
|
||||
@@ -1571,14 +1574,14 @@ Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer,
|
||||
return Api::NewError(
|
||||
"Creating full snapshots requires --load_deferred_eagerly");
|
||||
}
|
||||
if (vm_isolate_snapshot_buffer != NULL && vm_isolate_snapshot_size == NULL) {
|
||||
RETURN_NULL_ERROR(vm_isolate_snapshot_size);
|
||||
if (vm_snapshot_data_buffer != NULL && vm_snapshot_data_size == NULL) {
|
||||
RETURN_NULL_ERROR(vm_snapshot_data_size);
|
||||
}
|
||||
if (isolate_snapshot_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_buffer);
|
||||
if (isolate_snapshot_data_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_data_buffer);
|
||||
}
|
||||
if (isolate_snapshot_size == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_size);
|
||||
if (isolate_snapshot_data_size == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_data_size);
|
||||
}
|
||||
// Finalize all classes if needed.
|
||||
Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
|
||||
@@ -1595,28 +1598,30 @@ Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer,
|
||||
|
||||
Symbols::Compact(I);
|
||||
|
||||
FullSnapshotWriter writer(Snapshot::kCore, vm_isolate_snapshot_buffer,
|
||||
isolate_snapshot_buffer, ApiReallocate,
|
||||
NULL /* instructions_writer */);
|
||||
FullSnapshotWriter writer(Snapshot::kCore, vm_snapshot_data_buffer,
|
||||
isolate_snapshot_data_buffer, ApiReallocate,
|
||||
NULL /* vm_instructions_writer */,
|
||||
NULL /* isolate_instructions_writer */);
|
||||
writer.WriteFullSnapshot();
|
||||
if (vm_isolate_snapshot_buffer != NULL) {
|
||||
*vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
|
||||
if (vm_snapshot_data_buffer != NULL) {
|
||||
*vm_snapshot_data_size = writer.VmIsolateSnapshotSize();
|
||||
}
|
||||
*isolate_snapshot_size = writer.IsolateSnapshotSize();
|
||||
*isolate_snapshot_data_size = writer.IsolateSnapshotSize();
|
||||
return Api::Success();
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
|
||||
intptr_t* size) {
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer,
|
||||
intptr_t* script_snapshot_size) {
|
||||
API_TIMELINE_DURATION;
|
||||
DARTSCOPE(Thread::Current());
|
||||
Isolate* I = T->isolate();
|
||||
if (buffer == NULL) {
|
||||
RETURN_NULL_ERROR(buffer);
|
||||
if (script_snapshot_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(script_snapshot_buffer);
|
||||
}
|
||||
if (size == NULL) {
|
||||
RETURN_NULL_ERROR(size);
|
||||
if (script_snapshot_size == NULL) {
|
||||
RETURN_NULL_ERROR(script_snapshot_size);
|
||||
}
|
||||
// Finalize all classes if needed.
|
||||
Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
|
||||
@@ -1631,9 +1636,9 @@ DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
|
||||
I->heap()->IterateObjects(&check_canonical);
|
||||
#endif // #if defined(DEBUG)
|
||||
|
||||
ScriptSnapshotWriter writer(buffer, ApiReallocate);
|
||||
ScriptSnapshotWriter writer(script_snapshot_buffer, ApiReallocate);
|
||||
writer.WriteScriptSnapshot(lib);
|
||||
*size = writer.BytesWritten();
|
||||
*script_snapshot_size = writer.BytesWritten();
|
||||
return Api::Success();
|
||||
}
|
||||
|
||||
@@ -3884,7 +3889,8 @@ DART_EXPORT Dart_Handle Dart_New(Dart_Handle type,
|
||||
}
|
||||
if (constructor.IsGenerativeConstructor()) {
|
||||
#if defined(DEBUG)
|
||||
if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) {
|
||||
if (!cls.is_allocated() &&
|
||||
(Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) {
|
||||
return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
|
||||
}
|
||||
#endif
|
||||
@@ -3979,7 +3985,7 @@ DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) {
|
||||
}
|
||||
const Class& cls = Class::Handle(Z, type_obj.type_class());
|
||||
#if defined(DEBUG)
|
||||
if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) {
|
||||
if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) {
|
||||
return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
|
||||
}
|
||||
#endif
|
||||
@@ -4009,7 +4015,7 @@ Dart_AllocateWithNativeFields(Dart_Handle type,
|
||||
}
|
||||
const Class& cls = Class::Handle(Z, type_obj.type_class());
|
||||
#if defined(DEBUG)
|
||||
if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) {
|
||||
if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) {
|
||||
return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
|
||||
}
|
||||
#endif
|
||||
@@ -6654,11 +6660,11 @@ Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer,
|
||||
"WriteAppAOTSnapshot"));
|
||||
AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate,
|
||||
2 * MB /* initial_size */);
|
||||
uint8_t* vm_isolate_snapshot_buffer = NULL;
|
||||
uint8_t* isolate_snapshot_buffer = NULL;
|
||||
FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_isolate_snapshot_buffer,
|
||||
&isolate_snapshot_buffer, ApiReallocate,
|
||||
&instructions_writer);
|
||||
uint8_t* vm_snapshot_data_buffer = NULL;
|
||||
uint8_t* isolate_snapshot_data_buffer = NULL;
|
||||
FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_snapshot_data_buffer,
|
||||
&isolate_snapshot_data_buffer, ApiReallocate,
|
||||
&instructions_writer, &instructions_writer);
|
||||
|
||||
writer.WriteFullSnapshot();
|
||||
*assembly_size = instructions_writer.AssemblySize();
|
||||
@@ -6669,14 +6675,14 @@ Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer,
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer,
|
||||
intptr_t* vm_isolate_snapshot_size,
|
||||
uint8_t** isolate_snapshot_buffer,
|
||||
intptr_t* isolate_snapshot_size,
|
||||
uint8_t** instructions_blob_buffer,
|
||||
intptr_t* instructions_blob_size,
|
||||
uint8_t** rodata_blob_buffer,
|
||||
intptr_t* rodata_blob_size) {
|
||||
Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer,
|
||||
intptr_t* vm_snapshot_data_size,
|
||||
uint8_t** vm_snapshot_instructions_buffer,
|
||||
intptr_t* vm_snapshot_instructions_size,
|
||||
uint8_t** isolate_snapshot_data_buffer,
|
||||
intptr_t* isolate_snapshot_data_size,
|
||||
uint8_t** isolate_snapshot_instructions_buffer,
|
||||
intptr_t* isolate_snapshot_instructions_size) {
|
||||
#if defined(TARGET_ARCH_IA32)
|
||||
return Api::NewError("AOT compilation is not supported on IA32.");
|
||||
#elif defined(TARGET_ARCH_DBC)
|
||||
@@ -6694,45 +6700,50 @@ Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer,
|
||||
"Did you forget to call Dart_Precompile?");
|
||||
}
|
||||
ASSERT(FLAG_load_deferred_eagerly);
|
||||
if (vm_isolate_snapshot_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(vm_isolate_snapshot_buffer);
|
||||
if (vm_snapshot_data_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(vm_snapshot_data_buffer);
|
||||
}
|
||||
if (vm_isolate_snapshot_size == NULL) {
|
||||
RETURN_NULL_ERROR(vm_isolate_snapshot_size);
|
||||
if (vm_snapshot_data_size == NULL) {
|
||||
RETURN_NULL_ERROR(vm_snapshot_data_size);
|
||||
}
|
||||
if (isolate_snapshot_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_buffer);
|
||||
if (vm_snapshot_instructions_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(vm_snapshot_instructions_buffer);
|
||||
}
|
||||
if (isolate_snapshot_size == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_size);
|
||||
if (vm_snapshot_instructions_size == NULL) {
|
||||
RETURN_NULL_ERROR(vm_snapshot_instructions_size);
|
||||
}
|
||||
if (instructions_blob_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_buffer);
|
||||
if (isolate_snapshot_data_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_data_buffer);
|
||||
}
|
||||
if (instructions_blob_size == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_size);
|
||||
if (isolate_snapshot_data_size == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_data_size);
|
||||
}
|
||||
if (rodata_blob_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_buffer);
|
||||
if (isolate_snapshot_instructions_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_snapshot_blob_buffer);
|
||||
}
|
||||
if (rodata_blob_size == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_size);
|
||||
if (isolate_snapshot_instructions_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_snapshot_blob_size);
|
||||
}
|
||||
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
|
||||
"WriteAppAOTSnapshot"));
|
||||
BlobInstructionsWriter instructions_writer(instructions_blob_buffer,
|
||||
rodata_blob_buffer, ApiReallocate,
|
||||
2 * MB /* initial_size */);
|
||||
FullSnapshotWriter writer(Snapshot::kAppAOT, vm_isolate_snapshot_buffer,
|
||||
isolate_snapshot_buffer, ApiReallocate,
|
||||
&instructions_writer);
|
||||
BlobInstructionsWriter vm_instructions_writer(vm_snapshot_instructions_buffer,
|
||||
ApiReallocate,
|
||||
2 * MB /* initial_size */);
|
||||
BlobInstructionsWriter isolate_instructions_writer(
|
||||
isolate_snapshot_instructions_buffer, ApiReallocate,
|
||||
2 * MB /* initial_size */);
|
||||
FullSnapshotWriter writer(
|
||||
Snapshot::kAppAOT, vm_snapshot_data_buffer, isolate_snapshot_data_buffer,
|
||||
ApiReallocate, &vm_instructions_writer, &isolate_instructions_writer);
|
||||
|
||||
writer.WriteFullSnapshot();
|
||||
*vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
|
||||
*isolate_snapshot_size = writer.IsolateSnapshotSize();
|
||||
*instructions_blob_size = instructions_writer.InstructionsBlobSize();
|
||||
*rodata_blob_size = instructions_writer.RodataBlobSize();
|
||||
*vm_snapshot_data_size = writer.VmIsolateSnapshotSize();
|
||||
*vm_snapshot_instructions_size =
|
||||
vm_instructions_writer.InstructionsBlobSize();
|
||||
*isolate_snapshot_data_size = writer.IsolateSnapshotSize();
|
||||
*isolate_snapshot_instructions_size =
|
||||
isolate_instructions_writer.InstructionsBlobSize();
|
||||
|
||||
return Api::Success();
|
||||
#endif
|
||||
@@ -6740,12 +6751,10 @@ Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer,
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer,
|
||||
intptr_t* isolate_snapshot_size,
|
||||
uint8_t** instructions_blob_buffer,
|
||||
intptr_t* instructions_blob_size,
|
||||
uint8_t** rodata_blob_buffer,
|
||||
intptr_t* rodata_blob_size) {
|
||||
Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer,
|
||||
intptr_t* isolate_snapshot_data_size,
|
||||
uint8_t** isolate_snapshot_instructions_buffer,
|
||||
intptr_t* isolate_snapshot_instructions_size) {
|
||||
#if defined(TARGET_ARCH_IA32)
|
||||
return Api::NewError("Snapshots with code are not supported on IA32.");
|
||||
#elif defined(TARGET_ARCH_DBC)
|
||||
@@ -6760,23 +6769,17 @@ Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer,
|
||||
return Api::NewError(
|
||||
"Creating full snapshots requires --load_deferred_eagerly");
|
||||
}
|
||||
if (isolate_snapshot_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_buffer);
|
||||
if (isolate_snapshot_data_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_data_buffer);
|
||||
}
|
||||
if (isolate_snapshot_size == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_size);
|
||||
if (isolate_snapshot_data_size == NULL) {
|
||||
RETURN_NULL_ERROR(isolate_snapshot_data_size);
|
||||
}
|
||||
if (instructions_blob_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_buffer);
|
||||
if (isolate_snapshot_instructions_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_snapshot_blob_buffer);
|
||||
}
|
||||
if (instructions_blob_size == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_size);
|
||||
}
|
||||
if (rodata_blob_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_buffer);
|
||||
}
|
||||
if (rodata_blob_size == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_blob_size);
|
||||
if (isolate_snapshot_instructions_buffer == NULL) {
|
||||
RETURN_NULL_ERROR(instructions_snapshot_blob_size);
|
||||
}
|
||||
// Finalize all classes if needed.
|
||||
Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
|
||||
@@ -6789,15 +6792,17 @@ Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer,
|
||||
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
|
||||
"WriteAppJITSnapshot"));
|
||||
BlobInstructionsWriter instructions_writer(instructions_blob_buffer,
|
||||
rodata_blob_buffer, ApiReallocate,
|
||||
2 * MB /* initial_size */);
|
||||
FullSnapshotWriter writer(Snapshot::kAppJIT, NULL, isolate_snapshot_buffer,
|
||||
ApiReallocate, &instructions_writer);
|
||||
BlobInstructionsWriter isolate_instructions_writer(
|
||||
isolate_snapshot_instructions_buffer, ApiReallocate,
|
||||
2 * MB /* initial_size */);
|
||||
FullSnapshotWriter writer(Snapshot::kAppJIT, NULL,
|
||||
isolate_snapshot_data_buffer, ApiReallocate, NULL,
|
||||
&isolate_instructions_writer);
|
||||
writer.WriteFullSnapshot();
|
||||
*isolate_snapshot_size = writer.IsolateSnapshotSize();
|
||||
*instructions_blob_size = instructions_writer.InstructionsBlobSize();
|
||||
*rodata_blob_size = instructions_writer.RodataBlobSize();
|
||||
|
||||
*isolate_snapshot_data_size = writer.IsolateSnapshotSize();
|
||||
*isolate_snapshot_instructions_size =
|
||||
isolate_instructions_writer.InstructionsBlobSize();
|
||||
|
||||
return Api::Success();
|
||||
#endif
|
||||
|
||||
@@ -3497,7 +3497,8 @@ UNIT_TEST_CASE(CurrentIsolateData) {
|
||||
intptr_t mydata = 12345;
|
||||
char* err;
|
||||
Dart_Isolate isolate =
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL,
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL,
|
||||
reinterpret_cast<void*>(mydata), &err);
|
||||
EXPECT(isolate != NULL);
|
||||
EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData()));
|
||||
@@ -3528,7 +3529,8 @@ UNIT_TEST_CASE(IsolateSetCheckedMode) {
|
||||
|
||||
char* err;
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
NULL, NULL, bin::core_isolate_snapshot_buffer, &api_flags, NULL, &err);
|
||||
NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, &api_flags, NULL, &err);
|
||||
if (isolate == NULL) {
|
||||
OS::Print("Creation of isolate failed '%s'\n", err);
|
||||
free(err);
|
||||
@@ -7573,7 +7575,8 @@ void BusyLoop_start(uword unused) {
|
||||
MonitorLocker ml(sync);
|
||||
char* error = NULL;
|
||||
shared_isolate = Dart_CreateIsolate(
|
||||
NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, &error);
|
||||
NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, &error);
|
||||
EXPECT(shared_isolate != NULL);
|
||||
Dart_EnterScope();
|
||||
Dart_Handle url = NewString(TestCase::url());
|
||||
@@ -7624,7 +7627,8 @@ UNIT_TEST_CASE(IsolateShutdown) {
|
||||
// Create an isolate.
|
||||
char* err;
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, my_data, &err);
|
||||
NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, my_data, &err);
|
||||
if (isolate == NULL) {
|
||||
OS::Print("Creation of isolate failed '%s'\n", err);
|
||||
free(err);
|
||||
@@ -7673,7 +7677,8 @@ UNIT_TEST_CASE(IsolateShutdownRunDartCode) {
|
||||
// Create an isolate.
|
||||
char* err;
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, &err);
|
||||
NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, &err);
|
||||
if (isolate == NULL) {
|
||||
OS::Print("Creation of isolate failed '%s'\n", err);
|
||||
free(err);
|
||||
|
||||
@@ -314,6 +314,12 @@ class WriteStream : public ValueObject {
|
||||
|
||||
void set_current(uint8_t* value) { current_ = value; }
|
||||
|
||||
void Align(intptr_t alignment) {
|
||||
intptr_t position = current_ - *buffer_;
|
||||
position = Utils::RoundUp(position, alignment);
|
||||
current_ = *buffer_ + position;
|
||||
}
|
||||
|
||||
template <int N, typename T>
|
||||
class Raw {};
|
||||
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
namespace dart {
|
||||
|
||||
bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) {
|
||||
if (page->embedder_allocated()) {
|
||||
// Don't clear mark bits.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Keep track whether this page is still in use.
|
||||
bool in_use = false;
|
||||
|
||||
|
||||
+19
-3
@@ -189,6 +189,17 @@ void Heap::VisitObjects(ObjectVisitor* visitor) const {
|
||||
}
|
||||
|
||||
|
||||
void Heap::VisitObjectsNoExternalPages(ObjectVisitor* visitor) const {
|
||||
new_space_.VisitObjects(visitor);
|
||||
old_space_.VisitObjectsNoExternalPages(visitor);
|
||||
}
|
||||
|
||||
|
||||
void Heap::VisitObjectsExternalPages(ObjectVisitor* visitor) const {
|
||||
old_space_.VisitObjectsExternalPages(visitor);
|
||||
}
|
||||
|
||||
|
||||
HeapIterationScope::HeapIterationScope(bool writable)
|
||||
: StackResource(Thread::Current()),
|
||||
old_space_(isolate()->heap()->old_space()),
|
||||
@@ -247,9 +258,9 @@ void Heap::IterateOldObjects(ObjectVisitor* visitor) const {
|
||||
}
|
||||
|
||||
|
||||
void Heap::IterateOldObjectsNoEmbedderPages(ObjectVisitor* visitor) const {
|
||||
void Heap::IterateOldObjectsNoExternalPages(ObjectVisitor* visitor) const {
|
||||
HeapIterationScope heap_iteration_scope;
|
||||
old_space_.VisitObjectsNoEmbedderPages(visitor);
|
||||
old_space_.VisitObjectsNoExternalPages(visitor);
|
||||
}
|
||||
|
||||
|
||||
@@ -520,7 +531,12 @@ ObjectSet* Heap::CreateAllocatedObjectSet(
|
||||
{
|
||||
VerifyObjectVisitor object_visitor(isolate(), allocated_set,
|
||||
mark_expectation);
|
||||
this->VisitObjects(&object_visitor);
|
||||
this->VisitObjectsNoExternalPages(&object_visitor);
|
||||
}
|
||||
{
|
||||
VerifyObjectVisitor object_visitor(isolate(), allocated_set,
|
||||
kRequireMarked);
|
||||
this->VisitObjectsExternalPages(&object_visitor);
|
||||
}
|
||||
|
||||
Isolate* vm_isolate = Dart::vm_isolate();
|
||||
|
||||
+3
-1
@@ -92,7 +92,7 @@ class Heap {
|
||||
|
||||
void IterateObjects(ObjectVisitor* visitor) const;
|
||||
void IterateOldObjects(ObjectVisitor* visitor) const;
|
||||
void IterateOldObjectsNoEmbedderPages(ObjectVisitor* visitor) const;
|
||||
void IterateOldObjectsNoExternalPages(ObjectVisitor* visitor) const;
|
||||
void IterateObjectPointers(ObjectVisitor* visitor) const;
|
||||
|
||||
// Find an object by visiting all pointers in the specified heap space,
|
||||
@@ -296,6 +296,8 @@ class Heap {
|
||||
// Visit all objects, including FreeListElement "objects". Caller must ensure
|
||||
// concurrent sweeper is not running, and the visitor must not allocate.
|
||||
void VisitObjects(ObjectVisitor* visitor) const;
|
||||
void VisitObjectsNoExternalPages(ObjectVisitor* visitor) const;
|
||||
void VisitObjectsExternalPages(ObjectVisitor* visitor) const;
|
||||
|
||||
// Like Verify, but does not wait for concurrent sweeper, so caller must
|
||||
// ensure thread-safety.
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace dart {
|
||||
|
||||
UNIT_TEST_CASE(IsolateCurrent) {
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, NULL);
|
||||
NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
EXPECT_EQ(isolate, Dart_CurrentIsolate());
|
||||
Dart_ShutdownIsolate();
|
||||
EXPECT_EQ(reinterpret_cast<Dart_Isolate>(NULL), Dart_CurrentIsolate());
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace dart {
|
||||
#ifndef PRODUCT
|
||||
|
||||
UNIT_TEST_CASE(Metric_Simple) {
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
{
|
||||
Metric metric;
|
||||
|
||||
@@ -45,8 +45,8 @@ class MyMetric : public Metric {
|
||||
};
|
||||
|
||||
UNIT_TEST_CASE(Metric_OnDemand) {
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
{
|
||||
Thread* thread = Thread::Current();
|
||||
StackZone zone(thread);
|
||||
|
||||
+10
-10
@@ -1051,7 +1051,7 @@ void Object::FinalizeVMIsolate(Isolate* isolate) {
|
||||
WritableVMIsolateScope scope(Thread::Current());
|
||||
PremarkingVisitor premarker;
|
||||
ASSERT(isolate->heap()->UsedInWords(Heap::kNew) == 0);
|
||||
isolate->heap()->IterateOldObjectsNoEmbedderPages(&premarker);
|
||||
isolate->heap()->IterateOldObjectsNoExternalPages(&premarker);
|
||||
// Make the VM isolate read-only again after setting all objects as marked.
|
||||
}
|
||||
}
|
||||
@@ -3501,7 +3501,7 @@ TokenPosition Class::ComputeEndTokenPos() const {
|
||||
|
||||
const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens());
|
||||
if (tkns.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return TokenPosition::kNoSource;
|
||||
}
|
||||
TokenStream::Iterator tkit(zone, tkns, token_pos(),
|
||||
@@ -7662,7 +7662,7 @@ RawString* Field::InitializingExpression() const {
|
||||
ASSERT(!scr.IsNull());
|
||||
const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens());
|
||||
if (tkns.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return String::null();
|
||||
}
|
||||
TokenStream::Iterator tkit(zone, tkns, token_pos());
|
||||
@@ -8815,7 +8815,7 @@ RawString* Script::GenerateSource() const {
|
||||
|
||||
const TokenStream& token_stream = TokenStream::Handle(tokens());
|
||||
if (token_stream.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return String::null();
|
||||
}
|
||||
return token_stream.GenerateSource();
|
||||
@@ -9072,7 +9072,7 @@ void Script::GetTokenLocation(TokenPosition token_pos,
|
||||
|
||||
const TokenStream& tkns = TokenStream::Handle(zone, tokens());
|
||||
if (tkns.IsNull()) {
|
||||
ASSERT((Dart::snapshot_kind() == Snapshot::kAppAOT));
|
||||
ASSERT((Dart::vm_snapshot_kind() == Snapshot::kAppAOT));
|
||||
*line = -1;
|
||||
if (column != NULL) {
|
||||
*column = -1;
|
||||
@@ -9230,7 +9230,7 @@ int32_t Script::SourceFingerprint(TokenPosition start,
|
||||
RawString* Script::GetLine(intptr_t line_number, Heap::Space space) const {
|
||||
const String& src = String::Handle(Source());
|
||||
if (src.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return Symbols::OptimizedOut().raw();
|
||||
}
|
||||
intptr_t relative_line_number = line_number - line_offset();
|
||||
@@ -9280,7 +9280,7 @@ RawString* Script::GetSnippet(intptr_t from_line,
|
||||
intptr_t to_column) const {
|
||||
const String& src = String::Handle(Source());
|
||||
if (src.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return Symbols::OptimizedOut().raw();
|
||||
}
|
||||
intptr_t length = src.Length();
|
||||
@@ -11211,7 +11211,7 @@ bool LibraryPrefix::LoadLibrary() const {
|
||||
}
|
||||
ASSERT(is_deferred_load());
|
||||
ASSERT(num_imports() == 1);
|
||||
if (Dart::snapshot_kind() == Snapshot::kAppAOT) {
|
||||
if (Dart::vm_snapshot_kind() == Snapshot::kAppAOT) {
|
||||
// The library list was tree-shaken away.
|
||||
this->set_is_loaded();
|
||||
return true;
|
||||
@@ -12814,7 +12814,7 @@ const char* ICData::ToCString() const {
|
||||
RawFunction* ICData::Owner() const {
|
||||
Object& obj = Object::Handle(raw_ptr()->owner_);
|
||||
if (obj.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return Function::null();
|
||||
} else if (obj.IsFunction()) {
|
||||
return Function::Cast(obj).raw();
|
||||
@@ -14002,7 +14002,7 @@ RawTypedData* Code::GetDeoptInfoAtPc(uword pc,
|
||||
uword code_entry = instrs.PayloadStart();
|
||||
const Array& table = Array::Handle(deopt_info_array());
|
||||
if (table.IsNull()) {
|
||||
ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() == Snapshot::kAppAOT);
|
||||
return TypedData::null();
|
||||
}
|
||||
// Linear search for the PC offset matching the target PC.
|
||||
|
||||
@@ -149,7 +149,7 @@ class Unmarker : public ObjectVisitor {
|
||||
|
||||
static void UnmarkAll(Isolate* isolate) {
|
||||
Unmarker unmarker;
|
||||
isolate->heap()->VisitObjects(&unmarker);
|
||||
isolate->heap()->VisitObjectsNoExternalPages(&unmarker);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -213,7 +213,7 @@ void ObjectGraph::IterateObjectsFrom(intptr_t class_id,
|
||||
Stack stack(isolate());
|
||||
|
||||
InstanceAccumulator accumulator(&stack, class_id);
|
||||
isolate()->heap()->VisitObjects(&accumulator);
|
||||
isolate()->heap()->VisitObjectsNoExternalPages(&accumulator);
|
||||
|
||||
stack.TraverseGraph(visitor);
|
||||
Unmarker::UnmarkAll(isolate());
|
||||
|
||||
+23
-9
@@ -229,16 +229,16 @@ HeapPage* PageSpace::AllocatePage(HeapPage::PageType type) {
|
||||
} else {
|
||||
// Should not allocate executable pages when running from a precompiled
|
||||
// snapshot.
|
||||
ASSERT(Dart::snapshot_kind() != Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() != Snapshot::kAppAOT);
|
||||
|
||||
if (exec_pages_ == NULL) {
|
||||
exec_pages_ = page;
|
||||
} else {
|
||||
if (FLAG_write_protect_code) {
|
||||
if (FLAG_write_protect_code && !exec_pages_tail_->embedder_allocated()) {
|
||||
exec_pages_tail_->WriteProtect(false);
|
||||
}
|
||||
exec_pages_tail_->set_next(page);
|
||||
if (FLAG_write_protect_code) {
|
||||
if (FLAG_write_protect_code && !exec_pages_tail_->embedder_allocated()) {
|
||||
exec_pages_tail_->WriteProtect(true);
|
||||
}
|
||||
}
|
||||
@@ -626,7 +626,7 @@ void PageSpace::VisitObjects(ObjectVisitor* visitor) const {
|
||||
}
|
||||
|
||||
|
||||
void PageSpace::VisitObjectsNoEmbedderPages(ObjectVisitor* visitor) const {
|
||||
void PageSpace::VisitObjectsNoExternalPages(ObjectVisitor* visitor) const {
|
||||
for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) {
|
||||
if (!it.page()->embedder_allocated()) {
|
||||
it.page()->VisitObjects(visitor);
|
||||
@@ -635,6 +635,15 @@ void PageSpace::VisitObjectsNoEmbedderPages(ObjectVisitor* visitor) const {
|
||||
}
|
||||
|
||||
|
||||
void PageSpace::VisitObjectsExternalPages(ObjectVisitor* visitor) const {
|
||||
for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) {
|
||||
if (it.page()->embedder_allocated()) {
|
||||
it.page()->VisitObjects(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageSpace::VisitObjectPointers(ObjectPointerVisitor* visitor) const {
|
||||
for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) {
|
||||
it.page()->VisitObjectPointers(visitor);
|
||||
@@ -802,12 +811,15 @@ void PageSpace::WriteProtectCode(bool read_only) {
|
||||
HeapPage* page = exec_pages_;
|
||||
while (page != NULL) {
|
||||
ASSERT(page->type() == HeapPage::kExecutable);
|
||||
page->WriteProtect(read_only);
|
||||
if (!page->embedder_allocated()) {
|
||||
page->WriteProtect(read_only);
|
||||
}
|
||||
page = page->next();
|
||||
}
|
||||
page = large_pages_;
|
||||
while (page != NULL) {
|
||||
if (page->type() == HeapPage::kExecutable) {
|
||||
if (page->type() == HeapPage::kExecutable &&
|
||||
!page->embedder_allocated()) {
|
||||
page->WriteProtect(read_only);
|
||||
}
|
||||
page = page->next();
|
||||
@@ -1095,18 +1107,20 @@ void PageSpace::SetupExternalPage(void* pointer,
|
||||
first = &exec_pages_;
|
||||
tail = &exec_pages_tail_;
|
||||
} else {
|
||||
page->type_ = HeapPage::kReadOnlyData;
|
||||
page->type_ = HeapPage::kData;
|
||||
first = &pages_;
|
||||
tail = &pages_tail_;
|
||||
}
|
||||
if (*first == NULL) {
|
||||
*first = page;
|
||||
} else {
|
||||
if (is_executable && FLAG_write_protect_code) {
|
||||
if (is_executable && FLAG_write_protect_code &&
|
||||
!(*tail)->embedder_allocated()) {
|
||||
(*tail)->WriteProtect(false);
|
||||
}
|
||||
(*tail)->set_next(page);
|
||||
if (is_executable && FLAG_write_protect_code) {
|
||||
if (is_executable && FLAG_write_protect_code &&
|
||||
!(*tail)->embedder_allocated()) {
|
||||
(*tail)->WriteProtect(true);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -28,7 +28,7 @@ class ObjectSet;
|
||||
// A page containing old generation objects.
|
||||
class HeapPage {
|
||||
public:
|
||||
enum PageType { kData = 0, kExecutable, kReadOnlyData, kNumPageTypes };
|
||||
enum PageType { kData = 0, kExecutable, kNumPageTypes };
|
||||
|
||||
HeapPage* next() const { return next_; }
|
||||
void set_next(HeapPage* next) { next_ = next; }
|
||||
@@ -231,7 +231,8 @@ class PageSpace {
|
||||
bool IsValidAddress(uword addr) const { return Contains(addr); }
|
||||
|
||||
void VisitObjects(ObjectVisitor* visitor) const;
|
||||
void VisitObjectsNoEmbedderPages(ObjectVisitor* visitor) const;
|
||||
void VisitObjectsNoExternalPages(ObjectVisitor* visitor) const;
|
||||
void VisitObjectsExternalPages(ObjectVisitor* visitor) const;
|
||||
void VisitObjectPointers(ObjectPointerVisitor* visitor) const;
|
||||
|
||||
RawObject* FindObject(FindObjectVisitor* visitor,
|
||||
|
||||
@@ -1195,7 +1195,7 @@ void Precompiler::AddField(const Field& field) {
|
||||
if (FLAG_trace_precompiler) {
|
||||
THR_Print("Precompiling initializer for %s\n", field.ToCString());
|
||||
}
|
||||
ASSERT(Dart::snapshot_kind() != Snapshot::kAppAOT);
|
||||
ASSERT(Dart::vm_snapshot_kind() != Snapshot::kAppAOT);
|
||||
const Function& initializer = Function::Handle(
|
||||
Z, CompileStaticInitializer(field, /* compute_type = */ true));
|
||||
ASSERT(!initializer.IsNull());
|
||||
|
||||
@@ -609,6 +609,7 @@ class RawObject {
|
||||
friend class RetainingPathVisitor; // GetClassId
|
||||
friend class SkippedCodeFunctions; // StorePointer
|
||||
friend class InstructionsReader; // tags_ check
|
||||
friend class InstructionsWriter;
|
||||
friend class AssemblyInstructionsWriter;
|
||||
friend class BlobInstructionsWriter;
|
||||
friend class SnapshotReader;
|
||||
|
||||
+81
-109
@@ -709,21 +709,7 @@ int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) {
|
||||
}
|
||||
|
||||
|
||||
static void EnsureIdentifier(char* label) {
|
||||
for (char c = *label; c != '\0'; c = *++label) {
|
||||
if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ||
|
||||
((c >= '0') && (c <= '9'))) {
|
||||
continue;
|
||||
}
|
||||
*label = '_';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AssemblyInstructionsWriter::Write(uint8_t* vmisolate_buffer,
|
||||
intptr_t vmisolate_length,
|
||||
uint8_t* isolate_buffer,
|
||||
intptr_t isolate_length) {
|
||||
void InstructionsWriter::Write(WriteStream* clustered_stream, bool vm) {
|
||||
Thread* thread = Thread::Current();
|
||||
Zone* zone = thread->zone();
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds(thread, Timeline::GetIsolateStream(),
|
||||
@@ -742,12 +728,68 @@ void AssemblyInstructionsWriter::Write(uint8_t* vmisolate_buffer,
|
||||
data.obj_ = &Object::Handle(zone, data.raw_obj_);
|
||||
}
|
||||
|
||||
// Append the direct-mapped RO data objects after the clustered snapshot.
|
||||
WriteROData(clustered_stream);
|
||||
|
||||
WriteText(clustered_stream, vm);
|
||||
}
|
||||
|
||||
|
||||
void InstructionsWriter::WriteROData(WriteStream* stream) {
|
||||
stream->Align(OS::kMaxPreferredCodeAlignment);
|
||||
|
||||
// Heap page starts here.
|
||||
|
||||
stream->WriteWord(next_object_offset_); // Data length.
|
||||
COMPILE_ASSERT(OS::kMaxPreferredCodeAlignment >= kObjectAlignment);
|
||||
stream->Align(OS::kMaxPreferredCodeAlignment);
|
||||
|
||||
// Heap page objects start here.
|
||||
|
||||
for (intptr_t i = 0; i < objects_.length(); i++) {
|
||||
const Object& obj = *objects_[i].obj_;
|
||||
|
||||
NoSafepointScope no_safepoint;
|
||||
uword start = reinterpret_cast<uword>(obj.raw()) - kHeapObjectTag;
|
||||
uword end = start + obj.raw()->Size();
|
||||
|
||||
// Write object header with the mark and VM heap bits set.
|
||||
uword marked_tags = obj.raw()->ptr()->tags_;
|
||||
marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags);
|
||||
marked_tags = RawObject::MarkBit::update(true, marked_tags);
|
||||
stream->WriteWord(marked_tags);
|
||||
start += sizeof(uword);
|
||||
for (uword* cursor = reinterpret_cast<uword*>(start);
|
||||
cursor < reinterpret_cast<uword*>(end); cursor++) {
|
||||
stream->WriteWord(*cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void EnsureIdentifier(char* label) {
|
||||
for (char c = *label; c != '\0'; c = *++label) {
|
||||
if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ||
|
||||
((c >= '0') && (c <= '9'))) {
|
||||
continue;
|
||||
}
|
||||
*label = '_';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AssemblyInstructionsWriter::WriteText(WriteStream* clustered_stream,
|
||||
bool vm) {
|
||||
Zone* zone = Thread::Current()->zone();
|
||||
|
||||
const char* instructions_symbol =
|
||||
vm ? "_kDartVmSnapshotInstructions" : "_kDartIsolateSnapshotInstructions";
|
||||
assembly_stream_.Print(".text\n");
|
||||
assembly_stream_.Print(".globl _kInstructionsSnapshot\n");
|
||||
assembly_stream_.Print(".globl %s\n", instructions_symbol);
|
||||
// Start snapshot at page boundary.
|
||||
ASSERT(VirtualMemory::PageSize() >= OS::kMaxPreferredCodeAlignment);
|
||||
assembly_stream_.Print(".balign %" Pd ", 0\n", VirtualMemory::PageSize());
|
||||
assembly_stream_.Print("_kInstructionsSnapshot:\n");
|
||||
assembly_stream_.Print("%s:\n", instructions_symbol);
|
||||
|
||||
// This head also provides the gap to make the instructions snapshot
|
||||
// look like a HeapPage.
|
||||
@@ -829,6 +871,8 @@ void AssemblyInstructionsWriter::Write(uint8_t* vmisolate_buffer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(TARGET_OS_LINUX)
|
||||
assembly_stream_.Print(".section .rodata\n");
|
||||
#elif defined(TARGET_OS_MACOS)
|
||||
@@ -837,76 +881,24 @@ void AssemblyInstructionsWriter::Write(uint8_t* vmisolate_buffer,
|
||||
// Unsupported platform.
|
||||
UNREACHABLE();
|
||||
#endif
|
||||
assembly_stream_.Print(".globl _kDataSnapshot\n");
|
||||
// Start snapshot at page boundary.
|
||||
assembly_stream_.Print(".balign %" Pd ", 0\n", VirtualMemory::PageSize());
|
||||
assembly_stream_.Print("_kDataSnapshot:\n");
|
||||
WriteWordLiteralData(next_object_offset_); // Data length.
|
||||
COMPILE_ASSERT(OS::kMaxPreferredCodeAlignment >= kObjectAlignment);
|
||||
|
||||
const char* data_symbol =
|
||||
vm ? "_kDartVmSnapshotData" : "_kDartIsolateSnapshotData";
|
||||
assembly_stream_.Print(".globl %s\n", data_symbol);
|
||||
assembly_stream_.Print(".balign %" Pd ", 0\n",
|
||||
OS::kMaxPreferredCodeAlignment);
|
||||
|
||||
for (intptr_t i = 0; i < objects_.length(); i++) {
|
||||
const Object& obj = *objects_[i].obj_;
|
||||
assembly_stream_.Print("Precompiled_Obj_%d:\n", i);
|
||||
|
||||
NoSafepointScope no_safepoint;
|
||||
uword start = reinterpret_cast<uword>(obj.raw()) - kHeapObjectTag;
|
||||
uword end = start + obj.raw()->Size();
|
||||
|
||||
// Write object header with the mark and VM heap bits set.
|
||||
uword marked_tags = obj.raw()->ptr()->tags_;
|
||||
marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags);
|
||||
marked_tags = RawObject::MarkBit::update(true, marked_tags);
|
||||
WriteWordLiteralData(marked_tags);
|
||||
start += sizeof(uword);
|
||||
for (uword* cursor = reinterpret_cast<uword*>(start);
|
||||
cursor < reinterpret_cast<uword*>(end); cursor++) {
|
||||
WriteWordLiteralData(*cursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
assembly_stream_.Print(".globl _kVmIsolateSnapshot\n");
|
||||
assembly_stream_.Print(".balign %" Pd ", 0\n", VirtualMemory::PageSize());
|
||||
assembly_stream_.Print("_kVmIsolateSnapshot:\n");
|
||||
for (intptr_t i = 0; i < vmisolate_length; i++) {
|
||||
assembly_stream_.Print(".byte %" Pd "\n", vmisolate_buffer[i]);
|
||||
}
|
||||
|
||||
assembly_stream_.Print(".globl _kIsolateSnapshot\n");
|
||||
assembly_stream_.Print(".balign %" Pd ", 0\n", VirtualMemory::PageSize());
|
||||
assembly_stream_.Print("_kIsolateSnapshot:\n");
|
||||
for (intptr_t i = 0; i < isolate_length; i++) {
|
||||
assembly_stream_.Print(".byte %" Pd "\n", isolate_buffer[i]);
|
||||
assembly_stream_.Print("%s:\n", data_symbol);
|
||||
uint8_t* buffer = clustered_stream->buffer();
|
||||
intptr_t length = clustered_stream->bytes_written();
|
||||
for (intptr_t i = 0; i < length; i++) {
|
||||
assembly_stream_.Print(".byte %" Pd "\n", buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlobInstructionsWriter::Write(uint8_t* vmisolate_buffer,
|
||||
intptr_t vmisolate_len,
|
||||
uint8_t* isolate_buffer,
|
||||
intptr_t isolate_length) {
|
||||
Thread* thread = Thread::Current();
|
||||
Zone* zone = thread->zone();
|
||||
NOT_IN_PRODUCT(TimelineDurationScope tds(thread, Timeline::GetIsolateStream(),
|
||||
"WriteInstructions"));
|
||||
|
||||
// Handlify collected raw pointers as building the names below
|
||||
// will allocate on the Dart heap.
|
||||
for (intptr_t i = 0; i < instructions_.length(); i++) {
|
||||
InstructionsData& data = instructions_[i];
|
||||
data.insns_ = &Instructions::Handle(zone, data.raw_insns_);
|
||||
ASSERT(data.raw_code_ != NULL);
|
||||
data.code_ = &Code::Handle(zone, data.raw_code_);
|
||||
}
|
||||
for (intptr_t i = 0; i < objects_.length(); i++) {
|
||||
ObjectData& data = objects_[i];
|
||||
data.obj_ = &Object::Handle(zone, data.raw_obj_);
|
||||
}
|
||||
|
||||
// This head also provides the gap to make the instructions snapshot
|
||||
// look like a HeapPage.
|
||||
void BlobInstructionsWriter::WriteText(WriteStream* clustered_stream, bool vm) {
|
||||
// This header provides the gap to make the instructions snapshot look like a
|
||||
// HeapPage.
|
||||
intptr_t instructions_length = next_offset_;
|
||||
instructions_blob_stream_.WriteWord(instructions_length);
|
||||
intptr_t header_words = InstructionsSnapshot::kHeaderSize / sizeof(uword);
|
||||
@@ -960,38 +952,18 @@ void BlobInstructionsWriter::Write(uint8_t* vmisolate_buffer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rodata_blob_stream_.WriteWord(next_object_offset_); // Data length.
|
||||
COMPILE_ASSERT(OS::kMaxPreferredCodeAlignment >= kObjectAlignment);
|
||||
while (!Utils::IsAligned(rodata_blob_stream_.bytes_written(),
|
||||
OS::kMaxPreferredCodeAlignment)) {
|
||||
rodata_blob_stream_.WriteWord(0);
|
||||
}
|
||||
|
||||
for (intptr_t i = 0; i < objects_.length(); i++) {
|
||||
const Object& obj = *objects_[i].obj_;
|
||||
|
||||
NoSafepointScope no_safepoint;
|
||||
uword start = reinterpret_cast<uword>(obj.raw()) - kHeapObjectTag;
|
||||
uword end = start + obj.raw()->Size();
|
||||
|
||||
// Write object header with the mark and VM heap bits set.
|
||||
uword marked_tags = obj.raw()->ptr()->tags_;
|
||||
marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags);
|
||||
marked_tags = RawObject::MarkBit::update(true, marked_tags);
|
||||
rodata_blob_stream_.WriteWord(marked_tags);
|
||||
start += sizeof(uword);
|
||||
for (uword* cursor = reinterpret_cast<uword*>(start);
|
||||
cursor < reinterpret_cast<uword*>(end); cursor++) {
|
||||
rodata_blob_stream_.WriteWord(*cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uword InstructionsReader::GetInstructionsAt(int32_t offset) {
|
||||
RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset) {
|
||||
ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment()));
|
||||
return reinterpret_cast<uword>(instructions_buffer_) + offset;
|
||||
|
||||
RawInstructions* result = reinterpret_cast<RawInstructions*>(
|
||||
reinterpret_cast<uword>(instructions_buffer_) + offset + kHeapObjectTag);
|
||||
ASSERT(result->IsInstructions());
|
||||
ASSERT(result->IsMarked());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+20
-42
@@ -190,7 +190,7 @@ class Snapshot {
|
||||
return (kind == kAppJIT) || (kind == kAppAOT);
|
||||
}
|
||||
|
||||
uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); }
|
||||
const uint8_t* Addr() const { return reinterpret_cast<const uint8_t*>(this); }
|
||||
|
||||
static intptr_t length_offset() {
|
||||
return OFFSET_OF(Snapshot, unaligned_length_);
|
||||
@@ -375,7 +375,7 @@ class InstructionsReader : public ZoneAllocated {
|
||||
OS::PreferredCodeAlignment()));
|
||||
}
|
||||
|
||||
uword GetInstructionsAt(int32_t offset);
|
||||
RawInstructions* GetInstructionsAt(int32_t offset);
|
||||
RawObject* GetObjectAt(int32_t offset);
|
||||
|
||||
private:
|
||||
@@ -728,24 +728,28 @@ class ForwardList {
|
||||
class InstructionsWriter : public ZoneAllocated {
|
||||
public:
|
||||
InstructionsWriter()
|
||||
: next_offset_(InstructionsSnapshot::kHeaderSize),
|
||||
next_object_offset_(DataSnapshot::kHeaderSize),
|
||||
instructions_(),
|
||||
objects_() {}
|
||||
: next_offset_(0), next_object_offset_(0), instructions_(), objects_() {
|
||||
ResetOffsets();
|
||||
}
|
||||
virtual ~InstructionsWriter() {}
|
||||
|
||||
void ResetOffsets() {
|
||||
next_offset_ = InstructionsSnapshot::kHeaderSize;
|
||||
next_object_offset_ = DataSnapshot::kHeaderSize;
|
||||
instructions_.Clear();
|
||||
objects_.Clear();
|
||||
}
|
||||
int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code);
|
||||
|
||||
int32_t GetObjectOffsetFor(RawObject* raw_object);
|
||||
|
||||
virtual void Write(uint8_t* vmisolate_buffer,
|
||||
intptr_t vmisolate_length,
|
||||
uint8_t* isolate_buffer,
|
||||
intptr_t isolate_length) = 0;
|
||||
void Write(WriteStream* clustered_stream, bool vm);
|
||||
virtual intptr_t text_size() = 0;
|
||||
virtual intptr_t data_size() = 0;
|
||||
intptr_t data_size() { return next_object_offset_; }
|
||||
|
||||
protected:
|
||||
void WriteROData(WriteStream* stream);
|
||||
virtual void WriteText(WriteStream* clustered_stream, bool vm) = 0;
|
||||
|
||||
struct InstructionsData {
|
||||
explicit InstructionsData(RawInstructions* insns,
|
||||
RawCode* code,
|
||||
@@ -789,15 +793,10 @@ class AssemblyInstructionsWriter : public InstructionsWriter {
|
||||
intptr_t initial_size)
|
||||
: InstructionsWriter(),
|
||||
assembly_stream_(assembly_buffer, alloc, initial_size),
|
||||
text_size_(0),
|
||||
data_size_(0) {}
|
||||
text_size_(0) {}
|
||||
|
||||
virtual void Write(uint8_t* vmisolate_buffer,
|
||||
intptr_t vmisolate_length,
|
||||
uint8_t* isolate_buffer,
|
||||
intptr_t isolate_length);
|
||||
virtual void WriteText(WriteStream* clustered_stream, bool vm);
|
||||
virtual intptr_t text_size() { return text_size_; }
|
||||
virtual intptr_t data_size() { return data_size_; }
|
||||
|
||||
intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); }
|
||||
|
||||
@@ -812,19 +811,8 @@ class AssemblyInstructionsWriter : public InstructionsWriter {
|
||||
text_size_ += sizeof(value);
|
||||
}
|
||||
|
||||
void WriteWordLiteralData(uword value) {
|
||||
// Padding is helpful for comparing the .S with --disassemble.
|
||||
#if defined(ARCH_IS_64_BIT)
|
||||
assembly_stream_.Print(".quad 0x%0.16" Px "\n", value);
|
||||
#else
|
||||
assembly_stream_.Print(".long 0x%0.8" Px "\n", value);
|
||||
#endif
|
||||
data_size_ += sizeof(value);
|
||||
}
|
||||
|
||||
WriteStream assembly_stream_;
|
||||
intptr_t text_size_;
|
||||
intptr_t data_size_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter);
|
||||
};
|
||||
@@ -833,32 +821,22 @@ class AssemblyInstructionsWriter : public InstructionsWriter {
|
||||
class BlobInstructionsWriter : public InstructionsWriter {
|
||||
public:
|
||||
BlobInstructionsWriter(uint8_t** instructions_blob_buffer,
|
||||
uint8_t** rodata_blob_buffer,
|
||||
ReAlloc alloc,
|
||||
intptr_t initial_size)
|
||||
: InstructionsWriter(),
|
||||
instructions_blob_stream_(instructions_blob_buffer,
|
||||
alloc,
|
||||
initial_size),
|
||||
rodata_blob_stream_(rodata_blob_buffer, alloc, initial_size) {}
|
||||
initial_size) {}
|
||||
|
||||
virtual void Write(uint8_t* vmisolate_buffer,
|
||||
intptr_t vmisolate_length,
|
||||
uint8_t* isolate_buffer,
|
||||
intptr_t isolate_length);
|
||||
virtual void WriteText(WriteStream* clustered_stream, bool vm);
|
||||
virtual intptr_t text_size() { return InstructionsBlobSize(); }
|
||||
virtual intptr_t data_size() { return RodataBlobSize(); }
|
||||
|
||||
intptr_t InstructionsBlobSize() const {
|
||||
return instructions_blob_stream_.bytes_written();
|
||||
}
|
||||
intptr_t RodataBlobSize() const {
|
||||
return rodata_blob_stream_.bytes_written();
|
||||
}
|
||||
|
||||
private:
|
||||
WriteStream instructions_blob_stream_;
|
||||
WriteStream rodata_blob_stream_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BlobInstructionsWriter);
|
||||
};
|
||||
|
||||
+17
-14
@@ -1164,7 +1164,7 @@ UNIT_TEST_CASE(FullSnapshot) {
|
||||
"}\n";
|
||||
Dart_Handle result;
|
||||
|
||||
uint8_t* isolate_snapshot_buffer;
|
||||
uint8_t* isolate_snapshot_data_buffer;
|
||||
|
||||
// Start an Isolate, load a script and create a full snapshot.
|
||||
Timer timer1(true, "Snapshot_test");
|
||||
@@ -1184,9 +1184,9 @@ UNIT_TEST_CASE(FullSnapshot) {
|
||||
|
||||
// Write snapshot with object content.
|
||||
{
|
||||
FullSnapshotWriter writer(Snapshot::kCore, NULL, &isolate_snapshot_buffer,
|
||||
&malloc_allocator,
|
||||
NULL /* instructions_writer */);
|
||||
FullSnapshotWriter writer(
|
||||
Snapshot::kCore, NULL, &isolate_snapshot_data_buffer,
|
||||
&malloc_allocator, NULL, NULL /* instructions_writer */);
|
||||
writer.WriteFullSnapshot();
|
||||
}
|
||||
}
|
||||
@@ -1195,7 +1195,7 @@ UNIT_TEST_CASE(FullSnapshot) {
|
||||
// from the script.
|
||||
Timer timer2(true, "Snapshot_test");
|
||||
timer2.Start();
|
||||
TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer);
|
||||
TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_data_buffer);
|
||||
{
|
||||
Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
|
||||
timer2.Stop();
|
||||
@@ -1208,7 +1208,7 @@ UNIT_TEST_CASE(FullSnapshot) {
|
||||
Dart_ExitScope();
|
||||
}
|
||||
Dart_ShutdownIsolate();
|
||||
free(isolate_snapshot_buffer);
|
||||
free(isolate_snapshot_data_buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1221,7 +1221,7 @@ UNIT_TEST_CASE(FullSnapshot1) {
|
||||
};
|
||||
const char* kScriptChars = kFullSnapshotScriptChars;
|
||||
|
||||
uint8_t* isolate_snapshot_buffer;
|
||||
uint8_t* isolate_snapshot_data_buffer;
|
||||
|
||||
// Start an Isolate, load a script and create a full snapshot.
|
||||
Timer timer1(true, "Snapshot_test");
|
||||
@@ -1241,9 +1241,9 @@ UNIT_TEST_CASE(FullSnapshot1) {
|
||||
|
||||
// Write snapshot with object content.
|
||||
{
|
||||
FullSnapshotWriter writer(Snapshot::kCore, NULL, &isolate_snapshot_buffer,
|
||||
&malloc_allocator,
|
||||
NULL /* instructions_writer */);
|
||||
FullSnapshotWriter writer(
|
||||
Snapshot::kCore, NULL, &isolate_snapshot_data_buffer,
|
||||
&malloc_allocator, NULL, NULL /* instructions_writer */);
|
||||
writer.WriteFullSnapshot();
|
||||
}
|
||||
|
||||
@@ -1257,7 +1257,7 @@ UNIT_TEST_CASE(FullSnapshot1) {
|
||||
// from the script.
|
||||
Timer timer2(true, "Snapshot_test");
|
||||
timer2.Start();
|
||||
TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer);
|
||||
TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_data_buffer);
|
||||
{
|
||||
Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
|
||||
timer2.Stop();
|
||||
@@ -1274,7 +1274,7 @@ UNIT_TEST_CASE(FullSnapshot1) {
|
||||
Dart_ExitScope();
|
||||
}
|
||||
Dart_ShutdownIsolate();
|
||||
free(isolate_snapshot_buffer);
|
||||
free(isolate_snapshot_data_buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1661,10 +1661,13 @@ UNIT_TEST_CASE(MismatchedSnapshotKinds) {
|
||||
// Use a script snapshot where a full snapshot is expected.
|
||||
char* error = NULL;
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
"script-uri", "main", script_snapshot, NULL, NULL, &error);
|
||||
"script-uri", "main", script_snapshot, NULL, NULL, NULL, &error);
|
||||
EXPECT(isolate == NULL);
|
||||
EXPECT(error != NULL);
|
||||
EXPECT_SUBSTRING("got 'script', expected 'core'", error);
|
||||
EXPECT_SUBSTRING(
|
||||
"Incompatible snapshot kinds:"
|
||||
" vm 'core', isolate 'script'",
|
||||
error);
|
||||
free(error);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace dart {
|
||||
|
||||
UNIT_TEST_CASE(Mutex) {
|
||||
// This unit test case needs a running isolate.
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
|
||||
Mutex* mutex = new Mutex();
|
||||
mutex->Lock();
|
||||
@@ -37,8 +37,8 @@ UNIT_TEST_CASE(Mutex) {
|
||||
|
||||
UNIT_TEST_CASE(Monitor) {
|
||||
// This unit test case needs a running isolate.
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
OSThread* thread = OSThread::Current();
|
||||
// Thread interrupter interferes with this test, disable interrupts.
|
||||
thread->DisableThreadInterrupts();
|
||||
@@ -389,14 +389,14 @@ TEST_CASE(ThreadRegistry) {
|
||||
char* orig_str = orig_zone->PrintToString("foo");
|
||||
Dart_ExitIsolate();
|
||||
// Create and enter a new isolate.
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
Zone* zone0 = Thread::Current()->zone();
|
||||
EXPECT(zone0 != orig_zone);
|
||||
Dart_ShutdownIsolate();
|
||||
// Create and enter yet another isolate.
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
{
|
||||
// Create a stack resource this time, and exercise it.
|
||||
StackZone stack_zone(Thread::Current());
|
||||
|
||||
@@ -54,7 +54,7 @@ void TestCaseBase::RunAll() {
|
||||
Dart_Isolate TestCase::CreateIsolate(const uint8_t* buffer, const char* name) {
|
||||
char* err;
|
||||
Dart_Isolate isolate =
|
||||
Dart_CreateIsolate(name, NULL, buffer, NULL, NULL, &err);
|
||||
Dart_CreateIsolate(name, NULL, buffer, NULL, NULL, NULL, &err);
|
||||
if (isolate == NULL) {
|
||||
OS::Print("Creation of isolate failed '%s'\n", err);
|
||||
free(err);
|
||||
|
||||
@@ -242,13 +242,11 @@ class VirtualMemory;
|
||||
|
||||
|
||||
namespace bin {
|
||||
// vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we
|
||||
// link in a snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* vm_isolate_snapshot_buffer;
|
||||
|
||||
// isolate_snapshot_buffer points to a snapshot for an isolate if we link in a
|
||||
// snapshot otherwise it is initialized to NULL.
|
||||
extern const uint8_t* core_isolate_snapshot_buffer;
|
||||
// Snapshot pieces if we link in a snapshot, otherwise initialized to NULL.
|
||||
extern const uint8_t* vm_snapshot_data;
|
||||
extern const uint8_t* vm_snapshot_instructions;
|
||||
extern const uint8_t* core_isolate_snapshot_data;
|
||||
extern const uint8_t* core_isolate_snapshot_instructions;
|
||||
}
|
||||
|
||||
|
||||
@@ -296,7 +294,7 @@ class TestCase : TestCaseBase {
|
||||
return CreateIsolate(buffer, name);
|
||||
}
|
||||
static Dart_Isolate CreateTestIsolate(const char* name = NULL) {
|
||||
return CreateIsolate(bin::core_isolate_snapshot_buffer, name);
|
||||
return CreateIsolate(bin::core_isolate_snapshot_data, name);
|
||||
}
|
||||
static Dart_Handle library_handler(Dart_LibraryTag tag,
|
||||
Dart_Handle library,
|
||||
|
||||
+10
-10
@@ -14,8 +14,8 @@ UNIT_TEST_CASE(AllocateZone) {
|
||||
#if defined(DEBUG)
|
||||
FLAG_trace_zones = true;
|
||||
#endif
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
Thread* thread = Thread::Current();
|
||||
EXPECT(thread->zone() == NULL);
|
||||
{
|
||||
@@ -76,8 +76,8 @@ UNIT_TEST_CASE(AllocGeneric_Success) {
|
||||
#if defined(DEBUG)
|
||||
FLAG_trace_zones = true;
|
||||
#endif
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
Thread* thread = Thread::Current();
|
||||
EXPECT(thread->zone() == NULL);
|
||||
{
|
||||
@@ -100,8 +100,8 @@ UNIT_TEST_CASE(AllocGeneric_Overflow) {
|
||||
#if defined(DEBUG)
|
||||
FLAG_trace_zones = true;
|
||||
#endif
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
Thread* thread = Thread::Current();
|
||||
EXPECT(thread->zone() == NULL);
|
||||
{
|
||||
@@ -119,8 +119,8 @@ UNIT_TEST_CASE(ZoneAllocated) {
|
||||
#if defined(DEBUG)
|
||||
FLAG_trace_zones = true;
|
||||
#endif
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
Thread* thread = Thread::Current();
|
||||
EXPECT(thread->zone() == NULL);
|
||||
static int marker;
|
||||
@@ -175,8 +175,8 @@ UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) {
|
||||
#if defined(DEBUG)
|
||||
FLAG_trace_zones = true;
|
||||
#endif
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL,
|
||||
NULL);
|
||||
Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
|
||||
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
|
||||
Thread* thread = Thread::Current();
|
||||
EXPECT(thread->zone() == NULL);
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user