JDK-8176055: Fix heap dumps on Java 8u141+

In Java 8u141 (1.8.0_141-b15) and newer, the
com.sun.management.HotSpotDiagnostic::dumpHeap API has changed and now
requires all heap dumps to end with the .hprof file extension.

Before this change, servers running 8u141 would be unable to perform a
heap dump.

For more information, please see the official release notes of Java 8
Update 141, linked below.
http://www.oracle.com/technetwork/java/javase/8u141-relnotes-3720385.html
This commit is contained in:
Zach Brown 2017-07-26 20:28:56 -05:00
parent dcd4f3710f
commit c6c6b4f69a
No known key found for this signature in database
GPG Key ID: CC9DA35FC5450B76
4 changed files with 29 additions and 23 deletions

View File

@ -1,4 +1,4 @@
From 8f7a6bb066e1009c5e436852a08b4642c93d219d Mon Sep 17 00:00:00 2001
From added675968cf0fad5fedb1761ef8ea5906c8235 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Mon, 29 Feb 2016 21:02:09 -0600
Subject: [PATCH] Paper config files
@ -6,10 +6,10 @@ Subject: [PATCH] Paper config files
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
new file mode 100644
index 000000000..cd67ab2bb
index 000000000..5cdf4bbf4
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -0,0 +1,72 @@
@@ -0,0 +1,75 @@
+package com.destroystokyo.paper;
+
+import net.minecraft.server.MinecraftServer;
@ -62,10 +62,13 @@ index 000000000..cd67ab2bb
+
+ private void dumpHeap(CommandSender sender) {
+ File file = new File(new File(new File("."), "dumps"),
+ "heap-dump-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(LocalDateTime.now()) + "-server.bin");
+ "heap-dump-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(LocalDateTime.now()) + "-server.hprof");
+ Command.broadcastCommandMessage(sender, ChatColor.YELLOW + "Writing JVM heap data to " + file);
+ CraftServer.dumpHeap(file);
+ Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Heap dump complete");
+ if (CraftServer.dumpHeap(file)) {
+ Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Heap dump complete");
+ } else {
+ Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed to write heap dump, see sever log for details");
+ }
+ }
+
+ private void doReload(CommandSender sender) {
@ -370,7 +373,7 @@ index f5d387511..fd204ad7a 100644
this.world = new CraftWorld((WorldServer) this, gen, env);
this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index e21fb9bd7..d7af2c00f 100644
index e21fb9bd7..dd50d5c56 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -691,6 +691,7 @@ public final class CraftServer implements Server {
@ -397,14 +400,14 @@ index e21fb9bd7..d7af2c00f 100644
overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
int pollCount = 0;
@@ -1766,4 +1769,23 @@ public final class CraftServer implements Server {
@@ -1766,4 +1769,26 @@ public final class CraftServer implements Server {
{
return spigot;
}
+
+ // Paper start
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static void dumpHeap(File file) {
+ public static boolean dumpHeap(File file) {
+ try {
+ if (file.getParentFile() != null) {
+ file.getParentFile().mkdirs();
@ -415,8 +418,11 @@ index e21fb9bd7..d7af2c00f 100644
+ Object hotspotMBean = java.lang.management.ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", clazz);
+ java.lang.reflect.Method m = clazz.getMethod("dumpHeap", String.class, boolean.class);
+ m.invoke(hotspotMBean, file.getPath(), true);
+ return true;
+ } catch (Throwable t) {
+ Bukkit.getLogger().severe("Could not write heap to " + file);
+ t.printStackTrace();
+ return false;
+ }
+ }
+ // Paper end
@ -482,5 +488,5 @@ index 01e73eb89..0b66f5e35 100644
config.addDefault( "world-settings.default." + path, def );
return config.getString( "world-settings." + worldName + "." + path, config.getString( "world-settings.default." + path ) );
--
2.13.0
2.13.3.windows.1

View File

@ -1,4 +1,4 @@
From a1b7df898e8737d3fd84bc0285449f5407fcd847 Mon Sep 17 00:00:00 2001
From 12270cc7b873df6ca91f3342c83b225c60124ef1 Mon Sep 17 00:00:00 2001
From: William <admin@domnian.com>
Date: Fri, 18 Mar 2016 03:30:17 -0400
Subject: [PATCH] Allow Reloading of Custom Permissions
@ -6,11 +6,11 @@ Subject: [PATCH] Allow Reloading of Custom Permissions
https://github.com/PaperMC/Paper/issues/49
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 815a26284..7a2c19159 100644
index 3007a724b..e8b8e86e8 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1843,5 +1843,20 @@ public final class CraftServer implements Server {
Bukkit.getLogger().severe("Could not write heap to " + file);
@@ -1846,5 +1846,20 @@ public final class CraftServer implements Server {
return false;
}
}
+
@ -31,5 +31,5 @@ index 815a26284..7a2c19159 100644
// Paper end
}
--
2.13.0
2.13.3.windows.1

View File

@ -1,4 +1,4 @@
From da3b13a76dd03704923c2733b178dced3fb12053 Mon Sep 17 00:00:00 2001
From b287a9cb56a72f2ec109954e2b872e4a406f208c Mon Sep 17 00:00:00 2001
From: willies952002 <admin@domnian.com>
Date: Mon, 28 Nov 2016 10:21:52 -0500
Subject: [PATCH] Allow Reloading of Command Aliases
@ -6,10 +6,10 @@ Subject: [PATCH] Allow Reloading of Command Aliases
Reload the aliases stored in commands.yml
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 5a9555135..6dba269e7 100644
index 37dc16186..3d484fbcf 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1869,5 +1869,24 @@ public final class CraftServer implements Server {
@@ -1872,5 +1872,24 @@ public final class CraftServer implements Server {
});
}
}
@ -35,5 +35,5 @@ index 5a9555135..6dba269e7 100644
// Paper end
}
--
2.13.0
2.13.3.windows.1

View File

@ -1,4 +1,4 @@
From e4c4805b5122877b5bed6cfe116e0d5ee7bf3991 Mon Sep 17 00:00:00 2001
From f50ce9dfc0be01c0da8cdfa2c79a72c2aa363b35 Mon Sep 17 00:00:00 2001
From: kashike <kashike@vq.lc>
Date: Fri, 9 Jun 2017 07:24:34 -0700
Subject: [PATCH] Add configuration option to prevent player names from being
@ -20,10 +20,10 @@ index 28917f63d..f4b237034 100644
+ }
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 6dba269e7..3e5421932 100644
index 3d484fbcf..3c6f46057 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1888,5 +1888,10 @@ public final class CraftServer implements Server {
@@ -1891,5 +1891,10 @@ public final class CraftServer implements Server {
commandMap.registerServerAliases();
return true;
}
@ -35,5 +35,5 @@ index 6dba269e7..3e5421932 100644
// Paper end
}
--
2.13.0
2.13.3.windows.1