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

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

Issue 2514373002: VM: [Kernel] Cherry-pick from dart-lang/kernel_sdk (Closed)
Patch Set: Rebased Created 4 years, 1 month 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/object.cc » ('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/longjump.h" 10 #include "vm/longjump.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 Program* KernelReader::ReadPrecompiledProgram() { 96 Program* KernelReader::ReadPrecompiledProgram() {
97 Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_); 97 Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_);
98 if (program == NULL) return NULL; 98 if (program == NULL) return NULL;
99 intptr_t source_file_count = program->line_starting_table().size(); 99 intptr_t source_file_count = program->line_starting_table().size();
100 scripts_ = Array::New(source_file_count); 100 scripts_ = Array::New(source_file_count);
101 program_ = program; 101 program_ = program;
102 return program; 102 return program;
103 } 103 }
104 104
105 Object& KernelReader::ReadProgram() { 105 Object& KernelReader::ReadProgram() {
106 ASSERT(!bootstrapping_); 106 Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_);
107 Program* program = ReadPrecompiledProgram();
108 if (program == NULL) { 107 if (program == NULL) {
109 const dart::String& error = H.DartString("Failed to read .kernell file"); 108 const dart::String& error = H.DartString("Failed to read .kernell file");
110 return Object::Handle(Z, ApiError::New(error)); 109 return Object::Handle(Z, ApiError::New(error));
111 } 110 }
112 111
113 LongJumpScope jump; 112 LongJumpScope jump;
114 if (setjmp(*jump.Set()) == 0) { 113 if (setjmp(*jump.Set()) == 0) {
115 Procedure* main = program->main_method(); 114 Procedure* main = program->main_method();
116 Library* kernel_main_library = Library::Cast(main->parent()); 115 Library* kernel_main_library = Library::Cast(main->parent());
117 116
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 library.SetLoadInProgress(); 166 library.SetLoadInProgress();
168 } 167 }
169 // Setup toplevel class (which contains library fields/procedures). 168 // Setup toplevel class (which contains library fields/procedures).
170 169
171 Script& script = ScriptAt(kernel_library->source_uri_index()); 170 Script& script = ScriptAt(kernel_library->source_uri_index());
172 dart::Class& toplevel_class = dart::Class::Handle( 171 dart::Class& toplevel_class = dart::Class::Handle(
173 Z, dart::Class::New(library, Symbols::TopLevel(), script, 172 Z, dart::Class::New(library, Symbols::TopLevel(), script,
174 TokenPosition::kNoSource)); 173 TokenPosition::kNoSource));
175 toplevel_class.set_is_cycle_free(); 174 toplevel_class.set_is_cycle_free();
176 library.set_toplevel_class(toplevel_class); 175 library.set_toplevel_class(toplevel_class);
177 if (bootstrapping_) {
178 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes())
179 .Add(toplevel_class, Heap::kOld);
180 }
181 176
182 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class); 177 ActiveClassScope active_class_scope(&active_class_, NULL, &toplevel_class);
183 // Load toplevel fields. 178 // Load toplevel fields.
184 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) { 179 for (intptr_t i = 0; i < kernel_library->fields().length(); i++) {
185 Field* kernel_field = kernel_library->fields()[i]; 180 Field* kernel_field = kernel_library->fields()[i];
186 181
187 ActiveMemberScope active_member_scope(&active_class_, kernel_field); 182 ActiveMemberScope active_member_scope(&active_class_, kernel_field);
188 const dart::String& name = H.DartFieldName(kernel_field->name()); 183 const dart::String& name = H.DartFieldName(kernel_field->name());
189 const Object& script_class = 184 const Object& script_class =
190 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index()); 185 ClassForScriptAt(toplevel_class, kernel_field->source_uri_index());
(...skipping 17 matching lines...) Expand all
208 } 203 }
209 204
210 const GrowableObjectArray& classes = 205 const GrowableObjectArray& classes =
211 GrowableObjectArray::Handle(I->object_store()->pending_classes()); 206 GrowableObjectArray::Handle(I->object_store()->pending_classes());
212 207
213 // Load all classes. 208 // Load all classes.
214 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) { 209 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) {
215 Class* kernel_klass = kernel_library->classes()[i]; 210 Class* kernel_klass = kernel_library->classes()[i];
216 classes.Add(ReadClass(library, kernel_klass), Heap::kOld); 211 classes.Add(ReadClass(library, kernel_klass), Heap::kOld);
217 } 212 }
213
214 classes.Add(toplevel_class, Heap::kOld);
218 } 215 }
219 216
220 217
221 void KernelReader::ReadPreliminaryClass(dart::Class* klass, 218 void KernelReader::ReadPreliminaryClass(dart::Class* klass,
222 Class* kernel_klass) { 219 Class* kernel_klass) {
223 ASSERT(kernel_klass->IsNormalClass()); 220 ASSERT(kernel_klass->IsNormalClass());
224 NormalClass* kernel_normal_class = NormalClass::Cast(kernel_klass); 221 NormalClass* kernel_normal_class = NormalClass::Cast(kernel_klass);
225 222
226 ActiveClassScope active_class_scope(&active_class_, kernel_klass, klass); 223 ActiveClassScope active_class_scope(&active_class_, kernel_klass, klass);
227 224
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 true, // is_method 340 true, // is_method
344 false); // is_closure 341 false); // is_closure
345 } 342 }
346 343
347 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) { 344 for (intptr_t i = 0; i < kernel_klass->procedures().length(); i++) {
348 Procedure* kernel_procedure = kernel_klass->procedures()[i]; 345 Procedure* kernel_procedure = kernel_klass->procedures()[i];
349 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure); 346 ActiveMemberScope active_member_scope(&active_class_, kernel_procedure);
350 ReadProcedure(library, klass, kernel_procedure, kernel_klass); 347 ReadProcedure(library, klass, kernel_procedure, kernel_klass);
351 } 348 }
352 349
353 if (bootstrapping_ && !klass.is_marked_for_parsing()) { 350 if (!klass.is_marked_for_parsing()) {
354 klass.set_is_marked_for_parsing(); 351 klass.set_is_marked_for_parsing();
355 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes())
356 .Add(klass, Heap::kOld);
357 } 352 }
358 353
359 return klass; 354 return klass;
360 } 355 }
361 356
362 357
363 void KernelReader::ReadProcedure(const dart::Library& library, 358 void KernelReader::ReadProcedure(const dart::Library& library,
364 const dart::Class& owner, 359 const dart::Class& owner,
365 Procedure* kernel_procedure, 360 Procedure* kernel_procedure,
366 Class* kernel_klass) { 361 Class* kernel_klass) {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } else if (handle->script() == Script::null()) { 660 } else if (handle->script() == Script::null()) {
666 // When bootstrapping we can encounter classes that do not yet have a 661 // When bootstrapping we can encounter classes that do not yet have a
667 // dummy script. 662 // dummy script.
668 Script& script = ScriptAt(klass->source_uri_index()); 663 Script& script = ScriptAt(klass->source_uri_index());
669 handle->set_script(script); 664 handle->set_script(script);
670 } 665 }
671 // Insert the class in the cache before calling ReadPreliminaryClass so 666 // Insert the class in the cache before calling ReadPreliminaryClass so
672 // we do not risk allocating the class again by calling LookupClass 667 // we do not risk allocating the class again by calling LookupClass
673 // recursively from ReadPreliminaryClass for the same class. 668 // recursively from ReadPreliminaryClass for the same class.
674 classes_.Insert(klass, handle); 669 classes_.Insert(klass, handle);
675 if (!handle->is_type_finalized()) { 670 if (!handle->is_cycle_free()) {
676 ReadPreliminaryClass(handle, klass); 671 ReadPreliminaryClass(handle, klass);
677 } 672 }
678 } 673 }
679 return *handle; 674 return *handle;
680 } 675 }
681 676
682 677
683 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) { 678 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) {
684 intptr_t lookuptable[] = { 679 intptr_t lookuptable[] = {
685 RawFunction::kRegularFunction, // Procedure::kMethod 680 RawFunction::kRegularFunction, // Procedure::kMethod
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 initializer_fun.set_is_debuggable(false); 718 initializer_fun.set_is_debuggable(false);
724 initializer_fun.set_is_reflectable(false); 719 initializer_fun.set_is_reflectable(false);
725 initializer_fun.set_is_inlinable(false); 720 initializer_fun.set_is_inlinable(false);
726 return new (zone) ParsedFunction(thread, initializer_fun); 721 return new (zone) ParsedFunction(thread, initializer_fun);
727 } 722 }
728 723
729 724
730 } // namespace kernel 725 } // namespace kernel
731 } // namespace dart 726 } // namespace dart
732 #endif // !defined(DART_PRECOMPILED_RUNTIME) 727 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698