src/share/vm/runtime/stackValue.cpp

changeset 435
a61af66fc99e
child 766
cecd8eb4e0ca
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/stackValue.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,180 @@
     1.4 +/*
     1.5 + * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_stackValue.cpp.incl"
    1.30 +
    1.31 +StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv) {
    1.32 +  if (sv->is_location()) {
    1.33 +    // Stack or register value
    1.34 +    Location loc = ((LocationValue *)sv)->location();
    1.35 +
    1.36 +#ifdef SPARC
    1.37 +    // %%%%% Callee-save floats will NOT be working on a Sparc until we
    1.38 +    // handle the case of a 2 floats in a single double register.
    1.39 +    assert( !(loc.is_register() && loc.type() == Location::float_in_dbl), "Sparc does not handle callee-save floats yet" );
    1.40 +#endif // SPARC
    1.41 +
    1.42 +    // First find address of value
    1.43 +
    1.44 +    address value_addr = loc.is_register()
    1.45 +      // Value was in a callee-save register
    1.46 +      ? reg_map->location(VMRegImpl::as_VMReg(loc.register_number()))
    1.47 +      // Else value was directly saved on the stack. The frame's original stack pointer,
    1.48 +      // before any extension by its callee (due to Compiler1 linkage on SPARC), must be used.
    1.49 +      : ((address)fr->unextended_sp()) + loc.stack_offset();
    1.50 +
    1.51 +    // Then package it right depending on type
    1.52 +    // Note: the transfer of the data is thru a union that contains
    1.53 +    // an intptr_t. This is because an interpreter stack slot is
    1.54 +    // really an intptr_t. The use of a union containing an intptr_t
    1.55 +    // ensures that on a 64 bit platform we have proper alignment
    1.56 +    // and that we store the value where the interpreter will expect
    1.57 +    // to find it (i.e. proper endian). Similarly on a 32bit platform
    1.58 +    // using the intptr_t ensures that when a value is larger than
    1.59 +    // a stack slot (jlong/jdouble) that we capture the proper part
    1.60 +    // of the value for the stack slot in question.
    1.61 +    //
    1.62 +    switch( loc.type() ) {
    1.63 +    case Location::float_in_dbl: { // Holds a float in a double register?
    1.64 +      // The callee has no clue whether the register holds a float,
    1.65 +      // double or is unused.  He always saves a double.  Here we know
    1.66 +      // a double was saved, but we only want a float back.  Narrow the
    1.67 +      // saved double to the float that the JVM wants.
    1.68 +      assert( loc.is_register(), "floats always saved to stack in 1 word" );
    1.69 +      union { intptr_t p; jfloat jf; } value;
    1.70 +      value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
    1.71 +      value.jf = (jfloat) *(jdouble*) value_addr;
    1.72 +      return new StackValue(value.p); // 64-bit high half is stack junk
    1.73 +    }
    1.74 +    case Location::int_in_long: { // Holds an int in a long register?
    1.75 +      // The callee has no clue whether the register holds an int,
    1.76 +      // long or is unused.  He always saves a long.  Here we know
    1.77 +      // a long was saved, but we only want an int back.  Narrow the
    1.78 +      // saved long to the int that the JVM wants.
    1.79 +      assert( loc.is_register(), "ints always saved to stack in 1 word" );
    1.80 +      union { intptr_t p; jint ji;} value;
    1.81 +      value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
    1.82 +      value.ji = (jint) *(jlong*) value_addr;
    1.83 +      return new StackValue(value.p); // 64-bit high half is stack junk
    1.84 +    }
    1.85 +#ifdef _LP64
    1.86 +    case Location::dbl:
    1.87 +      // Double value in an aligned adjacent pair
    1.88 +      return new StackValue(*(intptr_t*)value_addr);
    1.89 +    case Location::lng:
    1.90 +      // Long   value in an aligned adjacent pair
    1.91 +      return new StackValue(*(intptr_t*)value_addr);
    1.92 +#endif
    1.93 +    case Location::oop: {
    1.94 +      Handle h(*(oop *)value_addr); // Wrap a handle around the oop
    1.95 +      return new StackValue(h);
    1.96 +    }
    1.97 +    case Location::addr: {
    1.98 +      ShouldNotReachHere(); // both C1 and C2 now inline jsrs
    1.99 +    }
   1.100 +    case Location::normal: {
   1.101 +      // Just copy all other bits straight through
   1.102 +      union { intptr_t p; jint ji;} value;
   1.103 +      value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
   1.104 +      value.ji = *(jint*)value_addr;
   1.105 +      return new StackValue(value.p);
   1.106 +    }
   1.107 +    case Location::invalid:
   1.108 +      return new StackValue();
   1.109 +    default:
   1.110 +      ShouldNotReachHere();
   1.111 +    }
   1.112 +
   1.113 +  } else if (sv->is_constant_int()) {
   1.114 +    // Constant int: treat same as register int.
   1.115 +    union { intptr_t p; jint ji;} value;
   1.116 +    value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
   1.117 +    value.ji = (jint)((ConstantIntValue*)sv)->value();
   1.118 +    return new StackValue(value.p);
   1.119 +  } else if (sv->is_constant_oop()) {
   1.120 +    // constant oop
   1.121 +    return new StackValue(((ConstantOopReadValue *)sv)->value());
   1.122 +#ifdef _LP64
   1.123 +  } else if (sv->is_constant_double()) {
   1.124 +    // Constant double in a single stack slot
   1.125 +    union { intptr_t p; double d; } value;
   1.126 +    value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
   1.127 +    value.d = ((ConstantDoubleValue *)sv)->value();
   1.128 +    return new StackValue(value.p);
   1.129 +  } else if (sv->is_constant_long()) {
   1.130 +    // Constant long in a single stack slot
   1.131 +    union { intptr_t p; jlong jl; } value;
   1.132 +    value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
   1.133 +    value.jl = ((ConstantLongValue *)sv)->value();
   1.134 +    return new StackValue(value.p);
   1.135 +#endif
   1.136 +  } else if (sv->is_object()) {
   1.137 +    return new StackValue(((ObjectValue *)sv)->value());
   1.138 +  }
   1.139 +
   1.140 +  // Unknown ScopeValue type
   1.141 +  ShouldNotReachHere();
   1.142 +  return new StackValue((intptr_t) 0);   // dummy
   1.143 +}
   1.144 +
   1.145 +
   1.146 +BasicLock* StackValue::resolve_monitor_lock(const frame* fr, Location location) {
   1.147 +  assert(location.is_stack(), "for now we only look at the stack");
   1.148 +  int word_offset = location.stack_offset() / wordSize;
   1.149 +  // (stack picture)
   1.150 +  // high: [     ]  word_offset + 1
   1.151 +  // low   [     ]  word_offset
   1.152 +  //
   1.153 +  // sp->  [     ]  0
   1.154 +  // the word_offset is the distance from the stack pointer to the lowest address
   1.155 +  // The frame's original stack pointer, before any extension by its callee
   1.156 +  // (due to Compiler1 linkage on SPARC), must be used.
   1.157 +  return (BasicLock*) (fr->unextended_sp() + word_offset);
   1.158 +}
   1.159 +
   1.160 +
   1.161 +#ifndef PRODUCT
   1.162 +
   1.163 +void StackValue::print_on(outputStream* st) const {
   1.164 +  switch(_type) {
   1.165 +    case T_INT:
   1.166 +      st->print("%d (int) %f (float) %x (hex)",  *(int *)&_i, *(float *)&_i,  *(int *)&_i);
   1.167 +      break;
   1.168 +
   1.169 +    case T_OBJECT:
   1.170 +     _o()->print_value_on(st);
   1.171 +      st->print(" <" INTPTR_FORMAT ">", (address)_o());
   1.172 +     break;
   1.173 +
   1.174 +    case T_CONFLICT:
   1.175 +     st->print("conflict");
   1.176 +     break;
   1.177 +
   1.178 +    default:
   1.179 +     ShouldNotReachHere();
   1.180 +  }
   1.181 +}
   1.182 +
   1.183 +#endif

mercurial