From e170ab7fceff2112a16b47fa318a58725eec4f27 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 25 Jul 2019 18:36:26 -0700 Subject: [PATCH] Do not schedule to main for getChunkImmediately type calls (#2362) They are MT-Safe already. These changes reduce deadlock chances given these calls are used in Entity#isValid(), and plugins check this in packet handling... --- ...tually-Limit-Natural-Spawns-To-Limit.patch | 2 +- .../Fix-World-isChunkGenerated-calls.patch | 19 ++---------- Spigot-Server-Patches/MC-Utils.patch | 29 +++---------------- Spigot-Server-Patches/Timings-v2.patch | 2 +- 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/Spigot-Server-Patches/Actually-Limit-Natural-Spawns-To-Limit.patch b/Spigot-Server-Patches/Actually-Limit-Natural-Spawns-To-Limit.patch index 19156c15f0..e5c2b2156f 100644 --- a/Spigot-Server-Patches/Actually-Limit-Natural-Spawns-To-Limit.patch +++ b/Spigot-Server-Patches/Actually-Limit-Natural-Spawns-To-Limit.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Actually-Limit-Natural-Spawns-To-Limit diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java -index 744fa825e6..3b7288c6cb 100644 +index a58cfc14bb..26216fe72c 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { diff --git a/Spigot-Server-Patches/Fix-World-isChunkGenerated-calls.patch b/Spigot-Server-Patches/Fix-World-isChunkGenerated-calls.patch index 3ef2207df9..c560f57af2 100644 --- a/Spigot-Server-Patches/Fix-World-isChunkGenerated-calls.patch +++ b/Spigot-Server-Patches/Fix-World-isChunkGenerated-calls.patch @@ -8,7 +8,7 @@ This patch also adds a chunk status cache on region files (note that its only purpose is to cache the status on DISK) diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java -index 220cd197fa..775b5f7fe3 100644 +index 9765eaf24c..d714b8d01b 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { @@ -27,24 +27,9 @@ index 220cd197fa..775b5f7fe3 100644 + + @Nullable + public IChunkAccess getChunkAtImmediately(int x, int z) { -+ if (Thread.currentThread() != this.serverThread) { -+ return CompletableFuture.supplyAsync(() -> { -+ return this.getChunkAtImmediately(x, z); -+ }, this.serverThreadQueue).join(); -+ } -+ + long k = ChunkCoordIntPair.pair(x, z); + -+ IChunkAccess ichunkaccess; -+ -+ for (int l = 0; l < 4; ++l) { -+ if (k == this.cachePos[l]) { -+ ichunkaccess = this.cacheChunk[l]; -+ if (ichunkaccess != null) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime -+ return ichunkaccess; -+ } -+ } -+ } ++ // Note: Bypass cache to make this MT-Safe + + PlayerChunk playerChunk = this.getChunk(k); + if (playerChunk == null) { diff --git a/Spigot-Server-Patches/MC-Utils.patch b/Spigot-Server-Patches/MC-Utils.patch index a744e6e601..545f2b7e9d 100644 --- a/Spigot-Server-Patches/MC-Utils.patch +++ b/Spigot-Server-Patches/MC-Utils.patch @@ -167,7 +167,7 @@ index 857b2f8868..bbf136614c 100644 } diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java -index 36a89817f8..dd6e69a0f1 100644 +index 36a89817f8..baf3bd461b 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { @@ -178,24 +178,9 @@ index 36a89817f8..dd6e69a0f1 100644 + // Note: Partially copied from the getChunkAt method below + @Nullable + public Chunk getChunkAtIfCachedImmediately(int x, int z) { -+ if (Thread.currentThread() != this.serverThread) { -+ return CompletableFuture.supplyAsync(() -> { -+ return this.getChunkAtIfCachedImmediately(x, z); -+ }, this.serverThreadQueue).join(); -+ } -+ + long k = ChunkCoordIntPair.pair(x, z); + -+ IChunkAccess ichunkaccess; -+ -+ for (int l = 0; l < 4; ++l) { -+ if (k == this.cachePos[l] && ChunkStatus.FULL == this.cacheStatus[l]) { -+ ichunkaccess = this.cacheChunk[l]; -+ if (ichunkaccess instanceof Chunk) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime -+ return (Chunk)ichunkaccess; -+ } -+ } -+ } ++ // Note: Bypass cache to make this MT-Safe + + PlayerChunk playerChunk = this.getChunk(k); + if (playerChunk == null) { @@ -207,15 +192,9 @@ index 36a89817f8..dd6e69a0f1 100644 + + @Nullable + public Chunk getChunkAtIfLoadedImmediately(int x, int z) { -+ if (Thread.currentThread() != this.serverThread) { -+ return CompletableFuture.supplyAsync(() -> { -+ return this.getChunkAtIfLoadedImmediately(x, z); -+ }, this.serverThreadQueue).join(); -+ } -+ + long k = ChunkCoordIntPair.pair(x, z); + -+ // Note: Bypass cache since we need to check ticket level ++ // Note: Bypass cache since we need to check ticket level, and to make this MT-Safe + + PlayerChunk playerChunk = this.getChunk(k); + if (playerChunk == null) { @@ -326,7 +305,7 @@ index 613d534aeb..f31a996aa5 100644 // CraftBukkit start - fire event setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true); diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java -index 35a67665a2..5c863860ae 100644 +index 9c3e95bbbc..dcbc4ea7e1 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity { diff --git a/Spigot-Server-Patches/Timings-v2.patch b/Spigot-Server-Patches/Timings-v2.patch index 245904791d..6b1ba72439 100644 --- a/Spigot-Server-Patches/Timings-v2.patch +++ b/Spigot-Server-Patches/Timings-v2.patch @@ -358,7 +358,7 @@ index 3ed48be382..c4d989f702 100644 } } diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java -index dd6e69a0f1..978a9f9172 100644 +index baf3bd461b..f351d021dc 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {