Program: 149788
Project: 149788
Buggy source:
/** 
 * Return a generation context that represents the execution of inlDec in the context <parent,ebag> for the call instruction callSite. <p> PRECONDITION: inlDec.isYes() <p> POSTCONDITIONS: Let gc be the returned generation context. <ul> <li> gc.cfg.firstInCodeOrder is the entry to the inlined context <li>gc.cfg.lastInCodeOrder is the exit from the inlined context <li> GenerationContext.transferState(parent, child) has been called. </ul>
 * @param inlDec the inlining decision to execute
 * @param parent the caller generation context
 * @param ebag exception handler scope for the caller
 * @param callSite the callsite to execute
 * @return a generation context that represents the execution of theinline decision in the given context
 */
public static GenerationContext execute(InlineDecision inlDec,GenerationContext parent,ExceptionHandlerBasicBlockBag ebag,Instruction callSite){
  if (inlDec.needsGuard()) {
    GenerationContext container=GenerationContext.createSynthetic(parent,ebag);
    container.cfg.breakCodeOrder(container.prologue,container.epilogue);
    RVMMethod[] targets=inlDec.getTargets();
    byte[] guards=inlDec.getGuards();
    GenerationContext[] children=new GenerationContext[targets.length];
    for (int i=0; i < targets.length; i++) {
      NormalMethod callee=(NormalMethod)targets[i];
      if (parent.options.PRINT_INLINE_REPORT) {
        String guard=guards[i] == OptOptions.IG_CLASS_TEST ? "String_Node_Str" : "String_Node_Str";
        VM.sysWrite("String_Node_Str" + guard + "String_Node_Str"+ callee+ "String_Node_Str"+ callSite.position.getMethod()+ "String_Node_Str"+ callSite.bcIndex+ "String_Node_Str");
      }
      children[i]=GenerationContext.createChildContext(parent,ebag,callee,callSite);
      BC2IR.generateHIR(children[i]);
      GenerationContext.transferState(parent,children[i]);
    }
    if (Call.hasResult(callSite)) {
      Register reg=Call.getResult(callSite).getRegister();
      container.result=children[0].result;
      for (int i=1; i < targets.length; i++) {
        container.result=Operand.meet(container.result,children[i].result,reg);
      }
      if (!inlDec.OSRTestFailed()) {
        container.result=Operand.meet(container.result,Call.getResult(callSite),reg);
      }
    }
    BasicBlock testFailed=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
    testFailed.exceptionHandlers=ebag;
    if (COUNT_FAILED_GUARDS && Controller.options.INSERT_DEBUGGING_COUNTERS) {
      String eventName="String_Node_Str" + callSite.position.getMethod().toString();
      Instruction counterInst=AOSDatabase.debuggingCounterData.getCounterInstructionForEvent(eventName);
      testFailed.appendInstruction(counterInst);
    }
    if (inlDec.OSRTestFailed()) {
      Instruction lastOsrBarrier=(Instruction)callSite.scratchObject;
      Instruction s=BC2IR._osrHelper(lastOsrBarrier);
      s.position=callSite.position;
      s.bcIndex=callSite.bcIndex;
      testFailed.appendInstruction(s);
      testFailed.insertOut(parent.exit);
    }
 else {
      Instruction call=callSite.copyWithoutLinks();
      Call.getMethod(call).setIsGuardedInlineOffBranch(true);
      call.bcIndex=callSite.bcIndex;
      call.position=callSite.position;
      testFailed.appendInstruction(call);
      testFailed.insertOut(container.epilogue);
      if (ebag != null) {
        for (BasicBlockEnumeration e=ebag.enumerator(); e.hasMoreElements(); ) {
          BasicBlock handler=e.next();
          testFailed.insertOut(handler);
        }
      }
      testFailed.setCanThrowExceptions();
      testFailed.setMayThrowUncaughtException();
    }
    container.cfg.linkInCodeOrder(testFailed,container.epilogue);
    testFailed.setInfrequent();
    BasicBlock firstIfBlock=testFailed;
    Operand receiver=Call.getParam(callSite,0);
    MethodOperand mo=Call.getMethod(callSite);
    boolean isInterface=mo.isInterface();
    if (isInterface) {
      if (VM.BuildForIMTInterfaceInvocation) {
        RVMType interfaceType=mo.getTarget().getDeclaringClass();
        TypeReference recTypeRef=receiver.getType();
        RVMClass recType=(RVMClass)recTypeRef.peekType();
        boolean requiresImplementsTest=true;
        if (recType != null && recType.isResolved() && !recType.isInterface()) {
          byte doesImplement=ClassLoaderProxy.includesType(interfaceType.getTypeRef(),recTypeRef);
          requiresImplementsTest=doesImplement != OptConstants.YES;
        }
        if (requiresImplementsTest) {
          RegisterOperand checkedReceiver=parent.temps.makeTemp(receiver);
          Instruction dtc=TypeCheck.create(MUST_IMPLEMENT_INTERFACE,checkedReceiver,receiver.copy(),new TypeOperand(interfaceType),Call.getGuard(callSite).copy());
          dtc.copyPosition(callSite);
          checkedReceiver.refine(interfaceType.getTypeRef());
          Call.setParam(callSite,0,checkedReceiver.copyRO());
          testFailed.prependInstruction(dtc);
        }
      }
    }
    for (int i=children.length - 1; i >= 0; i--, testFailed=firstIfBlock) {
      firstIfBlock=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
      firstIfBlock.exceptionHandlers=ebag;
      BasicBlock lastIfBlock=firstIfBlock;
      RVMMethod target=children[i].method;
      Instruction tmp;
      if (isInterface) {
        RVMClass callDeclClass=mo.getTarget().getDeclaringClass();
        if (!callDeclClass.isInterface()) {
          throw new OptimizingCompilerException("String_Node_Str");
        }
        byte doesImplement=ClassLoaderProxy.includesType(callDeclClass.getTypeRef(),target.getDeclaringClass().getTypeRef());
        if (doesImplement != OptConstants.YES) {
          if (parent.options.PRINT_INLINE_REPORT) {
            VM.sysWrite("String_Node_Str" + callDeclClass + "String_Node_Str");
          }
          firstIfBlock=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
          firstIfBlock.exceptionHandlers=ebag;
          RegisterOperand instanceOfResult=parent.temps.makeTempInt();
          tmp=InstanceOf.create(INSTANCEOF_NOTNULL,instanceOfResult,new TypeOperand(callDeclClass),receiver.copy(),Call.getGuard(callSite));
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          tmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),instanceOfResult.copyD2U(),new IntConstantOperand(0),ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          firstIfBlock.insertOut(testFailed);
          firstIfBlock.insertOut(lastIfBlock);
          container.cfg.linkInCodeOrder(firstIfBlock,lastIfBlock);
        }
      }
      if (guards[i] == OptOptions.IG_CLASS_TEST) {
        tmp=InlineGuard.create(IG_CLASS_TEST,receiver.copy(),Call.getGuard(callSite).copy(),new TypeOperand(target.getDeclaringClass()),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
      }
 else       if (guards[i] == OptOptions.IG_METHOD_TEST) {
        if (isInterface) {
          RegisterOperand t=parent.temps.makeTempInt();
          Instruction test=InstanceOf.create(INSTANCEOF_NOTNULL,t,new TypeOperand(target.getDeclaringClass().getTypeRef()),receiver.copy());
          test.copyPosition(callSite);
          lastIfBlock.appendInstruction(test);
          Instruction cmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),t.copyD2U(),new IntConstantOperand(0),ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
          cmp.copyPosition(callSite);
          lastIfBlock.appendInstruction(cmp);
          BasicBlock subclassTest=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
          lastIfBlock.insertOut(testFailed);
          lastIfBlock.insertOut(subclassTest);
          container.cfg.linkInCodeOrder(lastIfBlock,subclassTest);
          lastIfBlock=subclassTest;
        }
        tmp=InlineGuard.create(IG_METHOD_TEST,receiver.copy(),Call.getGuard(callSite).copy(),MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
      }
 else {
        tmp=InlineGuard.create(IG_PATCH_POINT,receiver.copy(),Call.getGuard(callSite).copy(),MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),inlDec.OSRTestFailed() ? BranchProfileOperand.never() : BranchProfileOperand.unlikely());
      }
      tmp.copyPosition(callSite);
      lastIfBlock.appendInstruction(tmp);
      lastIfBlock.insertOut(testFailed);
      lastIfBlock.insertOut(children[i].prologue);
      container.cfg.linkInCodeOrder(lastIfBlock,children[i].cfg.firstInCodeOrder());
      if (children[i].epilogue != null) {
        children[i].epilogue.appendInstruction(container.epilogue.makeGOTO());
        children[i].epilogue.insertOut(container.epilogue);
      }
      container.cfg.linkInCodeOrder(children[i].cfg.lastInCodeOrder(),testFailed);
    }
    container.prologue.insertOut(testFailed);
    container.cfg.linkInCodeOrder(container.prologue,testFailed);
    return container;
  }
 else {
    if (VM.VerifyAssertions)     VM._assert(inlDec.getNumberOfTargets() == 1);
    NormalMethod callee=(NormalMethod)inlDec.getTargets()[0];
    if (parent.options.PRINT_INLINE_REPORT) {
      VM.sysWrite("String_Node_Str" + callee + "String_Node_Str"+ callSite.position.getMethod()+ "String_Node_Str"+ callSite.bcIndex+ "String_Node_Str");
    }
    GenerationContext child=GenerationContext.createChildContext(parent,ebag,callee,callSite);
    BC2IR.generateHIR(child);
    GenerationContext.transferState(parent,child);
    return child;
  }
}

