annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 2011:dad31fc330cd

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