2021-06-11 12:02:28 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
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.
|
|
|
|
|
2021-10-07 04:00:32 +00:00
|
|
|
Note: This patch is no longer necessary as upstream now also closes
|
|
|
|
PluginClassLoaders on disable. This patch is now only to keep around
|
|
|
|
API methods it previously added, and to add back the log message when a
|
|
|
|
PluginClassLoader fails to disable, as upstream decided to ignore the
|
|
|
|
exception.
|
|
|
|
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
2023-02-19 14:57:10 +00:00
|
|
|
index cb530369e667c426c842da356c31304bb5c3ecfa..a11515b81575fc42c771a218a81fea8f05d2289d 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
2023-02-19 14:57:10 +00:00
|
|
|
@@ -78,4 +78,21 @@ public interface PluginLoader {
|
2021-06-11 12:02:28 +00:00
|
|
|
* @param plugin Plugin to disable
|
|
|
|
*/
|
|
|
|
public void disablePlugin(@NotNull Plugin plugin);
|
2021-10-07 04:00:32 +00:00
|
|
|
+
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
+ /**
|
2021-10-07 04:00:32 +00:00
|
|
|
+ * This method is no longer useful as upstream has
|
|
|
|
+ * made it so plugin classloaders are always closed on disable.
|
|
|
|
+ * Use {@link #disablePlugin(Plugin)} instead.
|
2021-06-11 12:02:28 +00:00
|
|
|
+ *
|
|
|
|
+ * @param plugin Plugin to disable
|
2021-10-07 04:00:32 +00:00
|
|
|
+ * @param closeClassloader unused
|
|
|
|
+ * @deprecated Classloader is always closed by upstream now.
|
2021-06-11 12:02:28 +00:00
|
|
|
+ */
|
2021-10-07 04:00:32 +00:00
|
|
|
+ @Deprecated(forRemoval = true)
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // provide default to allow other PluginLoader implementations to work
|
|
|
|
+ default public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
|
|
|
+ disablePlugin(plugin);
|
|
|
|
+ }
|
|
|
|
+ // 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
|
2023-02-19 14:57:10 +00:00
|
|
|
index 03213fde8315384ec56c16031cfc606ade2e8091..94fef99525a3613dcc313a0d0b03e47a91d4117b 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
|
2023-02-19 14:57:10 +00:00
|
|
|
@@ -162,6 +162,22 @@ public interface PluginManager extends io.papermc.paper.plugin.PermissionManager
|
2021-06-11 12:02:28 +00:00
|
|
|
*/
|
|
|
|
public void disablePlugin(@NotNull Plugin plugin);
|
|
|
|
|
|
|
|
+ // Paper start - close Classloader on disable
|
|
|
|
+ /**
|
2021-10-07 04:00:32 +00:00
|
|
|
+ * This method is no longer useful as upstream has
|
|
|
|
+ * made it so plugin classloaders are always closed on disable.
|
|
|
|
+ * Use {@link #disablePlugin(Plugin)} instead.
|
2021-06-11 12:02:28 +00:00
|
|
|
+ *
|
|
|
|
+ * @param plugin Plugin to disable
|
2021-10-07 04:00:32 +00:00
|
|
|
+ * @param closeClassloader unused
|
|
|
|
+ * @deprecated Classloader is always closed by upstream now.
|
2021-06-11 12:02:28 +00:00
|
|
|
+ */
|
2021-10-07 04:00:32 +00:00
|
|
|
+ @Deprecated(forRemoval = true)
|
|
|
|
+ public default void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
|
|
|
+ this.disablePlugin(plugin);
|
|
|
|
+ }
|
2021-06-11 12:02:28 +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
|
2023-02-19 14:57:10 +00:00
|
|
|
index 2b8308989fce7f8a16907f8711b362e671fdbfb6..f96164a2bc4e042bdd7c6045a9b392ad4e4dbea7 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
2023-02-19 14:57:10 +00:00
|
|
|
@@ -532,6 +532,21 @@ public final class SimplePluginManager implements PluginManager {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 04:00:32 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * This method is no longer useful as upstream has
|
|
|
|
+ * made it so plugin classloaders are always closed on disable.
|
|
|
|
+ * Use {@link #disablePlugins()} instead.
|
|
|
|
+ *
|
|
|
|
+ * @param closeClassloaders unused
|
|
|
|
+ * @deprecated Classloader is always closed by upstream now.
|
|
|
|
+ */
|
|
|
|
+ @Deprecated(forRemoval = true)
|
|
|
|
+ public void disablePlugins(boolean closeClassloaders) {
|
|
|
|
+ this.disablePlugins();
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
2021-10-07 04:00:32 +00:00
|
|
|
+ // Paper end
|
2021-06-11 12:02:28 +00:00
|
|
|
+
|
|
|
|
@Override
|
2021-10-07 04:00:32 +00:00
|
|
|
public void disablePlugin(@NotNull final Plugin plugin) {
|
2023-02-19 14:57:10 +00:00
|
|
|
if (true) {this.paperPluginManager.disablePlugin(plugin); return;} // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
2023-02-19 14:57:10 +00:00
|
|
|
index ac1c884e950ce13e9e7b3a7be1378808012fafc4..e0423adf45bf5855c23259257863f67cec1c3d54 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
2023-02-19 14:57:10 +00:00
|
|
|
@@ -368,6 +368,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
2021-10-07 04:00:32 +00:00
|
|
|
loader.close();
|
2021-06-11 12:02:28 +00:00
|
|
|
} catch (IOException ex) {
|
|
|
|
//
|
2021-10-07 04:00:32 +00:00
|
|
|
+ this.server.getLogger().log(Level.WARNING, "Error closing the PluginClassLoader for '" + plugin.getDescription().getFullName() + "'", ex); // Paper - log exception
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|