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