Home | History | Annotate | Download | only in x86-atom
      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_INVOKE_VIRTUAL.S
     18     *
     19     * Code: Call a virtual method. Provides an "isrange" variable and
     20     *       a "routine" variable to specify this is the "range" version of
     21     *       invoke_direct that allows up to 255 arguments.
     22     *
     23     * For: invoke-virtual, invoke-virtual/range
     24     *
     25     * Description: invoke-virtual is used to invoke a normal virtual method;
     26     *              a method that is not static or final, and is not a constructor.
     27     *
     28     * Format: B|A|op CCCC G|F|E|D (35c)
     29     *         AA|op BBBB CCCC (3rc)
     30     *
     31     * Syntax: [B=5] op {vD, vE, vF, vG, vA}, meth@CCCC (35c)
     32     *         [B=5] op {vD, vE, vF, vG, vA}, type@CCCC (35c)
     33     *         [B=4] op {vD, vE, vF, vG}, kind@CCCC (35c)
     34     *         [B=3] op {vD, vE, vF}, kind@CCCC (35c)
     35     *         [B=2] op {vD, vE}, kind@CCCC (35c)
     36     *         [B=1] op {vD}, kind@CCCC (35c)
     37     *         [B=0] op {}, kind@CCCC (35c)
     38     *
     39     *         op {vCCCC .. vNNNN}, meth@BBBB (3rc) (where NNNN = CCCC+AA-1, that
     40     *         op {vCCCC .. vNNNN}, type@BBBB (3rc) is A determines the count 0..255,
     41     *                                              and C determines the first register)
     42     */
     43 
     44 %default { "isrange":"0", "routine":"NoRange" }
     45 
     46     movl        rGLUE, %eax             # %eax<- pMterpGlue
     47     EXPORT_PC                           # must export pc for invoke
     48     movl        offGlue_methodClassDex(%eax), %eax # %eax<- pDvmDex
     49     FETCH       1, %ecx                 # %ecx<- method index
     50     movl        offDvmDex_pResMethods(%eax), %eax # %eax<- pDvmDex->pResMethods
     51     FETCH       2, %edx                 # %edx<- GFED or CCCC
     52     .if         (!$isrange)
     53     and         $$15, %edx              # %edx<- D if not range
     54     .endif
     55     cmp         $$0, (%eax, %ecx, 4)    # check if already resolved
     56     je          .L${opcode}_break
     57     movl        (%eax, %ecx, 4), %eax   # %eax<- resolved base method
     58     jmp         .L${opcode}_continue
     59 %break
     60 
     61 .L${opcode}_break:
     62     movl        rGLUE, %eax             # %eax<- pMterpGlue
     63     movl        %edx, -4(%esp)          # save "this" pointer register
     64     movl        offGlue_method(%eax), %eax # %eax<- glue->method
     65     movl        $$METHOD_VIRTUAL, -8(%esp) # push parameter method type
     66     movl        %ecx, -12(%esp)         # push paramter method index
     67     movl        offMethod_clazz(%eax), %eax # %eax<- glue->method->clazz
     68     lea         -16(%esp), %esp
     69     movl        %eax, (%esp)            # push parameter clazz
     70     call        dvmResolveMethod        # call: (const ClassObject* referrer,
     71                                         #       u4 methodIdx, MethodType methodType)
     72                                         # return: Method*
     73     lea         16(%esp), %esp
     74     cmp         $$0, %eax               # check for null method return
     75     movl        -4(%esp), %edx          # get "this" pointer register
     76     jne         .L${opcode}_continue
     77     jmp         common_exceptionThrown  # null pointer; handle exception
     78 
     79    /*
     80     * At this point:
     81     *  %eax = resolved base method
     82     *  %edx = D or CCCC (index of first arg, which is the "this" ptr)
     83     */
     84 
     85 .L${opcode}_continue:
     86     GET_VREG    %edx                    # %edx<- "this" ptr
     87     movzwl      offMethod_methodIndex(%eax), %eax # %eax<- baseMethod->methodIndex
     88     cmp         $$0, %edx               # %edx<- check for null "this"
     89     je          common_errNullObject    # handle null object
     90     movl        offObject_clazz(%edx), %edx # %edx<- thisPtr->clazz
     91     movl        offClassObject_vtable(%edx), %edx # %edx<- thisPtr->clazz->vtable
     92     movl        (%edx, %eax, 4), %ecx   # %ecx<- vtable[methodIndex]
     93     jmp         common_invokeMethod${routine} # invoke method common code
     94