src/cpu/sparc/vm/vtableStubs_sparc.cpp

Wed, 08 Apr 2009 10:56:49 -0700

author
jrose
date
Wed, 08 Apr 2009 10:56:49 -0700
changeset 1145
e5b0439ef4ae
parent 1144
1d037ecd7960
child 1162
6b2273dd6fa9
permissions
-rw-r--r--

6655638: dynamic languages need method handles
Summary: initial implementation, with known omissions (x86/64, sparc, compiler optim., c-oops, C++ interp.)
Reviewed-by: kvn, twisti, never

duke@435 1 /*
xdono@631 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_vtableStubs_sparc.cpp.incl"
duke@435 27
duke@435 28 // machine-dependent part of VtableStubs: create vtableStub of correct size and
duke@435 29 // initialize its code
duke@435 30
duke@435 31 #define __ masm->
duke@435 32
duke@435 33
duke@435 34 #ifndef PRODUCT
duke@435 35 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oopDesc* receiver, int index);
duke@435 36 #endif
duke@435 37
duke@435 38
duke@435 39 // Used by compiler only; may use only caller saved, non-argument registers
duke@435 40 // NOTE: %%%% if any change is made to this stub make sure that the function
duke@435 41 // pd_code_size_limit is changed to ensure the correct size for VtableStub
duke@435 42 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
duke@435 43 const int sparc_code_length = VtableStub::pd_code_size_limit(true);
duke@435 44 VtableStub* s = new(sparc_code_length) VtableStub(true, vtable_index);
duke@435 45 ResourceMark rm;
duke@435 46 CodeBuffer cb(s->entry_point(), sparc_code_length);
duke@435 47 MacroAssembler* masm = new MacroAssembler(&cb);
duke@435 48
duke@435 49 #ifndef PRODUCT
duke@435 50 if (CountCompiledCalls) {
duke@435 51 Address ctr(G5, SharedRuntime::nof_megamorphic_calls_addr());
duke@435 52 __ sethi(ctr);
duke@435 53 __ ld(ctr, G3_scratch);
duke@435 54 __ inc(G3_scratch);
duke@435 55 __ st(G3_scratch, ctr);
duke@435 56 }
duke@435 57 #endif /* PRODUCT */
duke@435 58
duke@435 59 assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");
duke@435 60
duke@435 61 // get receiver klass
duke@435 62 address npe_addr = __ pc();
coleenp@548 63 __ load_klass(O0, G3_scratch);
duke@435 64
duke@435 65 // set methodOop (in case of interpreted method), and destination address
duke@435 66 int entry_offset = instanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
duke@435 67 #ifndef PRODUCT
duke@435 68 if (DebugVtables) {
duke@435 69 Label L;
duke@435 70 // check offset vs vtable length
duke@435 71 __ ld(G3_scratch, instanceKlass::vtable_length_offset()*wordSize, G5);
duke@435 72 __ cmp(G5, vtable_index*vtableEntry::size());
duke@435 73 __ br(Assembler::greaterUnsigned, false, Assembler::pt, L);
duke@435 74 __ delayed()->nop();
duke@435 75 __ set(vtable_index, O2);
duke@435 76 __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), O0, O2);
duke@435 77 __ bind(L);
duke@435 78 }
duke@435 79 #endif
duke@435 80 int v_off = entry_offset*wordSize + vtableEntry::method_offset_in_bytes();
duke@435 81 if( __ is_simm13(v_off) ) {
duke@435 82 __ ld_ptr(G3, v_off, G5_method);
duke@435 83 } else {
duke@435 84 __ set(v_off,G5);
duke@435 85 __ ld_ptr(G3, G5, G5_method);
duke@435 86 }
duke@435 87
duke@435 88 #ifndef PRODUCT
duke@435 89 if (DebugVtables) {
duke@435 90 Label L;
duke@435 91 __ br_notnull(G5_method, false, Assembler::pt, L);
duke@435 92 __ delayed()->nop();
duke@435 93 __ stop("Vtable entry is ZERO");
duke@435 94 __ bind(L);
duke@435 95 }
duke@435 96 #endif
duke@435 97
duke@435 98 address ame_addr = __ pc(); // if the vtable entry is null, the method is abstract
duke@435 99 // NOTE: for vtable dispatches, the vtable entry will never be null.
duke@435 100
duke@435 101 __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);
duke@435 102
duke@435 103 // jump to target (either compiled code or c2iadapter)
duke@435 104 __ JMP(G3_scratch, 0);
duke@435 105 // load methodOop (in case we call c2iadapter)
duke@435 106 __ delayed()->nop();
duke@435 107
duke@435 108 masm->flush();
jrose@1058 109
jrose@1058 110 if (PrintMiscellaneous && (WizardMode || Verbose)) {
jrose@1058 111 tty->print_cr("vtable #%d at "PTR_FORMAT"[%d] left over: %d",
jrose@1058 112 vtable_index, s->entry_point(),
jrose@1058 113 (int)(s->code_end() - s->entry_point()),
jrose@1058 114 (int)(s->code_end() - __ pc()));
jrose@1058 115 }
jrose@1058 116 guarantee(__ pc() <= s->code_end(), "overflowed buffer");
jrose@1144 117 // shut the door on sizing bugs
jrose@1144 118 int slop = 2*BytesPerInstWord; // 32-bit offset is this much larger than a 13-bit one
jrose@1144 119 assert(vtable_index > 10 || __ pc() + slop <= s->code_end(), "room for sethi;add");
jrose@1058 120
duke@435 121 s->set_exception_points(npe_addr, ame_addr);
duke@435 122 return s;
duke@435 123 }
duke@435 124
duke@435 125
duke@435 126 // NOTE: %%%% if any change is made to this stub make sure that the function
duke@435 127 // pd_code_size_limit is changed to ensure the correct size for VtableStub
jrose@1058 128 VtableStub* VtableStubs::create_itable_stub(int itable_index) {
duke@435 129 const int sparc_code_length = VtableStub::pd_code_size_limit(false);
jrose@1058 130 VtableStub* s = new(sparc_code_length) VtableStub(false, itable_index);
duke@435 131 ResourceMark rm;
duke@435 132 CodeBuffer cb(s->entry_point(), sparc_code_length);
duke@435 133 MacroAssembler* masm = new MacroAssembler(&cb);
duke@435 134
duke@435 135 Register G3_klassOop = G3_scratch;
duke@435 136 Register G5_interface = G5; // Passed in as an argument
duke@435 137 Label search;
duke@435 138
duke@435 139 // Entry arguments:
duke@435 140 // G5_interface: Interface
duke@435 141 // O0: Receiver
duke@435 142 assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");
duke@435 143
duke@435 144 // get receiver klass (also an implicit null-check)
duke@435 145 address npe_addr = __ pc();
coleenp@548 146 __ load_klass(O0, G3_klassOop);
duke@435 147 __ verify_oop(G3_klassOop);
duke@435 148
duke@435 149 // Push a new window to get some temp registers. This chops the head of all
duke@435 150 // my 64-bit %o registers in the LION build, but this is OK because no longs
duke@435 151 // are passed in the %o registers. Instead, longs are passed in G1 and G4
duke@435 152 // and so those registers are not available here.
duke@435 153 __ save(SP,-frame::register_save_words*wordSize,SP);
duke@435 154
duke@435 155 #ifndef PRODUCT
duke@435 156 if (CountCompiledCalls) {
duke@435 157 Address ctr(L0, SharedRuntime::nof_megamorphic_calls_addr());
duke@435 158 __ sethi(ctr);
duke@435 159 __ ld(ctr, L1);
duke@435 160 __ inc(L1);
duke@435 161 __ st(L1, ctr);
duke@435 162 }
duke@435 163 #endif /* PRODUCT */
duke@435 164
jrose@1058 165 Label throw_icce;
duke@435 166
jrose@1058 167 Register L5_method = L5;
jrose@1058 168 __ lookup_interface_method(// inputs: rec. class, interface, itable index
jrose@1058 169 G3_klassOop, G5_interface, itable_index,
jrose@1058 170 // outputs: method, scan temp. reg
jrose@1058 171 L5_method, L2, L3,
jrose@1058 172 throw_icce);
duke@435 173
duke@435 174 #ifndef PRODUCT
duke@435 175 if (DebugVtables) {
duke@435 176 Label L01;
jrose@1058 177 __ bpr(Assembler::rc_nz, false, Assembler::pt, L5_method, L01);
duke@435 178 __ delayed()->nop();
duke@435 179 __ stop("methodOop is null");
duke@435 180 __ bind(L01);
jrose@1058 181 __ verify_oop(L5_method);
duke@435 182 }
duke@435 183 #endif
duke@435 184
duke@435 185 // If the following load is through a NULL pointer, we'll take an OS
duke@435 186 // exception that should translate into an AbstractMethodError. We need the
duke@435 187 // window count to be correct at that time.
jrose@1058 188 __ restore(L5_method, 0, G5_method);
jrose@1058 189 // Restore registers *before* the AME point.
duke@435 190
duke@435 191 address ame_addr = __ pc(); // if the vtable entry is null, the method is abstract
duke@435 192 __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);
duke@435 193
duke@435 194 // G5_method: methodOop
duke@435 195 // O0: Receiver
duke@435 196 // G3_scratch: entry point
duke@435 197 __ JMP(G3_scratch, 0);
duke@435 198 __ delayed()->nop();
duke@435 199
dcubed@451 200 __ bind(throw_icce);
dcubed@451 201 Address icce(G3_scratch, StubRoutines::throw_IncompatibleClassChangeError_entry());
dcubed@451 202 __ jump_to(icce, 0);
dcubed@451 203 __ delayed()->restore();
dcubed@451 204
duke@435 205 masm->flush();
dcubed@451 206
jrose@1058 207 if (PrintMiscellaneous && (WizardMode || Verbose)) {
jrose@1058 208 tty->print_cr("itable #%d at "PTR_FORMAT"[%d] left over: %d",
jrose@1058 209 itable_index, s->entry_point(),
jrose@1058 210 (int)(s->code_end() - s->entry_point()),
jrose@1058 211 (int)(s->code_end() - __ pc()));
jrose@1058 212 }
dcubed@451 213 guarantee(__ pc() <= s->code_end(), "overflowed buffer");
jrose@1144 214 // shut the door on sizing bugs
jrose@1144 215 int slop = 2*BytesPerInstWord; // 32-bit offset is this much larger than a 13-bit one
jrose@1144 216 assert(itable_index > 10 || __ pc() + slop <= s->code_end(), "room for sethi;add");
dcubed@451 217
duke@435 218 s->set_exception_points(npe_addr, ame_addr);
duke@435 219 return s;
duke@435 220 }
duke@435 221
duke@435 222
duke@435 223 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
dcubed@451 224 if (TraceJumps || DebugVtables || CountCompiledCalls || VerifyOops) return 1000;
duke@435 225 else {
duke@435 226 const int slop = 2*BytesPerInstWord; // sethi;add (needed for long offsets)
duke@435 227 if (is_vtable_stub) {
coleenp@548 228 // ld;ld;ld,jmp,nop
coleenp@548 229 const int basic = 5*BytesPerInstWord +
kvn@1077 230 // shift;add for load_klass (only shift with zero heap based)
kvn@1077 231 (UseCompressedOops ?
kvn@1077 232 ((Universe::narrow_oop_base() == NULL) ? BytesPerInstWord : 2*BytesPerInstWord) : 0);
duke@435 233 return basic + slop;
duke@435 234 } else {
jrose@1058 235 const int basic = (28 LP64_ONLY(+ 6)) * BytesPerInstWord +
kvn@1077 236 // shift;add for load_klass (only shift with zero heap based)
kvn@1077 237 (UseCompressedOops ?
kvn@1077 238 ((Universe::narrow_oop_base() == NULL) ? BytesPerInstWord : 2*BytesPerInstWord) : 0);
duke@435 239 return (basic + slop);
duke@435 240 }
duke@435 241 }
jrose@1144 242
jrose@1144 243 // In order to tune these parameters, run the JVM with VM options
jrose@1144 244 // +PrintMiscellaneous and +WizardMode to see information about
jrose@1144 245 // actual itable stubs. Look for lines like this:
jrose@1144 246 // itable #1 at 0x5551212[116] left over: 8
jrose@1144 247 // Reduce the constants so that the "left over" number is 8
jrose@1144 248 // Do not aim at a left-over number of zero, because a very
jrose@1144 249 // large vtable or itable offset (> 4K) will require an extra
jrose@1144 250 // sethi/or pair of instructions.
jrose@1144 251 //
jrose@1144 252 // The JVM98 app. _202_jess has a megamorphic interface call.
jrose@1144 253 // The itable code looks like this:
jrose@1144 254 // Decoding VtableStub itbl[1]@16
jrose@1144 255 // ld [ %o0 + 4 ], %g3
jrose@1144 256 // save %sp, -64, %sp
jrose@1144 257 // ld [ %g3 + 0xe8 ], %l2
jrose@1144 258 // sll %l2, 2, %l2
jrose@1144 259 // add %l2, 0x134, %l2
jrose@1144 260 // and %l2, -8, %l2 ! NOT_LP64 only
jrose@1144 261 // add %g3, %l2, %l2
jrose@1144 262 // add %g3, 4, %g3
jrose@1144 263 // ld [ %l2 ], %l5
jrose@1144 264 // brz,pn %l5, throw_icce
jrose@1144 265 // cmp %l5, %g5
jrose@1144 266 // be %icc, success
jrose@1144 267 // add %l2, 8, %l2
jrose@1144 268 // loop:
jrose@1144 269 // ld [ %l2 ], %l5
jrose@1144 270 // brz,pn %l5, throw_icce
jrose@1144 271 // cmp %l5, %g5
jrose@1144 272 // bne,pn %icc, loop
jrose@1144 273 // add %l2, 8, %l2
jrose@1144 274 // success:
jrose@1144 275 // ld [ %l2 + -4 ], %l2
jrose@1144 276 // ld [ %g3 + %l2 ], %l5
jrose@1144 277 // restore %l5, 0, %g5
jrose@1144 278 // ld [ %g5 + 0x44 ], %g3
jrose@1144 279 // jmp %g3
jrose@1144 280 // nop
jrose@1144 281 // throw_icce:
jrose@1144 282 // sethi %hi(throw_ICCE_entry), %g3
jrose@1144 283 // ! 5 more instructions here, LP64_ONLY
jrose@1144 284 // jmp %g3 + %lo(throw_ICCE_entry)
jrose@1144 285 // restore
duke@435 286 }
duke@435 287
duke@435 288
duke@435 289 int VtableStub::pd_code_alignment() {
duke@435 290 // UltraSPARC cache line size is 8 instructions:
duke@435 291 const unsigned int icache_line_size = 32;
duke@435 292 return icache_line_size;
duke@435 293 }

mercurial