1 /*
2 * Copyright (c) 2009, 2026, 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 ScopeValue properties;
40 private List<ScopeValue> fieldsValue;
41
42 // Field "boolean visited" is not implemented here since
43 // it is used only a during debug info creation.
44
45 public ObjectValue(int id) {
46 this.id = id;
47 klass = null;
48 properties = null;
49 fieldsValue = new ArrayList<>();
50 }
51
52 public boolean isObject() { return true; }
53 public int id() { return id; }
54 public ScopeValue getKlass() { return klass; }
55 public ScopeValue getProperties() { return properties; }
56 public List<ScopeValue> getFieldsValue() { return fieldsValue; }
57 public ScopeValue getFieldAt(int i) { return fieldsValue.get(i); }
58 public int fieldsSize() { return fieldsValue.size(); }
59
60 // Field "value" is always NULL here since it is used
61 // only during deoptimization of a compiled frame
62 // pointing to reallocated object.
63 public OopHandle getValue() { return null; }
64
65 /** Serialization of debugging information */
66
67 void readObject(DebugInfoReadStream stream) {
68 isRoot = stream.readBoolean();
69 klass = readFrom(stream);
70 Assert.that(klass.isConstantOop(), "should be constant klass oop: " + klass);
71 properties = readFrom(stream);
72 int length = stream.readInt();
73 for (int i = 0; i < length; i++) {
74 ScopeValue val = readFrom(stream);
75 fieldsValue.add(val);
76 }
77 }
78
79 // Printing
80
81 public void print() {
82 printOn(System.out);
83 }
84
85 public void printOn(PrintStream tty) {
86 tty.print("scalarObj[" + id + "]");
87 }
88
89 void printFieldsOn(PrintStream tty) {
90 if (fieldsValue.size() > 0) {
91 fieldsValue.get(0).printOn(tty);
92 }
93 for (int i = 1; i < fieldsValue.size(); i++) {
94 tty.print(", ");
95 fieldsValue.get(i).printOn(tty);
96 }
97 }
98
99 };