author | alanb |
Sat, 23 Jun 2018 09:46:18 +0100 | |
changeset 50740 | edf11e5dc766 |
parent 50738 | 6cc2dc161c64 |
parent 50735 | 2f2af62dfac7 |
child 50892 | a5557f24b4d4 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
48746
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
2 |
* Copyright (c) 2002, 2018, 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 |
||
37940 | 63 |
/** JDK 9. */ |
43646 | 64 |
JDK1_9("1.9", 53, 0), |
65 |
||
48081 | 66 |
/** JDK 10. */ |
48343 | 67 |
JDK1_10("1.10", 54, 0), |
68 |
||
69 |
/** JDK 11. */ |
|
48355 | 70 |
JDK1_11("11", 55, 0); |
10 | 71 |
|
22163 | 72 |
private static final Context.Key<Target> targetKey = new Context.Key<>(); |
10 | 73 |
|
74 |
public static Target instance(Context context) { |
|
75 |
Target instance = context.get(targetKey); |
|
76 |
if (instance == null) { |
|
77 |
Options options = Options.instance(context); |
|
6721 | 78 |
String targetString = options.get(TARGET); |
10 | 79 |
if (targetString != null) instance = lookup(targetString); |
80 |
if (instance == null) instance = DEFAULT; |
|
81 |
context.put(targetKey, instance); |
|
82 |
} |
|
83 |
return instance; |
|
84 |
} |
|
85 |
||
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
22163
diff
changeset
|
86 |
public static final Target MIN = Target.JDK1_6; |
10 | 87 |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14445
diff
changeset
|
88 |
private static final Target MAX = values()[values().length - 1]; |
10 | 89 |
|
22151 | 90 |
private static final Map<String,Target> tab = new HashMap<>(); |
10 | 91 |
static { |
92 |
for (Target t : values()) { |
|
93 |
tab.put(t.name, t); |
|
94 |
} |
|
95 |
tab.put("5", JDK1_5); |
|
96 |
tab.put("6", JDK1_6); |
|
97 |
tab.put("7", JDK1_7); |
|
10180 | 98 |
tab.put("8", JDK1_8); |
22151 | 99 |
tab.put("9", JDK1_9); |
43646 | 100 |
tab.put("10", JDK1_10); |
48343 | 101 |
tab.put("11", JDK1_11); |
10 | 102 |
} |
103 |
||
104 |
public final String name; |
|
105 |
public final int majorVersion; |
|
106 |
public final int minorVersion; |
|
107 |
private Target(String name, int majorVersion, int minorVersion) { |
|
108 |
this.name = name; |
|
109 |
this.majorVersion = majorVersion; |
|
110 |
this.minorVersion = minorVersion; |
|
111 |
} |
|
112 |
||
43646 | 113 |
public static final Target DEFAULT = values()[values().length - 1]; |
10 | 114 |
|
115 |
public static Target lookup(String name) { |
|
116 |
return tab.get(name); |
|
117 |
} |
|
118 |
||
119 |
/** Return the character to be used in constructing synthetic |
|
120 |
* identifiers, where not specified by the JLS. |
|
121 |
*/ |
|
122 |
public char syntheticNameChar() { |
|
123 |
return '$'; |
|
124 |
} |
|
125 |
||
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
126 |
/** Does the VM support an invokedynamic instruction? |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
127 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
128 |
public boolean hasInvokedynamic() { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
129 |
return compareTo(JDK1_7) >= 0; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
130 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
10
diff
changeset
|
131 |
|
29295
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
25874
diff
changeset
|
132 |
/** Does the target JDK contains the java.util.Objects class? |
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
25874
diff
changeset
|
133 |
*/ |
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
25874
diff
changeset
|
134 |
public boolean hasObjects() { |
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
25874
diff
changeset
|
135 |
return compareTo(JDK1_7) >= 0; |
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
25874
diff
changeset
|
136 |
} |
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
25874
diff
changeset
|
137 |
|
48746
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
138 |
/** Does the target VM expect MethodParameters attributes? |
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
139 |
*/ |
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
140 |
public boolean hasMethodParameters() { |
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
141 |
return compareTo(JDK1_8) >= 0; |
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
142 |
} |
c9ab849cd2f5
8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents:
48355
diff
changeset
|
143 |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
144 |
/** 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
|
145 |
* 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
|
146 |
* 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
|
147 |
*/ |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
148 |
public boolean hasMethodHandles() { |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
149 |
return hasInvokedynamic(); |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
150 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
5847
diff
changeset
|
151 |
|
35424 | 152 |
/** Does the target JDK contain StringConcatFactory class? |
153 |
*/ |
|
154 |
public boolean hasStringConcatFactory() { |
|
155 |
return compareTo(JDK1_9) >= 0; |
|
156 |
} |
|
157 |
||
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
35424
diff
changeset
|
158 |
/** Value of platform release used to access multi-release jar files |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
35424
diff
changeset
|
159 |
*/ |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
35424
diff
changeset
|
160 |
public String multiReleaseValue() { |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
35424
diff
changeset
|
161 |
return Integer.toString(this.ordinal() - Target.JDK1_1.ordinal() + 1); |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
35424
diff
changeset
|
162 |
} |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
163 |
|
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
48746
diff
changeset
|
164 |
/** All modules that export an API are roots when compiling code in the unnamed |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
48746
diff
changeset
|
165 |
* module and targeting 11 or newer. |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
48746
diff
changeset
|
166 |
*/ |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
48746
diff
changeset
|
167 |
public boolean allApiModulesAreRoots() { |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
48746
diff
changeset
|
168 |
return compareTo(JDK1_11) >= 0; |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
48746
diff
changeset
|
169 |
} |
50740 | 170 |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
171 |
/** Does the target VM support nestmate access? |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
172 |
*/ |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
173 |
public boolean hasNestmateAccess() { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
174 |
return compareTo(JDK1_11) >= 0; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
175 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
176 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
177 |
/** Does the target VM support virtual private invocations? |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
178 |
*/ |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
179 |
public boolean hasVirtualPrivateInvoke() { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
180 |
return compareTo(JDK1_11) >= 0; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
181 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
48746
diff
changeset
|
182 |
|
10 | 183 |
} |