android art代码,Android art new class 代码产生过程

测试JAVA代码

public voidonClick(View v) {

// TODOAuto-generated method stub

//WifiManagerwifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

//WifiInfoinfo = wifi.getConnectionInfo();

//System.out.println("Wifi mac :" + info.getMacAddress());

//System.out.println("return " + test());

//InjectApplicationia = (InjectApplication) getApplication();

//System.out.println("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");

AuroraTest tt = newAuroraTest();

tt.Test1(50);

// Test1(100);

//System.out.println(tt.Test1(50));

//System.out.println(test2());

//System.out.println(test3());

//System.out.println(test4());

}

});

oatdump输出

1:void com.example.testar.MainActivity$1.onClick(android.view.View)(dex_method_idx=13)

DEX CODE:

0x0000:new-instance v0, aurora.view.AuroraTest // type@13

0x0002: invoke-direct {v0}, voidaurora.view.AuroraTest.() // method@6

0x0005: const/16 v1, #+50

0x0007: invoke-virtual {v0, v1}, intaurora.view.AuroraTest.Test1(int) // method@7

0x000a: return-void

OAT DATA:

frame_size_in_bytes: 48

r5对应this object

r6对应[method*]

r9对应Thead *

core_spill_mask: 0x00008060 (r5, r6, r15)

fp_spill_mask: 0x00000000

vmap_table: 0xb6c372d2(offset=0x000312d2)

v0/r5, v65534/r6, v65535/r15

mapping_table: 0xb6c372c8(offset=0x000312c8)

gc_map: 0xb6c372da (offset=0x000312da)

CODE: 0xb6c3725d (offset=0x0003125dsize=108)...

