diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 94c014b..29cf337 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -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. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index d23a8d7..1b6ddcd 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -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'"' '/ - 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") diff --git a/src/main/scala/codechicken/multipart/asm/ClassBytes.java b/src/main/scala/codechicken/multipart/asm/ClassBytes.java index 4795487..f49488d 100644 --- a/src/main/scala/codechicken/multipart/asm/ClassBytes.java +++ b/src/main/scala/codechicken/multipart/asm/ClassBytes.java @@ -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('/', '.');