mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
ConcurrentUtil: Fix concurrent long map resize chain pull function
The function assumed that the current resize chain pointed to the previous table, when in fact it pointed to the current table. The function is supposed to restore the resize chain to the previous table, previous increment, and previous index + new increment.
This commit is contained in:
parent
bad7a89384
commit
842831a3cf
1 changed files with 13 additions and 10 deletions
|
@ -4123,7 +4123,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import ca.spottedleaf.concurrentutil.util.IntegerUtil;
|
+import ca.spottedleaf.concurrentutil.util.IntegerUtil;
|
||||||
+import ca.spottedleaf.concurrentutil.util.ThrowUtil;
|
+import ca.spottedleaf.concurrentutil.util.ThrowUtil;
|
||||||
+import ca.spottedleaf.concurrentutil.util.Validate;
|
+import ca.spottedleaf.concurrentutil.util.Validate;
|
||||||
+
|
|
||||||
+import java.lang.invoke.VarHandle;
|
+import java.lang.invoke.VarHandle;
|
||||||
+import java.util.Arrays;
|
+import java.util.Arrays;
|
||||||
+import java.util.Iterator;
|
+import java.util.Iterator;
|
||||||
|
@ -5573,23 +5572,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ this.currentTable = null;
|
+ this.currentTable = null;
|
||||||
+ return null;
|
+ return null;
|
||||||
+ }
|
+ }
|
||||||
+ final TableEntry<V>[] newTable = resizeChain.table;
|
+
|
||||||
+ if (newTable == null) {
|
+ final ResizeChain<V> prevChain = resizeChain.prev;
|
||||||
|
+ this.resizeChain = prevChain;
|
||||||
|
+ if (prevChain == null) {
|
||||||
+ this.currentTable = null;
|
+ this.currentTable = null;
|
||||||
+ return null;
|
+ return null;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // the increment is a multiple of table.length, so we can undo the increments on idx by taking the
|
+ final TableEntry<V>[] newTable = prevChain.table;
|
||||||
+ // mod
|
+
|
||||||
|
+ // we recover the original index by modding by the new table length, as the increments applied to the index
|
||||||
|
+ // are a multiple of the new table's length
|
||||||
+ int newIdx = index & (newTable.length - 1);
|
+ int newIdx = index & (newTable.length - 1);
|
||||||
+
|
+
|
||||||
+ final ResizeChain<V> newChain = this.resizeChain = resizeChain.prev;
|
+ // the increment is always the previous table's length
|
||||||
+ final TableEntry<V>[] prevTable = newChain.table;
|
+ final ResizeChain<V> nextPrevChain = prevChain.prev;
|
||||||
+ final int increment;
|
+ final int increment;
|
||||||
+ if (prevTable == null) {
|
+ if (nextPrevChain == null) {
|
||||||
+ increment = 1;
|
+ increment = 1;
|
||||||
+ } else {
|
+ } else {
|
||||||
+ increment = prevTable.length;
|
+ increment = nextPrevChain.table.length;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // done with the upper table, so we can skip the resize node
|
+ // done with the upper table, so we can skip the resize node
|
||||||
|
@ -5706,8 +5709,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ protected ResizeChain(final TableEntry<V>[] table, final ResizeChain<V> prev, final ResizeChain<V> next) {
|
+ protected ResizeChain(final TableEntry<V>[] table, final ResizeChain<V> prev, final ResizeChain<V> next) {
|
||||||
+ this.table = table;
|
+ this.table = table;
|
||||||
+ this.next = next;
|
|
||||||
+ this.prev = prev;
|
+ this.prev = prev;
|
||||||
|
+ this.next = next;
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
|
Loading…
Reference in a new issue