annotate agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/BasicCompoundType.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.debugger.cdbg.basic;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public class BasicCompoundType extends BasicType implements CompoundType {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private CompoundTypeKind kind;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private List baseClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private List fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public BasicCompoundType(String name, int size, CompoundTypeKind kind) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 this(name, size, kind, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private BasicCompoundType(String name, int size, CompoundTypeKind kind, int cvAttributes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 super(name, size, cvAttributes);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Assert.that(kind != null, "null kind");
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 this.kind = kind;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 public CompoundType asCompound() { return this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public int getNumBaseClasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return ((baseClasses == null) ? 0 : baseClasses.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public BaseClass getBaseClass(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return (BaseClass) baseClasses.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public void addBaseClass(BaseClass b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (baseClasses == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 baseClasses = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 baseClasses.add(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 public int getNumFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return ((fields == null) ? 0 : fields.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public Field getField(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return (Field) fields.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public void addField(Field f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (fields == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 fields = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 fields.add(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public boolean isClass() { return (kind == CompoundTypeKind.CLASS); }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public boolean isStruct() { return (kind == CompoundTypeKind.STRUCT); }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public boolean isUnion() { return (kind == CompoundTypeKind.UNION); }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Type resolveTypes(BasicCDebugInfoDataBase db, ResolveListener listener) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 super.resolveTypes(db, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (baseClasses != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 for (Iterator iter = baseClasses.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 BasicBaseClass b = (BasicBaseClass) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 b.resolveTypes(this, db, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (fields != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 for (Iterator iter = fields.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 BasicField b = (BasicField) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 b.resolveTypes(this, db, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return this;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public void iterateObject(Address a, ObjectVisitor v, FieldIdentifier f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // What kind of iteration are we doing? If the end user requested
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // iteration over a given object at a given address, the field
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // identifier will be null, and we should descend and iterate over
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // our fields and superclasses. Otherwise, we are already
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // iterating through an object, and it is up to the end user
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // whether to descend into the embedded object.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (f == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // FIXME: this is one of the key hard components of this
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // implementation. Will need to properly handle multiple
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // inheritance and possibly virtual base classes (i.e., not
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // iterating twice for a virtual base class inherited indirectly
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // more than once). For now, we do the simple thing, which
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // assumes single inheritance.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 for (int i = 0; i < getNumBaseClasses(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 BasicCompoundType b = (BasicCompoundType) getBaseClass(i).getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 b.iterateObject(a, v, f);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Now we are in our scope
a61af66fc99e Initial load
duke
parents:
diff changeset
119 v.enterType(this, a);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Iterate through our fields
a61af66fc99e Initial load
duke
parents:
diff changeset
121 for (int i = 0; i < getNumFields(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 Field field = getField(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 BasicType fieldType = (BasicType) field.getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 fieldType.iterateObject(a.addOffsetTo(field.getOffset()), v, new BasicNamedFieldIdentifier(field));
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 v.exitType();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 v.doCompound(f, a);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 protected Type createCVVariant(int cvAttributes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 BasicCompoundType t = new BasicCompoundType(getName(), getSize(), kind, cvAttributes);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 t.kind = kind;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 t.baseClasses = baseClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 t.fields = fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public void visit(TypeVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 v.doCompoundType(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }