src/cpu/sparc/vm/vtableStubs_sparc.cpp

changeset 435
a61af66fc99e
child 451
f8236e79048a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/sparc/vm/vtableStubs_sparc.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,280 @@
     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_sparc.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 +
    1.37 +#ifndef PRODUCT
    1.38 +extern "C" void bad_compiled_vtable_index(JavaThread* thread, oopDesc* receiver, int index);
    1.39 +#endif
    1.40 +
    1.41 +
    1.42 +// Used by compiler only; may use only caller saved, non-argument registers
    1.43 +// NOTE:  %%%% if any change is made to this stub make sure that the function
    1.44 +//             pd_code_size_limit is changed to ensure the correct size for VtableStub
    1.45 +VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
    1.46 +  const int sparc_code_length = VtableStub::pd_code_size_limit(true);
    1.47 +  VtableStub* s = new(sparc_code_length) VtableStub(true, vtable_index);
    1.48 +  ResourceMark rm;
    1.49 +  CodeBuffer cb(s->entry_point(), sparc_code_length);
    1.50 +  MacroAssembler* masm = new MacroAssembler(&cb);
    1.51 +
    1.52 +#ifndef PRODUCT
    1.53 +  if (CountCompiledCalls) {
    1.54 +    Address ctr(G5, SharedRuntime::nof_megamorphic_calls_addr());
    1.55 +    __ sethi(ctr);
    1.56 +    __ ld(ctr, G3_scratch);
    1.57 +    __ inc(G3_scratch);
    1.58 +    __ st(G3_scratch, ctr);
    1.59 +  }
    1.60 +#endif /* PRODUCT */
    1.61 +
    1.62 +  assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");
    1.63 +
    1.64 +  // get receiver klass
    1.65 +  address npe_addr = __ pc();
    1.66 +  __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), G3_scratch);
    1.67 +
    1.68 +  // set methodOop (in case of interpreted method), and destination address
    1.69 +  int entry_offset = instanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
    1.70 +#ifndef PRODUCT
    1.71 +  if (DebugVtables) {
    1.72 +    Label L;
    1.73 +    // check offset vs vtable length
    1.74 +    __ ld(G3_scratch, instanceKlass::vtable_length_offset()*wordSize, G5);
    1.75 +    __ cmp(G5, vtable_index*vtableEntry::size());
    1.76 +    __ br(Assembler::greaterUnsigned, false, Assembler::pt, L);
    1.77 +    __ delayed()->nop();
    1.78 +    __ set(vtable_index, O2);
    1.79 +    __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), O0, O2);
    1.80 +    __ bind(L);
    1.81 +  }
    1.82 +#endif
    1.83 +  int v_off = entry_offset*wordSize + vtableEntry::method_offset_in_bytes();
    1.84 +  if( __ is_simm13(v_off) ) {
    1.85 +    __ ld_ptr(G3, v_off, G5_method);
    1.86 +  } else {
    1.87 +    __ set(v_off,G5);
    1.88 +    __ ld_ptr(G3, G5, G5_method);
    1.89 +  }
    1.90 +
    1.91 +#ifndef PRODUCT
    1.92 +  if (DebugVtables) {
    1.93 +    Label L;
    1.94 +    __ br_notnull(G5_method, false, Assembler::pt, L);
    1.95 +    __ delayed()->nop();
    1.96 +    __ stop("Vtable entry is ZERO");
    1.97 +    __ bind(L);
    1.98 +  }
    1.99 +#endif
   1.100 +
   1.101 +  address ame_addr = __ pc();  // if the vtable entry is null, the method is abstract
   1.102 +                               // NOTE: for vtable dispatches, the vtable entry will never be null.
   1.103 +
   1.104 +  __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);
   1.105 +
   1.106 +  // jump to target (either compiled code or c2iadapter)
   1.107 +  __ JMP(G3_scratch, 0);
   1.108 +  // load methodOop (in case we call c2iadapter)
   1.109 +  __ delayed()->nop();
   1.110 +
   1.111 +  masm->flush();
   1.112 +  s->set_exception_points(npe_addr, ame_addr);
   1.113 +  return s;
   1.114 +}
   1.115 +
   1.116 +
   1.117 +// NOTE:  %%%% if any change is made to this stub make sure that the function
   1.118 +//             pd_code_size_limit is changed to ensure the correct size for VtableStub
   1.119 +VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
   1.120 +  const int sparc_code_length = VtableStub::pd_code_size_limit(false);
   1.121 +  VtableStub* s = new(sparc_code_length) VtableStub(false, vtable_index);
   1.122 +  ResourceMark rm;
   1.123 +  CodeBuffer cb(s->entry_point(), sparc_code_length);
   1.124 +  MacroAssembler* masm = new MacroAssembler(&cb);
   1.125 +
   1.126 +  Register G3_klassOop = G3_scratch;
   1.127 +  Register G5_interface = G5;  // Passed in as an argument
   1.128 +  Label search;
   1.129 +
   1.130 +  // Entry arguments:
   1.131 +  //  G5_interface: Interface
   1.132 +  //  O0:           Receiver
   1.133 +  assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");
   1.134 +
   1.135 +  // get receiver klass (also an implicit null-check)
   1.136 +  address npe_addr = __ pc();
   1.137 +  __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), G3_klassOop);
   1.138 +  __ verify_oop(G3_klassOop);
   1.139 +
   1.140 +  // Push a new window to get some temp registers.  This chops the head of all
   1.141 +  // my 64-bit %o registers in the LION build, but this is OK because no longs
   1.142 +  // are passed in the %o registers.  Instead, longs are passed in G1 and G4
   1.143 +  // and so those registers are not available here.
   1.144 +  __ save(SP,-frame::register_save_words*wordSize,SP);
   1.145 +  Register I0_receiver = I0;    // Location of receiver after save
   1.146 +
   1.147 +#ifndef PRODUCT
   1.148 +  if (CountCompiledCalls) {
   1.149 +    Address ctr(L0, SharedRuntime::nof_megamorphic_calls_addr());
   1.150 +    __ sethi(ctr);
   1.151 +    __ ld(ctr, L1);
   1.152 +    __ inc(L1);
   1.153 +    __ st(L1, ctr);
   1.154 +  }
   1.155 +#endif /* PRODUCT */
   1.156 +
   1.157 +  // load start of itable entries into L0 register
   1.158 +  const int base = instanceKlass::vtable_start_offset() * wordSize;
   1.159 +  __ ld(Address(G3_klassOop, 0, instanceKlass::vtable_length_offset() * wordSize), L0);
   1.160 +
   1.161 +  // %%% Could store the aligned, prescaled offset in the klassoop.
   1.162 +  __ sll(L0, exact_log2(vtableEntry::size() * wordSize), L0);
   1.163 +  // see code for instanceKlass::start_of_itable!
   1.164 +  const int vtable_alignment = align_object_offset(1);
   1.165 +  assert(vtable_alignment == 1 || vtable_alignment == 2, "");
   1.166 +  const int odd_bit = vtableEntry::size() * wordSize;
   1.167 +  if (vtable_alignment == 2) {
   1.168 +    __ and3(L0, odd_bit, L1);   // isolate the odd bit
   1.169 +  }
   1.170 +  __ add(G3_klassOop, L0, L0);
   1.171 +  if (vtable_alignment == 2) {
   1.172 +    __ add(L0, L1, L0);         // double the odd bit, to align up
   1.173 +  }
   1.174 +
   1.175 +  // Loop over all itable entries until desired interfaceOop (G5_interface) found
   1.176 +  __ bind(search);
   1.177 +
   1.178 +  // %%%% Could load both offset and interface in one ldx, if they were
   1.179 +  // in the opposite order.  This would save a load.
   1.180 +  __ ld_ptr(L0, base + itableOffsetEntry::interface_offset_in_bytes(), L1);
   1.181 +#ifdef ASSERT
   1.182 +  Label ok;
   1.183 +  // Check that entry is non-null and an Oop
   1.184 +  __ bpr(Assembler::rc_nz, false, Assembler::pt, L1, ok);
   1.185 +  __ delayed()->nop();
   1.186 +  __ stop("null entry point found in itable's offset table");
   1.187 +  __ bind(ok);
   1.188 +  __ verify_oop(L1);
   1.189 +#endif // ASSERT
   1.190 +
   1.191 +  __ cmp(G5_interface, L1);
   1.192 +  __ brx(Assembler::notEqual, true, Assembler::pn, search);
   1.193 +  __ delayed()->add(L0, itableOffsetEntry::size() * wordSize, L0);
   1.194 +
   1.195 +  // entry found and L0 points to it, move offset of vtable for interface into L0
   1.196 +  __ ld(L0, base + itableOffsetEntry::offset_offset_in_bytes(), L0);
   1.197 +
   1.198 +  // Compute itableMethodEntry and get methodOop(G5_method) and entrypoint(L0) for compiler
   1.199 +  const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) + itableMethodEntry::method_offset_in_bytes();
   1.200 +  __ add(G3_klassOop, L0, L1);
   1.201 +  __ ld_ptr(L1, method_offset, G5_method);
   1.202 +
   1.203 +#ifndef PRODUCT
   1.204 +  if (DebugVtables) {
   1.205 +    Label L01;
   1.206 +    __ ld_ptr(L1, method_offset, G5_method);
   1.207 +    __ bpr(Assembler::rc_nz, false, Assembler::pt, G5_method, L01);
   1.208 +    __ delayed()->nop();
   1.209 +    __ stop("methodOop is null");
   1.210 +    __ bind(L01);
   1.211 +    __ verify_oop(G5_method);
   1.212 +  }
   1.213 +#endif
   1.214 +
   1.215 +  // If the following load is through a NULL pointer, we'll take an OS
   1.216 +  // exception that should translate into an AbstractMethodError.  We need the
   1.217 +  // window count to be correct at that time.
   1.218 +  __ restore();                 // Restore registers BEFORE the AME point
   1.219 +
   1.220 +  address ame_addr = __ pc();   // if the vtable entry is null, the method is abstract
   1.221 +  __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);
   1.222 +
   1.223 +  // G5_method:  methodOop
   1.224 +  // O0:         Receiver
   1.225 +  // G3_scratch: entry point
   1.226 +  __ JMP(G3_scratch, 0);
   1.227 +  __ delayed()->nop();
   1.228 +
   1.229 +  masm->flush();
   1.230 +  s->set_exception_points(npe_addr, ame_addr);
   1.231 +  return s;
   1.232 +}
   1.233 +
   1.234 +
   1.235 +int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
   1.236 +  if (TraceJumps || DebugVtables || CountCompiledCalls || VerifyOops) return 999;
   1.237 +  else {
   1.238 +    const int slop = 2*BytesPerInstWord; // sethi;add  (needed for long offsets)
   1.239 +    if (is_vtable_stub) {
   1.240 +      const int basic = 5*BytesPerInstWord; // ld;ld;ld,jmp,nop
   1.241 +      return basic + slop;
   1.242 +    } else {
   1.243 +#ifdef ASSERT
   1.244 +      return 999;
   1.245 +#endif // ASSERT
   1.246 +      const int basic = 17*BytesPerInstWord; // save, ld, ld, sll, and, add, add, ld, cmp, br, add, ld, add, ld, ld, jmp, restore
   1.247 +      return (basic + slop);
   1.248 +    }
   1.249 +  }
   1.250 +}
   1.251 +
   1.252 +
   1.253 +int VtableStub::pd_code_alignment() {
   1.254 +  // UltraSPARC cache line size is 8 instructions:
   1.255 +  const unsigned int icache_line_size = 32;
   1.256 +  return icache_line_size;
   1.257 +}
   1.258 +
   1.259 +
   1.260 +//Reconciliation History
   1.261 +// 1.2 97/12/09 17:13:31 vtableStubs_i486.cpp
   1.262 +// 1.4 98/01/21 19:18:37 vtableStubs_i486.cpp
   1.263 +// 1.5 98/02/13 16:33:55 vtableStubs_i486.cpp
   1.264 +// 1.7 98/03/05 17:17:28 vtableStubs_i486.cpp
   1.265 +// 1.9 98/05/18 09:26:17 vtableStubs_i486.cpp
   1.266 +// 1.10 98/05/26 16:28:13 vtableStubs_i486.cpp
   1.267 +// 1.11 98/05/27 08:51:35 vtableStubs_i486.cpp
   1.268 +// 1.12 98/06/15 15:04:12 vtableStubs_i486.cpp
   1.269 +// 1.13 98/07/28 18:44:22 vtableStubs_i486.cpp
   1.270 +// 1.15 98/08/28 11:31:19 vtableStubs_i486.cpp
   1.271 +// 1.16 98/09/02 12:58:31 vtableStubs_i486.cpp
   1.272 +// 1.17 98/09/04 12:15:52 vtableStubs_i486.cpp
   1.273 +// 1.18 98/11/19 11:55:24 vtableStubs_i486.cpp
   1.274 +// 1.19 99/01/12 14:57:56 vtableStubs_i486.cpp
   1.275 +// 1.20 99/01/19 17:42:52 vtableStubs_i486.cpp
   1.276 +// 1.22 99/01/21 10:29:25 vtableStubs_i486.cpp
   1.277 +// 1.30 99/06/02 15:27:39 vtableStubs_i486.cpp
   1.278 +// 1.26 99/06/24 14:25:07 vtableStubs_i486.cpp
   1.279 +// 1.23 99/02/22 14:37:52 vtableStubs_i486.cpp
   1.280 +// 1.28 99/06/29 18:06:17 vtableStubs_i486.cpp
   1.281 +// 1.29 99/07/22 17:03:44 vtableStubs_i486.cpp
   1.282 +// 1.30 99/08/11 09:33:27 vtableStubs_i486.cpp
   1.283 +//End

mercurial