annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 4962:38fd165da001

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