diff --git a/Spigot-Server-Patches/0499-Cleanup-Region-Files-Direct-Memory-on-close.patch b/Spigot-Server-Patches/0499-Cleanup-Region-Files-Direct-Memory-on-close.patch deleted file mode 100644 index 6fbf1686d9..0000000000 --- a/Spigot-Server-Patches/0499-Cleanup-Region-Files-Direct-Memory-on-close.patch +++ /dev/null @@ -1,84 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -Date: Mon, 4 May 2020 00:38:13 -0400 -Subject: [PATCH] Cleanup Region Files Direct Memory on close - -Mojang was semi leaking native memory here by relying on finalizers -to clean up the direct memory. - -Finalizers have no guarantee on when they will be ran, and since this is -old generation memory, it might be a while before its called. - -diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java -index df728e2c0a2bf660a91e0bd6342c4b4b1471dcb7..20927d55c6700f66f0931bfe3d20fd8959c87989 100644 ---- a/src/main/java/net/minecraft/server/RegionFile.java -+++ b/src/main/java/net/minecraft/server/RegionFile.java -@@ -30,7 +30,7 @@ public class RegionFile implements AutoCloseable { - private final FileChannel dataFile; - private final java.nio.file.Path d; - private final RegionFileCompression e; -- private final ByteBuffer f; -+ private final ByteBuffer f; private ByteBuffer getFileBuffer() { return f; } // Paper - clean up direct buffers on close - private final IntBuffer g; - private final IntBuffer h; - private final RegionFileBitSet freeSectors; -@@ -403,10 +403,59 @@ public class RegionFile implements AutoCloseable { - } - } finally { // Paper start - Prevent regionfiles from being closed during use - this.fileLock.unlock(); -+ if (getFileBuffer().isDirect()) cleanDirectByteBuffer(getFileBuffer()); // Paper - clean up direct buffers on close - } - } // Paper end - - } -+ // Paper start -+ private static int getVersion() { -+ String version = System.getProperty("java.version"); -+ if(version.startsWith("1.")) { -+ version = version.substring(2, 3); -+ } else { -+ int dot = version.indexOf("."); -+ if(dot != -1) { version = version.substring(0, dot); } -+ } return Integer.parseInt(version); -+ } -+ static java.lang.reflect.Method unsafeClean; -+ static sun.misc.Unsafe unsafe = com.destroystokyo.paper.utils.UnsafeUtils.getUnsafe(); -+ static java.util.function.Consumer cleaner; -+ static { -+ try { -+ if (unsafe != null) { -+ unsafeClean = unsafe.getClass().getMethod("invokeCleaner", ByteBuffer.class); -+ if (unsafeClean != null) { -+ cleaner = (buf) -> { -+ try { -+ unsafeClean.invoke(unsafe, buf); -+ } catch (Exception ex) { -+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ex); -+ } -+ }; -+ LOGGER.info("[RegionFile] Using Java 9+ invokeCleaner DirectByteBuffer cleanup method"); -+ } -+ } -+ } catch (java.lang.NoSuchMethodException e) {} -+ if (cleaner == null && getVersion() <= 8) { -+ cleaner = (buf) -> { -+ ((sun.nio.ch.DirectBuffer) buf).cleaner().clean(); -+ }; -+ LOGGER.info("[RegionFile] Using Java 8 DirectByteBuffer cleanup method"); -+ } -+ } -+ public static void cleanDirectByteBuffer(ByteBuffer toBeDestroyed) { -+ try { -+ if (cleaner != null) { -+ cleaner.accept(toBeDestroyed); -+ } -+ } catch (Exception ex) { -+ LOGGER.warn("Failed automatically cleaning DirectByteBuffer"); -+ ex.printStackTrace(); -+ cleaner = null; -+ } -+ } -+ // Paper end - - private void c() throws IOException { - int i = (int) this.dataFile.size(); diff --git a/Spigot-Server-Patches/0500-Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch b/Spigot-Server-Patches/0499-Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch similarity index 100% rename from Spigot-Server-Patches/0500-Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch rename to Spigot-Server-Patches/0499-Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch diff --git a/Spigot-Server-Patches/0501-Implement-Mob-Goal-API.patch b/Spigot-Server-Patches/0500-Implement-Mob-Goal-API.patch similarity index 100% rename from Spigot-Server-Patches/0501-Implement-Mob-Goal-API.patch rename to Spigot-Server-Patches/0500-Implement-Mob-Goal-API.patch diff --git a/Spigot-Server-Patches/0502-Use-distance-map-to-optimise-entity-tracker.patch b/Spigot-Server-Patches/0501-Use-distance-map-to-optimise-entity-tracker.patch similarity index 100% rename from Spigot-Server-Patches/0502-Use-distance-map-to-optimise-entity-tracker.patch rename to Spigot-Server-Patches/0501-Use-distance-map-to-optimise-entity-tracker.patch diff --git a/Spigot-Server-Patches/0503-Optimize-isOutsideRange-to-use-distance-maps.patch b/Spigot-Server-Patches/0502-Optimize-isOutsideRange-to-use-distance-maps.patch similarity index 100% rename from Spigot-Server-Patches/0503-Optimize-isOutsideRange-to-use-distance-maps.patch rename to Spigot-Server-Patches/0502-Optimize-isOutsideRange-to-use-distance-maps.patch diff --git a/Spigot-Server-Patches/0504-Stop-copy-on-write-operations-for-updating-light-dat.patch b/Spigot-Server-Patches/0503-Stop-copy-on-write-operations-for-updating-light-dat.patch similarity index 100% rename from Spigot-Server-Patches/0504-Stop-copy-on-write-operations-for-updating-light-dat.patch rename to Spigot-Server-Patches/0503-Stop-copy-on-write-operations-for-updating-light-dat.patch diff --git a/Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch b/Spigot-Server-Patches/0504-No-Tick-view-distance-implementation.patch similarity index 99% rename from Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch rename to Spigot-Server-Patches/0504-No-Tick-view-distance-implementation.patch index f8260ddb57..9b24616353 100644 --- a/Spigot-Server-Patches/0505-No-Tick-view-distance-implementation.patch +++ b/Spigot-Server-Patches/0504-No-Tick-view-distance-implementation.patch @@ -37,7 +37,7 @@ index 4612697569fd6e3683b0e58453b61a9a8d077229..5c8a946d5c895fc2622c7df656cc462c + } } diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index d73987ffc416f47eb6231013a76420bc71c34f0e..fc332dd824ecb4237edbf2974cfe036309d9765c 100644 +index cf86ce24e12068d6ff7ae43cb1fd6fe665c24932..c80a55ee53eac128c94d74b78c5641854e974750 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -245,7 +245,51 @@ public class Chunk implements IChunkAccess { diff --git a/Spigot-Server-Patches/0506-Add-villager-reputation-API.patch b/Spigot-Server-Patches/0505-Add-villager-reputation-API.patch similarity index 100% rename from Spigot-Server-Patches/0506-Add-villager-reputation-API.patch rename to Spigot-Server-Patches/0505-Add-villager-reputation-API.patch diff --git a/Spigot-Server-Patches/0507-Fix-Light-Command.patch b/Spigot-Server-Patches/0506-Fix-Light-Command.patch similarity index 100% rename from Spigot-Server-Patches/0507-Fix-Light-Command.patch rename to Spigot-Server-Patches/0506-Fix-Light-Command.patch diff --git a/Spigot-Server-Patches/0508-Fix-CraftServer.unloadWorld-Leak.patch b/Spigot-Server-Patches/0507-Fix-CraftServer.unloadWorld-Leak.patch similarity index 100% rename from Spigot-Server-Patches/0508-Fix-CraftServer.unloadWorld-Leak.patch rename to Spigot-Server-Patches/0507-Fix-CraftServer.unloadWorld-Leak.patch diff --git a/Spigot-Server-Patches/0509-Fix-PotionEffect-ignores-icon-flag.patch b/Spigot-Server-Patches/0508-Fix-PotionEffect-ignores-icon-flag.patch similarity index 100% rename from Spigot-Server-Patches/0509-Fix-PotionEffect-ignores-icon-flag.patch rename to Spigot-Server-Patches/0508-Fix-PotionEffect-ignores-icon-flag.patch diff --git a/Spigot-Server-Patches/0510-Optimize-brigadier-child-sorting-performance.patch b/Spigot-Server-Patches/0509-Optimize-brigadier-child-sorting-performance.patch similarity index 100% rename from Spigot-Server-Patches/0510-Optimize-brigadier-child-sorting-performance.patch rename to Spigot-Server-Patches/0509-Optimize-brigadier-child-sorting-performance.patch diff --git a/Spigot-Server-Patches/0511-MC-183249-Don-t-generate-Carving-Masks-BitSet-unless.patch b/Spigot-Server-Patches/0510-MC-183249-Don-t-generate-Carving-Masks-BitSet-unless.patch similarity index 96% rename from Spigot-Server-Patches/0511-MC-183249-Don-t-generate-Carving-Masks-BitSet-unless.patch rename to Spigot-Server-Patches/0510-MC-183249-Don-t-generate-Carving-Masks-BitSet-unless.patch index 590e026afe..613fea34fe 100644 --- a/Spigot-Server-Patches/0511-MC-183249-Don-t-generate-Carving-Masks-BitSet-unless.patch +++ b/Spigot-Server-Patches/0510-MC-183249-Don-t-generate-Carving-Masks-BitSet-unless.patch @@ -28,7 +28,7 @@ index fa893b14bcef9bab6891dea2c4375b09d74ac038..e625842e524f18e469f7695b27d52d4d nbttagcompound1.set("CarvingMasks", nbttagcompound3); diff --git a/src/main/java/net/minecraft/server/ProtoChunk.java b/src/main/java/net/minecraft/server/ProtoChunk.java -index deb7fb090196c4a33c0bb224f1c4e899aa3cd8c3..9223ef9545be4a87b421e25ebe3f5b7ad72c4726 100644 +index a78b240621e0407fff67b018224c39fc4f97f4e5..2eb14bbf888f5e5601441743cb7642da6ee1249c 100644 --- a/src/main/java/net/minecraft/server/ProtoChunk.java +++ b/src/main/java/net/minecraft/server/ProtoChunk.java @@ -43,7 +43,8 @@ public class ProtoChunk implements IChunkAccess { diff --git a/Spigot-Server-Patches/0512-Don-t-toString-block-unless-actually-showing-the-mes.patch b/Spigot-Server-Patches/0511-Don-t-toString-block-unless-actually-showing-the-mes.patch similarity index 100% rename from Spigot-Server-Patches/0512-Don-t-toString-block-unless-actually-showing-the-mes.patch rename to Spigot-Server-Patches/0511-Don-t-toString-block-unless-actually-showing-the-mes.patch diff --git a/Spigot-Server-Patches/0513-Implement-JellySquid-s-Entity-Collision-optimisation.patch b/Spigot-Server-Patches/0512-Implement-JellySquid-s-Entity-Collision-optimisation.patch similarity index 100% rename from Spigot-Server-Patches/0513-Implement-JellySquid-s-Entity-Collision-optimisation.patch rename to Spigot-Server-Patches/0512-Implement-JellySquid-s-Entity-Collision-optimisation.patch diff --git a/Spigot-Server-Patches/0514-Remove-some-Streams-usage-in-Entity-Collision.patch b/Spigot-Server-Patches/0513-Remove-some-Streams-usage-in-Entity-Collision.patch similarity index 100% rename from Spigot-Server-Patches/0514-Remove-some-Streams-usage-in-Entity-Collision.patch rename to Spigot-Server-Patches/0513-Remove-some-Streams-usage-in-Entity-Collision.patch diff --git a/Spigot-Server-Patches/0515-Ensure-Entity-AABB-s-are-never-invalid.patch b/Spigot-Server-Patches/0514-Ensure-Entity-AABB-s-are-never-invalid.patch similarity index 100% rename from Spigot-Server-Patches/0515-Ensure-Entity-AABB-s-are-never-invalid.patch rename to Spigot-Server-Patches/0514-Ensure-Entity-AABB-s-are-never-invalid.patch diff --git a/Spigot-Server-Patches/0516-Potential-bed-API.patch b/Spigot-Server-Patches/0515-Potential-bed-API.patch similarity index 100% rename from Spigot-Server-Patches/0516-Potential-bed-API.patch rename to Spigot-Server-Patches/0515-Potential-bed-API.patch diff --git a/Spigot-Server-Patches/0517-Wait-for-Async-Tasks-during-shutdown.patch b/Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch similarity index 96% rename from Spigot-Server-Patches/0517-Wait-for-Async-Tasks-during-shutdown.patch rename to Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch index 1144778af6..90826ec509 100644 --- a/Spigot-Server-Patches/0517-Wait-for-Async-Tasks-during-shutdown.patch +++ b/Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch @@ -10,7 +10,7 @@ Adds a 5 second grace period for any async tasks to finish and warns if any are still running after that delay just as reload does. diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index d1a1c4a89d7148c58d1e60843f233f026a6d9f0e..b853d50a4a23de87a87d674cd7e01484d750c352 100644 +index a70492f617408597230a39e49fa311822171851d..a03dc230521673a21872d70836903a2c2d15220e 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -746,6 +746,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant