src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigVerifier.java

Print this page
rev 10816 : 8153756: jdk.vm.ci should not depend on sun.misc ( jdk.unsupported module )
Reviewed-by:


  23 package jdk.vm.ci.hotspot;
  24 
  25 import static java.lang.String.format;
  26 
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.Executable;
  31 import java.lang.reflect.Method;
  32 import java.lang.reflect.Modifier;
  33 import java.util.Arrays;
  34 import java.util.Objects;
  35 
  36 import jdk.vm.ci.common.JVMCIError;
  37 import jdk.internal.org.objectweb.asm.ClassReader;
  38 import jdk.internal.org.objectweb.asm.ClassVisitor;
  39 import jdk.internal.org.objectweb.asm.Label;
  40 import jdk.internal.org.objectweb.asm.MethodVisitor;
  41 import jdk.internal.org.objectweb.asm.Opcodes;
  42 import jdk.internal.org.objectweb.asm.Type;
  43 import sun.misc.Unsafe;
  44 
  45 /**
  46  * A {@link ClassVisitor} that verifies {@link HotSpotVMConfig} does not access {@link Unsafe} from
  47  * any of its non-static, non-constructor methods. This ensures that a deserialized
  48  * {@link HotSpotVMConfig} object does not perform any unsafe reads on addresses that are only valid
  49  * in the context in which the object was serialized. Note that this does not catch cases where a
  50  * client uses an address stored in a {@link HotSpotVMConfig} field.
  51  */
  52 final class HotSpotVMConfigVerifier extends ClassVisitor {
  53 
  54     public static boolean check() {
  55         Class<?> cls = HotSpotVMConfig.class;
  56         String classFilePath = "/" + cls.getName().replace('.', '/') + ".class";
  57         try {
  58             InputStream classfile = cls.getResourceAsStream(classFilePath);
  59             ClassReader cr = new ClassReader(Objects.requireNonNull(classfile, "Could not find class file for " + cls.getName()));
  60             ClassVisitor cv = new HotSpotVMConfigVerifier();
  61             cr.accept(cv, 0);
  62             return true;
  63         } catch (IOException e) {




  23 package jdk.vm.ci.hotspot;
  24 
  25 import static java.lang.String.format;
  26 
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.Executable;
  31 import java.lang.reflect.Method;
  32 import java.lang.reflect.Modifier;
  33 import java.util.Arrays;
  34 import java.util.Objects;
  35 
  36 import jdk.vm.ci.common.JVMCIError;
  37 import jdk.internal.org.objectweb.asm.ClassReader;
  38 import jdk.internal.org.objectweb.asm.ClassVisitor;
  39 import jdk.internal.org.objectweb.asm.Label;
  40 import jdk.internal.org.objectweb.asm.MethodVisitor;
  41 import jdk.internal.org.objectweb.asm.Opcodes;
  42 import jdk.internal.org.objectweb.asm.Type;
  43 import jdk.internal.misc.Unsafe;
  44 
  45 /**
  46  * A {@link ClassVisitor} that verifies {@link HotSpotVMConfig} does not access {@link Unsafe} from
  47  * any of its non-static, non-constructor methods. This ensures that a deserialized
  48  * {@link HotSpotVMConfig} object does not perform any unsafe reads on addresses that are only valid
  49  * in the context in which the object was serialized. Note that this does not catch cases where a
  50  * client uses an address stored in a {@link HotSpotVMConfig} field.
  51  */
  52 final class HotSpotVMConfigVerifier extends ClassVisitor {
  53 
  54     public static boolean check() {
  55         Class<?> cls = HotSpotVMConfig.class;
  56         String classFilePath = "/" + cls.getName().replace('.', '/') + ".class";
  57         try {
  58             InputStream classfile = cls.getResourceAsStream(classFilePath);
  59             ClassReader cr = new ClassReader(Objects.requireNonNull(classfile, "Could not find class file for " + cls.getName()));
  60             ClassVisitor cv = new HotSpotVMConfigVerifier();
  61             cr.accept(cv, 0);
  62             return true;
  63         } catch (IOException e) {