2020-03-26 02:37:20 +00:00
|
|
|
From 889d1e3dc852de32f8f2e72ffde3f5917fa7dd5c Mon Sep 17 00:00:00 2001
|
2018-05-02 01:36:55 +00: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 17:58:04 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
2019-07-11 16:59:21 +00:00
|
|
|
index a88733f1..6ab9cd82 100644
|
2018-06-09 17:58:04 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
2019-04-23 04:47:07 +00:00
|
|
|
@@ -77,4 +77,18 @@ public interface PluginLoader {
|
2018-06-09 17:58:04 +00:00
|
|
|
* @param plugin Plugin to disable
|
|
|
|
*/
|
2019-03-20 00:28:15 +00:00
|
|
|
public void disablePlugin(@NotNull Plugin plugin);
|
2018-06-09 17:58:04 +00:00
|
|
|
+ // 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 15:10:01 +00:00
|
|
|
+ // provide default to allow other PluginLoader implementations to work
|
2019-03-20 00:28:15 +00:00
|
|
|
+ default public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
2018-06-12 15:10:01 +00:00
|
|
|
+ disablePlugin(plugin);
|
|
|
|
+ }
|
2018-06-09 17:58:04 +00: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
|
2019-07-11 16:59:21 +00:00
|
|
|
index 41e26451..86cc5025 100644
|
2018-06-09 17:58:04 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
|
2019-04-23 04:47:07 +00:00
|
|
|
@@ -161,6 +161,18 @@ public interface PluginManager {
|
2018-06-09 17:58:04 +00:00
|
|
|
*/
|
2019-03-20 00:28:15 +00:00
|
|
|
public void disablePlugin(@NotNull Plugin plugin);
|
2018-06-09 17:58:04 +00:00
|
|
|
|
|
|
|
+ // 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
|
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader);
|
2018-06-09 17:58:04 +00:00
|
|
|
+ // 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
|
2020-03-26 02:37:20 +00:00
|
|
|
index 8ddaf9c2..8bb24f73 100644
|
2018-06-09 17:58:04 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
2020-03-26 02:37:20 +00:00
|
|
|
@@ -492,17 +492,28 @@ public final class SimplePluginManager implements PluginManager {
|
2018-06-09 17:58:04 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2018-06-09 17:58:04 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
public void disablePlugin(@NotNull final Plugin plugin) {
|
2018-06-09 17:58:04 +00:00
|
|
|
+ disablePlugin(plugin, false);
|
|
|
|
+ }
|
|
|
|
+
|
2019-05-06 02:58:04 +00:00
|
|
|
+ @Override
|
2019-03-20 00:28:15 +00:00
|
|
|
+ public void disablePlugin(@NotNull final Plugin plugin, boolean closeClassloader) {
|
2018-06-09 17:58:04 +00:00
|
|
|
+ // 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
|
2020-03-26 02:37:20 +00:00
|
|
|
@@ -557,7 +568,7 @@ public final class SimplePluginManager implements PluginManager {
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2018-06-09 17:58:04 +00:00
|
|
|
public void clearPlugins() {
|
|
|
|
synchronized (this) {
|
|
|
|
- disablePlugins();
|
|
|
|
+ disablePlugins(true); // Paper - close Classloader on disable
|
|
|
|
plugins.clear();
|
|
|
|
lookupNames.clear();
|
2020-01-28 19:43:57 +00:00
|
|
|
dependencyGraph = GraphBuilder.directed().build();
|
2018-05-02 01:36:55 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
2020-01-28 19:43:57 +00:00
|
|
|
index e72cbde4..32ec68b4 100644
|
2018-05-02 01:36:55 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
2020-01-28 19:43:57 +00:00
|
|
|
@@ -331,7 +331,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
2018-06-09 17:58:04 +00: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 21:45:16 +00:00
|
|
|
+ server.getPluginManager().disablePlugin(jPlugin, true); // Paper - close Classloader on disable - She's dead jim
|
2018-06-09 17:58:04 +00:00
|
|
|
return;
|
|
|
|
// Paper end
|
|
|
|
}
|
2020-01-28 19:43:57 +00:00
|
|
|
@@ -344,6 +344,12 @@ public final class JavaPluginLoader implements PluginLoader {
|
2018-06-09 17:58:04 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
public void disablePlugin(@NotNull Plugin plugin) {
|
2018-06-09 17:58:04 +00:00
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
+ disablePlugin(plugin, false); // Retain old behavior unless requested
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 00:28:15 +00:00
|
|
|
+ public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
2018-06-09 17:58:04 +00:00
|
|
|
+ // Paper end - close Class Loader on disable
|
|
|
|
Validate.isTrue(plugin instanceof JavaPlugin, "Plugin is not associated with this PluginLoader");
|
|
|
|
|
|
|
|
if (plugin.isEnabled()) {
|
2020-01-28 19:43:57 +00:00
|
|
|
@@ -370,6 +376,16 @@ public final class JavaPluginLoader implements PluginLoader {
|
2018-05-02 01:36:55 +00:00
|
|
|
for (String name : names) {
|
|
|
|
removeClass(name);
|
|
|
|
}
|
|
|
|
+ // Paper start - close Class Loader on disable
|
|
|
|
+ try {
|
2018-06-09 17:58:04 +00:00
|
|
|
+ if (closeClassloader) {
|
|
|
|
+ loader.close();
|
|
|
|
+ }
|
2018-05-02 01:36:55 +00:00
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ server.getLogger().log(Level.WARNING, "Error closing the Plugin Class Loader for " + plugin.getDescription().getFullName());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--
|
2020-03-26 02:37:20 +00:00
|
|
|
2.26.0
|
2018-05-02 01:36:55 +00:00
|
|
|
|