From 842831a3cfab1f46484445cb37b84ec1d03c7e76 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 1 Aug 2024 16:55:33 -0700 Subject: [PATCH] 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. --- patches/server/ConcurrentUtil.patch | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/patches/server/ConcurrentUtil.patch b/patches/server/ConcurrentUtil.patch index ad373f03f9..5f96c71aad 100644 --- a/patches/server/ConcurrentUtil.patch +++ b/patches/server/ConcurrentUtil.patch @@ -4123,7 +4123,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import ca.spottedleaf.concurrentutil.util.IntegerUtil; +import ca.spottedleaf.concurrentutil.util.ThrowUtil; +import ca.spottedleaf.concurrentutil.util.Validate; -+ +import java.lang.invoke.VarHandle; +import java.util.Arrays; +import java.util.Iterator; @@ -5573,23 +5572,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + this.currentTable = null; + return null; + } -+ final TableEntry[] newTable = resizeChain.table; -+ if (newTable == null) { ++ ++ final ResizeChain prevChain = resizeChain.prev; ++ this.resizeChain = prevChain; ++ if (prevChain == null) { + this.currentTable = null; + return null; + } + -+ // the increment is a multiple of table.length, so we can undo the increments on idx by taking the -+ // mod ++ final TableEntry[] newTable = prevChain.table; ++ ++ // 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); + -+ final ResizeChain newChain = this.resizeChain = resizeChain.prev; -+ final TableEntry[] prevTable = newChain.table; ++ // the increment is always the previous table's length ++ final ResizeChain nextPrevChain = prevChain.prev; + final int increment; -+ if (prevTable == null) { ++ if (nextPrevChain == null) { + increment = 1; + } else { -+ increment = prevTable.length; ++ increment = nextPrevChain.table.length; + } + + // done with the upper table, so we can skip the resize node @@ -5706,8 +5709,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + protected ResizeChain(final TableEntry[] table, final ResizeChain prev, final ResizeChain next) { + this.table = table; -+ this.next = next; + this.prev = prev; ++ this.next = next; + } + } + }