refactor: modernize class info lookup

This commit is contained in:
Algent committed 2026-09-09 12:16:06 +02:00
1 parent 99ee689158
commit fa0bd01ab2
3 files changed
+25 -12

No files matched your search

+21 -10
View File
@@ -4,9 +4,9 @@
The scoped integration is implemented on `algent/java`, building on baseline `65d0cd0`. The three regression fixes The scoped integration is implemented on `algent/java`, building on baseline `65d0cd0`. The three regression fixes
are preserved. `build.gradle` adds two tasks; `StackAnalyserLogic.visitInsn` uses the validated Java 21 pattern switch, are preserved. `build.gradle` adds two tasks; `StackAnalyserLogic.visitInsn` uses the validated Java 21 pattern switch,
and `JavaTraitRegistration` uses Java 21 pattern variables. The nine Scala sources, Scala 2.11.5 dependency, source while `JavaTraitRegistration` and `ClassInfoLookup` use Java 21 pattern variables. The nine Scala sources, Scala 2.11.5
layout, and normal Gradle entry points remain in place. Production tasks do not read a frozen jar or any files under dependency, source layout, and normal Gradle entry points remain in place. Production tasks do not read a frozen jar
`run/jvmdg-trial/`. or any files under `run/jvmdg-trial/`.
The subsequent `StackAnalyser` initializer extraction is recorded in `JAVA_MIGRATION_HANDOFF.md`. The exact-byte The subsequent `StackAnalyser` initializer extraction is recorded in `JAVA_MIGRATION_HANDOFF.md`. The exact-byte
comparisons and frozen-version reproduction below describe checkpoint `5f0e329`; later helper edits need their own comparisons and frozen-version reproduction below describe checkpoint `5f0e329`; later helper edits need their own
@@ -24,6 +24,11 @@ reference comparisons. The current extraction's evidence is in `run/migration-st
The source-path declaration is an explicit Scala-task input. The existing `scalaCompileOptions.force = true` guard The source-path declaration is an explicit Scala-task input. The existing `scalaCompileOptions.force = true` guard
remains to prevent stale joint-compiled Java annotations after generated `Tags.VERSION` changes. remains to prevent stale joint-compiled Java annotations after generated `Tags.VERSION` changes.
The per-file include/exclude pairs are temporary compiler routing. These Java files still live in the Scala source set,
whose joint compiler would otherwise send them to Java 8 javac. Once the retained Scala/Java dependency cycle is gone,
move the modern cohort behind one source-set or directory boundary; once Scala is gone, compile all Java with the
modern toolchain and remove the exclusions, `-sourcepath` bridge and force guard together.
The bundled `DowngradeFiles` task initially declares outputs only for inputs that already exist during configuration. The bundled `DowngradeFiles` task initially declares outputs only for inputs that already exist during configuration.
`outputs.dirs(outputMap.values())` explicitly declares the directory for clean builds. Raw and downgraded output use `outputs.dirs(outputMap.values())` explicitly declares the directory for clean builds. Raw and downgraded output use
separate directories and normal task dependencies. No stub sources or replacement Scala compiler are needed. separate directories and normal task dependencies. No stub sources or replacement Scala compiler are needed.
@@ -67,11 +72,12 @@ individual review. The normal production configuration remains unchanged.
Recommended order: Recommended order:
1. Start with package-private helpers called directly by retained Scala. `JavaTraitRegistration.java` is the first 1. Start with package-private helpers called directly by retained Scala. `JavaTraitRegistration.java` and
completed follow-up: only `ASMMixinCompiler.scala` calls it, while pattern variables remove repeated checked casts. `ClassInfoLookup.java` are completed follow-ups; pattern variables remove their checked casts without changing the
`StackAnalyserLogic.java` remains the original proven example. Scala-facing declarations. `StackAnalyserLogic.java` remains the original proven example.
2. Continue with internal ASM helpers that have real cast/control-flow gains, especially `ClassInfoLookup.java` and 2. Continue only where modern syntax produces a concrete control-flow gain. `ScalaSignatureParser.java` is the next
`ScalaTraitRegistration.java`, one behavior-preserving batch at a time with generated-output comparison. useful candidate because its two result-producing switches can become exhaustive switch expressions.
`ScalaTraitRegistration.java` should not move merely to restyle its erased `Some` checks.
3. Consider public core implementations such as `RedstoneInteractions$.java`, `TileMultipart.java` and the registries 3. Consider public core implementations such as `RedstoneInteractions$.java`, `TileMultipart.java` and the registries
only after the internal batches. Modern method bodies are technically possible, but their published ABI and frozen only after the internal batches. Modern method bodies are technically possible, but their published ABI and frozen
behavior make the review cost higher. behavior make the review cost higher.
@@ -95,6 +101,11 @@ references, and all 134 generated ASM dump names and hashes match the pre-change
joint output and present only in the raw/downgraded modern directories. Its own class bytes changed as expected under joint output and present only in the raw/downgraded modern directories. Its own class bytes changed as expected under
modern javac/JVM Downgrader, but no source signature or consumer-facing class is changed. modern javac/JVM Downgrader, but no source signature or consumer-facing class is changed.
The completed `ClassInfoLookup` batch has the same clean-build, 576-test, Java 8 Forge, 450-class/version-52 and
134-dump results. Its source signatures and package-private visibility are unchanged. JVM Downgrader records nest
metadata as annotations for this helper's anonymous callbacks, but the packaged classes contain no executable JVM
Downgrader API reference and the Java 8 runtime needs no added dependency.
### fastutil audit ### fastutil audit
GTNHLib 0.11.44 currently contributes `it.unimi.dsi:fastutil:8.5.18` to `compileClasspath`. It does **not** contribute GTNHLib 0.11.44 currently contributes `it.unimi.dsi:fastutil:8.5.18` to `compileClasspath`. It does **not** contribute
@@ -154,8 +165,8 @@ scoped path selectively; if parsing, compilation order, ABI or downgrade support
working syntax and record the blocker and revisit condition. Do not add fragile workarounds solely for syntax. working syntax and record the blocker and revisit condition. Do not add fragile workarounds solely for syntax.
The production source tree now contains 231 Java files and nine Scala files / 782 nonblank Scala lines. Of the 224 Java The production source tree now contains 231 Java files and nine Scala files / 782 nonblank Scala lines. Of the 224 Java
sources in the Scala source tree, only `StackAnalyserLogic` and `JavaTraitRegistration` bypass joint compilation. sources in the Scala source tree, only `StackAnalyserLogic`, `JavaTraitRegistration` and `ClassInfoLookup` bypass joint
Retained models, trait compilation. Retained models, trait
metadata, synthetic super accessors, and downstream Scala consumers prevent treating the last nine files as a metadata, synthetic super accessors, and downstream Scala consumers prevent treating the last nine files as a
mechanical deletion queue. Modern GTNH runtime support does not remove the retained Scala compiler's Java 8 mechanical deletion queue. Modern GTNH runtime support does not remove the retained Scala compiler's Java 8
requirement. The main migration plan and working handoff carry the current API/adoption priorities and source counts. requirement. The main migration plan and working handoff carry the current API/adoption priorities and source counts.
+3 -1
View File
@@ -8,12 +8,13 @@ tasks.test {
useJUnitPlatform() useJUnitPlatform()
} }
// Scope modern syntax to this helper; retained Scala and joint Java stay on Java 8. // Scope modern syntax to these helpers; retained Scala and joint Java stay on Java 8.
apply plugin: xyz.wagyourtail.jvmdg.gradle.JVMDowngraderPlugin apply plugin: xyz.wagyourtail.jvmdg.gradle.JVMDowngraderPlugin
def modernJavaSources = sourceSets.main.scala.matching { def modernJavaSources = sourceSets.main.scala.matching {
include 'codechicken/multipart/asm/StackAnalyserLogic.java' include 'codechicken/multipart/asm/StackAnalyserLogic.java'
include 'codechicken/multipart/asm/JavaTraitRegistration.java' include 'codechicken/multipart/asm/JavaTraitRegistration.java'
include 'codechicken/multipart/asm/ClassInfoLookup.java'
} }
def legacyScala = tasks.named('compileScala') { def legacyScala = tasks.named('compileScala') {
// Zinc does not invalidate joint-compiled Java annotations when Tags.VERSION changes. // Zinc does not invalidate joint-compiled Java annotations when Tags.VERSION changes.
@@ -21,6 +22,7 @@ def legacyScala = tasks.named('compileScala') {
// Scalac reads the Java declaration without asking Java 8 javac to compile its body. // Scalac reads the Java declaration without asking Java 8 javac to compile its body.
exclude 'codechicken/multipart/asm/StackAnalyserLogic.java' exclude 'codechicken/multipart/asm/StackAnalyserLogic.java'
exclude 'codechicken/multipart/asm/JavaTraitRegistration.java' exclude 'codechicken/multipart/asm/JavaTraitRegistration.java'
exclude 'codechicken/multipart/asm/ClassInfoLookup.java'
scalaCompileOptions.additionalParameters = ['-sourcepath', file('src/main/scala').absolutePath] scalaCompileOptions.additionalParameters = ['-sourcepath', file('src/main/scala').absolutePath]
inputs.files(modernJavaSources).withPropertyName('modernJavaDeclarations').withPathSensitivity(PathSensitivity.RELATIVE) inputs.files(modernJavaSources).withPropertyName('modernJavaDeclarations').withPathSensitivity(PathSensitivity.RELATIVE)
} }
@@ -191,7 +191,7 @@ final class ClassInfoLookup {
// Preserve the compiler's argument-count indexing, including its behavior for wide stack values. // Preserve the compiler's argument-count indexing, including its behavior for wide stack values.
StackEntry receiver = stack.peek(Type.getType(call.desc).getArgumentTypes().length); StackEntry receiver = stack.peek(Type.getType(call.desc).getArgumentTypes().length);
if (!(receiver instanceof Load) || !(((Load) receiver).e() instanceof This)) return Option.empty(); if (!(receiver instanceof Load load) || !(load.e() instanceof This)) return Option.empty();
return ASMMixinCompiler$.MODULE$.getClassInfo(stack.owner().getInternalName()).superClass() return ASMMixinCompiler$.MODULE$.getClassInfo(stack.owner().getInternalName()).superClass()
.flatMap(new AbstractFunction1<ClassInfo, Option<MethodInfo>>() { .flatMap(new AbstractFunction1<ClassInfo, Option<MethodInfo>>() {