src/cpu/x86/vm/jniTypes_x86.hpp

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

author
rasbold
date
Wed, 07 May 2008 08:06:46 -0700
changeset 580
f3de1255b035
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

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

     1 /*
     2  * Copyright 1998-2003 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  */
    25 // This file holds platform-dependent routines used to write primitive jni
    26 // types to the array of arguments passed into JavaCalls::call
    28 class JNITypes : AllStatic {
    29   // These functions write a java primitive type (in native format)
    30   // to a java stack slot array to be passed as an argument to JavaCalls:calls.
    31   // I.e., they are functionally 'push' operations if they have a 'pos'
    32   // formal parameter.  Note that jlong's and jdouble's are written
    33   // _in reverse_ of the order in which they appear in the interpreter
    34   // stack.  This is because call stubs (see stubGenerator_sparc.cpp)
    35   // reverse the argument list constructed by JavaCallArguments (see
    36   // javaCalls.hpp).
    38 private:
    40 #ifndef AMD64
    41   // 32bit Helper routines.
    42   static inline void    put_int2r(jint *from, intptr_t *to)           { *(jint *)(to++) = from[1];
    43                                                                         *(jint *)(to  ) = from[0]; }
    44   static inline void    put_int2r(jint *from, intptr_t *to, int& pos) { put_int2r(from, to + pos); pos += 2; }
    45 #endif // AMD64
    47 public:
    48   // Ints are stored in native format in one JavaCallArgument slot at *to.
    49   static inline void    put_int(jint  from, intptr_t *to)           { *(jint *)(to +   0  ) =  from; }
    50   static inline void    put_int(jint  from, intptr_t *to, int& pos) { *(jint *)(to + pos++) =  from; }
    51   static inline void    put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; }
    53 #ifdef AMD64
    54   // Longs are stored in native format in one JavaCallArgument slot at
    55   // *(to+1).
    56   static inline void put_long(jlong  from, intptr_t *to) {
    57     *(jlong*) (to + 1) = from;
    58   }
    60   static inline void put_long(jlong  from, intptr_t *to, int& pos) {
    61     *(jlong*) (to + 1 + pos) = from;
    62     pos += 2;
    63   }
    65   static inline void put_long(jlong *from, intptr_t *to, int& pos) {
    66     *(jlong*) (to + 1 + pos) = *from;
    67     pos += 2;
    68   }
    69 #else
    70   // Longs are stored in big-endian word format in two JavaCallArgument slots at *to.
    71   // The high half is in *to and the low half in *(to+1).
    72   static inline void    put_long(jlong  from, intptr_t *to)           { put_int2r((jint *)&from, to); }
    73   static inline void    put_long(jlong  from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); }
    74   static inline void    put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }
    75 #endif // AMD64
    77   // Oops are stored in native format in one JavaCallArgument slot at *to.
    78   static inline void    put_obj(oop  from, intptr_t *to)           { *(oop *)(to +   0  ) =  from; }
    79   static inline void    put_obj(oop  from, intptr_t *to, int& pos) { *(oop *)(to + pos++) =  from; }
    80   static inline void    put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
    82   // Floats are stored in native format in one JavaCallArgument slot at *to.
    83   static inline void    put_float(jfloat  from, intptr_t *to)           { *(jfloat *)(to +   0  ) =  from;  }
    84   static inline void    put_float(jfloat  from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) =  from; }
    85   static inline void    put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; }
    87 #undef _JNI_SLOT_OFFSET
    88 #ifdef AMD64
    89 #define _JNI_SLOT_OFFSET 1
    90   // Doubles are stored in native word format in one JavaCallArgument
    91   // slot at *(to+1).
    92   static inline void put_double(jdouble  from, intptr_t *to) {
    93     *(jdouble*) (to + 1) = from;
    94   }
    96   static inline void put_double(jdouble  from, intptr_t *to, int& pos) {
    97     *(jdouble*) (to + 1 + pos) = from;
    98     pos += 2;
    99   }
   101   static inline void put_double(jdouble *from, intptr_t *to, int& pos) {
   102     *(jdouble*) (to + 1 + pos) = *from;
   103     pos += 2;
   104   }
   105 #else
   106 #define _JNI_SLOT_OFFSET 0
   107   // Doubles are stored in big-endian word format in two JavaCallArgument slots at *to.
   108   // The high half is in *to and the low half in *(to+1).
   109   static inline void    put_double(jdouble  from, intptr_t *to)           { put_int2r((jint *)&from, to); }
   110   static inline void    put_double(jdouble  from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); }
   111   static inline void    put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }
   112 #endif // AMD64
   115   // The get_xxx routines, on the other hand, actually _do_ fetch
   116   // java primitive types from the interpreter stack.
   117   // No need to worry about alignment on Intel.
   118   static inline jint    get_int   (intptr_t *from) { return *(jint *)   from; }
   119   static inline jlong   get_long  (intptr_t *from) { return *(jlong *)  (from + _JNI_SLOT_OFFSET); }
   120   static inline oop     get_obj   (intptr_t *from) { return *(oop *)    from; }
   121   static inline jfloat  get_float (intptr_t *from) { return *(jfloat *) from; }
   122   static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); }
   123 #undef _JNI_SLOT_OFFSET
   124 };

mercurial