Skip to content

Commit 4b8ec82

Browse files
committed
Merge 1.16 into 1.18
2 parents 39fa555 + 8059fc4 commit 4b8ec82

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_sounds/SoundBufferLibraryMixin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.embeddedt.modernfix.common.mixin.perf.dynamic_sounds;
22

33
import com.google.common.cache.CacheBuilder;
4+
import com.google.common.cache.RemovalCause;
45
import com.google.common.cache.RemovalNotification;
56
import com.mojang.blaze3d.audio.SoundBuffer;
67
import net.minecraft.client.sounds.SoundBufferLibrary;
@@ -26,12 +27,15 @@ public abstract class SoundBufferLibraryMixin {
2627
@Shadow @Final @Mutable
2728
private Map<ResourceLocation, CompletableFuture<SoundBuffer>> cache = CacheBuilder.newBuilder()
2829
.expireAfterAccess(DynamicSoundHelpers.MAX_SOUND_LIFETIME_SECS, TimeUnit.SECONDS)
30+
.concurrencyLevel(1)
2931
// Excessive use of type hinting due to it assuming Object as the broadest correct type
3032
.<ResourceLocation, CompletableFuture<SoundBuffer>>removalListener(this::onSoundRemoval)
3133
.build()
3234
.asMap();
3335

3436
private <K extends ResourceLocation, V extends CompletableFuture<SoundBuffer>> void onSoundRemoval(RemovalNotification<K, V> notification) {
37+
if(notification.getCause() == RemovalCause.REPLACED && notification.getValue() == cache.get(notification.getKey()))
38+
return;
3539
notification.getValue().thenAccept(SoundBuffer::discardAlBuffer);
3640
if(debugDynamicSoundLoading) {
3741
K k = notification.getKey();

fabric/src/main/java/org/embeddedt/modernfix/fabric/mappings/MappingsClearer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public static void clear() {
2121
if(FabricLoader.getInstance().isDevelopmentEnvironment())
2222
return; // never do this in dev
2323
CommonModUtil.runWithoutCrash(() -> {
24+
// For now, force the mapping resolver to be initialized. Fabric Loader 0.14.23 stops initializing it early,
25+
// which means that we actually need to keep the TinyMappingFactory tree around for initialization to work
26+
// later. We force init it now because then we can store less in memory.
27+
// Comparing heap dumps on 0.14.23 suggests a savings of 20MB by doing it our way, since many mods will
28+
// end up needing the mapping resolver.
29+
// This will need to be revisited when https://github.com/FabricMC/fabric-loader/pull/812 is merged.
30+
FabricLoader.getInstance().getMappingResolver();
31+
2432
// clear notch->intermediary mappings
2533
MappingConfiguration config = FabricLauncherBase.getLauncher().getMappingConfiguration();
2634
Field mappingsField = MappingConfiguration.class.getDeclaredField("mappings");
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.embeddedt.modernfix.forge.mixin.bugfix.unsafe_modded_shape_caches;
2+
3+
import org.embeddedt.modernfix.ModernFix;
4+
import org.embeddedt.modernfix.annotation.RequiresMod;
5+
import org.spongepowered.asm.mixin.*;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
import java.util.Map;
11+
import java.util.concurrent.ConcurrentHashMap;
12+
13+
/**
14+
* see {@link ShapeCacheRSMixin}
15+
*/
16+
@Pseudo
17+
@Mixin(targets = { "com/lothrazar/cyclic/block/cable/ShapeCache" }, remap = false)
18+
@RequiresMod("cyclic")
19+
@SuppressWarnings("rawtypes")
20+
public class ShapeCacheCyclicMixin {
21+
@Shadow @Final @Mutable private static final Map CACHE = new ConcurrentHashMap();
22+
23+
@Inject(method = "<clinit>", at = @At("RETURN"))
24+
private static void mfix$notify(CallbackInfo ci) {
25+
ModernFix.LOGGER.info("Made Cyclic shape cache map thread-safe");
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.embeddedt.modernfix.forge.mixin.bugfix.unsafe_modded_shape_caches;
2+
3+
import org.embeddedt.modernfix.ModernFix;
4+
import org.embeddedt.modernfix.annotation.RequiresMod;
5+
import org.spongepowered.asm.mixin.*;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
import java.util.Map;
11+
import java.util.concurrent.ConcurrentHashMap;
12+
13+
/**
14+
* Some mods use a custom shape cache with a non-thread-safe map. There is no reason why this wouldn't cause crashes
15+
* in vanilla as well if getShape was called on two threads at once. It seems more likely to happen with ModernFix
16+
* installed due to the dynamic blockstate cache generation, so we solve it by making the maps thread-safe.
17+
*/
18+
@Pseudo
19+
@Mixin(targets = { "com/refinedmods/refinedstorage/block/shape/ShapeCache" }, remap = false)
20+
@RequiresMod("refinedstorage")
21+
@SuppressWarnings("rawtypes")
22+
public class ShapeCacheRSMixin {
23+
@Shadow @Final @Mutable private static final Map CACHE = new ConcurrentHashMap();
24+
25+
@Inject(method = "<clinit>", at = @At("RETURN"))
26+
private static void mfix$notify(CallbackInfo ci) {
27+
ModernFix.LOGGER.info("Made Refined Storage shape cache map thread-safe");
28+
}
29+
}

0 commit comments

Comments
 (0)