Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 6940:18fb7da42534
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
Summary: Change types of above methods and field to InstanceKlass and remove unneeded casts from the source files.
Reviewed-by: dholmes, coleenp, zgu
Contributed-by: harold.seigel@oracle.com
author | coleenp |
---|---|
date | Tue, 06 Nov 2012 15:09:37 -0500 |
parents | da91efe96a93 |
children | f16e75e0cf11 |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
2 * Copyright (c) 2000, 2012, 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) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
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"; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
472 case JVM_CONSTANT_Object: return "JVM_CONSTANT_Object"; |
0 | 473 } |
1385 | 474 throw new InternalError("Unknown tag: " + tag); |
0 | 475 } |
476 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
477 public void iterateFields(MetadataVisitor visitor) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
478 super.iterateFields(visitor); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
479 visitor.doMetadata(poolHolder, true); |
0 | 480 |
481 final int length = (int) getLength(); | |
482 // zero'th pool entry is always invalid. ignore it. | |
483 for (int index = 1; index < length; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
484 int ctag = (int) getTags().at((int) index); |
0 | 485 switch (ctag) { |
486 case JVM_CONSTANT_ClassIndex: | |
487 case JVM_CONSTANT_StringIndex: | |
488 case JVM_CONSTANT_Integer: | |
489 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
490 break; | |
491 | |
492 case JVM_CONSTANT_Float: | |
493 visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
494 break; | |
495 | |
496 case JVM_CONSTANT_Long: | |
497 visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
498 // long entries occupy two slots | |
499 index++; | |
500 break; | |
501 | |
502 case JVM_CONSTANT_Double: | |
503 visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
504 // double entries occupy two slots | |
505 index++; | |
506 break; | |
507 | |
1385 | 508 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 509 case JVM_CONSTANT_UnresolvedClass: |
510 case JVM_CONSTANT_Class: | |
511 case JVM_CONSTANT_Utf8: | |
512 visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); | |
513 break; | |
514 | |
515 case JVM_CONSTANT_Fieldref: | |
516 case JVM_CONSTANT_Methodref: | |
517 case JVM_CONSTANT_InterfaceMethodref: | |
518 case JVM_CONSTANT_NameAndType: | |
1602 | 519 case JVM_CONSTANT_MethodHandle: |
520 case JVM_CONSTANT_MethodType: | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
521 case JVM_CONSTANT_InvokeDynamic: |
0 | 522 visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); |
523 break; | |
524 } | |
525 } | |
526 } | |
527 | |
528 public void writeBytes(OutputStream os) throws IOException { | |
529 // Map between any modified UTF-8 and it's constant pool index. | |
530 Map utf8ToIndex = new HashMap(); | |
531 DataOutputStream dos = new DataOutputStream(os); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
532 U1Array tags = getTags(); |
0 | 533 int len = (int)getLength(); |
534 int ci = 0; // constant pool index | |
535 | |
536 // collect all modified UTF-8 Strings from Constant Pool | |
537 | |
538 for (ci = 1; ci < len; ci++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
539 int cpConstType = tags.at(ci); |
0 | 540 if(cpConstType == JVM_CONSTANT_Utf8) { |
541 Symbol sym = getSymbolAt(ci); | |
542 utf8ToIndex.put(sym.asString(), new Short((short) ci)); | |
543 } | |
544 else if(cpConstType == JVM_CONSTANT_Long || | |
545 cpConstType == JVM_CONSTANT_Double) { | |
546 ci++; | |
547 } | |
548 } | |
549 | |
550 | |
551 for(ci = 1; ci < len; ci++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
552 int cpConstType = tags.at(ci); |
0 | 553 // write cp_info |
554 // write constant type | |
555 switch(cpConstType) { | |
556 case JVM_CONSTANT_Utf8: { | |
557 dos.writeByte(cpConstType); | |
558 Symbol sym = getSymbolAt(ci); | |
559 dos.writeShort((short)sym.getLength()); | |
560 dos.write(sym.asByteArray()); | |
561 if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); | |
562 break; | |
563 } | |
564 | |
565 case JVM_CONSTANT_Unicode: | |
566 throw new IllegalArgumentException("Unicode constant!"); | |
567 | |
568 case JVM_CONSTANT_Integer: | |
569 dos.writeByte(cpConstType); | |
570 dos.writeInt(getIntAt(ci)); | |
571 if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci)); | |
572 break; | |
573 | |
574 case JVM_CONSTANT_Float: | |
575 dos.writeByte(cpConstType); | |
576 dos.writeFloat(getFloatAt(ci)); | |
577 if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci)); | |
578 break; | |
579 | |
580 case JVM_CONSTANT_Long: { | |
581 dos.writeByte(cpConstType); | |
582 long l = getLongAt(ci); | |
583 // long entries occupy two pool entries | |
584 ci++; | |
585 dos.writeLong(l); | |
586 break; | |
587 } | |
588 | |
589 case JVM_CONSTANT_Double: | |
590 dos.writeByte(cpConstType); | |
591 dos.writeDouble(getDoubleAt(ci)); | |
592 // double entries occupy two pool entries | |
593 ci++; | |
594 break; | |
595 | |
596 case JVM_CONSTANT_Class: { | |
597 dos.writeByte(cpConstType); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
598 // Klass already resolved. ConstantPool constains Klass*. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
599 Klass refKls = (Klass)Metadata.instantiateWrapperFor(getAddressAtRaw(ci)); |
0 | 600 String klassName = refKls.getName().asString(); |
601 Short s = (Short) utf8ToIndex.get(klassName); | |
602 dos.writeShort(s.shortValue()); | |
603 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
604 break; | |
605 } | |
606 | |
607 // case JVM_CONSTANT_ClassIndex: | |
1385 | 608 case JVM_CONSTANT_UnresolvedClassInError: |
0 | 609 case JVM_CONSTANT_UnresolvedClass: { |
610 dos.writeByte(JVM_CONSTANT_Class); | |
611 String klassName = getSymbolAt(ci).asString(); | |
612 Short s = (Short) utf8ToIndex.get(klassName); | |
613 dos.writeShort(s.shortValue()); | |
614 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
615 break; | |
616 } | |
617 | |
618 case JVM_CONSTANT_String: { | |
619 dos.writeByte(cpConstType); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
620 String str = getUnresolvedStringAt(ci).asString(); |
0 | 621 Short s = (Short) utf8ToIndex.get(str); |
622 dos.writeShort(s.shortValue()); | |
623 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
624 break; | |
625 } | |
626 | |
627 // all external, internal method/field references | |
628 case JVM_CONSTANT_Fieldref: | |
629 case JVM_CONSTANT_Methodref: | |
630 case JVM_CONSTANT_InterfaceMethodref: { | |
631 dos.writeByte(cpConstType); | |
632 int value = getIntAt(ci); | |
633 short klassIndex = (short) extractLowShortFromInt(value); | |
634 short nameAndTypeIndex = (short) extractHighShortFromInt(value); | |
635 dos.writeShort(klassIndex); | |
636 dos.writeShort(nameAndTypeIndex); | |
637 if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " + | |
638 klassIndex + ", N&T = " + nameAndTypeIndex); | |
639 break; | |
640 } | |
641 | |
642 case JVM_CONSTANT_NameAndType: { | |
643 dos.writeByte(cpConstType); | |
644 int value = getIntAt(ci); | |
645 short nameIndex = (short) extractLowShortFromInt(value); | |
646 short signatureIndex = (short) extractHighShortFromInt(value); | |
647 dos.writeShort(nameIndex); | |
648 dos.writeShort(signatureIndex); | |
649 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
650 + ", type = " + signatureIndex); | |
651 break; | |
652 } | |
1602 | 653 |
654 case JVM_CONSTANT_MethodHandle: { | |
655 dos.writeByte(cpConstType); | |
656 int value = getIntAt(ci); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
657 byte refKind = (byte) extractLowShortFromInt(value); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
658 short memberIndex = (short) extractHighShortFromInt(value); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
659 dos.writeByte(refKind); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
660 dos.writeShort(memberIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
661 if (DEBUG) debugMessage("CP[" + ci + "] = MH kind = " + |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
662 refKind + ", mem = " + memberIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
663 break; |
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 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
666 case JVM_CONSTANT_MethodType: { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
667 dos.writeByte(cpConstType); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
668 int value = getIntAt(ci); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
669 short refIndex = (short) value; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
670 dos.writeShort(refIndex); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
671 if (DEBUG) debugMessage("CP[" + ci + "] = MT index = " + refIndex); |
1602 | 672 break; |
673 } | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
674 |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
675 case JVM_CONSTANT_InvokeDynamic: { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 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
|
680 dos.writeShort(bsmIndex); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1913
diff
changeset
|
681 dos.writeShort(nameAndTypeIndex); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
682 if (DEBUG) debugMessage("CP[" + ci + "] = INDY bsm = " + |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
683 bsmIndex + ", N&T = " + nameAndTypeIndex); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
684 break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
685 } |
1913
3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
1660
diff
changeset
|
686 |
1385 | 687 default: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
688 throw new InternalError("Unknown tag: " + cpConstType); |
0 | 689 } // switch |
690 } | |
691 dos.flush(); | |
692 return; | |
693 } | |
694 | |
695 public void printValueOn(PrintStream tty) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
696 tty.print("ConstantPool for " + getPoolHolder().getName().asString()); |
0 | 697 } |
698 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
699 public long getSize() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
700 return Oop.alignObjectSize(headerSize + getLength()); |
0 | 701 } |
702 | |
703 //---------------------------------------------------------------------- | |
704 // Internals only below this point | |
705 // | |
706 | |
707 private static int extractHighShortFromInt(int val) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
708 // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc. |
0 | 709 return (val >> 16) & 0xFFFF; |
710 } | |
711 | |
712 private static int extractLowShortFromInt(int val) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4962
diff
changeset
|
713 // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc. |
0 | 714 return val & 0xFFFF; |
715 } | |
716 } |