Program: 150079
Project: 150079
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> OPT_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 OPT_GenerationContext execute(OPT_InlineDecision inlDec,OPT_GenerationContext parent,OPT_ExceptionHandlerBasicBlockBag ebag,OPT_Instruction callSite){
  if (inlDec.needsGuard()) {
    OPT_GenerationContext container=OPT_GenerationContext.createSynthetic(parent,ebag);
    container.cfg.breakCodeOrder(container.prologue,container.epilogue);
    VM_Method[] targets=inlDec.getTargets();
    byte[] guards=inlDec.getGuards();
    OPT_GenerationContext[] children=new OPT_GenerationContext[targets.length];
    for (int i=0; i < targets.length; i++) {
      VM_NormalMethod callee=(VM_NormalMethod)targets[i];
      if (parent.options.PRINT_INLINE_REPORT) {
        String guard=guards[i] == OPT_Options.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]=OPT_GenerationContext.createChildContext(parent,ebag,callee,callSite);
      OPT_BC2IR.generateHIR(children[i]);
      OPT_GenerationContext.transferState(parent,children[i]);
    }
    if (Call.hasResult(callSite)) {
      OPT_Register reg=Call.getResult(callSite).register;
      container.result=children[0].result;
      for (int i=1; i < targets.length; i++) {
        container.result=OPT_Operand.meet(container.result,children[i].result,reg);
      }
      container.result=OPT_Operand.meet(container.result,Call.getResult(callSite),reg);
    }
    OPT_BasicBlock testFailed=new OPT_BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
    testFailed.exceptionHandlers=ebag;
    OPT_Instruction call=callSite.copyWithoutLinks();
    Call.getMethod(call).setIsGuardedInlineOffBranch(true);
    call.bcIndex=callSite.bcIndex;
    call.position=callSite.position;
    if (COUNT_FAILED_GUARDS && VM_Controller.options.INSERT_DEBUGGING_COUNTERS) {
      String eventName="String_Node_Str" + callSite.position.getMethod().toString();
      OPT_Instruction counterInst=VM_AOSDatabase.debuggingCounterData.getCounterInstructionForEvent(eventName);
      testFailed.appendInstruction(counterInst);
    }
    if (inlDec.OSRTestFailed()) {
      OPT_Instruction lastOsrBarrier=(OPT_Instruction)callSite.scratchObject;
      OPT_Instruction s=OPT_BC2IR._osrHelper(lastOsrBarrier);
      s.position=callSite.position;
      s.bcIndex=callSite.bcIndex;
      testFailed.appendInstruction(s);
    }
 else {
      testFailed.appendInstruction(call);
    }
    testFailed.appendInstruction(call);
    testFailed.insertOut(container.epilogue);
    container.cfg.linkInCodeOrder(testFailed,container.epilogue);
    if (ebag != null) {
      for (OPT_BasicBlockEnumeration e=ebag.enumerator(); e.hasMoreElements(); ) {
        OPT_BasicBlock handler=e.next();
        testFailed.insertOut(handler);
      }
    }
    testFailed.setCanThrowExceptions();
    testFailed.setMayThrowUncaughtException();
    testFailed.setInfrequent();
    OPT_BasicBlock firstIfBlock=testFailed;
    OPT_RegisterOperand receiver=Call.getParam(callSite,0).asRegister();
    OPT_MethodOperand mo=Call.getMethod(callSite);
    boolean isInterface=mo.isInterface();
    if (isInterface) {
      if (VM.BuildForIMTInterfaceInvocation || (VM.BuildForITableInterfaceInvocation && VM.DirectlyIndexedITables)) {
        VM_Type interfaceType=mo.getTarget().getDeclaringClass();
        VM_TypeReference recTypeRef=receiver.type;
        VM_Class recType=(VM_Class)recTypeRef.peekResolvedType();
        boolean requiresImplementsTest=true;
        if (recType != null && recType.isResolved() && !recType.isInterface()) {
          byte doesImplement=OPT_ClassLoaderProxy.includesType(interfaceType.getTypeRef(),recTypeRef);
          requiresImplementsTest=doesImplement != OPT_Constants.YES;
        }
        if (requiresImplementsTest) {
          OPT_Instruction dtc=TypeCheck.create(MUST_IMPLEMENT_INTERFACE,receiver.copyU2U(),new OPT_TypeOperand(interfaceType),Call.getGuard(callSite).copy());
          dtc.copyPosition(callSite);
          testFailed.prependInstruction(dtc);
        }
      }
    }
    for (int i=children.length - 1; i >= 0; i--, testFailed=firstIfBlock) {
      firstIfBlock=new OPT_BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
      firstIfBlock.exceptionHandlers=ebag;
      OPT_BasicBlock lastIfBlock=firstIfBlock;
      VM_Method target=children[i].method;
      OPT_Instruction tmp;
      if (isInterface) {
        VM_Class callDeclClass=mo.getTarget().getDeclaringClass();
        if (!callDeclClass.isInterface()) {
          throw new OPT_OptimizingCompilerException("String_Node_Str");
        }
        byte doesImplement=OPT_ClassLoaderProxy.includesType(callDeclClass.getTypeRef(),target.getDeclaringClass().getTypeRef());
        if (doesImplement != OPT_Constants.YES) {
          if (parent.options.PRINT_INLINE_REPORT) {
            VM.sysWrite("String_Node_Str" + callDeclClass + "String_Node_Str");
          }
          firstIfBlock=new OPT_BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
          firstIfBlock.exceptionHandlers=ebag;
          OPT_RegisterOperand instanceOfResult=parent.temps.makeTempInt();
          tmp=InstanceOf.create(INSTANCEOF_NOTNULL,instanceOfResult,new OPT_TypeOperand(callDeclClass),receiver.copy(),Call.getGuard(callSite));
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          tmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),instanceOfResult.copyD2U(),new OPT_IntConstantOperand(0),OPT_ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          firstIfBlock.insertOut(testFailed);
          firstIfBlock.insertOut(lastIfBlock);
          container.cfg.linkInCodeOrder(firstIfBlock,lastIfBlock);
        }
      }
      if (guards[i] == OPT_Options.IG_CLASS_TEST) {
        tmp=InlineGuard.create(IG_CLASS_TEST,receiver.copyU2U(),Call.getGuard(callSite).copy(),new OPT_TypeOperand(target.getDeclaringClass()),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
      }
 else       if (guards[i] == OPT_Options.IG_METHOD_TEST) {
        if (isInterface) {
          OPT_RegisterOperand t=parent.temps.makeTempInt();
          OPT_Instruction test=InstanceOf.create(INSTANCEOF_NOTNULL,t,new OPT_TypeOperand(target.getDeclaringClass().getTypeRef()),receiver);
          test.copyPosition(callSite);
          lastIfBlock.appendInstruction(test);
          OPT_Instruction cmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),t.copyD2U(),new OPT_IntConstantOperand(0),OPT_ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
          cmp.copyPosition(callSite);
          lastIfBlock.appendInstruction(cmp);
          OPT_BasicBlock subclassTest=new OPT_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.copyU2U(),Call.getGuard(callSite).copy(),OPT_MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
      }
 else {
        tmp=InlineGuard.create(IG_PATCH_POINT,receiver.copyU2U(),Call.getGuard(callSite).copy(),OPT_MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),OPT_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);
    VM_NormalMethod callee=(VM_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");
    }
    OPT_GenerationContext child=OPT_GenerationContext.createChildContext(parent,ebag,callee,callSite);
    OPT_BC2IR.generateHIR(child);
    OPT_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> OPT_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 OPT_GenerationContext execute(OPT_InlineDecision inlDec,OPT_GenerationContext parent,OPT_ExceptionHandlerBasicBlockBag ebag,OPT_Instruction callSite){
  if (inlDec.needsGuard()) {
    OPT_GenerationContext container=OPT_GenerationContext.createSynthetic(parent,ebag);
    container.cfg.breakCodeOrder(container.prologue,container.epilogue);
    VM_Method[] targets=inlDec.getTargets();
    byte[] guards=inlDec.getGuards();
    OPT_GenerationContext[] children=new OPT_GenerationContext[targets.length];
    for (int i=0; i < targets.length; i++) {
      VM_NormalMethod callee=(VM_NormalMethod)targets[i];
      if (parent.options.PRINT_INLINE_REPORT) {
        String guard=guards[i] == OPT_Options.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]=OPT_GenerationContext.createChildContext(parent,ebag,callee,callSite);
      OPT_BC2IR.generateHIR(children[i]);
      OPT_GenerationContext.transferState(parent,children[i]);
    }
    if (Call.hasResult(callSite)) {
      OPT_Register reg=Call.getResult(callSite).register;
      container.result=children[0].result;
      for (int i=1; i < targets.length; i++) {
        container.result=OPT_Operand.meet(container.result,children[i].result,reg);
      }
      container.result=OPT_Operand.meet(container.result,Call.getResult(callSite),reg);
    }
    OPT_BasicBlock testFailed=new OPT_BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
    testFailed.exceptionHandlers=ebag;
    OPT_Instruction call=callSite.copyWithoutLinks();
    Call.getMethod(call).setIsGuardedInlineOffBranch(true);
    call.bcIndex=callSite.bcIndex;
    call.position=callSite.position;
    if (COUNT_FAILED_GUARDS && VM_Controller.options.INSERT_DEBUGGING_COUNTERS) {
      String eventName="String_Node_Str" + callSite.position.getMethod().toString();
      OPT_Instruction counterInst=VM_AOSDatabase.debuggingCounterData.getCounterInstructionForEvent(eventName);
      testFailed.appendInstruction(counterInst);
    }
    if (inlDec.OSRTestFailed()) {
      OPT_Instruction lastOsrBarrier=(OPT_Instruction)callSite.scratchObject;
      OPT_Instruction s=OPT_BC2IR._osrHelper(lastOsrBarrier);
      s.position=callSite.position;
      s.bcIndex=callSite.bcIndex;
      testFailed.appendInstruction(s);
    }
 else {
      testFailed.appendInstruction(call);
    }
    testFailed.appendInstruction(call);
    testFailed.insertOut(container.epilogue);
    container.cfg.linkInCodeOrder(testFailed,container.epilogue);
    if (ebag != null) {
      for (OPT_BasicBlockEnumeration e=ebag.enumerator(); e.hasMoreElements(); ) {
        OPT_BasicBlock handler=e.next();
        testFailed.insertOut(handler);
      }
    }
    testFailed.setCanThrowExceptions();
    testFailed.setMayThrowUncaughtException();
    testFailed.setInfrequent();
    OPT_BasicBlock firstIfBlock=testFailed;
    OPT_RegisterOperand receiver=Call.getParam(callSite,0).asRegister();
    OPT_MethodOperand mo=Call.getMethod(callSite);
    boolean isInterface=mo.isInterface();
    if (isInterface) {
      if (VM.BuildForIMTInterfaceInvocation || (VM.BuildForITableInterfaceInvocation && VM.DirectlyIndexedITables)) {
        VM_Type interfaceType=mo.getTarget().getDeclaringClass();
        VM_TypeReference recTypeRef=receiver.type;
        VM_Class recType=(VM_Class)recTypeRef.peekResolvedType();
        boolean requiresImplementsTest=true;
        if (recType != null && recType.isResolved() && !recType.isInterface()) {
          byte doesImplement=OPT_ClassLoaderProxy.includesType(interfaceType.getTypeRef(),recTypeRef);
          requiresImplementsTest=doesImplement != OPT_Constants.YES;
        }
        if (requiresImplementsTest) {
          OPT_Instruction dtc=TypeCheck.create(MUST_IMPLEMENT_INTERFACE,receiver.copyU2U(),new OPT_TypeOperand(interfaceType),Call.getGuard(callSite).copy());
          dtc.copyPosition(callSite);
          testFailed.prependInstruction(dtc);
        }
      }
    }
    for (int i=children.length - 1; i >= 0; i--, testFailed=firstIfBlock) {
      firstIfBlock=new OPT_BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
      firstIfBlock.exceptionHandlers=ebag;
      OPT_BasicBlock lastIfBlock=firstIfBlock;
      VM_Method target=children[i].method;
      OPT_Instruction tmp;
      if (isInterface) {
        VM_Class callDeclClass=mo.getTarget().getDeclaringClass();
        if (!callDeclClass.isInterface()) {
          throw new OPT_OptimizingCompilerException("String_Node_Str");
        }
        byte doesImplement=OPT_ClassLoaderProxy.includesType(callDeclClass.getTypeRef(),target.getDeclaringClass().getTypeRef());
        if (doesImplement != OPT_Constants.YES) {
          if (parent.options.PRINT_INLINE_REPORT) {
            VM.sysWrite("String_Node_Str" + callDeclClass + "String_Node_Str");
          }
          firstIfBlock=new OPT_BasicBlock(callSite.bcIndex,callSite.position,parent.cfg);
          firstIfBlock.exceptionHandlers=ebag;
          OPT_RegisterOperand instanceOfResult=parent.temps.makeTempInt();
          tmp=InstanceOf.create(INSTANCEOF_NOTNULL,instanceOfResult,new OPT_TypeOperand(callDeclClass),receiver.copy(),Call.getGuard(callSite));
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          tmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),instanceOfResult.copyD2U(),new OPT_IntConstantOperand(0),OPT_ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
          tmp.copyPosition(callSite);
          firstIfBlock.appendInstruction(tmp);
          firstIfBlock.insertOut(testFailed);
          firstIfBlock.insertOut(lastIfBlock);
          container.cfg.linkInCodeOrder(firstIfBlock,lastIfBlock);
        }
      }
      if (guards[i] == OPT_Options.IG_CLASS_TEST) {
        tmp=InlineGuard.create(IG_CLASS_TEST,receiver.copyU2U(),Call.getGuard(callSite).copy(),new OPT_TypeOperand(target.getDeclaringClass()),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
      }
 else       if (guards[i] == OPT_Options.IG_METHOD_TEST) {
        if (isInterface) {
          OPT_RegisterOperand t=parent.temps.makeTempInt();
          OPT_Instruction test=InstanceOf.create(INSTANCEOF_NOTNULL,t,new OPT_TypeOperand(target.getDeclaringClass().getTypeRef()),receiver.copyU2U());
          test.copyPosition(callSite);
          lastIfBlock.appendInstruction(test);
          OPT_Instruction cmp=IfCmp.create(INT_IFCMP,parent.temps.makeTempValidation(),t.copyD2U(),new OPT_IntConstantOperand(0),OPT_ConditionOperand.EQUAL(),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
          cmp.copyPosition(callSite);
          lastIfBlock.appendInstruction(cmp);
          OPT_BasicBlock subclassTest=new OPT_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.copyU2U(),Call.getGuard(callSite).copy(),OPT_MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),OPT_BranchProfileOperand.unlikely());
      }
 else {
        tmp=InlineGuard.create(IG_PATCH_POINT,receiver.copyU2U(),Call.getGuard(callSite).copy(),OPT_MethodOperand.VIRTUAL(target.getMemberRef().asMethodReference(),target),testFailed.makeJumpTarget(),OPT_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);
    VM_NormalMethod callee=(VM_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");
    }
    OPT_GenerationContext child=OPT_GenerationContext.createChildContext(parent,ebag,callee,callSite);
    OPT_BC2IR.generateHIR(child);
    OPT_GenerationContext.transferState(parent,child);
    return child;
  }
}