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

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

Issue 2853423002: Move the Kernel canonical name table into the VM's heap (Closed)
Patch Set: Merge a bugfix Created 3 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #if !defined(DART_PRECOMPILED_RUNTIME) 4 #if !defined(DART_PRECOMPILED_RUNTIME)
5 5
6 #include "vm/kernel_binary.h" 6 #include "vm/kernel_binary.h"
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/growable_array.h" 9 #include "vm/growable_array.h"
10 #include "vm/kernel.h" 10 #include "vm/kernel.h"
11 #include "vm/kernel_to_il.h" 11 #include "vm/kernel_to_il.h"
12 #include "vm/os.h" 12 #include "vm/os.h"
13 13
14 #if defined(DEBUG) 14 #if defined(DEBUG)
15 #define TRACE_READ_OFFSET() \ 15 #define TRACE_READ_OFFSET() \
16 do { \ 16 do { \
17 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \ 17 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \
18 } while (0) 18 } while (0)
19 #else 19 #else
20 #define TRACE_READ_OFFSET() 20 #define TRACE_READ_OFFSET()
21 #endif 21 #endif
22 22
23 namespace dart { 23 namespace dart {
24 24
25 25
26 namespace kernel { 26 namespace kernel {
27 27
28 28
29 Reader::~Reader() {
30 delete[] string_offsets_;
31 delete[] canonical_name_parents_;
32 delete[] canonical_name_strings_;
33 }
34
35
29 template <typename T> 36 template <typename T>
30 template <typename IT> 37 template <typename IT>
31 void List<T>::ReadFrom(Reader* reader, TreeNode* parent) { 38 void List<T>::ReadFrom(Reader* reader, TreeNode* parent) {
32 TRACE_READ_OFFSET(); 39 TRACE_READ_OFFSET();
33 ASSERT(parent != NULL); 40 ASSERT(parent != NULL);
34 int length = reader->ReadListLength(); 41 int length = reader->ReadListLength();
35 EnsureInitialized(length); 42 EnsureInitialized(length);
36 43
37 for (intptr_t i = 0; i < length_; i++) { 44 for (intptr_t i = 0; i < length_; i++) {
38 IT* object = GetOrCreate<IT>(i, parent); 45 IT* object = GetOrCreate<IT>(i, parent);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 170
164 Library* Library::ReadFrom(Reader* reader) { 171 Library* Library::ReadFrom(Reader* reader) {
165 TRACE_READ_OFFSET(); 172 TRACE_READ_OFFSET();
166 int flags = reader->ReadFlags(); 173 int flags = reader->ReadFlags();
167 ASSERT(flags == 0); // external libraries not supported 174 ASSERT(flags == 0); // external libraries not supported
168 kernel_data_ = reader->buffer(); 175 kernel_data_ = reader->buffer();
169 kernel_data_size_ = reader->size(); 176 kernel_data_size_ = reader->size();
170 177
171 canonical_name_ = reader->ReadCanonicalNameReference(); 178 canonical_name_ = reader->ReadCanonicalNameReference();
172 name_index_ = reader->ReadUInt(); 179 name_index_ = reader->ReadUInt();
173 import_uri_index_ = canonical_name_->name(); 180 import_uri_index_ = reader->CanonicalNameString(canonical_name_);
174 source_uri_index_ = reader->ReadUInt(); 181 source_uri_index_ = reader->ReadUInt();
175 reader->set_current_script_id(source_uri_index_); 182 reader->set_current_script_id(source_uri_index_);
176 183
177 int num_imports = reader->ReadUInt(); 184 int num_imports = reader->ReadUInt();
178 if (num_imports != 0) { 185 if (num_imports != 0) {
179 FATAL("Deferred imports not implemented in VM"); 186 FATAL("Deferred imports not implemented in VM");
180 } 187 }
181 int num_typedefs = reader->ReadUInt(); 188 int num_typedefs = reader->ReadUInt();
182 typedefs().EnsureInitialized(num_typedefs); 189 typedefs().EnsureInitialized(num_typedefs);
183 for (intptr_t i = 0; i < num_typedefs; i++) { 190 for (intptr_t i = 0; i < num_typedefs; i++) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 type_parameters_.ReadFrom(reader); 263 type_parameters_.ReadFrom(reader);
257 first_ = InterfaceType::Cast(DartType::ReadFrom(reader)); 264 first_ = InterfaceType::Cast(DartType::ReadFrom(reader));
258 second_ = InterfaceType::Cast(DartType::ReadFrom(reader)); 265 second_ = InterfaceType::Cast(DartType::ReadFrom(reader));
259 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >( 266 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >(
260 reader); 267 reader);
261 constructors_.ReadFrom<Constructor>(reader, this); 268 constructors_.ReadFrom<Constructor>(reader, this);
262 return this; 269 return this;
263 } 270 }
264 271
265 272
266 CanonicalName* Reference::ReadMemberFrom(Reader* reader, bool allow_null) { 273 intptr_t Reference::ReadMemberFrom(Reader* reader, bool allow_null) {
267 TRACE_READ_OFFSET(); 274 TRACE_READ_OFFSET();
268 275 intptr_t canonical_name = reader->ReadCanonicalNameReference();
269 CanonicalName* canonical_name = reader->ReadCanonicalNameReference(); 276 if ((canonical_name == -1) && !allow_null) {
270 if (canonical_name == NULL && !allow_null) {
271 FATAL("Expected a valid member reference, but got `null`"); 277 FATAL("Expected a valid member reference, but got `null`");
272 } 278 }
273
274 if (canonical_name != NULL) {
275 canonical_name->set_referenced(true);
276 }
277
278 return canonical_name; 279 return canonical_name;
279 } 280 }
280 281
281 282
282 CanonicalName* Reference::ReadClassFrom(Reader* reader, bool allow_null) { 283 intptr_t Reference::ReadClassFrom(Reader* reader, bool allow_null) {
283 TRACE_READ_OFFSET(); 284 TRACE_READ_OFFSET();
284 285 intptr_t canonical_name = reader->ReadCanonicalNameReference();
285 CanonicalName* canonical_name = reader->ReadCanonicalNameReference(); 286 if ((canonical_name == -1) && !allow_null) {
286 if (canonical_name == NULL && !allow_null) {
287 FATAL("Expected a valid class reference, but got `null`"); 287 FATAL("Expected a valid class reference, but got `null`");
288 } 288 }
289
290 if (canonical_name != NULL) {
291 canonical_name->set_referenced(true);
292 }
293
294 return canonical_name; 289 return canonical_name;
295 } 290 }
296 291
297 292
298 CanonicalName* Reference::ReadTypedefFrom(Reader* reader) { 293 intptr_t Reference::ReadTypedefFrom(Reader* reader) {
299 TRACE_READ_OFFSET(); 294 TRACE_READ_OFFSET();
300 295 intptr_t canonical_name = reader->ReadCanonicalNameReference();
301 CanonicalName* canonical_name = reader->ReadCanonicalNameReference(); 296 if (canonical_name == -1) {
302 if (canonical_name == NULL) {
303 FATAL("Expected a valid typedef reference, but got `null`"); 297 FATAL("Expected a valid typedef reference, but got `null`");
304 } 298 }
305
306 canonical_name->set_referenced(true);
307
308 return canonical_name; 299 return canonical_name;
309 } 300 }
310 301
311 302
312 Field* Field::ReadFrom(Reader* reader) { 303 Field* Field::ReadFrom(Reader* reader) {
313 TRACE_READ_OFFSET(); 304 TRACE_READ_OFFSET();
314 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. 305 kernel_offset_ = reader->offset(); // Notice the ReadTag() below.
315 Tag tag = reader->ReadTag(); 306 Tag tag = reader->ReadTag();
316 ASSERT(tag == kField); 307 ASSERT(tag == kField);
317 308
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 VariableScope<ReaderHelper> parameters(reader->helper()); 1356 VariableScope<ReaderHelper> parameters(reader->helper());
1366 decl->function_ = FunctionNode::ReadFrom(reader); 1357 decl->function_ = FunctionNode::ReadFrom(reader);
1367 return decl; 1358 return decl;
1368 } 1359 }
1369 1360
1370 1361
1371 Name* Name::ReadFrom(Reader* reader) { 1362 Name* Name::ReadFrom(Reader* reader) {
1372 intptr_t name_index = reader->ReadUInt(); 1363 intptr_t name_index = reader->ReadUInt();
1373 if ((reader->StringLength(name_index) >= 1) && 1364 if ((reader->StringLength(name_index) >= 1) &&
1374 (reader->CharacterAt(name_index, 0) == '_')) { 1365 (reader->CharacterAt(name_index, 0) == '_')) {
1375 CanonicalName* library_reference = reader->ReadCanonicalNameReference(); 1366 intptr_t library_reference = reader->ReadCanonicalNameReference();
1376 return new Name(name_index, library_reference); 1367 return new Name(name_index, library_reference);
1377 } else { 1368 } else {
1378 return new Name(name_index, NULL); 1369 return new Name(name_index, NULL);
1379 } 1370 }
1380 } 1371 }
1381 1372
1382 1373
1383 DartType* DartType::ReadFrom(Reader* reader) { 1374 DartType* DartType::ReadFrom(Reader* reader) {
1384 TRACE_READ_OFFSET(); 1375 TRACE_READ_OFFSET();
1385 Tag tag = reader->ReadTag(); 1376 Tag tag = reader->ReadTag();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 1416
1426 1417
1427 VoidType* VoidType::ReadFrom(Reader* reader) { 1418 VoidType* VoidType::ReadFrom(Reader* reader) {
1428 TRACE_READ_OFFSET(); 1419 TRACE_READ_OFFSET();
1429 return new VoidType(); 1420 return new VoidType();
1430 } 1421 }
1431 1422
1432 1423
1433 InterfaceType* InterfaceType::ReadFrom(Reader* reader) { 1424 InterfaceType* InterfaceType::ReadFrom(Reader* reader) {
1434 TRACE_READ_OFFSET(); 1425 TRACE_READ_OFFSET();
1435 CanonicalName* klass_name = Reference::ReadClassFrom(reader); 1426 intptr_t klass_name = Reference::ReadClassFrom(reader);
1436 InterfaceType* type = new InterfaceType(klass_name); 1427 InterfaceType* type = new InterfaceType(klass_name);
1437 type->type_arguments().ReadFromStatic<DartType>(reader); 1428 type->type_arguments().ReadFromStatic<DartType>(reader);
1438 return type; 1429 return type;
1439 } 1430 }
1440 1431
1441 1432
1442 InterfaceType* InterfaceType::ReadFrom(Reader* reader, 1433 InterfaceType* InterfaceType::ReadFrom(Reader* reader,
1443 bool _without_type_arguments_) { 1434 bool _without_type_arguments_) {
1444 TRACE_READ_OFFSET(); 1435 TRACE_READ_OFFSET();
1445 CanonicalName* klass_name = Reference::ReadClassFrom(reader); 1436 intptr_t klass_name = Reference::ReadClassFrom(reader);
1446 InterfaceType* type = new InterfaceType(klass_name); 1437 InterfaceType* type = new InterfaceType(klass_name);
1447 ASSERT(_without_type_arguments_); 1438 ASSERT(_without_type_arguments_);
1448 return type; 1439 return type;
1449 } 1440 }
1450 1441
1451 1442
1452 TypedefType* TypedefType::ReadFrom(Reader* reader) { 1443 TypedefType* TypedefType::ReadFrom(Reader* reader) {
1453 TRACE_READ_OFFSET(); 1444 TRACE_READ_OFFSET();
1454 CanonicalName* typedef_name = Reference::ReadTypedefFrom(reader); 1445 intptr_t typedef_name = Reference::ReadTypedefFrom(reader);
1455 TypedefType* type = new TypedefType(typedef_name); 1446 TypedefType* type = new TypedefType(typedef_name);
1456 type->type_arguments().ReadFromStatic<DartType>(reader); 1447 type->type_arguments().ReadFromStatic<DartType>(reader);
1457 return type; 1448 return type;
1458 } 1449 }
1459 1450
1460 1451
1461 FunctionType* FunctionType::ReadFrom(Reader* reader) { 1452 FunctionType* FunctionType::ReadFrom(Reader* reader) {
1462 TRACE_READ_OFFSET(); 1453 TRACE_READ_OFFSET();
1463 FunctionType* type = new FunctionType(); 1454 FunctionType* type = new FunctionType();
1464 TypeParameterScope<ReaderHelper> scope(reader->helper()); 1455 TypeParameterScope<ReaderHelper> scope(reader->helper());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 return type; 1488 return type;
1498 } 1489 }
1499 1490
1500 1491
1501 Program* Program::ReadFrom(Reader* reader) { 1492 Program* Program::ReadFrom(Reader* reader) {
1502 TRACE_READ_OFFSET(); 1493 TRACE_READ_OFFSET();
1503 uint32_t magic = reader->ReadUInt32(); 1494 uint32_t magic = reader->ReadUInt32();
1504 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); 1495 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier");
1505 1496
1506 Program* program = new Program(); 1497 Program* program = new Program();
1507 program->canonical_name_root_ = CanonicalName::NewRoot();
1508 reader->helper()->set_program(program); 1498 reader->helper()->set_program(program);
1509 1499
1510 // Skip the table of string end offsets. 1500 // Deserialize the string offset table to give fast access to the string data
1511 reader->MarkStringTableOffset(); 1501 // during deserialization.
1512 intptr_t length = reader->ReadUInt(); 1502 program->string_table_offset_ = reader->offset();
1513 reader->string_offsets_ = new intptr_t[length + 1]; 1503 intptr_t string_count = reader->ReadUInt();
1504 reader->string_offsets_ = new intptr_t[string_count + 1];
1514 intptr_t offset = 0; 1505 intptr_t offset = 0;
1515 for (intptr_t i = 0; i < length; ++i) { 1506 for (intptr_t i = 0; i < string_count; ++i) {
1516 reader->string_offsets_[i] = offset; 1507 reader->string_offsets_[i] = offset;
1517 offset = reader->ReadUInt(); 1508 offset = reader->ReadUInt();
1518 } 1509 }
1519 reader->string_offsets_[length] = offset; 1510 reader->string_offsets_[string_count] = offset;
1520 // Skip the UTF-8 encoded strings. 1511 // Skip the UTF-8 encoded strings.
1521 reader->MarkStringDataOffset(); 1512 reader->MarkStringDataOffset();
1522 reader->Consume(offset); 1513 reader->Consume(offset);
1523 1514
1524 program->string_table_offset_ = reader->string_table_offset();
1525 ASSERT(program->string_table_offset_ >= 0);
1526 program->source_table_.ReadFrom(reader); 1515 program->source_table_.ReadFrom(reader);
1527 1516
1528 int canonical_names = reader->ReadUInt(); 1517 // Deserialize the canonical name table to give fast access to canonical names
1529 reader->helper()->SetCanonicalNameCount(canonical_names); 1518 // during deserialization.
1530 for (int i = 0; i < canonical_names; ++i) { 1519 program->name_table_offset_ = reader->offset();
1531 int biased_parent_index = reader->ReadUInt(); 1520 intptr_t name_count = reader->ReadUInt();
1532 CanonicalName* parent; 1521 reader->canonical_name_parents_ = new intptr_t[name_count];
1533 if (biased_parent_index != 0) { 1522 reader->canonical_name_strings_ = new intptr_t[name_count];
1534 parent = reader->helper()->GetCanonicalName(biased_parent_index - 1); 1523 for (int i = 0; i < name_count; ++i) {
1535 } else { 1524 // The parent name index is biased: 0 is the root name and otherwise N+1 is
1536 parent = program->canonical_name_root(); 1525 // the Nth name.
1537 } 1526 reader->canonical_name_parents_[i] = reader->ReadUInt() - 1;
1538 ASSERT(parent != NULL); 1527 reader->canonical_name_strings_[i] = reader->ReadUInt();
1539 intptr_t name_index = reader->ReadUInt();
1540 CanonicalName* canonical_name = parent->AddChild(name_index);
1541 reader->helper()->SetCanonicalName(i, canonical_name);
1542 } 1528 }
1543 1529
1544 int libraries = reader->ReadUInt(); 1530 int libraries = reader->ReadUInt();
1545 program->libraries().EnsureInitialized(libraries); 1531 program->libraries().EnsureInitialized(libraries);
1546 for (intptr_t i = 0; i < libraries; i++) { 1532 for (intptr_t i = 0; i < libraries; i++) {
1547 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); 1533 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader);
1548 } 1534 }
1549 1535
1550 program->main_method_reference_ = 1536 program->main_method_reference_ =
1551 Reference::ReadMemberFrom(reader, /*allow_null=*/true); 1537 Reference::ReadMemberFrom(reader, /*allow_null=*/true);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 1580
1595 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 1581 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
1596 intptr_t buffer_length) { 1582 intptr_t buffer_length) {
1597 kernel::Reader reader(buffer, buffer_length); 1583 kernel::Reader reader(buffer, buffer_length);
1598 return kernel::Program::ReadFrom(&reader); 1584 return kernel::Program::ReadFrom(&reader);
1599 } 1585 }
1600 1586
1601 1587
1602 } // namespace dart 1588 } // namespace dart
1603 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1589 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698