For an example of how this is used when setup: https://wiki.fabricmc.net/tutorial:mixin_examples
> ASM is an all purpose Java bytecode manipulation and analysis framework.
Oh. I was expecting something much more weird from the title, and that's a pretty confusing/misleading name for that.
I was curious about this as perhaps a new approach to recipe-oriented bytecode injection. But the I looked at the project's (long) history and docs status. It seems that the main contributor has tapered off this project over time, and more specifically hasn't been active since July. (Mumfrey, if you're out there, please tell us what's up)
So, OP, what made you mention this here now?
I would say that the feature set is pretty powerful as is, and it shows in the earlier history (having worked with Mixins since before it was called Mixins). The history reaches further back than the first commit to having been developed for Mumfrey's own modloader (LiteLoader).
As someone else already replied, Mumfrey still practices private development and only pushes new code after his own extensive testing. He has long periods of "public" inactivity because code refactors and other changes can be delicate given the widespread usage of the library within the Minecraft modding ecosystem, and as such, he doesn't want the distraction that in-development can attract from said community.
There's a maintained fork here: https://github.com/FabricMC/Mixin
IIRC, at least a few years ago, Mumfrey had a tendency to develop Mixin in private and only push the commit backlog for releases, leading to periods of time where no activity was publicly visible. (Also IIRC, this is part of the reason why the FabricMC fork exists.)
I kind of wish Java just went full Objective-C and provided native APIs to patch and redirect methods. Having everyone ship a bytecode manipulation library just to mock a method or two is quite annoying given how easy it would be for the runtime to offer this directly (and probably more performantly).
The applications for Mixin wasn't to mock a method or two, it's to enable full-scale modification of an existing Java application at runtime without recompiling/redistributing the original application. In the case of its origins, modifying Minecraft server to add a non-obfuscated API and implement said API on top of it through Mixins. The way this is achieved is practically at the class load point in time so the runtime costs are reduced to maybe a couple of seconds (as of current writing, Sponge has somewhere around 1.2k mixins overall). Could there be a better native API? I'm hoping so, Java's Class File API (JEP-484) is a pretty good start, but I don't think it's quite enough yet to enable the full functionality of what Mixin does.
Not sure if this fits, but JDK 24 includes a new API, java.lang.classfile, for classfile manipulation.
Is their a design document, somewhere about this new library ?
The jep does not explain how to prepare to new Java bytecodes and future enhancements. Am i suppose to only run with the latest version of Java if i want to use that library ?
What is the advantage compared to established AOP libraries, such as AspectJ or BytecodeBuddy?
A primary advantage of Mixin is using Java as a DSL to apply various kinds of bytecode transformation with some examples here:
- Changing a constant within a target method https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9ed...
- Replacing a method call within a specific method https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9ed...
- Adding an interface and its implementation to the target class (in this case net.minecraft.world.entity.Entity will now implement org.spongepowered.api.entity.Entity and its methods) https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9ed...
There's a fair bit more that is possible that would otherwise require a fair bit more code wrangling with AspectJ or BytecodeBuddy to achieve the same effects.
Both of these use ASM under the hood
Isn't composition is superior to mixins for a few reasons, particularly the "Single-responsibility principle" ?
The purpose of this library is to make it easier to modify existing code, eg to make existing classes implement new interfaces. In particular, it seems to be used for Minecraft modding.
Yes, Minecraft gets more and more data-driven, but for adding completely new features like, a solar system with planets, or turning the player into a robot of something, you'll have to edit some of the built in code.
This Mixin library is very useful, since it allows different mods to edit different parts of the same code without interfering for example.
It's also very easy to use compared to jvm bytecode manipulation, you just write a normal java function and put an annotation on it, and boom, now it runs right before line X inside of class Y, at runtime !
You're referring to mixins in programming (https://en.wikipedia.org/wiki/Mixin) which isn't related to this library
? alt: Java 23 - Class-File API (Second Preview)
ah yes ASM, the bytecode manipulator for java. Please look forward to JAVA, my upcoming tool for manipulating assembly code.