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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jdk.vm.ci.hotspot; 24 25 import static java.lang.String.*; 26 27 import java.io.*; 28 import java.lang.reflect.*; 29 import java.util.*; 30 31 import jdk.internal.org.objectweb.asm.*; 32 import jdk.internal.org.objectweb.asm.Type; 33 import jdk.vm.ci.common.*; 34 import sun.misc.*; 35 36 /** 37 * A {@link ClassVisitor} that verifies {@link HotSpotVMConfig} does not access {@link Unsafe} from 38 * any of its non-static, non-constructor methods. This ensures that a deserialized 39 * {@link HotSpotVMConfig} object does not perform any unsafe reads on addresses that are only valid 40 * in the context in which the object was serialized. Note that this does not catch cases where a 41 * client uses an address stored in a {@link HotSpotVMConfig} field. 42 */ 43 final class HotSpotVMConfigVerifier extends ClassVisitor { 44 45 public static boolean check() { 46 Class<?> cls = HotSpotVMConfig.class; 47 String classFilePath = "/" + cls.getName().replace('.', '/') + ".class"; 48 try { 49 InputStream classfile = cls.getResourceAsStream(classFilePath); 50 ClassReader cr = new ClassReader(Objects.requireNonNull(classfile, "Could not find class file for " + cls.getName())); 51 ClassVisitor cv = new HotSpotVMConfigVerifier(); 52 cr.accept(cv, 0); 53 return true; 54 } catch (IOException e) { | 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 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) { |