annotate agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java @ 17587:561045d22599 jdk8u11-b07

Added tag jdk8u11-b06 for changeset b73ee2b9027c
author katleman
date Tue, 29 Apr 2014 12:51:45 -0700
parents 7a40901e0d5c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
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.tools.jcore;
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.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class ClassWriter implements /* imports */ ClassConstants
a61af66fc99e Initial load
duke
parents:
diff changeset
34 {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public static final boolean DEBUG = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 protected void debugMessage(String message) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 System.out.println(message);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 protected InstanceKlass klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 protected DataOutputStream dos;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 protected ConstantPool cpool;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // constant pool index for attribute names.
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 protected short _sourceFileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 protected short _innerClassesIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 protected short _syntheticIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 protected short _deprecatedIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 protected short _constantValueIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 protected short _codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 protected short _exceptionsIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 protected short _lineNumberTableIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 protected short _localVariableTableIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 protected short _signatureIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return (val >> 16) & 0xFFFF;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return val & 0xFFFF;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public ClassWriter(InstanceKlass kls, OutputStream os) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 klass = kls;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 dos = new DataOutputStream(os);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 cpool = klass.getConstants();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public void write() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (DEBUG) debugMessage("class name = " + klass.getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // write magic
a61af66fc99e Initial load
duke
parents:
diff changeset
84 dos.writeInt(0xCAFEBABE);
a61af66fc99e Initial load
duke
parents:
diff changeset
85
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
86 writeVersion();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87 writeConstantPool();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 writeClassAccessFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 writeThisClass();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 writeSuperClass();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 writeInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 writeFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 writeMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 writeClassAttributes();
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // flush output
a61af66fc99e Initial load
duke
parents:
diff changeset
97 dos.flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
100 protected void writeVersion() throws IOException {
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
101 dos.writeShort((short)klass.minorVersion());
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
102 dos.writeShort((short)klass.majorVersion());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
105 protected void writeIndex(int index) throws IOException {
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
106 if (index == 0) throw new InternalError();
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
107 dos.writeShort(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
113 dos.writeShort((short) len);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (DEBUG) debugMessage("constant pool length = " + len);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 int ci = 0; // constant pool index
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // collect all modified UTF-8 Strings from Constant Pool
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if(cpConstType == JVM_CONSTANT_Utf8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 Symbol sym = cpool.getSymbolAt(ci);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 utf8ToIndex.put(sym.asString(), new Short((short) ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 else if(cpConstType == JVM_CONSTANT_Long ||
a61af66fc99e Initial load
duke
parents:
diff changeset
128 cpConstType == JVM_CONSTANT_Double) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ci++;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // remember index of attribute name modified UTF-8 strings
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // class attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
136 Short sourceFileIndex = (Short) utf8ToIndex.get("SourceFile");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 _sourceFileIndex = (sourceFileIndex != null)? sourceFileIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (DEBUG) debugMessage("SourceFile index = " + _sourceFileIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 Short innerClassesIndex = (Short) utf8ToIndex.get("InnerClasses");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _innerClassesIndex = (innerClassesIndex != null)? innerClassesIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (DEBUG) debugMessage("InnerClasses index = " + _innerClassesIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // field attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Short constantValueIndex = (Short) utf8ToIndex.get("ConstantValue");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 _constantValueIndex = (constantValueIndex != null)?
a61af66fc99e Initial load
duke
parents:
diff changeset
147 constantValueIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (DEBUG) debugMessage("ConstantValue index = " + _constantValueIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 Short syntheticIndex = (Short) utf8ToIndex.get("Synthetic");
a61af66fc99e Initial load
duke
parents:
diff changeset
151 _syntheticIndex = (syntheticIndex != null)? syntheticIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (DEBUG) debugMessage("Synthetic index = " + _syntheticIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 Short deprecatedIndex = (Short) utf8ToIndex.get("Deprecated");
a61af66fc99e Initial load
duke
parents:
diff changeset
155 _deprecatedIndex = (deprecatedIndex != null)? deprecatedIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (DEBUG) debugMessage("Deprecated index = " + _deprecatedIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // method attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
159 Short codeIndex = (Short) utf8ToIndex.get("Code");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 _codeIndex = (codeIndex != null)? codeIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (DEBUG) debugMessage("Code index = " + _codeIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 Short exceptionsIndex = (Short) utf8ToIndex.get("Exceptions");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 _exceptionsIndex = (exceptionsIndex != null)? exceptionsIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (DEBUG) debugMessage("Exceptions index = " + _exceptionsIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Short syntheticIndex = (Short) utf8ToIndex.get("Synthetic");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Short deprecatedIndex = (Short) utf8ToIndex.get("Deprecated");
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Code attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Short lineNumberTableIndex = (Short) utf8ToIndex.get("LineNumberTable");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 _lineNumberTableIndex = (lineNumberTableIndex != null)?
a61af66fc99e Initial load
duke
parents:
diff changeset
173 lineNumberTableIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (DEBUG) debugMessage("LineNumberTable index = " + _lineNumberTableIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 Short localVariableTableIndex = (Short) utf8ToIndex.get("LocalVariableTable");
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _localVariableTableIndex = (localVariableTableIndex != null)?
a61af66fc99e Initial load
duke
parents:
diff changeset
178 localVariableTableIndex.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (DEBUG) debugMessage("LocalVariableTable index = " + _localVariableTableIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 Short signatureIdx = (Short) utf8ToIndex.get("Signature");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 _signatureIndex = (signatureIdx != null)? signatureIdx.shortValue() : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (DEBUG) debugMessage("Signature index = " + _signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // write cp_info
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // write constant type
a61af66fc99e Initial load
duke
parents:
diff changeset
189 switch(cpConstType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 case JVM_CONSTANT_Utf8: {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 Symbol sym = cpool.getSymbolAt(ci);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 dos.writeShort((short)sym.getLength());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 dos.write(sym.asByteArray());
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
196 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 case JVM_CONSTANT_Unicode:
a61af66fc99e Initial load
duke
parents:
diff changeset
200 throw new IllegalArgumentException("Unicode constant!");
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 case JVM_CONSTANT_Integer:
a61af66fc99e Initial load
duke
parents:
diff changeset
203 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 dos.writeInt(cpool.getIntAt(ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (DEBUG) debugMessage("CP[" + ci + "] = int " + cpool.getIntAt(ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
206 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 case JVM_CONSTANT_Float:
a61af66fc99e Initial load
duke
parents:
diff changeset
209 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 dos.writeFloat(cpool.getFloatAt(ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (DEBUG) debugMessage("CP[" + ci + "] = float " + cpool.getFloatAt(ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
212 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 case JVM_CONSTANT_Long: {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 long l = cpool.getLongAt(ci);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // long entries occupy two pool entries
a61af66fc99e Initial load
duke
parents:
diff changeset
218 ci++;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 dos.writeLong(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 case JVM_CONSTANT_Double:
a61af66fc99e Initial load
duke
parents:
diff changeset
224 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 dos.writeDouble(cpool.getDoubleAt(ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // double entries occupy two pool entries
a61af66fc99e Initial load
duke
parents:
diff changeset
227 ci++;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
235 Short s = (Short) utf8ToIndex.get(klassName);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 classToIndex.put(klassName, new Short((short)ci));
a61af66fc99e Initial load
duke
parents:
diff changeset
237 dos.writeShort(s.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 case JVM_CONSTANT_String: {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
245 Short s = (Short) utf8ToIndex.get(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 dos.writeShort(s.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // all external, internal method/field references
a61af66fc99e Initial load
duke
parents:
diff changeset
252 case JVM_CONSTANT_Fieldref:
a61af66fc99e Initial load
duke
parents:
diff changeset
253 case JVM_CONSTANT_Methodref:
a61af66fc99e Initial load
duke
parents:
diff changeset
254 case JVM_CONSTANT_InterfaceMethodref: {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 int value = cpool.getIntAt(ci);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 short klassIndex = (short) extractLowShortFromInt(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 short nameAndTypeIndex = (short) extractHighShortFromInt(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 dos.writeShort(klassIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 dos.writeShort(nameAndTypeIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " +
a61af66fc99e Initial load
duke
parents:
diff changeset
262 klassIndex + ", N&T = " + nameAndTypeIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 case JVM_CONSTANT_NameAndType: {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 dos.writeByte(cpConstType);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 int value = cpool.getIntAt(ci);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 short nameIndex = (short) extractLowShortFromInt(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 short signatureIndex = (short) extractHighShortFromInt(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 dos.writeShort(nameIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 dos.writeShort(signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex
a61af66fc99e Initial load
duke
parents:
diff changeset
274 + ", type = " + signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
277
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
278 case JVM_CONSTANT_MethodHandle: {
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
279 dos.writeByte(cpConstType);
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
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
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
287 break;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
288 }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
289
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
290 case JVM_CONSTANT_MethodType: {
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
291 dos.writeByte(cpConstType);
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
292 int value = cpool.getIntAt(ci);
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
293 short refIndex = (short) value;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
294 dos.writeShort(refIndex);
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
295 if (DEBUG) debugMessage("CP[" + ci + "] = MT index = " + refIndex);
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
296 break;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
297 }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1552
diff changeset
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
bc32f286fae0 6945219: minor SA fixes
never
parents: 844
diff changeset
311 default:
bc32f286fae0 6945219: minor SA fixes
never
parents: 844
diff changeset
312 throw new InternalError("Unknown tag: " + cpConstType);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
313 } // switch
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 protected void writeClassAccessFlags() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 int flags = (int)(klass.getAccessFlags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 dos.writeShort((short)flags);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 protected void writeThisClass() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 String klassName = klass.getName().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 Short index = (Short) classToIndex.get(klassName);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 dos.writeShort(index.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (DEBUG) debugMessage("this class = " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 protected void writeSuperClass() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 Klass superKlass = klass.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (superKlass != null) { // is not java.lang.Object
a61af66fc99e Initial load
duke
parents:
diff changeset
332 String superName = superKlass.getName().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
333 Short index = (Short) classToIndex.get(superName);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (DEBUG) debugMessage("super class = " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 dos.writeShort(index.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
336 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 dos.writeShort(0); // no super class
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (DEBUG) debugMessage("number of interfaces = " + len);
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // write interfaces count
a61af66fc99e Initial load
duke
parents:
diff changeset
347 dos.writeShort((short) len);
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
350 Short index = (Short) classToIndex.get(k.getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
351 dos.writeShort(index.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
352 if (DEBUG) debugMessage("\t" + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 protected void writeFields() throws IOException {
6838
7a40901e0d5c 8000332: SA ClassDump throws exception after permgen removal
minqi
parents: 6725
diff changeset
357 final int javaFieldsCount = klass.getJavaFieldsCount();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // write number of fields
6838
7a40901e0d5c 8000332: SA ClassDump throws exception after permgen removal
minqi
parents: 6725
diff changeset
360 dos.writeShort((short) javaFieldsCount);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
361
6838
7a40901e0d5c 8000332: SA ClassDump throws exception after permgen removal
minqi
parents: 6725
diff changeset
362 if (DEBUG) debugMessage("number of fields = " + javaFieldsCount);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
363
6838
7a40901e0d5c 8000332: SA ClassDump throws exception after permgen removal
minqi
parents: 6725
diff changeset
364 for (int index = 0; index < javaFieldsCount; index++) {
3962
cb315dc80374 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 3938
diff changeset
365 short accessFlags = klass.getFieldAccessFlags(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
366 dos.writeShort(accessFlags & (short) JVM_RECOGNIZED_FIELD_MODIFIERS);
a61af66fc99e Initial load
duke
parents:
diff changeset
367
3962
cb315dc80374 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 3938
diff changeset
368 short nameIndex = klass.getFieldNameIndex(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
369 dos.writeShort(nameIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
370
3962
cb315dc80374 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 3938
diff changeset
371 short signatureIndex = klass.getFieldSignatureIndex(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
372 dos.writeShort(signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (DEBUG) debugMessage("\tfield name = " + nameIndex + ", signature = " + signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375 short fieldAttributeCount = 0;
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
376 boolean hasSyn = hasSyntheticAttribute(accessFlags);
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
377 if (hasSyn)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
378 fieldAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
379
3962
cb315dc80374 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 3938
diff changeset
380 short initvalIndex = klass.getFieldInitialValueIndex(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
381 if (initvalIndex != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
382 fieldAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
383
3962
cb315dc80374 7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
never
parents: 3938
diff changeset
384 short genSigIndex = klass.getFieldGenericSignatureIndex(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (genSigIndex != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
386 fieldAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 dos.writeShort(fieldAttributeCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 // write synthetic, if applicable
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
391 if (hasSyn)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
392 writeSynthetic();
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 if (initvalIndex != 0) {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
395 writeIndex(_constantValueIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
396 dos.writeInt(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 dos.writeShort(initvalIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 if (DEBUG) debugMessage("\tfield init value = " + initvalIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
400
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (genSigIndex != 0) {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
402 writeIndex(_signatureIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
403 dos.writeInt(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 dos.writeShort(genSigIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (DEBUG) debugMessage("\tfield generic signature index " + genSigIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 protected boolean isSynthetic(short accessFlags) {
a61af66fc99e Initial load
duke
parents:
diff changeset
411 return (accessFlags & (short) JVM_ACC_SYNTHETIC) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
414 protected boolean hasSyntheticAttribute(short accessFlags) {
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
415 // Check if flags have the attribute and if the constant pool contains an entry for it.
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
416 return isSynthetic(accessFlags) && _syntheticIndex != 0;
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
417 }
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
418
0
a61af66fc99e Initial load
duke
parents:
diff changeset
419 protected void writeSynthetic() throws IOException {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
420 writeIndex(_syntheticIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
421 dos.writeInt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 protected void writeMethods() throws IOException {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6213
diff changeset
425 MethodArray methods = klass.getMethods();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6213
diff changeset
426 final int len = methods.length();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // write number of methods
a61af66fc99e Initial load
duke
parents:
diff changeset
428 dos.writeShort((short) len);
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (DEBUG) debugMessage("number of methods = " + len);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 for (int m = 0; m < len; m++) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6213
diff changeset
431 writeMethod(methods.at(m));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 protected void writeMethod(Method m) throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 long accessFlags = m.getAccessFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 dos.writeShort((short) (accessFlags & JVM_RECOGNIZED_METHOD_MODIFIERS));
a61af66fc99e Initial load
duke
parents:
diff changeset
438 dos.writeShort((short) m.getNameIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
439 dos.writeShort((short) m.getSignatureIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (DEBUG) debugMessage("\tmethod name = " + m.getNameIndex() + ", signature = "
a61af66fc99e Initial load
duke
parents:
diff changeset
441 + m.getSignatureIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
442
a61af66fc99e Initial load
duke
parents:
diff changeset
443 final boolean isNative = ((accessFlags & JVM_ACC_NATIVE) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 final boolean isAbstract = ((accessFlags & JVM_ACC_ABSTRACT) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 short methodAttributeCount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
447
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
448 final boolean hasSyn = hasSyntheticAttribute((short)accessFlags);
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
449 if (hasSyn)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
450 methodAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 final boolean hasCheckedExceptions = m.hasCheckedExceptions();
a61af66fc99e Initial load
duke
parents:
diff changeset
453 if (hasCheckedExceptions)
a61af66fc99e Initial load
duke
parents:
diff changeset
454 methodAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 final boolean isCodeAvailable = (!isNative) && (!isAbstract);
a61af66fc99e Initial load
duke
parents:
diff changeset
457 if (isCodeAvailable)
a61af66fc99e Initial load
duke
parents:
diff changeset
458 methodAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 final boolean isGeneric = (m.getGenericSignature() != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
461 if (isGeneric)
a61af66fc99e Initial load
duke
parents:
diff changeset
462 methodAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
463
a61af66fc99e Initial load
duke
parents:
diff changeset
464 dos.writeShort(methodAttributeCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
465 if (DEBUG) debugMessage("\tmethod attribute count = " + methodAttributeCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
466
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
467 if (hasSyn) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
468 if (DEBUG) debugMessage("\tmethod is synthetic");
a61af66fc99e Initial load
duke
parents:
diff changeset
469 writeSynthetic();
a61af66fc99e Initial load
duke
parents:
diff changeset
470 }
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 if (isCodeAvailable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 byte[] code = m.getByteCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
474 short codeAttrCount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
475 int codeSize = 2 /* max_stack */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
476 2 /* max_locals */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
477 4 /* code_length */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
478 code.length /* code */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
479 2 /* exp. table len. */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
480 2 /* code attr. count */;
a61af66fc99e Initial load
duke
parents:
diff changeset
481
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
482 boolean hasExceptionTable = m.hasExceptionTable();
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
483 ExceptionTableElement[] exceptionTable = null;
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
484 int exceptionTableLen = 0;
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
485 if (hasExceptionTable) {
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
486 exceptionTable = m.getExceptionTable();
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
487 exceptionTableLen = exceptionTable.length;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
488 if (DEBUG) debugMessage("\tmethod has exception table");
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
489 codeSize += exceptionTableLen /* exception table is 4-tuple array */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
490 * (2 /* start_pc */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
491 2 /* end_pc */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
492 2 /* handler_pc */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
493 2 /* catch_type */);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 boolean hasLineNumberTable = m.hasLineNumberTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
497 LineNumberTableElement[] lineNumberTable = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 int lineNumberAttrLen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 if (hasLineNumberTable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 if (DEBUG) debugMessage("\tmethod has line number table");
a61af66fc99e Initial load
duke
parents:
diff changeset
502 lineNumberTable = m.getLineNumberTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
503 if (DEBUG) debugMessage("\t\tline table length = " + lineNumberTable.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 lineNumberAttrLen = 2 /* line number table length */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
506 lineNumberTable.length * (2 /* start_pc */ + 2 /* line_number */);
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 codeSize += 2 /* line number table attr index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
509 4 /* line number table attr length */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
510 lineNumberAttrLen;
a61af66fc99e Initial load
duke
parents:
diff changeset
511
a61af66fc99e Initial load
duke
parents:
diff changeset
512 if (DEBUG) debugMessage("\t\tline number table attr size = " +
a61af66fc99e Initial load
duke
parents:
diff changeset
513 lineNumberAttrLen);
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 codeAttrCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 boolean hasLocalVariableTable = m.hasLocalVariableTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
519 LocalVariableTableElement[] localVariableTable = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
520 int localVarAttrLen = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 if (hasLocalVariableTable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
523 if (DEBUG) debugMessage("\tmethod has local variable table");
a61af66fc99e Initial load
duke
parents:
diff changeset
524 localVariableTable = m.getLocalVariableTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
525 if (DEBUG) debugMessage("\t\tlocal variable table length = "
a61af66fc99e Initial load
duke
parents:
diff changeset
526 + localVariableTable.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
527 localVarAttrLen =
a61af66fc99e Initial load
duke
parents:
diff changeset
528 2 /* local variable table length */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
529 localVariableTable.length * ( 2 /* start_pc */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
530 2 /* length */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
531 2 /* name_index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
532 2 /* signature_index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
533 2 /* variable index */ );
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 if (DEBUG) debugMessage("\t\tlocal variable attr size = " +
a61af66fc99e Initial load
duke
parents:
diff changeset
536 localVarAttrLen);
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 codeSize += 2 /* local variable table attr index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
539 4 /* local variable table attr length */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
540 localVarAttrLen;
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 codeAttrCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // fix ConstantPoolCache indices to ConstantPool indices.
a61af66fc99e Initial load
duke
parents:
diff changeset
546 rewriteByteCode(m, code);
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // start writing Code
a61af66fc99e Initial load
duke
parents:
diff changeset
549
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
550 writeIndex(_codeIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 dos.writeInt(codeSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 if (DEBUG) debugMessage("\tcode attribute length = " + codeSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555 dos.writeShort((short) m.getMaxStack());
a61af66fc99e Initial load
duke
parents:
diff changeset
556 if (DEBUG) debugMessage("\tmax stack = " + m.getMaxStack());
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 dos.writeShort((short) m.getMaxLocals());
a61af66fc99e Initial load
duke
parents:
diff changeset
559 if (DEBUG) debugMessage("\tmax locals = " + m.getMaxLocals());
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 dos.writeInt(code.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
562 if (DEBUG) debugMessage("\tcode size = " + code.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 dos.write(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // write exception table size
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
567 dos.writeShort((short) exceptionTableLen);
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
568 if (DEBUG) debugMessage("\texception table length = " + exceptionTableLen);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 if (exceptionTableLen != 0) {
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
571 for (int e = 0; e < exceptionTableLen; e++) {
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
572 dos.writeShort((short) exceptionTable[e].getStartPC());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
573 dos.writeShort((short) exceptionTable[e].getEndPC());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
574 dos.writeShort((short) exceptionTable[e].getHandlerPC());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3962
diff changeset
575 dos.writeShort((short) exceptionTable[e].getCatchTypeIndex());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 dos.writeShort((short)codeAttrCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 if (DEBUG) debugMessage("\tcode attribute count = " + codeAttrCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 // write LineNumberTable, if available.
a61af66fc99e Initial load
duke
parents:
diff changeset
583 if (hasLineNumberTable) {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
584 writeIndex(_lineNumberTableIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
585 dos.writeInt(lineNumberAttrLen);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 dos.writeShort((short) lineNumberTable.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 for (int l = 0; l < lineNumberTable.length; l++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 dos.writeShort((short) lineNumberTable[l].getStartBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
589 dos.writeShort((short) lineNumberTable[l].getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // write LocalVariableTable, if available.
a61af66fc99e Initial load
duke
parents:
diff changeset
594 if (hasLocalVariableTable) {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
595 writeIndex((short) _localVariableTableIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
596 dos.writeInt(localVarAttrLen);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 dos.writeShort((short) localVariableTable.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 for (int l = 0; l < localVariableTable.length; l++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 dos.writeShort((short) localVariableTable[l].getStartBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
600 dos.writeShort((short) localVariableTable[l].getLength());
a61af66fc99e Initial load
duke
parents:
diff changeset
601 dos.writeShort((short) localVariableTable[l].getNameCPIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
602 dos.writeShort((short) localVariableTable[l].getDescriptorCPIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
603 dos.writeShort((short) localVariableTable[l].getSlot());
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606 }
a61af66fc99e Initial load
duke
parents:
diff changeset
607
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
608 if (hasCheckedExceptions) {
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
609 CheckedExceptionElement[] exceptions = m.getCheckedExceptions();
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
610 writeIndex(_exceptionsIndex);
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
611
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
612 int attrSize = 2 /* number_of_exceptions */ +
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
613 exceptions.length * 2 /* exception_index */;
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
614 dos.writeInt(attrSize);
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
615 dos.writeShort(exceptions.length);
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
616 if (DEBUG) debugMessage("\tmethod has " + exceptions.length
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
617 + " checked exception(s)");
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
618 for (int e = 0; e < exceptions.length; e++) {
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
619 short cpIndex = (short) exceptions[e].getClassCPIndex();
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
620 dos.writeShort(cpIndex);
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
621 }
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
622 }
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
623
0
a61af66fc99e Initial load
duke
parents:
diff changeset
624 if (isGeneric) {
a61af66fc99e Initial load
duke
parents:
diff changeset
625 writeGenericSignature(m.getGenericSignature().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 protected void rewriteByteCode(Method m, byte[] code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
630 ByteCodeRewriter r = new ByteCodeRewriter(m, cpool, code);
a61af66fc99e Initial load
duke
parents:
diff changeset
631 r.rewrite();
a61af66fc99e Initial load
duke
parents:
diff changeset
632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 protected void writeGenericSignature(String signature) throws IOException {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
635 writeIndex(_signatureIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
636 if (DEBUG) debugMessage("signature attribute = " + _signatureIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
637 dos.writeInt(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
638 Short index = (Short) utf8ToIndex.get(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
639 dos.writeShort(index.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
640 if (DEBUG) debugMessage("generic signature = " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643 protected void writeClassAttributes() throws IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
644 final long flags = klass.getAccessFlags();
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
645 final boolean hasSyn = hasSyntheticAttribute((short) flags);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // check for source file
a61af66fc99e Initial load
duke
parents:
diff changeset
648 short classAttributeCount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
649
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
650 if (hasSyn)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
651 classAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 Symbol sourceFileName = klass.getSourceFileName();
a61af66fc99e Initial load
duke
parents:
diff changeset
654 if (sourceFileName != null)
a61af66fc99e Initial load
duke
parents:
diff changeset
655 classAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
656
a61af66fc99e Initial load
duke
parents:
diff changeset
657 Symbol genericSignature = klass.getGenericSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
658 if (genericSignature != null)
a61af66fc99e Initial load
duke
parents:
diff changeset
659 classAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
660
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6213
diff changeset
661 U2Array innerClasses = klass.getInnerClasses();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6213
diff changeset
662 final int numInnerClasses = (int) (innerClasses.length() / 4);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
663 if (numInnerClasses != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
664 classAttributeCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
665
a61af66fc99e Initial load
duke
parents:
diff changeset
666 dos.writeShort(classAttributeCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
667 if (DEBUG) debugMessage("class attribute count = " + classAttributeCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
668
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
669 if (hasSyn)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
670 writeSynthetic();
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // write SourceFile, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
673 if (sourceFileName != null) {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
674 writeIndex(_sourceFileIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
675 if (DEBUG) debugMessage("source file attribute = " + _sourceFileIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 dos.writeInt(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
677 Short index = (Short) utf8ToIndex.get(sourceFileName.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
678 dos.writeShort(index.shortValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
679 if (DEBUG) debugMessage("source file name = " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
680 }
a61af66fc99e Initial load
duke
parents:
diff changeset
681
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // write Signature, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
683 if (genericSignature != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
684 writeGenericSignature(genericSignature.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // write inner classes, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
688 if (numInnerClasses != 0) {
705
1f2abec69714 6826261: class file dumping from SA is broken
never
parents: 0
diff changeset
689 writeIndex(_innerClassesIndex);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
690 final int innerAttrLen = 2 /* number_of_inner_classes */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
691 numInnerClasses * (
a61af66fc99e Initial load
duke
parents:
diff changeset
692 2 /* inner_class_info_index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
693 2 /* outer_class_info_index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
694 2 /* inner_class_name_index */ +
a61af66fc99e Initial load
duke
parents:
diff changeset
695 2 /* inner_class_access_flags */);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 dos.writeInt(innerAttrLen);
a61af66fc99e Initial load
duke
parents:
diff changeset
697
a61af66fc99e Initial load
duke
parents:
diff changeset
698 dos.writeShort(numInnerClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 if (DEBUG) debugMessage("class has " + numInnerClasses + " inner class entries");
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 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
702 dos.writeShort(innerClasses.at(index));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
704 }
a61af66fc99e Initial load
duke
parents:
diff changeset
705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }