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