DebugMemoryUntracker .java

com.mojang.blaze3d.platform.DebugMemoryUntracker (class): members: UNTRACK, untrack. strings: "org.lwjgl.system.MemoryManage$DebugAllocator", "ALLOCATOR".

com.mojang.blaze3d.platformclass40 linesclient1.4 KB

API Surface (1)

void untrack(final long address)

Fields & Constants (1)

UNTRACK

String literals (4)

"org.lwjgl.system.MemoryManage$DebugAllocator"
"untrack"
"org.lwjgl.system.MemoryUtil$LazyInit"
"ALLOCATOR"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

DebugMemoryUntracker.java40 lines · Minecraft 26.3 · verbatim
1
package com.mojang.blaze3d.platform;
2
3
import java.lang.invoke.MethodHandle;
4
import java.lang.invoke.MethodHandles;
5
import java.lang.invoke.MethodHandles.Lookup;
6
import java.lang.reflect.Field;
7
import java.lang.reflect.Method;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
import net.minecraft.util.Util;
11
import org.jspecify.annotations.Nullable;
12
13
@Environment(EnvType.CLIENT)
14
public class DebugMemoryUntracker {
15
	private static final @Nullable MethodHandle UNTRACK = Util.make(() -> {
16
		try {
17
			Lookup lookup = MethodHandles.lookup();
18
			Class<?> debugAllocator = Class.forName("org.lwjgl.system.MemoryManage$DebugAllocator");
19
			Method reflectionUntrack = debugAllocator.getDeclaredMethod("untrack", long.class);
20
			reflectionUntrack.setAccessible(true);
21
			Field allocatorField = Class.forName("org.lwjgl.system.MemoryUtil$LazyInit").getDeclaredField("ALLOCATOR");
22
			allocatorField.setAccessible(true);
23
			Object allocator = allocatorField.get(null);
24
			return debugAllocator.isInstance(allocator) ? lookup.unreflect(reflectionUntrack) : null;
25
		} catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException e) {
26
			throw new RuntimeException(e);
27
		}
28
	});
29
30
	public static void untrack(final long address) {
31
		if (UNTRACK != null) {
32
			try {
33
				UNTRACK.invoke((long)address);
34
			} catch (Throwable throwable) {
35
				throw new RuntimeException(throwable);
36
			}
37
		}
38
	}
39
}
40

Decompiled Minecraft 26.3 source of DebugMemoryUntracker (com/mojang/blaze3d/platform/DebugMemoryUntracker.java) with Mojang official mappings, stored verbatim on the site.