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