< prev index next >

jdk/src/java.base/share/classes/valhalla/shady/MinimalValueTypes_1_0.java

Print this page




   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
  23  * questions.
  24  */
  25 package valhalla.shady;
  26 
  27 import jdk.experimental.bytecode.BasicClassBuilder;
  28 import jdk.internal.misc.Unsafe;

  29 import sun.security.action.GetPropertyAction;
  30 
  31 import java.io.BufferedOutputStream;
  32 import java.io.File;
  33 import java.io.IOException;
  34 import java.io.OutputStream;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.security.ProtectionDomain;
  39 import java.util.Properties;
  40 
  41 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  42 
  43 import jdk.internal.misc.JavaLangAccess;
  44 import jdk.internal.misc.SharedSecrets;
  45 public class MinimalValueTypes_1_0 {
  46 
  47     public static final int V53_1 = 1 << 16 | 53;
  48     public static final int ACC_VALUE = ACC_NATIVE;
  49     public static final String OBJECT_CLASS_DESC = "java/lang/Object";
  50     public static final String VALUE_CLASS_DESC = "java/lang/__Value";
  51 
  52     public static final String DERIVE_VALUE_TYPE_DESC = "Ljvm/internal/value/ValueCapableClass;";
  53     public static final String DERIVE_VT_CLASSNAME_POSTFIX = "$Value";
  54     public static final int    DERIVE_VT_CLASS_ACCESS = ACC_PUBLIC|ACC_SUPER|ACC_FINAL|ACC_VALUE|ACC_SYNTHETIC;
  55 
  56     public static final boolean DUMP_CLASS_FILES;

  57     private static final JavaLangAccess JLA;
  58 
  59     static {
  60         // Use same property as in j.l.invoke.MethodHandleStatics
  61         Properties props = GetPropertyAction.privilegedGetProperties();
  62         DUMP_CLASS_FILES = Boolean.parseBoolean(
  63             props.getProperty("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES"));
  64 



  65         JLA = SharedSecrets.getJavaLangAccess();
  66     }
  67 
  68     public static String getValueTypeClassName(ValueTypeDesc valueTypeDesc) {
  69         return getValueTypeClassName(valueTypeDesc.getName());
  70     }
  71 
  72     public static String getValueTypeClassName(String vccName) {
  73         return vccName + DERIVE_VT_CLASSNAME_POSTFIX;
  74     }
  75 
  76     public static String getValueCapableClassName(String valName) {
  77         return valName.substring(0, valName.length() - DERIVE_VT_CLASSNAME_POSTFIX.length());
  78     }
  79 
  80     public static boolean isValueType(Class<?> dvt) {
  81         return (dvt.getModifiers() & ACC_VALUE) != 0;
  82     }
  83 
  84     public static boolean isValueCapable(Class<?> vcc) {


 176                         if (!root.exists() && !root.mkdirs()) {
 177                             throw new IllegalStateException("Could not create dump file directory: " + root);
 178                         }
 179                         System.out.println("dump: " + dumpFile);
 180                         try (OutputStream os = Files.newOutputStream(dumpFile);
 181                              BufferedOutputStream bos = new BufferedOutputStream(os)) {
 182                             bos.write(classFile);
 183                         } catch (IOException ex) {
 184                             throw new InternalError(ex);
 185                         }
 186                         return null;
 187                     }
 188                 });
 189 
 190         }
 191     }
 192 
 193     private final native Class<?> getDerivedValueType(Class<?> ofClass);
 194 
 195     public static Class<?> getValueClass() {
 196         return (Class<?>)(Object)__Value.class; //hack around static type-system checks
 197     }
 198 
 199     public static String mangleValueClassName(String name) {
 200         return ";Q" + name + ";";
 201     }










 202 }


   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
  23  * questions.
  24  */
  25 package valhalla.shady;
  26 
  27 import jdk.experimental.bytecode.BasicClassBuilder;
  28 import jdk.internal.misc.Unsafe;
  29 import jdk.internal.misc.VM;
  30 import sun.security.action.GetPropertyAction;
  31 
  32 import java.io.BufferedOutputStream;
  33 import java.io.File;
  34 import java.io.IOException;
  35 import java.io.OutputStream;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import java.nio.file.Paths;
  39 import java.security.ProtectionDomain;
  40 import java.util.Properties;
  41 
  42 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  43 
  44 import jdk.internal.misc.JavaLangAccess;
  45 import jdk.internal.misc.SharedSecrets;
  46 public class MinimalValueTypes_1_0 {
  47 
  48     public static final int V53_1 = 1 << 16 | 53;
  49     public static final int ACC_VALUE = ACC_NATIVE;
  50     public static final String OBJECT_CLASS_DESC = "java/lang/Object";
  51     public static final String VALUE_CLASS_DESC = "java/lang/__Value";
  52 
  53     public static final String DERIVE_VALUE_TYPE_DESC = "Ljvm/internal/value/ValueCapableClass;";
  54     public static final String DERIVE_VT_CLASSNAME_POSTFIX = "$Value";
  55     public static final int    DERIVE_VT_CLASS_ACCESS = ACC_PUBLIC|ACC_SUPER|ACC_FINAL|ACC_VALUE|ACC_SYNTHETIC;
  56 
  57     public static final boolean DUMP_CLASS_FILES;
  58     private static final boolean VALUE_TYPE_ENABLED;
  59     private static final JavaLangAccess JLA;
  60 
  61     static {
  62         // Use same property as in j.l.invoke.MethodHandleStatics
  63         Properties props = GetPropertyAction.privilegedGetProperties();
  64         DUMP_CLASS_FILES = Boolean.parseBoolean(
  65             props.getProperty("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES"));
  66 
  67         VALUE_TYPE_ENABLED = Boolean.parseBoolean(
  68             props.getProperty("valhalla.enableValueType"));
  69 
  70         JLA = SharedSecrets.getJavaLangAccess();
  71     }
  72 
  73     public static String getValueTypeClassName(ValueTypeDesc valueTypeDesc) {
  74         return getValueTypeClassName(valueTypeDesc.getName());
  75     }
  76 
  77     public static String getValueTypeClassName(String vccName) {
  78         return vccName + DERIVE_VT_CLASSNAME_POSTFIX;
  79     }
  80 
  81     public static String getValueCapableClassName(String valName) {
  82         return valName.substring(0, valName.length() - DERIVE_VT_CLASSNAME_POSTFIX.length());
  83     }
  84 
  85     public static boolean isValueType(Class<?> dvt) {
  86         return (dvt.getModifiers() & ACC_VALUE) != 0;
  87     }
  88 
  89     public static boolean isValueCapable(Class<?> vcc) {


 181                         if (!root.exists() && !root.mkdirs()) {
 182                             throw new IllegalStateException("Could not create dump file directory: " + root);
 183                         }
 184                         System.out.println("dump: " + dumpFile);
 185                         try (OutputStream os = Files.newOutputStream(dumpFile);
 186                              BufferedOutputStream bos = new BufferedOutputStream(os)) {
 187                             bos.write(classFile);
 188                         } catch (IOException ex) {
 189                             throw new InternalError(ex);
 190                         }
 191                         return null;
 192                     }
 193                 });
 194 
 195         }
 196     }
 197 
 198     private final native Class<?> getDerivedValueType(Class<?> ofClass);
 199 
 200     public static Class<?> getValueClass() {
 201         return VALUE_TYPE_ENABLED ? ValueClassHolder.CLASS_OBJECT : null;
 202     }
 203 
 204     public static String mangleValueClassName(String name) {
 205         return ";Q" + name + ";";
 206     }
 207 
 208     /*
 209      * A holder class that references __Value to be loaded only when MVT is enabled.
 210      *
 211      * This holder class would fail verification if loaded if MVT is not enabled.
 212      */
 213     private static class ValueClassHolder {
 214          static final Class<?> CLASS_OBJECT =
 215              (Class<?>)(Object)__Value.class; //hack around static type-system checks
 216     }
 217 }
< prev index next >