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

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

Issue 22184003: Fix a bug in compilation of try-finally. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_builder.h ('k') | runtime/vm/il_printer.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/bit_vector.h" 9 #include "vm/bit_vector.h"
10 #include "vm/code_descriptors.h" 10 #include "vm/code_descriptors.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ic_data_array_(ic_data_array), 50 ic_data_array_(ic_data_array),
51 num_copied_params_(parsed_function->num_copied_params()), 51 num_copied_params_(parsed_function->num_copied_params()),
52 // All parameters are copied if any parameter is. 52 // All parameters are copied if any parameter is.
53 num_non_copied_params_((num_copied_params_ == 0) 53 num_non_copied_params_((num_copied_params_ == 0)
54 ? parsed_function->function().num_fixed_parameters() 54 ? parsed_function->function().num_fixed_parameters()
55 : 0), 55 : 0),
56 num_stack_locals_(parsed_function->num_stack_locals()), 56 num_stack_locals_(parsed_function->num_stack_locals()),
57 exit_collector_(exit_collector), 57 exit_collector_(exit_collector),
58 last_used_block_id_(0), // 0 is used for the graph entry. 58 last_used_block_id_(0), // 0 is used for the graph entry.
59 context_level_(0), 59 context_level_(0),
60 last_used_try_index_(CatchClauseNode::kInvalidTryIndex),
61 try_index_(CatchClauseNode::kInvalidTryIndex), 60 try_index_(CatchClauseNode::kInvalidTryIndex),
62 loop_depth_(0), 61 loop_depth_(0),
63 graph_entry_(NULL), 62 graph_entry_(NULL),
64 args_pushed_(0), 63 args_pushed_(0),
65 osr_id_(osr_id) { } 64 osr_id_(osr_id) { }
66 65
67 66
68 void FlowGraphBuilder::AddCatchEntry(CatchBlockEntryInstr* entry) { 67 void FlowGraphBuilder::AddCatchEntry(CatchBlockEntryInstr* entry) {
69 graph_entry_->AddCatchEntry(entry); 68 graph_entry_->AddCatchEntry(entry);
70 } 69 }
(...skipping 3237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3308 3307
3309 EffectGraphVisitor for_catch(owner(), temp_index()); 3308 EffectGraphVisitor for_catch(owner(), temp_index());
3310 node->VisitChildren(&for_catch); 3309 node->VisitChildren(&for_catch);
3311 Append(for_catch); 3310 Append(for_catch);
3312 } 3311 }
3313 3312
3314 3313
3315 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) { 3314 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) {
3316 InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)"); 3315 InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)");
3317 intptr_t original_handler_index = owner()->try_index(); 3316 intptr_t original_handler_index = owner()->try_index();
3318 intptr_t try_handler_index = owner()->AllocateTryIndex(); 3317 intptr_t try_handler_index = node->try_index();
3318 ASSERT(try_handler_index != original_handler_index);
3319 owner()->set_try_index(try_handler_index); 3319 owner()->set_try_index(try_handler_index);
3320 3320
3321 // Preserve CTX into local variable '%saved_context'. 3321 // Preserve CTX into local variable '%saved_context'.
3322 BuildSaveContext(node->context_var()); 3322 BuildSaveContext(node->context_var());
3323 3323
3324 EffectGraphVisitor for_try(owner(), temp_index()); 3324 EffectGraphVisitor for_try(owner(), temp_index());
3325 node->try_block()->Visit(&for_try); 3325 node->try_block()->Visit(&for_try);
3326 3326
3327 if (for_try.is_open()) { 3327 if (for_try.is_open()) {
3328 JoinEntryInstr* after_try = 3328 JoinEntryInstr* after_try =
(...skipping 12 matching lines...) Expand all
3341 // We are done generating code for the try block. 3341 // We are done generating code for the try block.
3342 owner()->set_try_index(original_handler_index); 3342 owner()->set_try_index(original_handler_index);
3343 3343
3344 CatchClauseNode* catch_block = node->catch_block(); 3344 CatchClauseNode* catch_block = node->catch_block();
3345 SequenceNode* finally_block = node->finally_block(); 3345 SequenceNode* finally_block = node->finally_block();
3346 if (catch_block != NULL) { 3346 if (catch_block != NULL) {
3347 // If there is a finally block, it is the handler for code in the catch 3347 // If there is a finally block, it is the handler for code in the catch
3348 // block. 3348 // block.
3349 intptr_t catch_handler_index = (finally_block == NULL) 3349 intptr_t catch_handler_index = (finally_block == NULL)
3350 ? original_handler_index 3350 ? original_handler_index
3351 : owner()->AllocateTryIndex(); 3351 : catch_block->catch_handler_index();
3352
3352 owner()->set_try_index(catch_handler_index); 3353 owner()->set_try_index(catch_handler_index);
3353 EffectGraphVisitor for_catch(owner(), temp_index()); 3354 EffectGraphVisitor for_catch(owner(), temp_index());
3354 catch_block->Visit(&for_catch); 3355 catch_block->Visit(&for_catch);
3355 CatchBlockEntryInstr* catch_entry = 3356 CatchBlockEntryInstr* catch_entry =
3356 new CatchBlockEntryInstr(owner()->AllocateBlockId(), 3357 new CatchBlockEntryInstr(owner()->AllocateBlockId(),
3357 catch_handler_index, 3358 catch_handler_index,
3358 catch_block->handler_types(), 3359 catch_block->handler_types(),
3359 try_handler_index); 3360 try_handler_index);
3360 owner()->AddCatchEntry(catch_entry); 3361 owner()->AddCatchEntry(catch_entry);
3361 ASSERT(!for_catch.is_open()); 3362 ASSERT(!for_catch.is_open());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3396 types.SetAt(0, Type::Handle(Type::DynamicType())); 3397 types.SetAt(0, Type::Handle(Type::DynamicType()));
3397 CatchBlockEntryInstr* finally_entry = 3398 CatchBlockEntryInstr* finally_entry =
3398 new CatchBlockEntryInstr(owner()->AllocateBlockId(), 3399 new CatchBlockEntryInstr(owner()->AllocateBlockId(),
3399 original_handler_index, 3400 original_handler_index,
3400 types, 3401 types,
3401 catch_handler_index); 3402 catch_handler_index);
3402 owner()->AddCatchEntry(finally_entry); 3403 owner()->AddCatchEntry(finally_entry);
3403 AppendFragment(finally_entry, for_finally); 3404 AppendFragment(finally_entry, for_finally);
3404 } 3405 }
3405 } 3406 }
3406
3407 // Generate code for the finally block if one exists. 3407 // Generate code for the finally block if one exists.
3408 if ((finally_block != NULL) && is_open()) { 3408 if ((finally_block != NULL) && is_open()) {
3409 EffectGraphVisitor for_finally_block(owner(), temp_index()); 3409 EffectGraphVisitor for_finally_block(owner(), temp_index());
3410 finally_block->Visit(&for_finally_block); 3410 finally_block->Visit(&for_finally_block);
3411 Append(for_finally_block); 3411 Append(for_finally_block);
3412 } 3412 }
3413 } 3413 }
3414 3414
3415 3415
3416 // Looks up dynamic method noSuchMethod in target_class 3416 // Looks up dynamic method noSuchMethod in target_class
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3537 } 3537 }
3538 3538
3539 3539
3540 void EffectGraphVisitor::VisitInlinedFinallyNode(InlinedFinallyNode* node) { 3540 void EffectGraphVisitor::VisitInlinedFinallyNode(InlinedFinallyNode* node) {
3541 InlineBailout("EffectGraphVisitor::VisitInlinedFinallyNode (exception)"); 3541 InlineBailout("EffectGraphVisitor::VisitInlinedFinallyNode (exception)");
3542 const intptr_t try_index = owner()->try_index(); 3542 const intptr_t try_index = owner()->try_index();
3543 if (try_index >= 0) { 3543 if (try_index >= 0) {
3544 // We are about to generate code for an inlined finally block. Exceptions 3544 // We are about to generate code for an inlined finally block. Exceptions
3545 // thrown in this block of code should be treated as though they are 3545 // thrown in this block of code should be treated as though they are
3546 // thrown not from the current try block but the outer try block if any. 3546 // thrown not from the current try block but the outer try block if any.
3547 owner()->set_try_index((try_index - 1)); 3547 intptr_t outer_try_index = node->try_index();
3548 owner()->set_try_index(outer_try_index);
3548 } 3549 }
3549 BuildRestoreContext(node->context_var()); 3550 BuildRestoreContext(node->context_var());
3550 3551
3551 JoinEntryInstr* finally_entry = 3552 JoinEntryInstr* finally_entry =
3552 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index()); 3553 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index());
3553 EffectGraphVisitor for_finally_block(owner(), temp_index()); 3554 EffectGraphVisitor for_finally_block(owner(), temp_index());
3554 node->finally_block()->Visit(&for_finally_block); 3555 node->finally_block()->Visit(&for_finally_block);
3555 3556
3556 if (try_index >= 0) { 3557 if (try_index >= 0) {
3557 owner()->set_try_index(try_index); 3558 owner()->set_try_index(try_index);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3622 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; 3623 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
3623 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 3624 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
3624 OS::SNPrint(chars, len, kFormat, function_name, reason); 3625 OS::SNPrint(chars, len, kFormat, function_name, reason);
3625 const Error& error = Error::Handle( 3626 const Error& error = Error::Handle(
3626 LanguageError::New(String::Handle(String::New(chars)))); 3627 LanguageError::New(String::Handle(String::New(chars))));
3627 Isolate::Current()->long_jump_base()->Jump(1, error); 3628 Isolate::Current()->long_jump_base()->Jump(1, error);
3628 } 3629 }
3629 3630
3630 3631
3631 } // namespace dart 3632 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.h ('k') | runtime/vm/il_printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698