src/cpu/x86/vm/vtableStubs_x86_64.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial