On 8/28/17 4:23 PM, Paul Sandoz wrote:
Hi Mandy,
MethodType::fromMethodDescriptorString (and the three arg Class.forName)
requires that a class loader be supplied. Perhaps for the thing consuming
StackWalker it’s not possible to reproduce a MethodType (or components of) from
the descriptor string
The class loader can be obtained from
StackFrame::getDeclaringClass().getClassLoader().
much like it may not possible to reproduce the declaring class from the class
name string, hence the need for RETAIN_CLASS_REFERENCE?
Right and also security permission check can be performed once when
getting StackWalker instance. No security permission check is performed
for each StackFrame::getDeclaringClass for better performance.
If i understand you correctly i think you are saying the method descriptor is
more useful for informational (logging say) purposes?
Yes for completeness since the method signature is currently unavailable.
Mandy
Paul.
On 28 Aug 2017, at 15:57, mandy chung <[email protected]> wrote:
Method signature is missing in the StackFrame API. This proposes to add
StackFrame::getMethodDescriptor method to return the method descriptor in a
stack frame.
Webrev at:
http://cr.openjdk.java.net/~mchung/jdk10/webrevs/8186050/webrev.00/index.html
There are a couple options how to present the method signature in the API level:
1. Class<?>[] getParameterTypes() and Class<?> getReturnTypes() similiar to
what java.lang.reflect.Method has.
2. java.lang.invoke.MethodType
3. a String representation (i) comma-separated list of the method's formal
parameter types (ii) bytecode method descriptor as specified in JVMS
Returning Class<?> instance should require to add a new StackWalker option to
access to the parameter types and return type for option #1 and #2.
StackFrame::getDeclaringClass requires the stack walker to have the
RETAIN_CLASS_REFERENCE capability.
Option #2 returning MethodType is handy while java.lang would reference a type
in java.lang.invoke.
Option #3 requires the caller to parse the return string and call Class.forName to
get the Class<?> instance. OTOH MethodType::fromMethodDescriptorString method
that returns MethodType from a bytecode method descriptor string.
Method signature is for information for typical cases. Getting Class<?> for the
parameter types and return type would be a niche case. I think returning the method
descriptor string is a good option - keep the API simple and can use
MethodType::fromMethodDescriptorString to get back the types if needed.
thanks
Mandy