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