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

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

Issue 2901533002: [kernel] Stream everything. Replace .kernel_function with .kernel_offset (Closed)
Patch Set: Fix for bad merge Created 3 years, 6 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_binary_flowgraph.cc ('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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return dart::Library::Handle(Z); 195 return dart::Library::Handle(Z);
196 } 196 }
197 197
198 NameIndex 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(
206 Z, builtin_library.LookupFunctionAllowPrivate(
207 dart::String::Handle(dart::String::New("_getMainClosure"))));
208
209 Procedure* procedure =
210 reinterpret_cast<Procedure*>(to_patch.kernel_function());
211 // If dart:_builtin was not compiled from Kernel at all it does not need
212 // to be patched.
213 if (procedure != NULL) {
214 // We will handle the StaticGet specially and will not use the name.
215 // Note that we pass "true" in cannot_stream to avoid trying to stream
216 // a non-existing part of the binary.
217 //
218 // TODO(kmillikin): we are leaking the new function body. Find a way to
219 // deallocate it.
220 procedure->function()->ReplaceBody(
221 new ReturnStatement(new StaticGet(NameIndex(), false), false));
222 }
223 return library; 205 return library;
224 } 206 }
225 } 207 }
226 208
227 // Either class finalization failed or we caught a compile error. 209 // Either class finalization failed or we caught a compile error.
228 // In both cases sticky error would be set. 210 // In both cases sticky error would be set.
229 Error& error = Error::Handle(Z); 211 Error& error = Error::Handle(Z);
230 error = thread_->sticky_error(); 212 error = thread_->sticky_error();
231 thread_->clear_sticky_error(); 213 thread_->clear_sticky_error();
232 return error; 214 return error;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 Field* kernel_field = kernel_library->fields()[i]; 246 Field* kernel_field = kernel_library->fields()[i];
265 247
266 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 248 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
267 const dart::String& name = H.DartFieldName(kernel_field->name()); 249 const dart::String& name = H.DartFieldName(kernel_field->name());
268 const Object& script_class = 250 const Object& script_class =
269 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index()); 251 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index());
270 dart::Field& field = dart::Field::Handle( 252 dart::Field& field = dart::Field::Handle(
271 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(), 253 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(),
272 kernel_field->IsConst(), script_class, 254 kernel_field->IsConst(), script_class,
273 kernel_field->position())); 255 kernel_field->position()));
274 field.set_kernel_field(kernel_field); 256 field.set_kernel_offset(kernel_field->kernel_offset());
275 const AbstractType& type = T.TranslateType(kernel_field->type()); 257 const AbstractType& type = T.TranslateType(kernel_field->type());
276 field.SetFieldType(type); 258 field.SetFieldType(type);
277 field.set_has_initializer(kernel_field->initializer() != NULL); 259 field.set_has_initializer(kernel_field->initializer() != NULL);
278 GenerateFieldAccessors(toplevel_class, field, kernel_field); 260 GenerateFieldAccessors(toplevel_class, field, kernel_field);
279 fields_.Add(&field); 261 fields_.Add(&field);
280 library.AddObject(field, name); 262 library.AddObject(field, name);
281 } 263 }
282 toplevel_class.AddFields(fields_); 264 toplevel_class.AddFields(fields_);
283 265
284 // Load toplevel procedures. 266 // Load toplevel procedures.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 dart::Field& field = dart::Field::Handle( 398 dart::Field& field = dart::Field::Handle(
417 Z, 399 Z,
418 dart::Field::New(name, kernel_field->IsStatic(), 400 dart::Field::New(name, kernel_field->IsStatic(),
419 // In the VM all const fields are implicitly final 401 // In the VM all const fields are implicitly final
420 // whereas in Kernel they are not final because they 402 // whereas in Kernel they are not final because they
421 // are not explicitly declared that way. 403 // are not explicitly declared that way.
422 kernel_field->IsFinal() || kernel_field->IsConst(), 404 kernel_field->IsFinal() || kernel_field->IsConst(),
423 kernel_field->IsConst(), 405 kernel_field->IsConst(),
424 false, // is_reflectable 406 false, // is_reflectable
425 script_class, type, kernel_field->position())); 407 script_class, type, kernel_field->position()));
426 field.set_kernel_field(kernel_field); 408 field.set_kernel_offset(kernel_field->kernel_offset());
427 field.set_has_initializer(kernel_field->initializer() != NULL); 409 field.set_has_initializer(kernel_field->initializer() != NULL);
428 GenerateFieldAccessors(klass, field, kernel_field); 410 GenerateFieldAccessors(klass, field, kernel_field);
429 fields_.Add(&field); 411 fields_.Add(&field);
430 } 412 }
431 klass.AddFields(fields_); 413 klass.AddFields(fields_);
432 } 414 }
433 415
434 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) { 416 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) {
435 Constructor* kernel_constructor = kernel_klass->constructors()[i]; 417 Constructor* kernel_constructor = kernel_klass->constructors()[i];
436 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor); 418 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor);
437 419
438 const dart::String& name = 420 const dart::String& name =
439 H.DartConstructorName(kernel_constructor->canonical_name()); 421 H.DartConstructorName(kernel_constructor->canonical_name());
440 Function& function = dart::Function::ZoneHandle( 422 Function& function = dart::Function::ZoneHandle(
441 Z, dart::Function::New(name, RawFunction::kConstructor, 423 Z, dart::Function::New(name, RawFunction::kConstructor,
442 false, // is_static 424 false, // is_static
443 kernel_constructor->IsConst(), 425 kernel_constructor->IsConst(),
444 false, // is_abstract 426 false, // is_abstract
445 kernel_constructor->IsExternal(), 427 kernel_constructor->IsExternal(),
446 false, // is_native 428 false, // is_native
447 klass, kernel_constructor->position())); 429 klass, kernel_constructor->position()));
448 function.set_end_token_pos(kernel_constructor->end_position()); 430 function.set_end_token_pos(kernel_constructor->end_position());
449 functions_.Add(&function); 431 functions_.Add(&function);
450 function.set_kernel_function(kernel_constructor); 432 function.set_kernel_offset(kernel_constructor->kernel_offset());
451 function.set_result_type(T.ReceiverType(klass)); 433 function.set_result_type(T.ReceiverType(klass));
452 SetupFunctionParameters(H, T, klass, function, 434 SetupFunctionParameters(H, T, klass, function,
453 kernel_constructor->function(), 435 kernel_constructor->function(),
454 true, // is_method 436 true, // is_method
455 false); // is_closure 437 false); // is_closure
456 438
457 if (FLAG_enable_mirrors) { 439 if (FLAG_enable_mirrors) {
458 library.AddFunctionMetadata(function, TokenPosition::kNoSource, 440 library.AddFunctionMetadata(function, TokenPosition::kNoSource,
459 kernel_constructor); 441 kernel_constructor->kernel_offset());
460 } 442 }
461 } 443 }
462 444
463 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { 445 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) {
464 Procedure* kernel_procedure = kernel_klass->procedures()[i]; 446 Procedure* kernel_procedure = kernel_klass->procedures()[i];
465 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); 447 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure);
466 ReadProcedure(library, klass, kernel_procedure, kernel_klass); 448 ReadProcedure(library, klass, kernel_procedure, kernel_klass);
467 } 449 }
468 450
469 klass.SetFunctions(Array::Handle(MakeFunctionsArray())); 451 klass.SetFunctions(Array::Handle(MakeFunctionsArray()));
470 452
471 if (!klass.is_marked_for_parsing()) { 453 if (!klass.is_marked_for_parsing()) {
472 klass.set_is_marked_for_parsing(); 454 klass.set_is_marked_for_parsing();
473 } 455 }
474 456
475 if (FLAG_enable_mirrors) { 457 if (FLAG_enable_mirrors) {
476 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, 458 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource,
477 kernel_klass); 459 kernel_klass->kernel_offset());
478 } 460 }
479 461
480 return klass; 462 return klass;
481 } 463 }
482 464
483 465
484 void KernelReader::ReadProcedure(const dart::Library& library, 466 void KernelReader::ReadProcedure(const dart::Library& library,
485 const dart::Class& owner, 467 const dart::Class& owner,
486 Procedure* kernel_procedure, 468 Procedure* kernel_procedure,
487 Class* kernel_klass) { 469 Class* kernel_klass) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 ClassForScriptAt(owner, kernel_procedure->source_uri_index()); 508 ClassForScriptAt(owner, kernel_procedure->source_uri_index());
527 dart::Function& function = dart::Function::ZoneHandle( 509 dart::Function& function = dart::Function::ZoneHandle(
528 Z, Function::New(name, GetFunctionType(kernel_procedure), 510 Z, Function::New(name, GetFunctionType(kernel_procedure),
529 !is_method, // is_static 511 !is_method, // is_static
530 false, // is_const 512 false, // is_const
531 is_abstract, is_external, 513 is_abstract, is_external,
532 native_name != NULL, // is_native 514 native_name != NULL, // is_native
533 script_class, kernel_procedure->position())); 515 script_class, kernel_procedure->position()));
534 function.set_end_token_pos(kernel_procedure->end_position()); 516 function.set_end_token_pos(kernel_procedure->end_position());
535 functions_.Add(&function); 517 functions_.Add(&function);
536 function.set_kernel_function(kernel_procedure); 518 function.set_kernel_offset(kernel_procedure->kernel_offset());
537 519
538 function.set_is_debuggable( 520 function.set_is_debuggable(
539 kernel_procedure->function()->dart_async_marker() == FunctionNode::kSync); 521 kernel_procedure->function()->dart_async_marker() == FunctionNode::kSync);
540 switch (kernel_procedure->function()->dart_async_marker()) { 522 switch (kernel_procedure->function()->dart_async_marker()) {
541 case FunctionNode::kSyncStar: 523 case FunctionNode::kSyncStar:
542 function.set_modifier(RawFunction::kSyncGen); 524 function.set_modifier(RawFunction::kSyncGen);
543 break; 525 break;
544 case FunctionNode::kAsync: 526 case FunctionNode::kAsync:
545 function.set_modifier(RawFunction::kAsync); 527 function.set_modifier(RawFunction::kAsync);
546 function.set_is_inlinable(!FLAG_causal_async_stacks); 528 function.set_is_inlinable(!FLAG_causal_async_stacks);
(...skipping 18 matching lines...) Expand all
565 547
566 if (kernel_klass == NULL) { 548 if (kernel_klass == NULL) {
567 library.AddObject(function, name); 549 library.AddObject(function, name);
568 ASSERT(!Object::Handle( 550 ASSERT(!Object::Handle(
569 Z, library.LookupObjectAllowPrivate( 551 Z, library.LookupObjectAllowPrivate(
570 H.DartProcedureName(kernel_procedure->canonical_name()))) 552 H.DartProcedureName(kernel_procedure->canonical_name())))
571 .IsNull()); 553 .IsNull());
572 } 554 }
573 if (FLAG_enable_mirrors) { 555 if (FLAG_enable_mirrors) {
574 library.AddFunctionMetadata(function, TokenPosition::kNoSource, 556 library.AddFunctionMetadata(function, TokenPosition::kNoSource,
575 kernel_procedure); 557 kernel_procedure->kernel_offset());
576 } 558 }
577 } 559 }
578 560
579 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, 561 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass,
580 intptr_t source_uri_index) { 562 intptr_t source_uri_index) {
581 Script& correct_script = ScriptAt(source_uri_index); 563 Script& correct_script = ScriptAt(source_uri_index);
582 if (klass.script() != correct_script.raw()) { 564 if (klass.script() != correct_script.raw()) {
583 // TODO(jensj): We could probably cache this so we don't create 565 // TODO(jensj): We could probably cache this so we don't create
584 // new PatchClasses all the time 566 // new PatchClasses all the time
585 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); 567 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 intptr_t uri_size = program_->source_table().UriSizeFor(index); 617 intptr_t uri_size = program_->source_table().UriSizeFor(index);
636 dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld); 618 dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld);
637 dart::String& import_uri_string = 619 dart::String& import_uri_string =
638 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); 620 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld);
639 uint8_t* source_buffer = program_->source_table().SourceCodeFor(index); 621 uint8_t* source_buffer = program_->source_table().SourceCodeFor(index);
640 intptr_t source_size = program_->source_table().SourceCodeSizeFor(index); 622 intptr_t source_size = program_->source_table().SourceCodeSizeFor(index);
641 dart::String& source_code = 623 dart::String& source_code =
642 H.DartString(source_buffer, source_size, Heap::kOld); 624 H.DartString(source_buffer, source_size, Heap::kOld);
643 script = Script::New(import_uri_string, uri_string, source_code, 625 script = Script::New(import_uri_string, uri_string, source_code,
644 RawScript::kKernelTag); 626 RawScript::kKernelTag);
627 script.set_kernel_data(program_->libraries()[0]->kernel_data());
628 script.set_kernel_data_size(program_->libraries()[0]->kernel_data_size());
645 script.set_kernel_string_offsets(H.string_offsets()); 629 script.set_kernel_string_offsets(H.string_offsets());
646 script.set_kernel_string_data(H.string_data()); 630 script.set_kernel_string_data(H.string_data());
647 script.set_kernel_canonical_names(H.canonical_names()); 631 script.set_kernel_canonical_names(H.canonical_names());
648 scripts_.SetAt(index, script); 632 scripts_.SetAt(index, script);
649 633
650 // Create line_starts array for the script. 634 // Create line_starts array for the script.
651 intptr_t* line_starts = program_->source_table().LineStartsFor(index); 635 intptr_t* line_starts = program_->source_table().LineStartsFor(index);
652 intptr_t line_count = program_->source_table().LineCountFor(index); 636 intptr_t line_count = program_->source_table().LineCountFor(index);
653 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld)); 637 Array& array_object = Array::Handle(Z, Array::New(line_count, Heap::kOld));
654 Smi& value = Smi::Handle(Z); 638 Smi& value = Smi::Handle(Z);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 // non-static 706 // non-static
723 // fields that are final. 707 // fields that are final.
724 kernel_field->IsStatic() ? kernel_field->IsConst() 708 kernel_field->IsStatic() ? kernel_field->IsConst()
725 : kernel_field->IsFinal(), 709 : kernel_field->IsFinal(),
726 false, // is_abstract 710 false, // is_abstract
727 false, // is_external 711 false, // is_external
728 false, // is_native 712 false, // is_native
729 script_class, kernel_field->position())); 713 script_class, kernel_field->position()));
730 functions_.Add(&getter); 714 functions_.Add(&getter);
731 getter.set_end_token_pos(kernel_field->end_position()); 715 getter.set_end_token_pos(kernel_field->end_position());
732 getter.set_kernel_function(kernel_field); 716 getter.set_kernel_offset(kernel_field->kernel_offset());
733 getter.set_result_type(AbstractType::Handle(Z, field.type())); 717 getter.set_result_type(AbstractType::Handle(Z, field.type()));
734 getter.set_is_debuggable(false); 718 getter.set_is_debuggable(false);
735 SetupFieldAccessorFunction(klass, getter); 719 SetupFieldAccessorFunction(klass, getter);
736 720
737 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) { 721 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) {
738 // Only static fields can be const. 722 // Only static fields can be const.
739 ASSERT(!kernel_field->IsConst()); 723 ASSERT(!kernel_field->IsConst());
740 const dart::String& setter_name = 724 const dart::String& setter_name =
741 H.DartSetterName(kernel_field->canonical_name()); 725 H.DartSetterName(kernel_field->canonical_name());
742 Function& setter = Function::ZoneHandle( 726 Function& setter = Function::ZoneHandle(
743 Z, Function::New(setter_name, RawFunction::kImplicitSetter, 727 Z, Function::New(setter_name, RawFunction::kImplicitSetter,
744 false, // is_static 728 false, // is_static
745 false, // is_const 729 false, // is_const
746 false, // is_abstract 730 false, // is_abstract
747 false, // is_external 731 false, // is_external
748 false, // is_native 732 false, // is_native
749 script_class, kernel_field->position())); 733 script_class, kernel_field->position()));
750 functions_.Add(&setter); 734 functions_.Add(&setter);
751 setter.set_end_token_pos(kernel_field->end_position()); 735 setter.set_end_token_pos(kernel_field->end_position());
752 setter.set_kernel_function(kernel_field); 736 setter.set_kernel_offset(kernel_field->kernel_offset());
753 setter.set_result_type(Object::void_type()); 737 setter.set_result_type(Object::void_type());
754 setter.set_is_debuggable(false); 738 setter.set_is_debuggable(false);
755 SetupFieldAccessorFunction(klass, setter); 739 SetupFieldAccessorFunction(klass, setter);
756 } 740 }
757 } 741 }
758 742
759 743
760 void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper, 744 void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper,
761 DartTypeTranslator type_translator, 745 DartTypeTranslator type_translator,
762 const dart::Class& klass, 746 const dart::Class& klass,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 } else { 893 } else {
910 ASSERT(0 <= kind && kind <= Procedure::kFactory); 894 ASSERT(0 <= kind && kind <= Procedure::kFactory);
911 return static_cast<RawFunction::Kind>(lookuptable[kind]); 895 return static_cast<RawFunction::Kind>(lookuptable[kind]);
912 } 896 }
913 } 897 }
914 898
915 899
916 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, 900 ParsedFunction* ParseStaticFieldInitializer(Zone* zone,
917 const dart::Field& field) { 901 const dart::Field& field) {
918 Thread* thread = Thread::Current(); 902 Thread* thread = Thread::Current();
919 kernel::Field* kernel_field = kernel::Field::Cast(
920 reinterpret_cast<kernel::Node*>(field.kernel_field()));
921 903
922 dart::String& init_name = dart::String::Handle(zone, field.name()); 904 dart::String& init_name = dart::String::Handle(zone, field.name());
923 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name); 905 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name);
924 906
925 // Create a static initializer. 907 // Create a static initializer.
926 const Object& owner = Object::Handle(field.RawOwner()); 908 const Object& owner = Object::Handle(field.RawOwner());
927 const Function& initializer_fun = Function::ZoneHandle( 909 const Function& initializer_fun = Function::ZoneHandle(
928 zone, 910 zone,
929 dart::Function::New(init_name, RawFunction::kImplicitStaticFinalGetter, 911 dart::Function::New(init_name, RawFunction::kImplicitStaticFinalGetter,
930 true, // is_static 912 true, // is_static
931 false, // is_const 913 false, // is_const
932 false, // is_abstract 914 false, // is_abstract
933 false, // is_external 915 false, // is_external
934 false, // is_native 916 false, // is_native
935 owner, TokenPosition::kNoSource)); 917 owner, TokenPosition::kNoSource));
936 initializer_fun.set_kernel_function(kernel_field); 918 initializer_fun.set_kernel_offset(field.kernel_offset());
937 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); 919 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type()));
938 initializer_fun.set_is_debuggable(false); 920 initializer_fun.set_is_debuggable(false);
939 initializer_fun.set_is_reflectable(false); 921 initializer_fun.set_is_reflectable(false);
940 initializer_fun.set_is_inlinable(false); 922 initializer_fun.set_is_inlinable(false);
941 return new (zone) ParsedFunction(thread, initializer_fun); 923 return new (zone) ParsedFunction(thread, initializer_fun);
942 } 924 }
943 925
944 926
945 } // namespace kernel 927 } // namespace kernel
946 } // namespace dart 928 } // namespace dart
947 #endif // !defined(DART_PRECOMPILED_RUNTIME) 929 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_binary_flowgraph.cc ('k') | runtime/vm/kernel_to_il.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698