mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Merge branch 'perf-gen' into perf-review
This commit is contained in:
commit
b475d20aec
14 files changed
+413
-53
No files matched your search
@@ -44,7 +44,7 @@ public class PlatformStateRebindTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunkDataAirIsResolvedAgainstTheCurrentlyBoundPlatform() {
|
||||
public void chunkDataAirIsResolvedAgainstThePlatformBoundWhenTheBufferFirstReadsIt() {
|
||||
NativeBlockState first = bindPlatform("first");
|
||||
SectionBuffer holder = new SectionBuffer(384);
|
||||
|
||||
@@ -53,7 +53,8 @@ public class PlatformStateRebindTest {
|
||||
IrisPlatforms.unbind();
|
||||
NativeBlockState second = bindPlatform("second");
|
||||
|
||||
assertSame(second, holder.getRaw(0, -1, 0));
|
||||
assertSame(first, holder.getRaw(0, -1, 0));
|
||||
assertSame(second, new SectionBuffer(384).getRaw(0, -1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -264,6 +264,42 @@ public class SectionBufferTest {
|
||||
assertEquals(List.of(9, 8, 7), order);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void columnReadsMatchSingleReadsAcrossEmptySectionsAndBufferEdges() {
|
||||
SectionBuffer buffer = new SectionBuffer(40);
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
NativeBlockState dirt = mock(NativeBlockState.class);
|
||||
buffer.setRaw(3, 2, 9, stone);
|
||||
buffer.setRaw(3, 33, 9, dirt);
|
||||
buffer.setRaw(3, 39, 9, stone);
|
||||
ColumnExtentListeningHunk<NativeBlockState> listening = new ColumnExtentListeningHunk<>(buffer, (x, y, z, state) -> {
|
||||
});
|
||||
NativeBlockState[] column = new NativeBlockState[52];
|
||||
|
||||
ColumnReadHunk.readColumn(listening, 3, 9, -3, 44, column, 4);
|
||||
|
||||
for (int y = -3; y <= 44; y++) {
|
||||
assertSame("y=" + y, buffer.getRaw(3, y, 9), column[4 + y + 3]);
|
||||
}
|
||||
assertNull(column[0]);
|
||||
assertSame(dirt, column[4 + 33 + 3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plainHunksAnswerColumnReadsWithSingleReads() {
|
||||
Hunk<NativeBlockState> array = Hunk.newArrayHunk(16, 32, 16);
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
array.setRaw(5, 7, 1, stone);
|
||||
NativeBlockState[] column = new NativeBlockState[10];
|
||||
|
||||
ColumnReadHunk.readColumn(array, 5, 1, 6, 8, column, 2);
|
||||
|
||||
assertNull(column[2]);
|
||||
assertSame(stone, column[3]);
|
||||
assertNull(column[4]);
|
||||
assertNull(column[5]);
|
||||
}
|
||||
|
||||
private static void assertSameContents(SectionBuffer expected, SectionBuffer actual) {
|
||||
assertEquals(expected.sectionCount(), actual.sectionCount());
|
||||
NativeBlockState[] expectedPalette = expected.palette();
|
||||
|
||||
@@ -3,6 +3,8 @@ package art.arcane.iris.generation.context;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -50,6 +52,42 @@ public class IrisContextIsolationTest {
|
||||
assertNull(rightAfterClose.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextsStayIsolatedWhenThreadsOutnumberTheBindingSlots() throws Exception {
|
||||
Engine engine = mock(Engine.class);
|
||||
int threads = 640;
|
||||
CyclicBarrier allBound = new CyclicBarrier(threads);
|
||||
AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||
List<Thread> workers = new ArrayList<>(threads);
|
||||
for (int index = 0; index < threads; index++) {
|
||||
long session = index + 1L;
|
||||
Thread worker = new Thread(() -> {
|
||||
try (IrisContext.Scope ignored = IrisContext.open(engine, session, null)) {
|
||||
allBound.await(30L, TimeUnit.SECONDS);
|
||||
if (IrisContext.get().getGenerationSessionId() != session) {
|
||||
failure.compareAndSet(null, new AssertionError("Thread observed session "
|
||||
+ IrisContext.get().getGenerationSessionId() + " instead of " + session));
|
||||
}
|
||||
allBound.await(30L, TimeUnit.SECONDS);
|
||||
} catch (Throwable thrown) {
|
||||
failure.compareAndSet(null, thrown);
|
||||
}
|
||||
if (IrisContext.get() != null) {
|
||||
failure.compareAndSet(null, new AssertionError("Context survived its scope"));
|
||||
}
|
||||
}, "iris-context-crowd-" + index);
|
||||
workers.add(worker);
|
||||
worker.start();
|
||||
}
|
||||
for (Thread worker : workers) {
|
||||
worker.join(60000L);
|
||||
assertFalse("Context worker did not finish.", worker.isAlive());
|
||||
}
|
||||
|
||||
assertNull(failure.get());
|
||||
assertNull(IrisContext.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scopeRebindsWorkerWhenEngineChanges() throws Exception {
|
||||
Engine firstEngine = mock(Engine.class);
|
||||
|
||||
+17
-11
@@ -250,7 +250,7 @@ public class GenerationHistoryAdmissionTest {
|
||||
.addSurfaceBiome("iris:conflict").seal().build()
|
||||
: claim(stage);
|
||||
results.add(executor.submit(() -> persistCounting(history, stage, update, appends, forces)));
|
||||
awaitBlockedOnHistory(history, workers, index + 1);
|
||||
awaitQueuedOnHistory(history, workers, index + 1);
|
||||
}
|
||||
stages.get(5).close();
|
||||
}
|
||||
@@ -340,7 +340,7 @@ public class GenerationHistoryAdmissionTest {
|
||||
for (int index = 0; index < stages.size(); index++) {
|
||||
GenerationHistory.GenerationStage stage = stages.get(index);
|
||||
results.add(executor.submit(() -> persistFailingRegion(history, stage, failure)));
|
||||
awaitBlockedOnHistory(history, workers, index + 1);
|
||||
awaitQueuedOnHistory(history, workers, index + 1);
|
||||
}
|
||||
}
|
||||
assertTrue(results.getFirst().get(5, TimeUnit.SECONDS));
|
||||
@@ -404,21 +404,27 @@ public class GenerationHistoryAdmissionTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static void awaitBlockedOnHistory(GenerationHistory history, List<Thread> workers, int count) {
|
||||
Await.until("semantic claim callers to queue behind the History monitor", Duration.ofSeconds(5L),
|
||||
() -> blockedOnHistory(history, workers) == count);
|
||||
private static void awaitQueuedOnHistory(GenerationHistory history, List<Thread> workers, int count) {
|
||||
Await.until("semantic claim callers to queue behind the History writer", Duration.ofSeconds(5L),
|
||||
() -> queuedOnHistory(history, workers) == count);
|
||||
}
|
||||
|
||||
private static int blockedOnHistory(GenerationHistory history, List<Thread> workers) {
|
||||
int blocked = 0;
|
||||
private static int queuedOnHistory(GenerationHistory history, List<Thread> workers) {
|
||||
int queued = 0;
|
||||
for (Thread worker : workers) {
|
||||
ThreadInfo info = ManagementFactory.getThreadMXBean().getThreadInfo(worker.threadId());
|
||||
if (info != null && info.getThreadState() == Thread.State.BLOCKED
|
||||
&& info.getLockInfo().getIdentityHashCode() == System.identityHashCode(history)) {
|
||||
blocked++;
|
||||
if (info == null || info.getLockInfo() == null) {
|
||||
continue;
|
||||
}
|
||||
boolean writer = info.getThreadState() == Thread.State.BLOCKED
|
||||
&& info.getLockInfo().getIdentityHashCode() == System.identityHashCode(history);
|
||||
boolean follower = info.getThreadState() == Thread.State.TIMED_WAITING
|
||||
&& info.getLockInfo().getClassName().endsWith("GenerationHistory$PendingSemanticClaim");
|
||||
if (writer || follower) {
|
||||
queued++;
|
||||
}
|
||||
}
|
||||
return blocked;
|
||||
return queued;
|
||||
}
|
||||
|
||||
private static boolean persistPaused(GenerationHistory history, GenerationHistory.GenerationStage stage,
|
||||
|
||||
Reference in new issue
Block a user