author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 22151 | cb8daa93eeb1 |
child 25445 | 603f0c93d5c9 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, 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.util.*; |
|
29 |
||
30 |
import com.sun.tools.javac.code.Flags; |
|
31 |
import com.sun.tools.javac.code.Symbol; |
|
32 |
import com.sun.tools.javac.util.*; |
|
33 |
||
15724 | 34 |
import static com.sun.tools.javac.main.Option.TARGET; |
6721 | 35 |
|
10 | 36 |
/** The classfile version target. |
37 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
38 |
* <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
|
39 |
* If you write code that depends on this, you do so at your own risk. |
10 | 40 |
* This code and its internal interfaces are subject to change or |
41 |
* deletion without notice.</b> |
|
42 |
*/ |
|
43 |
public enum Target { |
|
44 |
JDK1_1("1.1", 45, 3), |
|
45 |
JDK1_2("1.2", 46, 0), |
|
46 |
JDK1_3("1.3", 47, 0), |
|
47 |
||
48 |
/** J2SE1.4 = Merlin. */ |
|
49 |
JDK1_4("1.4", 48, 0), |
|
50 |
||
22151 | 51 |
/** JDK 5, codename Tiger. */ |
10 | 52 |
JDK1_5("1.5", 49, 0), |
53 |
||
54 |
/** JDK 6. */ |
|
55 |
JDK1_6("1.6", 50, 0), |
|
56 |
||
57 |
/** JDK 7. */ |
|
10180 | 58 |
JDK1_7("1.7", 51, 0), |
59 |
||
14445
835eb1433d39
8001112: Make -target 8 in javac generate version 52.0 classfile
ksrini
parents:
11314
diff
changeset
|
60 |
/** JDK 8. */ |
22151 | 61 |
JDK1_8("1.8", 52, 0), |
62 |
||
63 |
/** JDK 9, initially an alias for 8. */ |
|
64 |
JDK1_9("1.9", 52, 0); |
|
10 | 65 |
|
22163 | 66 |
private static final Context.Key<Target> targetKey = new Context.Key<>(); |
10 | 67 |
|
68 |
public static Target instance(Context context) { |
|
69 |
Target instance = context.get(targetKey); |
|
70 |
if (instance == null) { |
|
71 |
Options options = Options.instance(context); |
|
6721 | 72 |
String targetString = options.get(TARGET); |
10 | 73 |
if (targetString != null) instance = lookup(targetString); |
74 |
if (instance == null) instance = DEFAULT; |
|
75 |
context.put(targetKey, instance); |
|
76 |
} |
|
77 |
return instance; |
|
78 |
} |
|
79 |
||
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14445
diff
changeset
|
80 |
private static final Target MIN = values()[0]; |
10 | 81 |
public static Target MIN() { return MIN; } |
82 |
||
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14445
diff
changeset
|
83 |
private static final Target MAX = values()[values().length - 1]; |
10 | 84 |
public static Target MAX() { return MAX; } |
85 |
||
22151 | 86 |
private static final Map<String,Target> tab = new HashMap<>(); |
10 | 87 |
static { |
88 |
for (Target t : values()) { |
|
89 |
tab.put(t.name, t); |
|
90 |
} |
|
91 |
tab.put("5", JDK1_5); |
|
92 |
tab.put("6", JDK1_6); |
|
93 |
tab.put("7", JDK1_7); |
|
10180 | 94 |
tab.put("8", JDK1_8); |
22151 | 95 |
tab.put("9", JDK1_9); |
10 | 96 |
} |
97 |
||
98 |
public final String name; |
|
99 |
public final int majorVersion; |
|
100 |
public final int minorVersion; |
|
101 |
private Target(String name, int majorVersion, int minorVersion) { |
|
102 |
this.name = name; |
|
103 |
this.majorVersion = majorVersion; |
|
104 |
this.minorVersion = minorVersion; |
|
105 |
} |
|
106 |
||
22151 | 107 |
public static final Target DEFAULT = JDK1_9; |
10 | 108 |
|
109 |
public static Target lookup(String name) { |
|
110 |
return tab.get(name); |
|
111 |
} |
|
112 |
||
113 |
/** In -target 1.1 and earlier, the compiler is required to emit |
|
114 |
* synthetic method definitions in abstract classes for interface |
|
115 |
* methods that are not overridden. We call them "Miranda" methods. |
|
116 |
*/ |
|
117 |
public boolean requiresIproxy() { |
|
118 |
return compareTo(JDK1_1) <= 0; |
|
119 |
} |
|
120 |
||
121 |
/** Beginning in 1.4, we take advantage of the possibility of emitting |
|
122 |
* code to initialize fields before calling the superclass constructor. |
|
123 |
* This is allowed by the VM spec, but the verifier refused to allow |
|
124 |
* it until 1.4. This is necesary to translate some code involving |
|
125 |
* inner classes. See, for example, 4030374. |
|
126 |
*/ |
|
127 |
public boolean initializeFieldsBeforeSuper() { |
|
128 |
return compareTo(JDK1_4) >= 0; |
|
129 |
} |
|
130 |
||
131 |
/** Beginning with -target 1.2 we obey the JLS rules for binary |
|
132 |
* compatibility, emitting as the qualifying type of a reference |
|
133 |
* to a method or field the type of the qualifier. In earlier |
|
134 |
* targets we use as the qualifying type the class in which the |
|
135 |
* member was found. The following methods named |
|
136 |
* *binaryCompatibility() indicate places where we vary from this |
|
137 |
* general rule. */ |
|
138 |
public boolean obeyBinaryCompatibility() { |
|
139 |
return compareTo(JDK1_2) >= 0; |
|
140 |
} |
|
141 |
||
142 |
/** Starting in 1.5, the compiler uses an array type as |
|
143 |
* the qualifier for method calls (such as clone) where required by |
|
144 |
* the language and VM spec. Earlier versions of the compiler |
|
145 |
* qualified them by Object. |
|
146 |
*/ |
|
147 |
public boolean arrayBinaryCompatibility() { |
|
148 |
return compareTo(JDK1_5) >= 0; |
|
149 |
} |
|
150 |
||
151 |
/** Beginning after 1.2, we follow the binary compatibility rules for |
|
152 |
* interface fields. The 1.2 VMs had bugs handling interface fields |
|
153 |
* when compiled using binary compatibility (see 4400598), so this is |
|
154 |
* an accommodation to them. |
|
155 |
*/ |
|
156 |
public boolean interfaceFieldsBinaryCompatibility() { |
|
157 |
return compareTo(JDK1_2) > 0; |
|
158 |
} |
|
159 |
||
160 |
/** Beginning in -target 1.5, we follow the binary compatibility |
|
161 |
* rules for interface methods that redefine Object methods. |
|
162 |
* Earlier VMs had bugs handling such methods compiled using binary |
|
163 |
* compatibility (see 4392595, 4398791, 4392595, 4400415). |
|
164 |
* The VMs were fixed during or soon after 1.4. See 4392595. |
|
165 |
*/ |
|
166 |
public boolean interfaceObjectOverridesBinaryCompatibility() { |
|
167 |
return compareTo(JDK1_5) >= 0; |
|
168 |
} |
|
169 |
||
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
170 |
/** Beginning in -target 1.5, we make synthetic variables |
10 | 171 |
* package-private instead of private. This is to prevent the |
172 |
* necessity of access methods, which effectively relax the |
|
173 |
* protection of the field but bloat the class files and affect |
|
174 |
* execution. |
|
175 |
*/ |
|
176 |
public boolean usePrivateSyntheticFields() { |
|
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
177 |
return compareTo(JDK1_5) < 0; |
10 | 178 |
} |
179 |
||
180 |
/** Sometimes we need to create a field to cache a value like a |
|
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
181 |
* class literal of the assertions flag. In -target 1.5 and |
10 | 182 |
* later we create a new synthetic class for this instead of |
183 |
* using the outermost class. See 4401576. |
|
184 |
*/ |
|
185 |
public boolean useInnerCacheClass() { |
|
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
186 |
return compareTo(JDK1_5) >= 0; |
10 | 187 |
} |
188 |
||
189 |
/** Return true if cldc-style stack maps need to be generated. */ |
|
190 |
public boolean generateCLDCStackmap() { |
|
191 |
return false; |
|
192 |
} |
|
193 |
||
194 |
/** Beginning in -target 6, we generate stackmap attribute in |
|
195 |
* compact format. */ |
|
196 |
public boolean generateStackMapTable() { |
|
197 |
return compareTo(JDK1_6) >= 0; |
|
198 |
} |
|
199 |
||
200 |
/** Beginning in -target 6, package-info classes are marked synthetic. |
|
201 |
*/ |
|
202 |
public boolean isPackageInfoSynthetic() { |
|
203 |
return compareTo(JDK1_6) >= 0; |
|
204 |
} |
|
205 |
||
206 |
/** Do we generate "empty" stackmap slots after double and long? |
|
207 |
*/ |
|
208 |
public boolean generateEmptyAfterBig() { |
|
209 |
return false; |
|
210 |
} |
|
211 |
||
212 |
/** Beginning in 1.5, we have an unsynchronized version of |
|
213 |
* StringBuffer called StringBuilder that can be used by the |
|
214 |
* compiler for string concatenation. |
|
215 |
*/ |
|
216 |
public boolean useStringBuilder() { |
|
217 |
return compareTo(JDK1_5) >= 0; |
|
218 |
} |
|
219 |
||
220 |
/** Beginning in 1.5, we have flag bits we can use instead of |
|
221 |
* marker attributes. |
|
222 |
*/ |
|
223 |
public boolean useSyntheticFlag() { |
|
224 |
return compareTo(JDK1_5) >= 0; |
|
225 |
} |
|
226 |
public boolean useEnumFlag() { |
|
227 |
return compareTo(JDK1_5) >= 0; |
|
228 |
} |
|
229 |
public boolean useAnnotationFlag() { |
|
230 |
return compareTo(JDK1_5) >= 0; |
|
231 |
} |
|
232 |
public boolean useVarargsFlag() { |
|
233 |
return compareTo(JDK1_5) >= 0; |
|
234 |
} |
|
235 |
public boolean useBridgeFlag() { |
|
236 |
return compareTo(JDK1_5) >= 0; |
|
237 |
} |
|
238 |
||
239 |
/** Return the character to be used in constructing synthetic |
|
240 |
* identifiers, where not specified by the JLS. |
|
241 |
*/ |
|
242 |
public char syntheticNameChar() { |
|
243 |
return '$'; |
|
244 |
} |
|
245 |
||
246 |
/** Does the VM have direct support for class literals? |
|
247 |
*/ |
|
248 |
public boolean hasClassLiterals() { |
|
249 |
return compareTo(JDK1_5) >= 0; |
|
250 |
} |
|
251 |
||
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
252 |
/** Does the VM support an invokedynamic instruction? |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
253 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
254 |
public boolean hasInvokedynamic() { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
255 |
return compareTo(JDK1_7) >= 0; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
256 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
257 |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
258 |
/** Does the VM support polymorphic method handle invocation? |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
259 |
* Affects the linkage information output to the classfile. |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
260 |
* An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together. |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
261 |
*/ |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
262 |
public boolean hasMethodHandles() { |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
263 |
return hasInvokedynamic(); |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
264 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
265 |
|
10 | 266 |
/** Although we may not have support for class literals, should we |
267 |
* avoid initializing the class that the literal refers to? |
|
268 |
* See 4468823 |
|
269 |
*/ |
|
270 |
public boolean classLiteralsNoInit() { |
|
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
271 |
return compareTo(JDK1_5) >= 0; |
10 | 272 |
} |
273 |
||
274 |
/** Although we may not have support for class literals, when we |
|
275 |
* throw a NoClassDefFoundError, should we initialize its cause? |
|
276 |
*/ |
|
277 |
public boolean hasInitCause() { |
|
278 |
return compareTo(JDK1_4) >= 0; |
|
279 |
} |
|
280 |
||
281 |
/** For bootstrapping, we use J2SE1.4's wrapper class constructors |
|
282 |
* to implement boxing. |
|
283 |
*/ |
|
284 |
public boolean boxWithConstructors() { |
|
285 |
return compareTo(JDK1_5) < 0; |
|
286 |
} |
|
287 |
||
288 |
/** For bootstrapping, we use J2SE1.4's java.util.Collection |
|
289 |
* instead of java.lang.Iterable. |
|
290 |
*/ |
|
291 |
public boolean hasIterable() { |
|
292 |
return compareTo(JDK1_5) >= 0; |
|
293 |
} |
|
294 |
||
295 |
/** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute |
|
296 |
* for improved reflection support. |
|
297 |
*/ |
|
298 |
public boolean hasEnclosingMethodAttribute() { |
|
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
15724
diff
changeset
|
299 |
return compareTo(JDK1_5) >= 0; |
10 | 300 |
} |
301 |
} |