hotspot/src/cpu/x86/vm/jniTypes_x86.hpp
author kvn
Fri, 07 Nov 2008 09:29:38 -0800
changeset 1500 bea9a90f3e8f
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6462850: generate biased locking code in C2 ideal graph Summary: Inline biased locking code in C2 ideal graph during macro nodes expansion Reviewed-by: never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2003 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// This file holds platform-dependent routines used to write primitive jni
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// types to the array of arguments passed into JavaCalls::call
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class JNITypes : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  // These functions write a java primitive type (in native format)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // to a java stack slot array to be passed as an argument to JavaCalls:calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  // I.e., they are functionally 'push' operations if they have a 'pos'
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // formal parameter.  Note that jlong's and jdouble's are written
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // _in reverse_ of the order in which they appear in the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // stack.  This is because call stubs (see stubGenerator_sparc.cpp)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // reverse the argument list constructed by JavaCallArguments (see
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // javaCalls.hpp).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // 32bit Helper routines.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static inline void    put_int2r(jint *from, intptr_t *to)           { *(jint *)(to++) = from[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                                                                        *(jint *)(to  ) = from[0]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static inline void    put_int2r(jint *from, intptr_t *to, int& pos) { put_int2r(from, to + pos); pos += 2; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Ints are stored in native format in one JavaCallArgument slot at *to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  static inline void    put_int(jint  from, intptr_t *to)           { *(jint *)(to +   0  ) =  from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  static inline void    put_int(jint  from, intptr_t *to, int& pos) { *(jint *)(to + pos++) =  from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  static inline void    put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // Longs are stored in native format in one JavaCallArgument slot at
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // *(to+1).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static inline void put_long(jlong  from, intptr_t *to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    *(jlong*) (to + 1) = from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static inline void put_long(jlong  from, intptr_t *to, int& pos) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    *(jlong*) (to + 1 + pos) = from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    pos += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  static inline void put_long(jlong *from, intptr_t *to, int& pos) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    *(jlong*) (to + 1 + pos) = *from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    pos += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Longs are stored in big-endian word format in two JavaCallArgument slots at *to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // The high half is in *to and the low half in *(to+1).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static inline void    put_long(jlong  from, intptr_t *to)           { put_int2r((jint *)&from, to); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static inline void    put_long(jlong  from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static inline void    put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Oops are stored in native format in one JavaCallArgument slot at *to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  static inline void    put_obj(oop  from, intptr_t *to)           { *(oop *)(to +   0  ) =  from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static inline void    put_obj(oop  from, intptr_t *to, int& pos) { *(oop *)(to + pos++) =  from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  static inline void    put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Floats are stored in native format in one JavaCallArgument slot at *to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static inline void    put_float(jfloat  from, intptr_t *to)           { *(jfloat *)(to +   0  ) =  from;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  static inline void    put_float(jfloat  from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) =  from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  static inline void    put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
#undef _JNI_SLOT_OFFSET
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
#define _JNI_SLOT_OFFSET 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Doubles are stored in native word format in one JavaCallArgument
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // slot at *(to+1).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  static inline void put_double(jdouble  from, intptr_t *to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    *(jdouble*) (to + 1) = from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  static inline void put_double(jdouble  from, intptr_t *to, int& pos) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    *(jdouble*) (to + 1 + pos) = from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    pos += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  static inline void put_double(jdouble *from, intptr_t *to, int& pos) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    *(jdouble*) (to + 1 + pos) = *from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    pos += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
#define _JNI_SLOT_OFFSET 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // Doubles are stored in big-endian word format in two JavaCallArgument slots at *to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // The high half is in *to and the low half in *(to+1).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static inline void    put_double(jdouble  from, intptr_t *to)           { put_int2r((jint *)&from, to); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  static inline void    put_double(jdouble  from, intptr_t *to, int& pos) { put_int2r((jint *)&from, to, pos); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  static inline void    put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // The get_xxx routines, on the other hand, actually _do_ fetch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // java primitive types from the interpreter stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // No need to worry about alignment on Intel.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  static inline jint    get_int   (intptr_t *from) { return *(jint *)   from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static inline jlong   get_long  (intptr_t *from) { return *(jlong *)  (from + _JNI_SLOT_OFFSET); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  static inline oop     get_obj   (intptr_t *from) { return *(oop *)    from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  static inline jfloat  get_float (intptr_t *from) { return *(jfloat *) from; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  static inline jdouble get_double(intptr_t *from) { return *(jdouble *)(from + _JNI_SLOT_OFFSET); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
#undef _JNI_SLOT_OFFSET
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
};