Invoke the game using MethodHandle
See original GitHub issueCurrently the minecraft game provider invokes the game by using reflection. Reflection leaves a bunch of useless stack frames that will be present in most stacktraces given it’ll always be at the top.
MethodHandle stacktraces are hidden, therefore if loader would invoke the game using one of them it would prevent these useless frames from being printed to all those logs, crash reports or profiles.
I tried implementing this a while ago, but ran into an issue with proguard complaining about something, and I haven’t tried since.
Relevant code:
Issue Analytics
- State:
- Created a year ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
MethodHandle invoke during debugging - java - Stack Overflow
I'm trying to wrap my brain around how to use effectively use MethodHandles, one thing that's throwing me off is trying to execute...
Read more >MethodHandle (Java Platform SE 8 ) - Oracle Help Center
A method handle must be invoked using a symbolic type descriptor which matches the method handle's own type descriptor. Every method handle reports...
Read more >MethodHandle - Android Developers
A method handle must be invoked using a symbolic type descriptor which matches the method handle's own type descriptor. Every method handle reports...
Read more >MethodHandles, Java Proxies and Default Methods - JRebel
MethodHandle utilises the invokespecial instruction to call the method directly. In order to achieve that we had to go through several steps:.
Read more >MethodHandles Everywhere by Charles Nutter - YouTube
Method handles, Java's fast function pointers and functional adapters, were added in Java 7 to support new language features.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, I know there is no performance benefit with this (even if the handle was made constant, I doubt it’d have any noticeable performance benefit anyway given, as you said, it’s only called once. Initializing it may even be more expensive than any potential optimization). The only reason I mentioned it is because of the stack reduction.
We don’t know if/when Mojang will update Java again, and if they don’t (which is likely at least until the next LTS), I think hiding those is quite nice. They’re just noise that gives no information.
Not only that, from some quick testing it seems like the implementation of JEP 416 still has some non-hidden frames (
java.base/java.lang.reflect.Method.invoke
andjava.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke
), while a MethodHandle implementation has none. Tested with the panama JDK 19 build.Although proguard seems to think the bug is requiring a more precise warning, rather than the warning not being appropriate.
“ProGuard should probably provide a more accurate warning for this particular case. I’ll consider it. Your thoughts are welcome.”