refactor: port class definition to Java

This commit is contained in:
Algent committed 2026-09-03 18:45:47 +02:00
1 parent 4d59900be6
commit cf8b2f9c83
4 files changed
+53 -23

No files matched your search

+17
View File
@@ -1599,3 +1599,20 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
both packaged jar versions. External Scala-trait tests remain green; existing manual client checks and Java-source
model/trait limitations remain. Next: `ASMMixinCompiler.define`, characterized first for publication/debug
accounting, reflective definition and failure ordering, without algorithm changes.
- Added ten Forge characterization tests for `ASMMixinCompiler.define`, passing on untouched Scala and committed
first as `4d59900`. They execute real JVM definitions in isolated LaunchClassLoaders and restore compiler caches,
loader/reflection state and debug state. Tests freeze bytecode-name versus cache-key handling, delayed class
initialization, exact byte publication, metadata invalidation, byte accounting and failures before/after reflection.
Real duplicate definitions remain `InvocationTargetException` wrapping `LinkageError`; direct linkage errors from
reflective class initialization exercise the original case-sensitive duplicate guard, including its null-message
`NullPointerException`. Dump/accounting failures remain outside that guard. These quirks are preserved, not fixed.
- Moved only `define` into the existing Java `ClassBytes`, retaining its exact Scala entry point and the loader's
startup initialization. Class composition, trait rewriting and external Scala-trait/model bridges are unchanged.
Reference source/jar, reports, 42 dumps and verification scripts are in ignored `run/migration-define-reference/`.
The 456-class inventory is unchanged; all 426 non-closure APIs (including 16 named compiler APIs), 3,628 other method
bodies and 30 compiler closures match. All 42 generated dump names/hashes match exactly. No new divergence is needed.
- Formatting/checkstyle/build and Forge pass, including clean verification after stopping Gradle: 333 JVM / 183 Forge,
zero failures/errors/skips. The characterization tests, dev config and forced Scala-compilation guard are unchanged;
all five `@Mod` versions match both packaged jar versions. Sources total 211 Java files and 9 Scala files / 1,583
nonblank Scala lines. Next: `ASMMixinCompiler.mixinClasses`, characterized for composition/constructor/dispatch and
generated output before extraction; keep compiler algorithm fixes separate.
+17 -7
View File
@@ -12,8 +12,8 @@ what breaks, and what is left. The other documents hold the reasoning.
| `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client |
| `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command |
Branch: `algent/java`. Base: `master`. 189 commits including the API-cleanup plan, divergence-log cleanup, ports
through class-byte loading/cache helpers, the ASM characterization backfill, and review/client-rendering fixes.
Branch: `algent/java`. Base: `master`. 191 commits including the API-cleanup plan, divergence-log cleanup, ports
through reflective class definition, the ASM characterization backfill, and review/client-rendering fixes.
The multipart review corrections (`5af333c`) are on `algent/java`; subsequent migration work continues in that branch.
@@ -76,7 +76,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
```
Current baseline: **333 plain-JVM tests and 173 Java 8 Forge dedicated-server tests passing.** The ignored local server
Current baseline: **333 plain-JVM tests and 183 Java 8 Forge dedicated-server tests passing.** The ignored local server
EULA is accepted in this checkout. GitHub Actions runs the same self-validating Forge suite in a dependent job after
the shared GTNH build; keep both jobs required.
@@ -852,10 +852,20 @@ zero failures/errors/skips. Clean APIs and dumps repeat the matches above; the d
guard are unchanged. All five `@Mod` versions match both packaged jar versions. Manual client checks and the
previously documented Java-source model/trait limitations remain outstanding.
**Next: `ASMMixinCompiler.define` reflective class definition.** Characterize publication, debug accounting and
definition/error ordering first, including duplicate definitions and reflection wrapping. Preserve its current
algorithm and leave startup initialization, Java-trait rewriting and composition separate. Retain external
Scala-trait support and the model bridges.
`ASMMixinCompiler.define` now delegates to the existing Java `ClassBytes`. Ten Forge characterization tests passed
against untouched Scala first (`4d59900`) and remain unchanged. Real JVM definitions pin delayed initialization,
bytecode names versus cache keys, publication/invalidation/accounting order, dump failures and reflective errors.
Ordinary duplicates remain reflection-wrapped; the case-sensitive direct-LinkageError guard and its null-message
failure remain unchanged. Clean formatting/checkstyle/build and Forge pass at 333 JVM / 183 Forge, zero failures or
skips. All 456 classes remain; 426 non-closure APIs, 3,628 other method bodies, 30 compiler closures and all 42 dump
names/hashes match. Reference evidence is in ignored `run/migration-define-reference/`. The version guard and dev
config are unchanged; all five `@Mod` annotations match both jars. Sources: 211 Java / 9 Scala / 1,583 nonblank Scala
lines. There is no new divergence.
**Next: `ASMMixinCompiler.mixinClasses` composite generation.** Characterize constructor selection, trait
linearization, field initialization, method/super dispatch, failure ordering and emitted class shapes before
extraction. Preserve the compiler algorithm; keep Java-trait rewriting and startup initialization separate. Retain
external Scala-trait support and the model bridges.
The remaining generated microblock traits still need the Phase 7 abstract-Java-mixin and side-only-member support
before their Java mixin inputs are safe; do not bypass those prerequisites by flattening their inheritance.
@@ -37,22 +37,7 @@ object ASMMixinCompiler {
private val traitByteMap = MMap[String, Array[Byte]]()
private val mixinMap = MMap[String, MixinInfo]()
def define(name: String, bytes: Array[Byte]) = {
internalDefine(name, bytes)
DebugPrinter$.MODULE$.defined(name, bytes)
try {
m_defineClass
.invoke(cl, bytes, 0: Integer, bytes.length: Integer)
.asInstanceOf[Class[_]]
} catch {
case link: LinkageError if link.getMessage.contains("duplicate") =>
throw new IllegalStateException(
"class with name: " + name + " already loaded. Do not reference your java mixin classes before registering",
link
)
}
}
def define(name: String, bytes: Array[Byte]) = ClassBytes.define(name, bytes)
getBytes("cpw/mods/fml/common/asm/FMLSanityChecker")
@@ -20,6 +20,24 @@ final class ClassBytes {
private ClassBytes() {}
static Class<?> define(String name, byte[] bytes) throws IllegalAccessException, InvocationTargetException {
ASMMixinCompiler$ compiler = ASMMixinCompiler$.MODULE$;
compiler.internalDefine(name, bytes);
DebugPrinter$.MODULE$.defined(name, bytes);
try {
return (Class<?>) compiler.m_defineClass().invoke(compiler.cl(), bytes, 0, bytes.length);
} catch (LinkageError link) {
// Reflective failures normally remain wrapped; retain the original direct-error guard.
if (link.getMessage().contains("duplicate")) {
throw new IllegalStateException(
"class with name: " + name
+ " already loaded. Do not reference your java mixin classes before registering",
link);
}
throw link;
}
}
static byte[] getBytes(String name) throws IOException, IllegalAccessException, InvocationTargetException {
ASMMixinCompiler$ compiler = ASMMixinCompiler$.MODULE$;
final String javaName = name.replace('/', '.');