Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>dfa11</sonar.organization>
<sonar.projectKey>dfa1_zstd-java</sonar.projectKey>
<!-- The benchmark module is JMH main code with no tests by design, and the
native modules carry no Java sources — neither should drag the coverage
ratio. Exclude from coverage. -->
<!-- The benchmark module is a JMH harness, not shipped runtime: its
@Setup/@TearDown lifecycle trips false "resource not closed" reports and
it has no tests by design. Exclude from analysis entirely (which also
keeps it out of the coverage ratio). -->
<sonar.exclusions>
**/benchmark/**
</sonar.exclusions>
<sonar.coverage.exclusions>
**/benchmark/**
</sonar.coverage.exclusions>
Expand Down
2 changes: 1 addition & 1 deletion zstd/src/main/java/io/github/dfa1/zstd/Bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ final class Bindings {
static final MethodHandle DPARAM_GET_BOUNDS =
NativeLibrary.lookup("ZSTD_dParam_getBounds", FunctionDescriptor.of(BOUNDS_LAYOUT, JAVA_INT));

// ZSTD_frameProgression { u64 ingested, consumed, produced, flushed; u32 currentJobID, nbActiveWorkers; }
// ZSTD_frameProgression layout: u64 ingested, consumed, produced, flushed, then u32 currentJobID, nbActiveWorkers.
private static final MemoryLayout FRAME_PROGRESSION_LAYOUT =
MemoryLayout.structLayout(JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_INT, JAVA_INT);
// ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx*) — returned by value
Expand Down
2 changes: 1 addition & 1 deletion zstd/src/main/java/io/github/dfa1/zstd/NativeObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final void close() {
if (!MemorySegment.NULL.equals(p)) {
try {
tryClose(p);
} catch (Throwable ignored) {
} catch (Throwable _) {
// destructors must not throw
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public long sizeOf() {

@Override
protected void tryClose(MemorySegment ptr) throws Throwable {
long ignored = (long) Bindings.FREE_CCTX.invokeExact(ptr);
var _ = (long) Bindings.FREE_CCTX.invokeExact(ptr);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public long sizeOf() {

@Override
protected void tryClose(MemorySegment ptr) throws Throwable {
long ignored = (long) Bindings.FREE_CDICT.invokeExact(ptr);
var _ = (long) Bindings.FREE_CDICT.invokeExact(ptr);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public long sizeOf() {
@Override
protected void tryClose(MemorySegment ptr) throws Throwable {
try {
long ignored = (long) Bindings.FREE_CCTX.invokeExact(ptr);
var _ = (long) Bindings.FREE_CCTX.invokeExact(ptr);
} finally {
arena.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public long sizeOf() {

@Override
protected void tryClose(MemorySegment ptr) throws Throwable {
long ignored = (long) Bindings.FREE_DCTX.invokeExact(ptr);
var _ = (long) Bindings.FREE_DCTX.invokeExact(ptr);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public long sizeOf() {

@Override
protected void tryClose(MemorySegment ptr) throws Throwable {
long ignored = (long) Bindings.FREE_DDICT.invokeExact(ptr);
var _ = (long) Bindings.FREE_DDICT.invokeExact(ptr);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public long sizeOf() {
@Override
protected void tryClose(MemorySegment ptr) throws Throwable {
try {
long ignored = (long) Bindings.FREE_DCTX.invokeExact(ptr);
var _ = (long) Bindings.FREE_DCTX.invokeExact(ptr);
} finally {
arena.close();
}
Expand Down
21 changes: 12 additions & 9 deletions zstd/src/main/java/io/github/dfa1/zstd/ZstdDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@
/// }
public final class ZstdDictionary {

// ZDICT_cover_params_t { unsigned k,d,steps,nbThreads; double splitPoint;
// unsigned shrinkDict, shrinkDictMaxRegression; ZDICT_params_t zParams; }
// ZDICT_params_t { int compressionLevel; unsigned notificationLevel, dictID; }
private static final String FIELD_NB_THREADS = "nbThreads";
private static final String FIELD_COMPRESSION_LEVEL = "compressionLevel";

// ZDICT_cover_params_t fields: unsigned k, d, steps, nbThreads; double
// splitPoint; unsigned shrinkDict, shrinkDictMaxRegression; then a nested
// ZDICT_params_t of int compressionLevel, unsigned notificationLevel, dictID.
private static final MemoryLayout COVER_PARAMS = MemoryLayout.structLayout(
JAVA_INT.withName("k"),
JAVA_INT.withName("d"),
JAVA_INT.withName("steps"),
JAVA_INT.withName("nbThreads"),
JAVA_INT.withName(FIELD_NB_THREADS),
JAVA_DOUBLE.withName("splitPoint"),
JAVA_INT.withName("shrinkDict"),
JAVA_INT.withName("shrinkDictMaxRegression"),
JAVA_INT.withName("compressionLevel"),
JAVA_INT.withName(FIELD_COMPRESSION_LEVEL),
JAVA_INT.withName("notificationLevel"),
JAVA_INT.withName("dictID"),
MemoryLayout.paddingLayout(4)); // trailing pad to the C struct's 8-byte alignment
Expand All @@ -54,13 +57,13 @@ public final class ZstdDictionary {
JAVA_INT.withName("d"),
JAVA_INT.withName("f"),
JAVA_INT.withName("steps"),
JAVA_INT.withName("nbThreads"),
JAVA_INT.withName(FIELD_NB_THREADS),
MemoryLayout.paddingLayout(4),
JAVA_DOUBLE.withName("splitPoint"),
JAVA_INT.withName("accel"),
JAVA_INT.withName("shrinkDict"),
JAVA_INT.withName("shrinkDictMaxRegression"),
JAVA_INT.withName("compressionLevel"),
JAVA_INT.withName(FIELD_COMPRESSION_LEVEL),
JAVA_INT.withName("notificationLevel"),
JAVA_INT.withName("dictID"));

Expand Down Expand Up @@ -192,8 +195,8 @@ private static ZstdDictionary optimize(List<byte[]> samples, int maxDictBytes,
// zeroed params (auto-tune k/d/steps); set single-threaded + target level.
MemoryLayout layout = fast ? FASTCOVER_PARAMS : COVER_PARAMS;
MemorySegment params = arena.allocate(layout);
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement("nbThreads")), 1);
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement("compressionLevel")), compressionLevel);
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement(FIELD_NB_THREADS)), 1);
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement(FIELD_COMPRESSION_LEVEL)), compressionLevel);
MethodHandle handle = fast ? Bindings.ZDICT_OPTIMIZE_FASTCOVER : Bindings.ZDICT_OPTIMIZE_COVER;
MemorySegment dictBuf = arena.allocate(maxDictBytes);
long produced;
Expand Down
4 changes: 2 additions & 2 deletions zstd/src/main/java/io/github/dfa1/zstd/ZstdInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public void close() throws IOException {
}
closed = true;
try {
long ignored = (long) Bindings.FREE_DCTX.invokeExact(dctx);
} catch (Throwable ignored) {
var _ = (long) Bindings.FREE_DCTX.invokeExact(dctx);
} catch (Throwable _) {
// best-effort free
}
arena.close();
Expand Down
4 changes: 2 additions & 2 deletions zstd/src/main/java/io/github/dfa1/zstd/ZstdOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public void close() throws IOException {
} finally {
closed = true;
try {
long ignored = (long) Bindings.FREE_CCTX.invokeExact(cctx);
} catch (Throwable ignored) {
var _ = (long) Bindings.FREE_CCTX.invokeExact(cctx);
} catch (Throwable _) {
// best-effort free
}
arena.close();
Expand Down
6 changes: 3 additions & 3 deletions zstd/src/main/java/io/github/dfa1/zstd/ZstdStreamBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import static java.lang.foreign.ValueLayout.ADDRESS;
import static java.lang.foreign.ValueLayout.JAVA_LONG;

// Backing for ZSTD_inBuffer / ZSTD_outBuffer, which share the layout
// { void* ptr; size_t size; size_t pos; }
// on LP64: ptr@0 (8), size@8 (8), pos@16 (8) -> 24 bytes.
// Backing for ZSTD_inBuffer / ZSTD_outBuffer, which share a layout of a
// void pointer then two size_t values. On LP64: ptr@0 (8), size@8 (8),
// pos@16 (8) -> 24 bytes.
final class ZstdStreamBuffer {

static final long BYTES = 24;
Expand Down
Loading