Summary
Add methods to StackFrame to return the method signature information at runtime.
Problem
Method signature is one important part of a stack frame but is not available in JDK 9. Exposing method signature will provide the complete information of a stack frame and enable one to look up the method reflectively, if desire.
Solution
This proposes to add StackFrame::getMethodType and StackFrame::getDescriptor to return the method type of this stack frame and the method descriptor string respectively. The MethodType is only available when the stack walker has the Option.RETAIN_CLASS_REFERENCE capability, similar to getDeclaringClass; otherwise access to the method type will not be available.
Specification
/**
* 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();
}
- csr of
-
JDK-8186050 StackFrame should provide the method signature
-
- Resolved
-