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

Thu, 25 Sep 2014 17:09:23 -0700

author
vromero
date
Thu, 25 Sep 2014 17:09:23 -0700
changeset 2572
31d2a837676f
parent 1646
a4913ea9bb62
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8058708: java.lang.AssertionError compiling source code
Reviewed-by: jjg

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

mercurial