question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoke the game using MethodHandle

See original GitHub issue

Currently 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:

https://github.com/FabricMC/fabric-loader/blob/7c83b2604cd678bcb6dd29312e438cd09b8671ca/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java#L450-L452

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
altrisicommented, Apr 30, 2022

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 and java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke), while a MethodHandle implementation has none. Tested with the panama JDK 19 build.

0reactions
warjortcommented, May 1, 2022

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.”

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found