src/cpu/x86/vm/vtableStubs_x86_32.cpp

Wed, 07 May 2008 08:06:46 -0700

author
rasbold
date
Wed, 07 May 2008 08:06:46 -0700
changeset 580
f3de1255b035
parent 451
f8236e79048a
child 739
dc7f315e41f7
permissions
-rw-r--r--

6603011: RFE: Optimize long division
Summary: Transform long division by constant into multiply
Reviewed-by: never, kvn

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

mercurial