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

Print this page


   1 /*
   2  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  31 import com.sun.tools.javac.code.Symbol;
  32 import com.sun.tools.javac.util.*;
  33 
  34 import static com.sun.tools.javac.main.Option.TARGET;
  35 
  36 /** The classfile version target.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  */
  43 public enum Target {
  44     JDK1_1("1.1", 45, 3),
  45     JDK1_2("1.2", 46, 0),
  46     JDK1_3("1.3", 47, 0),
  47 
  48     /** J2SE1.4 = Merlin. */
  49     JDK1_4("1.4", 48, 0),
  50 
  51     /** Support for the JSR14 prototype compiler (targeting 1.4 VMs
  52      *  augmented with a few support classes).  This is a transitional
  53      *  option that will not be supported in the product.  */
  54     JSR14("jsr14", 48, 0),
  55 
  56     /** The following are undocumented transitional targets that we
  57      *  had used to test VM fixes in update releases.  We do not
  58      *  promise to retain support for them.  */
  59     JDK1_4_1("1.4.1", 48, 0),
  60     JDK1_4_2("1.4.2", 48, 0),
  61 
  62     /** Tiger. */
  63     JDK1_5("1.5", 49, 0),
  64 
  65     /** JDK 6. */
  66     JDK1_6("1.6", 50, 0),
  67 
  68     /** JDK 7. */
  69     JDK1_7("1.7", 51, 0),
  70 
  71     /** JDK 8. */
  72     JDK1_8("1.8", 52, 0);
  73 
  74     private static final Context.Key<Target> targetKey =
  75         new Context.Key<Target>();
  76 
  77     public static Target instance(Context context) {
  78         Target instance = context.get(targetKey);
  79         if (instance == null) {
  80             Options options = Options.instance(context);
  81             String targetString = options.get(TARGET);


 158 
 159     /** Beginning after 1.2, we follow the binary compatibility rules for
 160      *  interface fields.  The 1.2 VMs had bugs handling interface fields
 161      *  when compiled using binary compatibility (see 4400598), so this is
 162      *  an accommodation to them.
 163      */
 164     public boolean interfaceFieldsBinaryCompatibility() {
 165         return compareTo(JDK1_2) > 0;
 166     }
 167 
 168     /** Beginning in -target 1.5, we follow the binary compatibility
 169      *  rules for interface methods that redefine Object methods.
 170      *  Earlier VMs had bugs handling such methods compiled using binary
 171      *  compatibility (see 4392595, 4398791, 4392595, 4400415).
 172      *  The VMs were fixed during or soon after 1.4.  See 4392595.
 173      */
 174     public boolean interfaceObjectOverridesBinaryCompatibility() {
 175         return compareTo(JDK1_5) >= 0;
 176     }
 177 
 178     /** Beginning in -target 1.4.2, we make synthetic variables
 179      *  package-private instead of private.  This is to prevent the
 180      *  necessity of access methods, which effectively relax the
 181      *  protection of the field but bloat the class files and affect
 182      *  execution.
 183      */
 184     public boolean usePrivateSyntheticFields() {
 185         return compareTo(JDK1_4_2) < 0;
 186     }
 187 
 188     /** Sometimes we need to create a field to cache a value like a
 189      *  class literal of the assertions flag.  In -target 1.4.2 and
 190      *  later we create a new synthetic class for this instead of
 191      *  using the outermost class.  See 4401576.
 192      */
 193     public boolean useInnerCacheClass() {
 194         return compareTo(JDK1_4_2) >= 0;
 195     }
 196 
 197     /** Return true if cldc-style stack maps need to be generated. */
 198     public boolean generateCLDCStackmap() {
 199         return false;
 200     }
 201 
 202     /** Beginning in -target 6, we generate stackmap attribute in
 203      *  compact format. */
 204     public boolean generateStackMapTable() {
 205         return compareTo(JDK1_6) >= 0;
 206     }
 207 
 208     /** Beginning in -target 6, package-info classes are marked synthetic.
 209      */
 210     public boolean isPackageInfoSynthetic() {
 211         return compareTo(JDK1_6) >= 0;
 212     }
 213 
 214     /** Do we generate "empty" stackmap slots after double and long?


 259 
 260     /** Does the VM support an invokedynamic instruction?
 261      */
 262     public boolean hasInvokedynamic() {
 263         return compareTo(JDK1_7) >= 0;
 264     }
 265 
 266     /** Does the VM support polymorphic method handle invocation?
 267      *  Affects the linkage information output to the classfile.
 268      *  An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together.
 269      */
 270     public boolean hasMethodHandles() {
 271         return hasInvokedynamic();
 272     }
 273 
 274     /** Although we may not have support for class literals, should we
 275      *  avoid initializing the class that the literal refers to?
 276      *  See 4468823
 277      */
 278     public boolean classLiteralsNoInit() {
 279         return compareTo(JDK1_4_2) >= 0;
 280     }
 281 
 282     /** Although we may not have support for class literals, when we
 283      *  throw a NoClassDefFoundError, should we initialize its cause?
 284      */
 285     public boolean hasInitCause() {
 286         return compareTo(JDK1_4) >= 0;
 287     }
 288 
 289     /** For bootstrapping, we use J2SE1.4's wrapper class constructors
 290      *  to implement boxing.
 291      */
 292     public boolean boxWithConstructors() {
 293         return compareTo(JDK1_5) < 0;
 294     }
 295 
 296     /** For bootstrapping, we use J2SE1.4's java.util.Collection
 297      *  instead of java.lang.Iterable.
 298      */
 299     public boolean hasIterable() {
 300         return compareTo(JDK1_5) >= 0;
 301     }
 302 
 303     /** For bootstrapping javac only, we do without java.lang.Enum if
 304      *  necessary.
 305      */
 306     public boolean compilerBootstrap(Symbol c) {
 307         return
 308             this == JSR14 &&
 309             (c.flags() & Flags.ENUM) != 0 &&
 310             c.flatName().toString().startsWith("com.sun.tools.")
 311             // && !Target.class.getSuperclass().getName().equals("java.lang.Enum")
 312             ;
 313     }
 314 
 315     /** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute
 316      *  for improved reflection support.
 317      */
 318     public boolean hasEnclosingMethodAttribute() {
 319         return compareTo(JDK1_5) >= 0 || this == JSR14;
 320     }
 321 }
   1 /*
   2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  31 import com.sun.tools.javac.code.Symbol;
  32 import com.sun.tools.javac.util.*;
  33 
  34 import static com.sun.tools.javac.main.Option.TARGET;
  35 
  36 /** The classfile version target.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  */
  43 public enum Target {
  44     JDK1_1("1.1", 45, 3),
  45     JDK1_2("1.2", 46, 0),
  46     JDK1_3("1.3", 47, 0),
  47 
  48     /** J2SE1.4 = Merlin. */
  49     JDK1_4("1.4", 48, 0),
  50 











  51     /** Tiger. */
  52     JDK1_5("1.5", 49, 0),
  53 
  54     /** JDK 6. */
  55     JDK1_6("1.6", 50, 0),
  56 
  57     /** JDK 7. */
  58     JDK1_7("1.7", 51, 0),
  59 
  60     /** JDK 8. */
  61     JDK1_8("1.8", 52, 0);
  62 
  63     private static final Context.Key<Target> targetKey =
  64         new Context.Key<Target>();
  65 
  66     public static Target instance(Context context) {
  67         Target instance = context.get(targetKey);
  68         if (instance == null) {
  69             Options options = Options.instance(context);
  70             String targetString = options.get(TARGET);


 147 
 148     /** Beginning after 1.2, we follow the binary compatibility rules for
 149      *  interface fields.  The 1.2 VMs had bugs handling interface fields
 150      *  when compiled using binary compatibility (see 4400598), so this is
 151      *  an accommodation to them.
 152      */
 153     public boolean interfaceFieldsBinaryCompatibility() {
 154         return compareTo(JDK1_2) > 0;
 155     }
 156 
 157     /** Beginning in -target 1.5, we follow the binary compatibility
 158      *  rules for interface methods that redefine Object methods.
 159      *  Earlier VMs had bugs handling such methods compiled using binary
 160      *  compatibility (see 4392595, 4398791, 4392595, 4400415).
 161      *  The VMs were fixed during or soon after 1.4.  See 4392595.
 162      */
 163     public boolean interfaceObjectOverridesBinaryCompatibility() {
 164         return compareTo(JDK1_5) >= 0;
 165     }
 166 
 167     /** Beginning in -target 1.5, we make synthetic variables
 168      *  package-private instead of private.  This is to prevent the
 169      *  necessity of access methods, which effectively relax the
 170      *  protection of the field but bloat the class files and affect
 171      *  execution.
 172      */
 173     public boolean usePrivateSyntheticFields() {
 174         return compareTo(JDK1_5) < 0;
 175     }
 176 
 177     /** Sometimes we need to create a field to cache a value like a
 178      *  class literal of the assertions flag.  In -target 1.5 and
 179      *  later we create a new synthetic class for this instead of
 180      *  using the outermost class.  See 4401576.
 181      */
 182     public boolean useInnerCacheClass() {
 183         return compareTo(JDK1_5) >= 0;
 184     }
 185 
 186     /** Return true if cldc-style stack maps need to be generated. */
 187     public boolean generateCLDCStackmap() {
 188         return false;
 189     }
 190 
 191     /** Beginning in -target 6, we generate stackmap attribute in
 192      *  compact format. */
 193     public boolean generateStackMapTable() {
 194         return compareTo(JDK1_6) >= 0;
 195     }
 196 
 197     /** Beginning in -target 6, package-info classes are marked synthetic.
 198      */
 199     public boolean isPackageInfoSynthetic() {
 200         return compareTo(JDK1_6) >= 0;
 201     }
 202 
 203     /** Do we generate "empty" stackmap slots after double and long?


 248 
 249     /** Does the VM support an invokedynamic instruction?
 250      */
 251     public boolean hasInvokedynamic() {
 252         return compareTo(JDK1_7) >= 0;
 253     }
 254 
 255     /** Does the VM support polymorphic method handle invocation?
 256      *  Affects the linkage information output to the classfile.
 257      *  An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together.
 258      */
 259     public boolean hasMethodHandles() {
 260         return hasInvokedynamic();
 261     }
 262 
 263     /** Although we may not have support for class literals, should we
 264      *  avoid initializing the class that the literal refers to?
 265      *  See 4468823
 266      */
 267     public boolean classLiteralsNoInit() {
 268         return compareTo(JDK1_5) >= 0;
 269     }
 270 
 271     /** Although we may not have support for class literals, when we
 272      *  throw a NoClassDefFoundError, should we initialize its cause?
 273      */
 274     public boolean hasInitCause() {
 275         return compareTo(JDK1_4) >= 0;
 276     }
 277 
 278     /** For bootstrapping, we use J2SE1.4's wrapper class constructors
 279      *  to implement boxing.
 280      */
 281     public boolean boxWithConstructors() {
 282         return compareTo(JDK1_5) < 0;
 283     }
 284 
 285     /** For bootstrapping, we use J2SE1.4's java.util.Collection
 286      *  instead of java.lang.Iterable.
 287      */
 288     public boolean hasIterable() {
 289         return compareTo(JDK1_5) >= 0;
 290     }
 291 












 292     /** In J2SE1.5.0, we introduced the "EnclosingMethod" attribute
 293      *  for improved reflection support.
 294      */
 295     public boolean hasEnclosingMethodAttribute() {
 296         return compareTo(JDK1_5) >= 0;
 297     }
 298 }