never@1445: /* stefank@2314: * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. never@1445: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. never@1445: * never@1445: * This code is free software; you can redistribute it and/or modify it never@1445: * under the terms of the GNU General Public License version 2 only, as never@1445: * published by the Free Software Foundation. never@1445: * never@1445: * This code is distributed in the hope that it will be useful, but WITHOUT never@1445: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or never@1445: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License never@1445: * version 2 for more details (a copy is included in the LICENSE file that never@1445: * accompanied this code). never@1445: * never@1445: * You should have received a copy of the GNU General Public License version never@1445: * 2 along with this work; if not, write to the Free Software Foundation, never@1445: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. never@1445: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. never@1445: * never@1445: */ never@1445: stefank@2314: #ifndef CPU_ZERO_VM_JNITYPES_ZERO_HPP stefank@2314: #define CPU_ZERO_VM_JNITYPES_ZERO_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "oops/oop.hpp" stefank@2314: #include "prims/jni.h" stefank@2314: never@1445: // This file holds platform-dependent routines used to write primitive jni never@1445: // types to the array of arguments passed into JavaCalls::call never@1445: never@1445: class JNITypes : AllStatic { never@1445: // These functions write a java primitive type (in native format) never@1445: // to a java stack slot array to be passed as an argument to JavaCalls:calls. never@1445: // I.e., they are functionally 'push' operations if they have a 'pos' never@1445: // formal parameter. Note that jlong's and jdouble's are written never@1445: // _in reverse_ of the order in which they appear in the interpreter never@1445: // stack. This is because call stubs (see stubGenerator_zero.cpp) never@1445: // reverse the argument list constructed by JavaCallArguments (see never@1445: // javaCalls.hpp). never@1445: never@1445: private: never@1445: // Helper routines. never@1445: static inline void put_int2 (jint *from, jint *to) { to[0] = from[0]; to[1] = from[1]; } never@1445: static inline void put_int2 (jint *from, jint *to, int& pos) { put_int2 (from, (jint *)((intptr_t *)to + pos)); pos += 2; } never@1445: static inline void put_int2r(jint *from, jint *to) { to[0] = from[1]; to[1] = from[0]; } never@1445: static inline void put_int2r(jint *from, jint *to, int& pos) { put_int2r(from, (jint *)((intptr_t *)to + pos)); pos += 2; } never@1445: never@1445: public: never@1445: // Ints are stored in native format in one JavaCallArgument slot at *to. never@1445: static inline void put_int(jint from, intptr_t *to) { *(jint *)(to + 0 ) = from; } never@1445: static inline void put_int(jint from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = from; } never@1445: static inline void put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; } never@1445: never@1445: #ifdef _LP64 never@1445: // Longs are stored in native format in one JavaCallArgument slot at *(to+1). never@1445: static inline void put_long(jlong from, intptr_t *to) { *(jlong *)(to + 1 + 0) = from; } never@1445: static inline void put_long(jlong from, intptr_t *to, int& pos) { *(jlong *)(to + 1 + pos) = from; pos += 2; } never@1445: static inline void put_long(jlong *from, intptr_t *to, int& pos) { *(jlong *)(to + 1 + pos) = *from; pos += 2; } never@1445: #else never@1445: // Longs are stored in reversed native word format in two JavaCallArgument slots at *to. never@1445: // The high half is in *(to+1) and the low half in *to. never@1445: static inline void put_long(jlong from, intptr_t *to) { put_int2r((jint *)&from, (jint *)to); } never@1445: static inline void put_long(jlong from, intptr_t *to, int& pos) { put_int2r((jint *)&from, (jint *)to, pos); } never@1445: static inline void put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, (jint *)to, pos); } never@1445: #endif never@1445: never@1445: // Oops are stored in native format in one JavaCallArgument slot at *to. never@1445: static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; } never@1445: static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; } never@1445: static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; } never@1445: never@1445: // Floats are stored in native format in one JavaCallArgument slot at *to. never@1445: static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; } never@1445: static inline void put_float(jfloat from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = from; } never@1445: static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; } never@1445: never@1445: #ifdef _LP64 never@1445: // Doubles are stored in native word format in one JavaCallArgument slot at *(to+1). never@1445: static inline void put_double(jdouble from, intptr_t *to) { *(jdouble *)(to + 1 + 0) = from; } never@1445: static inline void put_double(jdouble from, intptr_t *to, int& pos) { *(jdouble *)(to + 1 + pos) = from; pos += 2; } never@1445: static inline void put_double(jdouble *from, intptr_t *to, int& pos) { *(jdouble *)(to + 1 + pos) = *from; pos += 2; } never@1445: #else never@1445: // Doubles are stored in reversed native word format in two JavaCallArgument slots at *to. never@1445: static inline void put_double(jdouble from, intptr_t *to) { put_int2r((jint *)&from, (jint *)to); } never@1445: static inline void put_double(jdouble from, intptr_t *to, int& pos) { put_int2r((jint *)&from, (jint *)to, pos); } never@1445: static inline void put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, (jint *)to, pos); } never@1445: #endif never@1445: never@1445: // The get_xxx routines, on the other hand, actually _do_ fetch never@1445: // java primitive types from the interpreter stack. never@1445: static inline jint get_int(intptr_t *from) { return *(jint *)from; } never@1445: never@1445: #ifdef _LP64 never@1445: static inline jlong get_long(intptr_t *from) { return *(jlong *)from; } never@1445: #else never@1445: static inline jlong get_long(intptr_t *from) { return ((jlong)(*( signed int *)((jint *)from )) << 32) | never@1445: ((jlong)(*(unsigned int *)((jint *)from + 1)) << 0); } never@1445: #endif never@1445: never@1445: static inline oop get_obj(intptr_t *from) { return *(oop *)from; } never@1445: static inline jfloat get_float(intptr_t *from) { return *(jfloat *)from; } never@1445: never@1445: #ifdef _LP64 never@1445: static inline jdouble get_double(intptr_t *from) { return *(jdouble *)from; } never@1445: #else never@1445: static inline jdouble get_double(intptr_t *from) { jlong jl = ((jlong)(*( signed int *)((jint *)from )) << 32) | never@1445: ((jlong)(*(unsigned int *)((jint *)from + 1)) << 0); never@1445: return *(jdouble *)&jl; } never@1445: #endif never@1445: never@1445: }; stefank@2314: stefank@2314: #endif // CPU_ZERO_VM_JNITYPES_ZERO_HPP