hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/StackValue.java
author xdono
Tue, 28 Jul 2009 12:12:40 -0700
changeset 3261 c7d5aae8d3f7
parent 3171 aa289b22b577
child 5547 f4b087cbb361
permissions -rw-r--r--
6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 3171
diff changeset
     2
 * Copyright 2000-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
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
package sun.jvm.hotspot.runtime;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
public class StackValue {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  private int       type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  private OopHandle handleValue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  private long      integerValue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  public StackValue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    type = BasicType.getTConflict();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    40
  public StackValue(OopHandle h, long scalar_replaced) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    handleValue = h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    type = BasicType.getTObject();
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    43
    integerValue = scalar_replaced;
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    44
    Assert.that(integerValue == 0 || handleValue == null, "not null object should not be marked as scalar replaced");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  public StackValue(long i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    integerValue = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    type = BasicType.getTInt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  /** This returns one of the "enum" values in BasicType.java */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  public int getType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  public OopHandle getObject() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      Assert.that(type == BasicType.getTObject(), "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    return handleValue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    64
  boolean objIsScalarReplaced() {
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    65
    if (Assert.ASSERTS_ENABLED) {
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    66
      Assert.that(type == BasicType.getTObject(), "type check");
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    67
    }
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    68
    return integerValue != 0;
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    69
  }
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    70
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  public long getInteger() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      Assert.that(type == BasicType.getTInt(), "type check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    return integerValue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  public boolean equals(Object arg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    if (arg == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    if (!arg.getClass().equals(getClass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    StackValue sv = (StackValue) arg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    if (type != sv.type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (type == BasicType.getTObject()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      return handleValue.equals(sv.handleValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    } else if (type == BasicType.getTInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      return (integerValue == sv.integerValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      // Conflict type (not yet used)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  public int hashCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    if (type == BasicType.getTObject()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      return handleValue.hashCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      // Returns 0 for conflict type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      return (int) integerValue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    printOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if (type == BasicType.getTInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      tty.print(integerValue + " (long) " + (int) integerValue + " (int)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    } else if (type == BasicType.getTObject()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      tty.print("<" + handleValue + ">");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    } else if (type == BasicType.getTConflict()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      tty.print("conflict");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}