Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f
aoqi@0 | 1 | /* |
dbuck@8997 | 2 | * Copyright (c) 2003, 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.hpp" |
aoqi@0 | 27 | #include "code/vtableStubs.hpp" |
aoqi@0 | 28 | #include "interp_masm_x86.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_x86.inline.hpp" |
aoqi@0 | 35 | #ifdef COMPILER2 |
aoqi@0 | 36 | #include "opto/runtime.hpp" |
aoqi@0 | 37 | #endif |
aoqi@0 | 38 | |
aoqi@0 | 39 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 40 | |
aoqi@0 | 41 | // machine-dependent part of VtableStubs: create VtableStub of correct size and |
aoqi@0 | 42 | // initialize its code |
aoqi@0 | 43 | |
aoqi@0 | 44 | #define __ masm-> |
aoqi@0 | 45 | |
aoqi@0 | 46 | #ifndef PRODUCT |
aoqi@0 | 47 | extern "C" void bad_compiled_vtable_index(JavaThread* thread, |
aoqi@0 | 48 | oop receiver, |
aoqi@0 | 49 | int index); |
aoqi@0 | 50 | #endif |
aoqi@0 | 51 | |
aoqi@0 | 52 | VtableStub* VtableStubs::create_vtable_stub(int vtable_index) { |
aoqi@0 | 53 | const int amd64_code_length = VtableStub::pd_code_size_limit(true); |
aoqi@0 | 54 | VtableStub* s = new(amd64_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(), amd64_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 | __ incrementl(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr())); |
aoqi@0 | 67 | } |
aoqi@0 | 68 | #endif |
aoqi@0 | 69 | |
aoqi@0 | 70 | // get receiver (need to skip return address on top of stack) |
aoqi@0 | 71 | assert(VtableStub::receiver_location() == j_rarg0->as_VMReg(), "receiver expected in j_rarg0"); |
aoqi@0 | 72 | |
aoqi@0 | 73 | // Free registers (non-args) are rax, rbx |
aoqi@0 | 74 | |
aoqi@0 | 75 | // get receiver klass |
aoqi@0 | 76 | address npe_addr = __ pc(); |
aoqi@0 | 77 | __ load_klass(rax, j_rarg0); |
aoqi@0 | 78 | |
aoqi@0 | 79 | #ifndef PRODUCT |
aoqi@0 | 80 | if (DebugVtables) { |
aoqi@0 | 81 | Label L; |
aoqi@0 | 82 | // check offset vs vtable length |
aoqi@0 | 83 | __ cmpl(Address(rax, InstanceKlass::vtable_length_offset() * wordSize), |
aoqi@0 | 84 | vtable_index * vtableEntry::size()); |
aoqi@0 | 85 | __ jcc(Assembler::greater, L); |
aoqi@0 | 86 | __ movl(rbx, vtable_index); |
aoqi@0 | 87 | __ call_VM(noreg, |
aoqi@0 | 88 | CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), j_rarg0, rbx); |
aoqi@0 | 89 | __ bind(L); |
aoqi@0 | 90 | } |
aoqi@0 | 91 | #endif // PRODUCT |
aoqi@0 | 92 | |
aoqi@0 | 93 | // load Method* and target address |
aoqi@0 | 94 | const Register method = rbx; |
aoqi@0 | 95 | |
aoqi@0 | 96 | __ lookup_virtual_method(rax, vtable_index, method); |
aoqi@0 | 97 | |
aoqi@0 | 98 | if (DebugVtables) { |
aoqi@0 | 99 | Label L; |
aoqi@0 | 100 | __ cmpptr(method, (int32_t)NULL_WORD); |
aoqi@0 | 101 | __ jcc(Assembler::equal, L); |
aoqi@0 | 102 | __ cmpptr(Address(method, Method::from_compiled_offset()), (int32_t)NULL_WORD); |
aoqi@0 | 103 | __ jcc(Assembler::notZero, L); |
aoqi@0 | 104 | __ stop("Vtable entry is NULL"); |
aoqi@0 | 105 | __ bind(L); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | // rax: receiver klass |
aoqi@0 | 108 | // rbx: Method* |
aoqi@0 | 109 | // rcx: receiver |
aoqi@0 | 110 | address ame_addr = __ pc(); |
aoqi@0 | 111 | __ jmp( Address(rbx, Method::from_compiled_offset())); |
aoqi@0 | 112 | |
aoqi@0 | 113 | __ flush(); |
aoqi@0 | 114 | |
aoqi@0 | 115 | if (PrintMiscellaneous && (WizardMode || Verbose)) { |
kevinw@9327 | 116 | tty->print_cr("vtable #%d at " PTR_FORMAT "[%d] left over: %d", |
aoqi@0 | 117 | vtable_index, s->entry_point(), |
aoqi@0 | 118 | (int)(s->code_end() - s->entry_point()), |
aoqi@0 | 119 | (int)(s->code_end() - __ pc())); |
aoqi@0 | 120 | } |
aoqi@0 | 121 | guarantee(__ pc() <= s->code_end(), "overflowed buffer"); |
aoqi@0 | 122 | // shut the door on sizing bugs |
aoqi@0 | 123 | int slop = 3; // 32-bit offset is this much larger than an 8-bit one |
aoqi@0 | 124 | assert(vtable_index > 10 || __ pc() + slop <= s->code_end(), "room for 32-bit offset"); |
aoqi@0 | 125 | |
aoqi@0 | 126 | s->set_exception_points(npe_addr, ame_addr); |
aoqi@0 | 127 | return s; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | |
aoqi@0 | 131 | VtableStub* VtableStubs::create_itable_stub(int itable_index) { |
aoqi@0 | 132 | // Note well: pd_code_size_limit is the absolute minimum we can get |
aoqi@0 | 133 | // away with. If you add code here, bump the code stub size |
aoqi@0 | 134 | // returned by pd_code_size_limit! |
aoqi@0 | 135 | const int amd64_code_length = VtableStub::pd_code_size_limit(false); |
aoqi@0 | 136 | VtableStub* s = new(amd64_code_length) VtableStub(false, itable_index); |
aoqi@0 | 137 | // Can be NULL if there is no free space in the code cache. |
aoqi@0 | 138 | if (s == NULL) { |
aoqi@0 | 139 | return NULL; |
aoqi@0 | 140 | } |
aoqi@0 | 141 | |
aoqi@0 | 142 | ResourceMark rm; |
aoqi@0 | 143 | CodeBuffer cb(s->entry_point(), amd64_code_length); |
aoqi@0 | 144 | MacroAssembler* masm = new MacroAssembler(&cb); |
aoqi@0 | 145 | |
aoqi@0 | 146 | #ifndef PRODUCT |
aoqi@0 | 147 | if (CountCompiledCalls) { |
aoqi@0 | 148 | __ incrementl(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr())); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | #endif |
aoqi@0 | 151 | |
aoqi@0 | 152 | // Entry arguments: |
dbuck@8997 | 153 | // rax: CompiledICHolder |
aoqi@0 | 154 | // j_rarg0: Receiver |
aoqi@0 | 155 | |
aoqi@0 | 156 | // Most registers are in use; we'll use rax, rbx, r10, r11 |
aoqi@0 | 157 | // (various calling sequences use r[cd]x, r[sd]i, r[89]; stay away from them) |
dbuck@8997 | 158 | const Register recv_klass_reg = r10; |
dbuck@8997 | 159 | const Register holder_klass_reg = rax; // declaring interface klass (DECC) |
dbuck@8997 | 160 | const Register resolved_klass_reg = rbx; // resolved interface klass (REFC) |
dbuck@8997 | 161 | const Register temp_reg = r11; |
dbuck@8997 | 162 | |
dbuck@8997 | 163 | Label L_no_such_interface; |
dbuck@8997 | 164 | |
dbuck@8997 | 165 | const Register icholder_reg = rax; |
dbuck@8997 | 166 | __ movptr(resolved_klass_reg, Address(icholder_reg, CompiledICHolder::holder_klass_offset())); |
dbuck@8997 | 167 | __ movptr(holder_klass_reg, Address(icholder_reg, CompiledICHolder::holder_metadata_offset())); |
dbuck@8997 | 168 | |
dbuck@8997 | 169 | // get receiver klass (also an implicit null-check) |
dbuck@8997 | 170 | assert(VtableStub::receiver_location() == j_rarg0->as_VMReg(), "receiver expected in j_rarg0"); |
dbuck@8997 | 171 | address npe_addr = __ pc(); |
dbuck@8997 | 172 | __ load_klass(recv_klass_reg, j_rarg0); |
dbuck@8997 | 173 | |
dbuck@8997 | 174 | // Receiver subtype check against REFC. |
dbuck@8997 | 175 | // Destroys recv_klass_reg value. |
dbuck@8997 | 176 | __ lookup_interface_method(// inputs: rec. class, interface |
dbuck@8997 | 177 | recv_klass_reg, resolved_klass_reg, noreg, |
dbuck@8997 | 178 | // outputs: scan temp. reg1, scan temp. reg2 |
dbuck@8997 | 179 | recv_klass_reg, temp_reg, |
dbuck@8997 | 180 | L_no_such_interface, |
dbuck@8997 | 181 | /*return_method=*/false); |
dbuck@8997 | 182 | |
dbuck@8997 | 183 | // Get selected method from declaring class and itable index |
dbuck@8997 | 184 | const Register method = rbx; |
dbuck@8997 | 185 | __ load_klass(recv_klass_reg, j_rarg0); // restore recv_klass_reg |
dbuck@8997 | 186 | __ lookup_interface_method(// inputs: rec. class, interface, itable index |
dbuck@8997 | 187 | recv_klass_reg, holder_klass_reg, itable_index, |
dbuck@8997 | 188 | // outputs: method, scan temp. reg |
dbuck@8997 | 189 | method, temp_reg, |
dbuck@8997 | 190 | L_no_such_interface); |
aoqi@0 | 191 | |
aoqi@0 | 192 | // If we take a trap while this arg is on the stack we will not |
aoqi@0 | 193 | // be able to walk the stack properly. This is not an issue except |
aoqi@0 | 194 | // when there are mistakes in this assembly code that could generate |
aoqi@0 | 195 | // a spurious fault. Ask me how I know... |
aoqi@0 | 196 | |
aoqi@0 | 197 | // method (rbx): Method* |
aoqi@0 | 198 | // j_rarg0: receiver |
aoqi@0 | 199 | |
aoqi@0 | 200 | #ifdef ASSERT |
aoqi@0 | 201 | if (DebugVtables) { |
aoqi@0 | 202 | Label L2; |
aoqi@0 | 203 | __ cmpptr(method, (int32_t)NULL_WORD); |
aoqi@0 | 204 | __ jcc(Assembler::equal, L2); |
aoqi@0 | 205 | __ cmpptr(Address(method, Method::from_compiled_offset()), (int32_t)NULL_WORD); |
aoqi@0 | 206 | __ jcc(Assembler::notZero, L2); |
aoqi@0 | 207 | __ stop("compiler entrypoint is null"); |
aoqi@0 | 208 | __ bind(L2); |
aoqi@0 | 209 | } |
aoqi@0 | 210 | #endif // ASSERT |
aoqi@0 | 211 | |
aoqi@0 | 212 | // rbx: Method* |
aoqi@0 | 213 | // j_rarg0: receiver |
aoqi@0 | 214 | address ame_addr = __ pc(); |
aoqi@0 | 215 | __ jmp(Address(method, Method::from_compiled_offset())); |
aoqi@0 | 216 | |
dbuck@8997 | 217 | __ bind(L_no_such_interface); |
aoqi@0 | 218 | __ jump(RuntimeAddress(StubRoutines::throw_IncompatibleClassChangeError_entry())); |
aoqi@0 | 219 | |
aoqi@0 | 220 | __ flush(); |
aoqi@0 | 221 | |
aoqi@0 | 222 | if (PrintMiscellaneous && (WizardMode || Verbose)) { |
kevinw@9327 | 223 | tty->print_cr("itable #%d at " PTR_FORMAT "[%d] left over: %d", |
aoqi@0 | 224 | itable_index, s->entry_point(), |
aoqi@0 | 225 | (int)(s->code_end() - s->entry_point()), |
aoqi@0 | 226 | (int)(s->code_end() - __ pc())); |
aoqi@0 | 227 | } |
aoqi@0 | 228 | guarantee(__ pc() <= s->code_end(), "overflowed buffer"); |
aoqi@0 | 229 | // shut the door on sizing bugs |
aoqi@0 | 230 | int slop = 3; // 32-bit offset is this much larger than an 8-bit one |
aoqi@0 | 231 | assert(itable_index > 10 || __ pc() + slop <= s->code_end(), "room for 32-bit offset"); |
aoqi@0 | 232 | |
aoqi@0 | 233 | s->set_exception_points(npe_addr, ame_addr); |
aoqi@0 | 234 | return s; |
aoqi@0 | 235 | } |
aoqi@0 | 236 | |
aoqi@0 | 237 | int VtableStub::pd_code_size_limit(bool is_vtable_stub) { |
aoqi@0 | 238 | if (is_vtable_stub) { |
aoqi@0 | 239 | // Vtable stub size |
aoqi@0 | 240 | return (DebugVtables ? 512 : 24) + (CountCompiledCalls ? 13 : 0) + |
aoqi@0 | 241 | (UseCompressedClassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); |
aoqi@0 | 242 | } else { |
aoqi@0 | 243 | // Itable stub size |
dbuck@8997 | 244 | return (DebugVtables ? 512 : 140) + (CountCompiledCalls ? 13 : 0) + |
dbuck@8997 | 245 | (UseCompressedClassPointers ? 2 * MacroAssembler::instr_size_for_decode_klass_not_null() : 0); |
aoqi@0 | 246 | } |
aoqi@0 | 247 | // In order to tune these parameters, run the JVM with VM options |
aoqi@0 | 248 | // +PrintMiscellaneous and +WizardMode to see information about |
aoqi@0 | 249 | // actual itable stubs. Look for lines like this: |
aoqi@0 | 250 | // itable #1 at 0x5551212[71] left over: 3 |
aoqi@0 | 251 | // Reduce the constants so that the "left over" number is >=3 |
aoqi@0 | 252 | // for the common cases. |
aoqi@0 | 253 | // Do not aim at a left-over number of zero, because a |
aoqi@0 | 254 | // large vtable or itable index (>= 32) will require a 32-bit |
aoqi@0 | 255 | // immediate displacement instead of an 8-bit one. |
aoqi@0 | 256 | // |
aoqi@0 | 257 | // The JVM98 app. _202_jess has a megamorphic interface call. |
aoqi@0 | 258 | // The itable code looks like this: |
aoqi@0 | 259 | // Decoding VtableStub itbl[1]@12 |
aoqi@0 | 260 | // mov 0x8(%rsi),%r10 |
aoqi@0 | 261 | // mov 0x198(%r10),%r11d |
aoqi@0 | 262 | // lea 0x218(%r10,%r11,8),%r11 |
aoqi@0 | 263 | // lea 0x8(%r10),%r10 |
aoqi@0 | 264 | // mov (%r11),%rbx |
aoqi@0 | 265 | // cmp %rbx,%rax |
aoqi@0 | 266 | // je success |
aoqi@0 | 267 | // loop: |
aoqi@0 | 268 | // test %rbx,%rbx |
aoqi@0 | 269 | // je throw_icce |
aoqi@0 | 270 | // add $0x10,%r11 |
aoqi@0 | 271 | // mov (%r11),%rbx |
aoqi@0 | 272 | // cmp %rbx,%rax |
aoqi@0 | 273 | // jne loop |
aoqi@0 | 274 | // success: |
aoqi@0 | 275 | // mov 0x8(%r11),%r11d |
aoqi@0 | 276 | // mov (%r10,%r11,1),%rbx |
aoqi@0 | 277 | // jmpq *0x60(%rbx) |
aoqi@0 | 278 | // throw_icce: |
aoqi@0 | 279 | // jmpq throw_ICCE_entry |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | int VtableStub::pd_code_alignment() { |
aoqi@0 | 283 | return wordSize; |
aoqi@0 | 284 | } |