1 /* 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "runtime/stackValueCollection.hpp" 27 #ifdef TARGET_ARCH_x86 28 # include "jniTypes_x86.hpp" 29 #endif 30 #ifdef TARGET_ARCH_aarch64 31 # include "jniTypes_aarch64.hpp" 32 #endif 33 #ifdef TARGET_ARCH_sparc 34 # include "jniTypes_sparc.hpp" 35 #endif 36 #ifdef TARGET_ARCH_zero 37 # include "jniTypes_zero.hpp" 38 #endif 39 #ifdef TARGET_ARCH_arm 40 # include "jniTypes_arm.hpp" 41 #endif 42 #ifdef TARGET_ARCH_ppc 43 # include "jniTypes_ppc.hpp" 44 #endif 45 46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 47 48 jint StackValueCollection::int_at(int slot) const { 49 intptr_t val = at(slot)->get_int(); 50 jint ival = *((jint*) (&val)); 51 return ival; 52 } 53 54 jlong StackValueCollection::long_at(int slot) const { 55 #ifdef _LP64 56 return at(slot+1)->get_int(); 57 #else 58 union { 59 jlong jl; 60 jint array[2]; 61 } value; 62 // Interpreter stack is reversed in memory: 63 // low memory location is in higher java local slot. 64 value.array[0] = at(slot+1)->get_int(); 65 value.array[1] = at(slot )->get_int(); 66 return value.jl; 67 #endif 68 } 69 70 Handle StackValueCollection::obj_at(int slot) const { 71 return at(slot)->get_obj(); 72 } 73 74 jfloat StackValueCollection::float_at(int slot) const { 75 intptr_t res = at(slot)->get_int(); 76 return *((jfloat*) (&res)); 77 } 78 79 jdouble StackValueCollection::double_at(int slot) const { 80 #ifdef _LP64 81 intptr_t res = at(slot+1)->get_int(); 82 return *((jdouble*) (&res)); 83 #else 84 union { 85 jdouble jd; 86 jint array[2]; 87 } value; 88 // Interpreter stack is reversed in memory: 89 // low memory location is in higher java local slot. 90 value.array[0] = at(slot+1)->get_int(); 91 value.array[1] = at(slot )->get_int(); 92 return value.jd; 93 #endif 94 } 95 96 void StackValueCollection::set_int_at(int slot, jint value) { 97 intptr_t val; 98 *((jint*) (&val)) = value; 99 at(slot)->set_int(val); 100 } 101 102 void StackValueCollection::set_long_at(int slot, jlong value) { 103 #ifdef _LP64 104 at(slot+1)->set_int(value); 105 #else 106 union { 107 jlong jl; 108 jint array[2]; 109 } x; 110 // Interpreter stack is reversed in memory: 111 // low memory location is in higher java local slot. 112 x.jl = value; 113 at(slot+1)->set_int(x.array[0]); 114 at(slot+0)->set_int(x.array[1]); 115 #endif 116 } 117 118 void StackValueCollection::set_obj_at(int slot, Handle value) { 119 at(slot)->set_obj(value); 120 } 121 122 void StackValueCollection::set_float_at(int slot, jfloat value) { 123 #ifdef _LP64 124 union { 125 intptr_t jd; 126 jint array[2]; 127 } val; 128 // Interpreter stores 32 bit floats in first half of 64 bit word. 129 val.array[0] = *(jint*)(&value); 130 val.array[1] = 0; 131 at(slot)->set_int(val.jd); 132 #else 133 at(slot)->set_int(*(jint*)(&value)); 134 #endif 135 } 136 137 void StackValueCollection::set_double_at(int slot, jdouble value) { 138 #ifdef _LP64 139 at(slot+1)->set_int(*(intptr_t*)(&value)); 140 #else 141 union { 142 jdouble jd; 143 jint array[2]; 144 } x; 145 // Interpreter stack is reversed in memory: 146 // low memory location is in higher java local slot. 147 x.jd = value; 148 at(slot+1)->set_int(x.array[0]); 149 at(slot+0)->set_int(x.array[1]); 150 #endif 151 } 152 153 #ifndef PRODUCT 154 void StackValueCollection::print() { 155 for(int index = 0; index < size(); index++) { 156 tty->print("\t %2d ", index); 157 at(index)->print_on(tty); 158 if( at(index )->type() == T_INT && 159 index+1 < size() && 160 at(index+1)->type() == T_INT ) { 161 tty->print(" " INT64_FORMAT " (long)", long_at(index)); 162 tty->cr(); 163 tty->print("\t %.15e (double)", double_at(index)); 164 tty->print(" " PTR64_FORMAT " (longhex)", long_at(index)); 165 } 166 tty->cr(); 167 } 168 } 169 #endif