1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/jniTypes_x86.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,133 @@ 1.4 +/* 1.5 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef CPU_X86_VM_JNITYPES_X86_HPP 1.29 +#define CPU_X86_VM_JNITYPES_X86_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "oops/oop.hpp" 1.33 +#include "prims/jni.h" 1.34 + 1.35 +// This file holds platform-dependent routines used to write primitive jni 1.36 +// types to the array of arguments passed into JavaCalls::call 1.37 + 1.38 +class JNITypes : AllStatic { 1.39 + // These functions write a java primitive type (in native format) 1.40 + // to a java stack slot array to be passed as an argument to JavaCalls:calls. 1.41 + // I.e., they are functionally 'push' operations if they have a 'pos' 1.42 + // formal parameter. Note that jlong's and jdouble's are written 1.43 + // _in reverse_ of the order in which they appear in the interpreter 1.44 + // stack. This is because call stubs (see stubGenerator_sparc.cpp) 1.45 + // reverse the argument list constructed by JavaCallArguments (see 1.46 + // javaCalls.hpp). 1.47 + 1.48 +private: 1.49 + 1.50 +#ifndef AMD64 1.51 + // 32bit Helper routines. 1.52 + static inline void put_int2r(jint *from, intptr_t *to) { *(jint *)(to++) = from[1]; 1.53 + *(jint *)(to ) = from[0]; } 1.54 + static inline void put_int2r(jint *from, intptr_t *to, int& pos) { put_int2r(from, to + pos); pos += 2; } 1.55 +#endif // AMD64 1.56 + 1.57 +public: 1.58 + // Ints are stored in native format in one JavaCallArgument slot at *to. 1.59 + static inline void put_int(jint from, intptr_t *to) { *(jint *)(to + 0 ) = from; } 1.60 + static inline void put_int(jint from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = from; } 1.61 + static inline void put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; } 1.62 + 1.63 +#ifdef AMD64 1.64 + // Longs are stored in native format in one JavaCallArgument slot at 1.65 + // *(to+1). 1.66 + static inline void put_long(jlong from, intptr_t *to) { 1.67 + *(jlong*) (to + 1) = from; 1.68 + } 1.69 + 1.70 + static inline void put_long(jlong from, intptr_t *to, int& pos) { 1.71 + *(jlong*) (to + 1 + pos) = from; 1.72 + pos += 2; 1.73 + } 1.74 + 1.75 + static inline void put_long(jlong *from, intptr_t *to, int& pos) { 1.76 + *(jlong*) (to + 1 + pos) = *from; 1.77 + pos += 2; 1.78 + } 1.79 +#else 1.80 + // Longs are stored in big-endian word format in two JavaCallArgument slots at *to. 1.81 + // The high half is in *to and the low half in *(to+1). 1.82 + static inline void put_long(jlong from, intptr_t *to) { put_int2r((jint *)&from, to); } 1.83 + static inline void put_long(jlong from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); } 1.84 + static inline void put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); } 1.85 +#endif // AMD64 1.86 + 1.87 + // Oops are stored in native format in one JavaCallArgument slot at *to. 1.88 + static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; } 1.89 + static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; } 1.90 + static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; } 1.91 + 1.92 + // Floats are stored in native format in one JavaCallArgument slot at *to. 1.93 + static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; } 1.94 + static inline void put_float(jfloat from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = from; } 1.95 + static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; } 1.96 + 1.97 +#undef _JNI_SLOT_OFFSET 1.98 +#ifdef AMD64 1.99 +#define _JNI_SLOT_OFFSET 1 1.100 + // Doubles are stored in native word format in one JavaCallArgument 1.101 + // slot at *(to+1). 1.102 + static inline void put_double(jdouble from, intptr_t *to) { 1.103 + *(jdouble*) (to + 1) = from; 1.104 + } 1.105 + 1.106 + static inline void put_double(jdouble from, intptr_t *to, int& pos) { 1.107 + *(jdouble*) (to + 1 + pos) = from; 1.108 + pos += 2; 1.109 + } 1.110 + 1.111 + static inline void put_double(jdouble *from, intptr_t *to, int& pos) { 1.112 + *(jdouble*) (to + 1 + pos) = *from; 1.113 + pos += 2; 1.114 + } 1.115 +#else 1.116 +#define _JNI_SLOT_OFFSET 0 1.117 + // Doubles are stored in big-endian word format in two JavaCallArgument slots at *to. 1.118 + // The high half is in *to and the low half in *(to+1). 1.119 + static inline void put_double(jdouble from, intptr_t *to) { put_int2r((jint *)&from, to); } 1.120 + static inline void put_double(jdouble from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); } 1.121 + static inline void put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); } 1.122 +#endif // AMD64 1.123 + 1.124 + 1.125 + // The get_xxx routines, on the other hand, actually _do_ fetch 1.126 + // java primitive types from the interpreter stack. 1.127 + // No need to worry about alignment on Intel. 1.128 + static inline jint get_int (intptr_t *from) { return *(jint *) from; } 1.129 + static inline jlong get_long (intptr_t *from) { return *(jlong *) (from + _JNI_SLOT_OFFSET); } 1.130 + static inline oop get_obj (intptr_t *from) { return *(oop *) from; } 1.131 + static inline jfloat get_float (intptr_t *from) { return *(jfloat *) from; } 1.132 + static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); } 1.133 +#undef _JNI_SLOT_OFFSET 1.134 +}; 1.135 + 1.136 +#endif // CPU_X86_VM_JNITYPES_X86_HPP