Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed May 29, 2024
1 parent fd45fcd commit 016dd7c
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 3 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/github/nickid2018/genwiki/RemapSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> OVERRIDE_BLOCK_PUSH_REACTION = Set.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,8 +106,15 @@ public static void analyze(MinecraftServer server) {
while (iterator.hasNext()) {
CompletableFuture<ChunkResult<ChunkAccess>> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.minecraft.server.level;

import net.minecraft.util.SortedArraySet;

public abstract class DistanceManager {

public SortedArraySet<Ticket<?>> getTickets(long l2) {
throw new RuntimeException();
}

public void removeTicket(long l, Ticket<?> ticket) {
throw new RuntimeException();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;

import java.util.concurrent.CompletableFuture;

public class ServerChunkCache {

public final DistanceManager distanceManager = SneakyUtil.sneakyNotNull();

public CompletableFuture<ChunkResult<ChunkAccess>> getChunkFuture(int n, int n2, ChunkStatus chunkStatus, boolean bl) {
throw new RuntimeException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.minecraft.server.level;

public class Ticket<T> implements Comparable<Ticket<T>> {

@Override
public int compareTo(Ticket<T> o) {
throw new RuntimeException();
}
}
17 changes: 17 additions & 0 deletions wrapped-mc/src/main/java/net/minecraft/util/SortedArraySet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.minecraft.util;

import java.util.AbstractSet;
import java.util.Iterator;

public class SortedArraySet<T> extends AbstractSet<T> {

@Override
public Iterator<T> iterator() {
throw new RuntimeException();
}

@Override
public int size() {
throw new RuntimeException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.minecraft.world.level;

public class ChunkPos {

public long toLong() {
throw new RuntimeException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

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;

public abstract class ChunkAccess implements BlockGetter {

public abstract ChunkStatus getStatus();

public ChunkPos getPos() {
throw new RuntimeException();
}

public Holder<Biome> getNoiseBiome(int n, int n2, int n3) {
throw new RuntimeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
public class ChunkStatus {

public static final ChunkStatus FEATURES = SneakyUtil.sneakyNotNull();
public static final ChunkStatus FULL = SneakyUtil.sneakyNotNull();
}

0 comments on commit 016dd7c

Please sign in to comment.