• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1   /* Copyright (C) 2008 The Android Open Source Project
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10    * distributed under the License is distributed on an "AS IS" BASIS,
11    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    * See the License for the specific language governing permissions and
13    * limitations under the License.
14    */
15
16   /*
17    * File: OP_NEW_INSTANCE.S
18    *
19    * Code: Create a new instance of a given type. Uses no substitutions.
20    *
21    * For: new-instance
22    *
23    * Description: Construct a new instance of the indicated type,
24    *              storing a reference to it in the destination.
25    *              The type must refer to a non-array class.
26    *
27    *
28    *
29    * Format: AA|op BBBB (21c)
30    *
31    * Syntax: op vAA, type@BBBB
32    *         op vAA, field@BBBB
33    *         op vAA, string@BBBB
34    */
35
36    movl        rGLUE, %ecx             # %ecx<- pMterpGlue
37    movl        offGlue_methodClassDex(%ecx), %ecx # %ecx<- glue->pDvmDex
38    FETCH       1, %edx                 # %edx<- BBBB
39    movl        offDvmDex_pResClasses(%ecx), %ecx # %ecx<- glue->pDvmDex->pResClasses
40    movl        (%ecx, %edx, 4), %edx   # %edx<- vB
41    EXPORT_PC                           # required for resolve
42    cmp         $$0, %edx               # check for null
43    je          .L${opcode}_resolve     # need to resolve
44
45   /*
46    *  %edx holds class object
47    */
48
49.L${opcode}_resolved:
50    movzbl      offClassObject_status(%edx), %eax # %eax<- class status
51    cmp         $$CLASS_INITIALIZED, %eax # check if class is initialized
52    jne         .L${opcode}_needinit    # initialize class
53
54   /*
55    *  %edx holds class object
56    */
57
58.L${opcode}_initialized:
59    testl       $$(ACC_INTERFACE|ACC_ABSTRACT), offClassObject_accessFlags(%edx)
60    mov         $$ALLOC_DONT_TRACK, %eax # %eax<- flag for alloc call
61    je          .L${opcode}_finish      # continue
62    jmp         .L${opcode}_abstract    # handle abstract or interface
63
64   /*
65    *  %edx holds class object
66    *  %eax holds flags for alloc call
67    */
68
69%break
70.balign 32
71.L${opcode}_finish:
72    movl        %edx, -8(%esp)          # push parameter object
73    movl        %eax, -4(%esp)          # push parameter flags
74    lea         -8(%esp), %esp
75    call        dvmAllocObject          # call: (ClassObject* clazz, int flags)
76                                        # return: Object*
77    cmp         $$0, %eax               # check for failure
78    lea         8(%esp), %esp
79    je          common_exceptionThrown  # handle exception
80    SET_VREG    %eax, rINST             # vAA<- pObject
81    FINISH      2                       # jump to next instruction
82
83   /*
84    * Class initialization required.
85    *
86    *  %edx holds class object
87    */
88
89.L${opcode}_needinit:
90    movl        %edx, -4(%esp)          # push parameter object
91    lea         -4(%esp), %esp
92    call        dvmInitClass            # call: (ClassObject* clazz)
93                                        # return: bool
94    lea         4(%esp), %esp
95    cmp         $$0, %eax               # check for failure
96    movl        -4(%esp), %edx          # %edx<- object
97    je          common_exceptionThrown  # handle exception
98    testl       $$(ACC_INTERFACE|ACC_ABSTRACT), offClassObject_accessFlags(%edx)
99    mov         $$ALLOC_DONT_TRACK, %eax # %eax<- flag for alloc call
100    je          .L${opcode}_finish      # continue
101    jmp         .L${opcode}_abstract    # handle abstract or interface
102
103   /*
104    * Resolution required.  This is the least-likely path.
105    *
106    *  BBBB in %eax
107    */
108
109.L${opcode}_resolve:
110
111
112    movl        rGLUE, %ecx             # %ecx<- pMterpGlue
113    FETCH       1, %eax                 # %eax<- BBBB
114    movl        offGlue_method(%ecx), %ecx # %ecx<- glue->method
115    movl        offMethod_clazz(%ecx), %ecx # %ecx<- glue->method->clazz
116    movl        %ecx, -12(%esp)         # push parameter clazz
117    movl        $$0, -4(%esp)           # push parameter false
118    movl        %eax, -8(%esp)          # push parameter BBBB
119    lea         -12(%esp), %esp
120    call        dvmResolveClass         # call: (const ClassObject* referrer,
121                                        #       u4 classIdx, bool fromUnverifiedConstant)
122                                        # return: ClassObject*
123    lea         12(%esp), %esp
124    movl        %eax, %edx              # %edx<- pObject
125    cmp         $$0, %edx               # check for failure
126    jne         .L${opcode}_resolved    # continue
127    jmp         common_exceptionThrown  # handle exception
128
129   /*
130    * We can't instantiate an abstract class or interface, so throw an
131    * InstantiationError with the class descriptor as the message.
132    *
133    *  %edx holds class object
134    */
135
136.L${opcode}_abstract:
137    movl        offClassObject_descriptor(%edx), %ecx # %ecx<- descriptor
138    movl        %ecx, -4(%esp)          # push parameter descriptor
139    movl        $$.LstrInstantiationErrorPtr, -8(%esp) # push parameter message
140    lea         -8(%esp), %esp
141    call        dvmThrowExceptionWithClassMessage # call: (const char* exceptionDescriptor,
142                                                  #        const char* messageDescriptor)
143                                                  # return: void
144    jmp         common_exceptionThrown  # handle exception
145
146.LstrInstantiationErrorPtr:
147.asciz      "Ljava/lang/InstantiationError;"
148