mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-12 15:08:27 +02:00
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.
This commit is contained in:
parent
7f6d9d1fb7
commit
b4f8ae96a2
@ -1,4 +1,4 @@
|
||||
From c622cf3a0fddf3113bcf8bf27d99339fff13e400 Mon Sep 17 00:00:00 2001
|
||||
From 8f6a95b59cc9531a91f2396aca273d5eb6c218bc Mon Sep 17 00:00:00 2001
|
||||
From: md_5 <md_5@live.com.au>
|
||||
Date: Sun, 1 Dec 2013 15:10:48 +1100
|
||||
Subject: [PATCH] mc-dev imports
|
||||
@ -1328,6 +1328,75 @@ index 0000000..33cfdb2
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/server/IntCache.java b/src/main/java/net/minecraft/server/IntCache.java
|
||||
new file mode 100644
|
||||
index 0000000..9858720
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/server/IntCache.java
|
||||
@@ -0,0 +1,63 @@
|
||||
+package net.minecraft.server;
|
||||
+
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class IntCache {
|
||||
+
|
||||
+ private static int a = 256;
|
||||
+ private static List b = new ArrayList();
|
||||
+ private static List c = new ArrayList();
|
||||
+ private static List d = new ArrayList();
|
||||
+ private static List e = new ArrayList();
|
||||
+
|
||||
+ public static synchronized int[] a(int i) {
|
||||
+ int[] aint;
|
||||
+
|
||||
+ if (i <= 256) {
|
||||
+ if (b.isEmpty()) {
|
||||
+ aint = new int[256];
|
||||
+ c.add(aint);
|
||||
+ return aint;
|
||||
+ } else {
|
||||
+ aint = (int[]) b.remove(b.size() - 1);
|
||||
+ c.add(aint);
|
||||
+ return aint;
|
||||
+ }
|
||||
+ } else if (i > a) {
|
||||
+ a = i;
|
||||
+ d.clear();
|
||||
+ e.clear();
|
||||
+ aint = new int[a];
|
||||
+ e.add(aint);
|
||||
+ return aint;
|
||||
+ } else if (d.isEmpty()) {
|
||||
+ aint = new int[a];
|
||||
+ e.add(aint);
|
||||
+ return aint;
|
||||
+ } else {
|
||||
+ aint = (int[]) d.remove(d.size() - 1);
|
||||
+ e.add(aint);
|
||||
+ return aint;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static synchronized void a() {
|
||||
+ if (!d.isEmpty()) {
|
||||
+ d.remove(d.size() - 1);
|
||||
+ }
|
||||
+
|
||||
+ if (!b.isEmpty()) {
|
||||
+ b.remove(b.size() - 1);
|
||||
+ }
|
||||
+
|
||||
+ d.addAll(e);
|
||||
+ b.addAll(c);
|
||||
+ e.clear();
|
||||
+ c.clear();
|
||||
+ }
|
||||
+
|
||||
+ public static synchronized String b() {
|
||||
+ return "cache: " + d.size() + ", tcache: " + b.size() + ", allocated: " + e.size() + ", tallocated: " + c.size();
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/server/ItemSkull.java b/src/main/java/net/minecraft/server/ItemSkull.java
|
||||
new file mode 100644
|
||||
index 0000000..f20c69e
|
||||
|
@ -0,0 +1,62 @@
|
||||
From bcb5d85cb761fa898b684ad953bf253632d7d4be 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 b00f635..5818cab 100644
|
||||
--- a/src/main/java/org/spigotmc/SpigotConfig.java
|
||||
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
|
||||
@@ -310,4 +310,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
|
||||
|
Loading…
Reference in New Issue
Block a user