Fixed version (ground truth):
/** 
 * Return a generation context that represents the execution of inlDec in the context <parent,ebag> for the call instruction callSite. <p> PRECONDITION: inlDec.isYes() <p> POSTCONDITIONS: Let gc be the returned generation context. <ul> <li> gc.cfg.firstInCodeOrder is the entry to the inlined context <li>gc.cfg.lastInCodeOrder is the exit from the inlined context <li> GenerationContext.transferState(parent, child) has been called. </ul>
 * @param inlDec the inlining decision to execute
 * @param parent the caller generation context
 * @param ebag exception handler scope for the caller
 * @param callSite the callsite to execute
 * @return a generation context that represents the execution of theinline decision in the given context
 */
public static GenerationContext execute(InlineDecision inlDec,GenerationContext parent,ExceptionHandlerBasicBlockBag ebag,Instruction callSite){
  if (inlDec.needsGuard()) {
    GenerationContext container=GenerationContext.createSynthetic(parent,ebag);
    container.cfg.breakCodeOrder(container.prologue,container.epilogue);
    RVMMethod[] targets=inlDec.getTargets();
    byte[] guards=inlDec.getGuards();
    GenerationContext[] children=new GenerationContext[targets.length];
    for (int i=0; i < targets.length; i++) {
      NormalMethod callee=(NormalMethod)targets[i];
      if (parent.options.PRINT_INLINE_REPORT) {
        String guard=guards[i] == OptOptions.IG_CLASS_TEST ? "String_Node_Str" : "String_Node_Str";
        VM.sysWrite("String_Node_Str" + guard + "String_Node_Str"+ callee+ "String_Node_Str"+ callSite.position.getMethod()+ "String_Node_Str"+ callSite.bcIndex+ "String_Node_Str");
      }
      children[i]=GenerationContext.createChildContext(parent,ebag,callee,callSite);
      BC2IR.generateHIR(children[i]);
      GenerationContext.transferState(parent,children[i]);
    }
    if (Call.hasResult(callSite)) {
      Register reg=Call.getResult(callSite).getRegister();
      container.result=children[0].result;
      for (int i=1; i < targets.length; i++) {
        if (children[i].result != null) {
          container.result=(container.result == null) ? children[i].result : Operand.meet(container.result,children[i].result,reg);
        }
      }
      if (!inlDec.OSRTestFailed()) {
        RegisterOperand failureCaseResult=Call.getResult(callSite);
        container.result=(container.result == null) ? failureCaseResult : Operand.meet(container.result,failureCaseResult,reg);
      }
    }
    BasicBlock testFailed=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
    testFailed.exceptionHandlers=ebag;
    if (COUNT_FAILED_GUARDS && Controller.options.INSERT_DEBUGGING_COUNTERS) {
      String eventName="String_Node_Str" + callSite.position.getMethod().toString();
      Instruction counterInst=AOSDatabase.debuggingCounterData.getCounterInstructionForEvent(eventName);
      testFailed.appendInstruction(counterInst);
    }
    if (inlDec.OSRTestFailed()) {
      Instruction lastOsrBarrier=(Instruction)callSite.scratchObject;
      Instruction s=BC2IR._osrHelper(lastOsrBarrier);
      s.position=callSite.position;
      s.bcIndex=callSite.bcIndex;
      testFailed.appendInstruction(s);
      testFailed.insertOut(parent.exit);
    }
 else {
      Instruction call=callSite.copyWithoutLinks();
      Call.getMethod(call).setIsGuardedInlineOffBranch(true);
      call.bcIndex=callSite.bcIndex;
      call.position=callSite.position;
      testFailed.appendInstruction(call);
      testFailed.insertOut(container.epilogue);
      if (ebag != null) {
        for (BasicBlockEnumeration e=ebag.enumerator(); e.hasMoreElements(); ) {
          BasicBlock handler=e.next();
          testFailed.insertOut(handler);
        }
      }
      testFailed.setCanThrowExceptions();
      testFailed.setMayThrowUncaughtException();
    }
    container.cfg.linkInCodeOrder(testFailed,container.epilogue);
    testFailed.setInfrequent();
    BasicBlock firstIfBlock=testFailed;
    Operand receiver=Call.getParam(callSite,0);
    MethodOperand mo=Call.getMethod(callSite);
    boolean isInterface=mo.isInterface();
    if (isInterface) {
      if (VM.BuildForIMTInterfaceInvocation) {
        RVMType interfaceType=mo.getTarget().getDeclaringClass();
        TypeReference recTypeRef=receiver.getType();
        RVMClass recType=(RVMClass)recTypeRef.peekType();
        boolean requiresImplementsTest=true;
        if (recType != null && recType.isResolved() && !recType.isInterface()) {
          byte doesImplement=ClassLoaderProxy.includesType(interfaceType.getTypeRef(),recTypeRef);
          requiresImplementsTest=doesImplement != OptConstants.YES;
        }
        if (requiresImplementsTest) {
          RegisterOperand checkedReceiver=parent.temps.makeTemp(receiver);
          Instruction dtc=TypeCheck.create(MUST_IMPLEMENT_INTERFACE,checkedReceiver,receiver.copy(),new TypeOperand(interfaceType),Call.getGuard(callSite).copy());
          dtc.copyPosition(callSite);
          checkedReceiver.refine(interfaceType.getTypeRef());
          Call.setParam(callSite,0,checkedReceiver.copyRO());
          testFailed.prependInstruction(dtc);
        }
      }
    }
    for (int i=children.length - 1; i >= 0; i--, testFailed=firstIfBlock) {
      firstIfBlock=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
      firstIfBlock.exceptionHandlers=ebag;
      BasicBlock lastIfBlock=firstIfBlock;
      RVMMethod target=children[i].method;
      Instruction tmp;
      if (isInterface) {
        RVMClass callDeclClass=mo.getTarget().getDeclaringClass();
        if (!callDeclClass.isInterface()) {
          throw new OptimizingCompilerException("String_Node_Str");
        }
        byte doesImplement=ClassLoaderProxy.includesType(callDeclClass.getTypeRef(),target.getDeclaringClass().getTypeRef());
        if (doesImplement != OptConstants.YES) {
          if (parent.options.PRINT_INLINE_REPORT) {
            VM.sysWrite("String_Node_Str" + callDeclClass + "String_Node_Str");
          }
          firstIfBlock=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
          firstIfBlock.exceptionHandlers=ebag;
          RegisterOperand instanceOfResult=parent.temps.makeTempInt();
          tmp=InstanceOf.create(INSTANCEOF_NOTNULL,instanceOfResult,new TypeOperand(callDeclClass),receiver.copy(),Call.getGuard(callSite));
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          tmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),instanceOfResult.copyD2U(),new IntConstantOperand(0),ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          firstIfBlock.insertOut(testFailed);
          firstIfBlock.insertOut(lastIfBlock);
          container.cfg.linkInCodeOrder(firstIfBlock,lastIfBlock);
        }
      }
      if (guards[i] == OptOptions.IG_CLASS_TEST) {
        tmp=InlineGuard.create(IG_CLASS_TEST,receiver.copy(),Call.getGuard(callSite).copy(),new TypeOperand(target.getDeclaringClass()),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
      }
 else       if (guards[i] == OptOptions.IG_METHOD_TEST) {
        if (isInterface) {
          RegisterOperand t=parent.temps.makeTempInt();
          Instruction test=InstanceOf.create(INSTANCEOF_NOTNULL,t,new TypeOperand(target.getDeclaringClass().getTypeRef()),receiver.copy());
          test.copyPosition(callSite);
          lastIfBlock.appendInstruction(test);
          Instruction cmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),t.copyD2U(),new IntConstantOperand(0),ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
          cmp.copyPosition(callSite);
          lastIfBlock.appendInstruction(cmp);
          BasicBlock subclassTest=new BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
          lastIfBlock.insertOut(testFailed);
          lastIfBlock.insertOut(subclassTest);
          container.cfg.linkInCodeOrder(lastIfBlock,subclassTest);
          lastIfBlock=subclassTest;
        }
        tmp=InlineGuard.create(IG_METHOD_TEST,receiver.copy(),Call.getGuard(callSite).copy(),MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),BranchProfileOperand.unlikely());
      }
 else {
        tmp=InlineGuard.create(IG_PATCH_POINT,receiver.copy(),Call.getGuard(callSite).copy(),MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),inlDec.OSRTestFailed() ? BranchProfileOperand.never() : BranchProfileOperand.unlikely());
      }
      tmp.copyPosition(callSite);
      lastIfBlock.appendInstruction(tmp);
      lastIfBlock.insertOut(testFailed);
      lastIfBlock.insertOut(children[i].prologue);
      container.cfg.linkInCodeOrder(lastIfBlock,children[i].cfg.firstInCodeOrder());
      if (children[i].epilogue != null) {
        children[i].epilogue.appendInstruction(container.epilogue.makeGOTO());
        children[i].epilogue.insertOut(container.epilogue);
      }
      container.cfg.linkInCodeOrder(children[i].cfg.lastInCodeOrder(),testFailed);
    }
    container.prologue.insertOut(testFailed);
    container.cfg.linkInCodeOrder(container.prologue,testFailed);
    return container;
  }
 else {
    if (VM.VerifyAssertions)     VM._assert(inlDec.getNumberOfTargets() == 1);
    NormalMethod callee=(NormalMethod)inlDec.getTargets()[0];
    if (parent.options.PRINT_INLINE_REPORT) {
      VM.sysWrite("String_Node_Str" + callee + "String_Node_Str"+ callSite.position.getMethod()+ "String_Node_Str"+ callSite.bcIndex+ "String_Node_Str");
    }
    GenerationContext child=GenerationContext.createChildContext(parent,ebag,callee,callSite);
    BC2IR.generateHIR(child);
    GenerationContext.transferState(parent,child);
    return child;
  }
}