1 /* 2 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020, 2022, Huawei Technologies Co., Ltd. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef CPU_RISCV_JNITYPES_RISCV_HPP 27 #define CPU_RISCV_JNITYPES_RISCV_HPP 28 29 #include "jni.h" 30 #include "memory/allStatic.hpp" 31 #include "oops/oop.hpp" 32 33 // This file holds platform-dependent routines used to write primitive jni 34 // types to the array of arguments passed into JavaCalls::call 35 36 class JNITypes : private AllStatic { 37 // These functions write a java primitive type (in native format) 38 // to a java stack slot array to be passed as an argument to JavaCalls:calls. 39 // I.e., they are functionally 'push' operations if they have a 'pos' 40 // formal parameter. Note that jlong's and jdouble's are written 41 // _in reverse_ of the order in which they appear in the interpreter 42 // stack. This is because call stubs (see stubGenerator_sparc.cpp) 43 // reverse the argument list constructed by JavaCallArguments (see 44 // javaCalls.hpp). 45 46 public: 47 // Ints are stored in native format in one JavaCallArgument slot at *to. 48 static inline void put_int(jint from, intptr_t *to) { *(jint *)(to + 0 ) = from; } 49 static inline void put_int(jint from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = from; } 50 static inline void put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; } 51 52 // Longs are stored in native format in one JavaCallArgument slot at 53 // *(to+1). 54 static inline void put_long(jlong from, intptr_t *to) { 55 *(jlong*) (to + 1) = from; 56 } 57 58 static inline void put_long(jlong from, intptr_t *to, int& pos) { 59 *(jlong*) (to + 1 + pos) = from; 60 pos += 2; 61 } 62 63 static inline void put_long(jlong *from, intptr_t *to, int& pos) { 64 *(jlong*) (to + 1 + pos) = *from; 65 pos += 2; 66 } 67 68 // Oops are stored in native format in one JavaCallArgument slot at *to. 69 static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle.raw_value(); } 70 static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle; } 71 72 // Floats are stored in native format in one JavaCallArgument slot at *to. 73 static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; } 74 static inline void put_float(jfloat from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = from; } 75 static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; } 76 77 #undef _JNI_SLOT_OFFSET 78 #define _JNI_SLOT_OFFSET 1 79 // Doubles are stored in native word format in one JavaCallArgument 80 // slot at *(to+1). 81 static inline void put_double(jdouble from, intptr_t *to) { 82 *(jdouble*) (to + 1) = from; 83 } 84 85 static inline void put_double(jdouble from, intptr_t *to, int& pos) { 86 *(jdouble*) (to + 1 + pos) = from; 87 pos += 2; 88 } 89 90 static inline void put_double(jdouble *from, intptr_t *to, int& pos) { 91 *(jdouble*) (to + 1 + pos) = *from; 92 pos += 2; 93 } 94 95 // The get_xxx routines, on the other hand, actually _do_ fetch 96 // java primitive types from the interpreter stack. 97 // No need to worry about alignment on Intel. 98 static inline jint get_int (intptr_t *from) { return *(jint *) from; } 99 static inline jlong get_long (intptr_t *from) { return *(jlong *) (from + _JNI_SLOT_OFFSET); } 100 static inline oop get_obj (intptr_t *from) { return *(oop *) from; } 101 static inline jfloat get_float (intptr_t *from) { return *(jfloat *) from; } 102 static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); } 103 #undef _JNI_SLOT_OFFSET 104 }; 105 106 #endif // CPU_RISCV_JNITYPES_RISCV_HPP