mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8186050: StackFrame should provide the method signature
Reviewed-by: alanb, bchristi, forax, plevart
This commit is contained in:
parent
f2a9034adf
commit
5d986605ca
7 changed files with 172 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue