Merge remote-tracking branch 'origin/main' into 1.18

This commit is contained in:
embeddedt 2023-05-04 11:17:23 -04:00
commit 7e7f336ccb
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 29 additions and 10 deletions

View File

@ -17,15 +17,13 @@ import java.util.concurrent.TimeUnit;
import java.util.function.IntFunction;
public class DFUBlaster {
private static final Cache<Pair<IntFunction<RewriteResult<?, ?>>, Integer>, RewriteResult<?, ?>> hmapApplyCache = CacheBuilder.newBuilder()
.expireAfterAccess(3, TimeUnit.MINUTES)
.build();
private static final Cache<Triple<Type<?>, TypeRewriteRule, PointFreeRule>, Optional<? extends RewriteResult<?, ?>>> rewriteCache = CacheBuilder.newBuilder()
.expireAfterAccess(3, TimeUnit.MINUTES)
.build();
public static void blastMaps() {
Cache<Pair<IntFunction<RewriteResult<?, ?>>, Integer>, RewriteResult<?, ?>> hmapApplyCache = CacheBuilder.newBuilder()
.maximumSize(200) /* should mean approximately 50MB used max */
.expireAfterAccess(3, TimeUnit.MINUTES)
.build();
Cache<Triple<Type<?>, TypeRewriteRule, PointFreeRule>, Optional<? extends RewriteResult<?, ?>>> rewriteCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterAccess(3, TimeUnit.MINUTES)
.build();
try {
Class<?> FOLD_CLASS = Class.forName("com.mojang.datafixers.functions.Fold");
Field hmapField = FOLD_CLASS.getDeclaredField("HMAP_APPLY_CACHE");
@ -41,8 +39,30 @@ public class DFUBlaster {
base = unsafe.staticFieldBase(rewriteCacheField);
offset = unsafe.staticFieldOffset(rewriteCacheField);
unsafe.putObject(base, offset, rewriteCache.asMap());
new CleanerThread().start();
} catch(Throwable e) {
ModernFix.LOGGER.error("Could not replace DFU map", e);
}
}
static class CleanerThread extends Thread {
CleanerThread() {
this.setName("DFU cleaning thread");
this.setPriority(1);
this.setDaemon(true);
}
@Override
public void run() {
while(true) {
try {
Thread.sleep(15000);
} catch(InterruptedException e){
return;
}
rewriteCache.cleanUp();
hmapApplyCache.cleanUp();
}
}
}
}

View File

@ -35,6 +35,7 @@ public class LazyDataFixer implements DataFixer {
synchronized (this) {
if(backingDataFixer == null) {
LOGGER.info("Instantiating Mojang DFU");
DFUBlaster.blastMaps();
backingDataFixer = dfuSupplier.get();
}
}

View File

@ -25,7 +25,6 @@ import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.embeddedt.modernfix.forge.classloading.FastAccessTransformerList;
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
import org.embeddedt.modernfix.dfu.DFUBlaster;
import org.embeddedt.modernfix.forge.packet.PacketHandler;
import org.embeddedt.modernfix.util.DummyList;
import org.objectweb.asm.Opcodes;
@ -126,7 +125,6 @@ public class ModernFixPlatformHooksImpl {
public static void injectPlatformSpecificHacks() {
FastAccessTransformerList.attemptReplace();
DFUBlaster.blastMaps();
/* https://github.com/FabricMC/Mixin/pull/99 */
try {