Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 18665:96861e3f8cc5
made CFGPrinterObserver reset (upon close) properly
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 11 Dec 2014 22:14:30 +0100 |
parents | 4ca6dc0799b6 |
children | 7848fc12602b |
rev | line source |
---|---|
0 | 1 /* |
14909 | 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
21 * questions. |
0 | 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 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
34 // A ConstantPool is an oop containing class constants |
0 | 35 // as described in the class file |
36 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
37 public class ConstantPool extends Metadata implements ClassConstants { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
38 public class CPSlot { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
39 private Address ptr; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
40 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
41 CPSlot(Address ptr) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
42 this.ptr = ptr; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
43 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
44 CPSlot(Symbol sym) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
45 this.ptr = sym.getAddress().orWithMask(1); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
46 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
47 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
48 public boolean isResolved() { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
49 return (ptr.minus(null) & 1) == 0; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
50 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
51 public boolean isUnresolved() { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
52 return (ptr.minus(null) & 1) == 1; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
53 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
54 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
55 public Symbol getSymbol() { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
56 if (!isUnresolved()) throw new InternalError("not a symbol"); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
57 return Symbol.create(ptr.xorWithMask(1)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
58 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
59 public Klass getKlass() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
60 if (!isResolved()) throw new InternalError("not klass"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
61 return (Klass)Metadata.instantiateWrapperFor(ptr); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
62 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
63 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
64 |
0 | 65 // Used for debugging this code |
66 private static final boolean DEBUG = false; | |
67 | |
68 protected void debugMessage(String message) { | |
69 System.out.println(message); | |
70 } | |
71 | |
72 static { | |
73 VM.registerVMInitializedObserver(new Observer() { | |
74 public void update(Observable o, Object data) { | |
75 initialize(VM.getVM().getTypeDataBase()); | |
76 } | |
77 }); | |
78 } | |
79 | |
80 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
81 Type type = db.lookupType("ConstantPool"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
82 tags = type.getAddressField("_tags"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
83 operands = type.getAddressField("_operands"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
84 cache = type.getAddressField("_cache"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
85 poolHolder = new MetadataField(type.getAddressField("_pool_holder"), 0); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
86 length = new CIntField(type.getCIntegerField("_length"), 0); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
87 resolvedReferences = type.getAddressField("_resolved_references"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
88 referenceMap = type.getAddressField("_reference_map"); |
0 | 89 headerSize = type.getSize(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
90 elementSize = 0; |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
91 // fetch constants: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
92 INDY_BSM_OFFSET = db.lookupIntConstant("ConstantPool::_indy_bsm_offset").intValue(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
93 INDY_ARGC_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argc_offset").intValue(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
94 INDY_ARGV_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argv_offset").intValue(); |
0 | 95 } |
96 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
97 public ConstantPool(Address addr) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
98 super(addr); |
0 | 99 } |
100 | |
101 public boolean isConstantPool() { return true; } | |
102 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
103 private static AddressField tags; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
104 private static AddressField operands; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
105 private static AddressField cache; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
106 private static MetadataField poolHolder; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
107 private static CIntField length; // number of elements in oop |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
108 private static AddressField resolvedReferences; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
109 private static AddressField referenceMap; |
0 | 110 |
111 private static long headerSize; | |
112 private static long elementSize; | |
113 | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
114 private static int INDY_BSM_OFFSET; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
115 private static int INDY_ARGC_OFFSET; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
116 private static int INDY_ARGV_OFFSET; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
117 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
118 public U1Array getTags() { return new U1Array(tags.getValue(getAddress())); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
119 public U2Array getOperands() { return new U2Array(operands.getValue(getAddress())); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
120 public ConstantPoolCache getCache() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
121 Address addr = cache.getValue(getAddress()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
122 return (ConstantPoolCache) VMObjectFactory.newObject(ConstantPoolCache.class, addr); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
123 } |
6940
18fb7da42534
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
6725
diff
changeset
|
124 public InstanceKlass getPoolHolder() { return (InstanceKlass)poolHolder.getValue(this); } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
125 public int getLength() { return (int)length.getValue(getAddress()); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
126 public Oop getResolvedReferences() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
127 Address handle = resolvedReferences.getValue(getAddress()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
128 if (handle != null) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
129 // Load through the handle |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
130 OopHandle refs = handle.getOopHandleAt(0); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
131 return VM.getVM().getObjectHeap().newOop(refs); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
132 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
133 return null; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
134 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
135 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
136 public U2Array referenceMap() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
137 return new U2Array(referenceMap.getValue(getAddress())); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
138 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
139 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
140 public int objectToCPIndex(int index) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
141 return referenceMap().at(index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
142 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
143 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
144 private long getElementSize() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
145 if (elementSize !=0 ) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
146 return elementSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
147 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
148 elementSize = VM.getVM().getOopSize(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
149 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
150 return elementSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
151 } |
0 | 152 |
153 private long indexOffset(long index) { | |
154 if (Assert.ASSERTS_ENABLED) { | |
14909 | 155 Assert.that(index > 0 && index < getLength(), "invalid cp index " + index + " " + getLength()); |
0 | 156 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
157 return (index * getElementSize()) + headerSize; |
0 | 158 } |
159 | |
160 public ConstantTag getTagAt(long index) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
161 return new ConstantTag((byte)getTags().at((int) index)); |
0 | 162 } |
163 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
164 public CPSlot getSlotAt(long index) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
165 return new CPSlot(getAddressAtRaw(index)); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
166 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2011
diff
changeset
|
167 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
168 public Address getAddressAtRaw(long index) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
169 return getAddress().getAddressAt(indexOffset(index)); |
0 | 170 } |
171 | |
172 public Symbol getSymbolAt(long index) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
173 return Symbol.create(getAddressAtRaw(index)); |
0 | 174 } |
175 | |
176 public int getIntAt(long index){ | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
177 return getAddress().getJIntAt(indexOffset(index)); |
0 | 178 } |
179 | |
180 public float getFloatAt(long index){ | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
181 return getAddress().getJFloatAt(indexOffset(index)); |
0 | 182 } |
183 | |
184 public long getLongAt(long index) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
185 int oneHalf = getAddress().getJIntAt(indexOffset(index + 1)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
186 int otherHalf = getAddress().getJIntAt(indexOffset(index)); |
0 | 187 // buildLongFromIntsPD accepts higher address value, lower address value |
188 // in that order. | |
189 return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf); | |
190 } | |
191 | |
192 public double getDoubleAt(long index) { | |
193 return Double.longBitsToDouble(getLongAt(index)); | |
194 } | |
195 | |
196 public int getFieldOrMethodAt(int which) { | |
197 if (DEBUG) { | |
198 System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = "); | |
199 } | |
200 int i = -1; | |
201 ConstantPoolCache cache = getCache(); | |
202 if (cache == null) { | |
203 i = which; | |
204 } else { | |
205 // change byte-ordering and go via cache | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
206 i = cache.getEntryAt(0xFFFF & which).getConstantPoolIndex(); |
0 | 207 } |
208 if (Assert.ASSERTS_ENABLED) { | |
209 Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool"); | |
210 } | |
211 if (DEBUG) { | |
212 System.err.println(i); | |
213 } | |
214 int res = getIntAt(i); | |
215 if (DEBUG) { | |
216 System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res); | |
217 } | |
218 return res; | |
219 } | |
220 | |
1602 | 221 public int[] getNameAndTypeAt(int which) { |
0 | 222 if (Assert.ASSERTS_ENABLED) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
223 Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool: " + which + " " + getTagAt(which)); |
0 | 224 } |
225 int i = getIntAt(which); | |
226 if (DEBUG) { | |
227 System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i); | |
228 } | |
1602 | 229 return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) }; |
0 | 230 } |
231 | |
232 public Symbol getNameRefAt(int which) { | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
233 return implGetNameRefAt(which, false); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
234 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
235 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
236 public Symbol uncachedGetNameRefAt(int which) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
237 return implGetNameRefAt(which, true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
238 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
239 |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
240 private Symbol implGetNameRefAt(int which, boolean uncached) { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
241 int signatureIndex = getNameRefIndexAt(implNameAndTypeRefIndexAt(which, uncached)); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
242 return getSymbolAt(signatureIndex); |
0 | 243 } |
244 | |
245 public Symbol getSignatureRefAt(int which) { | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
246 return implGetSignatureRefAt(which, false); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
247 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
248 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
249 public Symbol uncachedGetSignatureRefAt(int which) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
250 return implGetSignatureRefAt(which, true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
251 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
252 |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
253 private Symbol implGetSignatureRefAt(int which, boolean uncached) { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
254 int signatureIndex = getSignatureRefIndexAt(implNameAndTypeRefIndexAt(which, uncached)); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
255 return getSymbolAt(signatureIndex); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
256 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
257 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
258 public static boolean isInvokedynamicIndex(int i) { return (i < 0); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
259 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
260 public static int decodeInvokedynamicIndex(int i) { Assert.that(isInvokedynamicIndex(i), ""); return ~i; } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
261 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
262 // The invokedynamic points at the object index. The object map points at |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
263 // the cpCache index and the cpCache entry points at the original constant |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
264 // pool index. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
265 public int invokedynamicCPCacheIndex(int index) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
266 Assert.that(isInvokedynamicIndex(index), "should be a invokedynamic index"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
267 int rawIndex = decodeInvokedynamicIndex(index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
268 return referenceMap().at(rawIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
269 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
270 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
271 ConstantPoolCacheEntry invokedynamicCPCacheEntryAt(int index) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
272 // decode index that invokedynamic points to. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
273 int cpCacheIndex = invokedynamicCPCacheIndex(index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
274 return getCache().getEntryAt(cpCacheIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
275 } |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
276 |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
277 private int implNameAndTypeRefIndexAt(int which, boolean uncached) { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
278 int i = which; |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
279 if (!uncached && getCache() != null) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
280 if (isInvokedynamicIndex(which)) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
281 // Invokedynamic index is index into resolved_references |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
282 int poolIndex = invokedynamicCPCacheEntryAt(which).getConstantPoolIndex(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
283 poolIndex = invokeDynamicNameAndTypeRefIndexAt(poolIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
284 Assert.that(getTagAt(poolIndex).isNameAndType(), ""); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
285 return poolIndex; |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
286 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
287 // change byte-ordering and go via cache |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
288 i = remapInstructionOperandFromCache(which); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
289 } else { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
290 if (getTagAt(which).isInvokeDynamic()) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
291 int poolIndex = invokeDynamicNameAndTypeRefIndexAt(which); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
292 Assert.that(getTagAt(poolIndex).isNameAndType(), ""); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
293 return poolIndex; |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
294 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
295 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
296 // assert(tag_at(i).is_field_or_method(), "Corrupted constant pool"); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
297 // assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above"); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
298 int refIndex = getIntAt(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
299 return extractHighShortFromInt(refIndex); |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
300 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
301 |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
302 private int remapInstructionOperandFromCache(int operand) { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
303 int cpc_index = operand; |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
304 // DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
305 // assert((int)(u2)cpc_index == cpc_index, "clean u2"); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
306 int member_index = getCache().getEntryAt(cpc_index).getConstantPoolIndex(); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
307 return member_index; |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
308 } |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
309 |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
310 int invokeDynamicNameAndTypeRefIndexAt(int which) { |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
311 // assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); |
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
312 return extractHighShortFromInt(getIntAt(which)); |
0 | 313 } |
314 | |
315 // returns null, if not resolved. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
316 public Klass getKlassAt(int which) { |
0 | 317 if( ! getTagAt(which).isKlass()) return null; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
318 return (Klass)Metadata.instantiateWrapperFor(getAddressAtRaw(which)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
319 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
320 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
321 public Symbol getKlassNameAt(int which) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
322 CPSlot entry = getSlotAt(which); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
323 if (entry.isResolved()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
324 return entry.getKlass().getName(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
325 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
326 return entry.getSymbol(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
327 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
328 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
329 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
330 public Symbol getUnresolvedStringAt(int which) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
331 return getSymbolAt(which); |
0 | 332 } |
333 | |
334 // returns null, if not resolved. | |
335 public InstanceKlass getFieldOrMethodKlassRefAt(int which) { | |
336 int refIndex = getFieldOrMethodAt(which); | |
337 int klassIndex = extractLowShortFromInt(refIndex); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
338 return (InstanceKlass) getKlassAt(klassIndex); |
0 | 339 } |
340 | |
341 // returns null, if not resolved. | |
342 public Method getMethodRefAt(int which) { | |
343 InstanceKlass klass = getFieldOrMethodKlassRefAt(which); | |
344 if (klass == null) return null; | |
345 Symbol name = getNameRefAt(which); | |
346 Symbol sig = getSignatureRefAt(which); | |
347 return klass.findMethod(name, sig); | |
348 } | |
349 | |
350 // returns null, if not resolved. | |
351 public Field getFieldRefAt(int which) { | |
352 InstanceKlass klass = getFieldOrMethodKlassRefAt(which); | |
353 if (klass == null) return null; | |
354 Symbol name = getNameRefAt(which); | |
355 Symbol sig = getSignatureRefAt(which); | |
356 return klass.findField(name, sig); | |
357 } | |
358 | |
359 public int getNameAndTypeRefIndexAt(int index) { | |
3838
6a991dcb52bb
7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents:
2468
diff
changeset
|
360 return implNameAndTypeRefIndexAt(index, false); |
0 | 361 } |
362 | |
363 /** Lookup for entries consisting of (name_index, signature_index) */ | |
364 public int getNameRefIndexAt(int index) { | |
1602 | 365 int[] refIndex = getNameAndTypeAt(index); |
0 | 366 if (DEBUG) { |
1602 | 367 System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]); |
0 | 368 } |
1602 | 369 int i = refIndex[0]; |
0 | 370 if (DEBUG) { |
371 System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): result = " + i); | |
372 } | |
373 return i; | |
374 } | |
375 | |
376 /** Lookup for entries consisting of (name_index, signature_index) */ | |
377 public int getSignatureRefIndexAt(int index) { | |
1602 | 378 int[] refIndex = getNameAndTypeAt(index); |
0 | 379 if (DEBUG) { |
1602 | 380 System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]); |
0 | 381 } |
1602 | 382 int i = refIndex[1]; |
0 | 383 if (DEBUG) { |
384 System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): result = " + i); | |
385 } | |
386 return i; | |
387 } | |
388 | |
1602 | 389 /** Lookup for MethodHandle entries. */ |
390 public int getMethodHandleIndexAt(int i) { | |
391 if (Assert.ASSERTS_ENABLED) { | |
392 Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool"); | |
393 } | |
394 int res = extractHighShortFromInt(getIntAt(i)); | |
395 if (DEBUG) { | |
396 System.err.println("ConstantPool.getMethodHandleIndexAt(" + i + "): result = " + res); | |
397 } | |
398 return res; | |
399 } | |
400 | |
401 /** Lookup for MethodHandle entries. */ | |
402 public int getMethodHandleRefKindAt(int i) { | |
403 if (Assert.ASSERTS_ENABLED) { | |
404 Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool"); | |
405 } | |
406 int res = extractLowShortFromInt(getIntAt(i)); | |
407 if (DEBUG) { | |
408 System.err.println("ConstantPool.getMethodHandleRefKindAt(" + i + "): result = " + res); | |
409 } | |
410 return res; | |
411 } | |
412 | |
413 /** Lookup for MethodType entries. */ | |
414 public int getMethodTypeIndexAt(int i) { | |
415 if (Assert.ASSERTS_ENABLED) { | |
416 Assert.that(getTagAt(i).isMethodType(), "Corrupted constant pool"); | |
417 } | |
418 int res = getIntAt(i); | |
419 if (DEBUG) { | |
420 System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res); | |
421 } | |
422 return res; | |
423 } | |
424 | |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
425 /** Lookup for multi-operand (InvokeDynamic) entries. */ |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
426 public short[] getBootstrapSpecifierAt(int i) { |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
427 if (Assert.ASSERTS_ENABLED) { |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
428 Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool"); |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
429 } |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
430 int bsmSpec = extractLowShortFromInt(this.getIntAt(i)); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
431 U2Array operands = getOperands(); |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
432 if (operands == null) return null; // safety first |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
433 int basePos = VM.getVM().buildIntFromShorts(operands.at(bsmSpec * 2 + 0), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
434 operands.at(bsmSpec * 2 + 1)); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
435 int argv = basePos + INDY_ARGV_OFFSET; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
436 int argc = operands.at(basePos + INDY_ARGC_OFFSET); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
437 int endPos = argv + argc; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
438 short[] values = new short[endPos - basePos]; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
439 for (int j = 0; j < values.length; j++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
440 values[j] = operands.at(basePos+j); |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
441 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
442 return values; |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
443 } |
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
444 |
0 | 445 final private static String[] nameForTag = new String[] { |
446 }; | |
447 | |
448 private String nameForTag(int tag) { | |
449 switch (tag) { | |
450 case JVM_CONSTANT_Utf8: return "JVM_CONSTANT_Utf8"; | |
451 case JVM_CONSTANT_Unicode: return "JVM_CONSTANT_Unicode"; | |
452 case JVM_CONSTANT_Integer: return "JVM_CONSTANT_Integer"; | |
453 case JVM_CONSTANT_Float: return "JVM_CONSTANT_Float"; | |
454 case JVM_CONSTANT_Long: return "JVM_CONSTANT_Long"; | |
455 case JVM_CONSTANT_Double: return "JVM_CONSTANT_Double"; | |
456 case JVM_CONSTANT_Class: return "JVM_CONSTANT_Class"; | |
457 case JVM_CONSTANT_String: return "JVM_CONSTANT_String"; | |
458 case JVM_CONSTANT_Fieldref: return "JVM_CONSTANT_Fieldref"; | |
459 case JVM_CONSTANT_Methodref: return "JVM_CONSTANT_Methodref"; | |
460 case JVM_CONSTANT_InterfaceMethodref: return "JVM_CONSTANT_InterfaceMethodref"; | |
461 case JVM_CONSTANT_NameAndType: return "JVM_CONSTANT_NameAndType"; | |
1602 | 462 case JVM_CONSTANT_MethodHandle: return "JVM_CONSTANT_MethodHandle"; |
463 case JVM_CONSTANT_MethodType: return "JVM_CONSTANT_MethodType"; | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
464 case JVM_CONSTANT_InvokeDynamic: return "JVM_CONSTANT_InvokeDynamic"; |
0 | 465 case JVM_CONSTANT_Invalid: return "JVM_CONSTANT_Invalid"; |
466 case JVM_CONSTANT_UnresolvedClass: return "JVM_CONSTANT_UnresolvedClass"; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
467 case JVM_CONSTANT_ClassIndex: return "JVM_CONSTANT_ClassIndex"; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
468 case JVM_CONSTANT_StringIndex: return "JVM_CONSTANT_StringIndex"; |
1385 | 469 case JVM_CONSTANT_UnresolvedClassInError: return "JVM_CONSTANT_UnresolvedClassInError"; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
470 case JVM_CONSTANT_MethodHandleInError:return "JVM_CONSTANT_MethodHandleInError"; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
471 case JVM_CONSTANT_MethodTypeInError: return "JVM_CONSTANT_MethodTypeInError"; |
0 | 472 } |
1385 | 473 throw new InternalError("Unknown tag: " + tag); |
0 | 474 } |
475 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
476 public void iterateFields(MetadataVisitor visitor) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
477 super.iterateFields(visitor); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
478 visitor.doMetadata(poolHolder, true); |
0 | 479 |
480 final int length = (int) getLength(); | |
481 // zero'th pool entry is always invalid. ignore it. | |
482 for (int index = 1; index < length; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
483 int ctag = (int) getTags().at((int) index); |
0 | 484 switch (ctag) { |
485 case JVM_CONSTANT_ClassIndex: | |
486 case JVM_CONSTANT_StringIndex: | |
487 case JVM_CONSTANT_Integer: | |
488 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
489 break; | |
490 | |
491 case JVM_CONSTANT_Float: | |
492 visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
493 break; | |
494 | |
495 case JVM_CONSTANT_Long: | |
496 visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
497 // long entries occupy two slots | |
498 index++; | |
499 break; | |
500 | |
501 case JVM_CONSTANT_Double: | |
502 visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
503 // double entries occupy two slots | |
504 index++; | |
505 break; | |
506 | |
1385 | 507 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 508 case JVM_CONSTANT_UnresolvedClass: |
509 case JVM_CONSTANT_Class: | |
510 case JVM_CONSTANT_Utf8: | |
511 visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
512 break; | |
513 | |
514 case JVM_CONSTANT_Fieldref: | |
515 case JVM_CONSTANT_Methodref: | |
516 case JVM_CONSTANT_InterfaceMethodref: | |
517 case JVM_CONSTANT_NameAndType: | |
1602 | 518 case JVM_CONSTANT_MethodHandle: |
519 case JVM_CONSTANT_MethodType: | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
520 case JVM_CONSTANT_InvokeDynamic: |
0 | 521 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
522 break; | |
523 } | |
524 } | |
525 } | |
526 | |
527 public void writeBytes(OutputStream os) throws IOException { | |
528 // Map between any modified UTF-8 and it's constant pool index. | |
529 Map utf8ToIndex = new HashMap(); | |
530 DataOutputStream dos = new DataOutputStream(os); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
531 U1Array tags = getTags(); |
0 | 532 int len = (int)getLength(); |
533 int ci = 0; // constant pool index | |
534 | |
535 // collect all modified UTF-8 Strings from Constant Pool | |
536 | |
537 for (ci = 1; ci < len; ci++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
538 int cpConstType = tags.at(ci); |
0 | 539 if(cpConstType == JVM_CONSTANT_Utf8) { |
540 Symbol sym = getSymbolAt(ci); | |
541 utf8ToIndex.put(sym.asString(), new Short((short) ci)); | |
542 } | |
543 else if(cpConstType == JVM_CONSTANT_Long || | |
544 cpConstType == JVM_CONSTANT_Double) { | |
545 ci++; | |
546 } | |
547 } | |
548 | |
549 | |
550 for(ci = 1; ci < len; ci++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
551 int cpConstType = tags.at(ci); |
0 | 552 // write cp_info |
553 // write constant type | |
554 switch(cpConstType) { | |
555 case JVM_CONSTANT_Utf8: { | |
556 dos.writeByte(cpConstType); | |
557 Symbol sym = getSymbolAt(ci); | |
558 dos.writeShort((short)sym.getLength()); | |
559 dos.write(sym.asByteArray()); | |
560 if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); | |
561 break; | |
562 } | |
563 | |
564 case JVM_CONSTANT_Unicode: | |
565 throw new IllegalArgumentException("Unicode constant!"); | |
566 | |
567 case JVM_CONSTANT_Integer: | |
568 dos.writeByte(cpConstType); | |
569 dos.writeInt(getIntAt(ci)); | |
570 if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci)); | |
571 break; | |
572 | |
573 case JVM_CONSTANT_Float: | |
574 dos.writeByte(cpConstType); | |
575 dos.writeFloat(getFloatAt(ci)); | |
576 if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci)); | |
577 break; | |
578 | |
579 case JVM_CONSTANT_Long: { | |
580 dos.writeByte(cpConstType); | |
581 long l = getLongAt(ci); | |
582 // long entries occupy two pool entries | |
583 ci++; | |
584 dos.writeLong(l); | |
585 break; | |
586 } | |
587 | |
588 case JVM_CONSTANT_Double: | |
589 dos.writeByte(cpConstType); | |
590 dos.writeDouble(getDoubleAt(ci)); | |
591 // double entries occupy two pool entries | |
592 ci++; | |
593 break; | |
594 | |
595 case JVM_CONSTANT_Class: { | |
596 dos.writeByte(cpConstType); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
597 // Klass already resolved. ConstantPool constains Klass*. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
598 Klass refKls = (Klass)Metadata.instantiateWrapperFor(getAddressAtRaw(ci)); |
0 | 599 String klassName = refKls.getName().asString(); |
600 Short s = (Short) utf8ToIndex.get(klassName); | |
601 dos.writeShort(s.shortValue()); | |
602 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
603 break; | |
604 } | |
605 | |
606 // case JVM_CONSTANT_ClassIndex: | |
1385 | 607 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 608 case JVM_CONSTANT_UnresolvedClass: { |
609 dos.writeByte(JVM_CONSTANT_Class); | |
610 String klassName = getSymbolAt(ci).asString(); | |
611 Short s = (Short) utf8ToIndex.get(klassName); | |
612 dos.writeShort(s.shortValue()); | |
613 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
614 break; | |
615 } | |
616 | |
617 case JVM_CONSTANT_String: { | |
618 dos.writeByte(cpConstType); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
619 String str = getUnresolvedStringAt(ci).asString(); |
0 | 620 Short s = (Short) utf8ToIndex.get(str); |
621 dos.writeShort(s.shortValue()); | |
622 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
623 break; | |
624 } | |
625 | |
626 // all external, internal method/field references | |
627 case JVM_CONSTANT_Fieldref: | |
628 case JVM_CONSTANT_Methodref: | |
629 case JVM_CONSTANT_InterfaceMethodref: { | |
630 dos.writeByte(cpConstType); | |
631 int value = getIntAt(ci); | |
632 short klassIndex = (short) extractLowShortFromInt(value); | |
633 short nameAndTypeIndex = (short) extractHighShortFromInt(value); | |
634 dos.writeShort(klassIndex); | |
635 dos.writeShort(nameAndTypeIndex); | |
636 if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " + | |
637 klassIndex + ", N&T = " + nameAndTypeIndex); | |
638 break; | |
639 } | |
640 | |
641 case JVM_CONSTANT_NameAndType: { | |
642 dos.writeByte(cpConstType); | |
643 int value = getIntAt(ci); | |
644 short nameIndex = (short) extractLowShortFromInt(value); | |
645 short signatureIndex = (short) extractHighShortFromInt(value); | |
646 dos.writeShort(nameIndex); | |
647 dos.writeShort(signatureIndex); | |
648 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
649 + ", type = " + signatureIndex); | |
650 break; | |
651 } | |
1602 | 652 |
653 case JVM_CONSTANT_MethodHandle: { | |
654 dos.writeByte(cpConstType); | |
655 int value = getIntAt(ci); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
656 byte refKind = (byte) extractLowShortFromInt(value); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
657 short memberIndex = (short) extractHighShortFromInt(value); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
658 dos.writeByte(refKind); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
659 dos.writeShort(memberIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
660 if (DEBUG) debugMessage("CP[" + ci + "] = MH kind = " + |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
661 refKind + ", mem = " + memberIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
662 break; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
663 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
664 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
665 case JVM_CONSTANT_MethodType: { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
666 dos.writeByte(cpConstType); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
667 int value = getIntAt(ci); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
668 short refIndex = (short) value; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
669 dos.writeShort(refIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
670 if (DEBUG) debugMessage("CP[" + ci + "] = MT index = " + refIndex); |
1602 | 671 break; |
672 } | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
673 |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
674 case JVM_CONSTANT_InvokeDynamic: { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
675 dos.writeByte(cpConstType); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
676 int value = getIntAt(ci); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
677 short bsmIndex = (short) extractLowShortFromInt(value); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
678 short nameAndTypeIndex = (short) extractHighShortFromInt(value); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
679 dos.writeShort(bsmIndex); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
680 dos.writeShort(nameAndTypeIndex); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
681 if (DEBUG) debugMessage("CP[" + ci + "] = INDY bsm = " + |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
682 bsmIndex + ", N&T = " + nameAndTypeIndex); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
683 break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
684 } |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
685 |
1385 | 686 default: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
687 throw new InternalError("Unknown tag: " + cpConstType); |
0 | 688 } // switch |
689 } | |
690 dos.flush(); | |
691 return; | |
692 } | |
693 | |
694 public void printValueOn(PrintStream tty) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
695 tty.print("ConstantPool for " + getPoolHolder().getName().asString()); |
0 | 696 } |
697 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
698 public long getSize() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
699 return Oop.alignObjectSize(headerSize + getLength()); |
0 | 700 } |
701 | |
702 //---------------------------------------------------------------------- | |
703 // Internals only below this point | |
704 // | |
705 | |
706 private static int extractHighShortFromInt(int val) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
707 // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc. |
0 | 708 return (val >> 16) & 0xFFFF; |
709 } | |
710 | |
711 private static int extractLowShortFromInt(int val) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
712 // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc. |
0 | 713 return val & 0xFFFF; |
714 } | |
715 } |