9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-21 15:59:23 +00:00

include threads by default in spark

This commit is contained in:
NONPLAYT
2025-03-24 22:52:38 +03:00
parent 95522311db
commit 9ab385ab73
17 changed files with 270 additions and 66 deletions

View File

@@ -36,6 +36,18 @@ index 1485186d4989874ef89c4e83830f26358a43759c..b48fc9e0b95fe6c8f72c5501b8de374e
@SuppressForbidden(
reason = "System.out needed before bootstrap"
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 781030cb2e0316151c20351f04347c8db63f43e1..6bb8afb3b0e92c374474c92fa44dc7b80af0bd73 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1182,6 +1182,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected void runServer() {
try {
+ org.bxteam.divinemc.spark.ThreadDumperRegistry.REGISTRY.add(Thread.currentThread().getName()); // DivineMC
if (!this.initServer()) {
throw new IllegalStateException("Failed to initialize server");
}
diff --git a/net/minecraft/server/gui/MinecraftServerGui.java b/net/minecraft/server/gui/MinecraftServerGui.java
index 614c7d9f673c926562acc8fa3b3788623900db41..33456c7c106abbddf743e1203a6e8122cf10b797 100644
--- a/net/minecraft/server/gui/MinecraftServerGui.java

View File

@@ -213,7 +213,7 @@ index 18071dcc69cc28471dddb7de94e803ec1e5fc2e4..aa25f5ebaf7d1b22825b962b02dcae02
}
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a7572fc3f 100644
index 6bb8afb3b0e92c374474c92fa44dc7b80af0bd73..4cb26cb312802ffc00426293014ed3994793a391 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -114,19 +114,8 @@ import net.minecraft.util.TimeUtil;
@@ -260,7 +260,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
LOGGER.info("Stopping server");
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
@@ -1282,50 +1261,40 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1283,50 +1262,40 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Spigot end
boolean flag = l == 0L;
@@ -338,7 +338,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
this.isReady = true;
JvmProfiler.INSTANCE.onServerTick(this.smoothedTickTimeMillis);
}
@@ -1497,7 +1466,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1498,7 +1467,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@Override
public void doRunTask(TickTask task) {
@@ -346,7 +346,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
super.doRunTask(task);
}
@@ -1587,12 +1555,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1588,12 +1556,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.ticksUntilAutosave--;
// Paper start - Incremental chunk and player saving
@@ -359,7 +359,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
final boolean fullSave = autosavePeriod > 0 && this.tickCount % autosavePeriod == 0;
try {
this.isSaving = true;
@@ -1607,10 +1573,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1608,10 +1574,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} finally {
this.isSaving = false;
}
@@ -370,7 +370,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
this.runAllTasks(); // Paper - move runAllTasks() into full server tick (previously for timings)
this.server.spark.executeMainThreadTasks(); // Paper - spark
// Paper start - Server Tick Events
@@ -1619,7 +1583,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1620,7 +1584,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
// Paper end - Server Tick Events
this.server.spark.tickEnd(((double)(endTime - lastTick) / 1000000D)); // Paper - spark
@@ -378,7 +378,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
long l = Util.getNanos() - nanos;
int i1 = this.tickCount % 100;
this.aggregatedTickTimesNanos = this.aggregatedTickTimesNanos - this.tickTimesNanos[i1];
@@ -1632,16 +1595,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1633,16 +1596,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickTimes60s.add(this.tickCount, l);
// Paper end - Add tick times API and /mspt command
this.logTickMethodTime(nanos);
@@ -395,7 +395,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
LOGGER.debug("Autosave finished");
}
@@ -1707,7 +1666,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1708,7 +1667,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
protected void tickChildren(BooleanSupplier hasTimeLeft) {
@@ -403,7 +403,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
// Paper start - Folia scheduler API
@@ -1725,9 +1683,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1726,9 +1684,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
});
// Paper end - Folia scheduler API
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
@@ -413,7 +413,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
// CraftBukkit start
// Run tasks that are waiting on processing
@@ -1763,17 +1719,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1764,17 +1720,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.updateLagCompensationTick(); // Paper - lag compensation
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = serverLevel.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers
serverLevel.hasRidableMoveEvent = org.purpurmc.purpur.event.entity.RidableMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Purpur - Ridables
@@ -431,7 +431,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
try {
serverLevel.tick(hasTimeLeft);
} catch (Throwable var7) {
@@ -1782,34 +1733,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1783,34 +1734,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
throw new ReportedException(crashReport);
}
@@ -466,7 +466,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
}
public void tickConnection() {
@@ -1825,14 +1766,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1826,14 +1767,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public void forceTimeSynchronization() {
@@ -481,7 +481,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
}
public boolean isLevelEnabled(Level level) {
@@ -2652,55 +2588,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2653,55 +2589,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit end
@@ -537,7 +537,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
public Path getWorldPath(LevelResource levelResource) {
return this.storageSource.getLevelPath(levelResource);
}
@@ -2750,24 +2637,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2751,24 +2638,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return this.isSaving;
}
@@ -562,7 +562,7 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..c2cc1cd510f501cb8cd7c1c1925cc94a
public int getMaxChainedNeighborUpdates() {
return 1000000;
}
@@ -2873,55 +2742,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2874,55 +2743,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) {
}
@@ -4848,7 +4848,7 @@ index 16fbe4e6521cd4f6baa8f5dd590da0fc749f6585..fec90e482c8935dfca609bbf90e67f86
this.assignProfessionWhenSpawned = false;
}
diff --git a/net/minecraft/world/item/crafting/RecipeManager.java b/net/minecraft/world/item/crafting/RecipeManager.java
index aefaac550b58be479cc282f52dea91d4b1e530f6..f679b7f4f152faf0255b8776c91dfff1be2851c8 100644
index 70eb3f84da8f0c962eaa52998ded69fcfae2f197..c7d91a38fc3b5cf2487e09719a1f9bc39ca5d20e 100644
--- a/net/minecraft/world/item/crafting/RecipeManager.java
+++ b/net/minecraft/world/item/crafting/RecipeManager.java
@@ -28,7 +28,6 @@ import net.minecraft.server.level.ServerLevel;

View File

@@ -261,7 +261,7 @@ index 5ab2c8333178335515e619b87ae420f948c83bd1..9d2bc41befd0f73b6a0f097d45fbe771
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index c2cc1cd510f501cb8cd7c1c1925cc94a7572fc3f..18c83691fa48abf83ba775d66171d72d9103049c 100644
index 4cb26cb312802ffc00426293014ed3994793a391..9f7698f8ce56d5d89cf86f6ea2d5b4d51b18c9a2 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -288,6 +288,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -322,7 +322,7 @@ index c2cc1cd510f501cb8cd7c1c1925cc94a7572fc3f..18c83691fa48abf83ba775d66171d72d
}
@Override
@@ -1665,6 +1678,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1666,6 +1679,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
@@ -341,7 +341,7 @@ index c2cc1cd510f501cb8cd7c1c1925cc94a7572fc3f..18c83691fa48abf83ba775d66171d72d
protected void tickChildren(BooleanSupplier hasTimeLeft) {
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
@@ -1713,28 +1738,43 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1714,28 +1739,43 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
@@ -403,7 +403,7 @@ index c2cc1cd510f501cb8cd7c1c1925cc94a7572fc3f..18c83691fa48abf83ba775d66171d72d
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
this.tickConnection();
@@ -1812,6 +1852,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1813,6 +1853,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
newLevels.remove(level.dimension());

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Optimize hoppers
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 18c83691fa48abf83ba775d66171d72d9103049c..bc7c8140051192dccdd2500e53d946eb3849b3b8 100644
index 9f7698f8ce56d5d89cf86f6ea2d5b4d51b18c9a2..351b035d1f3025af28b5147b95b912e0e2ab9212 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1745,7 +1745,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1746,7 +1746,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
serverLevel.updateLagCompensationTick(); // Paper - lag compensation

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Lag compensation
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index bc7c8140051192dccdd2500e53d946eb3849b3b8..295eb0f89d18d8ed88b633f2e8257268c07af294 100644
index 351b035d1f3025af28b5147b95b912e0e2ab9212..1bcccba4df407ec4d53f49c3c2c7493db87b2240 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -289,6 +289,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -16,7 +16,7 @@ index bc7c8140051192dccdd2500e53d946eb3849b3b8..295eb0f89d18d8ed88b633f2e8257268
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
@@ -1557,6 +1558,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1558,6 +1559,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
this.server.spark.tickStart(); // Paper - spark

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] MSPT Tracking for each world
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 295eb0f89d18d8ed88b633f2e8257268c07af294..ea19137150115a592a501e10e92a011855c135e3 100644
index 1bcccba4df407ec4d53f49c3c2c7493db87b2240..54c8605a4e36605208344e39726a4c3bbe972076 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1683,7 +1683,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1684,7 +1684,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// DivineMC start - Parallel world ticking
private void tickLevel(ServerLevel serverLevel, BooleanSupplier hasTimeLeft) {
try {

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Skip EntityScheduler's executeTick checks if there isn't any
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index ea19137150115a592a501e10e92a011855c135e3..72b2d9c0d9b5b2038f13ea961c977fe4b36d7291 100644
index 54c8605a4e36605208344e39726a4c3bbe972076..72ab570ca8b532a1f55408515f34a02aa0c79a6a 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -290,6 +290,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -17,7 +17,7 @@ index ea19137150115a592a501e10e92a011855c135e3..72b2d9c0d9b5b2038f13ea961c977fe4
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
@@ -1705,17 +1706,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1706,17 +1707,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
// Paper start - Folia scheduler API
((io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler) org.bukkit.Bukkit.getGlobalRegionScheduler()).tick();

View File

@@ -20,10 +20,10 @@ index 4535858701b2bb232b9d2feb2af6551526232ddc..aa4dd7517e8be167aef1eaf7aa907e3c
if (var4 instanceof ReportedException reportedException && reportedException.getCause() instanceof OutOfMemoryError) {
throw makeReportedException(var4, packet, processor);
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 72b2d9c0d9b5b2038f13ea961c977fe4b36d7291..4480bb9de51a1a0ffbc1b3c1374876212f1f20db 100644
index 72ab570ca8b532a1f55408515f34a02aa0c79a6a..fe2d9328a7e9365f8c7e24e862038bc94ddfe1ca 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1693,6 +1693,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1694,6 +1694,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.tickTimes10s.add(this.tickCount, j);
serverLevel.tickTimes60s.add(this.tickCount, j);
// DivineMC end - MSPT Tracking for each world

View File

@@ -36,10 +36,10 @@ index 212d2bcfd34f7cb14e18a8af2cd296fc01d371f6..ec76e4f29ba96b31a24a5d195b852342
new java.util.concurrent.LinkedBlockingQueue<>(),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 4480bb9de51a1a0ffbc1b3c1374876212f1f20db..19ebcc9a175fa1bcd3bb4f954bdda00664a86f19 100644
index fe2d9328a7e9365f8c7e24e862038bc94ddfe1ca..daf6141a6aed6baf7b8de4030324703a0fe872d3 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -2708,8 +2708,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2709,8 +2709,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}

View File

@@ -217,6 +217,19 @@ index b36e30fd4057a938e4d90cb42a2dca661f16478e..4e29f5f55b9a894099bef6f7c7f11e2a
}
@Override
diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java
index 62e2d5704c348955bc8284dc2d54c933b7bcdd06..341f13e57896f03058ea3ec68e69b7cb946ce3fc 100644
--- a/src/main/java/io/papermc/paper/SparksFly.java
+++ b/src/main/java/io/papermc/paper/SparksFly.java
@@ -42,7 +42,7 @@ public final class SparksFly {
this.mainThreadTaskQueue = new ConcurrentLinkedQueue<>();
this.logger = Logger.getLogger(ID);
this.logger.log(Level.INFO, "This server bundles the spark profiler. For more information please visit https://docs.papermc.io/paper/profiling");
- this.spark = PaperSparkModule.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() {
+ this.spark = org.bxteam.divinemc.spark.DivineSparkPlugin.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() { // DivineMC - use own spark module
@Override
public void executeAsync(final Runnable runnable) {
MCUtil.scheduleAsyncTask(this.catching(runnable, "asynchronous"));
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index 2e1b7f613de8876095ef39bb0341a3f9520c8d5d..bab0d25e82f85c7b9524ae42e0bb41e6233d71cf 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java

View File

@@ -4,21 +4,8 @@ Date: Mon, 27 Jan 2025 20:53:24 +0300
Subject: [PATCH] Configuration
diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java
index 62e2d5704c348955bc8284dc2d54c933b7bcdd06..341f13e57896f03058ea3ec68e69b7cb946ce3fc 100644
--- a/src/main/java/io/papermc/paper/SparksFly.java
+++ b/src/main/java/io/papermc/paper/SparksFly.java
@@ -42,7 +42,7 @@ public final class SparksFly {
this.mainThreadTaskQueue = new ConcurrentLinkedQueue<>();
this.logger = Logger.getLogger(ID);
this.logger.log(Level.INFO, "This server bundles the spark profiler. For more information please visit https://docs.papermc.io/paper/profiling");
- this.spark = PaperSparkModule.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() {
+ this.spark = org.bxteam.divinemc.spark.DivineSparkPlugin.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() { // DivineMC - use own spark module
@Override
public void executeAsync(final Runnable runnable) {
MCUtil.scheduleAsyncTask(this.catching(runnable, "asynchronous"));
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index f87062cdaf4e02e51904f275913907c0269f4d41..037ca6ea2edb3c4ff9bf9f7856360cd2c19b7628 100644
index 362ab47d0cdba42d7174e9558dd9b926538136d1..d0adbe6fc8ed89ece59226905608cdceb04a6752 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1103,6 +1103,13 @@ public final class CraftServer implements Server {

View File

@@ -1,11 +1,12 @@
package org.bxteam.divinemc.entity.pathfinding;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import ca.spottedleaf.moonrise.common.util.TickThread;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.pathfinder.Path;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bxteam.divinemc.DivineConfig;
import org.bxteam.divinemc.util.NamedAgnosticThreadFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -19,7 +20,7 @@ import java.util.function.Consumer;
*/
@SuppressWarnings("DuplicatedCode")
public class AsyncPathProcessor {
private static final String THREAD_PREFIX = "DivineMC Async Pathfinding";
private static final String THREAD_PREFIX = "Async Pathfinding";
private static final Logger LOGGER = LogManager.getLogger(THREAD_PREFIX);
private static long lastWarnMillis = System.currentTimeMillis();
@@ -28,10 +29,7 @@ public class AsyncPathProcessor {
DivineConfig.asyncPathfindingMaxThreads,
DivineConfig.asyncPathfindingKeepalive, TimeUnit.SECONDS,
getQueueImpl(),
new ThreadFactoryBuilder()
.setNameFormat(THREAD_PREFIX + " Thread - %d")
.setPriority(Thread.NORM_PRIORITY - 2)
.build(),
new NamedAgnosticThreadFactory<>(THREAD_PREFIX, TickThread::new, Thread.NORM_PRIORITY - 2),
new RejectedTaskHandler()
);

View File

@@ -2,10 +2,10 @@ package org.bxteam.divinemc.entity.tracking;
import ca.spottedleaf.moonrise.common.list.ReferenceList;
import ca.spottedleaf.moonrise.common.misc.NearbyPlayers;
import ca.spottedleaf.moonrise.common.util.TickThread;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup;
import ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
@@ -13,6 +13,7 @@ import net.minecraft.world.entity.Entity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bxteam.divinemc.DivineConfig;
import org.bxteam.divinemc.util.NamedAgnosticThreadFactory;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -26,7 +27,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class MultithreadedTracker {
private static final String THREAD_PREFIX = "DivineMC Async Tracker";
private static final String THREAD_PREFIX = "Async Tracker";
private static final Logger LOGGER = LogManager.getLogger(THREAD_PREFIX);
private static long lastWarnMillis = System.currentTimeMillis();
@@ -148,11 +149,7 @@ public class MultithreadedTracker {
}
private static @NotNull ThreadFactory getThreadFactory() {
return new ThreadFactoryBuilder()
.setThreadFactory(MultithreadedTrackerThread::new)
.setNameFormat(THREAD_PREFIX + " Thread - %d")
.setPriority(Thread.NORM_PRIORITY - 2)
.build();
return new NamedAgnosticThreadFactory<>(THREAD_PREFIX, TickThread::new, Thread.NORM_PRIORITY - 2);
}
private static @NotNull RejectedExecutionHandler getRejectedPolicy() {

View File

@@ -1,6 +1,7 @@
package org.bxteam.divinemc.server;
import ca.spottedleaf.moonrise.common.util.TickThread;
import org.bxteam.divinemc.spark.ThreadDumperRegistry;
import java.util.concurrent.ThreadFactory;
public class ServerLevelTickExecutorThreadFactory implements ThreadFactory {
@@ -8,6 +9,7 @@ public class ServerLevelTickExecutorThreadFactory implements ThreadFactory {
public ServerLevelTickExecutorThreadFactory(String worldName) {
this.worldName = worldName;
ThreadDumperRegistry.REGISTRY.add("serverlevel-tick-worker [" + worldName + "]");
}
@Override

View File

@@ -1,27 +1,176 @@
package org.bxteam.divinemc.spark;
import me.lucko.spark.paper.PaperSparkPlugin;
import me.lucko.spark.paper.PaperClassSourceLookup;
import me.lucko.spark.paper.PaperCommandSender;
import me.lucko.spark.paper.PaperPlatformInfo;
import me.lucko.spark.paper.PaperPlayerPingProvider;
import me.lucko.spark.paper.PaperTickHook;
import me.lucko.spark.paper.PaperTickReporter;
import me.lucko.spark.paper.PaperWorldInfoProvider;
import me.lucko.spark.paper.api.Compatibility;
import me.lucko.spark.paper.api.PaperClassLookup;
import me.lucko.spark.paper.api.PaperScheduler;
import me.lucko.spark.paper.api.PaperSparkModule;
import me.lucko.spark.paper.common.SparkPlatform;
import me.lucko.spark.paper.common.SparkPlugin;
import me.lucko.spark.paper.common.monitor.ping.PlayerPingProvider;
import me.lucko.spark.paper.common.platform.PlatformInfo;
import me.lucko.spark.paper.common.platform.serverconfig.ServerConfigProvider;
import me.lucko.spark.paper.common.platform.world.WorldInfoProvider;
import me.lucko.spark.paper.common.sampler.ThreadDumper;
import me.lucko.spark.paper.common.sampler.source.ClassSourceLookup;
import me.lucko.spark.paper.common.sampler.source.SourceMetadata;
import me.lucko.spark.paper.common.tick.TickHook;
import me.lucko.spark.paper.common.tick.TickReporter;
import me.lucko.spark.paper.common.util.classfinder.ClassFinder;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class DivineSparkPlugin extends PaperSparkPlugin {
@NotNull
public static DivineSparkPlugin create(Compatibility ignoredCompatibility, Server server, Logger logger, PaperScheduler scheduler, PaperClassLookup classLookup) {
public class DivineSparkPlugin implements PaperSparkModule, SparkPlugin {
private final Server server;
private final Logger logger;
private final PaperScheduler scheduler;
private final PaperClassLookup classLookup;
private final PaperTickHook tickHook;
private final PaperTickReporter tickReporter;
private final ThreadDumper gameThreadDumper;
private final SparkPlatform platform;
public DivineSparkPlugin(Server server, Logger logger, PaperScheduler scheduler, PaperClassLookup classLookup) {
this.server = server;
this.logger = logger;
this.scheduler = scheduler;
this.classLookup = classLookup;
this.tickHook = new PaperTickHook();
this.tickReporter = new PaperTickReporter();
this.gameThreadDumper = new ThreadDumperRegistry();
this.platform = new SparkPlatform(this);
}
public static @NotNull PaperSparkModule create(Compatibility compatibility, Server server, Logger logger, PaperScheduler scheduler, PaperClassLookup classLookup) {
return new DivineSparkPlugin(server, logger, scheduler, classLookup);
}
public DivineSparkPlugin(Server server, Logger logger, PaperScheduler scheduler, PaperClassLookup classLookup) {
super(server, logger, scheduler, classLookup);
public void enable() {
this.platform.enable();
}
public void disable() {
this.platform.disable();
}
public void executeCommand(CommandSender sender, String[] args) {
this.platform.executeCommand(new PaperCommandSender(sender), args);
}
public List<String> tabComplete(CommandSender sender, String[] args) {
return this.platform.tabCompleteCommand(new PaperCommandSender(sender), args);
}
public boolean hasPermission(CommandSender sender) {
return this.platform.hasPermissionForAnyCommand(new PaperCommandSender(sender));
}
public Collection<String> getPermissions() {
return this.platform.getAllSparkPermissions();
}
public void onServerTickStart() {
this.tickHook.onTick();
}
public void onServerTickEnd(double duration) {
this.tickReporter.onTick(duration);
}
public String getVersion() {
return "1.10.119";
}
public Path getPluginDirectory() {
return this.server.getPluginsFolder().toPath().resolve("spark");
}
public String getCommandName() {
return "spark";
}
public Stream<PaperCommandSender> getCommandSenders() {
return Stream.concat(this.server.getOnlinePlayers().stream(), Stream.of(this.server.getConsoleSender()))
.map((x$0) -> new PaperCommandSender(x$0));
}
public void executeAsync(Runnable task) {
this.scheduler.executeAsync(task);
}
public void executeSync(Runnable task) {
this.scheduler.executeSync(task);
}
public void log(Level level, String msg) {
this.logger.log(level, msg);
}
public void log(Level level, String msg, Throwable throwable) {
this.logger.log(level, msg, throwable);
}
public ThreadDumper getDefaultThreadDumper() {
return this.gameThreadDumper;
}
public TickHook createTickHook() {
return this.tickHook;
}
public TickReporter createTickReporter() {
return this.tickReporter;
}
public ClassSourceLookup createClassSourceLookup() {
return new PaperClassSourceLookup();
}
public ClassFinder createClassFinder() {
return (className) -> {
try {
return this.classLookup.lookup(className);
} catch (Exception var3) {
return null;
}
};
}
public Collection<SourceMetadata> getKnownSources() {
return SourceMetadata.gather(Arrays.asList(this.server.getPluginManager().getPlugins()), Plugin::getName, (plugin) -> plugin.getPluginMeta()
.getVersion(), (plugin) -> String.join(", ", plugin.getPluginMeta()
.getAuthors()), (plugin) -> plugin.getPluginMeta().getDescription());
}
public PlayerPingProvider createPlayerPingProvider() {
return new PaperPlayerPingProvider(this.server);
}
@Override
public ServerConfigProvider createServerConfigProvider() {
return new DivineServerConfigProvider();
}
public WorldInfoProvider createWorldInfoProvider() {
return new PaperWorldInfoProvider(this.server);
}
public PlatformInfo getPlatformInfo() {
return PaperPlatformInfo.INSTANCE;
}
}

View File

@@ -0,0 +1,44 @@
package org.bxteam.divinemc.spark;
import me.lucko.spark.paper.common.sampler.ThreadDumper;
import me.lucko.spark.paper.common.util.ThreadFinder;
import me.lucko.spark.paper.proto.SparkSamplerProtos;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.Objects;
import java.util.concurrent.ConcurrentLinkedQueue;
public final class ThreadDumperRegistry implements ThreadDumper {
public static final ConcurrentLinkedQueue<String> REGISTRY = new ConcurrentLinkedQueue<>();
private static final int STACK_TRACE_DEPTH = 10;
private final ThreadFinder threadFinder = new ThreadFinder();
@Override
public ThreadInfo[] dumpThreads(final ThreadMXBean threadMXBean) {
return this.threadFinder.getThreads()
.filter(thread -> isThreadIncluded(thread.threadId(), thread.getName()))
.map(thread -> threadMXBean.getThreadInfo(thread.threadId(), STACK_TRACE_DEPTH))
.filter(Objects::nonNull)
.toArray(ThreadInfo[]::new);
}
@Override
public boolean isThreadIncluded(long threadId, String threadName) {
for (final String prefix : REGISTRY) {
if (threadName.startsWith(prefix)) {
return true;
}
}
return false;
}
@Override
public SparkSamplerProtos.SamplerMetadata.ThreadDumper getMetadata() {
return SparkSamplerProtos.SamplerMetadata.ThreadDumper.newBuilder()
.setType(SparkSamplerProtos.SamplerMetadata.ThreadDumper.Type.SPECIFIC)
.addAllPatterns(REGISTRY)
.build();
}
}

View File

@@ -3,6 +3,7 @@ package org.bxteam.divinemc.util;
import com.mojang.logging.LogUtils;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import org.bxteam.divinemc.spark.ThreadDumperRegistry;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@@ -19,6 +20,7 @@ public class NamedAgnosticThreadFactory<T extends Thread> implements ThreadFacto
this.priority = priority;
this.group = Thread.currentThread().getThreadGroup();
this.namePrefix = name + "-";
ThreadDumperRegistry.REGISTRY.add(namePrefix);
}
@Override