Skip to content

Commit f4b2db8

Browse files
committed
Merge remote-tracking branch 'origin/1.18' into 1.19.2
2 parents 214b39c + 5a09f27 commit f4b2db8

File tree

7 files changed

+80
-29
lines changed

7 files changed

+80
-29
lines changed

common/src/main/java/org/embeddedt/modernfix/ModernFix.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
1212
import org.embeddedt.modernfix.resources.ReloadExecutor;
1313
import org.embeddedt.modernfix.util.ClassInfoManager;
14+
import org.embeddedt.modernfix.world.IntegratedWatchdog;
1415

1516
import java.lang.management.ManagementFactory;
1617
import java.util.concurrent.ExecutorService;
@@ -46,6 +47,19 @@ public static ExecutorService resourceReloadExecutor() {
4647
public ModernFix() {
4748
INSTANCE = this;
4849
ModernFixPlatformHooks.onServerCommandRegister(ModernFixCommands::register);
50+
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spam_thread_dump.ThreadDumper")) {
51+
Thread t = new Thread() {
52+
public void run() {
53+
while(true) {
54+
LOGGER.error("------ DEBUG THREAD DUMP (occurs every 60 seconds) ------");
55+
LOGGER.error(IntegratedWatchdog.obtainThreadDump());
56+
try { Thread.sleep(60000); } catch(InterruptedException e) {}
57+
}
58+
}
59+
};
60+
t.setDaemon(true);
61+
t.start();
62+
}
4963
}
5064

5165
public void onServerStarted() {

common/src/main/java/org/embeddedt/modernfix/api/entrypoint/ModernFixClientIntegration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ default UnbakedModel onUnbakedModelLoad(ResourceLocation location, UnbakedModel
3434
return originalModel;
3535
}
3636

37+
/**
38+
* Called to allow mods to observe the use of an unbaked model at bake time and either make changes to it or wrap it with their
39+
* own instance.
40+
* @param location the ResourceLocation of the model (this may be a ModelResourceLocation)
41+
* @param originalModel the original model
42+
* @param bakery the model bakery - do not touch internal fields as they probably don't behave the way you expect
43+
* with dynamic resources on
44+
* @return the model which should actually be loaded for this resource location
45+
*/
46+
default UnbakedModel onUnbakedModelPreBake(ResourceLocation location, UnbakedModel originalModel, ModelBakery bakery) {
47+
return originalModel;
48+
}
49+
3750
/**
3851
* Called to allow mods to observe the loading of a baked model and either make changes to it or wrap it with their
3952
* own instance.

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/nbt_memory_usage/CompoundTagMixin.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66
import org.spongepowered.asm.mixin.*;
77
import org.spongepowered.asm.mixin.injection.At;
88
import org.spongepowered.asm.mixin.injection.Inject;
9-
import org.spongepowered.asm.mixin.injection.Redirect;
9+
import org.spongepowered.asm.mixin.injection.ModifyArg;
1010
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1111

1212
import java.util.Map;
1313

1414
@Mixin(CompoundTag.class)
1515
public class CompoundTagMixin {
16-
@Shadow @Final @Mutable
16+
@Shadow @Final
1717
private Map<String, Tag> tags;
1818

1919
/**
20-
* Ensure that the backing map is always a CanonizingStringMap.
20+
* Ensure that the default backing map is a CanonizingStringMap.
2121
*/
22-
@Redirect(method = "<init>(Ljava/util/Map;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/nbt/CompoundTag;tags:Ljava/util/Map;", ordinal = 0))
23-
private void replaceTagMap(CompoundTag tag, Map<String, Tag> incomingMap) {
24-
if(incomingMap instanceof CanonizingStringMap)
25-
this.tags = incomingMap;
26-
else {
27-
this.tags = new CanonizingStringMap<>();
28-
this.tags.putAll(incomingMap);
29-
}
22+
@ModifyArg(method = "<init>()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;<init>(Ljava/util/Map;)V"), index = 0)
23+
private static Map<String, Tag> useCanonizingStringMap(Map<String, Tag> incoming) {
24+
CanonizingStringMap<Tag> newMap = new CanonizingStringMap<>();
25+
newMap.putAll(incoming);
26+
return newMap;
3027
}
3128

3229
/**

common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ else if(isClientOnly && !ModernFixPlatformHooks.isClient())
143143
.put("mixin.perf.dynamic_entity_renderers", false)
144144
.put("mixin.feature.integrated_server_watchdog", true)
145145
.put("mixin.perf.faster_item_rendering", false)
146+
.put("mixin.feature.spam_thread_dump", false)
146147
.put("mixin.devenv", isDevEnv)
147148
.put("mixin.perf.remove_spawn_chunks", isDevEnv)
148149
.build();

common/src/main/java/org/embeddedt/modernfix/world/IntegratedWatchdog.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ public IntegratedWatchdog(MinecraftServer server) {
2525
this.setName("ModernFix integrated server watchdog");
2626
}
2727

28+
public static String obtainThreadDump() {
29+
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
30+
ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
31+
StringBuilder sb = new StringBuilder();
32+
sb.append("Thread Dump:\n");
33+
for(ThreadInfo threadinfo : athreadinfo) {
34+
sb.append(threadinfo);
35+
StackTraceElement[] elements = threadinfo.getStackTrace();
36+
if(elements.length > 8) {
37+
sb.append("extended trace:\n");
38+
for(int i = 8; i < elements.length; i++) {
39+
sb.append("\tat ");
40+
sb.append(elements[i]);
41+
sb.append('\n');
42+
}
43+
}
44+
sb.append('\n');
45+
}
46+
return sb.toString();
47+
}
48+
2849
public void run() {
2950
while(true) {
3051
MinecraftServer server = this.server.get();
@@ -35,24 +56,7 @@ public void run() {
3556
long delta = curTime - nextTick;
3657
if(delta > MAX_TICK_DELTA) {
3758
LOGGER.error("A single server tick has taken {}, more than {} milliseconds", delta, MAX_TICK_DELTA);
38-
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
39-
ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
40-
StringBuilder sb = new StringBuilder();
41-
sb.append("Thread Dump:\n");
42-
for(ThreadInfo threadinfo : athreadinfo) {
43-
sb.append(threadinfo);
44-
StackTraceElement[] elements = threadinfo.getStackTrace();
45-
if(elements.length > 8) {
46-
sb.append("extended trace:\n");
47-
for(int i = 8; i < elements.length; i++) {
48-
sb.append("\tat ");
49-
sb.append(elements[i]);
50-
sb.append('\n');
51-
}
52-
}
53-
sb.append('\n');
54-
}
55-
LOGGER.error(sb.toString());
59+
LOGGER.error(obtainThreadDump());
5660
nextTick = 0;
5761
curTime = 0;
5862
}

fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,17 @@ public void getOrLoadBakedModelDynamic(ResourceLocation arg, ModelState arg2, Ca
453453

454454
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
455455
LOGGER.warn("Model {} not present", arg);
456+
457+
if(iunbakedmodel != missingModel) {
458+
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
459+
try {
460+
iunbakedmodel = integration.onUnbakedModelPreBake(arg, iunbakedmodel, (ModelBakery)(Object)this);
461+
} catch(RuntimeException e) {
462+
ModernFix.LOGGER.error("Exception firing model pre-bake event for {}", arg, e);
463+
}
464+
}
465+
}
466+
456467
BakedModel ibakedmodel = null;
457468
if (iunbakedmodel instanceof BlockModel) {
458469
BlockModel blockmodel = (BlockModel)iunbakedmodel;

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ public void getOrLoadBakedModelDynamic(ResourceLocation arg, ModelState arg2, Fu
330330
iunbakedmodel.getMaterials(this::getModel, new HashSet<>());
331331
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
332332
LOGGER.warn("Model {} not present", arg);
333+
334+
if(iunbakedmodel != missingModel) {
335+
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
336+
try {
337+
iunbakedmodel = integration.onUnbakedModelPreBake(arg, iunbakedmodel, (ModelBakery)(Object)this);
338+
} catch(RuntimeException e) {
339+
ModernFix.LOGGER.error("Exception encountered firing bake event for {}", arg, e);
340+
}
341+
}
342+
}
343+
333344
BakedModel ibakedmodel = null;
334345
if (iunbakedmodel instanceof BlockModel) {
335346
BlockModel blockmodel = (BlockModel)iunbakedmodel;

0 commit comments

Comments
 (0)