1 /* 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * 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 34 void 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 42 void InterpreterRuntime::SignatureHandlerGenerator::pass_long() { 43 Argument jni_arg(jni_offset(), false); 44 Register Rtmp = O0; 45 46 #ifdef _LP64 47 __ ldx(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 48 __ store_long_argument(Rtmp, jni_arg); 49 #else 50 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 51 __ store_argument(Rtmp, jni_arg); 52 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 0), Rtmp); 53 Argument successor(jni_arg.successor()); 54 __ store_argument(Rtmp, successor); 55 #endif 56 } 57 58 59 void InterpreterRuntime::SignatureHandlerGenerator::pass_float() { 60 Argument jni_arg(jni_offset(), false); 61 #ifdef _LP64 62 FloatRegister Rtmp = F0; 63 __ ldf(FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); 64 __ store_float_argument(Rtmp, jni_arg); 65 #else 66 Register Rtmp = O0; 67 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); 68 __ store_argument(Rtmp, jni_arg); 69 #endif 70 } 71 72 73 void InterpreterRuntime::SignatureHandlerGenerator::pass_double() { 74 Argument jni_arg(jni_offset(), false); 75 #ifdef _LP64 76 FloatRegister Rtmp = F0; 77 __ ldf(FloatRegisterImpl::D, Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 78 __ store_double_argument(Rtmp, jni_arg); 79 #else 80 Register Rtmp = O0; 81 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); 82 __ store_argument(Rtmp, jni_arg); 83 __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); 84 Argument successor(jni_arg.successor()); 85 __ store_argument(Rtmp, successor); 86 #endif 87 } 88 89 void InterpreterRuntime::SignatureHandlerGenerator::pass_object() { 90 Argument jni_arg(jni_offset(), false); 91 Argument java_arg( offset(), true); 92 Register Rtmp1 = O0; 93 Register Rtmp2 = jni_arg.is_register() ? jni_arg.as_register() : O0; 94 Register Rtmp3 = G3_scratch; 95 96 // the handle for a receiver will never be null 97 bool do_NULL_check = offset() != 0 || is_static(); 98 99 Address h_arg = Address(Llocals, Interpreter::local_offset_in_bytes(offset())); 100 __ ld_ptr(h_arg, Rtmp1); 101 if (!do_NULL_check) { 102 __ add(h_arg.base(), h_arg.disp(), Rtmp2); 103 } else { 104 if (Rtmp1 == Rtmp2) 105 __ tst(Rtmp1); 106 else __ addcc(G0, Rtmp1, Rtmp2); // optimize mov/test pair 107 Label L; 108 __ brx(Assembler::notZero, true, Assembler::pt, L); 109 __ delayed()->add(h_arg.base(), h_arg.disp(), Rtmp2); 110 __ bind(L); 111 } 112 __ store_ptr_argument(Rtmp2, jni_arg); // this is often a no-op 113 } 114 115 116 void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) { 117 118 // generate code to handle arguments 119 iterate(fingerprint); 120 121 // return result handler 122 AddressLiteral result_handler(Interpreter::result_handler(method()->result_type())); 123 __ sethi(result_handler, Lscratch); 124 __ retl(); 125 __ delayed()->add(Lscratch, result_handler.low10(), Lscratch); 126 127 __ flush(); 128 } 129 130 131 // Implementation of SignatureHandlerLibrary 132 133 void SignatureHandlerLibrary::pd_set_handler(address handler) {} 134 135 136 class SlowSignatureHandler: public NativeSignatureIterator { 137 private: 138 address _from; 139 intptr_t* _to; 140 intptr_t* _RegArgSignature; // Signature of first Arguments to be passed in Registers 141 uint _argcount; 142 143 enum { // We need to differenciate float from non floats in reg args 144 non_float = 0, 145 float_sig = 1, 146 double_sig = 2, 147 long_sig = 3 148 }; 149 150 virtual void pass_int() { 151 *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); 152 _from -= Interpreter::stackElementSize; 153 add_signature( non_float ); 154 } 155 156 virtual void pass_object() { 157 // pass address of from 158 intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0)); 159 *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr; 160 _from -= Interpreter::stackElementSize; 161 add_signature( non_float ); 162 } 163 164 #ifdef _LP64 165 virtual void pass_float() { 166 *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); 167 _from -= Interpreter::stackElementSize; 168 add_signature( float_sig ); 169 } 170 171 virtual void pass_double() { 172 *_to++ = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); 173 _from -= 2*Interpreter::stackElementSize; 174 add_signature( double_sig ); 175 } 176 177 virtual void pass_long() { 178 _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); 179 _to += 1; 180 _from -= 2*Interpreter::stackElementSize; 181 add_signature( long_sig ); 182 } 183 #else 184 // pass_double() is pass_long() and pass_float() only _LP64 185 virtual void pass_long() { 186 _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); 187 _to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0)); 188 _to += 2; 189 _from -= 2*Interpreter::stackElementSize; 190 add_signature( non_float ); 191 } 192 193 virtual void pass_float() { 194 *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); 195 _from -= Interpreter::stackElementSize; 196 add_signature( non_float ); 197 } 198 199 #endif // _LP64 200 201 virtual void add_signature( intptr_t sig_type ) { 202 if ( _argcount < (sizeof (intptr_t))*4 ) { 203 *_RegArgSignature |= (sig_type << (_argcount*2) ); 204 _argcount++; 205 } 206 } 207 208 209 public: 210 SlowSignatureHandler(methodHandle method, address from, intptr_t* to, intptr_t *RegArgSig) : NativeSignatureIterator(method) { 211 _from = from; 212 _to = to; 213 _RegArgSignature = RegArgSig; 214 *_RegArgSignature = 0; 215 _argcount = method->is_static() ? 2 : 1; 216 } 217 }; 218 219 220 IRT_ENTRY(address, InterpreterRuntime::slow_signature_handler( 221 JavaThread* thread, 222 methodOopDesc* method, 223 intptr_t* from, 224 intptr_t* to )) 225 methodHandle m(thread, method); 226 assert(m->is_native(), "sanity check"); 227 // handle arguments 228 // Warning: We use reg arg slot 00 temporarily to return the RegArgSignature 229 // back to the code that pops the arguments into the CPU registers 230 SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate(UCONST64(-1)); 231 // return result handler 232 return Interpreter::result_handler(m->result_type()); 233 IRT_END