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

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

Issue 2777963002: VM [KERNEL] Fix performance issue in KernelReader (Closed)
Patch Set: VM [KERNEL] Fix performance issue in KernelReader Created 3 years, 8 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') | no next file » | 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/longjump.h" 10 #include "vm/longjump.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 dart::Zone* zone() const { return zone_; } 76 dart::Zone* zone() const { return zone_; }
77 77
78 private: 78 private:
79 TranslationHelper translation_helper_; 79 TranslationHelper translation_helper_;
80 dart::Zone* zone_; 80 dart::Zone* zone_;
81 bool is_simple_; 81 bool is_simple_;
82 dart::Instance* simple_value_; 82 dart::Instance* simple_value_;
83 }; 83 };
84 84
85 85
86 RawArray* KernelReader::MakeFunctionsArray() {
87 const intptr_t len = functions_.length();
88 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld));
89 for (intptr_t i = 0; i < len; i++) {
90 res.SetAt(i, *functions_[i]);
91 }
92 return res.raw();
93 }
94
95
86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( 96 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary(
87 CanonicalName* library) { 97 CanonicalName* library) {
88 return reader_->LookupLibrary(library).raw(); 98 return reader_->LookupLibrary(library).raw();
89 } 99 }
90 100
91 101
92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass( 102 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(
93 CanonicalName* klass) { 103 CanonicalName* klass) {
94 return reader_->LookupClass(klass).raw(); 104 return reader_->LookupClass(klass).raw();
95 } 105 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Setup toplevel class (which contains library fields/procedures). 172 // Setup toplevel class (which contains library fields/procedures).
163 173
164 Script& script = ScriptAt(kernel_library->source_uri_index(), 174 Script& script = ScriptAt(kernel_library->source_uri_index(),
165 kernel_library->import_uri()); 175 kernel_library->import_uri());
166 dart::Class& toplevel_class = dart::Class::Handle( 176 dart::Class& toplevel_class = dart::Class::Handle(
167 Z, dart::Class::New(library, Symbols::TopLevel(), script, 177 Z, dart::Class::New(library, Symbols::TopLevel(), script,
168 TokenPosition::kNoSource)); 178 TokenPosition::kNoSource));
169 toplevel_class.set_is_cycle_free(); 179 toplevel_class.set_is_cycle_free();
170 library.set_toplevel_class(toplevel_class); 180 library.set_toplevel_class(toplevel_class);
171 181
182 fields_.Clear();
183 functions_.Clear();
172 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class); 184 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class);
173 // Load toplevel fields. 185 // Load toplevel fields.
174 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) { 186 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) {
175 Field* kernel_field = kernel_library->fields()[i]; 187 Field* kernel_field = kernel_library->fields()[i];
176 188
177 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 189 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
178 const dart::String& name = H.DartFieldName(kernel_field->name()); 190 const dart::String& name = H.DartFieldName(kernel_field->name());
179 const Object& script_class = 191 const Object& script_class =
180 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index()); 192 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index());
181 dart::Field& field = dart::Field::Handle( 193 dart::Field& field = dart::Field::Handle(
182 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(), 194 Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(),
183 kernel_field->IsConst(), script_class, 195 kernel_field->IsConst(), script_class,
184 kernel_field->position())); 196 kernel_field->position()));
185 field.set_kernel_field(kernel_field); 197 field.set_kernel_field(kernel_field);
186 const AbstractType& type = T.TranslateType(kernel_field->type()); 198 const AbstractType& type = T.TranslateType(kernel_field->type());
187 field.SetFieldType(type); 199 field.SetFieldType(type);
188 field.set_has_initializer(kernel_field->initializer() != NULL); 200 field.set_has_initializer(kernel_field->initializer() != NULL);
189 GenerateFieldAccessors(toplevel_class, field, kernel_field); 201 GenerateFieldAccessors(toplevel_class, field, kernel_field);
190 toplevel_class.AddField(field); 202 fields_.Add(&field);
191 library.AddObject(field, name); 203 library.AddObject(field, name);
192 } 204 }
205 toplevel_class.AddFields(fields_);
193 206
194 // Load toplevel procedures. 207 // Load toplevel procedures.
195 for (intptr_t i = 0; i < kernel_library->procedures().length(); i++) { 208 for (intptr_t i = 0; i < kernel_library->procedures().length(); i++) {
196 Procedure* kernel_procedure = kernel_library->procedures()[i]; 209 Procedure* kernel_procedure = kernel_library->procedures()[i];
197 ReadProcedure(library, toplevel_class, kernel_procedure); 210 ReadProcedure(library, toplevel_class, kernel_procedure, NULL);
Vyacheslav Egorov (Google) 2017/03/27 18:19:09 NULL is a default value. You can remove this chang
198 } 211 }
199 212
213 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray()));
214
200 const GrowableObjectArray& classes = 215 const GrowableObjectArray& classes =
201 GrowableObjectArray::Handle(I->object_store()->pending_classes()); 216 GrowableObjectArray::Handle(I->object_store()->pending_classes());
202 217
203 // Load all classes. 218 // Load all classes.
204 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) { 219 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) {
205 Class* kernel_klass = kernel_library->classes()[i]; 220 Class* kernel_klass = kernel_library->classes()[i];
206 classes.Add(ReadClass(library, toplevel_class, kernel_klass), Heap::kOld); 221 classes.Add(ReadClass(library, toplevel_class, kernel_klass), Heap::kOld);
207 } 222 }
208 223
209 classes.Add(toplevel_class, Heap::kOld); 224 classes.Add(toplevel_class, Heap::kOld);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 klass.set_script(ScriptAt(kernel_klass->source_uri_index())); 310 klass.set_script(ScriptAt(kernel_klass->source_uri_index()));
296 } 311 }
297 if (klass.token_pos() == TokenPosition::kNoSource) { 312 if (klass.token_pos() == TokenPosition::kNoSource) {
298 klass.set_token_pos(kernel_klass->position()); 313 klass.set_token_pos(kernel_klass->position());
299 } 314 }
300 if (!klass.is_cycle_free()) { 315 if (!klass.is_cycle_free()) {
301 ReadPreliminaryClass(&klass, kernel_klass); 316 ReadPreliminaryClass(&klass, kernel_klass);
302 } 317 }
303 318
304 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); 319 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass);
320 fields_.Clear();
321 functions_.Clear();
305 322
306 if (library.raw() == dart::Library::InternalLibrary() && 323 if (library.raw() == dart::Library::InternalLibrary() &&
307 klass.Name() == Symbols::ClassID().raw()) { 324 klass.Name() == Symbols::ClassID().raw()) {
308 // If this is a dart:internal.ClassID class ignore field declarations 325 // If this is a dart:internal.ClassID class ignore field declarations
309 // contained in the Kernel file and instead inject our own const 326 // contained in the Kernel file and instead inject our own const
310 // fields. 327 // fields.
311 klass.InjectCIDFields(); 328 klass.InjectCIDFields();
312 } else { 329 } else {
313 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { 330 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) {
314 Field* kernel_field = kernel_klass->fields()[i]; 331 Field* kernel_field = kernel_klass->fields()[i];
(...skipping 10 matching lines...) Expand all
325 // In the VM all const fields are implicitly final 342 // In the VM all const fields are implicitly final
326 // whereas in Kernel they are not final because they 343 // whereas in Kernel they are not final because they
327 // are not explicitly declared that way. 344 // are not explicitly declared that way.
328 kernel_field->IsFinal() || kernel_field->IsConst(), 345 kernel_field->IsFinal() || kernel_field->IsConst(),
329 kernel_field->IsConst(), 346 kernel_field->IsConst(),
330 false, // is_reflectable 347 false, // is_reflectable
331 script_class, type, kernel_field->position())); 348 script_class, type, kernel_field->position()));
332 field.set_kernel_field(kernel_field); 349 field.set_kernel_field(kernel_field);
333 field.set_has_initializer(kernel_field->initializer() != NULL); 350 field.set_has_initializer(kernel_field->initializer() != NULL);
334 GenerateFieldAccessors(klass, field, kernel_field); 351 GenerateFieldAccessors(klass, field, kernel_field);
335 klass.AddField(field); 352 fields_.Add(&field);
336 } 353 }
354 klass.AddFields(fields_);
337 } 355 }
338 356
339 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) { 357 for (intptr_t i = 0; i < kernel_klass->constructors().length(); i++) {
340 Constructor* kernel_constructor = kernel_klass->constructors()[i]; 358 Constructor* kernel_constructor = kernel_klass->constructors()[i];
341 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor); 359 ActiveMemberScope active_member_scope(&active_class_, kernel_constructor);
342 ActiveFunctionScope active_function_scope(&active_class_, 360 ActiveFunctionScope active_function_scope(&active_class_,
343 kernel_constructor->function()); 361 kernel_constructor->function());
344 362
345 const dart::String& name = H.DartConstructorName(kernel_constructor); 363 const dart::String& name = H.DartConstructorName(kernel_constructor);
346 Function& function = dart::Function::ZoneHandle( 364 Function& function = dart::Function::ZoneHandle(
347 Z, dart::Function::New(name, RawFunction::kConstructor, 365 Z, dart::Function::New(name, RawFunction::kConstructor,
348 false, // is_static 366 false, // is_static
349 kernel_constructor->IsConst(), 367 kernel_constructor->IsConst(),
350 false, // is_abstract 368 false, // is_abstract
351 kernel_constructor->IsExternal(), 369 kernel_constructor->IsExternal(),
352 false, // is_native 370 false, // is_native
353 klass, kernel_constructor->position())); 371 klass, kernel_constructor->position()));
354 function.set_end_token_pos(kernel_constructor->end_position()); 372 function.set_end_token_pos(kernel_constructor->end_position());
355 klass.AddFunction(function); 373 functions_.Add(&function);
356 function.set_kernel_function(kernel_constructor); 374 function.set_kernel_function(kernel_constructor);
357 function.set_result_type(T.ReceiverType(klass)); 375 function.set_result_type(T.ReceiverType(klass));
358 SetupFunctionParameters(H, T, klass, function, 376 SetupFunctionParameters(H, T, klass, function,
359 kernel_constructor->function(), 377 kernel_constructor->function(),
360 true, // is_method 378 true, // is_method
361 false); // is_closure 379 false); // is_closure
362 380
363 if (FLAG_enable_mirrors) { 381 if (FLAG_enable_mirrors) {
364 library.AddFunctionMetadata(function, TokenPosition::kNoSource, 382 library.AddFunctionMetadata(function, TokenPosition::kNoSource,
365 kernel_constructor); 383 kernel_constructor);
366 } 384 }
367 } 385 }
368 386
369 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { 387 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) {
370 Procedure* kernel_procedure = kernel_klass->procedures()[i]; 388 Procedure* kernel_procedure = kernel_klass->procedures()[i];
371 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); 389 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure);
372 ReadProcedure(library, klass, kernel_procedure, kernel_klass); 390 ReadProcedure(library, klass, kernel_procedure, kernel_klass);
373 } 391 }
374 392
393 klass.SetFunctions(Array::Handle(MakeFunctionsArray()));
394
375 if (!klass.is_marked_for_parsing()) { 395 if (!klass.is_marked_for_parsing()) {
376 klass.set_is_marked_for_parsing(); 396 klass.set_is_marked_for_parsing();
377 } 397 }
378 398
379 if (FLAG_enable_mirrors) { 399 if (FLAG_enable_mirrors) {
380 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, 400 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource,
381 kernel_klass); 401 kernel_klass);
382 } 402 }
383 403
384 return klass; 404 return klass;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 const Object& script_class = 453 const Object& script_class =
434 ClassForScriptAt(owner, kernel_procedure->source_uri_index()); 454 ClassForScriptAt(owner, kernel_procedure->source_uri_index());
435 dart::Function& function = dart::Function::ZoneHandle( 455 dart::Function& function = dart::Function::ZoneHandle(
436 Z, Function::New(name, GetFunctionType(kernel_procedure), 456 Z, Function::New(name, GetFunctionType(kernel_procedure),
437 !is_method, // is_static 457 !is_method, // is_static
438 false, // is_const 458 false, // is_const
439 is_abstract, is_external, 459 is_abstract, is_external,
440 native_name != NULL, // is_native 460 native_name != NULL, // is_native
441 script_class, kernel_procedure->position())); 461 script_class, kernel_procedure->position()));
442 function.set_end_token_pos(kernel_procedure->end_position()); 462 function.set_end_token_pos(kernel_procedure->end_position());
443 owner.AddFunction(function); 463 functions_.Add(&function);
444 function.set_kernel_function(kernel_procedure); 464 function.set_kernel_function(kernel_procedure);
445 465
446 function.set_is_debuggable( 466 function.set_is_debuggable(
447 kernel_procedure->function()->dart_async_marker() == FunctionNode::kSync); 467 kernel_procedure->function()->dart_async_marker() == FunctionNode::kSync);
448 switch (kernel_procedure->function()->dart_async_marker()) { 468 switch (kernel_procedure->function()->dart_async_marker()) {
449 case FunctionNode::kSyncStar: 469 case FunctionNode::kSyncStar:
450 function.set_modifier(RawFunction::kSyncGen); 470 function.set_modifier(RawFunction::kSyncGen);
451 break; 471 break;
452 case FunctionNode::kAsync: 472 case FunctionNode::kAsync:
453 function.set_modifier(RawFunction::kAsync); 473 function.set_modifier(RawFunction::kAsync);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 // The functions created by the parser have is_const for static fields 642 // The functions created by the parser have is_const for static fields
623 // that are const (not just final) and they have is_const for 643 // that are const (not just final) and they have is_const for
624 // non-static 644 // non-static
625 // fields that are final. 645 // fields that are final.
626 kernel_field->IsStatic() ? kernel_field->IsConst() 646 kernel_field->IsStatic() ? kernel_field->IsConst()
627 : kernel_field->IsFinal(), 647 : kernel_field->IsFinal(),
628 false, // is_abstract 648 false, // is_abstract
629 false, // is_external 649 false, // is_external
630 false, // is_native 650 false, // is_native
631 script_class, kernel_field->position())); 651 script_class, kernel_field->position()));
632 klass.AddFunction(getter); 652 functions_.Add(&getter);
633 getter.set_end_token_pos(kernel_field->end_position()); 653 getter.set_end_token_pos(kernel_field->end_position());
634 getter.set_kernel_function(kernel_field); 654 getter.set_kernel_function(kernel_field);
635 getter.set_result_type(AbstractType::Handle(Z, field.type())); 655 getter.set_result_type(AbstractType::Handle(Z, field.type()));
636 getter.set_is_debuggable(false); 656 getter.set_is_debuggable(false);
637 SetupFieldAccessorFunction(klass, getter); 657 SetupFieldAccessorFunction(klass, getter);
638 658
639 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) { 659 if (!kernel_field->IsStatic() && !kernel_field->IsFinal()) {
640 // Only static fields can be const. 660 // Only static fields can be const.
641 ASSERT(!kernel_field->IsConst()); 661 ASSERT(!kernel_field->IsConst());
642 const dart::String& setter_name = H.DartSetterName(kernel_field->name()); 662 const dart::String& setter_name = H.DartSetterName(kernel_field->name());
643 Function& setter = Function::ZoneHandle( 663 Function& setter = Function::ZoneHandle(
644 Z, Function::New(setter_name, RawFunction::kImplicitSetter, 664 Z, Function::New(setter_name, RawFunction::kImplicitSetter,
645 false, // is_static 665 false, // is_static
646 false, // is_const 666 false, // is_const
647 false, // is_abstract 667 false, // is_abstract
648 false, // is_external 668 false, // is_external
649 false, // is_native 669 false, // is_native
650 script_class, kernel_field->position())); 670 script_class, kernel_field->position()));
651 klass.AddFunction(setter); 671 functions_.Add(&setter);
652 setter.set_end_token_pos(kernel_field->end_position()); 672 setter.set_end_token_pos(kernel_field->end_position());
653 setter.set_kernel_function(kernel_field); 673 setter.set_kernel_function(kernel_field);
654 setter.set_result_type(Object::void_type()); 674 setter.set_result_type(Object::void_type());
655 setter.set_is_debuggable(false); 675 setter.set_is_debuggable(false);
656 SetupFieldAccessorFunction(klass, setter); 676 SetupFieldAccessorFunction(klass, setter);
657 } 677 }
658 } 678 }
659 679
660 680
661 void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper, 681 void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 initializer_fun.set_is_debuggable(false); 859 initializer_fun.set_is_debuggable(false);
840 initializer_fun.set_is_reflectable(false); 860 initializer_fun.set_is_reflectable(false);
841 initializer_fun.set_is_inlinable(false); 861 initializer_fun.set_is_inlinable(false);
842 return new (zone) ParsedFunction(thread, initializer_fun); 862 return new (zone) ParsedFunction(thread, initializer_fun);
843 } 863 }
844 864
845 865
846 } // namespace kernel 866 } // namespace kernel
847 } // namespace dart 867 } // namespace dart
848 #endif // !defined(DART_PRECOMPILED_RUNTIME) 868 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698