diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc index 86685dc9ef5dd..6eade2f26f4f5 100644 --- a/runtime/bin/dartutils.cc +++ b/runtime/bin/dartutils.cc @@ -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, @@ -436,8 +435,6 @@ DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const char* filename) { if (file != NULL) { RefCntReleaseScope 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 = @@ -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; } diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h index 5bfaf6dbeb1d7..666d248e6380f 100644 --- a/runtime/bin/dartutils.h +++ b/runtime/bin/dartutils.h @@ -222,7 +222,6 @@ class DartUtils { static Dart_Handle ResolveScript(Dart_Handle url); enum MagicNumber { - kSnapshotMagicNumber, kAppJITMagicNumber, kKernelMagicNumber, kKernelListMagicNumber, @@ -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; diff --git a/runtime/bin/loader.cc b/runtime/bin/loader.cc index b3a9074d31b9e..b7418a940e9a7 100644 --- a/runtime/bin/loader.cc +++ b/runtime/bin/loader.cc @@ -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 diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc index 133b9c7c183c5..5f30cfb157c1a 100644 --- a/runtime/bin/main.cc +++ b/runtime/bin/main.cc @@ -915,7 +915,7 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { IsolateData* isolate_data = reinterpret_cast(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 diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc index 38e7fa60e0967..bbaeaadc8916f 100644 --- a/runtime/bin/main_options.cc +++ b/runtime/bin/main_options.cc @@ -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; @@ -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; diff --git a/runtime/bin/main_options.h b/runtime/bin/main_options.h index 11681aed835d5..eebc9edf6d40d 100644 --- a/runtime/bin/main_options.h +++ b/runtime/bin/main_options.h @@ -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, }; diff --git a/runtime/bin/snapshot_utils.cc b/runtime/bin/snapshot_utils.cc index 99ee0ec8e0d41..ad6c28f8607d5 100644 --- a/runtime/bin/snapshot_utils.cc +++ b/runtime/bin/snapshot_utils.cc @@ -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) { @@ -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)); @@ -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. diff --git a/runtime/bin/snapshot_utils.h b/runtime/bin/snapshot_utils.h index c1d6edf2bf487..d93af1445c231 100644 --- a/runtime/bin/snapshot_utils.h +++ b/runtime/bin/snapshot_utils.h @@ -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, diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h index a41812c6e0669..266eb33ec6a5c 100644 --- a/runtime/include/dart_api.h +++ b/runtime/include/dart_api.h @@ -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 @@ -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. @@ -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. * diff --git a/runtime/tests/vm/dart/script_determinism_test.dart b/runtime/tests/vm/dart/script_determinism_test.dart deleted file mode 100644 index 4b51b4faa4d64..0000000000000 --- a/runtime/tests/vm/dart/script_determinism_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// Verify creating a script snapshot twice generates the same bits. - -import 'dart:async'; -import 'snapshot_test_helper.dart'; - -int fib(int n) { - if (n <= 1) return 1; - return fib(n - 1) + fib(n - 2); -} - -Future main(List args) async { - if (args.contains('--child')) { - print(fib(35)); - return; - } - - await checkDeterministicSnapshot("script", ""); -} diff --git a/runtime/tests/vm/vm.status b/runtime/tests/vm/vm.status index fcf7c0f28595d..e4f01e47e7618 100644 --- a/runtime/tests/vm/vm.status +++ b/runtime/tests/vm/vm.status @@ -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 @@ -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 @@ -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. diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index 3d41c2614c07d..d72d56916f8c2 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -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; @@ -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) diff --git a/runtime/vm/dart_api_message.cc b/runtime/vm/dart_api_message.cc index 689d488f0cc66..6b4b612f06ba5 100644 --- a/runtime/vm/dart_api_message.cc +++ b/runtime/vm/dart_api_message.cc @@ -504,7 +504,6 @@ Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, intptr_t object_id) { switch (class_id) { case kClassCid: { - Read(); // Consume the is_in_fullsnapshot indicator. Dart_CObject_Internal* object = AllocateDartCObjectClass(); AddBackRef(object_id, object, kIsDeserialized); object->internal.as_class.library_url = ReadObjectImpl(); diff --git a/runtime/vm/object_store.h b/runtime/vm/object_store.h index 0470f1a15cc28..c9d59ae3f9483 100644 --- a/runtime/vm/object_store.h +++ b/runtime/vm/object_store.h @@ -231,7 +231,6 @@ class ObjectStore { case Snapshot::kFullJIT: case Snapshot::kFullAOT: return reinterpret_cast(&megamorphic_miss_function_); - case Snapshot::kScript: case Snapshot::kMessage: case Snapshot::kNone: case Snapshot::kInvalid: diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h index adc81d85b93bb..c81074bc6c1b7 100644 --- a/runtime/vm/raw_object.h +++ b/runtime/vm/raw_object.h @@ -844,7 +844,6 @@ class RawClass : public RawObject { case Snapshot::kFullAOT: return reinterpret_cast(&ptr()->allocation_stub_); case Snapshot::kFull: - case Snapshot::kScript: return reinterpret_cast(&ptr()->direct_subclasses_); case Snapshot::kFullJIT: return reinterpret_cast(&ptr()->dependent_code_); @@ -912,7 +911,6 @@ class RawPatchClass : public RawObject { return reinterpret_cast(&ptr()->script_); case Snapshot::kFull: case Snapshot::kFullJIT: - case Snapshot::kScript: return reinterpret_cast(&ptr()->library_kernel_data_); case Snapshot::kMessage: case Snapshot::kNone: @@ -990,7 +988,6 @@ class RawFunction : public RawObject { case Snapshot::kFullAOT: case Snapshot::kFull: case Snapshot::kFullJIT: - case Snapshot::kScript: return reinterpret_cast(&ptr()->data_); case Snapshot::kMessage: case Snapshot::kNone: @@ -1121,7 +1118,6 @@ class RawField : public RawObject { RawObject** to_snapshot(Snapshot::Kind kind) { switch (kind) { case Snapshot::kFull: - case Snapshot::kScript: return reinterpret_cast(&ptr()->guarded_list_length_); case Snapshot::kFullJIT: return reinterpret_cast(&ptr()->dependent_code_); @@ -1217,7 +1213,6 @@ class RawScript : public RawObject { return reinterpret_cast(&ptr()->url_); case Snapshot::kFull: case Snapshot::kFullJIT: - case Snapshot::kScript: return reinterpret_cast(&ptr()->tokens_); case Snapshot::kMessage: case Snapshot::kNone: @@ -1264,7 +1259,6 @@ class RawLibrary : public RawObject { return reinterpret_cast(&ptr()->load_error_); case Snapshot::kFull: case Snapshot::kFullJIT: - case Snapshot::kScript: return reinterpret_cast(&ptr()->kernel_data_); case Snapshot::kMessage: case Snapshot::kNone: @@ -1783,7 +1777,6 @@ class RawICData : public RawObject { case Snapshot::kFullAOT: return reinterpret_cast(&ptr()->args_descriptor_); case Snapshot::kFull: - case Snapshot::kScript: case Snapshot::kFullJIT: return to(); case Snapshot::kMessage: @@ -1885,7 +1878,6 @@ class RawLibraryPrefix : public RawInstance { RawObject** to_snapshot(Snapshot::Kind kind) { switch (kind) { case Snapshot::kFull: - case Snapshot::kScript: case Snapshot::kFullJIT: return reinterpret_cast(&ptr()->imports_); case Snapshot::kFullAOT: diff --git a/runtime/vm/raw_object_snapshot.cc b/runtime/vm/raw_object_snapshot.cc index 279d28e9e05b5..24a6cd4a5cf4b 100644 --- a/runtime/vm/raw_object_snapshot.cc +++ b/runtime/vm/raw_object_snapshot.cc @@ -36,47 +36,7 @@ RawClass* Class::ReadFrom(SnapshotReader* reader, ASSERT(reader != NULL); Class& cls = Class::ZoneHandle(reader->zone(), Class::null()); - bool is_in_fullsnapshot = reader->Read(); - if ((kind == Snapshot::kScript) && !is_in_fullsnapshot) { - // Read in the base information. - classid_t class_id = reader->ReadClassIDValue(); - - // Allocate class object of specified kind. - if (class_id < kNumPredefinedCids) { - ASSERT((class_id >= kInstanceCid) && (class_id <= kMirrorReferenceCid)); - cls = reader->isolate()->class_table()->At(class_id); - } else { - cls = Class::NewInstanceClass(); - } - reader->AddBackRef(object_id, &cls, kIsDeserialized); - - // Set all non object fields. - if (!RawObject::IsInternalVMdefinedClassId(class_id)) { - // Instance size of a VM defined class is already set up. - cls.set_instance_size_in_words(reader->Read()); - cls.set_next_field_offset_in_words(reader->Read()); - } - cls.set_type_arguments_field_offset_in_words(reader->Read()); - cls.set_num_type_arguments(reader->Read()); - cls.set_has_pragma_and_num_own_type_arguments(reader->Read()); - cls.set_num_native_fields(reader->Read()); - cls.set_token_pos(TokenPosition::SnapshotDecode(reader->Read())); - cls.set_state_bits(reader->Read()); -#if !defined(DART_PRECOMPILED_RUNTIME) - cls.set_kernel_offset(reader->Read()); -#endif - - // Set all the object fields. - READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to_snapshot(kind), - kAsReference); - cls.StorePointer(&cls.raw_ptr()->dependent_code_, Array::null()); - ASSERT(!cls.IsInFullSnapshot()); - // Also sets instance size in class table. - reader->isolate()->class_table()->SetAt(cls.id(), cls.raw()); - } else { - cls ^= reader->ReadClassId(object_id); - ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot()); - } + cls ^= reader->ReadClassId(object_id); return cls.raw(); } @@ -85,7 +45,6 @@ void RawClass::WriteTo(SnapshotWriter* writer, Snapshot::Kind kind, bool as_reference) { ASSERT(writer != NULL); - bool is_in_fullsnapshot = Class::IsInFullSnapshot(this); // Write out the serialization header value for this object. writer->WriteInlinedObjectHeader(object_id); @@ -94,47 +53,14 @@ void RawClass::WriteTo(SnapshotWriter* writer, writer->WriteVMIsolateObject(kClassCid); writer->WriteTags(writer->GetObjectTags(this)); - // Write out the boolean is_in_fullsnapshot first as this will - // help the reader decide how the rest of the information needs - // to be interpreted. - writer->Write(is_in_fullsnapshot); - - if ((kind == Snapshot::kScript) && !is_in_fullsnapshot) { - // Write out all the non object pointer fields. - // NOTE: cpp_vtable_ is not written. - classid_t class_id = ptr()->id_; - ASSERT(class_id != kIllegalCid); - writer->Write(class_id); - if (!RawObject::IsInternalVMdefinedClassId(class_id)) { - // We don't write the instance size of VM defined classes as they - // are already setup during initialization as part of pre populating - // the class table. - writer->Write(ptr()->instance_size_in_words_); - writer->Write(ptr()->next_field_offset_in_words_); - } - writer->Write(ptr()->type_arguments_field_offset_in_words_); - writer->Write(ptr()->num_type_arguments_); - writer->Write(ptr()->has_pragma_and_num_own_type_arguments_); - writer->Write(ptr()->num_native_fields_); - writer->Write(ptr()->token_pos_.SnapshotEncode()); - writer->Write(ptr()->state_bits_); -#if !defined(DART_PRECOMPILED_RUNTIME) - writer->Write(ptr()->kernel_offset_); -#endif - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); + if (writer->can_send_any_object() || + writer->AllowObjectsInDartLibrary(ptr()->library_)) { + writer->WriteClassId(this); } else { - if (writer->can_send_any_object() || - writer->AllowObjectsInDartLibrary(ptr()->library_)) { - writer->WriteClassId(this); - } else { - // We do not allow regular dart instances in isolate messages. - writer->SetWriteException(Exceptions::kArgument, - "Illegal argument in isolate message" - " : (object is a regular Dart Instance)"); - } + // We do not allow regular dart instances in isolate messages. + writer->SetWriteException(Exceptions::kArgument, + "Illegal argument in isolate message" + " : (object is a regular Dart Instance)"); } } @@ -473,8 +399,8 @@ RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, // Read the length so that we can determine instance size to allocate. intptr_t len = reader->ReadSmiValue(); - TypeArguments& type_arguments = TypeArguments::ZoneHandle( - reader->zone(), TypeArguments::New(len, HEAP_SPACE(kind))); + TypeArguments& type_arguments = + TypeArguments::ZoneHandle(reader->zone(), TypeArguments::New(len)); bool is_canonical = RawObject::IsCanonical(tags); bool defer_canonicalization = is_canonical && (!Snapshot::IsFull(kind)); reader->AddBackRef(object_id, &type_arguments, kIsDeserialized, @@ -547,45 +473,15 @@ RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate function object. - PatchClass& cls = PatchClass::ZoneHandle(reader->zone(), PatchClass::New()); - reader->AddBackRef(object_id, &cls, kIsDeserialized); - -#if !defined(DART_PRECOMPILED_RUNTIME) - cls.set_library_kernel_offset(reader->Read()); -#endif - - // Set all the object fields. - READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to_snapshot(kind), - kAsReference); - - return cls.raw(); + UNREACHABLE(); + return PatchClass::null(); } void RawPatchClass::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kPatchClassCid); - writer->WriteTags(writer->GetObjectTags(this)); - -#if !defined(DART_PRECOMPILED_RUNTIME) - writer->Write(ptr()->library_kernel_offset_); -#endif - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); + UNREACHABLE(); } RawClosure* Closure::ReadFrom(SnapshotReader* reader, @@ -602,7 +498,7 @@ void RawClosure::WriteTo(SnapshotWriter* writer, Snapshot::Kind kind, bool as_reference) { ASSERT(writer != NULL); - ASSERT((kind == Snapshot::kMessage) || (kind == Snapshot::kScript)); + ASSERT(kind == Snapshot::kMessage); // Check if closure is serializable, throw an exception otherwise. RawFunction* func = writer->IsSerializableClosure(this); @@ -620,53 +516,15 @@ RawClosureData* ClosureData::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate closure data object. - ClosureData& data = - ClosureData::ZoneHandle(reader->zone(), ClosureData::New()); - reader->AddBackRef(object_id, &data, kIsDeserialized); - - // Set all the object fields. - READ_OBJECT_FIELDS(data, data.raw()->from(), data.raw()->to(), - kAsInlinedObject); - - return data.raw(); + UNREACHABLE(); + return ClosureData::null(); } void RawClosureData::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kClosureDataCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Context scope. - if (ptr()->context_scope_ == Object::empty_context_scope().raw()) { - writer->WriteVMIsolateObject(kEmptyContextScopeObject); - } else if (ptr()->context_scope_->ptr()->is_implicit_) { - writer->WriteObjectImpl(ptr()->context_scope_, kAsInlinedObject); - } else { - // We don't write non implicit context scopes in the snapshot. - writer->WriteVMIsolateObject(kNullObject); - } - - // Parent function. - writer->WriteObjectImpl(ptr()->parent_function_, kAsInlinedObject); - - // Signature type. - writer->WriteObjectImpl(ptr()->signature_type_, kAsInlinedObject); - - // Canonical static closure. - writer->WriteObjectImpl(ptr()->closure_, kAsInlinedObject); + UNREACHABLE(); } RawSignatureData* SignatureData::ReadFrom(SnapshotReader* reader, @@ -674,38 +532,15 @@ RawSignatureData* SignatureData::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate signature data object. - SignatureData& data = - SignatureData::ZoneHandle(reader->zone(), SignatureData::New()); - reader->AddBackRef(object_id, &data, kIsDeserialized); - - // Set all the object fields. - READ_OBJECT_FIELDS(data, data.raw()->from(), data.raw()->to(), - kAsInlinedObject); - - return data.raw(); + UNREACHABLE(); + return SignatureData::null(); } void RawSignatureData::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kSignatureDataCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsInlinedObject); - visitor.VisitPointers(from(), to()); + UNREACHABLE(); } RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, @@ -713,37 +548,15 @@ RawRedirectionData* RedirectionData::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate redirection data object. - RedirectionData& data = - RedirectionData::ZoneHandle(reader->zone(), RedirectionData::New()); - reader->AddBackRef(object_id, &data, kIsDeserialized); - - // Set all the object fields. - READ_OBJECT_FIELDS(data, data.raw()->from(), data.raw()->to(), kAsReference); - - return data.raw(); + UNREACHABLE(); + return RedirectionData::null(); } void RawRedirectionData::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kRedirectionDataCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to()); + UNREACHABLE(); } RawFunction* Function::ReadFrom(SnapshotReader* reader, @@ -751,116 +564,15 @@ RawFunction* Function::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - bool is_in_fullsnapshot = reader->Read(); - if (!is_in_fullsnapshot) { - // Allocate function object. - Function& func = Function::ZoneHandle(reader->zone(), Function::New()); - reader->AddBackRef(object_id, &func, kIsDeserialized); - - // Set all the non object fields. Read the token positions now but - // don't set them until after setting the kind. - const int32_t token_pos = reader->Read(); - const int32_t end_token_pos = reader->Read(); - int32_t kernel_offset = 0; -#if !defined(DART_PRECOMPILED_RUNTIME) - kernel_offset = reader->Read(); -#endif - func.set_packed_fields(reader->Read()); - func.set_kind_tag(reader->Read()); - func.set_token_pos(TokenPosition::SnapshotDecode(token_pos)); - func.set_end_token_pos(TokenPosition::SnapshotDecode(end_token_pos)); - func.set_kernel_offset(kernel_offset); - func.set_usage_counter(reader->Read()); - func.set_deoptimization_counter(reader->Read()); - func.set_optimized_instruction_count(reader->Read()); - func.set_optimized_call_site_count(reader->Read()); - func.set_state_bits(0); - - // Set all the object fields. - READ_OBJECT_FIELDS(func, func.raw()->from(), func.raw()->to_snapshot(kind), - kAsReference); - // Initialize all fields that are not part of the snapshot. - bool is_optimized = func.usage_counter() != 0; - if (is_optimized) { - // Read the ic data array as the function is an optimized one. - (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference); - func.set_ic_data_array(*reader->ArrayHandle()); - } else { - func.ClearICDataArray(); - } - func.ClearCode(); - return func.raw(); - } else { - return reader->ReadFunctionId(object_id); - } + UNREACHABLE(); + return Function::null(); } void RawFunction::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - bool is_in_fullsnapshot = false; - bool owner_is_class = false; - if ((kind == Snapshot::kScript) && !Function::IsSignatureFunction(this)) { - intptr_t tags = writer->GetObjectTags(ptr()->owner_); - intptr_t cid = ClassIdTag::decode(tags); - owner_is_class = (cid == kClassCid); - is_in_fullsnapshot = - owner_is_class ? Class::IsInFullSnapshot( - reinterpret_cast(ptr()->owner_)) - : PatchClass::IsInFullSnapshot( - reinterpret_cast(ptr()->owner_)); - } - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kFunctionCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out the boolean is_in_fullsnapshot first as this will - // help the reader decide how the rest of the information needs - // to be interpreted. - writer->Write(is_in_fullsnapshot); - - if (!is_in_fullsnapshot) { - bool is_optimized = Code::IsOptimized(ptr()->code_); - -// Write out all the non object fields. -#if !defined(DART_PRECOMPILED_RUNTIME) - writer->Write(ptr()->token_pos_.SnapshotEncode()); - writer->Write(ptr()->end_token_pos_.SnapshotEncode()); - writer->Write(ptr()->kernel_offset_); -#endif - writer->Write(ptr()->packed_fields_); - writer->Write(ptr()->kind_tag_); -#if !defined(DART_PRECOMPILED_RUNTIME) - if (is_optimized) { - writer->Write(FLAG_optimization_counter_threshold); - } else { - writer->Write(0); - } - writer->Write(ptr()->deoptimization_counter_); - writer->Write(ptr()->optimized_instruction_count_); - writer->Write(ptr()->optimized_call_site_count_); -#endif - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); - if (is_optimized) { - // Write out the ic data array as the function is optimized. - writer->WriteObjectImpl(ptr()->ic_data_array_, kAsReference); - } - } else { - writer->WriteFunctionId(this, owner_is_class); - } + UNREACHABLE(); } RawField* Field::ReadFrom(SnapshotReader* reader, @@ -868,92 +580,15 @@ RawField* Field::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate field object. - Field& field = Field::ZoneHandle(reader->zone(), Field::New()); - reader->AddBackRef(object_id, &field, kIsDeserialized); - - // Set all non object fields. - field.set_token_pos(TokenPosition::SnapshotDecode(reader->Read())); - field.set_end_token_pos( - TokenPosition::SnapshotDecode(reader->Read())); - field.set_guarded_cid(reader->Read()); - field.set_is_nullable(reader->Read()); - field.set_static_type_exactness_state( - StaticTypeExactnessState::Decode(reader->Read())); -#if !defined(DART_PRECOMPILED_RUNTIME) - field.set_kernel_offset(reader->Read()); -#endif - field.set_kind_bits(reader->Read()); - - // Set all the object fields. - READ_OBJECT_FIELDS(field, field.raw()->from(), field.raw()->to_snapshot(kind), - kAsReference); - field.StorePointer(&field.raw_ptr()->dependent_code_, Array::null()); - - if (!reader->isolate()->use_field_guards()) { - field.set_guarded_cid(kDynamicCid); - field.set_is_nullable(true); - field.set_guarded_list_length(Field::kNoFixedLength); - field.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset); - field.set_static_type_exactness_state( - StaticTypeExactnessState::NotTracking()); - } else { - field.InitializeGuardedListLengthInObjectOffset(); - } - - return field.raw(); + UNREACHABLE(); + return Field::null(); } void RawField::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kFieldCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the non object fields. - writer->Write(ptr()->token_pos_.SnapshotEncode()); - writer->Write(ptr()->end_token_pos_.SnapshotEncode()); - writer->Write(ptr()->guarded_cid_); - writer->Write(ptr()->is_nullable_); - writer->Write(ptr()->static_type_exactness_state_); -#if !defined(DART_PRECOMPILED_RUNTIME) - writer->Write(ptr()->kernel_offset_); -#endif - writer->Write(ptr()->kind_bits_); - - // Write out the name. - writer->WriteObjectImpl(ptr()->name_, kAsReference); - // Write out the owner. - writer->WriteObjectImpl(ptr()->owner_, kAsReference); - // Write out the type. - writer->WriteObjectImpl(ptr()->type_, kAsReference); - // Write out the initial static value or field offset. - if (Field::StaticBit::decode(ptr()->kind_bits_)) { - if (Field::ConstBit::decode(ptr()->kind_bits_)) { - // Do not reset const fields. - writer->WriteObjectImpl(ptr()->value_.static_value_, kAsReference); - } else { - // Otherwise, for static fields we write out the initial static value. - writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); - } - } else { - writer->WriteObjectImpl(ptr()->value_.offset_, kAsReference); - } - // Write out the initializer function or saved initial value. - writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); - // Write out the guarded list length. - writer->WriteObjectImpl(ptr()->guarded_list_length_, kAsReference); + UNREACHABLE(); } RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader, @@ -961,45 +596,15 @@ RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind != Snapshot::kMessage); - - // Create the literal token object. - LiteralToken& literal_token = - LiteralToken::ZoneHandle(reader->zone(), LiteralToken::New()); - reader->AddBackRef(object_id, &literal_token, kIsDeserialized); - - // Read the token attributes. - Token::Kind token_kind = static_cast(reader->Read()); - literal_token.set_kind(token_kind); - - // Set all the object fields. - READ_OBJECT_FIELDS(literal_token, literal_token.raw()->from(), - literal_token.raw()->to(), kAsReference); - - return literal_token.raw(); + UNREACHABLE(); + return LiteralToken::null(); } void RawLiteralToken::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind != Snapshot::kMessage); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kLiteralTokenCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out the kind field. - writer->Write(ptr()->kind_); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to()); + UNREACHABLE(); } RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, @@ -1007,59 +612,15 @@ RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Read the length so that we can determine number of tokens to read. - intptr_t len = reader->ReadSmiValue(); - - // Create the token stream object. - TokenStream& token_stream = - TokenStream::ZoneHandle(reader->zone(), TokenStream::New(len)); - reader->AddBackRef(object_id, &token_stream, kIsDeserialized); - - // Read the stream of tokens into the TokenStream object for script - // snapshots as we made a copy of token stream. - if (kind == Snapshot::kScript) { - NoSafepointScope no_safepoint; - RawExternalTypedData* stream = token_stream.GetStream(); - reader->ReadBytes(stream->ptr()->data_, len); - } - - // Read in the literal/identifier token array. - *(reader->TokensHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); - token_stream.SetTokenObjects(*(reader->TokensHandle())); - // Read in the private key in use by the token stream. - *(reader->StringHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); - token_stream.SetPrivateKey(*(reader->StringHandle())); - - return token_stream.raw(); + UNREACHABLE(); + return TokenStream::null(); } void RawTokenStream::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kTokenStreamCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out the length field and the token stream. - RawExternalTypedData* stream = ptr()->stream_; - intptr_t len = Smi::Value(stream->ptr()->length_); - writer->Write(stream->ptr()->length_); - writer->WriteBytes(stream->ptr()->data_, len); - - // Write out the literal/identifier token array. - writer->WriteObjectImpl(ptr()->token_objects_, kAsInlinedObject); - // Write out the private key in use by the token stream. - writer->WriteObjectImpl(ptr()->private_key_, kAsInlinedObject); + UNREACHABLE(); } RawScript* Script::ReadFrom(SnapshotReader* reader, @@ -1067,64 +628,15 @@ RawScript* Script::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate script object. - Script& script = Script::ZoneHandle(reader->zone(), Script::New()); - reader->AddBackRef(object_id, &script, kIsDeserialized); - - script.StoreNonPointer(&script.raw_ptr()->line_offset_, - reader->Read()); - script.StoreNonPointer(&script.raw_ptr()->col_offset_, - reader->Read()); - script.StoreNonPointer(&script.raw_ptr()->kind_, reader->Read()); - script.StoreNonPointer(&script.raw_ptr()->kernel_script_index_, - reader->Read()); - script.StoreNonPointer(&script.raw_ptr()->load_timestamp_, 0); - - *reader->StringHandle() ^= String::null(); - script.set_source(*reader->StringHandle()); - *reader->StreamHandle() ^= TokenStream::null(); - script.set_tokens(*reader->StreamHandle()); - - // Set all the object fields. - // TODO(5411462): Need to assert No GC can happen here, even though - // allocations may happen. - intptr_t num_flds = (script.raw()->to_snapshot(kind) - script.raw()->from()); - for (intptr_t i = 0; i <= num_flds; i++) { - (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); - script.StorePointer((script.raw()->from() + i), - reader->PassiveObjectHandle()->raw()); - } - - return script.raw(); + UNREACHABLE(); + return Script::null(); } void RawScript::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(tokens_ != TokenStream::null()); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kScriptCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the non object fields. - writer->Write(ptr()->line_offset_); - writer->Write(ptr()->col_offset_); - writer->Write(ptr()->kind_); - writer->Write(ptr()->kernel_script_index_); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); + UNREACHABLE(); } RawLibrary* Library::ReadFrom(SnapshotReader* reader, @@ -1132,109 +644,15 @@ RawLibrary* Library::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind != Snapshot::kMessage); - - Library& library = Library::ZoneHandle(reader->zone(), Library::null()); - reader->AddBackRef(object_id, &library, kIsDeserialized); - - bool is_in_fullsnapshot = reader->Read(); - if ((kind == Snapshot::kScript) && is_in_fullsnapshot) { - // Lookup the object as it should already exist in the heap. - *reader->StringHandle() ^= reader->ReadObjectImpl(kAsInlinedObject); - library = Library::LookupLibrary(reader->thread(), *reader->StringHandle()); - ASSERT(library.is_in_fullsnapshot()); - } else { - // Allocate library object. - library = Library::New(); - - // Set all non object fields. - library.StoreNonPointer(&library.raw_ptr()->index_, - reader->ReadClassIDValue()); - library.StoreNonPointer(&library.raw_ptr()->num_imports_, - reader->Read()); - library.StoreNonPointer(&library.raw_ptr()->load_state_, - reader->Read()); - library.StoreNonPointer(&library.raw_ptr()->corelib_imported_, - reader->Read()); - library.StoreNonPointer(&library.raw_ptr()->is_dart_scheme_, - reader->Read()); - library.StoreNonPointer(&library.raw_ptr()->debuggable_, - reader->Read()); -#if !defined(DART_PRECOMPILED_RUNTIME) - library.StoreNonPointer(&library.raw_ptr()->kernel_offset_, - reader->Read()); -#endif - library.StoreNonPointer(&library.raw_ptr()->is_in_fullsnapshot_, - is_in_fullsnapshot); - // The native resolver and symbolizer are not serialized. - library.set_native_entry_resolver(NULL); - library.set_native_entry_symbol_resolver(NULL); - - // Set all the object fields. - // TODO(5411462): Need to assert No GC can happen here, even though - // allocations may happen. - intptr_t num_flds = - library.raw()->to_snapshot(kind) - library.raw()->from(); - for (intptr_t i = 0; i <= num_flds; i++) { - (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); - library.StorePointer((library.raw()->from() + i), - reader->PassiveObjectHandle()->raw()); - } - // Initialize caches that are not serialized. - library.StorePointer(&library.raw_ptr()->resolved_names_, Array::null()); - library.StorePointer(&library.raw_ptr()->exported_names_, Array::null()); - library.StorePointer(&library.raw_ptr()->loaded_scripts_, Array::null()); - library.Register(reader->thread()); - } - return library.raw(); + UNREACHABLE(); + return Library::null(); } void RawLibrary::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind != Snapshot::kMessage); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kLibraryCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out the boolean is_in_fullsnapshot_ first as this will - // help the reader decide how the rest of the information needs - // to be interpreted. - writer->Write(ptr()->is_in_fullsnapshot_); - - if ((kind == Snapshot::kScript) && ptr()->is_in_fullsnapshot_) { - // Write out library URL so that it can be looked up when reading. - writer->WriteObjectImpl(ptr()->url_, kAsInlinedObject); - } else { - ASSERT(!ptr()->is_in_fullsnapshot_); - // Write out all non object fields. - ASSERT(ptr()->index_ != static_cast(-1)); - writer->WriteClassIDValue(ptr()->index_); - writer->Write(ptr()->num_imports_); - writer->Write(ptr()->load_state_); - writer->Write(ptr()->corelib_imported_); - writer->Write(ptr()->is_dart_scheme_); - writer->Write(ptr()->debuggable_); -#if !defined(DART_PRECOMPILED_RUNTIME) - writer->Write(ptr()->kernel_offset_); -#endif - // We do not serialize the native resolver or symbolizer. These need to be - // explicitly set after deserialization. - - // We do not write the loaded_scripts_ and resolved_names_ caches to the - // snapshot. They get initialized when reading the library from the - // snapshot and will be rebuilt lazily. - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); - } + UNREACHABLE(); } RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, @@ -1242,51 +660,15 @@ RawLibraryPrefix* LibraryPrefix::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate library prefix object. - LibraryPrefix& prefix = - LibraryPrefix::ZoneHandle(reader->zone(), LibraryPrefix::New()); - reader->AddBackRef(object_id, &prefix, kIsDeserialized); - - // Set all non object fields. - prefix.StoreNonPointer(&prefix.raw_ptr()->num_imports_, - reader->Read()); - prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, - reader->Read()); - prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, - !prefix.raw_ptr()->is_deferred_load_); - - // Set all the object fields. - READ_OBJECT_FIELDS(prefix, prefix.raw()->from(), - prefix.raw()->to_snapshot(kind), kAsReference); - prefix.StorePointer(&prefix.raw_ptr()->dependent_code_, Array::null()); - - return prefix.raw(); + UNREACHABLE(); + return LibraryPrefix::null(); } void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteIndexedObject(kLibraryPrefixCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all non object fields. - writer->Write(ptr()->num_imports_); - writer->Write(ptr()->is_deferred_load_); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); + UNREACHABLE(); } RawNamespace* Namespace::ReadFrom(SnapshotReader* reader, @@ -1294,36 +676,15 @@ RawNamespace* Namespace::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - // Allocate Namespace object. - Namespace& ns = Namespace::ZoneHandle(reader->zone(), Namespace::New()); - reader->AddBackRef(object_id, &ns, kIsDeserialized); - - // Set all the object fields. - READ_OBJECT_FIELDS(ns, ns.raw()->from(), ns.raw()->to(), kAsReference); - - return ns.raw(); + UNREACHABLE(); + return Namespace::null(); } void RawNamespace::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kNamespaceCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to()); + UNREACHABLE(); } RawKernelProgramInfo* KernelProgramInfo::ReadFrom(SnapshotReader* reader, @@ -1331,36 +692,15 @@ RawKernelProgramInfo* KernelProgramInfo::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(reader != NULL); - ASSERT(kind == Snapshot::kScript); - - KernelProgramInfo& info = - KernelProgramInfo::ZoneHandle(reader->zone(), KernelProgramInfo::New()); - reader->AddBackRef(object_id, &info, kIsDeserialized); - - // Set all the object fields. - READ_OBJECT_FIELDS(info, info.raw()->from(), info.raw()->to_snapshot(kind), - kAsReference); - return info.raw(); + UNREACHABLE(); + return KernelProgramInfo::null(); } void RawKernelProgramInfo::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(writer != NULL); - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kKernelProgramInfoCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the object pointer fields. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); + UNREACHABLE(); } RawCode* Code::ReadFrom(SnapshotReader* reader, @@ -1637,49 +977,15 @@ RawICData* ICData::ReadFrom(SnapshotReader* reader, intptr_t tags, Snapshot::Kind kind, bool as_reference) { - ASSERT(kind == Snapshot::kScript); - - ICData& result = ICData::ZoneHandle(reader->zone(), ICData::New()); - reader->AddBackRef(object_id, &result, kIsDeserialized); - - NOT_IN_PRECOMPILED(result.set_deopt_id(reader->Read())); - result.set_state_bits(reader->Read()); -#if defined(TAG_IC_DATA) - result.set_tag(static_cast(reader->Read())); -#endif - - // Set all the object fields. - READ_OBJECT_FIELDS(result, result.raw()->from(), - result.raw()->to_snapshot(kind), kAsReference); - - return result.raw(); + UNREACHABLE(); + return ICData::null(); } void RawICData::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - ASSERT(kind == Snapshot::kScript); - - // Write out the serialization header value for this object. - writer->WriteInlinedObjectHeader(object_id); - - // Write out the class and tags information. - writer->WriteVMIsolateObject(kICDataCid); - writer->WriteTags(writer->GetObjectTags(this)); - - // Write out all the non object fields. - NOT_IN_PRECOMPILED(writer->Write(ptr()->deopt_id_)); - writer->Write(ptr()->state_bits_); -#if defined(TAG_IC_DATA) - writer->Write(static_cast(ptr()->tag_)); -#endif - - // Write out all the object pointer fields. - // In precompiled snapshots, omit the owner field. The owner field may - // refer to a function which was always inlined and no longer needed. - SnapshotWriterVisitor visitor(writer, kAsReference); - visitor.VisitPointers(from(), to_snapshot(kind)); + UNREACHABLE(); } RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader, @@ -1871,8 +1177,7 @@ RawInstance* Instance::ReadFrom(SnapshotReader* reader, // Create an Instance object or get canonical one if it is a canonical // constant. Instance& obj = Instance::ZoneHandle(reader->zone(), Instance::null()); - obj ^= Object::Allocate(kInstanceCid, Instance::InstanceSize(), - HEAP_SPACE(kind)); + obj ^= Object::Allocate(kInstanceCid, Instance::InstanceSize(), Heap::kNew); if (RawObject::IsCanonical(tags)) { const char* error_str = NULL; obj = obj.CheckAndCanonicalize(reader->thread(), &error_str); @@ -1929,7 +1234,7 @@ RawInteger* Mint::ReadFrom(SnapshotReader* reader, mint = Mint::NewCanonical(value); ASSERT(mint.IsCanonical()); } else { - mint = Mint::New(value, HEAP_SPACE(kind)); + mint = Mint::New(value); } reader->AddBackRef(object_id, &mint, kIsDeserialized); return mint.raw(); @@ -1972,7 +1277,7 @@ RawDouble* Double::ReadFrom(SnapshotReader* reader, dbl = Double::NewCanonical(value); ASSERT(dbl.IsCanonical()); } else { - dbl = Double::New(value, HEAP_SPACE(kind)); + dbl = Double::New(value); } reader->AddBackRef(object_id, &dbl, kIsDeserialized); return dbl.raw(); @@ -2029,7 +1334,7 @@ void String::ReadFromImpl(SnapshotReader* reader, *str_obj ^= (*new_symbol)(reader->thread(), ptr, len); } else { // Set up the string object. - *str_obj = StringType::New(len, HEAP_SPACE(kind)); + *str_obj = StringType::New(len, Heap::kNew); str_obj->SetHash(0); // Will get computed when needed. if (len == 0) { return; @@ -2198,8 +1503,7 @@ RawArray* Array::ReadFrom(SnapshotReader* reader, state = kIsNotDeserialized; } if (array == NULL) { - array = - &(Array::ZoneHandle(reader->zone(), Array::New(len, HEAP_SPACE(kind)))); + array = &(Array::ZoneHandle(reader->zone(), Array::New(len))); reader->AddBackRef(object_id, array, state); } if (!as_reference) { @@ -2228,8 +1532,7 @@ RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, state = kIsNotDeserialized; } if (array == NULL) { - array = &(Array::ZoneHandle(reader->zone(), - ImmutableArray::New(len, HEAP_SPACE(kind)))); + array = &(Array::ZoneHandle(reader->zone(), ImmutableArray::New(len))); reader->AddBackRef(object_id, array, state); } if (!as_reference) { @@ -2275,7 +1578,7 @@ RawGrowableObjectArray* GrowableObjectArray::ReadFrom(SnapshotReader* reader, // Read the length so that we can determine instance size to allocate. GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( reader->zone(), GrowableObjectArray::null()); - array = GrowableObjectArray::New(0, HEAP_SPACE(kind)); + array = GrowableObjectArray::New(0); reader->AddBackRef(object_id, &array, kIsDeserialized); // Read type arguments of growable array object. @@ -2328,14 +1631,8 @@ RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, LinkedHashMap& map = LinkedHashMap::ZoneHandle(reader->zone(), LinkedHashMap::null()); - if (kind == Snapshot::kScript) { - // The immutable maps that seed map literals are not yet VM-internal, so - // we don't reach this. - UNREACHABLE(); - } else { - // Since the map might contain itself as a key or value, allocate first. - map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); - } + // Since the map might contain itself as a key or value, allocate first. + map = LinkedHashMap::NewUninitialized(); reader->AddBackRef(object_id, &map, kIsDeserialized); // Read the type arguments. @@ -2354,8 +1651,7 @@ RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, intptr_t data_size = Utils::Maximum(Utils::RoundUpToPowerOfTwo(used_data), static_cast(LinkedHashMap::kInitialIndexSize)); - Array& data = Array::ZoneHandle(reader->zone(), - Array::New(data_size, HEAP_SPACE(kind))); + Array& data = Array::ZoneHandle(reader->zone(), Array::New(data_size)); map.SetData(data); map.SetDeletedKeys(0); @@ -2381,10 +1677,6 @@ void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind, bool as_reference) { - if (kind == Snapshot::kScript) { - // The immutable maps that seed map literals are not yet VM-internal, so - // we don't reach this. - } ASSERT(writer != NULL); // Write out the serialization header value for this object. @@ -2441,7 +1733,7 @@ RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, // Create a Float32x4 object. Float32x4& simd = Float32x4::ZoneHandle(reader->zone(), Float32x4::null()); - simd = Float32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind)); + simd = Float32x4::New(value0, value1, value2, value3); reader->AddBackRef(object_id, &simd, kIsDeserialized); return simd.raw(); } @@ -2480,7 +1772,7 @@ RawInt32x4* Int32x4::ReadFrom(SnapshotReader* reader, // Create a Float32x4 object. Int32x4& simd = Int32x4::ZoneHandle(reader->zone(), Int32x4::null()); - simd = Int32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind)); + simd = Int32x4::New(value0, value1, value2, value3); reader->AddBackRef(object_id, &simd, kIsDeserialized); return simd.raw(); } @@ -2517,7 +1809,7 @@ RawFloat64x2* Float64x2::ReadFrom(SnapshotReader* reader, // Create a Float64x2 object. Float64x2& simd = Float64x2::ZoneHandle(reader->zone(), Float64x2::null()); - simd = Float64x2::New(value0, value1, HEAP_SPACE(kind)); + simd = Float64x2::New(value0, value1); reader->AddBackRef(object_id, &simd, kIsDeserialized); return simd.raw(); } @@ -2549,8 +1841,8 @@ RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, intptr_t cid = RawObject::ClassIdTag::decode(tags); intptr_t len = reader->ReadSmiValue(); - TypedData& result = TypedData::ZoneHandle( - reader->zone(), TypedData::New(cid, len, HEAP_SPACE(kind))); + TypedData& result = + TypedData::ZoneHandle(reader->zone(), TypedData::New(cid, len)); reader->AddBackRef(object_id, &result, kIsDeserialized); // Setup the array elements. diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc index 5e1709ce91299..c35af9c352d80 100644 --- a/runtime/vm/snapshot.cc +++ b/runtime/vm/snapshot.cc @@ -157,14 +157,12 @@ const char* Snapshot::KindToCString(Kind kind) { switch (kind) { case kFull: return "full"; - case kScript: - return "script"; - case kMessage: - return "message"; case kFullJIT: return "full-jit"; case kFullAOT: return "full-aot"; + case kMessage: + return "message"; case kNone: return "none"; case kInvalid: @@ -238,8 +236,8 @@ RawObject* SnapshotReader::ReadObject() { // Setup for long jump in case there is an exception while reading. LongJumpScope jump; if (setjmp(*jump.Set()) == 0) { - objects_to_rehash_ = GrowableObjectArray::New(HEAP_SPACE(kind_)); - types_to_postprocess_ = GrowableObjectArray::New(HEAP_SPACE(kind_)); + objects_to_rehash_ = GrowableObjectArray::New(); + types_to_postprocess_ = GrowableObjectArray::New(); PassiveObject& obj = PassiveObject::Handle(zone(), ReadObjectImpl(kAsInlinedObject)); @@ -252,9 +250,6 @@ RawObject* SnapshotReader::ReadObject() { Object& result = Object::Handle(zone_); if (backward_references_->length() > 0) { ProcessDeferredCanonicalizations(); - if (kind() == Snapshot::kScript) { - FixSubclassesAndImplementors(); - } result = (*backward_references_)[0].reference()->raw(); } else { result = obj.raw(); @@ -275,7 +270,7 @@ RawObject* SnapshotReader::ReadObject() { } void SnapshotReader::EnqueueTypePostprocessing(const AbstractType& type) { - types_to_postprocess_.Add(type, HEAP_SPACE(kind_)); + types_to_postprocess_.Add(type); } void SnapshotReader::RunDelayedTypePostprocessing() { @@ -291,7 +286,7 @@ void SnapshotReader::RunDelayedTypePostprocessing() { } void SnapshotReader::EnqueueRehashingOfMap(const LinkedHashMap& map) { - objects_to_rehash_.Add(map, HEAP_SPACE(kind_)); + objects_to_rehash_.Add(map); } RawObject* SnapshotReader::RunDelayedRehashingOfMaps() { @@ -303,8 +298,7 @@ RawObject* SnapshotReader::RunDelayedRehashingOfMaps() { collections_lib.LookupFunctionAllowPrivate(Symbols::_rehashObjects())); ASSERT(!rehashing_function.IsNull()); - const Array& arguments = - Array::Handle(zone_, Array::New(1, HEAP_SPACE(kind_))); + const Array& arguments = Array::Handle(zone_, Array::New(1)); arguments.SetAt(0, objects_to_rehash_); return DartEntry::InvokeFunction(rehashing_function, arguments); @@ -344,42 +338,6 @@ RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { return cls.raw(); } -RawFunction* SnapshotReader::ReadFunctionId(intptr_t object_id) { - ASSERT(kind_ == Snapshot::kScript); - // Read the function header information and lookup the function. - intptr_t func_header = Read(); - ASSERT((func_header & kSmiTagMask) != kSmiTag); - ASSERT(!IsVMIsolateObject(func_header) || - !IsSingletonClassId(GetVMIsolateObjectId(func_header))); - ASSERT((SerializedHeaderTag::decode(func_header) != kObjectId) || - !IsObjectStoreClassId(SerializedHeaderData::decode(func_header))); - Function& func = Function::ZoneHandle(zone(), Function::null()); - AddBackRef(object_id, &func, kIsDeserialized); - // Read the library/class/function information and lookup the function. - str_ ^= ReadObjectImpl(func_header, kAsInlinedObject, kInvalidPatchIndex, 0); - library_ = Library::LookupLibrary(thread(), str_); - if (library_.IsNull() || !library_.Loaded()) { - SetReadException("Expected a library name, but found an invalid name."); - } - str_ ^= ReadObjectImpl(kAsInlinedObject); - if (str_.Equals(Symbols::TopLevel(), 0, Symbols::TopLevel().Length())) { - str_ ^= ReadObjectImpl(kAsInlinedObject); - func ^= library_.LookupLocalFunction(str_); - } else { - cls_ = library_.LookupClassAllowPrivate(str_); - if (cls_.IsNull()) { - SetReadException("Expected a class name, but found an invalid name."); - } - cls_.EnsureIsFinalized(thread()); - str_ ^= ReadObjectImpl(kAsInlinedObject); - func ^= cls_.LookupFunctionAllowPrivate(str_); - } - if (func.IsNull()) { - SetReadException("Expected a function name, but found an invalid name."); - } - return func.raw(); -} - RawObject* SnapshotReader::ReadStaticImplicitClosure(intptr_t object_id, intptr_t class_header) { ASSERT(!Snapshot::IsFull(kind_)); @@ -559,7 +517,7 @@ RawObject* SnapshotReader::ReadInstance(intptr_t object_id, instance_size = cls_.instance_size(); ASSERT(instance_size > 0); // Allocate the instance and read in all the fields for the object. - *result ^= Object::Allocate(cls_.id(), instance_size, HEAP_SPACE(kind_)); + *result ^= Object::Allocate(cls_.id(), instance_size, Heap::kNew); } else { cls_ ^= ReadObjectImpl(kAsInlinedObject); ASSERT(!cls_.IsNull()); @@ -644,31 +602,6 @@ class HeapLocker : public StackResource { PageSpace* page_space_; }; -RawObject* SnapshotReader::ReadScriptSnapshot() { - ASSERT(kind_ == Snapshot::kScript); - - // First read the version string, and check that it matches. - RawApiError* error = VerifyVersionAndFeatures(Isolate::Current()); - if (error != ApiError::null()) { - return error; - } - - // The version string matches. Read the rest of the snapshot. - obj_ = ReadObject(); - if (!obj_.IsLibrary()) { - if (!obj_.IsError()) { - const intptr_t kMessageBufferSize = 128; - char message_buffer[kMessageBufferSize]; - Utils::SNPrint(message_buffer, kMessageBufferSize, - "Invalid object %s found in script snapshot", - obj_.ToCString()); - const String& msg = String::Handle(String::New(message_buffer)); - obj_ = ApiError::New(msg); - } - } - return obj_.raw(); -} - RawApiError* SnapshotReader::VerifyVersionAndFeatures(Isolate* isolate) { // If the version string doesn't match, return an error. // Note: New things are allocated only if we're going to return an error. @@ -899,43 +832,6 @@ void SnapshotReader::ProcessDeferredCanonicalizations() { } } -void SnapshotReader::FixSubclassesAndImplementors() { - Class& cls = Class::Handle(zone()); - Class& supercls = Class::Handle(zone()); - Array& interfaces = Array::Handle(zone()); - AbstractType& interface = AbstractType::Handle(zone()); - Class& interface_cls = Class::Handle(zone()); - for (intptr_t i = 0; i < backward_references_->length(); i++) { - BackRefNode& backref = (*backward_references_)[i]; - Object* objref = backref.reference(); - if (objref->IsClass()) { - cls ^= objref->raw(); - if (!cls.IsInFullSnapshot()) { - supercls = cls.SuperClass(); - if (!supercls.IsNull() && !supercls.IsObjectClass() && - supercls.IsInFullSnapshot()) { - supercls.AddDirectSubclass(cls); - supercls.DisableCHAOptimizedCode(cls); - } - interfaces = cls.interfaces(); - for (intptr_t i = 0; i < interfaces.Length(); i++) { - interface ^= interfaces.At(i); - interface_cls = interface.type_class(); - - interface_cls.set_is_implemented(); - interface_cls.DisableCHAOptimizedCode(cls); - - if (!interface_cls.IsObjectClass() && - interface_cls.IsInFullSnapshot()) { - interface_cls.AddDirectImplementor(cls); - interface_cls.DisableCHAImplementorUsers(); - } - } - } - } - } -} - void SnapshotReader::ArrayReadFrom(intptr_t object_id, const Array& result, intptr_t len, @@ -957,19 +853,6 @@ void SnapshotReader::ArrayReadFrom(intptr_t object_id, } } -ScriptSnapshotReader::ScriptSnapshotReader(const uint8_t* buffer, - intptr_t size, - Thread* thread) - : SnapshotReader(buffer, - size, - Snapshot::kScript, - new ZoneGrowableArray(kNumInitialReferences), - thread) {} - -ScriptSnapshotReader::~ScriptSnapshotReader() { - ResetBackwardReferenceTable(); -} - MessageSnapshotReader::MessageSnapshotReader(Message* message, Thread* thread) : SnapshotReader(message->snapshot(), message->snapshot_length(), @@ -1359,22 +1242,6 @@ void SnapshotWriter::WriteClassId(RawClass* cls) { WriteObjectImpl(cls->ptr()->name_, kAsInlinedObject); } -void SnapshotWriter::WriteFunctionId(RawFunction* func, bool owner_is_class) { - ASSERT(kind_ == Snapshot::kScript); - RawClass* cls = (owner_is_class) - ? reinterpret_cast(func->ptr()->owner_) - : reinterpret_cast(func->ptr()->owner_) - ->ptr() - ->patched_class_; - - // Write out the library url and class name. - RawLibrary* library = cls->ptr()->library_; - ASSERT(library != Library::null()); - WriteObjectImpl(library->ptr()->url_, kAsInlinedObject); - WriteObjectImpl(cls->ptr()->name_, kAsInlinedObject); - WriteObjectImpl(func->ptr()->name_, kAsInlinedObject); -} - void SnapshotWriter::WriteStaticImplicitClosure(intptr_t object_id, RawFunction* func, intptr_t tags) { @@ -1595,47 +1462,6 @@ void SnapshotWriter::WriteVersionAndFeatures() { free(const_cast(expected_features)); } -ScriptSnapshotWriter::ScriptSnapshotWriter(ReAlloc alloc) - : SnapshotWriter(Thread::Current(), - Snapshot::kScript, - alloc, - NULL, - kInitialSize, - &forward_list_, - true /* can_send_any_object */), - forward_list_(thread(), kMaxPredefinedObjectIds) { - ASSERT(alloc != NULL); -} - -void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { - ASSERT(kind() == Snapshot::kScript); - ASSERT(isolate() != NULL); - ASSERT(ClassFinalizer::AllClassesFinalized()); - - // Setup for long jump in case there is an exception while writing - // the snapshot. - LongJumpScope jump; - if (setjmp(*jump.Set()) == 0) { - // Reserve space in the output buffer for a snapshot header. - ReserveHeader(); - - // Write out the version string. - WriteVersionAndFeatures(); - - // Write out the library object. - { - NoSafepointScope no_safepoint; - - // Write out the library object. - WriteObject(lib.raw()); - - FillHeader(kind()); - } - } else { - ThrowException(exception_type(), exception_msg()); - } -} - void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { ASSERT(Utils::IsAligned(first, sizeof(*first))); ASSERT(Utils::IsAligned(last, sizeof(*last))); diff --git a/runtime/vm/snapshot.h b/runtime/vm/snapshot.h index 1a7db5217c87f..a16e1a6450e03 100644 --- a/runtime/vm/snapshot.h +++ b/runtime/vm/snapshot.h @@ -138,8 +138,6 @@ enum SerializeState { kIsNotSerialized = 1, }; -#define HEAP_SPACE(kind) (kind == Snapshot::kMessage) ? Heap::kNew : Heap::kOld - // Structure capturing the raw snapshot. // // TODO(turnidge): Remove this class once the snapshot does not have a @@ -148,14 +146,11 @@ enum SerializeState { class Snapshot { public: enum Kind { - // N.B. The order of these values must be preserved to give proper error - // messages for old snapshots. - kFull = 0, // Full snapshot of core libraries or an application. - kScript, // A partial snapshot of only the application script. - kMessage, // A partial snapshot used only for isolate messaging. - kFullJIT, // Full + JIT code - kFullAOT, // Full + AOT code - kNone, // dart_bootstrap/gen_snapshot + kFull, // Full snapshot of core libraries or an application. + kFullJIT, // Full + JIT code + kFullAOT, // Full + AOT code + kMessage, // A partial snapshot used only for isolate messaging. + kNone, // dart_bootstrap/gen_snapshot kInvalid }; static const char* KindToCString(Kind kind); @@ -387,7 +382,6 @@ class SnapshotReader : public BaseReader { RawObject* RunDelayedRehashingOfMaps(); RawClass* ReadClassId(intptr_t object_id); - RawFunction* ReadFunctionId(intptr_t object_id); RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); // Implementation to read an object. @@ -420,10 +414,6 @@ class SnapshotReader : public BaseReader { // Process all the deferred canonicalization entries and patch all references. void ProcessDeferredCanonicalizations(); - // Update subclasses array and is implemented bit for interfaces/superclass in - // the core snapshot. - void FixSubclassesAndImplementors(); - // Decode class id from the header field. intptr_t LookupInternalClass(intptr_t class_header); @@ -507,15 +497,6 @@ class SnapshotReader : public BaseReader { DISALLOW_COPY_AND_ASSIGN(SnapshotReader); }; -class ScriptSnapshotReader : public SnapshotReader { - public: - ScriptSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); - ~ScriptSnapshotReader(); - - private: - DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); -}; - class MessageSnapshotReader : public SnapshotReader { public: MessageSnapshotReader(Message* message, Thread* thread); @@ -711,8 +692,6 @@ class SnapshotWriter : public BaseWriter { // Write a version string for the snapshot. void WriteVersionAndFeatures(); - void WriteFunctionId(RawFunction* func, bool owner_is_class); - RawFunction* IsSerializableClosure(RawClosure* closure); void WriteStaticImplicitClosure(intptr_t object_id, @@ -794,21 +773,6 @@ class SnapshotWriter : public BaseWriter { DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); }; -class ScriptSnapshotWriter : public SnapshotWriter { - public: - static const intptr_t kInitialSize = 64 * KB; - explicit ScriptSnapshotWriter(ReAlloc alloc); - ~ScriptSnapshotWriter() {} - - // Writes a partial snapshot of the script. - void WriteScriptSnapshot(const Library& lib); - - private: - ForwardList forward_list_; - - DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); -}; - class SerializedObjectBuffer : public StackResource { public: SerializedObjectBuffer() : StackResource(Thread::Current()), message_(NULL) {} diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc index 10b47157e09a3..6e698857d660a 100644 --- a/runtime/vm/snapshot_test.cc +++ b/runtime/vm/snapshot_test.cc @@ -726,31 +726,6 @@ ISOLATE_UNIT_TEST_CASE(SerializeEmptyByteArray) { delete message; } -class TestSnapshotWriter : public SnapshotWriter { - public: - static const intptr_t kInitialSize = 64 * KB; - explicit TestSnapshotWriter(ReAlloc alloc) - : SnapshotWriter(Thread::Current(), - Snapshot::kScript, - alloc, - NULL, - kInitialSize, - &forward_list_, - true /* can_send_any_object */), - forward_list_(thread(), kMaxPredefinedObjectIds) { - ASSERT(alloc != NULL); - } - ~TestSnapshotWriter() {} - - // Writes just a script object - void WriteScript(const Script& script) { WriteObject(script.raw()); } - - private: - ForwardList forward_list_; - - DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); -}; - static void GenerateSourceAndCheck(const Script& script) { // Check if we are able to generate the source from the token stream. // Rescan this source and compare the token stream to see if they are @@ -786,333 +761,6 @@ static void GenerateSourceAndCheck(const Script& script) { } } -ISOLATE_UNIT_TEST_CASE(SerializeScript) { - const char* kScriptChars = - "class A {\n" - " static bar() { return 42; }\n" - " static fly() { return 5; }\n" - " static s1() { return 'this is a string in the source'; }\n" - " static s2() { return 'this is a \"string\" in the source'; }\n" - " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" - " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" - " static ms1() {\n" - " return '''\n" - "abc\n" - "def\n" - "ghi''';\n" - " }\n" - " static ms2() {\n" - " return '''\n" - "abc\n" - "$def\n" - "ghi''';\n" - " }\n" - " static ms3() {\n" - " return '''\n" - "a b c\n" - "d $d e\n" - "g h i''';\n" - " }\n" - " static ms4() {\n" - " return '''\n" - "abc\n" - "${def}\n" - "ghi''';\n" - " }\n" - " static ms5() {\n" - " return '''\n" - "a b c\n" - "d ${d} e\n" - "g h i''';\n" - " }\n" - " static ms6() {\n" - " return '\\t \\n \\x00 \\xFF';\n" - " }\n" - "}\n"; - - Zone* zone = thread->zone(); - String& url = String::Handle(zone, String::New("dart-test:SerializeScript")); - String& source = String::Handle(zone, String::New(kScriptChars)); - Script& script = - Script::Handle(zone, Script::New(url, source, RawScript::kScriptTag)); - const String& lib_url = String::Handle(zone, Symbols::New(thread, "TestLib")); - Library& lib = Library::Handle(zone, Library::New(lib_url)); - lib.Register(thread); - EXPECT(CompilerTest::TestCompileScript(lib, script)); - - // Write snapshot with script content. - TestSnapshotWriter writer(&malloc_allocator); - writer.WriteScript(script); - - // Read object back from the snapshot. - ScriptSnapshotReader reader(writer.buffer(), writer.BytesWritten(), thread); - Script& serialized_script = Script::Handle(zone); - serialized_script ^= reader.ReadObject(); - - // Check if the serialized script object matches the original script. - String& expected_literal = String::Handle(zone); - String& actual_literal = String::Handle(zone); - String& str = String::Handle(zone); - str ^= serialized_script.url(); - EXPECT(url.Equals(str)); - - const TokenStream& expected_tokens = - TokenStream::Handle(zone, script.tokens()); - const TokenStream& serialized_tokens = - TokenStream::Handle(zone, serialized_script.tokens()); - const ExternalTypedData& expected_data = - ExternalTypedData::Handle(zone, expected_tokens.GetStream()); - const ExternalTypedData& serialized_data = - ExternalTypedData::Handle(zone, serialized_tokens.GetStream()); - EXPECT_EQ(expected_data.Length(), serialized_data.Length()); - TokenStream::Iterator expected_iterator(zone, expected_tokens, - TokenPosition::kMinSource); - TokenStream::Iterator serialized_iterator(zone, serialized_tokens, - TokenPosition::kMinSource); - Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); - Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind(); - while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) { - EXPECT_EQ(expected_kind, serialized_kind); - expected_literal ^= expected_iterator.CurrentLiteral(); - actual_literal ^= serialized_iterator.CurrentLiteral(); - EXPECT(expected_literal.Equals(actual_literal)); - expected_iterator.Advance(); - serialized_iterator.Advance(); - expected_kind = expected_iterator.CurrentTokenKind(); - serialized_kind = serialized_iterator.CurrentTokenKind(); - } - - // Check if we are able to generate the source from the token stream. - // Rescan this source and compare the token stream to see if they are - // the same. - GenerateSourceAndCheck(serialized_script); - - free(writer.buffer()); -} - -#if !defined(PRODUCT) // Uses mirrors. -VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { - const char* kScriptChars = - "\n" - "import 'dart:mirrors';" - "import 'dart:isolate';" - "void main() {" - " if (reflectClass(MyException).superclass.reflectedType != " - " IsolateSpawnException) {" - " throw new Exception('Canonicalization failure');" - " }" - " if (reflectClass(IsolateSpawnException).reflectedType != " - " IsolateSpawnException) {" - " throw new Exception('Canonicalization failure');" - " }" - "}\n" - "class MyException extends IsolateSpawnException {}" - "\n"; - - Dart_Handle result; - - uint8_t* buffer; - intptr_t size; - intptr_t vm_isolate_snapshot_size; - uint8_t* isolate_snapshot = NULL; - intptr_t isolate_snapshot_size; - uint8_t* full_snapshot = NULL; - uint8_t* script_snapshot = NULL; - - bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; - FLAG_load_deferred_eagerly = true; - { - // Start an Isolate, and create a full snapshot of it. - TestIsolateScope __test_isolate__; - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Write out the script snapshot. - result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, - &isolate_snapshot, &isolate_snapshot_size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(isolate_snapshot, isolate_snapshot_size)); - full_snapshot = reinterpret_cast(malloc(isolate_snapshot_size)); - memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); - Dart_ExitScope(); - } - FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; - - { - // Now Create an Isolate using the full snapshot and load the - // script and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Create a test library and Load up a test script in it. - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID(lib); - - // Invoke a function which returns an object. - result = Dart_Invoke(lib, NewString("main"), 0, NULL); - EXPECT_VALID(result); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // Create an Isolate using the full snapshot, load a script and create - // a script snapshot of the script. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Create a test library and Load up a test script in it. - TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); - - // Write out the script snapshot. - result = Dart_CreateScriptSnapshot(&buffer, &size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(buffer, size)); - script_snapshot = reinterpret_cast(malloc(size)); - memmove(script_snapshot, buffer, size); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // Now Create an Isolate using the full snapshot and load the - // script snapshot created above and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the test library from the snapshot. - EXPECT(script_snapshot != NULL); - result = Dart_LoadScriptFromSnapshot(script_snapshot, size); - EXPECT_VALID(result); - - // Invoke a function which returns an object. - result = Dart_Invoke(result, NewString("main"), 0, NULL); - EXPECT_VALID(result); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - free(script_snapshot); - free(full_snapshot); -} -#endif - -VM_UNIT_TEST_CASE(ScriptSnapshotsUpdateSubclasses) { - const char* kScriptChars = - "class _DebugDuration extends Duration {\n" - " const _DebugDuration() : super(milliseconds: 42);\n" - "}\n" - "foo(x, y) {\n" - " for (var i = 0; i < 1000000; i++) {\n" - " if (x != y) {\n" - " throw 'Boom!';\n" - " }\n" - " }\n" - "}\n" - "main() {\n" - " final v = const Duration(milliseconds: 42);\n" - " foo(v, new _DebugDuration());\n" - "}\n" - "\n"; - - Dart_Handle result; - - uint8_t* buffer; - intptr_t size; - intptr_t vm_isolate_snapshot_size; - uint8_t* isolate_snapshot = NULL; - intptr_t isolate_snapshot_size; - uint8_t* full_snapshot = NULL; - uint8_t* script_snapshot = NULL; - -#if !defined(PRODUCT) - bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; - FLAG_load_deferred_eagerly = true; -#endif - intptr_t saved_max_polymorphic_checks = FLAG_max_polymorphic_checks; - FLAG_max_polymorphic_checks = 0; - - { - // Start an Isolate, and create a full snapshot of it. - TestIsolateScope __test_isolate__; - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Write out the script snapshot. - result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, - &isolate_snapshot, &isolate_snapshot_size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(isolate_snapshot, isolate_snapshot_size)); - full_snapshot = reinterpret_cast(malloc(isolate_snapshot_size)); - memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); - Dart_ExitScope(); - } - - { - // Now Create an Isolate using the full snapshot and load the - // script and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Create a test library and Load up a test script in it. - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID(lib); - - // Invoke a function which returns an object. - result = Dart_Invoke(lib, NewString("main"), 0, NULL); - EXPECT_VALID(result); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // Create an Isolate using the full snapshot, load a script and create - // a script snapshot of the script. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Create a test library and Load up a test script in it. - TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); - - // Write out the script snapshot. - result = Dart_CreateScriptSnapshot(&buffer, &size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(buffer, size)); - script_snapshot = reinterpret_cast(malloc(size)); - memmove(script_snapshot, buffer, size); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // Now Create an Isolate using the full snapshot and load the - // script snapshot created above and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the test library from the snapshot. - EXPECT(script_snapshot != NULL); - result = Dart_LoadScriptFromSnapshot(script_snapshot, size); - EXPECT_VALID(result); - - // Invoke a function which returns an object. - result = Dart_Invoke(result, NewString("main"), 0, NULL); - EXPECT_VALID(result); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - free(script_snapshot); - free(full_snapshot); - - FLAG_max_polymorphic_checks = saved_max_polymorphic_checks; -#if !defined(PRODUCT) - FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; -#endif -} - static void IterateScripts(const Library& lib) { const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); Script& script = Script::Handle(); @@ -1292,419 +940,6 @@ VM_UNIT_TEST_CASE(FullSnapshot1) { #ifndef PRODUCT -VM_UNIT_TEST_CASE(ScriptSnapshot) { - const char* kLibScriptChars = - "library dart_import_lib;" - "class LibFields {" - " LibFields(int i, int j) : fld1 = i, fld2 = j {}" - " int fld1;" - " final int fld2;" - "}"; - const char* kScriptChars = - "class TestTrace implements StackTrace {" - " TestTrace();" - " String toString() { return 'my trace'; }" - "}" - "class Fields {" - " Fields(int i, int j) : fld1 = i, fld2 = j {}" - " int fld1;" - " final int fld2;" - " static int fld3;" - " static const int fld4 = 10;" - "}" - "class FieldsTest {" - " static Fields testMain() {" - " Fields obj = new Fields(10, 20);" - " Fields.fld3 = 100;" - " if (obj == null) {" - " throw new Exception('Allocation failure');" - " }" - " if (obj.fld1 != 10) {" - " throw new Exception('fld1 needs to be 10');" - " }" - " if (obj.fld2 != 20) {" - " throw new Exception('fld2 needs to be 20');" - " }" - " if (Fields.fld3 != 100) {" - " throw new Exception('Fields.fld3 needs to be 100');" - " }" - " if (Fields.fld4 != 10) {" - " throw new Exception('Fields.fld4 needs to be 10');" - " }" - " return obj;" - " }" - "}"; - Dart_Handle result; - - uint8_t* buffer; - intptr_t size; - intptr_t vm_isolate_snapshot_size; - uint8_t* isolate_snapshot = NULL; - intptr_t isolate_snapshot_size; - uint8_t* full_snapshot = NULL; - uint8_t* script_snapshot = NULL; - intptr_t expected_num_libs; - intptr_t actual_num_libs; - - bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; - FLAG_load_deferred_eagerly = true; - { - // Start an Isolate, and create a full snapshot of it. - TestIsolateScope __test_isolate__; - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Write out the script snapshot. - result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, - &isolate_snapshot, &isolate_snapshot_size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(isolate_snapshot, isolate_snapshot_size)); - full_snapshot = reinterpret_cast(malloc(isolate_snapshot_size)); - memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); - Dart_ExitScope(); - } - FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; - - // Test for Dart_CreateScriptSnapshot. - { - // Create an Isolate using the full snapshot, load a script and create - // a script snapshot of the script. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the library. - Dart_Handle import_lib = - Dart_LoadLibrary(NewString("dart_import_lib"), Dart_Null(), - NewString(kLibScriptChars), 0, 0); - EXPECT_VALID(import_lib); - - // Create a test library and Load up a test script in it. - TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID( - Dart_LibraryImportLibrary(TestCase::lib(), import_lib, Dart_Null())); - EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); - - // Get list of library URLs loaded and save the count. - Dart_Handle libs = Dart_GetLibraryIds(); - EXPECT(Dart_IsList(libs)); - Dart_ListLength(libs, &expected_num_libs); - - // Write out the script snapshot. - result = Dart_CreateScriptSnapshot(&buffer, &size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(buffer, size)); - script_snapshot = reinterpret_cast(malloc(size)); - memmove(script_snapshot, buffer, size); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // Now Create an Isolate using the full snapshot and load the - // script snapshot created above and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the test library from the snapshot. - EXPECT(script_snapshot != NULL); - result = Dart_LoadScriptFromSnapshot(script_snapshot, size); - EXPECT_VALID(result); - - // Get list of library URLs loaded and compare with expected count. - Dart_Handle libs = Dart_GetLibraryIds(); - EXPECT(Dart_IsList(libs)); - Dart_ListLength(libs, &actual_num_libs); - - EXPECT_EQ(expected_num_libs, actual_num_libs); - - // Invoke a function which returns an object. - Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); - result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); - EXPECT_VALID(result); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - free(full_snapshot); - free(script_snapshot); -} - -VM_UNIT_TEST_CASE(ScriptSnapshot1) { - const char* kScriptChars = - "class _SimpleNumEnumerable {" - "final Iterable _source;" - "const _SimpleNumEnumerable(this._source) : super();" - "}"; - - Dart_Handle result; - uint8_t* buffer; - intptr_t size; - intptr_t vm_isolate_snapshot_size; - uint8_t* isolate_snapshot = NULL; - intptr_t isolate_snapshot_size; - uint8_t* full_snapshot = NULL; - uint8_t* script_snapshot = NULL; - - bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; - FLAG_load_deferred_eagerly = true; - bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; - FLAG_concurrent_sweep = false; - { - // Start an Isolate, and create a full snapshot of it. - TestIsolateScope __test_isolate__; - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Write out the script snapshot. - result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, - &isolate_snapshot, &isolate_snapshot_size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(isolate_snapshot, isolate_snapshot_size)); - full_snapshot = reinterpret_cast(malloc(isolate_snapshot_size)); - memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); - Dart_ExitScope(); - } - FLAG_concurrent_sweep = saved_concurrent_sweep_mode; - - { - // Create an Isolate using the full snapshot, load a script and create - // a script snapshot of the script. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Create a test library and Load up a test script in it. - TestCase::LoadTestScript(kScriptChars, NULL); - - // Write out the script snapshot. - result = Dart_CreateScriptSnapshot(&buffer, &size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(buffer, size)); - script_snapshot = reinterpret_cast(malloc(size)); - memmove(script_snapshot, buffer, size); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // Now Create an Isolate using the full snapshot and load the - // script snapshot created above and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the test library from the snapshot. - EXPECT(script_snapshot != NULL); - result = Dart_LoadScriptFromSnapshot(script_snapshot, size); - EXPECT_VALID(result); - Dart_ExitScope(); - } - - FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; - Dart_ShutdownIsolate(); - free(full_snapshot); - free(script_snapshot); -} - -VM_UNIT_TEST_CASE(ScriptSnapshot2) { - // The snapshot of this library is always created in production mode, but - // loaded and executed in both production and checked modes. - // This test verifies that type information is still contained in the snapshot - // although it was created in production mode and that type errors and - // compilation errors (for const fields) are correctly reported according to - // the execution mode. - const char* kLibScriptChars = - "library dart_import_lib;" - "const String s = 1.0;" - "final int i = true;" - "bool b;"; - const char* kScriptChars = - "test_s() {" - " s;" - "}" - "test_i() {" - " i;" - "}" - "test_b() {" - " b = 0;" - "}"; - Dart_Handle result; - - uint8_t* buffer; - intptr_t size; - intptr_t vm_isolate_snapshot_size; - uint8_t* isolate_snapshot = NULL; - intptr_t isolate_snapshot_size; - uint8_t* full_snapshot = NULL; - uint8_t* script_snapshot = NULL; - - // Force creation of snapshot in production mode. - bool saved_enable_type_checks_mode = FLAG_enable_type_checks; - NOT_IN_PRODUCT(FLAG_enable_type_checks = false); - bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; - FLAG_load_deferred_eagerly = true; - bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; - FLAG_concurrent_sweep = false; - { - // Start an Isolate, and create a full snapshot of it. - TestIsolateScope __test_isolate__; - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Write out the script snapshot. - result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, - &isolate_snapshot, &isolate_snapshot_size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(isolate_snapshot, isolate_snapshot_size)); - full_snapshot = reinterpret_cast(malloc(isolate_snapshot_size)); - memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); - Dart_ExitScope(); - } - FLAG_concurrent_sweep = saved_concurrent_sweep_mode; - - { - // Create an Isolate using the full snapshot, load a script and create - // a script snapshot of the script. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the library. - Dart_Handle import_lib = - Dart_LoadLibrary(NewString("dart_import_lib"), Dart_Null(), - NewString(kLibScriptChars), 0, 0); - EXPECT_VALID(import_lib); - - // Create a test library and Load up a test script in it. - TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID( - Dart_LibraryImportLibrary(TestCase::lib(), import_lib, Dart_Null())); - EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); - - // Write out the script snapshot. - result = Dart_CreateScriptSnapshot(&buffer, &size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(buffer, size)); - script_snapshot = reinterpret_cast(malloc(size)); - memmove(script_snapshot, buffer, size); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - // Continue in originally saved mode. - NOT_IN_PRODUCT(FLAG_enable_type_checks = saved_enable_type_checks_mode); - FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; - - { - // Now Create an Isolate using the full snapshot and load the - // script snapshot created above and execute it. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Load the test library from the snapshot. - EXPECT(script_snapshot != NULL); - Dart_Handle lib = Dart_LoadScriptFromSnapshot(script_snapshot, size); - EXPECT_VALID(lib); - - // Invoke the test_s function. - result = Dart_Invoke(lib, NewString("test_s"), 0, NULL); - EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); - - // Invoke the test_i function. - result = Dart_Invoke(lib, NewString("test_i"), 0, NULL); - EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); - - // Invoke the test_b function. - result = Dart_Invoke(lib, NewString("test_b"), 0, NULL); - EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); - Dart_ExitScope(); - } - Dart_ShutdownIsolate(); - free(full_snapshot); - free(script_snapshot); -} - -VM_UNIT_TEST_CASE(MismatchedSnapshotKinds) { - const char* kScriptChars = "main() { print('Hello, world!'); }"; - Dart_Handle result; - - uint8_t* buffer; - intptr_t size; - intptr_t vm_isolate_snapshot_size; - uint8_t* isolate_snapshot = NULL; - intptr_t isolate_snapshot_size; - uint8_t* full_snapshot = NULL; - uint8_t* script_snapshot = NULL; - - bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; - FLAG_load_deferred_eagerly = true; - bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; - FLAG_concurrent_sweep = false; - { - // Start an Isolate, and create a full snapshot of it. - TestIsolateScope __test_isolate__; - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Write out the script snapshot. - result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, - &isolate_snapshot, &isolate_snapshot_size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(isolate_snapshot, isolate_snapshot_size)); - full_snapshot = reinterpret_cast(malloc(isolate_snapshot_size)); - memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); - Dart_ExitScope(); - } - FLAG_concurrent_sweep = saved_concurrent_sweep_mode; - FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; - - { - // Create an Isolate using the full snapshot, load a script and create - // a script snapshot of the script. - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Create a test library and Load up a test script in it. - TestCase::LoadTestScript(kScriptChars, NULL); - - EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); - - // Write out the script snapshot. - result = Dart_CreateScriptSnapshot(&buffer, &size); - EXPECT_VALID(result); - EXPECT(Dart_IsSnapshot(buffer, size)); - script_snapshot = reinterpret_cast(malloc(size)); - memmove(script_snapshot, buffer, size); - Dart_ExitScope(); - Dart_ShutdownIsolate(); - } - - { - // 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, - NULL, NULL, NULL, &error); - EXPECT(isolate == NULL); - EXPECT(error != NULL); - EXPECT_SUBSTRING( - "Incompatible snapshot kinds:" - " vm 'full', isolate 'script'", - error); - free(error); - } - - { - TestCase::CreateTestIsolateFromSnapshot(full_snapshot); - Dart_EnterScope(); // Start a Dart API scope for invoking API functions. - - // Use a full snapshot where a script snapshot is expected. - Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); - EXPECT_ERROR(result, - "Dart_LoadScriptFromSnapshot expects parameter" - " 'buffer' to be a script type snapshot."); - - Dart_ExitScope(); - } - Dart_ShutdownIsolate(); - free(full_snapshot); - free(script_snapshot); -} - VM_UNIT_TEST_CASE(CheckKernelSnapshot) { intptr_t vm_isolate_snapshot_size; uint8_t* isolate_snapshot = NULL; diff --git a/samples/sample_extension/test/sample_extension_script_snapshot_test.dart b/samples/sample_extension/test/sample_extension_script_snapshot_test.dart deleted file mode 100644 index 31b9e03fc5356..0000000000000 --- a/samples/sample_extension/test/sample_extension_script_snapshot_test.dart +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -// -// Dart test program for testing native extensions. - -import 'sample_extension_test_helper.dart'; - -void main() { - testNativeExtensions("script"); -} diff --git a/samples/samples.status b/samples/samples.status index 2d1d4b8ff6575..3af1d7e4bdccb 100644 --- a/samples/samples.status +++ b/samples/samples.status @@ -28,7 +28,6 @@ sample_extension/test/sample_extension_app_snapshot_test: Pass, RuntimeError # I [ $compiler == app_jitk || $compiler == dartk || $compiler == dartkb || $compiler == dartkp ] sample_extension/test/sample_extension_app_snapshot_test: RuntimeError -sample_extension/test/sample_extension_script_snapshot_test: RuntimeError sample_extension/test/sample_extension_test: RuntimeError # Skip tests that use dart:io @@ -37,4 +36,3 @@ sample_extension/*: Skip [ $hot_reload || $hot_reload_rollback ] sample_extension/test/sample_extension_app_snapshot_test: SkipByDesign # Cannot reload with URI pointing to app snapshot. -sample_extension/test/sample_extension_script_snapshot_test: SkipByDesign # Cannot reload with URI pointing to script snapshot. diff --git a/tests/standalone/script_snapshot_depfile_test.dart b/tests/standalone/script_snapshot_depfile_test.dart deleted file mode 100644 index 3bcd2ec0cb6ab..0000000000000 --- a/tests/standalone/script_snapshot_depfile_test.dart +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "dart:io"; - -void main(List args) { - if (args.contains("--child")) { - print("Hello, pre-scanned world!"); - } else { - generateSnapshot(); - } -} - -void generateSnapshot() { - var tempDir = Directory.systemTemp.createTempSync("script-snapshot"); - var snapshotPath = tempDir.uri.resolve("hello.snapshot").toFilePath(); - var depfilePath = tempDir.uri.resolve("hello.snapshot.d").toFilePath(); - var scriptPath = Platform.script.toFilePath(); - - var exec = Platform.resolvedExecutable; - var args = new List(); - args.addAll(Platform.executableArguments); - args.add("--snapshot=$snapshotPath"); - args.add("--snapshot-depfile=$depfilePath"); - args.add(scriptPath); - args.add("--child"); - var result = Process.runSync(exec, args); - - print("Exit code: ${result.exitCode}"); - print("stdout:"); - print(result.stdout); - print("stderr:"); - print(result.stderr); - - if (result.exitCode != 0) { - throw "Bad exit code: ${result.exitCode}"; - } - - var depfileContents = new File(depfilePath).readAsStringSync(); - print("depfile:"); - print(depfileContents); - if (!depfileContents.contains(snapshotPath)) { - print("snapshotPath:"); - print(snapshotPath); - throw "Missing snapshot path"; - } - if (!depfileContents.contains(scriptPath)) { - print("scriptPath:"); - print(scriptPath); - throw "Missing script path"; - } -} diff --git a/tests/standalone/script_snapshot_not_executed_test.dart b/tests/standalone/script_snapshot_not_executed_test.dart deleted file mode 100644 index f00227059ae05..0000000000000 --- a/tests/standalone/script_snapshot_not_executed_test.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "dart:io"; - -void main(List args) { - if (args.contains("--child")) { - print("Hello, pre-scanned world!"); - } else { - runSnapshot(generateSnapshot()); - } -} - -generateSnapshot() { - var tempDir = Directory.systemTemp.createTempSync("script-snapshot"); - var snapshotPath = tempDir.uri.resolve("hello.snapshot").toFilePath(); - - var exec = Platform.resolvedExecutable; - var args = new List(); - args.addAll(Platform.executableArguments); - args.add("--snapshot=$snapshotPath"); - args.add(Platform.script.toFilePath()); - args.add("--child"); - var result = Process.runSync(exec, args); - if (result.exitCode != 0) { - throw "Bad exit code: ${result.exitCode}"; - } - if (result.stdout.contains("Hello, pre-scanned world!")) { - print(result.stdout); - throw "Should not have run the script."; - } - - return snapshotPath; -} - -runSnapshot(var snapshotPath) { - var exec = Platform.resolvedExecutable; - var args = new List(); - args.addAll(Platform.executableArguments); - args.add(snapshotPath); - args.add("--child"); - var result = Process.runSync(exec, args); - if (result.exitCode != 0) { - throw "Bad exit code: ${result.exitCode}"; - } - if (!result.stdout.contains("Hello, pre-scanned world!")) { - print(result.stdout); - throw "Failed to run the snapshot."; - } -} diff --git a/tools/gn.py b/tools/gn.py index 9c24ee307936e..877e73547ca26 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -177,7 +177,7 @@ def ToGnArgs(args, mode, arch, target_os): if arch != HostCpuForArch(arch): # Training an app-jit snapshot under a simulator is slow. Use script # snapshots instead. - gn_args['dart_snapshot_kind'] = 'script' + gn_args['dart_snapshot_kind'] = 'kernel' else: gn_args['dart_snapshot_kind'] = 'app-jit' diff --git a/utils/application_snapshot.gni b/utils/application_snapshot.gni index 16b002566c19e..2b515d04015ad 100644 --- a/utils/application_snapshot.gni +++ b/utils/application_snapshot.gni @@ -11,7 +11,7 @@ declare_args() { # Default to building app-jit snapshots. The simulator and cross builds # override this to script snapshots to cut down on build time. if (target_cpu != host_cpu) { - dart_snapshot_kind = "script" + dart_snapshot_kind = "kernel" } else { dart_snapshot_kind = "app-jit" } @@ -96,9 +96,9 @@ template("_application_snapshot") { "--snapshot-depfile=$abs_depfile", ] + snapshot_vm_args - if (dart_snapshot_kind == "script") { + if (dart_snapshot_kind == "kernel") { vm_args += [ - "--snapshot-kind=script", + "--snapshot-kind=kernel", ] assert(training_args != "", "Ignoring unused argument") args = []