diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-11-07 16:21:34 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-11-07 16:21:34 +0800 |
| commit | f8fc41207ca444c0a90ae10d78a821831b245bc2 (patch) | |
| tree | a2a049cc4ead3157eb9d284027e12798f9e48c81 /runtime | |
| parent | d1e91e2e2ffa317a52e659f2ca2b76800108f427 (diff) | |
| download | RoughlyEnoughItems-f8fc41207ca444c0a90ae10d78a821831b245bc2.tar.gz RoughlyEnoughItems-f8fc41207ca444c0a90ae10d78a821831b245bc2.tar.bz2 RoughlyEnoughItems-f8fc41207ca444c0a90ae10d78a821831b245bc2.zip | |
Fix #654
Diffstat (limited to 'runtime')
5 files changed, 25 insertions, 11 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 094bbe4ea..98f5aab24 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -380,7 +380,7 @@ public class RoughlyEnoughItemsCoreClient { public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start) { if (lastReload != null) { if (lastReload.getValue() > 0 && System.currentTimeMillis() - lastReload.getValue() <= 5000) { - RoughlyEnoughItemsCore.LOGGER.warn("Suppressing Reload Plugins!"); + RoughlyEnoughItemsCore.LOGGER.warn("Suppressing Reload Plugins of stage " + start); return; } lastReload.setValue(System.currentTimeMillis()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java index 92bfb78be..b6e5b5f92 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java @@ -150,7 +150,11 @@ public class PerformanceScreen extends Screen { inner.times().forEach((obj, time) -> { entries.add(new EntryListEntry(new TextComponent(obj instanceof Pair ? ((Pair<REIPluginProvider<?>, REIPlugin<?>>) obj).getFirst().getPluginProviderName() : Objects.toString(obj)), time)); }); - long separateTime = inner.times().values().stream().collect(Collectors.summarizingLong(value -> value)).getSum(); + Collection<Long> values = inner.times().values(); + long separateTime; + synchronized (inner.times()) { + separateTime = values.stream().collect(Collectors.summarizingLong(value -> value)).getSum(); + } if ((inner.totalNano() - separateTime) > 1000000) { entries.add(new EntryListEntry(new TextComponent("Miscellaneous Operations"), inner.totalNano() - separateTime)); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/performance/PerformanceLoggerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/performance/PerformanceLoggerImpl.java index 934bf494e..227d067c7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/performance/PerformanceLoggerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/performance/PerformanceLoggerImpl.java @@ -28,14 +28,16 @@ import com.google.common.collect.Maps; import com.mojang.datafixers.util.Pair; import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; +import it.unimi.dsi.fastutil.objects.Object2LongMaps; import me.shedaniel.rei.api.common.plugins.REIPlugin; import me.shedaniel.rei.api.common.plugins.REIPluginProvider; +import java.util.Collections; import java.util.Map; import java.util.concurrent.TimeUnit; public class PerformanceLoggerImpl implements PerformanceLogger { - private final Map<String, PluginImpl> stages = Maps.newLinkedHashMap(); + private final Map<String, PluginImpl> stages = Collections.synchronizedMap(Maps.newLinkedHashMap()); @Override public Plugin stage(String stage) { @@ -52,7 +54,7 @@ public class PerformanceLoggerImpl implements PerformanceLogger { private static class PluginImpl implements Plugin { private final Stopwatch stopwatch = Stopwatch.createUnstarted(); private long totalTime = 0; - private Object2LongMap<Object> times = new Object2LongLinkedOpenHashMap<>(); + private Object2LongMap<Object> times = Object2LongMaps.synchronize(new Object2LongLinkedOpenHashMap<>()); @Override public Inner stage(String stage) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 71b1cb716..bda591fb1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -213,6 +213,8 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< ((REIPlugin<P>) plugin.plugin).preStage(this, stage); } }); + } catch (Throwable throwable) { + new RuntimeException("Failed to run pre registration").printStackTrace(); } } @@ -229,6 +231,8 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< ((REIPlugin<P>) plugin.plugin).postStage(this, stage); } }); + } catch (Throwable throwable) { + new RuntimeException("Failed to run post registration").printStackTrace(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java index 10326394c..86eddd5c0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java @@ -40,7 +40,7 @@ import java.util.*; import java.util.stream.Collectors; public class PluginStageExecutionWatcher implements HintProvider { - private Map<PluginManager<?>, Set<ReloadStage>> allStages = new HashMap<>(); + private final Map<PluginManager<?>, Set<ReloadStage>> allStages = new HashMap<>(); public <T extends REIPlugin<?>> Reloadable<? extends T> reloadable(PluginManager<?> manager) { return new Reloadable<>() { @@ -53,17 +53,21 @@ public class PluginStageExecutionWatcher implements HintProvider { @Override public void startReload(ReloadStage stage) { - Set<ReloadStage> stages = allStages.computeIfAbsent(manager, $ -> new HashSet<>()); - if (stage.ordinal() == 0) stages.clear(); - stages.add(stage); + synchronized (allStages) { + Set<ReloadStage> stages = allStages.computeIfAbsent(manager, $ -> new HashSet<>()); + if (stage.ordinal() == 0) stages.clear(); + stages.add(stage); + } } }; } public Set<ReloadStage> notVisited() { - Set<ReloadStage> notVisited = new HashSet<>(Arrays.asList(ReloadStage.values())); - notVisited.removeIf(stage -> allStages.values().stream().allMatch(stages -> stages.contains(stage))); - return notVisited; + synchronized (allStages) { + Set<ReloadStage> notVisited = new HashSet<>(Arrays.asList(ReloadStage.values())); + notVisited.removeIf(stage -> allStages.values().stream().allMatch(stages -> stages.contains(stage))); + return notVisited; + } } @Override |
