OP_FILLED_NEW_ARRAY.S revision 5d709784bbf5001012d7f25172927d46f6c1abe1
1%default { "isrange":"0" }
2%verify "executed"
3%verify "unimplemented array type"
4    /*
5     * Create a new array with elements filled from registers.
6     *
7     * for: filled-new-array, filled-new-array/range
8     */
9    /* op vB, {vD, vE, vF, vG, vA}, class@CCCC */
10    /* op {vCCCC..v(CCCC+AA-1)}, type@BBBB */
11    ldr     r3, [rGLUE, #offGlue_methodClassDex]    @ r3<- pDvmDex
12    FETCH(r1, 1)                        @ r1<- BBBB
13    ldr     r3, [r3, #offDvmDex_pResClasses]    @ r3<- pDvmDex->pResClasses
14    EXPORT_PC()                         @ need for resolve and alloc
15    ldr     r0, [r3, r1, lsl #2]        @ r0<- resolved class
16    mov     r10, rINST, lsr #8          @ r10<- AA or BA
17    cmp     r0, #0                      @ already resolved?
18    bne     .L${opcode}_continue        @ yes, continue on
198:  ldr     r3, [rGLUE, #offGlue_method] @ r3<- glue->method
20    mov     r2, #0                      @ r2<- false
21    ldr     r0, [r3, #offMethod_clazz]  @ r0<- method->clazz
22    bl      dvmResolveClass             @ r0<- call(clazz, ref)
23    cmp     r0, #0                      @ got null?
24    beq     common_exceptionThrown      @ yes, handle exception
25    b       .L${opcode}_continue
26%break
27
28    /*
29     * On entry:
30     *  r0 holds array class
31     *  r10 holds AA or BA
32     */
33.L${opcode}_continue:
34    ldr     r3, [r0, #offClassObject_descriptor] @ r3<- arrayClass->descriptor
35    mov     r2, #ALLOC_DONT_TRACK       @ r2<- alloc flags
36    ldrb    r3, [r3, #1]                @ r3<- descriptor[1]
37    .if     $isrange
38    mov     r1, r10                     @ r1<- AA (length)
39    .else
40    mov     r1, r10, lsr #4             @ r1<- B (length)
41    .endif
42    cmp     r3, #'I'                    @ array of ints?
43    cmpne   r3, #'L'                    @ array of objects?
44    cmpne   r3, #'['                    @ array of arrays?
45    mov     r9, r1                      @ save length in r9
46    bne     .L${opcode}_notimpl         @ no, not handled yet
47    bl      dvmAllocArrayByClass        @ r0<- call(arClass, length, flags)
48    cmp     r0, #0                      @ null return?
49    beq     common_exceptionThrown      @ alloc failed, handle exception
50
51    FETCH(r1, 2)                        @ r1<- FEDC or CCCC
52    str     r0, [rGLUE, #offGlue_retval]    @ retval.l <- new array
53    add     r0, r0, #offArrayObject_contents @ r0<- newArray->contents
54    subs    r9, r9, #1                  @ length--, check for neg
55    FETCH_ADVANCE_INST(3)               @ advance to next instr, load rINST
56    bmi     2f                          @ was zero, bail
57
58    @ copy values from registers into the array
59    @ r0=array, r1=CCCC/FEDC, r9=length (from AA or B), r10=AA/BA
60    .if     $isrange
61    add     r2, rFP, r1, lsl #2         @ r2<- &fp[CCCC]
621:  ldr     r3, [r2], #4                @ r3<- *r2++
63    subs    r9, r9, #1                  @ count--
64    str     r3, [r0], #4                @ *contents++ = vX
65    bpl     1b
66    @ continue at 2
67    .else
68    cmp     r9, #4                      @ length was initially 5?
69    and     r2, r10, #15                @ r2<- A
70    bne     1f                          @ <= 4 args, branch
71    GET_VREG(r3, r2)                    @ r3<- vA
72    sub     r9, r9, #1                  @ count--
73    str     r3, [r0, #16]               @ contents[4] = vA
741:  and     r2, r1, #15                 @ r2<- F/E/D/C
75    GET_VREG(r3, r2)                    @ r3<- vF/vE/vD/vC
76    mov     r1, r1, lsr #4              @ r1<- next reg in low 4
77    subs    r9, r9, #1                  @ count--
78    str     r3, [r0], #4                @ *contents++ = vX
79    bpl     1b
80    @ continue at 2
81    .endif
82
832:
84    GET_INST_OPCODE(ip)                 @ ip<- opcode from rINST
85    GOTO_OPCODE(ip)                     @ execute it
86
87    /*
88     * Throw an exception indicating that we have not implemented this
89     * mode of filled-new-array.
90     */
91.L${opcode}_notimpl:
92    ldr     r0, .L_strInternalError
93    ldr     r1, .L_strFilledNewArrayNotImpl
94    bl      dvmThrowException
95    b       common_exceptionThrown
96
97    .if     (!$isrange)                 @ define in one or the other, not both
98.L_strFilledNewArrayNotImpl:
99    .word   .LstrFilledNewArrayNotImpl
100.L_strInternalError:
101    .word   .LstrInternalError
102    .endif
103
104