From 264a3545fe479b38a339f6aafacf1c1962dc0c51 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 30 May 2019 20:19:06 -0700 Subject: [PATCH] Fix memory leak if the server is constantly overloaded (#2109) --- ...more-aggressive-in-the-chunk-unload-.patch | 24 +++++++++++++++++-- ...8-PlayerNaturallySpawnCreaturesEvent.patch | 6 ++--- ...ies-option-to-debug-dupe-uuid-issues.patch | 14 +++++------ .../0392-Duplicate-UUID-Resolve-Option.patch | 16 ++++++------- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Spigot-Server-Patches/0150-Make-targetSize-more-aggressive-in-the-chunk-unload-.patch b/Spigot-Server-Patches/0150-Make-targetSize-more-aggressive-in-the-chunk-unload-.patch index b5c6073551..97698b2991 100644 --- a/Spigot-Server-Patches/0150-Make-targetSize-more-aggressive-in-the-chunk-unload-.patch +++ b/Spigot-Server-Patches/0150-Make-targetSize-more-aggressive-in-the-chunk-unload-.patch @@ -1,13 +1,22 @@ -From 49a84ac1c81e92f2090e5438cfbbf1f3be6d0637 Mon Sep 17 00:00:00 2001 +From 78203ccab7cc30370850c42578162e394a7172fb Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 7 Feb 2017 16:55:35 -0600 Subject: [PATCH] Make targetSize more aggressive in the chunk unload queue diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java -index ba59c561e8..6a49251cc7 100644 +index ff32fe32ce..74a1b4a852 100644 --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java +@@ -81,7 +81,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { + this.v = new AtomicInteger(); + this.playerMap = new PlayerMap(); + this.trackedEntities = new Int2ObjectOpenHashMap(); +- this.A = Queues.newConcurrentLinkedQueue(); ++ this.A = new com.destroystokyo.paper.utils.CachedSizeConcurrentLinkedQueue<>(); // Paper + this.definedStructureManager = definedstructuremanager; + this.x = worldserver.getWorldProvider().getDimensionManager().a(file); + this.world = worldserver; @@ -324,7 +324,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { // Spigot start org.spigotmc.SlackActivityAccountant activityAccountant = this.world.getMinecraftServer().slackActivityAccountant; @@ -17,6 +26,17 @@ index ba59c561e8..6a49251cc7 100644 // Spigot end while (longiterator.hasNext()) { // Spigot long j = longiterator.nextLong(); +@@ -346,7 +346,9 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { + + Runnable runnable; + +- while (booleansupplier.getAsBoolean() && (runnable = (Runnable) this.A.poll()) != null) { ++ int queueTarget = Math.min(this.A.size() - 100, (int) (this.A.size() * UNLOAD_QUEUE_RESIZE_FACTOR)); // Paper - Target this queue as well ++ ++ while ((booleansupplier.getAsBoolean() || this.A.size() > queueTarget) && (runnable = (Runnable) this.A.poll()) != null) { // Paper - Target this queue as well + runnable.run(); + } + -- 2.21.0 diff --git a/Spigot-Server-Patches/0198-PlayerNaturallySpawnCreaturesEvent.patch b/Spigot-Server-Patches/0198-PlayerNaturallySpawnCreaturesEvent.patch index a17fb1bef9..ca972b2f39 100644 --- a/Spigot-Server-Patches/0198-PlayerNaturallySpawnCreaturesEvent.patch +++ b/Spigot-Server-Patches/0198-PlayerNaturallySpawnCreaturesEvent.patch @@ -1,4 +1,4 @@ -From e27ae28fa9c01ce1867832c3452849b3b05a7290 Mon Sep 17 00:00:00 2001 +From 435506a861b923a8f536856f51c269544dae2e7e Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 14 Jan 2018 17:36:02 -0500 Subject: [PATCH] PlayerNaturallySpawnCreaturesEvent @@ -9,10 +9,10 @@ from triggering monster spawns on a server. Also a highly more effecient way to blanket block spawns in a world diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java -index c2f442051..5d6d6a5a5 100644 +index 74a1b4a852..81b82aeeef 100644 --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java -@@ -762,11 +762,17 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { +@@ -764,11 +764,17 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange; chunkRange = (chunkRange > 8) ? 8 : chunkRange; diff --git a/Spigot-Server-Patches/0257-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch b/Spigot-Server-Patches/0257-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch index 59b395cf22..1b48f1b318 100644 --- a/Spigot-Server-Patches/0257-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch +++ b/Spigot-Server-Patches/0257-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch @@ -1,4 +1,4 @@ -From 47ed7330a0622394ccfddab469d7e2036c27e100 Mon Sep 17 00:00:00 2001 +From 166a535e26b549f2bcfd27f34e729db7badcf875 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 08:25:40 -0400 Subject: [PATCH] Add Debug Entities option to debug dupe uuid issues @@ -6,7 +6,7 @@ Subject: [PATCH] Add Debug Entities option to debug dupe uuid issues Add -Ddebug.entities=true to your JVM flags to gain more information diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index 6b33c1c41..c97421721 100644 +index 6b33c1c418..c97421721e 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -75,6 +75,8 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -19,10 +19,10 @@ index 6b33c1c41..c97421721 100644 if (bukkitEntity == null) { bukkitEntity = CraftEntity.getEntity(world.getServer(), this); diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java -index 5d6d6a5a5..45ba357f8 100644 +index 81b82aeeef..446bdb0216 100644 --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java -@@ -924,6 +924,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { +@@ -926,6 +926,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { } else { PlayerChunkMap.EntityTracker playerchunkmap_entitytracker = new PlayerChunkMap.EntityTracker(entity, i, j, entitytypes.isDeltaTracking()); @@ -30,7 +30,7 @@ index 5d6d6a5a5..45ba357f8 100644 this.trackedEntities.put(entity.getId(), playerchunkmap_entitytracker); playerchunkmap_entitytracker.track(this.world.getPlayers()); if (entity instanceof EntityPlayer) { -@@ -966,7 +967,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { +@@ -968,7 +969,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { if (playerchunkmap_entitytracker1 != null) { playerchunkmap_entitytracker1.a(); } @@ -40,7 +40,7 @@ index 5d6d6a5a5..45ba357f8 100644 protected void g() { diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java -index d7229f100..5cf3aea4f 100644 +index d7229f100b..5cf3aea4fc 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -68,6 +68,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose @@ -52,7 +52,7 @@ index d7229f100..5cf3aea4f 100644 public boolean captureBlockStates = false; public boolean captureTreeGeneration = false; diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java -index 8cffbabfb..f6ba51d14 100644 +index 8cffbabfb6..f6ba51d14a 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -69,6 +69,9 @@ public class WorldServer extends World { diff --git a/Spigot-Server-Patches/0392-Duplicate-UUID-Resolve-Option.patch b/Spigot-Server-Patches/0392-Duplicate-UUID-Resolve-Option.patch index 7e5db717e8..66e86fe4c0 100644 --- a/Spigot-Server-Patches/0392-Duplicate-UUID-Resolve-Option.patch +++ b/Spigot-Server-Patches/0392-Duplicate-UUID-Resolve-Option.patch @@ -1,4 +1,4 @@ -From 5d490a5bfe80403f4e89ac3d6ede504a5eb83103 Mon Sep 17 00:00:00 2001 +From 5e0eb7ee9051bfaa6998a4393b0e59ef349662c5 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 14:27:34 -0400 Subject: [PATCH] Duplicate UUID Resolve Option @@ -33,7 +33,7 @@ But for those who are ok with leaving this inconsistent behavior, you may use WA It is recommended you regenerate the entities, as these were legit entities, and deserve your love. diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java -index ef882b897..385b3ac0c 100644 +index ef882b897f..385b3ac0ce 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -449,4 +449,43 @@ public class PaperWorldConfig { @@ -81,7 +81,7 @@ index ef882b897..385b3ac0c 100644 + } } diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index 197c0fe16..ef07f665b 100644 +index 197c0fe169..ef07f665b7 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -397,6 +397,7 @@ public class Chunk implements IChunkAccess { @@ -93,7 +93,7 @@ index 197c0fe16..ef07f665b 100644 int k = MathHelper.floor(entity.locY / 16.0D); diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index 5711cf664..fffe26939 100644 +index 50c52118b8..5fa0dc8ac5 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -2674,6 +2674,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -105,7 +105,7 @@ index 5711cf664..fffe26939 100644 this.uniqueID = uuid; this.ap = this.uniqueID.toString(); diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java -index 1362099f1..3fdb6935e 100644 +index 446bdb0216..276a365ff5 100644 --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java @@ -1,5 +1,6 @@ @@ -131,7 +131,7 @@ index 1362099f1..3fdb6935e 100644 import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; -@@ -557,12 +561,49 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { +@@ -559,12 +563,49 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { for (int j = 0; j < i; ++j) { List entityslice = aentityslice[j]; // Spigot @@ -185,7 +185,7 @@ index 1362099f1..3fdb6935e 100644 if (list == null) { list = Lists.newArrayList(new Entity[]{entity}); } else { -@@ -570,6 +611,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { +@@ -572,6 +613,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { } } } @@ -194,7 +194,7 @@ index 1362099f1..3fdb6935e 100644 if (list != null) { diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java -index e61381221..e9e5ecf74 100644 +index e61381221f..e9e5ecf747 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -2,6 +2,8 @@ package net.minecraft.server;