Program: 150154
Project: 150154
Buggy source:
/** 
 * "Semantic inlining" of methods of the VM_Magic class. Based on the methodName, generate a sequence of opt instructions that implement the magic, updating the expression stack as necessary.
 * @param bc2ir the bc2ir object that is generating the ir containing this magic
 * @param gc must be bc2ir.gc
 * @param meth the VM_Method that is the magic method
 */
static boolean generateMagic(OPT_BC2IR bc2ir,OPT_GenerationContext gc,VM_MethodReference meth) throws OPT_MagicNotImplementedException {
  if (gc.method.hasNoInlinePragma())   gc.allocFrame=true;
  bc2ir.markBBUnsafeForScheduling();
  VM_Atom methodName=meth.getName();
  boolean address=(meth.getType() == VM_TypeReference.Address);
  VM_TypeReference[] types=meth.getParameterTypes();
  if (address && isLoad(methodName)) {
    OPT_Operand offset=(types.length == 0) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    OPT_RegisterOperand result=gc.temps.makeTemp(meth.getReturnType());
    bc2ir.appendInstruction(Load.create(getOperator(meth.getReturnType(),LOAD_OP),result,base,offset,null));
    bc2ir.push(result.copyD2U());
  }
 else   if (address && isPrepare(methodName)) {
    OPT_Operand offset=(types.length == 0) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    OPT_RegisterOperand result=gc.temps.makeTemp(meth.getReturnType());
    bc2ir.appendInstruction(Prepare.create(getOperator(meth.getReturnType(),PREPARE_OP),result,base,offset,null));
    bc2ir.push(result.copyD2U());
  }
 else   if (address && methodName == VM_MagicNames.attempt) {
    VM_TypeReference attemptType=types[0];
    OPT_Operand offset=(types.length == 2) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand newVal=bc2ir.pop();
    OPT_Operand oldVal=bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(getOperator(attemptType,ATTEMPT_OP),test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (address && methodName == VM_MagicNames.store) {
    VM_TypeReference storeType=types[0];
    OPT_Operand offset=(types.length == 1) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand val=bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(getOperator(storeType,STORE_OP),val,base,offset,null));
  }
 else   if (methodName == VM_MagicNames.getProcessorRegister) {
    OPT_RegisterOperand rop=gc.temps.makePROp();
    bc2ir.markGuardlessNonNull(rop);
    bc2ir.push(rop);
  }
 else   if (methodName == VM_MagicNames.setProcessorRegister) {
    OPT_Operand val=bc2ir.popRef();
    if (val instanceof OPT_RegisterOperand) {
      bc2ir.appendInstruction(Move.create(REF_MOVE,gc.temps.makePROp(),val));
    }
 else {
      String msg="String_Node_Str";
      throw OPT_MagicNotImplementedException.UNEXPECTED(msg);
    }
  }
 else   if (methodName == VM_MagicNames.addressArrayCreate) {
    OPT_Instruction s=bc2ir.generateAnewarray(meth.getType().getArrayElementType());
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.addressArrayLength) {
    OPT_Operand op1=bc2ir.pop();
    bc2ir.clearCurrentGuard();
    if (bc2ir.do_NullCheck(op1))     return true;
    OPT_RegisterOperand t=gc.temps.makeTempInt();
    OPT_Instruction s=GuardedUnary.create(ARRAYLENGTH,t,op1,bc2ir.getCurrentGuard());
    bc2ir.push(t.copyD2U());
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.addressArrayGet) {
    VM_TypeReference elementType=meth.getType().getArrayElementType();
    OPT_Operand index=bc2ir.popInt();
    OPT_Operand ref=bc2ir.popRef();
    OPT_RegisterOperand offset=gc.temps.makeTempInt();
    OPT_RegisterOperand result;
    if (meth.getType().isCodeArrayType()) {
      if (VM.BuildForIA32) {
        result=gc.temps.makeTemp(VM_TypeReference.Byte);
        bc2ir.appendInstruction(Load.create(BYTE_LOAD,result,ref,index,new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
 else       if (VM.BuildForPowerPC) {
        result=gc.temps.makeTemp(VM_TypeReference.Int);
        bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_INT)));
        bc2ir.appendInstruction(Load.create(INT_LOAD,result,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
    }
 else {
      result=gc.temps.makeTemp(elementType);
      bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_ADDRESS)));
      bc2ir.appendInstruction(Load.create(REF_LOAD,result,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
    }
    bc2ir.push(result.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressArraySet) {
    VM_TypeReference elementType=meth.getType().getArrayElementType();
    OPT_Operand val=bc2ir.pop();
    OPT_Operand index=bc2ir.popInt();
    OPT_Operand ref=bc2ir.popRef();
    OPT_RegisterOperand offset=gc.temps.makeTempInt();
    if (meth.getType().isCodeArrayType()) {
      if (VM.BuildForIA32) {
        bc2ir.appendInstruction(Store.create(BYTE_STORE,val,ref,index,new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
 else       if (VM.BuildForPowerPC) {
        bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_INT)));
        bc2ir.appendInstruction(Store.create(INT_STORE,val,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
    }
 else {
      bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_ADDRESS)));
      bc2ir.appendInstruction(Store.create(REF_STORE,val,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
    }
  }
 else   if (methodName == VM_MagicNames.getIntAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Load.create(INT_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setIntAtOffset) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(INT_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getWordAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Word);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setWordAtOffset) {
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getLongAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempLong();
    bc2ir.appendInstruction(Load.create(LONG_LOAD,val,object,offset,null));
    bc2ir.pushDual(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setLongAtOffset) {
    OPT_Operand val=bc2ir.popLong();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(LONG_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getDoubleAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempDouble();
    bc2ir.appendInstruction(Load.create(DOUBLE_LOAD,val,object,offset,null));
    bc2ir.pushDual(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setDoubleAtOffset) {
    OPT_Operand val=bc2ir.popDouble();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(DOUBLE_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getObjectAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getObjectArrayAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.JavaLangObjectArray);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setObjectAtOffset) {
    OPT_LocationOperand loc=null;
    if (meth.getParameterTypes().length == 4) {
      loc=mapToMetadata(bc2ir.popInt());
    }
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,object,offset,loc));
  }
 else   if (methodName == VM_MagicNames.getByteAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Byte);
    bc2ir.appendInstruction(Load.create(BYTE_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setByteAtOffset) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(BYTE_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getCharAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Char);
    bc2ir.appendInstruction(Load.create(USHORT_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setCharAtOffset) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(SHORT_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getMemoryInt) {
    OPT_Operand memAddr=bc2ir.popAddress();
    OPT_RegisterOperand val=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Load.create(INT_LOAD,val,memAddr,new OPT_IntConstantOperand(0),null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getMemoryWord) {
    OPT_Operand memAddr=bc2ir.popAddress();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Word);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,memAddr,new OPT_IntConstantOperand(0),null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getMemoryAddress) {
    OPT_Operand memAddr=bc2ir.popAddress();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Address);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,memAddr,new OPT_IntConstantOperand(0),null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setMemoryInt) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand memAddr=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(INT_STORE,val,memAddr,new OPT_IntConstantOperand(0),null));
  }
 else   if (methodName == VM_MagicNames.setMemoryWord) {
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand memAddr=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,memAddr,new OPT_IntConstantOperand(0),null));
  }
 else   if (methodName == VM_MagicNames.setMemoryAddress) {
    OPT_LocationOperand loc=null;
    if (meth.getParameterTypes().length == 3) {
      loc=mapToMetadata(bc2ir.popInt());
    }
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand memAddr=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,memAddr,new OPT_IntConstantOperand(0),loc));
  }
 else   if (meth.getType() == VM_TypeReference.SysCall) {
    VM_TypeReference[] args=meth.getParameterTypes();
    int numArgs=args.length;
    VM_Field ip=VM_Entrypoints.getSysCallField(meth.getName().toString());
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(ip);
    OPT_Instruction call=Call.create(SYSCALL,null,null,mo,null,args.length);
    for (int i=args.length - 1; i >= 0; i--) {
      Call.setParam(call,i,bc2ir.pop(args[i]));
    }
    VM_TypeReference rtype=meth.getReturnType();
    if (!rtype.isVoidType()) {
      OPT_RegisterOperand op0=gc.temps.makeTemp(rtype);
      Call.setResult(call,op0);
      bc2ir.push(op0.copyD2U(),rtype);
    }
    bc2ir.appendInstruction(call);
  }
 else   if (methodName == VM_MagicNames.threadAsCollectorThread) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsType) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.VM_Type);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsThread) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsProcessor) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.VM_Processor);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsAddress) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.Address);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsObject) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsObjectArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.JavaLangObjectArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsType) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.VM_Type);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsThread) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsRegisters) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsByteArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.ByteArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsIntArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.IntArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsByteArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.ByteArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsShortArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.ShortArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsIntArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.IntArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsStack) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.IntArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.floatAsIntBits) {
    OPT_Operand val=bc2ir.popFloat();
    OPT_RegisterOperand op0=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Unary.create(FLOAT_AS_INT_BITS,op0,val));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.intBitsAsFloat) {
    OPT_Operand val=bc2ir.popInt();
    OPT_RegisterOperand op0=gc.temps.makeTempFloat();
    bc2ir.appendInstruction(Unary.create(INT_BITS_AS_FLOAT,op0,val));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.doubleAsLongBits) {
    OPT_Operand val=bc2ir.popDouble();
    OPT_RegisterOperand op0=gc.temps.makeTempLong();
    bc2ir.appendInstruction(Unary.create(DOUBLE_AS_LONG_BITS,op0,val));
    bc2ir.pushDual(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.longBitsAsDouble) {
    OPT_Operand val=bc2ir.popLong();
    OPT_RegisterOperand op0=gc.temps.makeTempDouble();
    bc2ir.appendInstruction(Unary.create(LONG_BITS_AS_DOUBLE,op0,val));
    bc2ir.pushDual(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getObjectType) {
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand guard=bc2ir.getGuard(val);
    if (guard == null) {
      guard=new OPT_TrueGuardOperand();
    }
    OPT_RegisterOperand tibPtr=gc.temps.makeTemp(VM_TypeReference.JavaLangObjectArray);
    bc2ir.appendInstruction(GuardedUnary.create(GET_OBJ_TIB,tibPtr,val,guard));
    OPT_RegisterOperand op0;
    VM_TypeReference argType=val.getType();
    if (argType.isArrayType()) {
      op0=gc.temps.makeTemp(VM_TypeReference.VM_Array);
    }
 else {
      if (argType == VM_TypeReference.JavaLangObject || argType == VM_TypeReference.JavaLangCloneable || argType == VM_TypeReference.JavaIoSerializable) {
        op0=gc.temps.makeTemp(VM_TypeReference.VM_Type);
      }
 else {
        op0=gc.temps.makeTemp(VM_TypeReference.VM_Class);
      }
    }
    bc2ir.markGuardlessNonNull(op0);
    bc2ir.appendInstruction(Unary.create(GET_TYPE_FROM_TIB,op0,tibPtr.copyD2U()));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getArrayLength) {
    OPT_Operand val=bc2ir.popRef();
    OPT_RegisterOperand op0=gc.temps.makeTempInt();
    bc2ir.appendInstruction(GuardedUnary.create(ARRAYLENGTH,op0,val,new OPT_TrueGuardOperand()));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.invokeClassInitializer) {
    OPT_Instruction s=Call.create0(CALL,null,bc2ir.popRef(),null);
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.invokeMain) {
    OPT_Operand code=bc2ir.popRef();
    OPT_Operand args=bc2ir.popRef();
    bc2ir.appendInstruction(Call.create1(CALL,null,code,null,args));
  }
 else   if ((methodName == VM_MagicNames.invokeMethodReturningObject) || (methodName == VM_MagicNames.invokeMethodReturningVoid) || (methodName == VM_MagicNames.invokeMethodReturningLong)|| (methodName == VM_MagicNames.invokeMethodReturningDouble)|| (methodName == VM_MagicNames.invokeMethodReturningFloat)|| (methodName == VM_MagicNames.invokeMethodReturningInt)) {
    OPT_Operand spills=bc2ir.popRef();
    OPT_Operand fprs=bc2ir.popRef();
    OPT_Operand gprs=bc2ir.popRef();
    OPT_Operand code=bc2ir.popRef();
    OPT_RegisterOperand res=null;
    if (methodName == VM_MagicNames.invokeMethodReturningObject) {
      res=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
      bc2ir.push(res.copyD2U());
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningLong) {
      res=gc.temps.makeTemp(VM_TypeReference.Long);
      bc2ir.push(res.copyD2U(),VM_TypeReference.Long);
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningDouble) {
      res=gc.temps.makeTempDouble();
      bc2ir.push(res.copyD2U(),VM_TypeReference.Double);
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningFloat) {
      res=gc.temps.makeTempFloat();
      bc2ir.push(res.copyD2U(),VM_TypeReference.Float);
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningInt) {
      res=gc.temps.makeTempInt();
      bc2ir.push(res.copyD2U());
    }
    VM_Field target=VM_Entrypoints.reflectiveMethodInvokerInstructionsField;
    OPT_MethodOperand met=OPT_MethodOperand.STATIC(target);
    OPT_Instruction s=Call.create4(CALL,res,new OPT_IntConstantOperand(target.getOffset()),met,code,gprs,fprs,spills);
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.saveThreadState) {
    OPT_Operand p1=bc2ir.popRef();
    VM_Field target=VM_Entrypoints.saveThreadStateInstructionsField;
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(target);
    bc2ir.appendInstruction(Call.create1(CALL,null,new OPT_IntConstantOperand(target.getOffset()),mo,p1));
  }
 else   if (methodName == VM_MagicNames.threadSwitch) {
    OPT_Operand p2=bc2ir.popRef();
    OPT_Operand p1=bc2ir.popRef();
    VM_Field target=VM_Entrypoints.threadSwitchInstructionsField;
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(target);
    bc2ir.appendInstruction(Call.create2(CALL,null,new OPT_IntConstantOperand(target.getOffset()),mo,p1,p2));
  }
 else   if (methodName == VM_MagicNames.restoreHardwareExceptionState) {
    VM_Field target=VM_Entrypoints.restoreHardwareExceptionStateInstructionsField;
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(target);
    bc2ir.appendInstruction(Call.create1(CALL,null,new OPT_IntConstantOperand(target.getOffset()),mo,bc2ir.popRef()));
  }
 else   if (methodName == VM_MagicNames.prepareInt) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Prepare.create(PREPARE_INT,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.prepareObject) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
    bc2ir.appendInstruction(Prepare.create(PREPARE_ADDR,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.prepareAddress) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Address);
    bc2ir.appendInstruction(Prepare.create(PREPARE_ADDR,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.prepareWord) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Word);
    bc2ir.appendInstruction(Prepare.create(PREPARE_ADDR,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptInt) {
    OPT_Operand newVal=bc2ir.popInt();
    OPT_Operand oldVal=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_INT,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptObject) {
    OPT_Operand newVal=bc2ir.popRef();
    OPT_Operand oldVal=bc2ir.popRef();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_ADDR,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptAddress) {
    OPT_Operand newVal=bc2ir.popAddress();
    OPT_Operand oldVal=bc2ir.popAddress();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_ADDR,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptWord) {
    OPT_Operand newVal=bc2ir.pop();
    OPT_Operand oldVal=bc2ir.pop();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_ADDR,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (generatePolymorphicMagic(bc2ir,gc,meth,methodName)) {
    return true;
  }
 else   if (methodName == VM_MagicNames.getTimeBase) {
    OPT_RegisterOperand op0=gc.temps.makeTempLong();
    bc2ir.appendInstruction(Nullary.create(GET_TIME_BASE,op0));
    bc2ir.pushDual(op0.copyD2U());
  }
 else {
    return OPT_GenerateMachineSpecificMagic.generateMagic(bc2ir,gc,meth);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * "Semantic inlining" of methods of the VM_Magic class. Based on the methodName, generate a sequence of opt instructions that implement the magic, updating the expression stack as necessary.
 * @param bc2ir the bc2ir object that is generating the ir containing this magic
 * @param gc must be bc2ir.gc
 * @param meth the VM_Method that is the magic method
 */
static boolean generateMagic(OPT_BC2IR bc2ir,OPT_GenerationContext gc,VM_MethodReference meth) throws OPT_MagicNotImplementedException {
  if (gc.method.hasNoInlinePragma())   gc.allocFrame=true;
  bc2ir.markBBUnsafeForScheduling();
  VM_Atom methodName=meth.getName();
  boolean address=(meth.getType() == VM_TypeReference.Address);
  VM_TypeReference[] types=meth.getParameterTypes();
  VM_TypeReference returnType=meth.getReturnType();
  if (address && isLoad(methodName)) {
    OPT_Operand offset=(types.length == 0) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    OPT_RegisterOperand result=gc.temps.makeTemp(returnType);
    bc2ir.appendInstruction(Load.create(getOperator(returnType,LOAD_OP),result,base,offset,null));
    bc2ir.push(result.copyD2U(),returnType);
  }
 else   if (address && isPrepare(methodName)) {
    OPT_Operand offset=(types.length == 0) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    OPT_RegisterOperand result=gc.temps.makeTemp(returnType);
    bc2ir.appendInstruction(Prepare.create(getOperator(returnType,PREPARE_OP),result,base,offset,null));
    bc2ir.push(result.copyD2U(),returnType);
  }
 else   if (address && methodName == VM_MagicNames.attempt) {
    VM_TypeReference attemptType=types[0];
    OPT_Operand offset=(types.length == 2) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand newVal=bc2ir.pop();
    OPT_Operand oldVal=bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(getOperator(attemptType,ATTEMPT_OP),test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U(),returnType);
  }
 else   if (address && methodName == VM_MagicNames.store) {
    VM_TypeReference storeType=types[0];
    OPT_Operand offset=(types.length == 1) ? new OPT_IntConstantOperand(0) : bc2ir.pop();
    OPT_Operand val=bc2ir.pop();
    OPT_Operand base=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(getOperator(storeType,STORE_OP),val,base,offset,null));
  }
 else   if (methodName == VM_MagicNames.getProcessorRegister) {
    OPT_RegisterOperand rop=gc.temps.makePROp();
    bc2ir.markGuardlessNonNull(rop);
    bc2ir.push(rop);
  }
 else   if (methodName == VM_MagicNames.setProcessorRegister) {
    OPT_Operand val=bc2ir.popRef();
    if (val instanceof OPT_RegisterOperand) {
      bc2ir.appendInstruction(Move.create(REF_MOVE,gc.temps.makePROp(),val));
    }
 else {
      String msg="String_Node_Str";
      throw OPT_MagicNotImplementedException.UNEXPECTED(msg);
    }
  }
 else   if (methodName == VM_MagicNames.addressArrayCreate) {
    OPT_Instruction s=bc2ir.generateAnewarray(meth.getType().getArrayElementType());
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.addressArrayLength) {
    OPT_Operand op1=bc2ir.pop();
    bc2ir.clearCurrentGuard();
    if (bc2ir.do_NullCheck(op1))     return true;
    OPT_RegisterOperand t=gc.temps.makeTempInt();
    OPT_Instruction s=GuardedUnary.create(ARRAYLENGTH,t,op1,bc2ir.getCurrentGuard());
    bc2ir.push(t.copyD2U());
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.addressArrayGet) {
    VM_TypeReference elementType=meth.getType().getArrayElementType();
    OPT_Operand index=bc2ir.popInt();
    OPT_Operand ref=bc2ir.popRef();
    OPT_RegisterOperand offset=gc.temps.makeTempInt();
    OPT_RegisterOperand result;
    if (meth.getType().isCodeArrayType()) {
      if (VM.BuildForIA32) {
        result=gc.temps.makeTemp(VM_TypeReference.Byte);
        bc2ir.appendInstruction(Load.create(BYTE_LOAD,result,ref,index,new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
 else       if (VM.BuildForPowerPC) {
        result=gc.temps.makeTemp(VM_TypeReference.Int);
        bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_INT)));
        bc2ir.appendInstruction(Load.create(INT_LOAD,result,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
    }
 else {
      result=gc.temps.makeTemp(elementType);
      bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_ADDRESS)));
      bc2ir.appendInstruction(Load.create(REF_LOAD,result,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
    }
    bc2ir.push(result.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressArraySet) {
    VM_TypeReference elementType=meth.getType().getArrayElementType();
    OPT_Operand val=bc2ir.pop();
    OPT_Operand index=bc2ir.popInt();
    OPT_Operand ref=bc2ir.popRef();
    OPT_RegisterOperand offset=gc.temps.makeTempInt();
    if (meth.getType().isCodeArrayType()) {
      if (VM.BuildForIA32) {
        bc2ir.appendInstruction(Store.create(BYTE_STORE,val,ref,index,new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
 else       if (VM.BuildForPowerPC) {
        bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_INT)));
        bc2ir.appendInstruction(Store.create(INT_STORE,val,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
      }
    }
 else {
      bc2ir.appendInstruction(Binary.create(INT_SHL,offset,index,new OPT_IntConstantOperand(LOG_BYTES_IN_ADDRESS)));
      bc2ir.appendInstruction(Store.create(REF_STORE,val,ref,offset.copy(),new OPT_LocationOperand(elementType),new OPT_TrueGuardOperand()));
    }
  }
 else   if (methodName == VM_MagicNames.getIntAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Load.create(INT_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setIntAtOffset) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(INT_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getWordAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Word);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setWordAtOffset) {
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getLongAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempLong();
    bc2ir.appendInstruction(Load.create(LONG_LOAD,val,object,offset,null));
    bc2ir.pushDual(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setLongAtOffset) {
    OPT_Operand val=bc2ir.popLong();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(LONG_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getDoubleAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempDouble();
    bc2ir.appendInstruction(Load.create(DOUBLE_LOAD,val,object,offset,null));
    bc2ir.pushDual(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setDoubleAtOffset) {
    OPT_Operand val=bc2ir.popDouble();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(DOUBLE_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getObjectAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getObjectArrayAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.JavaLangObjectArray);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setObjectAtOffset) {
    OPT_LocationOperand loc=null;
    if (meth.getParameterTypes().length == 4) {
      loc=mapToMetadata(bc2ir.popInt());
    }
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,object,offset,loc));
  }
 else   if (methodName == VM_MagicNames.getByteAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Byte);
    bc2ir.appendInstruction(Load.create(BYTE_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setByteAtOffset) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(BYTE_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getCharAtOffset) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Char);
    bc2ir.appendInstruction(Load.create(USHORT_LOAD,val,object,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setCharAtOffset) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand object=bc2ir.popRef();
    bc2ir.appendInstruction(Store.create(SHORT_STORE,val,object,offset,null));
  }
 else   if (methodName == VM_MagicNames.getMemoryInt) {
    OPT_Operand memAddr=bc2ir.popAddress();
    OPT_RegisterOperand val=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Load.create(INT_LOAD,val,memAddr,new OPT_IntConstantOperand(0),null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getMemoryWord) {
    OPT_Operand memAddr=bc2ir.popAddress();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Word);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,memAddr,new OPT_IntConstantOperand(0),null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getMemoryAddress) {
    OPT_Operand memAddr=bc2ir.popAddress();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Address);
    bc2ir.appendInstruction(Load.create(REF_LOAD,val,memAddr,new OPT_IntConstantOperand(0),null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.setMemoryInt) {
    OPT_Operand val=bc2ir.popInt();
    OPT_Operand memAddr=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(INT_STORE,val,memAddr,new OPT_IntConstantOperand(0),null));
  }
 else   if (methodName == VM_MagicNames.setMemoryWord) {
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand memAddr=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,memAddr,new OPT_IntConstantOperand(0),null));
  }
 else   if (methodName == VM_MagicNames.setMemoryAddress) {
    OPT_LocationOperand loc=null;
    if (meth.getParameterTypes().length == 3) {
      loc=mapToMetadata(bc2ir.popInt());
    }
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand memAddr=bc2ir.popAddress();
    bc2ir.appendInstruction(Store.create(REF_STORE,val,memAddr,new OPT_IntConstantOperand(0),loc));
  }
 else   if (meth.getType() == VM_TypeReference.SysCall) {
    VM_TypeReference[] args=meth.getParameterTypes();
    int numArgs=args.length;
    VM_Field ip=VM_Entrypoints.getSysCallField(meth.getName().toString());
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(ip);
    OPT_Instruction call=Call.create(SYSCALL,null,null,mo,null,args.length);
    for (int i=args.length - 1; i >= 0; i--) {
      Call.setParam(call,i,bc2ir.pop(args[i]));
    }
    if (!returnType.isVoidType()) {
      OPT_RegisterOperand op0=gc.temps.makeTemp(returnType);
      Call.setResult(call,op0);
      bc2ir.push(op0.copyD2U(),returnType);
    }
    bc2ir.appendInstruction(call);
  }
 else   if (methodName == VM_MagicNames.threadAsCollectorThread) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsType) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.VM_Type);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsThread) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsProcessor) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.VM_Processor);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsAddress) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.Address);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsObject) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsObjectArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.JavaLangObjectArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsType) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.VM_Type);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsThread) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsRegisters) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.findOrCreate(VM_SystemClassLoader.getVMClassLoader(),VM_Atom.findOrCreateAsciiAtom("String_Node_Str")));
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsByteArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.ByteArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsIntArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.IntArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsByteArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.ByteArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsShortArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.ShortArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.objectAsIntArray) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.IntArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popRef()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.addressAsStack) {
    OPT_RegisterOperand reg=gc.temps.makeTemp(VM_TypeReference.IntArray);
    bc2ir.appendInstruction(Move.create(REF_MOVE,reg,bc2ir.popAddress()));
    bc2ir.push(reg.copyD2U());
  }
 else   if (methodName == VM_MagicNames.floatAsIntBits) {
    OPT_Operand val=bc2ir.popFloat();
    OPT_RegisterOperand op0=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Unary.create(FLOAT_AS_INT_BITS,op0,val));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.intBitsAsFloat) {
    OPT_Operand val=bc2ir.popInt();
    OPT_RegisterOperand op0=gc.temps.makeTempFloat();
    bc2ir.appendInstruction(Unary.create(INT_BITS_AS_FLOAT,op0,val));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.doubleAsLongBits) {
    OPT_Operand val=bc2ir.popDouble();
    OPT_RegisterOperand op0=gc.temps.makeTempLong();
    bc2ir.appendInstruction(Unary.create(DOUBLE_AS_LONG_BITS,op0,val));
    bc2ir.pushDual(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.longBitsAsDouble) {
    OPT_Operand val=bc2ir.popLong();
    OPT_RegisterOperand op0=gc.temps.makeTempDouble();
    bc2ir.appendInstruction(Unary.create(LONG_BITS_AS_DOUBLE,op0,val));
    bc2ir.pushDual(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getObjectType) {
    OPT_Operand val=bc2ir.popRef();
    OPT_Operand guard=bc2ir.getGuard(val);
    if (guard == null) {
      guard=new OPT_TrueGuardOperand();
    }
    OPT_RegisterOperand tibPtr=gc.temps.makeTemp(VM_TypeReference.JavaLangObjectArray);
    bc2ir.appendInstruction(GuardedUnary.create(GET_OBJ_TIB,tibPtr,val,guard));
    OPT_RegisterOperand op0;
    VM_TypeReference argType=val.getType();
    if (argType.isArrayType()) {
      op0=gc.temps.makeTemp(VM_TypeReference.VM_Array);
    }
 else {
      if (argType == VM_TypeReference.JavaLangObject || argType == VM_TypeReference.JavaLangCloneable || argType == VM_TypeReference.JavaIoSerializable) {
        op0=gc.temps.makeTemp(VM_TypeReference.VM_Type);
      }
 else {
        op0=gc.temps.makeTemp(VM_TypeReference.VM_Class);
      }
    }
    bc2ir.markGuardlessNonNull(op0);
    bc2ir.appendInstruction(Unary.create(GET_TYPE_FROM_TIB,op0,tibPtr.copyD2U()));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.getArrayLength) {
    OPT_Operand val=bc2ir.popRef();
    OPT_RegisterOperand op0=gc.temps.makeTempInt();
    bc2ir.appendInstruction(GuardedUnary.create(ARRAYLENGTH,op0,val,new OPT_TrueGuardOperand()));
    bc2ir.push(op0.copyD2U());
  }
 else   if (methodName == VM_MagicNames.invokeClassInitializer) {
    OPT_Instruction s=Call.create0(CALL,null,bc2ir.popRef(),null);
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.invokeMain) {
    OPT_Operand code=bc2ir.popRef();
    OPT_Operand args=bc2ir.popRef();
    bc2ir.appendInstruction(Call.create1(CALL,null,code,null,args));
  }
 else   if ((methodName == VM_MagicNames.invokeMethodReturningObject) || (methodName == VM_MagicNames.invokeMethodReturningVoid) || (methodName == VM_MagicNames.invokeMethodReturningLong)|| (methodName == VM_MagicNames.invokeMethodReturningDouble)|| (methodName == VM_MagicNames.invokeMethodReturningFloat)|| (methodName == VM_MagicNames.invokeMethodReturningInt)) {
    OPT_Operand spills=bc2ir.popRef();
    OPT_Operand fprs=bc2ir.popRef();
    OPT_Operand gprs=bc2ir.popRef();
    OPT_Operand code=bc2ir.popRef();
    OPT_RegisterOperand res=null;
    if (methodName == VM_MagicNames.invokeMethodReturningObject) {
      res=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
      bc2ir.push(res.copyD2U());
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningLong) {
      res=gc.temps.makeTemp(VM_TypeReference.Long);
      bc2ir.push(res.copyD2U(),VM_TypeReference.Long);
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningDouble) {
      res=gc.temps.makeTempDouble();
      bc2ir.push(res.copyD2U(),VM_TypeReference.Double);
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningFloat) {
      res=gc.temps.makeTempFloat();
      bc2ir.push(res.copyD2U(),VM_TypeReference.Float);
    }
 else     if (methodName == VM_MagicNames.invokeMethodReturningInt) {
      res=gc.temps.makeTempInt();
      bc2ir.push(res.copyD2U());
    }
    VM_Field target=VM_Entrypoints.reflectiveMethodInvokerInstructionsField;
    OPT_MethodOperand met=OPT_MethodOperand.STATIC(target);
    OPT_Instruction s=Call.create4(CALL,res,new OPT_IntConstantOperand(target.getOffset()),met,code,gprs,fprs,spills);
    bc2ir.appendInstruction(s);
  }
 else   if (methodName == VM_MagicNames.saveThreadState) {
    OPT_Operand p1=bc2ir.popRef();
    VM_Field target=VM_Entrypoints.saveThreadStateInstructionsField;
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(target);
    bc2ir.appendInstruction(Call.create1(CALL,null,new OPT_IntConstantOperand(target.getOffset()),mo,p1));
  }
 else   if (methodName == VM_MagicNames.threadSwitch) {
    OPT_Operand p2=bc2ir.popRef();
    OPT_Operand p1=bc2ir.popRef();
    VM_Field target=VM_Entrypoints.threadSwitchInstructionsField;
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(target);
    bc2ir.appendInstruction(Call.create2(CALL,null,new OPT_IntConstantOperand(target.getOffset()),mo,p1,p2));
  }
 else   if (methodName == VM_MagicNames.restoreHardwareExceptionState) {
    VM_Field target=VM_Entrypoints.restoreHardwareExceptionStateInstructionsField;
    OPT_MethodOperand mo=OPT_MethodOperand.STATIC(target);
    bc2ir.appendInstruction(Call.create1(CALL,null,new OPT_IntConstantOperand(target.getOffset()),mo,bc2ir.popRef()));
  }
 else   if (methodName == VM_MagicNames.prepareInt) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Prepare.create(PREPARE_INT,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.prepareObject) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.JavaLangObject);
    bc2ir.appendInstruction(Prepare.create(PREPARE_ADDR,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.prepareAddress) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Address);
    bc2ir.appendInstruction(Prepare.create(PREPARE_ADDR,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.prepareWord) {
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand val=gc.temps.makeTemp(VM_TypeReference.Word);
    bc2ir.appendInstruction(Prepare.create(PREPARE_ADDR,val,base,offset,null));
    bc2ir.push(val.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptInt) {
    OPT_Operand newVal=bc2ir.popInt();
    OPT_Operand oldVal=bc2ir.popInt();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_INT,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptObject) {
    OPT_Operand newVal=bc2ir.popRef();
    OPT_Operand oldVal=bc2ir.popRef();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_ADDR,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptAddress) {
    OPT_Operand newVal=bc2ir.popAddress();
    OPT_Operand oldVal=bc2ir.popAddress();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_ADDR,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (methodName == VM_MagicNames.attemptWord) {
    OPT_Operand newVal=bc2ir.pop();
    OPT_Operand oldVal=bc2ir.pop();
    OPT_Operand offset=bc2ir.popInt();
    OPT_Operand base=bc2ir.popRef();
    OPT_RegisterOperand test=gc.temps.makeTempInt();
    bc2ir.appendInstruction(Attempt.create(ATTEMPT_ADDR,test,base,offset,oldVal,newVal,null));
    bc2ir.push(test.copyD2U());
  }
 else   if (generatePolymorphicMagic(bc2ir,gc,meth,methodName)) {
    return true;
  }
 else   if (methodName == VM_MagicNames.getTimeBase) {
    OPT_RegisterOperand op0=gc.temps.makeTempLong();
    bc2ir.appendInstruction(Nullary.create(GET_TIME_BASE,op0));
    bc2ir.pushDual(op0.copyD2U());
  }
 else {
    return OPT_GenerateMachineSpecificMagic.generateMagic(bc2ir,gc,meth);
  }
  return true;
}