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

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
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // When we are writing the VM isolate snapshot, write out the object
1927 // itself instead of a VM object id.
1928 return false;
1929 }
1930
1925 if (Snapshot::IsFull(kind())) { 1931 if (Snapshot::IsFull(kind())) {
1926 // Check it is a predefined symbol in the VM isolate. 1932 // Check it is a predefined symbol in the VM isolate.
1927 id = Symbols::LookupVMSymbol(rawobj); 1933 id = Symbols::LookupPredefinedSymbol(rawobj);
1928 if (id != kInvalidIndex) { 1934 if (id != kInvalidIndex) {
1929 WriteVMIsolateObject(id); 1935 WriteVMIsolateObject(id);
1930 return true; 1936 return true;
1931 } 1937 }
1932 1938
1933 // Check if it is an object from the vm isolate snapshot object table. 1939 // Check if it is an object from the vm isolate snapshot object table.
1934 id = FindVmSnapshotObject(rawobj); 1940 id = FindVmSnapshotObject(rawobj);
1935 if (id != kInvalidIndex) { 1941 if (id != kInvalidIndex) {
1936 WriteIndexedObject(id); 1942 WriteIndexedObject(id);
1937 return true; 1943 return true;
(...skipping 15 matching lines...) Expand all
1953 raw_obj->WriteTo(this, object_id, kind(), false); 1959 raw_obj->WriteTo(this, object_id, kind(), false);
1954 return true; 1960 return true;
1955 } 1961 }
1956 default: 1962 default:
1957 OS::Print("class id = %" Pd "\n", id); 1963 OS::Print("class id = %" Pd "\n", id);
1958 break; 1964 break;
1959 } 1965 }
1960 } 1966 }
1961 } 1967 }
1962 1968
1963 if (!vm_isolate_is_symbolic()) {
1964 return false;
1965 }
1966
1967 const Object& obj = Object::Handle(rawobj); 1969 const Object& obj = Object::Handle(rawobj);
1968 FATAL1("Unexpected reference to object in VM isolate: %s\n", obj.ToCString()); 1970 FATAL1("Unexpected reference to object in VM isolate: %s\n", obj.ToCString());
1969 return false; 1971 return false;
1970 } 1972 }
1971 1973
1972 #undef VM_OBJECT_WRITE 1974 #undef VM_OBJECT_WRITE
1973 1975
1974 1976
1975 // An object visitor which will iterate over all the script objects in the heap 1977 // 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 1978 // and either count them or collect them into an array. This is used during
(...skipping 27 matching lines...) Expand all
2004 Object& objHandle_; 2006 Object& objHandle_;
2005 intptr_t count_; 2007 intptr_t count_;
2006 const Array* scripts_; 2008 const Array* scripts_;
2007 }; 2009 };
2008 2010
2009 2011
2010 FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind, 2012 FullSnapshotWriter::FullSnapshotWriter(Snapshot::Kind kind,
2011 uint8_t** vm_isolate_snapshot_buffer, 2013 uint8_t** vm_isolate_snapshot_buffer,
2012 uint8_t** isolate_snapshot_buffer, 2014 uint8_t** isolate_snapshot_buffer,
2013 ReAlloc alloc, 2015 ReAlloc alloc,
2014 InstructionsWriter* instructions_writer, 2016 InstructionsWriter* instructions_writer)
2015 bool vm_isolate_is_symbolic)
2016 : thread_(Thread::Current()), 2017 : thread_(Thread::Current()),
2017 kind_(kind), 2018 kind_(kind),
2018 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer), 2019 vm_isolate_snapshot_buffer_(vm_isolate_snapshot_buffer),
2019 isolate_snapshot_buffer_(isolate_snapshot_buffer), 2020 isolate_snapshot_buffer_(isolate_snapshot_buffer),
2020 alloc_(alloc), 2021 alloc_(alloc),
2021 vm_isolate_snapshot_size_(0), 2022 vm_isolate_snapshot_size_(0),
2022 isolate_snapshot_size_(0), 2023 isolate_snapshot_size_(0),
2023 forward_list_(NULL), 2024 forward_list_(NULL),
2024 instructions_writer_(instructions_writer), 2025 instructions_writer_(instructions_writer),
2025 scripts_(Array::Handle(zone())), 2026 scripts_(Array::Handle(zone())),
2026 symbol_table_(Array::Handle(zone())), 2027 saved_symbol_table_(Array::Handle(zone())),
2027 vm_isolate_is_symbolic_(vm_isolate_is_symbolic) { 2028 new_vm_symbol_table_(Array::Handle(zone())) {
2028 ASSERT(isolate_snapshot_buffer_ != NULL); 2029 ASSERT(isolate_snapshot_buffer_ != NULL);
2029 ASSERT(alloc_ != NULL); 2030 ASSERT(alloc_ != NULL);
2030 ASSERT(isolate() != NULL); 2031 ASSERT(isolate() != NULL);
2031 ASSERT(ClassFinalizer::AllClassesFinalized()); 2032 ASSERT(ClassFinalizer::AllClassesFinalized());
2032 ASSERT(isolate() != NULL); 2033 ASSERT(isolate() != NULL);
2033 ASSERT(heap() != NULL); 2034 ASSERT(heap() != NULL);
2034 ObjectStore* object_store = isolate()->object_store(); 2035 ObjectStore* object_store = isolate()->object_store();
2035 ASSERT(object_store != NULL); 2036 ASSERT(object_store != NULL);
2037
2038 #if defined(DEBUG)
2036 // Ensure the class table is valid. 2039 // Ensure the class table is valid.
2037 #if defined(DEBUG)
2038 isolate()->ValidateClassTable(); 2040 isolate()->ValidateClassTable();
2039 #endif 2041 #endif
2042 // Can't have any mutation happening while we're serializing.
2040 ASSERT(isolate()->background_compiler() == NULL); 2043 ASSERT(isolate()->background_compiler() == NULL);
2041 2044
2042 // Collect all the script objects and their accompanying token stream objects 2045 intptr_t first_object_id = -1;
2043 // into an array so that we can write it out as part of the VM isolate 2046 if (vm_isolate_snapshot_buffer != NULL) {
2044 // snapshot. We first count the number of script objects, allocate an array 2047 // Collect all the script objects and their accompanying token stream
2045 // and then fill it up with the script objects. 2048 // objects into an array so that we can write it out as part of the VM
2046 ScriptVisitor scripts_counter(thread()); 2049 // isolate snapshot. We first count the number of script objects, allocate
2047 heap()->IterateOldObjects(&scripts_counter); 2050 // an array and then fill it up with the script objects.
2048 intptr_t count = scripts_counter.count(); 2051 ScriptVisitor scripts_counter(thread());
2049 scripts_ = Array::New(count, Heap::kOld); 2052 heap()->IterateOldObjects(&scripts_counter);
2050 ScriptVisitor script_visitor(thread(), &scripts_); 2053 Dart::vm_isolate()->heap()->IterateOldObjects(&scripts_counter);
2051 heap()->IterateOldObjects(&script_visitor); 2054 intptr_t count = scripts_counter.count();
2055 scripts_ = Array::New(count, Heap::kOld);
2056 ScriptVisitor script_visitor(thread(), &scripts_);
2057 heap()->IterateOldObjects(&script_visitor);
2058 Dart::vm_isolate()->heap()->IterateOldObjects(&script_visitor);
2059 ASSERT(script_visitor.count() == count);
2052 2060
2053 if (vm_isolate_snapshot_buffer != NULL) { 2061 // Tuck away the current symbol table.
2054 // Stash the symbol table away for writing and reading into the vm isolate, 2062 saved_symbol_table_ = object_store->symbol_table();
2055 // and reset the symbol table for the regular isolate so that we do not 2063
2056 // write these symbols into the snapshot of a regular dart isolate. 2064 // Create a unified symbol table that will be written as the vm isolate's
2057 symbol_table_ = object_store->symbol_table(); 2065 // symbol table.
2066 new_vm_symbol_table_ = Symbols::UnifiedSymbolTable();
2067
2068 // Create an empty symbol table that will be written as the isolate's symbol
2069 // table.
2058 Symbols::SetupSymbolTable(isolate()); 2070 Symbols::SetupSymbolTable(isolate());
2071
2072 first_object_id = kMaxPredefinedObjectIds;
2073 } else {
2074 intptr_t max_vm_isolate_object_id =
2075 Object::vm_isolate_snapshot_object_table().Length();
2076 first_object_id = kMaxPredefinedObjectIds + max_vm_isolate_object_id;
2059 } 2077 }
2060 2078
2061 forward_list_ = new ForwardList(thread(), SnapshotWriter::FirstObjectId()); 2079 forward_list_ = new ForwardList(thread(), first_object_id);
2062 ASSERT(forward_list_ != NULL); 2080 ASSERT(forward_list_ != NULL);
2063 } 2081 }
2064 2082
2065 2083
2066 FullSnapshotWriter::~FullSnapshotWriter() { 2084 FullSnapshotWriter::~FullSnapshotWriter() {
2067 delete forward_list_; 2085 delete forward_list_;
2068 // We may run Dart code afterwards, restore the symbol table if needed. 2086 // We may run Dart code afterwards, restore the symbol table if needed.
2069 if (!symbol_table_.IsNull()) { 2087 if (!saved_symbol_table_.IsNull()) {
2070 isolate()->object_store()->set_symbol_table(symbol_table_); 2088 isolate()->object_store()->set_symbol_table(saved_symbol_table_);
2071 symbol_table_ = Array::null(); 2089 saved_symbol_table_ = Array::null();
2072 } 2090 }
2091 new_vm_symbol_table_ = Array::null();
2073 scripts_ = Array::null(); 2092 scripts_ = Array::null();
2074 } 2093 }
2075 2094
2076 2095
2077 void FullSnapshotWriter::WriteVmIsolateSnapshot() { 2096 void FullSnapshotWriter::WriteVmIsolateSnapshot() {
2078 ASSERT(vm_isolate_snapshot_buffer_ != NULL); 2097 ASSERT(vm_isolate_snapshot_buffer_ != NULL);
2079 SnapshotWriter writer(thread(), 2098 SnapshotWriter writer(thread(),
2080 kind_, 2099 kind_,
2081 vm_isolate_snapshot_buffer_, 2100 vm_isolate_snapshot_buffer_,
2082 alloc_, 2101 alloc_,
2083 kInitialSize, 2102 kInitialSize,
2084 forward_list_, 2103 forward_list_,
2085 instructions_writer_, 2104 instructions_writer_,
2086 true, /* can_send_any_object */ 2105 true, /* can_send_any_object */
2087 vm_isolate_is_symbolic_); 2106 true /* writing_vm_isolate */);
2088 // Write full snapshot for the VM isolate. 2107 // Write full snapshot for the VM isolate.
2089 // Setup for long jump in case there is an exception while writing 2108 // Setup for long jump in case there is an exception while writing
2090 // the snapshot. 2109 // the snapshot.
2091 LongJumpScope jump; 2110 LongJumpScope jump;
2092 if (setjmp(*jump.Set()) == 0) { 2111 if (setjmp(*jump.Set()) == 0) {
2093 // Reserve space in the output buffer for a snapshot header. 2112 // Reserve space in the output buffer for a snapshot header.
2094 writer.ReserveHeader(); 2113 writer.ReserveHeader();
2095 2114
2096 // Write out the version string. 2115 // Write out the version string.
2097 writer.WriteVersion(); 2116 writer.WriteVersion();
2098 2117
2099 /* 2118 /*
2100 * Now Write out the following 2119 * Now Write out the following
2101 * - the symbol table 2120 * - the symbol table
2102 * - all the scripts and token streams for these scripts 2121 * - all the scripts and token streams for these scripts
2103 * 2122 * - the stub code (precompiled snapshots only)
2104 **/ 2123 **/
2105 // Write out the symbol table. 2124 // Write out the symbol table.
2106 writer.WriteObject(symbol_table_.raw()); 2125 writer.WriteObject(new_vm_symbol_table_.raw());
2107 2126
2108 // Write out all the script objects and the accompanying token streams 2127 // Write out all the script objects and the accompanying token streams
2109 // for the bootstrap libraries so that they are in the VM isolate 2128 // for the bootstrap libraries so that they are in the VM isolate
2110 // read only memory. 2129 // read only memory.
2111 writer.WriteObject(scripts_.raw()); 2130 writer.WriteObject(scripts_.raw());
2112 2131
2113 if (Snapshot::IncludesCode(kind_)) { 2132 if (Snapshot::IncludesCode(kind_)) {
2114 ASSERT(!vm_isolate_is_symbolic_);
2115 StubCode::WriteTo(&writer); 2133 StubCode::WriteTo(&writer);
2116 } 2134 }
2117 2135
2118
2119 writer.FillHeader(writer.kind()); 2136 writer.FillHeader(writer.kind());
2120 2137
2121 vm_isolate_snapshot_size_ = writer.BytesWritten(); 2138 vm_isolate_snapshot_size_ = writer.BytesWritten();
2122 } else { 2139 } else {
2123 writer.ThrowException(writer.exception_type(), writer.exception_msg()); 2140 writer.ThrowException(writer.exception_type(), writer.exception_msg());
2124 } 2141 }
2125 } 2142 }
2126 2143
2127 2144
2128 void FullSnapshotWriter::WriteIsolateFullSnapshot() { 2145 void FullSnapshotWriter::WriteIsolateFullSnapshot() {
2129 SnapshotWriter writer(thread(), 2146 SnapshotWriter writer(thread(),
2130 kind_, 2147 kind_,
2131 isolate_snapshot_buffer_, 2148 isolate_snapshot_buffer_,
2132 alloc_, 2149 alloc_,
2133 kInitialSize, 2150 kInitialSize,
2134 forward_list_, 2151 forward_list_,
2135 instructions_writer_, 2152 instructions_writer_,
2136 true, /* can_send_any_object */ 2153 true, /* can_send_any_object */
2137 true /* vm_isolate_is_symbolic */); 2154 false /* writing_vm_isolate */);
2138 ObjectStore* object_store = isolate()->object_store(); 2155 ObjectStore* object_store = isolate()->object_store();
2139 ASSERT(object_store != NULL); 2156 ASSERT(object_store != NULL);
2140 2157
2141 // Write full snapshot for a regular isolate. 2158 // Write full snapshot for a regular isolate.
2142 // Setup for long jump in case there is an exception while writing 2159 // Setup for long jump in case there is an exception while writing
2143 // the snapshot. 2160 // the snapshot.
2144 LongJumpScope jump; 2161 LongJumpScope jump;
2145 if (setjmp(*jump.Set()) == 0) { 2162 if (setjmp(*jump.Set()) == 0) {
2146 // Reserve space in the output buffer for a snapshot header. 2163 // Reserve space in the output buffer for a snapshot header.
2147 writer.ReserveHeader(); 2164 writer.ReserveHeader();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 OS::Print("Total(CodeSize): %" Pd "\n", total); 2204 OS::Print("Total(CodeSize): %" Pd "\n", total);
2188 } 2205 }
2189 } 2206 }
2190 2207
2191 2208
2192 ForwardList::ForwardList(Thread* thread, intptr_t first_object_id) 2209 ForwardList::ForwardList(Thread* thread, intptr_t first_object_id)
2193 : thread_(thread), 2210 : thread_(thread),
2194 first_object_id_(first_object_id), 2211 first_object_id_(first_object_id),
2195 nodes_(), 2212 nodes_(),
2196 first_unprocessed_object_id_(first_object_id) { 2213 first_unprocessed_object_id_(first_object_id) {
2214 ASSERT(first_object_id > 0);
2197 } 2215 }
2198 2216
2199 2217
2200 ForwardList::~ForwardList() { 2218 ForwardList::~ForwardList() {
2201 heap()->ResetObjectIdTable(); 2219 heap()->ResetObjectIdTable();
2202 } 2220 }
2203 2221
2204 2222
2205 intptr_t ForwardList::AddObject(Zone* zone, 2223 intptr_t ForwardList::AddObject(Zone* zone,
2206 RawObject* raw, 2224 RawObject* raw,
2207 SerializeState state) { 2225 SerializeState state) {
2208 NoSafepointScope no_safepoint; 2226 NoSafepointScope no_safepoint;
2209 intptr_t object_id = next_object_id(); 2227 intptr_t object_id = next_object_id();
2210 ASSERT(object_id > 0 && object_id <= kMaxObjectId); 2228 ASSERT(object_id > 0 && object_id <= kMaxObjectId);
2211 const Object& obj = Object::ZoneHandle(zone, raw); 2229 const Object& obj = Object::ZoneHandle(zone, raw);
2212 Node* node = new Node(&obj, state); 2230 Node* node = new Node(&obj, state);
2213 ASSERT(node != NULL); 2231 ASSERT(node != NULL);
2214 nodes_.Add(node); 2232 nodes_.Add(node);
2215 ASSERT(SnapshotWriter::FirstObjectId() > 0);
2216 ASSERT(object_id != 0); 2233 ASSERT(object_id != 0);
2217 heap()->SetObjectId(raw, object_id); 2234 heap()->SetObjectId(raw, object_id);
2218 return object_id; 2235 return object_id;
2219 } 2236 }
2220 2237
2221 2238
2222 intptr_t ForwardList::FindObject(RawObject* raw) { 2239 intptr_t ForwardList::FindObject(RawObject* raw) {
2223 NoSafepointScope no_safepoint; 2240 NoSafepointScope no_safepoint;
2224 ASSERT(SnapshotWriter::FirstObjectId() > 0);
2225 intptr_t id = heap()->GetObjectId(raw); 2241 intptr_t id = heap()->GetObjectId(raw);
2226 ASSERT(id == 0 || NodeForObjectId(id)->obj()->raw() == raw); 2242 ASSERT(id == 0 || NodeForObjectId(id)->obj()->raw() == raw);
2227 return (id == 0) ? static_cast<intptr_t>(kInvalidIndex) : id; 2243 return (id == 0) ? static_cast<intptr_t>(kInvalidIndex) : id;
2228 } 2244 }
2229 2245
2230 2246
2231 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) { 2247 bool SnapshotWriter::CheckAndWritePredefinedObject(RawObject* rawobj) {
2232 // Check if object can be written in one of the following ways: 2248 // 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). 2249 // - 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) 2250 // - 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 2689
2674 2690
2675 void SnapshotWriter::WriteVersion() { 2691 void SnapshotWriter::WriteVersion() {
2676 const char* expected_version = Version::SnapshotString(); 2692 const char* expected_version = Version::SnapshotString();
2677 ASSERT(expected_version != NULL); 2693 ASSERT(expected_version != NULL);
2678 const intptr_t version_len = strlen(expected_version); 2694 const intptr_t version_len = strlen(expected_version);
2679 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); 2695 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len);
2680 } 2696 }
2681 2697
2682 2698
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, 2699 ScriptSnapshotWriter::ScriptSnapshotWriter(uint8_t** buffer,
2691 ReAlloc alloc) 2700 ReAlloc alloc)
2692 : SnapshotWriter(Thread::Current(), 2701 : SnapshotWriter(Thread::Current(),
2693 Snapshot::kScript, 2702 Snapshot::kScript,
2694 buffer, 2703 buffer,
2695 alloc, 2704 alloc,
2696 kInitialSize, 2705 kInitialSize,
2697 &forward_list_, 2706 &forward_list_,
2698 NULL, /* instructions_writer */ 2707 NULL, /* instructions_writer */
2699 true, /* can_send_any_object */ 2708 true, /* can_send_any_object */
2700 true /* vm_isolate_is_symbolic */), 2709 false /* writing_vm_isolate */),
2701 forward_list_(thread(), kMaxPredefinedObjectIds) { 2710 forward_list_(thread(), kMaxPredefinedObjectIds) {
2702 ASSERT(buffer != NULL); 2711 ASSERT(buffer != NULL);
2703 ASSERT(alloc != NULL); 2712 ASSERT(alloc != NULL);
2704 } 2713 }
2705 2714
2706 2715
2707 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { 2716 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) {
2708 ASSERT(kind() == Snapshot::kScript); 2717 ASSERT(kind() == Snapshot::kScript);
2709 ASSERT(isolate() != NULL); 2718 ASSERT(isolate() != NULL);
2710 ASSERT(ClassFinalizer::AllClassesFinalized()); 2719 ASSERT(ClassFinalizer::AllClassesFinalized());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2746 ReAlloc alloc, 2755 ReAlloc alloc,
2747 bool can_send_any_object) 2756 bool can_send_any_object)
2748 : SnapshotWriter(Thread::Current(), 2757 : SnapshotWriter(Thread::Current(),
2749 Snapshot::kMessage, 2758 Snapshot::kMessage,
2750 buffer, 2759 buffer,
2751 alloc, 2760 alloc,
2752 kInitialSize, 2761 kInitialSize,
2753 &forward_list_, 2762 &forward_list_,
2754 NULL, /* instructions_writer */ 2763 NULL, /* instructions_writer */
2755 can_send_any_object, 2764 can_send_any_object,
2756 true /* vm_isolate_is_symbolic */), 2765 false /* writing_vm_isolate */),
2757 forward_list_(thread(), kMaxPredefinedObjectIds) { 2766 forward_list_(thread(), kMaxPredefinedObjectIds) {
2758 ASSERT(buffer != NULL); 2767 ASSERT(buffer != NULL);
2759 ASSERT(alloc != NULL); 2768 ASSERT(alloc != NULL);
2760 } 2769 }
2761 2770
2762 2771
2763 void MessageWriter::WriteMessage(const Object& obj) { 2772 void MessageWriter::WriteMessage(const Object& obj) {
2764 ASSERT(kind() == Snapshot::kMessage); 2773 ASSERT(kind() == Snapshot::kMessage);
2765 ASSERT(isolate() != NULL); 2774 ASSERT(isolate() != NULL);
2766 2775
2767 // Setup for long jump in case there is an exception while writing 2776 // Setup for long jump in case there is an exception while writing
2768 // the message. 2777 // the message.
2769 LongJumpScope jump; 2778 LongJumpScope jump;
2770 if (setjmp(*jump.Set()) == 0) { 2779 if (setjmp(*jump.Set()) == 0) {
2771 NoSafepointScope no_safepoint; 2780 NoSafepointScope no_safepoint;
2772 WriteObject(obj.raw()); 2781 WriteObject(obj.raw());
2773 } else { 2782 } else {
2774 ThrowException(exception_type(), exception_msg()); 2783 ThrowException(exception_type(), exception_msg());
2775 } 2784 }
2776 } 2785 }
2777 2786
2778 2787
2779 } // namespace dart 2788 } // namespace dart
OLDNEW
« no previous file with comments | « 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