Class ImpulseAssert
java.lang.Object
org.impulsegraph.api.util.ImpulseAssert
Zero-overhead, C2-JIT-friendly invariant assertion and boundary coverage
primitives modeled on SQLite's sqliteInt.h (assert, CORRUPT_DB, ALWAYS,
NEVER, testcase).
Why not Java's built-in assert keyword?
javacinjects a synthetic$assertionsDisabledstatic field and a conditional branch (ifeq/ifne) at every call site, polluting JaCoCo andjavapbranch coverage metrics.- Caller methods in
VmHandlersandImpulseVmInterpreteraccumulate bytecode bloat that can exceed HotSpotFreqInlineSize(325 bytes). - By moving the check inside static methods gated by
static final booleanorImpulseTestControlflags, caller bytecode stays minimal and clean.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanTier 1: Standard internal invariant assertions (-Dimpulse.debug.assertions=true).static final booleanTier 2: Expensive O(N) structural audit assertions (-Dimpulse.debug.audit=true).static final booleanCoverage mode (-Dimpulse.coverage.test=true): makes ALWAYS/NEVER pass-through constants.static final booleanAlias forASSERTIONS_ENABLED_PROP.static final booleanAlias forAUDIT_ENABLED_PROP. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanalways(boolean cond) SQLiteALWAYS(X)equivalent: Assertions enabled: traps if!cond. Coverage mode: returnstrueso defensive fallback is not counted as missed. Release mode: returnscond(self-healing / ductile behavior).static voidaudit(BooleanSupplier checkFn, String msg) Tier 2: Expensive O(N) structural invariant check (IMPULSE_AUDIT_ASSERT).static voidTier 1: Internal invariant check (SQLiteassert(X)/IMPULSE_ASSERT(X)).static voidstatic voidcheckWellFormed(boolean cond, String msg) Tier 1b: Well-formed snapshot/bytecode invariant (SQLiteassert(X || CORRUPT_DB)).static voidcheckWellFormed(boolean cond, Supplier<String> msgSupplier) static longstatic booleanstatic booleanstatic booleanstatic booleanstatic booleannever(boolean cond) SQLiteNEVER(X)equivalent: Assertions enabled: traps ifcond. Coverage mode: returnsfalse. Release mode: returnscond(self-healing / ductile behavior).static voidstatic voidstatic voidsetAssertionsEnabled(boolean enabled) static voidsetAuditEnabled(boolean enabled) static voidsetCoverageMode(boolean enabled) static voidsetNeverCorrupt(boolean value) static voidtestcase(boolean cond) SQLitetestcase(X)equivalent with default siteId1.static voidtestcase(int siteId, boolean cond) SQLitetestcase(X)equivalent: records boundary condition evaluation (bit 0 =trueobserved, bit 1 =falseobserved; mask0x03= both sides hit).static voidSQLitetestcase(X)with a human-readable boundary description.static StringtestcaseDescription(int siteId) Returns the description registered forsiteId, or empty string if none.static inttestcaseMask(int siteId) Returns the observed bitmask atsiteId(1 = true seen, 2 = false seen, 3 = both seen).Returns a sorted snapshot of all recorded testcase site bitmasks.static longtestcaseTrueCount(int siteId) Returns the number of timescond == truewas observed atsiteId.
-
Field Details
-
ASSERTIONS_ENABLED_PROP
public static final boolean ASSERTIONS_ENABLED_PROPTier 1: Standard internal invariant assertions (-Dimpulse.debug.assertions=true). -
ENABLE_ASSERTIONS
public static final boolean ENABLE_ASSERTIONSAlias forASSERTIONS_ENABLED_PROP. -
AUDIT_ENABLED_PROP
public static final boolean AUDIT_ENABLED_PROPTier 2: Expensive O(N) structural audit assertions (-Dimpulse.debug.audit=true). -
ENABLE_AUDIT
public static final boolean ENABLE_AUDITAlias forAUDIT_ENABLED_PROP. -
COVERAGE_TEST_PROP
public static final boolean COVERAGE_TEST_PROPCoverage mode (-Dimpulse.coverage.test=true): makes ALWAYS/NEVER pass-through constants.
-
-
Method Details
-
isAssertionsEnabled
public static boolean isAssertionsEnabled() -
setAssertionsEnabled
public static void setAssertionsEnabled(boolean enabled) -
isAuditEnabled
public static boolean isAuditEnabled() -
setAuditEnabled
public static void setAuditEnabled(boolean enabled) -
isCoverageMode
public static boolean isCoverageMode() -
setCoverageMode
public static void setCoverageMode(boolean enabled) -
setNeverCorrupt
public static void setNeverCorrupt(boolean value) -
isNeverCorrupt
public static boolean isNeverCorrupt() -
check
Tier 1: Internal invariant check (SQLiteassert(X)/IMPULSE_ASSERT(X)). Must never depend on untrusted external input unless guarded bycheckWellFormed(boolean, String). -
check
-
checkWellFormed
Tier 1b: Well-formed snapshot/bytecode invariant (SQLiteassert(X || CORRUPT_DB)). Only traps when both assertions andneverCorruptare enabled; otherwise allows the caller's normal error return path to handle corrupt input gracefully. -
checkWellFormed
-
audit
Tier 2: Expensive O(N) structural invariant check (IMPULSE_AUDIT_ASSERT). Uses aBooleanSupplierso O(N) traversal is skipped entirely when disabled. -
always
public static boolean always(boolean cond) SQLiteALWAYS(X)equivalent:- Assertions enabled: traps if
!cond. - Coverage mode: returns
trueso defensive fallback is not counted as missed. - Release mode: returns
cond(self-healing / ductile behavior).
- Assertions enabled: traps if
-
never
public static boolean never(boolean cond) SQLiteNEVER(X)equivalent:- Assertions enabled: traps if
cond. - Coverage mode: returns
false. - Release mode: returns
cond(self-healing / ductile behavior).
- Assertions enabled: traps if
-
testcase
public static void testcase(boolean cond) SQLitetestcase(X)equivalent with default siteId1. -
testcase
public static void testcase(int siteId, boolean cond) SQLitetestcase(X)equivalent: records boundary condition evaluation (bit 0 =trueobserved, bit 1 =falseobserved; mask0x03= both sides hit). -
testcase
SQLitetestcase(X)with a human-readable boundary description. -
testcaseTrueCount
public static long testcaseTrueCount(int siteId) Returns the number of timescond == truewas observed atsiteId. -
testcaseMask
public static int testcaseMask(int siteId) Returns the observed bitmask atsiteId(1 = true seen, 2 = false seen, 3 = both seen). -
testcaseSnapshot
-
testcaseDescription
Returns the description registered forsiteId, or empty string if none. -
coverageCounterSum
public static long coverageCounterSum() -
resetCoverage
public static void resetCoverage() -
resetCounters
public static void resetCounters()
-