Skip to content

Commit

Permalink
Work on fixing several issues relating to mod compatibility
Browse files Browse the repository at this point in the history
Also found out that the pSCP is a bottleneck so that needs to be fixed

Also be aware this release has been somewhat unstable in my test envs
(tho they are modded so \shrug)
  • Loading branch information
jediminer543 committed Jun 12, 2021
1 parent 73559d7 commit b474214
Show file tree
Hide file tree
Showing 6 changed files with 149 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.77-PRE
mcmt_ver=0.21.79-PRE

mappings_ver=20200723-1.16.1
mappings_chan=snapshot
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jmt/mcmt/asmdest/ConcurrentCollections.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collector;
import java.util.stream.Collectors;
Expand All @@ -20,7 +23,7 @@ public static <T> Set<T> newHashSet() {
return Collections.newSetFromMap(new ConcurrentHashMap<T, Boolean>());
}

public static <T, U> ConcurrentHashMap<T, U> newHashMap() {
public static <T, U> Map<T, U> newHashMap() {
LOGGER.info("Concurrent hash map created");
return new ConcurrentHashMap<T, U>();
}
Expand All @@ -33,4 +36,10 @@ public static <T> List<T> newLinkedList() {
public static <T> Collector<T, ?, List<T>> toList() {
return Collectors.toCollection(CopyOnWriteArrayList::new);
}

public static <T> Queue<T> newArrayDeque() {
LOGGER.info("Concurrent \"array\" deque created");
return new ConcurrentLinkedDeque<T>();
}

}
13 changes: 12 additions & 1 deletion src/main/java/org/jmt/mcmt/commands/DebugCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.ILocationArgument;
import net.minecraft.command.arguments.Vec3Argument;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
Expand Down Expand Up @@ -107,6 +108,16 @@ public static LiteralArgumentBuilder<CommandSource> registerDebug(LiteralArgumen
cmdCtx.getSource().sendFeedback(message, true);
System.out.println(message.toString());
return 1;
}));
}))
/*
.then(Commands.literal("goinf").requires(cmdSrc -> {
return cmdSrc.hasPermissionLevel(2);
}).executes(cmdCtx -> {
ServerPlayerEntity p = cmdCtx.getSource().asPlayer();
p.setPosition(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
return 1;
}))
*/
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public IChunk getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boole
}
long i = ChunkPos.asLong(chunkX, chunkZ);

IChunk c = lookupChunk(i, requiredStatus);
IChunk c = lookupChunk(i, requiredStatus, false);
if (c != null) {
return c;
}
Expand All @@ -97,11 +97,30 @@ public IChunk getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boole

IChunk cl;
synchronized (this) {
//cl = super.getChunk(chunkX, chunkZ, requiredStatus, load);
/*
ChunkCacheLine ccl;
ccl = chunkCache.computeIfAbsent(new ChunkCacheAddress(i, requiredStatus), a->new ChunkCacheLine(getChunkyThing(a.chunk, a.status, load)));
if (ccl != null) {
ccl.updateLastAccess();
return ccl.getChunk();
}
*/
// This shouldn't be needed but if it is well something definately brokey
cl = super.getChunk(chunkX, chunkZ, requiredStatus, load);
}
cacheChunk(i, cl, requiredStatus);
return cl;
}

@SuppressWarnings("unused")
private IChunk getChunkyThing(long chunkPos, ChunkStatus requiredStatus, boolean load) {
IChunk cl;
synchronized (this) {
cl = super.getChunk(ChunkPos.getX(chunkPos), ChunkPos.getZ(chunkPos), requiredStatus, load);
}
return cl;
}

/* 1.15.2/1.16.2 */
@Override
Expand All @@ -112,7 +131,7 @@ public Chunk getChunkNow(int chunkX, int chunkZ) {
}
long i = ChunkPos.asLong(chunkX, chunkZ);

IChunk c = lookupChunk(i, ChunkStatus.FULL);
IChunk c = lookupChunk(i, ChunkStatus.FULL, false);
if (c != null) {
return (Chunk) c;
}
Expand All @@ -125,19 +144,21 @@ public Chunk getChunkNow(int chunkX, int chunkZ) {
}
/* */

