aoqi@1: /* aoqi@1: * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@1: * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved. aoqi@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@1: * aoqi@1: * This code is free software; you can redistribute it and/or modify it aoqi@1: * under the terms of the GNU General Public License version 2 only, as aoqi@1: * published by the Free Software Foundation. aoqi@1: * aoqi@1: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@1: * version 2 for more details (a copy is included in the LICENSE file that aoqi@1: * accompanied this code). aoqi@1: * aoqi@1: * You should have received a copy of the GNU General Public License version aoqi@1: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@1: * aoqi@1: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@1: * or visit www.oracle.com if you need additional information or have any aoqi@1: * questions. aoqi@1: * aoqi@1: */ aoqi@1: aoqi@1: #ifndef CPU_MIPS_VM_JNITYPES_MIPS_HPP aoqi@1: #define CPU_MIPS_VM_JNITYPES_MIPS_HPP aoqi@1: aoqi@1: #include "memory/allocation.hpp" aoqi@1: #include "oops/oop.hpp" aoqi@1: #include "prims/jni.h" aoqi@1: aoqi@1: // This file holds platform-dependent routines used to write primitive jni aoqi@1: // types to the array of arguments passed into JavaCalls::call aoqi@1: aoqi@1: class JNITypes : AllStatic { aoqi@1: // These functions write a java primitive type (in native format) aoqi@1: // to a java stack slot array to be passed as an argument to JavaCalls:calls. aoqi@1: // I.e., they are functionally 'push' operations if they have a 'pos' aoqi@1: // formal parameter. Note that jlong's and jdouble's are written aoqi@1: // _in reverse_ of the order in which they appear in the interpreter aoqi@1: // stack. This is because call stubs (see stubGenerator_sparc.cpp) aoqi@1: // reverse the argument list constructed by JavaCallArguments (see aoqi@1: // javaCalls.hpp). aoqi@1: aoqi@1: private: aoqi@1: aoqi@1: #ifndef AMD64 aoqi@1: // 32bit Helper routines. aoqi@1: static inline void put_int2r(jint *from, intptr_t *to) { *(jint *)(to++) = from[1]; aoqi@1: *(jint *)(to ) = from[0]; aoqi@1: } aoqi@1: static inline void put_int2r(jint *from, intptr_t *to, int& pos) { put_int2r(from, to + pos); pos += 2; } aoqi@1: #endif // AMD64 aoqi@1: aoqi@1: public: aoqi@1: #ifdef _LP64 aoqi@1: // Jin: In MIPS64, the sizeof intptr_t is 8 bytes, and each unit in JavaCallArguments::_value_buffer[] aoqi@1: // is 8 bytes. aoqi@1: // If we only write the low 4 bytes with (jint *), the high 4-bits will be left with uncertain values. aoqi@1: // Then, in JavaCallArguments::parameters(), the whole 8 bytes of a T_INT parameter is loaded. aoqi@1: // This error occurs in ReflectInvoke.java aoqi@1: // The parameter of DD(int) should be 4 instead of 0x550000004. aoqi@1: // aoqi@1: // See: [runtime/javaCalls.hpp] aoqi@1: aoqi@1: static inline void put_int(jint from, intptr_t *to) { *(intptr_t *)(to + 0 ) = from; } aoqi@1: static inline void put_int(jint from, intptr_t *to, int& pos) { *(intptr_t *)(to + pos++) = from; } aoqi@1: static inline void put_int(jint *from, intptr_t *to, int& pos) { *(intptr_t *)(to + pos++) = *from; } aoqi@1: #else aoqi@1: // Ints are stored in native format in one JavaCallArgument slot at *to. aoqi@1: static inline void put_int(jint from, intptr_t *to) { *(jint *)(to + 0 ) = from; } aoqi@1: static inline void put_int(jint from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = from; } aoqi@1: static inline void put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; } aoqi@1: #endif aoqi@1: aoqi@1: #ifdef _LP64 aoqi@1: // Longs are stored in native format in one JavaCallArgument slot at aoqi@1: // *(to). aoqi@1: // In theory, *(to + 1) is an empty slot. But, for several Java2D testing programs (TestBorderLayout, SwingTest), aoqi@1: // *(to + 1) must contains a copy of the long value. Otherwise it will corrupts. aoqi@1: static inline void put_long(jlong from, intptr_t *to) { aoqi@1: *(jlong*) (to + 1) = from; aoqi@1: *(jlong*) (to) = from; aoqi@1: } aoqi@1: aoqi@1: /* Jin: A long parameter occupies two slot. aoqi@1: * It must fit the layout rule in methodHandle. aoqi@1: * aoqi@1: * See: [runtime/reflection.cpp] Reflection::invoke() aoqi@1: * assert(java_args.size_of_parameters() == method->size_of_parameters(), "just checking"); aoqi@1: */ aoqi@1: static inline void put_long(jlong from, intptr_t *to, int& pos) { aoqi@1: *(jlong*) (to + 1 + pos) = from; aoqi@1: *(jlong*) (to + pos) = from; aoqi@1: pos += 2; aoqi@1: } aoqi@1: aoqi@1: static inline void put_long(jlong *from, intptr_t *to, int& pos) { aoqi@1: *(jlong*) (to + 1 + pos) = *from; aoqi@1: *(jlong*) (to + pos) = *from; aoqi@1: pos += 2; aoqi@1: } aoqi@1: #else aoqi@1: // Longs are stored in big-endian word format in two JavaCallArgument slots at *to. aoqi@1: // The high half is in *to and the low half in *(to+1). aoqi@1: static inline void put_long(jlong from, intptr_t *to) { put_int2r((jint *)&from, to); } aoqi@1: static inline void put_long(jlong from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); } aoqi@1: static inline void put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); } aoqi@1: #endif // AMD64 aoqi@1: aoqi@1: // Oops are stored in native format in one JavaCallArgument slot at *to. aoqi@1: static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; } aoqi@1: static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; } aoqi@1: static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; } aoqi@1: aoqi@1: // Floats are stored in native format in one JavaCallArgument slot at *to. aoqi@1: static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; } aoqi@1: static inline void put_float(jfloat from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = from; } aoqi@1: static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; } aoqi@1: aoqi@1: #undef _JNI_SLOT_OFFSET aoqi@1: #define _JNI_SLOT_OFFSET 0 aoqi@1: aoqi@1: #ifdef _LP64 aoqi@1: // Longs are stored in native format in one JavaCallArgument slot at aoqi@1: // *(to). aoqi@1: // In theory, *(to + 1) is an empty slot. But, for several Java2D testing programs (TestBorderLayout, SwingTest), aoqi@1: // *(to + 1) must contains a copy of the long value. Otherwise it will corrupts. aoqi@1: static inline void put_double(jdouble from, intptr_t *to) { aoqi@1: *(jdouble*) (to + 1) = from; aoqi@1: *(jdouble*) (to) = from; aoqi@1: } aoqi@1: aoqi@1: /* Jin: A long parameter occupies two slot. aoqi@1: * It must fit the layout rule in methodHandle. aoqi@1: * aoqi@1: * See: [runtime/reflection.cpp] Reflection::invoke() aoqi@1: * assert(java_args.size_of_parameters() == method->size_of_parameters(), "just checking"); aoqi@1: */ aoqi@1: static inline void put_double(jdouble from, intptr_t *to, int& pos) { aoqi@1: *(jdouble*) (to + 1 + pos) = from; aoqi@1: *(jdouble*) (to + pos) = from; aoqi@1: pos += 2; aoqi@1: } aoqi@1: aoqi@1: static inline void put_double(jdouble *from, intptr_t *to, int& pos) { aoqi@1: *(jdouble*) (to + 1 + pos) = *from; aoqi@1: *(jdouble*) (to + pos) = *from; aoqi@1: pos += 2; aoqi@1: } aoqi@1: #else aoqi@1: // Doubles are stored in big-endian word format in two JavaCallArgument slots at *to. aoqi@1: // The high half is in *to and the low half in *(to+1). aoqi@1: static inline void put_double(jdouble from, intptr_t *to) { put_int2r((jint *)&from, to); } aoqi@1: static inline void put_double(jdouble from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); } aoqi@1: static inline void put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); } aoqi@1: #endif aoqi@1: aoqi@1: aoqi@1: // The get_xxx routines, on the other hand, actually _do_ fetch aoqi@1: // java primitive types from the interpreter stack. aoqi@1: // No need to worry about alignment on Intel. aoqi@1: static inline jint get_int (intptr_t *from) { return *(jint *) from; } aoqi@1: static inline jlong get_long (intptr_t *from) { return *(jlong *) (from + _JNI_SLOT_OFFSET); } aoqi@1: static inline oop get_obj (intptr_t *from) { return *(oop *) from; } aoqi@1: static inline jfloat get_float (intptr_t *from) { return *(jfloat *) from; } aoqi@1: static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); } aoqi@1: #undef _JNI_SLOT_OFFSET aoqi@1: }; aoqi@1: aoqi@1: #endif // CPU_MIPS_VM_JNITYPES_MIPS_HPP