Skip to content

Commit

Permalink
More work on debugging loading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jediminer543 committed Jun 14, 2021
1 parent b474214 commit 0e5ac61
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mcmt_ver=0.21.79-PRE
mcmt_ver=0.21.80-PRE

mappings_ver=20200723-1.16.1
mappings_chan=snapshot
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/jmt/mcmt/asmdest/DebugHookTerminator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.chunk.storage.ChunkSerializer;
import net.minecraft.world.server.ChunkHolder;
Expand Down Expand Up @@ -71,6 +72,16 @@ public static void chunkLoadDrive(ServerChunkProvider.ChunkExecutor executor, Bo
}
completableFuture.complete(ChunkHolder.MISSING_CHUNK);
} else {
System.err.println(completableFuture.toString());
ChunkHolder chunkholder = scp.func_217213_a(chunkpos);
for (ChunkStatus cs : ChunkStatus.getAll()) {
CompletableFuture<Either<IChunk, IChunkLoadingError>> cf = chunkholder.func_219301_a(cs);
if (cf == ChunkHolder.MISSING_CHUNK_FUTURE) {
System.out.println("Status: " + cs.toString() + " is not yet loaded");
} else {
System.out.println("Status: " + cs.toString() + " is " + cf.toString());
}
}
completableFuture.complete(Either.right(new IChunkLoadingError() {
@Override
public String toString() {
Expand All @@ -82,4 +93,11 @@ public String toString() {
}
}
}

public static void checkNull(Object o) {
if (o == null) {
System.out.println("Null warning:");
new Throwable("Null trace").printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public IChunk getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boole
}
return super.getChunk(chunkX, chunkZ, requiredStatus, load);
}
if (ASMHookTerminator.isThreadPooled("Main", Thread.currentThread())) {
return CompletableFuture.supplyAsync(() -> {
return this.getChunk(chunkX, chunkZ, requiredStatus, load);
}, this.executor).join();
}

long i = ChunkPos.asLong(chunkX, chunkZ);

IChunk c = lookupChunk(i, requiredStatus, false);
Expand All @@ -89,12 +95,6 @@ public IChunk getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boole

//log.debug("Missed chunk " + i + " on status " + requiredStatus.toString());

if (ASMHookTerminator.isThreadPooled("Main", Thread.currentThread())) {
return CompletableFuture.supplyAsync(() -> {
return this.getChunk(chunkX, chunkZ, requiredStatus, load);
}, this.executor).join();
}

IChunk cl;
synchronized (this) {
//cl = super.getChunk(chunkX, chunkZ, requiredStatus, load);
Expand Down
61 changes: 61 additions & 0 deletions src/main/resources/trans/debug/SCPDriveDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,66 @@ function initializeCoreMod() {
return methodNode;
}
},
/*
'ChunkHolderNullCheck': {
'target': {
'type': 'METHOD',
'class': 'net.minecraft.world.server.ChunkHolder',
"methodName": "func_219276_a",
"methodDesc": "(Lnet/minecraft/world/chunk/ChunkStatus;Lnet/minecraft/world/server/ChunkManager;)Ljava/util/concurrent/CompletableFuture;"
},
'transformer': function(methodNode) {
var opcodes = Java.type('org.objectweb.asm.Opcodes');
var asmapi = Java.type('net.minecraftforge.coremod.api.ASMAPI');
var InsnList = Java.type("org.objectweb.asm.tree.InsnList");
var InsnNode = Java.type("org.objectweb.asm.tree.InsnNode");
var LabelNode = Java.type("org.objectweb.asm.tree.LabelNode");
var MethodInsnNode = Java.type("org.objectweb.asm.tree.MethodInsnNode");
var JumpInsnNode = Java.type("org.objectweb.asm.tree.JumpInsnNode");
var LdcInsnNode = Java.type("org.objectweb.asm.tree.LdcInsnNode");
var VarInsnNode = Java.type("org.objectweb.asm.tree.VarInsnNode");
var MethodType = asmapi.MethodType;
asmapi.log("INFO", "[JMTSUPERTRANS] ChunkHolderNullCheck Transformer Called");
//INVOKEVIRTUAL java/util/concurrent/CompletableFuture.getNow(Ljava/lang/Object;)Ljava/lang/Object;
//mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/world/server/ServerChunkProvider", "getLoadedChunksCount", "()I", false);
var targetMethodOwner = "java/util/concurrent/CompletableFuture";
var targetMethodName = "getNow";//asmapi.mapMethod("func_217229_b");
var targetMethodDesc = "(Ljava/lang/Object;)Ljava/lang/Object;";
var method = methodNode
var instructions = methodNode.instructions;
var callTarget = asmapi.findFirstMethodCallAfter(method, MethodType.VIRTUAL,
targetMethodOwner, targetMethodName, targetMethodDesc, 0);
if (callTarget != null) {
asmapi.log("DEBUG", "[JMTSUPERTRANS] FOUND TARGET INSNS");
} else {
asmapi.log("DEBUG", "[JMTSUPERTRANS] MISSING TARGET INSNS:");
asmapi.log("DEBUG", "[JMTSUPERTRANS] HAVE CALL:" + (callTarget != null));
return;
}
//Call Hook
var il = new InsnList();
//il.add(new InsnNode(opcodes.DUP));
//il.add(new MethodInsnNode(opcodes.INVOKESTATIC,
// "org/jmt/mcmt/asmdest/DebugHookTerminator", "checkNull",
// "(Ljava/lang/Object;)V",
// false));
instructions.insert(callTarget, il);
asmapi.log("INFO", "[JMTSUPERTRANS] ChunkHolderNullCheck Transformer Complete");
return methodNode;
}
},
*/
}
}

0 comments on commit 0e5ac61

Please sign in to comment.