1 /*
2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3  * Copyright (c) 2016 SAP SE. 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_S390_JNITYPES_S390_HPP
27 #define CPU_S390_JNITYPES_S390_HPP
28 
29 // This file holds platform-dependent routines used to write primitive
30 // jni types to the array of arguments passed into JavaCalls::call.
31 
32 #include "jni.h"
33 #include "memory/allocation.hpp"
34 #include "oops/oop.hpp"
35 
36 class JNITypes : AllStatic {
37   // These functions write a java primitive type (in native format) to
38   // a java stack slot array to be passed as an argument to
39   // JavaCalls:calls. I.e., they are functionally 'push' operations
40   // if they have a 'pos' formal parameter. Note that jlongs and
41   // jdoubles are written _in reverse_ of the order in which they
42   // appear in the interpreter stack. This is because call stubs (see
43   // stubGenerator_s390.cpp) reverse the argument list constructed by
44   // JavaCallArguments (see javaCalls.hpp).
45 
46  public:
47   // Ints are stored in native format in one JavaCallArgument slot at *to.
put_int(jint from,intptr_t * to)48   static inline void put_int(jint  from, intptr_t *to) {
49     *(jint*) to = from;
50   }
51 
put_int(jint from,intptr_t * to,int & pos)52   static inline void put_int(jint  from, intptr_t *to, int& pos) {
53     *(jint*) (to + pos++) = from;
54   }
55 
put_int(jint * from,intptr_t * to,int & pos)56   static inline void put_int(jint *from, intptr_t *to, int& pos) {
57     *(jint*) (to + pos++) = *from;
58   }
59 
60   // Longs are stored in native format in one JavaCallArgument slot at *(to+1).
put_long(jlong from,intptr_t * to)61   static inline void put_long(jlong  from, intptr_t *to) {
62     *(jlong*) (to + 1) = from;
63   }
64 
put_long(jlong from,intptr_t * to,int & pos)65   static inline void put_long(jlong  from, intptr_t *to, int& pos) {
66     *(jlong*) (to + 1 + pos) = from;
67     pos += 2;
68   }
69 
put_long(jlong * from,intptr_t * to,int & pos)70   static inline void put_long(jlong *from, intptr_t *to, int& pos) {
71     *(jlong*) (to + 1 + pos) = *from;
72     pos += 2;
73   }
74 
75   // Oops are stored in native format in one JavaCallArgument slot at *to.
put_obj(const Handle & from_handle,intptr_t * to,int & pos)76   static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) {
77     *(to + pos++) = (intptr_t)from_handle.raw_value();
78   }
79 
put_obj(jobject from_handle,intptr_t * to,int & pos)80   static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) {
81     *(to + pos++) =  (intptr_t)from_handle;
82   }
83 
84   // Floats are stored in native format in one JavaCallArgument slot at *to.
put_float(jfloat from,intptr_t * to)85   static inline void put_float(jfloat  from, intptr_t *to) {
86     *(jfloat*) to = from;
87   }
88 
put_float(jfloat from,intptr_t * to,int & pos)89   static inline void put_float(jfloat  from, intptr_t *to, int& pos) {
90     *(jfloat*) (to + pos++) = from;
91   }
92 
put_float(jfloat * from,intptr_t * to,int & pos)93   static inline void put_float(jfloat *from, intptr_t *to, int& pos) {
94     *(jfloat*) (to + pos++) = *from;
95   }
96 
97   // Doubles are stored in native word format in one JavaCallArgument
98   // slot at *(to+1).
put_double(jdouble from,intptr_t * to)99   static inline void put_double(jdouble  from, intptr_t *to) {
100     *(jdouble*) (to + 1) = from;
101   }
102 
put_double(jdouble from,intptr_t * to,int & pos)103   static inline void put_double(jdouble  from, intptr_t *to, int& pos) {
104     *(jdouble*) (to + 1 + pos) = from;
105     pos += 2;
106   }
107 
put_double(jdouble * from,intptr_t * to,int & pos)108   static inline void put_double(jdouble *from, intptr_t *to, int& pos) {
109     *(jdouble*) (to + 1 + pos) = *from;
110     pos += 2;
111   }
112 
113   // The get_xxx routines, on the other hand, actually _do_ fetch
114   // java primitive types from the interpreter stack.
115   // No need to worry about alignment on z/Architecture.
get_int(intptr_t * from)116   static inline jint get_int(intptr_t *from) {
117     return *(jint*) from;
118   }
119 
get_long(intptr_t * from)120   static inline jlong get_long(intptr_t *from) {
121     return *(jlong*) (from + 1);
122   }
123 
get_obj(intptr_t * from)124   static inline oop get_obj(intptr_t *from) {
125     return *(oop*) from;
126   }
127 
get_float(intptr_t * from)128   static inline jfloat get_float(intptr_t *from) {
129     return *(jfloat*) from;
130   }
131 
get_double(intptr_t * from)132   static inline jdouble get_double(intptr_t *from) {
133     return *(jdouble*) (from + 1);
134   }
135 };
136 
137 #endif // CPU_S390_JNITYPES_S390_HPP
138