From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar 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. diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/plugin/PluginLoader.java +++ b/src/main/java/org/bukkit/plugin/PluginLoader.java @@ -0,0 +0,0 @@ public interface PluginLoader { * @param plugin Plugin to disable */ 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. + * + * @param plugin Plugin to disable + * @param closeClassloader unused + * @deprecated Classloader is always closed by upstream now. + */ + @Deprecated(forRemoval = true) + // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/plugin/PluginManager.java +++ b/src/main/java/org/bukkit/plugin/PluginManager.java @@ -0,0 +0,0 @@ public interface PluginManager { */ 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. + * + * @param plugin Plugin to disable + * @param closeClassloader unused + * @deprecated Classloader is always closed by upstream now. + */ + @Deprecated(forRemoval = true) + public default void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) { + this.disablePlugin(plugin); + } + // 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 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -0,0 +0,0 @@ public final class SimplePluginManager implements PluginManager { } } + // 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(); + } + // Paper end + @Override public void disablePlugin(@NotNull final Plugin plugin) { if (plugin.isEnabled()) { diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -0,0 +0,0 @@ public final class JavaPluginLoader implements PluginLoader { loader.close(); } catch (IOException ex) { // + this.server.getLogger().log(Level.WARNING, "Error closing the PluginClassLoader for '" + plugin.getDescription().getFullName() + "'", ex); // Paper - log exception } } }