Skip to content

Commit

Permalink
[Core] Update debug functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Jan 6, 2024
1 parent a1b34dd commit 5d8650f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
![Maven Central](https://img.shields.io/maven-central/v/io.github.over-run/overrungl)
![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.over-run/overrungl?server=https%3A%2F%2Fs01.oss.sonatype.org%2F)

![GitHub repo size](https://img.shields.io/github/repo-size/Over-Run/overrungl)
[![Java CI with Gradle](https://github.com/Over-Run/overrungl/actions/workflows/gradle.yml/badge.svg?event=push)](https://github.com/Over-Run/overrungl/actions/workflows/gradle.yml)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8279/badge)](https://www.bestpractices.dev/projects/8279)

## Introduction

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,8 +19,10 @@
import io.github.overrun.platform.Architecture;
import io.github.overrun.platform.Platform;
import org.jetbrains.annotations.Nullable;
import overrungl.Configurations;
import overrungl.FunctionDescriptors;
import overrungl.NativeType;
import overrungl.OverrunGL;
import overrungl.util.MemoryUtil;

import java.io.File;
Expand Down Expand Up @@ -167,6 +169,9 @@ public static SymbolLookup load(String module, String basename, String version)
}
uri = libFile.toURI();
}
if (Configurations.DEBUG.get()) {
OverrunGL.apiLog(STR."[OverrunGL] Loading native library from: \{uri}");
}
// Load the library by the path with the global arena
return SymbolLookup.libraryLookup(Path.of(uri), Arena.global());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -45,16 +45,16 @@ final class DebugAllocator {
for (Allocation allocation : ALLOCATIONS.keySet()) {
StringBuilder sb = new StringBuilder(512);

sb.append(STR. """
[OverrunGL] \{ allocation.size } bytes leaked,\
thread \{ allocation.threadId } (\{ THREADS.get(allocation.threadId) }),\
address: 0x\{ Long.toHexString(allocation.address).toUpperCase() }
""" );
sb.append(STR."""
[OverrunGL] \{allocation.size} bytes leaked,\
thread \{allocation.threadId} (\{THREADS.get(allocation.threadId)}),\
address: 0x\{Long.toHexString(allocation.address).toUpperCase()}
""");

StackTraceElement[] stackTrace = allocation.getElements();
if (stackTrace != null) {
for (Object el : stackTrace) {
sb.append(STR. "\tat \{ el.toString() }\n" );
sb.append(STR."\tat \{el.toString()}\n");
}
} else {
missingStacktrace = true;
Expand Down Expand Up @@ -99,22 +99,22 @@ private static void trackAbort(long address, Allocation allocationOld, Allocatio
trackAbortPrint(allocationOld, "Old", addressHex);
trackAbortPrint(allocationNew, "New", addressHex);

throw Exceptions.ISE. "The memory address specified is already being tracked: 0x\{ addressHex }" ;
throw Exceptions.ISE."The memory address specified is already being tracked: 0x\{addressHex}";
}

private static void trackAbortPrint(Allocation allocation, String name, String address) {
StringBuilder sb = new StringBuilder(512);

sb.append(STR. """
[OverrunGL] \{ name } allocation with size \{ allocation.size },\
thread \{ allocation.threadId } (\{ THREADS.get(allocation.threadId) }),\
address: 0x\{ address }
""" );
sb.append(STR."""
[OverrunGL] \{name} allocation with size \{allocation.size},\
thread \{allocation.threadId} (\{THREADS.get(allocation.threadId)}),\
address: 0x\{address}
""");

StackTraceElement[] stackTrace = allocation.getElements();
if (stackTrace != null) {
for (Object el : stackTrace) {
sb.append(STR. "\tat \{ el.toString() }\n" );
sb.append(STR."\tat \{el.toString()}\n");
}
}

Expand All @@ -138,7 +138,7 @@ static long untrack(long address) {
private static void untrackAbort(long address) {
String addressHex = Long.toHexString(address).toUpperCase();

throw Exceptions.ISE. "The memory address specified is not being tracked: 0x\{ addressHex }" ;
throw Exceptions.ISE."The memory address specified is not being tracked: 0x\{addressHex}";
}

private record Allocation(long address, long size, long threadId, @Nullable Object[] stacktrace) {
Expand All @@ -147,10 +147,11 @@ private StackTraceElement[] getElements() {
return stacktrace == null ? null : StackWalkUtil.stackWalkArray(stacktrace);
}

@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override
public boolean equals(Object obj) {
return address == ((Allocation) obj).address;
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Allocation that)) return false;
return address == that.address;
}

@Override
Expand Down

0 comments on commit 5d8650f

Please sign in to comment.