1 /*
 2  * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 package sun.jvm.hotspot.code;
26 
27 import java.io.*;
28 import java.util.*;
29 
30 import sun.jvm.hotspot.debugger.*;
31 import sun.jvm.hotspot.utilities.*;
32 
33 /** An ObjectValue describes an object eliminated by escape analysis. */
34 
35 public class ObjectValue extends ScopeValue {
36   protected final int      id;
37   private boolean          isRoot;
38   private ScopeValue       klass;
39   private List<ScopeValue> fieldsValue;
40 
41   // Field "boolean visited" is not implemented here since
42   // it is used only a during debug info creation.
43 
44   public ObjectValue(int id) {
45     this.id = id;
46     klass   = null;
47     fieldsValue = new ArrayList<>();
48   }
49 
50   public boolean isObject() { return true; }
51   public int id() { return id; }
52   public ScopeValue getKlass() { return klass; }
53   public List<ScopeValue> getFieldsValue() { return fieldsValue; }
54   public ScopeValue getFieldAt(int i) { return fieldsValue.get(i); }
55   public int fieldsSize() { return fieldsValue.size(); }
56 
57   // Field "value" is always NULL here since it is used
58   // only during deoptimization of a compiled frame
59   // pointing to reallocated object.
60   public OopHandle getValue() { return null; }
61 
62   /** Serialization of debugging information */
63 
64   void readObject(DebugInfoReadStream stream) {
65     isRoot = stream.readBoolean();
66     klass = readFrom(stream);
67     Assert.that(klass.isConstantOop(), "should be constant klass oop: " + klass);
68     int length = stream.readInt();
69     for (int i = 0; i < length; i++) {
70       ScopeValue val = readFrom(stream);
71       fieldsValue.add(val);
72     }
73   }
74 
75   // Printing
76 
77   public void print() {
78     printOn(System.out);
79   }
80 
81   public void printOn(PrintStream tty) {
82     tty.print("scalarObj[" + id + "]");
83   }
84 
85   void printFieldsOn(PrintStream tty) {
86     if (fieldsValue.size() > 0) {
87       fieldsValue.get(0).printOn(tty);
88     }
89     for (int i = 1; i < fieldsValue.size(); i++) {
90       tty.print(", ");
91       fieldsValue.get(i).printOn(tty);
92     }
93   }
94 
95 };