Use accessor methods for Object fields.

Ensure that Object fields are modified via accessors so that it's easy
to insert barriers (make all fields within Objects private). Add validity
checks to Field and Method accessors to ensure they are accessed when a
Class is in a suitable state. Add validity checks to all Object
accessors to check heap isn't corrupted. Remove hacked in strings from Field
and Method; make type fields used the dex cache that is lazily initialized.
Clean up various other TODOs and lint issues.

Change-Id: Iac0afc515c01f5419874d9cdcdb9a7b45443e3fb
diff --git a/src/compiler/codegen/arm/ArchUtility.cc b/src/compiler/codegen/arm/ArchUtility.cc
index d643a90..dc8bdec 100644
--- a/src/compiler/codegen/arm/ArchUtility.cc
+++ b/src/compiler/codegen/arm/ArchUtility.cc
@@ -407,7 +407,7 @@
         " bytes, Dalvik size is " << insnsSize * 2;
     LOG(INFO) << "expansion factor: " <<
          (float)cUnit->totalSize / (float)(insnsSize * 2);
-    for (int i = 0; i < method->num_registers_; i++) {
+    for (int i = 0; i < method->NumRegisters(); i++) {
         RegLocation loc = cUnit->regLocation[i];
         char buf[100];
         if (loc.fpLocation == kLocPhysReg) {
diff --git a/src/compiler/codegen/arm/ArmRallocUtil.cc b/src/compiler/codegen/arm/ArmRallocUtil.cc
index 6223512..78d5267 100644
--- a/src/compiler/codegen/arm/ArmRallocUtil.cc
+++ b/src/compiler/codegen/arm/ArmRallocUtil.cc
@@ -94,7 +94,7 @@
             for (i=0; i< ssaRep->numUses; i++) {
                 int origSreg = DECODE_REG(
                     oatConvertSSARegToDalvik(cUnit, ssaRep->uses[i]));
-                assert(origSreg < cUnit->method->num_registers_);
+                assert(origSreg < cUnit->method->NumRegisters());
                 bool fpUse = ssaRep->fpUse ? ssaRep->fpUse[i] : false;
                 if (fp == fpUse) {
                     counts[origSreg].count++;
@@ -107,7 +107,7 @@
                 }
                 int origSreg = DECODE_REG(
                     oatConvertSSARegToDalvik(cUnit, ssaRep->defs[i]));
-                assert(origSreg < cUnit->method->num_registers_);
+                assert(origSreg < cUnit->method->NumRegisters());
                 bool fpDef = ssaRep->fpDef ? ssaRep->fpDef[i] : false;
                 if (fp == fpDef) {
                     counts[origSreg].count++;
@@ -139,8 +139,8 @@
  */
 extern void oatDoPromotion(CompilationUnit* cUnit)
 {
-    int numRegs = cUnit->method->num_registers_;
-    int numIns = cUnit->method->num_ins_;
+    int numRegs = cUnit->method->NumRegisters();
+    int numIns = cUnit->method->NumIns();
 
     /*
      * Because ins don't have explicit definitions, we need to type
diff --git a/src/compiler/codegen/arm/MethodCodegenDriver.cc b/src/compiler/codegen/arm/MethodCodegenDriver.cc
index c69a27e..8caf0d1 100644
--- a/src/compiler/codegen/arm/MethodCodegenDriver.cc
+++ b/src/compiler/codegen/arm/MethodCodegenDriver.cc
@@ -404,12 +404,12 @@
             break;
         case 1:  // Get the current Method->DeclaringClass() [sets r0]
             loadBaseDisp(cUnit, mir, r0,
-                         OFFSETOF_MEMBER(art::Method, declaring_class_),
+                         art::Method::DeclaringClassOffset().Int32Value(),
                          r0, kWord, INVALID_SREG);
             break;
         case 2:  // Method->DeclaringClass()->GetDexCache() [sets r0]
             loadBaseDisp(cUnit, mir, r0,
-                         OFFSETOF_MEMBER(art::Class, dex_cache_), r0, kWord,
+                         art::Class::DexCacheOffset().Int32Value(), r0, kWord,
                          INVALID_SREG);
             break;
         case 3:  // Method->DeclaringClass()->GetDexCache()->methodsObjectArr
@@ -425,7 +425,8 @@
                          kWord, INVALID_SREG);
             break;
         case 6: // Get the target compiled code address [uses r0, sets rLR]
-            loadBaseDisp(cUnit, mir, r0, art::Method::GetCodeOffset(), rLR,
+            loadBaseDisp(cUnit, mir, r0,
+                         art::Method::GetCodeOffset().Int32Value(), rLR,
                          kWord, INVALID_SREG);
             break;
         default:
@@ -502,18 +503,19 @@
             break;
         case 1:  // Get the current Method->DeclaringClass() [uses/sets r0]
             loadBaseDisp(cUnit, mir, r0,
-                         OFFSETOF_MEMBER(art::Method, declaring_class_),
+                         art::Method::DeclaringClassOffset().Int32Value(),
                          r0, kWord, INVALID_SREG);
             break;
         case 2:  // Method->DeclaringClass()->GetDexCache() [uses/sets r0]
             loadBaseDisp(cUnit, mir, r0,
-                         OFFSETOF_MEMBER(art::Class, dex_cache_), r0, kWord,
+                         art::Class::DexCacheOffset().Int32Value(),
+                         r0, kWord,
                          INVALID_SREG);
             break;
         case 3:  // ...()->GetDexCache()->methodsObjectArr [uses/sets r0]
             loadBaseDisp(cUnit, mir, r0,
-                         art::DexCache::ResolvedMethodsOffset().Int32Value(), r0,
-                         kWord, INVALID_SREG);
+                         art::DexCache::ResolvedMethodsOffset().Int32Value(),
+                         r0, kWord, INVALID_SREG);
             // Load "this" [set r1]
             rlArg = oatGetSrc(cUnit, mir, 0);
             loadValueDirectFixed(cUnit, rlArg, r1);
@@ -524,17 +526,18 @@
             // Is "this" null? [use r1]
             genNullCheck(cUnit, oatSSASrc(mir,0), r1, mir->offset, NULL);
             // get this->clazz [use r1, set rLR]
-            loadBaseDisp(cUnit, mir, r1, OFFSETOF_MEMBER(Object, klass_), rLR,
-                         kWord, INVALID_SREG);
+            loadBaseDisp(cUnit, mir, r1, Object::ClassOffset().Int32Value(),
+                         rLR, kWord, INVALID_SREG);
             // Get the base Method* [uses r0, sets r0]
             loadBaseDisp(cUnit, mir, r0, dInsn->vB * 4, r0,
                          kWord, INVALID_SREG);
             // get this->clazz->vtable [use rLR, set rLR]
             loadBaseDisp(cUnit, mir, rLR,
-                         OFFSETOF_MEMBER(Class, vtable_), rLR, kWord,
+                         Class::VTableOffset().Int32Value(), rLR, kWord,
                          INVALID_SREG);
             // Get the method index [use r0, set r12]
-            loadBaseDisp(cUnit, mir, r0, OFFSETOF_MEMBER(Method, method_index_),
+            loadBaseDisp(cUnit, mir, r0,
+                         Method::MethodIndexOffset().Int32Value(),
                          r12, kUnsignedHalf, INVALID_SREG);
             // Skip past the object header
             opRegImm(cUnit, kOpAdd, rLR, art::Array::DataOffset().Int32Value());
@@ -542,7 +545,8 @@
             loadBaseIndexed(cUnit, rLR, r12, r0, 2, kWord);
             break;
         case 5: // Get the target compiled code address [uses r0, sets rLR]
-            loadBaseDisp(cUnit, mir, r0, art::Method::GetCodeOffset(), rLR,
+            loadBaseDisp(cUnit, mir, r0,
+                         art::Method::GetCodeOffset().Int32Value(), rLR,
                          kWord, INVALID_SREG);
             break;
         default:
@@ -766,7 +770,7 @@
      * Dalvik vRegs and the ins.
      */
     int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow;
-    int boundaryReg = cUnit->method->num_registers_ - cUnit->method->num_ins_;
+    int boundaryReg = cUnit->method->NumRegisters() - cUnit->method->NumIns();
     if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) {
         LOG(FATAL) << "Argument list spanned locals & args";
     }
@@ -1628,11 +1632,13 @@
  * home location */
 static void flushIns(CompilationUnit* cUnit)
 {
-    if (cUnit->method->num_ins_ == 0)
+    if (cUnit->method->NumIns() == 0)
         return;
-    int inRegs = (cUnit->method->num_ins_ > 2) ? 3 : cUnit->method->num_ins_;
+    int inRegs = (cUnit->method->NumIns() > 2) ? 3
+                                               : cUnit->method->NumIns();
     int startReg = r1;
-    int startLoc = cUnit->method->num_registers_ - cUnit->method->num_ins_;
+    int startLoc = cUnit->method->NumRegisters() -
+        cUnit->method->NumIns();
     for (int i = 0; i < inRegs; i++) {
         RegLocation loc = cUnit->regLocation[startLoc + i];
         //TUNING: be smarter about flushing ins to frame
@@ -1654,7 +1660,7 @@
     }
 
     // Now, do initial assignment of all promoted arguments passed in frame
-    for (int i = inRegs; i < cUnit->method->num_ins_;) {
+    for (int i = inRegs; i < cUnit->method->NumIns();) {
         RegLocation loc = cUnit->regLocation[startLoc + i];
         if (loc.fpLocation == kLocPhysReg) {
             loc.location = kLocPhysReg;
diff --git a/src/compiler/codegen/arm/Thumb2/Gen.cc b/src/compiler/codegen/arm/Thumb2/Gen.cc
index 11146f7..c4a1fed 100644
--- a/src/compiler/codegen/arm/Thumb2/Gen.cc
+++ b/src/compiler/codegen/arm/Thumb2/Gen.cc
@@ -389,7 +389,7 @@
 #else
     bool isVolatile = false;
 #endif
-    int fieldOffset = fieldPtr->GetOffset();
+    int fieldOffset = fieldPtr->GetOffset().Int32Value();
     RegLocation rlResult;
     RegisterClass regClass = oatRegClassBySize(size);
     rlObj = loadValue(cUnit, rlObj, kCoreReg);
@@ -418,7 +418,7 @@
 #else
     bool isVolatile = false;
 #endif
-    int fieldOffset = fieldPtr->GetOffset();
+    int fieldOffset = fieldPtr->GetOffset().Int32Value();
     RegisterClass regClass = oatRegClassBySize(size);
     rlObj = loadValue(cUnit, rlObj, kCoreReg);
     rlSrc = loadValue(cUnit, rlSrc, regClass);
@@ -448,7 +448,7 @@
 #else
     bool isVolatile = false;
 #endif
-    int fieldOffset = fieldPtr->GetOffset();
+    int fieldOffset = fieldPtr->GetOffset().Int32Value();
     RegLocation rlResult;
     rlObj = loadValue(cUnit, rlObj, kCoreReg);
     int regPtr = oatAllocTemp(cUnit);
@@ -483,7 +483,7 @@
 #else
     bool isVolatile = false;
 #endif
-    int fieldOffset = fieldPtr->GetOffset();
+    int fieldOffset = fieldPtr->GetOffset().Int32Value();
 
     rlObj = loadValue(cUnit, rlObj, kCoreReg);
     int regPtr;
@@ -504,12 +504,12 @@
 static void genConstClass(CompilationUnit* cUnit, MIR* mir,
                           RegLocation rlDest, RegLocation rlSrc)
 {
-    art::Class* classPtr = cUnit->method->dex_cache_resolved_types_->
+    art::Class* classPtr = cUnit->method->GetDexCacheResolvedTypes()->
         Get(mir->dalvikInsn.vB);
     int mReg = loadCurrMethod(cUnit);
     int resReg = oatAllocTemp(cUnit);
     RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
-    loadWordDisp(cUnit, mReg, OFFSETOF_MEMBER(Method, dex_cache_strings_),
+    loadWordDisp(cUnit, mReg, Method::DexCacheStringsOffset().Int32Value(),
                  resReg);
     loadWordDisp(cUnit, resReg, Array::DataOffset().Int32Value() +
                  (sizeof(String*) * mir->dalvikInsn.vB), rlResult.lowReg);
@@ -547,14 +547,14 @@
                            RegLocation rlDest, RegLocation rlSrc)
 {
     /* All strings should be available at compile time */
-    const art::String* str = cUnit->method->dex_cache_strings_->
+    const art::String* str = cUnit->method->GetDexCacheStrings()->
         Get(mir->dalvikInsn.vB);
     DCHECK(str != NULL);
 
     int mReg = loadCurrMethod(cUnit);
     int resReg = oatAllocTemp(cUnit);
     RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
-    loadWordDisp(cUnit, mReg, OFFSETOF_MEMBER(Method, dex_cache_strings_),
+    loadWordDisp(cUnit, mReg, Method::DexCacheStringsOffset().Int32Value(),
                  resReg);
     loadWordDisp(cUnit, resReg, Array::DataOffset().Int32Value() +
                  (sizeof(String*) * mir->dalvikInsn.vB), rlResult.lowReg);
@@ -605,8 +605,8 @@
     /* When taken r0 has NULL which can be used for store directly */
     ArmLIR* branch1 = genCmpImmBranch(cUnit, kArmCondEq, r0, 0);
     /* r1 now contains object->clazz */
-    assert(OFFSETOF_MEMBER(Object, klass_) == 0);
-    loadWordDisp(cUnit, r0, OFFSETOF_MEMBER(Object, klass_), r1);
+    assert(Object::ClassOffset().Int32Value() == 0);
+    loadWordDisp(cUnit, r0,  Object::ClassOffset().Int32Value(), r1);
     /* r1 now contains object->clazz */
     loadWordDisp(cUnit, rSELF,
                  OFFSETOF_MEMBER(Thread, pInstanceofNonTrivialFromCode), rLR);
@@ -647,7 +647,7 @@
      *  with clazz.
      */
     /* r0 now contains object->clazz */
-    loadWordDisp(cUnit, rlSrc.lowReg, OFFSETOF_MEMBER(Object, klass_), r0);
+    loadWordDisp(cUnit, rlSrc.lowReg, Object::ClassOffset().Int32Value(), r0);
     loadWordDisp(cUnit, rSELF,
                  OFFSETOF_MEMBER(Thread, pInstanceofNonTrivialFromCode), rLR);
     opRegReg(cUnit, kOpCmp, r0, r1);
@@ -799,7 +799,7 @@
     genNullCheck(cUnit, rlSrc.sRegLow, r1, mir->offset, NULL);
     loadWordDisp(cUnit, rSELF, Thread::IdOffset().Int32Value(), r3);
     newLIR3(cUnit, kThumb2Ldrex, r2, r1,
-            OFFSETOF_MEMBER(Object, monitor_) >> 2); // Get object->lock
+            Object::MonitorOffset().Int32Value() >> 2); // Get object->lock
     // Align owner
     opRegImm(cUnit, kOpLsl, r3, art::Monitor::kLwLockOwnerShift);
     // Is lock unheld on lock or held by us (==threadId) on unlock?
@@ -809,7 +809,7 @@
             art::Monitor::kLwLockOwnerShift - 1);
     hopBranch = newLIR2(cUnit, kThumb2Cbnz, r2, 0);
     newLIR4(cUnit, kThumb2Strex, r2, r3, r1,
-            OFFSETOF_MEMBER(Object, monitor_) >> 2);
+            Object::MonitorOffset().Int32Value() >> 2);
     oatGenMemBarrier(cUnit, kSY);
     branch = newLIR2(cUnit, kThumb2Cbz, r2, 0);
 
@@ -848,7 +848,7 @@
     loadValueDirectFixed(cUnit, rlSrc, r1);  // Get obj
     oatLockCallTemps(cUnit);  // Prepare for explicit register usage
     genNullCheck(cUnit, rlSrc.sRegLow, r1, mir->offset, NULL);
-    loadWordDisp(cUnit, r1, OFFSETOF_MEMBER(Object, monitor_), r2); // Get lock
+    loadWordDisp(cUnit, r1, Object::MonitorOffset().Int32Value(), r2); // Get lock
     loadWordDisp(cUnit, rSELF, Thread::IdOffset().Int32Value(), r3);
     // Is lock unheld on lock or held by us (==threadId) on unlock?
     opRegRegImm(cUnit, kOpAnd, r12, r2, (art::Monitor::kLwHashStateMask <<
@@ -860,7 +860,7 @@
     opRegReg(cUnit, kOpSub, r2, r3);
     hopBranch = opCondBranch(cUnit, kArmCondNe);
     oatGenMemBarrier(cUnit, kSY);
-    storeWordDisp(cUnit, r1, OFFSETOF_MEMBER(Object, monitor_), r12);
+    storeWordDisp(cUnit, r1, Object::MonitorOffset().Int32Value(), r12);
     branch = opNone(cUnit, kOpUncondBr);
 
     hopTarget = newLIR0(cUnit, kArmPseudoTargetLabel);
@@ -1152,9 +1152,9 @@
     loadWordDisp(cUnit, rSELF,
                  OFFSETOF_MEMBER(Thread, pCanPutArrayElementFromCode), rLR);
     /* Get the array's clazz */
-    loadWordDisp(cUnit, r1, OFFSETOF_MEMBER(Object, klass_), r1);
+    loadWordDisp(cUnit, r1, Object::ClassOffset().Int32Value(), r1);
     /* Get the object's clazz */
-    loadWordDisp(cUnit, r0, OFFSETOF_MEMBER(Object, klass_), r0);
+    loadWordDisp(cUnit, r0, Object::ClassOffset().Int32Value(), r0);
     opReg(cUnit, kOpBlx, rLR);
     oatClobberCallRegs(cUnit);