annotate agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicField.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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.types.basic;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 /** A basic implementation of Field which should be suitable for
a61af66fc99e Initial load
duke
parents:
diff changeset
31 cross-platform use. */
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class BasicField implements Field {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 protected BasicTypeDataBase db;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 protected Type type;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private Type containingType;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private boolean isStatic;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 /** Used for nonstatic fields only */
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private long offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 /** Used for static fields only */
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private Address staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 /** offsetInBytes is ignored if the field is static;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 staticFieldAddress is used only if the field is static. */
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public BasicField(BasicTypeDataBase db, Type containingType, String name, Type type,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 boolean isStatic, long offsetInBytes, Address staticFieldAddress) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 this.db = db;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 this.containingType = containingType;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 this.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 this.type = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 this.size = type.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 this.isStatic = isStatic;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 this.offset = offsetInBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 this.staticFieldAddress = staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return name;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public Type getType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public long getSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return size;
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 boolean isStatic() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return isStatic;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public long getOffset() throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 throw new WrongTypeException("field \"" + name + "\" in class " +
a61af66fc99e Initial load
duke
parents:
diff changeset
79 containingType.getName() + " is static");
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 public Address getStaticFieldAddress() throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 throw new WrongTypeException("field \"" + name + "\" in class " +
a61af66fc99e Initial load
duke
parents:
diff changeset
87 containingType.getName() + " is not static");
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return staticFieldAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Dereferencing operations for non-static fields
a61af66fc99e Initial load
duke
parents:
diff changeset
94 //
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public boolean getJBoolean (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return addr.getJBooleanAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public byte getJByte (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return addr.getJByteAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public char getJChar (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return addr.getJCharAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public double getJDouble (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return addr.getJDoubleAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public float getJFloat (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return addr.getJFloatAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public int getJInt (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return addr.getJIntAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public long getJLong (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return addr.getJLongAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public short getJShort (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return addr.getJShortAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public long getCInteger (Address addr, CIntegerType type)
a61af66fc99e Initial load
duke
parents:
diff changeset
145 throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return addr.getCIntegerAt(offset, type.getSize(), type.isUnsigned());
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public Address getAddress (Address addr) throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return addr.getAddressAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public OopHandle getOopHandle(Address addr)
a61af66fc99e Initial load
duke
parents:
diff changeset
158 throws UnmappedAddressException, UnalignedAddressException, WrongTypeException, NotInHeapException {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return addr.getOopHandleAt(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Dereferencing operations for static fields
a61af66fc99e Initial load
duke
parents:
diff changeset
167 //
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public boolean getJBoolean () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 return staticFieldAddress.getJBooleanAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public byte getJByte () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return staticFieldAddress.getJByteAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public char getJChar () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return staticFieldAddress.getJCharAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 public double getJDouble () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return staticFieldAddress.getJDoubleAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public float getJFloat () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return staticFieldAddress.getJFloatAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public int getJInt () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return staticFieldAddress.getJIntAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205 public long getJLong () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return staticFieldAddress.getJLongAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public short getJShort () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return staticFieldAddress.getJShortAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 public long getCInteger (CIntegerType type)
a61af66fc99e Initial load
duke
parents:
diff changeset
218 throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return staticFieldAddress.getCIntegerAt(0, type.getSize(), type.isUnsigned());
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 public Address getAddress () throws UnmappedAddressException, UnalignedAddressException, WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 return staticFieldAddress.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 public OopHandle getOopHandle()
a61af66fc99e Initial load
duke
parents:
diff changeset
231 throws UnmappedAddressException, UnalignedAddressException, WrongTypeException, NotInHeapException {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 throw new WrongTypeException();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return staticFieldAddress.getOopHandleAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }