refactor: port StackAnalyser initialization to Java

This commit is contained in:
Algent committed 2026-09-04 15:48:02 +02:00
1 parent 929a704d13
commit 1ed698e975
5 files changed
+70 -29

No files matched your search

+18 -17
View File
@@ -1,6 +1,6 @@
# Java migration — working handoff
Start here. Work in `C:\Users\Algent\IdeaProjects\ForgeMultipart` on **`algent/java`**, based on `master`; inspect
Start here. Work in this migration checkout on **`algent/java`**, based on `master`; inspect
branch, status and recent commits before editing and preserve existing work. The detached review worktree is not the
migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes reached `algent/java`.
@@ -16,32 +16,33 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes
## Current state and next target
**398 plain-JVM tests and 237 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **224 Java
files and 9 Scala files / 782 nonblank Scala lines**. The packaged inventory has 445 classes.
**407 plain-JVM tests and 237 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **224 Java
files and 9 Scala files / 779 nonblank Scala lines**. The packaged inventory has 444 classes.
Review follow-up: restored packet-scheduler callback mutation behavior with the original Scala hash-map traversal,
virtual tile accessor dispatch throughout `TMultiPart`, and null-safe equality for scheduled-tick deduplication.
Six JVM and two Forge regression cases cover the fixes. Callable signatures remain unchanged; the packet traversal
callback adds one anonymous class. See the latest history entries for the individual fixes and validation.
Latest bounded target: `TMicroOcclusionClient` delegates bounds copying and mask updates to
`TMicroOcclusionClientLogic.java`. Scala retains inheritance metadata, mutable state/accessors and the three
lifecycle super/recalc bridges. Characterization was committed first as `d69d12b`: frozen Scala forwarders pin
super/recalc order, argument identity, virtual copying, mask replacement and partial publication on failure.
Forge exercises live Stone/Glass neighbors through the hollow client probe and real factories. Clean checks
preserve all 443 original class/member APIs, all 17 ScalaSignature payloads, 3,725 unrelated method bodies and
all 116 generated dumps. Only the Java helper is added. Evidence: `run/migration-micro-occlusion-client-reference/`.
Latest bounded target: `StackAnalyser` delegates constructor control flow to `StackAnalyserLogic.initialize`.
Nine characterization tests were committed first as `929a704`. They pin constructor argument use, virtual
`pushL`/`setL` ordering, descriptor mutation/parsing failures, wide slots, partial publication and handler behavior.
Scala retains the class/companion/models, field initialization, default-argument bridges and a handler callback
that preserves its mangled virtual map accessor. Handler traversal retains Scala-backed buffers' `foreach` dispatch.
All 407 frozen JVM consumers pass; checks preserve 443 retained class/member APIs, all 17 ScalaSignature payloads,
3,727 unrelated method bodies and all 116 generated dumps. The obsolete parameter-loop closure disappears;
the handler callback changes only its compiler number. Evidence: `run/migration-stack-initialization-reference/`.
**Next: extract `StackAnalyser` constructor initialization to its existing Java helper.** Characterize receiver
and parameter slot setup, virtual `pushL` ordering, malformed descriptors and duplicate exception-handler
precedence before editing. Keep the Scala class/companion/models, field initialization and default-argument
bridges; this is an initialization extraction, not a full shell replacement or opcode algorithm fix.
**Next bounded candidate: `StackAnalyser.Const.getType`.** Characterize boxed constant classification, null/String
handling, unsupported-value formatting/failure and virtual `c` access before extracting to the existing helper.
Keep case-class/product/serialization shapes and simple model accessors. Broader shell replacement and opcode
algorithm fixes remain separate work.
The external ProjectRed Scala-trait fixture and ScalaSignature model bridges remain required. Actual client
generation, GPU output and full-pack checks remain manual.
The JVM Downgrader checkpoint now supports Java 21 method-body syntax in `StackAnalyserLogic` while retaining
Scala 2.11.5 on Java 8. Its integrated normal/clean builds preserve all retained Scala binaries and all 116 dumps;
398 JVM tests, the same 398 frozen JVM consumer tests, and 237 Forge tests pass. See `JVM_DOWNGRADER_HANDOFF.md`.
Scala 2.11.5 on Java 8. The constructor extraction uses that existing build stage; it adds no build configuration
or runtime dependencies. See `JVM_DOWNGRADER_HANDOFF.md` for the original 398-test integration checkpoint.
Finish the remaining useful behavior extractions and define the retained compilation boundary before a broad
modern-syntax pass. Removing every remaining Scala declaration still requires the documented consumer/ABI work.
@@ -51,7 +52,7 @@ Remaining Scala units:
| --- | --- |
| `multipart/asm/ASMMixinCompiler.scala` | Retained nested models, construction callbacks and Scala entry-point shell |
| `multipart/asm/ScalaSignature.scala` | Named models, primitive/erased bridges and five generic inner-construction branches |
| `multipart/asm/StackAnalyser.scala` | Class/companion/models over Java `StackAnalyserLogic`; initialization and model queries remain Scala |
| `multipart/asm/StackAnalyser.scala` | Class/companion/models over Java `StackAnalyserLogic`; state, handler callback, bridges and model queries remain Scala |
| `microblock/MicroblockTraits.scala`, `FaceMicroblockTraits.scala`, `CornerMicroblockTraits.scala`, `EdgeMicroblockTraits.scala` | Nine retained state/inheritance/bridge shells over Java implementation, including post lifecycle/super dispatch |
| `microblock/HollowMicroblockTraits.scala` | Hollow server/client inheritance, initializer and super shells over Java behavior |
| `microblock/TMicroOcclusion.scala` | Occlusion/client inheritance, state/accessor and lifecycle/super shells over Java behavior |
+4
View File
@@ -7,6 +7,10 @@ are preserved. `build.gradle` adds two tasks; `StackAnalyserLogic.visitInsn` use
The nine Scala sources, Scala 2.11.5 dependency, source layout, and normal Gradle entry points remain in place.
Production tasks do not read a frozen jar or any files under `run/jvmdg-trial/`.
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
reference comparisons. The current extraction's evidence is in `run/migration-stack-initialization-reference/`.
## Build arrangement
1. Normal Java and joint Scala/Java compilation remain on Java 8. `compileScala` excludes the helper from javac's
+28
View File
@@ -1311,3 +1311,31 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m
pass. Evidence and reproduction commands are in `JVM_DOWNGRADER_HANDOFF.md` and ignored `run/jvmdg-trial/`.
- Prefer completing useful remaining Scala behavior extractions before broad Java syntax changes. Most remaining
Scala declarations preserve model/trait binary contracts; zero Scala is a separate compatibility decision.
### 2026-09-04 — StackAnalyser constructor initialization
- Committed nine JVM characterization cases first as `929a704`, against the untouched Scala constructor.
They cover direct constructor arguments despite overridden getters, virtual receiver/parameter pushes and
`setL` slot order, descriptor mutation and malformed descriptors, wide aliases and formal parameter indices,
receiver/parameter callback failures, delayed handler publication, duplicate/null keys, node identity, partial
maps on failure, repeated virtual map reads and Scala-backed handler buffers' `foreach` dispatch.
- Moved initialization control flow to the existing `StackAnalyserLogic.initialize` Java helper. Scala retains
field initialization and one handler callback: accessing its private map from that closure preserves the
mangled field/accessor and virtual reads before each handler key. Java retains `asScalaBuffer(...).foreach`
so wrapping a Scala buffer as a Java list does not bypass its overrides. Constructor arguments are passed
directly; callback changes to the descriptor and handler list remain visible at the original points.
- Normal and clean formatting/checkstyle/build/Forge checks pass with 407 JVM tests, the same 407 frozen JVM
consumers, and 237 Java 8 Forge tests, with zero failures/errors/skips. The frozen baseline jar, sources,
compiled tests, reports, comparison tools and 116 matching ASM dumps are saved under ignored
`run/migration-stack-initialization-reference/`. The version override matches the frozen test commit because
two existing consumers inline that version; the normal final build still uses the actual Git version.
- Preserved all 443 retained class/member APIs, all 17 ScalaSignature payloads and 3,727 unrelated method bodies.
The parameter-loop closure disappears and the handler closure is identical after compiler renumbering. Forty
retained model/companion classes differ only in debug metadata after import removal. The helper adds two
references to existing nested models in its `InnerClasses` table. These are covered compiler artifacts, with
no new effective divergence. Dev/release jars contain 444 Java 8 classes; packaged sources match both edited
sources and the helper introduces no JVM Downgrader runtime-stub reference.
- Reused the scoped modern Java build without configuration changes. Sources remain 224 Java files and nine
Scala files / 779 nonblank lines. Next bounded candidate: `StackAnalyser.Const.getType`, preserving its
case-class, product and serialization contracts. The simple model getters and full Scala shell replacement
remain separate from useful behavior extraction.
@@ -2,10 +2,8 @@ package codechicken.multipart.asm
import scala.collection.mutable.{Map => MMap, ListBuffer => MList}
import org.objectweb.asm.tree._
import org.objectweb.asm.Opcodes._
import org.objectweb.asm.Type
import org.objectweb.asm.Type._
import scala.collection.JavaConversions._
object StackAnalyser {
def width(t: Type): Int = t.getSize
@@ -119,16 +117,13 @@ class StackAnalyser(val owner: Type, val m: MethodNode) {
val locals = MList[LocalEntry]()
private val catchHandlers = MMap[LabelNode, TryCatchBlockNode]()
{
if ((m.access & ACC_STATIC) == 0)
pushL(This(owner))
val ptypes = getArgumentTypes(m.desc)
for (i <- 0 until ptypes.length)
pushL(Param(i, ptypes(i)))
m.tryCatchBlocks.foreach(b => catchHandlers.put(b.handler, b))
}
// The callback preserves Scala's mangled catchHandlers accessor.
StackAnalyserLogic.initialize(
this,
owner,
m,
b => catchHandlers.put(b.handler, b)
)
def pushL(entry: LocalEntry) = setL(locals.size, entry)
@@ -14,6 +14,7 @@ import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.LookupSwitchInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
@@ -33,22 +34,34 @@ import codechicken.multipart.asm.StackAnalyser.LocalEntry;
import codechicken.multipart.asm.StackAnalyser.New;
import codechicken.multipart.asm.StackAnalyser.NewArray;
import codechicken.multipart.asm.StackAnalyser.NewMultiArray;
import codechicken.multipart.asm.StackAnalyser.Param;
import codechicken.multipart.asm.StackAnalyser.PrimitiveCast;
import codechicken.multipart.asm.StackAnalyser.ReturnAddress;
import codechicken.multipart.asm.StackAnalyser.StackEntry;
import codechicken.multipart.asm.StackAnalyser.Store;
import codechicken.multipart.asm.StackAnalyser.This;
import codechicken.multipart.asm.StackAnalyser.UnaryOp;
import scala.Function1;
import scala.MatchError;
import scala.None$;
import scala.Option;
import scala.Predef;
import scala.Some;
import scala.collection.JavaConversions;
/** Analyser control flow behind the retained Scala model and default-argument API. */
final class StackAnalyserLogic {
private StackAnalyserLogic() {}
static void initialize(StackAnalyser a, Type owner, MethodNode method,
Function1<TryCatchBlockNode, Option<TryCatchBlockNode>> addHandler) {
if ((method.access & ACC_STATIC) == 0) a.pushL(new This(owner));
Type[] parameters = getArgumentTypes(method.desc);
for (int i = 0; i < parameters.length; i++) a.pushL(new Param(i, parameters[i]));
JavaConversions.asScalaBuffer(method.tryCatchBlocks).foreach(addHandler);
}
static void setL(StackAnalyser a, int i, LocalEntry entry) {
while (i + entry.getType().getSize() > a.locals().size()) a.locals().$plus$eq(null);
a.locals().update(i, entry);