annotate src/cpu/x86/vm/vtableStubs_x86_32.cpp @ 340:9ee9cf798b59

6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
author xdono
date Thu, 02 Oct 2008 19:58:19 -0700
parents dc7f315e41f7
children 9adddb8c0fc8
rev   line source
duke@0 1 /*
xdono@340 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 #include "incls/_precompiled.incl"
duke@0 26 #include "incls/_vtableStubs_x86_32.cpp.incl"
duke@0 27
duke@0 28 // machine-dependent part of VtableStubs: create VtableStub of correct size and
duke@0 29 // initialize its code
duke@0 30
duke@0 31 #define __ masm->
duke@0 32
duke@0 33 #ifndef PRODUCT
duke@0 34 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
duke@0 35 #endif
duke@0 36
duke@0 37 // used by compiler only; may use only caller saved registers rax, rbx, rcx.
duke@0 38 // rdx holds first int arg, rsi, rdi, rbp are callee-save & must be preserved.
duke@0 39 // Leave receiver in rcx; required behavior when +OptoArgsInRegisters
duke@0 40 // is modifed to put first oop in rcx.
duke@0 41 //
duke@0 42 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
duke@0 43 const int i486_code_length = VtableStub::pd_code_size_limit(true);
duke@0 44 VtableStub* s = new(i486_code_length) VtableStub(true, vtable_index);
duke@0 45 ResourceMark rm;
duke@0 46 CodeBuffer cb(s->entry_point(), i486_code_length);
duke@0 47 MacroAssembler* masm = new MacroAssembler(&cb);
duke@0 48
duke@0 49 #ifndef PRODUCT
duke@0 50
duke@0 51 if (CountCompiledCalls) {
never@307 52 __ incrementl(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));
duke@0 53 }
duke@0 54 #endif /* PRODUCT */
duke@0 55
duke@0 56 // get receiver (need to skip return address on top of stack)
duke@0 57 assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx");
duke@0 58
duke@0 59 // get receiver klass
duke@0 60 address npe_addr = __ pc();
never@307 61 __ movptr(rax, Address(rcx, oopDesc::klass_offset_in_bytes()));
duke@0 62 // compute entry offset (in words)
duke@0 63 int entry_offset = instanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
duke@0 64 #ifndef PRODUCT
duke@0 65 if (DebugVtables) {
duke@0 66 Label L;
duke@0 67 // check offset vs vtable length
duke@0 68 __ cmpl(Address(rax, instanceKlass::vtable_length_offset()*wordSize), vtable_index*vtableEntry::size());
duke@0 69 __ jcc(Assembler::greater, L);
duke@0 70 __ movl(rbx, vtable_index);
duke@0 71 __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), rcx, rbx);
duke@0 72 __ bind(L);
duke@0 73 }
duke@0 74 #endif // PRODUCT
duke@0 75
duke@0 76 const Register method = rbx;
duke@0 77
duke@0 78 // load methodOop and target address
never@307 79 __ movptr(method, Address(rax, entry_offset*wordSize + vtableEntry::method_offset_in_bytes()));
duke@0 80 if (DebugVtables) {
duke@0 81 Label L;
never@307 82 __ cmpptr(method, (int32_t)NULL_WORD);
duke@0 83 __ jcc(Assembler::equal, L);
never@307 84 __ cmpptr(Address(method, methodOopDesc::from_compiled_offset()), (int32_t)NULL_WORD);
duke@0 85 __ jcc(Assembler::notZero, L);
duke@0 86 __ stop("Vtable entry is NULL");
duke@0 87 __ bind(L);
duke@0 88 }
duke@0 89
duke@0 90 // rax,: receiver klass
duke@0 91 // method (rbx): methodOop
duke@0 92 // rcx: receiver
duke@0 93 address ame_addr = __ pc();
duke@0 94 __ jmp( Address(method, methodOopDesc::from_compiled_offset()));
duke@0 95
duke@0 96 masm->flush();
duke@0 97 s->set_exception_points(npe_addr, ame_addr);
duke@0 98 return s;
duke@0 99 }
duke@0 100
duke@0 101
duke@0 102 VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
duke@0 103 // Note well: pd_code_size_limit is the absolute minimum we can get away with. If you
duke@0 104 // add code here, bump the code stub size returned by pd_code_size_limit!
duke@0 105 const int i486_code_length = VtableStub::pd_code_size_limit(false);
duke@0 106 VtableStub* s = new(i486_code_length) VtableStub(false, vtable_index);
duke@0 107 ResourceMark rm;
duke@0 108 CodeBuffer cb(s->entry_point(), i486_code_length);
duke@0 109 MacroAssembler* masm = new MacroAssembler(&cb);
duke@0 110
duke@0 111 // Entry arguments:
duke@0 112 // rax,: Interface
duke@0 113 // rcx: Receiver
duke@0 114
duke@0 115 #ifndef PRODUCT
duke@0 116 if (CountCompiledCalls) {
never@307 117 __ incrementl(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));
duke@0 118 }
duke@0 119 #endif /* PRODUCT */
duke@0 120 // get receiver (need to skip return address on top of stack)
duke@0 121
duke@0 122 assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx");
duke@0 123
duke@0 124 // get receiver klass (also an implicit null-check)
duke@0 125 address npe_addr = __ pc();
never@307 126 __ movptr(rbx, Address(rcx, oopDesc::klass_offset_in_bytes()));
duke@0 127
never@307 128 __ mov(rsi, rbx); // Save klass in free register
duke@0 129 // Most registers are in use, so save a few
never@307 130 __ push(rdx);
duke@0 131 // compute itable entry offset (in words)
duke@0 132 const int base = instanceKlass::vtable_start_offset() * wordSize;
duke@0 133 assert(vtableEntry::size() * wordSize == 4, "adjust the scaling in the code below");
duke@0 134 __ movl(rdx, Address(rbx, instanceKlass::vtable_length_offset() * wordSize)); // Get length of vtable
never@307 135 __ lea(rbx, Address(rbx, rdx, Address::times_ptr, base));
duke@0 136 if (HeapWordsPerLong > 1) {
duke@0 137 // Round up to align_object_offset boundary
duke@0 138 __ round_to(rbx, BytesPerLong);
duke@0 139 }
duke@0 140
dcubed@16 141 Label hit, next, entry, throw_icce;
duke@0 142
dcubed@16 143 __ jmpb(entry);
duke@0 144
duke@0 145 __ bind(next);
never@307 146 __ addptr(rbx, itableOffsetEntry::size() * wordSize);
duke@0 147
duke@0 148 __ bind(entry);
duke@0 149
dcubed@16 150 // If the entry is NULL then we've reached the end of the table
dcubed@16 151 // without finding the expected interface, so throw an exception
never@307 152 __ movptr(rdx, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
never@307 153 __ testptr(rdx, rdx);
dcubed@16 154 __ jcc(Assembler::zero, throw_icce);
never@307 155 __ cmpptr(rax, rdx);
duke@0 156 __ jcc(Assembler::notEqual, next);
duke@0 157
duke@0 158 // We found a hit, move offset into rbx,
duke@0 159 __ movl(rdx, Address(rbx, itableOffsetEntry::offset_offset_in_bytes()));
duke@0 160
duke@0 161 // Compute itableMethodEntry.
duke@0 162 const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) + itableMethodEntry::method_offset_in_bytes();
duke@0 163
duke@0 164 // Get methodOop and entrypoint for compiler
duke@0 165 const Register method = rbx;
never@307 166 __ movptr(method, Address(rsi, rdx, Address::times_1, method_offset));
duke@0 167
duke@0 168 // Restore saved register, before possible trap.
never@307 169 __ pop(rdx);
duke@0 170
duke@0 171 // method (rbx): methodOop
duke@0 172 // rcx: receiver
duke@0 173
duke@0 174 #ifdef ASSERT
duke@0 175 if (DebugVtables) {
duke@0 176 Label L1;
never@307 177 __ cmpptr(method, (int32_t)NULL_WORD);
duke@0 178 __ jcc(Assembler::equal, L1);
never@307 179 __ cmpptr(Address(method, methodOopDesc::from_compiled_offset()), (int32_t)NULL_WORD);
duke@0 180 __ jcc(Assembler::notZero, L1);
duke@0 181 __ stop("methodOop is null");
duke@0 182 __ bind(L1);
duke@0 183 }
duke@0 184 #endif // ASSERT
duke@0 185
duke@0 186 address ame_addr = __ pc();
duke@0 187 __ jmp(Address(method, methodOopDesc::from_compiled_offset()));
duke@0 188
dcubed@16 189 __ bind(throw_icce);
dcubed@16 190 // Restore saved register
never@307 191 __ pop(rdx);
dcubed@16 192 __ jump(RuntimeAddress(StubRoutines::throw_IncompatibleClassChangeError_entry()));
dcubed@16 193
duke@0 194 masm->flush();
dcubed@16 195
dcubed@16 196 guarantee(__ pc() <= s->code_end(), "overflowed buffer");
dcubed@16 197
duke@0 198 s->set_exception_points(npe_addr, ame_addr);
duke@0 199 return s;
duke@0 200 }
duke@0 201
duke@0 202
duke@0 203
duke@0 204 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
duke@0 205 if (is_vtable_stub) {
duke@0 206 // Vtable stub size
duke@0 207 return (DebugVtables ? 210 : 16) + (CountCompiledCalls ? 6 : 0);
duke@0 208 } else {
duke@0 209 // Itable stub size
dcubed@16 210 return (DebugVtables ? 144 : 64) + (CountCompiledCalls ? 6 : 0);
duke@0 211 }
duke@0 212 }
duke@0 213
duke@0 214 int VtableStub::pd_code_alignment() {
duke@0 215 return wordSize;
duke@0 216 }