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

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

Issue 2972343002: [kernel] Insert kernel bodies into VM heap (Closed)
Patch Set: Review comments Created 3 years, 4 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_to_il.h ('k') | runtime/vm/object.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 <set> 5 #include <set>
6 6
7 #include "vm/kernel_to_il.h" 7 #include "vm/kernel_to_il.h"
8 8
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/intermediate_language.h" 10 #include "vm/intermediate_language.h"
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 try_catch_block_(NULL), 627 try_catch_block_(NULL),
628 next_used_try_index_(0), 628 next_used_try_index_(0),
629 catch_block_(NULL), 629 catch_block_(NULL),
630 streaming_flow_graph_builder_(NULL) { 630 streaming_flow_graph_builder_(NULL) {
631 Script& script = Script::Handle(Z, parsed_function->function().script()); 631 Script& script = Script::Handle(Z, parsed_function->function().script());
632 H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); 632 H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
633 H.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); 633 H.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
634 H.SetCanonicalNames(TypedData::Handle(Z, script.kernel_canonical_names())); 634 H.SetCanonicalNames(TypedData::Handle(Z, script.kernel_canonical_names()));
635 } 635 }
636 636
637 FlowGraphBuilder::~FlowGraphBuilder() { 637 FlowGraphBuilder::~FlowGraphBuilder() {}
638 if (streaming_flow_graph_builder_ != NULL) {
639 delete streaming_flow_graph_builder_;
640 }
641 }
642 638
643 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( 639 Fragment FlowGraphBuilder::TranslateFinallyFinalizers(
644 TryFinallyBlock* outer_finally, 640 TryFinallyBlock* outer_finally,
645 intptr_t target_context_depth) { 641 intptr_t target_context_depth) {
646 TryFinallyBlock* const saved_block = try_finally_block_; 642 TryFinallyBlock* const saved_block = try_finally_block_;
647 TryCatchBlock* const saved_try_catch_block = try_catch_block_; 643 TryCatchBlock* const saved_try_catch_block = try_catch_block_;
648 const intptr_t saved_depth = context_depth_; 644 const intptr_t saved_depth = context_depth_;
649 const intptr_t saved_try_depth = try_depth_; 645 const intptr_t saved_try_depth = try_depth_;
650 646
651 Fragment instructions; 647 Fragment instructions;
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 parsed_function_->function().set_is_inlinable(false); 1639 parsed_function_->function().set_is_inlinable(false);
1644 parsed_function_->Bailout("kernel::FlowGraphBuilder", reason); 1640 parsed_function_->Bailout("kernel::FlowGraphBuilder", reason);
1645 } 1641 }
1646 } 1642 }
1647 1643
1648 FlowGraph* FlowGraphBuilder::BuildGraph() { 1644 FlowGraph* FlowGraphBuilder::BuildGraph() {
1649 const Function& function = parsed_function_->function(); 1645 const Function& function = parsed_function_->function();
1650 1646
1651 if (function.IsConstructorClosureFunction()) return NULL; 1647 if (function.IsConstructorClosureFunction()) return NULL;
1652 1648
1653 if (streaming_flow_graph_builder_ != NULL) { 1649 StreamingFlowGraphBuilder streaming_flow_graph_builder(
1654 delete streaming_flow_graph_builder_; 1650 this, function.kernel_offset(),
1655 streaming_flow_graph_builder_ = NULL; 1651 TypedData::Handle(Z, function.kernel_data()));
1656 } 1652 streaming_flow_graph_builder_ = &streaming_flow_graph_builder;
1657 1653 FlowGraph* result = streaming_flow_graph_builder_->BuildGraph(0);
1658 Script& script = Script::Handle(Z, function.script()); 1654 streaming_flow_graph_builder_ = NULL;
1659 streaming_flow_graph_builder_ = new StreamingFlowGraphBuilder( 1655 return result;
1660 this, script.kernel_data(), script.kernel_data_size());
1661
1662 return streaming_flow_graph_builder_->BuildGraph(kernel_offset_);
1663 } 1656 }
1664 1657
1665 Fragment FlowGraphBuilder::NativeFunctionBody(intptr_t first_positional_offset, 1658 Fragment FlowGraphBuilder::NativeFunctionBody(intptr_t first_positional_offset,
1666 const Function& function) { 1659 const Function& function) {
1667 ASSERT(function.is_native()); 1660 ASSERT(function.is_native());
1668 // We explicitly build the graph for native functions in the same way that the 1661 // We explicitly build the graph for native functions in the same way that the
1669 // from-source backend does. We should find a way to have a single component 1662 // from-source backend does. We should find a way to have a single component
1670 // to build these graphs so that this code is not duplicated. 1663 // to build these graphs so that this code is not duplicated.
1671 1664
1672 Fragment body; 1665 Fragment body;
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 Zone* zone_ = thread->zone(); 2234 Zone* zone_ = thread->zone();
2242 TranslationHelper helper(thread); 2235 TranslationHelper helper(thread);
2243 Script& script = Script::Handle(Z, metadata_field.Script()); 2236 Script& script = Script::Handle(Z, metadata_field.Script());
2244 helper.SetStringOffsets( 2237 helper.SetStringOffsets(
2245 TypedData::Handle(Z, script.kernel_string_offsets())); 2238 TypedData::Handle(Z, script.kernel_string_offsets()));
2246 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); 2239 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
2247 helper.SetCanonicalNames( 2240 helper.SetCanonicalNames(
2248 TypedData::Handle(Z, script.kernel_canonical_names())); 2241 TypedData::Handle(Z, script.kernel_canonical_names()));
2249 2242
2250 StreamingFlowGraphBuilder streaming_flow_graph_builder( 2243 StreamingFlowGraphBuilder streaming_flow_graph_builder(
2251 &helper, zone_, script.kernel_data(), script.kernel_data_size()); 2244 &helper, zone_, metadata_field.kernel_offset(),
2252 return streaming_flow_graph_builder.EvaluateMetadata( 2245 TypedData::Handle(Z, metadata_field.kernel_data()));
2253 metadata_field.kernel_offset()); 2246 return streaming_flow_graph_builder.EvaluateMetadata(0);
2254 } else { 2247 } else {
2255 Thread* thread = Thread::Current(); 2248 Thread* thread = Thread::Current();
2256 Error& error = Error::Handle(); 2249 Error& error = Error::Handle();
2257 error = thread->sticky_error(); 2250 error = thread->sticky_error();
2258 thread->clear_sticky_error(); 2251 thread->clear_sticky_error();
2259 return error.raw(); 2252 return error.raw();
2260 } 2253 }
2261 } 2254 }
2262 2255
2263 RawObject* BuildParameterDescriptor(const Function& function) { 2256 RawObject* BuildParameterDescriptor(const Function& function) {
2264 LongJumpScope jump; 2257 LongJumpScope jump;
2265 if (setjmp(*jump.Set()) == 0) { 2258 if (setjmp(*jump.Set()) == 0) {
2266 Thread* thread = Thread::Current(); 2259 Thread* thread = Thread::Current();
2267 Zone* zone_ = thread->zone(); 2260 Zone* zone_ = thread->zone();
2268 TranslationHelper helper(thread); 2261 TranslationHelper helper(thread);
2269 Script& script = Script::Handle(Z, function.script()); 2262 Script& script = Script::Handle(Z, function.script());
2270 helper.SetStringOffsets( 2263 helper.SetStringOffsets(
2271 TypedData::Handle(Z, script.kernel_string_offsets())); 2264 TypedData::Handle(Z, script.kernel_string_offsets()));
2272 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); 2265 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
2273 helper.SetCanonicalNames( 2266 helper.SetCanonicalNames(
2274 TypedData::Handle(Z, script.kernel_canonical_names())); 2267 TypedData::Handle(Z, script.kernel_canonical_names()));
2275 2268
2276 StreamingFlowGraphBuilder streaming_flow_graph_builder( 2269 StreamingFlowGraphBuilder streaming_flow_graph_builder(
2277 &helper, zone_, script.kernel_data(), script.kernel_data_size()); 2270 &helper, zone_, function.kernel_offset(),
2278 return streaming_flow_graph_builder.BuildParameterDescriptor( 2271 TypedData::Handle(Z, function.kernel_data()));
2279 function.kernel_offset()); 2272 return streaming_flow_graph_builder.BuildParameterDescriptor(0);
2280 } else { 2273 } else {
2281 Thread* thread = Thread::Current(); 2274 Thread* thread = Thread::Current();
2282 Error& error = Error::Handle(); 2275 Error& error = Error::Handle();
2283 error = thread->sticky_error(); 2276 error = thread->sticky_error();
2284 thread->clear_sticky_error(); 2277 thread->clear_sticky_error();
2285 return error.raw(); 2278 return error.raw();
2286 } 2279 }
2287 } 2280 }
2288 2281
2289 static int LowestFirst(const intptr_t* a, const intptr_t* b) { 2282 static int LowestFirst(const intptr_t* a, const intptr_t* b) {
(...skipping 25 matching lines...) Expand all
2315 Array& array_object = Array::Handle(); 2308 Array& array_object = Array::Handle();
2316 array_object = Array::New(last + 1, Heap::kOld); 2309 array_object = Array::New(last + 1, Heap::kOld);
2317 Smi& smi_value = Smi::Handle(); 2310 Smi& smi_value = Smi::Handle();
2318 for (intptr_t i = 0; i <= last; ++i) { 2311 for (intptr_t i = 0; i <= last; ++i) {
2319 smi_value = Smi::New(source->At(i)); 2312 smi_value = Smi::New(source->At(i));
2320 array_object.SetAt(i, smi_value); 2313 array_object.SetAt(i, smi_value);
2321 } 2314 }
2322 return array_object.raw(); 2315 return array_object.raw();
2323 } 2316 }
2324 2317
2318 void ProcessTokenPositionsEntry(const TypedData& data,
2319 const Script& script,
2320 const Script& entry_script,
2321 intptr_t kernel_offset,
2322 Zone* zone_,
2323 TranslationHelper* helper,
2324 GrowableArray<intptr_t>* token_positions,
2325 GrowableArray<intptr_t>* yield_positions) {
2326 if (data.IsNull() ||
2327 script.kernel_string_offsets() != entry_script.kernel_string_offsets()) {
2328 return;
2329 }
2330
2331 StreamingFlowGraphBuilder streaming_flow_graph_builder(helper, zone_,
2332 kernel_offset, data);
2333 streaming_flow_graph_builder.CollectTokenPositionsFor(
2334 script.kernel_script_index(), entry_script.kernel_script_index(),
2335 token_positions, yield_positions);
2336 }
2337
2325 void CollectTokenPositionsFor(const Script& const_script) { 2338 void CollectTokenPositionsFor(const Script& const_script) {
2326 Thread* thread = Thread::Current(); 2339 Thread* thread = Thread::Current();
2327 Zone* zone_ = thread->zone(); 2340 Zone* zone_ = thread->zone();
2328 Script& script = Script::Handle(Z, const_script.raw()); 2341 Script& script = Script::Handle(Z, const_script.raw());
2329 TranslationHelper helper(thread); 2342 TranslationHelper helper(thread);
2330 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); 2343 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
2331 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); 2344 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
2332 helper.SetCanonicalNames( 2345 helper.SetCanonicalNames(
2333 TypedData::Handle(Z, script.kernel_canonical_names())); 2346 TypedData::Handle(Z, script.kernel_canonical_names()));
2334 2347
2335 GrowableArray<intptr_t> token_positions(10); 2348 GrowableArray<intptr_t> token_positions(10);
2336 GrowableArray<intptr_t> yield_positions(1); 2349 GrowableArray<intptr_t> yield_positions(1);
2337 StreamingFlowGraphBuilder streaming_flow_graph_builder( 2350
2338 &helper, zone_, script.kernel_data(), script.kernel_data_size()); 2351 Isolate* isolate = thread->isolate();
2339 streaming_flow_graph_builder.CollectTokenPositionsFor( 2352 const GrowableObjectArray& libs =
2340 script.kernel_script_index(), &token_positions, &yield_positions); 2353 GrowableObjectArray::Handle(Z, isolate->object_store()->libraries());
2354 Library& lib = Library::Handle(Z);
2355 Object& entry = Object::Handle();
2356 Script& entry_script = Script::Handle(Z);
2357 TypedData& data = TypedData::Handle(Z);
2358 for (intptr_t i = 0; i < libs.Length(); i++) {
2359 lib ^= libs.At(i);
2360 DictionaryIterator it(lib);
2361 while (it.HasNext()) {
2362 entry = it.GetNext();
2363 data = TypedData::null();
2364 if (entry.IsClass()) {
2365 const Class& klass = Class::Cast(entry);
2366 entry_script = klass.script();
2367 if (!entry_script.IsNull() && script.kernel_script_index() ==
2368 entry_script.kernel_script_index()) {
2369 token_positions.Add(klass.token_pos().value());
2370 }
2371 Array& array = Array::Handle(zone_, klass.fields());
2372 dart::Field& field = dart::Field::Handle(Z);
2373 for (intptr_t i = 0; i < array.Length(); ++i) {
2374 field ^= array.At(i);
2375 data = field.kernel_data();
2376 entry_script = field.Script();
2377 ProcessTokenPositionsEntry(data, script, entry_script,
2378 field.kernel_offset(), zone_, &helper,
2379 &token_positions, &yield_positions);
2380 }
2381 array = klass.functions();
2382 Function& function = Function::Handle(Z);
2383 for (intptr_t i = 0; i < array.Length(); ++i) {
2384 function ^= array.At(i);
2385 data = function.kernel_data();
2386 entry_script = function.script();
2387 ProcessTokenPositionsEntry(data, script, entry_script,
2388 function.kernel_offset(), zone_, &helper,
2389 &token_positions, &yield_positions);
2390 }
2391 } else if (entry.IsFunction()) {
2392 const Function& function = Function::Cast(entry);
2393 data = function.kernel_data();
2394 entry_script = function.script();
2395 ProcessTokenPositionsEntry(data, script, entry_script,
2396 function.kernel_offset(), zone_, &helper,
2397 &token_positions, &yield_positions);
2398 } else if (entry.IsField()) {
2399 const dart::Field& field = dart::Field::Cast(entry);
2400 data = field.kernel_data();
2401 entry_script = field.Script();
2402 ProcessTokenPositionsEntry(data, script, entry_script,
2403 field.kernel_offset(), zone_, &helper,
2404 &token_positions, &yield_positions);
2405 }
2406 }
2407 }
2408
2341 Array& array_object = Array::Handle(Z); 2409 Array& array_object = Array::Handle(Z);
2342 array_object = AsSortedDuplicateFreeArray(&token_positions); 2410 array_object = AsSortedDuplicateFreeArray(&token_positions);
2343 script.set_debug_positions(array_object); 2411 script.set_debug_positions(array_object);
2344 array_object = AsSortedDuplicateFreeArray(&yield_positions); 2412 array_object = AsSortedDuplicateFreeArray(&yield_positions);
2345 script.set_yield_positions(array_object); 2413 script.set_yield_positions(array_object);
2346 } 2414 }
2347 2415
2348 String& GetSourceFor(const Script& const_script) {
2349 Thread* thread = Thread::Current();
2350 Zone* zone_ = thread->zone();
2351 Script& script = Script::Handle(Z, const_script.raw());
2352 TranslationHelper helper(thread);
2353 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
2354 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
2355 helper.SetCanonicalNames(
2356 TypedData::Handle(Z, script.kernel_canonical_names()));
2357
2358 StreamingFlowGraphBuilder streaming_flow_graph_builder(
2359 &helper, zone_, script.kernel_data(), script.kernel_data_size());
2360 return streaming_flow_graph_builder.GetSourceFor(
2361 script.kernel_script_index());
2362 }
2363
2364 Array& GetLineStartsFor(const Script& const_script) {
2365 Thread* thread = Thread::Current();
2366 Zone* zone_ = thread->zone();
2367 Script& script = Script::Handle(Z, const_script.raw());
2368 TranslationHelper helper(thread);
2369 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
2370 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
2371 helper.SetCanonicalNames(
2372 TypedData::Handle(Z, script.kernel_canonical_names()));
2373
2374 StreamingFlowGraphBuilder streaming_flow_graph_builder(
2375 &helper, zone_, script.kernel_data(), script.kernel_data_size());
2376 return streaming_flow_graph_builder.GetLineStartsFor(
2377 script.kernel_script_index());
2378 }
2379
2380 } // namespace kernel 2416 } // namespace kernel
2381 } // namespace dart 2417 } // namespace dart
2382 2418
2383 #endif // !defined(DART_PRECOMPILED_RUNTIME) 2419 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698