• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1%verify "executed"
2%verify "class not resolved"
3%verify "class cannot be resolved"
4%verify "class not initialized"
5%verify "class fails to initialize"
6%verify "class already resolved/initialized"
7%verify "class is abstract or interface"
8%verify "allocation fails"
9    /*
10     * Create a new instance of a class.
11     */
12    /* new-instance vAA, class@BBBB */
13    ldr     r3, [rGLUE, #offGlue_methodClassDex]    @ r3<- pDvmDex
14    FETCH(r1, 1)                        @ r1<- BBBB
15    ldr     r3, [r3, #offDvmDex_pResClasses]    @ r3<- pDvmDex->pResClasses
16    ldr     r0, [r3, r1, lsl #2]        @ r0<- resolved class
17    EXPORT_PC()                         @ req'd for init, resolve, alloc
18    cmp     r0, #0                      @ already resolved?
19    beq     .L${opcode}_resolve         @ no, resolve it now
20.L${opcode}_resolved:   @ r0=class
21    ldrb    r1, [r0, #offClassObject_status]    @ r1<- ClassStatus enum
22    cmp     r1, #CLASS_INITIALIZED      @ has class been initialized?
23    bne     .L${opcode}_needinit        @ no, init class now
24.L${opcode}_initialized: @ r0=class
25    ldr     r3, [r0, #offClassObject_accessFlags]   @ r3<- clazz->accessFlags
26    tst     r3, #(ACC_INTERFACE|ACC_ABSTRACT)   @ abstract or interface?
27    mov     r1, #ALLOC_DONT_TRACK       @ flags for alloc call
28    beq     .L${opcode}_finish          @ concrete class, continue
29    b       .L${opcode}_abstract        @ fail
30%break
31
32    .balign 32                          @ minimize cache lines
33.L${opcode}_finish: @ r0=class
34    bl      dvmAllocObject              @ r0<- new object
35    mov     r3, rINST, lsr #8           @ r3<- AA
36    cmp     r0, #0                      @ failed?
37    beq     common_exceptionThrown      @ yes, handle the exception
38    FETCH_ADVANCE_INST(2)               @ advance rPC, load rINST
39    GET_INST_OPCODE(ip)                 @ extract opcode from rINST
40    SET_VREG(r0, r3)                    @ vAA<- r0
41    GOTO_OPCODE(ip)                     @ jump to next instruction
42
43    /*
44     * Class initialization required.
45     *
46     *  r0 holds class object
47     */
48.L${opcode}_needinit:
49    mov     r9, r0                      @ save r0
50    bl      dvmInitClass                @ initialize class
51    cmp     r0, #0                      @ check boolean result
52    mov     r0, r9                      @ restore r0
53    bne     .L${opcode}_initialized     @ success, continue
54    b       common_exceptionThrown      @ failed, deal with init exception
55
56    /*
57     * Resolution required.  This is the least-likely path.
58     *
59     *  r1 holds BBBB
60     */
61.L${opcode}_resolve:
62    ldr     r3, [rGLUE, #offGlue_method] @ r3<- glue->method
63    mov     r2, #0                      @ r2<- false
64    ldr     r0, [r3, #offMethod_clazz]  @ r0<- method->clazz
65    bl      dvmResolveClass             @ r0<- resolved ClassObject ptr
66    cmp     r0, #0                      @ got null?
67    bne     .L${opcode}_resolved        @ no, continue
68    b       common_exceptionThrown      @ yes, handle exception
69
70    /*
71     * We can't instantiate an abstract class or interface, so throw an
72     * InstantiationError with the class descriptor as the message.
73     *
74     *  r0 holds class object
75     */
76.L${opcode}_abstract:
77    ldr     r1, [r0, #offClassObject_descriptor]
78    ldr     r0, .LstrInstantiationErrorPtr
79    bl      dvmThrowExceptionWithClassMessage
80    b       common_exceptionThrown
81
82.LstrInstantiationErrorPtr:
83    .word   .LstrInstantiationError
84
85