2018-11-09 22:45:16 +01:00
|
|
|
From 58698c7b920454d0f0171be3ff53e4df1471dc44 Mon Sep 17 00:00:00 2001
|
2018-05-02 03:36:55 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Tue, 1 May 2018 21:33:35 -0400
|
|
|
|
Subject: [PATCH] Close Plugin Class Loaders on Disable
|
|
|
|
|
|
|
|
This should close more memory leaks from /reload and disabling plugins,
|
|
|
|
by closing the class loader and the jar file.
|
|
|
|
|
2018-06-09 19:58:04 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
2018-11-09 22:45:16 +01:00
|
|
|
index e7981a1d9..d34756f15 100644
|
2018-06-09 19:58:04 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
2018-06-12 17:10:01 +02:00
|
|
|
@@ -73,4 +73,19 @@ public interface PluginLoader {
|
2018-06-09 19:58:04 +02:00
|
|
|
* @param plugin Plugin to disable
|
|
|
|
*/
|
|
|
|
public void disablePlugin(Plugin plugin);
|
|
|
|
+
|
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
+ /**
|
|
|
|
+ * Disables the specified plugin
|
|
|
|
+ * <p>
|
|
|
|
+ * Attempting to disable a plugin that is not enabled will have no effect
|
|
|
|
+ *
|
|
|
|
+ * @param plugin Plugin to disable
|
|
|
|
+ * @param closeClassloader if the classloader for the Plugin should be closed
|
|
|
|
+ */
|
2018-06-12 17:10:01 +02:00
|
|
|
+ // provide default to allow other PluginLoader implementations to work
|
|
|
|
+ default public void disablePlugin(Plugin plugin, boolean closeClassloader) {
|
|
|
|
+ disablePlugin(plugin);
|
|
|
|
+ }
|
2018-06-09 19:58:04 +02:00
|
|
|
+ // Paper end - close Classloader on disable
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java
|
2018-11-09 22:45:16 +01:00
|
|
|
index e5638d560..b72d5a9bc 100644
|
2018-06-09 19:58:04 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
|
|
|
|
@@ -154,6 +154,18 @@ public interface PluginManager {
|
|
|
|
*/
|
|
|
|
public void disablePlugin(Plugin plugin);
|
|
|
|
|
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
+ /**
|
|
|
|
+ * Disables the specified plugin
|
|
|
|
+ * <p>
|
|
|
|
+ * Attempting to disable a plugin that is not enabled will have no effect
|
|
|
|
+ *
|
|
|
|
+ * @param plugin Plugin to disable
|
|
|
|
+ * @param closeClassloader if the classloader for the Plugin should be closed
|
|
|
|
+ */
|
|
|
|
+ public void disablePlugin(Plugin plugin, boolean closeClassloader);
|
|
|
|
+ // Paper end - close Classloader on disable
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Gets a {@link Permission} from its fully qualified name
|
|
|
|
*
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
2018-11-09 22:45:16 +01:00
|
|
|
index bd0588a20..cb2b0b9cb 100644
|
2018-06-09 19:58:04 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
|
|
@@ -412,17 +412,29 @@ public final class SimplePluginManager implements PluginManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
public void disablePlugins() {
|
|
|
|
+ disablePlugins(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void disablePlugins(boolean closeClassloaders) {
|
|
|
|
+ // Paper end - close Classloader on disable
|
|
|
|
Plugin[] plugins = getPlugins();
|
|
|
|
for (int i = plugins.length - 1; i >= 0; i--) {
|
|
|
|
- disablePlugin(plugins[i]);
|
|
|
|
+ disablePlugin(plugins[i], closeClassloaders); // Paper - close Classloader on disable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- public void disablePlugin(final Plugin plugin) {
|
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
+ public void disablePlugin(Plugin plugin) {
|
|
|
|
+ disablePlugin(plugin, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void disablePlugin(final Plugin plugin, boolean closeClassloader) {
|
|
|
|
+ // Paper end - close Classloader on disable
|
|
|
|
if (plugin.isEnabled()) {
|
|
|
|
try {
|
|
|
|
- plugin.getPluginLoader().disablePlugin(plugin);
|
|
|
|
+ plugin.getPluginLoader().disablePlugin(plugin, closeClassloader); // Paper - close Classloader on disable
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
handlePluginException("Error occurred (in the plugin loader) while disabling "
|
|
|
|
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
|
|
|
|
@@ -468,7 +480,7 @@ public final class SimplePluginManager implements PluginManager {
|
|
|
|
|
|
|
|
public void clearPlugins() {
|
|
|
|
synchronized (this) {
|
|
|
|
- disablePlugins();
|
|
|
|
+ disablePlugins(true); // Paper - close Classloader on disable
|
|
|
|
plugins.clear();
|
|
|
|
lookupNames.clear();
|
|
|
|
HandlerList.unregisterAll();
|
2018-05-02 03:36:55 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
2018-11-09 22:45:16 +01:00
|
|
|
index 72d506d1f..3411a365c 100644
|
2018-05-02 03:36:55 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
2018-07-15 03:53:17 +02:00
|
|
|
@@ -319,7 +319,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
2018-06-09 19:58:04 +02:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
|
|
|
// Paper start - Disable plugins that fail to load
|
|
|
|
- disablePlugin(jPlugin);
|
2018-11-09 22:45:16 +01:00
|
|
|
+ server.getPluginManager().disablePlugin(jPlugin, true); // Paper - close Classloader on disable - She's dead jim
|
2018-06-09 19:58:04 +02:00
|
|
|
return;
|
|
|
|
// Paper end
|
|
|
|
}
|
2018-07-15 03:53:17 +02:00
|
|
|
@@ -330,7 +330,13 @@ public final class JavaPluginLoader implements PluginLoader {
|
2018-06-09 19:58:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
public void disablePlugin(Plugin plugin) {
|
|
|
|
+ disablePlugin(plugin, false); // Retain old behavior unless requested
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void disablePlugin(Plugin plugin, boolean closeClassloader) {
|
|
|
|
+ // Paper end - close Class Loader on disable
|
|
|
|
Validate.isTrue(plugin instanceof JavaPlugin, "Plugin is not associated with this PluginLoader");
|
|
|
|
|
|
|
|
if (plugin.isEnabled()) {
|
2018-07-15 03:53:17 +02:00
|
|
|
@@ -357,6 +363,16 @@ public final class JavaPluginLoader implements PluginLoader {
|
2018-05-02 03:36:55 +02:00
|
|
|
for (String name : names) {
|
|
|
|
removeClass(name);
|
|
|
|
}
|
|
|
|
+ // Paper start - close Class Loader on disable
|
|
|
|
+ try {
|
2018-06-09 19:58:04 +02:00
|
|
|
+ if (closeClassloader) {
|
|
|
|
+ loader.close();
|
|
|
|
+ }
|
2018-05-02 03:36:55 +02:00
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ server.getLogger().log(Level.WARNING, "Error closing the Plugin Class Loader for " + plugin.getDescription().getFullName());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--
|
2018-11-09 22:45:16 +01:00
|
|
|
2.19.1
|
2018-05-02 03:36:55 +02:00
|
|
|
|