Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rfb support and new JUL logging #159

Open
wants to merge 11 commits into
base: staging
Choose a base branch
from

Conversation

gravit0
Copy link
Contributor

@gravit0 gravit0 commented Jul 26, 2024

This PR fixes bugs related to the old version of ASM in mods such as #148
Instead of launchwrapper, https://github.com/GTNewHorizons/RetroFuturaBootstrap is used which provides transformers that fix this and other problems.
About JUL
RFB breaks hacks used by Crucible to implement logging of plugins and mods. These hacks were removed, and a simplified version of the log4j-jul library was written instead. The log4j-jul library itself has a minimum version of 2.1 and is not compatible with log4j 2.0-beta9. Updating to the latest log4j is complicated by the project structure
About SystemClassLoader
RFB supports two launch options - with the argument -Djava.system.class.loader=com.gtnewhorizons.retrofuturabootstrap.RfbSystemClassLoader and with the argument -Drfb.skipClassLoaderCheck=true. I don't know which option will be better for Crucible, I didn't notice any difference in behavior during testing.
This change may be break something. Requires thorough testing!

@gravit0
Copy link
Contributor Author

gravit0 commented Jul 26, 2024

It would be nice to get rfb transformers working for plugins. I might need some help with that.

@juanmuscaria
Copy link
Member

Plugin transforming is quite a special case, since you would have to delegate plugin classes to launchwrapper (or rfb in this case) but not define them in the lw/rfb classloader. My proposal would be enumerating transformers/plugins manually and having a config of "safe" transformers that can interact with plugins, then call it directly

@juanmuscaria juanmuscaria self-assigned this Jul 26, 2024
@gravit0
Copy link
Contributor Author

gravit0 commented Jul 26, 2024

Plugin transforming is quite a special case, since you would have to delegate plugin classes to launchwrapper (or rfb in this case) but not define them in the lw/rfb classloader. My proposal would be enumerating transformers/plugins manually and having a config of "safe" transformers that can interact with plugins, then call it directly

I found method https://github.com/GTNewHorizons/RetroFuturaBootstrap/blob/c948dae9fd90c1db88385915c328dfd51971a294/src/main/java/com/gtnewhorizons/retrofuturabootstrap/URLClassLoaderWithUtilities.java#L37 that can be helpful. This method not define class itself, public and can be invoked from PluginClassLoader. Example use from LaunchClassLoader here: https://github.com/GTNewHorizons/RetroFuturaBootstrap/blob/c948dae9fd90c1db88385915c328dfd51971a294/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java#L313
I dont know what context need for plugins. It looks easy

@gravit0
Copy link
Contributor Author

gravit0 commented Jul 26, 2024

An alternative option is to use rfb to load plugins directly without PluginClassLoader (the plugin must be ready for this). Unfortunately, such plugins will not be able to interact with others from PluginClassLoader

@juanmuscaria
Copy link
Member

I dont know what context need for plugins.
We would need to grab https://github.com/GTNewHorizons/RetroFuturaBootstrap/blob/c948dae9fd90c1db88385915c328dfd51971a294/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java#L68 somehow to decide the context, or keep our own transformer exclusion, or both.

About that method, seems like it only invokes rfb transformers while skipping normal lw transformers, which can be good and bad? Rfb transformers would be less common and would not cause as many issues as normal transformers, so less manual labor. But how should mixins be handled?

I'm open to more opinions on how plugin transformation should be handled at all.

@gravit0
Copy link
Contributor Author

gravit0 commented Jul 26, 2024

rfb transformers seem safe and are required to work on new versions of Java. We can make options for using rfb and regular transformers the same way remapping is configured now. We can use the runTransformers method via reflection, or if we really need it, create an issue to the authors of RFB.
I don't know what exactly is required for mixins to work (maybe some kind of registration of the mod in the system that is not performed in the case of plugins).
We are unlikely to encounter a situation where we need to load a class from the exclusion list

@gravit0
Copy link
Contributor Author

gravit0 commented Jul 28, 2024

Enabling rfb and lw transformers did not break the plugins I tested. However, plugins like NBT API and PowerNBT do not work correctly in both staging and rfb-support (this PR) branches. The problem is that Class.forName returns ClassNotFound if the requested name differs from the name of the received class. This problem persists on both Java 17+ and Java 8.

@juanmuscaria
Copy link
Member

That issue in specific was caused by including unimixin, not sure why, but it breaks reflection on vanilla classes due to reflection trying to find unmapped classes.

@gravit0
Copy link
Contributor Author

gravit0 commented Jul 28, 2024

That issue in specific was caused by including unimixin, not sure why, but it breaks reflection on vanilla classes due to reflection trying to find unmapped classes.

I not using unimixins while testing.

@gravit0
Copy link
Contributor Author

gravit0 commented Jul 28, 2024

Replace Class.forName to classloader.loadClass works for my test plugin. May be need apply this fix to all plugins by asm transformer?

