mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
Drop Close region files patch, doesn't add any value.
Upon further knowledge of the system, it is known that region files are closing properly, as well as this didn't help native memory use anyways. This patch also caused issues compiling on a newer JDK being able to release the jar to java 8 users.
This commit is contained in:
parent
700070c5e6
commit
f0409edcd7
40 changed files with 8 additions and 92 deletions
|
@ -1,84 +0,0 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
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<ByteBuffer> 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();
|
|
@ -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 {
|
|
@ -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 {
|
|
@ -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<TickTas
|
|
@ -101,7 +101,7 @@ index b19bbbbc81376177751396a2de9452ce1f84c06b..296b41bf36ee1ace5bd9db2b810bf926
|
|||
public Material getMaterial() {
|
||||
return this.getBlock().k(this);
|
||||
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
||||
index e82b8b9a4dbc9a595df7d8e56596a93fde7b687a..561b42472261a973fea6344d76ca7ea1993aee27 100644
|
||||
index 5535f98ac0ec1668b162cb652e88a122bcadac0c..9de505d01fa30f31f2528265cb0d6af7ff59961f 100644
|
||||
--- a/src/main/java/net/minecraft/server/World.java
|
||||
+++ b/src/main/java/net/minecraft/server/World.java
|
||||
@@ -342,6 +342,10 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
|
@ -31,7 +31,7 @@ index ef2a496eda45ae5ee8fe52ef09e77c2906069d2e..6a0d70033b4eec384795b5cccd76bce2
|
|||
} else {
|
||||
if (entityhuman.getWorld().isClientSide) {
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
index 45944cad9436dd309a6323f80a0c4c2f2bb6367b..947a514ea601af46ea27ff3c47eb30b795ba03c7 100644
|
||||
index 1f9d231fb93e30286205f7a0a4c898a0e153bd95..d52fbda79fe1c52d3ddb53c0f1c1f521d7620702 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
@@ -612,7 +612,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
@ -12,7 +12,7 @@ to the client, so that it doesn't attempt to calculate them.
|
|||
This mitigates the frametime impact to a minimum (but it's still there).
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
||||
index fc332dd824ecb4237edbf2974cfe036309d9765c..f22c37be6e779e569db6016b633872fefa20b1a2 100644
|
||||
index c80a55ee53eac128c94d74b78c5641854e974750..d7beb47d9e07707e5875c50932dfe4698cb6ad72 100644
|
||||
--- a/src/main/java/net/minecraft/server/Chunk.java
|
||||
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
||||
@@ -277,7 +277,7 @@ public class Chunk implements IChunkAccess {
|
||||
|
@ -25,7 +25,7 @@ index fc332dd824ecb4237edbf2974cfe036309d9765c..f22c37be6e779e569db6016b633872fe
|
|||
Object temp = backingSet[index];
|
||||
if (!(temp instanceof EntityPlayer)) {
|
||||
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
|
||||
index b7b06e082e59f8518be2036637385c7710d524ea..71da9f00b8a969e84414066fb1852cecb9440e14 100644
|
||||
index f6df85c6bf27bfa7a16967259a6016c9473201a5..4dcb111c704a495c214827f4ef554fb8e65ca2da 100644
|
||||
--- a/src/main/java/net/minecraft/server/ChunkSection.java
|
||||
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
|
||||
@@ -99,6 +99,7 @@ public class ChunkSection {
|
|
@ -11,7 +11,7 @@ This will drastically cut down on packet sending cost for worlds with
|
|||
lots of players in them.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
||||
index 9b726de6daeba42120f3a948fbdcf080d0e72917..ada082e67ac8a3e79bab5b360f09c9402f683b86 100644
|
||||
index 3061d856d52776ebc2eed6541238c8a760d7c536..7bb46cc7c6fefc04a8faf7766f31e4780a9c7e10 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
||||
@@ -1027,11 +1027,30 @@ public abstract class PlayerList {
|
Loading…
Reference in a new issue