src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java
author darcy
Thu, 13 Dec 2018 19:06:11 +0100
changeset 53023 6879069d9d94
parent 51047 860a3648c494
child 55382 30b1b7b4dd86
permissions -rw-r--r--
8205626: Start of release updates for JDK 13 8205393: Add SourceVersion.RELEASE_13 8205394: Add source 13 and target 13 to javac 8205645: Bump maximum recognized class file version to 57 for JDK 13 8214825: Update preview language features for start of JDK 13 Reviewed-by: erikj, alanb, mchung, mcimadamore, dholmes, smarks, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     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
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2982
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2982
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2982
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2982
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2982
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.Flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.code.Symbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14801
diff changeset
    34
import static com.sun.tools.javac.main.Option.TARGET;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    35
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/** The classfile version target.
06bc494ca11e Initial load
duke
parents:
diff changeset
    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
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
public enum Target {
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    JDK1_1("1.1", 45, 3),
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    JDK1_2("1.2", 46, 0),
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    JDK1_3("1.3", 47, 0),
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /** J2SE1.4 = Merlin. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    JDK1_4("1.4", 48, 0),
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 16558
diff changeset
    51
    /** JDK 5, codename Tiger. */
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
    52
    JDK1_5("5", 49, 0),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /** JDK 6. */
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
    55
    JDK1_6("6", 50, 0),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** JDK 7. */
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
    58
    JDK1_7("7", 51, 0),
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 7681
diff changeset
    59
14445
835eb1433d39 8001112: Make -target 8 in javac generate version 52.0 classfile
ksrini
parents: 11314
diff changeset
    60
    /** JDK 8. */
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
    61
    JDK1_8("8", 52, 0),
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 16558
diff changeset
    62
37940
ead113a2f92e 8150011: Update javac to generate V53.0 class files
jjg
parents: 37394
diff changeset
    63
    /** JDK 9. */
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
    64
    JDK1_9("9", 53, 0),
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 37940
diff changeset
    65
48081
89829dd3cc54 8188870: Bump classfile version number to 54
psandoz
parents: 47216
diff changeset
    66
    /** JDK 10. */
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
    67
    JDK1_10("10", 54, 0),
48343
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48081
diff changeset
    68
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48081
diff changeset
    69
    /** JDK 11. */
50892
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50740
diff changeset
    70
    JDK1_11("11", 55, 0),
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50740
diff changeset
    71
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50740
diff changeset
    72
    /** JDK 12. */
53023
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 51047
diff changeset
    73
    JDK1_12("12", 56, 0),
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 51047
diff changeset
    74
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 51047
diff changeset
    75
    /** JDK 13. */
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 51047
diff changeset
    76
    JDK1_13("13", 57, 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22151
diff changeset
    78
    private static final Context.Key<Target> targetKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public static Target instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        Target instance = context.get(targetKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        if (instance == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            Options options = Options.instance(context);
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    84
            String targetString = options.get(TARGET);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            if (targetString != null) instance = lookup(targetString);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            if (instance == null) instance = DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            context.put(targetKey, instance);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
51047
860a3648c494 8028563: Remove javac support for 6/1.6 source and target values
darcy
parents: 51040
diff changeset
    92
    public static final Target MIN = Target.JDK1_7;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14445
diff changeset
    94
    private static final Target MAX = values()[values().length - 1];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 16558
diff changeset
    96
    private static final Map<String,Target> tab = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        for (Target t : values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            tab.put(t.name, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        }
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   101
        tab.put("1.5", JDK1_5);
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   102
        tab.put("1.6", JDK1_6);
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   103
        tab.put("1.7", JDK1_7);
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   104
        tab.put("1.8", JDK1_8);
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   105
        tab.put("1.9", JDK1_9);
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   106
        tab.put("1.10", JDK1_10);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public final String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    public final int majorVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    public final int minorVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    private Target(String name, int majorVersion, int minorVersion) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        this.majorVersion = majorVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        this.minorVersion = minorVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 37940
diff changeset
   118
    public static final Target DEFAULT = values()[values().length - 1];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    public static Target lookup(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        return tab.get(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   124
    public boolean isSupported() {
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   125
        return this.compareTo(MIN) >= 0;
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   126
    }
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   127
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /** Return the character to be used in constructing synthetic
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *  identifiers, where not specified by the JLS.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public char syntheticNameChar() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        return '$';
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
48746
c9ab849cd2f5 8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents: 48355
diff changeset
   135
    /** 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
   136
     */
c9ab849cd2f5 8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents: 48355
diff changeset
   137
    public boolean hasMethodParameters() {
c9ab849cd2f5 8190452: javac should not add MethodParameters attributes to v51 and earlier class files
cushon
parents: 48355
diff changeset
   138
        return compareTo(JDK1_8) >= 0;
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
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 29295
diff changeset
   141
    /** Does the target JDK contain StringConcatFactory class?
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 29295
diff changeset
   142
     */
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 29295
diff changeset
   143
    public boolean hasStringConcatFactory() {
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 29295
diff changeset
   144
        return compareTo(JDK1_9) >= 0;
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 29295
diff changeset
   145
    }
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 29295
diff changeset
   146
37394
c36230ee15d9 8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents: 35424
diff changeset
   147
    /** 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
   148
     */
c36230ee15d9 8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents: 35424
diff changeset
   149
    public String multiReleaseValue() {
c36230ee15d9 8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents: 35424
diff changeset
   150
        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
   151
    }
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   152
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
   153
    /** 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
   154
     *  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
   155
     */
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
   156
    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
   157
        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
   158
    }
50740
alanb
parents: 50738 50735
diff changeset
   159
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   160
    /** Does the target VM support nestmate access?
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   161
     */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   162
    public boolean hasNestmateAccess() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   163
        return compareTo(JDK1_11) >= 0;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   164
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   165
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   166
    /** Does the target VM support virtual private invocations?
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   167
     */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   168
    public boolean hasVirtualPrivateInvoke() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   169
        return compareTo(JDK1_11) >= 0;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   170
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 48746
diff changeset
   171
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
}