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