Class ImpulseAssert

java.lang.Object
org.impulsegraph.api.util.ImpulseAssert

public final class ImpulseAssert extends Object
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?

  1. javac injects a synthetic $assertionsDisabled static field and a conditional branch (ifeq/ifne) at every call site, polluting JaCoCo and javap branch coverage metrics.
  2. Caller methods in VmHandlers and ImpulseVmInterpreter accumulate bytecode bloat that can exceed HotSpot FreqInlineSize (325 bytes).
  3. By moving the check inside static methods gated by static final boolean or ImpulseTestControl flags, caller bytecode stays minimal and clean.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Tier 1: Standard internal invariant assertions (-Dimpulse.debug.assertions=true).
    static final boolean
    Tier 2: Expensive O(N) structural audit assertions (-Dimpulse.debug.audit=true).
    static final boolean
    Coverage mode (-Dimpulse.coverage.test=true): makes ALWAYS/NEVER pass-through constants.
    static final boolean
    static final boolean
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    always(boolean cond)
    SQLite ALWAYS(X) equivalent: Assertions enabled: traps if !cond. Coverage mode: returns true so defensive fallback is not counted as missed. Release mode: returns cond (self-healing / ductile behavior).
    static void
    audit(BooleanSupplier checkFn, String msg)
    Tier 2: Expensive O(N) structural invariant check (IMPULSE_AUDIT_ASSERT).
    static void
    check(boolean cond, String msg)
    Tier 1: Internal invariant check (SQLite assert(X) / IMPULSE_ASSERT(X)).
    static void
    check(boolean cond, Supplier<String> msgSupplier)
     
    static void
    checkWellFormed(boolean cond, String msg)
    Tier 1b: Well-formed snapshot/bytecode invariant (SQLite assert(X || CORRUPT_DB)).
    static void
    checkWellFormed(boolean cond, Supplier<String> msgSupplier)
     
    static long
     
    static boolean
     
    static boolean
     
    static boolean
     
    static boolean
     
    static boolean
    never(boolean cond)
    SQLite NEVER(X) equivalent: Assertions enabled: traps if cond. Coverage mode: returns false. Release mode: returns cond (self-healing / ductile behavior).
    static void
     
    static void
     
    static void
    setAssertionsEnabled(boolean enabled)
     
    static void
    setAuditEnabled(boolean enabled)
     
    static void
    setCoverageMode(boolean enabled)
     
    static void
    setNeverCorrupt(boolean value)
     
    static void
    testcase(boolean cond)
    SQLite testcase(X) equivalent with default siteId 1.
    static void
    testcase(int siteId, boolean cond)
    SQLite testcase(X) equivalent: records boundary condition evaluation (bit 0 = true observed, bit 1 = false observed; mask 0x03 = both sides hit).
    static void
    testcase(int siteId, String description, boolean cond)
    SQLite testcase(X) with a human-readable boundary description.
    static String
    testcaseDescription(int siteId)
    Returns the description registered for siteId, or empty string if none.
    static int
    testcaseMask(int siteId)
    Returns the observed bitmask at siteId (1 = true seen, 2 = false seen, 3 = both seen).
    Returns a sorted snapshot of all recorded testcase site bitmasks.
    static long
    testcaseTrueCount(int siteId)
    Returns the number of times cond == true was observed at siteId.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ASSERTIONS_ENABLED_PROP

      public static final boolean ASSERTIONS_ENABLED_PROP
      Tier 1: Standard internal invariant assertions (-Dimpulse.debug.assertions=true).
    • ENABLE_ASSERTIONS

      public static final boolean ENABLE_ASSERTIONS
    • AUDIT_ENABLED_PROP

      public static final boolean AUDIT_ENABLED_PROP
      Tier 2: Expensive O(N) structural audit assertions (-Dimpulse.debug.audit=true).
    • ENABLE_AUDIT

      public static final boolean ENABLE_AUDIT
    • COVERAGE_TEST_PROP

      public static final boolean COVERAGE_TEST_PROP
      Coverage 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

      public static void check(boolean cond, String msg)
      Tier 1: Internal invariant check (SQLite assert(X) / IMPULSE_ASSERT(X)). Must never depend on untrusted external input unless guarded by checkWellFormed(boolean, String).
    • check

      public static void check(boolean cond, Supplier<String> msgSupplier)
    • checkWellFormed

      public static void checkWellFormed(boolean cond, String msg)
      Tier 1b: Well-formed snapshot/bytecode invariant (SQLite assert(X || CORRUPT_DB)). Only traps when both assertions and neverCorrupt are enabled; otherwise allows the caller's normal error return path to handle corrupt input gracefully.
    • checkWellFormed

      public static void checkWellFormed(boolean cond, Supplier<String> msgSupplier)
    • audit

      public static void audit(BooleanSupplier checkFn, String msg)
      Tier 2: Expensive O(N) structural invariant check (IMPULSE_AUDIT_ASSERT). Uses a BooleanSupplier so O(N) traversal is skipped entirely when disabled.
    • always

      public static boolean always(boolean cond)
      SQLite ALWAYS(X) equivalent:
      • Assertions enabled: traps if !cond.
      • Coverage mode: returns true so defensive fallback is not counted as missed.
      • Release mode: returns cond (self-healing / ductile behavior).
    • never

      public static boolean never(boolean cond)
      SQLite NEVER(X) equivalent:
      • Assertions enabled: traps if cond.
      • Coverage mode: returns false.
      • Release mode: returns cond (self-healing / ductile behavior).
    • testcase

      public static void testcase(boolean cond)
      SQLite testcase(X) equivalent with default siteId 1.
    • testcase

      public static void testcase(int siteId, boolean cond)
      SQLite testcase(X) equivalent: records boundary condition evaluation (bit 0 = true observed, bit 1 = false observed; mask 0x03 = both sides hit).
    • testcase

      public static void testcase(int siteId, String description, boolean cond)
      SQLite testcase(X) with a human-readable boundary description.
    • testcaseTrueCount

      public static long testcaseTrueCount(int siteId)
      Returns the number of times cond == true was observed at siteId.
    • testcaseMask

      public static int testcaseMask(int siteId)
      Returns the observed bitmask at siteId (1 = true seen, 2 = false seen, 3 = both seen).
    • testcaseSnapshot

      public static Map<Integer,Integer> testcaseSnapshot()
      Returns a sorted snapshot of all recorded testcase site bitmasks.
    • testcaseDescription

      public static String testcaseDescription(int siteId)
      Returns the description registered for siteId, or empty string if none.
    • coverageCounterSum

      public static long coverageCounterSum()
    • resetCoverage

      public static void resetCoverage()
    • resetCounters

      public static void resetCounters()