0N/A/*
797N/A * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.javac.jvm;
0N/A
0N/Aimport java.util.*;
0N/A
0N/Aimport com.sun.tools.javac.code.Flags;
0N/Aimport com.sun.tools.javac.code.Symbol;
0N/Aimport com.sun.tools.javac.util.*;
0N/A
699N/Aimport static com.sun.tools.javac.main.OptionName.*;
699N/A
0N/A/** The classfile version target.
0N/A *
580N/A * <p><b>This is NOT part of any supported API.
580N/A * If you write code that depends on this, you do so at your own risk.
0N/A * This code and its internal interfaces are subject to change or
0N/A * deletion without notice.</b>
0N/A */
0N/Apublic enum Target {
0N/A JDK1_1("1.1", 45, 3),
0N/A JDK1_2("1.2", 46, 0),
0N/A JDK1_3("1.3", 47, 0),
0N/A
0N/A /** J2SE1.4 = Merlin. */
0N/A JDK1_4("1.4", 48, 0),
0N/A
0N/A /** Support for the JSR14 prototype compiler (targeting 1.4 VMs
0N/A * augmented with a few support classes). This is a transitional
0N/A * option that will not be supported in the product. */
0N/A JSR14("jsr14", 48, 0),
0N/A
0N/A /** The following are undocumented transitional targets that we
0N/A * had used to test VM fixes in update releases. We do not
0N/A * promise to retain support for them. */
0N/A JDK1_4_1("1.4.1", 48, 0),
0N/A JDK1_4_2("1.4.2", 48, 0),
0N/A
0N/A /** Tiger. */
0N/A JDK1_5("1.5", 49, 0),
0N/A
0N/A /** JDK 6. */
0N/A JDK1_6("1.6", 50, 0),
0N/A
0N/A /** JDK 7. */
0N/A JDK1_7("1.7", 51, 0);
0N/A
0N/A private static final Context.Key<Target> targetKey =
0N/A new Context.Key<Target>();
0N/A
0N/A public static Target instance(Context context) {
0N/A Target instance = context.get(targetKey);
0N/A if (instance == null) {
0N/A Options options = Options.instance(context);
699N/A String targetString = options.get(TARGET);
0N/A if (targetString != null) instance = lookup(targetString);
0N/A if (instance == null) instance = DEFAULT;
0N/A context.put(targetKey, instance);
0N/A }
0N/A return instance;
0N/A }
0N/A
0N/A private static Target MIN;
0N/A public static Target MIN() { return MIN; }
0N/A
0N/A private static Target MAX;
0N/A public static Target MAX() { return MAX; }
0N/A
0N/A private static Map<String,Target> tab = new HashMap<String,Target>();
0N/A static {
0N/A for (Target t : values()) {
0N/A if (MIN == null) MIN = t;
0N/A MAX = t;
0N/A tab.put(t.name, t);
0N/A }
0N/A tab.put("5", JDK1_5);
0N/A tab.put("6", JDK1_6);
0N/A tab.put("7", JDK1_7);
0N/A }
0N/A
0N/A public final String name;
0N/A public final int majorVersion;
0N/A public final int minorVersion;
0N/A private Target(String name, int majorVersion, int minorVersion) {
0N/A this.name = name;
0N/A this.majorVersion = majorVersion;
0N/A this.minorVersion = minorVersion;
0N/A }
0N/A
285N/A public static final Target DEFAULT = JDK1_7;
0N/A
0N/A public static Target lookup(String name) {
0N/A return tab.get(name);
0N/A }
0N/A
0N/A /** In -target 1.1 and earlier, the compiler is required to emit
0N/A * synthetic method definitions in abstract classes for interface
0N/A * methods that are not overridden. We call them "Miranda" methods.
0N/A */
0N/A public boolean requiresIproxy() {
0N/A return compareTo(JDK1_1) <= 0;
0N/A }
0N/A
0N/A /** Beginning in 1.4, we take advantage of the possibility of emitting
0N/A * code to initialize fields before calling the superclass constructor.
0N/A * This is allowed by the VM spec, but the verifier refused to allow
0N/A * it until 1.4. This is necesary to translate some code involving
0N/A * inner classes. See, for example, 4030374.
0N/A */
0N/A public boolean initializeFieldsBeforeSuper() {
0N/A return compareTo(JDK1_4) >= 0;
0N/A }
0N/A
0N/A /** Beginning with -target 1.2 we obey the JLS rules for binary
0N/A * compatibility, emitting as the qualifying type of a reference
0N/A * to a method or field the type of the qualifier. In earlier
0N/A * targets we use as the qualifying type the class in which the
0N/A * member was found. The following methods named
0N/A * *binaryCompatibility() indicate places where we vary from this
0N/A * general rule. */
0N/A public boolean obeyBinaryCompatibility() {
0N/A return compareTo(JDK1_2) >= 0;
0N/A }
0N/A
0N/A /** Starting in 1.5, the compiler uses an array type as
0N/A * the qualifier for method calls (such as clone) where required by
0N/A * the language and VM spec. Earlier versions of the compiler
0N/A * qualified them by Object.
0N/A */
0N/A public boolean arrayBinaryCompatibility() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A
0N/A /** Beginning after 1.2, we follow the binary compatibility rules for
0N/A * interface fields. The 1.2 VMs had bugs handling interface fields
0N/A * when compiled using binary compatibility (see 4400598), so this is
0N/A * an accommodation to them.
0N/A */
0N/A public boolean interfaceFieldsBinaryCompatibility() {
0N/A return compareTo(JDK1_2) > 0;
0N/A }
0N/A
0N/A /** Beginning in -target 1.5, we follow the binary compatibility
0N/A * rules for interface methods that redefine Object methods.
0N/A * Earlier VMs had bugs handling such methods compiled using binary
0N/A * compatibility (see 4392595, 4398791, 4392595, 4400415).
0N/A * The VMs were fixed during or soon after 1.4. See 4392595.
0N/A */
0N/A public boolean interfaceObjectOverridesBinaryCompatibility() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A
0N/A /** Beginning in -target 1.4.2, we make synthetic variables
0N/A * package-private instead of private. This is to prevent the
0N/A * necessity of access methods, which effectively relax the
0N/A * protection of the field but bloat the class files and affect
0N/A * execution.
0N/A */
0N/A public boolean usePrivateSyntheticFields() {
0N/A return compareTo(JDK1_4_2) < 0;
0N/A }
0N/A
0N/A /** Sometimes we need to create a field to cache a value like a
0N/A * class literal of the assertions flag. In -target 1.4.2 and
0N/A * later we create a new synthetic class for this instead of
0N/A * using the outermost class. See 4401576.
0N/A */
0N/A public boolean useInnerCacheClass() {
0N/A return compareTo(JDK1_4_2) >= 0;
0N/A }
0N/A
0N/A /** Return true if cldc-style stack maps need to be generated. */
0N/A public boolean generateCLDCStackmap() {
0N/A return false;
0N/A }
0N/A
0N/A /** Beginning in -target 6, we generate stackmap attribute in
0N/A * compact format. */
0N/A public boolean generateStackMapTable() {
0N/A return compareTo(JDK1_6) >= 0;
0N/A }
0N/A
0N/A /** Beginning in -target 6, package-info classes are marked synthetic.
0N/A */
0N/A public boolean isPackageInfoSynthetic() {
0N/A return compareTo(JDK1_6) >= 0;
0N/A }
0N/A
0N/A /** Do we generate "empty" stackmap slots after double and long?
0N/A */
0N/A public boolean generateEmptyAfterBig() {
0N/A return false;
0N/A }
0N/A
0N/A /** Beginning in 1.5, we have an unsynchronized version of
0N/A * StringBuffer called StringBuilder that can be used by the
0N/A * compiler for string concatenation.
0N/A */
0N/A public boolean useStringBuilder() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A
0N/A /** Beginning in 1.5, we have flag bits we can use instead of
0N/A * marker attributes.
0N/A */
0N/A public boolean useSyntheticFlag() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A public boolean useEnumFlag() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A public boolean useAnnotationFlag() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A public boolean useVarargsFlag() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A public boolean useBridgeFlag() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A
0N/A /** Return the character to be used in constructing synthetic
0N/A * identifiers, where not specified by the JLS.
0N/A */
0N/A public char syntheticNameChar() {
0N/A return '$';
0N/A }
0N/A
0N/A /** Does the VM have direct support for class literals?
0N/A */
0N/A public boolean hasClassLiterals() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A
266N/A /** Does the VM support an invokedynamic instruction?
266N/A */
266N/A public boolean hasInvokedynamic() {
266N/A return compareTo(JDK1_7) >= 0;
266N/A }
266N/A
673N/A /** Does the VM support polymorphic method handle invocation?
673N/A * Affects the linkage information output to the classfile.
673N/A * An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together.
673N/A */
673N/A public boolean hasMethodHandles() {
673N/A return hasInvokedynamic();
673N/A }
673N/A
0N/A /** Although we may not have support for class literals, should we
0N/A * avoid initializing the class that the literal refers to?
0N/A * See 4468823
0N/A */
0N/A public boolean classLiteralsNoInit() {
0N/A return compareTo(JDK1_4_2) >= 0;
0N/A }
0N/A
0N/A /** Although we may not have support for class literals, when we
0N/A * throw a NoClassDefFoundError, should we initialize its cause?
0N/A */
0N/A public boolean hasInitCause() {
0N/A return compareTo(JDK1_4) >= 0;
0N/A }
0N/A
0N/A /** For bootstrapping, we use J2SE1.4's wrapper class constructors
0N/A * to implement boxing.
0N/A */
0N/A public boolean boxWithConstructors() {
0N/A return compareTo(JDK1_5) < 0;
0N/A }
0N/A
0N/A /** For bootstrapping, we use J2SE1.4's java.util.Collection
0N/A * instead of java.lang.Iterable.
0N/A */
0N/A public boolean hasIterable() {
0N/A return compareTo(JDK1_5) >= 0;
0N/A }
0N/A
0N/A /** For bootstrapping javac only, we do without java.lang.Enum if
0N/A * necessary.
0N/A */
0N/A public boolean compilerBootstrap(Symbol c) {
0N/A return
0N/A this == JSR14 &&
0N/A (c.flags() & Flags.ENUM) != 0 &&
0N/A c.flatName().toString().startsWith("com.sun.tools.")
0N/A // && !Target.class.getSuperclass().getName().equals("java.lang.Enum")
0N/A ;
0N/A }
0N/A
0N/A /** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute
0N/A * for improved reflection support.
0N/A */
0N/A public boolean hasEnclosingMethodAttribute() {
0N/A return compareTo(JDK1_5) >= 0 || this == JSR14;
0N/A }
0N/A}