mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
5c7081fecc
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories CraftBukkit Changes:4090d01f
SPIGOT-5047: Correct slot types for 1.14 inventoriese8c08362
SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.d445af3b
SPIGOT-5067: Add item meta for 1.14 spawn eggs * Bring Chunk load checks in-line with spigot As of the last upstream merge spigot now checks ticket level status when returning loaded chunks for a world from api. Now our checks will respect that decision. * Fix spawn ticket levels Vanilla would keep the inner chunks of spawn available for ticking, however my changes made all chunks non-ticking. Resolve by changing ticket levels for spawn chunks inside the border to respect this behavior. * Make World#getChunkIfLoadedImmediately return only entity ticking chunks Mojang appears to be using chunks with level > 33 (non-ticking chunks) as cached chunks and not actually loaded chunks. * Bring all loaded checks in line with spigot Loaded chunks must be at least border chunks, or level <= 33
144 lines
6.3 KiB
Diff
144 lines
6.3 KiB
Diff
From da5e5bf8a3dba0a6586ef65001ab662466726386 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.
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
|
index a88733f1c..6ab9cd821 100644
|
|
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
|
@@ -77,4 +77,18 @@ public interface PluginLoader {
|
|
* @param plugin Plugin to disable
|
|
*/
|
|
public void disablePlugin(@NotNull 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
|
|
+ */
|
|
+ // 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 41e26451f..86cc5025a 100644
|
|
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
|
|
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
|
|
@@ -161,6 +161,18 @@ public interface PluginManager {
|
|
*/
|
|
public void disablePlugin(@NotNull 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(@NotNull 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
|
|
index 4cbec1f11..da3cd63ba 100644
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
@@ -428,17 +428,28 @@ public final class SimplePluginManager implements PluginManager {
|
|
|
|
@Override
|
|
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
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void disablePlugin(@NotNull final Plugin plugin) {
|
|
+ disablePlugin(plugin, false);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void disablePlugin(@NotNull 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
|
|
@@ -485,7 +496,7 @@ public final class SimplePluginManager implements PluginManager {
|
|
@Override
|
|
public void clearPlugins() {
|
|
synchronized (this) {
|
|
- disablePlugins();
|
|
+ disablePlugins(true); // Paper - close Classloader on disable
|
|
plugins.clear();
|
|
lookupNames.clear();
|
|
HandlerList.unregisterAll();
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
index 06b6724fa..bc7bf6a35 100644
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
@@ -332,7 +332,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
} 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);
|
|
+ server.getPluginManager().disablePlugin(jPlugin, true); // Paper - close Classloader on disable - She's dead jim
|
|
return;
|
|
// Paper end
|
|
}
|
|
@@ -345,6 +345,12 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
|
|
@Override
|
|
public void disablePlugin(@NotNull Plugin plugin) {
|
|
+ // Paper start - close Classloader on disable
|
|
+ disablePlugin(plugin, false); // Retain old behavior unless requested
|
|
+ }
|
|
+
|
|
+ public void disablePlugin(@NotNull 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()) {
|
|
@@ -371,6 +377,16 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
for (String name : names) {
|
|
removeClass(name);
|
|
}
|
|
+ // Paper start - close Class Loader on disable
|
|
+ try {
|
|
+ if (closeClassloader) {
|
|
+ loader.close();
|
|
+ }
|
|
+ } catch (IOException e) {
|
|
+ server.getLogger().log(Level.WARNING, "Error closing the Plugin Class Loader for " + plugin.getDescription().getFullName());
|
|
+ e.printStackTrace();
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
}
|
|
}
|
|
--
|
|
2.21.0
|
|
|