1 /*
   2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2013 SAP AG. 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_PPC_VM_JNITYPES_PPC_HPP
  27 #define CPU_PPC_VM_JNITYPES_PPC_HPP
  28 
  29 #include "memory/allocation.hpp"
  30 #include "oops/oop.hpp"
  31 #include "prims/jni.h"
  32 
  33 // This file holds platform-dependent routines used to write primitive
  34 // jni types to the array of arguments passed into JavaCalls::call.
  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 jlong's and
  41   // jdouble's are written _in reverse_ of the order in which they
  42   // appear in the interpreter stack.  This is because call stubs (see
  43   // stubGenerator_sparc.cpp) reverse the argument list constructed by
  44   // JavaCallArguments (see javaCalls.hpp).
  45 
  46  private:
  47 
  48 #ifndef PPC64
  49 #error "ppc32 support currently not implemented!!!"
  50 #endif // PPC64
  51 
  52  public:
  53   // Ints are stored in native format in one JavaCallArgument slot at *to.
  54   static inline void put_int(jint  from, intptr_t *to)           { *(jint *)(to +   0  ) =  from; }
  55   static inline void put_int(jint  from, intptr_t *to, int& pos) { *(jint *)(to + pos++) =  from; }
  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
  59   // *(to+1).
  60   static inline void put_long(jlong  from, intptr_t *to) {
  61     *(jlong*) (to + 1) = from;
  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 
  69   static inline void put_long(jlong *from, intptr_t *to, int& pos) {
  70     *(jlong*) (to + 1 + pos) = *from;
  71     pos += 2;
  72   }
  73 
  74   // Oops are stored in native format in one JavaCallArgument slot at *to.
  75   static inline void put_obj(oop  from, intptr_t *to)           { *(oop *)(to +   0  ) =  from; }
  76   static inline void put_obj(oop  from, intptr_t *to, int& pos) { *(oop *)(to + pos++) =  from; }
  77   static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
  78 
  79   // Floats are stored in native format in one JavaCallArgument slot at *to.
  80   static inline void put_float(jfloat  from, intptr_t *to)           { *(jfloat *)(to +   0  ) =  from;  }
  81   static inline void put_float(jfloat  from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) =  from; }
  82   static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; }
  83 
  84   // Doubles are stored in native word format in one JavaCallArgument
  85   // slot at *(to+1).
  86   static inline void put_double(jdouble  from, intptr_t *to) {
  87     *(jdouble*) (to + 1) = from;
  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   static inline void put_double(jdouble *from, intptr_t *to, int& pos) {
  96     *(jdouble*) (to + 1 + pos) = *from;
  97     pos += 2;
  98   }
  99 
 100   // The get_xxx routines, on the other hand, actually _do_ fetch
 101   // java primitive types from the interpreter stack.
 102   // No need to worry about alignment on Intel.
 103   static inline jint    get_int   (intptr_t *from) { return *(jint *)    from; }
 104   static inline jlong   get_long  (intptr_t *from) { return *(jlong *)  (from + 1); }
 105   static inline oop     get_obj   (intptr_t *from) { return *(oop *)     from; }
 106   static inline jfloat  get_float (intptr_t *from) { return *(jfloat *)  from; }
 107   static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + 1); }
 108 };
 109 
 110 #endif // CPU_PPC_VM_JNITYPES_PPC_HPP