From 016dd7c0e110086e7a8d3902a8b97187ae8619fe Mon Sep 17 00:00:00 2001 From: Nickid2018 Date: Wed, 29 May 2024 23:45:57 +0800 Subject: [PATCH] Fix memory leak --- build.gradle | 2 ++ .../nickid2018/genwiki/GenerateWikiData.java | 8 ++++++++ .../nickid2018/genwiki/RemapSettings.java | 2 ++ .../genwiki/autovalue/BlockDataExtractor.java | 4 ++-- .../statistic/ChunkStatisticsAnalyzer.java | 11 ++++++++++- .../minecraft/server/level/DistanceManager.java | 14 ++++++++++++++ .../server/level/ServerChunkCache.java | 3 +++ .../java/net/minecraft/server/level/Ticket.java | 9 +++++++++ .../java/net/minecraft/util/SortedArraySet.java | 17 +++++++++++++++++ .../net/minecraft/world/level/ChunkPos.java | 8 ++++++++ .../world/level/chunk/ChunkAccess.java | 5 +++++ .../world/level/chunk/status/ChunkStatus.java | 1 + 12 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 wrapped-mc/src/main/java/net/minecraft/server/level/DistanceManager.java create mode 100644 wrapped-mc/src/main/java/net/minecraft/server/level/Ticket.java create mode 100644 wrapped-mc/src/main/java/net/minecraft/util/SortedArraySet.java create mode 100644 wrapped-mc/src/main/java/net/minecraft/world/level/ChunkPos.java diff --git a/build.gradle b/build.gradle index 1227cce..56d2e7b 100644 --- a/build.gradle +++ b/build.gradle @@ -71,6 +71,7 @@ tasks.register("run", Exec) { if (environment["MAKE_VERSION"] == null) environment["MAKE_VERSION"] = "" commandLine("java", "-jar", "../build/libs/GenWiki.jar", environment["MAKE_VERSION"]) + standardInput = System.in }.configure { dependsOn(shadowJar) } @@ -84,6 +85,7 @@ tasks.register("runStatistics", Exec) { if (environment["MAKE_VERSION"] == null) environment["MAKE_VERSION"] = "" commandLine("java", "-jar", "../build/libs/GenWiki.jar", environment["MAKE_VERSION"], "--mode", "statistics") + standardInput = System.in }.configure { dependsOn(shadowJar) } diff --git a/src/main/java/io/github/nickid2018/genwiki/GenerateWikiData.java b/src/main/java/io/github/nickid2018/genwiki/GenerateWikiData.java index b28c68b..7464b3a 100644 --- a/src/main/java/io/github/nickid2018/genwiki/GenerateWikiData.java +++ b/src/main/java/io/github/nickid2018/genwiki/GenerateWikiData.java @@ -156,6 +156,14 @@ private static void runWikiGenerator(String file) throws Exception { try (FileWriter w = new FileWriter(new File(RUNTIME_FOLDER, "server.properties"))) { w.write("max-tick-time=-1\nsync-chunk-writes=false"); } + try (FileWriter w = new FileWriter(new File(RUNTIME_FOLDER, "ops.json"))) { + w.write("[{\n" + + " \"uuid\": \"79380052-7171-4dc6-9362-7ef172d88adc\",\n" + + " \"name\": \"Nickid2018\",\n" + + " \"level\": 4,\n" + + " \"bypassesPlayerLimit\": false\n" + + " }]"); + } ProcessBuilder builder; if (System.getenv("JVM_ARGS") != null) { diff --git a/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java b/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java index 494bc8b..b131a64 100644 --- a/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java +++ b/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java @@ -135,6 +135,8 @@ public static void remapSettings(boolean isChunkStatistics, RemapProgram remapPr ); if (isChunkStatistics) { + remapProgram.addPostTransform("net.minecraft.server.level.DistanceManager", ExtendAccessTransform.ALL); + remapProgram.addPostTransform("net.minecraft.server.level.ServerChunkCache", ExtendAccessTransform.ALL); remapProgram.addInjectEntries(new IncludeJarPackages("io.github.nickid2018.genwiki.statistic")); remapProgram.addInjectEntries(new IncludeJarPackages("me.tongfei.progressbar", ProgressBar.class)); remapProgram.addInjectEntries(new IncludeJarPackages("org.jline", TerminalBuilder.class)); diff --git a/src/main/java/io/github/nickid2018/genwiki/autovalue/BlockDataExtractor.java b/src/main/java/io/github/nickid2018/genwiki/autovalue/BlockDataExtractor.java index abc161c..b6c6fd2 100644 --- a/src/main/java/io/github/nickid2018/genwiki/autovalue/BlockDataExtractor.java +++ b/src/main/java/io/github/nickid2018/genwiki/autovalue/BlockDataExtractor.java @@ -194,8 +194,8 @@ public static void extractBlockData(MinecraftServer serverObj) { WikiData.write(SUPPORT_TYPE, SUPPORT_TYPE_EXCEPT, "block_support_type.txt"); WikiData.write(BLOCK_PROPERTY_VALUES, "block_property_values.txt"); WikiData.write(BLOCK_PROPERTIES, "block_properties.txt"); - WikiData.write(OCCLUSION_SHAPE_VALUES, "block_occlusion_shape.txt"); - WikiData.write(LIQUID_COMPUTATION_VALUES, "block_liquid_computation.txt"); + WikiData.write(OCCLUSION_SHAPE_VALUES, "block_occlusion_shape.json"); + WikiData.write(LIQUID_COMPUTATION_VALUES, "block_liquid_computation.json"); } private static final Set OVERRIDE_BLOCK_PUSH_REACTION = Set.of( diff --git a/src/main/java/io/github/nickid2018/genwiki/statistic/ChunkStatisticsAnalyzer.java b/src/main/java/io/github/nickid2018/genwiki/statistic/ChunkStatisticsAnalyzer.java index 1ddbe10..dec9738 100644 --- a/src/main/java/io/github/nickid2018/genwiki/statistic/ChunkStatisticsAnalyzer.java +++ b/src/main/java/io/github/nickid2018/genwiki/statistic/ChunkStatisticsAnalyzer.java @@ -13,8 +13,10 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.ServerTickRateManager; import net.minecraft.server.level.ChunkResult; +import net.minecraft.server.level.DistanceManager; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; @@ -104,8 +106,15 @@ public static void analyze(MinecraftServer server) { while (iterator.hasNext()) { CompletableFuture> future = iterator.next(); if (future.isDone()) { - createdChunk.offer(future.get().orElse(null)); + ChunkAccess chunk = future.get().orElse(null); + createdChunk.offer(chunk); iterator.remove(); + + ChunkPos chunkPos = chunk.getPos(); + long chunkPosLong = chunkPos.toLong(); + chunkSource.distanceManager.getTickets(chunkPosLong).forEach( + ticket -> chunkSource.distanceManager.removeTicket(chunkPosLong, ticket) + ); bar.step(); } } diff --git a/wrapped-mc/src/main/java/net/minecraft/server/level/DistanceManager.java b/wrapped-mc/src/main/java/net/minecraft/server/level/DistanceManager.java new file mode 100644 index 0000000..f38fc76 --- /dev/null +++ b/wrapped-mc/src/main/java/net/minecraft/server/level/DistanceManager.java @@ -0,0 +1,14 @@ +package net.minecraft.server.level; + +import net.minecraft.util.SortedArraySet; + +public abstract class DistanceManager { + + public SortedArraySet> getTickets(long l2) { + throw new RuntimeException(); + } + + public void removeTicket(long l, Ticket ticket) { + throw new RuntimeException(); + } +} diff --git a/wrapped-mc/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/wrapped-mc/src/main/java/net/minecraft/server/level/ServerChunkCache.java index 964ed1f..d611b6b 100644 --- a/wrapped-mc/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/wrapped-mc/src/main/java/net/minecraft/server/level/ServerChunkCache.java @@ -1,5 +1,6 @@ package net.minecraft.server.level; +import io.github.nickid2018.util.SneakyUtil; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.status.ChunkStatus; @@ -7,6 +8,8 @@ public class ServerChunkCache { + public final DistanceManager distanceManager = SneakyUtil.sneakyNotNull(); + public CompletableFuture> getChunkFuture(int n, int n2, ChunkStatus chunkStatus, boolean bl) { throw new RuntimeException(); } diff --git a/wrapped-mc/src/main/java/net/minecraft/server/level/Ticket.java b/wrapped-mc/src/main/java/net/minecraft/server/level/Ticket.java new file mode 100644 index 0000000..1bd27c9 --- /dev/null +++ b/wrapped-mc/src/main/java/net/minecraft/server/level/Ticket.java @@ -0,0 +1,9 @@ +package net.minecraft.server.level; + +public class Ticket implements Comparable> { + + @Override + public int compareTo(Ticket o) { + throw new RuntimeException(); + } +} diff --git a/wrapped-mc/src/main/java/net/minecraft/util/SortedArraySet.java b/wrapped-mc/src/main/java/net/minecraft/util/SortedArraySet.java new file mode 100644 index 0000000..5367148 --- /dev/null +++ b/wrapped-mc/src/main/java/net/minecraft/util/SortedArraySet.java @@ -0,0 +1,17 @@ +package net.minecraft.util; + +import java.util.AbstractSet; +import java.util.Iterator; + +public class SortedArraySet extends AbstractSet { + + @Override + public Iterator iterator() { + throw new RuntimeException(); + } + + @Override + public int size() { + throw new RuntimeException(); + } +} diff --git a/wrapped-mc/src/main/java/net/minecraft/world/level/ChunkPos.java b/wrapped-mc/src/main/java/net/minecraft/world/level/ChunkPos.java new file mode 100644 index 0000000..18699d3 --- /dev/null +++ b/wrapped-mc/src/main/java/net/minecraft/world/level/ChunkPos.java @@ -0,0 +1,8 @@ +package net.minecraft.world.level; + +public class ChunkPos { + + public long toLong() { + throw new RuntimeException(); + } +} diff --git a/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java index 788f001..cd6d21b 100644 --- a/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java +++ b/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java @@ -2,6 +2,7 @@ import net.minecraft.core.Holder; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.status.ChunkStatus; @@ -9,6 +10,10 @@ public abstract class ChunkAccess implements BlockGetter { public abstract ChunkStatus getStatus(); + public ChunkPos getPos() { + throw new RuntimeException(); + } + public Holder getNoiseBiome(int n, int n2, int n3) { throw new RuntimeException(); } diff --git a/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatus.java b/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatus.java index a69ea18..314fcbd 100644 --- a/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatus.java +++ b/wrapped-mc/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatus.java @@ -5,4 +5,5 @@ public class ChunkStatus { public static final ChunkStatus FEATURES = SneakyUtil.sneakyNotNull(); + public static final ChunkStatus FULL = SneakyUtil.sneakyNotNull(); }