Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/api/0102-Close-Plugin-Class-Loaders-on-Disable.patch

106 Zeilen
4.6 KiB
Diff

2021-06-11 14:02:28 +02: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.
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 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
index a88733f1cd1ddb5d85ab1b0e6af4fd5b80bbc1c6..256e440e699942e3c9da4205bb964bdc10ec92c4 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
@@ -77,4 +77,21 @@ public interface PluginLoader {
2021-06-11 14:02:28 +02:00
* @param plugin Plugin to disable
*/
public void disablePlugin(@NotNull Plugin plugin);
+
2021-06-11 14:02:28 +02:00
+ // Paper start - close Classloader on disable
+ /**
+ * 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 14:02:28 +02:00
+ *
+ * @param plugin Plugin to disable
+ * @param closeClassloader unused
+ * @deprecated Classloader is always closed by upstream now.
2021-06-11 14:02:28 +02:00
+ */
+ @Deprecated(forRemoval = true)
2021-06-11 14:02:28 +02: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
index 41e26451fe12d8e6e0ef73c85731b24b4e3f200c..0d1b20f2b5580ea5505ccc2f003925dbcee67199 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
@@ -161,6 +161,22 @@ public interface PluginManager {
2021-06-11 14:02:28 +02:00
*/
public void disablePlugin(@NotNull Plugin plugin);
+ // Paper start - close Classloader on disable
+ /**
+ * 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 14:02:28 +02:00
+ *
+ * @param plugin Plugin to disable
+ * @param closeClassloader unused
+ * @deprecated Classloader is always closed by upstream now.
2021-06-11 14:02:28 +02:00
+ */
+ @Deprecated(forRemoval = true)
+ public default void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
+ this.disablePlugin(plugin);
+ }
2021-06-11 14:02:28 +02: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
2022-07-21 21:53:04 +02:00
index 77caec9f974077ed6580d3cbbc20feb1199feb11..9f32b57464352c08617f6adec144111b8fcad50c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
2022-07-21 21:53:04 +02:00
@@ -504,6 +504,21 @@ public final class SimplePluginManager implements PluginManager {
2021-06-11 14:02:28 +02: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 14:02:28 +02:00
+ }
+ // Paper end
2021-06-11 14:02:28 +02:00
+
@Override
public void disablePlugin(@NotNull final Plugin plugin) {
if (plugin.isEnabled()) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
2022-06-07 19:20:30 +02:00
index 5d74fab03a15d7099e5dacb780eade4cdc185797..032ed2aba7d47144d241d616ba27489ce22d6fea 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -366,6 +366,7 @@ public final class JavaPluginLoader implements PluginLoader {
loader.close();
2021-06-11 14:02:28 +02:00
} catch (IOException ex) {
//
+ this.server.getLogger().log(Level.WARNING, "Error closing the PluginClassLoader for '" + plugin.getDescription().getFullName() + "'", ex); // Paper - log exception
2021-06-11 14:02:28 +02:00
}
}
}