mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 02:24:40 +02:00
8243287: Removal of Unsafe::defineAnonymousClass
Reviewed-by: iklam, mchung, alanb, dholmes
This commit is contained in:
parent
a564f2cbd5
commit
e14b026841
122 changed files with 328 additions and 3679 deletions
|
@ -1012,8 +1012,6 @@ class InvokerBytecodeGenerator {
|
|||
return false; // not on BCP
|
||||
if (cls.isHidden())
|
||||
return false;
|
||||
if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: Unsafe::defineAnonymousClass to be removed
|
||||
return false;
|
||||
if (!isStaticallyInvocableType(member.getMethodOrFieldType()))
|
||||
return false;
|
||||
if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
|
||||
|
@ -1045,8 +1043,6 @@ class InvokerBytecodeGenerator {
|
|||
return true; // int[].class, for example
|
||||
if (cls.isHidden())
|
||||
return false;
|
||||
if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: Unsafe::defineAnonymousClass to be removed
|
||||
return false;
|
||||
// could use VerifyAccess.isClassAccessible but the following is a safe approximation
|
||||
if (cls.getClassLoader() != Object.class.getClassLoader())
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1329,34 +1329,6 @@ public final class Unsafe {
|
|||
ClassLoader loader,
|
||||
ProtectionDomain protectionDomain);
|
||||
|
||||
/**
|
||||
* Defines a class but does not make it known to the class loader or system dictionary.
|
||||
* <p>
|
||||
* For each CP entry, the corresponding CP patch must either be null or have
|
||||
* the a format that matches its tag:
|
||||
* <ul>
|
||||
* <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
|
||||
* <li>Utf8: a string (must have suitable syntax if used as signature or name)
|
||||
* <li>Class: any java.lang.Class object
|
||||
* <li>String: any object (not just a java.lang.String)
|
||||
* <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
|
||||
* </ul>
|
||||
* @param hostClass context for linkage, access control, protection domain, and class loader
|
||||
* @param data bytes of a class file
|
||||
* @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
|
||||
*/
|
||||
@Deprecated(since = "15", forRemoval = true)
|
||||
public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
|
||||
if (hostClass == null || data == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (hostClass.isArray() || hostClass.isPrimitive()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
return defineAnonymousClass0(hostClass, data, cpPatches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates an instance but does not run any constructor.
|
||||
* Initializes the class if it has not yet been.
|
||||
|
@ -3855,7 +3827,6 @@ public final class Unsafe {
|
|||
private native void ensureClassInitialized0(Class<?> c);
|
||||
private native int arrayBaseOffset0(Class<?> arrayClass);
|
||||
private native int arrayIndexScale0(Class<?> arrayClass);
|
||||
private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
|
||||
private native int getLoadAverage0(double[] loadavg, int nelems);
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -57,7 +57,6 @@ class NativeConstructorAccessorImpl extends ConstructorAccessorImpl {
|
|||
// be found from the generated bytecode.
|
||||
if (++numInvocations > ReflectionFactory.inflationThreshold()
|
||||
&& !c.getDeclaringClass().isHidden()
|
||||
&& !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())
|
||||
&& generated == 0
|
||||
&& U.compareAndSetInt(this, GENERATED_OFFSET, 0, 1)) {
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -55,7 +55,6 @@ class NativeMethodAccessorImpl extends MethodAccessorImpl {
|
|||
// found from the generated bytecode.
|
||||
if (++numInvocations > ReflectionFactory.inflationThreshold()
|
||||
&& !method.getDeclaringClass().isHidden()
|
||||
&& !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())
|
||||
&& generated == 0
|
||||
&& U.compareAndSetInt(this, GENERATED_OFFSET, 0, 1)) {
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -202,8 +202,7 @@ public class ReflectionFactory {
|
|||
method = root;
|
||||
}
|
||||
|
||||
if (noInflation && !method.getDeclaringClass().isHidden()
|
||||
&& !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
|
||||
if (noInflation && !method.getDeclaringClass().isHidden()) {
|
||||
return new MethodAccessorGenerator().
|
||||
generateMethod(method.getDeclaringClass(),
|
||||
method.getName(),
|
||||
|
@ -247,8 +246,7 @@ public class ReflectionFactory {
|
|||
return new BootstrapConstructorAccessorImpl(c);
|
||||
}
|
||||
|
||||
if (noInflation && !c.getDeclaringClass().isHidden()
|
||||
&& !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
|
||||
if (noInflation && !c.getDeclaringClass().isHidden()) {
|
||||
return new MethodAccessorGenerator().
|
||||
generateConstructor(c.getDeclaringClass(),
|
||||
c.getParameterTypes(),
|
||||
|
|
|
@ -312,12 +312,4 @@ public final class ReflectUtil {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if {@code Class cls} is a VM-anonymous class
|
||||
* as defined by {@link jdk.internal.misc.Unsafe#defineAnonymousClass}
|
||||
* (not to be confused with a Java Language anonymous inner class).
|
||||
*/
|
||||
public static boolean isVMAnonymousClass(Class<?> cls) {
|
||||
return cls.getName().indexOf('/') > -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue