This commit is contained in:
Jesper Wilhelmsson 2021-06-27 23:51:05 +00:00
commit a29953d805
90 changed files with 1714 additions and 489 deletions

View file

@ -894,7 +894,7 @@ abstract class GaloisCounterMode extends CipherSpi {
// if src is read only, then we need a copy
if (!src.isReadOnly()) {
// If using the heap, check underlying byte[] address.
if (!src.array().equals(dst.array()) ) {
if (src.array() != dst.array()) {
return dst;
}

View file

@ -59,7 +59,8 @@ public class MethodHandleProxies {
* even though it re-declares the {@code Object.equals} method and also
* declares default methods, such as {@code Comparator.reverse}.
* <p>
* The interface must be public. No additional access checks are performed.
* The interface must be public and not {@linkplain Class#isSealed() sealed}.
* No additional access checks are performed.
* <p>
* The resulting instance of the required type will respond to
* invocation of the type's uniquely named method by calling
@ -156,6 +157,8 @@ public class MethodHandleProxies {
public static <T> T asInterfaceInstance(final Class<T> intfc, final MethodHandle target) {
if (!intfc.isInterface() || !Modifier.isPublic(intfc.getModifiers()))
throw newIllegalArgumentException("not a public interface", intfc.getName());
if (intfc.isSealed())
throw newIllegalArgumentException("a sealed interface", intfc.getName());
final MethodHandle mh;
if (System.getSecurityManager() != null) {
final Class<?> caller = Reflection.getCallerClass();

View file

@ -2768,6 +2768,7 @@ assertEquals("[x, y, z]", pb.command().toString());
* @throws ClassNotFoundException if the class cannot be loaded by the lookup class' loader.
* @throws IllegalAccessException if the class is not accessible, using the allowed access
* modes.
* @throws NullPointerException if {@code targetName} is null
* @since 9
* @jvms 5.4.3.1 Class and Interface Resolution
*/
@ -2837,8 +2838,12 @@ assertEquals("[x, y, z]", pb.command().toString());
/**
* Determines if a class can be accessed from the lookup context defined by
* this {@code Lookup} object. The static initializer of the class is not run.
* If {@code targetClass} is an array class, {@code targetClass} is accessible
* if the element type of the array class is accessible. Otherwise,
* {@code targetClass} is determined as accessible as follows.
*
* <p>
* If the {@code targetClass} is in the same module as the lookup class,
* If {@code targetClass} is in the same module as the lookup class,
* the lookup class is {@code LC} in module {@code M1} and
* the previous lookup class is in module {@code M0} or
* {@code null} if not present,
@ -2861,7 +2866,7 @@ assertEquals("[x, y, z]", pb.command().toString());
* can access public types in all modules when the type is in a package
* that is exported unconditionally.
* <p>
* Otherwise, the target class is in a different module from {@code lookupClass},
* Otherwise, {@code targetClass} is in a different module from {@code lookupClass},
* and if this lookup does not have {@code PUBLIC} access, {@code lookupClass}
* is inaccessible.
* <p>
@ -2897,13 +2902,14 @@ assertEquals("[x, y, z]", pb.command().toString());
* @return the class that has been access-checked
* @throws IllegalAccessException if the class is not accessible from the lookup class
* and previous lookup class, if present, using the allowed access modes.
* @throws SecurityException if a security manager is present and it
* <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
* @throws SecurityException if a security manager is present and it
* <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
* @throws NullPointerException if {@code targetClass} is {@code null}
* @since 9
* @see <a href="#cross-module-lookup">Cross-module lookups</a>
*/
public Class<?> accessClass(Class<?> targetClass) throws IllegalAccessException {
if (!VerifyAccess.isClassAccessible(targetClass, lookupClass, prevLookupClass, allowedModes)) {
if (!isClassAccessible(targetClass)) {
throw makeAccessException(targetClass);
}
checkSecurityManager(targetClass);
@ -3684,7 +3690,11 @@ return mh1;
boolean isClassAccessible(Class<?> refc) {
Objects.requireNonNull(refc);
Class<?> caller = lookupClassOrNull();
return caller == null || VerifyAccess.isClassAccessible(refc, caller, prevLookupClass, allowedModes);
Class<?> type = refc;
while (type.isArray()) {
type = type.getComponentType();
}
return caller == null || VerifyAccess.isClassAccessible(type, caller, prevLookupClass, allowedModes);
}
/** Check name for an illegal leading "&lt;" character. */

View file

@ -710,6 +710,10 @@ public class Proxy implements java.io.Serializable {
throw new IllegalArgumentException(intf.getName() + " is a hidden interface");
}
if (intf.isSealed()) {
throw new IllegalArgumentException(intf.getName() + " is a sealed interface");
}
/*
* Verify that the class loader resolves the name of this
* interface to the same Class object.
@ -930,7 +934,8 @@ public class Proxy implements java.io.Serializable {
* if any of the following restrictions is violated:</a>
* <ul>
* <li>All of {@code Class} objects in the given {@code interfaces} array
* must represent {@linkplain Class#isHidden() non-hidden} interfaces,
* must represent {@linkplain Class#isHidden() non-hidden} and
* {@linkplain Class#isSealed() non-sealed} interfaces,
* not classes or primitive types.
*
* <li>No two elements in the {@code interfaces} array may

View file

@ -31,10 +31,15 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.ref.Reference;
import java.io.FileDescriptor;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.foreign.MemorySegmentProxy;
import jdk.internal.util.ArraysSupport;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
/**
@ -334,6 +339,126 @@ public class ScopedMemoryAccess {
Reference.reachabilityFence(scope);
}
}
// ByteBuffer vector access ops
// Buffer access constants, to be initalized when required.
// Avoids a null value for NIO_ACCESS, due to class initalization dependencies
static final class BufferAccess {
// Buffer.address
static final long BUFFER_ADDRESS
= UNSAFE.objectFieldOffset(Buffer.class, "address");
// ByteBuffer.hb
static final long BYTE_BUFFER_HB
= UNSAFE.objectFieldOffset(ByteBuffer.class, "hb");
@ForceInline
static Object bufferBase(ByteBuffer bb) {
return UNSAFE.getReference(bb, BYTE_BUFFER_HB);
}
@ForceInline
static long bufferAddress(ByteBuffer bb, long offset) {
return UNSAFE.getLong(bb, BUFFER_ADDRESS) + offset;
}
static final JavaNioAccess NIO_ACCESS = SharedSecrets.getJavaNioAccess();
@ForceInline
static ScopedMemoryAccess.Scope scope(ByteBuffer bb) {
MemorySegmentProxy segmentProxy = NIO_ACCESS.bufferSegment(bb);
return segmentProxy != null ?
segmentProxy.scope() : null;
}
}
@ForceInline
public static
<V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
V loadFromByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
ByteBuffer bb, int offset,
S s,
VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
try {
return loadFromByteBufferScoped(
BufferAccess.scope(bb),
vmClass, e, length,
bb, offset,
s,
defaultImpl);
} catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
throw new IllegalStateException("This segment is already closed");
}
}
@Scoped
@ForceInline
private static
<V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
V loadFromByteBufferScoped(ScopedMemoryAccess.Scope scope,
Class<? extends V> vmClass, Class<E> e, int length,
ByteBuffer bb, int offset,
S s,
VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
try {
if (scope != null) {
scope.checkValidState();
}
return VectorSupport.load(vmClass, e, length,
BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
bb, offset, s,
defaultImpl);
} finally {
Reference.reachabilityFence(scope);
}
}
@ForceInline
public static
<V extends VectorSupport.Vector<E>, E>
void storeIntoByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
V v,
ByteBuffer bb, int offset,
VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
try {
storeIntoByteBufferScoped(
BufferAccess.scope(bb),
vmClass, e, length,
v,
bb, offset,
defaultImpl);
} catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
throw new IllegalStateException("This segment is already closed");
}
}
@Scoped
@ForceInline
private static
<V extends VectorSupport.Vector<E>, E>
void storeIntoByteBufferScoped(ScopedMemoryAccess.Scope scope,
Class<? extends V> vmClass, Class<E> e, int length,
V v,
ByteBuffer bb, int offset,
VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
try {
if (scope != null) {
scope.checkValidState();
}
VectorSupport.store(vmClass, e, length,
BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
v,
bb, offset,
defaultImpl);
} finally {
Reference.reachabilityFence(scope);
}
}
// typed-ops here
// Note: all the accessor methods defined below take advantage of argument type profiling