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

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

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