public IChunk lookupChunk(long chunkPos, ChunkStatus status) {
public IChunk lookupChunk(long chunkPos, ChunkStatus status, boolean compute) {
int oldaccess = access++;
if (access < oldaccess) {
// Long Rollover so super rare
chunkCache.clear();
return null;
}
ChunkCacheLine ccl = chunkCache.get(new ChunkCacheAddress(chunkPos, status));
ChunkCacheLine ccl;
ccl = chunkCache.get(new ChunkCacheAddress(chunkPos, status));
if (ccl != null) {
ccl.updateLastAccess();
return ccl.getChunk();
}
return null;

}

public void cacheChunk(long chunkPos, IChunk chunk, ChunkStatus status) {
Expand Down
70 changes: 70 additions & 0 deletions src/main/resources/trans/general/generalparallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,56 @@ function toParallelHashSets(methodNode) {
}
}

function toParallelHashMaps(methodNode) {
var asmapi = Java.type('net.minecraftforge.coremod.api.ASMAPI');
var MethodType = asmapi.MethodType;
var instructions = methodNode.instructions;

var callMethod = "newHashMap";
var callClass = "com/google/common/collect/Maps";
var callDesc = "()Ljava/util/HashMap;";

var tgtMethod = "newHashMap";
var tgtClass = "org/jmt/mcmt/asmdest/ConcurrentCollections";
var tgtDesc = "()Ljava/util/Map;";

var invoke = asmapi.findFirstMethodCallAfter(methodNode, MethodType.STATIC, callClass, callMethod, callDesc, 0);
if (invoke != null) {
do {
invoke.owner = tgtClass;
invoke.name = tgtMethod;
invoke.desc = tgtDesc;
} while ((invoke = asmapi.findFirstMethodCallAfter(methodNode,
MethodType.STATIC, callClass, callMethod, callDesc, instructions.indexOf(invoke))) != null)
}
}

function toParallelDeque(methodNode) {
var asmapi = Java.type('net.minecraftforge.coremod.api.ASMAPI');
var MethodType = asmapi.MethodType;
var instructions = methodNode.instructions;

//com/google/common/collect/Queues.newArrayDeque()Ljava/util/ArrayDeque;
var callMethod = "newArrayDeque";
var callClass = "com/google/common/collect/Queues";
var callDesc = "()Ljava/util/ArrayDeque;";

var tgtMethod = "newArrayDeque";
var tgtClass = "org/jmt/mcmt/asmdest/ConcurrentCollections";
var tgtDesc = "()Ljava/util/Queue;";

var invoke = asmapi.findFirstMethodCallAfter(methodNode, MethodType.STATIC, callClass, callMethod, callDesc, 0);
if (invoke != null) {
do {
invoke.owner = tgtClass;
invoke.name = tgtMethod;
invoke.desc = tgtDesc;
} while ((invoke = asmapi.findFirstMethodCallAfter(methodNode,
MethodType.STATIC, callClass, callMethod, callDesc, instructions.indexOf(invoke))) != null)
}
}


function initializeCoreMod() {
return {
'serverChunkProviderTick': {
Expand Down Expand Up @@ -103,6 +153,7 @@ function initializeCoreMod() {
print("[JMTSUPERTRANS] ServerWorldCollections Transformer Called");

toParallelHashSets(methodNode);
toParallelDeque(methodNode);

print("[JMTSUPERTRANS] ServerWorldCollections Transformer Complete");

Expand All @@ -120,6 +171,7 @@ function initializeCoreMod() {
print("[JMTSUPERTRANS] ServerWorldCollections116 Transformer Called");

toParallelHashSets(methodNode);
toParallelDeque(methodNode);

print("[JMTSUPERTRANS] ServerWorldCollections116 Transformer Complete");

Expand All @@ -137,6 +189,7 @@ function initializeCoreMod() {
print("[JMTSUPERTRANS] ServerWorldCollections116 Transformer Called");

toParallelHashSets(methodNode);
toParallelDeque(methodNode);

print("[JMTSUPERTRANS] ServerWorldCollections116 Transformer Complete");

Expand Down Expand Up @@ -379,6 +432,23 @@ function initializeCoreMod() {

print("[JMTSUPERTRANS] PlayerEntityRemoveQueueSync Transformer Complete");

return methodNode;
}
},
'TemplateManagerHashMap': {
'target': {
'type': 'METHOD',
'class': 'net.minecraft.world.gen.feature.template.TemplateManager',
"methodName": "<init>",
"methodDesc": "(Lnet/minecraft/resources/IResourceManager;Lnet/minecraft/world/storage/SaveFormat$LevelSave;Lcom/mojang/datafixers/DataFixer;)V"
},
"transformer": function(methodNode) {
print("[JMTSUPERTRANS] TemplateManagerHashMap Transformer Called");

toParallelHashMaps(methodNode);

print("[JMTSUPERTRANS] TemplateManagerHashMap Transformer Complete");

return methodNode;
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.jmt.mcmt.modlauncher;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -164,6 +170,31 @@ public Set<Target> targets() {
out.add(Target.targetClass("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap"));
out.add(Target.targetClass("it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet"));
out.add(Target.targetClass("it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap"));
//out.add(Target.targetClass("it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap"));
File f = new File("config/mcmt-sync-fu-list.txt");
if (f.exists()) {
try (BufferedReader r = new BufferedReader(new FileReader(f))) {
r.lines().filter(s -> !(s.startsWith("#") || s.startsWith("//") || s.equals(""))).map(s -> Target.targetClass(s)).forEach(t -> out.add(t));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
} else {
try {
f.createNewFile();
FileWriter fw = new FileWriter(f);
fw.write("// This file allows you to add targets to sync-fu\n"
+ "// Lines starting with // or # are comments\n"
+ "// This is done by specifying a class name\n"
+ "// As an example: \n"
+ "//it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap\n");
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return out;
}

Expand Down

0 comments on commit b474214

Please sign in to comment.