author | jrose |
Sat, 30 Oct 2010 13:08:23 -0700 | |
changeset 7114 | 65d21c4c6337 |
parent 6062 | bab93afe9df7 |
child 7436 | dbc43da3d512 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
2 |
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.oops; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
import sun.jvm.hotspot.debugger.*; |
|
30 |
import sun.jvm.hotspot.runtime.*; |
|
31 |
import sun.jvm.hotspot.types.*; |
|
32 |
import sun.jvm.hotspot.utilities.*; |
|
33 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
34 |
// A ConstantPool is an oop containing class constants |
1 | 35 |
// as described in the class file |
36 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
37 |
public class ConstantPool extends Oop implements ClassConstants { |
1 | 38 |
// Used for debugging this code |
39 |
private static final boolean DEBUG = false; |
|
40 |
||
41 |
protected void debugMessage(String message) { |
|
42 |
System.out.println(message); |
|
43 |
} |
|
44 |
||
45 |
static { |
|
46 |
VM.registerVMInitializedObserver(new Observer() { |
|
47 |
public void update(Observable o, Object data) { |
|
48 |
initialize(VM.getVM().getTypeDataBase()); |
|
49 |
} |
|
50 |
}); |
|
51 |
} |
|
52 |
||
53 |
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
|
54 |
Type type = db.lookupType("constantPoolOopDesc"); |
|
55 |
tags = new OopField(type.getOopField("_tags"), 0); |
|
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
56 |
operands = new OopField(type.getOopField("_operands"), 0); |
1 | 57 |
cache = new OopField(type.getOopField("_cache"), 0); |
58 |
poolHolder = new OopField(type.getOopField("_pool_holder"), 0); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
59 |
length = new CIntField(type.getCIntegerField("_length"), 0); |
1 | 60 |
headerSize = type.getSize(); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
61 |
elementSize = 0; |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
62 |
// fetch constants: |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
63 |
MULTI_OPERAND_COUNT_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_multi_operand_count_offset").intValue(); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
64 |
MULTI_OPERAND_BASE_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_multi_operand_base_offset").intValue(); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
65 |
INDY_BSM_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_bsm_offset").intValue(); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
66 |
INDY_NT_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_nt_offset").intValue(); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
67 |
INDY_ARGC_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argc_offset").intValue(); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
68 |
INDY_ARGV_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argv_offset").intValue(); |
1 | 69 |
} |
70 |
||
71 |
ConstantPool(OopHandle handle, ObjectHeap heap) { |
|
72 |
super(handle, heap); |
|
73 |
} |
|
74 |
||
75 |
public boolean isConstantPool() { return true; } |
|
76 |
||
77 |
private static OopField tags; |
|
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
78 |
private static OopField operands; |
1 | 79 |
private static OopField cache; |
80 |
private static OopField poolHolder; |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
81 |
private static CIntField length; // number of elements in oop |
1 | 82 |
|
83 |
private static long headerSize; |
|
84 |
private static long elementSize; |
|
85 |
||
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
86 |
private static int MULTI_OPERAND_COUNT_OFFSET; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
87 |
private static int MULTI_OPERAND_BASE_OFFSET; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
88 |
private static int INDY_BSM_OFFSET; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
89 |
private static int INDY_NT_OFFSET; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
90 |
private static int INDY_ARGC_OFFSET; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
91 |
private static int INDY_ARGV_OFFSET; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
92 |
|
1 | 93 |
public TypeArray getTags() { return (TypeArray) tags.getValue(this); } |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
94 |
public TypeArray getOperands() { return (TypeArray) operands.getValue(this); } |
1 | 95 |
public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); } |
96 |
public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); } |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
97 |
public int getLength() { return (int)length.getValue(this); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
98 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
99 |
private long getElementSize() { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
100 |
if (elementSize !=0 ) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
101 |
return elementSize; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
102 |
} else { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
103 |
elementSize = VM.getVM().getOopSize(); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
104 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
105 |
return elementSize; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
106 |
} |
1 | 107 |
|
108 |
private long indexOffset(long index) { |
|
109 |
if (Assert.ASSERTS_ENABLED) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
110 |
Assert.that(index > 0 && index < getLength(), "invalid cp index " + index + " " + getLength()); |
1 | 111 |
} |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
112 |
return (index * getElementSize()) + headerSize; |
1 | 113 |
} |
114 |
||
115 |
public ConstantTag getTagAt(long index) { |
|
116 |
return new ConstantTag(getTags().getByteAt((int) index)); |
|
117 |
} |
|
118 |
||
119 |
public Oop getObjAt(long index){ |
|
120 |
return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index))); |
|
121 |
} |
|
122 |
||
123 |
public Symbol getSymbolAt(long index) { |
|
124 |
return (Symbol) getObjAt(index); |
|
125 |
} |
|
126 |
||
127 |
public int getIntAt(long index){ |
|
128 |
return getHandle().getJIntAt(indexOffset(index)); |
|
129 |
} |
|
130 |
||
131 |
public float getFloatAt(long index){ |
|
132 |
return getHandle().getJFloatAt(indexOffset(index)); |
|
133 |
} |
|
134 |
||
135 |
public long getLongAt(long index) { |
|
136 |
int oneHalf = getHandle().getJIntAt(indexOffset(index + 1)); |
|
137 |
int otherHalf = getHandle().getJIntAt(indexOffset(index)); |
|
138 |
// buildLongFromIntsPD accepts higher address value, lower address value |
|
139 |
// in that order. |
|
140 |
return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf); |
|
141 |
} |
|
142 |
||
143 |
public double getDoubleAt(long index) { |
|
144 |
return Double.longBitsToDouble(getLongAt(index)); |
|
145 |
} |
|
146 |
||
147 |
public int getFieldOrMethodAt(int which) { |
|
148 |
if (DEBUG) { |
|
149 |
System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = "); |
|
150 |
} |
|
151 |
int i = -1; |
|
152 |
ConstantPoolCache cache = getCache(); |
|
153 |
if (cache == null) { |
|
154 |
i = which; |
|
155 |
} else { |
|
156 |
// change byte-ordering and go via cache |
|
157 |
i = cache.getEntryAt(0xFFFF & VM.getVM().getBytes().swapShort((short) which)).getConstantPoolIndex(); |
|
158 |
} |
|
159 |
if (Assert.ASSERTS_ENABLED) { |
|
160 |
Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool"); |
|
161 |
} |
|
162 |
if (DEBUG) { |
|
163 |
System.err.println(i); |
|
164 |
} |
|
165 |
int res = getIntAt(i); |
|
166 |
if (DEBUG) { |
|
167 |
System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res); |
|
168 |
} |
|
169 |
return res; |
|
170 |
} |
|
171 |
||
5882 | 172 |
public int[] getNameAndTypeAt(int which) { |
1 | 173 |
if (Assert.ASSERTS_ENABLED) { |
174 |
Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool"); |
|
175 |
} |
|
176 |
int i = getIntAt(which); |
|
177 |
if (DEBUG) { |
|
178 |
System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i); |
|
179 |
} |
|
5882 | 180 |
return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) }; |
1 | 181 |
} |
182 |
||
183 |
public Symbol getNameRefAt(int which) { |
|
5882 | 184 |
int nameIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[0]; |
1 | 185 |
return getSymbolAt(nameIndex); |
186 |
} |
|
187 |
||
188 |
public Symbol getSignatureRefAt(int which) { |
|
5882 | 189 |
int sigIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[1]; |
1 | 190 |
return getSymbolAt(sigIndex); |
191 |
} |
|
192 |
||
193 |
// returns null, if not resolved. |
|
194 |
public Klass getKlassRefAt(int which) { |
|
195 |
if( ! getTagAt(which).isKlass()) return null; |
|
196 |
return (Klass) getObjAt(which); |
|
197 |
} |
|
198 |
||
199 |
// returns null, if not resolved. |
|
200 |
public InstanceKlass getFieldOrMethodKlassRefAt(int which) { |
|
201 |
int refIndex = getFieldOrMethodAt(which); |
|
202 |
int klassIndex = extractLowShortFromInt(refIndex); |
|
203 |
return (InstanceKlass) getKlassRefAt(klassIndex); |
|
204 |
} |
|
205 |
||
206 |
// returns null, if not resolved. |
|
207 |
public Method getMethodRefAt(int which) { |
|
208 |
InstanceKlass klass = getFieldOrMethodKlassRefAt(which); |
|
209 |
if (klass == null) return null; |
|
210 |
Symbol name = getNameRefAt(which); |
|
211 |
Symbol sig = getSignatureRefAt(which); |
|
212 |
return klass.findMethod(name, sig); |
|
213 |
} |
|
214 |
||
215 |
// returns null, if not resolved. |
|
216 |
public Field getFieldRefAt(int which) { |
|
217 |
InstanceKlass klass = getFieldOrMethodKlassRefAt(which); |
|
218 |
if (klass == null) return null; |
|
219 |
Symbol name = getNameRefAt(which); |
|
220 |
Symbol sig = getSignatureRefAt(which); |
|
221 |
return klass.findField(name, sig); |
|
222 |
} |
|
223 |
||
224 |
public int getNameAndTypeRefIndexAt(int index) { |
|
225 |
int refIndex = getFieldOrMethodAt(index); |
|
226 |
if (DEBUG) { |
|
227 |
System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): refIndex = " + refIndex); |
|
228 |
} |
|
229 |
int i = extractHighShortFromInt(refIndex); |
|
230 |
if (DEBUG) { |
|
231 |
System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): result = " + i); |
|
232 |
} |
|
233 |
return i; |
|
234 |
} |
|
235 |
||
236 |
/** Lookup for entries consisting of (name_index, signature_index) */ |
|
237 |
public int getNameRefIndexAt(int index) { |
|
5882 | 238 |
int[] refIndex = getNameAndTypeAt(index); |
1 | 239 |
if (DEBUG) { |
5882 | 240 |
System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]); |
1 | 241 |
} |
5882 | 242 |
int i = refIndex[0]; |
1 | 243 |
if (DEBUG) { |
244 |
System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): result = " + i); |
|
245 |
} |
|
246 |
return i; |
|
247 |
} |
|
248 |
||
249 |
/** Lookup for entries consisting of (name_index, signature_index) */ |
|
250 |
public int getSignatureRefIndexAt(int index) { |
|
5882 | 251 |
int[] refIndex = getNameAndTypeAt(index); |
1 | 252 |
if (DEBUG) { |
5882 | 253 |
System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]); |
1 | 254 |
} |
5882 | 255 |
int i = refIndex[1]; |
1 | 256 |
if (DEBUG) { |
257 |
System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): result = " + i); |
|
258 |
} |
|
259 |
return i; |
|
260 |
} |
|
261 |
||
5882 | 262 |
/** Lookup for MethodHandle entries. */ |
263 |
public int getMethodHandleIndexAt(int i) { |
|
264 |
if (Assert.ASSERTS_ENABLED) { |
|
265 |
Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool"); |
|
266 |
} |
|
267 |
int res = extractHighShortFromInt(getIntAt(i)); |
|
268 |
if (DEBUG) { |
|
269 |
System.err.println("ConstantPool.getMethodHandleIndexAt(" + i + "): result = " + res); |
|
270 |
} |
|
271 |
return res; |
|
272 |
} |
|
273 |
||
274 |
/** Lookup for MethodHandle entries. */ |
|
275 |
public int getMethodHandleRefKindAt(int i) { |
|
276 |
if (Assert.ASSERTS_ENABLED) { |
|
277 |
Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool"); |
|
278 |
} |
|
279 |
int res = extractLowShortFromInt(getIntAt(i)); |
|
280 |
if (DEBUG) { |
|
281 |
System.err.println("ConstantPool.getMethodHandleRefKindAt(" + i + "): result = " + res); |
|
282 |
} |
|
283 |
return res; |
|
284 |
} |
|
285 |
||
286 |
/** Lookup for MethodType entries. */ |
|
287 |
public int getMethodTypeIndexAt(int i) { |
|
288 |
if (Assert.ASSERTS_ENABLED) { |
|
289 |
Assert.that(getTagAt(i).isMethodType(), "Corrupted constant pool"); |
|
290 |
} |
|
291 |
int res = getIntAt(i); |
|
292 |
if (DEBUG) { |
|
293 |
System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res); |
|
294 |
} |
|
295 |
return res; |
|
296 |
} |
|
297 |
||
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
298 |
/** Lookup for multi-operand (InvokeDynamic) entries. */ |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
299 |
public int[] getMultiOperandsAt(int i) { |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
300 |
if (Assert.ASSERTS_ENABLED) { |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
301 |
Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool"); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
302 |
} |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
303 |
int pos = this.getIntAt(i); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
304 |
int countPos = pos + MULTI_OPERAND_COUNT_OFFSET; // == pos-1 |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
305 |
int basePos = pos + MULTI_OPERAND_BASE_OFFSET; // == pos |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
306 |
if (countPos < 0) return null; // safety first |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
307 |
TypeArray operands = getOperands(); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
308 |
if (operands == null) return null; // safety first |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
309 |
int length = operands.getIntAt(countPos); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
310 |
int[] values = new int[length]; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
311 |
for (int j = 0; j < length; j++) { |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
312 |
values[j] = operands.getIntAt(basePos+j); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
313 |
} |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
314 |
return values; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
315 |
} |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
316 |
|
1 | 317 |
final private static String[] nameForTag = new String[] { |
318 |
}; |
|
319 |
||
320 |
private String nameForTag(int tag) { |
|
321 |
switch (tag) { |
|
322 |
case JVM_CONSTANT_Utf8: return "JVM_CONSTANT_Utf8"; |
|
323 |
case JVM_CONSTANT_Unicode: return "JVM_CONSTANT_Unicode"; |
|
324 |
case JVM_CONSTANT_Integer: return "JVM_CONSTANT_Integer"; |
|
325 |
case JVM_CONSTANT_Float: return "JVM_CONSTANT_Float"; |
|
326 |
case JVM_CONSTANT_Long: return "JVM_CONSTANT_Long"; |
|
327 |
case JVM_CONSTANT_Double: return "JVM_CONSTANT_Double"; |
|
328 |
case JVM_CONSTANT_Class: return "JVM_CONSTANT_Class"; |
|
329 |
case JVM_CONSTANT_String: return "JVM_CONSTANT_String"; |
|
330 |
case JVM_CONSTANT_Fieldref: return "JVM_CONSTANT_Fieldref"; |
|
331 |
case JVM_CONSTANT_Methodref: return "JVM_CONSTANT_Methodref"; |
|
332 |
case JVM_CONSTANT_InterfaceMethodref: return "JVM_CONSTANT_InterfaceMethodref"; |
|
333 |
case JVM_CONSTANT_NameAndType: return "JVM_CONSTANT_NameAndType"; |
|
5882 | 334 |
case JVM_CONSTANT_MethodHandle: return "JVM_CONSTANT_MethodHandle"; |
335 |
case JVM_CONSTANT_MethodType: return "JVM_CONSTANT_MethodType"; |
|
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
336 |
case JVM_CONSTANT_InvokeDynamic: return "JVM_CONSTANT_InvokeDynamic"; |
1 | 337 |
case JVM_CONSTANT_Invalid: return "JVM_CONSTANT_Invalid"; |
338 |
case JVM_CONSTANT_UnresolvedClass: return "JVM_CONSTANT_UnresolvedClass"; |
|
5341 | 339 |
case JVM_CONSTANT_UnresolvedClassInError: return "JVM_CONSTANT_UnresolvedClassInError"; |
1 | 340 |
case JVM_CONSTANT_ClassIndex: return "JVM_CONSTANT_ClassIndex"; |
341 |
case JVM_CONSTANT_UnresolvedString: return "JVM_CONSTANT_UnresolvedString"; |
|
342 |
case JVM_CONSTANT_StringIndex: return "JVM_CONSTANT_StringIndex"; |
|
343 |
} |
|
5341 | 344 |
throw new InternalError("Unknown tag: " + tag); |
1 | 345 |
} |
346 |
||
347 |
public void iterateFields(OopVisitor visitor, boolean doVMFields) { |
|
348 |
super.iterateFields(visitor, doVMFields); |
|
349 |
if (doVMFields) { |
|
350 |
visitor.doOop(tags, true); |
|
351 |
visitor.doOop(cache, true); |
|
352 |
visitor.doOop(poolHolder, true); |
|
353 |
||
354 |
final int length = (int) getLength(); |
|
355 |
// zero'th pool entry is always invalid. ignore it. |
|
356 |
for (int index = 1; index < length; index++) { |
|
357 |
int ctag = (int) getTags().getByteAt((int) index); |
|
358 |
switch (ctag) { |
|
359 |
case JVM_CONSTANT_ClassIndex: |
|
360 |
case JVM_CONSTANT_StringIndex: |
|
361 |
case JVM_CONSTANT_Integer: |
|
362 |
visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
|
363 |
break; |
|
364 |
||
365 |
case JVM_CONSTANT_Float: |
|
366 |
visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
|
367 |
break; |
|
368 |
||
369 |
case JVM_CONSTANT_Long: |
|
370 |
visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
|
371 |
// long entries occupy two slots |
|
372 |
index++; |
|
373 |
break; |
|
374 |
||
375 |
case JVM_CONSTANT_Double: |
|
376 |
visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
|
377 |
// double entries occupy two slots |
|
378 |
index++; |
|
379 |
break; |
|
380 |
||
5341 | 381 |
case JVM_CONSTANT_UnresolvedClassInError: |
1 | 382 |
case JVM_CONSTANT_UnresolvedClass: |
383 |
case JVM_CONSTANT_Class: |
|
384 |
case JVM_CONSTANT_UnresolvedString: |
|
385 |
case JVM_CONSTANT_Utf8: |
|
386 |
visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
|
387 |
break; |
|
388 |
||
389 |
case JVM_CONSTANT_Fieldref: |
|
390 |
case JVM_CONSTANT_Methodref: |
|
391 |
case JVM_CONSTANT_InterfaceMethodref: |
|
392 |
case JVM_CONSTANT_NameAndType: |
|
5882 | 393 |
case JVM_CONSTANT_MethodHandle: |
394 |
case JVM_CONSTANT_MethodType: |
|
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
395 |
case JVM_CONSTANT_InvokeDynamic: |
1 | 396 |
visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
397 |
break; |
|
398 |
} |
|
399 |
} |
|
400 |
} |
|
401 |
/* |
|
402 |
int length = getLength(); |
|
403 |
for (int index = 0; index < length; index++) { |
|
404 |
long offset = baseOffset + (index + typeDataBase.getOopSize()); |
|
405 |
visitor.doOop(new IndexableField(index, offset, false), getObjAt(index)); |
|
406 |
} |
|
407 |
*/ |
|
408 |
} |
|
409 |
||
410 |
public void writeBytes(OutputStream os) throws IOException { |
|
411 |
// Map between any modified UTF-8 and it's constant pool index. |
|
412 |
Map utf8ToIndex = new HashMap(); |
|
413 |
DataOutputStream dos = new DataOutputStream(os); |
|
414 |
TypeArray tags = getTags(); |
|
415 |
int len = (int)getLength(); |
|
416 |
int ci = 0; // constant pool index |
|
417 |
||
418 |
// collect all modified UTF-8 Strings from Constant Pool |
|
419 |
||
420 |
for (ci = 1; ci < len; ci++) { |
|
421 |
byte cpConstType = tags.getByteAt(ci); |
|
422 |
if(cpConstType == JVM_CONSTANT_Utf8) { |
|
423 |
Symbol sym = getSymbolAt(ci); |
|
424 |
utf8ToIndex.put(sym.asString(), new Short((short) ci)); |
|
425 |
} |
|
426 |
else if(cpConstType == JVM_CONSTANT_Long || |
|
427 |
cpConstType == JVM_CONSTANT_Double) { |
|
428 |
ci++; |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
||
433 |
for(ci = 1; ci < len; ci++) { |
|
434 |
int cpConstType = (int)tags.getByteAt(ci); |
|
435 |
// write cp_info |
|
436 |
// write constant type |
|
437 |
switch(cpConstType) { |
|
438 |
case JVM_CONSTANT_Utf8: { |
|
439 |
dos.writeByte(cpConstType); |
|
440 |
Symbol sym = getSymbolAt(ci); |
|
441 |
dos.writeShort((short)sym.getLength()); |
|
442 |
dos.write(sym.asByteArray()); |
|
443 |
if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); |
|
444 |
break; |
|
445 |
} |
|
446 |
||
447 |
case JVM_CONSTANT_Unicode: |
|
448 |
throw new IllegalArgumentException("Unicode constant!"); |
|
449 |
||
450 |
case JVM_CONSTANT_Integer: |
|
451 |
dos.writeByte(cpConstType); |
|
452 |
dos.writeInt(getIntAt(ci)); |
|
453 |
if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci)); |
|
454 |
break; |
|
455 |
||
456 |
case JVM_CONSTANT_Float: |
|
457 |
dos.writeByte(cpConstType); |
|
458 |
dos.writeFloat(getFloatAt(ci)); |
|
459 |
if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci)); |
|
460 |
break; |
|
461 |
||
462 |
case JVM_CONSTANT_Long: { |
|
463 |
dos.writeByte(cpConstType); |
|
464 |
long l = getLongAt(ci); |
|
465 |
// long entries occupy two pool entries |
|
466 |
ci++; |
|
467 |
dos.writeLong(l); |
|
468 |
break; |
|
469 |
} |
|
470 |
||
471 |
case JVM_CONSTANT_Double: |
|
472 |
dos.writeByte(cpConstType); |
|
473 |
dos.writeDouble(getDoubleAt(ci)); |
|
474 |
// double entries occupy two pool entries |
|
475 |
ci++; |
|
476 |
break; |
|
477 |
||
478 |
case JVM_CONSTANT_Class: { |
|
479 |
dos.writeByte(cpConstType); |
|
480 |
// Klass already resolved. ConstantPool constains klassOop. |
|
481 |
Klass refKls = (Klass) getObjAt(ci); |
|
482 |
String klassName = refKls.getName().asString(); |
|
483 |
Short s = (Short) utf8ToIndex.get(klassName); |
|
484 |
dos.writeShort(s.shortValue()); |
|
485 |
if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); |
|
486 |
break; |
|
487 |
} |
|
488 |
||
489 |
// case JVM_CONSTANT_ClassIndex: |
|
5341 | 490 |
case JVM_CONSTANT_UnresolvedClassInError: |
1 | 491 |
case JVM_CONSTANT_UnresolvedClass: { |
492 |
dos.writeByte(JVM_CONSTANT_Class); |
|
493 |
String klassName = getSymbolAt(ci).asString(); |
|
494 |
Short s = (Short) utf8ToIndex.get(klassName); |
|
495 |
dos.writeShort(s.shortValue()); |
|
496 |
if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); |
|
497 |
break; |
|
498 |
} |
|
499 |
||
500 |
case JVM_CONSTANT_String: { |
|
501 |
dos.writeByte(cpConstType); |
|
502 |
String str = OopUtilities.stringOopToString(getObjAt(ci)); |
|
503 |
Short s = (Short) utf8ToIndex.get(str); |
|
504 |
dos.writeShort(s.shortValue()); |
|
505 |
if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); |
|
506 |
break; |
|
507 |
} |
|
508 |
||
509 |
// case JVM_CONSTANT_StringIndex: |
|
510 |
case JVM_CONSTANT_UnresolvedString: { |
|
511 |
dos.writeByte(JVM_CONSTANT_String); |
|
512 |
String val = getSymbolAt(ci).asString(); |
|
513 |
||
514 |
Short s = (Short) utf8ToIndex.get(val); |
|
515 |
dos.writeShort(s.shortValue()); |
|
516 |
if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); |
|
517 |
break; |
|
518 |
} |
|
519 |
||
520 |
// all external, internal method/field references |
|
521 |
case JVM_CONSTANT_Fieldref: |
|
522 |
case JVM_CONSTANT_Methodref: |
|
523 |
case JVM_CONSTANT_InterfaceMethodref: { |
|
524 |
dos.writeByte(cpConstType); |
|
525 |
int value = getIntAt(ci); |
|
526 |
short klassIndex = (short) extractLowShortFromInt(value); |
|
527 |
short nameAndTypeIndex = (short) extractHighShortFromInt(value); |
|
528 |
dos.writeShort(klassIndex); |
|
529 |
dos.writeShort(nameAndTypeIndex); |
|
530 |
if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " + |
|
531 |
klassIndex + ", N&T = " + nameAndTypeIndex); |
|
532 |
break; |
|
533 |
} |
|
534 |
||
535 |
case JVM_CONSTANT_NameAndType: { |
|
536 |
dos.writeByte(cpConstType); |
|
537 |
int value = getIntAt(ci); |
|
538 |
short nameIndex = (short) extractLowShortFromInt(value); |
|
539 |
short signatureIndex = (short) extractHighShortFromInt(value); |
|
540 |
dos.writeShort(nameIndex); |
|
541 |
dos.writeShort(signatureIndex); |
|
542 |
if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex |
|
543 |
+ ", type = " + signatureIndex); |
|
544 |
break; |
|
545 |
} |
|
5882 | 546 |
|
547 |
case JVM_CONSTANT_MethodHandle: { |
|
548 |
dos.writeByte(cpConstType); |
|
549 |
int value = getIntAt(ci); |
|
550 |
short nameIndex = (short) extractLowShortFromInt(value); |
|
551 |
short signatureIndex = (short) extractHighShortFromInt(value); |
|
552 |
dos.writeShort(nameIndex); |
|
553 |
dos.writeShort(signatureIndex); |
|
554 |
if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex |
|
555 |
+ ", type = " + signatureIndex); |
|
556 |
break; |
|
557 |
} |
|
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
558 |
|
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
559 |
case JVM_CONSTANT_InvokeDynamic: { |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
560 |
dos.writeByte(cpConstType); |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
561 |
int[] values = getMultiOperandsAt(ci); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
562 |
for (int vn = 0; vn < values.length; vn++) { |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
563 |
dos.writeShort(values[vn]); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
564 |
} |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
565 |
int bootstrapMethodIndex = values[INDY_BSM_OFFSET]; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
566 |
int nameAndTypeIndex = values[INDY_NT_OFFSET]; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
567 |
int argumentCount = values[INDY_ARGC_OFFSET]; |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
568 |
assert(INDY_ARGV_OFFSET + argumentCount == values.length); |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
569 |
if (DEBUG) debugMessage("CP[" + ci + "] = indy BSM = " + bootstrapMethodIndex |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
570 |
+ ", N&T = " + nameAndTypeIndex |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
571 |
+ ", argc = " + argumentCount); |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
572 |
break; |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
573 |
} |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
6062
diff
changeset
|
574 |
|
5341 | 575 |
default: |
576 |
throw new InternalError("unknown tag: " + cpConstType); |
|
1 | 577 |
} // switch |
578 |
} |
|
579 |
dos.flush(); |
|
580 |
return; |
|
581 |
} |
|
582 |
||
583 |
public void printValueOn(PrintStream tty) { |
|
584 |
tty.print("ConstantPool for " + getPoolHolder().getName().asString()); |
|
585 |
} |
|
586 |
||
587 |
public long getObjectSize() { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
588 |
return alignObjectSize(headerSize + (getLength() * getElementSize())); |
1 | 589 |
} |
590 |
||
591 |
//---------------------------------------------------------------------- |
|
592 |
// Internals only below this point |
|
593 |
// |
|
594 |
||
595 |
private static int extractHighShortFromInt(int val) { |
|
5882 | 596 |
// must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc. |
1 | 597 |
return (val >> 16) & 0xFFFF; |
598 |
} |
|
599 |
||
600 |
private static int extractLowShortFromInt(int val) { |
|
5882 | 601 |
// must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc. |
1 | 602 |
return val & 0xFFFF; |
603 |
} |
|
604 |
} |