|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 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. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 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 com.oracle.svm.core.jdk15; |
| 26 | + |
| 27 | +import java.lang.invoke.MethodHandles; |
| 28 | +// Checkstyle: stop |
| 29 | +import sun.invoke.util.VerifyAccess; |
| 30 | +// Checkstyle: resume |
| 31 | +import jdk.internal.misc.Unsafe; |
| 32 | + |
| 33 | +import com.oracle.svm.core.jdk.JDK15OrLater; |
| 34 | +import com.oracle.svm.core.jdk.JDK15OrEarlier; |
| 35 | +import com.oracle.svm.core.SubstrateUtil; |
| 36 | +import com.oracle.svm.core.annotate.Alias; |
| 37 | +import com.oracle.svm.core.annotate.Substitute; |
| 38 | +import com.oracle.svm.core.annotate.TargetClass; |
| 39 | + |
| 40 | +@TargetClass(className = "java.lang.invoke.MethodHandles", innerClass = "Lookup", onlyWith = {JDK15OrLater.class, JDK15OrEarlier.class}) |
| 41 | +final class Target_java_lang_invoke_MethodHandles_Lookup_JDK15 { |
| 42 | + |
| 43 | + @Alias // |
| 44 | + private Class<?> lookupClass; |
| 45 | + |
| 46 | + @Alias // |
| 47 | + private Class<?> prevLookupClass; |
| 48 | + |
| 49 | + @Alias // |
| 50 | + private int allowedModes; |
| 51 | + |
| 52 | + @Substitute |
| 53 | + public Class<?> lookupClass() { |
| 54 | + return lookupClass; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Eliminate the dependencies on MemberName. |
| 59 | + */ |
| 60 | + @Substitute |
| 61 | + public Class<?> ensureInitialized(Class<?> targetClass) throws IllegalAccessException { |
| 62 | + if (targetClass.isPrimitive()) { |
| 63 | + throw new IllegalArgumentException(targetClass + " is a primitive class"); |
| 64 | + } |
| 65 | + if (targetClass.isArray()) { |
| 66 | + throw new IllegalArgumentException(targetClass + " is an array class"); |
| 67 | + } |
| 68 | + if (!VerifyAccess.isClassAccessible(targetClass, lookupClass, prevLookupClass, allowedModes)) { |
| 69 | + // throw new MemberName(targetClass).makeAccessException("access violation", this); |
| 70 | + String message = "access violation: " + targetClass; |
| 71 | + if (this == SubstrateUtil.cast(MethodHandles.publicLookup(), Target_java_lang_invoke_MethodHandles_Lookup_JDK15.class)) { |
| 72 | + message += ", from public Lookup"; |
| 73 | + } else { |
| 74 | + Module m = lookupClass().getModule(); |
| 75 | + message += ", from " + lookupClass() + " (" + m + ")"; |
| 76 | + if (prevLookupClass != null) { |
| 77 | + message += ", previous lookup " + |
| 78 | + prevLookupClass.getName() + " (" + prevLookupClass.getModule() + ")"; |
| 79 | + } |
| 80 | + } |
| 81 | + throw new IllegalAccessException(message); |
| 82 | + } |
| 83 | + |
| 84 | + // This call is a noop without the security manager |
| 85 | + // checkSecurityManager(targetClass, null); |
| 86 | + |
| 87 | + // ensure class initialization |
| 88 | + Unsafe.getUnsafe().ensureClassInitialized(targetClass); |
| 89 | + return targetClass; |
| 90 | + } |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | +public class Target_java_lang_invoke_MethodHandles_JDK15 { |
| 95 | +} |
0 commit comments