Wed, 08 Apr 2009 10:56:49 -0700
6655638: dynamic languages need method handles
Summary: initial implementation, with known omissions (x86/64, sparc, compiler optim., c-oops, C++ interp.)
Reviewed-by: kvn, twisti, never
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1998-2002 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // This file holds platform-dependent routines used to write primitive jni |
duke@435 | 26 | // types to the array of arguments passed into JavaCalls::call |
duke@435 | 27 | |
duke@435 | 28 | class JNITypes : AllStatic { |
duke@435 | 29 | // These functions write a java primitive type (in native format) |
duke@435 | 30 | // to a java stack slot array to be passed as an argument to JavaCalls:calls. |
duke@435 | 31 | // I.e., they are functionally 'push' operations if they have a 'pos' |
duke@435 | 32 | // formal parameter. Note that jlong's and jdouble's are written |
duke@435 | 33 | // _in reverse_ of the order in which they appear in the interpreter |
duke@435 | 34 | // stack. This is because call stubs (see stubGenerator_sparc.cpp) |
duke@435 | 35 | // reverse the argument list constructed by JavaCallArguments (see |
duke@435 | 36 | // javaCalls.hpp). |
duke@435 | 37 | |
duke@435 | 38 | private: |
duke@435 | 39 | // Helper routines. |
duke@435 | 40 | static inline void put_int2 (jint *from, jint *to) { to[0] = from[0]; to[1] = from[1]; } |
duke@435 | 41 | static inline void put_int2 (jint *from, jint *to, int& pos) { put_int2 (from, (jint *)((intptr_t *)to + pos)); pos += 2; } |
duke@435 | 42 | static inline void put_int2r(jint *from, jint *to) { to[0] = from[1]; to[1] = from[0]; } |
duke@435 | 43 | static inline void put_int2r(jint *from, jint *to, int& pos) { put_int2r(from, (jint *)((intptr_t *)to + pos)); pos += 2; } |
duke@435 | 44 | |
duke@435 | 45 | public: |
duke@435 | 46 | // Ints are stored in native format in one JavaCallArgument slot at *to. |
duke@435 | 47 | static inline void put_int(jint from, intptr_t *to) { *(jint *)(to + 0 ) = from; } |
duke@435 | 48 | static inline void put_int(jint from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = from; } |
duke@435 | 49 | static inline void put_int(jint *from, intptr_t *to, int& pos) { *(jint *)(to + pos++) = *from; } |
duke@435 | 50 | |
duke@435 | 51 | #ifdef _LP64 |
duke@435 | 52 | // Longs are stored in native format in one JavaCallArgument slot at *(to+1). |
duke@435 | 53 | static inline void put_long(jlong from, intptr_t *to) { *(jlong *)(to + 1 + 0) = from; } |
duke@435 | 54 | static inline void put_long(jlong from, intptr_t *to, int& pos) { *(jlong *)(to + 1 + pos) = from; pos += 2; } |
duke@435 | 55 | static inline void put_long(jlong *from, intptr_t *to, int& pos) { *(jlong *)(to + 1 + pos) = *from; pos += 2; } |
duke@435 | 56 | #else |
duke@435 | 57 | // Longs are stored in reversed native word format in two JavaCallArgument slots at *to. |
duke@435 | 58 | // The high half is in *(to+1) and the low half in *to. |
duke@435 | 59 | static inline void put_long(jlong from, intptr_t *to) { put_int2r((jint *)&from, (jint *)to); } |
duke@435 | 60 | static inline void put_long(jlong from, intptr_t *to, int& pos) { put_int2r((jint *)&from, (jint *)to, pos); } |
duke@435 | 61 | static inline void put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, (jint *)to, pos); } |
duke@435 | 62 | #endif |
duke@435 | 63 | |
duke@435 | 64 | // Oops are stored in native format in one JavaCallArgument slot at *to. |
duke@435 | 65 | static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; } |
duke@435 | 66 | static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; } |
duke@435 | 67 | static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; } |
duke@435 | 68 | |
duke@435 | 69 | // Floats are stored in native format in one JavaCallArgument slot at *to. |
duke@435 | 70 | static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; } |
duke@435 | 71 | static inline void put_float(jfloat from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = from; } |
duke@435 | 72 | static inline void put_float(jfloat *from, intptr_t *to, int& pos) { *(jfloat *)(to + pos++) = *from; } |
duke@435 | 73 | |
duke@435 | 74 | #ifdef _LP64 |
duke@435 | 75 | // Doubles are stored in native word format in one JavaCallArgument slot at *(to+1). |
duke@435 | 76 | static inline void put_double(jdouble from, intptr_t *to) { *(jdouble *)(to + 1 + 0) = from; } |
duke@435 | 77 | static inline void put_double(jdouble from, intptr_t *to, int& pos) { *(jdouble *)(to + 1 + pos) = from; pos += 2; } |
duke@435 | 78 | static inline void put_double(jdouble *from, intptr_t *to, int& pos) { *(jdouble *)(to + 1 + pos) = *from; pos += 2; } |
duke@435 | 79 | #else |
duke@435 | 80 | // Doubles are stored in reversed native word format in two JavaCallArgument slots at *to. |
duke@435 | 81 | static inline void put_double(jdouble from, intptr_t *to) { put_int2r((jint *)&from, (jint *)to); } |
duke@435 | 82 | static inline void put_double(jdouble from, intptr_t *to, int& pos) { put_int2r((jint *)&from, (jint *)to, pos); } |
duke@435 | 83 | static inline void put_double(jdouble *from, intptr_t *to, int& pos) { put_int2r((jint *) from, (jint *)to, pos); } |
duke@435 | 84 | #endif |
duke@435 | 85 | |
duke@435 | 86 | // The get_xxx routines, on the other hand, actually _do_ fetch |
duke@435 | 87 | // java primitive types from the interpreter stack. |
duke@435 | 88 | static inline jint get_int(intptr_t *from) { return *(jint *)from; } |
duke@435 | 89 | |
duke@435 | 90 | #ifdef _LP64 |
duke@435 | 91 | static inline jlong get_long(intptr_t *from) { return *(jlong *)from; } |
duke@435 | 92 | #else |
duke@435 | 93 | static inline jlong get_long(intptr_t *from) { return ((jlong)(*( signed int *)((jint *)from )) << 32) | |
duke@435 | 94 | ((jlong)(*(unsigned int *)((jint *)from + 1)) << 0); } |
duke@435 | 95 | #endif |
duke@435 | 96 | |
duke@435 | 97 | static inline oop get_obj(intptr_t *from) { return *(oop *)from; } |
duke@435 | 98 | static inline jfloat get_float(intptr_t *from) { return *(jfloat *)from; } |
duke@435 | 99 | |
duke@435 | 100 | #ifdef _LP64 |
duke@435 | 101 | static inline jdouble get_double(intptr_t *from) { return *(jdouble *)from; } |
duke@435 | 102 | #else |
duke@435 | 103 | static inline jdouble get_double(intptr_t *from) { jlong jl = ((jlong)(*( signed int *)((jint *)from )) << 32) | |
duke@435 | 104 | ((jlong)(*(unsigned int *)((jint *)from + 1)) << 0); |
duke@435 | 105 | return *(jdouble *)&jl; } |
duke@435 | 106 | #endif |
duke@435 | 107 | |
duke@435 | 108 | }; |