src/cpu/sparc/vm/vtableStubs_sparc.cpp

Mon, 28 May 2018 10:33:52 +0800

author
aoqi
date
Mon, 28 May 2018 10:33:52 +0800
changeset 9041
95a08233f46c
parent 8997
f8a45a60bc6b
parent 6876
710a3c8b516e
child 9448
73d689add964
permissions
-rw-r--r--

Merge

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

mercurial