2015-03-08 12:04:41 +01:00
From d20ccbd2b2d81c2f60bb5ca0a78d23c8a20ac988 Mon Sep 17 00:00:00 2001
2014-07-21 22:46:54 +02:00
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
2015-02-28 12:36:22 +01:00
index 8167fdd..95060a4 100644
2014-07-21 22:46:54 +02:00
--- 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) {
2014-11-28 02:17:45 +01:00
if (IntCache.b.isEmpty()) {
2014-07-21 22:46:54 +02:00
aint = new int[256];
2014-11-28 02:17:45 +01:00
- IntCache.c.add(aint);
+ if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.c.add(aint);
2014-07-21 22:46:54 +02:00
return aint;
} else {
2014-11-28 02:17:45 +01:00
aint = (int[]) IntCache.b.remove(IntCache.b.size() - 1);
- IntCache.c.add(aint);
+ if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.c.add(aint);
2014-07-21 22:46:54 +02:00
return aint;
}
2014-11-28 02:17:45 +01:00
} else if (i > IntCache.a) {
2014-07-21 22:46:54 +02:00
@@ -29,15 +29,15 @@ public class IntCache {
2014-11-28 02:17:45 +01:00
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);
2014-07-21 22:46:54 +02:00
return aint;
2014-11-28 02:17:45 +01:00
} 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);
2014-07-21 22:46:54 +02:00
return aint;
} else {
2014-11-28 02:17:45 +01:00
aint = (int[]) IntCache.d.remove(IntCache.d.size() - 1);
- IntCache.e.add(aint);
+ if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
2014-07-21 22:46:54 +02:00
return aint;
}
}
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
2014-11-28 02:17:45 +01:00
index 78dcb39..c5e995b 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
2014-07-30 10:35:19 +02:00
@@ -327,4 +327,10 @@ public class SpigotConfig
2014-07-21 22:46:54 +02:00
{
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 );
+ }
}
--
2014-11-28 02:17:45 +01:00
2.1.0
2014-07-21 22:46:54 +02:00