annotate jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigVerifier.java @ 23392:b3a816d3b844

Backed out changeset: a920338dd4d4
author Doug Simon <doug.simon@oracle.com>
date Thu, 12 May 2016 11:06:49 +0200
parents a920338dd4d4
children
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
23392
b3a816d3b844 Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents: 23387
diff changeset
37 import jdk.vm.ci.common.JVMCIError;
22569
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.ClassReader;
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.ClassVisitor;
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.Label;
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.MethodVisitor;
ec96f33a101d updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22054
diff changeset
42 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
43 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
44 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
45
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
46 /**
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
47 * 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
48 * 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
49 * 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
50 * 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
51 * 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
52 */
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
53 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
54
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 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 return true;
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
64 } catch (AccessControlException e) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
65 /*
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
66 * 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
67 * not be accessible.
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
68 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
69 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
70 } catch (IOException e) {
23392
b3a816d3b844 Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents: 23387
diff changeset
71 throw new JVMCIError(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
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
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 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
76 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
77 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
78 } catch (ClassNotFoundException e) {
23392
b3a816d3b844 Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents: 23387
diff changeset
79 throw new JVMCIError(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
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 }
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
82
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
83 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
84
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
85 /**
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
86 * 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
87 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
88 String sourceFile = null;
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 /**
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
91 * 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
92 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
93 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
94
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
95 Verifier() {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
96 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
97 }
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
98
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
99 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
100 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
101 this.sourceFile = source;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
102 }
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
103
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
104 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
105 if (!condition) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
106 error(message);
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
107 }
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
108 }
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
109
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
110 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
111 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
112 sourceFile, lineNo, message, HotSpotVMConfig.class.getSimpleName());
23392
b3a816d3b844 Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents: 23387
diff changeset
113 throw new JVMCIError(errorMessage);
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
114
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
115 }
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
116
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
117 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
118 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
119 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
120 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
121
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
122 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
123 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
124 lineNo = line;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
125 }
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
126
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
127 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
128 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
129 while (declaringClass != null) {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
130 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
131 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
132 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
133 return c;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
134 }
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
135 }
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
136 } else {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
137 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
138 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
139 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
140 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
141 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
142 return m;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
143 }
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
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 }
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
147 }
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
148 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
149 }
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
150 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
151 }
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
152
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
153 /**
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
154 * 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
155 */
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
156 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
157 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
158 return false;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
159 }
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
160 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
161 }
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
162
23328
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
163 @Override
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
164 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
165 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
166 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
167 }
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
168 };
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
169 } else {
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
170 return null;
d6cbb275d6ce Ignore AccessControlExceptions when trying to use ASM from the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22672
diff changeset
171 }
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
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 }
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
174 }