interpreterRT_sparc.cpp revision 727:6b2273dd6fa9
1/* 2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 * 23 */ 24 25#include "incls/_precompiled.incl" 26#include "incls/_interpreterRT_sparc.cpp.incl" 27 28 29#define __ _masm-> 30 31 32// Implementation of SignatureHandlerGenerator 33 34void InterpreterRuntime::SignatureHandlerGenerator::pass_word(int size_of_arg, int offset_in_arg) { 35 Argument jni_arg(jni_offset() + offset_in_arg, false); 36 Register Rtmp = O0; 37 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); 38 39 __ store_argument(Rtmp, jni_arg); 40} 41 42void InterpreterRuntime::SignatureHandlerGenerator::pass_long() { 43 Argument jni_arg(jni_offset(), false); 44 Register Rtmp = O0; 45 46#ifdef ASSERT 47 if (TaggedStackInterpreter) { 48 // check at least one tag is okay 49 Label ok; 50 __ ld_ptr(Llocals, Interpreter::local_tag_offset_in_bytes(offset() + 1), Rtmp); 51 __ cmp(Rtmp, G0); 52 __ brx(Assembler::equal, false, Assembler::pt, ok); 53 __ delayed()->nop(); 54 __ stop("Native object has bad tag value"); 55 __ bind(ok); 56 } 57#endif // ASSERT 58 59#ifdef _LP64 60 __ ldx(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 61 __ store_long_argument(Rtmp, jni_arg); 62#else 63 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 64 __ store_argument(Rtmp, jni_arg); 65 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 0), Rtmp); 66 Argument successor(jni_arg.successor()); 67 __ store_argument(Rtmp, successor); 68#endif 69} 70 71 72#ifdef _LP64 73void InterpreterRuntime::SignatureHandlerGenerator::pass_float() { 74 Argument jni_arg(jni_offset(), false); 75 FloatRegister Rtmp = F0; 76 __ ldf(FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); 77 __ store_float_argument(Rtmp, jni_arg); 78} 79#endif 80 81 82void InterpreterRuntime::SignatureHandlerGenerator::pass_double() { 83 Argument jni_arg(jni_offset(), false); 84#ifdef _LP64 85 FloatRegister Rtmp = F0; 86 __ ldf(FloatRegisterImpl::D, Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 87 __ store_double_argument(Rtmp, jni_arg); 88#else 89 Register Rtmp = O0; 90 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 91 __ store_argument(Rtmp, jni_arg); 92 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); 93 Argument successor(jni_arg.successor()); 94 __ store_argument(Rtmp, successor); 95#endif 96} 97 98void InterpreterRuntime::SignatureHandlerGenerator::pass_object() { 99 Argument jni_arg(jni_offset(), false); 100 Argument java_arg( offset(), true); 101 Register Rtmp1 = O0; 102 Register Rtmp2 = jni_arg.is_register() ? jni_arg.as_register() : O0; 103 Register Rtmp3 = G3_scratch; 104 105 // the handle for a receiver will never be null 106 bool do_NULL_check = offset() != 0 || is_static(); 107 108 Address h_arg = Address(Llocals, Interpreter::local_offset_in_bytes(offset())); 109 __ ld_ptr(h_arg, Rtmp1); 110#ifdef ASSERT 111 if (TaggedStackInterpreter) { 112 // check we have the obj and not the tag 113 Label ok; 114 __ mov(frame::TagReference, Rtmp3); 115 __ cmp(Rtmp1, Rtmp3); 116 __ brx(Assembler::notEqual, true, Assembler::pt, ok); 117 __ delayed()->nop(); 118 __ stop("Native object passed tag by mistake"); 119 __ bind(ok); 120 } 121#endif // ASSERT 122 if (!do_NULL_check) { 123 __ add(h_arg.base(), h_arg.disp(), Rtmp2); 124 } else { 125 if (Rtmp1 == Rtmp2) 126 __ tst(Rtmp1); 127 else __ addcc(G0, Rtmp1, Rtmp2); // optimize mov/test pair 128 Label L; 129 __ brx(Assembler::notZero, true, Assembler::pt, L); 130 __ delayed()->add(h_arg.base(), h_arg.disp(), Rtmp2); 131 __ bind(L); 132 } 133 __ store_ptr_argument(Rtmp2, jni_arg); // this is often a no-op 134} 135 136 137void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) { 138 139 // generate code to handle arguments 140 iterate(fingerprint); 141 142 // return result handler 143 AddressLiteral result_handler(Interpreter::result_handler(method()->result_type())); 144 __ sethi(result_handler, Lscratch); 145 __ retl(); 146 __ delayed()->add(Lscratch, result_handler.low10(), Lscratch); 147 148 __ flush(); 149} 150 151 152// Implementation of SignatureHandlerLibrary 153 154void SignatureHandlerLibrary::pd_set_handler(address handler) {} 155 156 157class SlowSignatureHandler: public NativeSignatureIterator { 158 private: 159 address _from; 160 intptr_t* _to; 161 intptr_t* _RegArgSignature; // Signature of first Arguments to be passed in Registers 162 uint _argcount; 163 164 enum { // We need to differenciate float from non floats in reg args 165 non_float = 0, 166 float_sig = 1, 167 double_sig = 2, 168 long_sig = 3 169 }; 170 171#ifdef ASSERT 172 void verify_tag(frame::Tag t) { 173 assert(!TaggedStackInterpreter || 174 *(intptr_t*)(_from+Interpreter::local_tag_offset_in_bytes(0)) == t, "wrong tag"); 175 } 176#endif // ASSERT 177 178 virtual void pass_int() { 179 *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); 180 debug_only(verify_tag(frame::TagValue)); 181 _from -= Interpreter::stackElementSize(); 182 add_signature( non_float ); 183 } 184 185 virtual void pass_object() { 186 // pass address of from 187 intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0)); 188 *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr; 189 debug_only(verify_tag(frame::TagReference)); 190 _from -= Interpreter::stackElementSize(); 191 add_signature( non_float ); 192 } 193 194#ifdef _LP64 195 virtual void pass_float() { 196 *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); 197 debug_only(verify_tag(frame::TagValue)); 198 _from -= Interpreter::stackElementSize(); 199 add_signature( float_sig ); 200 } 201 202 virtual void pass_double() { 203 *_to++ = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); 204 debug_only(verify_tag(frame::TagValue)); 205 _from -= 2*Interpreter::stackElementSize(); 206 add_signature( double_sig ); 207 } 208 209 virtual void pass_long() { 210 _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); 211 debug_only(verify_tag(frame::TagValue)); 212 _to += 1; 213 _from -= 2*Interpreter::stackElementSize(); 214 add_signature( long_sig ); 215 } 216#else 217 // pass_double() is pass_long() and pass_float() only _LP64 218 virtual void pass_long() { 219 _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); 220 _to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0)); 221 debug_only(verify_tag(frame::TagValue)); 222 _to += 2; 223 _from -= 2*Interpreter::stackElementSize(); 224 add_signature( non_float ); 225 } 226#endif // _LP64 227 228 virtual void add_signature( intptr_t sig_type ) { 229 if ( _argcount < (sizeof (intptr_t))*4 ) { 230 *_RegArgSignature |= (sig_type << (_argcount*2) ); 231 _argcount++; 232 } 233 } 234 235 236 public: 237 SlowSignatureHandler(methodHandle method, address from, intptr_t* to, intptr_t *RegArgSig) : NativeSignatureIterator(method) { 238 _from = from; 239 _to = to; 240 _RegArgSignature = RegArgSig; 241 *_RegArgSignature = 0; 242 _argcount = method->is_static() ? 2 : 1; 243 } 244}; 245 246 247IRT_ENTRY(address, InterpreterRuntime::slow_signature_handler( 248 JavaThread* thread, 249 methodOopDesc* method, 250 intptr_t* from, 251 intptr_t* to )) 252 methodHandle m(thread, method); 253 assert(m->is_native(), "sanity check"); 254 // handle arguments 255 // Warning: We use reg arg slot 00 temporarily to return the RegArgSignature 256 // back to the code that pops the arguments into the CPU registers 257 SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate(UCONST64(-1)); 258 // return result handler 259 return Interpreter::result_handler(m->result_type()); 260IRT_END 261