Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/LivenessPath.java
41161 views
/*1* Copyright (c) 2001, 2020, 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.utilities;2526import java.io.*;27import java.util.*;28import sun.jvm.hotspot.oops.*;2930/** Describes a path from an object back to the root which is keeping31it alive. Elements of the path are (object, field) pairs, where32the object is expressed as a @link{sun.jvm.hotspot.oops.Oop}, and33where the field is expressed as a34@link{sun.jvm.hotspot.oops.FieldIdentifier}. If the element35reflects a root, the Oop will be null. If the element is the end36of the path, the FieldIdentifier will be null. */3738public class LivenessPath {39LivenessPath() {40stack = new Stack<>();41}4243/** Number of elements in the path */44public int size() {45return stack.size();46}4748/** Fetch the element at the given index; 0-based */49public LivenessPathElement get(int index) throws ArrayIndexOutOfBoundsException {50return (LivenessPathElement) stack.get(index);51}5253public void printOn(PrintStream tty) {54for (int j = 0; j < size(); j++) {55LivenessPathElement el = get(j);56tty.print(" - ");57if (el.getObj() != null) {58Oop.printOopValueOn(el.getObj(), tty);59}60if (el.getField() != null) {61if (el.getObj() != null) {62tty.print(", field ");63}64tty.print(el.getField().getName());65}66tty.println();67}68}6970/** Indicates whether this path is "complete", i.e., whether the71last element is a root. Convenience routine for LivenessAnalysis. */72boolean isComplete() {73if (size() == 0)74return false;75return peek().isRoot();76}7778// Convenience routine for LivenessAnalysis79LivenessPathElement peek() {80return (LivenessPathElement) stack.peek();81}8283// Convenience routine for LivenessAnalysis84void push(LivenessPathElement el) {85stack.push(el);86}8788// Convenience routine for LivenessAnalysis89void pop() {90stack.pop();91}9293// Make a copy of the contents of the path -- the94// LivenessPathElements are not duplicated, only the containing path95LivenessPath copy() {96LivenessPath dup = new LivenessPath();97for (int i = 0; i < stack.size(); i++) {98dup.stack.push(stack.get(i));99}100return dup;101}102103//---------------------------------------------------------------------------104// Internals only below this point105//106private Stack<LivenessPathElement> stack;107}108109110