src/cpu/x86/vm/vtableStubs_x86_32.cpp

changeset 435
a61af66fc99e
child 451
f8236e79048a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/x86/vm/vtableStubs_x86_32.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,216 @@
     1.4 +/*
     1.5 + * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_vtableStubs_x86_32.cpp.incl"
    1.30 +
    1.31 +// machine-dependent part of VtableStubs: create VtableStub of correct size and
    1.32 +// initialize its code
    1.33 +
    1.34 +#define __ masm->
    1.35 +
    1.36 +#ifndef PRODUCT
    1.37 +extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
    1.38 +#endif
    1.39 +
    1.40 +// used by compiler only; may use only caller saved registers rax, rbx, rcx.
    1.41 +// rdx holds first int arg, rsi, rdi, rbp are callee-save & must be preserved.
    1.42 +// Leave receiver in rcx; required behavior when +OptoArgsInRegisters
    1.43 +// is modifed to put first oop in rcx.
    1.44 +//
    1.45 +VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
    1.46 +  const int i486_code_length = VtableStub::pd_code_size_limit(true);
    1.47 +  VtableStub* s = new(i486_code_length) VtableStub(true, vtable_index);
    1.48 +  ResourceMark rm;
    1.49 +  CodeBuffer cb(s->entry_point(), i486_code_length);
    1.50 +  MacroAssembler* masm = new MacroAssembler(&cb);
    1.51 +
    1.52 +#ifndef PRODUCT
    1.53 +
    1.54 +  if (CountCompiledCalls) {
    1.55 +    __ increment(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));
    1.56 +  }
    1.57 +#endif /* PRODUCT */
    1.58 +
    1.59 +  // get receiver (need to skip return address on top of stack)
    1.60 +  assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx");
    1.61 +
    1.62 +  // get receiver klass
    1.63 +  address npe_addr = __ pc();
    1.64 +  __ movl(rax, Address(rcx, oopDesc::klass_offset_in_bytes()));
    1.65 +  // compute entry offset (in words)
    1.66 +  int entry_offset = instanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
    1.67 +#ifndef PRODUCT
    1.68 +  if (DebugVtables) {
    1.69 +    Label L;
    1.70 +    // check offset vs vtable length
    1.71 +    __ cmpl(Address(rax, instanceKlass::vtable_length_offset()*wordSize), vtable_index*vtableEntry::size());
    1.72 +    __ jcc(Assembler::greater, L);
    1.73 +    __ movl(rbx, vtable_index);
    1.74 +    __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), rcx, rbx);
    1.75 +    __ bind(L);
    1.76 +  }
    1.77 +#endif // PRODUCT
    1.78 +
    1.79 +  const Register method = rbx;
    1.80 +
    1.81 +  // load methodOop and target address
    1.82 +  __ movl(method, Address(rax, entry_offset*wordSize + vtableEntry::method_offset_in_bytes()));
    1.83 +  if (DebugVtables) {
    1.84 +    Label L;
    1.85 +    __ cmpl(method, NULL_WORD);
    1.86 +    __ jcc(Assembler::equal, L);
    1.87 +    __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), NULL_WORD);
    1.88 +    __ jcc(Assembler::notZero, L);
    1.89 +    __ stop("Vtable entry is NULL");
    1.90 +    __ bind(L);
    1.91 +  }
    1.92 +
    1.93 +  // rax,: receiver klass
    1.94 +  // method (rbx): methodOop
    1.95 +  // rcx: receiver
    1.96 +  address ame_addr = __ pc();
    1.97 +  __ jmp( Address(method, methodOopDesc::from_compiled_offset()));
    1.98 +
    1.99 +  masm->flush();
   1.100 +  s->set_exception_points(npe_addr, ame_addr);
   1.101 +  return s;
   1.102 +}
   1.103 +
   1.104 +
   1.105 +VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
   1.106 +  // Note well: pd_code_size_limit is the absolute minimum we can get away with.  If you
   1.107 +  //            add code here, bump the code stub size returned by pd_code_size_limit!
   1.108 +  const int i486_code_length = VtableStub::pd_code_size_limit(false);
   1.109 +  VtableStub* s = new(i486_code_length) VtableStub(false, vtable_index);
   1.110 +  ResourceMark rm;
   1.111 +  CodeBuffer cb(s->entry_point(), i486_code_length);
   1.112 +  MacroAssembler* masm = new MacroAssembler(&cb);
   1.113 +
   1.114 +  // Entry arguments:
   1.115 +  //  rax,: Interface
   1.116 +  //  rcx: Receiver
   1.117 +
   1.118 +#ifndef PRODUCT
   1.119 +  if (CountCompiledCalls) {
   1.120 +    __ increment(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));
   1.121 +  }
   1.122 +#endif /* PRODUCT */
   1.123 +  // get receiver (need to skip return address on top of stack)
   1.124 +
   1.125 +  assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx");
   1.126 +
   1.127 +  // get receiver klass (also an implicit null-check)
   1.128 +  address npe_addr = __ pc();
   1.129 +  __ movl(rbx, Address(rcx, oopDesc::klass_offset_in_bytes()));
   1.130 +
   1.131 +  __ movl(rsi, rbx);   // Save klass in free register
   1.132 +  // Most registers are in use, so save a few
   1.133 +  __ pushl(rdx);
   1.134 +  // compute itable entry offset (in words)
   1.135 +  const int base = instanceKlass::vtable_start_offset() * wordSize;
   1.136 +  assert(vtableEntry::size() * wordSize == 4, "adjust the scaling in the code below");
   1.137 +  __ movl(rdx, Address(rbx, instanceKlass::vtable_length_offset() * wordSize)); // Get length of vtable
   1.138 +  __ leal(rbx, Address(rbx, rdx, Address::times_4, base));
   1.139 +  if (HeapWordsPerLong > 1) {
   1.140 +    // Round up to align_object_offset boundary
   1.141 +    __ round_to(rbx, BytesPerLong);
   1.142 +  }
   1.143 +
   1.144 +  Label hit, next, entry;
   1.145 +
   1.146 +  __ jmp(entry);
   1.147 +
   1.148 +  __ bind(next);
   1.149 +  __ addl(rbx, itableOffsetEntry::size() * wordSize);
   1.150 +
   1.151 +  __ bind(entry);
   1.152 +
   1.153 +#ifdef ASSERT
   1.154 +    // Check that the entry is non-null
   1.155 +  if (DebugVtables) {
   1.156 +    Label L;
   1.157 +    __ pushl(rbx);
   1.158 +    __ movl(rbx, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
   1.159 +    __ testl(rbx, rbx);
   1.160 +    __ jcc(Assembler::notZero, L);
   1.161 +    __ stop("null entry point found in itable's offset table");
   1.162 +    __ bind(L);
   1.163 +    __ popl(rbx);
   1.164 +  }
   1.165 +#endif
   1.166 +  __ cmpl(rax, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
   1.167 +  __ jcc(Assembler::notEqual, next);
   1.168 +
   1.169 +  // We found a hit, move offset into rbx,
   1.170 +  __ movl(rdx, Address(rbx, itableOffsetEntry::offset_offset_in_bytes()));
   1.171 +
   1.172 +  // Compute itableMethodEntry.
   1.173 +  const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) + itableMethodEntry::method_offset_in_bytes();
   1.174 +
   1.175 +  // Get methodOop and entrypoint for compiler
   1.176 +  const Register method = rbx;
   1.177 +  __ movl(method, Address(rsi, rdx, Address::times_1, method_offset));
   1.178 +
   1.179 +  // Restore saved register, before possible trap.
   1.180 +  __ popl(rdx);
   1.181 +
   1.182 +  // method (rbx): methodOop
   1.183 +  // rcx: receiver
   1.184 +
   1.185 +#ifdef ASSERT
   1.186 +  if (DebugVtables) {
   1.187 +      Label L1;
   1.188 +      __ cmpl(method, NULL_WORD);
   1.189 +      __ jcc(Assembler::equal, L1);
   1.190 +      __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), NULL_WORD);
   1.191 +      __ jcc(Assembler::notZero, L1);
   1.192 +      __ stop("methodOop is null");
   1.193 +      __ bind(L1);
   1.194 +    }
   1.195 +#endif // ASSERT
   1.196 +
   1.197 +  address ame_addr = __ pc();
   1.198 +  __ jmp(Address(method, methodOopDesc::from_compiled_offset()));
   1.199 +
   1.200 +  masm->flush();
   1.201 +  s->set_exception_points(npe_addr, ame_addr);
   1.202 +  return s;
   1.203 +}
   1.204 +
   1.205 +
   1.206 +
   1.207 +int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
   1.208 +  if (is_vtable_stub) {
   1.209 +    // Vtable stub size
   1.210 +    return (DebugVtables ? 210 : 16) + (CountCompiledCalls ? 6 : 0);
   1.211 +  } else {
   1.212 +    // Itable stub size
   1.213 +    return (DebugVtables ? 140 : 55) + (CountCompiledCalls ? 6 : 0);
   1.214 +  }
   1.215 +}
   1.216 +
   1.217 +int VtableStub::pd_code_alignment() {
   1.218 +  return wordSize;
   1.219 +}

mercurial