Mercurial > hg > graal-jvmci-8
annotate agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.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 | 8150fa46d2ed |
children | 7a40901e0d5c |
rev | line source |
---|---|
0 | 1 /* |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools.jcore; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.oops.*; | |
30 import sun.jvm.hotspot.runtime.*; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
31 import sun.jvm.hotspot.utilities.*; |
0 | 32 |
33 public class ClassWriter implements /* imports */ ClassConstants | |
34 { | |
35 public static final boolean DEBUG = false; | |
36 | |
37 protected void debugMessage(String message) { | |
38 System.out.println(message); | |
39 } | |
40 | |
41 protected InstanceKlass klass; | |
42 protected DataOutputStream dos; | |
43 protected ConstantPool cpool; | |
44 | |
45 // Map between class name to index of type CONSTANT_Class | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
46 protected Map<String, Short> classToIndex = new HashMap<String, Short>(); |
0 | 47 |
48 // Map between any modified UTF-8 and it's constant pool index. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
49 protected Map<String, Short> utf8ToIndex = new HashMap<String, Short>(); |
0 | 50 |
51 // constant pool index for attribute names. | |
52 | |
53 protected short _sourceFileIndex; | |
54 protected short _innerClassesIndex; | |
55 protected short _syntheticIndex; | |
56 protected short _deprecatedIndex; | |
57 protected short _constantValueIndex; | |
58 protected short _codeIndex; | |
59 protected short _exceptionsIndex; | |
60 protected short _lineNumberTableIndex; | |
61 protected short _localVariableTableIndex; | |
62 protected short _signatureIndex; | |
63 | |
64 protected static int extractHighShortFromInt(int val) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
65 // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc. |
0 | 66 return (val >> 16) & 0xFFFF; |
67 } | |
68 | |
69 protected static int extractLowShortFromInt(int val) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
70 // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc. |
0 | 71 return val & 0xFFFF; |
72 } | |
73 | |
74 public ClassWriter(InstanceKlass kls, OutputStream os) { | |
75 klass = kls; | |
76 dos = new DataOutputStream(os); | |
77 cpool = klass.getConstants(); | |
78 } | |
79 | |
80 public void write() throws IOException { | |
81 if (DEBUG) debugMessage("class name = " + klass.getName().asString()); | |
82 | |
83 // write magic | |
84 dos.writeInt(0xCAFEBABE); | |
85 | |
705 | 86 writeVersion(); |
0 | 87 writeConstantPool(); |
88 writeClassAccessFlags(); | |
89 writeThisClass(); | |
90 writeSuperClass(); | |
91 writeInterfaces(); | |
92 writeFields(); | |
93 writeMethods(); | |
94 writeClassAttributes(); | |
95 | |
96 // flush output | |
97 dos.flush(); | |
98 } | |
99 | |
705 | 100 protected void writeVersion() throws IOException { |
101 dos.writeShort((short)klass.minorVersion()); | |
102 dos.writeShort((short)klass.majorVersion()); | |
0 | 103 } |
104 | |
705 | 105 protected void writeIndex(int index) throws IOException { |
106 if (index == 0) throw new InternalError(); | |
107 dos.writeShort(index); | |
0 | 108 } |
109 | |
110 protected void writeConstantPool() throws IOException { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
111 final U1Array tags = cpool.getTags(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
112 final long len = tags.length(); |
0 | 113 dos.writeShort((short) len); |
114 | |
115 if (DEBUG) debugMessage("constant pool length = " + len); | |
116 | |
117 int ci = 0; // constant pool index | |
118 | |
119 // collect all modified UTF-8 Strings from Constant Pool | |
120 | |
121 for (ci = 1; ci < len; ci++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
122 int cpConstType = tags.at(ci); |
0 | 123 if(cpConstType == JVM_CONSTANT_Utf8) { |
124 Symbol sym = cpool.getSymbolAt(ci); | |
125 utf8ToIndex.put(sym.asString(), new Short((short) ci)); | |
126 } | |
127 else if(cpConstType == JVM_CONSTANT_Long || | |
128 cpConstType == JVM_CONSTANT_Double) { | |
129 ci++; | |
130 } | |
131 } | |
132 | |
133 // remember index of attribute name modified UTF-8 strings | |
134 | |
135 // class attributes | |
136 Short sourceFileIndex = (Short) utf8ToIndex.get("SourceFile"); | |
137 _sourceFileIndex = (sourceFileIndex != null)? sourceFileIndex.shortValue() : 0; | |
138 if (DEBUG) debugMessage("SourceFile index = " + _sourceFileIndex); | |
139 | |
140 Short innerClassesIndex = (Short) utf8ToIndex.get("InnerClasses"); | |
141 _innerClassesIndex = (innerClassesIndex != null)? innerClassesIndex.shortValue() : 0; | |
142 if (DEBUG) debugMessage("InnerClasses index = " + _innerClassesIndex); | |
143 | |
144 // field attributes | |
145 Short constantValueIndex = (Short) utf8ToIndex.get("ConstantValue"); | |
146 _constantValueIndex = (constantValueIndex != null)? | |
147 constantValueIndex.shortValue() : 0; | |
148 if (DEBUG) debugMessage("ConstantValue index = " + _constantValueIndex); | |
149 | |
150 Short syntheticIndex = (Short) utf8ToIndex.get("Synthetic"); | |
151 _syntheticIndex = (syntheticIndex != null)? syntheticIndex.shortValue() : 0; | |
152 if (DEBUG) debugMessage("Synthetic index = " + _syntheticIndex); | |
153 | |
154 Short deprecatedIndex = (Short) utf8ToIndex.get("Deprecated"); | |
155 _deprecatedIndex = (deprecatedIndex != null)? deprecatedIndex.shortValue() : 0; | |
156 if (DEBUG) debugMessage("Deprecated index = " + _deprecatedIndex); | |
157 | |
158 // method attributes | |
159 Short codeIndex = (Short) utf8ToIndex.get("Code"); | |
160 _codeIndex = (codeIndex != null)? codeIndex.shortValue() : 0; | |
161 if (DEBUG) debugMessage("Code index = " + _codeIndex); | |
162 | |
163 Short exceptionsIndex = (Short) utf8ToIndex.get("Exceptions"); | |
164 _exceptionsIndex = (exceptionsIndex != null)? exceptionsIndex.shortValue() : 0; | |
165 if (DEBUG) debugMessage("Exceptions index = " + _exceptionsIndex); | |
166 | |
167 // Short syntheticIndex = (Short) utf8ToIndex.get("Synthetic"); | |
168 // Short deprecatedIndex = (Short) utf8ToIndex.get("Deprecated"); | |
169 | |
170 // Code attributes | |
171 Short lineNumberTableIndex = (Short) utf8ToIndex.get("LineNumberTable"); | |
172 _lineNumberTableIndex = (lineNumberTableIndex != null)? | |
173 lineNumberTableIndex.shortValue() : 0; | |
174 if (DEBUG) debugMessage("LineNumberTable index = " + _lineNumberTableIndex); | |
175 | |
176 Short localVariableTableIndex = (Short) utf8ToIndex.get("LocalVariableTable"); | |
177 _localVariableTableIndex = (localVariableTableIndex != null)? | |
178 localVariableTableIndex.shortValue() : 0; | |
179 if (DEBUG) debugMessage("LocalVariableTable index = " + _localVariableTableIndex); | |
180 | |
181 Short signatureIdx = (Short) utf8ToIndex.get("Signature"); | |
182 _signatureIndex = (signatureIdx != null)? signatureIdx.shortValue() : 0; | |
183 if (DEBUG) debugMessage("Signature index = " + _signatureIndex); | |
184 | |
185 for(ci = 1; ci < len; ci++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
186 int cpConstType = tags.at(ci); |
0 | 187 // write cp_info |
188 // write constant type | |
189 switch(cpConstType) { | |
190 case JVM_CONSTANT_Utf8: { | |
191 dos.writeByte(cpConstType); | |
192 Symbol sym = cpool.getSymbolAt(ci); | |
193 dos.writeShort((short)sym.getLength()); | |
194 dos.write(sym.asByteArray()); | |
195 if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); | |
196 break; | |
197 } | |
198 | |
199 case JVM_CONSTANT_Unicode: | |
200 throw new IllegalArgumentException("Unicode constant!"); | |
201 | |
202 case JVM_CONSTANT_Integer: | |
203 dos.writeByte(cpConstType); | |
204 dos.writeInt(cpool.getIntAt(ci)); | |
205 if (DEBUG) debugMessage("CP[" + ci + "] = int " + cpool.getIntAt(ci)); | |
206 break; | |
207 | |
208 case JVM_CONSTANT_Float: | |
209 dos.writeByte(cpConstType); | |
210 dos.writeFloat(cpool.getFloatAt(ci)); | |
211 if (DEBUG) debugMessage("CP[" + ci + "] = float " + cpool.getFloatAt(ci)); | |
212 break; | |
213 | |
214 case JVM_CONSTANT_Long: { | |
215 dos.writeByte(cpConstType); | |
216 long l = cpool.getLongAt(ci); | |
217 // long entries occupy two pool entries | |
218 ci++; | |
219 dos.writeLong(l); | |
220 break; | |
221 } | |
222 | |
223 case JVM_CONSTANT_Double: | |
224 dos.writeByte(cpConstType); | |
225 dos.writeDouble(cpool.getDoubleAt(ci)); | |
226 // double entries occupy two pool entries | |
227 ci++; | |
228 break; | |
229 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
230 case JVM_CONSTANT_Class: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
231 case JVM_CONSTANT_UnresolvedClass: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
232 case JVM_CONSTANT_UnresolvedClassInError: { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
233 dos.writeByte(JVM_CONSTANT_Class); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
234 String klassName = cpool.getKlassNameAt(ci).asString(); |
0 | 235 Short s = (Short) utf8ToIndex.get(klassName); |
236 classToIndex.put(klassName, new Short((short)ci)); | |
237 dos.writeShort(s.shortValue()); | |
238 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | |
239 break; | |
240 } | |
241 | |
242 case JVM_CONSTANT_String: { | |
243 dos.writeByte(cpConstType); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
244 String str = cpool.getUnresolvedStringAt(ci).asString(); |
0 | 245 Short s = (Short) utf8ToIndex.get(str); |
246 dos.writeShort(s.shortValue()); | |
247 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | |
248 break; | |
249 } | |
250 | |
251 // all external, internal method/field references | |
252 case JVM_CONSTANT_Fieldref: | |
253 case JVM_CONSTANT_Methodref: | |
254 case JVM_CONSTANT_InterfaceMethodref: { | |
255 dos.writeByte(cpConstType); | |
256 int value = cpool.getIntAt(ci); | |
257 short klassIndex = (short) extractLowShortFromInt(value); | |
258 short nameAndTypeIndex = (short) extractHighShortFromInt(value); | |
259 dos.writeShort(klassIndex); | |
260 dos.writeShort(nameAndTypeIndex); | |
261 if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " + | |
262 klassIndex + ", N&T = " + nameAndTypeIndex); | |
263 break; | |
264 } | |
265 | |
266 case JVM_CONSTANT_NameAndType: { | |
267 dos.writeByte(cpConstType); | |
268 int value = cpool.getIntAt(ci); | |
269 short nameIndex = (short) extractLowShortFromInt(value); | |
270 short signatureIndex = (short) extractHighShortFromInt(value); | |
271 dos.writeShort(nameIndex); | |
272 dos.writeShort(signatureIndex); | |
273 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex | |
274 + ", type = " + signatureIndex); | |
275 break; | |
276 } | |
1602 | 277 |
278 case JVM_CONSTANT_MethodHandle: { | |
279 dos.writeByte(cpConstType); | |
280 int value = cpool.getIntAt(ci); | |
1917
f42a2f0c16bb
6996563: 6984311 changes forgot to update vmStructs.cpp for new field _operands
jrose
parents:
1913
diff
changeset
|
281 byte refKind = (byte) extractLowShortFromInt(value); |
f42a2f0c16bb
6996563: 6984311 changes forgot to update vmStructs.cpp for new field _operands
jrose
parents:
1913
diff
changeset
|
282 short memberIndex = (short) extractHighShortFromInt(value); |
f42a2f0c16bb
6996563: 6984311 changes forgot to update vmStructs.cpp for new field _operands
jrose
parents:
1913
diff
changeset
|
283 dos.writeByte(refKind); |
f42a2f0c16bb
6996563: 6984311 changes forgot to update vmStructs.cpp for new field _operands
jrose
parents:
1913
diff
changeset
|
284 dos.writeShort(memberIndex); |
f42a2f0c16bb
6996563: 6984311 changes forgot to update vmStructs.cpp for new field _operands
jrose
parents:
1913
diff
changeset
|
285 if (DEBUG) debugMessage("CP[" + ci + "] = MH kind = " + |
f42a2f0c16bb
6996563: 6984311 changes forgot to update vmStructs.cpp for new field _operands
jrose
parents:
1913
diff
changeset
|
286 refKind + ", mem = " + memberIndex); |
1602 | 287 break; |
288 } | |
289 | |
290 case JVM_CONSTANT_MethodType: { | |
291 dos.writeByte(cpConstType); | |
292 int value = cpool.getIntAt(ci); | |
293 short refIndex = (short) value; | |
294 dos.writeShort(refIndex); | |
295 if (DEBUG) debugMessage("CP[" + ci + "] = MT index = " + refIndex); | |
296 break; | |
297 } | |
298 | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
299 case JVM_CONSTANT_InvokeDynamic: { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
300 dos.writeByte(cpConstType); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
301 int value = cpool.getIntAt(ci); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
302 short bsmIndex = (short) extractLowShortFromInt(value); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
303 short nameAndTypeIndex = (short) extractHighShortFromInt(value); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
304 dos.writeShort(bsmIndex); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
305 dos.writeShort(nameAndTypeIndex); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
306 if (DEBUG) debugMessage("CP[" + ci + "] = INDY bsm = " + |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1917
diff
changeset
|
307 bsmIndex + ", N&T = " + nameAndTypeIndex); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
308 break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
309 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
310 |
1385 | 311 default: |
312 throw new InternalError("Unknown tag: " + cpConstType); | |
0 | 313 } // switch |
314 } | |
315 } | |
316 | |
317 protected void writeClassAccessFlags() throws IOException { | |
318 int flags = (int)(klass.getAccessFlags() & JVM_RECOGNIZED_CLASS_MODIFIERS); | |
319 dos.writeShort((short)flags); | |
320 } | |
321 | |
322 protected void writeThisClass() throws IOException { | |
323 String klassName = klass.getName().asString(); | |
324 Short index = (Short) classToIndex.get(klassName); | |
325 dos.writeShort(index.shortValue()); | |
326 if (DEBUG) debugMessage("this class = " + index); | |
327 } | |
328 | |
329 protected void writeSuperClass() throws IOException { | |
330 Klass superKlass = klass.getSuper(); | |
331 if (superKlass != null) { // is not java.lang.Object | |
332 String superName = superKlass.getName().asString(); | |
333 Short index = (Short) classToIndex.get(superName); | |
334 if (DEBUG) debugMessage("super class = " + index); | |
335 dos.writeShort(index.shortValue()); | |
336 } else { | |
337 dos.writeShort(0); // no super class | |
338 } | |
339 } | |
340 protected void writeInterfaces() throws IOException { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
341 KlassArray interfaces = klass.getLocalInterfaces(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
342 final int len = interfaces.length(); |
0 | 343 |
344 if (DEBUG) debugMessage("number of interfaces = " + len); | |
345 | |
346 // write interfaces count | |
347 dos.writeShort((short) len); | |
348 for (int i = 0; i < len; i++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
349 Klass k = interfaces.getAt(i); |
0 | 350 Short index = (Short) classToIndex.get(k.getName().asString()); |
351 dos.writeShort(index.shortValue()); | |
352 if (DEBUG) debugMessage("\t" + index); | |
353 } | |
354 } | |
355 | |
356 protected void writeFields() throws IOException { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
357 U2Array fields = klass.getFields(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
358 final int length = (int) fields.length(); |
0 | 359 |
360 // write number of fields | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
361 dos.writeShort((short) length); |
0 | 362 |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
363 if (DEBUG) debugMessage("number of fields = " + length); |
0 | 364 |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
365 for (int index = 0; index < length; index++) { |
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
366 short accessFlags = klass.getFieldAccessFlags(index); |
0 | 367 dos.writeShort(accessFlags & (short) JVM_RECOGNIZED_FIELD_MODIFIERS); |
368 | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
369 short nameIndex = klass.getFieldNameIndex(index); |
0 | 370 dos.writeShort(nameIndex); |
371 | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
372 short signatureIndex = klass.getFieldSignatureIndex(index); |
0 | 373 dos.writeShort(signatureIndex); |
374 if (DEBUG) debugMessage("\tfield name = " + nameIndex + ", signature = " + signatureIndex); | |
375 | |
376 short fieldAttributeCount = 0; | |
705 | 377 boolean hasSyn = hasSyntheticAttribute(accessFlags); |
378 if (hasSyn) | |
0 | 379 fieldAttributeCount++; |
380 | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
381 short initvalIndex = klass.getFieldInitialValueIndex(index); |
0 | 382 if (initvalIndex != 0) |
383 fieldAttributeCount++; | |
384 | |
3962
cb315dc80374
7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents:
3938
diff
changeset
|
385 short genSigIndex = klass.getFieldGenericSignatureIndex(index); |
0 | 386 if (genSigIndex != 0) |
387 fieldAttributeCount++; | |
388 | |
389 dos.writeShort(fieldAttributeCount); | |
390 | |
391 // write synthetic, if applicable | |
705 | 392 if (hasSyn) |
0 | 393 writeSynthetic(); |
394 | |
395 if (initvalIndex != 0) { | |
705 | 396 writeIndex(_constantValueIndex); |
0 | 397 dos.writeInt(2); |
398 dos.writeShort(initvalIndex); | |
399 if (DEBUG) debugMessage("\tfield init value = " + initvalIndex); | |
400 } | |
401 | |
402 if (genSigIndex != 0) { | |
705 | 403 writeIndex(_signatureIndex); |
0 | 404 dos.writeInt(2); |
405 dos.writeShort(genSigIndex); | |
406 if (DEBUG) debugMessage("\tfield generic signature index " + genSigIndex); | |
407 } | |
408 } | |
409 } | |
410 | |
411 protected boolean isSynthetic(short accessFlags) { | |
412 return (accessFlags & (short) JVM_ACC_SYNTHETIC) != 0; | |
413 } | |
414 | |
705 | 415 protected boolean hasSyntheticAttribute(short accessFlags) { |
416 // Check if flags have the attribute and if the constant pool contains an entry for it. | |
417 return isSynthetic(accessFlags) && _syntheticIndex != 0; | |
418 } | |
419 | |
0 | 420 protected void writeSynthetic() throws IOException { |
705 | 421 writeIndex(_syntheticIndex); |
0 | 422 dos.writeInt(0); |
423 } | |
424 | |
425 protected void writeMethods() throws IOException { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
426 MethodArray methods = klass.getMethods(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
427 final int len = methods.length(); |
0 | 428 // write number of methods |
429 dos.writeShort((short) len); | |
430 if (DEBUG) debugMessage("number of methods = " + len); | |
431 for (int m = 0; m < len; m++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
432 writeMethod(methods.at(m)); |
0 | 433 } |
434 } | |
435 | |
436 protected void writeMethod(Method m) throws IOException { | |
437 long accessFlags = m.getAccessFlags(); | |
438 dos.writeShort((short) (accessFlags & JVM_RECOGNIZED_METHOD_MODIFIERS)); | |
439 dos.writeShort((short) m.getNameIndex()); | |
440 dos.writeShort((short) m.getSignatureIndex()); | |
441 if (DEBUG) debugMessage("\tmethod name = " + m.getNameIndex() + ", signature = " | |
442 + m.getSignatureIndex()); | |
443 | |
444 final boolean isNative = ((accessFlags & JVM_ACC_NATIVE) != 0); | |
445 final boolean isAbstract = ((accessFlags & JVM_ACC_ABSTRACT) != 0); | |
446 | |
447 short methodAttributeCount = 0; | |
448 | |
705 | 449 final boolean hasSyn = hasSyntheticAttribute((short)accessFlags); |
450 if (hasSyn) | |
0 | 451 methodAttributeCount++; |
452 | |
453 final boolean hasCheckedExceptions = m.hasCheckedExceptions(); | |
454 if (hasCheckedExceptions) | |
455 methodAttributeCount++; | |
456 | |
457 final boolean isCodeAvailable = (!isNative) && (!isAbstract); | |
458 if (isCodeAvailable) | |
459 methodAttributeCount++; | |
460 | |
461 final boolean isGeneric = (m.getGenericSignature() != null); | |
462 if (isGeneric) | |
463 methodAttributeCount++; | |
464 | |
465 dos.writeShort(methodAttributeCount); | |
466 if (DEBUG) debugMessage("\tmethod attribute count = " + methodAttributeCount); | |
467 | |
705 | 468 if (hasSyn) { |
0 | 469 if (DEBUG) debugMessage("\tmethod is synthetic"); |
470 writeSynthetic(); | |
471 } | |
472 | |
473 if (isCodeAvailable) { | |
474 byte[] code = m.getByteCode(); | |
475 short codeAttrCount = 0; | |
476 int codeSize = 2 /* max_stack */ + | |
477 2 /* max_locals */ + | |
478 4 /* code_length */ + | |
479 code.length /* code */ + | |
480 2 /* exp. table len. */ + | |
481 2 /* code attr. count */; | |
482 | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
483 boolean hasExceptionTable = m.hasExceptionTable(); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
484 ExceptionTableElement[] exceptionTable = null; |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
485 int exceptionTableLen = 0; |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
486 if (hasExceptionTable) { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
487 exceptionTable = m.getExceptionTable(); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
488 exceptionTableLen = exceptionTable.length; |
0 | 489 if (DEBUG) debugMessage("\tmethod has exception table"); |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
490 codeSize += exceptionTableLen /* exception table is 4-tuple array */ |
0 | 491 * (2 /* start_pc */ + |
492 2 /* end_pc */ + | |
493 2 /* handler_pc */ + | |
494 2 /* catch_type */); | |
495 } | |
496 | |
497 boolean hasLineNumberTable = m.hasLineNumberTable(); | |
498 LineNumberTableElement[] lineNumberTable = null; | |
499 int lineNumberAttrLen = 0; | |
500 | |
501 if (hasLineNumberTable) { | |
502 if (DEBUG) debugMessage("\tmethod has line number table"); | |
503 lineNumberTable = m.getLineNumberTable(); | |
504 if (DEBUG) debugMessage("\t\tline table length = " + lineNumberTable.length); | |
505 | |
506 lineNumberAttrLen = 2 /* line number table length */ + | |
507 lineNumberTable.length * (2 /* start_pc */ + 2 /* line_number */); | |
508 | |
509 codeSize += 2 /* line number table attr index */ + | |
510 4 /* line number table attr length */ + | |
511 lineNumberAttrLen; | |
512 | |
513 if (DEBUG) debugMessage("\t\tline number table attr size = " + | |
514 lineNumberAttrLen); | |
515 | |
516 codeAttrCount++; | |
517 } | |
518 | |
519 boolean hasLocalVariableTable = m.hasLocalVariableTable(); | |
520 LocalVariableTableElement[] localVariableTable = null; | |
521 int localVarAttrLen = 0; | |
522 | |
523 if (hasLocalVariableTable) { | |
524 if (DEBUG) debugMessage("\tmethod has local variable table"); | |
525 localVariableTable = m.getLocalVariableTable(); | |
526 if (DEBUG) debugMessage("\t\tlocal variable table length = " | |
527 + localVariableTable.length); | |
528 localVarAttrLen = | |
529 2 /* local variable table length */ + | |
530 localVariableTable.length * ( 2 /* start_pc */ + | |
531 2 /* length */ + | |
532 2 /* name_index */ + | |
533 2 /* signature_index */ + | |
534 2 /* variable index */ ); | |
535 | |
536 if (DEBUG) debugMessage("\t\tlocal variable attr size = " + | |
537 localVarAttrLen); | |
538 | |
539 codeSize += 2 /* local variable table attr index */ + | |
540 4 /* local variable table attr length */ + | |
541 localVarAttrLen; | |
542 | |
543 codeAttrCount++; | |
544 } | |
545 | |
546 // fix ConstantPoolCache indices to ConstantPool indices. | |
547 rewriteByteCode(m, code); | |
548 | |
549 // start writing Code | |
550 | |
705 | 551 writeIndex(_codeIndex); |
0 | 552 |
553 dos.writeInt(codeSize); | |
554 if (DEBUG) debugMessage("\tcode attribute length = " + codeSize); | |
555 | |
556 dos.writeShort((short) m.getMaxStack()); | |
557 if (DEBUG) debugMessage("\tmax stack = " + m.getMaxStack()); | |
558 | |
559 dos.writeShort((short) m.getMaxLocals()); | |
560 if (DEBUG) debugMessage("\tmax locals = " + m.getMaxLocals()); | |
561 | |
562 dos.writeInt(code.length); | |
563 if (DEBUG) debugMessage("\tcode size = " + code.length); | |
564 | |
565 dos.write(code); | |
566 | |
567 // write exception table size | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
568 dos.writeShort((short) exceptionTableLen); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
569 if (DEBUG) debugMessage("\texception table length = " + exceptionTableLen); |
0 | 570 |
571 if (exceptionTableLen != 0) { | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
572 for (int e = 0; e < exceptionTableLen; e++) { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
573 dos.writeShort((short) exceptionTable[e].getStartPC()); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
574 dos.writeShort((short) exceptionTable[e].getEndPC()); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
575 dos.writeShort((short) exceptionTable[e].getHandlerPC()); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
3962
diff
changeset
|
576 dos.writeShort((short) exceptionTable[e].getCatchTypeIndex()); |
0 | 577 } |
578 } | |
579 | |
580 dos.writeShort((short)codeAttrCount); | |
581 if (DEBUG) debugMessage("\tcode attribute count = " + codeAttrCount); | |
582 | |
583 // write LineNumberTable, if available. | |
584 if (hasLineNumberTable) { | |
705 | 585 writeIndex(_lineNumberTableIndex); |
0 | 586 dos.writeInt(lineNumberAttrLen); |
587 dos.writeShort((short) lineNumberTable.length); | |
588 for (int l = 0; l < lineNumberTable.length; l++) { | |
589 dos.writeShort((short) lineNumberTable[l].getStartBCI()); | |
590 dos.writeShort((short) lineNumberTable[l].getLineNumber()); | |
591 } | |
592 } | |
593 | |
594 // write LocalVariableTable, if available. | |
595 if (hasLocalVariableTable) { | |
705 | 596 writeIndex((short) _localVariableTableIndex); |
0 | 597 dos.writeInt(localVarAttrLen); |
598 dos.writeShort((short) localVariableTable.length); | |
599 for (int l = 0; l < localVariableTable.length; l++) { | |
600 dos.writeShort((short) localVariableTable[l].getStartBCI()); | |
601 dos.writeShort((short) localVariableTable[l].getLength()); | |
602 dos.writeShort((short) localVariableTable[l].getNameCPIndex()); | |
603 dos.writeShort((short) localVariableTable[l].getDescriptorCPIndex()); | |
604 dos.writeShort((short) localVariableTable[l].getSlot()); | |
605 } | |
606 } | |
607 } | |
608 | |
705 | 609 if (hasCheckedExceptions) { |
610 CheckedExceptionElement[] exceptions = m.getCheckedExceptions(); | |
611 writeIndex(_exceptionsIndex); | |
612 | |
613 int attrSize = 2 /* number_of_exceptions */ + | |
614 exceptions.length * 2 /* exception_index */; | |
615 dos.writeInt(attrSize); | |
616 dos.writeShort(exceptions.length); | |
617 if (DEBUG) debugMessage("\tmethod has " + exceptions.length | |
618 + " checked exception(s)"); | |
619 for (int e = 0; e < exceptions.length; e++) { | |
620 short cpIndex = (short) exceptions[e].getClassCPIndex(); | |
621 dos.writeShort(cpIndex); | |
622 } | |
623 } | |
624 | |
0 | 625 if (isGeneric) { |
626 writeGenericSignature(m.getGenericSignature().asString()); | |
627 } | |
628 } | |
629 | |
630 protected void rewriteByteCode(Method m, byte[] code) { | |
631 ByteCodeRewriter r = new ByteCodeRewriter(m, cpool, code); | |
632 r.rewrite(); | |
633 } | |
634 | |
635 protected void writeGenericSignature(String signature) throws IOException { | |
705 | 636 writeIndex(_signatureIndex); |
0 | 637 if (DEBUG) debugMessage("signature attribute = " + _signatureIndex); |
638 dos.writeInt(2); | |
639 Short index = (Short) utf8ToIndex.get(signature); | |
640 dos.writeShort(index.shortValue()); | |
641 if (DEBUG) debugMessage("generic signature = " + index); | |
642 } | |
643 | |
644 protected void writeClassAttributes() throws IOException { | |
645 final long flags = klass.getAccessFlags(); | |
705 | 646 final boolean hasSyn = hasSyntheticAttribute((short) flags); |
0 | 647 |
648 // check for source file | |
649 short classAttributeCount = 0; | |
650 | |
705 | 651 if (hasSyn) |
0 | 652 classAttributeCount++; |
653 | |
654 Symbol sourceFileName = klass.getSourceFileName(); | |
655 if (sourceFileName != null) | |
656 classAttributeCount++; | |
657 | |
658 Symbol genericSignature = klass.getGenericSignature(); | |
659 if (genericSignature != null) | |
660 classAttributeCount++; | |
661 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
662 U2Array innerClasses = klass.getInnerClasses(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
663 final int numInnerClasses = (int) (innerClasses.length() / 4); |
0 | 664 if (numInnerClasses != 0) |
665 classAttributeCount++; | |
666 | |
667 dos.writeShort(classAttributeCount); | |
668 if (DEBUG) debugMessage("class attribute count = " + classAttributeCount); | |
669 | |
705 | 670 if (hasSyn) |
0 | 671 writeSynthetic(); |
672 | |
673 // write SourceFile, if any | |
674 if (sourceFileName != null) { | |
705 | 675 writeIndex(_sourceFileIndex); |
0 | 676 if (DEBUG) debugMessage("source file attribute = " + _sourceFileIndex); |
677 dos.writeInt(2); | |
678 Short index = (Short) utf8ToIndex.get(sourceFileName.asString()); | |
679 dos.writeShort(index.shortValue()); | |
680 if (DEBUG) debugMessage("source file name = " + index); | |
681 } | |
682 | |
683 // write Signature, if any | |
684 if (genericSignature != null) { | |
685 writeGenericSignature(genericSignature.asString()); | |
686 } | |
687 | |
688 // write inner classes, if any | |
689 if (numInnerClasses != 0) { | |
705 | 690 writeIndex(_innerClassesIndex); |
0 | 691 final int innerAttrLen = 2 /* number_of_inner_classes */ + |
692 numInnerClasses * ( | |
693 2 /* inner_class_info_index */ + | |
694 2 /* outer_class_info_index */ + | |
695 2 /* inner_class_name_index */ + | |
696 2 /* inner_class_access_flags */); | |
697 dos.writeInt(innerAttrLen); | |
698 | |
699 dos.writeShort(numInnerClasses); | |
700 if (DEBUG) debugMessage("class has " + numInnerClasses + " inner class entries"); | |
701 | |
702 for (int index = 0; index < numInnerClasses * 4; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6213
diff
changeset
|
703 dos.writeShort(innerClasses.at(index)); |
0 | 704 } |
705 } | |
706 } | |
707 } |