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

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

Issue 1584443002: VM: Precompiled rodata snapshot. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: win32, android build Created 4 years, 11 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
« runtime/vm/pages.cc ('K') | « runtime/vm/snapshot.h ('k') | no next file » | 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 intptr_t BaseReader::ReadSmiValue() { 168 intptr_t BaseReader::ReadSmiValue() {
169 return Smi::Value(ReadAsSmi()); 169 return Smi::Value(ReadAsSmi());
170 } 170 }
171 171
172 172
173 SnapshotReader::SnapshotReader( 173 SnapshotReader::SnapshotReader(
174 const uint8_t* buffer, 174 const uint8_t* buffer,
175 intptr_t size, 175 intptr_t size,
176 const uint8_t* instructions_buffer, 176 const uint8_t* instructions_buffer,
177 const uint8_t* data_buffer,
177 Snapshot::Kind kind, 178 Snapshot::Kind kind,
178 ZoneGrowableArray<BackRefNode>* backward_refs, 179 ZoneGrowableArray<BackRefNode>* backward_refs,
179 Thread* thread) 180 Thread* thread)
180 : BaseReader(buffer, size), 181 : BaseReader(buffer, size),
181 instructions_buffer_(instructions_buffer), 182 instructions_buffer_(instructions_buffer),
183 data_buffer_(data_buffer),
182 kind_(kind), 184 kind_(kind),
183 snapshot_code_(instructions_buffer != NULL), 185 snapshot_code_(instructions_buffer != NULL),
184 thread_(thread), 186 thread_(thread),
185 zone_(thread->zone()), 187 zone_(thread->zone()),
186 heap_(isolate()->heap()), 188 heap_(isolate()->heap()),
187 old_space_(thread_->isolate()->heap()->old_space()), 189 old_space_(thread_->isolate()->heap()->old_space()),
188 cls_(Class::Handle(zone_)), 190 cls_(Class::Handle(zone_)),
189 obj_(Object::Handle(zone_)), 191 obj_(Object::Handle(zone_)),
190 pobj_(PassiveObject::Handle(zone_)), 192 pobj_(PassiveObject::Handle(zone_)),
191 array_(Array::Handle(zone_)), 193 array_(Array::Handle(zone_)),
192 field_(Field::Handle(zone_)), 194 field_(Field::Handle(zone_)),
193 str_(String::Handle(zone_)), 195 str_(String::Handle(zone_)),
194 library_(Library::Handle(zone_)), 196 library_(Library::Handle(zone_)),
195 type_(AbstractType::Handle(zone_)), 197 type_(AbstractType::Handle(zone_)),
196 type_arguments_(TypeArguments::Handle(zone_)), 198 type_arguments_(TypeArguments::Handle(zone_)),
197 tokens_(GrowableObjectArray::Handle(zone_)), 199 tokens_(GrowableObjectArray::Handle(zone_)),
198 stream_(TokenStream::Handle(zone_)), 200 stream_(TokenStream::Handle(zone_)),
199 data_(ExternalTypedData::Handle(zone_)), 201 data_(ExternalTypedData::Handle(zone_)),
200 typed_data_(TypedData::Handle(zone_)), 202 typed_data_(TypedData::Handle(zone_)),
201 code_(Code::Handle(zone_)), 203 code_(Code::Handle(zone_)),
202 function_(Function::Handle(zone_)), 204 function_(Function::Handle(zone_)),
203 megamorphic_cache_(MegamorphicCache::Handle(zone_)), 205 megamorphic_cache_(MegamorphicCache::Handle(zone_)),
204 error_(UnhandledException::Handle(zone_)), 206 error_(UnhandledException::Handle(zone_)),
205 max_vm_isolate_object_id_( 207 max_vm_isolate_object_id_(
206 (kind == Snapshot::kFull) ? 208 (kind == Snapshot::kFull) ?
207 Object::vm_isolate_snapshot_object_table().Length() : 0), 209 Object::vm_isolate_snapshot_object_table().Length() : 0),
208 backward_references_(backward_refs), 210 backward_references_(backward_refs),
209 instructions_reader_(NULL) { 211 instructions_reader_(NULL) {
210 if (instructions_buffer != NULL) { 212 if (instructions_buffer != NULL) {
211 instructions_reader_ = new InstructionsReader(instructions_buffer); 213 instructions_reader_ =
214 new InstructionsReader(instructions_buffer, data_buffer);
212 } 215 }
213 } 216 }
214 217
215 218
216 RawObject* SnapshotReader::ReadObject() { 219 RawObject* SnapshotReader::ReadObject() {
217 // Setup for long jump in case there is an exception while reading. 220 // Setup for long jump in case there is an exception while reading.
218 LongJumpScope jump; 221 LongJumpScope jump;
219 if (setjmp(*jump.Set()) == 0) { 222 if (setjmp(*jump.Set()) == 0) {
220 PassiveObject& obj = 223 PassiveObject& obj =
221 PassiveObject::Handle(zone(), ReadObjectImpl(kAsInlinedObject)); 224 PassiveObject::Handle(zone(), ReadObjectImpl(kAsInlinedObject));
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 1103
1101 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) { 1104 int32_t InstructionsWriter::GetOffsetFor(RawInstructions* instructions) {
1102 intptr_t heap_size = instructions->Size(); 1105 intptr_t heap_size = instructions->Size();
1103 intptr_t offset = next_offset_; 1106 intptr_t offset = next_offset_;
1104 next_offset_ += heap_size; 1107 next_offset_ += heap_size;
1105 instructions_.Add(InstructionsData(instructions)); 1108 instructions_.Add(InstructionsData(instructions));
1106 return offset; 1109 return offset;
1107 } 1110 }
1108 1111
1109 1112
1113 int32_t InstructionsWriter::GetObjectOffsetFor(RawObject* raw_object) {
1114 intptr_t heap_size = raw_object->Size();
1115 intptr_t offset = next_object_offset_;
1116 next_object_offset_ += heap_size;
1117 objects_.Add(ObjectData(raw_object));
1118 return offset;
1119 }
1120
1121
1110 static void EnsureIdentifier(char* label) { 1122 static void EnsureIdentifier(char* label) {
1111 for (char c = *label; c != '\0'; c = *++label) { 1123 for (char c = *label; c != '\0'; c = *++label) {
1112 if (((c >= 'a') && (c <= 'z')) || 1124 if (((c >= 'a') && (c <= 'z')) ||
1113 ((c >= 'A') && (c <= 'Z')) || 1125 ((c >= 'A') && (c <= 'Z')) ||
1114 ((c >= '0') && (c <= '9'))) { 1126 ((c >= '0') && (c <= '9'))) {
1115 continue; 1127 continue;
1116 } 1128 }
1117 *label = '_'; 1129 *label = '_';
1118 } 1130 }
1119 } 1131 }
1120 1132
1121 1133
1122 void InstructionsWriter::WriteAssembly() { 1134 void InstructionsWriter::WriteAssembly() {
1123 Zone* Z = Thread::Current()->zone(); 1135 Zone* Z = Thread::Current()->zone();
1124 1136
1125 // Handlify collected raw pointers as building the names below 1137 // Handlify collected raw pointers as building the names below
1126 // will allocate on the Dart heap. 1138 // will allocate on the Dart heap.
1127 for (intptr_t i = 0; i < instructions_.length(); i++) { 1139 for (intptr_t i = 0; i < instructions_.length(); i++) {
1128 InstructionsData& data = instructions_[i]; 1140 InstructionsData& data = instructions_[i];
1129 data.insns_ = &Instructions::Handle(Z, data.raw_insns_); 1141 data.insns_ = &Instructions::Handle(Z, data.raw_insns_);
1130 ASSERT(data.raw_code_ != NULL); 1142 ASSERT(data.raw_code_ != NULL);
1131 data.code_ = &Code::Handle(Z, data.raw_code_); 1143 data.code_ = &Code::Handle(Z, data.raw_code_);
1132 } 1144 }
1145 for (intptr_t i = 0; i < objects_.length(); i++) {
1146 ObjectData& data = objects_[i];
1147 data.obj_ = &Object::Handle(Z, data.raw_obj_);
1148 }
1133 1149
1134 stream_.Print(".text\n"); 1150 stream_.Print(".text\n");
1135 stream_.Print(".globl _kInstructionsSnapshot\n"); 1151 stream_.Print(".globl _kInstructionsSnapshot\n");
1136 stream_.Print(".balign %" Pd ", 0\n", OS::kMaxPreferredCodeAlignment); 1152 stream_.Print(".balign %" Pd ", 0\n", OS::kMaxPreferredCodeAlignment);
1137 stream_.Print("_kInstructionsSnapshot:\n"); 1153 stream_.Print("_kInstructionsSnapshot:\n");
1138 1154
1139 // This head also provides the gap to make the instructions snapshot 1155 // This head also provides the gap to make the instructions snapshot
1140 // look like a HeapPage. 1156 // look like a HeapPage.
1141 intptr_t instructions_length = next_offset_; 1157 intptr_t instructions_length = next_offset_;
1142 WriteWordLiteral(instructions_length); 1158 WriteWordLiteral(instructions_length);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t))); 1224 ASSERT(Utils::IsAligned(entry, sizeof(uint64_t)));
1209 ASSERT(Utils::IsAligned(end, sizeof(uint64_t))); 1225 ASSERT(Utils::IsAligned(end, sizeof(uint64_t)));
1210 1226
1211 for (uword* cursor = reinterpret_cast<uword*>(entry); 1227 for (uword* cursor = reinterpret_cast<uword*>(entry);
1212 cursor < reinterpret_cast<uword*>(end); 1228 cursor < reinterpret_cast<uword*>(end);
1213 cursor++) { 1229 cursor++) {
1214 WriteWordLiteral(*cursor); 1230 WriteWordLiteral(*cursor);
1215 } 1231 }
1216 } 1232 }
1217 } 1233 }
1234 #if defined(TARGET_OS_LINUX)
1235 stream_.Print(".section .rodata\n");
1236 #elif defined(TARGET_OS_MACOS)
1237 stream_.Print(".section __DATA,__const\n");
1238 #else
1239 #error Unsupported platform
1240 #endif
1241 stream_.Print(".globl _kDataSnapshot\n");
1242 stream_.Print(".balign %" Pd ", 0\n", kObjectAlignment);
1243 stream_.Print("_kDataSnapshot:\n");
1244 WriteWordLiteral(next_object_offset_); // Data length.
1245 WriteWordLiteral(0); // Zero padding for object alignment.
1246
1247 for (intptr_t i = 0; i < objects_.length(); i++) {
1248 const Object& obj = *objects_[i].obj_;
1249 stream_.Print("Precompiled_Obj_%d:\n", i);
1250
1251 NoSafepointScope no_safepoint;
1252 uword start = reinterpret_cast<uword>(obj.raw()) - kHeapObjectTag;
1253 uword end = start + obj.raw()->Size();
1254
1255 // Write object header with the mark and VM heap bits set.
1256 uword marked_tags = obj.raw()->ptr()->tags_;
1257 marked_tags = RawObject::VMHeapObjectTag::update(true, marked_tags);
1258 marked_tags = RawObject::MarkBit::update(true, marked_tags);
1259 WriteWordLiteral(marked_tags);
1260 start += sizeof(uword);
1261 for (uword* cursor = reinterpret_cast<uword*>(start);
1262 cursor < reinterpret_cast<uword*>(end);
1263 cursor++) {
1264 WriteWordLiteral(*cursor);
1265 }
1266 }
1218 } 1267 }
1219 1268
1220 1269
1221 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset, 1270 RawInstructions* InstructionsReader::GetInstructionsAt(int32_t offset,
1222 uword expected_tags) { 1271 uword expected_tags) {
1223 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment())); 1272 ASSERT(Utils::IsAligned(offset, OS::PreferredCodeAlignment()));
1224 1273
1225 RawInstructions* result = 1274 RawInstructions* result =
1226 reinterpret_cast<RawInstructions*>( 1275 reinterpret_cast<RawInstructions*>(
1227 reinterpret_cast<uword>(buffer_) + offset + kHeapObjectTag); 1276 reinterpret_cast<uword>(instructions_buffer_) +
1277 offset + kHeapObjectTag);
1228 1278
1279 #ifdef DEBUG
1229 uword actual_tags = result->ptr()->tags_; 1280 uword actual_tags = result->ptr()->tags_;
1230 if (actual_tags != expected_tags) { 1281 if (actual_tags != expected_tags) {
1231 FATAL2("Instructions tag mismatch: expected %" Pd ", saw %" Pd, 1282 FATAL2("Instructions tag mismatch: expected %" Pd ", saw %" Pd,
1232 expected_tags, 1283 expected_tags,
1233 actual_tags); 1284 actual_tags);
1234 } 1285 }
1286 #endif
1235 1287
1236 ASSERT(result->IsMarked()); 1288 ASSERT(result->IsMarked());
1237 1289
1238 return result; 1290 return result;
1291 }
1292
1293
1294 RawObject* InstructionsReader::GetObjectAt(int32_t offset) {
1295 ASSERT(Utils::IsAligned(offset, kWordSize));
1296
1297 RawObject* result =
1298 reinterpret_cast<RawObject*>(
1299 reinterpret_cast<uword>(data_buffer_) + offset + kHeapObjectTag);
1300 ASSERT(result->IsMarked());
1301
1302 return result;
1239 } 1303 }
1240 1304
1241 1305
1242 intptr_t SnapshotReader::LookupInternalClass(intptr_t class_header) { 1306 intptr_t SnapshotReader::LookupInternalClass(intptr_t class_header) {
1243 // If the header is an object Id, lookup singleton VM classes or classes 1307 // If the header is an object Id, lookup singleton VM classes or classes
1244 // stored in the object store. 1308 // stored in the object store.
1245 if (IsVMIsolateObject(class_header)) { 1309 if (IsVMIsolateObject(class_header)) {
1246 intptr_t class_id = GetVMIsolateObjectId(class_header); 1310 intptr_t class_id = GetVMIsolateObjectId(class_header);
1247 ASSERT(IsSingletonClassId(class_id)); 1311 ASSERT(IsSingletonClassId(class_id));
1248 return class_id; 1312 return class_id;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 (i + offset)); 1516 (i + offset));
1453 result.SetAt(i, *PassiveObjectHandle()); 1517 result.SetAt(i, *PassiveObjectHandle());
1454 } 1518 }
1455 } 1519 }
1456 1520
1457 1521
1458 VmIsolateSnapshotReader::VmIsolateSnapshotReader( 1522 VmIsolateSnapshotReader::VmIsolateSnapshotReader(
1459 const uint8_t* buffer, 1523 const uint8_t* buffer,
1460 intptr_t size, 1524 intptr_t size,
1461 const uint8_t* instructions_buffer, 1525 const uint8_t* instructions_buffer,
1526 const uint8_t* data_buffer,
1462 Thread* thread) 1527 Thread* thread)
1463 : SnapshotReader(buffer, 1528 : SnapshotReader(buffer,
1464 size, 1529 size,
1465 instructions_buffer, 1530 instructions_buffer,
1531 data_buffer,
1466 Snapshot::kFull, 1532 Snapshot::kFull,
1467 new ZoneGrowableArray<BackRefNode>( 1533 new ZoneGrowableArray<BackRefNode>(
1468 kNumVmIsolateSnapshotReferences), 1534 kNumVmIsolateSnapshotReferences),
1469 thread) { 1535 thread) {
1470 } 1536 }
1471 1537
1472 1538
1473 VmIsolateSnapshotReader::~VmIsolateSnapshotReader() { 1539 VmIsolateSnapshotReader::~VmIsolateSnapshotReader() {
1474 intptr_t len = GetBackwardReferenceTable()->length(); 1540 intptr_t len = GetBackwardReferenceTable()->length();
1475 Object::InitVmIsolateSnapshotObjectTable(len); 1541 Object::InitVmIsolateSnapshotObjectTable(len);
1476 ZoneGrowableArray<BackRefNode>* backrefs = GetBackwardReferenceTable(); 1542 ZoneGrowableArray<BackRefNode>* backrefs = GetBackwardReferenceTable();
1477 for (intptr_t i = 0; i < len; i++) { 1543 for (intptr_t i = 0; i < len; i++) {
1478 Object::vm_isolate_snapshot_object_table().SetAt( 1544 Object::vm_isolate_snapshot_object_table().SetAt(
1479 i, *(backrefs->At(i).reference())); 1545 i, *(backrefs->At(i).reference()));
1480 } 1546 }
1481 ResetBackwardReferenceTable(); 1547 ResetBackwardReferenceTable();
1482 Dart::set_instructions_snapshot_buffer(instructions_buffer_); 1548 Dart::set_instructions_snapshot_buffer(instructions_buffer_);
1549 Dart::set_data_snapshot_buffer(data_buffer_);
1483 } 1550 }
1484 1551
1485 1552
1486 RawApiError* VmIsolateSnapshotReader::ReadVmIsolateSnapshot() { 1553 RawApiError* VmIsolateSnapshotReader::ReadVmIsolateSnapshot() {
1487 ASSERT(kind() == Snapshot::kFull); 1554 ASSERT(kind() == Snapshot::kFull);
1488 Thread* thread = Thread::Current(); 1555 Thread* thread = Thread::Current();
1489 Isolate* isolate = thread->isolate(); 1556 Isolate* isolate = thread->isolate();
1490 ASSERT(isolate != NULL); 1557 ASSERT(isolate != NULL);
1491 ASSERT(isolate == Dart::vm_isolate()); 1558 ASSERT(isolate == Dart::vm_isolate());
1492 ObjectStore* object_store = isolate->object_store(); 1559 ObjectStore* object_store = isolate->object_store();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 #endif 1591 #endif
1525 1592
1526 return ApiError::null(); 1593 return ApiError::null();
1527 } 1594 }
1528 } 1595 }
1529 1596
1530 1597
1531 IsolateSnapshotReader::IsolateSnapshotReader(const uint8_t* buffer, 1598 IsolateSnapshotReader::IsolateSnapshotReader(const uint8_t* buffer,
1532 intptr_t size, 1599 intptr_t size,
1533 const uint8_t* instructions_buffer, 1600 const uint8_t* instructions_buffer,
1601 const uint8_t* data_buffer,
1534 Thread* thread) 1602 Thread* thread)
1535 : SnapshotReader(buffer, 1603 : SnapshotReader(buffer,
1536 size, 1604 size,
1537 instructions_buffer, 1605 instructions_buffer,
1606 data_buffer,
1538 Snapshot::kFull, 1607 Snapshot::kFull,
1539 new ZoneGrowableArray<BackRefNode>( 1608 new ZoneGrowableArray<BackRefNode>(
1540 kNumInitialReferencesInFullSnapshot), 1609 kNumInitialReferencesInFullSnapshot),
1541 thread) { 1610 thread) {
1542 isolate()->set_compilation_allowed(instructions_buffer_ == NULL); 1611 isolate()->set_compilation_allowed(instructions_buffer_ == NULL);
1543 } 1612 }
1544 1613
1545 1614
1546 IsolateSnapshotReader::~IsolateSnapshotReader() { 1615 IsolateSnapshotReader::~IsolateSnapshotReader() {
1547 ResetBackwardReferenceTable(); 1616 ResetBackwardReferenceTable();
1548 } 1617 }
1549 1618
1550 1619
1551 ScriptSnapshotReader::ScriptSnapshotReader(const uint8_t* buffer, 1620 ScriptSnapshotReader::ScriptSnapshotReader(const uint8_t* buffer,
1552 intptr_t size, 1621 intptr_t size,
1553 Thread* thread) 1622 Thread* thread)
1554 : SnapshotReader(buffer, 1623 : SnapshotReader(buffer,
1555 size, 1624 size,
1556 NULL, /* instructions_buffer */ 1625 NULL, /* instructions_buffer */
1626 NULL, /* data_buffer */
1557 Snapshot::kScript, 1627 Snapshot::kScript,
1558 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences), 1628 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences),
1559 thread) { 1629 thread) {
1560 } 1630 }
1561 1631
1562 1632
1563 ScriptSnapshotReader::~ScriptSnapshotReader() { 1633 ScriptSnapshotReader::~ScriptSnapshotReader() {
1564 ResetBackwardReferenceTable(); 1634 ResetBackwardReferenceTable();
1565 } 1635 }
1566 1636
1567 1637
1568 MessageSnapshotReader::MessageSnapshotReader(const uint8_t* buffer, 1638 MessageSnapshotReader::MessageSnapshotReader(const uint8_t* buffer,
1569 intptr_t size, 1639 intptr_t size,
1570 Thread* thread) 1640 Thread* thread)
1571 : SnapshotReader(buffer, 1641 : SnapshotReader(buffer,
1572 size, 1642 size,
1573 NULL, /* instructions_buffer */ 1643 NULL, /* instructions_buffer */
1644 NULL, /* data_buffer */
1574 Snapshot::kMessage, 1645 Snapshot::kMessage,
1575 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences), 1646 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences),
1576 thread) { 1647 thread) {
1577 } 1648 }
1578 1649
1579 1650
1580 MessageSnapshotReader::~MessageSnapshotReader() { 1651 MessageSnapshotReader::~MessageSnapshotReader() {
1581 ResetBackwardReferenceTable(); 1652 ResetBackwardReferenceTable();
1582 } 1653 }
1583 1654
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 if (setjmp(*jump.Set()) == 0) { 2656 if (setjmp(*jump.Set()) == 0) {
2586 NoSafepointScope no_safepoint; 2657 NoSafepointScope no_safepoint;
2587 WriteObject(obj.raw()); 2658 WriteObject(obj.raw());
2588 } else { 2659 } else {
2589 ThrowException(exception_type(), exception_msg()); 2660 ThrowException(exception_type(), exception_msg());
2590 } 2661 }
2591 } 2662 }
2592 2663
2593 2664
2594 } // namespace dart 2665 } // namespace dart
OLDNEW
« runtime/vm/pages.cc ('K') | « runtime/vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698