annotate src/cpu/x86/vm/vtableStubs_x86_32.cpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children f8236e79048a
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2006 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) {
duke@0 52 __ increment(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();
duke@0 61 __ movl(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
duke@0 79 __ movl(method, Address(rax, entry_offset*wordSize + vtableEntry::method_offset_in_bytes()));
duke@0 80 if (DebugVtables) {
duke@0 81 Label L;
duke@0 82 __ cmpl(method, NULL_WORD);
duke@0 83 __ jcc(Assembler::equal, L);
duke@0 84 __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), 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) {
duke@0 117 __ increment(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();
duke@0 126 __ movl(rbx, Address(rcx, oopDesc::klass_offset_in_bytes()));
duke@0 127
duke@0 128 __ movl(rsi, rbx); // Save klass in free register
duke@0 129 // Most registers are in use, so save a few
duke@0 130 __ pushl(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
duke@0 135 __ leal(rbx, Address(rbx, rdx, Address::times_4, 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
duke@0 141 Label hit, next, entry;
duke@0 142
duke@0 143 __ jmp(entry);
duke@0 144
duke@0 145 __ bind(next);
duke@0 146 __ addl(rbx, itableOffsetEntry::size() * wordSize);
duke@0 147
duke@0 148 __ bind(entry);
duke@0 149
duke@0 150 #ifdef ASSERT
duke@0 151 // Check that the entry is non-null
duke@0 152 if (DebugVtables) {
duke@0 153 Label L;
duke@0 154 __ pushl(rbx);
duke@0 155 __ movl(rbx, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
duke@0 156 __ testl(rbx, rbx);
duke@0 157 __ jcc(Assembler::notZero, L);
duke@0 158 __ stop("null entry point found in itable's offset table");
duke@0 159 __ bind(L);
duke@0 160 __ popl(rbx);
duke@0 161 }
duke@0 162 #endif
duke@0 163 __ cmpl(rax, Address(rbx, itableOffsetEntry::interface_offset_in_bytes()));
duke@0 164 __ jcc(Assembler::notEqual, next);
duke@0 165
duke@0 166 // We found a hit, move offset into rbx,
duke@0 167 __ movl(rdx, Address(rbx, itableOffsetEntry::offset_offset_in_bytes()));
duke@0 168
duke@0 169 // Compute itableMethodEntry.
duke@0 170 const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) + itableMethodEntry::method_offset_in_bytes();
duke@0 171
duke@0 172 // Get methodOop and entrypoint for compiler
duke@0 173 const Register method = rbx;
duke@0 174 __ movl(method, Address(rsi, rdx, Address::times_1, method_offset));
duke@0 175
duke@0 176 // Restore saved register, before possible trap.
duke@0 177 __ popl(rdx);
duke@0 178
duke@0 179 // method (rbx): methodOop
duke@0 180 // rcx: receiver
duke@0 181
duke@0 182 #ifdef ASSERT
duke@0 183 if (DebugVtables) {
duke@0 184 Label L1;
duke@0 185 __ cmpl(method, NULL_WORD);
duke@0 186 __ jcc(Assembler::equal, L1);
duke@0 187 __ cmpl(Address(method, methodOopDesc::from_compiled_offset()), NULL_WORD);
duke@0 188 __ jcc(Assembler::notZero, L1);
duke@0 189 __ stop("methodOop is null");
duke@0 190 __ bind(L1);
duke@0 191 }
duke@0 192 #endif // ASSERT
duke@0 193
duke@0 194 address ame_addr = __ pc();
duke@0 195 __ jmp(Address(method, methodOopDesc::from_compiled_offset()));
duke@0 196
duke@0 197 masm->flush();
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
duke@0 210 return (DebugVtables ? 140 : 55) + (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 }