Paper/CraftBukkit-Patches/0125-Prevent-Unbounded-IntCache-Growth.patch
Zach Brown 19972e09b8 Update SpigotMC's patches
5a0150f586ed3eb15fe6f1f596d1a5a7d806f0f9 Fix ITEM_BREAK
e6a3911057bd94d8bd7021cbb4923fb84fb106d1 Upstream merge
d1cdcf8d4c3639f956474f02ed662517cffbe23e Remove old patch
068df64aeee368377e1673667bffc7a6dcf90554 Rebuild all patches
2014-11-30 16:16:48 -06:00

63 Zeilen
2.6 KiB
Diff

From c73ddaa7d7bcd47fa46a513343b34e2d624d4c06 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 4b4f005..0d8eb6c 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 (IntCache.b.isEmpty()) {
aint = new int[256];
- IntCache.c.add(aint);
+ if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.c.add(aint);
return aint;
} else {
aint = (int[]) IntCache.b.remove(IntCache.b.size() - 1);
- IntCache.c.add(aint);
+ if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.c.add(aint);
return aint;
}
} else if (i > IntCache.a) {
@@ -29,15 +29,15 @@ public class IntCache {
IntCache.d.clear();
IntCache.e.clear();
aint = new int[IntCache.a];
- IntCache.e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
return aint;
} else if (IntCache.d.isEmpty()) {
aint = new int[IntCache.a];
- IntCache.e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
return aint;
} else {
aint = (int[]) IntCache.d.remove(IntCache.d.size() - 1);
- IntCache.e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
return aint;
}
}
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 78dcb39..c5e995b 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 );
+ }
}
--
2.1.0