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

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

Issue 2860823002: Introduce classes for string and name indexes (Closed)
Patch Set: 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
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('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) 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/kernel_binary.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const intptr_t len = functions_.length(); 88 const intptr_t len = functions_.length();
89 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld)); 89 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld));
90 for (intptr_t i = 0; i < len; i++) { 90 for (intptr_t i = 0; i < len; i++) {
91 res.SetAt(i, *functions_[i]); 91 res.SetAt(i, *functions_[i]);
92 } 92 }
93 return res.raw(); 93 return res.raw();
94 } 94 }
95 95
96 96
97 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( 97 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary(
98 intptr_t library) { 98 NameIndex library) {
99 return reader_->LookupLibrary(library).raw(); 99 return reader_->LookupLibrary(library).raw();
100 } 100 }
101 101
102 102
103 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(intptr_t klass) { 103 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(NameIndex klass) {
104 return reader_->LookupClass(klass).raw(); 104 return reader_->LookupClass(klass).raw();
105 } 105 }
106 106
107 107
108 KernelReader::KernelReader(Program* program) 108 KernelReader::KernelReader(Program* program)
109 : program_(program), 109 : program_(program),
110 thread_(dart::Thread::Current()), 110 thread_(dart::Thread::Current()),
111 zone_(thread_->zone()), 111 zone_(thread_->zone()),
112 isolate_(thread_->isolate()), 112 isolate_(thread_->isolate()),
113 scripts_(Array::ZoneHandle(zone_)), 113 scripts_(Array::ZoneHandle(zone_)),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!library.Loaded()) library.SetLoaded(); 175 if (!library.Loaded()) library.SetLoaded();
176 } 176 }
177 177
178 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { 178 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) {
179 // There is a function _getMainClosure in dart:_builtin that returns the 179 // There is a function _getMainClosure in dart:_builtin that returns the
180 // main procedure. Since the platform libraries are compiled before the 180 // main procedure. Since the platform libraries are compiled before the
181 // program script, this function might need to be patched here. 181 // program script, this function might need to be patched here.
182 182
183 // If there is no main method then we have compiled a partial Kernel file 183 // If there is no main method then we have compiled a partial Kernel file
184 // and do not need to patch here. 184 // and do not need to patch here.
185 intptr_t main = program_->main_method(); 185 NameIndex main = program_->main_method();
186 if (main == -1) { 186 if (main == -1) {
187 return dart::Library::Handle(Z); 187 return dart::Library::Handle(Z);
188 } 188 }
189 189
190 // If the builtin library is not set in the object store, then we are 190 // If the builtin library is not set in the object store, then we are
191 // bootstrapping and do not need to patch here. 191 // bootstrapping and do not need to patch here.
192 dart::Library& builtin_library = 192 dart::Library& builtin_library =
193 dart::Library::Handle(Z, I->object_store()->builtin_library()); 193 dart::Library::Handle(Z, I->object_store()->builtin_library());
194 if (builtin_library.IsNull()) { 194 if (builtin_library.IsNull()) {
195 return dart::Library::Handle(Z); 195 return dart::Library::Handle(Z);
196 } 196 }
197 197
198 intptr_t main_library = H.EnclosingName(main); 198 NameIndex main_library = H.EnclosingName(main);
199 dart::Library& library = LookupLibrary(main_library); 199 dart::Library& library = LookupLibrary(main_library);
200 // Sanity check that we can find the main entrypoint. 200 // Sanity check that we can find the main entrypoint.
201 Object& main_obj = Object::Handle( 201 Object& main_obj = Object::Handle(
202 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); 202 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main")));
203 ASSERT(!main_obj.IsNull()); 203 ASSERT(!main_obj.IsNull());
204 204
205 Function& to_patch = Function::Handle( 205 Function& to_patch = Function::Handle(
206 Z, builtin_library.LookupFunctionAllowPrivate( 206 Z, builtin_library.LookupFunctionAllowPrivate(
207 dart::String::Handle(dart::String::New("_getMainClosure")))); 207 dart::String::Handle(dart::String::New("_getMainClosure"))));
208 208
209 Procedure* procedure = 209 Procedure* procedure =
210 reinterpret_cast<Procedure*>(to_patch.kernel_function()); 210 reinterpret_cast<Procedure*>(to_patch.kernel_function());
211 // If dart:_builtin was not compiled from Kernel at all or if it was 211 // If dart:_builtin was not compiled from Kernel at all or if it was
212 // linked with a script, it does not need to be patched. 212 // linked with a script, it does not need to be patched.
213 if ((procedure != NULL) && (procedure->function()->body() == NULL)) { 213 if ((procedure != NULL) && (procedure->function()->body() == NULL)) {
214 // We will handle the StaticGet specially and will not use the name. 214 // We will handle the StaticGet specially and will not use the name.
215 // 215 //
216 // TODO(kmillikin): we are leaking the function body. Find a way to 216 // TODO(kmillikin): we are leaking the function body. Find a way to
217 // deallocate it. 217 // deallocate it.
218 procedure->function()->set_body( 218 procedure->function()->set_body(
219 new ReturnStatement(new StaticGet(NULL))); 219 new ReturnStatement(new StaticGet(NameIndex())));
220 } 220 }
221 return library; 221 return library;
222 } 222 }
223 } 223 }
224 224
225 // Either class finalization failed or we caught a compile error. 225 // Either class finalization failed or we caught a compile error.
226 // In both cases sticky error would be set. 226 // In both cases sticky error would be set.
227 Error& error = Error::Handle(Z); 227 Error& error = Error::Handle(Z);
228 error = thread_->sticky_error(); 228 error = thread_->sticky_error();
229 thread_->clear_sticky_error(); 229 thread_->clear_sticky_error();
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 dart::String* native_name = NULL; 498 dart::String* native_name = NULL;
499 if (is_external) { 499 if (is_external) {
500 // Maybe it has a native implementation, which is not external as far as 500 // Maybe it has a native implementation, which is not external as far as
501 // the VM is concerned because it does have an implementation. Check for 501 // the VM is concerned because it does have an implementation. Check for
502 // an ExternalName annotation and extract the string from it. 502 // an ExternalName annotation and extract the string from it.
503 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) { 503 for (int i = 0; i < kernel_procedure->annotations().length(); ++i) {
504 Expression* annotation = kernel_procedure->annotations()[i]; 504 Expression* annotation = kernel_procedure->annotations()[i];
505 if (!annotation->IsConstructorInvocation()) continue; 505 if (!annotation->IsConstructorInvocation()) continue;
506 ConstructorInvocation* invocation = 506 ConstructorInvocation* invocation =
507 ConstructorInvocation::Cast(annotation); 507 ConstructorInvocation::Cast(annotation);
508 intptr_t annotation_class = H.EnclosingName(invocation->target()); 508 NameIndex annotation_class = H.EnclosingName(invocation->target());
509 ASSERT(H.IsClass(annotation_class)); 509 ASSERT(H.IsClass(annotation_class));
510 intptr_t class_name_index = H.CanonicalNameString(annotation_class); 510 StringIndex class_name_index = H.CanonicalNameString(annotation_class);
511 // Just compare by name, do not generate the annotation class. 511 // Just compare by name, do not generate the annotation class.
512 if (!H.StringEquals(class_name_index, "ExternalName")) continue; 512 if (!H.StringEquals(class_name_index, "ExternalName")) continue;
513 ASSERT(H.IsLibrary(H.CanonicalNameParent(annotation_class))); 513 ASSERT(H.IsLibrary(H.CanonicalNameParent(annotation_class)));
514 intptr_t library_name_index = 514 StringIndex library_name_index =
515 H.CanonicalNameString(H.CanonicalNameParent(annotation_class)); 515 H.CanonicalNameString(H.CanonicalNameParent(annotation_class));
516 if (!H.StringEquals(library_name_index, "dart:_internal")) continue; 516 if (!H.StringEquals(library_name_index, "dart:_internal")) continue;
517 517
518 is_external = false; 518 is_external = false;
519 ASSERT(invocation->arguments()->positional().length() == 1 && 519 ASSERT(invocation->arguments()->positional().length() == 1 &&
520 invocation->arguments()->named().length() == 0); 520 invocation->arguments()->named().length() == 0);
521 StringLiteral* literal = 521 StringLiteral* literal =
522 StringLiteral::Cast(invocation->arguments()->positional()[0]); 522 StringLiteral::Cast(invocation->arguments()->positional()[0]);
523 native_name = &H.DartSymbol(literal->value()); 523 native_name = &H.DartSymbol(literal->value());
524 break; 524 break;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 for (intptr_t i = 0; i <= last; ++i) { 621 for (intptr_t i = 0; i <= last; ++i) {
622 smi_value = Smi::New(source->At(i)); 622 smi_value = Smi::New(source->At(i));
623 array_object.SetAt(i, smi_value); 623 array_object.SetAt(i, smi_value);
624 } 624 }
625 return array_object.raw(); 625 return array_object.raw();
626 } else { 626 } else {
627 return Array::New(0); 627 return Array::New(0);
628 } 628 }
629 } 629 }
630 630
631 Script& KernelReader::ScriptAt(intptr_t index, intptr_t import_uri) { 631 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) {
632 Script& script = Script::ZoneHandle(Z); 632 Script& script = Script::ZoneHandle(Z);
633 script ^= scripts_.At(index); 633 script ^= scripts_.At(index);
634 if (script.IsNull()) { 634 if (script.IsNull()) {
635 // Create script with correct uri(s). 635 // Create script with correct uri(s).
636 uint8_t* uri_buffer = program_->source_table().UriFor(index); 636 uint8_t* uri_buffer = program_->source_table().UriFor(index);
637 intptr_t uri_size = program_->source_table().UriSizeFor(index); 637 intptr_t uri_size = program_->source_table().UriSizeFor(index);
638 dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld); 638 dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld);
639 dart::String& import_uri_string = 639 dart::String& import_uri_string =
640 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); 640 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld);
641 uint8_t* source_buffer = program_->source_table().SourceCodeFor(index); 641 uint8_t* source_buffer = program_->source_table().SourceCodeFor(index);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 pos++; 853 pos++;
854 } 854 }
855 if (is_setter) { 855 if (is_setter) {
856 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); 856 function.SetParameterTypeAt(pos, AbstractType::dynamic_type());
857 function.SetParameterNameAt(pos, Symbols::Value()); 857 function.SetParameterNameAt(pos, Symbols::Value());
858 pos++; 858 pos++;
859 } 859 }
860 } 860 }
861 861
862 862
863 dart::Library& KernelReader::LookupLibrary(intptr_t library) { 863 dart::Library& KernelReader::LookupLibrary(NameIndex library) {
864 dart::Library* handle = NULL; 864 dart::Library* handle = NULL;
865 if (!libraries_.Lookup(library, &handle)) { 865 if (!libraries_.Lookup(library, &handle)) {
866 const dart::String& url = H.DartSymbol(H.CanonicalNameString(library)); 866 const dart::String& url = H.DartSymbol(H.CanonicalNameString(library));
867 handle = 867 handle =
868 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url)); 868 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url));
869 if (handle->IsNull()) { 869 if (handle->IsNull()) {
870 *handle = dart::Library::New(url); 870 *handle = dart::Library::New(url);
871 handle->Register(thread_); 871 handle->Register(thread_);
872 } 872 }
873 ASSERT(!handle->IsNull()); 873 ASSERT(!handle->IsNull());
874 libraries_.Insert(library, handle); 874 libraries_.Insert(library, handle);
875 } 875 }
876 return *handle; 876 return *handle;
877 } 877 }
878 878
879 879
880 dart::Class& KernelReader::LookupClass(intptr_t klass) { 880 dart::Class& KernelReader::LookupClass(NameIndex klass) {
881 dart::Class* handle = NULL; 881 dart::Class* handle = NULL;
882 if (!classes_.Lookup(klass, &handle)) { 882 if (!classes_.Lookup(klass, &handle)) {
883 dart::Library& library = LookupLibrary(H.CanonicalNameParent(klass)); 883 dart::Library& library = LookupLibrary(H.CanonicalNameParent(klass));
884 const dart::String& name = H.DartClassName(klass); 884 const dart::String& name = H.DartClassName(klass);
885 handle = &dart::Class::Handle(Z, library.LookupClass(name)); 885 handle = &dart::Class::Handle(Z, library.LookupClass(name));
886 if (handle->IsNull()) { 886 if (handle->IsNull()) {
887 *handle = dart::Class::New(library, name, Script::Handle(Z), 887 *handle = dart::Class::New(library, name, Script::Handle(Z),
888 TokenPosition::kNoSource); 888 TokenPosition::kNoSource);
889 library.AddClass(*handle); 889 library.AddClass(*handle);
890 } 890 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 initializer_fun.set_is_debuggable(false); 940 initializer_fun.set_is_debuggable(false);
941 initializer_fun.set_is_reflectable(false); 941 initializer_fun.set_is_reflectable(false);
942 initializer_fun.set_is_inlinable(false); 942 initializer_fun.set_is_inlinable(false);
943 return new (zone) ParsedFunction(thread, initializer_fun); 943 return new (zone) ParsedFunction(thread, initializer_fun);
944 } 944 }
945 945
946 946
947 } // namespace kernel 947 } // namespace kernel
948 } // namespace dart 948 } // namespace dart
949 #endif // !defined(DART_PRECOMPILED_RUNTIME) 949 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698