0xb6c3725c: f8d9c010         ldr.w  r12, [r9, #16]  ; stack_end_

0xb6c37260: e92d4060        push   {r5, r6, lr}

0xb6c37264: f2ad0e24         subw   lr, sp, #36

0xb6c37268: 45e6            cmp     lr, r12

0xb6c3726a: f0c08026         bcc.w  +76 (0xb6c372ba)

0xb6c3726e: 46f5             mov     sp, lr

0xb6c37270: 1c06            mov     r6, r0

0xb6c37272: 9000            str     r0, [sp, #0]

0xb6c37274: 910d            str     r1, [sp, #52]

0xb6c37276: 920e            str     r2, [sp, #56]

调用thread的pAllocObject, 参数为r1=r6(Method *), r0(type, 13)

0xb6c37278:f8d9e158        ldr.w   lr, [r9, #344]  ; pAllocObject

0xb6c3727c:1c31            mov     r1, r6

0xb6c3727e:200d           movs    r0, #13

0xb6c37280:47f0            blx     lr

suspend point dex PC: 0x0000

GC map objects:  v2 ([sp + #52]), v3 ([sp + #56])

R0现在保存的是AuroraTest对象的值

0xb6c37282: 1c05            mov     r5, r0

0xb6c37284: 1c30            mov     r0, r6

0xb6c37286: 6900            ldr     r0, [r0, #16]

0xb6c37288: 1c29            mov     r1, r5

0xb6c3728a: 6a40            ldr     r0, [r0, #36]

0xb6c3728c: f8d0e028         ldr.w  lr, [r0, #40]

0xb6c37290: 47f0             blx     lr

suspend point dex PC: 0x0002

GC map objects:  v0 (r5), v2 ([sp + #52]), v3 ([sp + #56])

0xb6c37292: 2232            movs    r2, #50

0xb6c37294: 9207            str     r2, [sp, #28]

0xb6c37296: 1c30            mov     r0, r6

0xb6c37298: 6900            ldr     r0, [r0, #16]

0xb6c3729a: 1c29            mov     r1, r5

0xb6c3729c: 2232            movs    r2, #50

0xb6c3729e: 6a80            ldr     r0, [r0, #40]

0xb6c372a0: f8d0e028         ldr.w  lr, [r0, #40]

0xb6c372a4: 47f0             blx     lr

suspend point dex PC: 0x0007

GCmap objects:  v0 (r5), v2 ([sp + #52]),v3 ([sp + #56])

0xb6c372a6: 3c01            subs    r4, #1

0xb6c372a8: f0008003         beq.w  +6 (0xb6c372b2)

0xb6c372ac: b009            add     sp, sp, #36

0xb6c372ae: e8bd8060        pop    {r5, r6, pc}

0xb6c372b2: f8d9e25c         ldr.w   lr, [r9,#604]  ; pTestSuspend

0xb6c372b6: 47f0             blx     lr

suspend point dex PC: 0x000a

0xb6c372b8: e7f8             b       -16 (0xb6c372ac)

0xb6c372ba: f8dde008         ldr.w  lr, [sp, #8]

0xb6c372be: b003            add     sp, sp, #12

0xb6c372c0: f8d9c274         ldr.w  r12, [r9, #628]  ;pThrowStackOverflow

0xb6c372c4: 4760            bx      r12

0xb6c372c6: 0000            lsls    r0, r0, #0

art/runtime/thread.cc

93 void Thread::InitTlsEntryPoints() {

94 #if !defined(__APPLE__)  // The Mac GCC is too old to accept thiscode.

95   //Insert a placeholder so we can easily tell if we call an unimplemented entrypoint.

96  uintptr_t* begin = reinterpret_cast(&interpreter_entrypoints_);

97  uintptr_t* end =reinterpret_cast(reinterpret_cast(begin) +sizeof(quick_entrypoints_));

98  for (uintptr_t* it = begin; it != end; ++it) {

99    *it = reinterpret_cast(UnimplementedEntryPoint);

100   }

101  begin =reinterpret_cast(&interpreter_entrypoints_);

102  end =reinterpret_cast(reinterpret_cast(begin) +sizeof(portable_entrypoints_));

103  for (uintptr_t* it = begin; it != end; ++it) {

104    *it = reinterpret_cast(UnimplementedEntryPoint);

105   }

106 #endif

107  InitEntryPoints(&interpreter_entrypoints_, &jni_entrypoints_,&portable_entrypoints_,

108                   &quick_entrypoints_);

109 }

art/runtime/arch/arm/entrypoints_init_arm.cc

136void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints*jpoints,

137                      PortableEntryPoints*ppoints, QuickEntryPoints* qpoints) {

138   // Interpreter

139   ipoints->pInterpreterToInterpreterBridge= artInterpreterToInterpreterBridge;

140   ipoints->pInterpreterToCompiledCodeBridge= artInterpreterToCompiledCodeBridge;

141

142   // JNI

143   jpoints->pDlsymLookup =art_jni_dlsym_lookup_stub;

144

145   // Portable

146   ppoints->pPortableResolutionTrampoline =art_portable_resolution_trampoline;

147   ppoints->pPortableToInterpreterBridge =art_portable_to_interpreter_bridge;

148

149   // Alloc

150   qpoints->pAllocArray =art_quick_alloc_array;

151   qpoints->pAllocArrayWithAccessCheck =art_quick_alloc_array_with_access_check;

152  qpoints->pAllocObject = art_quick_alloc_object;

153   qpoints->pAllocObjectWithAccessCheck =art_quick_alloc_object_with_access_check;

154   qpoints->pCheckAndAllocArray =art_quick_check_and_alloc_array;

155  qpoints->pCheckAndAllocArrayWithAccessCheck =art_quick_check_and_alloc_array_with_access_check;

./runtime/arch/arm/quick_entrypoints_arm.S

698     .extern artAllocObjectFromCode

699 ENTRYart_quick_alloc_object

700    SETUP_REF_ONLY_CALLEE_SAVE_FRAME @ save callee saves in case of GC

701    mov    r2, r9                     @ passThread::Current

702    mov    r3, sp                     @ pass SP

703     bl    artAllocObjectFromCode     @(uint32_t type_idx, Method* method,Thread*, SP)

704    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME

705    RETURN_IF_RESULT_IS_NON_ZERO

706    DELIVER_PENDING_EXCEPTION

707 END art_quick_alloc_object

art/runtime/entrypoints/quick/quick_alloc_entrypoints.cc

26extern "C" mirror::Object* artAllocObjectFromCode(uint32_t type_idx,mirror::ArtMethod* method,

27                                                  Thread* self, mirror::ArtMethod** sp)

28    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {

29  FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly);

30  return AllocObjectFromCode(type_idx, method, self, false);

31 }

32

art/runtime/entrypoints/entrypoint_utils.h

41// Given the context of a calling Method, use its DexCache to resolve a type toa Class. If it

42 // cannot be resolved, throw an error. Ifit can, use it to create an instance.

43 // When verification/compiler hasn't beenable to verify access, optionally perform an access

44 // check.

45 static inline mirror::Object* AllocObjectFromCode(uint32_t type_idx,mirror::ArtMethod* method,

46                                                  Thread* self,

47                                                   bool access_check)

48    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {

49   mirror::Class* klass =method->GetDexCacheResolvedTypes()->Get(type_idx);

50  Runtime* runtime = Runtime::Current();

51   if(UNLIKELY(klass == NULL)) {

52    klass = runtime->GetClassLinker()->ResolveType(type_idx, method);

53    if (klass == NULL) {

54      DCHECK(self->IsExceptionPending());

55      return NULL;  // Failure

56     }

57   }

58   if(access_check) {

59    if (UNLIKELY(!klass->IsInstantiable())) {

60      ThrowLocation throw_location = self->GetCurrentLocationForThrow();

61      self->ThrowNewException(throw_location,"Ljava/lang/InstantiationError;",

62                              PrettyDescriptor(klass).c_str());

63      return NULL;  // Failure

64     }

65    mirror::Class* referrer = method->GetDeclaringClass();

66    if (UNLIKELY(!referrer->CanAccess(klass))) {

67      ThrowIllegalAccessErrorClass(referrer, klass);

68      return NULL;  // Failure

69     }

70   }

71   if(!klass->IsInitialized() &&

72      !runtime->GetClassLinker()->EnsureInitialized(klass, true, true)){

73    DCHECK(self->IsExceptionPending());

74    return NULL;  // Failure

75   }

76   return klass->AllocObject(self);

77 }

78

art/runtime/mirror/class.cc

121Object* Class::AllocObject(Thread* self) {

122   DCHECK(!IsArrayClass()) <

123   DCHECK(IsInstantiable()) <

124   // TODO: decide whether we want this check.It currently fails during bootstrap.

125   //DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) <

126   DCHECK_GE(this->object_size_,sizeof(Object));

127   returnRuntime::Current()->GetHeap()->AllocObject(self, this,this->object_size_);

128}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值