@gravit0
Copy link
Contributor Author

gravit0 commented Aug 11, 2024

I tested this PR with GTNH 5.6.1 and popular plugins

  1. Small problem with console: small visual bugs with display command
  2. WorldGuard/WorldEdit not compatibility with CoFH (for mods who fix this) lw transformer (but lw transformers for plugins are disabled by default)
  3. Rfb transformers seems fully safe

Plugins (16): CoreProtect, Chatty, LuckPerms, MultiWorld, WorldEdit, Essentials, EssentialsProtect, EssentialsChat, EssentialsAntiBuild, ClearLag, WorldBorder, TestPlugin, EssentialsSpawn, WorldGuard, Multiverse-Core, Crucible_Server

Can you review this PR?

@juanmuscaria
Copy link
Member

Small problem with console: small visual bugs with display command

The logger hack was supposed to fix that by handing over logger control to bukkit console handler

@juanmuscaria
Copy link
Member

I wonder if it would be possible to be able to switch between rfb and lw with a simple option toggle, it would require changing crucible bootstrapping a bit though, so something for me to do later.

@gravit0
Copy link
Contributor Author

gravit0 commented Aug 12, 2024

The logger hack was supposed to fix that by handing over logger control to bukkit console handler

I try fix this without return logger hack

I wonder if it would be possible to be able to switch between rfb and lw with a simple option toggle, it would require changing crucible bootstrapping a bit though, so something for me to do later.

Probably a bad idea. Rfb contains modified lw classes

@juanmuscaria
Copy link
Member

Probably a bad idea. Rfb contains modified lw classes

With a modified bootstrapping, it either loads crucible lw or rfb, so it would not have any conflict.

Copy link
Member

@juanmuscaria juanmuscaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all looks good, I'll add the cruible start/end patch commends when I merge it. Can't test the changes in a live server at the moment, but if someone else can test it and give feedback, it would be helpful.

@EverNife EverNife self-requested a review October 21, 2024 19:16
@EverNife
Copy link
Member

EverNife commented Oct 21, 2024

I am testing this pull-request to check for the compats of these changes.
My modpack cannot start with these changes.
I got this crash from EnderIOAddons after changing from latest-staging to your build:

[CrashReport from EnderIOAddons]

CrashReport

java.lang.NullPointerException: Cannot invoke "net.minecraft.item.ItemStack.func_77973_b()" because "info.loenwind.enderioaddons.recipe.Recipes.capBankCreative" is null
	at Launch//info.loenwind.enderioaddons.plant.EioaGrowthRequirement.<init>(EioaGrowthRequirement.java:34)
	at Launch//info.loenwind.enderioaddons.plant.EioaCropPlant.<init>(EioaCropPlant.java:40)
	at Launch//info.loenwind.enderioaddons.machine.afarm.TileAfarm.registerPlants(TileAfarm.java:138)
	at Launch//info.loenwind.enderioaddons.machine.afarm.AgriDetector.registerPlants(AgriDetector.java:35)
	at Launch//info.loenwind.enderioaddons.proxy.ClientAndServerProxy.init(ClientAndServerProxy.java:66)
	at Launch//info.loenwind.enderioaddons.EnderIOAddons.init(EnderIOAddons.java:80)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at Launch//cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at Launch//com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
	at Launch//com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
	at Launch//com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
	at Launch//com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
	at Launch//com.google.common.eventbus.EventBus.post(EventBus.java:275)
	at Launch//cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
	at Launch//cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at Launch//com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
	at Launch//com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
	at Launch//com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
	at Launch//com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
	at Launch//com.google.common.eventbus.EventBus.post(EventBus.java:275)
	at Launch//cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
	at Launch//cpw.mods.fml.common.Loader.initializeMods(Loader.java:739)
	at Launch//cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:97)
	at Launch//cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:323)
	at Launch//net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:270)
	at Launch//net.minecraft.server.MinecraftServer.run(MinecraftServer.java:644)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Seems to be a problem on a mixin over ItemStack. Maybe the change of loading order of mixins caused that.

Anyway, EnderIoAddons is not the most stable mod in the World, so maybe is something specific with him that can be fixed on the mod itself. But is already something to keep in mind.

For the plugins, you said something about WorldGuard and Cofh, i was not able to reproduce the bug you said exist when these two are together, for my modpack the WorldGuard is working. Can you clarify that a little bit oh, its only with lw transformer turned true '-'

@EverNife
Copy link
Member

EverNife commented Oct 21, 2024

Well, without enabling the lwTransformer everything seems fine. (tecnically is meanted to be enabled for specific plugins so whatever)

Gonna try to fix the compatibility with the EnderIOAddons.

@gravit0
Copy link
Contributor Author

gravit0 commented Oct 21, 2024

The logging behavior does not exactly match the logging behavior in staging. You can help to fix the remaining issues

lwTransformers may not be safe for plugins, so they are not enabled by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants