1/*
2 * Copyright (c) 2016, 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_VM_JNITYPES_S390_HPP
27#define CPU_S390_VM_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 "memory/allocation.hpp"
33#include "oops/oop.hpp"
34#include "prims/jni.h"
35
36class 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.
48  static inline void put_int(jint  from, intptr_t *to) {
49    *(jint*) to = from;
50  }
51
52  static inline void put_int(jint  from, intptr_t *to, int& pos) {
53    *(jint*) (to + pos++) = from;
54  }
55
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).
61  static inline void put_long(jlong  from, intptr_t *to) {
62    *(jlong*) (to + 1) = from;
63  }
64
65  static inline void put_long(jlong  from, intptr_t *to, int& pos) {
66    *(jlong*) (to + 1 + pos) = from;
67    pos += 2;
68  }
69
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.
76  static inline void put_obj(oop  from, intptr_t *to) {
77    *(oop*) to = from;
78  }
79
80  static inline void put_obj(oop  from, intptr_t *to, int& pos) {
81    *(oop*) (to + pos++) = from;
82  }
83
84  static inline void put_obj(oop *from, intptr_t *to, int& pos) {
85    *(oop*) (to + pos++) = *from;
86  }
87
88  // Floats are stored in native format in one JavaCallArgument slot at *to.
89  static inline void put_float(jfloat  from, intptr_t *to) {
90    *(jfloat*) to = from;
91  }
92
93  static inline void put_float(jfloat  from, intptr_t *to, int& pos) {
94    *(jfloat*) (to + pos++) = from;
95  }
96
97  static inline void put_float(jfloat *from, intptr_t *to, int& pos) {
98    *(jfloat*) (to + pos++) = *from;
99  }
100
101  // Doubles are stored in native word format in one JavaCallArgument
102  // slot at *(to+1).
103  static inline void put_double(jdouble  from, intptr_t *to) {
104    *(jdouble*) (to + 1) = from;
105  }
106
107  static inline void put_double(jdouble  from, intptr_t *to, int& pos) {
108    *(jdouble*) (to + 1 + pos) = from;
109    pos += 2;
110  }
111
112  static inline void put_double(jdouble *from, intptr_t *to, int& pos) {
113    *(jdouble*) (to + 1 + pos) = *from;
114    pos += 2;
115  }
116
117  // The get_xxx routines, on the other hand, actually _do_ fetch
118  // java primitive types from the interpreter stack.
119  // No need to worry about alignment on z/Architecture.
120  static inline jint get_int(intptr_t *from) {
121    return *(jint*) from;
122  }
123
124  static inline jlong get_long(intptr_t *from) {
125    return *(jlong*) (from + 1);
126  }
127
128  static inline oop get_obj(intptr_t *from) {
129    return *(oop*) from;
130  }
131
132  static inline jfloat get_float(intptr_t *from) {
133    return *(jfloat*) from;
134  }
135
136  static inline jdouble get_double(intptr_t *from) {
137    return *(jdouble*) (from + 1);
138  }
139};
140
141#endif // CPU_S390_VM_JNITYPES_S390_HPP
142