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