duke@435: /* duke@435: * Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // This file holds platform-dependent routines used to write primitive jni duke@435: // types to the array of arguments passed into JavaCalls::call duke@435: duke@435: class JNITypes : AllStatic { duke@435: // These functions write a java primitive type (in native format) duke@435: // to a java stack slot array to be passed as an argument to JavaCalls:calls. duke@435: // I.e., they are functionally 'push' operations if they have a 'pos' duke@435: // formal parameter. Note that jlong's and jdouble's are written duke@435: // _in reverse_ of the order in which they appear in the interpreter duke@435: // stack. This is because call stubs (see stubGenerator_sparc.cpp) duke@435: // reverse the argument list constructed by JavaCallArguments (see duke@435: // javaCalls.hpp). duke@435: duke@435: private: duke@435: duke@435: #ifndef AMD64 duke@435: // 32bit Helper routines. duke@435: static inline void put_int2r(jint *from, intptr_t *to) { *(jint *)(to++) = from[1]; duke@435: *(jint *)(to ) = from[0]; } duke@435: static inline void put_int2r(jint *from, intptr_t *to, int& pos) { put_int2r(from, to + pos); pos += 2; } duke@435: #endif // AMD64 duke@435: duke@435: public: duke@435: // Ints are stored in native format in one JavaCallArgument slot at *to. duke@435: static inline void put_int(jint from, intptr_t *to) { *(jint *)(to + 0 ) = from; } duke@435: static inline void put_int(jint from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = from; } duke@435: static inline void put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; } duke@435: duke@435: #ifdef AMD64 duke@435: // Longs are stored in native format in one JavaCallArgument slot at duke@435: // *(to+1). duke@435: static inline void put_long(jlong from, intptr_t *to) { duke@435: *(jlong*) (to + 1) = from; duke@435: } duke@435: duke@435: static inline void put_long(jlong from, intptr_t *to, int& pos) { duke@435: *(jlong*) (to + 1 + pos) = from; duke@435: pos += 2; duke@435: } duke@435: duke@435: static inline void put_long(jlong *from, intptr_t *to, int& pos) { duke@435: *(jlong*) (to + 1 + pos) = *from; duke@435: pos += 2; duke@435: } duke@435: #else duke@435: // Longs are stored in big-endian word format in two JavaCallArgument slots at *to. duke@435: // The high half is in *to and the low half in *(to+1). duke@435: static inline void put_long(jlong from, intptr_t *to) { put_int2r((jint *)&from, to); } duke@435: static inline void put_long(jlong from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); } duke@435: static inline void put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); } duke@435: #endif // AMD64 duke@435: duke@435: // Oops are stored in native format in one JavaCallArgument slot at *to. duke@435: static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; } duke@435: static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; } duke@435: static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; } duke@435: duke@435: // Floats are stored in native format in one JavaCallArgument slot at *to. duke@435: static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; } duke@435: static inline void put_float(jfloat from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = from; } duke@435: static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; } duke@435: duke@435: #undef _JNI_SLOT_OFFSET duke@435: #ifdef AMD64 duke@435: #define _JNI_SLOT_OFFSET 1 duke@435: // Doubles are stored in native word format in one JavaCallArgument duke@435: // slot at *(to+1). duke@435: static inline void put_double(jdouble from, intptr_t *to) { duke@435: *(jdouble*) (to + 1) = from; duke@435: } duke@435: duke@435: static inline void put_double(jdouble from, intptr_t *to, int& pos) { duke@435: *(jdouble*) (to + 1 + pos) = from; duke@435: pos += 2; duke@435: } duke@435: duke@435: static inline void put_double(jdouble *from, intptr_t *to, int& pos) { duke@435: *(jdouble*) (to + 1 + pos) = *from; duke@435: pos += 2; duke@435: } duke@435: #else duke@435: #define _JNI_SLOT_OFFSET 0 duke@435: // Doubles are stored in big-endian word format in two JavaCallArgument slots at *to. duke@435: // The high half is in *to and the low half in *(to+1). duke@435: static inline void put_double(jdouble from, intptr_t *to) { put_int2r((jint *)&from, to); } duke@435: static inline void put_double(jdouble from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); } duke@435: static inline void put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); } duke@435: #endif // AMD64 duke@435: duke@435: duke@435: // The get_xxx routines, on the other hand, actually _do_ fetch duke@435: // java primitive types from the interpreter stack. duke@435: // No need to worry about alignment on Intel. duke@435: static inline jint get_int (intptr_t *from) { return *(jint *) from; } duke@435: static inline jlong get_long (intptr_t *from) { return *(jlong *) (from + _JNI_SLOT_OFFSET); } duke@435: static inline oop get_obj (intptr_t *from) { return *(oop *) from; } duke@435: static inline jfloat get_float (intptr_t *from) { return *(jfloat *) from; } duke@435: static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); } duke@435: #undef _JNI_SLOT_OFFSET duke@435: };