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

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 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 } 1555 }
1556 } 1556 }
1557 1557
1558 // Check if it is a singleton ICData array object. 1558 // Check if it is a singleton ICData array object.
1559 for (intptr_t i = 0; i < ICData::kCachedICDataArrayCount; i++) { 1559 for (intptr_t i = 0; i < ICData::kCachedICDataArrayCount; i++) {
1560 if (object_id == (kCachedICDataArray0 + i)) { 1560 if (object_id == (kCachedICDataArray0 + i)) {
1561 return ICData::cached_icdata_arrays_[i]; 1561 return ICData::cached_icdata_arrays_[i];
1562 } 1562 }
1563 } 1563 }
1564 1564
1565 ASSERT(Symbols::IsVMSymbolId(object_id)); 1565 ASSERT(Symbols::IsPredefinedSymbolId(object_id));
1566 return Symbols::GetVMSymbol(object_id); // return VM symbol. 1566 return Symbols::GetPredefinedSymbol(object_id); // return VM symbol.
1567 } 1567 }
1568 1568
1569 1569
1570 RawObject* SnapshotReader::ReadIndexedObject(intptr_t object_id, 1570 RawObject* SnapshotReader::ReadIndexedObject(intptr_t object_id,
1571 intptr_t patch_object_id, 1571 intptr_t patch_object_id,
1572 intptr_t patch_offset) { 1572 intptr_t patch_offset) {
1573 intptr_t class_id = ClassIdFromObjectId(object_id); 1573 intptr_t class_id = ClassIdFromObjectId(object_id);
1574 if (IsObjectStoreClassId(class_id)) { 1574 if (IsObjectStoreClassId(class_id)) {
1575 return isolate()->class_table()->At(class_id); // get singleton class. 1575 return isolate()->class_table()->At(class_id); // get singleton class.
1576 } 1576 }
(...skipping 234 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.
siva 2016/05/10 00:49:10 maybe make this comment a little more elaborate by
rmacnak 2016/05/10 01:45:01 Done.
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::LookupPredefinedSymbol(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);
1935 if (id != kInvalidIndex) { 1940 if (id != kInvalidIndex) {
1936 WriteIndexedObject(id); 1941 WriteIndexedObject(id);
1937 return true; 1942 return true;
(...skipping 15 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
2037 #if defined(DEBUG)
2036 // Ensure the class table is valid. 2038 // Ensure the class table is valid.
2037 #if defined(DEBUG)
2038 isolate()->ValidateClassTable(); 2039 isolate()->ValidateClassTable();
2039 #endif 2040 #endif
2041 // Can't have any mutation happening while we're serializing.
2040 ASSERT(isolate()->background_compiler() == NULL); 2042 ASSERT(isolate()->background_compiler() == NULL);
2041 2043
2042 // Collect all the script objects and their accompanying token stream objects 2044 intptr_t first_object_id = -1;
2043 // into an array so that we can write it out as part of the VM isolate 2045 if (vm_isolate_snapshot_buffer != NULL) {
2044 // snapshot. We first count the number of script objects, allocate an array 2046 // Collect all the script objects and their accompanying token stream
2045 // and then fill it up with the script objects. 2047 // objects into an array so that we can write it out as part of the VM
2046 ScriptVisitor scripts_counter(thread()); 2048 // isolate snapshot. We first count the number of script objects, allocate
2047 heap()->IterateOldObjects(&scripts_counter); 2049 // an array and then fill it up with the script objects.
2048 intptr_t count = scripts_counter.count(); 2050 ScriptVisitor scripts_counter(thread());
2049 scripts_ = Array::New(count, Heap::kOld); 2051 heap()->IterateOldObjects(&scripts_counter);
2050 ScriptVisitor script_visitor(thread(), &scripts_); 2052 Dart::vm_isolate()->heap()->IterateOldObjects(&scripts_counter);
2051 heap()->IterateOldObjects(&script_visitor); 2053 intptr_t count = scripts_counter.count();
2054 scripts_ = Array::New(count, Heap::kOld);
2055 ScriptVisitor script_visitor(thread(), &scripts_);
2056 heap()->IterateOldObjects(&script_visitor);
2057 Dart::vm_isolate()->heap()->IterateOldObjects(&script_visitor);
2058 ASSERT(script_visitor.count() == count);
2052 2059
2053 if (vm_isolate_snapshot_buffer != NULL) { 2060 // Tuck away the current symbol table.
2054 // Stash the symbol table away for writing and reading into the vm isolate, 2061 saved_symbol_table_ = object_store->symbol_table();
2055 // and reset the symbol table for the regular isolate so that we do not 2062
2056 // write these symbols into the snapshot of a regular dart isolate. 2063 // Create a unified symbol table that will be written as the vm isolate's
2057 symbol_table_ = object_store->symbol_table(); 2064 // symbol table.
2065 new_vm_symbol_table_ = Symbols::UnifiedSymbolTable();
2066
2067 // Create an empty symbol table that will be written as the isolate's symbol
2068 // table.
2058 Symbols::SetupSymbolTable(isolate()); 2069 Symbols::SetupSymbolTable(isolate());
2070
2071 first_object_id = kMaxPredefinedObjectIds;
2072 } else {
2073 intptr_t max_vm_isolate_object_id =
2074 Object::vm_isolate_snapshot_object_table().Length();
2075 first_object_id = kMaxPredefinedObjectIds + max_vm_isolate_object_id;
2059 } 2076 }
2060 2077
2061 forward_list_ = new ForwardList(thread(), SnapshotWriter::FirstObjectId()); 2078 forward_list_ = new ForwardList(thread(), first_object_id);
2062 ASSERT(forward_list_ != NULL); 2079 ASSERT(forward_list_ != NULL);
2063 } 2080 }
2064 2081
2065 2082
2066 FullSnapshotWriter::~FullSnapshotWriter() { 2083 FullSnapshotWriter::~FullSnapshotWriter() {
2067 delete forward_list_; 2084 delete forward_list_;
2068 // We may run Dart code afterwards, restore the symbol table if needed. 2085 // We may run Dart code afterwards, restore the symbol table if needed.
2069 if (!symbol_table_.IsNull()) { 2086 if (!saved_symbol_table_.IsNull()) {
2070 isolate()->object_store()->set_symbol_table(symbol_table_); 2087 isolate()->object_store()->set_symbol_table(saved_symbol_table_);
2071 symbol_table_ = Array::null(); 2088 saved_symbol_table_ = Array::null();
2072 } 2089 }
2090 new_vm_symbol_table_ = Array::null();
2073 scripts_ = Array::null(); 2091 scripts_ = Array::null();
2074 } 2092 }
2075 2093
2076 2094
2077 void FullSnapshotWriter::WriteVmIsolateSnapshot() { 2095 void FullSnapshotWriter::WriteVmIsolateSnapshot() {
2078 ASSERT(vm_isolate_snapshot_buffer_ != NULL); 2096 ASSERT(vm_isolate_snapshot_buffer_ != NULL);
2079 SnapshotWriter writer(thread(), 2097 SnapshotWriter writer(thread(),
2080 kind_, 2098 kind_,
2081 vm_isolate_snapshot_buffer_, 2099 vm_isolate_snapshot_buffer_,
2082 alloc_, 2100 alloc_,
2083 kInitialSize, 2101 kInitialSize,
2084 forward_list_, 2102 forward_list_,
2085 instructions_writer_, 2103 instructions_writer_,
2086 true, /* can_send_any_object */ 2104 true, /* can_send_any_object */
2087 vm_isolate_is_symbolic_); 2105 true /* writing_vm_isolate */);
2088 // Write full snapshot for the VM isolate. 2106 // Write full snapshot for the VM isolate.
2089 // Setup for long jump in case there is an exception while writing 2107 // Setup for long jump in case there is an exception while writing
2090 // the snapshot. 2108 // the snapshot.
2091 LongJumpScope jump; 2109 LongJumpScope jump;
2092 if (setjmp(*jump.Set()) == 0) { 2110 if (setjmp(*jump.Set()) == 0) {
2093 // Reserve space in the output buffer for a snapshot header. 2111 // Reserve space in the output buffer for a snapshot header.
2094 writer.ReserveHeader(); 2112 writer.ReserveHeader();
2095 2113
2096 // Write out the version string. 2114 // Write out the version string.
2097 writer.WriteVersion(); 2115 writer.WriteVersion();
2098 2116
2099 /* 2117 /*
2100 * Now Write out the following 2118 * Now Write out the following
2101 * - the symbol table 2119 * - the symbol table
2102 * - all the scripts and token streams for these scripts 2120 * - all the scripts and token streams for these scripts
2103 * 2121 * - the stub code (precompiled snapshots only)
2104 **/ 2122 **/
2105 // Write out the symbol table. 2123 // Write out the symbol table.
2106 writer.WriteObject(symbol_table_.raw()); 2124 writer.WriteObject(new_vm_symbol_table_.raw());
2107 2125
2108 // Write out all the script objects and the accompanying token streams 2126 // Write out all the script objects and the accompanying token streams
2109 // for the bootstrap libraries so that they are in the VM isolate 2127 // for the bootstrap libraries so that they are in the VM isolate
2110 // read only memory. 2128 // read only memory.
2111 writer.WriteObject(scripts_.raw()); 2129 writer.WriteObject(scripts_.raw());
2112 2130
2113 if (Snapshot::IncludesCode(kind_)) { 2131 if (Snapshot::IncludesCode(kind_)) {
2114 ASSERT(!vm_isolate_is_symbolic_);
2115 StubCode::WriteTo(&writer); 2132 StubCode::WriteTo(&writer);
2116 } 2133 }
2117 2134
2118
2119 writer.FillHeader(writer.kind()); 2135 writer.FillHeader(writer.kind());
2120 2136
2121 vm_isolate_snapshot_size_ = writer.BytesWritten(); 2137 vm_isolate_snapshot_size_ = writer.BytesWritten();
2122 } else { 2138 } else {
2123 writer.ThrowException(writer.exception_type(), writer.exception_msg()); 2139 writer.ThrowException(writer.exception_type(), writer.exception_msg());
2124 } 2140 }
2125 } 2141 }
2126 2142
2127 2143
2128 void FullSnapshotWriter::WriteIsolateFullSnapshot() { 2144 void FullSnapshotWriter::WriteIsolateFullSnapshot() {
2129 SnapshotWriter writer(thread(), 2145 SnapshotWriter writer(thread(),
2130 kind_, 2146 kind_,
2131 isolate_snapshot_buffer_, 2147 isolate_snapshot_buffer_,
2132 alloc_, 2148 alloc_,
2133 kInitialSize, 2149 kInitialSize,
2134 forward_list_, 2150 forward_list_,
2135 instructions_writer_, 2151 instructions_writer_,
2136 true, /* can_send_any_object */ 2152 true, /* can_send_any_object */
2137 true /* vm_isolate_is_symbolic */); 2153 false /* writing_vm_isolate */);
2138 ObjectStore* object_store = isolate()->object_store(); 2154 ObjectStore* object_store = isolate()->object_store();
2139 ASSERT(object_store != NULL); 2155 ASSERT(object_store != NULL);
2140 2156
2141 // Write full snapshot for a regular isolate. 2157 // Write full snapshot for a regular isolate.
2142 // Setup for long jump in case there is an exception while writing 2158 // Setup for long jump in case there is an exception while writing
2143 // the snapshot. 2159 // the snapshot.
2144 LongJumpScope jump; 2160 LongJumpScope jump;
2145 if (setjmp(*jump.Set()) == 0) { 2161 if (setjmp(*jump.Set()) == 0) {
2146 // Reserve space in the output buffer for a snapshot header. 2162 // Reserve space in the output buffer for a snapshot header.
2147 writer.ReserveHeader(); 2163 writer.ReserveHeader();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 OS::Print("Total(CodeSize): %" Pd "\n", total); 2203 OS::Print("Total(CodeSize): %" Pd "\n", total);
2188 } 2204 }
2189 } 2205 }
2190 2206
2191 2207
2192 ForwardList::ForwardList(Thread* thread, intptr_t first_object_id) 2208 ForwardList::ForwardList(Thread* thread, intptr_t first_object_id)
2193 : thread_(thread), 2209 : thread_(thread),
2194 first_object_id_(first_object_id), 2210 first_object_id_(first_object_id),
2195 nodes_(), 2211 nodes_(),
2196 first_unprocessed_object_id_(first_object_id) { 2212 first_unprocessed_object_id_(first_object_id) {
2213 ASSERT(first_object_id > 0);
2197 } 2214 }
2198 2215
2199 2216
2200 ForwardList::~ForwardList() { 2217 ForwardList::~ForwardList() {
2201 heap()->ResetObjectIdTable(); 2218 heap()->ResetObjectIdTable();
2202 } 2219 }
2203 2220
2204 2221
2205 intptr_t ForwardList::AddObject(Zone* zone, 2222 intptr_t ForwardList::AddObject(Zone* zone,
2206 RawObject* raw, 2223 RawObject* raw,
2207 SerializeState state) { 2224 SerializeState state) {
2208 NoSafepointScope no_safepoint; 2225 NoSafepointScope no_safepoint;
2209 intptr_t object_id = next_object_id(); 2226 intptr_t object_id = next_object_id();
2210 ASSERT(object_id > 0 && object_id <= kMaxObjectId); 2227 ASSERT(object_id > 0 && object_id <= kMaxObjectId);
2211 const Object& obj = Object::ZoneHandle(zone, raw); 2228 const Object& obj = Object::ZoneHandle(zone, raw);
2212 Node* node = new Node(&obj, state); 2229 Node* node = new Node(&obj, state);
2213 ASSERT(node != NULL); 2230 ASSERT(node != NULL);
2214 nodes_.Add(node); 2231 nodes_.Add(node);
2215 ASSERT(SnapshotWriter::FirstObjectId() > 0);
2216 ASSERT(object_id != 0); 2232 ASSERT(object_id != 0);
2217 heap()->SetObjectId(raw, object_id); 2233 heap()->SetObjectId(raw, object_id);
2218 return object_id; 2234 return object_id;
2219 } 2235 }
2220 2236
2221 2237
2222 intptr_t ForwardList::FindObject(RawObject* raw) { 2238 intptr_t ForwardList::FindObject(RawObject* raw) {
2223 NoSafepointScope no_safepoint; 2239 NoSafepointScope no_safepoint;
2224 ASSERT(SnapshotWriter::FirstObjectId() > 0);
2225 intptr_t id = heap()->GetObjectId(raw); 2240 intptr_t id = heap()->GetObjectId(raw);
2226 ASSERT(id == 0 || NodeForObjectId(id)->obj()->raw() == raw); 2241 ASSERT(id == 0 || NodeForObjectId(id)->obj()->raw() == raw);
2227 return (id == 0) ? static_cast<intptr_t>(kInvalidIndex) : id; 2242 return (id == 0) ? static_cast<intptr_t>(kInvalidIndex) : id;
2228 } 2243 }
2229 2244
2230 2245
2231 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) { 2246 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) {
2232 // Check if object can be written in one of the following ways: 2247 // Check if object can be written in one of the following ways:
2233 // - Smi: the Smi value is written as is (last bit is not tagged). 2248 // - Smi: the Smi value is written as is (last bit is not tagged).
2234 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) 2249 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3)
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
2673 2688
2674 2689
2675 void SnapshotWriter::WriteVersion() { 2690 void SnapshotWriter::WriteVersion() {
2676 const char* expected_version = Version::SnapshotString(); 2691 const char* expected_version = Version::SnapshotString();
2677 ASSERT(expected_version != NULL); 2692 ASSERT(expected_version != NULL);
2678 const intptr_t version_len = strlen(expected_version); 2693 const intptr_t version_len = strlen(expected_version);
2679 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); 2694 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len);
2680 } 2695 }
2681 2696
2682 2697
2683 intptr_t SnapshotWriter::FirstObjectId() {
2684 intptr_t max_vm_isolate_object_id =
2685 Object::vm_isolate_snapshot_object_table().Length();
2686 return kMaxPredefinedObjectIds + max_vm_isolate_object_id;
2687 }
2688
2689
2690 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer, 2698 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer,
2691 ReAlloc alloc) 2699 ReAlloc alloc)
2692 : SnapshotWriter(Thread::Current(), 2700 : SnapshotWriter(Thread::Current(),
2693 Snapshot::kScript, 2701 Snapshot::kScript,
2694 buffer, 2702 buffer,
2695 alloc, 2703 alloc,
2696 kInitialSize, 2704 kInitialSize,
2697 &forward_list_, 2705 &forward_list_,
2698 NULL, /* instructions_writer */ 2706 NULL, /* instructions_writer */
2699 true, /* can_send_any_object */ 2707 true, /* can_send_any_object */
2700 true /* vm_isolate_is_symbolic */), 2708 false /* writing_vm_isolate */),
2701 forward_list_(thread(), kMaxPredefinedObjectIds) { 2709 forward_list_(thread(), kMaxPredefinedObjectIds) {
2702 ASSERT(buffer != NULL); 2710 ASSERT(buffer != NULL);
2703 ASSERT(alloc != NULL); 2711 ASSERT(alloc != NULL);
2704 } 2712 }
2705 2713
2706 2714
2707 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { 2715 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) {
2708 ASSERT(kind() == Snapshot::kScript); 2716 ASSERT(kind() == Snapshot::kScript);
2709 ASSERT(isolate() != NULL); 2717 ASSERT(isolate() != NULL);
2710 ASSERT(ClassFinalizer::AllClassesFinalized()); 2718 ASSERT(ClassFinalizer::AllClassesFinalized());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2746 ReAlloc alloc, 2754 ReAlloc alloc,
2747 bool can_send_any_object) 2755 bool can_send_any_object)
2748 : SnapshotWriter(Thread::Current(), 2756 : SnapshotWriter(Thread::Current(),
2749 Snapshot::kMessage, 2757 Snapshot::kMessage,
2750 buffer, 2758 buffer,
2751 alloc, 2759 alloc,
2752 kInitialSize, 2760 kInitialSize,
2753 &forward_list_, 2761 &forward_list_,
2754 NULL, /* instructions_writer */ 2762 NULL, /* instructions_writer */
2755 can_send_any_object, 2763 can_send_any_object,
2756 true /* vm_isolate_is_symbolic */), 2764 false /* writing_vm_isolate */),
2757 forward_list_(thread(), kMaxPredefinedObjectIds) { 2765 forward_list_(thread(), kMaxPredefinedObjectIds) {
2758 ASSERT(buffer != NULL); 2766 ASSERT(buffer != NULL);
2759 ASSERT(alloc != NULL); 2767 ASSERT(alloc != NULL);
2760 } 2768 }
2761 2769
2762 2770
2763 void MessageWriter::WriteMessage(const Object& obj) { 2771 void MessageWriter::WriteMessage(const Object& obj) {
2764 ASSERT(kind() == Snapshot::kMessage); 2772 ASSERT(kind() == Snapshot::kMessage);
2765 ASSERT(isolate() != NULL); 2773 ASSERT(isolate() != NULL);
2766 2774
2767 // Setup for long jump in case there is an exception while writing 2775 // Setup for long jump in case there is an exception while writing
2768 // the message. 2776 // the message.
2769 LongJumpScope jump; 2777 LongJumpScope jump;
2770 if (setjmp(*jump.Set()) == 0) { 2778 if (setjmp(*jump.Set()) == 0) {
2771 NoSafepointScope no_safepoint; 2779 NoSafepointScope no_safepoint;
2772 WriteObject(obj.raw()); 2780 WriteObject(obj.raw());
2773 } else { 2781 } else {
2774 ThrowException(exception_type(), exception_msg()); 2782 ThrowException(exception_type(), exception_msg());
2775 } 2783 }
2776 } 2784 }
2777 2785
2778 2786
2779 } // namespace dart 2787 } // namespace dart
OLDNEW
« runtime/vm/snapshot.h ('K') | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698