src/cpu/x86/vm/vtableStubs_x86_32.cpp

Wed, 05 Dec 2007 09:00:00 -0800

author
dcubed
date
Wed, 05 Dec 2007 09:00:00 -0800
changeset 451
f8236e79048a
parent 435
a61af66fc99e
child 739
dc7f315e41f7
permissions
-rw-r--r--

6664627: Merge changes made only in hotspot 11 forward to jdk 7
Reviewed-by: jcoomes

     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, throw_icce;
   143   __ jmpb(entry);
   145   __ bind(next);
   146   __ addl(rbx, itableOffsetEntry::size() * wordSize);
   148   __ bind(entry);
   150   // If the entry is NULL then we've reached the end of the table
   151   // without finding the expected interface, so throw an exception
   152   __ movl(rdx, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
   153   __ testl(rdx, rdx);
   154   __ jcc(Assembler::zero, throw_icce);
   155   __ cmpl(rax, rdx);
   156   __ jcc(Assembler::notEqual, next);
   158   // We found a hit, move offset into rbx,
   159   __ movl(rdx, Address(rbx, itableOffsetEntry::offset_offset_in_bytes()));
   161   // Compute itableMethodEntry.
   162   const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) + itableMethodEntry::method_offset_in_bytes();
   164   // Get methodOop and entrypoint for compiler
   165   const Register method = rbx;
   166   __ movl(method, Address(rsi, rdx, Address::times_1, method_offset));
   168   // Restore saved register, before possible trap.
   169   __ popl(rdx);
   171   // method (rbx): methodOop
   172   // rcx: receiver
   174 #ifdef ASSERT
   175   if (DebugVtables) {
   176       Label L1;
   177       __ cmpl(method, NULL_WORD);
   178       __ jcc(Assembler::equal, L1);
   179       __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), NULL_WORD);
   180       __ jcc(Assembler::notZero, L1);
   181       __ stop("methodOop is null");
   182       __ bind(L1);
   183     }
   184 #endif // ASSERT
   186   address ame_addr = __ pc();
   187   __ jmp(Address(method, methodOopDesc::from_compiled_offset()));
   189   __ bind(throw_icce);
   190   // Restore saved register
   191   __ popl(rdx);
   192   __ jump(RuntimeAddress(StubRoutines::throw_IncompatibleClassChangeError_entry()));
   194   masm->flush();
   196   guarantee(__ pc() <= s->code_end(), "overflowed buffer");
   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 ? 144 : 64) + (CountCompiledCalls ? 6 : 0);
   211   }
   212 }
   214 int VtableStub::pd_code_alignment() {
   215   return wordSize;
   216 }

mercurial