Updating the compiler to use the new-world model
New compiler is integrated and passes first test (Fibonacci).
Change-Id: Ic5448ab89ebd22baa30fafc3d1300324687d1fc2
diff --git a/src/compiler/CompilerIR.h b/src/compiler/CompilerIR.h
index 02b5dfa..643e795 100644
--- a/src/compiler/CompilerIR.h
+++ b/src/compiler/CompilerIR.h
@@ -18,6 +18,7 @@
#define ART_SRC_COMPILER_COMPILER_IR_H_
#include "codegen/Optimizer.h"
+#include <vector>
typedef enum RegisterClass {
kCoreReg,
@@ -197,8 +198,7 @@
int totalSize; // header + code size
AssemblerStatus assemblerStatus; // Success or fix and retry
int assemblerRetries;
- unsigned char* codeBuffer;
- void* baseAddr;
+ std::vector<short>codeBuffer;
bool printMe;
bool printMeVerbose;
bool hasClassLiterals; // Contains class ptrs used as literals
diff --git a/src/compiler/Dalvik.h b/src/compiler/Dalvik.h
index 4e93c9c..a9ddcd8 100644
--- a/src/compiler/Dalvik.h
+++ b/src/compiler/Dalvik.h
@@ -24,12 +24,14 @@
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
-#include "../logging.h"
+#include "logging.h"
+#include "object.h"
+#include "thread.h"
+#include "class_linker.h"
+#include "dex_cache.h"
+#include "utils.h"
// From Common.h
-#define MIN(x,y) (((x) < (y)) ? (x) : (y))
-#define MAX(x,y) (((x) > (y)) ? (x) : (y))
-
typedef uint8_t u1;
typedef uint16_t u2;
typedef uint32_t u4;
@@ -40,667 +42,27 @@
typedef int64_t s8;
typedef unsigned long long u8;
-struct Object;
+//Skip old DexFile.h
+#define LIBDEX_DEXFILE_H_
+//Skip old vm/Common.h
+#define DALVIK_COMMON_H_
+//Make inlines inline
+#define DEX_INLINE inline
+#include "DexOpcodes.h"
+#include "InstrUtils.h"
-union JValue {
- u1 z;
- s1 b;
- u2 c;
- s2 s;
- s4 i;
- s8 j;
- float f;
- double d;
- Object* l;
-};
-
-
-// From libdex/DexOpcodes.h
-#define kNumPackedOpcodes 0x200
-#define kPackedSwitchSignature 0x0100
-#define kSparseSwitchSignature 0x0200
-#define kArrayDataSignature 0x0300
-enum Opcode {
- // BEGIN(libdex-opcode-enum); GENERATED AUTOMATICALLY BY opcode-gen
- OP_NOP = 0x00,
- OP_MOVE = 0x01,
- OP_MOVE_FROM16 = 0x02,
- OP_MOVE_16 = 0x03,
- OP_MOVE_WIDE = 0x04,
- OP_MOVE_WIDE_FROM16 = 0x05,
- OP_MOVE_WIDE_16 = 0x06,
- OP_MOVE_OBJECT = 0x07,
- OP_MOVE_OBJECT_FROM16 = 0x08,
- OP_MOVE_OBJECT_16 = 0x09,
- OP_MOVE_RESULT = 0x0a,
- OP_MOVE_RESULT_WIDE = 0x0b,
- OP_MOVE_RESULT_OBJECT = 0x0c,
- OP_MOVE_EXCEPTION = 0x0d,
- OP_RETURN_VOID = 0x0e,
- OP_RETURN = 0x0f,
- OP_RETURN_WIDE = 0x10,
- OP_RETURN_OBJECT = 0x11,
- OP_CONST_4 = 0x12,
- OP_CONST_16 = 0x13,
- OP_CONST = 0x14,
- OP_CONST_HIGH16 = 0x15,
- OP_CONST_WIDE_16 = 0x16,
- OP_CONST_WIDE_32 = 0x17,
- OP_CONST_WIDE = 0x18,
- OP_CONST_WIDE_HIGH16 = 0x19,
- OP_CONST_STRING = 0x1a,
- OP_CONST_STRING_JUMBO = 0x1b,
- OP_CONST_CLASS = 0x1c,
- OP_MONITOR_ENTER = 0x1d,
- OP_MONITOR_EXIT = 0x1e,
- OP_CHECK_CAST = 0x1f,
- OP_INSTANCE_OF = 0x20,
- OP_ARRAY_LENGTH = 0x21,
- OP_NEW_INSTANCE = 0x22,
- OP_NEW_ARRAY = 0x23,
- OP_FILLED_NEW_ARRAY = 0x24,
- OP_FILLED_NEW_ARRAY_RANGE = 0x25,
- OP_FILL_ARRAY_DATA = 0x26,
- OP_THROW = 0x27,
- OP_GOTO = 0x28,
- OP_GOTO_16 = 0x29,
- OP_GOTO_32 = 0x2a,
- OP_PACKED_SWITCH = 0x2b,
- OP_SPARSE_SWITCH = 0x2c,
- OP_CMPL_FLOAT = 0x2d,
- OP_CMPG_FLOAT = 0x2e,
- OP_CMPL_DOUBLE = 0x2f,
- OP_CMPG_DOUBLE = 0x30,
- OP_CMP_LONG = 0x31,
- OP_IF_EQ = 0x32,
- OP_IF_NE = 0x33,
- OP_IF_LT = 0x34,
- OP_IF_GE = 0x35,
- OP_IF_GT = 0x36,
- OP_IF_LE = 0x37,
- OP_IF_EQZ = 0x38,
- OP_IF_NEZ = 0x39,
- OP_IF_LTZ = 0x3a,
- OP_IF_GEZ = 0x3b,
- OP_IF_GTZ = 0x3c,
- OP_IF_LEZ = 0x3d,
- OP_UNUSED_3E = 0x3e,
- OP_UNUSED_3F = 0x3f,
- OP_UNUSED_40 = 0x40,
- OP_UNUSED_41 = 0x41,
- OP_UNUSED_42 = 0x42,
- OP_UNUSED_43 = 0x43,
- OP_AGET = 0x44,
- OP_AGET_WIDE = 0x45,
- OP_AGET_OBJECT = 0x46,
- OP_AGET_BOOLEAN = 0x47,
- OP_AGET_BYTE = 0x48,
- OP_AGET_CHAR = 0x49,
- OP_AGET_SHORT = 0x4a,
- OP_APUT = 0x4b,
- OP_APUT_WIDE = 0x4c,
- OP_APUT_OBJECT = 0x4d,
- OP_APUT_BOOLEAN = 0x4e,
- OP_APUT_BYTE = 0x4f,
- OP_APUT_CHAR = 0x50,
- OP_APUT_SHORT = 0x51,
- OP_IGET = 0x52,
- OP_IGET_WIDE = 0x53,
- OP_IGET_OBJECT = 0x54,
- OP_IGET_BOOLEAN = 0x55,
- OP_IGET_BYTE = 0x56,
- OP_IGET_CHAR = 0x57,
- OP_IGET_SHORT = 0x58,
- OP_IPUT = 0x59,
- OP_IPUT_WIDE = 0x5a,
- OP_IPUT_OBJECT = 0x5b,
- OP_IPUT_BOOLEAN = 0x5c,
- OP_IPUT_BYTE = 0x5d,
- OP_IPUT_CHAR = 0x5e,
- OP_IPUT_SHORT = 0x5f,
- OP_SGET = 0x60,
- OP_SGET_WIDE = 0x61,
- OP_SGET_OBJECT = 0x62,
- OP_SGET_BOOLEAN = 0x63,
- OP_SGET_BYTE = 0x64,
- OP_SGET_CHAR = 0x65,
- OP_SGET_SHORT = 0x66,
- OP_SPUT = 0x67,
- OP_SPUT_WIDE = 0x68,
- OP_SPUT_OBJECT = 0x69,
- OP_SPUT_BOOLEAN = 0x6a,
- OP_SPUT_BYTE = 0x6b,
- OP_SPUT_CHAR = 0x6c,
- OP_SPUT_SHORT = 0x6d,
- OP_INVOKE_VIRTUAL = 0x6e,
- OP_INVOKE_SUPER = 0x6f,
- OP_INVOKE_DIRECT = 0x70,
- OP_INVOKE_STATIC = 0x71,
- OP_INVOKE_INTERFACE = 0x72,
- OP_UNUSED_73 = 0x73,
- OP_INVOKE_VIRTUAL_RANGE = 0x74,
- OP_INVOKE_SUPER_RANGE = 0x75,
- OP_INVOKE_DIRECT_RANGE = 0x76,
- OP_INVOKE_STATIC_RANGE = 0x77,
- OP_INVOKE_INTERFACE_RANGE = 0x78,
- OP_UNUSED_79 = 0x79,
- OP_UNUSED_7A = 0x7a,
- OP_NEG_INT = 0x7b,
- OP_NOT_INT = 0x7c,
- OP_NEG_LONG = 0x7d,
- OP_NOT_LONG = 0x7e,
- OP_NEG_FLOAT = 0x7f,
- OP_NEG_DOUBLE = 0x80,
- OP_INT_TO_LONG = 0x81,
- OP_INT_TO_FLOAT = 0x82,
- OP_INT_TO_DOUBLE = 0x83,
- OP_LONG_TO_INT = 0x84,
- OP_LONG_TO_FLOAT = 0x85,
- OP_LONG_TO_DOUBLE = 0x86,
- OP_FLOAT_TO_INT = 0x87,
- OP_FLOAT_TO_LONG = 0x88,
- OP_FLOAT_TO_DOUBLE = 0x89,
- OP_DOUBLE_TO_INT = 0x8a,
- OP_DOUBLE_TO_LONG = 0x8b,
- OP_DOUBLE_TO_FLOAT = 0x8c,
- OP_INT_TO_BYTE = 0x8d,
- OP_INT_TO_CHAR = 0x8e,
- OP_INT_TO_SHORT = 0x8f,
- OP_ADD_INT = 0x90,
- OP_SUB_INT = 0x91,
- OP_MUL_INT = 0x92,
- OP_DIV_INT = 0x93,
- OP_REM_INT = 0x94,
- OP_AND_INT = 0x95,
- OP_OR_INT = 0x96,
- OP_XOR_INT = 0x97,
- OP_SHL_INT = 0x98,
- OP_SHR_INT = 0x99,
- OP_USHR_INT = 0x9a,
- OP_ADD_LONG = 0x9b,
- OP_SUB_LONG = 0x9c,
- OP_MUL_LONG = 0x9d,
- OP_DIV_LONG = 0x9e,
- OP_REM_LONG = 0x9f,
- OP_AND_LONG = 0xa0,
- OP_OR_LONG = 0xa1,
- OP_XOR_LONG = 0xa2,
- OP_SHL_LONG = 0xa3,
- OP_SHR_LONG = 0xa4,
- OP_USHR_LONG = 0xa5,
- OP_ADD_FLOAT = 0xa6,
- OP_SUB_FLOAT = 0xa7,
- OP_MUL_FLOAT = 0xa8,
- OP_DIV_FLOAT = 0xa9,
- OP_REM_FLOAT = 0xaa,
- OP_ADD_DOUBLE = 0xab,
- OP_SUB_DOUBLE = 0xac,
- OP_MUL_DOUBLE = 0xad,
- OP_DIV_DOUBLE = 0xae,
- OP_REM_DOUBLE = 0xaf,
- OP_ADD_INT_2ADDR = 0xb0,
- OP_SUB_INT_2ADDR = 0xb1,
- OP_MUL_INT_2ADDR = 0xb2,
- OP_DIV_INT_2ADDR = 0xb3,
- OP_REM_INT_2ADDR = 0xb4,
- OP_AND_INT_2ADDR = 0xb5,
- OP_OR_INT_2ADDR = 0xb6,
- OP_XOR_INT_2ADDR = 0xb7,
- OP_SHL_INT_2ADDR = 0xb8,
- OP_SHR_INT_2ADDR = 0xb9,
- OP_USHR_INT_2ADDR = 0xba,
- OP_ADD_LONG_2ADDR = 0xbb,
- OP_SUB_LONG_2ADDR = 0xbc,
- OP_MUL_LONG_2ADDR = 0xbd,
- OP_DIV_LONG_2ADDR = 0xbe,
- OP_REM_LONG_2ADDR = 0xbf,
- OP_AND_LONG_2ADDR = 0xc0,
- OP_OR_LONG_2ADDR = 0xc1,
- OP_XOR_LONG_2ADDR = 0xc2,
- OP_SHL_LONG_2ADDR = 0xc3,
- OP_SHR_LONG_2ADDR = 0xc4,
- OP_USHR_LONG_2ADDR = 0xc5,
- OP_ADD_FLOAT_2ADDR = 0xc6,
- OP_SUB_FLOAT_2ADDR = 0xc7,
- OP_MUL_FLOAT_2ADDR = 0xc8,
- OP_DIV_FLOAT_2ADDR = 0xc9,
- OP_REM_FLOAT_2ADDR = 0xca,
- OP_ADD_DOUBLE_2ADDR = 0xcb,
- OP_SUB_DOUBLE_2ADDR = 0xcc,
- OP_MUL_DOUBLE_2ADDR = 0xcd,
- OP_DIV_DOUBLE_2ADDR = 0xce,
- OP_REM_DOUBLE_2ADDR = 0xcf,
- OP_ADD_INT_LIT16 = 0xd0,
- OP_RSUB_INT = 0xd1,
- OP_MUL_INT_LIT16 = 0xd2,
- OP_DIV_INT_LIT16 = 0xd3,
- OP_REM_INT_LIT16 = 0xd4,
- OP_AND_INT_LIT16 = 0xd5,
- OP_OR_INT_LIT16 = 0xd6,
- OP_XOR_INT_LIT16 = 0xd7,
- OP_ADD_INT_LIT8 = 0xd8,
- OP_RSUB_INT_LIT8 = 0xd9,
- OP_MUL_INT_LIT8 = 0xda,
- OP_DIV_INT_LIT8 = 0xdb,
- OP_REM_INT_LIT8 = 0xdc,
- OP_AND_INT_LIT8 = 0xdd,
- OP_OR_INT_LIT8 = 0xde,
- OP_XOR_INT_LIT8 = 0xdf,
- OP_SHL_INT_LIT8 = 0xe0,
- OP_SHR_INT_LIT8 = 0xe1,
- OP_USHR_INT_LIT8 = 0xe2,
- OP_IGET_VOLATILE = 0xe3,
- OP_IPUT_VOLATILE = 0xe4,
- OP_SGET_VOLATILE = 0xe5,
- OP_SPUT_VOLATILE = 0xe6,
- OP_IGET_OBJECT_VOLATILE = 0xe7,
- OP_IGET_WIDE_VOLATILE = 0xe8,
- OP_IPUT_WIDE_VOLATILE = 0xe9,
- OP_SGET_WIDE_VOLATILE = 0xea,
- OP_SPUT_WIDE_VOLATILE = 0xeb,
- OP_BREAKPOINT = 0xec,
- OP_THROW_VERIFICATION_ERROR = 0xed,
- OP_EXECUTE_INLINE = 0xee,
- OP_EXECUTE_INLINE_RANGE = 0xef,
- OP_INVOKE_OBJECT_INIT_RANGE = 0xf0,
- OP_RETURN_VOID_BARRIER = 0xf1,
- OP_IGET_QUICK = 0xf2,
- OP_IGET_WIDE_QUICK = 0xf3,
- OP_IGET_OBJECT_QUICK = 0xf4,
- OP_IPUT_QUICK = 0xf5,
- OP_IPUT_WIDE_QUICK = 0xf6,
- OP_IPUT_OBJECT_QUICK = 0xf7,
- OP_INVOKE_VIRTUAL_QUICK = 0xf8,
- OP_INVOKE_VIRTUAL_QUICK_RANGE = 0xf9,
- OP_INVOKE_SUPER_QUICK = 0xfa,
- OP_INVOKE_SUPER_QUICK_RANGE = 0xfb,
- OP_IPUT_OBJECT_VOLATILE = 0xfc,
- OP_SGET_OBJECT_VOLATILE = 0xfd,
- OP_SPUT_OBJECT_VOLATILE = 0xfe,
-};
+typedef art::JValue JValue;
+typedef art::Thread Thread;
+typedef art::Class Class;
+typedef art::Array Array;
+typedef art::Method Method;
+typedef art::Object Object;
+typedef art::Field Field;
+typedef art::String String;
// From alloc/CardTable.h
#define GC_CARD_SHIFT 7
-// From all/Alloc.h
-/* flags for dvmMalloc */
-enum {
- ALLOC_DEFAULT = 0x00,
- ALLOC_DONT_TRACK = 0x01, /* don't add to internal tracking list */
- ALLOC_NON_MOVING = 0x02,
-};
-
-
-// From oo/Object.h
-struct ClassObject;
-struct ArrayObject;
-struct DvmDex;
-struct Method;
-
-struct Object {
- ClassObject* clazz;
- u4 lock;
- Method** vtable;
- int vtableCount;
- u4 accessFlags;
-};
-
-struct ArrayObject : Object {
- u4 length;
- u8 contents[1];
-};
-
-struct ClassObject : Object {
- const char* descriptor;
- DvmDex* pDvmDex;
- ClassObject* super;
-};
-
-// From InstrUtils.h
-enum InstructionFormat {
- kFmt00x = 0, // unknown format (also used for "breakpoint" opcode)
- kFmt10x, // op
- kFmt12x, // op vA, vB
- kFmt11n, // op vA, #+B
- kFmt11x, // op vAA
- kFmt10t, // op +AA
- kFmt20bc, // [opt] op AA, thing@BBBB
- kFmt20t, // op +AAAA
- kFmt22x, // op vAA, vBBBB
- kFmt21t, // op vAA, +BBBB
- kFmt21s, // op vAA, #+BBBB
- kFmt21h, // op vAA, #+BBBB00000[00000000]
- kFmt21c, // op vAA, thing@BBBB
- kFmt23x, // op vAA, vBB, vCC
- kFmt22b, // op vAA, vBB, #+CC
- kFmt22t, // op vA, vB, +CCCC
- kFmt22s, // op vA, vB, #+CCCC
- kFmt22c, // op vA, vB, thing@CCCC
- kFmt22cs, // [opt] op vA, vB, field offset CCCC
- kFmt30t, // op +AAAAAAAA
- kFmt32x, // op vAAAA, vBBBB
- kFmt31i, // op vAA, #+BBBBBBBB
- kFmt31t, // op vAA, +BBBBBBBB
- kFmt31c, // op vAA, string@BBBBBBBB
- kFmt35c, // op {vC,vD,vE,vF,vG}, thing@BBBB
- kFmt35ms, // [opt] invoke-virtual+super
- kFmt3rc, // op {vCCCC .. v(CCCC+AA-1)}, thing@BBBB
- kFmt3rms, // [opt] invoke-virtual+super/range
- kFmt51l, // op vAA, #+BBBBBBBBBBBBBBBB
- kFmt35mi, // [opt] inline invoke
- kFmt3rmi, // [opt] inline invoke/range
- kFmt33x, // exop vAA, vBB, vCCCC
- kFmt32s, // exop vAA, vBB, #+CCCC
- kFmt40sc, // [opt] exop AAAA, thing@BBBBBBBB
- kFmt41c, // exop vAAAA, thing@BBBBBBBB
- kFmt52c, // exop vAAAA, vBBBB, thing@CCCCCCCC
- kFmt5rc, // exop {vCCCC .. v(CCCC+AAAA-1)}, thing@BBBBBBBB
-};
-
-enum InstructionIndexType {
- kIndexUnknown = 0,
- kIndexNone, // has no index
- kIndexVaries, // "It depends." Used for throw-verification-error
- kIndexTypeRef, // type reference index
- kIndexStringRef, // string reference index
- kIndexMethodRef, // method reference index
- kIndexFieldRef, // field reference index
- kIndexInlineMethod, // inline method index (for inline linked methods)
- kIndexVtableOffset, // vtable offset (for static linked methods)
- kIndexFieldOffset // field offset (for static linked fields)
-};
-
-typedef u1 InstructionWidth;
-
-typedef u1 OpcodeFlags;
-enum OpcodeFlagsBits {
- kInstrCanBranch = 1, // conditional or unconditional branch
- kInstrCanContinue = 1 << 1, // flow can continue to next statement
- kInstrCanSwitch = 1 << 2, // switch statement
- kInstrCanThrow = 1 << 3, // could cause an exception to be thrown
- kInstrCanReturn = 1 << 4, // returns, no additional statements
- kInstrInvoke = 1 << 5, // a flavor of invoke
-};
-
-struct InstructionInfoTables {
- u1* formats; /* InstructionFormat elements */
- u1* indexTypes; /* InstructionIndexType elements */
- OpcodeFlags* flags;
- InstructionWidth* widths;
-};
-
-extern InstructionInfoTables gDexOpcodeInfo;
-
-struct DecodedInstruction {
- u4 vA;
- u4 vB;
- u8 vB_wide; /* for kFmt51l */
- u4 vC;
- u4 arg[5]; /* vC/D/E/F/G in invoke or filled-new-array */
- Opcode opcode;
- InstructionIndexType indexType;
-};
-
-#define DEX_INLINE inline
-#define INLINE inline
-
-DEX_INLINE size_t dexGetWidthFromOpcode(Opcode opcode)
-{
- assert((u4) opcode < kNumPackedOpcodes);
- return gDexOpcodeInfo.widths[opcode];
-}
-
-size_t dexGetWidthFromInstruction(const u2* insns);
-
-DEX_INLINE OpcodeFlags dexGetFlagsFromOpcode(Opcode opcode)
-{
- assert((u4) opcode < kNumPackedOpcodes);
- return gDexOpcodeInfo.flags[opcode];
-}
-
-DEX_INLINE bool dexIsGoto(OpcodeFlags flags)
-{
- return (flags & (kInstrCanBranch | kInstrCanContinue)) == kInstrCanBranch;
-}
-
-DEX_INLINE InstructionFormat dexGetFormatFromOpcode(Opcode opcode)
-{
- assert((u4) opcode < kNumPackedOpcodes);
- return (InstructionFormat) gDexOpcodeInfo.formats[opcode];
-}
-
-DEX_INLINE InstructionIndexType dexGetIndexTypeFromOpcode(Opcode opcode)
-{
- assert((u4) opcode < kNumPackedOpcodes);
- return (InstructionIndexType) gDexOpcodeInfo.indexTypes[opcode];
-}
-
-void dexDecodeInstruction(const u2* insns, DecodedInstruction* pDec);
-
-// From DexOpcodes
-const char* dexGetOpcodeName(Opcode op);
-
-DEX_INLINE Opcode dexOpcodeFromCodeUnit(u2 codeUnit) {
- int lowByte = codeUnit & 0xff;
- if (lowByte != 0xff) {
- return (Opcode) lowByte;
- } else {
- return (Opcode) ((codeUnit >> 8) | 0x100);
- }
-}
-
-// From DexFile
-struct DexFile;
-struct DexTry {
- u4 startAddr; /* start address, in 16-bit code units */
- u2 insnCount; /* instruction count, in 16-bit code units */
- u2 handlerOff; /* offset in encoded handler data to handlers */
-};
-struct DexCode {
- u2 registersSize;
- u2 insSize;
- u2 outsSize;
- u2 triesSize;
- u4 debugInfoOff; /* file offset to debug info stream */
- u4 insnsSize; /* size of the insns array, in u2 units */
- u2 insns[1];
-};
-
-DEX_INLINE const DexTry* dexGetTries(const DexCode* pCode) {
- const u2* insnsEnd = &pCode->insns[pCode->insnsSize];
-
- // Round to four bytes.
- if ((((u4) insnsEnd) & 3) != 0) {
- insnsEnd++;
- }
-
- return (const DexTry*) insnsEnd;
-}
-
-enum {
- ACC_PUBLIC = 0x00000001, // class, field, method, ic
- ACC_PRIVATE = 0x00000002, // field, method, ic
- ACC_PROTECTED = 0x00000004, // field, method, ic
- ACC_STATIC = 0x00000008, // field, method, ic
- ACC_FINAL = 0x00000010, // class, field, method, ic
- ACC_SYNCHRONIZED = 0x00000020, // method (only allowed on natives)
- ACC_SUPER = 0x00000020, // class (not used in Dalvik)
- ACC_VOLATILE = 0x00000040, // field
- ACC_BRIDGE = 0x00000040, // method (1.5)
- ACC_TRANSIENT = 0x00000080, // field
- ACC_VARARGS = 0x00000080, // method (1.5)
- ACC_NATIVE = 0x00000100, // method
- ACC_INTERFACE = 0x00000200, // class, ic
- ACC_ABSTRACT = 0x00000400, // class, method, ic
- ACC_STRICT = 0x00000800, // method
- ACC_SYNTHETIC = 0x00001000, // field, method, ic
- ACC_ANNOTATION = 0x00002000, // class, ic (1.5)
- ACC_ENUM = 0x00004000, // class, field, ic (1.5)
- ACC_CONSTRUCTOR = 0x00010000, // method (Dalvik only)
- ACC_DECLARED_SYNCHRONIZED =
- 0x00020000, // method (Dalvik only)
- ACC_CLASS_MASK =
- (ACC_PUBLIC | ACC_FINAL | ACC_INTERFACE | ACC_ABSTRACT
- | ACC_SYNTHETIC | ACC_ANNOTATION | ACC_ENUM),
- ACC_INNER_CLASS_MASK =
- (ACC_CLASS_MASK | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC),
- ACC_FIELD_MASK =
- (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL
- | ACC_VOLATILE | ACC_TRANSIENT | ACC_SYNTHETIC | ACC_ENUM),
- ACC_METHOD_MASK =
- (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL
- | ACC_SYNCHRONIZED | ACC_BRIDGE | ACC_VARARGS | ACC_NATIVE
- | ACC_ABSTRACT | ACC_STRICT | ACC_SYNTHETIC | ACC_CONSTRUCTOR
- | ACC_DECLARED_SYNCHRONIZED),
-};
-
-// From DexProto
-struct DexProto {
- const DexFile* dexFile; /* file the idx refers to */
- u4 protoIdx; /* index into proto_ids table of dexFile */
-};
-char* dexProtoCopyMethodDescriptor(const DexProto* pProto);
-
-// From DexCatch.h
-struct DexCatchHandler {
- u4 typeIdx; /* type index of the caught exception type */
- u4 address; /* handler address */
-};
-struct DexCatchIterator {
- const u1* pEncodedData;
- bool catchesAll;
- u4 countRemaining;
- DexCatchHandler handler;
-};
-bool dexFindCatchHandler(DexCatchIterator *pIterator,
- const DexCode* pCode, u4 address);
-DexCatchHandler* dexCatchIteratorNext(DexCatchIterator* pIterator);
-u4 dexGetFirstHandlerOffset(const DexCode* pCode);
-u4 dexGetHandlersSize(const DexCode* pCode);
-u4 dexCatchIteratorGetEndOffset(DexCatchIterator* pIterator,
- const DexCode* pCode);
-void dexCatchIteratorInit(DexCatchIterator* pIterator,
- const DexCode* pCode, u4 offset);
-
-
-
-// From DvmDex.h
-struct Field;
-struct StringObject;
-struct DvmDex {
- struct Method** pResMethods;
- struct ClassObject** pResClasses;
- struct Field** pResFields;
- struct StringObject** pResStrings;
-};
-
-// from oo/Object.h
-struct Method {
- ClassObject* clazz;
- u2 methodIndex;
- u2 registersSize;
- u2 outsSize;
- u2 insSize;
- u4 accessFlags;
- const char* name;
- const char* shorty;
- DexProto prototype;
- void* compiledInsns;
- DvmDex* pDvmDex;
- u2* insns;
- struct Method** pResMethods;
-};
-
-struct Field {
- ClassObject* clazz; /* class in which the field is declared */
- const char* name;
- const char* signature; /* e.g. "I", "[C", "Landroid/os/Debug;" */
- u4 accessFlags;
-};
-
-struct InstField : Field {
- int byteOffset;
-};
-/*
- * Static field.
- */
-struct StaticField : Field {
- JValue value; /* initially set from DEX for primitives */
-};
-
-INLINE bool dvmIsVolatileField(const Field* field) {
- return (field->accessFlags & ACC_VOLATILE) != 0;
-}
-
-INLINE bool dvmIsBytecodeMethod(const Method* method) {
- return (method->accessFlags & (ACC_NATIVE | ACC_ABSTRACT)) == 0;
-}
-
-INLINE const DexCode* dvmGetMethodCode(const Method* meth) {
- if (dvmIsBytecodeMethod(meth)) {
- return (const DexCode*)
- (((const u1*) meth->insns) - offsetof(DexCode, insns));
- } else {
- return NULL;
- }
-}
-
-// From Thread.h
-struct Thread {
-
- u4 threadId;
- u1* cardTable;
- Object* exception;
-
- /* Runtime support function pointers */
- void* (*pMemcpy)(void*, const void*, size_t);
- float (*pI2f)(int);
- int (*pF2iz)(float);
- float (*pD2f)(double);
- double (*pF2d)(float);
- double (*pI2d)(int);
- int (*pD2iz)(double);
- float (*pL2f)(long);
- double (*pL2d)(long);
- s8 (*pArtF2l)(float);
- s8 (*pArtD2l)(double);
- float (*pFadd)(float, float);
- float (*pFsub)(float, float);
- float (*pFdiv)(float, float);
- float (*pFmul)(float, float);
- float (*pFmodf)(float, float);
- double (*pDadd)(double, double);
- double (*pDsub)(double, double);
- double (*pDdiv)(double, double);
- double (*pDmul)(double, double);
- double (*pFmod)(double, double);
- int (*pIdivmod)(int, int);
- int (*pIdiv)(int, int);
- long long (*pLdivmod)(long long, long long);
- bool (*pArtUnlockObject)(struct Thread*, struct Object*);
- bool (*pArtCanPutArrayElementNoThrow)(const ClassObject*,
- const ClassObject*);
- int (*pArtInstanceofNonTrivialNoThrow)
- (const ClassObject*, const ClassObject*);
- int (*pArtInstanceofNonTrivial) (const ClassObject*, const ClassObject*);
- ArrayObject* (*pArtAllocArrayByClass)(ClassObject*, size_t, int);
- Method* (*pArtFindInterfaceMethodInCache)(ClassObject*, u4, const Method*,
- DvmDex*);
- bool (*pArtUnlockObjectNoThrow)(Thread*, Object*);
- void (*pArtLockObjectNoThrow)(Thread*, Object*);
- Object* (*pArtAllocObjectNoThrow)(ClassObject*, int);
- void (*pArtThrowException)(Thread*, Object*);
- bool (*pArtHandleFillArrayDataNoThrow)(ArrayObject*, const u2*);
-
-};
-
-// From Sync.h
-#define LW_LOCK_OWNER_SHIFT 3
-#define LW_HASH_STATE_SHIFT 1
-#define LW_HASH_STATE_MASK 0x3
-#define LW_SHAPE_THIN 0
-
-
#include "Compiler.h"
#endif
diff --git a/src/compiler/Dataflow.cc b/src/compiler/Dataflow.cc
index 41bf8bc..5cfddc0 100644
--- a/src/compiler/Dataflow.cc
+++ b/src/compiler/Dataflow.cc
@@ -2092,11 +2092,11 @@
* blocks.
*/
bb->dataFlowInfo->dalvikToSSAMap =
- (int *)oatNew(sizeof(int) * cUnit->method->registersSize,
+ (int *)oatNew(sizeof(int) * cUnit->method->num_registers_,
false);
memcpy(bb->dataFlowInfo->dalvikToSSAMap, cUnit->dalvikToSSAMap,
- sizeof(int) * cUnit->method->registersSize);
+ sizeof(int) * cUnit->method->num_registers_);
return true;
}
@@ -2184,7 +2184,7 @@
void oatInitializeSSAConversion(CompilationUnit* cUnit)
{
int i;
- int numDalvikReg = cUnit->method->registersSize;
+ int numDalvikReg = cUnit->method->num_registers_;
cUnit->ssaToDalvikMap = (GrowableList *)oatNew(sizeof(GrowableList),
false);
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index b5d4e3f..7d38faa 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -17,6 +17,7 @@
#include "Dalvik.h"
#include "CompilerInternals.h"
#include "Dataflow.h"
+#include "constants.h"
static inline bool contentIsInsn(const u2* codePtr) {
u2 instr = *codePtr;
@@ -185,21 +186,15 @@
/* Dump the CFG into a DOT graph */
void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix)
{
- const Method* method = cUnit->method;
FILE* file;
- char* signature = dexProtoCopyMethodDescriptor(&method->prototype);
+ std::string name = art::PrettyMethod(cUnit->method, true);
char startOffset[80];
sprintf(startOffset, "_%x", cUnit->entryBlock->fallThrough->startOffset);
char* fileName = (char *) oatNew(
- strlen(dirPrefix) +
- strlen(method->clazz->descriptor) +
- strlen(method->name) +
- strlen(signature) +
- strlen(startOffset) +
- strlen(".dot") + 1, true);
- sprintf(fileName, "%s%s%s%s%s.dot", dirPrefix,
- method->clazz->descriptor, method->name, signature, startOffset);
- free(signature);
+ strlen(dirPrefix) +
+ name.length() +
+ strlen(".dot") + 1, true);
+ sprintf(fileName, "%s%s%s.dot", dirPrefix, name.c_str(), startOffset);
/*
* Convert the special characters into a filesystem- and shell-friendly
@@ -397,6 +392,9 @@
/* Identify code range in try blocks and set up the empty catch blocks */
static void processTryCatchBlocks(CompilationUnit* cUnit)
{
+
+ UNIMPLEMENTED(WARNING) << "Need to finish processTryCatchBlocks()";
+#if 0
const Method* meth = cUnit->method;
const DexCode *pCode = dvmGetMethodCode(meth);
int triesSize = pCode->triesSize;
@@ -450,6 +448,7 @@
offset = dexCatchIteratorGetEndOffset(&iterator, pCode);
}
+#endif
}
/* Process instructions with the kInstrCanBranch flag */
@@ -612,6 +611,8 @@
ArenaBitVector* tryBlockAddr, const u2* codePtr,
const u2* codeEnd)
{
+ UNIMPLEMENTED(WARNING) << "Need to complete processCanThrow";
+#if 0
const Method* method = cUnit->method;
const DexCode* dexCode = dvmGetMethodCode(method);
@@ -688,17 +689,22 @@
}
}
}
+#endif
}
/*
* Compile a method.
*/
-bool oatCompileMethod(Method* method, OatInstructionSetType insnSet)
+bool oatCompileMethod(Method* method, art::InstructionSet insnSet)
{
CompilationUnit cUnit;
- const DexCode* dexCode = dvmGetMethodCode(method);
- const u2* codePtr = dexCode->insns;
- const u2* codeEnd = dexCode->insns + dexCode->insnsSize;
+ art::ClassLinker* class_linker = art::Runtime::Current()->GetClassLinker();
+ const art::DexFile& dex_file = class_linker->FindDexFile(
+ method->GetDeclaringClass()->GetDexCache());
+ const art::DexFile::CodeItem* code_item =
+ dex_file.GetCodeItem(method->code_off_);
+ const u2* codePtr = code_item->insns_;
+ const u2* codeEnd = code_item->insns_ + code_item->insns_size_;
int numBlocks = 0;
unsigned int curOffset = 0;
@@ -709,9 +715,9 @@
memset(&cUnit, 0, sizeof(cUnit));
cUnit.method = method;
- cUnit.instructionSet = insnSet;
- cUnit.insns = dexCode->insns;
- cUnit.insnsSize = dexCode->insnsSize;
+ cUnit.instructionSet = (OatInstructionSetType)insnSet;
+ cUnit.insns = code_item->insns_;
+ cUnit.insnsSize = code_item->insns_size_;
#if 1
cUnit.printMe = true;
cUnit.printMeVerbose = true;
@@ -842,7 +848,7 @@
}
/* Adjust this value accordingly once inlining is performed */
- cUnit.numDalvikRegisters = cUnit.method->registersSize;
+ cUnit.numDalvikRegisters = cUnit.method->num_registers_;
/* Verify if all blocks are connected as claimed */
@@ -880,8 +886,12 @@
}
}
- method->compiledInsns = (void*)((int)cUnit.baseAddr | 1);
- method->pResMethods = method->clazz->pDvmDex->pResMethods;
+ method->SetCode((const art::byte*)&cUnit.codeBuffer[0],
+ cUnit.codeBuffer.size() * 2, art::kThumb2);
+ method->SetFrameSize(cUnit.frameSize);
+ method->SetCoreSpillMask(cUnit.coreSpillMask);
+ method->SetFpSpillMask(cUnit.fpSpillMask);
+ // TODO: Transmit mapping table to caller
#if 0
oatDumpCFG(&cUnit, "/sdcard/cfg/");
diff --git a/src/compiler/HackStubs.cc b/src/compiler/HackStubs.cc
deleted file mode 100644
index 9bdd733..0000000
--- a/src/compiler/HackStubs.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Dalvik.h"
-
-/* Hacky stubs for old-word functionality */
-InstructionInfoTables gDexOpcodeInfo;
-
-const char* dexGetOpcodeName(Opcode op) { return NULL; }
-
-void dexDecodeInstruction(unsigned short const* insns,
- DecodedInstruction* pDec) {}
-
-char* dexProtoCopyMethodDescriptor(DexProto const* gProto) {return NULL;}
-
-u4 dexGetFirstHandlerOffset(DexCode const* pCode) { return 0; }
-
-u4 dexGetHandlersSize(DexCode const* pCode) { return 0; }
-
-void dexCatchIteratorInit(DexCatchIterator* pIterator,
- DexCode const* pCode, unsigned int offset) {}
-
-DexCatchHandler* dexCatchIteratorNext(DexCatchIterator* pCode) { return NULL; }
-
-u4 dexCatchIteratorGetEndOffset(DexCatchIterator* pIterator,
- DexCode const* pCode) { return 0; }
-
-bool dexFindCatchHandler(DexCatchIterator* pIterator, DexCode const* pCode,
- unsigned int address) { return false; }
diff --git a/src/compiler/Ralloc.cc b/src/compiler/Ralloc.cc
index dbc93b9..c8b7632 100644
--- a/src/compiler/Ralloc.cc
+++ b/src/compiler/Ralloc.cc
@@ -119,9 +119,9 @@
}
/* Figure out the frame size */
- cUnit->numIns = cUnit->method->insSize;
- cUnit->numRegs = cUnit->method->registersSize - cUnit->numIns;
- cUnit->numOuts = cUnit->method->outsSize;
+ cUnit->numIns = cUnit->method->num_ins_;
+ cUnit->numRegs = cUnit->method->num_registers_ - cUnit->numIns;
+ cUnit->numOuts = cUnit->method->num_outs_;
cUnit->numPadding = (STACK_ALIGN_WORDS -
(cUnit->numSpills + cUnit->numRegs +
cUnit->numOuts + 2)) & (STACK_ALIGN_WORDS-1);
diff --git a/src/compiler/SSATransformation.cc b/src/compiler/SSATransformation.cc
index a843d51..42e855d 100644
--- a/src/compiler/SSATransformation.cc
+++ b/src/compiler/SSATransformation.cc
@@ -107,8 +107,8 @@
* Also set the incoming parameters as defs in the entry block.
* Only need to handle the parameters for the outer method.
*/
- int inReg = cUnit->method->registersSize - cUnit->method->insSize;
- for (; inReg < cUnit->method->registersSize; inReg++) {
+ int inReg = cUnit->method->num_registers_ - cUnit->method->num_ins_;
+ for (; inReg < cUnit->method->num_registers_; inReg++) {
oatSetBit(cUnit->defBlockMatrix[inReg],
cUnit->entryBlock->id);
}
diff --git a/src/compiler/Utility.cc b/src/compiler/Utility.cc
index b4dd80c..9c010b5 100644
--- a/src/compiler/Utility.cc
+++ b/src/compiler/Utility.cc
@@ -164,8 +164,7 @@
"Catch Block"
};
- LOG(INFO) << "Compiling " << cUnit->method->clazz->descriptor << " " <<
- cUnit->method->name;
+ LOG(INFO) << "Compiling " << art::PrettyMethod(cUnit->method, true);
LOG(INFO) << cUnit->insns << " insns";
LOG(INFO) << cUnit->numBlocks << " blocks in total";
GrowableListIterator iterator;
diff --git a/src/compiler/codegen/arm/ArchUtility.cc b/src/compiler/codegen/arm/ArchUtility.cc
index 16a0200..2f3af44 100644
--- a/src/compiler/codegen/arm/ArchUtility.cc
+++ b/src/compiler/codegen/arm/ArchUtility.cc
@@ -318,8 +318,7 @@
switch(lir->opcode) {
case kArmPseudoMethodEntry:
LOG(INFO) << "-------- method entry " <<
- cUnit->method->clazz->descriptor << ":" <<
- cUnit->method->name;
+ art::PrettyMethod(cUnit->method, true);
break;
case kArmPseudoMethodExit:
LOG(INFO) << "-------- Method_Exit";
@@ -390,8 +389,8 @@
{
const Method *method = cUnit->method;
LOG(INFO) << "/*";
- LOG(INFO) << "Dumping LIR insns for " << method->clazz->descriptor <<
- ":" << method->name;
+ LOG(INFO) << "Dumping LIR insns for " <<
+ art::PrettyMethod(cUnit->method, true);
LIR* lirInsn;
ArmLIR* armLIR;
int insnsSize = cUnit->insnsSize;
@@ -408,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->registersSize; i++) {
+ for (int i = 0; i < method->num_registers_; i++) {
RegLocation loc = cUnit->regLocation[i];
char buf[100];
if (loc.fpLocation == kLocPhysReg) {
@@ -425,41 +424,42 @@
}
for (lirInsn = cUnit->firstLIRInsn; lirInsn; lirInsn = lirInsn->next) {
- oatDumpLIRInsn(cUnit, lirInsn, (unsigned char*) cUnit->baseAddr);
+ oatDumpLIRInsn(cUnit, lirInsn, 0);
}
for (lirInsn = cUnit->classPointerList; lirInsn; lirInsn = lirInsn->next) {
armLIR = (ArmLIR*) lirInsn;
char buf[100];
- snprintf(buf, 100, "%p (%04x): .class (%s)",
- (char*)cUnit->baseAddr + armLIR->generic.offset,
- armLIR->generic.offset,
+ snprintf(buf, 100, "%x (%04x): .class (%s)",
+ armLIR->generic.offset, armLIR->generic.offset,
((CallsiteInfo *) armLIR->operands[0])->classDescriptor);
LOG(INFO) << buf;
}
for (lirInsn = cUnit->literalList; lirInsn; lirInsn = lirInsn->next) {
armLIR = (ArmLIR*) lirInsn;
char buf[100];
- snprintf(buf, 100, "%p (%04x): .word (%#x)",
- (char*)cUnit->baseAddr + armLIR->generic.offset,
- armLIR->generic.offset,
+ snprintf(buf, 100, "%x (%04x): .word (%#x)",
+ armLIR->generic.offset, armLIR->generic.offset,
armLIR->operands[0]);
LOG(INFO) << buf;
}
int linebreak = 0;
+ std::string signature = method->GetSignature()->ToModifiedUtf8();
+ std::string name = method->GetName()->ToModifiedUtf8();
+ std::string descriptor = method->GetDeclaringClass()->GetDescriptor()->
+ ToModifiedUtf8();
+
char buf[100];
LOG(INFO) << "*/";
- sprintf(buf,"\n u1 %s%s_%s_code[] = {",
- cUnit->method->clazz->descriptor, cUnit->method->name,
- cUnit->method->shorty);
+ sprintf(buf,"\n u1 %s%s_%s_code[] = {", descriptor.c_str(),
+ name.c_str(), signature.c_str());
for (unsigned int i = 0; i < strlen(buf); i++)
if (buf[i] == ';') buf[i] = '_';
LOG(INFO) << buf;
strcpy(buf," ");
- for (int i = 0; i < cUnit->totalSize; i++) {
- sprintf(buf+strlen(buf),"0x%02x,",
- ((u1*)cUnit->baseAddr)[i]);
+ for (int i = 0; i < cUnit->totalSize/2; i++) {
+ sprintf(buf+strlen(buf),"0x%04x,", cUnit->codeBuffer[i]);
if (++linebreak == 8) {
linebreak = 0;
LOG(INFO) << buf;
@@ -478,8 +478,8 @@
LOG(FATAL) << "Null table";
}
sprintf(buf,"\n MappingTable %s%s_%s_mappingTable[%d] = {",
- cUnit->method->clazz->descriptor, cUnit->method->name,
- cUnit->method->shorty, cUnit->mappingTableSize);
+ descriptor.c_str(), name.c_str(), signature.c_str(),
+ cUnit->mappingTableSize);
for (unsigned int i = 0; i < strlen(buf); i++)
if (buf[i] == ';') buf[i] = '_';
LOG(INFO) << buf;
diff --git a/src/compiler/codegen/arm/ArmRallocUtil.cc b/src/compiler/codegen/arm/ArmRallocUtil.cc
index 2fc1603..0a0c9bc 100644
--- a/src/compiler/codegen/arm/ArmRallocUtil.cc
+++ b/src/compiler/codegen/arm/ArmRallocUtil.cc
@@ -86,7 +86,7 @@
for (i=0; i< ssaRep->numUses; i++) {
int origSreg = DECODE_REG(
oatConvertSSARegToDalvik(cUnit, ssaRep->uses[i]));
- assert(origSreg < cUnit->method->registersSize);
+ assert(origSreg < cUnit->method->num_registers_);
bool fpUse = ssaRep->fpUse ? ssaRep->fpUse[i] : false;
if (fp == fpUse) {
counts[origSreg].count++;
@@ -99,7 +99,7 @@
}
int origSreg = DECODE_REG(
oatConvertSSARegToDalvik(cUnit, ssaRep->defs[i]));
- assert(origSreg < cUnit->method->registersSize);
+ assert(origSreg < cUnit->method->num_registers_);
bool fpDef = ssaRep->fpDef ? ssaRep->fpDef[i] : false;
if (fp == fpDef) {
counts[origSreg].count++;
@@ -131,8 +131,8 @@
*/
extern void oatDoPromotion(CompilationUnit* cUnit)
{
- int numRegs = cUnit->method->registersSize;
- int numIns = cUnit->method->insSize;
+ int numRegs = cUnit->method->num_registers_;
+ int numIns = cUnit->method->num_ins_;
/*
* Because ins don't have explicit definitions, we need to type
@@ -140,10 +140,9 @@
*/
if (numIns > 0) {
int sReg = numRegs - numIns;
- const char *shorty = cUnit->method->shorty;
- shorty++; // Move past return type;
- while (*shorty) {
- char arg = *shorty++;
+ const art::StringPiece& shorty = cUnit->method->GetShorty();
+ for (int i = 1; i < shorty.size(); i++) {
+ char arg = shorty[i];
// Is it wide?
if ((arg == 'D') || (arg == 'J')) {
cUnit->regLocation[sReg].wide = true;
diff --git a/src/compiler/codegen/arm/Assemble.cc b/src/compiler/codegen/arm/Assemble.cc
index a601286..9981d64 100644
--- a/src/compiler/codegen/arm/Assemble.cc
+++ b/src/compiler/codegen/arm/Assemble.cc
@@ -965,13 +965,23 @@
*/
#define PADDING_MOV_R5_R5 0x1C2D
+static void pushWord(std::vector<short>&buf, int data) {
+ buf.push_back( (data >> 16) & 0xffff);
+ buf.push_back( data & 0xffff);
+}
+
+void alignBuffer(std::vector<short>&buf, size_t offset) {
+ while (buf.size() < (offset/2))
+ buf.push_back(0);
+}
+
/* Write the numbers in the constant to the output stream */
static void installLiteralPools(CompilationUnit* cUnit)
{
- int* dataPtr = (int*) ((char*) cUnit->baseAddr + cUnit->dataOffset);
+ alignBuffer(cUnit->codeBuffer, cUnit->dataOffset);
ArmLIR* dataLIR = (ArmLIR*) cUnit->literalList;
while (dataLIR) {
- *dataPtr++ = dataLIR->operands[0];
+ pushWord(cUnit->codeBuffer, dataLIR->operands[0]);
dataLIR = NEXT_LIR(dataLIR);
}
}
@@ -985,7 +995,7 @@
SwitchTable* tabRec = (SwitchTable *) oatGrowableListIteratorNext(
&iterator);
if (tabRec == NULL) break;
- int* dataPtr = (int*)((char*)cUnit->baseAddr + tabRec->offset);
+ alignBuffer(cUnit->codeBuffer, tabRec->offset);
int bxOffset = tabRec->bxInst->generic.offset + 4;
if (cUnit->printMe) {
LOG(INFO) << "Switch table for offset 0x" /*<< hex*/ << bxOffset;
@@ -999,8 +1009,9 @@
std::hex << keys[elems] << ", disp: 0x" <<
std::hex << disp;
}
- *dataPtr++ = keys[elems];
- *dataPtr++ = tabRec->targets[elems]->generic.offset - bxOffset;
+ pushWord(cUnit->codeBuffer, keys[elems]);
+ pushWord(cUnit->codeBuffer,
+ tabRec->targets[elems]->generic.offset - bxOffset);
}
} else {
assert(tabRec->table[0] == kPackedSwitchSignature);
@@ -1010,7 +1021,8 @@
LOG(INFO) << " Case[" << elems << "] disp: 0x" <<
std::hex << disp;
}
- *dataPtr++ = tabRec->targets[elems]->generic.offset - bxOffset;
+ pushWord(cUnit->codeBuffer,
+ tabRec->targets[elems]->generic.offset - bxOffset);
}
}
}
@@ -1025,8 +1037,10 @@
FillArrayData *tabRec = (FillArrayData *) oatGrowableListIteratorNext(
&iterator);
if (tabRec == NULL) break;
- char* dataPtr = (char*)cUnit->baseAddr + tabRec->offset;
- memcpy(dataPtr, (char*)tabRec->table, tabRec->size);
+ alignBuffer(cUnit->codeBuffer, tabRec->offset);
+ cUnit->codeBuffer.reserve(cUnit->codeBuffer.size() + (tabRec->size/2));
+ memcpy(&cUnit->codeBuffer[tabRec->offset/2],
+ (char*)tabRec->table, tabRec->size);
}
}
@@ -1038,7 +1052,6 @@
static AssemblerStatus assembleInstructions(CompilationUnit* cUnit,
intptr_t startAddr)
{
- short* bufferAddr = (short*) cUnit->codeBuffer;
ArmLIR* lir;
AssemblerStatus res = kSuccess; // Assume success
@@ -1047,7 +1060,7 @@
if ((lir->opcode == kArmPseudoPseudoAlign4) &&
/* 1 means padding is needed */
(lir->operands[0] == 1)) {
- *bufferAddr++ = PADDING_MOV_R5_R5;
+ cUnit->codeBuffer.push_back(PADDING_MOV_R5_R5);
}
continue;
}
@@ -1394,9 +1407,9 @@
}
}
if (encoder->size == 2) {
- *bufferAddr++ = (bits >> 16) & 0xffff;
+ cUnit->codeBuffer.push_back((bits >> 16) & 0xffff);
}
- *bufferAddr++ = bits & 0xffff;
+ cUnit->codeBuffer.push_back(bits & 0xffff);
}
return res;
}
@@ -1526,23 +1539,6 @@
void oatAssembleLIR(CompilationUnit* cUnit)
{
assignOffsets(cUnit);
-
-#ifdef TESTMODE
-//For testing - caller will allocate buffer
- int testSize = 1024 * 1024;
- int fd = ashmem_create_region("dalvik-test-code-cache",testSize);
- if (fd < 0) {
- LOG(FATAL) << "Coudln't create ashmem region";
- }
- cUnit->baseAddr = cUnit->codeBuffer = (unsigned char *)
- mmap(NULL, testSize, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE, fd, 0);
- close(fd);
- if (cUnit->baseAddr == MAP_FAILED) {
- LOG(FATAL) << "Failed to mmap the test region: " << strerror(errno);
- }
-#endif
-
/*
* Assemble here. Note that we generate code with optimistic assumptions
* and if found now to work, we'll have to redo the sequence and retry.
@@ -1559,6 +1555,7 @@
}
// Redo offsets and try again
assignOffsets(cUnit);
+ cUnit->codeBuffer.clear();
}
}
diff --git a/src/compiler/codegen/arm/MethodCodegenDriver.cc b/src/compiler/codegen/arm/MethodCodegenDriver.cc
index 417fdca..b8dcdb2 100644
--- a/src/compiler/codegen/arm/MethodCodegenDriver.cc
+++ b/src/compiler/codegen/arm/MethodCodegenDriver.cc
@@ -14,12 +14,6 @@
* limitations under the License.
*/
-//#define TESTMODE
-
-#ifdef TESTMODE
-#include "CalloutHelper.h"
-#endif
-
static const RegLocation badLoc = {kLocDalvikFrame, 0, 0, INVALID_REG,
INVALID_REG, INVALID_SREG, 0,
kLocDalvikFrame, INVALID_REG, INVALID_REG,
@@ -31,8 +25,8 @@
RegLocation rlSrc)
{
oatFlushAllRegs(cUnit); /* All temps to home location */
- void* classPtr = (void*)
- (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vC]);
+ Class* classPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedClass(mir->dalvikInsn.vC);
if (classPtr == NULL) {
LOG(FATAL) << "Unexpected null passPtr";
} else {
@@ -41,14 +35,8 @@
}
// FIXME: need this to throw errNegativeArraySize
genRegImmCheck(cUnit, kArmCondMi, r1, 0, mir->offset, NULL);
-#ifdef TESTMODE
-// Hack until we get rSELF setup
- loadConstant(cUnit, rLR, (int)dvmAllocArrayByClass);
-#else
loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pArtAllocArrayByClass),
rLR);
-#endif
- loadConstant(cUnit, r2, ALLOC_DONT_TRACK);
newLIR1(cUnit, kThumbBlxR, rLR); // (arrayClass, length, allocFlags)
storeValue(cUnit, rlDest, retLoc);
}
@@ -72,8 +60,8 @@
typeIndex = dInsn->vC;
}
oatFlushAllRegs(cUnit); /* All temps to home location */
- void* classPtr = (void*)
- (cUnit->method->clazz->pDvmDex->pResClasses[typeIndex]);
+ Class* classPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedClass(typeIndex);
if (classPtr == NULL) {
LOG(FATAL) << "Unexpected null passPtr";
} else {
@@ -88,14 +76,8 @@
* the above mentioned bad cases of 'D', 'J' or !('L' | '[' | 'I').
* That will keep us from wasting space generating an inline check here.
*/
-#ifdef TESTMODE
-// Hack until we get rSELF setup
- loadConstant(cUnit, rLR, (int)dvmAllocArrayByClass);
-#else
loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pArtAllocArrayByClass),
rLR);
-#endif
- loadConstant(cUnit, r2, ALLOC_DONT_TRACK);
newLIR1(cUnit, kThumbBlxR, rLR); // (arrayClass, length, allocFlags)
// Reserve ret0 (r0) - we'll use it in place.
oatLockTemp(cUnit, r0);
@@ -130,7 +112,7 @@
opRegRegImm(cUnit, kOpAdd, rSrc, rSP, rlFirst.spOffset);
// Set up the target pointer
opRegRegImm(cUnit, kOpAdd, rDst, r0,
- OFFSETOF_MEMBER(ArrayObject, contents));
+ Array::DataOffset().Int32Value());
// Set up the loop counter (known to be > 0)
loadConstant(cUnit, rIdx, dInsn->vA);
// Generate the copy loop. Going backwards for convenience
@@ -148,7 +130,8 @@
for (unsigned int i = 0; i < dInsn->vA; i++) {
RegLocation rlArg = loadValue(cUnit,
oatGetSrc(cUnit, mir, i), kCoreReg);
- storeBaseDisp(cUnit, r0, OFFSETOF_MEMBER(ArrayObject, contents) +
+ storeBaseDisp(cUnit, r0,
+ Array::DataOffset().Int32Value() +
i * 4, rlArg.lowReg, kWord);
// If the loadValue caused a temp to be allocated, free it
if (oatIsTemp(cUnit, rlArg.lowReg)) {
@@ -160,6 +143,8 @@
static void genSput(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
{
+ UNIMPLEMENTED(FATAL) << "Must update for new world";
+#if 0
int valOffset = OFFSETOF_MEMBER(StaticField, value);
int tReg = oatAllocTemp(cUnit);
int objHead;
@@ -181,9 +166,9 @@
(opcode == OP_SPUT_VOLATILE_JUMBO) ||
(opcode == OP_SPUT_OBJECT_VOLATILE) ||
(opcode == OP_SPUT_OBJECT_VOLATILE_JUMBO);
- assert(isVolatile == dvmIsVolatileField((Field *) fieldPtr));
+ assert(isVolatile == artIsVolatileField((Field *) fieldPtr));
#else
- isVolatile = dvmIsVolatileField((Field *) fieldPtr);
+ isVolatile = artIsVolatileField((Field *) fieldPtr);
#endif
isSputObject = (opcode == OP_SPUT_OBJECT) ||
@@ -206,10 +191,13 @@
markGCCard(cUnit, rlSrc.lowReg, objHead);
oatFreeTemp(cUnit, objHead);
}
+#endif
}
static void genSputWide(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
{
+ UNIMPLEMENTED(FATAL) << "Must update for new world";
+#if 0
int tReg = oatAllocTemp(cUnit);
int valOffset = OFFSETOF_MEMBER(StaticField, value);
const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
@@ -227,6 +215,7 @@
loadConstant(cUnit, tReg, (int) fieldPtr + valOffset);
storePair(cUnit, tReg, rlSrc.lowReg, rlSrc.highReg);
+#endif
}
@@ -234,6 +223,8 @@
static void genSgetWide(CompilationUnit* cUnit, MIR* mir,
RegLocation rlResult, RegLocation rlDest)
{
+ UNIMPLEMENTED(FATAL) << "Must update for new world";
+#if 0
int valOffset = OFFSETOF_MEMBER(StaticField, value);
const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
mir->meta.calleeMethod : cUnit->method;
@@ -253,11 +244,14 @@
loadPair(cUnit, tReg, rlResult.lowReg, rlResult.highReg);
storeValueWide(cUnit, rlDest, rlResult);
+#endif
}
static void genSget(CompilationUnit* cUnit, MIR* mir,
RegLocation rlResult, RegLocation rlDest)
{
+ UNIMPLEMENTED(FATAL) << "Must update for new world";
+#if 0
int valOffset = OFFSETOF_MEMBER(StaticField, value);
int tReg = oatAllocTemp(cUnit);
bool isVolatile;
@@ -282,9 +276,9 @@
Opcode opcode = mir->dalvikInsn.opcode;
isVolatile = (opcode == OP_SGET_VOLATILE) ||
(opcode == OP_SGET_OBJECT_VOLATILE);
- assert(isVolatile == dvmIsVolatileField((Field *) fieldPtr));
+ assert(isVolatile == artIsVolatileField((Field *) fieldPtr));
#else
- isVolatile = dvmIsVolatileField((Field *) fieldPtr);
+ isVolatile = artIsVolatileField((Field *) fieldPtr);
#endif
rlDest = oatGetDest(cUnit, mir, 0);
@@ -297,6 +291,7 @@
loadWordDisp(cUnit, tReg, 0, rlResult.lowReg);
storeValue(cUnit, rlDest, rlResult);
+#endif
}
typedef int (*NextCallInsn)(CompilationUnit*, MIR*, DecodedInstruction*, int);
@@ -308,11 +303,14 @@
static int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir,
DecodedInstruction* dInsn, int state)
{
+ UNIMPLEMENTED(FATAL) << "Update with new cache model";
+#if 0
switch(state) {
case 0: // Get the current Method* [sets r0]
loadBaseDisp(cUnit, mir, rSP, 0, r0, kWord, INVALID_SREG);
break;
case 1: // Get the pResMethods pointer [uses r0, sets r0]
+ UNIMPLEMENTED(FATAL) << "Update with new cache";
loadBaseDisp(cUnit, mir, r0, OFFSETOF_MEMBER(Method, pResMethods),
r0, kWord, INVALID_SREG);
break;
@@ -328,6 +326,7 @@
default:
return -1;
}
+#endif
return state + 1;
}
@@ -341,6 +340,8 @@
static int nextVCallInsn(CompilationUnit* cUnit, MIR* mir,
DecodedInstruction* dInsn, int state)
{
+ UNIMPLEMENTED(FATAL) << "Update with new cache model";
+#if 0
RegLocation rlArg;
switch(state) {
case 0: // Get the current Method* [set r0]
@@ -368,19 +369,21 @@
r12, kUnsignedHalf, INVALID_SREG);
// get this->clazz->vtable [use rLR, set rLR]
loadBaseDisp(cUnit, mir, rLR,
- OFFSETOF_MEMBER(ClassObject, vtable), rLR, kWord,
+ OFFSETOF_MEMBER(Class, vtable), rLR, kWord,
INVALID_SREG);
break;
case 4: // get target Method* [use rLR, use r12, set r0]
loadBaseIndexed(cUnit, rLR, r12, r0, 2, kWord);
break;
case 5: // Get the target compiled code address [use r0, set rLR]
+ UNIMPLEMENTED(FATAL) << "Update with new cache";
loadBaseDisp(cUnit, mir, r0, OFFSETOF_MEMBER(Method, compiledInsns),
rLR, kWord, INVALID_SREG);
break;
default:
return -1;
}
+#endif
return state + 1;
}
@@ -412,6 +415,8 @@
static int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir,
DecodedInstruction* dInsn, int state)
{
+ UNIMPLEMENTED(FATAL) << "Update with new cache model";
+#if 0
RegLocation rlArg;
switch(state) {
case 0:
@@ -427,14 +432,14 @@
loadBaseDisp(cUnit, mir, r2, OFFSETOF_MEMBER(Method, clazz),
r3, kWord, INVALID_SREG);
// Load this->class [usr r12, set arg0]
- loadBaseDisp(cUnit, mir, r12, OFFSETOF_MEMBER(ClassObject, clazz),
+ loadBaseDisp(cUnit, mir, r12, OFFSETOF_MEMBER(Class, clazz),
r3, kWord, INVALID_SREG);
// Load address of helper function
loadBaseDisp(cUnit, mir, rSELF,
OFFSETOF_MEMBER(Thread, pArtFindInterfaceMethodInCache),
rLR, kWord, INVALID_SREG);
// Get dvmDex
- loadBaseDisp(cUnit, mir, r3, OFFSETOF_MEMBER(ClassObject, pDvmDex),
+ loadBaseDisp(cUnit, mir, r3, OFFSETOF_MEMBER(Class, pDvmDex),
r3, kWord, INVALID_SREG);
// Load ref [set arg1]
loadConstant(cUnit, r1, dInsn->vB);
@@ -447,6 +452,7 @@
default:
return -1;
}
+#endif
return state + 1;
}
@@ -458,6 +464,8 @@
static int nextSuperCallInsn(CompilationUnit* cUnit, MIR* mir,
DecodedInstruction* dInsn, int state)
{
+ UNIMPLEMENTED(FATAL) << "Update with new cache model";
+#if 0
RegLocation rlArg;
switch(state) {
case 0:
@@ -473,7 +481,7 @@
loadBaseDisp(cUnit, mir, r0, OFFSETOF_MEMBER(Method, pResMethods),
rLR, kWord, INVALID_SREG);
// Get clazz->super [use r12, set r12]
- loadBaseDisp(cUnit, mir, r12, OFFSETOF_MEMBER(ClassObject, super),
+ loadBaseDisp(cUnit, mir, r12, OFFSETOF_MEMBER(Class, super),
r12, kWord, INVALID_SREG);
// Get base method [use rLR, set r0]
loadBaseDisp(cUnit, mir, rLR, dInsn->vB * 4, r0,
@@ -486,7 +494,7 @@
rLR, kUnsignedHalf, INVALID_SREG);
// Get vtableCount [use r12, set r0]
loadBaseDisp(cUnit, mir, r12,
- OFFSETOF_MEMBER(ClassObject, vtableCount),
+ OFFSETOF_MEMBER(Class, vtableCount),
r0, kWord, INVALID_SREG);
// Compare method index w/ vtable count [use r12, use rLR]
genRegRegCheck(cUnit, kArmCondGe, rLR, r0, mir->offset, NULL);
@@ -498,6 +506,7 @@
default:
return -1;
}
+#endif
return state + 1;
}
@@ -591,7 +600,8 @@
* Dalvik vRegs and the ins.
*/
int highestVreg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow;
- if (highestVreg >= cUnit->method->registersSize - cUnit->method->insSize) {
+ if (highestVreg >= cUnit->method->num_registers_ -
+ cUnit->method->num_ins_) {
LOG(FATAL) << "Wide argument spanned locals & args";
}
@@ -622,7 +632,7 @@
newLIR1(cUnit, kThumbBlxR, rLR);
} else {
// Use vldm/vstm pair using r3 as a temp
- int regsLeft = MIN(numArgs - 3, 16);
+ int regsLeft = std::min(numArgs - 3, 16);
callState = nextCallInsn(cUnit, mir, dInsn, callState);
opRegRegImm(cUnit, kOpAdd, r3, rSP, startOffset);
newLIR3(cUnit, kThumb2Vldms, r3, fr0 & FP_REG_MASK, regsLeft);
@@ -791,7 +801,7 @@
case OP_MOVE_EXCEPTION:
int exOffset;
int resetReg;
- exOffset = OFFSETOF_MEMBER(Thread, exception);
+ exOffset = Thread::ExceptionOffset().Int32Value();
resetReg = oatAllocTemp(cUnit);
rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
loadWordDisp(cUnit, rSELF, exOffset, rlResult.lowReg);
@@ -923,7 +933,7 @@
case OP_ARRAY_LENGTH:
int lenOffset;
- lenOffset = OFFSETOF_MEMBER(ArrayObject, length);
+ lenOffset = Array::LengthOffset().Int32Value();
genNullCheck(cUnit, rlSrc[0].sRegLow, rlSrc[0].lowReg,
mir->offset, NULL);
rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
@@ -1101,7 +1111,7 @@
genArrayPut(cUnit, mir, kWord, rlSrc[1], rlSrc[2], rlSrc[0], 2);
break;
case OP_APUT_OBJECT:
- genArrayObjectPut(cUnit, mir, rlSrc[1], rlSrc[2], rlSrc[0], 2);
+ genArrayPut(cUnit, mir, rlSrc[1], rlSrc[2], rlSrc[0], 2);
break;
case OP_APUT_SHORT:
case OP_APUT_CHAR:
@@ -1432,11 +1442,11 @@
* Note: at this pointCopy any ins that are passed in register to their home location */
static void flushIns(CompilationUnit* cUnit)
{
- if (cUnit->method->insSize == 0)
+ if (cUnit->method->num_ins_ == 0)
return;
- int inRegs = (cUnit->method->insSize > 2) ? 3 : cUnit->method->insSize;
+ int inRegs = (cUnit->method->num_ins_ > 2) ? 3 : cUnit->method->num_ins_;
int startReg = r1;
- int startLoc = cUnit->method->registersSize - cUnit->method->insSize;
+ int startLoc = cUnit->method->num_registers_ - cUnit->method->num_ins_;
for (int i = 0; i < inRegs; i++) {
RegLocation loc = cUnit->regLocation[startLoc + i];
if (loc.location == kLocPhysReg) {
@@ -1459,7 +1469,7 @@
}
// Now, do initial assignment of all promoted arguments passed in frame
- for (int i = inRegs; i < cUnit->method->insSize;) {
+ for (int i = inRegs; i < cUnit->method->num_ins_;) {
RegLocation loc = cUnit->regLocation[startLoc + i];
if (loc.fpLocation == kLocPhysReg) {
loc.location = kLocPhysReg;
@@ -1721,45 +1731,3 @@
{
storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi);
}
-
-#ifdef TESTMODE
-// Will be done at runtime by art. Keep for debugging
-void oatInitHelpers(Thread* thread)
-{
- thread->pMemcpy = memcpy;
- thread->pI2f = __aeabi_i2f;
- thread->pF2iz = __aeabi_f2iz;
- thread->pD2f = __aeabi_d2f;
- thread->pF2d = __aeabi_f2d;
- thread->pI2d = __aeabi_i2d;
- thread->pD2iz = __aeabi_d2iz;
- thread->pL2f = __aeabi_l2f;
- thread->pL2d = __aeabi_l2d;
- thread->pArtF2l = artF2L;
- thread->pArtD2l = artD2L;
- thread->pFadd = __aeabi_fadd;
- thread->pFsub = __aeabi_fsub;
- thread->pFdiv = __aeabi_fdiv;
- thread->pFmul = __aeabi_fmul;
- thread->pFmodf = fmodf;
- thread->pDadd = __aeabi_dadd;
- thread->pDsub = __aeabi_dsub;
- thread->pDdiv = __aeabi_ddiv;
- thread->pDmul = __aeabi_dmul;
- thread->pFmod = fmod;
- thread->pIdivmod = __aeabi_idivmod;
- thread->pIdiv = __aeabi_idiv;
- thread->pLdivmod = __aeabi_ldivmod;
- thread->pArtUnlockObject = dvmUnlockObject;
- thread->pArtCanPutArrayElementNoThrow = dvmCanPutArrayElement;
- thread->pArtInstanceofNonTrivialNoThrow = dvmInstanceofNonTrivial;
- thread->pArtInstanceofNonTrivial = dvmInstanceofNonTrivial;
- thread->pArtAllocArrayByClass = dvmAllocArrayByClass;
- thread->pArtFindInterfaceMethodInCache = dvmFindInterfaceMethodInCache;
- thread->pArtUnlockObjectNoThrow = dvmUnlockObject;
- thread->pArtLockObjectNoThrow = dvmLockObject;
- thread->pArtAllocObjectNoThrow = dvmAllocObject;
- thread->pArtThrowException = NULL; //TBD
- thread->pArtHandleFillArrayDataNoThrow = dvmInterpHandleFillArrayData;
-}
-#endif
diff --git a/src/compiler/codegen/arm/Thumb2/Gen.cc b/src/compiler/codegen/arm/Thumb2/Gen.cc
index c9d72f7..1a126e4 100644
--- a/src/compiler/codegen/arm/Thumb2/Gen.cc
+++ b/src/compiler/codegen/arm/Thumb2/Gen.cc
@@ -356,7 +356,7 @@
int regCardBase = oatAllocTemp(cUnit);
int regCardNo = oatAllocTemp(cUnit);
ArmLIR* branchOver = genCmpImmBranch(cUnit, kArmCondEq, valReg, 0);
- loadWordDisp(cUnit, rSELF, offsetof(Thread, cardTable),
+ loadWordDisp(cUnit, rSELF, Thread::CardTableOffset().Int32Value(),
regCardBase);
opRegRegImm(cUnit, kOpLsr, regCardNo, tgtAddrReg, GC_CARD_SHIFT);
storeBaseIndexed(cUnit, regCardBase, regCardNo, regCardBase, 0,
@@ -371,8 +371,8 @@
static void genIGetX(CompilationUnit* cUnit, MIR* mir, OpSize size,
RegLocation rlDest, RegLocation rlObj)
{
- Field* fieldPtr =
- cUnit->method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vC];
+ Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedField(mir->dalvikInsn.vC);
if (fieldPtr == NULL) {
/*
* With current scheme, we should never be in a situation
@@ -387,7 +387,7 @@
#else
bool isVolatile = false;
#endif
- int fieldOffset = ((InstField *)fieldPtr)->byteOffset;
+ int fieldOffset = fieldPtr->GetOffset();
RegLocation rlResult;
RegisterClass regClass = oatRegClassBySize(size);
rlObj = loadValue(cUnit, rlObj, kCoreReg);
@@ -406,8 +406,8 @@
static void genIPutX(CompilationUnit* cUnit, MIR* mir, OpSize size,
RegLocation rlSrc, RegLocation rlObj, bool isObject)
{
- Field* fieldPtr =
- cUnit->method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vC];
+ Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedField(mir->dalvikInsn.vC);
if (fieldPtr == NULL) {
/*
* With current scheme, we should never be in a situation
@@ -422,7 +422,7 @@
#else
bool isVolatile = false;
#endif
- int fieldOffset = ((InstField *)fieldPtr)->byteOffset;
+ int fieldOffset = fieldPtr->GetOffset();
RegisterClass regClass = oatRegClassBySize(size);
rlObj = loadValue(cUnit, rlObj, kCoreReg);
rlSrc = loadValue(cUnit, rlSrc, regClass);
@@ -442,8 +442,8 @@
static void genIGetWideX(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest,
RegLocation rlObj)
{
- Field* fieldPtr =
- cUnit->method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vC];
+ Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedField(mir->dalvikInsn.vC);
if (fieldPtr == NULL) {
/*
* With current scheme, we should never be in a situation
@@ -458,7 +458,7 @@
#else
bool isVolatile = false;
#endif
- int fieldOffset = ((InstField *)fieldPtr)->byteOffset;
+ int fieldOffset = fieldPtr->GetOffset();
RegLocation rlResult;
rlObj = loadValue(cUnit, rlObj, kCoreReg);
int regPtr = oatAllocTemp(cUnit);
@@ -483,8 +483,8 @@
static void genIPutWideX(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc,
RegLocation rlObj)
{
- Field* fieldPtr =
- cUnit->method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vC];
+ Field* fieldPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedField(mir->dalvikInsn.vC);
if (fieldPtr == NULL) {
/*
* With current scheme, we should never be in a situation
@@ -499,7 +499,7 @@
#else
bool isVolatile = false;
#endif
- int fieldOffset = ((InstField *)fieldPtr)->byteOffset;
+ int fieldOffset = fieldPtr->GetOffset();
rlObj = loadValue(cUnit, rlObj, kCoreReg);
int regPtr;
@@ -520,13 +520,14 @@
static void genConstClass(CompilationUnit* cUnit, MIR* mir,
RegLocation rlDest, RegLocation rlSrc)
{
- void* classPtr = (void*)
- (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
+ Class* classPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedClass(mir->dalvikInsn.vB);
if (classPtr == NULL) {
LOG(FATAL) << "Unexpected null class pointer";
}
+ UNIMPLEMENTED(WARNING) << "Not position independent. Fix";
RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
loadConstantNoClobber(cUnit, rlResult.lowReg, (int) classPtr );
storeValue(cUnit, rlDest, rlResult);
@@ -535,14 +536,15 @@
static void genConstString(CompilationUnit* cUnit, MIR* mir,
RegLocation rlDest, RegLocation rlSrc)
{
- void* strPtr = (void*)
- (cUnit->method->clazz->pDvmDex->pResStrings[mir->dalvikInsn.vB]);
+ String* strPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedString(mir->dalvikInsn.vB);
if (strPtr == NULL) {
/* Shouldn't happen */
LOG(FATAL) << "Unexpected null const string pointer";
}
+ UNIMPLEMENTED(WARNING) << "Not position indendent. Fix";
RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
loadConstantNoClobber(cUnit, rlResult.lowReg, (int) strPtr );
storeValue(cUnit, rlDest, rlResult);
@@ -551,8 +553,8 @@
static void genNewInstance(CompilationUnit* cUnit, MIR* mir,
RegLocation rlDest)
{
- ClassObject* classPtr = (ClassObject *)
- (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
+ Class* classPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedClass(mir->dalvikInsn.vB);
if (classPtr == NULL) {
/* Shouldn't happen */
@@ -560,12 +562,13 @@
}
// Verifier should have already rejected abstract/interface
- assert((classPtr->accessFlags & (ACC_INTERFACE|ACC_ABSTRACT)) == 0);
+ assert((classPtr->access_flags_ &
+ (art::kAccInterface|art::kAccAbstract)) == 0);
oatFlushAllRegs(cUnit); /* Everything to home location */
loadWordDisp(cUnit, rSELF,
OFFSETOF_MEMBER(Thread, pArtAllocObjectNoThrow), rLR);
loadConstant(cUnit, r0, (int) classPtr);
- loadConstant(cUnit, r1, ALLOC_DONT_TRACK);
+ UNIMPLEMENTED(WARNING) << "Need NewWorld dvmAllocObject";
opReg(cUnit, kOpBlx, rLR);
oatClobberCallRegs(cUnit);
RegLocation rlResult = oatGetReturn(cUnit);
@@ -586,8 +589,8 @@
{
// May generate a call - use explicit registers
RegLocation rlResult;
- ClassObject* classPtr =
- (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vC]);
+ Class* classPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedClass(mir->dalvikInsn.vC);
if (classPtr == NULL) {
/* Shouldn't happen */
LOG(FATAL) << "Unexpected null class pointer";
@@ -598,7 +601,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 */
- loadWordDisp(cUnit, r0, offsetof(Object, clazz), r1);
+ assert(OFFSETOF_MEMBER(Object, klass_) == 0);
+ loadWordDisp(cUnit, r0, OFFSETOF_MEMBER(Object, klass_), r1);
/* r1 now contains object->clazz */
loadWordDisp(cUnit, rSELF,
OFFSETOF_MEMBER(Thread, pArtInstanceofNonTrivial), rLR);
@@ -620,8 +624,8 @@
static void genCheckCast(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
{
- ClassObject* classPtr =
- (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
+ Class* classPtr = cUnit->method->GetDeclaringClass()->GetDexCache()->
+ GetResolvedClass(mir->dalvikInsn.vB);
if (classPtr == NULL) {
/* Shouldn't happen with our current model */
LOG(FATAL) << "Unexpected null class pointer";
@@ -639,7 +643,7 @@
* with clazz.
*/
/* r0 now contains object->clazz */
- loadWordDisp(cUnit, rlSrc.lowReg, offsetof(Object, clazz), r0);
+ loadWordDisp(cUnit, rlSrc.lowReg, OFFSETOF_MEMBER(Object, klass_), r0);
loadWordDisp(cUnit, rSELF,
OFFSETOF_MEMBER(Thread, pArtInstanceofNonTrivialNoThrow), rLR);
opRegReg(cUnit, kOpCmp, r0, r1);
@@ -783,20 +787,23 @@
ArmLIR* hopBranch;
oatFlushAllRegs(cUnit);
- assert(LW_SHAPE_THIN == 0);
+ assert(art::Monitor::kLwShapeThin == 0);
loadValueDirectFixed(cUnit, rlSrc, r1); // Get obj
oatLockAllTemps(cUnit); // Prepare for explicit register usage
genNullCheck(cUnit, rlSrc.sRegLow, r1, mir->offset, NULL);
- loadWordDisp(cUnit, rSELF, offsetof(Thread, threadId), r3); // Get threadId
+ loadWordDisp(cUnit, rSELF, Thread::IdOffset().Int32Value(), r3);
newLIR3(cUnit, kThumb2Ldrex, r2, r1,
- offsetof(Object, lock) >> 2); // Get object->lock
- opRegImm(cUnit, kOpLsl, r3, LW_LOCK_OWNER_SHIFT); // Align owner
+ OFFSETOF_MEMBER(Object, monitor_) >> 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?
- newLIR4(cUnit, kThumb2Bfi, r3, r2, 0, LW_LOCK_OWNER_SHIFT - 1);
- newLIR3(cUnit, kThumb2Bfc, r2, LW_HASH_STATE_SHIFT,
- LW_LOCK_OWNER_SHIFT - 1);
+ newLIR4(cUnit, kThumb2Bfi, r3, r2, 0, art::Monitor::kLwLockOwnerShift
+ - 1);
+ newLIR3(cUnit, kThumb2Bfc, r2, art::Monitor::kLwHashStateShift,
+ art::Monitor::kLwLockOwnerShift - 1);
hopBranch = newLIR2(cUnit, kThumb2Cbnz, r2, 0);
- newLIR4(cUnit, kThumb2Strex, r2, r3, r1, offsetof(Object, lock) >> 2);
+ newLIR4(cUnit, kThumb2Strex, r2, r3, r1,
+ OFFSETOF_MEMBER(Object, monitor_) >> 2);
oatGenMemBarrier(cUnit, kSY);
branch = newLIR2(cUnit, kThumb2Cbz, r2, 0);
@@ -830,23 +837,24 @@
ArmLIR* hopTarget;
ArmLIR* hopBranch;
- assert(LW_SHAPE_THIN == 0);
+ assert(art::Monitor::kLwShapeThin == 0);
oatFlushAllRegs(cUnit);
loadValueDirectFixed(cUnit, rlSrc, r1); // Get obj
oatLockAllTemps(cUnit); // Prepare for explicit register usage
genNullCheck(cUnit, rlSrc.sRegLow, r1, mir->offset, NULL);
- loadWordDisp(cUnit, r1, offsetof(Object, lock), r2); // Get object->lock
- loadWordDisp(cUnit, rSELF, offsetof(Thread, threadId), r3); // Get threadId
+ loadWordDisp(cUnit, r1, OFFSETOF_MEMBER(Object, monitor_), 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,
- (LW_HASH_STATE_MASK << LW_HASH_STATE_SHIFT));
- opRegImm(cUnit, kOpLsl, r3, LW_LOCK_OWNER_SHIFT); // Align owner
- newLIR3(cUnit, kThumb2Bfc, r2, LW_HASH_STATE_SHIFT,
- LW_LOCK_OWNER_SHIFT - 1);
+ opRegRegImm(cUnit, kOpAnd, r12, r2, (art::Monitor::kLwHashStateMask <<
+ art::Monitor::kLwHashStateShift));
+ // Align owner
+ opRegImm(cUnit, kOpLsl, r3, art::Monitor::kLwLockOwnerShift);
+ newLIR3(cUnit, kThumb2Bfc, r2, art::Monitor::kLwHashStateShift,
+ art::Monitor::kLwLockOwnerShift - 1);
opRegReg(cUnit, kOpSub, r2, r3);
hopBranch = opCondBranch(cUnit, kArmCondNe);
oatGenMemBarrier(cUnit, kSY);
- storeWordDisp(cUnit, r1, offsetof(Object, lock), r12);
+ storeWordDisp(cUnit, r1, OFFSETOF_MEMBER(Object, monitor_), r12);
branch = opNone(cUnit, kOpUncondBr);
hopTarget = newLIR0(cUnit, kArmPseudoTargetLabel);
@@ -1116,13 +1124,13 @@
* Generate array store
*
*/
-static void genArrayObjectPut(CompilationUnit* cUnit, MIR* mir,
+static void genArrayPut(CompilationUnit* cUnit, MIR* mir,
RegLocation rlArray, RegLocation rlIndex,
RegLocation rlSrc, int scale)
{
RegisterClass regClass = oatRegClassBySize(kWord);
- int lenOffset = OFFSETOF_MEMBER(ArrayObject, length);
- int dataOffset = OFFSETOF_MEMBER(ArrayObject, contents);
+ int lenOffset = Array::LengthOffset().Int32Value();
+ int dataOffset = Array::DataOffset().Int32Value();
/* Make sure it's a legal object Put. Use direct regs at first */
loadValueDirectFixed(cUnit, rlArray, r1);
@@ -1138,9 +1146,9 @@
loadWordDisp(cUnit, rSELF,
OFFSETOF_MEMBER(Thread, pArtCanPutArrayElementNoThrow), rLR);
/* Get the array's clazz */
- loadWordDisp(cUnit, r1, offsetof(Object, clazz), r1);
+ loadWordDisp(cUnit, r1, OFFSETOF_MEMBER(Object, klass_), r1);
/* Get the object's clazz */
- loadWordDisp(cUnit, r0, offsetof(Object, clazz), r0);
+ loadWordDisp(cUnit, r0, OFFSETOF_MEMBER(Object, klass_), r0);
opReg(cUnit, kOpBlx, rLR);
oatClobberCallRegs(cUnit);
@@ -1186,8 +1194,8 @@
RegLocation rlDest, int scale)
{
RegisterClass regClass = oatRegClassBySize(size);
- int lenOffset = OFFSETOF_MEMBER(ArrayObject, length);
- int dataOffset = OFFSETOF_MEMBER(ArrayObject, contents);
+ int lenOffset = Array::LengthOffset().Int32Value();
+ int dataOffset = Array::DataOffset().Int32Value();
RegLocation rlResult;
rlArray = loadValue(cUnit, rlArray, kCoreReg);
rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
@@ -1251,8 +1259,8 @@
RegLocation rlSrc, int scale)
{
RegisterClass regClass = oatRegClassBySize(size);
- int lenOffset = OFFSETOF_MEMBER(ArrayObject, length);
- int dataOffset = OFFSETOF_MEMBER(ArrayObject, contents);
+ int lenOffset = Array::LengthOffset().Int32Value();
+ int dataOffset = Array::DataOffset().Int32Value();
int regPtr;
rlArray = loadValue(cUnit, rlArray, kCoreReg);