src/cpu/x86/vm/vtableStubs_x86_32.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 451
f8236e79048a
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_vtableStubs_x86_32.cpp.incl"
    28 // machine-dependent part of VtableStubs: create VtableStub of correct size and
    29 // initialize its code
    31 #define __ masm->
    33 #ifndef PRODUCT
    34 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
    35 #endif
    37 // used by compiler only; may use only caller saved registers rax, rbx, rcx.
    38 // rdx holds first int arg, rsi, rdi, rbp are callee-save & must be preserved.
    39 // Leave receiver in rcx; required behavior when +OptoArgsInRegisters
    40 // is modifed to put first oop in rcx.
    41 //
    42 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
    43   const int i486_code_length = VtableStub::pd_code_size_limit(true);
    44   VtableStub* s = new(i486_code_length) VtableStub(true, vtable_index);
    45   ResourceMark rm;
    46   CodeBuffer cb(s->entry_point(), i486_code_length);
    47   MacroAssembler* masm = new MacroAssembler(&cb);
    49 #ifndef PRODUCT
    51   if (CountCompiledCalls) {
    52     __ increment(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));
    53   }
    54 #endif /* PRODUCT */
    56   // get receiver (need to skip return address on top of stack)
    57   assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx");
    59   // get receiver klass
    60   address npe_addr = __ pc();
    61   __ movl(rax, Address(rcx, oopDesc::klass_offset_in_bytes()));
    62   // compute entry offset (in words)
    63   int entry_offset = instanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
    64 #ifndef PRODUCT
    65   if (DebugVtables) {
    66     Label L;
    67     // check offset vs vtable length
    68     __ cmpl(Address(rax, instanceKlass::vtable_length_offset()*wordSize), vtable_index*vtableEntry::size());
    69     __ jcc(Assembler::greater, L);
    70     __ movl(rbx, vtable_index);
    71     __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), rcx, rbx);
    72     __ bind(L);
    73   }
    74 #endif // PRODUCT
    76   const Register method = rbx;
    78   // load methodOop and target address
    79   __ movl(method, Address(rax, entry_offset*wordSize + vtableEntry::method_offset_in_bytes()));
    80   if (DebugVtables) {
    81     Label L;
    82     __ cmpl(method, NULL_WORD);
    83     __ jcc(Assembler::equal, L);
    84     __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), NULL_WORD);
    85     __ jcc(Assembler::notZero, L);
    86     __ stop("Vtable entry is NULL");
    87     __ bind(L);
    88   }
    90   // rax,: receiver klass
    91   // method (rbx): methodOop
    92   // rcx: receiver
    93   address ame_addr = __ pc();
    94   __ jmp( Address(method, methodOopDesc::from_compiled_offset()));
    96   masm->flush();
    97   s->set_exception_points(npe_addr, ame_addr);
    98   return s;
    99 }
   102 VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
   103   // Note well: pd_code_size_limit is the absolute minimum we can get away with.  If you
   104   //            add code here, bump the code stub size returned by pd_code_size_limit!
   105   const int i486_code_length = VtableStub::pd_code_size_limit(false);
   106   VtableStub* s = new(i486_code_length) VtableStub(false, vtable_index);
   107   ResourceMark rm;
   108   CodeBuffer cb(s->entry_point(), i486_code_length);
   109   MacroAssembler* masm = new MacroAssembler(&cb);
   111   // Entry arguments:
   112   //  rax,: Interface
   113   //  rcx: Receiver
   115 #ifndef PRODUCT
   116   if (CountCompiledCalls) {
   117     __ increment(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));
   118   }
   119 #endif /* PRODUCT */
   120   // get receiver (need to skip return address on top of stack)
   122   assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx");
   124   // get receiver klass (also an implicit null-check)
   125   address npe_addr = __ pc();
   126   __ movl(rbx, Address(rcx, oopDesc::klass_offset_in_bytes()));
   128   __ movl(rsi, rbx);   // Save klass in free register
   129   // Most registers are in use, so save a few
   130   __ pushl(rdx);
   131   // compute itable entry offset (in words)
   132   const int base = instanceKlass::vtable_start_offset() * wordSize;
   133   assert(vtableEntry::size() * wordSize == 4, "adjust the scaling in the code below");
   134   __ movl(rdx, Address(rbx, instanceKlass::vtable_length_offset() * wordSize)); // Get length of vtable
   135   __ leal(rbx, Address(rbx, rdx, Address::times_4, base));
   136   if (HeapWordsPerLong > 1) {
   137     // Round up to align_object_offset boundary
   138     __ round_to(rbx, BytesPerLong);
   139   }
   141   Label hit, next, entry;
   143   __ jmp(entry);
   145   __ bind(next);
   146   __ addl(rbx, itableOffsetEntry::size() * wordSize);
   148   __ bind(entry);
   150 #ifdef ASSERT
   151     // Check that the entry is non-null
   152   if (DebugVtables) {
   153     Label L;
   154     __ pushl(rbx);
   155     __ movl(rbx, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
   156     __ testl(rbx, rbx);
   157     __ jcc(Assembler::notZero, L);
   158     __ stop("null entry point found in itable's offset table");
   159     __ bind(L);
   160     __ popl(rbx);
   161   }
   162 #endif
   163   __ cmpl(rax, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
   164   __ jcc(Assembler::notEqual, next);
   166   // We found a hit, move offset into rbx,
   167   __ movl(rdx, Address(rbx, itableOffsetEntry::offset_offset_in_bytes()));
   169   // Compute itableMethodEntry.
   170   const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) + itableMethodEntry::method_offset_in_bytes();
   172   // Get methodOop and entrypoint for compiler
   173   const Register method = rbx;
   174   __ movl(method, Address(rsi, rdx, Address::times_1, method_offset));
   176   // Restore saved register, before possible trap.
   177   __ popl(rdx);
   179   // method (rbx): methodOop
   180   // rcx: receiver
   182 #ifdef ASSERT
   183   if (DebugVtables) {
   184       Label L1;
   185       __ cmpl(method, NULL_WORD);
   186       __ jcc(Assembler::equal, L1);
   187       __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), NULL_WORD);
   188       __ jcc(Assembler::notZero, L1);
   189       __ stop("methodOop is null");
   190       __ bind(L1);
   191     }
   192 #endif // ASSERT
   194   address ame_addr = __ pc();
   195   __ jmp(Address(method, methodOopDesc::from_compiled_offset()));
   197   masm->flush();
   198   s->set_exception_points(npe_addr, ame_addr);
   199   return s;
   200 }
   204 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
   205   if (is_vtable_stub) {
   206     // Vtable stub size
   207     return (DebugVtables ? 210 : 16) + (CountCompiledCalls ? 6 : 0);
   208   } else {
   209     // Itable stub size
   210     return (DebugVtables ? 140 : 55) + (CountCompiledCalls ? 6 : 0);
   211   }
   212 }
   214 int VtableStub::pd_code_alignment() {
   215   return wordSize;
   216 }

mercurial