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 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 | // Inline interpreter functions for sparc |
duke@435 | 26 | |
duke@435 | 27 | inline jfloat BytecodeInterpreter::VMfloatAdd(jfloat op1, jfloat op2) { return op1 + op2; } |
duke@435 | 28 | inline jfloat BytecodeInterpreter::VMfloatSub(jfloat op1, jfloat op2) { return op1 - op2; } |
duke@435 | 29 | inline jfloat BytecodeInterpreter::VMfloatMul(jfloat op1, jfloat op2) { return op1 * op2; } |
duke@435 | 30 | inline jfloat BytecodeInterpreter::VMfloatDiv(jfloat op1, jfloat op2) { return op1 / op2; } |
duke@435 | 31 | inline jfloat BytecodeInterpreter::VMfloatRem(jfloat op1, jfloat op2) { return fmod(op1, op2); } |
duke@435 | 32 | |
duke@435 | 33 | inline jfloat BytecodeInterpreter::VMfloatNeg(jfloat op) { return -op; } |
duke@435 | 34 | |
duke@435 | 35 | inline int32_t BytecodeInterpreter::VMfloatCompare(jfloat op1, jfloat op2, int32_t direction) { |
duke@435 | 36 | return ( op1 < op2 ? -1 : |
duke@435 | 37 | op1 > op2 ? 1 : |
duke@435 | 38 | op1 == op2 ? 0 : |
duke@435 | 39 | (direction == -1 || direction == 1) ? direction : 0); |
duke@435 | 40 | |
duke@435 | 41 | } |
duke@435 | 42 | |
duke@435 | 43 | inline void BytecodeInterpreter::VMmemCopy64(uint32_t to[2], const uint32_t from[2]) { |
duke@435 | 44 | // x86 can do unaligned copies but not 64bits at a time |
duke@435 | 45 | to[0] = from[0]; to[1] = from[1]; |
duke@435 | 46 | } |
duke@435 | 47 | |
duke@435 | 48 | // The long operations depend on compiler support for "long long" on x86 |
duke@435 | 49 | |
duke@435 | 50 | inline jlong BytecodeInterpreter::VMlongAdd(jlong op1, jlong op2) { |
duke@435 | 51 | return op1 + op2; |
duke@435 | 52 | } |
duke@435 | 53 | |
duke@435 | 54 | inline jlong BytecodeInterpreter::VMlongAnd(jlong op1, jlong op2) { |
duke@435 | 55 | return op1 & op2; |
duke@435 | 56 | } |
duke@435 | 57 | |
duke@435 | 58 | inline jlong BytecodeInterpreter::VMlongDiv(jlong op1, jlong op2) { |
duke@435 | 59 | // QQQ what about check and throw... |
duke@435 | 60 | return op1 / op2; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | inline jlong BytecodeInterpreter::VMlongMul(jlong op1, jlong op2) { |
duke@435 | 64 | return op1 * op2; |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | inline jlong BytecodeInterpreter::VMlongOr(jlong op1, jlong op2) { |
duke@435 | 68 | return op1 | op2; |
duke@435 | 69 | } |
duke@435 | 70 | |
duke@435 | 71 | inline jlong BytecodeInterpreter::VMlongSub(jlong op1, jlong op2) { |
duke@435 | 72 | return op1 - op2; |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | inline jlong BytecodeInterpreter::VMlongXor(jlong op1, jlong op2) { |
duke@435 | 76 | return op1 ^ op2; |
duke@435 | 77 | } |
duke@435 | 78 | |
duke@435 | 79 | inline jlong BytecodeInterpreter::VMlongRem(jlong op1, jlong op2) { |
duke@435 | 80 | return op1 % op2; |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | inline jlong BytecodeInterpreter::VMlongUshr(jlong op1, jint op2) { |
duke@435 | 84 | // CVM did this 0x3f mask, is the really needed??? QQQ |
duke@435 | 85 | return ((unsigned long long) op1) >> (op2 & 0x3F); |
duke@435 | 86 | } |
duke@435 | 87 | |
duke@435 | 88 | inline jlong BytecodeInterpreter::VMlongShr(jlong op1, jint op2) { |
duke@435 | 89 | return op1 >> (op2 & 0x3F); |
duke@435 | 90 | } |
duke@435 | 91 | |
duke@435 | 92 | inline jlong BytecodeInterpreter::VMlongShl(jlong op1, jint op2) { |
duke@435 | 93 | return op1 << (op2 & 0x3F); |
duke@435 | 94 | } |
duke@435 | 95 | |
duke@435 | 96 | inline jlong BytecodeInterpreter::VMlongNeg(jlong op) { |
duke@435 | 97 | return -op; |
duke@435 | 98 | } |
duke@435 | 99 | |
duke@435 | 100 | inline jlong BytecodeInterpreter::VMlongNot(jlong op) { |
duke@435 | 101 | return ~op; |
duke@435 | 102 | } |
duke@435 | 103 | |
duke@435 | 104 | inline int32_t BytecodeInterpreter::VMlongLtz(jlong op) { |
duke@435 | 105 | return (op <= 0); |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | inline int32_t BytecodeInterpreter::VMlongGez(jlong op) { |
duke@435 | 109 | return (op >= 0); |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | inline int32_t BytecodeInterpreter::VMlongEqz(jlong op) { |
duke@435 | 113 | return (op == 0); |
duke@435 | 114 | } |
duke@435 | 115 | |
duke@435 | 116 | inline int32_t BytecodeInterpreter::VMlongEq(jlong op1, jlong op2) { |
duke@435 | 117 | return (op1 == op2); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | inline int32_t BytecodeInterpreter::VMlongNe(jlong op1, jlong op2) { |
duke@435 | 121 | return (op1 != op2); |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | inline int32_t BytecodeInterpreter::VMlongGe(jlong op1, jlong op2) { |
duke@435 | 125 | return (op1 >= op2); |
duke@435 | 126 | } |
duke@435 | 127 | |
duke@435 | 128 | inline int32_t BytecodeInterpreter::VMlongLe(jlong op1, jlong op2) { |
duke@435 | 129 | return (op1 <= op2); |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | inline int32_t BytecodeInterpreter::VMlongLt(jlong op1, jlong op2) { |
duke@435 | 133 | return (op1 < op2); |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | inline int32_t BytecodeInterpreter::VMlongGt(jlong op1, jlong op2) { |
duke@435 | 137 | return (op1 > op2); |
duke@435 | 138 | } |
duke@435 | 139 | |
duke@435 | 140 | inline int32_t BytecodeInterpreter::VMlongCompare(jlong op1, jlong op2) { |
duke@435 | 141 | return (VMlongLt(op1, op2) ? -1 : VMlongGt(op1, op2) ? 1 : 0); |
duke@435 | 142 | } |
duke@435 | 143 | |
duke@435 | 144 | // Long conversions |
duke@435 | 145 | |
duke@435 | 146 | inline jdouble BytecodeInterpreter::VMlong2Double(jlong val) { |
duke@435 | 147 | return (jdouble) val; |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | inline jfloat BytecodeInterpreter::VMlong2Float(jlong val) { |
duke@435 | 151 | return (jfloat) val; |
duke@435 | 152 | } |
duke@435 | 153 | |
duke@435 | 154 | inline jint BytecodeInterpreter::VMlong2Int(jlong val) { |
duke@435 | 155 | return (jint) val; |
duke@435 | 156 | } |
duke@435 | 157 | |
duke@435 | 158 | // Double Arithmetic |
duke@435 | 159 | |
duke@435 | 160 | inline jdouble BytecodeInterpreter::VMdoubleAdd(jdouble op1, jdouble op2) { |
duke@435 | 161 | return op1 + op2; |
duke@435 | 162 | } |
duke@435 | 163 | |
duke@435 | 164 | inline jdouble BytecodeInterpreter::VMdoubleDiv(jdouble op1, jdouble op2) { |
duke@435 | 165 | // Divide by zero... QQQ |
duke@435 | 166 | return op1 / op2; |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | inline jdouble BytecodeInterpreter::VMdoubleMul(jdouble op1, jdouble op2) { |
duke@435 | 170 | return op1 * op2; |
duke@435 | 171 | } |
duke@435 | 172 | |
duke@435 | 173 | inline jdouble BytecodeInterpreter::VMdoubleNeg(jdouble op) { |
duke@435 | 174 | return -op; |
duke@435 | 175 | } |
duke@435 | 176 | |
duke@435 | 177 | inline jdouble BytecodeInterpreter::VMdoubleRem(jdouble op1, jdouble op2) { |
duke@435 | 178 | return fmod(op1, op2); |
duke@435 | 179 | } |
duke@435 | 180 | |
duke@435 | 181 | inline jdouble BytecodeInterpreter::VMdoubleSub(jdouble op1, jdouble op2) { |
duke@435 | 182 | return op1 - op2; |
duke@435 | 183 | } |
duke@435 | 184 | |
duke@435 | 185 | inline int32_t BytecodeInterpreter::VMdoubleCompare(jdouble op1, jdouble op2, int32_t direction) { |
duke@435 | 186 | return ( op1 < op2 ? -1 : |
duke@435 | 187 | op1 > op2 ? 1 : |
duke@435 | 188 | op1 == op2 ? 0 : |
duke@435 | 189 | (direction == -1 || direction == 1) ? direction : 0); |
duke@435 | 190 | } |
duke@435 | 191 | |
duke@435 | 192 | // Double Conversions |
duke@435 | 193 | |
duke@435 | 194 | inline jfloat BytecodeInterpreter::VMdouble2Float(jdouble val) { |
duke@435 | 195 | return (jfloat) val; |
duke@435 | 196 | } |
duke@435 | 197 | |
duke@435 | 198 | // Float Conversions |
duke@435 | 199 | |
duke@435 | 200 | inline jdouble BytecodeInterpreter::VMfloat2Double(jfloat op) { |
duke@435 | 201 | return (jdouble) op; |
duke@435 | 202 | } |
duke@435 | 203 | |
duke@435 | 204 | // Integer Arithmetic |
duke@435 | 205 | |
duke@435 | 206 | inline jint BytecodeInterpreter::VMintAdd(jint op1, jint op2) { |
duke@435 | 207 | return op1 + op2; |
duke@435 | 208 | } |
duke@435 | 209 | |
duke@435 | 210 | inline jint BytecodeInterpreter::VMintAnd(jint op1, jint op2) { |
duke@435 | 211 | return op1 & op2; |
duke@435 | 212 | } |
duke@435 | 213 | |
duke@435 | 214 | inline jint BytecodeInterpreter::VMintDiv(jint op1, jint op2) { |
duke@435 | 215 | /* it's possible we could catch this special case implicitly */ |
duke@435 | 216 | if (op1 == 0x80000000 && op2 == -1) return op1; |
duke@435 | 217 | else return op1 / op2; |
duke@435 | 218 | } |
duke@435 | 219 | |
duke@435 | 220 | inline jint BytecodeInterpreter::VMintMul(jint op1, jint op2) { |
duke@435 | 221 | return op1 * op2; |
duke@435 | 222 | } |
duke@435 | 223 | |
duke@435 | 224 | inline jint BytecodeInterpreter::VMintNeg(jint op) { |
duke@435 | 225 | return -op; |
duke@435 | 226 | } |
duke@435 | 227 | |
duke@435 | 228 | inline jint BytecodeInterpreter::VMintOr(jint op1, jint op2) { |
duke@435 | 229 | return op1 | op2; |
duke@435 | 230 | } |
duke@435 | 231 | |
duke@435 | 232 | inline jint BytecodeInterpreter::VMintRem(jint op1, jint op2) { |
duke@435 | 233 | /* it's possible we could catch this special case implicitly */ |
duke@435 | 234 | if (op1 == 0x80000000 && op2 == -1) return 0; |
duke@435 | 235 | else return op1 % op2; |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | inline jint BytecodeInterpreter::VMintShl(jint op1, jint op2) { |
duke@435 | 239 | return op1 << op2; |
duke@435 | 240 | } |
duke@435 | 241 | |
duke@435 | 242 | inline jint BytecodeInterpreter::VMintShr(jint op1, jint op2) { |
duke@435 | 243 | return op1 >> op2; // QQ op2 & 0x1f?? |
duke@435 | 244 | } |
duke@435 | 245 | |
duke@435 | 246 | inline jint BytecodeInterpreter::VMintSub(jint op1, jint op2) { |
duke@435 | 247 | return op1 - op2; |
duke@435 | 248 | } |
duke@435 | 249 | |
duke@435 | 250 | inline jint BytecodeInterpreter::VMintUshr(jint op1, jint op2) { |
duke@435 | 251 | return ((juint) op1) >> op2; // QQ op2 & 0x1f?? |
duke@435 | 252 | } |
duke@435 | 253 | |
duke@435 | 254 | inline jint BytecodeInterpreter::VMintXor(jint op1, jint op2) { |
duke@435 | 255 | return op1 ^ op2; |
duke@435 | 256 | } |
duke@435 | 257 | |
duke@435 | 258 | inline jdouble BytecodeInterpreter::VMint2Double(jint val) { |
duke@435 | 259 | return (jdouble) val; |
duke@435 | 260 | } |
duke@435 | 261 | |
duke@435 | 262 | inline jfloat BytecodeInterpreter::VMint2Float(jint val) { |
duke@435 | 263 | return (jfloat) val; |
duke@435 | 264 | } |
duke@435 | 265 | |
duke@435 | 266 | inline jlong BytecodeInterpreter::VMint2Long(jint val) { |
duke@435 | 267 | return (jlong) val; |
duke@435 | 268 | } |
duke@435 | 269 | |
duke@435 | 270 | inline jchar BytecodeInterpreter::VMint2Char(jint val) { |
duke@435 | 271 | return (jchar) val; |
duke@435 | 272 | } |
duke@435 | 273 | |
duke@435 | 274 | inline jshort BytecodeInterpreter::VMint2Short(jint val) { |
duke@435 | 275 | return (jshort) val; |
duke@435 | 276 | } |
duke@435 | 277 | |
duke@435 | 278 | inline jbyte BytecodeInterpreter::VMint2Byte(jint val) { |
duke@435 | 279 | return (jbyte) val; |
duke@435 | 280 | } |
duke@435 | 281 | |
duke@435 | 282 | // The implementations are platform dependent. We have to worry about alignment |
duke@435 | 283 | // issues on some machines which can change on the same platform depending on |
duke@435 | 284 | // whether it is an LP64 machine also. |
duke@435 | 285 | |
duke@435 | 286 | // We know that on LP32 mode that longs/doubles are the only thing that gives |
duke@435 | 287 | // us alignment headaches. We also know that the worst we have is 32bit alignment |
duke@435 | 288 | // so thing are not really too bad. |
duke@435 | 289 | // (Also sparcworks compiler does the right thing for free if we don't use -arch.. |
duke@435 | 290 | // switches. Only gcc gives us a hard time. In LP64 mode I think we have no issue |
duke@435 | 291 | // with alignment. |
duke@435 | 292 | |
duke@435 | 293 | #ifdef _GNU_SOURCE |
duke@435 | 294 | #define ALIGN_CONVERTER /* Needs alignment converter */ |
duke@435 | 295 | #else |
duke@435 | 296 | #undef ALIGN_CONVERTER /* No alignment converter */ |
duke@435 | 297 | #endif /* _GNU_SOURCE */ |
duke@435 | 298 | |
duke@435 | 299 | #ifdef ALIGN_CONVERTER |
duke@435 | 300 | class u8_converter { |
duke@435 | 301 | |
duke@435 | 302 | private: |
duke@435 | 303 | |
duke@435 | 304 | public: |
duke@435 | 305 | static jdouble get_jdouble(address p) { |
duke@435 | 306 | VMJavaVal64 tmp; |
duke@435 | 307 | tmp.v[0] = ((uint32_t*)p)[0]; |
duke@435 | 308 | tmp.v[1] = ((uint32_t*)p)[1]; |
duke@435 | 309 | return tmp.d; |
duke@435 | 310 | } |
duke@435 | 311 | |
duke@435 | 312 | static void put_jdouble(address p, jdouble d) { |
duke@435 | 313 | VMJavaVal64 tmp; |
duke@435 | 314 | tmp.d = d; |
duke@435 | 315 | ((uint32_t*)p)[0] = tmp.v[0]; |
duke@435 | 316 | ((uint32_t*)p)[1] = tmp.v[1]; |
duke@435 | 317 | } |
duke@435 | 318 | |
duke@435 | 319 | static jlong get_jlong(address p) { |
duke@435 | 320 | VMJavaVal64 tmp; |
duke@435 | 321 | tmp.v[0] = ((uint32_t*)p)[0]; |
duke@435 | 322 | tmp.v[1] = ((uint32_t*)p)[1]; |
duke@435 | 323 | return tmp.l; |
duke@435 | 324 | } |
duke@435 | 325 | |
duke@435 | 326 | static void put_jlong(address p, jlong l) { |
duke@435 | 327 | VMJavaVal64 tmp; |
duke@435 | 328 | tmp.l = l; |
duke@435 | 329 | ((uint32_t*)p)[0] = tmp.v[0]; |
duke@435 | 330 | ((uint32_t*)p)[1] = tmp.v[1]; |
duke@435 | 331 | } |
duke@435 | 332 | }; |
duke@435 | 333 | #endif /* ALIGN_CONVERTER */ |