annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 6725:da91efe96a93

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