src/share/classes/com/sun/tools/javac/jvm/Target.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javac.jvm;
aoqi@0 27
aoqi@0 28 import java.util.*;
aoqi@0 29
aoqi@0 30 import com.sun.tools.javac.code.Flags;
aoqi@0 31 import com.sun.tools.javac.code.Symbol;
aoqi@0 32 import com.sun.tools.javac.util.*;
aoqi@0 33
aoqi@0 34 import static com.sun.tools.javac.main.Option.TARGET;
aoqi@0 35
aoqi@0 36 /** The classfile version target.
aoqi@0 37 *
aoqi@0 38 * <p><b>This is NOT part of any supported API.
aoqi@0 39 * If you write code that depends on this, you do so at your own risk.
aoqi@0 40 * This code and its internal interfaces are subject to change or
aoqi@0 41 * deletion without notice.</b>
aoqi@0 42 */
aoqi@0 43 public enum Target {
aoqi@0 44 JDK1_1("1.1", 45, 3),
aoqi@0 45 JDK1_2("1.2", 46, 0),
aoqi@0 46 JDK1_3("1.3", 47, 0),
aoqi@0 47
aoqi@0 48 /** J2SE1.4 = Merlin. */
aoqi@0 49 JDK1_4("1.4", 48, 0),
aoqi@0 50
aoqi@0 51 /** Tiger. */
aoqi@0 52 JDK1_5("1.5", 49, 0),
aoqi@0 53
aoqi@0 54 /** JDK 6. */
aoqi@0 55 JDK1_6("1.6", 50, 0),
aoqi@0 56
aoqi@0 57 /** JDK 7. */
aoqi@0 58 JDK1_7("1.7", 51, 0),
aoqi@0 59
aoqi@0 60 /** JDK 8. */
aoqi@0 61 JDK1_8("1.8", 52, 0);
aoqi@0 62
aoqi@0 63 private static final Context.Key<Target> targetKey =
aoqi@0 64 new Context.Key<Target>();
aoqi@0 65
aoqi@0 66 public static Target instance(Context context) {
aoqi@0 67 Target instance = context.get(targetKey);
aoqi@0 68 if (instance == null) {
aoqi@0 69 Options options = Options.instance(context);
aoqi@0 70 String targetString = options.get(TARGET);
aoqi@0 71 if (targetString != null) instance = lookup(targetString);
aoqi@0 72 if (instance == null) instance = DEFAULT;
aoqi@0 73 context.put(targetKey, instance);
aoqi@0 74 }
aoqi@0 75 return instance;
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 private static final Target MIN = values()[0];
aoqi@0 79 public static Target MIN() { return MIN; }
aoqi@0 80
aoqi@0 81 private static final Target MAX = values()[values().length - 1];
aoqi@0 82 public static Target MAX() { return MAX; }
aoqi@0 83
aoqi@0 84 private static final Map<String,Target> tab = new HashMap<String,Target>();
aoqi@0 85 static {
aoqi@0 86 for (Target t : values()) {
aoqi@0 87 tab.put(t.name, t);
aoqi@0 88 }
aoqi@0 89 tab.put("5", JDK1_5);
aoqi@0 90 tab.put("6", JDK1_6);
aoqi@0 91 tab.put("7", JDK1_7);
aoqi@0 92 tab.put("8", JDK1_8);
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 public final String name;
aoqi@0 96 public final int majorVersion;
aoqi@0 97 public final int minorVersion;
aoqi@0 98 private Target(String name, int majorVersion, int minorVersion) {
aoqi@0 99 this.name = name;
aoqi@0 100 this.majorVersion = majorVersion;
aoqi@0 101 this.minorVersion = minorVersion;
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 public static final Target DEFAULT = JDK1_8;
aoqi@0 105
aoqi@0 106 public static Target lookup(String name) {
aoqi@0 107 return tab.get(name);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 /** In -target 1.1 and earlier, the compiler is required to emit
aoqi@0 111 * synthetic method definitions in abstract classes for interface
aoqi@0 112 * methods that are not overridden. We call them "Miranda" methods.
aoqi@0 113 */
aoqi@0 114 public boolean requiresIproxy() {
aoqi@0 115 return compareTo(JDK1_1) <= 0;
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 /** Beginning in 1.4, we take advantage of the possibility of emitting
aoqi@0 119 * code to initialize fields before calling the superclass constructor.
aoqi@0 120 * This is allowed by the VM spec, but the verifier refused to allow
aoqi@0 121 * it until 1.4. This is necesary to translate some code involving
aoqi@0 122 * inner classes. See, for example, 4030374.
aoqi@0 123 */
aoqi@0 124 public boolean initializeFieldsBeforeSuper() {
aoqi@0 125 return compareTo(JDK1_4) >= 0;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 /** Beginning with -target 1.2 we obey the JLS rules for binary
aoqi@0 129 * compatibility, emitting as the qualifying type of a reference
aoqi@0 130 * to a method or field the type of the qualifier. In earlier
aoqi@0 131 * targets we use as the qualifying type the class in which the
aoqi@0 132 * member was found. The following methods named
aoqi@0 133 * *binaryCompatibility() indicate places where we vary from this
aoqi@0 134 * general rule. */
aoqi@0 135 public boolean obeyBinaryCompatibility() {
aoqi@0 136 return compareTo(JDK1_2) >= 0;
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 /** Starting in 1.5, the compiler uses an array type as
aoqi@0 140 * the qualifier for method calls (such as clone) where required by
aoqi@0 141 * the language and VM spec. Earlier versions of the compiler
aoqi@0 142 * qualified them by Object.
aoqi@0 143 */
aoqi@0 144 public boolean arrayBinaryCompatibility() {
aoqi@0 145 return compareTo(JDK1_5) >= 0;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 /** Beginning after 1.2, we follow the binary compatibility rules for
aoqi@0 149 * interface fields. The 1.2 VMs had bugs handling interface fields
aoqi@0 150 * when compiled using binary compatibility (see 4400598), so this is
aoqi@0 151 * an accommodation to them.
aoqi@0 152 */
aoqi@0 153 public boolean interfaceFieldsBinaryCompatibility() {
aoqi@0 154 return compareTo(JDK1_2) > 0;
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 /** Beginning in -target 1.5, we follow the binary compatibility
aoqi@0 158 * rules for interface methods that redefine Object methods.
aoqi@0 159 * Earlier VMs had bugs handling such methods compiled using binary
aoqi@0 160 * compatibility (see 4392595, 4398791, 4392595, 4400415).
aoqi@0 161 * The VMs were fixed during or soon after 1.4. See 4392595.
aoqi@0 162 */
aoqi@0 163 public boolean interfaceObjectOverridesBinaryCompatibility() {
aoqi@0 164 return compareTo(JDK1_5) >= 0;
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 /** Beginning in -target 1.5, we make synthetic variables
aoqi@0 168 * package-private instead of private. This is to prevent the
aoqi@0 169 * necessity of access methods, which effectively relax the
aoqi@0 170 * protection of the field but bloat the class files and affect
aoqi@0 171 * execution.
aoqi@0 172 */
aoqi@0 173 public boolean usePrivateSyntheticFields() {
aoqi@0 174 return compareTo(JDK1_5) < 0;
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 /** Sometimes we need to create a field to cache a value like a
aoqi@0 178 * class literal of the assertions flag. In -target 1.5 and
aoqi@0 179 * later we create a new synthetic class for this instead of
aoqi@0 180 * using the outermost class. See 4401576.
aoqi@0 181 */
aoqi@0 182 public boolean useInnerCacheClass() {
aoqi@0 183 return compareTo(JDK1_5) >= 0;
aoqi@0 184 }
aoqi@0 185
aoqi@0 186 /** Return true if cldc-style stack maps need to be generated. */
aoqi@0 187 public boolean generateCLDCStackmap() {
aoqi@0 188 return false;
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 /** Beginning in -target 6, we generate stackmap attribute in
aoqi@0 192 * compact format. */
aoqi@0 193 public boolean generateStackMapTable() {
aoqi@0 194 return compareTo(JDK1_6) >= 0;
aoqi@0 195 }
aoqi@0 196
aoqi@0 197 /** Beginning in -target 6, package-info classes are marked synthetic.
aoqi@0 198 */
aoqi@0 199 public boolean isPackageInfoSynthetic() {
aoqi@0 200 return compareTo(JDK1_6) >= 0;
aoqi@0 201 }
aoqi@0 202
aoqi@0 203 /** Do we generate "empty" stackmap slots after double and long?
aoqi@0 204 */
aoqi@0 205 public boolean generateEmptyAfterBig() {
aoqi@0 206 return false;
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 /** Beginning in 1.5, we have an unsynchronized version of
aoqi@0 210 * StringBuffer called StringBuilder that can be used by the
aoqi@0 211 * compiler for string concatenation.
aoqi@0 212 */
aoqi@0 213 public boolean useStringBuilder() {
aoqi@0 214 return compareTo(JDK1_5) >= 0;
aoqi@0 215 }
aoqi@0 216
aoqi@0 217 /** Beginning in 1.5, we have flag bits we can use instead of
aoqi@0 218 * marker attributes.
aoqi@0 219 */
aoqi@0 220 public boolean useSyntheticFlag() {
aoqi@0 221 return compareTo(JDK1_5) >= 0;
aoqi@0 222 }
aoqi@0 223 public boolean useEnumFlag() {
aoqi@0 224 return compareTo(JDK1_5) >= 0;
aoqi@0 225 }
aoqi@0 226 public boolean useAnnotationFlag() {
aoqi@0 227 return compareTo(JDK1_5) >= 0;
aoqi@0 228 }
aoqi@0 229 public boolean useVarargsFlag() {
aoqi@0 230 return compareTo(JDK1_5) >= 0;
aoqi@0 231 }
aoqi@0 232 public boolean useBridgeFlag() {
aoqi@0 233 return compareTo(JDK1_5) >= 0;
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 /** Return the character to be used in constructing synthetic
aoqi@0 237 * identifiers, where not specified by the JLS.
aoqi@0 238 */
aoqi@0 239 public char syntheticNameChar() {
aoqi@0 240 return '$';
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 /** Does the VM have direct support for class literals?
aoqi@0 244 */
aoqi@0 245 public boolean hasClassLiterals() {
aoqi@0 246 return compareTo(JDK1_5) >= 0;
aoqi@0 247 }
aoqi@0 248
aoqi@0 249 /** Does the VM support an invokedynamic instruction?
aoqi@0 250 */
aoqi@0 251 public boolean hasInvokedynamic() {
aoqi@0 252 return compareTo(JDK1_7) >= 0;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 /** Does the VM support polymorphic method handle invocation?
aoqi@0 256 * Affects the linkage information output to the classfile.
aoqi@0 257 * An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together.
aoqi@0 258 */
aoqi@0 259 public boolean hasMethodHandles() {
aoqi@0 260 return hasInvokedynamic();
aoqi@0 261 }
aoqi@0 262
aoqi@0 263 /** Although we may not have support for class literals, should we
aoqi@0 264 * avoid initializing the class that the literal refers to?
aoqi@0 265 * See 4468823
aoqi@0 266 */
aoqi@0 267 public boolean classLiteralsNoInit() {
aoqi@0 268 return compareTo(JDK1_5) >= 0;
aoqi@0 269 }
aoqi@0 270
aoqi@0 271 /** Although we may not have support for class literals, when we
aoqi@0 272 * throw a NoClassDefFoundError, should we initialize its cause?
aoqi@0 273 */
aoqi@0 274 public boolean hasInitCause() {
aoqi@0 275 return compareTo(JDK1_4) >= 0;
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 /** For bootstrapping, we use J2SE1.4's wrapper class constructors
aoqi@0 279 * to implement boxing.
aoqi@0 280 */
aoqi@0 281 public boolean boxWithConstructors() {
aoqi@0 282 return compareTo(JDK1_5) < 0;
aoqi@0 283 }
aoqi@0 284
aoqi@0 285 /** For bootstrapping, we use J2SE1.4's java.util.Collection
aoqi@0 286 * instead of java.lang.Iterable.
aoqi@0 287 */
aoqi@0 288 public boolean hasIterable() {
aoqi@0 289 return compareTo(JDK1_5) >= 0;
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 /** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute
aoqi@0 293 * for improved reflection support.
aoqi@0 294 */
aoqi@0 295 public boolean hasEnclosingMethodAttribute() {
aoqi@0 296 return compareTo(JDK1_5) >= 0;
aoqi@0 297 }
aoqi@0 298 }

mercurial