mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-22 21:19:49 +00:00
refactor: port ASM bridge helpers to Java
This commit is contained in:
1 parent
5d611e0d47
commit
a27bf92a3d
4 files changed
+120
-41
No files matched your search
@@ -1437,3 +1437,25 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
files and 9 Scala files / 1,714 nonblank Scala lines. Next is the bounded descriptor/bridge-emission helper unit in
|
||||
`ASMMixinCompiler.scala`: `seperateDesc`, `staticDesc`, `finishBridgeCall`, `writeBridge` and `writeStaticBridge`, with
|
||||
fresh characterization and no composition/trait-rewriting algorithm changes.
|
||||
- Added eight Forge behavior tests for the descriptor/bridge helpers and committed them separately as `5d611e0`.
|
||||
All pass against untouched Scala: descriptor splitting and receiver insertion, every argument/return category,
|
||||
local-slot widths, invocation flags, instruction order, maxima, partial visitor failures, overridable metadata
|
||||
getter order and descriptor rereads. Generated executable bridges verify virtual, special, interface and
|
||||
Scala-style static-helper dispatch with mixed wide/reference arguments. The original compiler singleton requires
|
||||
a Forge `LaunchClassLoader`; these tests therefore use the existing Forge harness. Baseline: 326 JVM / 135 Forge.
|
||||
- Extracted only `seperateDesc`, `staticDesc`, `finishBridgeCall`, `writeBridge` and `writeStaticBridge` into Java
|
||||
`ASMBridgeEmitter`, retaining their Scala entry points and exact ABI. No composition, trait-rewriting, stack or
|
||||
signature-decoding algorithm changed. Existing descriptor-validation gaps, malformed-input exception types,
|
||||
unnormalized owner strings, independent bridge/callee descriptors and callback order are preserved.
|
||||
- Saved the pre-port jar/source, reports and 40 generated dumps under ignored `run/migration-bridge-reference/`.
|
||||
All 16 named compiler APIs match by names/descriptors/modifiers/generic signatures and private fields; 14 named
|
||||
classfiles are byte-identical. All 214 other named compiler methods, 35 algorithm closures and 143 ASM/generator
|
||||
disassemblies outside the compiler match. All 40 dump names/hashes match and the dev configuration is unchanged.
|
||||
One private bridge closure is replaced by the Java helper, keeping 450 packaged classes. No new ledger entry is
|
||||
needed. Sources total 209 Java files and 9 Scala files / 1,689 nonblank Scala lines. Next: `ASMMixinCompiler.getSuper`
|
||||
recognition/lookup, with fresh characterization and no algorithm fixes mixed into its port.
|
||||
- Formatting/checkstyle/build and the full Forge suite pass, including a clean build after stopping Gradle:
|
||||
326 JVM / 135 Forge, zero failures/errors/skips. The eight characterization tests are unchanged after the port,
|
||||
and the clean jar repeats the API/disassembly/dump matches above. The forced Scala-compilation version guard is
|
||||
retained; all five `@Mod` annotations match both packaged jar versions. External Scala-trait coverage remains green
|
||||
and the existing manual client checks and Java-source bridge limitations remain outstanding.
|
||||
+32
-10
@@ -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`. 176 commits including the API-cleanup plan, divergence-log cleanup, ports
|
||||
through the `ClassInfo` metadata lookup extraction, and the ASM characterization backfill and review fixes.
|
||||
Branch: `algent/java`. Base: `master`. 178 commits including the API-cleanup plan, divergence-log cleanup, ports
|
||||
through the ASM descriptor/bridge helper extraction, and the ASM characterization backfill and review fixes.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -74,7 +74,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: **326 plain-JVM tests and 127 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
Current baseline: **326 plain-JVM tests and 135 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.
|
||||
|
||||
@@ -280,7 +280,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.
|
||||
|
||||
208 Java files, 9 Scala files, 1,714 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
209 Java files, 9 Scala files, 1,689 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -682,12 +682,34 @@ dump is the new cache-invalidation fixture). Clean build and Forge pass at 326 J
|
||||
packaged class count falls from 451 to 450; no new ledger entry is needed. The forced Scala compilation guard remains,
|
||||
and all five `@Mod` annotations match both clean jar versions.
|
||||
|
||||
**Next: `multipart/asm/ASMMixinCompiler.scala`, bounded to descriptor and bridge-emission helpers:** `seperateDesc`
|
||||
(keep its existing spelling), `staticDesc`, `finishBridgeCall`, `writeBridge`, and `writeStaticBridge`. Characterize
|
||||
descriptors, argument/local widths, emitted instruction order, return opcodes and max-stack/local values first, with
|
||||
Forge where singleton initialization requires it. Keep composition/trait-rewriting algorithms, external Scala-trait
|
||||
support, retained metadata/stack models and `ScalaSignature` primitive/erased bridges unchanged. Save a fresh reference
|
||||
and compare all generated dumps before expanding scope.
|
||||
The descriptor/bridge helpers `seperateDesc` (original spelling), `staticDesc`, `finishBridgeCall`, `writeBridge` and
|
||||
`writeStaticBridge` now delegate to package-private Java `ASMBridgeEmitter`. Eight Forge characterization cases passed
|
||||
against untouched Scala and were committed separately as `5d611e0`. The original singleton requires a
|
||||
`LaunchClassLoader`, so these behavior tests belong in Forge. They freeze descriptor splitting and receiver insertion,
|
||||
all argument/return categories and slot widths, instruction order, interface flags, maxima, partial visitor output
|
||||
on failure, overridable metadata getter order and descriptor rereads. Executable generated classes verify virtual,
|
||||
special, interface and Scala-style static-helper dispatch with wide arguments and reference returns.
|
||||
|
||||
No compiler algorithm changed. Existing malformed-descriptor exceptions, unnormalized owner strings, independent
|
||||
bridge/callee descriptors and callback order remain. All 16 named compiler APIs retain their members, modifiers,
|
||||
generic signatures and private fields; 14 named classfiles are byte-identical. All 214 other named compiler methods,
|
||||
35 algorithm closures and 143 ASM/generator disassemblies outside the compiler match the reference. The one removed
|
||||
private bridge closure is replaced by the Java helper, keeping 450 packaged classes; no new divergence entry is needed.
|
||||
Sources now total 209 Java files and 9 Scala files / 1,689 nonblank Scala lines. Local reference source/jar, reports,
|
||||
40 generated dumps and comparison scripts are saved under ignored `run/migration-bridge-reference/`.
|
||||
|
||||
Formatting/checkstyle/build and Forge pass after stopping Gradle and building clean: 326 JVM / 135 Forge, zero
|
||||
failures/errors/skips. The characterization tests are unchanged after the port and all 40 generated dump names/hashes
|
||||
match. The dev config and forced Scala-compilation version guard remain unchanged; all five `@Mod` annotations match
|
||||
both packaged jar versions. External Scala-trait tests stay green. Existing manual client checks and the documented
|
||||
Java-source limitations in the retained Scala model bridges are still outstanding.
|
||||
|
||||
**Next: `multipart/asm/ASMMixinCompiler.getSuper`, bounded to super-call recognition and lookup.** Characterize the
|
||||
owner/name filters, Scala super-name pattern, stack receiver checks, argument indexing and inherited implementation
|
||||
selection before extracting it. Use Forge for compiler initialization and preserve the current algorithm, including
|
||||
any quirks exposed by tests. Keep composition/trait registration and rewriting separate, along with external Scala
|
||||
trait support, retained metadata/stack models and `ScalaSignature` primitive/erased bridges. Save a fresh reference
|
||||
and compare generated dumps before expanding scope.
|
||||
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.
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package codechicken.multipart.asm;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
import static org.objectweb.asm.Type.*;
|
||||
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.multipart.asm.ASMMixinCompiler.MixinInfo;
|
||||
import scala.Predef$;
|
||||
import scala.Tuple2;
|
||||
|
||||
/** Descriptor and instruction helpers behind the retained compiler companion. */
|
||||
final class ASMBridgeEmitter {
|
||||
|
||||
private ASMBridgeEmitter() {}
|
||||
|
||||
static Tuple2<String, String> seperateDesc(String nameDesc) {
|
||||
int split = nameDesc.indexOf('(');
|
||||
return new Tuple2<>(nameDesc.substring(0, split), nameDesc.substring(split));
|
||||
}
|
||||
|
||||
static String staticDesc(String owner, String desc) {
|
||||
Type method = getMethodType(desc);
|
||||
Type result = method.getReturnType();
|
||||
Type receiver = getType("L" + owner + ";");
|
||||
Type[] args = method.getArgumentTypes();
|
||||
Type[] staticArgs = new Type[args.length + 1];
|
||||
staticArgs[0] = receiver;
|
||||
System.arraycopy(args, 0, staticArgs, 1, args.length);
|
||||
return getMethodDescriptor(result, staticArgs);
|
||||
}
|
||||
|
||||
static void finishBridgeCall(MethodVisitor mv, String mvdesc, int opcode, String owner, String name, String desc) {
|
||||
Type[] args = getArgumentTypes(mvdesc);
|
||||
Type result = getReturnType(mvdesc);
|
||||
int localIndex = 1;
|
||||
for (Type arg : args) {
|
||||
mv.visitVarInsn(arg.getOpcode(ILOAD), localIndex);
|
||||
localIndex += StackAnalyser$.MODULE$.width(arg);
|
||||
}
|
||||
mv.visitMethodInsn(opcode, owner, name, desc, opcode == INVOKEINTERFACE);
|
||||
mv.visitInsn(result.getOpcode(IRETURN));
|
||||
mv.visitMaxs(
|
||||
Math.max(
|
||||
StackAnalyser$.MODULE$.width(Predef$.MODULE$.wrapRefArray(args)) + 1,
|
||||
StackAnalyser$.MODULE$.width(result)),
|
||||
StackAnalyser$.MODULE$.width(Predef$.MODULE$.wrapRefArray(args)) + 1);
|
||||
}
|
||||
|
||||
static void writeBridge(MethodVisitor mv, String mvdesc, int opcode, String owner, String name, String desc) {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
finishBridgeCall(mv, mvdesc, opcode, owner, name, desc);
|
||||
}
|
||||
|
||||
static void writeStaticBridge(MethodNode mv, String name, MixinInfo mixin) {
|
||||
writeBridge(mv, mv.desc, INVOKESTATIC, mixin.tname(), name, staticDesc(mixin.name(), mv.desc));
|
||||
}
|
||||
}
|
||||
@@ -236,16 +236,7 @@ object ASMMixinCompiler {
|
||||
name: String,
|
||||
desc: String
|
||||
) {
|
||||
val args = getArgumentTypes(mvdesc)
|
||||
val ret = getReturnType(mvdesc)
|
||||
var localIndex = 1
|
||||
args.foreach { arg =>
|
||||
mv.visitVarInsn(arg.getOpcode(ILOAD), localIndex)
|
||||
localIndex += width(arg)
|
||||
}
|
||||
mv.visitMethodInsn(opcode, owner, name, desc, opcode == INVOKEINTERFACE)
|
||||
mv.visitInsn(ret.getOpcode(IRETURN))
|
||||
mv.visitMaxs(Math.max(width(args) + 1, width(ret)), width(args) + 1)
|
||||
ASMBridgeEmitter.finishBridgeCall(mv, mvdesc, opcode, owner, name, desc)
|
||||
}
|
||||
|
||||
def writeBridge(
|
||||
@@ -256,19 +247,11 @@ object ASMMixinCompiler {
|
||||
name: String,
|
||||
desc: String
|
||||
) {
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
finishBridgeCall(mv, mvdesc, opcode, owner, name, desc)
|
||||
ASMBridgeEmitter.writeBridge(mv, mvdesc, opcode, owner, name, desc)
|
||||
}
|
||||
|
||||
def writeStaticBridge(mv: MethodNode, mname: String, t: MixinInfo) =
|
||||
writeBridge(
|
||||
mv,
|
||||
mv.desc,
|
||||
INVOKESTATIC,
|
||||
t.tname,
|
||||
mname,
|
||||
staticDesc(t.name, mv.desc)
|
||||
)
|
||||
ASMBridgeEmitter.writeStaticBridge(mv, mname, t)
|
||||
|
||||
def mixinClasses(
|
||||
name: String,
|
||||
@@ -444,18 +427,10 @@ object ASMMixinCompiler {
|
||||
c
|
||||
}
|
||||
|
||||
def seperateDesc(nameDesc: String) = {
|
||||
val n = nameDesc.indexOf('(')
|
||||
(nameDesc.substring(0, n), nameDesc.substring(n))
|
||||
}
|
||||
def seperateDesc(nameDesc: String) = ASMBridgeEmitter.seperateDesc(nameDesc)
|
||||
|
||||
def staticDesc(owner: String, desc: String) = {
|
||||
val descT = getMethodType(desc)
|
||||
getMethodDescriptor(
|
||||
descT.getReturnType,
|
||||
getType("L" + owner + ";") +: descT.getArgumentTypes: _*
|
||||
)
|
||||
}
|
||||
def staticDesc(owner: String, desc: String) =
|
||||
ASMBridgeEmitter.staticDesc(owner, desc)
|
||||
|
||||
def getSuper(
|
||||
minsn: MethodInsnNode,
|
||||
|
||||
Reference in new issue
Block a user