stackValueCollection.cpp revision 1472:c18cbe5936b8
113546Sjulian/* 213546Sjulian * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved. 313546Sjulian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 413546Sjulian * 513546Sjulian * This code is free software; you can redistribute it and/or modify it 613546Sjulian * under the terms of the GNU General Public License version 2 only, as 713546Sjulian * published by the Free Software Foundation. 813546Sjulian * 913546Sjulian * This code is distributed in the hope that it will be useful, but WITHOUT 1013546Sjulian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1113546Sjulian * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1213546Sjulian * version 2 for more details (a copy is included in the LICENSE file that 13165967Simp * accompanied this code). 1413546Sjulian * 1513546Sjulian * You should have received a copy of the GNU General Public License version 1613546Sjulian * 2 along with this work; if not, write to the Free Software Foundation, 1713546Sjulian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1813546Sjulian * 1913546Sjulian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2049439Sdeischen * or visit www.oracle.com if you need additional information or have any 2113546Sjulian * questions. 2213546Sjulian * 2313546Sjulian */ 2413546Sjulian 2513546Sjulian# include "incls/_precompiled.incl" 2613546Sjulian# include "incls/_stackValueCollection.cpp.incl" 2713546Sjulian 2813546Sjulianjint StackValueCollection::int_at(int slot) const { 2950476Speter intptr_t val = at(slot)->get_int(); 3013546Sjulian jint ival = *((jint*) (&val)); 31174112Sdeischen return ival; 32174112Sdeischen} 3313546Sjulian 34174112Sdeischenjlong StackValueCollection::long_at(int slot) const { 35103388Smini#ifdef _LP64 3613546Sjulian return at(slot+1)->get_int(); 3775369Sdeischen#else 3871581Sdeischen union { 3913546Sjulian jlong jl; 4071581Sdeischen jint array[2]; 4113546Sjulian } value; 4213546Sjulian // Interpreter stack is reversed in memory: 4313546Sjulian // low memory location is in higher java local slot. 4413546Sjulian value.array[0] = at(slot+1)->get_int(); 45 value.array[1] = at(slot )->get_int(); 46 return value.jl; 47#endif 48} 49 50Handle StackValueCollection::obj_at(int slot) const { 51 return at(slot)->get_obj(); 52} 53 54jfloat StackValueCollection::float_at(int slot) const { 55 intptr_t res = at(slot)->get_int(); 56 return *((jfloat*) (&res)); 57} 58 59jdouble 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 76void StackValueCollection::set_int_at(int slot, jint value) { 77 intptr_t val; 78 *((jint*) (&val)) = value; 79 at(slot)->set_int(val); 80} 81 82void 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 98void StackValueCollection::set_obj_at(int slot, Handle value) { 99 at(slot)->set_obj(value); 100} 101 102void 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 117void 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 134void 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)", long_at(index)); 142 tty->cr(); 143 tty->print("\t %.15e (double)", double_at(index)); 144 tty->print(" " PTR64_FORMAT " (longhex)", long_at(index)); 145 } 146 tty->cr(); 147 } 148} 149#endif 150