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

Mon, 07 Feb 2011 18:10:13 +0000

author
mcimadamore
date
Mon, 07 Feb 2011 18:10:13 +0000
changeset 858
96d4226bdd60
parent 798
4868a36f6fd8
child 1042
defdd98cb7ce
permissions
-rw-r--r--

7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
Summary: override clash algorithm is not implemented correctly
Reviewed-by: jjg

duke@1 1 /*
ohair@798 2 * Copyright (c) 2002, 2010, 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@700 34 import static com.sun.tools.javac.main.OptionName.*;
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 /** Support for the JSR14 prototype compiler (targeting 1.4 VMs
duke@1 52 * augmented with a few support classes). This is a transitional
duke@1 53 * option that will not be supported in the product. */
duke@1 54 JSR14("jsr14", 48, 0),
duke@1 55
duke@1 56 /** The following are undocumented transitional targets that we
duke@1 57 * had used to test VM fixes in update releases. We do not
duke@1 58 * promise to retain support for them. */
duke@1 59 JDK1_4_1("1.4.1", 48, 0),
duke@1 60 JDK1_4_2("1.4.2", 48, 0),
duke@1 61
duke@1 62 /** Tiger. */
duke@1 63 JDK1_5("1.5", 49, 0),
duke@1 64
duke@1 65 /** JDK 6. */
duke@1 66 JDK1_6("1.6", 50, 0),
duke@1 67
duke@1 68 /** JDK 7. */
duke@1 69 JDK1_7("1.7", 51, 0);
duke@1 70
duke@1 71 private static final Context.Key<Target> targetKey =
duke@1 72 new Context.Key<Target>();
duke@1 73
duke@1 74 public static Target instance(Context context) {
duke@1 75 Target instance = context.get(targetKey);
duke@1 76 if (instance == null) {
duke@1 77 Options options = Options.instance(context);
jjg@700 78 String targetString = options.get(TARGET);
duke@1 79 if (targetString != null) instance = lookup(targetString);
duke@1 80 if (instance == null) instance = DEFAULT;
duke@1 81 context.put(targetKey, instance);
duke@1 82 }
duke@1 83 return instance;
duke@1 84 }
duke@1 85
duke@1 86 private static Target MIN;
duke@1 87 public static Target MIN() { return MIN; }
duke@1 88
duke@1 89 private static Target MAX;
duke@1 90 public static Target MAX() { return MAX; }
duke@1 91
duke@1 92 private static Map<String,Target> tab = new HashMap<String,Target>();
duke@1 93 static {
duke@1 94 for (Target t : values()) {
duke@1 95 if (MIN == null) MIN = t;
duke@1 96 MAX = t;
duke@1 97 tab.put(t.name, t);
duke@1 98 }
duke@1 99 tab.put("5", JDK1_5);
duke@1 100 tab.put("6", JDK1_6);
duke@1 101 tab.put("7", JDK1_7);
duke@1 102 }
duke@1 103
duke@1 104 public final String name;
duke@1 105 public final int majorVersion;
duke@1 106 public final int minorVersion;
duke@1 107 private Target(String name, int majorVersion, int minorVersion) {
duke@1 108 this.name = name;
duke@1 109 this.majorVersion = majorVersion;
duke@1 110 this.minorVersion = minorVersion;
duke@1 111 }
duke@1 112
jjg@286 113 public static final Target DEFAULT = JDK1_7;
duke@1 114
duke@1 115 public static Target lookup(String name) {
duke@1 116 return tab.get(name);
duke@1 117 }
duke@1 118
duke@1 119 /** In -target 1.1 and earlier, the compiler is required to emit
duke@1 120 * synthetic method definitions in abstract classes for interface
duke@1 121 * methods that are not overridden. We call them "Miranda" methods.
duke@1 122 */
duke@1 123 public boolean requiresIproxy() {
duke@1 124 return compareTo(JDK1_1) <= 0;
duke@1 125 }
duke@1 126
duke@1 127 /** Beginning in 1.4, we take advantage of the possibility of emitting
duke@1 128 * code to initialize fields before calling the superclass constructor.
duke@1 129 * This is allowed by the VM spec, but the verifier refused to allow
duke@1 130 * it until 1.4. This is necesary to translate some code involving
duke@1 131 * inner classes. See, for example, 4030374.
duke@1 132 */
duke@1 133 public boolean initializeFieldsBeforeSuper() {
duke@1 134 return compareTo(JDK1_4) >= 0;
duke@1 135 }
duke@1 136
duke@1 137 /** Beginning with -target 1.2 we obey the JLS rules for binary
duke@1 138 * compatibility, emitting as the qualifying type of a reference
duke@1 139 * to a method or field the type of the qualifier. In earlier
duke@1 140 * targets we use as the qualifying type the class in which the
duke@1 141 * member was found. The following methods named
duke@1 142 * *binaryCompatibility() indicate places where we vary from this
duke@1 143 * general rule. */
duke@1 144 public boolean obeyBinaryCompatibility() {
duke@1 145 return compareTo(JDK1_2) >= 0;
duke@1 146 }
duke@1 147
duke@1 148 /** Starting in 1.5, the compiler uses an array type as
duke@1 149 * the qualifier for method calls (such as clone) where required by
duke@1 150 * the language and VM spec. Earlier versions of the compiler
duke@1 151 * qualified them by Object.
duke@1 152 */
duke@1 153 public boolean arrayBinaryCompatibility() {
duke@1 154 return compareTo(JDK1_5) >= 0;
duke@1 155 }
duke@1 156
duke@1 157 /** Beginning after 1.2, we follow the binary compatibility rules for
duke@1 158 * interface fields. The 1.2 VMs had bugs handling interface fields
duke@1 159 * when compiled using binary compatibility (see 4400598), so this is
duke@1 160 * an accommodation to them.
duke@1 161 */
duke@1 162 public boolean interfaceFieldsBinaryCompatibility() {
duke@1 163 return compareTo(JDK1_2) > 0;
duke@1 164 }
duke@1 165
duke@1 166 /** Beginning in -target 1.5, we follow the binary compatibility
duke@1 167 * rules for interface methods that redefine Object methods.
duke@1 168 * Earlier VMs had bugs handling such methods compiled using binary
duke@1 169 * compatibility (see 4392595, 4398791, 4392595, 4400415).
duke@1 170 * The VMs were fixed during or soon after 1.4. See 4392595.
duke@1 171 */
duke@1 172 public boolean interfaceObjectOverridesBinaryCompatibility() {
duke@1 173 return compareTo(JDK1_5) >= 0;
duke@1 174 }
duke@1 175
duke@1 176 /** Beginning in -target 1.4.2, we make synthetic variables
duke@1 177 * package-private instead of private. This is to prevent the
duke@1 178 * necessity of access methods, which effectively relax the
duke@1 179 * protection of the field but bloat the class files and affect
duke@1 180 * execution.
duke@1 181 */
duke@1 182 public boolean usePrivateSyntheticFields() {
duke@1 183 return compareTo(JDK1_4_2) < 0;
duke@1 184 }
duke@1 185
duke@1 186 /** Sometimes we need to create a field to cache a value like a
duke@1 187 * class literal of the assertions flag. In -target 1.4.2 and
duke@1 188 * later we create a new synthetic class for this instead of
duke@1 189 * using the outermost class. See 4401576.
duke@1 190 */
duke@1 191 public boolean useInnerCacheClass() {
duke@1 192 return compareTo(JDK1_4_2) >= 0;
duke@1 193 }
duke@1 194
duke@1 195 /** Return true if cldc-style stack maps need to be generated. */
duke@1 196 public boolean generateCLDCStackmap() {
duke@1 197 return false;
duke@1 198 }
duke@1 199
duke@1 200 /** Beginning in -target 6, we generate stackmap attribute in
duke@1 201 * compact format. */
duke@1 202 public boolean generateStackMapTable() {
duke@1 203 return compareTo(JDK1_6) >= 0;
duke@1 204 }
duke@1 205
duke@1 206 /** Beginning in -target 6, package-info classes are marked synthetic.
duke@1 207 */
duke@1 208 public boolean isPackageInfoSynthetic() {
duke@1 209 return compareTo(JDK1_6) >= 0;
duke@1 210 }
duke@1 211
duke@1 212 /** Do we generate "empty" stackmap slots after double and long?
duke@1 213 */
duke@1 214 public boolean generateEmptyAfterBig() {
duke@1 215 return false;
duke@1 216 }
duke@1 217
duke@1 218 /** Beginning in 1.5, we have an unsynchronized version of
duke@1 219 * StringBuffer called StringBuilder that can be used by the
duke@1 220 * compiler for string concatenation.
duke@1 221 */
duke@1 222 public boolean useStringBuilder() {
duke@1 223 return compareTo(JDK1_5) >= 0;
duke@1 224 }
duke@1 225
duke@1 226 /** Beginning in 1.5, we have flag bits we can use instead of
duke@1 227 * marker attributes.
duke@1 228 */
duke@1 229 public boolean useSyntheticFlag() {
duke@1 230 return compareTo(JDK1_5) >= 0;
duke@1 231 }
duke@1 232 public boolean useEnumFlag() {
duke@1 233 return compareTo(JDK1_5) >= 0;
duke@1 234 }
duke@1 235 public boolean useAnnotationFlag() {
duke@1 236 return compareTo(JDK1_5) >= 0;
duke@1 237 }
duke@1 238 public boolean useVarargsFlag() {
duke@1 239 return compareTo(JDK1_5) >= 0;
duke@1 240 }
duke@1 241 public boolean useBridgeFlag() {
duke@1 242 return compareTo(JDK1_5) >= 0;
duke@1 243 }
duke@1 244
duke@1 245 /** Return the character to be used in constructing synthetic
duke@1 246 * identifiers, where not specified by the JLS.
duke@1 247 */
duke@1 248 public char syntheticNameChar() {
duke@1 249 return '$';
duke@1 250 }
duke@1 251
duke@1 252 /** Does the VM have direct support for class literals?
duke@1 253 */
duke@1 254 public boolean hasClassLiterals() {
duke@1 255 return compareTo(JDK1_5) >= 0;
duke@1 256 }
duke@1 257
jrose@267 258 /** Does the VM support an invokedynamic instruction?
jrose@267 259 */
jrose@267 260 public boolean hasInvokedynamic() {
jrose@267 261 return compareTo(JDK1_7) >= 0;
jrose@267 262 }
jrose@267 263
mcimadamore@674 264 /** Does the VM support polymorphic method handle invocation?
mcimadamore@674 265 * Affects the linkage information output to the classfile.
mcimadamore@674 266 * An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together.
mcimadamore@674 267 */
mcimadamore@674 268 public boolean hasMethodHandles() {
mcimadamore@674 269 return hasInvokedynamic();
mcimadamore@674 270 }
mcimadamore@674 271
duke@1 272 /** Although we may not have support for class literals, should we
duke@1 273 * avoid initializing the class that the literal refers to?
duke@1 274 * See 4468823
duke@1 275 */
duke@1 276 public boolean classLiteralsNoInit() {
duke@1 277 return compareTo(JDK1_4_2) >= 0;
duke@1 278 }
duke@1 279
duke@1 280 /** Although we may not have support for class literals, when we
duke@1 281 * throw a NoClassDefFoundError, should we initialize its cause?
duke@1 282 */
duke@1 283 public boolean hasInitCause() {
duke@1 284 return compareTo(JDK1_4) >= 0;
duke@1 285 }
duke@1 286
duke@1 287 /** For bootstrapping, we use J2SE1.4's wrapper class constructors
duke@1 288 * to implement boxing.
duke@1 289 */
duke@1 290 public boolean boxWithConstructors() {
duke@1 291 return compareTo(JDK1_5) < 0;
duke@1 292 }
duke@1 293
duke@1 294 /** For bootstrapping, we use J2SE1.4's java.util.Collection
duke@1 295 * instead of java.lang.Iterable.
duke@1 296 */
duke@1 297 public boolean hasIterable() {
duke@1 298 return compareTo(JDK1_5) >= 0;
duke@1 299 }
duke@1 300
duke@1 301 /** For bootstrapping javac only, we do without java.lang.Enum if
duke@1 302 * necessary.
duke@1 303 */
duke@1 304 public boolean compilerBootstrap(Symbol c) {
duke@1 305 return
duke@1 306 this == JSR14 &&
duke@1 307 (c.flags() & Flags.ENUM) != 0 &&
duke@1 308 c.flatName().toString().startsWith("com.sun.tools.")
duke@1 309 // && !Target.class.getSuperclass().getName().equals("java.lang.Enum")
duke@1 310 ;
duke@1 311 }
duke@1 312
duke@1 313 /** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute
duke@1 314 * for improved reflection support.
duke@1 315 */
duke@1 316 public boolean hasEnclosingMethodAttribute() {
duke@1 317 return compareTo(JDK1_5) >= 0 || this == JSR14;
duke@1 318 }
duke@1 319 }

mercurial