Paper/CraftBukkit-Patches/0141-Prevent-Unbounded-IntCache-Growth.patch
Zach Brown cab333b217 Rebase (Update) from upstream SpigotMC
Don't send requests of every player was found in the global api cache SpigotMC/Spigot@841270ff1e
Correctly set the response code for the cached lookups and return the ... SpigotMC/Spigot@f170b7899c
Don't try and re-set the global api cache on reload SpigotMC/Spigot@b410a00a66
Use a compile time sneaky throw hack. SpigotMC/Spigot@508462b96b
Fix a missed rename in WorldGenGroundBush SpigotMC/Spigot@0614d8fae9
2014-11-28 14:19:07 -06:00

63 lines
2.4 KiB
Diff

From 2538f25c2c2b5dd9756a12393995575467da8bb5 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Fri, 20 Jun 2014 19:40:00 +1000
Subject: [PATCH] Prevent Unbounded IntCache Growth
Based on work by Peter Lawrey, this commit prevents unbounded growth of the integer cache and instead caps it to a value specified in the configuration (1024 by default). Should prevent thrashing, especially around world generation.
diff --git a/src/main/java/net/minecraft/server/IntCache.java b/src/main/java/net/minecraft/server/IntCache.java
index 9858720..47e06df 100644
--- a/src/main/java/net/minecraft/server/IntCache.java
+++ b/src/main/java/net/minecraft/server/IntCache.java
@@ -17,11 +17,11 @@ public class IntCache {
if (i <= 256) {
if (b.isEmpty()) {
aint = new int[256];
- c.add(aint);
+ if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) c.add(aint);
return aint;
} else {
aint = (int[]) b.remove(b.size() - 1);
- c.add(aint);
+ if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) c.add(aint);
return aint;
}
} else if (i > a) {
@@ -29,15 +29,15 @@ public class IntCache {
d.clear();
e.clear();
aint = new int[a];
- e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) e.add(aint);
return aint;
} else if (d.isEmpty()) {
aint = new int[a];
- e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) e.add(aint);
return aint;
} else {
aint = (int[]) d.remove(d.size() - 1);
- e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) e.add(aint);
return aint;
}
}
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 46c8573..429ad36 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -327,4 +327,10 @@ public class SpigotConfig
{
saveUserCacheOnStopOnly = getBoolean( "settings.save-user-cache-on-stop-only", false );
}
+
+ public static int intCacheLimit;
+ private static void intCacheLimit()
+ {
+ intCacheLimit = getInt( "settings.int-cache-limit", 1024 );
+ }
}
--
1.9.1