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 28 jint StackValueCollection::int_at(int slot) const { 29 intptr_t val = at(slot)->get_int(); 30 jint ival = *((jint*) (&val)); 31 return ival; 32 } 33 34 jlong StackValueCollection::long_at(int slot) const { 35 #ifdef _LP64 36 return at(slot+1)->get_int(); 37 #else 38 union { 39 jlong jl; 40 jint array[2]; 41 } value; 42 // Interpreter stack is reversed in memory: 43 // low memory location is in higher java local slot. 44 value.array[0] = at(slot+1)->get_int(); 45 value.array[1] = at(slot )->get_int(); 46 return value.jl; 47 #endif 48 } 49 50 Handle StackValueCollection::obj_at(int slot) const { 51 return at(slot)->get_obj(); 52 } 53 54 jfloat StackValueCollection::float_at(int slot) const { 55 intptr_t res = at(slot)->get_int(); 56 return *((jfloat*) (&res)); 57 } 58 59 jdouble StackValueCollection::double_at(int slot) const { 60 #ifdef _LP64 61 intptr_t res = at(slot+1)->get_int(); 62 return *((jdouble*) (&res)); 63 #else 64 union { 65 jdouble jd; 66 jint array[2]; 67 } value; 68 // Interpreter stack is reversed in memory: 69 // low memory location is in higher java local slot. 70 value.array[0] = at(slot+1)->get_int(); 71 value.array[1] = at(slot )->get_int(); 72 return value.jd; 73 #endif 74 } 75 76 void StackValueCollection::set_int_at(int slot, jint value) { 77 intptr_t val; 78 *((jint*) (&val)) = value; 79 at(slot)->set_int(val); 80 } 81 82 void StackValueCollection::set_long_at(int slot, jlong value) { 83 #ifdef _LP64 84 at(slot+1)->set_int(value); 85 #else 86 union { 87 jlong jl; 88 jint array[2]; 89 } x; 90 // Interpreter stack is reversed in memory: 91 // low memory location is in higher java local slot. 92 x.jl = value; 93 at(slot+1)->set_int(x.array[0]); 94 at(slot+0)->set_int(x.array[1]); 95 #endif 96 } 97 98 void StackValueCollection::set_obj_at(int slot, Handle value) { 99 at(slot)->set_obj(value); 100 } 101 102 void StackValueCollection::set_float_at(int slot, jfloat value) { 103 #ifdef _LP64 104 union { 105 intptr_t jd; 106 jint array[2]; 107 } val; 108 // Interpreter stores 32 bit floats in first half of 64 bit word. 109 val.array[0] = *(jint*)(&value); 110 val.array[1] = 0; 111 at(slot)->set_int(val.jd); 112 #else 113 at(slot)->set_int(*(jint*)(&value)); 114 #endif 115 } 116 117 void StackValueCollection::set_double_at(int slot, jdouble value) { 118 #ifdef _LP64 119 at(slot+1)->set_int(*(intptr_t*)(&value)); 120 #else 121 union { 122 jdouble jd; 123 jint array[2]; 124 } x; 125 // Interpreter stack is reversed in memory: 126 // low memory location is in higher java local slot. 127 x.jd = value; 128 at(slot+1)->set_int(x.array[0]); 129 at(slot+0)->set_int(x.array[1]); 130 #endif 131 } 132 133 #ifndef PRODUCT 134 void StackValueCollection::print() { 135 for(int index = 0; index < size(); index++) { 136 tty->print("\t %2d ", index); 137 at(index)->print_on(tty); 138 if( at(index )->type() == T_INT && 139 index+1 < size() && 140 at(index+1)->type() == T_INT ) { 141 tty->print(" " INT64_FORMAT " (long)", (int64_t)long_at(index)); 142 tty->cr(); 143 tty->print("\t %.15e (double)", double_at(index)); 144 tty->print(" " PTR64_FORMAT " (longhex)", (int64_t)long_at(index)); 145 } 146 tty->cr(); 147 } 148 } 149 #endif