OLD | NEW |
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 | 4 |
5 #include "vm/kernel_reader.h" | 5 #include "vm/kernel_reader.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/kernel_binary.h" |
10 #include "vm/longjump.h" | 11 #include "vm/longjump.h" |
11 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
12 #include "vm/parser.h" | 13 #include "vm/parser.h" |
13 #include "vm/symbols.h" | 14 #include "vm/symbols.h" |
14 | 15 |
15 #if !defined(DART_PRECOMPILED_RUNTIME) | 16 #if !defined(DART_PRECOMPILED_RUNTIME) |
16 namespace dart { | 17 namespace dart { |
17 namespace kernel { | 18 namespace kernel { |
18 | 19 |
19 #define Z (zone_) | 20 #define Z (zone_) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 zone_(thread_->zone()), | 112 zone_(thread_->zone()), |
112 isolate_(thread_->isolate()), | 113 isolate_(thread_->isolate()), |
113 scripts_(Array::ZoneHandle(zone_)), | 114 scripts_(Array::ZoneHandle(zone_)), |
114 translation_helper_(this, thread_), | 115 translation_helper_(this, thread_), |
115 type_translator_(&translation_helper_, | 116 type_translator_(&translation_helper_, |
116 &active_class_, | 117 &active_class_, |
117 /*finalize=*/false) { | 118 /*finalize=*/false) { |
118 intptr_t source_file_count = program->source_table().size(); | 119 intptr_t source_file_count = program->source_table().size(); |
119 scripts_ = Array::New(source_file_count, Heap::kOld); | 120 scripts_ = Array::New(source_file_count, Heap::kOld); |
120 | 121 |
121 // Copy the Kernel strings out of the binary and into the VM's heap. The size | |
122 // of the string data can be computed from the offset and size of the last | |
123 // string. This relies on the strings occurring in order in the program's | |
124 // string table. | |
125 List<String>& strings = program->string_table().strings(); | |
126 String* last_string = strings[strings.length() - 1]; | |
127 intptr_t size = last_string->offset() + last_string->size(); | |
128 TypedData& data = TypedData::Handle( | |
129 Z, TypedData::New(kTypedDataUint8ArrayCid, size, Heap::kOld)); | |
130 ASSERT(program->string_data_offset() >= 0); | |
131 // We need at least one library to get access to the binary. | 122 // We need at least one library to get access to the binary. |
132 ASSERT(program->libraries().length() > 0); | 123 ASSERT(program->libraries().length() > 0); |
| 124 Library* library = program->libraries()[0]; |
| 125 Reader reader(library->kernel_data(), library->kernel_data_size()); |
| 126 |
| 127 // Copy the Kernel string offsets out of the binary and into the VM's heap. |
| 128 ASSERT(program->string_table_offset() >= 0); |
| 129 reader.set_offset(program->string_table_offset()); |
| 130 intptr_t count = reader.ReadUInt() + 1; |
| 131 TypedData& offsets = TypedData::Handle( |
| 132 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld)); |
| 133 offsets.SetUint32(0, 0); |
| 134 intptr_t end_offset = 0; |
| 135 for (intptr_t i = 1; i < count; ++i) { |
| 136 end_offset = reader.ReadUInt(); |
| 137 offsets.SetUint32(i << 2, end_offset); |
| 138 } |
| 139 |
| 140 // Copy the string data out of the binary and into the VM's heap. |
| 141 TypedData& data = TypedData::Handle( |
| 142 Z, TypedData::New(kTypedDataUint8ArrayCid, end_offset, Heap::kOld)); |
133 { | 143 { |
134 NoSafepointScope no_safepoint; | 144 NoSafepointScope no_safepoint; |
135 memmove(data.DataAddr(0), program->libraries()[0]->kernel_data() + | 145 memmove(data.DataAddr(0), reader.buffer() + reader.offset(), end_offset); |
136 program->string_data_offset(), | |
137 size); | |
138 } | 146 } |
| 147 H.SetStringOffsets(offsets); |
139 H.SetStringData(data); | 148 H.SetStringData(data); |
140 } | 149 } |
141 | 150 |
142 | 151 |
143 Object& KernelReader::ReadProgram() { | 152 Object& KernelReader::ReadProgram() { |
144 LongJumpScope jump; | 153 LongJumpScope jump; |
145 if (setjmp(*jump.Set()) == 0) { | 154 if (setjmp(*jump.Set()) == 0) { |
146 intptr_t length = program_->libraries().length(); | 155 intptr_t length = program_->libraries().length(); |
147 for (intptr_t i = 0; i < length; i++) { | 156 for (intptr_t i = 0; i < length; i++) { |
148 Library* kernel_library = program_->libraries()[i]; | 157 Library* kernel_library = program_->libraries()[i]; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // Maybe it has a native implementation, which is not external as far as | 489 // Maybe it has a native implementation, which is not external as far as |
481 // the VM is concerned because it does have an implementation. Check for | 490 // the VM is concerned because it does have an implementation. Check for |
482 // an ExternalName annotation and extract the string from it. | 491 // an ExternalName annotation and extract the string from it. |
483 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { | 492 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { |
484 Expression* annotation = kernel_procedure->annotations()[i]; | 493 Expression* annotation = kernel_procedure->annotations()[i]; |
485 if (!annotation->IsConstructorInvocation()) continue; | 494 if (!annotation->IsConstructorInvocation()) continue; |
486 ConstructorInvocation* invocation = | 495 ConstructorInvocation* invocation = |
487 ConstructorInvocation::Cast(annotation); | 496 ConstructorInvocation::Cast(annotation); |
488 CanonicalName* annotation_class = H.EnclosingName(invocation->target()); | 497 CanonicalName* annotation_class = H.EnclosingName(invocation->target()); |
489 ASSERT(H.IsClass(annotation_class)); | 498 ASSERT(H.IsClass(annotation_class)); |
490 String* class_name = annotation_class->name(); | 499 intptr_t class_name_index = annotation_class->name(); |
491 // Just compare by name, do not generate the annotation class. | 500 // Just compare by name, do not generate the annotation class. |
492 if (!H.StringEquals(class_name, "ExternalName")) continue; | 501 if (!H.StringEquals(class_name_index, "ExternalName")) continue; |
493 ASSERT(H.IsLibrary(annotation_class->parent())); | 502 ASSERT(H.IsLibrary(annotation_class->parent())); |
494 String* library_name = annotation_class->parent()->name(); | 503 intptr_t library_name_index = annotation_class->parent()->name(); |
495 if (!H.StringEquals(library_name, "dart:_internal")) continue; | 504 if (!H.StringEquals(library_name_index, "dart:_internal")) continue; |
496 | 505 |
497 is_external = false; | 506 is_external = false; |
498 ASSERT(invocation->arguments()->positional().length() == 1 && | 507 ASSERT(invocation->arguments()->positional().length() == 1 && |
499 invocation->arguments()->named().length() == 0); | 508 invocation->arguments()->named().length() == 0); |
500 StringLiteral* literal = | 509 StringLiteral* literal = |
501 StringLiteral::Cast(invocation->arguments()->positional()[0]); | 510 StringLiteral::Cast(invocation->arguments()->positional()[0]); |
502 native_name = &H.DartSymbol(literal->value()); | 511 native_name = &H.DartSymbol(literal->value()); |
503 break; | 512 break; |
504 } | 513 } |
505 } | 514 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 for (intptr_t i = 0; i <= last; ++i) { | 609 for (intptr_t i = 0; i <= last; ++i) { |
601 smi_value = Smi::New(source->At(i)); | 610 smi_value = Smi::New(source->At(i)); |
602 array_object.SetAt(i, smi_value); | 611 array_object.SetAt(i, smi_value); |
603 } | 612 } |
604 return array_object.raw(); | 613 return array_object.raw(); |
605 } else { | 614 } else { |
606 return Array::New(0); | 615 return Array::New(0); |
607 } | 616 } |
608 } | 617 } |
609 | 618 |
610 Script& KernelReader::ScriptAt(intptr_t index, String* import_uri) { | 619 Script& KernelReader::ScriptAt(intptr_t index, intptr_t import_uri) { |
611 Script& script = Script::ZoneHandle(Z); | 620 Script& script = Script::ZoneHandle(Z); |
612 script ^= scripts_.At(index); | 621 script ^= scripts_.At(index); |
613 if (script.IsNull()) { | 622 if (script.IsNull()) { |
614 // Create script with correct uri(s). | 623 // Create script with correct uri(s). |
615 uint8_t* uri_buffer = program_->source_table().UriFor(index); | 624 uint8_t* uri_buffer = program_->source_table().UriFor(index); |
616 intptr_t uri_size = program_->source_table().UriSizeFor(index); | 625 intptr_t uri_size = program_->source_table().UriSizeFor(index); |
617 dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld); | 626 dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld); |
618 dart::String& import_uri_string = | 627 dart::String& import_uri_string = |
619 import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld); | 628 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); |
620 uint8_t* source_buffer = program_->source_table().SourceCodeFor(index); | 629 uint8_t* source_buffer = program_->source_table().SourceCodeFor(index); |
621 intptr_t source_size = program_->source_table().SourceCodeSizeFor(index); | 630 intptr_t source_size = program_->source_table().SourceCodeSizeFor(index); |
622 dart::String& source_code = | 631 dart::String& source_code = |
623 H.DartString(source_buffer, source_size, Heap::kOld); | 632 H.DartString(source_buffer, source_size, Heap::kOld); |
624 script = Script::New(import_uri_string, uri_string, source_code, | 633 script = Script::New(import_uri_string, uri_string, source_code, |
625 RawScript::kKernelTag); | 634 RawScript::kKernelTag); |
626 script.set_kernel_strings(H.string_data()); | 635 script.set_kernel_string_offsets(H.string_offsets()); |
| 636 script.set_kernel_string_data(H.string_data()); |
627 scripts_.SetAt(index, script); | 637 scripts_.SetAt(index, script); |
628 | 638 |
629 // Create line_starts array for the script. | 639 // Create line_starts array for the script. |
630 intptr_t* line_starts = program_->source_table().LineStartsFor(index); | 640 intptr_t* line_starts = program_->source_table().LineStartsFor(index); |
631 intptr_t line_count = program_->source_table().LineCountFor(index); | 641 intptr_t line_count = program_->source_table().LineCountFor(index); |
632 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); | 642 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); |
633 Smi& value = Smi::Handle(Z); | 643 Smi& value = Smi::Handle(Z); |
634 for (intptr_t i = 0; i < line_count; ++i) { | 644 for (intptr_t i = 0; i < line_count; ++i) { |
635 value = Smi::New(line_starts[i]); | 645 value = Smi::New(line_starts[i]); |
636 array_object.SetAt(i, value); | 646 array_object.SetAt(i, value); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 initializer_fun.set_is_debuggable(false); | 927 initializer_fun.set_is_debuggable(false); |
918 initializer_fun.set_is_reflectable(false); | 928 initializer_fun.set_is_reflectable(false); |
919 initializer_fun.set_is_inlinable(false); | 929 initializer_fun.set_is_inlinable(false); |
920 return new (zone) ParsedFunction(thread, initializer_fun); | 930 return new (zone) ParsedFunction(thread, initializer_fun); |
921 } | 931 } |
922 | 932 |
923 | 933 |
924 } // namespace kernel | 934 } // namespace kernel |
925 } // namespace dart | 935 } // namespace dart |
926 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 936 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |