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, [rSELF, #offThread_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#if defined(WITH_JIT)
18    add     r10, r3, r1, lsl #2         @ r10<- &resolved_class
19#endif
20    EXPORT_PC()                         @ req'd for init, resolve, alloc
21    cmp     r0, #0                      @ already resolved?
22    beq     .L${opcode}_resolve         @ no, resolve it now
23.L${opcode}_resolved:   @ r0=class
24    ldrb    r1, [r0, #offClassObject_status]    @ r1<- ClassStatus enum
25    cmp     r1, #CLASS_INITIALIZED      @ has class been initialized?
26    bne     .L${opcode}_needinit        @ no, init class now
27.L${opcode}_initialized: @ r0=class
28    mov     r1, #ALLOC_DONT_TRACK       @ flags for alloc call
29    bl      dvmAllocObject              @ r0<- new object
30    b       .L${opcode}_finish          @ continue
31%break
32
33    .balign 32                          @ minimize cache lines
34.L${opcode}_finish: @ r0=new object
35    mov     r3, rINST, lsr #8           @ r3<- AA
36    cmp     r0, #0                      @ failed?
37#if defined(WITH_JIT)
38    /*
39     * The JIT needs the class to be fully resolved before it can
40     * include this instruction in a trace.
41     */
42    ldrh    r1, [rSELF, #offThread_subMode]
43    beq     common_exceptionThrown      @ yes, handle the exception
44    ands    r1, #kSubModeJitTraceBuild  @ under construction?
45    bne     .L${opcode}_jitCheck
46#else
47    beq     common_exceptionThrown      @ yes, handle the exception
48#endif
49.L${opcode}_end:
50    FETCH_ADVANCE_INST(2)               @ advance rPC, load rINST
51    GET_INST_OPCODE(ip)                 @ extract opcode from rINST
52    SET_VREG(r0, r3)                    @ vAA<- r0
53    GOTO_OPCODE(ip)                     @ jump to next instruction
54
55#if defined(WITH_JIT)
56    /*
57     * Check to see if we need to stop the trace building early.
58     * r0: new object
59     * r3: vAA
60     */
61.L${opcode}_jitCheck:
62    ldr     r1, [r10]                   @ reload resolved class
63    cmp     r1, #0                      @ okay?
64    bne     .L${opcode}_end             @ yes, finish
65    mov     r9, r0                      @ preserve new object
66    mov     r10, r3                     @ preserve vAA
67    mov     r0, rSELF
68    mov     r1, rPC
69    bl      dvmJitEndTraceSelect        @ (self, pc)
70    FETCH_ADVANCE_INST(2)               @ advance rPC, load rINST
71    GET_INST_OPCODE(ip)                 @ extract opcode from rINST
72    SET_VREG(r9, r10)                   @ vAA<- new object
73    GOTO_OPCODE(ip)                     @ jump to next instruction
74#endif
75
76    /*
77     * Class initialization required.
78     *
79     *  r0 holds class object
80     */
81.L${opcode}_needinit:
82    mov     r9, r0                      @ save r0
83    bl      dvmInitClass                @ initialize class
84    cmp     r0, #0                      @ check boolean result
85    mov     r0, r9                      @ restore r0
86    bne     .L${opcode}_initialized     @ success, continue
87    b       common_exceptionThrown      @ failed, deal with init exception
88
89    /*
90     * Resolution required.  This is the least-likely path.
91     *
92     *  r1 holds BBBB
93     */
94.L${opcode}_resolve:
95    ldr     r3, [rSELF, #offThread_method] @ r3<- self->method
96    mov     r2, #0                      @ r2<- false
97    ldr     r0, [r3, #offMethod_clazz]  @ r0<- method->clazz
98    bl      dvmResolveClass             @ r0<- resolved ClassObject ptr
99    cmp     r0, #0                      @ got null?
100    bne     .L${opcode}_resolved        @ no, continue
101    b       common_exceptionThrown      @ yes, handle exception
102