Skip to content

Commit

Permalink
[vm] Remove script snapshots.
Browse files Browse the repository at this point in the history
Change-Id: I5bc692b754c0909de4aa5f05af81b074578b16f4
Reviewed-on: https://dart-review.googlesource.com/76706
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
rmacnak-google authored and commit-bot@chromium.org committed Sep 26, 2018
1 parent 5d10974 commit 2f25dcd
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 2,089 deletions.
7 changes: 0 additions & 7 deletions runtime/bin/dartutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const char* const DartUtils::kVMServiceLibURL = "dart:vmservice";
dart::SimpleHashMap* DartUtils::environment_ = NULL;

MagicNumberData appjit_magic_number = {8, {0xdc, 0xdc, 0xf6, 0xf6, 0, 0, 0, 0}};
MagicNumberData snapshot_magic_number = {4, {0xf5, 0xf5, 0xdc, 0xdc}};
MagicNumberData kernel_magic_number = {4, {0x90, 0xab, 0xcd, 0xef}};
MagicNumberData kernel_list_magic_number = {
7,
Expand Down Expand Up @@ -436,8 +435,6 @@ DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const char* filename) {
if (file != NULL) {
RefCntReleaseScope<File> rs(file);
intptr_t max_magic_length = 0;
max_magic_length =
Utils::Maximum(max_magic_length, snapshot_magic_number.length);
max_magic_length =
Utils::Maximum(max_magic_length, appjit_magic_number.length);
max_magic_length =
Expand All @@ -458,10 +455,6 @@ DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const char* filename) {

DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t* buffer,
intptr_t buffer_length) {
if (CheckMagicNumber(buffer, buffer_length, snapshot_magic_number)) {
return kSnapshotMagicNumber;
}

if (CheckMagicNumber(buffer, buffer_length, appjit_magic_number)) {
return kAppJITMagicNumber;
}
Expand Down
2 changes: 0 additions & 2 deletions runtime/bin/dartutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class DartUtils {
static Dart_Handle ResolveScript(Dart_Handle url);

enum MagicNumber {
kSnapshotMagicNumber,
kAppJITMagicNumber,
kKernelMagicNumber,
kKernelListMagicNumber,
Expand Down Expand Up @@ -649,7 +648,6 @@ struct MagicNumberData {
};

extern MagicNumberData appjit_magic_number;
extern MagicNumberData snapshot_magic_number;
extern MagicNumberData kernel_magic_number;
extern MagicNumberData kernel_list_magic_number;
extern MagicNumberData gzip_magic_number;
Expand Down
5 changes: 1 addition & 4 deletions runtime/bin/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,7 @@ bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) {
dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0);
} break;
case Dart_kScriptTag:
if (payload_type == DartUtils::kSnapshotMagicNumber) {
dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length);
reload_extensions = true;
} else if (payload_type == DartUtils::kKernelMagicNumber) {
if (payload_type == DartUtils::kKernelMagicNumber) {
// TODO(27590): This code path is only hit when trying to spawn
// isolates. We currently do not have support for neither
// `Isolate.spawn()` nor `Isolate.spawnUri()` with kernel-based
Expand Down
2 changes: 1 addition & 1 deletion runtime/bin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {

IsolateData* isolate_data =
reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate));
if (Options::gen_snapshot_kind() == kScript) {
if (Options::gen_snapshot_kind() == kKernel) {
if (vm_run_app_snapshot) {
Log::PrintErr("Cannot create a script snapshot from an app snapshot.\n");
// The snapshot would contain references to the app snapshot instead of
Expand Down
4 changes: 2 additions & 2 deletions runtime/bin/main_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace bin {

// These strings must match the enum SnapshotKind in main_options.h.
static const char* kSnapshotKindNames[] = {
"none", "script", "app-aot", "app-jit", NULL,
"none", "kernel", "app-aot", "app-jit", NULL,
};

SnapshotKind Options::gen_snapshot_kind_ = kNone;
Expand Down Expand Up @@ -461,7 +461,7 @@ int Options::ParseArguments(int argc,

// If --snapshot is given without --snapshot-kind, default to script snapshot.
if ((snapshot_filename_ != NULL) && (gen_snapshot_kind_ == kNone)) {
gen_snapshot_kind_ = kScript;
gen_snapshot_kind_ = kKernel;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion runtime/bin/main_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace bin {
// This enum must match the strings in kSnapshotKindNames in main_options.cc.
enum SnapshotKind {
kNone,
kScript,
kKernel,
kAppAOT,
kAppJIT,
};
Expand Down
14 changes: 2 additions & 12 deletions runtime/bin/snapshot_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_name) {
return NULL;
}

#if !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING)
static void WriteSnapshotFile(const char* filename,
const uint8_t* buffer,
const intptr_t size) {
Expand All @@ -263,6 +264,7 @@ static void WriteSnapshotFile(const char* filename,
}
file->Release();
}
#endif

static bool WriteInt64(File* file, int64_t size) {
return file->WriteFully(&size, sizeof(size));
Expand Down Expand Up @@ -354,18 +356,6 @@ void Snapshot::GenerateKernel(const char* snapshot_filename,
#endif // !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING)
}

void Snapshot::GenerateScript(const char* snapshot_filename) {
// First create a snapshot.
uint8_t* buffer = NULL;
intptr_t size = 0;
Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size);
if (Dart_IsError(result)) {
ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
}

WriteSnapshotFile(snapshot_filename, buffer, size);
}

void Snapshot::GenerateAppJIT(const char* snapshot_filename) {
#if defined(TARGET_ARCH_IA32)
// Snapshots with code are not supported on IA32.
Expand Down
1 change: 0 additions & 1 deletion runtime/bin/snapshot_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Snapshot {
static void GenerateKernel(const char* snapshot_filename,
const char* script_name,
const char* package_config);
static void GenerateScript(const char* snapshot_filename);
static void GenerateAppJIT(const char* snapshot_filename);
static void GenerateAppAOTAsBlobs(const char* snapshot_filename,
const uint8_t* shared_data,
Expand Down
38 changes: 1 addition & 37 deletions runtime/include/dart_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ DART_EXPORT void Dart_IsolateFlagsInitialize(Dart_IsolateFlags* flags);
* Isolate.spawn, or the argument to Isolate.spawnUri canonicalized by the
* library tag handler of the parent isolate.
* The callback is responsible for loading the program by a call to
* Dart_LoadScript or Dart_LoadScriptFromSnapshot.
* Dart_LoadScript or Dart_LoadScriptFromKernel.
* \param main The name of the main entry point this isolate will
* eventually run. This is provided for advisory purposes only to
* improve debugging messages. The main function is not invoked by
Expand Down Expand Up @@ -1023,26 +1023,6 @@ Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer,
uint8_t** isolate_snapshot_data_buffer,
intptr_t* isolate_snapshot_data_size);

/**
* Creates a snapshot of the application script loaded in the isolate.
*
* A script snapshot can be used for implementing fast startup of applications
* (skips the script tokenizing and parsing process). A Snapshot of the script
* can only be created before any dart code has executed.
*
* Requires there to be a current isolate which already has loaded script.
*
* \param buffer Returns a pointer to a buffer containing
* the snapshot. This buffer is scope allocated and is only valid
* until the next call to Dart_ExitScope.
* \param size Returns the size of the buffer.
*
* \return A valid handle if no error occurs during the operation.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer,
intptr_t* script_snapshot_size);

/**
* Returns whether the buffer contains a snapshot created by
* Dart_Create*Snapshot.
Expand Down Expand Up @@ -2970,22 +2950,6 @@ Dart_LoadScript(Dart_Handle url,
intptr_t line_offset,
intptr_t col_offset);

/**
* Loads the root script for current isolate from a script snapshot. The
* snapshot must have been created by Dart_CreateScriptSnapshot from a VM with
* the same version.
*
* \param buffer A buffer which contains a snapshot of the script. May be
* released when this function returns.
* \param buffer_len Length of the passed in buffer.
*
* \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* script_snapshot_buffer,
intptr_t script_snapshot_size);

/**
* Loads the root library for the current isolate.
*
Expand Down
22 changes: 0 additions & 22 deletions runtime/tests/vm/dart/script_determinism_test.dart

This file was deleted.

3 changes: 0 additions & 3 deletions runtime/tests/vm/vm.status
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ cc/IsolateReload_KernelIncrementalCompileGenerics: SkipByDesign
cc/Mixin_PrivateSuperResolution: Skip
cc/Mixin_PrivateSuperResolutionCrossLibraryShouldFail: Skip
dart/appjit_determinism_test: Pass, Fail # Issue 31427 - Lingering non-determinism.
dart/script_determinism_test: Pass, Fail # Issue 31427 - Lingering non-determinism.

[ $compiler == fasta ]
dart/data_uri_import_test/badencodeddate: CompileTimeError
Expand Down Expand Up @@ -238,7 +237,6 @@ cc/ScriptSnapshotsUpdateSubclasses: Fail, Crash, OK # Script snapshots not suppo

[ ($compiler == dartk || $compiler == dartkb) && ($arch == simarm || $arch == simarm64 || $arch == simdbc || $arch == simdbc64) ]
dart/appjit*: SkipSlow # DFE too slow
dart/script_determinism_test: SkipSlow # DFE too slow

# Enabling of dartk for sim{arm,arm64,dbc64} revelaed these test failures, which
# are to be triaged. Isolate tests are skipped on purpose due to the usage of
Expand Down Expand Up @@ -360,7 +358,6 @@ dart/redirection_type_shuffling_test: SkipByDesign # Imports dart:mirrors

[ $hot_reload || $hot_reload_rollback ]
dart/appjit*: SkipByDesign # Cannot reload with URI pointing to app snapshot.
dart/script_determinism_test: SkipByDesign # Cannot reload with URI pointing to script snapshot.
dart/slow_path_shared_stub_test: SkipSlow # Too slow with --slow-path-triggers-gc flag and not relevant outside precompiled.
dart/spawn_infinite_loop_test: Skip # We can shutdown an isolate before it reloads.
dart/spawn_shutdown_test: Skip # We can shutdown an isolate before it reloads.
Expand Down
102 changes: 0 additions & 102 deletions runtime/vm/dart_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1487,40 +1487,6 @@ Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer,
return Api::Success();
}

DART_EXPORT Dart_Handle
Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer,
intptr_t* script_snapshot_size) {
DARTSCOPE(Thread::Current());
API_TIMELINE_DURATION(T);
Isolate* I = T->isolate();
CHECK_NULL(script_snapshot_buffer);
CHECK_NULL(script_snapshot_size);
if (I->use_dart_frontend()) {
return Api::NewError("Script snapshots are not supported in Dart 2");
}
// Finalize all classes if needed.
Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
if (::Dart_IsError(state)) {
return state;
}
Library& lib = Library::Handle(Z, I->object_store()->root_library());

#if defined(DEBUG)
I->heap()->CollectAllGarbage();
{
HeapIterationScope iteration(T);
CheckFunctionTypesVisitor check_canonical(T);
iteration.IterateObjects(&check_canonical);
}
#endif // #if defined(DEBUG)

ScriptSnapshotWriter writer(ApiReallocate);
writer.WriteScriptSnapshot(lib);
*script_snapshot_buffer = writer.buffer();
*script_snapshot_size = writer.BytesWritten();
return Api::Success();
}

DART_EXPORT bool Dart_IsSnapshot(const uint8_t* buffer, intptr_t buffer_size) {
if (buffer_size < Snapshot::kHeaderSize) {
return false;
Expand Down Expand Up @@ -5074,74 +5040,6 @@ DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
#endif // defined(DART_PRECOMPILED_RUNTIME)
}

DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
intptr_t buffer_len) {
#if defined(DART_PRECOMPILED_RUNTIME)
return Api::NewError("%s: Cannot compile on an AOT runtime.", CURRENT_FUNC);
#else
DARTSCOPE(Thread::Current());
API_TIMELINE_DURATION(T);
Isolate* I = T->isolate();
StackZone zone(T);
if (buffer == NULL) {
RETURN_NULL_ERROR(buffer);
}
if (I->use_dart_frontend()) {
return Api::NewError("Script snapshots are not supported in Dart 2");
}
NoHeapGrowthControlScope no_growth_control;

const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
if (snapshot == NULL) {
return Api::NewError(
"%s expects parameter 'buffer' to be a script type"
" snapshot with a valid length.",
CURRENT_FUNC);
}
if (snapshot->kind() != Snapshot::kScript) {
return Api::NewError(
"%s expects parameter 'buffer' to be a script type"
" snapshot.",
CURRENT_FUNC);
}
if (snapshot->length() != buffer_len) {
return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd
" which is the expected length in the snapshot.",
CURRENT_FUNC, buffer_len, snapshot->length());
}
Library& library = Library::Handle(Z, I->object_store()->root_library());
if (!library.IsNull()) {
const String& library_url = String::Handle(Z, library.url());
return Api::NewError("%s: A script has already been loaded from '%s'.",
CURRENT_FUNC, library_url.ToCString());
}
CHECK_CALLBACK_STATE(T);
CHECK_COMPILATION_ALLOWED(I);

ASSERT(snapshot->kind() == Snapshot::kScript);
NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
"ScriptSnapshotReader"));

ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T);
const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot());
if (tmp.IsError()) {
return Api::NewHandle(T, tmp.raw());
}
#if !defined(PRODUCT)
if (tds2.enabled()) {
tds2.SetNumArguments(2);
tds2.FormatArgument(0, "snapshotSize", "%" Pd, snapshot->length());
tds2.FormatArgument(1, "heapSize", "%" Pd64,
I->heap()->UsedInWords(Heap::kOld) * kWordSize);
}
#endif // !defined(PRODUCT)
library ^= tmp.raw();
library.set_debuggable(true);
I->object_store()->set_root_library(library);
return Api::NewHandle(T, library.raw());
#endif // defined(DART_PRECOMPILED_RUNTIME)
}

DART_EXPORT Dart_Handle Dart_LoadScriptFromKernel(const uint8_t* buffer,
intptr_t buffer_size) {
#if defined(DART_PRECOMPILED_RUNTIME)
Expand Down
1 change: 0 additions & 1 deletion runtime/vm/dart_api_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id,
intptr_t object_id) {
switch (class_id) {
case kClassCid: {
Read<bool>(); // Consume the is_in_fullsnapshot indicator.
Dart_CObject_Internal* object = AllocateDartCObjectClass();
AddBackRef(object_id, object, kIsDeserialized);
object->internal.as_class.library_url = ReadObjectImpl();
Expand Down
1 change: 0 additions & 1 deletion runtime/vm/object_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ class ObjectStore {
case Snapshot::kFullJIT:
case Snapshot::kFullAOT:
return reinterpret_cast<RawObject**>(&megamorphic_miss_function_);
case Snapshot::kScript:
case Snapshot::kMessage:
case Snapshot::kNone:
case Snapshot::kInvalid:
Expand Down
Loading

0 comments on commit 2f25dcd

Please sign in to comment.