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