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

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

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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ 5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_
6 #define RUNTIME_VM_KERNEL_BINARY_H_ 6 #define RUNTIME_VM_KERNEL_BINARY_H_
7 7
8 #if !defined(DART_PRECOMPILED_RUNTIME) 8 #if !defined(DART_PRECOMPILED_RUNTIME)
9 9
10 #include <map> 10 #include <map>
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 Program* program() { return program_; } 305 Program* program() { return program_; }
306 void set_program(Program* program) { program_ = program; } 306 void set_program(Program* program) { program_ = program; }
307 307
308 BlockStack<VariableDeclaration>& variables() { return scope_; } 308 BlockStack<VariableDeclaration>& variables() { return scope_; }
309 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; } 309 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; }
310 BlockStack<SwitchCase>& switch_cases() { return switch_cases_; } 310 BlockStack<SwitchCase>& switch_cases() { return switch_cases_; }
311 311
312 BlockStack<LabeledStatement>* labels() { return labels_; } 312 BlockStack<LabeledStatement>* labels() { return labels_; }
313 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; } 313 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; }
314 314
315 CanonicalName* GetCanonicalName(int index) { return canonical_names_[index]; }
316 void SetCanonicalName(int index, CanonicalName* name) {
317 canonical_names_[index] = name;
318 }
319 void SetCanonicalNameCount(int count) { canonical_names_.SetLength(count); }
320
321 private: 315 private:
322 Program* program_; 316 Program* program_;
323 MallocGrowableArray<CanonicalName*> canonical_names_;
324 BlockStack<VariableDeclaration> scope_; 317 BlockStack<VariableDeclaration> scope_;
325 BlockStack<TypeParameter> type_parameters_; 318 BlockStack<TypeParameter> type_parameters_;
326 BlockStack<SwitchCase> switch_cases_; 319 BlockStack<SwitchCase> switch_cases_;
327 BlockStack<LabeledStatement>* labels_; 320 BlockStack<LabeledStatement>* labels_;
328 }; 321 };
329 322
330 323
331 class Reader { 324 class Reader {
332 public: 325 public:
333 Reader(const uint8_t* buffer, intptr_t size) 326 Reader(const uint8_t* buffer, intptr_t size)
334 : buffer_(buffer), 327 : buffer_(buffer),
335 size_(size), 328 size_(size),
336 offset_(0), 329 offset_(0),
337 string_table_offset_(-1),
338 string_data_offset_(-1), 330 string_data_offset_(-1),
339 string_offsets_(NULL) {} 331 string_offsets_(NULL),
332 canonical_name_parents_(NULL),
333 canonical_name_strings_(NULL) {}
340 334
341 ~Reader() { delete[] string_offsets_; } 335 ~Reader();
342 336
343 uint32_t ReadUInt32() { 337 uint32_t ReadUInt32() {
344 ASSERT(offset_ + 4 <= size_); 338 ASSERT(offset_ + 4 <= size_);
345 339
346 uint32_t value = (buffer_[offset_ + 0] << 24) | 340 uint32_t value = (buffer_[offset_ + 0] << 24) |
347 (buffer_[offset_ + 1] << 16) | 341 (buffer_[offset_ + 1] << 16) |
348 (buffer_[offset_ + 2] << 8) | (buffer_[offset_ + 3] << 0); 342 (buffer_[offset_ + 2] << 8) | (buffer_[offset_ + 3] << 0);
349 offset_ += 4; 343 offset_ += 4;
350 return value; 344 return value;
351 } 345 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return RT::ReadFrom(this); 484 return RT::ReadFrom(this);
491 } 485 }
492 486
493 template <typename T> 487 template <typename T>
494 T* ReadOptional() { 488 T* ReadOptional() {
495 return ReadOptional<T, T>(); 489 return ReadOptional<T, T>();
496 } 490 }
497 491
498 ReaderHelper* helper() { return &builder_; } 492 ReaderHelper* helper() { return &builder_; }
499 493
500 CanonicalName* ReadCanonicalNameReference() { 494 // A canonical name reference of -1 indicates none (for optional names), not
501 int index = ReadUInt(); 495 // the root name as in the canonical name table.
502 if (index == 0) return NULL; 496 intptr_t ReadCanonicalNameReference() { return ReadUInt() - 1; }
503 CanonicalName* name = builder_.GetCanonicalName(index - 1);
504 ASSERT(name != NULL);
505 return name;
506 }
507 497
508 intptr_t offset() { return offset_; } 498 intptr_t offset() { return offset_; }
509 void set_offset(intptr_t offset) { offset_ = offset; } 499 void set_offset(intptr_t offset) { offset_ = offset; }
510 intptr_t size() { return size_; } 500 intptr_t size() { return size_; }
511 501
512 const uint8_t* buffer() { return buffer_; } 502 const uint8_t* buffer() { return buffer_; }
513 503
514 intptr_t string_table_offset() { return string_table_offset_; }
515 void MarkStringTableOffset() {
516 ASSERT(string_table_offset_ == -1);
517 string_table_offset_ = offset_;
518 }
519
520 intptr_t string_data_offset() { return string_data_offset_; } 504 intptr_t string_data_offset() { return string_data_offset_; }
521 void MarkStringDataOffset() { 505 void MarkStringDataOffset() {
522 ASSERT(string_data_offset_ == -1); 506 ASSERT(string_data_offset_ == -1);
523 string_data_offset_ = offset_; 507 string_data_offset_ = offset_;
524 } 508 }
525 509
526 intptr_t StringLength(intptr_t string_index) { 510 intptr_t StringLength(intptr_t string_index) {
527 return string_offsets_[string_index + 1] - string_offsets_[string_index]; 511 return string_offsets_[string_index + 1] - string_offsets_[string_index];
528 } 512 }
529 513
530 uint8_t CharacterAt(intptr_t string_index, intptr_t index) { 514 uint8_t CharacterAt(intptr_t string_index, intptr_t index) {
531 ASSERT(index < StringLength(string_index)); 515 ASSERT(index < StringLength(string_index));
532 return buffer_[string_data_offset_ + string_offsets_[string_index] + index]; 516 return buffer_[string_data_offset_ + string_offsets_[string_index] + index];
533 } 517 }
534 518
519 // The canonical name index of a canonical name's parent (-1 indicates that
520 // the parent is the root name).
521 intptr_t CanonicalNameParent(intptr_t name_index) {
522 return canonical_name_parents_[name_index];
523 }
524
525 // The string index of a canonical name's name string.
526 intptr_t CanonicalNameString(intptr_t name_index) {
527 return canonical_name_strings_[name_index];
528 }
529
535 private: 530 private:
536 const uint8_t* buffer_; 531 const uint8_t* buffer_;
537 intptr_t size_; 532 intptr_t size_;
538 intptr_t offset_; 533 intptr_t offset_;
539 ReaderHelper builder_; 534 ReaderHelper builder_;
540 TokenPosition max_position_; 535 TokenPosition max_position_;
541 TokenPosition min_position_; 536 TokenPosition min_position_;
542 intptr_t current_script_id_; 537 intptr_t current_script_id_;
543 538
544 // When the binary is deserialized the offset of the start of the string table 539 // The offset of the start of the string data is recorded to allow access to
545 // (the length) and the offset of the start of the string data are recorded. 540 // the strings during deserialization.
546 intptr_t string_table_offset_;
547 intptr_t string_data_offset_; 541 intptr_t string_data_offset_;
548 542
549 // The string offsets are decoded to support efficient access to string UTF-8 543 // The string offsets are decoded to support efficient access to string UTF-8
550 // encodings. 544 // encodings.
551 intptr_t* string_offsets_; 545 intptr_t* string_offsets_;
552 546
547 // The canonical names are decoded.
548 intptr_t* canonical_name_parents_;
549 intptr_t* canonical_name_strings_;
550
553 friend class PositionScope; 551 friend class PositionScope;
554 friend class Program; 552 friend class Program;
555 }; 553 };
556 554
557 555
558 // A helper class that resets the readers min and max positions both upon 556 // A helper class that resets the readers min and max positions both upon
559 // initialization and upon destruction, i.e. when created the min an max 557 // initialization and upon destruction, i.e. when created the min an max
560 // positions will be reset to "noSource", when destructing the min and max will 558 // positions will be reset to "noSource", when destructing the min and max will
561 // be reset to have they value they would have had, if they hadn't been reset in 559 // be reset to have they value they would have had, if they hadn't been reset in
562 // the first place. 560 // the first place.
(...skipping 19 matching lines...) Expand all
582 Reader* reader_; 580 Reader* reader_;
583 TokenPosition min_; 581 TokenPosition min_;
584 TokenPosition max_; 582 TokenPosition max_;
585 }; 583 };
586 584
587 } // namespace kernel 585 } // namespace kernel
588 } // namespace dart 586 } // namespace dart
589 587
590 #endif // !defined(DART_PRECOMPILED_RUNTIME) 588 #endif // !defined(DART_PRECOMPILED_RUNTIME)
591 #endif // RUNTIME_VM_KERNEL_BINARY_H_ 589 #endif // RUNTIME_VM_KERNEL_BINARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698