Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StackValue.java
41161 views
/*1* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.runtime;2526import java.io.*;27import sun.jvm.hotspot.debugger.*;28import sun.jvm.hotspot.utilities.*;2930public class StackValue {31private int type;32private OopHandle handleValue;33private long integerValue;3435public StackValue() {36type = BasicType.getTConflict();37}3839public StackValue(OopHandle h, long scalar_replaced) {40handleValue = h;41type = BasicType.getTObject();42integerValue = scalar_replaced;43Assert.that(integerValue == 0 || handleValue == null, "not null object should not be marked as scalar replaced");44}4546public StackValue(long i) {47integerValue = i;48type = BasicType.getTInt();49}5051/** This returns one of the "enum" values in BasicType.java */52public int getType() {53return type;54}5556public OopHandle getObject() {57if (Assert.ASSERTS_ENABLED) {58Assert.that(type == BasicType.getTObject(), "type check");59}60return handleValue;61}6263boolean objIsScalarReplaced() {64if (Assert.ASSERTS_ENABLED) {65Assert.that(type == BasicType.getTObject(), "type check");66}67return integerValue != 0;68}6970public long getInteger() {71if (Assert.ASSERTS_ENABLED) {72Assert.that(type == BasicType.getTInt(), "type check");73}74return integerValue;75}7677public boolean equals(Object arg) {78if (arg == null) {79return false;80}8182if (!arg.getClass().equals(getClass())) {83return false;84}8586StackValue sv = (StackValue) arg;87if (type != sv.type) {88return false;89}90if (type == BasicType.getTObject()) {91return handleValue.equals(sv.handleValue);92} else if (type == BasicType.getTInt()) {93return (integerValue == sv.integerValue);94} else {95// Conflict type (not yet used)96return true;97}98}99100public int hashCode() {101if (type == BasicType.getTObject()) {102return handleValue != null ? handleValue.hashCode() : 5;103} else {104// Returns 0 for conflict type105return (int) integerValue;106}107}108109public void print() {110printOn(System.out);111}112113public void printOn(PrintStream tty) {114if (type == BasicType.getTInt()) {115tty.print(integerValue + " (long) " + (int) integerValue + " (int)");116} else if (type == BasicType.getTObject()) {117tty.print("<" + handleValue + ">");118} else if (type == BasicType.getTConflict()) {119tty.print("conflict");120} else {121throw new RuntimeException("should not reach here");122}123}124}125126127