src/share/vm/runtime/stackValue.cpp

Tue, 04 Mar 2008 09:44:24 -0500

author
sbohne
date
Tue, 04 Mar 2008 09:44:24 -0500
changeset 493
7ee622712fcf
parent 435
a61af66fc99e
child 766
cecd8eb4e0ca
permissions
-rw-r--r--

6666698: EnableBiasedLocking with BiasedLockingStartupDelay can block Watcher thread
Summary: Enqueue VM_EnableBiasedLocking operation asynchronously
Reviewed-by: never, xlu, kbr, acorn

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_stackValue.cpp.incl"
duke@435 27
duke@435 28 StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv) {
duke@435 29 if (sv->is_location()) {
duke@435 30 // Stack or register value
duke@435 31 Location loc = ((LocationValue *)sv)->location();
duke@435 32
duke@435 33 #ifdef SPARC
duke@435 34 // %%%%% Callee-save floats will NOT be working on a Sparc until we
duke@435 35 // handle the case of a 2 floats in a single double register.
duke@435 36 assert( !(loc.is_register() && loc.type() == Location::float_in_dbl), "Sparc does not handle callee-save floats yet" );
duke@435 37 #endif // SPARC
duke@435 38
duke@435 39 // First find address of value
duke@435 40
duke@435 41 address value_addr = loc.is_register()
duke@435 42 // Value was in a callee-save register
duke@435 43 ? reg_map->location(VMRegImpl::as_VMReg(loc.register_number()))
duke@435 44 // Else value was directly saved on the stack. The frame's original stack pointer,
duke@435 45 // before any extension by its callee (due to Compiler1 linkage on SPARC), must be used.
duke@435 46 : ((address)fr->unextended_sp()) + loc.stack_offset();
duke@435 47
duke@435 48 // Then package it right depending on type
duke@435 49 // Note: the transfer of the data is thru a union that contains
duke@435 50 // an intptr_t. This is because an interpreter stack slot is
duke@435 51 // really an intptr_t. The use of a union containing an intptr_t
duke@435 52 // ensures that on a 64 bit platform we have proper alignment
duke@435 53 // and that we store the value where the interpreter will expect
duke@435 54 // to find it (i.e. proper endian). Similarly on a 32bit platform
duke@435 55 // using the intptr_t ensures that when a value is larger than
duke@435 56 // a stack slot (jlong/jdouble) that we capture the proper part
duke@435 57 // of the value for the stack slot in question.
duke@435 58 //
duke@435 59 switch( loc.type() ) {
duke@435 60 case Location::float_in_dbl: { // Holds a float in a double register?
duke@435 61 // The callee has no clue whether the register holds a float,
duke@435 62 // double or is unused. He always saves a double. Here we know
duke@435 63 // a double was saved, but we only want a float back. Narrow the
duke@435 64 // saved double to the float that the JVM wants.
duke@435 65 assert( loc.is_register(), "floats always saved to stack in 1 word" );
duke@435 66 union { intptr_t p; jfloat jf; } value;
duke@435 67 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
duke@435 68 value.jf = (jfloat) *(jdouble*) value_addr;
duke@435 69 return new StackValue(value.p); // 64-bit high half is stack junk
duke@435 70 }
duke@435 71 case Location::int_in_long: { // Holds an int in a long register?
duke@435 72 // The callee has no clue whether the register holds an int,
duke@435 73 // long or is unused. He always saves a long. Here we know
duke@435 74 // a long was saved, but we only want an int back. Narrow the
duke@435 75 // saved long to the int that the JVM wants.
duke@435 76 assert( loc.is_register(), "ints always saved to stack in 1 word" );
duke@435 77 union { intptr_t p; jint ji;} value;
duke@435 78 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
duke@435 79 value.ji = (jint) *(jlong*) value_addr;
duke@435 80 return new StackValue(value.p); // 64-bit high half is stack junk
duke@435 81 }
duke@435 82 #ifdef _LP64
duke@435 83 case Location::dbl:
duke@435 84 // Double value in an aligned adjacent pair
duke@435 85 return new StackValue(*(intptr_t*)value_addr);
duke@435 86 case Location::lng:
duke@435 87 // Long value in an aligned adjacent pair
duke@435 88 return new StackValue(*(intptr_t*)value_addr);
duke@435 89 #endif
duke@435 90 case Location::oop: {
duke@435 91 Handle h(*(oop *)value_addr); // Wrap a handle around the oop
duke@435 92 return new StackValue(h);
duke@435 93 }
duke@435 94 case Location::addr: {
duke@435 95 ShouldNotReachHere(); // both C1 and C2 now inline jsrs
duke@435 96 }
duke@435 97 case Location::normal: {
duke@435 98 // Just copy all other bits straight through
duke@435 99 union { intptr_t p; jint ji;} value;
duke@435 100 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
duke@435 101 value.ji = *(jint*)value_addr;
duke@435 102 return new StackValue(value.p);
duke@435 103 }
duke@435 104 case Location::invalid:
duke@435 105 return new StackValue();
duke@435 106 default:
duke@435 107 ShouldNotReachHere();
duke@435 108 }
duke@435 109
duke@435 110 } else if (sv->is_constant_int()) {
duke@435 111 // Constant int: treat same as register int.
duke@435 112 union { intptr_t p; jint ji;} value;
duke@435 113 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
duke@435 114 value.ji = (jint)((ConstantIntValue*)sv)->value();
duke@435 115 return new StackValue(value.p);
duke@435 116 } else if (sv->is_constant_oop()) {
duke@435 117 // constant oop
duke@435 118 return new StackValue(((ConstantOopReadValue *)sv)->value());
duke@435 119 #ifdef _LP64
duke@435 120 } else if (sv->is_constant_double()) {
duke@435 121 // Constant double in a single stack slot
duke@435 122 union { intptr_t p; double d; } value;
duke@435 123 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
duke@435 124 value.d = ((ConstantDoubleValue *)sv)->value();
duke@435 125 return new StackValue(value.p);
duke@435 126 } else if (sv->is_constant_long()) {
duke@435 127 // Constant long in a single stack slot
duke@435 128 union { intptr_t p; jlong jl; } value;
duke@435 129 value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
duke@435 130 value.jl = ((ConstantLongValue *)sv)->value();
duke@435 131 return new StackValue(value.p);
duke@435 132 #endif
duke@435 133 } else if (sv->is_object()) {
duke@435 134 return new StackValue(((ObjectValue *)sv)->value());
duke@435 135 }
duke@435 136
duke@435 137 // Unknown ScopeValue type
duke@435 138 ShouldNotReachHere();
duke@435 139 return new StackValue((intptr_t) 0); // dummy
duke@435 140 }
duke@435 141
duke@435 142
duke@435 143 BasicLock* StackValue::resolve_monitor_lock(const frame* fr, Location location) {
duke@435 144 assert(location.is_stack(), "for now we only look at the stack");
duke@435 145 int word_offset = location.stack_offset() / wordSize;
duke@435 146 // (stack picture)
duke@435 147 // high: [ ] word_offset + 1
duke@435 148 // low [ ] word_offset
duke@435 149 //
duke@435 150 // sp-> [ ] 0
duke@435 151 // the word_offset is the distance from the stack pointer to the lowest address
duke@435 152 // The frame's original stack pointer, before any extension by its callee
duke@435 153 // (due to Compiler1 linkage on SPARC), must be used.
duke@435 154 return (BasicLock*) (fr->unextended_sp() + word_offset);
duke@435 155 }
duke@435 156
duke@435 157
duke@435 158 #ifndef PRODUCT
duke@435 159
duke@435 160 void StackValue::print_on(outputStream* st) const {
duke@435 161 switch(_type) {
duke@435 162 case T_INT:
duke@435 163 st->print("%d (int) %f (float) %x (hex)", *(int *)&_i, *(float *)&_i, *(int *)&_i);
duke@435 164 break;
duke@435 165
duke@435 166 case T_OBJECT:
duke@435 167 _o()->print_value_on(st);
duke@435 168 st->print(" <" INTPTR_FORMAT ">", (address)_o());
duke@435 169 break;
duke@435 170
duke@435 171 case T_CONFLICT:
duke@435 172 st->print("conflict");
duke@435 173 break;
duke@435 174
duke@435 175 default:
duke@435 176 ShouldNotReachHere();
duke@435 177 }
duke@435 178 }
duke@435 179
duke@435 180 #endif

mercurial