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