@@ -142,7 +142,7 @@ public abstract class IRScope implements ParseResult {
142
142
143
143
// What state is this scope in?
144
144
enum ScopeState {
145
- INIT , INSTRS_CLONED , CFG_BUILT
145
+ INIT , INTERPED , INSTRS_CLONED , CFG_BUILT
146
146
};
147
147
148
148
private ScopeState state = ScopeState .INIT ;
@@ -455,6 +455,13 @@ public CFG buildCFG() {
455
455
return getCFG ();
456
456
}
457
457
458
+ // If the scope has already been interpreted once,
459
+ // the scope can be on the call stack right now.
460
+ // So, clone instructions before building the CFG.
461
+ if (this .state == ScopeState .INTERPED ) {
462
+ this .cloneInstrs ();
463
+ }
464
+
458
465
CFG newCFG = new CFG (this );
459
466
newCFG .build (getInstrs ());
460
467
// Clear out instruction list after CFG has been built.
@@ -637,7 +644,7 @@ public InterpreterContext prepareForInterpretation() {
637
644
}
638
645
639
646
protected void cloneInstrs () {
640
- if (this . state == ScopeState . INIT ) {
647
+ if (getCFG () == null ) {
641
648
// Clone instrs before modifying them
642
649
SimpleCloneInfo cloneInfo = new SimpleCloneInfo (this , false );
643
650
List <Instr > newInstrList = new ArrayList <Instr >(this .instrList .size ());
@@ -647,20 +654,22 @@ protected void cloneInstrs() {
647
654
this .instrList = newInstrList ;
648
655
this .state = ScopeState .INSTRS_CLONED ;
649
656
}
657
+ for (IRClosure cl : getClosures ()) {
658
+ cl .cloneInstrs ();
659
+ }
650
660
}
651
661
652
662
/** Run any necessary passes to get the IR ready for interpretation */
653
663
public synchronized InterpreterContext prepareForInterpretation (boolean rebuild ) {
654
- if (interpreterContext != null ) {
664
+ if (interpreterContext == null ) {
665
+ this .state = ScopeState .INTERPED ;
666
+ } else {
655
667
if (!rebuild || getCFG () != null ) {
656
668
return interpreterContext ; // Already prepared/rebuilt
657
669
}
658
670
659
671
// If rebuilding, clone instrs before building cfg, running passes, etc.
660
672
this .cloneInstrs ();
661
- for (IRClosure cl : getClosures ()) {
662
- cl .cloneInstrs ();
663
- }
664
673
665
674
// Build CFG, run passes, etc.
666
675
initScope (false );
0 commit comments