annotate jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigVerifier.java @ 23387:a920338dd4d4

remove JVMCIError and UnsafeUtil classes (JDK-8156759)
author Doug Simon <doug.simon@oracle.com>
date Wed, 11 May 2016 15:54:36 +0200
parents d6cbb275d6ce
children b3a816d3b844
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
22672
1bbd4a7c274b Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22569
diff changeset
23 package jdk.vm.ci.hotspot;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
22569
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
25 import static java.lang.String.format;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26
22569
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
27 import java.io.IOException;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
28 import java.io.InputStream;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
29 import java.lang.reflect.Constructor;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
30 import java.lang.reflect.Executable;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
31 import java.lang.reflect.Method;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
32 import java.lang.reflect.Modifier;
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
33 import java.security.AccessControlException;
22569
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
34 import java.util.Arrays;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
35 import java.util.Objects;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36
22569
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
37 import jdk.internal.org.objectweb.asm.ClassReader;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
38 import jdk.internal.org.objectweb.asm.ClassVisitor;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
39 import jdk.internal.org.objectweb.asm.Label;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
40 import jdk.internal.org.objectweb.asm.MethodVisitor;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
41 import jdk.internal.org.objectweb.asm.Opcodes;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 import jdk.internal.org.objectweb.asm.Type;
22569
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
43 import sun.misc.Unsafe;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 /**
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
46 * A verifier that checks that {@link HotSpotVMConfig} does not access {@link Unsafe} from any of
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
47 * its non-static, non-constructor methods. This ensures that a deserialized {@link HotSpotVMConfig}
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
48 * object does not perform any unsafe reads on addresses that are only valid in the context in which
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
49 * the object was serialized. Note that this does not catch cases where a client uses an address
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
50 * stored in a {@link HotSpotVMConfig} field.
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 */
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
52 final class HotSpotVMConfigVerifier {
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 public static boolean check() {
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 Class<?> cls = HotSpotVMConfig.class;
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 String classFilePath = "/" + cls.getName().replace('.', '/') + ".class";
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 try {
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 InputStream classfile = cls.getResourceAsStream(classFilePath);
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 ClassReader cr = new ClassReader(Objects.requireNonNull(classfile, "Could not find class file for " + cls.getName()));
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
60 ClassVisitor cv = new Verifier();
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 cr.accept(cv, 0);
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 return true;
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
63 } catch (AccessControlException e) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
64 /*
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
65 * When running with a security manager and +UseJVMCIClassLoader the ASM classes might
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
66 * not be accessible.
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
67 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
68 return true;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 } catch (IOException e) {
23387
a920338dd4d4 remove JVMCIError and UnsafeUtil classes (JDK-8156759)
Doug Simon <doug.simon@oracle.com>
parents: 23328
diff changeset
70 throw new InternalError(e);
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 private static Class<?> resolve(String name) {
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 try {
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 return Class.forName(name.replace('/', '.'));
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 } catch (ClassNotFoundException e) {
23387
a920338dd4d4 remove JVMCIError and UnsafeUtil classes (JDK-8156759)
Doug Simon <doug.simon@oracle.com>
parents: 23328
diff changeset
78 throw new InternalError(e);
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
82 private static class Verifier extends ClassVisitor {
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
84 /**
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
85 * Source file context for error reporting.
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
86 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
87 String sourceFile = null;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
88
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
89 /**
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
90 * Line number for error reporting.
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
91 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
92 int lineNo = -1;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
94 Verifier() {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
95 super(Opcodes.ASM5);
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
98 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
99 public void visitSource(String source, String debug) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
100 this.sourceFile = source;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
101 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
103 void verify(boolean condition, String message) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
104 if (!condition) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
105 error(message);
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
106 }
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
107 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
108
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
109 void error(String message) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
110 String errorMessage = format("%s:%d: %s is not allowed in the context of compilation replay. The unsafe access should be moved into the %s constructor and the result cached in a field",
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
111 sourceFile, lineNo, message, HotSpotVMConfig.class.getSimpleName());
23387
a920338dd4d4 remove JVMCIError and UnsafeUtil classes (JDK-8156759)
Doug Simon <doug.simon@oracle.com>
parents: 23328
diff changeset
112 throw new InternalError(errorMessage);
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
113
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
114 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
115
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
116 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
117 public MethodVisitor visitMethod(int access, String name, String d, String signature, String[] exceptions) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
118 if (!Modifier.isStatic(access) && Modifier.isPublic(access) && !name.equals("<init>")) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
119 return new MethodVisitor(Opcodes.ASM5) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
120
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
121 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
122 public void visitLineNumber(int line, Label start) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
123 lineNo = line;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
124 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
126 private Executable resolveMethod(String owner, String methodName, String methodDesc) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
127 Class<?> declaringClass = resolve(owner);
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
128 while (declaringClass != null) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
129 if (methodName.equals("<init>")) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
130 for (Constructor<?> c : declaringClass.getDeclaredConstructors()) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
131 if (methodDesc.equals(Type.getConstructorDescriptor(c))) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
132 return c;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
133 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
134 }
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
135 } else {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
136 Type[] argumentTypes = Type.getArgumentTypes(methodDesc);
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
137 for (Method m : declaringClass.getDeclaredMethods()) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
138 if (m.getName().equals(methodName)) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
139 if (Arrays.equals(argumentTypes, Type.getArgumentTypes(m))) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
140 if (Type.getReturnType(methodDesc).equals(Type.getReturnType(m))) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
141 return m;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
142 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
145 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146 }
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
147 declaringClass = declaringClass.getSuperclass();
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 }
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
149 throw new NoSuchMethodError(owner + "." + methodName + methodDesc);
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
152 /**
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
153 * Checks whether a given method is allowed to be called.
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
154 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
155 private boolean checkInvokeTarget(Executable method) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
156 if (method.getDeclaringClass().equals(Unsafe.class)) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
157 return false;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
158 }
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
159 return true;
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
162 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
163 public void visitMethodInsn(int opcode, String owner, String methodName, String methodDesc, boolean itf) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
164 Executable callee = resolveMethod(owner, methodName, methodDesc);
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
165 verify(checkInvokeTarget(callee), "invocation of " + callee);
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
166 }
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
167 };
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
168 } else {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
169 return null;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
170 }
18652
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
171 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
172 }
dfacef5b7958 remove uses of Unsafe in HotSpotVMConfig methods that may be executed on a deserialized HotSpotVMConfig object
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 }