Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Side by Side Diff: runtime/vm/snapshot.cc

Issue 1944213002: Support for taking full snapshots from 'dart', not just 'dart_bootstrap'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 1811
1812 1812
1813 SnapshotWriter::SnapshotWriter(Thread* thread, 1813 SnapshotWriter::SnapshotWriter(Thread* thread,
1814 Snapshot::Kind kind, 1814 Snapshot::Kind kind,
1815 uint8_t** buffer, 1815 uint8_t** buffer,
1816 ReAlloc alloc, 1816 ReAlloc alloc,
1817 intptr_t initial_size, 1817 intptr_t initial_size,
1818 ForwardList* forward_list, 1818 ForwardList* forward_list,
1819 InstructionsWriter* instructions_writer, 1819 InstructionsWriter* instructions_writer,
1820 bool can_send_any_object, 1820 bool can_send_any_object,
1821 bool vm_isolate_is_symbolic) 1821 bool writing_vm_isolate)
1822 : BaseWriter(buffer, alloc, initial_size), 1822 : BaseWriter(buffer, alloc, initial_size),
1823 thread_(thread), 1823 thread_(thread),
1824 kind_(kind), 1824 kind_(kind),
1825 object_store_(isolate()->object_store()), 1825 object_store_(isolate()->object_store()),
1826 class_table_(isolate()->class_table()), 1826 class_table_(isolate()->class_table()),
1827 forward_list_(forward_list), 1827 forward_list_(forward_list),
1828 instructions_writer_(instructions_writer), 1828 instructions_writer_(instructions_writer),
1829 exception_type_(Exceptions::kNone), 1829 exception_type_(Exceptions::kNone),
1830 exception_msg_(NULL), 1830 exception_msg_(NULL),
1831 unmarked_objects_(false), 1831 unmarked_objects_(false),
1832 can_send_any_object_(can_send_any_object), 1832 can_send_any_object_(can_send_any_object),
1833 vm_isolate_is_symbolic_(vm_isolate_is_symbolic) { 1833 writing_vm_isolate_(writing_vm_isolate) {
1834 ASSERT(forward_list_ != NULL); 1834 ASSERT(forward_list_ != NULL);
1835 } 1835 }
1836 1836
1837 1837
1838 void SnapshotWriter::WriteObject(RawObject* rawobj) { 1838 void SnapshotWriter::WriteObject(RawObject* rawobj) {
1839 WriteObjectImpl(rawobj, kAsInlinedObject); 1839 WriteObjectImpl(rawobj, kAsInlinedObject);
1840 WriteForwardedObjects(); 1840 WriteForwardedObjects();
1841 } 1841 }
1842 1842
1843 1843
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 } 1915 }
1916 1916
1917 // Check if it is a singleton ICData array object. 1917 // Check if it is a singleton ICData array object.
1918 for (intptr_t i = 0; i < ICData::kCachedICDataArrayCount; i++) { 1918 for (intptr_t i = 0; i < ICData::kCachedICDataArrayCount; i++) {
1919 if (rawobj == ICData::cached_icdata_arrays_[i]) { 1919 if (rawobj == ICData::cached_icdata_arrays_[i]) {
1920 WriteVMIsolateObject(kCachedICDataArray0 + i); 1920 WriteVMIsolateObject(kCachedICDataArray0 + i);
1921 return true; 1921 return true;
1922 } 1922 }
1923 } 1923 }
1924 1924
1925 if (writing_vm_isolate_) {
1926 // Write the object instead of a reference.
1927 return false;
1928 }
1929
1925 if (Snapshot::IsFull(kind())) { 1930 if (Snapshot::IsFull(kind())) {
1926 // Check it is a predefined symbol in the VM isolate. 1931 // Check it is a predefined symbol in the VM isolate.
1927 id = Symbols::LookupVMSymbol(rawobj); 1932 id = Symbols::LookupVMSymbol(rawobj);
1928 if (id != kInvalidIndex) { 1933 if (id != kInvalidIndex) {
1929 WriteVMIsolateObject(id); 1934 WriteVMIsolateObject(id);
1930 return true; 1935 return true;
1931 } 1936 }
1932 1937
1933 // Check if it is an object from the vm isolate snapshot object table. 1938 // Check if it is an object from the vm isolate snapshot object table.
1934 id = FindVmSnapshotObject(rawobj); 1939 id = FindVmSnapshotObject(rawobj);
(...skipping 18 matching lines...) Expand all
1953 raw_obj->WriteTo(this, object_id, kind(), false); 1958 raw_obj->WriteTo(this, object_id, kind(), false);
1954 return true; 1959 return true;
1955 } 1960 }
1956 default: 1961 default:
1957 OS::Print("class id = %" Pd "\n", id); 1962 OS::Print("class id = %" Pd "\n", id);
1958 break; 1963 break;
1959 } 1964 }
1960 } 1965 }
1961 } 1966 }
1962 1967
1963 if (!vm_isolate_is_symbolic()) {
1964 return false;
1965 }
1966
1967 const Object& obj = Object::Handle(rawobj); 1968 const Object& obj = Object::Handle(rawobj);
1968 FATAL1("Unexpected reference to object in VM isolate: %s\n", obj.ToCString()); 1969 FATAL1("Unexpected reference to object in VM isolate: %s\n", obj.ToCString());
1969 return false; 1970 return false;
1970 } 1971 }
1971 1972
1972 #undef VM_OBJECT_WRITE 1973 #undef VM_OBJECT_WRITE
1973 1974
1974 1975
1975 // An object visitor which will iterate over all the script objects in the heap 1976 // An object visitor which will iterate over all the script objects in the heap
1976 // and either count them or collect them into an array. This is used during 1977 // and either count them or collect them into an array. This is used during
(...skipping 27 matching lines...) Expand all
2004 Object& objHandle_; 2005 Object& objHandle_;
2005 intptr_t count_; 2006 intptr_t count_;
2006 const Array* scripts_; 2007 const Array* scripts_;
2007 }; 2008 };
2008 2009
2009 2010
2010 FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind, 2011 FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind,
2011 uint8_t** vm_isolate_snapshot_buffer, 2012 uint8_t** vm_isolate_snapshot_buffer,
2012 uint8_t** isolate_snapshot_buffer, 2013 uint8_t** isolate_snapshot_buffer,
2013 ReAlloc alloc, 2014 ReAlloc alloc,
2014 InstructionsWriter* instructions_writer, 2015 InstructionsWriter* instructions_writer)
2015 bool vm_isolate_is_symbolic)
2016 : thread_(Thread::Current()), 2016 : thread_(Thread::Current()),
2017 kind_(kind), 2017 kind_(kind),
2018 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer), 2018 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer),
2019 isolate_snapshot_buffer_(isolate_snapshot_buffer), 2019 isolate_snapshot_buffer_(isolate_snapshot_buffer),
2020 alloc_(alloc), 2020 alloc_(alloc),
2021 vm_isolate_snapshot_size_(0), 2021 vm_isolate_snapshot_size_(0),
2022 isolate_snapshot_size_(0), 2022 isolate_snapshot_size_(0),
2023 forward_list_(NULL), 2023 forward_list_(NULL),
2024 instructions_writer_(instructions_writer), 2024 instructions_writer_(instructions_writer),
2025 scripts_(Array::Handle(zone())), 2025 scripts_(Array::Handle(zone())),
2026 symbol_table_(Array::Handle(zone())), 2026 saved_symbol_table_(Array::Handle(zone())),
2027 vm_isolate_is_symbolic_(vm_isolate_is_symbolic) { 2027 new_vm_symbol_table_(Array::Handle(zone())) {
2028 ASSERT(isolate_snapshot_buffer_ != NULL); 2028 ASSERT(isolate_snapshot_buffer_ != NULL);
2029 ASSERT(alloc_ != NULL); 2029 ASSERT(alloc_ != NULL);
2030 ASSERT(isolate() != NULL); 2030 ASSERT(isolate() != NULL);
2031 ASSERT(ClassFinalizer::AllClassesFinalized()); 2031 ASSERT(ClassFinalizer::AllClassesFinalized());
2032 ASSERT(isolate() != NULL); 2032 ASSERT(isolate() != NULL);
2033 ASSERT(heap() != NULL); 2033 ASSERT(heap() != NULL);
2034 ObjectStore* object_store = isolate()->object_store(); 2034 ObjectStore* object_store = isolate()->object_store();
2035 ASSERT(object_store != NULL); 2035 ASSERT(object_store != NULL);
2036 // Ensure the class table is valid. 2036 // Ensure the class table is valid.
2037 #if defined(DEBUG) 2037 #if defined(DEBUG)
2038 isolate()->ValidateClassTable(); 2038 isolate()->ValidateClassTable();
2039 #endif 2039 #endif
2040 2040
2041 // Collect all the script objects and their accompanying token stream objects 2041 // Collect all the script objects and their accompanying token stream objects
2042 // into an array so that we can write it out as part of the VM isolate 2042 // into an array so that we can write it out as part of the VM isolate
2043 // snapshot. We first count the number of script objects, allocate an array 2043 // snapshot. We first count the number of script objects, allocate an array
2044 // and then fill it up with the script objects. 2044 // and then fill it up with the script objects.
2045 ScriptVisitor scripts_counter(thread()); 2045 ScriptVisitor scripts_counter(thread());
2046 heap()->IterateOldObjects(&scripts_counter); 2046 heap()->IterateOldObjects(&scripts_counter);
2047 intptr_t count = scripts_counter.count(); 2047 intptr_t count = scripts_counter.count();
2048 scripts_ = Array::New(count, Heap::kOld); 2048 scripts_ = Array::New(count, Heap::kOld);
2049 ScriptVisitor script_visitor(thread(), &scripts_); 2049 ScriptVisitor script_visitor(thread(), &scripts_);
2050 heap()->IterateOldObjects(&script_visitor); 2050 heap()->IterateOldObjects(&script_visitor);
2051 2051
2052 if (vm_isolate_snapshot_buffer != NULL) { 2052 if (vm_isolate_snapshot_buffer != NULL) {
2053 // Stash the symbol table away for writing and reading into the vm isolate, 2053 // Tuck away the current symbol table.
2054 // and reset the symbol table for the regular isolate so that we do not 2054 saved_symbol_table_ = object_store->symbol_table();
2055 // write these symbols into the snapshot of a regular dart isolate. 2055
2056 symbol_table_ = object_store->symbol_table(); 2056 // Create a unified symbol table that will be written as the vm isolate's
2057 // symbol table.
2058 new_vm_symbol_table_ = Symbols::UnifiedSymbolTable();
2059
2060 // Create an empty symbol table that will be written as the isolate's symbol
2061 // table.
2057 Symbols::SetupSymbolTable(isolate()); 2062 Symbols::SetupSymbolTable(isolate());
2058 } 2063 }
2059 2064
2060 forward_list_ = new ForwardList(thread(), SnapshotWriter::FirstObjectId()); 2065 forward_list_ = new ForwardList(thread(), SnapshotWriter::FirstObjectId());
2061 ASSERT(forward_list_ != NULL); 2066 ASSERT(forward_list_ != NULL);
2062 } 2067 }
2063 2068
2064 2069
2065 FullSnapshotWriter::~FullSnapshotWriter() { 2070 FullSnapshotWriter::~FullSnapshotWriter() {
2066 delete forward_list_; 2071 delete forward_list_;
2067 // We may run Dart code afterwards, restore the symbol table if needed. 2072 // We may run Dart code afterwards, restore the symbol table if needed.
2068 if (!symbol_table_.IsNull()) { 2073 if (!saved_symbol_table_.IsNull()) {
2069 isolate()->object_store()->set_symbol_table(symbol_table_); 2074 isolate()->object_store()->set_symbol_table(saved_symbol_table_);
2070 symbol_table_ = Array::null(); 2075 saved_symbol_table_ = Array::null();
2071 } 2076 }
2077 new_vm_symbol_table_ = Array::null();
2072 scripts_ = Array::null(); 2078 scripts_ = Array::null();
2073 } 2079 }
2074 2080
2075 2081
2076 void FullSnapshotWriter::WriteVmIsolateSnapshot() { 2082 void FullSnapshotWriter::WriteVmIsolateSnapshot() {
2077 ASSERT(vm_isolate_snapshot_buffer_ != NULL); 2083 ASSERT(vm_isolate_snapshot_buffer_ != NULL);
2078 SnapshotWriter writer(thread(), 2084 SnapshotWriter writer(thread(),
2079 kind_, 2085 kind_,
2080 vm_isolate_snapshot_buffer_, 2086 vm_isolate_snapshot_buffer_,
2081 alloc_, 2087 alloc_,
2082 kInitialSize, 2088 kInitialSize,
2083 forward_list_, 2089 forward_list_,
2084 instructions_writer_, 2090 instructions_writer_,
2085 true, /* can_send_any_object */ 2091 true, /* can_send_any_object */
2086 vm_isolate_is_symbolic_); 2092 true /* writing_vm_isolate */);
2087 // Write full snapshot for the VM isolate. 2093 // Write full snapshot for the VM isolate.
2088 // Setup for long jump in case there is an exception while writing 2094 // Setup for long jump in case there is an exception while writing
2089 // the snapshot. 2095 // the snapshot.
2090 LongJumpScope jump; 2096 LongJumpScope jump;
2091 if (setjmp(*jump.Set()) == 0) { 2097 if (setjmp(*jump.Set()) == 0) {
2092 // Reserve space in the output buffer for a snapshot header. 2098 // Reserve space in the output buffer for a snapshot header.
2093 writer.ReserveHeader(); 2099 writer.ReserveHeader();
2094 2100
2095 // Write out the version string. 2101 // Write out the version string.
2096 writer.WriteVersion(); 2102 writer.WriteVersion();
2097 2103
2098 /* 2104 /*
2099 * Now Write out the following 2105 * Now Write out the following
2100 * - the symbol table 2106 * - the symbol table
2101 * - all the scripts and token streams for these scripts 2107 * - all the scripts and token streams for these scripts
2102 * 2108 * - the stub code (precompiled snapshots only)
2103 **/ 2109 **/
2104 // Write out the symbol table. 2110 // Write out the symbol table.
2105 writer.WriteObject(symbol_table_.raw()); 2111 writer.WriteObject(new_vm_symbol_table_.raw());
2106 2112
2107 // Write out all the script objects and the accompanying token streams 2113 // Write out all the script objects and the accompanying token streams
2108 // for the bootstrap libraries so that they are in the VM isolate 2114 // for the bootstrap libraries so that they are in the VM isolate
2109 // read only memory. 2115 // read only memory.
2110 writer.WriteObject(scripts_.raw()); 2116 writer.WriteObject(scripts_.raw());
2111 2117
2112 if (Snapshot::IncludesCode(kind_)) { 2118 if (Snapshot::IncludesCode(kind_)) {
2113 ASSERT(!vm_isolate_is_symbolic_);
2114 StubCode::WriteTo(&writer); 2119 StubCode::WriteTo(&writer);
2115 } 2120 }
2116 2121
2117
2118 writer.FillHeader(writer.kind()); 2122 writer.FillHeader(writer.kind());
2119 2123
2120 vm_isolate_snapshot_size_ = writer.BytesWritten(); 2124 vm_isolate_snapshot_size_ = writer.BytesWritten();
2121 } else { 2125 } else {
2122 writer.ThrowException(writer.exception_type(), writer.exception_msg()); 2126 writer.ThrowException(writer.exception_type(), writer.exception_msg());
2123 } 2127 }
2124 } 2128 }
2125 2129
2126 2130
2127 void FullSnapshotWriter::WriteIsolateFullSnapshot() { 2131 void FullSnapshotWriter::WriteIsolateFullSnapshot() {
2128 SnapshotWriter writer(thread(), 2132 SnapshotWriter writer(thread(),
2129 kind_, 2133 kind_,
2130 isolate_snapshot_buffer_, 2134 isolate_snapshot_buffer_,
2131 alloc_, 2135 alloc_,
2132 kInitialSize, 2136 kInitialSize,
2133 forward_list_, 2137 forward_list_,
2134 instructions_writer_, 2138 instructions_writer_,
2135 true, /* can_send_any_object */ 2139 true, /* can_send_any_object */
2136 true /* vm_isolate_is_symbolic */); 2140 false /* writing_vm_isolate */);
2137 ObjectStore* object_store = isolate()->object_store(); 2141 ObjectStore* object_store = isolate()->object_store();
2138 ASSERT(object_store != NULL); 2142 ASSERT(object_store != NULL);
2139 2143
2140 // Write full snapshot for a regular isolate. 2144 // Write full snapshot for a regular isolate.
2141 // Setup for long jump in case there is an exception while writing 2145 // Setup for long jump in case there is an exception while writing
2142 // the snapshot. 2146 // the snapshot.
2143 LongJumpScope jump; 2147 LongJumpScope jump;
2144 if (setjmp(*jump.Set()) == 0) { 2148 if (setjmp(*jump.Set()) == 0) {
2145 // Reserve space in the output buffer for a snapshot header. 2149 // Reserve space in the output buffer for a snapshot header.
2146 writer.ReserveHeader(); 2150 writer.ReserveHeader();
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer, 2693 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer,
2690 ReAlloc alloc) 2694 ReAlloc alloc)
2691 : SnapshotWriter(Thread::Current(), 2695 : SnapshotWriter(Thread::Current(),
2692 Snapshot::kScript, 2696 Snapshot::kScript,
2693 buffer, 2697 buffer,
2694 alloc, 2698 alloc,
2695 kInitialSize, 2699 kInitialSize,
2696 &forward_list_, 2700 &forward_list_,
2697 NULL, /* instructions_writer */ 2701 NULL, /* instructions_writer */
2698 true, /* can_send_any_object */ 2702 true, /* can_send_any_object */
2699 true /* vm_isolate_is_symbolic */), 2703 false /* writing_vm_isolate */),
2700 forward_list_(thread(), kMaxPredefinedObjectIds) { 2704 forward_list_(thread(), kMaxPredefinedObjectIds) {
2701 ASSERT(buffer != NULL); 2705 ASSERT(buffer != NULL);
2702 ASSERT(alloc != NULL); 2706 ASSERT(alloc != NULL);
2703 } 2707 }
2704 2708
2705 2709
2706 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { 2710 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) {
2707 ASSERT(kind() == Snapshot::kScript); 2711 ASSERT(kind() == Snapshot::kScript);
2708 ASSERT(isolate() != NULL); 2712 ASSERT(isolate() != NULL);
2709 ASSERT(ClassFinalizer::AllClassesFinalized()); 2713 ASSERT(ClassFinalizer::AllClassesFinalized());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2745 ReAlloc alloc, 2749 ReAlloc alloc,
2746 bool can_send_any_object) 2750 bool can_send_any_object)
2747 : SnapshotWriter(Thread::Current(), 2751 : SnapshotWriter(Thread::Current(),
2748 Snapshot::kMessage, 2752 Snapshot::kMessage,
2749 buffer, 2753 buffer,
2750 alloc, 2754 alloc,
2751 kInitialSize, 2755 kInitialSize,
2752 &forward_list_, 2756 &forward_list_,
2753 NULL, /* instructions_writer */ 2757 NULL, /* instructions_writer */
2754 can_send_any_object, 2758 can_send_any_object,
2755 true /* vm_isolate_is_symbolic */), 2759 false /* writing_vm_isolate */),
2756 forward_list_(thread(), kMaxPredefinedObjectIds) { 2760 forward_list_(thread(), kMaxPredefinedObjectIds) {
2757 ASSERT(buffer != NULL); 2761 ASSERT(buffer != NULL);
2758 ASSERT(alloc != NULL); 2762 ASSERT(alloc != NULL);
2759 } 2763 }
2760 2764
2761 2765
2762 void MessageWriter::WriteMessage(const Object& obj) { 2766 void MessageWriter::WriteMessage(const Object& obj) {
2763 ASSERT(kind() == Snapshot::kMessage); 2767 ASSERT(kind() == Snapshot::kMessage);
2764 ASSERT(isolate() != NULL); 2768 ASSERT(isolate() != NULL);
2765 2769
2766 // Setup for long jump in case there is an exception while writing 2770 // Setup for long jump in case there is an exception while writing
2767 // the message. 2771 // the message.
2768 LongJumpScope jump; 2772 LongJumpScope jump;
2769 if (setjmp(*jump.Set()) == 0) { 2773 if (setjmp(*jump.Set()) == 0) {
2770 NoSafepointScope no_safepoint; 2774 NoSafepointScope no_safepoint;
2771 WriteObject(obj.raw()); 2775 WriteObject(obj.raw());
2772 } else { 2776 } else {
2773 ThrowException(exception_type(), exception_msg()); 2777 ThrowException(exception_type(), exception_msg());
2774 } 2778 }
2775 } 2779 }
2776 2780
2777 2781
2778 } // namespace dart 2782 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698