From dca885cdb8bf2c7c78a5bd954a0d5e1e61f46b31 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 23 Mar 2013 09:31:28 +1100 Subject: [PATCH] [Cleanup] Split the long hash changes into their own patch. --- CraftBukkit-Patches/0002-Spigot-changes.patch | 143 +----------------- .../0003-LongHash-Tweaks.patch | 140 +++++++++++++++++ ...86-by-firing-the-inventory-close-ev.patch} | 4 +- ...tch => 0005-Update-item-merge-logic.patch} | 4 +- ...ray-from-mc-dev-for-diff-visibility.patch} | 4 +- ...ing-of-NibbleArrays-only-allocate-b.patch} | 4 +- .../0007-Return-LOHS-to-full-operation.patch | 30 ---- 7 files changed, 153 insertions(+), 176 deletions(-) create mode 100644 CraftBukkit-Patches/0003-LongHash-Tweaks.patch rename CraftBukkit-Patches/{0003-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch => 0004-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch} (96%) rename CraftBukkit-Patches/{0004-Update-item-merge-logic.patch => 0005-Update-item-merge-logic.patch} (97%) rename CraftBukkit-Patches/{0005-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch => 0006-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch} (95%) rename CraftBukkit-Patches/{0006-Implement-lightening-of-NibbleArrays-only-allocate-b.patch => 0007-Implement-lightening-of-NibbleArrays-only-allocate-b.patch} (99%) delete mode 100644 CraftBukkit-Patches/0007-Return-LOHS-to-full-operation.patch diff --git a/CraftBukkit-Patches/0002-Spigot-changes.patch b/CraftBukkit-Patches/0002-Spigot-changes.patch index 8da0ad5180..fe940c7786 100644 --- a/CraftBukkit-Patches/0002-Spigot-changes.patch +++ b/CraftBukkit-Patches/0002-Spigot-changes.patch @@ -1,6 +1,6 @@ -From e487f4eb5d39d9f09a9ffa5dafa8354d94115169 Mon Sep 17 00:00:00 2001 +From 5431f8ebb3020558e602456d8658e58e20dbe5f6 Mon Sep 17 00:00:00 2001 From: md_5 -Date: Sat, 16 Mar 2013 10:13:29 +1100 +Date: Sat, 23 Mar 2013 09:27:15 +1100 Subject: [PATCH] Spigot changes. --- @@ -28,16 +28,12 @@ Subject: [PATCH] Spigot changes. src/main/java/org/bukkit/craftbukkit/Spigot.java | 20 +++ .../craftbukkit/chunkio/ChunkIOProvider.java | 2 +- .../org/bukkit/craftbukkit/entity/CraftPlayer.java | 7 + - .../java/org/bukkit/craftbukkit/util/FlatMap.java | 34 +++++ - .../org/bukkit/craftbukkit/util/LongHashSet.java | 11 +- - .../bukkit/craftbukkit/util/LongObjectHashMap.java | 5 + src/main/resources/configurations/bukkit.yml | 27 ++++ - 28 files changed, 488 insertions(+), 81 deletions(-) + 25 files changed, 441 insertions(+), 78 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/Spigot.java - create mode 100644 src/main/java/org/bukkit/craftbukkit/util/FlatMap.java diff --git a/.gitignore b/.gitignore -index a689360..b97a549 100644 +index c3faf57..346b232 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ @@ -1057,135 +1053,6 @@ index 70111e7..1871d3e 100644 public void setCompassTarget(Location loc) { if (getHandle().playerConnection == null) return; -diff --git a/src/main/java/org/bukkit/craftbukkit/util/FlatMap.java b/src/main/java/org/bukkit/craftbukkit/util/FlatMap.java -new file mode 100644 -index 0000000..e8a7725 ---- /dev/null -+++ b/src/main/java/org/bukkit/craftbukkit/util/FlatMap.java -@@ -0,0 +1,34 @@ -+package org.bukkit.craftbukkit.util; -+ -+public class FlatMap { -+ -+ private static final int FLAT_LOOKUP_SIZE = 512; -+ private final Object[][] flatLookup = new Object[FLAT_LOOKUP_SIZE * 2][FLAT_LOOKUP_SIZE * 2]; -+ -+ public void put(long msw, long lsw, V value) { -+ long acx = Math.abs(msw); -+ long acz = Math.abs(lsw); -+ if (acx < FLAT_LOOKUP_SIZE && acz < FLAT_LOOKUP_SIZE) { -+ flatLookup[(int) (msw + FLAT_LOOKUP_SIZE)][(int) (lsw + FLAT_LOOKUP_SIZE)] = value; -+ } -+ } -+ -+ public void put(long key, V value) { -+ put(LongHash.msw(key), LongHash.lsw(key), value); -+ -+ } -+ -+ public V get(long msw, long lsw) { -+ long acx = Math.abs(msw); -+ long acz = Math.abs(lsw); -+ if (acx < FLAT_LOOKUP_SIZE && acz < FLAT_LOOKUP_SIZE) { -+ return (V) flatLookup[(int) (msw + FLAT_LOOKUP_SIZE)][(int) (lsw + FLAT_LOOKUP_SIZE)]; -+ } else { -+ return null; -+ } -+ } -+ -+ public V get(long key) { -+ return get(LongHash.msw(key), LongHash.lsw(key)); -+ } -+} -diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -index 22c96c5..3f1617d 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -@@ -31,6 +31,8 @@ public class LongHashSet { - private int elements; - private long[] values; - private int modCount; -+ private static final Object PRESENT = new Object(); -+ private final FlatMap flat = new FlatMap(); - - public LongHashSet() { - this(INITIAL_SIZE); -@@ -56,10 +58,11 @@ public class LongHashSet { - } - - public boolean contains(int msw, int lsw) { -+ if (flat.get(msw, lsw) != null) return true; // Spigot - return contains(LongHash.toLong(msw, lsw)); - } - -- public boolean contains(long value) { -+ private boolean contains(long value) { // Spigot - int hash = hash(value); - int index = (hash & 0x7FFFFFFF) % values.length; - int offset = 1; -@@ -78,10 +81,11 @@ public class LongHashSet { - } - - public boolean add(int msw, int lsw) { -+ flat.put(msw, lsw, PRESENT); // Spigot - return add(LongHash.toLong(msw, lsw)); - } - -- public boolean add(long value) { -+ private boolean add(long value) { // Spigot - int hash = hash(value); - int index = (hash & 0x7FFFFFFF) % values.length; - int offset = 1; -@@ -125,10 +129,11 @@ public class LongHashSet { - } - - public void remove(int msw, int lsw) { -+ flat.put(msw, lsw, null); // Spigot - remove(LongHash.toLong(msw, lsw)); - } - -- public boolean remove(long value) { -+ private boolean remove(long value) { // Spigot - int hash = hash(value); - int index = (hash & 0x7FFFFFFF) % values.length; - int offset = 1; -diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java b/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java -index 01861cc..dbd33fa 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java -@@ -28,6 +28,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { - private transient V[][] values; - private transient int modCount; - private transient int size; -+ private final FlatMap flat = new FlatMap(); // Spigot - - public LongObjectHashMap() { - initialize(); -@@ -61,6 +62,8 @@ public class LongObjectHashMap implements Cloneable, Serializable { - } - - public V get(long key) { -+ V val = flat.get(key); // Spigot -+ if (val != null) return val; // Spigot - int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); - long[] inner = keys[index]; - if (inner == null) return null; -@@ -78,6 +81,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { - } - - public V put(long key, V value) { -+ flat.put(key, value); // Spigot - int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); - long[] innerKeys = keys[index]; - V[] innerValues = values[index]; -@@ -124,6 +128,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { - } - - public V remove(long key) { -+ flat.put(key, null); // Spigot - int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); - long[] inner = keys[index]; - if (inner == null) { diff --git a/src/main/resources/configurations/bukkit.yml b/src/main/resources/configurations/bukkit.yml index 61a95e3..f44d5d0 100644 --- a/src/main/resources/configurations/bukkit.yml @@ -1225,5 +1092,5 @@ index 61a95e3..f44d5d0 100644 monsters: 70 animals: 15 -- -1.8.2 +1.8.1-rc2 diff --git a/CraftBukkit-Patches/0003-LongHash-Tweaks.patch b/CraftBukkit-Patches/0003-LongHash-Tweaks.patch new file mode 100644 index 0000000000..1ab47868f0 --- /dev/null +++ b/CraftBukkit-Patches/0003-LongHash-Tweaks.patch @@ -0,0 +1,140 @@ +From 47b8bac863a322c7431cca649eb4050910b3cc2c Mon Sep 17 00:00:00 2001 +From: md_5 +Date: Sat, 23 Mar 2013 09:29:43 +1100 +Subject: [PATCH] LongHash Tweaks. + +This commit adds a flat array based cache to the LongHash(Set/Map) classes leading to excellent efficiency for servers where most activity is centered around the origin (0,0) +--- + .../java/org/bukkit/craftbukkit/util/FlatMap.java | 34 ++++++++++++++++++++++ + .../org/bukkit/craftbukkit/util/LongHashSet.java | 8 ++++- + .../bukkit/craftbukkit/util/LongObjectHashMap.java | 5 ++++ + 3 files changed, 46 insertions(+), 1 deletion(-) + create mode 100644 src/main/java/org/bukkit/craftbukkit/util/FlatMap.java + +diff --git a/src/main/java/org/bukkit/craftbukkit/util/FlatMap.java b/src/main/java/org/bukkit/craftbukkit/util/FlatMap.java +new file mode 100644 +index 0000000..e8a7725 +--- /dev/null ++++ b/src/main/java/org/bukkit/craftbukkit/util/FlatMap.java +@@ -0,0 +1,34 @@ ++package org.bukkit.craftbukkit.util; ++ ++public class FlatMap { ++ ++ private static final int FLAT_LOOKUP_SIZE = 512; ++ private final Object[][] flatLookup = new Object[FLAT_LOOKUP_SIZE * 2][FLAT_LOOKUP_SIZE * 2]; ++ ++ public void put(long msw, long lsw, V value) { ++ long acx = Math.abs(msw); ++ long acz = Math.abs(lsw); ++ if (acx < FLAT_LOOKUP_SIZE && acz < FLAT_LOOKUP_SIZE) { ++ flatLookup[(int) (msw + FLAT_LOOKUP_SIZE)][(int) (lsw + FLAT_LOOKUP_SIZE)] = value; ++ } ++ } ++ ++ public void put(long key, V value) { ++ put(LongHash.msw(key), LongHash.lsw(key), value); ++ ++ } ++ ++ public V get(long msw, long lsw) { ++ long acx = Math.abs(msw); ++ long acz = Math.abs(lsw); ++ if (acx < FLAT_LOOKUP_SIZE && acz < FLAT_LOOKUP_SIZE) { ++ return (V) flatLookup[(int) (msw + FLAT_LOOKUP_SIZE)][(int) (lsw + FLAT_LOOKUP_SIZE)]; ++ } else { ++ return null; ++ } ++ } ++ ++ public V get(long key) { ++ return get(LongHash.msw(key), LongHash.lsw(key)); ++ } ++} +diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java +index 22c96c5..331d570 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java +@@ -31,6 +31,8 @@ public class LongHashSet { + private int elements; + private long[] values; + private int modCount; ++ private static final Object PRESENT = new Object(); ++ private final FlatMap flat = new FlatMap(); + + public LongHashSet() { + this(INITIAL_SIZE); +@@ -56,10 +58,12 @@ public class LongHashSet { + } + + public boolean contains(int msw, int lsw) { ++ if (flat.get(msw, lsw) != null) return true; // Spigot + return contains(LongHash.toLong(msw, lsw)); + } + + public boolean contains(long value) { ++ if (flat.get(value) != null) return true; // Spigot + int hash = hash(value); + int index = (hash & 0x7FFFFFFF) % values.length; + int offset = 1; +@@ -82,6 +86,7 @@ public class LongHashSet { + } + + public boolean add(long value) { ++ flat.put(value, PRESENT); // Spigot + int hash = hash(value); + int index = (hash & 0x7FFFFFFF) % values.length; + int offset = 1; +@@ -125,10 +130,11 @@ public class LongHashSet { + } + + public void remove(int msw, int lsw) { ++ flat.put(msw, lsw, null); // Spigot + remove(LongHash.toLong(msw, lsw)); + } + +- public boolean remove(long value) { ++ private boolean remove(long value) { // Spigot + int hash = hash(value); + int index = (hash & 0x7FFFFFFF) % values.length; + int offset = 1; +diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java b/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java +index 01861cc..dbd33fa 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java +@@ -28,6 +28,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { + private transient V[][] values; + private transient int modCount; + private transient int size; ++ private final FlatMap flat = new FlatMap(); // Spigot + + public LongObjectHashMap() { + initialize(); +@@ -61,6 +62,8 @@ public class LongObjectHashMap implements Cloneable, Serializable { + } + + public V get(long key) { ++ V val = flat.get(key); // Spigot ++ if (val != null) return val; // Spigot + int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); + long[] inner = keys[index]; + if (inner == null) return null; +@@ -78,6 +81,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { + } + + public V put(long key, V value) { ++ flat.put(key, value); // Spigot + int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); + long[] innerKeys = keys[index]; + V[] innerValues = values[index]; +@@ -124,6 +128,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { + } + + public V remove(long key) { ++ flat.put(key, null); // Spigot + int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); + long[] inner = keys[index]; + if (inner == null) { +-- +1.8.1-rc2 + diff --git a/CraftBukkit-Patches/0003-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch b/CraftBukkit-Patches/0004-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch similarity index 96% rename from CraftBukkit-Patches/0003-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch rename to CraftBukkit-Patches/0004-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch index c64b69d7c1..b51f7c68ee 100644 --- a/CraftBukkit-Patches/0003-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch +++ b/CraftBukkit-Patches/0004-Address-BUKKIT-3286-by-firing-the-inventory-close-ev.patch @@ -1,4 +1,4 @@ -From 2b9688df3fbf86e9dfe1acb39eda62ff49d795c7 Mon Sep 17 00:00:00 2001 +From 5dcb300e7971cc649311c94ca51859f6c7d2411f Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 23 Dec 2012 17:09:40 +1100 Subject: [PATCH] Address BUKKIT-3286 by firing the inventory close event when @@ -39,5 +39,5 @@ index 1f7b8ad..6f77702 100644 } } -- -1.8.2 +1.8.1-rc2 diff --git a/CraftBukkit-Patches/0004-Update-item-merge-logic.patch b/CraftBukkit-Patches/0005-Update-item-merge-logic.patch similarity index 97% rename from CraftBukkit-Patches/0004-Update-item-merge-logic.patch rename to CraftBukkit-Patches/0005-Update-item-merge-logic.patch index 58938f398e..5c3e8b01ce 100644 --- a/CraftBukkit-Patches/0004-Update-item-merge-logic.patch +++ b/CraftBukkit-Patches/0005-Update-item-merge-logic.patch @@ -1,4 +1,4 @@ -From fb269cb8e23a35d6356ea849600768b7d137adbd Mon Sep 17 00:00:00 2001 +From af7cc23dd2d34c8d0c4a26d860dbf7b4110eb331 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 23 Dec 2012 17:51:07 +1100 Subject: [PATCH] Update item merge logic @@ -41,5 +41,5 @@ index 134ab73..d78d948 100644 } } -- -1.8.2 +1.8.1-rc2 diff --git a/CraftBukkit-Patches/0005-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch b/CraftBukkit-Patches/0006-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch similarity index 95% rename from CraftBukkit-Patches/0005-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch rename to CraftBukkit-Patches/0006-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch index 4df90aa719..731d916708 100644 --- a/CraftBukkit-Patches/0005-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch +++ b/CraftBukkit-Patches/0006-Include-NibbleArray-from-mc-dev-for-diff-visibility.patch @@ -1,4 +1,4 @@ -From 77b8cb1974ea857b889682aa8d455400acb916b9 Mon Sep 17 00:00:00 2001 +From c0b74eb8b5124a081c1655af4948d8605eaeb028 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 14 Dec 2012 21:51:06 -0600 Subject: [PATCH] Include NibbleArray from mc-dev for diff visibility @@ -55,5 +55,5 @@ index 0000000..5d75a54 + } +} -- -1.8.2 +1.8.1-rc2 diff --git a/CraftBukkit-Patches/0006-Implement-lightening-of-NibbleArrays-only-allocate-b.patch b/CraftBukkit-Patches/0007-Implement-lightening-of-NibbleArrays-only-allocate-b.patch similarity index 99% rename from CraftBukkit-Patches/0006-Implement-lightening-of-NibbleArrays-only-allocate-b.patch rename to CraftBukkit-Patches/0007-Implement-lightening-of-NibbleArrays-only-allocate-b.patch index 5fcf692ff0..1bd3991c22 100644 --- a/CraftBukkit-Patches/0006-Implement-lightening-of-NibbleArrays-only-allocate-b.patch +++ b/CraftBukkit-Patches/0007-Implement-lightening-of-NibbleArrays-only-allocate-b.patch @@ -1,4 +1,4 @@ -From 3f7bb734d467c6ae5e7f717d09091f0072a8f8ab Mon Sep 17 00:00:00 2001 +From a062d1cbb45a6db914e4de8d44a5730833c895d1 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 23 Dec 2012 14:46:23 -0600 Subject: [PATCH] Implement 'lightening' of NibbleArrays - only allocate @@ -385,5 +385,5 @@ index c3b9113..e34e781 100644 } -- -1.8.2 +1.8.1-rc2 diff --git a/CraftBukkit-Patches/0007-Return-LOHS-to-full-operation.patch b/CraftBukkit-Patches/0007-Return-LOHS-to-full-operation.patch deleted file mode 100644 index d4e9dc4ae7..0000000000 --- a/CraftBukkit-Patches/0007-Return-LOHS-to-full-operation.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 5b1786bcc9f2bd9638adf0cfd076981a138ab2ae Mon Sep 17 00:00:00 2001 -From: md_5 -Date: Mon, 7 Jan 2013 09:57:30 +1100 -Subject: [PATCH] Return LOHS to full operation. - ---- - src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -index 3f1617d..a1250d3 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -@@ -81,11 +81,11 @@ public class LongHashSet { - } - - public boolean add(int msw, int lsw) { -- flat.put(msw, lsw, PRESENT); // Spigot - return add(LongHash.toLong(msw, lsw)); - } - -- private boolean add(long value) { // Spigot -+ public boolean add(long value) { -+ flat.put(value, PRESENT); // Spigot - int hash = hash(value); - int index = (hash & 0x7FFFFFFF) % values.length; - int offset = 1; --- -1.8.2 -