Skip to content

Commit

Permalink
Add back some overzealous removals
Browse files Browse the repository at this point in the history
  • Loading branch information
antithesis-shomik committed Aug 29, 2024
1 parent 20d56cb commit 9d26276
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions ffi/src/main/java/com/antithesis/ffi/internal/FfiHandler.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.antithesis.ffi.internal;

import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.logging.Logger;

public class FfiHandler implements OutputHandler {

private static long offset = -1;

public static Optional<OutputHandler> get() {
try {
FfiWrapperJNI.loadLibrary();
Expand All @@ -26,4 +26,23 @@ public long random() {
return FfiWrapperJNI.fuzz_get_random();
}

public long initializeModuleCoverage(long edgeCount, String symbolFilePath) {
if (offset != -1) {
// A Java application may not contain multiple "modules" in Antithesis terms.
throw new IllegalStateException("Antithesis Java instrumentation has already been initialized.");
}
if (edgeCount > Integer.MAX_VALUE || edgeCount < 1) {
throw new IllegalArgumentException("Antithesis Java instrumentation supports [1 ," + Integer.MAX_VALUE + "] edges");
}
offset = FfiWrapperJNI.init_coverage_module(edgeCount, symbolFilePath);
return offset;
}

public void notifyModuleEdge(long edgePlusModule) {
// Right now, the Java implementation defers completely to the native library.
// See instrumentation.h to understand the logic here. The shim (i.e. StaticModule.java)
// is responsible for handling the return value.
FfiWrapperJNI.notify_coverage(edgePlusModule);
}

}

0 comments on commit 9d26276

Please sign in to comment.