src/cpu/sparc/vm/interpreterRT_sparc.cpp

changeset 435
a61af66fc99e
child 1162
6b2273dd6fa9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/sparc/vm/interpreterRT_sparc.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,260 @@
     1.4 +/*
     1.5 + * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_interpreterRT_sparc.cpp.incl"
    1.30 +
    1.31 +
    1.32 +#define __ _masm->
    1.33 +
    1.34 +
    1.35 +// Implementation of SignatureHandlerGenerator
    1.36 +
    1.37 +void InterpreterRuntime::SignatureHandlerGenerator::pass_word(int size_of_arg, int offset_in_arg) {
    1.38 +  Argument  jni_arg(jni_offset() + offset_in_arg, false);
    1.39 +  Register     Rtmp = O0;
    1.40 +  __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
    1.41 +
    1.42 +  __ store_argument(Rtmp, jni_arg);
    1.43 +}
    1.44 +
    1.45 +void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
    1.46 +  Argument  jni_arg(jni_offset(), false);
    1.47 +  Register  Rtmp = O0;
    1.48 +
    1.49 +#ifdef ASSERT
    1.50 +  if (TaggedStackInterpreter) {
    1.51 +    // check at least one tag is okay
    1.52 +    Label ok;
    1.53 +    __ ld_ptr(Llocals, Interpreter::local_tag_offset_in_bytes(offset() + 1), Rtmp);
    1.54 +    __ cmp(Rtmp, G0);
    1.55 +    __ brx(Assembler::equal, false, Assembler::pt, ok);
    1.56 +    __ delayed()->nop();
    1.57 +    __ stop("Native object has bad tag value");
    1.58 +    __ bind(ok);
    1.59 +  }
    1.60 +#endif // ASSERT
    1.61 +
    1.62 +#ifdef _LP64
    1.63 +  __ ldx(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
    1.64 +  __ store_long_argument(Rtmp, jni_arg);
    1.65 +#else
    1.66 +  __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
    1.67 +  __ store_argument(Rtmp, jni_arg);
    1.68 +  __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 0), Rtmp);
    1.69 +  Argument successor(jni_arg.successor());
    1.70 +  __ store_argument(Rtmp, successor);
    1.71 +#endif
    1.72 +}
    1.73 +
    1.74 +
    1.75 +#ifdef _LP64
    1.76 +void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
    1.77 +  Argument  jni_arg(jni_offset(), false);
    1.78 +  FloatRegister  Rtmp = F0;
    1.79 +  __ ldf(FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
    1.80 +  __ store_float_argument(Rtmp, jni_arg);
    1.81 +}
    1.82 +#endif
    1.83 +
    1.84 +
    1.85 +void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
    1.86 +  Argument  jni_arg(jni_offset(), false);
    1.87 +#ifdef _LP64
    1.88 +  FloatRegister  Rtmp = F0;
    1.89 +  __ ldf(FloatRegisterImpl::D, Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
    1.90 +  __ store_double_argument(Rtmp, jni_arg);
    1.91 +#else
    1.92 +  Register  Rtmp = O0;
    1.93 +  __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
    1.94 +  __ store_argument(Rtmp, jni_arg);
    1.95 +  __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
    1.96 +  Argument successor(jni_arg.successor());
    1.97 +  __ store_argument(Rtmp, successor);
    1.98 +#endif
    1.99 +}
   1.100 +
   1.101 +void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
   1.102 +  Argument  jni_arg(jni_offset(), false);
   1.103 +  Argument java_arg(    offset(), true);
   1.104 +  Register    Rtmp1 = O0;
   1.105 +  Register    Rtmp2 =  jni_arg.is_register() ?  jni_arg.as_register() : O0;
   1.106 +  Register    Rtmp3 =  G3_scratch;
   1.107 +
   1.108 +  // the handle for a receiver will never be null
   1.109 +  bool do_NULL_check = offset() != 0 || is_static();
   1.110 +
   1.111 +  Address     h_arg = Address(Llocals, 0, Interpreter::local_offset_in_bytes(offset()));
   1.112 +  __ ld_ptr(h_arg, Rtmp1);
   1.113 +#ifdef ASSERT
   1.114 +  if (TaggedStackInterpreter) {
   1.115 +    // check we have the obj and not the tag
   1.116 +    Label ok;
   1.117 +    __ mov(frame::TagReference, Rtmp3);
   1.118 +    __ cmp(Rtmp1, Rtmp3);
   1.119 +    __ brx(Assembler::notEqual, true, Assembler::pt, ok);
   1.120 +    __ delayed()->nop();
   1.121 +    __ stop("Native object passed tag by mistake");
   1.122 +    __ bind(ok);
   1.123 +  }
   1.124 +#endif // ASSERT
   1.125 +  if (!do_NULL_check) {
   1.126 +    __ add(h_arg, Rtmp2);
   1.127 +  } else {
   1.128 +    if (Rtmp1 == Rtmp2)
   1.129 +          __ tst(Rtmp1);
   1.130 +    else  __ addcc(G0, Rtmp1, Rtmp2); // optimize mov/test pair
   1.131 +    Label L;
   1.132 +    __ brx(Assembler::notZero, true, Assembler::pt, L);
   1.133 +    __ delayed()->add(h_arg, Rtmp2);
   1.134 +    __ bind(L);
   1.135 +  }
   1.136 +  __ store_ptr_argument(Rtmp2, jni_arg);    // this is often a no-op
   1.137 +}
   1.138 +
   1.139 +
   1.140 +void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
   1.141 +
   1.142 +  // generate code to handle arguments
   1.143 +  iterate(fingerprint);
   1.144 +
   1.145 +  // return result handler
   1.146 +  Address result_handler(Lscratch, Interpreter::result_handler(method()->result_type()));
   1.147 +  __ sethi(result_handler);
   1.148 +  __ retl();
   1.149 +  __ delayed()->add(result_handler, result_handler.base());
   1.150 +
   1.151 +  __ flush();
   1.152 +}
   1.153 +
   1.154 +
   1.155 +// Implementation of SignatureHandlerLibrary
   1.156 +
   1.157 +void SignatureHandlerLibrary::pd_set_handler(address handler) {}
   1.158 +
   1.159 +
   1.160 +class SlowSignatureHandler: public NativeSignatureIterator {
   1.161 + private:
   1.162 +  address   _from;
   1.163 +  intptr_t* _to;
   1.164 +  intptr_t* _RegArgSignature;                   // Signature of first Arguments to be passed in Registers
   1.165 +  uint      _argcount;
   1.166 +
   1.167 +  enum {                                        // We need to differenciate float from non floats in reg args
   1.168 +    non_float  = 0,
   1.169 +    float_sig  = 1,
   1.170 +    double_sig = 2,
   1.171 +    long_sig   = 3
   1.172 +  };
   1.173 +
   1.174 +#ifdef ASSERT
   1.175 +  void verify_tag(frame::Tag t) {
   1.176 +    assert(!TaggedStackInterpreter ||
   1.177 +           *(intptr_t*)(_from+Interpreter::local_tag_offset_in_bytes(0)) == t, "wrong tag");
   1.178 +  }
   1.179 +#endif // ASSERT
   1.180 +
   1.181 +  virtual void pass_int() {
   1.182 +    *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
   1.183 +    debug_only(verify_tag(frame::TagValue));
   1.184 +    _from -= Interpreter::stackElementSize();
   1.185 +    add_signature( non_float );
   1.186 +  }
   1.187 +
   1.188 +  virtual void pass_object() {
   1.189 +    // pass address of from
   1.190 +    intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0));
   1.191 +    *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
   1.192 +    debug_only(verify_tag(frame::TagReference));
   1.193 +    _from -= Interpreter::stackElementSize();
   1.194 +    add_signature( non_float );
   1.195 +   }
   1.196 +
   1.197 +#ifdef _LP64
   1.198 +  virtual void pass_float()  {
   1.199 +    *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
   1.200 +    debug_only(verify_tag(frame::TagValue));
   1.201 +    _from -= Interpreter::stackElementSize();
   1.202 +    add_signature( float_sig );
   1.203 +   }
   1.204 +
   1.205 +  virtual void pass_double() {
   1.206 +    *_to++ = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
   1.207 +    debug_only(verify_tag(frame::TagValue));
   1.208 +    _from -= 2*Interpreter::stackElementSize();
   1.209 +   add_signature( double_sig );
   1.210 +   }
   1.211 +
   1.212 +  virtual void pass_long() {
   1.213 +    _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
   1.214 +    debug_only(verify_tag(frame::TagValue));
   1.215 +    _to += 1;
   1.216 +    _from -= 2*Interpreter::stackElementSize();
   1.217 +    add_signature( long_sig );
   1.218 +  }
   1.219 +#else
   1.220 +   // pass_double() is pass_long() and pass_float() only _LP64
   1.221 +  virtual void pass_long() {
   1.222 +    _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
   1.223 +    _to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0));
   1.224 +    debug_only(verify_tag(frame::TagValue));
   1.225 +    _to += 2;
   1.226 +    _from -= 2*Interpreter::stackElementSize();
   1.227 +    add_signature( non_float );
   1.228 +  }
   1.229 +#endif // _LP64
   1.230 +
   1.231 +  virtual void add_signature( intptr_t sig_type ) {
   1.232 +    if ( _argcount < (sizeof (intptr_t))*4 ) {
   1.233 +      *_RegArgSignature |= (sig_type << (_argcount*2) );
   1.234 +      _argcount++;
   1.235 +    }
   1.236 +  }
   1.237 +
   1.238 +
   1.239 + public:
   1.240 +  SlowSignatureHandler(methodHandle method, address from, intptr_t* to, intptr_t *RegArgSig) : NativeSignatureIterator(method) {
   1.241 +    _from = from;
   1.242 +    _to   = to;
   1.243 +    _RegArgSignature = RegArgSig;
   1.244 +    *_RegArgSignature = 0;
   1.245 +    _argcount = method->is_static() ? 2 : 1;
   1.246 +  }
   1.247 +};
   1.248 +
   1.249 +
   1.250 +IRT_ENTRY(address, InterpreterRuntime::slow_signature_handler(
   1.251 +                                                    JavaThread* thread,
   1.252 +                                                    methodOopDesc* method,
   1.253 +                                                    intptr_t* from,
   1.254 +                                                    intptr_t* to ))
   1.255 +  methodHandle m(thread, method);
   1.256 +  assert(m->is_native(), "sanity check");
   1.257 +  // handle arguments
   1.258 +  // Warning: We use reg arg slot 00 temporarily to return the RegArgSignature
   1.259 +  // back to the code that pops the arguments into the CPU registers
   1.260 +  SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate(UCONST64(-1));
   1.261 +  // return result handler
   1.262 +  return Interpreter::result_handler(m->result_type());
   1.263 +IRT_END

mercurial