private static boolean checkEscapesThread (OPT_RegisterOperand use, OPT_IR ir) { OPT_Instruction inst = use.instruction; OPT_Register reg = use.register; switch (inst.getOpcode()) { case INT_ASTORE_opcode:case LONG_ASTORE_opcode: case FLOAT_ASTORE_opcode:case DOUBLE_ASTORE_opcode: case BYTE_ASTORE_opcode:case SHORT_ASTORE_opcode: case REF_ASTORE_opcode:   OPT_Operand value = AStore.getValue(inst); if (value != use) { return  false; } else { return  true; } case GETFIELD_opcode:case GETFIELD_UNRESOLVED_opcode: case GETSTATIC_opcode:case GETSTATIC_UNRESOLVED_opcode: case INT_ALOAD_opcode:case LONG_ALOAD_opcode: case FLOAT_ALOAD_opcode:case DOUBLE_ALOAD_opcode: case BYTE_ALOAD_opcode:case UBYTE_ALOAD_opcode: case BYTE_LOAD_opcode:case UBYTE_LOAD_opcode: case SHORT_ALOAD_opcode:case USHORT_ALOAD_opcode: case REF_ALOAD_opcode: case INT_LOAD_opcode: case LONG_LOAD_opcode:case REF_LOAD_opcode:  OPT_Operand result = ResultCarrier.getResult(inst); if (result != use) { return  false; } else { return  true; } case PUTFIELD_opcode:case PUTFIELD_UNRESOLVED_opcode:   value = PutField.getValue(inst); if (value != use) { return  false; } else { return  true; } case PUTSTATIC_opcode:case PUTSTATIC_UNRESOLVED_opcode:   value = PutStatic.getValue(inst); if (value != use) { return  false; } else { return  true; } case BYTE_STORE_opcode: case SHORT_STORE_opcode: case INT_STORE_opcode:  case LONG_STORE_opcode:   value = Store.getValue(inst); if (value != use) { return  false; } else { return  true; }   case BOUNDS_CHECK_opcode:case MONITORENTER_opcode: case MONITOREXIT_opcode:case NULL_CHECK_opcode: case ARRAYLENGTH_opcode:case REF_IFCMP_opcode: case INT_IFCMP_opcode:case IG_PATCH_POINT_opcode: case IG_CLASS_TEST_opcode:case IG_METHOD_TEST_opcode: case BOOLEAN_CMP_opcode:case OBJARRAY_STORE_CHECK_opcode: case OBJARRAY_STORE_CHECK_NOTNULL_opcode: case GET_OBJ_TIB_opcode: case GET_TYPE_FROM_TIB_opcode:case NEW_opcode:case NEWARRAY_opcode: case NEWOBJMULTIARRAY_opcode:case NEW_UNRESOLVED_opcode: case INSTANCEOF_opcode:case INSTANCEOF_NOTNULL_opcode: case INSTANCEOF_UNRESOLVED_opcode: case CHECKCAST_opcode: case MUST_IMPLEMENT_INTERFACE_opcode: case CHECKCAST_NOTNULL_opcode: case CHECKCAST_UNRESOLVED_opcode: case GET_CAUGHT_EXCEPTION_opcode: case IR_PROLOGUE_opcode: return  false; case RETURN_opcode:    if (ir.isParameter(use)) return  false; else { return  true; } case CALL_opcode: OPT_MethodOperand mop = Call.getMethod(inst); if (mop == null) return  true; VM_Method m = mop.method;  if (m == null) return  true; if (m.getDeclaringClass() == null) return  true; if (!m.getDeclaringClass().isLoaded()) { return  true; } if (OPT_InlineTools.needsGuard(m)) { return  true; }  OPT_MethodSummary summ = findOrCreateMethodSummary(m, ir.options); if (summ == null) {  return  true; }  if (use == Call.getResult(inst)) { if (summ.resultMayEscapeThread()) { return  true; } else { return  false; } }  int p = getParameterIndex(use, inst); if (summ.parameterMayEscapeThread(p)) {  return  true; } else { return  false; } case REF_MOVE_opcode:case ATHROW_opcode:case PREPARE_opcode: case ATTEMPT_opcode: case INT_MOVE_opcode:case INT_ADD_opcode: case INT_MUL_opcode: case INT_DIV_opcode: case INT_REM_opcode: case INT_NEG_opcode: case INT_ZERO_CHECK_opcode: case INT_OR_opcode: case INT_AND_opcode: case INT_XOR_opcode: case INT_SUB_opcode:case INT_SHL_opcode: case INT_SHR_opcode:case INT_USHR_opcode:case SYSCALL_opcode: case GET_CLASS_OBJECT_opcode:case SET_CAUGHT_EXCEPTION_opcode: case PHI_opcode: case INT_2LONG_opcode: case REF_COND_MOVE_opcode: case INT_COND_MOVE_opcode:  case GET_JTOC_opcode: case GET_CURRENT_PROCESSOR_opcode:     return  true; default: throw  new OPT_OptimizingCompilerException("OPT_SimpleEscape: Unexpected " + inst); } }   private static boolean checkEscapesMethod (OPT_RegisterOperand use, OPT_IR ir) { OPT_Instruction inst = use.instruction; OPT_Register reg = use.register; switch (inst.getOpcode()) { case INT_ASTORE_opcode:case LONG_ASTORE_opcode: case FLOAT_ASTORE_opcode:case DOUBLE_ASTORE_opcode: case BYTE_ASTORE_opcode:case SHORT_ASTORE_opcode: case REF_ASTORE_opcode:   OPT_Operand value = AStore.getValue(inst); if (value != use) { return  false; } else { return  true; } case GETFIELD_opcode:case GETFIELD_UNRESOLVED_opcode: case GETSTATIC_opcode:case GETSTATIC_UNRESOLVED_opcode: case INT_ALOAD_opcode:case LONG_ALOAD_opcode:case FLOAT_ALOAD_opcode: case DOUBLE_ALOAD_opcode:case BYTE_ALOAD_opcode:case UBYTE_ALOAD_opcode: case BYTE_LOAD_opcode:case UBYTE_LOAD_opcode: case USHORT_ALOAD_opcode:case SHORT_ALOAD_opcode:case REF_ALOAD_opcode: case INT_LOAD_opcode:case LONG_LOAD_opcode:case REF_LOAD_opcode:  OPT_Operand result = ResultCarrier.getResult(inst); if (result != use) { return  false; } else { return  true; } case PUTFIELD_opcode:case PUTFIELD_UNRESOLVED_opcode:   value = PutField.getValue(inst); if (value != use) { return  false; } else { return  true; } case PUTSTATIC_opcode:case PUTSTATIC_UNRESOLVED_opcode:   value = PutStatic.getValue(inst); if (value != use) { return  false; } else { return  true; } case BYTE_STORE_opcode:case SHORT_STORE_opcode: case INT_STORE_opcode:case LONG_STORE_opcode:   value = Store.getValue(inst); if (value != use) { return  false; } else { return  true; }   case BOUNDS_CHECK_opcode:case MONITORENTER_opcode: case MONITOREXIT_opcode:case NULL_CHECK_opcode:case ARRAYLENGTH_opcode: case REF_IFCMP_opcode:case INT_IFCMP_opcode:case IG_PATCH_POINT_opcode: case IG_CLASS_TEST_opcode:case IG_METHOD_TEST_opcode: case BOOLEAN_CMP_opcode: case OBJARRAY_STORE_CHECK_opcode: case OBJARRAY_STORE_CHECK_NOTNULL_opcode: case GET_OBJ_TIB_opcode:case GET_TYPE_FROM_TIB_opcode:case NEW_opcode: case NEWARRAY_opcode:case NEWOBJMULTIARRAY_opcode: case NEW_UNRESOLVED_opcode: case INSTANCEOF_opcode:case INSTANCEOF_NOTNULL_opcode: case INSTANCEOF_UNRESOLVED_opcode: case CHECKCAST_opcode: case MUST_IMPLEMENT_INTERFACE_opcode: case CHECKCAST_NOTNULL_opcode: case CHECKCAST_UNRESOLVED_opcode: case GET_CAUGHT_EXCEPTION_opcode: case IR_PROLOGUE_opcode: return  false; case RETURN_opcode:  return  true; case CALL_opcode:  return  true; case REF_MOVE_opcode:case ATHROW_opcode:case PREPARE_opcode: case ATTEMPT_opcode: case INT_MOVE_opcode:case INT_ADD_opcode: case INT_MUL_opcode: case INT_DIV_opcode: case INT_REM_opcode: case INT_NEG_opcode: case INT_ZERO_CHECK_opcode: case INT_OR_opcode: case INT_AND_opcode: case INT_XOR_opcode: case INT_SUB_opcode:case INT_SHL_opcode: case INT_SHR_opcode:case INT_USHR_opcode:case SYSCALL_opcode: case GET_CLASS_OBJECT_opcode:case SET_CAUGHT_EXCEPTION_opcode: case PHI_opcode: case INT_2LONG_opcode: case REF_COND_MOVE_opcode: case INT_COND_MOVE_opcode:  case GET_JTOC_opcode: case GET_CURRENT_PROCESSOR_opcode:     return  true; default: throw  new OPT_OptimizingCompilerException("OPT_SimpleEscapge: Unexpected " + inst); } }
  private AnalysisResult checkAllAppearances (OPT_Register reg, OPT_IR ir) {    AnalysisResult result = new AnalysisResult();    result.threadLocal = true;    result.methodLocal = true;    for (OPT_RegisterOperand use = reg.useList; use != null;         use = (OPT_RegisterOperand)use.getNext()) {      // if the type is primitive, just say it escapes      // TODO: handle this more cleanly      if (use.type.isPrimitiveType()) {        result.threadLocal = false;        result.methodLocal = false;        break;      }      if (checkEscapesThread(use, ir)) {        result.threadLocal = false;      }      if (checkEscapesMethod(use, ir)) {        result.methodLocal = false;      }    }    for (OPT_RegisterOperand def = reg.defList; def != null;         def = (OPT_RegisterOperand)def.getNext()) {      // if the type is primitive, just say it escapes      // TODO: handle this more cleanly      if (def.type.isPrimitiveType()) {        result.threadLocal = false;        result.methodLocal = false;        break;      }      if (checkEscapesThread(def, ir)) {        result.threadLocal = false;      }      if (checkEscapesMethod(def, ir)) {        result.methodLocal = false;      }    }    return  result;  }