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