src/cpu/mips/vm/jniTypes_mips.hpp

Tue, 26 Jul 2016 17:06:17 +0800

author
fujie
date
Tue, 26 Jul 2016 17:06:17 +0800
changeset 41
d885f8d65c58
parent 1
2d8a650513c2
child 6880
52ea28d233d2
permissions
-rw-r--r--

Add multiply word to GPR instruction (mul) in MIPS assembler.

     1 /*
     2  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2016, Loongson Technology. 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  */
    26 #ifndef CPU_MIPS_VM_JNITYPES_MIPS_HPP
    27 #define CPU_MIPS_VM_JNITYPES_MIPS_HPP
    29 #include "memory/allocation.hpp"
    30 #include "oops/oop.hpp"
    31 #include "prims/jni.h"
    33 // This file holds platform-dependent routines used to write primitive jni
    34 // types to the array of arguments passed into JavaCalls::call
    36 class JNITypes : AllStatic {
    37   // These functions write a java primitive type (in native format)
    38   // to a java stack slot array to be passed as an argument to JavaCalls:calls.
    39   // I.e., they are functionally 'push' operations if they have a 'pos'
    40   // formal parameter.  Note that jlong's and jdouble's are written
    41   // _in reverse_ of the order in which they appear in the interpreter
    42   // stack.  This is because call stubs (see stubGenerator_sparc.cpp)
    43   // reverse the argument list constructed by JavaCallArguments (see
    44   // javaCalls.hpp).
    46 private:
    48 #ifndef AMD64
    49   // 32bit Helper routines.
    50   static inline void    put_int2r(jint *from, intptr_t *to)           { *(jint *)(to++) = from[1];
    51                                                                         *(jint *)(to  ) = from[0];
    52 									 }
    53   static inline void    put_int2r(jint *from, intptr_t *to, int& pos) { put_int2r(from, to + pos); pos += 2; }
    54 #endif // AMD64
    56 public:
    57 #ifdef _LP64
    58   // Jin: In MIPS64, the sizeof intptr_t is 8 bytes, and each unit in JavaCallArguments::_value_buffer[]
    59   //   is 8 bytes.
    60   // If we only write the low 4 bytes with (jint *), the high 4-bits will be left with uncertain values.
    61   // Then, in JavaCallArguments::parameters(), the whole 8 bytes of a T_INT parameter is loaded.
    62   // This error occurs in ReflectInvoke.java
    63   // The parameter of DD(int) should be 4 instead of 0x550000004.
    64   //
    65   // See: [runtime/javaCalls.hpp]
    67   static inline void    put_int(jint  from, intptr_t *to)           { *(intptr_t *)(to +   0  ) =  from; }
    68   static inline void    put_int(jint  from, intptr_t *to, int& pos) { *(intptr_t *)(to + pos++) =  from; }
    69   static inline void    put_int(jint *from, intptr_t *to, int& pos) { *(intptr_t *)(to + pos++) = *from; }
    70 #else
    71   // Ints are stored in native format in one JavaCallArgument slot at *to.
    72   static inline void    put_int(jint  from, intptr_t *to)           { *(jint *)(to +   0  ) =  from; }
    73   static inline void    put_int(jint  from, intptr_t *to, int& pos) { *(jint *)(to + pos++) =  from; }
    74   static inline void    put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; }
    75 #endif
    77 #ifdef _LP64
    78   // Longs are stored in native format in one JavaCallArgument slot at
    79   // *(to).
    80   // In theory, *(to + 1) is an empty slot. But, for several Java2D testing programs (TestBorderLayout, SwingTest),
    81   //  *(to + 1) must contains a copy of the long value. Otherwise it will corrupts.
    82   static inline void put_long(jlong  from, intptr_t *to) {
    83     *(jlong*) (to + 1) = from;
    84     *(jlong*) (to) = from;
    85   }
    87   /* Jin: A long parameter occupies two slot.
    88    *   It must fit the layout rule in methodHandle.
    89    *
    90    *   See: [runtime/reflection.cpp] Reflection::invoke()
    91    *    assert(java_args.size_of_parameters() == method->size_of_parameters(), "just checking");
    92    */
    93   static inline void put_long(jlong  from, intptr_t *to, int& pos) {
    94     *(jlong*) (to + 1 + pos) = from;
    95     *(jlong*) (to + pos) = from;
    96     pos += 2;
    97   }
    99   static inline void put_long(jlong *from, intptr_t *to, int& pos) {
   100     *(jlong*) (to + 1 + pos) = *from;
   101     *(jlong*) (to + pos) = *from;
   102     pos += 2;
   103   }
   104 #else
   105   // Longs are stored in big-endian word format in two JavaCallArgument slots at *to.
   106   // The high half is in *to and the low half in *(to+1).
   107   static inline void    put_long(jlong  from, intptr_t *to)           { put_int2r((jint *)&from, to); }
   108   static inline void    put_long(jlong  from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); }
   109   static inline void    put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }
   110 #endif // AMD64
   112   // Oops are stored in native format in one JavaCallArgument slot at *to.
   113   static inline void    put_obj(oop  from, intptr_t *to)           { *(oop *)(to +   0  ) =  from; }
   114   static inline void    put_obj(oop  from, intptr_t *to, int& pos) { *(oop *)(to + pos++) =  from; }
   115   static inline void    put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
   117   // Floats are stored in native format in one JavaCallArgument slot at *to.
   118   static inline void    put_float(jfloat  from, intptr_t *to)           { *(jfloat *)(to +   0  ) =  from;  }
   119   static inline void    put_float(jfloat  from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) =  from; }
   120   static inline void    put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; }
   122 #undef _JNI_SLOT_OFFSET
   123 #define _JNI_SLOT_OFFSET 0
   125 #ifdef _LP64
   126   // Longs are stored in native format in one JavaCallArgument slot at
   127   // *(to).
   128   // In theory, *(to + 1) is an empty slot. But, for several Java2D testing programs (TestBorderLayout, SwingTest),
   129   //  *(to + 1) must contains a copy of the long value. Otherwise it will corrupts.
   130   static inline void put_double(jdouble  from, intptr_t *to) {
   131     *(jdouble*) (to + 1) = from;
   132     *(jdouble*) (to) = from;
   133   }
   135   /* Jin: A long parameter occupies two slot.
   136    *   It must fit the layout rule in methodHandle.
   137    *
   138    *   See: [runtime/reflection.cpp] Reflection::invoke()
   139    *    assert(java_args.size_of_parameters() == method->size_of_parameters(), "just checking");
   140    */
   141   static inline void put_double(jdouble  from, intptr_t *to, int& pos) {
   142     *(jdouble*) (to + 1 + pos) = from;
   143     *(jdouble*) (to + pos) = from;
   144     pos += 2;
   145   }
   147   static inline void put_double(jdouble *from, intptr_t *to, int& pos) {
   148     *(jdouble*) (to + 1 + pos) = *from;
   149     *(jdouble*) (to + pos) = *from;
   150     pos += 2;
   151   }
   152 #else
   153   // Doubles are stored in big-endian word format in two JavaCallArgument slots at *to.
   154   // The high half is in *to and the low half in *(to+1).
   155   static inline void    put_double(jdouble  from, intptr_t *to)           { put_int2r((jint *)&from, to); }
   156   static inline void    put_double(jdouble  from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); }
   157   static inline void    put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }
   158 #endif
   161   // The get_xxx routines, on the other hand, actually _do_ fetch
   162   // java primitive types from the interpreter stack.
   163   // No need to worry about alignment on Intel.
   164   static inline jint    get_int   (intptr_t *from) { return *(jint *)   from; }
   165   static inline jlong   get_long  (intptr_t *from) { return *(jlong *)  (from + _JNI_SLOT_OFFSET); }
   166   static inline oop     get_obj   (intptr_t *from) { return *(oop *)    from; }
   167   static inline jfloat  get_float (intptr_t *from) { return *(jfloat *) from; }
   168   static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); }
   169 #undef _JNI_SLOT_OFFSET
   170 };
   172 #endif // CPU_MIPS_VM_JNITYPES_MIPS_HPP

mercurial