This commit is contained in:
Jesper Wilhelmsson 2017-10-04 20:01:19 +00:00
commit eed5d34c26
235 changed files with 7673 additions and 2642 deletions

View file

@ -2160,10 +2160,12 @@ public abstract class ClassLoader {
* if a package of the given {@code name} is already
* defined by this class loader
*
*
* @since 1.2
* @revised 9
* @spec JPMS
*
* @jvms 5.3 Run-time package
* @see <a href="{@docRoot}/../specs/jar/jar.html#sealing">
* The JAR File Specification: Package Sealing</a>
*/
@ -2186,17 +2188,19 @@ public abstract class ClassLoader {
}
/**
* Returns a {@code Package} of the given <a href="#name">name</a> that has been
* defined by this class loader.
* Returns a {@code Package} of the given <a href="#name">name</a> that
* has been defined by this class loader.
*
* @param name The <a href="#name">package name</a>
*
* @return The {@code Package} of the given name defined by this class loader,
* or {@code null} if not found
* @return The {@code Package} of the given name that has been defined
* by this class loader, or {@code null} if not found
*
* @throws NullPointerException
* if {@code name} is {@code null}.
*
* @jvms 5.3 Run-time package
*
* @since 9
* @spec JPMS
*/
@ -2211,14 +2215,18 @@ public abstract class ClassLoader {
}
/**
* Returns all of the {@code Package}s defined by this class loader.
* The returned array has no duplicated {@code Package}s of the same name.
* Returns all of the {@code Package}s that have been defined by
* this class loader. The returned array has no duplicated {@code Package}s
* of the same name.
*
* @apiNote This method returns an array rather than a {@code Set} or {@code Stream}
* for consistency with the existing {@link #getPackages} method.
*
* @return The array of {@code Package} objects defined by this class loader;
* or an zero length array if no package has been defined by this class loader.
* @return The array of {@code Package} objects that have been defined by
* this class loader; or an zero length array if no package has been
* defined by this class loader.
*
* @jvms 5.3 Run-time package
*
* @since 9
* @spec JPMS
@ -2244,7 +2252,7 @@ public abstract class ClassLoader {
* @param name
* The <a href="#name">package name</a>
*
* @return The {@code Package} corresponding to the given name defined by
* @return The {@code Package} of the given name that has been defined by
* this class loader or its ancestors, or {@code null} if not found.
*
* @throws NullPointerException
@ -2263,6 +2271,8 @@ public abstract class ClassLoader {
* {@link ClassLoader#getDefinedPackage} method which returns
* a {@code Package} for the specified class loader.
*
* @see ClassLoader#getDefinedPackage(String)
*
* @since 1.2
* @revised 9
* @spec JPMS
@ -2281,10 +2291,10 @@ public abstract class ClassLoader {
}
/**
* Returns all of the {@code Package}s defined by this class loader
* and its ancestors. The returned array may contain more than one
* {@code Package} object of the same package name, each defined by
* a different class loader in the class loader hierarchy.
* Returns all of the {@code Package}s that have been defined by
* this class loader and its ancestors. The returned array may contain
* more than one {@code Package} object of the same package name, each
* defined by a different class loader in the class loader hierarchy.
*
* @apiNote The {@link #getPlatformClassLoader() platform class loader}
* may delegate to the application class loader. In other words,
@ -2294,8 +2304,10 @@ public abstract class ClassLoader {
* when invoked on the platform class loader, this method will not
* return any packages defined to the application class loader.
*
* @return The array of {@code Package} objects defined by this
* class loader and its ancestors
* @return The array of {@code Package} objects that have been defined by
* this class loader and its ancestors
*
* @see ClassLoader#getDefinedPackages()
*
* @since 1.2
* @revised 9

View file

@ -29,6 +29,7 @@ import jdk.internal.misc.SharedSecrets;
import static java.lang.StackWalker.Option.*;
import java.lang.StackWalker.StackFrame;
import java.lang.invoke.MethodType;
class StackFrameInfo implements StackFrame {
private final static JavaLangInvokeAccess JLIA =
@ -78,6 +79,17 @@ class StackFrameInfo implements StackFrame {
return JLIA.getName(memberName);
}
@Override
public MethodType getMethodType() {
walker.ensureAccessEnabled(RETAIN_CLASS_REFERENCE);
return JLIA.getMethodType(memberName);
}
@Override
public String getDescriptor() {
return JLIA.getMethodDescriptor(memberName);
}
@Override
public int getByteCodeIndex() {
// bci not available for native methods

View file

@ -26,10 +26,12 @@ package java.lang;
import jdk.internal.reflect.CallerSensitive;
import java.util.*;
import java.lang.invoke.MethodType;
import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
@ -96,7 +98,7 @@ public final class StackWalker {
* @since 9
* @jvms 2.6
*/
public static interface StackFrame {
public interface StackFrame {
/**
* Gets the <a href="ClassLoader.html#name">binary name</a>
* of the declaring class of the method represented by this stack frame.
@ -127,6 +129,47 @@ public final class StackWalker {
*/
public Class<?> getDeclaringClass();
/**
* Returns the {@link MethodType} representing the parameter types and
* the return type for the method represented by this stack frame.
*
* @implSpec
* The default implementation throws {@code UnsupportedOperationException}.
*
* @return the {@code MethodType} for this stack frame
*
* @throws UnsupportedOperationException if this {@code StackWalker}
* is not configured with {@link Option#RETAIN_CLASS_REFERENCE
* Option.RETAIN_CLASS_REFERENCE}.
*
* @since 10
*/
public default MethodType getMethodType() {
throw new UnsupportedOperationException();
}
/**
* Returns the <i>descriptor</i> of the method represented by
* this stack frame as defined by
* <cite>The Java Virtual Machine Specification</cite>.
*
* @implSpec
* The default implementation throws {@code UnsupportedOperationException}.
*
* @return the descriptor of the method represented by
* this stack frame
*
* @see MethodType#fromMethodDescriptorString(String, ClassLoader)
* @see MethodType#toMethodDescriptorString()
* @jvms 4.3.3 Method Descriptor
*
* @since 10
*/
public default String getDescriptor() {
throw new UnsupportedOperationException();
}
/**
* Returns the index to the code array of the {@code Code} attribute
* containing the execution point represented by this stack frame.

View file

@ -28,6 +28,7 @@ package java.lang.invoke;
import java.util.Arrays;
import static java.lang.invoke.LambdaForm.*;
import static java.lang.invoke.LambdaForm.Kind.*;
import static java.lang.invoke.MethodHandleNatives.Constants.REF_invokeVirtual;
import static java.lang.invoke.MethodHandleStatics.*;
/**
@ -158,8 +159,11 @@ abstract class DelegatingMethodHandle extends MethodHandle {
static final NamedFunction NF_getTarget;
static {
try {
NF_getTarget = new NamedFunction(DelegatingMethodHandle.class
.getDeclaredMethod("getTarget"));
MemberName member = new MemberName(DelegatingMethodHandle.class, "getTarget",
MethodType.methodType(MethodHandle.class), REF_invokeVirtual);
NF_getTarget = new NamedFunction(
MemberName.getFactory()
.resolveOrFail(REF_invokeVirtual, member, DelegatingMethodHandle.class, NoSuchMethodException.class));
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}

View file

@ -753,42 +753,38 @@ class DirectMethodHandle extends MethodHandle {
return nf;
}
private static final MethodType OBJ_OBJ_TYPE = MethodType.methodType(Object.class, Object.class);
private static final MethodType LONG_OBJ_TYPE = MethodType.methodType(long.class, Object.class);
private static NamedFunction createFunction(byte func) {
try {
switch (func) {
case NF_internalMemberName:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("internalMemberName", Object.class));
return getNamedFunction("internalMemberName", OBJ_OBJ_TYPE);
case NF_internalMemberNameEnsureInit:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("internalMemberNameEnsureInit", Object.class));
return getNamedFunction("internalMemberNameEnsureInit", OBJ_OBJ_TYPE);
case NF_ensureInitialized:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("ensureInitialized", Object.class));
return getNamedFunction("ensureInitialized", MethodType.methodType(void.class, Object.class));
case NF_fieldOffset:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("fieldOffset", Object.class));
return getNamedFunction("fieldOffset", LONG_OBJ_TYPE);
case NF_checkBase:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("checkBase", Object.class));
return getNamedFunction("checkBase", OBJ_OBJ_TYPE);
case NF_staticBase:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("staticBase", Object.class));
return getNamedFunction("staticBase", OBJ_OBJ_TYPE);
case NF_staticOffset:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("staticOffset", Object.class));
return getNamedFunction("staticOffset", LONG_OBJ_TYPE);
case NF_checkCast:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("checkCast", Object.class, Object.class));
return getNamedFunction("checkCast", MethodType.methodType(Object.class, Object.class, Object.class));
case NF_allocateInstance:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("allocateInstance", Object.class));
return getNamedFunction("allocateInstance", OBJ_OBJ_TYPE);
case NF_constructorMethod:
return new NamedFunction(DirectMethodHandle.class
.getDeclaredMethod("constructorMethod", Object.class));
return getNamedFunction("constructorMethod", OBJ_OBJ_TYPE);
case NF_UNSAFE:
return new NamedFunction(new MemberName(MethodHandleStatics.class
.getDeclaredField("UNSAFE")));
MemberName member = new MemberName(MethodHandleStatics.class, "UNSAFE", Unsafe.class, REF_getField);
return new NamedFunction(
MemberName.getFactory()
.resolveOrFail(REF_getField, member, DirectMethodHandle.class, NoSuchMethodException.class));
default:
throw newInternalError("Unknown function: " + func);
}
@ -797,6 +793,15 @@ class DirectMethodHandle extends MethodHandle {
}
}
private static NamedFunction getNamedFunction(String name, MethodType type)
throws ReflectiveOperationException
{
MemberName member = new MemberName(DirectMethodHandle.class, name, type, REF_invokeStatic);
return new NamedFunction(
MemberName.getFactory()
.resolveOrFail(REF_invokeStatic, member, DirectMethodHandle.class, NoSuchMethodException.class));
}
static {
// The Holder class will contain pre-generated DirectMethodHandles resolved
// speculatively using MemberName.getFactory().resolveOrNull. However, that

View file

@ -611,23 +611,17 @@ class Invokers {
try {
switch (func) {
case NF_checkExactType:
return new NamedFunction(Invokers.class
.getDeclaredMethod("checkExactType", MethodHandle.class, MethodType.class));
return getNamedFunction("checkExactType", MethodType.methodType(void.class, MethodHandle.class, MethodType.class));
case NF_checkGenericType:
return new NamedFunction(Invokers.class
.getDeclaredMethod("checkGenericType", MethodHandle.class, MethodType.class));
return getNamedFunction("checkGenericType", MethodType.methodType(MethodHandle.class, MethodHandle.class, MethodType.class));
case NF_getCallSiteTarget:
return new NamedFunction(Invokers.class
.getDeclaredMethod("getCallSiteTarget", CallSite.class));
return getNamedFunction("getCallSiteTarget", MethodType.methodType(MethodHandle.class, CallSite.class));
case NF_checkCustomized:
return new NamedFunction(Invokers.class
.getDeclaredMethod("checkCustomized", MethodHandle.class));
return getNamedFunction("checkCustomized", MethodType.methodType(void.class, MethodHandle.class));
case NF_checkVarHandleGenericType:
return new NamedFunction(Invokers.class
.getDeclaredMethod("checkVarHandleGenericType", VarHandle.class, VarHandle.AccessDescriptor.class));
return getNamedFunction("checkVarHandleGenericType", MethodType.methodType(MethodHandle.class, VarHandle.class, VarHandle.AccessDescriptor.class));
case NF_checkVarHandleExactType:
return new NamedFunction(Invokers.class
.getDeclaredMethod("checkVarHandleExactType", VarHandle.class, VarHandle.AccessDescriptor.class));
return getNamedFunction("checkVarHandleExactType", MethodType.methodType(MethodHandle.class, VarHandle.class, VarHandle.AccessDescriptor.class));
default:
throw newInternalError("Unknown function: " + func);
}
@ -636,6 +630,15 @@ class Invokers {
}
}
private static NamedFunction getNamedFunction(String name, MethodType type)
throws ReflectiveOperationException
{
MemberName member = new MemberName(Invokers.class, name, type, REF_invokeStatic);
return new NamedFunction(
MemberName.getFactory()
.resolveOrFail(REF_invokeStatic, member, Invokers.class, NoSuchMethodException.class));
}
private static class Lazy {
private static final MethodHandle MH_asSpreader;

View file

@ -162,6 +162,29 @@ import static java.lang.invoke.MethodHandleStatics.newInternalError;
return (MethodType) type;
}
/** Return the descriptor of this member, which
* must be a method or constructor.
*/
String getMethodDescriptor() {
if (type == null) {
expandFromVM();
if (type == null) {
return null;
}
}
if (!isInvocable()) {
throw newIllegalArgumentException("not invocable, no method type");
}
// Get a snapshot of type which doesn't get changed by racing threads.
final Object type = this.type;
if (type instanceof String) {
return (String) type;
} else {
return getMethodType().toMethodDescriptorString();
}
}
/** Return the actual type under which this method or constructor must be invoked.
* For non-static methods or constructors, this is the type with a leading parameter,
* a reference to declaring class. For static methods, it is the same as the declared type.

View file

@ -1785,6 +1785,18 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
return memberName.getName();
}
@Override
public MethodType getMethodType(Object mname) {
MemberName memberName = (MemberName)mname;
return memberName.getMethodType();
}
@Override
public String getMethodDescriptor(Object mname) {
MemberName memberName = (MemberName)mname;
return memberName.getMethodDescriptor();
}
@Override
public boolean isNative(Object mname) {
MemberName memberName = (MemberName)mname;