stackValue.cpp revision 1472
5346N/A/*
5346N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
5346N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5346N/A *
5346N/A * This code is free software; you can redistribute it and/or modify it
5346N/A * under the terms of the GNU General Public License version 2 only, as
5346N/A * published by the Free Software Foundation.
5346N/A *
5346N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5346N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5346N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5346N/A * version 2 for more details (a copy is included in the LICENSE file that
5346N/A * accompanied this code).
5346N/A *
5346N/A * You should have received a copy of the GNU General Public License version
5346N/A * 2 along with this work; if not, write to the Free Software Foundation,
5346N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5346N/A *
5346N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5346N/A * or visit www.oracle.com if you need additional information or have any
5346N/A * questions.
5346N/A *
5346N/A */
5346N/A
5346N/A# include "incls/_precompiled.incl"
5346N/A# include "incls/_stackValue.cpp.incl"
5346N/A
5346N/AStackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv) {
5346N/A if (sv->is_location()) {
5346N/A // Stack or register value
5346N/A Location loc = ((LocationValue *)sv)->location();
5346N/A
5346N/A#ifdef SPARC
5346N/A // %%%%% Callee-save floats will NOT be working on a Sparc until we
5346N/A // handle the case of a 2 floats in a single double register.
5346N/A assert( !(loc.is_register() && loc.type() == Location::float_in_dbl), "Sparc does not handle callee-save floats yet" );
5346N/A#endif // SPARC
5346N/A
5346N/A // First find address of value
5346N/A
5346N/A address value_addr = loc.is_register()
5346N/A // Value was in a callee-save register
5346N/A ? reg_map->location(VMRegImpl::as_VMReg(loc.register_number()))
5346N/A // Else value was directly saved on the stack. The frame's original stack pointer,
5346N/A // before any extension by its callee (due to Compiler1 linkage on SPARC), must be used.
5346N/A : ((address)fr->unextended_sp()) + loc.stack_offset();
5346N/A
5346N/A // Then package it right depending on type
5346N/A // Note: the transfer of the data is thru a union that contains
5346N/A // an intptr_t. This is because an interpreter stack slot is
5346N/A // really an intptr_t. The use of a union containing an intptr_t
5346N/A // ensures that on a 64 bit platform we have proper alignment
5346N/A // and that we store the value where the interpreter will expect
5346N/A // to find it (i.e. proper endian). Similarly on a 32bit platform
5346N/A // using the intptr_t ensures that when a value is larger than
5346N/A // a stack slot (jlong/jdouble) that we capture the proper part
5346N/A // of the value for the stack slot in question.
5346N/A //
5346N/A switch( loc.type() ) {
5346N/A case Location::float_in_dbl: { // Holds a float in a double register?
5346N/A // The callee has no clue whether the register holds a float,
5346N/A // double or is unused. He always saves a double. Here we know
5346N/A // a double was saved, but we only want a float back. Narrow the
5346N/A // saved double to the float that the JVM wants.
5346N/A assert( loc.is_register(), "floats always saved to stack in 1 word" );
5346N/A union { intptr_t p; jfloat jf; } value;
5346N/A value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
5346N/A value.jf = (jfloat) *(jdouble*) value_addr;
5346N/A return new StackValue(value.p); // 64-bit high half is stack junk
5346N/A }
5346N/A case Location::int_in_long: { // Holds an int in a long register?
5346N/A // The callee has no clue whether the register holds an int,
5346N/A // long or is unused. He always saves a long. Here we know
5346N/A // a long was saved, but we only want an int back. Narrow the
5346N/A // saved long to the int that the JVM wants.
5346N/A assert( loc.is_register(), "ints always saved to stack in 1 word" );
5346N/A union { intptr_t p; jint ji;} value;
5346N/A value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
5346N/A value.ji = (jint) *(jlong*) value_addr;
5346N/A return new StackValue(value.p); // 64-bit high half is stack junk
5346N/A }
5346N/A#ifdef _LP64
5346N/A case Location::dbl:
5346N/A // Double value in an aligned adjacent pair
5346N/A return new StackValue(*(intptr_t*)value_addr);
5346N/A case Location::lng:
5346N/A // Long value in an aligned adjacent pair
5346N/A return new StackValue(*(intptr_t*)value_addr);
5346N/A case Location::narrowoop: {
5346N/A union { intptr_t p; narrowOop noop;} value;
5346N/A value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
5346N/A if (loc.is_register()) {
5346N/A // The callee has no clue whether the register holds an int,
5346N/A // long or is unused. He always saves a long. Here we know
5346N/A // a long was saved, but we only want an int back. Narrow the
5346N/A // saved long to the int that the JVM wants.
5346N/A value.noop = (narrowOop) *(julong*) value_addr;
5346N/A } else {
5346N/A value.noop = *(narrowOop*) value_addr;
5346N/A }
5346N/A // Decode narrowoop and wrap a handle around the oop
Handle h(oopDesc::decode_heap_oop(value.noop));
return new StackValue(h);
}
#endif
case Location::oop: {
oop val = *(oop *)value_addr;
#ifdef _LP64
if (Universe::is_narrow_oop_base(val)) {
// Compiled code may produce decoded oop = narrow_oop_base
// when a narrow oop implicit null check is used.
// The narrow_oop_base could be NULL or be the address
// of the page below heap. Use NULL value for both cases.
val = (oop)NULL;
}
#endif
Handle h(val); // Wrap a handle around the oop
return new StackValue(h);
}
case Location::addr: {
ShouldNotReachHere(); // both C1 and C2 now inline jsrs
}
case Location::normal: {
// Just copy all other bits straight through
union { intptr_t p; jint ji;} value;
value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
value.ji = *(jint*)value_addr;
return new StackValue(value.p);
}
case Location::invalid:
return new StackValue();
default:
ShouldNotReachHere();
}
} else if (sv->is_constant_int()) {
// Constant int: treat same as register int.
union { intptr_t p; jint ji;} value;
value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
value.ji = (jint)((ConstantIntValue*)sv)->value();
return new StackValue(value.p);
} else if (sv->is_constant_oop()) {
// constant oop
return new StackValue(((ConstantOopReadValue *)sv)->value());
#ifdef _LP64
} else if (sv->is_constant_double()) {
// Constant double in a single stack slot
union { intptr_t p; double d; } value;
value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
value.d = ((ConstantDoubleValue *)sv)->value();
return new StackValue(value.p);
} else if (sv->is_constant_long()) {
// Constant long in a single stack slot
union { intptr_t p; jlong jl; } value;
value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
value.jl = ((ConstantLongValue *)sv)->value();
return new StackValue(value.p);
#endif
} else if (sv->is_object()) { // Scalar replaced object in compiled frame
Handle ov = ((ObjectValue *)sv)->value();
return new StackValue(ov, (ov.is_null()) ? 1 : 0);
}
// Unknown ScopeValue type
ShouldNotReachHere();
return new StackValue((intptr_t) 0); // dummy
}
BasicLock* StackValue::resolve_monitor_lock(const frame* fr, Location location) {
assert(location.is_stack(), "for now we only look at the stack");
int word_offset = location.stack_offset() / wordSize;
// (stack picture)
// high: [ ] word_offset + 1
// low [ ] word_offset
//
// sp-> [ ] 0
// the word_offset is the distance from the stack pointer to the lowest address
// The frame's original stack pointer, before any extension by its callee
// (due to Compiler1 linkage on SPARC), must be used.
return (BasicLock*) (fr->unextended_sp() + word_offset);
}
#ifndef PRODUCT
void StackValue::print_on(outputStream* st) const {
switch(_type) {
case T_INT:
st->print("%d (int) %f (float) %x (hex)", *(int *)&_i, *(float *)&_i, *(int *)&_i);
break;
case T_OBJECT:
_o()->print_value_on(st);
st->print(" <" INTPTR_FORMAT ">", (address)_o());
break;
case T_CONFLICT:
st->print("conflict");
break;
default:
ShouldNotReachHere();
}
}
#endif