Refactor the use of Method by the oat compiler.

Change-Id: Ib0ee18ed06846f82567f746edc7a5049dc6215df
diff --git a/src/compiler/codegen/arm/ArchUtility.cc b/src/compiler/codegen/arm/ArchUtility.cc
index 2a20efa..b702682 100644
--- a/src/compiler/codegen/arm/ArchUtility.cc
+++ b/src/compiler/codegen/arm/ArchUtility.cc
@@ -309,7 +309,7 @@
     switch(lir->opcode) {
         case kArmPseudoMethodEntry:
             LOG(INFO) << "-------- method entry " <<
-                art::PrettyMethod(cUnit->method);
+                art::PrettyMethod(cUnit->method_idx, *cUnit->dex_file);
             break;
         case kArmPseudoMethodExit:
             LOG(INFO) << "-------- Method_Exit";
@@ -380,8 +380,7 @@
 
 void oatDumpPromotionMap(CompilationUnit *cUnit)
 {
-    const Method *method = cUnit->method;
-    for (int i = 0; i < method->NumRegisters(); i++) {
+    for (int i = 0; i < cUnit->numDalvikRegisters; i++) {
         PromotionMap vRegMap = cUnit->promotionMap[i];
         char buf[100];
         if (vRegMap.fpLocation == kLocPhysReg) {
@@ -400,8 +399,7 @@
 
 void oatDumpFullPromotionMap(CompilationUnit *cUnit)
 {
-    const Method *method = cUnit->method;
-    for (int i = 0; i < method->NumRegisters(); i++) {
+    for (int i = 0; i < cUnit->numDalvikRegisters; i++) {
         PromotionMap vRegMap = cUnit->promotionMap[i];
         LOG(INFO) << i << " -> " << "CL:" << (int)vRegMap.coreLocation <<
             ", CR:" << (int)vRegMap.coreReg << ", FL:" <<
@@ -413,9 +411,9 @@
 /* Dump instructions and constant pool contents */
 void oatCodegenDump(CompilationUnit* cUnit)
 {
-    const Method *method = cUnit->method;
     LOG(INFO) << "/*";
-    LOG(INFO) << "Dumping LIR insns for " << art::PrettyMethod(cUnit->method);
+    LOG(INFO) << "Dumping LIR insns for "
+        << art::PrettyMethod(cUnit->method_idx, *cUnit->dex_file);
     LIR* lirInsn;
     ArmLIR* armLIR;
     int insnsSize = cUnit->insnsSize;
@@ -449,10 +447,12 @@
             armLIR->generic.offset, armLIR->generic.offset, armLIR->operands[0]);
     }
 
-    std::string signature = method->GetSignature()->ToModifiedUtf8();
-    std::string name = method->GetName()->ToModifiedUtf8();
-    std::string descriptor = method->GetDeclaringClass()->GetDescriptor()->
-        ToModifiedUtf8();
+    const art::DexFile::MethodId& method_id =
+        cUnit->dex_file->GetMethodId(cUnit->method_idx);
+    std::string signature = cUnit->dex_file->GetMethodSignature(method_id);
+    std::string name = cUnit->dex_file->GetMethodName(method_id);
+    std::string descriptor =
+        cUnit->dex_file->GetMethodDeclaringClassDescriptor(method_id);
 
     // Dump mapping table
     if (cUnit->mappingTable.size() > 0) {
diff --git a/src/compiler/codegen/arm/ArmRallocUtil.cc b/src/compiler/codegen/arm/ArmRallocUtil.cc
index 81c721d..5d2c4e6 100644
--- a/src/compiler/codegen/arm/ArmRallocUtil.cc
+++ b/src/compiler/codegen/arm/ArmRallocUtil.cc
@@ -111,7 +111,7 @@
  */
 extern void oatDoPromotion(CompilationUnit* cUnit)
 {
-    int numRegs = cUnit->method->NumRegisters();
+    int numRegs = cUnit->numDalvikRegisters;
 
     /*
      * TUNING: is leaf?  Can't just use "hasInvoke" to determine as some
diff --git a/src/compiler/codegen/arm/CodegenCommon.cc b/src/compiler/codegen/arm/CodegenCommon.cc
index 4a2768c..9b71b14 100644
--- a/src/compiler/codegen/arm/CodegenCommon.cc
+++ b/src/compiler/codegen/arm/CodegenCommon.cc
@@ -283,7 +283,7 @@
     DCHECK(isPseudoOpcode(opcode) ||
            (EncodingMap[opcode].flags & IS_TERTIARY_OP))
             << (int)opcode << " "
-            << PrettyMethod(cUnit->method) << " "
+            << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " "
             << cUnit->currentDalvikOffset;
     insn->opcode = opcode;
     insn->operands[0] = dest;
diff --git a/src/compiler/codegen/arm/MethodCodegenDriver.cc b/src/compiler/codegen/arm/MethodCodegenDriver.cc
index a32446a..7a719f7 100644
--- a/src/compiler/codegen/arm/MethodCodegenDriver.cc
+++ b/src/compiler/codegen/arm/MethodCodegenDriver.cc
@@ -47,12 +47,15 @@
 {
     oatFlushAllRegs(cUnit);    /* Everything to home location */
     uint32_t type_idx = mir->dalvikInsn.vC;
-    if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method, type_idx)) {
+    if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
+                                                    cUnit->dex_cache,
+                                                    *cUnit->dex_file,
+                                                    type_idx)) {
         loadWordDisp(cUnit, rSELF,
                      OFFSETOF_MEMBER(Thread, pAllocArrayFromCode), rLR);
     } else {
         UNIMPLEMENTED(WARNING) << "Need to check access of '"
-                               << PrettyMethod(cUnit->method)
+                               << PrettyMethod(cUnit->method_idx, *cUnit->dex_file)
                                << "' to unresolved type " << type_idx;
         loadWordDisp(cUnit, rSELF,
                      OFFSETOF_MEMBER(Thread, pAllocArrayFromCode), rLR);
@@ -79,9 +82,13 @@
     oatFlushAllRegs(cUnit);    /* Everything to home location */
     loadWordDisp(cUnit, rSELF,
                  OFFSETOF_MEMBER(Thread, pCheckAndAllocArrayFromCode), rLR);
-    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method, typeId)) {
-        UNIMPLEMENTED(WARNING) << "Need to check access of '" << PrettyMethod(cUnit->method)
-                               << "' to unresolved type " << typeId;
+    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
+                                                     cUnit->dex_cache,
+                                                     *cUnit->dex_file,
+                                                     typeId)) {
+        UNIMPLEMENTED(WARNING) << "Need to check access of '"
+            << PrettyMethod(cUnit->method_idx, *cUnit->dex_file)
+            << "' to unresolved type " << typeId;
     }
     loadCurrMethodDirect(cUnit, r1);              // arg1 <- Method*
     loadConstant(cUnit, r0, typeId);              // arg0 <- type_id
@@ -158,11 +165,14 @@
     }
 }
 
-Field* FindFieldWithResolvedStaticStorage(const Method* method,
+Field* FindFieldWithResolvedStaticStorage(CompilationUnit* cUnit,
                                           const uint32_t fieldIdx,
                                           uint32_t& resolvedTypeIdx) {
-    art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
-    Field* field = class_linker->ResolveField(fieldIdx, method, true);
+    Field* field = cUnit->class_linker->ResolveField(*cUnit->dex_file,
+                                                     fieldIdx,
+                                                     cUnit->dex_cache,
+                                                     cUnit->class_loader,
+                                                     true);
     if (field == NULL) {
         Thread* thread = Thread::Current();
         if (thread->IsExceptionPending()) {  // clear any exception left by resolve field
@@ -170,11 +180,9 @@
         }
         return NULL;
     }
-    const art::DexFile& dex_file = class_linker->
-            FindDexFile(method->GetDeclaringClass()->GetDexCache());
-    const art::DexFile::FieldId& field_id = dex_file.GetFieldId(fieldIdx);
+    const art::DexFile::FieldId& field_id = cUnit->dex_file->GetFieldId(fieldIdx);
     int type_idx = field_id.class_idx_;
-    Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx);
+    Class* klass = cUnit->dex_cache->GetResolvedTypes()->Get(type_idx);
     // Check if storage class is the same as class referred to by type idx.
     // They may not be if the FieldId refers a subclass, but storage is in super
     if (field->GetDeclaringClass() == klass) {
@@ -185,14 +193,18 @@
     // we may not if the dex file never references the super class,
     // but usually it will.
     std::string descriptor = field->GetDeclaringClass()->GetDescriptor()->ToModifiedUtf8();
-    for (size_t type_idx = 0; type_idx < dex_file.NumTypeIds(); type_idx++) {
-        const art::DexFile::TypeId& type_id = dex_file.GetTypeId(type_idx);
-        if (descriptor == dex_file.GetTypeDescriptor(type_id)) {
-            resolvedTypeIdx = type_idx;
-            return field;
-        }
+    const art::DexFile::StringId* string_id =
+        cUnit->dex_file->FindStringId(descriptor);
+    if (string_id == NULL) {
+        return NULL;  // descriptor not found, resort to slow path
     }
-    return NULL;  // resort to slow path
+    const art::DexFile::TypeId* type_id =
+        cUnit->dex_file->FindTypeId(cUnit->dex_file->GetIndexForStringId(*string_id));
+    if (type_id == NULL) {
+        return NULL;  // type id not found, resort to slow path
+    }
+    resolvedTypeIdx = cUnit->dex_file->GetIndexForTypeId(*type_id);
+    return field;
 }
 
 STATIC void genSput(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
@@ -201,7 +213,7 @@
                      (mir->dalvikInsn.opcode == OP_SPUT_OBJECT_VOLATILE));
     int fieldIdx = mir->dalvikInsn.vB;
     uint32_t typeIdx;
-    Field* field = FindFieldWithResolvedStaticStorage(cUnit->method, fieldIdx, typeIdx);
+    Field* field = FindFieldWithResolvedStaticStorage(cUnit, fieldIdx, typeIdx);
     oatFlushAllRegs(cUnit);
     if (SLOW_FIELD_PATH || field == NULL) {
         // Slow path
@@ -261,7 +273,7 @@
 {
     int fieldIdx = mir->dalvikInsn.vB;
     uint32_t typeIdx;
-    Field* field = FindFieldWithResolvedStaticStorage(cUnit->method, fieldIdx, typeIdx);
+    Field* field = FindFieldWithResolvedStaticStorage(cUnit, fieldIdx, typeIdx);
     oatFlushAllRegs(cUnit);
 #if ANDROID_SMP != 0
     bool isVolatile = (field == NULL) || field->IsVolatile();
@@ -312,7 +324,7 @@
 {
     int fieldIdx = mir->dalvikInsn.vB;
     uint32_t typeIdx;
-    Field* field = FindFieldWithResolvedStaticStorage(cUnit->method, fieldIdx, typeIdx);
+    Field* field = FindFieldWithResolvedStaticStorage(cUnit, fieldIdx, typeIdx);
 #if ANDROID_SMP != 0
     bool isVolatile = (field == NULL) || field->IsVolatile();
 #else
@@ -364,7 +376,7 @@
 {
     int fieldIdx = mir->dalvikInsn.vB;
     uint32_t typeIdx;
-    Field* field = FindFieldWithResolvedStaticStorage(cUnit->method, fieldIdx, typeIdx);
+    Field* field = FindFieldWithResolvedStaticStorage(cUnit, fieldIdx, typeIdx);
     bool isObject = ((mir->dalvikInsn.opcode == OP_SGET_OBJECT) ||
                      (mir->dalvikInsn.opcode == OP_SGET_OBJECT_VOLATILE));
     oatFlushAllRegs(cUnit);
@@ -466,8 +478,11 @@
      * This is the fast path in which the target virtual method is
      * fully resolved at compile time.
      */
-    art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
-    Method* baseMethod = class_linker->ResolveMethod(dInsn->vB, cUnit->method, false);
+    Method* baseMethod = cUnit->class_linker->ResolveMethod(*cUnit->dex_file,
+                                                            dInsn->vB,
+                                                            cUnit->dex_cache,
+                                                            cUnit->class_loader,
+                                                            false);
     CHECK(baseMethod != NULL);
     uint32_t target_idx = baseMethod->GetMethodIndex();
     switch(state) {
@@ -631,9 +646,16 @@
      * within the size of the super's vtable has been done at compile-time.
      */
     art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
-    Method* baseMethod = class_linker->ResolveMethod(dInsn->vB, cUnit->method, false);
+    Method* baseMethod = class_linker->ResolveMethod(*cUnit->dex_file,
+                                                     dInsn->vB,
+                                                     cUnit->dex_cache,
+                                                     cUnit->class_loader,
+                                                     false);
     CHECK(baseMethod != NULL);
-    Class* superClass = cUnit->method->GetDeclaringClass()->GetSuperClass();
+    Class* declaring_class = cUnit->dex_cache->GetResolvedTypes()
+        ->Get(cUnit->dex_file->GetMethodId(cUnit->method_idx).class_idx_);
+    Class* superClass = (declaring_class != NULL)
+        ? declaring_class->GetSuperClass() : NULL;
     CHECK(superClass != NULL);
     int32_t target_idx = baseMethod->GetMethodIndex();
     CHECK(superClass->GetVTable()->GetLength() > target_idx);
@@ -872,7 +894,7 @@
      * Dalvik vRegs and the ins.
      */
     int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow;
-    int boundaryReg = cUnit->method->NumRegisters() - cUnit->method->NumIns();
+    int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns;
     if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) {
         LOG(FATAL) << "Argument list spanned locals & args";
     }
@@ -971,7 +993,7 @@
     // Is this the special "Ljava/lang/Object;.<init>:()V" case?
     if (mir->dalvikInsn.opcode == OP_INVOKE_DIRECT) {
         int idx = mir->dalvikInsn.vB;
-        Method* target = cUnit->method->GetDexCacheResolvedMethods()->Get(idx);
+        Method* target = cUnit->dex_cache->GetResolvedMethods()->Get(idx);
         if (target) {
             if (PrettyMethod(target) == "java.lang.Object.<init>()V") {
                 RegLocation rlArg = oatGetSrc(cUnit, mir, 0);
@@ -1043,7 +1065,11 @@
     int callState = 0;
     ArmLIR* rollback;
     art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
-    Method* baseMethod = class_linker->ResolveMethod(dInsn->vB, cUnit->method, false);
+    Method* baseMethod = class_linker->ResolveMethod(*cUnit->dex_file,
+                                                     dInsn->vB,
+                                                     cUnit->dex_cache,
+                                                     cUnit->class_loader,
+                                                     false);
     NextCallInsn nextCallInsn;
     bool fastPath = true;
     oatFlushAllRegs(cUnit);    /* Everything to home location */
@@ -1057,7 +1083,10 @@
         }
         fastPath = false;
     } else {
-        Class* superClass = cUnit->method->GetDeclaringClass()->GetSuperClass();
+        Class* declaring_class = cUnit->dex_cache->GetResolvedTypes()
+            ->Get(cUnit->dex_file->GetMethodId(cUnit->method_idx).class_idx_);
+        Class* superClass = (declaring_class != NULL)
+            ? declaring_class->GetSuperClass() : NULL;
         if (superClass == NULL) {
             fastPath = false;
         } else {
@@ -1100,7 +1129,11 @@
     int callState = 0;
     ArmLIR* rollback;
     art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
-    Method* method = class_linker->ResolveMethod(dInsn->vB, cUnit->method, false);
+    Method* method = class_linker->ResolveMethod(*cUnit->dex_file,
+                                                 dInsn->vB,
+                                                 cUnit->dex_cache,
+                                                 cUnit->class_loader,
+                                                 false);
     NextCallInsn nextCallInsn;
     oatFlushAllRegs(cUnit);    /* Everything to home location */
 
@@ -1825,12 +1858,11 @@
  */
 STATIC void flushIns(CompilationUnit* cUnit)
 {
-    if (cUnit->method->NumIns() == 0)
+    if (cUnit->numIns == 0)
         return;
     int firstArgReg = r1;
     int lastArgReg = r3;
-    int startVReg = cUnit->method->NumRegisters() -
-        cUnit->method->NumIns();
+    int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
     /*
      * Arguments passed in registers should be flushed
      * to their backing locations in the frame for now.
@@ -1842,7 +1874,7 @@
      * cases, copy argument to both.  This will be uncommon
      * enough that it isn't worth attempting to optimize.
      */
-    for (int i = 0; i < cUnit->method->NumIns(); i++) {
+    for (int i = 0; i < cUnit->numIns; i++) {
         PromotionMap vMap = cUnit->promotionMap[startVReg + i];
         if (i <= (lastArgReg - firstArgReg)) {
             // If arriving in register
diff --git a/src/compiler/codegen/arm/Thumb2/Gen.cc b/src/compiler/codegen/arm/Thumb2/Gen.cc
index 006be69..b02cde5 100644
--- a/src/compiler/codegen/arm/Thumb2/Gen.cc
+++ b/src/compiler/codegen/arm/Thumb2/Gen.cc
@@ -33,21 +33,13 @@
 
 STATIC RegLocation getRetLoc(CompilationUnit* cUnit);
 
-std::string fieldNameFromIndex(const Method* method, uint32_t fieldIdx)
-{
-    art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
-    const art::DexFile& dex_file = class_linker->FindDexFile(
-         method->GetDeclaringClass()->GetDexCache());
-    const art::DexFile::FieldId& field_id = dex_file.GetFieldId(fieldIdx);
-    std::string class_name = dex_file.StringByTypeIdx(field_id.class_idx_);
-    std::string field_name = dex_file.StringDataByIdx(field_id.name_idx_);
-    return class_name + "." + field_name;
-}
-
 void warnIfUnresolved(CompilationUnit* cUnit, int fieldIdx, Field* field) {
   if (field == NULL) {
-    LOG(INFO) << "Field " << fieldNameFromIndex(cUnit->method, fieldIdx)
-              << " unresolved at compile time";
+    const art::DexFile::FieldId& field_id = cUnit->dex_file->GetFieldId(fieldIdx);
+    std::string class_name = cUnit->dex_file->GetFieldDeclaringClassDescriptor(field_id);
+    std::string field_name = cUnit->dex_file->GetFieldName(field_id);
+    LOG(INFO) << "Field " << art::PrettyDescriptor(class_name) << "."
+        << field_name << " unresolved at compile time";
   } else {
     // We also use the slow path for wide volatile fields.
   }
@@ -455,8 +447,7 @@
 STATIC void genIGet(CompilationUnit* cUnit, MIR* mir, OpSize size,
                      RegLocation rlDest, RegLocation rlObj)
 {
-    Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
-        GetResolvedField(mir->dalvikInsn.vC);
+    Field* fieldPtr = cUnit->dex_cache->GetResolvedField(mir->dalvikInsn.vC);
     RegLocation rlResult;
     RegisterClass regClass = oatRegClassBySize(size);
     if (SLOW_FIELD_PATH || fieldPtr == NULL) {
@@ -490,8 +481,7 @@
 STATIC void genIPut(CompilationUnit* cUnit, MIR* mir, OpSize size,
                     RegLocation rlSrc, RegLocation rlObj, bool isObject)
 {
-    Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
-        GetResolvedField(mir->dalvikInsn.vC);
+    Field* fieldPtr = cUnit->dex_cache->GetResolvedField(mir->dalvikInsn.vC);
     RegisterClass regClass = oatRegClassBySize(size);
     if (SLOW_FIELD_PATH || fieldPtr == NULL) {
         getFieldOffset(cUnit, mir, fieldPtr);
@@ -530,8 +520,7 @@
                         RegLocation rlObj)
 {
     RegLocation rlResult;
-    Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
-        GetResolvedField(mir->dalvikInsn.vC);
+    Field* fieldPtr = cUnit->dex_cache->GetResolvedField(mir->dalvikInsn.vC);
 #if ANDROID_SMP != 0
     bool isVolatile = (fieldPtr == NULL) || fieldPtr->IsVolatile();
 #else
@@ -568,8 +557,7 @@
 STATIC void genIPutWide(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc,
                         RegLocation rlObj)
 {
-    Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
-        GetResolvedField(mir->dalvikInsn.vC);
+    Field* fieldPtr = cUnit->dex_cache->GetResolvedField(mir->dalvikInsn.vC);
 #if ANDROID_SMP != 0
     bool isVolatile = (fieldPtr == NULL) || fieldPtr->IsVolatile();
 #else
@@ -607,16 +595,28 @@
     int mReg = loadCurrMethod(cUnit);
     int resReg = oatAllocTemp(cUnit);
     RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
-    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method, type_idx)) {
-        // Check we have access to type_idx and if not throw IllegalAccessError
-        UNIMPLEMENTED(FATAL);
+    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
+                                                     cUnit->dex_cache,
+                                                     *cUnit->dex_file,
+                                                     type_idx)) {
+        // Call out to helper which resolves type and verifies access.
+        // Resolved type returned in r0.
+        loadWordDisp(cUnit, rSELF,
+                     OFFSETOF_MEMBER(Thread, pInitializeTypeAndVerifyAccessFromCode),
+                     rLR);
+        genRegCopy(cUnit, r1, mReg);
+        loadConstant(cUnit, r0, type_idx);
+        callRuntimeHelper(cUnit, rLR);
+        RegLocation rlResult = oatGetReturn(cUnit);
+        storeValue(cUnit, rlDest, rlResult);
     } else {
         // We're don't need access checks, load type from dex cache
         int32_t dex_cache_offset = Method::DexCacheResolvedTypesOffset().Int32Value();
         loadWordDisp(cUnit, mReg, dex_cache_offset, resReg);
         int32_t offset_of_type = Array::DataOffset().Int32Value() + (sizeof(Class*) * type_idx);
         loadWordDisp(cUnit, resReg, offset_of_type, rlResult.lowReg);
-        if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->method, type_idx) ||
+        if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache,
+                                                               type_idx) ||
             SLOW_TYPE_PATH) {
             // Slow path, at runtime test if the type is null and if so initialize
             oatFlushAllRegs(cUnit);
@@ -652,7 +652,7 @@
     /* NOTE: Most strings should be available at compile time */
     uint32_t string_idx = mir->dalvikInsn.vB;
     int32_t offset_of_string = Array::DataOffset().Int32Value() + (sizeof(String*) * string_idx);
-    if (!cUnit->compiler->CanAssumeStringIsPresentInDexCache(cUnit->method, string_idx) ||
+    if (!cUnit->compiler->CanAssumeStringIsPresentInDexCache(cUnit->dex_cache, string_idx) ||
         SLOW_STRING_PATH) {
         // slow path, resolve string if not in dex cache
         oatFlushAllRegs(cUnit);
@@ -694,7 +694,10 @@
     uint32_t type_idx = mir->dalvikInsn.vB;
     // alloc will always check for resolution, do we also need to verify access because the
     // verifier was unable to?
-    if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method, type_idx)) {
+    if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
+                                                    cUnit->dex_cache,
+                                                    *cUnit->dex_file,
+                                                    type_idx)) {
         loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pAllocObjectFromCode), rLR);
     } else {
         loadWordDisp(cUnit, rSELF,
@@ -724,7 +727,10 @@
     uint32_t type_idx = mir->dalvikInsn.vC;
     loadCurrMethodDirect(cUnit, r1);  // r1 <= current Method*
     int classReg = r2;  // r2 will hold the Class*
-    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method, type_idx)) {
+    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
+                                                     cUnit->dex_cache,
+                                                     *cUnit->dex_file,
+                                                     type_idx)) {
         // Check we have access to type_idx and if not throw IllegalAccessError,
         // returns Class* in r0
         loadWordDisp(cUnit, rSELF,
@@ -740,7 +746,7 @@
         loadWordDisp(cUnit, r1, Method::DexCacheResolvedTypesOffset().Int32Value(), classReg);
         int32_t offset_of_type = Array::DataOffset().Int32Value() + (sizeof(Class*) * type_idx);
         loadWordDisp(cUnit, classReg, offset_of_type, classReg);
-        if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->method, type_idx)) {
+        if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache, type_idx)) {
             // Need to test presence of type in dex cache at runtime
             ArmLIR* hopBranch = genCmpImmBranch(cUnit, kArmCondNe, classReg, 0);
             // Not resolved
@@ -787,7 +793,10 @@
     uint32_t type_idx = mir->dalvikInsn.vB;
     loadCurrMethodDirect(cUnit, r1);  // r1 <= current Method*
     int classReg = r2;  // r2 will hold the Class*
-    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method, type_idx)) {
+    if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
+                                                     cUnit->dex_cache,
+                                                     *cUnit->dex_file,
+                                                     type_idx)) {
         // Check we have access to type_idx and if not throw IllegalAccessError,
         // returns Class* in r0
         loadWordDisp(cUnit, rSELF,
@@ -801,7 +810,7 @@
         loadWordDisp(cUnit, r1, Method::DexCacheResolvedTypesOffset().Int32Value(), classReg);
         int32_t offset_of_type = Array::DataOffset().Int32Value() + (sizeof(Class*) * type_idx);
         loadWordDisp(cUnit, classReg, offset_of_type, classReg);
-        if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->method, type_idx)) {
+        if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache, type_idx)) {
             // Need to test presence of type in dex cache at runtime
             ArmLIR* hopBranch = genCmpImmBranch(cUnit, kArmCondNe, classReg, 0);
             // Not resolved
@@ -1793,7 +1802,7 @@
 /* Check if we need to check for pending suspend request */
 STATIC void genSuspendTest(CompilationUnit* cUnit, MIR* mir)
 {
-    if (NO_SUSPEND || mir->optimizationFlags & MIR_IGNORE_SUSPEND_CHECK) {
+    if (NO_SUSPEND || (mir->optimizationFlags & MIR_IGNORE_SUSPEND_CHECK)) {
         return;
     }
     oatFlushAllRegs(cUnit);