diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index f146e7f..0b0f311 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -1263,3 +1263,15 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec helpers have Java source markers and Java 8 class versions; compiler/factory public descriptors and the full 464-class packaged inventory match the reference. `MultipartGenerator$` disassembly is unchanged. The next bounded target is extracting `DebugPrinter` from `ASMMixinCompiler.scala`, leaving the compiler algorithms for later. +- Extracted `DebugPrinter` into a Java facade and companion, retaining all five methods on each and the companion + singleton field. Configuration/default gating, immediate-child cleanup, dump paths/content and the 16,000-byte + logging threshold are unchanged. Only three compiler call sites explicitly name `DebugPrinter$.MODULE$`. +- Per the current user instruction, no tests were added. A clean formatting/checkstyle/build passes all 276 existing + plain-JVM tests; the Java 8 Forge suite passes all 116 tests with dumping both enabled and disabled. Against the + saved `1faf0dd` baseline, all 39 generated dump filenames and SHA-256 hashes and all six ordered byte-count messages + match. The disabled run leaves the existing dump contents and modification times untouched and retains those log + messages. Restored the original local `debug_asm=true` setting afterward. +- Both converted types have Java source markers and Java 8 class versions, and all callable public names/descriptors + match. Removing the private cleanup closure shifts the compiler's private closure numbering; all 64 compiler types' + disassembly matches after that renaming alone. The packaged inventory drops from 464 to 463 classes. No new + divergence needs a ledger entry. `ByteCodeReader` in `multipart/asm/ScalaSignature.scala` is the next isolated target. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 492be12..d44d429 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`. 158 commits including the API-cleanup plan, divergence-log cleanup and separate -characterization and port commits through the ASM implicit helpers. +Branch: `algent/java`. Base: `master`. 159 commits including the API-cleanup plan, divergence-log cleanup and ports +through `DebugPrinter`. ## The one rule that matters @@ -24,6 +24,10 @@ must link; the source-level audit is the authority on behavior, serialized data, Followed for every port so far. It has caught three real ABI breaks that inspection missed. +**Current user instruction: do not add tests unless requested.** The characterization-first workflow below describes +the prior approach, not permission to add tests. Without that request, save a pre-port reference jar and use the +existing suites plus ABI/output comparisons, as for `DebugPrinter`. + 1. **Characterize first, commit separately.** Write tests against the untouched Scala and confirm they pass. Commit as `test: characterize X` before touching the implementation. 2. **Freeze a binary consumer** if the inventory shows a load-bearing `$class` or singleton. Recipe below. @@ -274,7 +278,7 @@ across the port. It is also where the two shim constraints in the gotchas list w `rayTraceAll`'s index production is now characterized, closing the gap the read-path cleanup left: the index written into `ExtendedMOP.data` is what `reduceMOP` hands back to every click, activate, harvest and pick block. -197 Java files, 11 Scala files, 2,352 Scala lines left (non-blank; that is the metric this figure has always used). +199 Java files, 11 Scala files, 2,316 Scala lines left (non-blank; that is the metric this figure has always used). ## What is left, and in what order @@ -558,10 +562,17 @@ the packaged class inventory and the multipart generator companion's disassembly explicit helper calls; normal calls retain the same results. The ledger records Java's public-companion constructor publication difference as well. -**Next: `DebugPrinter` in `multipart/asm/ASMMixinCompiler.scala`.** Extract the diagnostic singleton without changing -the compiler itself. Characterize configuration gating, initial directory cleanup, dump naming/content and the -16,000-byte logging threshold first. Isolate file-writing checks in temporary directories so they cannot purge real -debug output. Keep the facade/companion boundary and make only required source-call adjustments in the compiler. +`DebugPrinter` is now a Java facade and companion. Both public surfaces match the pre-port jar. Configuration gating, +non-recursive startup cleanup, slash-to-hash dump naming and the 16,000-byte logging threshold are retained. All 39 +Forge-suite dump names and contents plus all six ordered byte-count log messages match the reference. With dumping +disabled, the same suite leaves dump contents and timestamps untouched while still logging the byte counts; the +original local setting was restored. No tests were added. All 64 compiler types have identical disassembly after +normalizing private closure renumbering; removing the cleanup closure reduces the packaged inventory from 464 to 463. + +**Next: `ByteCodeReader` in `multipart/asm/ScalaSignature.scala`.** Extract this small reader before the signature +model or compiler. Preserve its mutable position accessors, generic `advance(int, A)` boundary, eager argument +evaluation, signed-byte/natural-number decoding, default-charset string construction and existing unchecked failures. +Keep the `ScalaSignature.Bytes` boundary and leave the signature model, codec and compiler algorithms unchanged. 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. diff --git a/src/main/scala/codechicken/multipart/asm/ASMMixinCompiler.scala b/src/main/scala/codechicken/multipart/asm/ASMMixinCompiler.scala index 039b28f..e89650e 100644 --- a/src/main/scala/codechicken/multipart/asm/ASMMixinCompiler.scala +++ b/src/main/scala/codechicken/multipart/asm/ASMMixinCompiler.scala @@ -10,57 +10,14 @@ import org.objectweb.asm.Type import org.objectweb.asm.MethodVisitor import Type._ import codechicken.lib.asm.ASMHelper._ -import codechicken.lib.asm.{ - InsnListSection, - InsnComparator, - ASMHelper, - ObfMapping -} -import java.io.File +import codechicken.lib.asm.{InsnListSection, InsnComparator, ObfMapping} import java.lang.reflect.Method import java.lang.reflect.Modifier import net.minecraft.launchwrapper.LaunchClassLoader -import codechicken.multipart.handler.MultipartProxy import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper -import org.apache.logging.log4j.LogManager import ASMImplicits._ import cpw.mods.fml.relauncher.FMLLaunchHandler -object DebugPrinter { - val debug = MultipartProxy.config - .getTag("debug_asm") - .getBooleanValue(!ObfMapping.obfuscated) - val logger = LogManager.getLogger("Multipart ASM") - - private var permGenUsed = 0 - val dir = new File("asm/multipart") - if (debug) { - if (!dir.exists) - dir.mkdirs() - for (file <- dir.listFiles) - file.delete - } - - def dump(name: String, bytes: Array[Byte]) { - if (debug) - ASMHelper.dump( - bytes, - new File(dir, name.replace('/', '#') + ".txt"), - false, - false - ) - } - - def defined(name: String, bytes: Array[Byte]) { - if ((permGenUsed + bytes.length) / 16000 != permGenUsed / 16000) - logger.debug( - (permGenUsed + bytes.length) + " bytes of permGen has been used by ASMMixinCompiler" - ) - - permGenUsed += bytes.length - } -} - object ASMMixinCompiler { val cl = getClass.getClassLoader.asInstanceOf[LaunchClassLoader] val m_defineClass = classOf[ClassLoader].getDeclaredMethod( @@ -86,7 +43,7 @@ object ASMMixinCompiler { def define(name: String, bytes: Array[Byte]) = { internalDefine(name, bytes) - DebugPrinter.defined(name, bytes) + DebugPrinter$.MODULE$.defined(name, bytes) try { m_defineClass @@ -131,7 +88,7 @@ object ASMMixinCompiler { val name = nodeName(name$) traitByteMap.put(name, bytes) remClassInfo(name) - DebugPrinter.dump(name, bytes) + DebugPrinter$.MODULE$.dump(name, bytes) } def classNode(name$ : String) = { @@ -492,11 +449,13 @@ object ASMMixinCompiler { val c = define(name, createBytes(cnode, 0)) - DebugPrinter.logger.debug( - "Generation [" + superClass + " with " + traits.mkString( - ", " - ) + "] took " + (System.currentTimeMillis - startTime) + "ms" - ) + DebugPrinter$.MODULE$ + .logger() + .debug( + "Generation [" + superClass + " with " + traits.mkString( + ", " + ) + "] took " + (System.currentTimeMillis - startTime) + "ms" + ) c } diff --git a/src/main/scala/codechicken/multipart/asm/DebugPrinter$.java b/src/main/scala/codechicken/multipart/asm/DebugPrinter$.java new file mode 100644 index 0000000..7577f0c --- /dev/null +++ b/src/main/scala/codechicken/multipart/asm/DebugPrinter$.java @@ -0,0 +1,55 @@ +package codechicken.multipart.asm; + +import java.io.File; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import codechicken.lib.asm.ASMHelper; +import codechicken.lib.asm.ObfMapping; +import codechicken.multipart.handler.MultipartProxy; + +public final class DebugPrinter$ { + + public static final DebugPrinter$ MODULE$ = new DebugPrinter$(); + + private final boolean debug; + private final Logger logger; + private int permGenUsed; + private final File dir; + + private DebugPrinter$() { + debug = MultipartProxy.config().getTag("debug_asm").getBooleanValue(!ObfMapping.obfuscated); + logger = LogManager.getLogger("Multipart ASM"); + dir = new File("asm/multipart"); + if (debug) { + if (!dir.exists()) dir.mkdirs(); + for (File file : dir.listFiles()) { + file.delete(); + } + } + } + + public boolean debug() { + return debug; + } + + public Logger logger() { + return logger; + } + + public File dir() { + return dir; + } + + public void dump(String name, byte[] bytes) { + if (debug) ASMHelper.dump(bytes, new File(dir, name.replace('/', '#') + ".txt"), false, false); + } + + public void defined(String name, byte[] bytes) { + if ((permGenUsed + bytes.length) / 16000 != permGenUsed / 16000) { + logger.debug((permGenUsed + bytes.length) + " bytes of permGen has been used by ASMMixinCompiler"); + } + permGenUsed += bytes.length; + } +} diff --git a/src/main/scala/codechicken/multipart/asm/DebugPrinter.java b/src/main/scala/codechicken/multipart/asm/DebugPrinter.java new file mode 100644 index 0000000..b8431b9 --- /dev/null +++ b/src/main/scala/codechicken/multipart/asm/DebugPrinter.java @@ -0,0 +1,30 @@ +package codechicken.multipart.asm; + +import java.io.File; + +import org.apache.logging.log4j.Logger; + +public final class DebugPrinter { + + private DebugPrinter() {} + + public static boolean debug() { + return DebugPrinter$.MODULE$.debug(); + } + + public static Logger logger() { + return DebugPrinter$.MODULE$.logger(); + } + + public static File dir() { + return DebugPrinter$.MODULE$.dir(); + } + + public static void dump(String name, byte[] bytes) { + DebugPrinter$.MODULE$.dump(name, bytes); + } + + public static void defined(String name, byte[] bytes) { + DebugPrinter$.MODULE$.defined(name, bytes); + } +}