author | mcimadamore |
Mon, 24 Aug 2015 13:15:12 +0100 | |
changeset 32334 | fd65e32e16b3 |
parent 29050 | 76df9080086c |
child 32336 | 9e9acf7f26a4 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
28330
d4bcdcac1211
8064857: javac generates LVT entry with length 0 for local variable
vromero
parents:
27853
diff
changeset
|
2 |
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.jvm; |
|
27 |
||
28 |
import java.io.*; |
|
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
29 |
import java.util.LinkedHashMap; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
30 |
import java.util.Map; |
10 | 31 |
import java.util.Set; |
32 |
import java.util.HashSet; |
|
33 |
||
34 |
import javax.tools.JavaFileManager; |
|
35 |
import javax.tools.FileObject; |
|
36 |
import javax.tools.JavaFileObject; |
|
37 |
||
38 |
import com.sun.tools.javac.code.*; |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6143
diff
changeset
|
39 |
import com.sun.tools.javac.code.Attribute.RetentionPolicy; |
10 | 40 |
import com.sun.tools.javac.code.Symbol.*; |
41 |
import com.sun.tools.javac.code.Type.*; |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
42 |
import com.sun.tools.javac.code.Types.UniqueType; |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3300
diff
changeset
|
43 |
import com.sun.tools.javac.file.BaseFileObject; |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
44 |
import com.sun.tools.javac.jvm.Pool.DynamicMethod; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
45 |
import com.sun.tools.javac.jvm.Pool.Method; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
46 |
import com.sun.tools.javac.jvm.Pool.MethodHandle; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
47 |
import com.sun.tools.javac.jvm.Pool.Variable; |
10 | 48 |
import com.sun.tools.javac.util.*; |
49 |
||
50 |
import static com.sun.tools.javac.code.Flags.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26532
diff
changeset
|
51 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
52 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
53 |
import static com.sun.tools.javac.code.TypeTag.*; |
11314 | 54 |
import static com.sun.tools.javac.main.Option.*; |
10 | 55 |
import static javax.tools.StandardLocation.CLASS_OUTPUT; |
56 |
||
57 |
/** This class provides operations to map an internal symbol table graph |
|
58 |
* rooted in a ClassSymbol into a classfile. |
|
59 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
60 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
61 |
* If you write code that depends on this, you do so at your own risk. |
10 | 62 |
* This code and its internal interfaces are subject to change or |
63 |
* deletion without notice.</b> |
|
64 |
*/ |
|
65 |
public class ClassWriter extends ClassFile { |
|
22163 | 66 |
protected static final Context.Key<ClassWriter> classWriterKey = new Context.Key<>(); |
10 | 67 |
|
68 |
private final Options options; |
|
69 |
||
70 |
/** Switch: verbose output. |
|
71 |
*/ |
|
72 |
private boolean verbose; |
|
73 |
||
15385 | 74 |
/** Switch: scramble private field names. |
10 | 75 |
*/ |
76 |
private boolean scramble; |
|
77 |
||
15385 | 78 |
/** Switch: scramble all field names. |
10 | 79 |
*/ |
80 |
private boolean scrambleAll; |
|
81 |
||
82 |
/** Switch: retrofit mode. |
|
83 |
*/ |
|
84 |
private boolean retrofit; |
|
85 |
||
86 |
/** Switch: emit source file attribute. |
|
87 |
*/ |
|
88 |
private boolean emitSourceFile; |
|
89 |
||
90 |
/** Switch: generate CharacterRangeTable attribute. |
|
91 |
*/ |
|
92 |
private boolean genCrt; |
|
93 |
||
15385 | 94 |
/** Switch: describe the generated stackmap. |
10 | 95 |
*/ |
96 |
boolean debugstackmap; |
|
97 |
||
98 |
/** |
|
99 |
* Target class version. |
|
100 |
*/ |
|
101 |
private Target target; |
|
102 |
||
103 |
/** |
|
104 |
* Source language version. |
|
105 |
*/ |
|
106 |
private Source source; |
|
107 |
||
108 |
/** Type utilities. */ |
|
109 |
private Types types; |
|
110 |
||
111 |
/** The initial sizes of the data and constant pool buffers. |
|
15385 | 112 |
* Sizes are increased when buffers get full. |
10 | 113 |
*/ |
114 |
static final int DATA_BUF_SIZE = 0x0fff0; |
|
115 |
static final int POOL_BUF_SIZE = 0x1fff0; |
|
116 |
||
117 |
/** An output buffer for member info. |
|
118 |
*/ |
|
119 |
ByteBuffer databuf = new ByteBuffer(DATA_BUF_SIZE); |
|
120 |
||
121 |
/** An output buffer for the constant pool. |
|
122 |
*/ |
|
123 |
ByteBuffer poolbuf = new ByteBuffer(POOL_BUF_SIZE); |
|
124 |
||
125 |
/** The constant pool. |
|
126 |
*/ |
|
127 |
Pool pool; |
|
128 |
||
129 |
/** The inner classes to be written, as a set. |
|
130 |
*/ |
|
131 |
Set<ClassSymbol> innerClasses; |
|
132 |
||
133 |
/** The inner classes to be written, as a queue where |
|
134 |
* enclosing classes come first. |
|
135 |
*/ |
|
136 |
ListBuffer<ClassSymbol> innerClassesQueue; |
|
137 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
138 |
/** The bootstrap methods to be written in the corresponding class attribute |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
139 |
* (one for each invokedynamic) |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
140 |
*/ |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
141 |
Map<DynamicMethod.BootstrapMethodsKey, MethodHandle> bootstrapMethods; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
142 |
|
10 | 143 |
/** The log to use for verbose output. |
144 |
*/ |
|
145 |
private final Log log; |
|
146 |
||
147 |
/** The name table. */ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
148 |
private final Names names; |
10 | 149 |
|
150 |
/** Access to files. */ |
|
151 |
private final JavaFileManager fileManager; |
|
152 |
||
16300 | 153 |
/** Sole signature generator */ |
154 |
private final CWSignatureGenerator signatureGen; |
|
155 |
||
10 | 156 |
/** The tags and constants used in compressed stackmap. */ |
157 |
static final int SAME_FRAME_SIZE = 64; |
|
158 |
static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247; |
|
159 |
static final int SAME_FRAME_EXTENDED = 251; |
|
160 |
static final int FULL_FRAME = 255; |
|
161 |
static final int MAX_LOCAL_LENGTH_DIFF = 4; |
|
162 |
||
163 |
/** Get the ClassWriter instance for this context. */ |
|
164 |
public static ClassWriter instance(Context context) { |
|
165 |
ClassWriter instance = context.get(classWriterKey); |
|
166 |
if (instance == null) |
|
167 |
instance = new ClassWriter(context); |
|
168 |
return instance; |
|
169 |
} |
|
170 |
||
171 |
/** Construct a class writer, given an options table. |
|
172 |
*/ |
|
13635
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
173 |
protected ClassWriter(Context context) { |
10 | 174 |
context.put(classWriterKey, this); |
175 |
||
176 |
log = Log.instance(context); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
177 |
names = Names.instance(context); |
10 | 178 |
options = Options.instance(context); |
179 |
target = Target.instance(context); |
|
180 |
source = Source.instance(context); |
|
181 |
types = Types.instance(context); |
|
182 |
fileManager = context.get(JavaFileManager.class); |
|
16300 | 183 |
signatureGen = new CWSignatureGenerator(types); |
10 | 184 |
|
6721 | 185 |
verbose = options.isSet(VERBOSE); |
186 |
scramble = options.isSet("-scramble"); |
|
187 |
scrambleAll = options.isSet("-scrambleAll"); |
|
188 |
retrofit = options.isSet("-retrofit"); |
|
189 |
genCrt = options.isSet(XJCOV); |
|
190 |
debugstackmap = options.isSet("debugstackmap"); |
|
10 | 191 |
|
6721 | 192 |
emitSourceFile = options.isUnset(G_CUSTOM) || |
193 |
options.isSet(G_CUSTOM, "source"); |
|
10 | 194 |
|
195 |
String dumpModFlags = options.get("dumpmodifiers"); |
|
196 |
dumpClassModifiers = |
|
197 |
(dumpModFlags != null && dumpModFlags.indexOf('c') != -1); |
|
198 |
dumpFieldModifiers = |
|
199 |
(dumpModFlags != null && dumpModFlags.indexOf('f') != -1); |
|
200 |
dumpInnerClassModifiers = |
|
201 |
(dumpModFlags != null && dumpModFlags.indexOf('i') != -1); |
|
202 |
dumpMethodModifiers = |
|
203 |
(dumpModFlags != null && dumpModFlags.indexOf('m') != -1); |
|
204 |
} |
|
205 |
||
206 |
/****************************************************************** |
|
207 |
* Diagnostics: dump generated class names and modifiers |
|
208 |
******************************************************************/ |
|
209 |
||
210 |
/** Value of option 'dumpmodifiers' is a string |
|
211 |
* indicating which modifiers should be dumped for debugging: |
|
212 |
* 'c' -- classes |
|
213 |
* 'f' -- fields |
|
214 |
* 'i' -- innerclass attributes |
|
215 |
* 'm' -- methods |
|
216 |
* For example, to dump everything: |
|
217 |
* javac -XDdumpmodifiers=cifm MyProg.java |
|
218 |
*/ |
|
219 |
private final boolean dumpClassModifiers; // -XDdumpmodifiers=c |
|
220 |
private final boolean dumpFieldModifiers; // -XDdumpmodifiers=f |
|
221 |
private final boolean dumpInnerClassModifiers; // -XDdumpmodifiers=i |
|
222 |
private final boolean dumpMethodModifiers; // -XDdumpmodifiers=m |
|
223 |
||
224 |
||
225 |
/** Return flags as a string, separated by " ". |
|
226 |
*/ |
|
227 |
public static String flagNames(long flags) { |
|
8032 | 228 |
StringBuilder sbuf = new StringBuilder(); |
10 | 229 |
int i = 0; |
230 |
long f = flags & StandardFlags; |
|
231 |
while (f != 0) { |
|
8032 | 232 |
if ((f & 1) != 0) { |
233 |
sbuf.append(" "); |
|
234 |
sbuf.append(flagName[i]); |
|
235 |
} |
|
10 | 236 |
f = f >> 1; |
237 |
i++; |
|
238 |
} |
|
239 |
return sbuf.toString(); |
|
240 |
} |
|
241 |
//where |
|
242 |
private final static String[] flagName = { |
|
243 |
"PUBLIC", "PRIVATE", "PROTECTED", "STATIC", "FINAL", |
|
244 |
"SUPER", "VOLATILE", "TRANSIENT", "NATIVE", "INTERFACE", |
|
245 |
"ABSTRACT", "STRICTFP"}; |
|
246 |
||
247 |
/****************************************************************** |
|
248 |
* Output routines |
|
249 |
******************************************************************/ |
|
250 |
||
251 |
/** Write a character into given byte buffer; |
|
252 |
* byte buffer will not be grown. |
|
253 |
*/ |
|
254 |
void putChar(ByteBuffer buf, int op, int x) { |
|
255 |
buf.elems[op ] = (byte)((x >> 8) & 0xFF); |
|
256 |
buf.elems[op+1] = (byte)((x ) & 0xFF); |
|
257 |
} |
|
258 |
||
259 |
/** Write an integer into given byte buffer; |
|
260 |
* byte buffer will not be grown. |
|
261 |
*/ |
|
262 |
void putInt(ByteBuffer buf, int adr, int x) { |
|
263 |
buf.elems[adr ] = (byte)((x >> 24) & 0xFF); |
|
264 |
buf.elems[adr+1] = (byte)((x >> 16) & 0xFF); |
|
265 |
buf.elems[adr+2] = (byte)((x >> 8) & 0xFF); |
|
266 |
buf.elems[adr+3] = (byte)((x ) & 0xFF); |
|
267 |
} |
|
268 |
||
16300 | 269 |
/** |
270 |
* Signature Generation |
|
10 | 271 |
*/ |
16300 | 272 |
private class CWSignatureGenerator extends Types.SignatureGenerator { |
273 |
||
274 |
/** |
|
275 |
* An output buffer for type signatures. |
|
276 |
*/ |
|
277 |
ByteBuffer sigbuf = new ByteBuffer(); |
|
278 |
||
279 |
CWSignatureGenerator(Types types) { |
|
280 |
super(types); |
|
281 |
} |
|
282 |
||
283 |
/** |
|
284 |
* Assemble signature of given type in string buffer. |
|
285 |
* Check for uninitialized types before calling the general case. |
|
286 |
*/ |
|
287 |
@Override |
|
288 |
public void assembleSig(Type type) { |
|
289 |
switch (type.getTag()) { |
|
290 |
case UNINITIALIZED_THIS: |
|
291 |
case UNINITIALIZED_OBJECT: |
|
292 |
// we don't yet have a spec for uninitialized types in the |
|
293 |
// local variable table |
|
294 |
assembleSig(types.erasure(((UninitializedType)type).qtype)); |
|
295 |
break; |
|
296 |
default: |
|
297 |
super.assembleSig(type); |
|
10 | 298 |
} |
16300 | 299 |
} |
300 |
||
301 |
@Override |
|
302 |
protected void append(char ch) { |
|
303 |
sigbuf.appendByte(ch); |
|
304 |
} |
|
305 |
||
306 |
@Override |
|
307 |
protected void append(byte[] ba) { |
|
308 |
sigbuf.appendBytes(ba); |
|
309 |
} |
|
310 |
||
311 |
@Override |
|
312 |
protected void append(Name name) { |
|
313 |
sigbuf.appendName(name); |
|
10 | 314 |
} |
16300 | 315 |
|
316 |
@Override |
|
317 |
protected void classReference(ClassSymbol c) { |
|
318 |
enterInner(c); |
|
319 |
} |
|
320 |
||
321 |
private void reset() { |
|
322 |
sigbuf.reset(); |
|
323 |
} |
|
324 |
||
325 |
private Name toName() { |
|
326 |
return sigbuf.toName(names); |
|
327 |
} |
|
328 |
||
329 |
private boolean isEmpty() { |
|
330 |
return sigbuf.length == 0; |
|
10 | 331 |
} |
332 |
} |
|
333 |
||
16300 | 334 |
/** |
335 |
* Return signature of given type |
|
10 | 336 |
*/ |
337 |
Name typeSig(Type type) { |
|
16300 | 338 |
Assert.check(signatureGen.isEmpty()); |
10 | 339 |
//- System.out.println(" ? " + type); |
16300 | 340 |
signatureGen.assembleSig(type); |
341 |
Name n = signatureGen.toName(); |
|
342 |
signatureGen.reset(); |
|
10 | 343 |
//- System.out.println(" " + n); |
344 |
return n; |
|
345 |
} |
|
346 |
||
347 |
/** Given a type t, return the extended class name of its erasure in |
|
348 |
* external representation. |
|
349 |
*/ |
|
350 |
public Name xClassName(Type t) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
351 |
if (t.hasTag(CLASS)) { |
10 | 352 |
return names.fromUtf(externalize(t.tsym.flatName())); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
353 |
} else if (t.hasTag(ARRAY)) { |
10 | 354 |
return typeSig(types.erasure(t)); |
355 |
} else { |
|
24396 | 356 |
throw new AssertionError("xClassName expects class or array type, got " + t); |
10 | 357 |
} |
358 |
} |
|
359 |
||
360 |
/****************************************************************** |
|
361 |
* Writing the Constant Pool |
|
362 |
******************************************************************/ |
|
363 |
||
364 |
/** Thrown when the constant pool is over full. |
|
365 |
*/ |
|
366 |
public static class PoolOverflow extends Exception { |
|
367 |
private static final long serialVersionUID = 0; |
|
368 |
public PoolOverflow() {} |
|
369 |
} |
|
370 |
public static class StringOverflow extends Exception { |
|
371 |
private static final long serialVersionUID = 0; |
|
372 |
public final String value; |
|
373 |
public StringOverflow(String s) { |
|
374 |
value = s; |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
/** Write constant pool to pool buffer. |
|
379 |
* Note: during writing, constant pool |
|
380 |
* might grow since some parts of constants still need to be entered. |
|
381 |
*/ |
|
382 |
void writePool(Pool pool) throws PoolOverflow, StringOverflow { |
|
383 |
int poolCountIdx = poolbuf.length; |
|
384 |
poolbuf.appendChar(0); |
|
385 |
int i = 1; |
|
386 |
while (i < pool.pp) { |
|
387 |
Object value = pool.pool[i]; |
|
8032 | 388 |
Assert.checkNonNull(value); |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
389 |
if (value instanceof Method || value instanceof Variable) |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
15385
diff
changeset
|
390 |
value = ((DelegatedSymbol)value).getUnderlyingSymbol(); |
10 | 391 |
|
392 |
if (value instanceof MethodSymbol) { |
|
393 |
MethodSymbol m = (MethodSymbol)value; |
|
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
394 |
if (!m.isDynamic()) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
395 |
poolbuf.appendByte((m.owner.flags() & INTERFACE) != 0 |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
396 |
? CONSTANT_InterfaceMethodref |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
397 |
: CONSTANT_Methodref); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
398 |
poolbuf.appendChar(pool.put(m.owner)); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
399 |
poolbuf.appendChar(pool.put(nameType(m))); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
400 |
} else { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
401 |
//invokedynamic |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
402 |
DynamicMethodSymbol dynSym = (DynamicMethodSymbol)m; |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
403 |
MethodHandle handle = new MethodHandle(dynSym.bsmKind, dynSym.bsm, types); |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
404 |
DynamicMethod.BootstrapMethodsKey key = new DynamicMethod.BootstrapMethodsKey(dynSym, types); |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
405 |
bootstrapMethods.put(key, handle); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
406 |
//init cp entries |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
407 |
pool.put(names.BootstrapMethods); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
408 |
pool.put(handle); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
409 |
for (Object staticArg : dynSym.staticArgs) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
410 |
pool.put(staticArg); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
411 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
412 |
poolbuf.appendByte(CONSTANT_InvokeDynamic); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
413 |
poolbuf.appendChar(bootstrapMethods.size() - 1); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
414 |
poolbuf.appendChar(pool.put(nameType(dynSym))); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
415 |
} |
10 | 416 |
} else if (value instanceof VarSymbol) { |
417 |
VarSymbol v = (VarSymbol)value; |
|
418 |
poolbuf.appendByte(CONSTANT_Fieldref); |
|
419 |
poolbuf.appendChar(pool.put(v.owner)); |
|
420 |
poolbuf.appendChar(pool.put(nameType(v))); |
|
421 |
} else if (value instanceof Name) { |
|
422 |
poolbuf.appendByte(CONSTANT_Utf8); |
|
423 |
byte[] bs = ((Name)value).toUtf(); |
|
424 |
poolbuf.appendChar(bs.length); |
|
425 |
poolbuf.appendBytes(bs, 0, bs.length); |
|
426 |
if (bs.length > Pool.MAX_STRING_LENGTH) |
|
427 |
throw new StringOverflow(value.toString()); |
|
428 |
} else if (value instanceof ClassSymbol) { |
|
429 |
ClassSymbol c = (ClassSymbol)value; |
|
430 |
if (c.owner.kind == TYP) pool.put(c.owner); |
|
431 |
poolbuf.appendByte(CONSTANT_Class); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
432 |
if (c.type.hasTag(ARRAY)) { |
10 | 433 |
poolbuf.appendChar(pool.put(typeSig(c.type))); |
434 |
} else { |
|
435 |
poolbuf.appendChar(pool.put(names.fromUtf(externalize(c.flatname)))); |
|
436 |
enterInner(c); |
|
437 |
} |
|
438 |
} else if (value instanceof NameAndType) { |
|
439 |
NameAndType nt = (NameAndType)value; |
|
440 |
poolbuf.appendByte(CONSTANT_NameandType); |
|
441 |
poolbuf.appendChar(pool.put(nt.name)); |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
442 |
poolbuf.appendChar(pool.put(typeSig(nt.uniqueType.type))); |
10 | 443 |
} else if (value instanceof Integer) { |
444 |
poolbuf.appendByte(CONSTANT_Integer); |
|
445 |
poolbuf.appendInt(((Integer)value).intValue()); |
|
446 |
} else if (value instanceof Long) { |
|
447 |
poolbuf.appendByte(CONSTANT_Long); |
|
448 |
poolbuf.appendLong(((Long)value).longValue()); |
|
449 |
i++; |
|
450 |
} else if (value instanceof Float) { |
|
451 |
poolbuf.appendByte(CONSTANT_Float); |
|
452 |
poolbuf.appendFloat(((Float)value).floatValue()); |
|
453 |
} else if (value instanceof Double) { |
|
454 |
poolbuf.appendByte(CONSTANT_Double); |
|
455 |
poolbuf.appendDouble(((Double)value).doubleValue()); |
|
456 |
i++; |
|
457 |
} else if (value instanceof String) { |
|
458 |
poolbuf.appendByte(CONSTANT_String); |
|
459 |
poolbuf.appendChar(pool.put(names.fromString((String)value))); |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
460 |
} else if (value instanceof UniqueType) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
461 |
Type type = ((UniqueType)value).type; |
24605
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
462 |
if (type.hasTag(METHOD)) { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
463 |
poolbuf.appendByte(CONSTANT_MethodType); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
464 |
poolbuf.appendChar(pool.put(typeSig((MethodType)type))); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
465 |
} else { |
24605
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
466 |
Assert.check(type.hasTag(ARRAY)); |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
467 |
poolbuf.appendByte(CONSTANT_Class); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
468 |
poolbuf.appendChar(pool.put(xClassName(type))); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
469 |
} |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
470 |
} else if (value instanceof MethodHandle) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
471 |
MethodHandle ref = (MethodHandle)value; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
472 |
poolbuf.appendByte(CONSTANT_MethodHandle); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
473 |
poolbuf.appendByte(ref.refKind); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
474 |
poolbuf.appendChar(pool.put(ref.refSym)); |
10 | 475 |
} else { |
8032 | 476 |
Assert.error("writePool " + value); |
10 | 477 |
} |
478 |
i++; |
|
479 |
} |
|
480 |
if (pool.pp > Pool.MAX_ENTRIES) |
|
481 |
throw new PoolOverflow(); |
|
482 |
putChar(poolbuf, poolCountIdx, pool.pp); |
|
483 |
} |
|
484 |
||
485 |
/** Given a field, return its name. |
|
486 |
*/ |
|
487 |
Name fieldName(Symbol sym) { |
|
488 |
if (scramble && (sym.flags() & PRIVATE) != 0 || |
|
489 |
scrambleAll && (sym.flags() & (PROTECTED | PUBLIC)) == 0) |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
490 |
return names.fromString("_$" + sym.name.getIndex()); |
10 | 491 |
else |
492 |
return sym.name; |
|
493 |
} |
|
494 |
||
495 |
/** Given a symbol, return its name-and-type. |
|
496 |
*/ |
|
497 |
NameAndType nameType(Symbol sym) { |
|
498 |
return new NameAndType(fieldName(sym), |
|
499 |
retrofit |
|
500 |
? sym.erasure(types) |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
501 |
: sym.externalType(types), types); |
10 | 502 |
// if we retrofit, then the NameAndType has been read in as is |
503 |
// and no change is necessary. If we compile normally, the |
|
504 |
// NameAndType is generated from a symbol reference, and the |
|
505 |
// adjustment of adding an additional this$n parameter needs to be made. |
|
506 |
} |
|
507 |
||
508 |
/****************************************************************** |
|
509 |
* Writing Attributes |
|
510 |
******************************************************************/ |
|
511 |
||
512 |
/** Write header for an attribute to data buffer and return |
|
513 |
* position past attribute length index. |
|
514 |
*/ |
|
515 |
int writeAttr(Name attrName) { |
|
516 |
databuf.appendChar(pool.put(attrName)); |
|
517 |
databuf.appendInt(0); |
|
518 |
return databuf.length; |
|
519 |
} |
|
520 |
||
521 |
/** Fill in attribute length. |
|
522 |
*/ |
|
523 |
void endAttr(int index) { |
|
524 |
putInt(databuf, index - 4, databuf.length - index); |
|
525 |
} |
|
526 |
||
527 |
/** Leave space for attribute count and return index for |
|
528 |
* number of attributes field. |
|
529 |
*/ |
|
530 |
int beginAttrs() { |
|
531 |
databuf.appendChar(0); |
|
532 |
return databuf.length; |
|
533 |
} |
|
534 |
||
535 |
/** Fill in number of attributes. |
|
536 |
*/ |
|
537 |
void endAttrs(int index, int count) { |
|
538 |
putChar(databuf, index - 2, count); |
|
539 |
} |
|
540 |
||
541 |
/** Write the EnclosingMethod attribute if needed. |
|
542 |
* Returns the number of attributes written (0 or 1). |
|
543 |
*/ |
|
544 |
int writeEnclosingMethodAttribute(ClassSymbol c) { |
|
13635
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
545 |
return writeEnclosingMethodAttribute(names.EnclosingMethod, c); |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
546 |
} |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
547 |
|
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
548 |
/** Write the EnclosingMethod attribute with a specified name. |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
549 |
* Returns the number of attributes written (0 or 1). |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
550 |
*/ |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
551 |
protected int writeEnclosingMethodAttribute(Name attributeName, ClassSymbol c) { |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
552 |
if (c.owner.kind != MTH && // neither a local class |
10 | 553 |
c.name != names.empty) // nor anonymous |
554 |
return 0; |
|
555 |
||
13635
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
556 |
int alenIdx = writeAttr(attributeName); |
10 | 557 |
ClassSymbol enclClass = c.owner.enclClass(); |
558 |
MethodSymbol enclMethod = |
|
559 |
(c.owner.type == null // local to init block |
|
560 |
|| c.owner.kind != MTH) // or member init |
|
561 |
? null |
|
562 |
: (MethodSymbol)c.owner; |
|
563 |
databuf.appendChar(pool.put(enclClass)); |
|
564 |
databuf.appendChar(enclMethod == null ? 0 : pool.put(nameType(c.owner))); |
|
565 |
endAttr(alenIdx); |
|
566 |
return 1; |
|
567 |
} |
|
568 |
||
569 |
/** Write flag attributes; return number of attributes written. |
|
570 |
*/ |
|
571 |
int writeFlagAttrs(long flags) { |
|
572 |
int acount = 0; |
|
573 |
if ((flags & DEPRECATED) != 0) { |
|
574 |
int alenIdx = writeAttr(names.Deprecated); |
|
575 |
endAttr(alenIdx); |
|
576 |
acount++; |
|
577 |
} |
|
578 |
return acount; |
|
579 |
} |
|
580 |
||
581 |
/** Write member (field or method) attributes; |
|
582 |
* return number of attributes written. |
|
583 |
*/ |
|
584 |
int writeMemberAttrs(Symbol sym) { |
|
585 |
int acount = writeFlagAttrs(sym.flags()); |
|
586 |
long flags = sym.flags(); |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
587 |
if ((flags & (SYNTHETIC | BRIDGE)) != SYNTHETIC && |
10 | 588 |
(flags & ANONCONSTR) == 0 && |
589 |
(!types.isSameType(sym.type, sym.erasure(types)) || |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
590 |
signatureGen.hasTypeVar(sym.type.getThrownTypes()))) { |
10 | 591 |
// note that a local class with captured variables |
592 |
// will get a signature attribute |
|
593 |
int alenIdx = writeAttr(names.Signature); |
|
594 |
databuf.appendChar(pool.put(typeSig(sym.type))); |
|
595 |
endAttr(alenIdx); |
|
596 |
acount++; |
|
597 |
} |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14949
diff
changeset
|
598 |
acount += writeJavaAnnotations(sym.getRawAttributes()); |
17578 | 599 |
acount += writeTypeAnnotations(sym.getRawTypeAttributes(), false); |
10 | 600 |
return acount; |
601 |
} |
|
602 |
||
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
603 |
/** |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
604 |
* Write method parameter names attribute. |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
605 |
*/ |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
606 |
int writeMethodParametersAttr(MethodSymbol m) { |
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
607 |
MethodType ty = m.externalType(types).asMethodType(); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
608 |
final int allparams = ty.argtypes.size(); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
609 |
if (m.params != null && allparams != 0) { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
610 |
final int attrIndex = writeAttr(names.MethodParameters); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
611 |
databuf.appendByte(allparams); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
612 |
// Write extra parameters first |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
613 |
for (VarSymbol s : m.extraParams) { |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
614 |
final int flags = |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
615 |
((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
616 |
((int) m.flags() & SYNTHETIC); |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
617 |
databuf.appendChar(pool.put(s.name)); |
16315
3e29f09420ca
8008658: Four new method param jtreg tests fail in nightly tests
ksrini
parents:
16305
diff
changeset
|
618 |
databuf.appendChar(flags); |
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
619 |
} |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
620 |
// Now write the real parameters |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
621 |
for (VarSymbol s : m.params) { |
15720
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
622 |
final int flags = |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
623 |
((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | |
e61b2f7a5148
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents:
15718
diff
changeset
|
624 |
((int) m.flags() & SYNTHETIC); |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
625 |
databuf.appendChar(pool.put(s.name)); |
16305
ee7f13d9d434
8006948: Update javac for MethodParameters format change
ksrini
parents:
16300
diff
changeset
|
626 |
databuf.appendChar(flags); |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
627 |
} |
19657
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
628 |
// Now write the captured locals |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
629 |
for (VarSymbol s : m.capturedLocals) { |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
630 |
final int flags = |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
631 |
((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) | |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
632 |
((int) m.flags() & SYNTHETIC); |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
633 |
databuf.appendChar(pool.put(s.name)); |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
634 |
databuf.appendChar(flags); |
48226ff07b84
8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents:
18009
diff
changeset
|
635 |
} |
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
636 |
endAttr(attrIndex); |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
637 |
return 1; |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
638 |
} else |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
639 |
return 0; |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
640 |
} |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
641 |
|
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
642 |
|
27853
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
643 |
private void writeParamAnnotations(List<VarSymbol> params, |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
644 |
RetentionPolicy retention) { |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
645 |
for (VarSymbol s : params) { |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
646 |
ListBuffer<Attribute.Compound> buf = new ListBuffer<>(); |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
647 |
for (Attribute.Compound a : s.getRawAttributes()) |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
648 |
if (types.getRetention(a) == retention) |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
649 |
buf.append(a); |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
650 |
databuf.appendChar(buf.length()); |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
651 |
for (Attribute.Compound a : buf) |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
652 |
writeCompoundAttribute(a); |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
653 |
} |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
654 |
|
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
655 |
} |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
656 |
|
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
657 |
private void writeParamAnnotations(MethodSymbol m, |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
658 |
RetentionPolicy retention) { |
29050 | 659 |
databuf.appendByte(m.params.length()); |
27853
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
660 |
writeParamAnnotations(m.params, retention); |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
661 |
} |
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
662 |
|
10 | 663 |
/** Write method parameter annotations; |
664 |
* return number of attributes written. |
|
665 |
*/ |
|
666 |
int writeParameterAttrs(MethodSymbol m) { |
|
667 |
boolean hasVisible = false; |
|
668 |
boolean hasInvisible = false; |
|
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
669 |
if (m.params != null) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
670 |
for (VarSymbol s : m.params) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
671 |
for (Attribute.Compound a : s.getRawAttributes()) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
672 |
switch (types.getRetention(a)) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
673 |
case SOURCE: break; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
674 |
case CLASS: hasInvisible = true; break; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
675 |
case RUNTIME: hasVisible = true; break; |
22163 | 676 |
default: // /* fail soft */ throw new AssertionError(vis); |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17578
diff
changeset
|
677 |
} |
10 | 678 |
} |
679 |
} |
|
680 |
} |
|
681 |
||
682 |
int attrCount = 0; |
|
683 |
if (hasVisible) { |
|
684 |
int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations); |
|
27853
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
685 |
writeParamAnnotations(m, RetentionPolicy.RUNTIME); |
10 | 686 |
endAttr(attrIndex); |
687 |
attrCount++; |
|
688 |
} |
|
689 |
if (hasInvisible) { |
|
690 |
int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations); |
|
27853
746c658e8d35
8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
27224
diff
changeset
|
691 |
writeParamAnnotations(m, RetentionPolicy.CLASS); |
10 | 692 |
endAttr(attrIndex); |
693 |
attrCount++; |
|
694 |
} |
|
695 |
return attrCount; |
|
696 |
} |
|
697 |
||
698 |
/********************************************************************** |
|
699 |
* Writing Java-language annotations (aka metadata, attributes) |
|
700 |
**********************************************************************/ |
|
701 |
||
702 |
/** Write Java-language annotations; return number of JVM |
|
703 |
* attributes written (zero or one). |
|
704 |
*/ |
|
705 |
int writeJavaAnnotations(List<Attribute.Compound> attrs) { |
|
706 |
if (attrs.isEmpty()) return 0; |
|
22163 | 707 |
ListBuffer<Attribute.Compound> visibles = new ListBuffer<>(); |
708 |
ListBuffer<Attribute.Compound> invisibles = new ListBuffer<>(); |
|
10 | 709 |
for (Attribute.Compound a : attrs) { |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6143
diff
changeset
|
710 |
switch (types.getRetention(a)) { |
10 | 711 |
case SOURCE: break; |
712 |
case CLASS: invisibles.append(a); break; |
|
713 |
case RUNTIME: visibles.append(a); break; |
|
22163 | 714 |
default: // /* fail soft */ throw new AssertionError(vis); |
10 | 715 |
} |
716 |
} |
|
717 |
||
718 |
int attrCount = 0; |
|
719 |
if (visibles.length() != 0) { |
|
720 |
int attrIndex = writeAttr(names.RuntimeVisibleAnnotations); |
|
721 |
databuf.appendChar(visibles.length()); |
|
722 |
for (Attribute.Compound a : visibles) |
|
723 |
writeCompoundAttribute(a); |
|
724 |
endAttr(attrIndex); |
|
725 |
attrCount++; |
|
726 |
} |
|
727 |
if (invisibles.length() != 0) { |
|
728 |
int attrIndex = writeAttr(names.RuntimeInvisibleAnnotations); |
|
729 |
databuf.appendChar(invisibles.length()); |
|
730 |
for (Attribute.Compound a : invisibles) |
|
731 |
writeCompoundAttribute(a); |
|
732 |
endAttr(attrIndex); |
|
733 |
attrCount++; |
|
734 |
} |
|
735 |
return attrCount; |
|
736 |
} |
|
737 |
||
17578 | 738 |
int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos, boolean inCode) { |
15385 | 739 |
if (typeAnnos.isEmpty()) return 0; |
740 |
||
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19941
diff
changeset
|
741 |
ListBuffer<Attribute.TypeCompound> visibles = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19941
diff
changeset
|
742 |
ListBuffer<Attribute.TypeCompound> invisibles = new ListBuffer<>(); |
15385 | 743 |
|
744 |
for (Attribute.TypeCompound tc : typeAnnos) { |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
745 |
if (tc.hasUnknownPosition()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
746 |
boolean fixed = tc.tryFixPosition(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
747 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
748 |
// Could we fix it? |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
749 |
if (!fixed) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
750 |
// This happens for nested types like @A Outer. @B Inner. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
751 |
// For method parameters we get the annotation twice! Once with |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
752 |
// a valid position, once unknown. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
753 |
// TODO: find a cleaner solution. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
754 |
PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
755 |
pw.println("ClassWriter: Position UNKNOWN in type annotation: " + tc); |
15385 | 756 |
continue; |
757 |
} |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
758 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
759 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
760 |
if (tc.position.type.isLocal() != inCode) |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24605
diff
changeset
|
761 |
continue; |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
762 |
if (!tc.position.emitToClassfile()) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
763 |
continue; |
15385 | 764 |
switch (types.getRetention(tc)) { |
765 |
case SOURCE: break; |
|
766 |
case CLASS: invisibles.append(tc); break; |
|
767 |
case RUNTIME: visibles.append(tc); break; |
|
22163 | 768 |
default: // /* fail soft */ throw new AssertionError(vis); |
15385 | 769 |
} |
770 |
} |
|
771 |
||
772 |
int attrCount = 0; |
|
773 |
if (visibles.length() != 0) { |
|
774 |
int attrIndex = writeAttr(names.RuntimeVisibleTypeAnnotations); |
|
775 |
databuf.appendChar(visibles.length()); |
|
776 |
for (Attribute.TypeCompound p : visibles) |
|
777 |
writeTypeAnnotation(p); |
|
778 |
endAttr(attrIndex); |
|
779 |
attrCount++; |
|
780 |
} |
|
781 |
||
782 |
if (invisibles.length() != 0) { |
|
783 |
int attrIndex = writeAttr(names.RuntimeInvisibleTypeAnnotations); |
|
784 |
databuf.appendChar(invisibles.length()); |
|
785 |
for (Attribute.TypeCompound p : invisibles) |
|
786 |
writeTypeAnnotation(p); |
|
787 |
endAttr(attrIndex); |
|
788 |
attrCount++; |
|
789 |
} |
|
790 |
||
791 |
return attrCount; |
|
792 |
} |
|
793 |
||
10 | 794 |
/** A visitor to write an attribute including its leading |
795 |
* single-character marker. |
|
796 |
*/ |
|
797 |
class AttributeWriter implements Attribute.Visitor { |
|
798 |
public void visitConstant(Attribute.Constant _value) { |
|
799 |
Object value = _value.value; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
800 |
switch (_value.type.getTag()) { |
10 | 801 |
case BYTE: |
802 |
databuf.appendByte('B'); |
|
803 |
break; |
|
804 |
case CHAR: |
|
805 |
databuf.appendByte('C'); |
|
806 |
break; |
|
807 |
case SHORT: |
|
808 |
databuf.appendByte('S'); |
|
809 |
break; |
|
810 |
case INT: |
|
811 |
databuf.appendByte('I'); |
|
812 |
break; |
|
813 |
case LONG: |
|
814 |
databuf.appendByte('J'); |
|
815 |
break; |
|
816 |
case FLOAT: |
|
817 |
databuf.appendByte('F'); |
|
818 |
break; |
|
819 |
case DOUBLE: |
|
820 |
databuf.appendByte('D'); |
|
821 |
break; |
|
822 |
case BOOLEAN: |
|
823 |
databuf.appendByte('Z'); |
|
824 |
break; |
|
825 |
case CLASS: |
|
8032 | 826 |
Assert.check(value instanceof String); |
10 | 827 |
databuf.appendByte('s'); |
828 |
value = names.fromString(value.toString()); // CONSTANT_Utf8 |
|
829 |
break; |
|
830 |
default: |
|
831 |
throw new AssertionError(_value.type); |
|
832 |
} |
|
833 |
databuf.appendChar(pool.put(value)); |
|
834 |
} |
|
835 |
public void visitEnum(Attribute.Enum e) { |
|
836 |
databuf.appendByte('e'); |
|
837 |
databuf.appendChar(pool.put(typeSig(e.value.type))); |
|
838 |
databuf.appendChar(pool.put(e.value.name)); |
|
839 |
} |
|
840 |
public void visitClass(Attribute.Class clazz) { |
|
841 |
databuf.appendByte('c'); |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13635
diff
changeset
|
842 |
databuf.appendChar(pool.put(typeSig(clazz.classType))); |
10 | 843 |
} |
844 |
public void visitCompound(Attribute.Compound compound) { |
|
845 |
databuf.appendByte('@'); |
|
846 |
writeCompoundAttribute(compound); |
|
847 |
} |
|
848 |
public void visitError(Attribute.Error x) { |
|
849 |
throw new AssertionError(x); |
|
850 |
} |
|
851 |
public void visitArray(Attribute.Array array) { |
|
852 |
databuf.appendByte('['); |
|
853 |
databuf.appendChar(array.values.length); |
|
854 |
for (Attribute a : array.values) { |
|
855 |
a.accept(this); |
|
856 |
} |
|
857 |
} |
|
858 |
} |
|
859 |
AttributeWriter awriter = new AttributeWriter(); |
|
860 |
||
861 |
/** Write a compound attribute excluding the '@' marker. */ |
|
862 |
void writeCompoundAttribute(Attribute.Compound c) { |
|
863 |
databuf.appendChar(pool.put(typeSig(c.type))); |
|
864 |
databuf.appendChar(c.values.length()); |
|
865 |
for (Pair<Symbol.MethodSymbol,Attribute> p : c.values) { |
|
866 |
databuf.appendChar(pool.put(p.fst.name)); |
|
867 |
p.snd.accept(awriter); |
|
868 |
} |
|
869 |
} |
|
15385 | 870 |
|
871 |
void writeTypeAnnotation(Attribute.TypeCompound c) { |
|
872 |
writePosition(c.position); |
|
873 |
writeCompoundAttribute(c); |
|
874 |
} |
|
875 |
||
876 |
void writePosition(TypeAnnotationPosition p) { |
|
877 |
databuf.appendByte(p.type.targetTypeValue()); // TargetType tag is a byte |
|
878 |
switch (p.type) { |
|
879 |
// instanceof |
|
880 |
case INSTANCEOF: |
|
881 |
// new expression |
|
882 |
case NEW: |
|
15718 | 883 |
// constructor/method reference receiver |
884 |
case CONSTRUCTOR_REFERENCE: |
|
885 |
case METHOD_REFERENCE: |
|
15385 | 886 |
databuf.appendChar(p.offset); |
887 |
break; |
|
888 |
// local variable |
|
889 |
case LOCAL_VARIABLE: |
|
890 |
// resource variable |
|
891 |
case RESOURCE_VARIABLE: |
|
892 |
databuf.appendChar(p.lvarOffset.length); // for table length |
|
893 |
for (int i = 0; i < p.lvarOffset.length; ++i) { |
|
894 |
databuf.appendChar(p.lvarOffset[i]); |
|
895 |
databuf.appendChar(p.lvarLength[i]); |
|
896 |
databuf.appendChar(p.lvarIndex[i]); |
|
897 |
} |
|
898 |
break; |
|
899 |
// exception parameter |
|
900 |
case EXCEPTION_PARAMETER: |
|
23975
c7c81595aea9
8040319: Clean up type annotation exception index generating code in Code.java
emc
parents:
23392
diff
changeset
|
901 |
databuf.appendChar(p.getExceptionIndex()); |
15385 | 902 |
break; |
903 |
// method receiver |
|
904 |
case METHOD_RECEIVER: |
|
905 |
// Do nothing |
|
906 |
break; |
|
907 |
// type parameter |
|
908 |
case CLASS_TYPE_PARAMETER: |
|
909 |
case METHOD_TYPE_PARAMETER: |
|
910 |
databuf.appendByte(p.parameter_index); |
|
911 |
break; |
|
912 |
// type parameter bound |
|
913 |
case CLASS_TYPE_PARAMETER_BOUND: |
|
914 |
case METHOD_TYPE_PARAMETER_BOUND: |
|
915 |
databuf.appendByte(p.parameter_index); |
|
916 |
databuf.appendByte(p.bound_index); |
|
917 |
break; |
|
918 |
// class extends or implements clause |
|
919 |
case CLASS_EXTENDS: |
|
920 |
databuf.appendChar(p.type_index); |
|
921 |
break; |
|
922 |
// throws |
|
923 |
case THROWS: |
|
924 |
databuf.appendChar(p.type_index); |
|
925 |
break; |
|
926 |
// method parameter |
|
927 |
case METHOD_FORMAL_PARAMETER: |
|
928 |
databuf.appendByte(p.parameter_index); |
|
929 |
break; |
|
15718 | 930 |
// type cast |
931 |
case CAST: |
|
15385 | 932 |
// method/constructor/reference type argument |
933 |
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: |
|
934 |
case METHOD_INVOCATION_TYPE_ARGUMENT: |
|
15718 | 935 |
case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: |
15385 | 936 |
case METHOD_REFERENCE_TYPE_ARGUMENT: |
937 |
databuf.appendChar(p.offset); |
|
938 |
databuf.appendByte(p.type_index); |
|
939 |
break; |
|
940 |
// We don't need to worry about these |
|
941 |
case METHOD_RETURN: |
|
942 |
case FIELD: |
|
943 |
break; |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
944 |
case UNKNOWN: |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
25874
diff
changeset
|
945 |
throw new AssertionError("jvm.ClassWriter: UNKNOWN target type should never occur!"); |
15385 | 946 |
default: |
947 |
throw new AssertionError("jvm.ClassWriter: Unknown target type for position: " + p); |
|
948 |
} |
|
949 |
||
950 |
{ // Append location data for generics/arrays. |
|
951 |
databuf.appendByte(p.location.size()); |
|
952 |
java.util.List<Integer> loc = TypeAnnotationPosition.getBinaryFromTypePath(p.location); |
|
953 |
for (int i : loc) |
|
954 |
databuf.appendByte((byte)i); |
|
955 |
} |
|
956 |
} |
|
957 |
||
10 | 958 |
/********************************************************************** |
959 |
* Writing Objects |
|
960 |
**********************************************************************/ |
|
961 |
||
962 |
/** Enter an inner class into the `innerClasses' set/queue. |
|
963 |
*/ |
|
964 |
void enterInner(ClassSymbol c) { |
|
7215
49e5caf5b854
6999635: Multicatch: crash while compiling simple code with a multicatch parameter
mcimadamore
parents:
6721
diff
changeset
|
965 |
if (c.type.isCompound()) { |
49e5caf5b854
6999635: Multicatch: crash while compiling simple code with a multicatch parameter
mcimadamore
parents:
6721
diff
changeset
|
966 |
throw new AssertionError("Unexpected intersection type: " + c.type); |
49e5caf5b854
6999635: Multicatch: crash while compiling simple code with a multicatch parameter
mcimadamore
parents:
6721
diff
changeset
|
967 |
} |
10 | 968 |
try { |
969 |
c.complete(); |
|
970 |
} catch (CompletionFailure ex) { |
|
971 |
System.err.println("error: " + c + ": " + ex.getMessage()); |
|
972 |
throw ex; |
|
973 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
974 |
if (!c.type.hasTag(CLASS)) return; // arrays |
10 | 975 |
if (pool != null && // pool might be null if called from xClassName |
10627
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
976 |
c.owner.enclClass() != null && |
10 | 977 |
(innerClasses == null || !innerClasses.contains(c))) { |
978 |
// log.errWriter.println("enter inner " + c);//DEBUG |
|
10627
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
979 |
enterInner(c.owner.enclClass()); |
10 | 980 |
pool.put(c); |
16976
aecde736ef83
8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
16315
diff
changeset
|
981 |
if (c.name != names.empty) |
aecde736ef83
8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
16315
diff
changeset
|
982 |
pool.put(c.name); |
10 | 983 |
if (innerClasses == null) { |
22163 | 984 |
innerClasses = new HashSet<>(); |
985 |
innerClassesQueue = new ListBuffer<>(); |
|
10 | 986 |
pool.put(names.InnerClasses); |
987 |
} |
|
988 |
innerClasses.add(c); |
|
989 |
innerClassesQueue.append(c); |
|
990 |
} |
|
991 |
} |
|
992 |
||
993 |
/** Write "inner classes" attribute. |
|
994 |
*/ |
|
995 |
void writeInnerClasses() { |
|
996 |
int alenIdx = writeAttr(names.InnerClasses); |
|
997 |
databuf.appendChar(innerClassesQueue.length()); |
|
998 |
for (List<ClassSymbol> l = innerClassesQueue.toList(); |
|
999 |
l.nonEmpty(); |
|
1000 |
l = l.tail) { |
|
1001 |
ClassSymbol inner = l.head; |
|
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28330
diff
changeset
|
1002 |
inner.markAbstractIfNeeded(types); |
10 | 1003 |
char flags = (char) adjustFlags(inner.flags_field); |
1004 |
if ((flags & INTERFACE) != 0) flags |= ABSTRACT; // Interfaces are always ABSTRACT |
|
1005 |
if (inner.name.isEmpty()) flags &= ~FINAL; // Anonymous class: unset FINAL flag |
|
18009
f47ea7c9c3f4
7165659: javac incorrectly sets strictfp access flag on inner-classes
vromero
parents:
18000
diff
changeset
|
1006 |
flags &= ~STRICTFP; //inner classes should not have the strictfp flag set. |
10 | 1007 |
if (dumpInnerClassModifiers) { |
11052
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1008 |
PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1009 |
pw.println("INNERCLASS " + inner.name); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1010 |
pw.println("---" + flagNames(flags)); |
10 | 1011 |
} |
1012 |
databuf.appendChar(pool.get(inner)); |
|
1013 |
databuf.appendChar( |
|
23392
869ad7bdc595
8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
22163
diff
changeset
|
1014 |
inner.owner.kind == TYP && !inner.name.isEmpty() ? pool.get(inner.owner) : 0); |
10 | 1015 |
databuf.appendChar( |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1016 |
!inner.name.isEmpty() ? pool.get(inner.name) : 0); |
10 | 1017 |
databuf.appendChar(flags); |
1018 |
} |
|
1019 |
endAttr(alenIdx); |
|
1020 |
} |
|
1021 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1022 |
/** Write "bootstrapMethods" attribute. |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1023 |
*/ |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1024 |
void writeBootstrapMethods() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1025 |
int alenIdx = writeAttr(names.BootstrapMethods); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1026 |
databuf.appendChar(bootstrapMethods.size()); |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
1027 |
for (Map.Entry<DynamicMethod.BootstrapMethodsKey, MethodHandle> entry : bootstrapMethods.entrySet()) { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
1028 |
DynamicMethod.BootstrapMethodsKey bsmKey = entry.getKey(); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1029 |
//write BSM handle |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1030 |
databuf.appendChar(pool.get(entry.getValue())); |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
1031 |
Object[] uniqueArgs = bsmKey.getUniqueArgs(); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1032 |
//write static args length |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
29050
diff
changeset
|
1033 |
databuf.appendChar(uniqueArgs.length); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1034 |
//write static args array |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14443
diff
changeset
|
1035 |
for (Object o : uniqueArgs) { |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1036 |
databuf.appendChar(pool.get(o)); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1037 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1038 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1039 |
endAttr(alenIdx); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1040 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1041 |
|
10 | 1042 |
/** Write field symbol, entering all references into constant pool. |
1043 |
*/ |
|
1044 |
void writeField(VarSymbol v) { |
|
1045 |
int flags = adjustFlags(v.flags()); |
|
1046 |
databuf.appendChar(flags); |
|
1047 |
if (dumpFieldModifiers) { |
|
11052
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1048 |
PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1049 |
pw.println("FIELD " + fieldName(v)); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1050 |
pw.println("---" + flagNames(v.flags())); |
10 | 1051 |
} |
1052 |
databuf.appendChar(pool.put(fieldName(v))); |
|
1053 |
databuf.appendChar(pool.put(typeSig(v.erasure(types)))); |
|
1054 |
int acountIdx = beginAttrs(); |
|
1055 |
int acount = 0; |
|
1056 |
if (v.getConstValue() != null) { |
|
1057 |
int alenIdx = writeAttr(names.ConstantValue); |
|
1058 |
databuf.appendChar(pool.put(v.getConstValue())); |
|
1059 |
endAttr(alenIdx); |
|
1060 |
acount++; |
|
1061 |
} |
|
1062 |
acount += writeMemberAttrs(v); |
|
1063 |
endAttrs(acountIdx, acount); |
|
1064 |
} |
|
1065 |
||
1066 |
/** Write method symbol, entering all references into constant pool. |
|
1067 |
*/ |
|
1068 |
void writeMethod(MethodSymbol m) { |
|
1069 |
int flags = adjustFlags(m.flags()); |
|
1070 |
databuf.appendChar(flags); |
|
1071 |
if (dumpMethodModifiers) { |
|
11052
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1072 |
PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1073 |
pw.println("METHOD " + fieldName(m)); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1074 |
pw.println("---" + flagNames(m.flags())); |
10 | 1075 |
} |
1076 |
databuf.appendChar(pool.put(fieldName(m))); |
|
1077 |
databuf.appendChar(pool.put(typeSig(m.externalType(types)))); |
|
1078 |
int acountIdx = beginAttrs(); |
|
1079 |
int acount = 0; |
|
1080 |
if (m.code != null) { |
|
1081 |
int alenIdx = writeAttr(names.Code); |
|
1082 |
writeCode(m.code); |
|
1083 |
m.code = null; // to conserve space |
|
1084 |
endAttr(alenIdx); |
|
1085 |
acount++; |
|
1086 |
} |
|
1087 |
List<Type> thrown = m.erasure(types).getThrownTypes(); |
|
1088 |
if (thrown.nonEmpty()) { |
|
1089 |
int alenIdx = writeAttr(names.Exceptions); |
|
1090 |
databuf.appendChar(thrown.length()); |
|
1091 |
for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
|
1092 |
databuf.appendChar(pool.put(l.head.tsym)); |
|
1093 |
endAttr(alenIdx); |
|
1094 |
acount++; |
|
1095 |
} |
|
1096 |
if (m.defaultValue != null) { |
|
1097 |
int alenIdx = writeAttr(names.AnnotationDefault); |
|
1098 |
m.defaultValue.accept(awriter); |
|
1099 |
endAttr(alenIdx); |
|
1100 |
acount++; |
|
1101 |
} |
|
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
1102 |
if (options.isSet(PARAMETERS)) |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14961
diff
changeset
|
1103 |
acount += writeMethodParametersAttr(m); |
10 | 1104 |
acount += writeMemberAttrs(m); |
1105 |
acount += writeParameterAttrs(m); |
|
1106 |
endAttrs(acountIdx, acount); |
|
1107 |
} |
|
1108 |
||
1109 |
/** Write code attribute of method. |
|
1110 |
*/ |
|
1111 |
void writeCode(Code code) { |
|
1112 |
databuf.appendChar(code.max_stack); |
|
1113 |
databuf.appendChar(code.max_locals); |
|
1114 |
databuf.appendInt(code.cp); |
|
1115 |
databuf.appendBytes(code.code, 0, code.cp); |
|
1116 |
databuf.appendChar(code.catchInfo.length()); |
|
1117 |
for (List<char[]> l = code.catchInfo.toList(); |
|
1118 |
l.nonEmpty(); |
|
1119 |
l = l.tail) { |
|
1120 |
for (int i = 0; i < l.head.length; i++) |
|
1121 |
databuf.appendChar(l.head[i]); |
|
1122 |
} |
|
1123 |
int acountIdx = beginAttrs(); |
|
1124 |
int acount = 0; |
|
1125 |
||
1126 |
if (code.lineInfo.nonEmpty()) { |
|
1127 |
int alenIdx = writeAttr(names.LineNumberTable); |
|
1128 |
databuf.appendChar(code.lineInfo.length()); |
|
1129 |
for (List<char[]> l = code.lineInfo.reverse(); |
|
1130 |
l.nonEmpty(); |
|
1131 |
l = l.tail) |
|
1132 |
for (int i = 0; i < l.head.length; i++) |
|
1133 |
databuf.appendChar(l.head[i]); |
|
1134 |
endAttr(alenIdx); |
|
1135 |
acount++; |
|
1136 |
} |
|
1137 |
||
1138 |
if (genCrt && (code.crt != null)) { |
|
1139 |
CRTable crt = code.crt; |
|
1140 |
int alenIdx = writeAttr(names.CharacterRangeTable); |
|
1141 |
int crtIdx = beginAttrs(); |
|
1142 |
int crtEntries = crt.writeCRT(databuf, code.lineMap, log); |
|
1143 |
endAttrs(crtIdx, crtEntries); |
|
1144 |
endAttr(alenIdx); |
|
1145 |
acount++; |
|
1146 |
} |
|
1147 |
||
1148 |
// counter for number of generic local variables |
|
21889
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1149 |
if (code.varDebugInfo && code.varBufferSize > 0) { |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1150 |
int nGenericVars = 0; |
10 | 1151 |
int alenIdx = writeAttr(names.LocalVariableTable); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1152 |
databuf.appendChar(code.getLVTSize()); |
10 | 1153 |
for (int i=0; i<code.varBufferSize; i++) { |
1154 |
Code.LocalVar var = code.varBuffer[i]; |
|
1155 |
||
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1156 |
for (Code.LocalVar.Range r: var.aliveRanges) { |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1157 |
// write variable info |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1158 |
Assert.check(r.start_pc >= 0 |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1159 |
&& r.start_pc <= code.cp); |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1160 |
databuf.appendChar(r.start_pc); |
28330
d4bcdcac1211
8064857: javac generates LVT entry with length 0 for local variable
vromero
parents:
27853
diff
changeset
|
1161 |
Assert.check(r.length > 0 |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1162 |
&& (r.start_pc + r.length) <= code.cp); |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1163 |
databuf.appendChar(r.length); |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1164 |
VarSymbol sym = var.sym; |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1165 |
databuf.appendChar(pool.put(sym.name)); |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1166 |
Type vartype = sym.erasure(types); |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1167 |
databuf.appendChar(pool.put(typeSig(vartype))); |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1168 |
databuf.appendChar(var.reg); |
21889
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1169 |
if (needsLocalVariableTypeEntry(var.sym.type)) { |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1170 |
nGenericVars++; |
21889
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1171 |
} |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1172 |
} |
10 | 1173 |
} |
1174 |
endAttr(alenIdx); |
|
1175 |
acount++; |
|
1176 |
||
21889
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1177 |
if (nGenericVars > 0) { |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1178 |
alenIdx = writeAttr(names.LocalVariableTypeTable); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1179 |
databuf.appendChar(nGenericVars); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1180 |
int count = 0; |
10 | 1181 |
|
21889
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1182 |
for (int i=0; i<code.varBufferSize; i++) { |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1183 |
Code.LocalVar var = code.varBuffer[i]; |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1184 |
VarSymbol sym = var.sym; |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1185 |
if (!needsLocalVariableTypeEntry(sym.type)) |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1186 |
continue; |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1187 |
for (Code.LocalVar.Range r : var.aliveRanges) { |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1188 |
// write variable info |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1189 |
databuf.appendChar(r.start_pc); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1190 |
databuf.appendChar(r.length); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1191 |
databuf.appendChar(pool.put(sym.name)); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1192 |
databuf.appendChar(pool.put(typeSig(sym.type))); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1193 |
databuf.appendChar(var.reg); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1194 |
count++; |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1195 |
} |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19657
diff
changeset
|
1196 |
} |
21889
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1197 |
Assert.check(count == nGenericVars); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1198 |
endAttr(alenIdx); |
7c3939a495ab
8028504: javac generates LocalVariableTable even with -g:none
vromero
parents:
20249
diff
changeset
|
1199 |
acount++; |
10 | 1200 |
} |
1201 |
} |
|
1202 |
||
1203 |
if (code.stackMapBufferSize > 0) { |
|
1204 |
if (debugstackmap) System.out.println("Stack map for " + code.meth); |
|
1205 |
int alenIdx = writeAttr(code.stackMap.getAttributeName(names)); |
|
1206 |
writeStackMap(code); |
|
1207 |
endAttr(alenIdx); |
|
1208 |
acount++; |
|
1209 |
} |
|
17578 | 1210 |
|
1211 |
acount += writeTypeAnnotations(code.meth.getRawTypeAttributes(), true); |
|
1212 |
||
10 | 1213 |
endAttrs(acountIdx, acount); |
1214 |
} |
|
7629
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1215 |
//where |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1216 |
private boolean needsLocalVariableTypeEntry(Type t) { |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1217 |
//a local variable needs a type-entry if its type T is generic |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1218 |
//(i.e. |T| != T) and if it's not an intersection type (not supported |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1219 |
//in signature attribute grammar) |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1220 |
return (!types.isSameType(t, types.erasure(t)) && |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1221 |
!t.isCompound()); |
4662e86bff2e
7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
7215
diff
changeset
|
1222 |
} |
10 | 1223 |
|
1224 |
void writeStackMap(Code code) { |
|
1225 |
int nframes = code.stackMapBufferSize; |
|
1226 |
if (debugstackmap) System.out.println(" nframes = " + nframes); |
|
1227 |
databuf.appendChar(nframes); |
|
1228 |
||
1229 |
switch (code.stackMap) { |
|
1230 |
case CLDC: |
|
1231 |
for (int i=0; i<nframes; i++) { |
|
1232 |
if (debugstackmap) System.out.print(" " + i + ":"); |
|
1233 |
Code.StackMapFrame frame = code.stackMapBuffer[i]; |
|
1234 |
||
1235 |
// output PC |
|
1236 |
if (debugstackmap) System.out.print(" pc=" + frame.pc); |
|
1237 |
databuf.appendChar(frame.pc); |
|
1238 |
||
1239 |
// output locals |
|
1240 |
int localCount = 0; |
|
1241 |
for (int j=0; j<frame.locals.length; |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1242 |
j += Code.width(frame.locals[j])) { |
10 | 1243 |
localCount++; |
1244 |
} |
|
1245 |
if (debugstackmap) System.out.print(" nlocals=" + |
|
1246 |
localCount); |
|
1247 |
databuf.appendChar(localCount); |
|
1248 |
for (int j=0; j<frame.locals.length; |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1249 |
j += Code.width(frame.locals[j])) { |
10 | 1250 |
if (debugstackmap) System.out.print(" local[" + j + "]="); |
1251 |
writeStackMapType(frame.locals[j]); |
|
1252 |
} |
|
1253 |
||
1254 |
// output stack |
|
1255 |
int stackCount = 0; |
|
1256 |
for (int j=0; j<frame.stack.length; |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1257 |
j += Code.width(frame.stack[j])) { |
10 | 1258 |
stackCount++; |
1259 |
} |
|
1260 |
if (debugstackmap) System.out.print(" nstack=" + |
|
1261 |
stackCount); |
|
1262 |
databuf.appendChar(stackCount); |
|
1263 |
for (int j=0; j<frame.stack.length; |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1264 |
j += Code.width(frame.stack[j])) { |
10 | 1265 |
if (debugstackmap) System.out.print(" stack[" + j + "]="); |
1266 |
writeStackMapType(frame.stack[j]); |
|
1267 |
} |
|
1268 |
if (debugstackmap) System.out.println(); |
|
1269 |
} |
|
1270 |
break; |
|
1271 |
case JSR202: { |
|
8032 | 1272 |
Assert.checkNull(code.stackMapBuffer); |
10 | 1273 |
for (int i=0; i<nframes; i++) { |
1274 |
if (debugstackmap) System.out.print(" " + i + ":"); |
|
1275 |
StackMapTableFrame frame = code.stackMapTableBuffer[i]; |
|
1276 |
frame.write(this); |
|
1277 |
if (debugstackmap) System.out.println(); |
|
1278 |
} |
|
1279 |
break; |
|
1280 |
} |
|
1281 |
default: |
|
1282 |
throw new AssertionError("Unexpected stackmap format value"); |
|
1283 |
} |
|
1284 |
} |
|
1285 |
||
1286 |
//where |
|
1287 |
void writeStackMapType(Type t) { |
|
1288 |
if (t == null) { |
|
1289 |
if (debugstackmap) System.out.print("empty"); |
|
1290 |
databuf.appendByte(0); |
|
1291 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1292 |
else switch(t.getTag()) { |
10 | 1293 |
case BYTE: |
1294 |
case CHAR: |
|
1295 |
case SHORT: |
|
1296 |
case INT: |
|
1297 |
case BOOLEAN: |
|
1298 |
if (debugstackmap) System.out.print("int"); |
|
1299 |
databuf.appendByte(1); |
|
1300 |
break; |
|
1301 |
case FLOAT: |
|
1302 |
if (debugstackmap) System.out.print("float"); |
|
1303 |
databuf.appendByte(2); |
|
1304 |
break; |
|
1305 |
case DOUBLE: |
|
1306 |
if (debugstackmap) System.out.print("double"); |
|
1307 |
databuf.appendByte(3); |
|
1308 |
break; |
|
1309 |
case LONG: |
|
1310 |
if (debugstackmap) System.out.print("long"); |
|
1311 |
databuf.appendByte(4); |
|
1312 |
break; |
|
1313 |
case BOT: // null |
|
1314 |
if (debugstackmap) System.out.print("null"); |
|
1315 |
databuf.appendByte(5); |
|
1316 |
break; |
|
1317 |
case CLASS: |
|
1318 |
case ARRAY: |
|
1319 |
if (debugstackmap) System.out.print("object(" + t + ")"); |
|
1320 |
databuf.appendByte(7); |
|
1321 |
databuf.appendChar(pool.put(t)); |
|
1322 |
break; |
|
1323 |
case TYPEVAR: |
|
1324 |
if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")"); |
|
1325 |
databuf.appendByte(7); |
|
1326 |
databuf.appendChar(pool.put(types.erasure(t).tsym)); |
|
1327 |
break; |
|
1328 |
case UNINITIALIZED_THIS: |
|
1329 |
if (debugstackmap) System.out.print("uninit_this"); |
|
1330 |
databuf.appendByte(6); |
|
1331 |
break; |
|
1332 |
case UNINITIALIZED_OBJECT: |
|
1333 |
{ UninitializedType uninitType = (UninitializedType)t; |
|
1334 |
databuf.appendByte(8); |
|
1335 |
if (debugstackmap) System.out.print("uninit_object@" + uninitType.offset); |
|
1336 |
databuf.appendChar(uninitType.offset); |
|
1337 |
} |
|
1338 |
break; |
|
1339 |
default: |
|
1340 |
throw new AssertionError(); |
|
1341 |
} |
|
1342 |
} |
|
1343 |
||
1344 |
/** An entry in the JSR202 StackMapTable */ |
|
1345 |
abstract static class StackMapTableFrame { |
|
1346 |
abstract int getFrameType(); |
|
1347 |
||
1348 |
void write(ClassWriter writer) { |
|
1349 |
int frameType = getFrameType(); |
|
1350 |
writer.databuf.appendByte(frameType); |
|
1351 |
if (writer.debugstackmap) System.out.print(" frame_type=" + frameType); |
|
1352 |
} |
|
1353 |
||
1354 |
static class SameFrame extends StackMapTableFrame { |
|
1355 |
final int offsetDelta; |
|
1356 |
SameFrame(int offsetDelta) { |
|
1357 |
this.offsetDelta = offsetDelta; |
|
1358 |
} |
|
1359 |
int getFrameType() { |
|
1360 |
return (offsetDelta < SAME_FRAME_SIZE) ? offsetDelta : SAME_FRAME_EXTENDED; |
|
1361 |
} |
|
1362 |
@Override |
|
1363 |
void write(ClassWriter writer) { |
|
1364 |
super.write(writer); |
|
1365 |
if (getFrameType() == SAME_FRAME_EXTENDED) { |
|
1366 |
writer.databuf.appendChar(offsetDelta); |
|
1367 |
if (writer.debugstackmap){ |
|
1368 |
System.out.print(" offset_delta=" + offsetDelta); |
|
1369 |
} |
|
1370 |
} |
|
1371 |
} |
|
1372 |
} |
|
1373 |
||
1374 |
static class SameLocals1StackItemFrame extends StackMapTableFrame { |
|
1375 |
final int offsetDelta; |
|
1376 |
final Type stack; |
|
1377 |
SameLocals1StackItemFrame(int offsetDelta, Type stack) { |
|
1378 |
this.offsetDelta = offsetDelta; |
|
1379 |
this.stack = stack; |
|
1380 |
} |
|
1381 |
int getFrameType() { |
|
1382 |
return (offsetDelta < SAME_FRAME_SIZE) ? |
|
1383 |
(SAME_FRAME_SIZE + offsetDelta) : |
|
1384 |
SAME_LOCALS_1_STACK_ITEM_EXTENDED; |
|
1385 |
} |
|
1386 |
@Override |
|
1387 |
void write(ClassWriter writer) { |
|
1388 |
super.write(writer); |
|
1389 |
if (getFrameType() == SAME_LOCALS_1_STACK_ITEM_EXTENDED) { |
|
1390 |
writer.databuf.appendChar(offsetDelta); |
|
1391 |
if (writer.debugstackmap) { |
|
1392 |
System.out.print(" offset_delta=" + offsetDelta); |
|
1393 |
} |
|
1394 |
} |
|
1395 |
if (writer.debugstackmap) { |
|
1396 |
System.out.print(" stack[" + 0 + "]="); |
|
1397 |
} |
|
1398 |
writer.writeStackMapType(stack); |
|
1399 |
} |
|
1400 |
} |
|
1401 |
||
1402 |
static class ChopFrame extends StackMapTableFrame { |
|
1403 |
final int frameType; |
|
1404 |
final int offsetDelta; |
|
1405 |
ChopFrame(int frameType, int offsetDelta) { |
|
1406 |
this.frameType = frameType; |
|
1407 |
this.offsetDelta = offsetDelta; |
|
1408 |
} |
|
1409 |
int getFrameType() { return frameType; } |
|
1410 |
@Override |
|
1411 |
void write(ClassWriter writer) { |
|
1412 |
super.write(writer); |
|
1413 |
writer.databuf.appendChar(offsetDelta); |
|
1414 |
if (writer.debugstackmap) { |
|
1415 |
System.out.print(" offset_delta=" + offsetDelta); |
|
1416 |
} |
|
1417 |
} |
|
1418 |
} |
|
1419 |
||
1420 |
static class AppendFrame extends StackMapTableFrame { |
|
1421 |
final int frameType; |
|
1422 |
final int offsetDelta; |
|
1423 |
final Type[] locals; |
|
1424 |
AppendFrame(int frameType, int offsetDelta, Type[] locals) { |
|
1425 |
this.frameType = frameType; |
|
1426 |
this.offsetDelta = offsetDelta; |
|
1427 |
this.locals = locals; |
|
1428 |
} |
|
1429 |
int getFrameType() { return frameType; } |
|
1430 |
@Override |
|
1431 |
void write(ClassWriter writer) { |
|
1432 |
super.write(writer); |
|
1433 |
writer.databuf.appendChar(offsetDelta); |
|
1434 |
if (writer.debugstackmap) { |
|
1435 |
System.out.print(" offset_delta=" + offsetDelta); |
|
1436 |
} |
|
1437 |
for (int i=0; i<locals.length; i++) { |
|
1438 |
if (writer.debugstackmap) System.out.print(" locals[" + i + "]="); |
|
1439 |
writer.writeStackMapType(locals[i]); |
|
1440 |
} |
|
1441 |
} |
|
1442 |
} |
|
1443 |
||
1444 |
static class FullFrame extends StackMapTableFrame { |
|
1445 |
final int offsetDelta; |
|
1446 |
final Type[] locals; |
|
1447 |
final Type[] stack; |
|
1448 |
FullFrame(int offsetDelta, Type[] locals, Type[] stack) { |
|
1449 |
this.offsetDelta = offsetDelta; |
|
1450 |
this.locals = locals; |
|
1451 |
this.stack = stack; |
|
1452 |
} |
|
1453 |
int getFrameType() { return FULL_FRAME; } |
|
1454 |
@Override |
|
1455 |
void write(ClassWriter writer) { |
|
1456 |
super.write(writer); |
|
1457 |
writer.databuf.appendChar(offsetDelta); |
|
1458 |
writer.databuf.appendChar(locals.length); |
|
1459 |
if (writer.debugstackmap) { |
|
1460 |
System.out.print(" offset_delta=" + offsetDelta); |
|
1461 |
System.out.print(" nlocals=" + locals.length); |
|
1462 |
} |
|
1463 |
for (int i=0; i<locals.length; i++) { |
|
1464 |
if (writer.debugstackmap) System.out.print(" locals[" + i + "]="); |
|
1465 |
writer.writeStackMapType(locals[i]); |
|
1466 |
} |
|
1467 |
||
1468 |
writer.databuf.appendChar(stack.length); |
|
1469 |
if (writer.debugstackmap) { System.out.print(" nstack=" + stack.length); } |
|
1470 |
for (int i=0; i<stack.length; i++) { |
|
1471 |
if (writer.debugstackmap) System.out.print(" stack[" + i + "]="); |
|
1472 |
writer.writeStackMapType(stack[i]); |
|
1473 |
} |
|
1474 |
} |
|
1475 |
} |
|
1476 |
||
1477 |
/** Compare this frame with the previous frame and produce |
|
1478 |
* an entry of compressed stack map frame. */ |
|
1479 |
static StackMapTableFrame getInstance(Code.StackMapFrame this_frame, |
|
1480 |
int prev_pc, |
|
1481 |
Type[] prev_locals, |
|
1482 |
Types types) { |
|
1483 |
Type[] locals = this_frame.locals; |
|
1484 |
Type[] stack = this_frame.stack; |
|
1485 |
int offset_delta = this_frame.pc - prev_pc - 1; |
|
1486 |
if (stack.length == 1) { |
|
1487 |
if (locals.length == prev_locals.length |
|
1488 |
&& compare(prev_locals, locals, types) == 0) { |
|
1489 |
return new SameLocals1StackItemFrame(offset_delta, stack[0]); |
|
1490 |
} |
|
1491 |
} else if (stack.length == 0) { |
|
1492 |
int diff_length = compare(prev_locals, locals, types); |
|
1493 |
if (diff_length == 0) { |
|
1494 |
return new SameFrame(offset_delta); |
|
1495 |
} else if (-MAX_LOCAL_LENGTH_DIFF < diff_length && diff_length < 0) { |
|
1496 |
// APPEND |
|
1497 |
Type[] local_diff = new Type[-diff_length]; |
|
1498 |
for (int i=prev_locals.length, j=0; i<locals.length; i++,j++) { |
|
1499 |
local_diff[j] = locals[i]; |
|
1500 |
} |
|
1501 |
return new AppendFrame(SAME_FRAME_EXTENDED - diff_length, |
|
1502 |
offset_delta, |
|
1503 |
local_diff); |
|
1504 |
} else if (0 < diff_length && diff_length < MAX_LOCAL_LENGTH_DIFF) { |
|
1505 |
// CHOP |
|
1506 |
return new ChopFrame(SAME_FRAME_EXTENDED - diff_length, |
|
1507 |
offset_delta); |
|
1508 |
} |
|
1509 |
} |
|
1510 |
// FULL_FRAME |
|
1511 |
return new FullFrame(offset_delta, locals, stack); |
|
1512 |
} |
|
1513 |
||
1514 |
static boolean isInt(Type t) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1515 |
return (t.getTag().isStrictSubRangeOf(INT) || t.hasTag(BOOLEAN)); |
10 | 1516 |
} |
1517 |
||
1518 |
static boolean isSameType(Type t1, Type t2, Types types) { |
|
1519 |
if (t1 == null) { return t2 == null; } |
|
1520 |
if (t2 == null) { return false; } |
|
1521 |
||
1522 |
if (isInt(t1) && isInt(t2)) { return true; } |
|
1523 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1524 |
if (t1.hasTag(UNINITIALIZED_THIS)) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1525 |
return t2.hasTag(UNINITIALIZED_THIS); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1526 |
} else if (t1.hasTag(UNINITIALIZED_OBJECT)) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1527 |
if (t2.hasTag(UNINITIALIZED_OBJECT)) { |
10 | 1528 |
return ((UninitializedType)t1).offset == ((UninitializedType)t2).offset; |
1529 |
} else { |
|
1530 |
return false; |
|
1531 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1532 |
} else if (t2.hasTag(UNINITIALIZED_THIS) || t2.hasTag(UNINITIALIZED_OBJECT)) { |
10 | 1533 |
return false; |
1534 |
} |
|
1535 |
||
1536 |
return types.isSameType(t1, t2); |
|
1537 |
} |
|
1538 |
||
1539 |
static int compare(Type[] arr1, Type[] arr2, Types types) { |
|
1540 |
int diff_length = arr1.length - arr2.length; |
|
1541 |
if (diff_length > MAX_LOCAL_LENGTH_DIFF || diff_length < -MAX_LOCAL_LENGTH_DIFF) { |
|
1542 |
return Integer.MAX_VALUE; |
|
1543 |
} |
|
1544 |
int len = (diff_length > 0) ? arr2.length : arr1.length; |
|
1545 |
for (int i=0; i<len; i++) { |
|
1546 |
if (!isSameType(arr1[i], arr2[i], types)) { |
|
1547 |
return Integer.MAX_VALUE; |
|
1548 |
} |
|
1549 |
} |
|
1550 |
return diff_length; |
|
1551 |
} |
|
1552 |
} |
|
1553 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1554 |
void writeFields(Scope s) { |
10 | 1555 |
// process them in reverse sibling order; |
1556 |
// i.e., process them in declaration order. |
|
1557 |
List<VarSymbol> vars = List.nil(); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1558 |
for (Symbol sym : s.getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1559 |
if (sym.kind == VAR) vars = vars.prepend((VarSymbol)sym); |
10 | 1560 |
} |
1561 |
while (vars.nonEmpty()) { |
|
1562 |
writeField(vars.head); |
|
1563 |
vars = vars.tail; |
|
1564 |
} |
|
1565 |
} |
|
1566 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1567 |
void writeMethods(Scope s) { |
10 | 1568 |
List<MethodSymbol> methods = List.nil(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1569 |
for (Symbol sym : s.getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1570 |
if (sym.kind == MTH && (sym.flags() & HYPOTHETICAL) == 0) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1571 |
methods = methods.prepend((MethodSymbol)sym); |
10 | 1572 |
} |
1573 |
while (methods.nonEmpty()) { |
|
1574 |
writeMethod(methods.head); |
|
1575 |
methods = methods.tail; |
|
1576 |
} |
|
1577 |
} |
|
1578 |
||
1579 |
/** Emit a class file for a given class. |
|
1580 |
* @param c The class from which a class file is generated. |
|
1581 |
*/ |
|
1582 |
public JavaFileObject writeClass(ClassSymbol c) |
|
1583 |
throws IOException, PoolOverflow, StringOverflow |
|
1584 |
{ |
|
1585 |
JavaFileObject outFile |
|
1586 |
= fileManager.getJavaFileForOutput(CLASS_OUTPUT, |
|
1587 |
c.flatname.toString(), |
|
1588 |
JavaFileObject.Kind.CLASS, |
|
1589 |
c.sourcefile); |
|
1590 |
OutputStream out = outFile.openOutputStream(); |
|
1591 |
try { |
|
1592 |
writeClassFile(out, c); |
|
1593 |
if (verbose) |
|
8630 | 1594 |
log.printVerbose("wrote.file", outFile); |
10 | 1595 |
out.close(); |
1596 |
out = null; |
|
1597 |
} finally { |
|
1598 |
if (out != null) { |
|
17578 | 1599 |
// if we are propagating an exception, delete the file |
10 | 1600 |
out.close(); |
1601 |
outFile.delete(); |
|
1602 |
outFile = null; |
|
1603 |
} |
|
1604 |
} |
|
1605 |
return outFile; // may be null if write failed |
|
1606 |
} |
|
1607 |
||
1608 |
/** Write class `c' to outstream `out'. |
|
1609 |
*/ |
|
1610 |
public void writeClassFile(OutputStream out, ClassSymbol c) |
|
1611 |
throws IOException, PoolOverflow, StringOverflow { |
|
8032 | 1612 |
Assert.check((c.flags() & COMPOUND) == 0); |
10 | 1613 |
databuf.reset(); |
1614 |
poolbuf.reset(); |
|
16300 | 1615 |
signatureGen.reset(); |
10 | 1616 |
pool = c.pool; |
1617 |
innerClasses = null; |
|
1618 |
innerClassesQueue = null; |
|
22163 | 1619 |
bootstrapMethods = new LinkedHashMap<>(); |
10 | 1620 |
|
1621 |
Type supertype = types.supertype(c.type); |
|
1622 |
List<Type> interfaces = types.interfaces(c.type); |
|
1623 |
List<Type> typarams = c.type.getTypeArguments(); |
|
1624 |
||
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1625 |
int flags = adjustFlags(c.flags() & ~DEFAULT); |
10 | 1626 |
if ((flags & PROTECTED) != 0) flags |= PUBLIC; |
1627 |
flags = flags & ClassFlags & ~STRICTFP; |
|
1628 |
if ((flags & INTERFACE) == 0) flags |= ACC_SUPER; |
|
1629 |
if (c.isInner() && c.name.isEmpty()) flags &= ~FINAL; |
|
1630 |
if (dumpClassModifiers) { |
|
11052
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1631 |
PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1632 |
pw.println(); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1633 |
pw.println("CLASSFILE " + c.getQualifiedName()); |
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10627
diff
changeset
|
1634 |
pw.println("---" + flagNames(flags)); |
10 | 1635 |
} |
1636 |
databuf.appendChar(flags); |
|
1637 |
||
1638 |
databuf.appendChar(pool.put(c)); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14053
diff
changeset
|
1639 |
databuf.appendChar(supertype.hasTag(CLASS) ? pool.put(supertype.tsym) : 0); |
10 | 1640 |
databuf.appendChar(interfaces.length()); |
1641 |
for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) |
|
1642 |
databuf.appendChar(pool.put(l.head.tsym)); |
|
1643 |
int fieldsCount = 0; |
|
1644 |
int methodsCount = 0; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1645 |
for (Symbol sym : c.members().getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1646 |
switch (sym.kind) { |
10 | 1647 |
case VAR: fieldsCount++; break; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1648 |
case MTH: if ((sym.flags() & HYPOTHETICAL) == 0) methodsCount++; |
10 | 1649 |
break; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1650 |
case TYP: enterInner((ClassSymbol)sym); break; |
8032 | 1651 |
default : Assert.error(); |
10 | 1652 |
} |
1653 |
} |
|
10627
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1654 |
|
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1655 |
if (c.trans_local != null) { |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1656 |
for (ClassSymbol local : c.trans_local) { |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1657 |
enterInner(local); |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1658 |
} |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1659 |
} |
d8e900b62e02
7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents:
8630
diff
changeset
|
1660 |
|
10 | 1661 |
databuf.appendChar(fieldsCount); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1662 |
writeFields(c.members()); |
10 | 1663 |
databuf.appendChar(methodsCount); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
1664 |
writeMethods(c.members()); |
10 | 1665 |
|
1666 |
int acountIdx = beginAttrs(); |
|
1667 |
int acount = 0; |
|
1668 |
||
1669 |
boolean sigReq = |
|
3138
c9fe0e7472ac
6835430: javac does not generate signature attributes for classes extending parameterized inner classes
mcimadamore
parents:
1264
diff
changeset
|
1670 |
typarams.length() != 0 || supertype.allparams().length() != 0; |
10 | 1671 |
for (List<Type> l = interfaces; !sigReq && l.nonEmpty(); l = l.tail) |
3138
c9fe0e7472ac
6835430: javac does not generate signature attributes for classes extending parameterized inner classes
mcimadamore
parents:
1264
diff
changeset
|
1672 |
sigReq = l.head.allparams().length() != 0; |
10 | 1673 |
if (sigReq) { |
1674 |
int alenIdx = writeAttr(names.Signature); |
|
16300 | 1675 |
if (typarams.length() != 0) signatureGen.assembleParamsSig(typarams); |
1676 |
signatureGen.assembleSig(supertype); |
|
10 | 1677 |
for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) |
16300 | 1678 |
signatureGen.assembleSig(l.head); |
1679 |
databuf.appendChar(pool.put(signatureGen.toName())); |
|
1680 |
signatureGen.reset(); |
|
10 | 1681 |
endAttr(alenIdx); |
1682 |
acount++; |
|
1683 |
} |
|
1684 |
||
1685 |
if (c.sourcefile != null && emitSourceFile) { |
|
1686 |
int alenIdx = writeAttr(names.SourceFile); |
|
1687 |
// WHM 6/29/1999: Strip file path prefix. We do it here at |
|
1688 |
// the last possible moment because the sourcefile may be used |
|
1689 |
// elsewhere in error diagnostics. Fixes 4241573. |
|
1690 |
//databuf.appendChar(c.pool.put(c.sourcefile)); |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3300
diff
changeset
|
1691 |
String simpleName = BaseFileObject.getSimpleName(c.sourcefile); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3300
diff
changeset
|
1692 |
databuf.appendChar(c.pool.put(names.fromString(simpleName))); |
10 | 1693 |
endAttr(alenIdx); |
1694 |
acount++; |
|
1695 |
} |
|
1696 |
||
1697 |
if (genCrt) { |
|
1698 |
// Append SourceID attribute |
|
1699 |
int alenIdx = writeAttr(names.SourceID); |
|
1700 |
databuf.appendChar(c.pool.put(names.fromString(Long.toString(getLastModified(c.sourcefile))))); |
|
1701 |
endAttr(alenIdx); |
|
1702 |
acount++; |
|
1703 |
// Append CompilationID attribute |
|
1704 |
alenIdx = writeAttr(names.CompilationID); |
|
1705 |
databuf.appendChar(c.pool.put(names.fromString(Long.toString(System.currentTimeMillis())))); |
|
1706 |
endAttr(alenIdx); |
|
1707 |
acount++; |
|
1708 |
} |
|
1709 |
||
1710 |
acount += writeFlagAttrs(c.flags()); |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14949
diff
changeset
|
1711 |
acount += writeJavaAnnotations(c.getRawAttributes()); |
17578 | 1712 |
acount += writeTypeAnnotations(c.getRawTypeAttributes(), false); |
10 | 1713 |
acount += writeEnclosingMethodAttribute(c); |
13635
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1714 |
acount += writeExtraClassAttributes(c); |
10 | 1715 |
|
1716 |
poolbuf.appendInt(JAVA_MAGIC); |
|
1717 |
poolbuf.appendChar(target.minorVersion); |
|
1718 |
poolbuf.appendChar(target.majorVersion); |
|
1719 |
||
1720 |
writePool(c.pool); |
|
1721 |
||
1722 |
if (innerClasses != null) { |
|
1723 |
writeInnerClasses(); |
|
1724 |
acount++; |
|
1725 |
} |
|
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1726 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1727 |
if (!bootstrapMethods.isEmpty()) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1728 |
writeBootstrapMethods(); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1729 |
acount++; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1730 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13689
diff
changeset
|
1731 |
|
10 | 1732 |
endAttrs(acountIdx, acount); |
1733 |
||
1734 |
poolbuf.appendBytes(databuf.elems, 0, databuf.length); |
|
1735 |
out.write(poolbuf.elems, 0, poolbuf.length); |
|
1736 |
||
1737 |
pool = c.pool = null; // to conserve space |
|
1738 |
} |
|
1739 |
||
13635
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1740 |
/**Allows subclasses to write additional class attributes |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1741 |
* |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1742 |
* @return the number of attributes written |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1743 |
*/ |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1744 |
protected int writeExtraClassAttributes(ClassSymbol c) { |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1745 |
return 0; |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1746 |
} |
5c742eabba7c
7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents:
12213
diff
changeset
|
1747 |
|
10 | 1748 |
int adjustFlags(final long flags) { |
1749 |
int result = (int)flags; |
|
1750 |
||
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1751 |
if ((flags & BRIDGE) != 0) |
10 | 1752 |
result |= ACC_BRIDGE; |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1753 |
if ((flags & VARARGS) != 0) |
10 | 1754 |
result |= ACC_VARARGS; |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1755 |
if ((flags & DEFAULT) != 0) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1756 |
result &= ~ABSTRACT; |
10 | 1757 |
return result; |
1758 |
} |
|
1759 |
||
1760 |
long getLastModified(FileObject filename) { |
|
1761 |
long mod = 0; |
|
1762 |
try { |
|
1763 |
mod = filename.getLastModified(); |
|
1764 |
} catch (SecurityException e) { |
|
1765 |
throw new AssertionError("CRT: couldn't get source file modification date: " + e.getMessage()); |
|
1766 |
} |
|
1767 |
return mod; |
|
1768 |
} |
|
1769 |
} |