fabric-loader icon indicating copy to clipboard operation
fabric-loader copied to clipboard

Thinking about a post Java 8 world

Open modmuss50 opened this issue 3 years ago • 26 comments

Thinking about a post Java 8 world

It seems quite likely that minecraft will recieve an update of Java in the near future. The latest version of the launcher has support for alternate Java versions, and the latest snapshot dropped support for the old GPUs that were forcing the use of an ancient version of Java 8.

My guess is Java 16 will be the target, mainly due to having some neat features that I can see Mojang wanting to make use of, most notably records.

This issue is just a place to gather thoughts / be a todo list of what would would need to required to get the whole fabric toolchain updated to support this. In someways most of the work has already been done over time. Moving our CI/CD setup to github actions means we already test, build and release from Java 15. (While targeting Java 8)

A lot of the following items in the "todo list" assumes that records are being used as this is where most of the work left is. The following list is somewhat in order of what would need to be done, however some of the tasks can be done independently of each other, or even at a later date.

Items with a :mag: emoji might already be done/need investigating.

Record mapping

  • Record fields and methods should be mapped as usual. Record components can just be based off the field names and reuse the field javadoc. This removes the need to update the mapping format and removes the pain with V1.

  • Tiny remapper and friends will need updating to support this.

Yarn/Intermediary

This section contains what would need to be done to get Yarn/Intermediary working.

  • Matcher
    • Support the above record changes.
    • Support matching records :mag:
  • Stitch
    • Jar Merging - Used by Loom and Yarn
    • Remove/dont update: Intermediary gen/updating as matcher can do this.
  • Engima
    • Add support for records in the mapping format
    • :mag: Check record remapping, I did brefily check this a while back and it seemed ok on the surface. I imagine the saving/loading will be missing.
  • Intermediary
    • Should generate the same field and method names for record components, comp_x?
  • Yarn
    • Should be quite easy once all the tools/libs are in place, just update them in the build.gradle
      • Should be able to build and remap a namedJar before releasing intermediary or yarn!

Fabric Loader

  • Should just work in theory?
  • Might have issues with a mismatching guava version assuming that gets updated at the time time
  • Java 8 support should be kept here for the foreseeable future for older minecraft versions and other games.

Loom

  • New branch
  • Bump to build against J16 and Gradle 7 (Required for J16)

Fabric API

  • Should be quite simple in theory, Just update loom / Target J16
  • Modules? - Should not be forced onto modders.

Access Widener

  • Sealed Classes support? Easy to do, still in preview so prob unlikely its being used.

There are going to be quite a few unforseen issues ontop of this, but I dont believe I have missed anything major. This clearly will take some time to handle, but it doesnt need to be perfect on the first go, we target snapshots so we have time to break things.

Feel free to point out stuff I've missed/provide ideas on things this is just what I have in my head.

PRs working to support this:

fabric-loom : Javadoc support for records intellij-fernflower : pulls in upstream changes containg a number of useful fixes.

modmuss50 avatar Mar 12 '21 19:03 modmuss50

Tiny remapper, needs to supoort remapping record components and their resident annotations.

i509VCB avatar Mar 12 '21 20:03 i509VCB

Added

modmuss50 avatar Mar 12 '21 20:03 modmuss50

I'm not sure it's especially necessary to have a specific mapping type for records. As ever the JLS is specifically vague; but either the record components do have to match the field/accessor name in which case field mappings should be used as the fields have to remain consistent with their respective record component (though leaves Enigma and Matcher responsible for keeping the accessor name consistent), or they don't in which case it doesn't matter (unless someone especially reflected the vanilla record type).

Chocohead avatar Mar 13 '21 02:03 Chocohead

Why specifically Java 16? At least according to wikipedia, Java 16 will stop recieving updates once 17 (the next LTS) is released. It doesn't really make much sense for mojang to switch to a Java version which will only be officially supported for a few months.

Hnaguski avatar Mar 13 '21 05:03 Hnaguski

@Hnaguski Peterix has hinted in MultiMC Discord that Minecraft may be based on Java 15 or a newer version. In short, the existing information does not confirm or falsify that Minecraft must be based on the LTS version.

image

ZekerZhayard avatar Mar 13 '21 06:03 ZekerZhayard

I would like to hope they would be able to keep up with java updates, I dont see why this wouldnt be possible.

Not having anything special for records might make things easier, would be easy enough to verify that the name are alinged.

modmuss50 avatar Mar 13 '21 11:03 modmuss50

Just a quick note: Java 15 was added to some launcher meta this snapshot, so it now looks really likely that they'll be going for 15 and not 16. Loom and fapi should therefore target 15 (and not 16) once Minecraft does.

Earthcomputer avatar Mar 17 '21 19:03 Earthcomputer

Java 16 was also released yesterday, so they might've just not updated it yet.

haykam821 avatar Mar 17 '21 19:03 haykam821

Yes, 16 would be nice but 15 seems like the safe option. We need to make sure we are in a position to keep up assuming mojang keeps upto date.

I do want to enable preview features (would allow records if it is java 15) at runtime but allow modders to opt-into them if they wish. I dont see much of a downside to this, I have used preview features for some other projects without issue.

modmuss50 avatar Mar 17 '21 19:03 modmuss50

Just a quick note: Java 15 was added to some launcher meta this snapshot, so it now looks really likely that they'll be going for 15 and not 16. Loom and fapi should therefore target 15 (and not 16) once Minecraft does.

There's no release actually using it yet, so you can't be sure yet.

kb-1000 avatar Mar 17 '21 19:03 kb-1000

Ive had a deeper dive into records and do think that basing the component names off the field names is the way to go. Javadoc can be pulled from the fields as well.

Intermediary will need to output the same name for the fields and methods, will prob need a new counter imo.

modmuss50 avatar Mar 17 '21 19:03 modmuss50

I do want to enable preview features (would allow records if it is java 15) at runtime but allow modders to opt-into them if they wish. I dont see much of a downside to this, I have used preview features for some other projects without issue.

I don't like the idea of Fabric using potentially fragile, or subject to change, features by default.

jamierocks avatar Mar 17 '21 20:03 jamierocks

It would be up to the modder to opt in for their mod. I think its worth the risk for the benefits, I see it being ulikely to cause issues outside of the experimental features.

modmuss50 avatar Mar 17 '21 20:03 modmuss50

Experimental features are fine in the situation where Minecraft is not on the latest Java version, and the feature is still in preview in the version Minecraft is compiled for, but in the current latest Java version, the feature is out of preview and has remained unchanged since it was in preview.

Earthcomputer avatar Mar 17 '21 20:03 Earthcomputer

Ive had a deeper dive into records and do think that basing the component names off the field names is the way to go. Javadoc can be pulled from the fields as well.

Intermediary will need to output the same name for the fields and methods, will prob need a new counter imo.

You're being held by both the field and method counters to which ID a record would use, so you'd either have to skip forward which ever counter was lower or introduce a new counter entirely. Presume you're thinking of both fields and methods called record_x for them to be the same name, rather than a method called field_x?

Chocohead avatar Mar 17 '21 22:03 Chocohead

Yes, adding a new counter and keeping the name the same between the fields and methods would be the solution here. Keeps the main bulk of the record specific code to intermediary. While the existing toolchain should be able to most ingore the fact that its working with a record.

modmuss50 avatar Mar 17 '21 22:03 modmuss50

POG

https://www.minecraft.net/en-us/article/minecraft-snapshot-21w19a

Toffikk avatar May 12 '21 15:05 Toffikk

I do want to enable preview features (would allow records if it is java 15) at runtime but allow modders to opt-into them if they wish. I dont see much of a downside to this, I have used preview features for some other projects without issue.

Imo this should be controlled by the launcher like other vm args than turned on by fabric loader.

liach avatar May 19 '21 15:05 liach

The fact that preview featues being enabled prevents your class from being loaded on a newer jvm is probably reason enough to gate that feature to the jvm args

i509VCB avatar May 19 '21 15:05 i509VCB

Preview features wont be enabled, there is little to gain in j16 with them.

modmuss50 avatar May 19 '21 15:05 modmuss50

hmm, can we actually enable preview after a jvm starts (beside calling native stuff)? If we do add it, will it be a command line argument for launcher to add?

liach avatar May 19 '21 15:05 liach

In addition, we have #40, where we think about putting code into modules. Imo we can make a custom module finder that reports minecraft code as one module, possibly an automatic one (need to consider dedi server where libs and minecraft are mixed); then mods that want to depend on minecraft can use some module features, I suppose.

liach avatar May 19 '21 15:05 liach

Are there any issues left here? The list hasn't been updated since March 17.

Other than a few edge cases, Fabric works fine on 1.17 (and thus Java 16).

haykam821 avatar Jun 24 '21 05:06 haykam821

We haven't encountered actual records in minecraft code yet. Maybe this can serve as a tracking issue.

liach avatar Jun 24 '21 05:06 liach

More precisely MC doesn't appear to use any Java 16 feature yet, it looks like Java 8 code built with Javac 16. So the breakage is yet to come ;)

sfPlayer1 avatar Jun 24 '21 05:06 sfPlayer1

Yes, they are probably compiling with source compatibility 8 and target compatibility 16 (where there are nest mates, indy string concat, etc).

liach avatar Jun 24 '21 06:06 liach

Closing this issue as we are now well into supporting modern java 👍

modmuss50 avatar Feb 17 '23 22:02 modmuss50