#!/usr/bin/env bash # Patches GraphUtils.java (one line), compiles the patched class via # --patch-module, then runs InferenceGraphScalingTest against the original # and patched jdk.compiler side-by-side. # # Usage: cd tests && bash bench/patch-and-time.sh set -euo pipefail JAVA="java" JAVAC="java -m jdk.compiler/com.sun.tools.javac.Main" REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" SRC="$REPO_ROOT/src/jdk.compiler/share/classes/com/sun/tools/javac/util/GraphUtils.java" PATCH_SRC="/tmp/jt-patch/com/sun/tools/javac/util" PATCH_CLASSES="/tmp/jt-patch-classes" EXPORTS="--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" TESTS="$(cd "$(dirname "$0")/.." && pwd)" echo "=== Tarjan Before/After: Real GraphUtils timing ===" echo "" # ── Compile test classes ─────────────────────────────────────────────────────── echo "[setup] Compiling integration test classes..." cd "$TESTS" $JAVAC $EXPORTS -cp . support/AbstractTestNode.java integration/InferenceGraphScalingTest.java # ── BEFORE: original GraphUtils ─────────────────────────────────────────────── echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " BEFORE (defective: stack.contains(n) — O(V²))" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" $JAVA $EXPORTS -cp . integration.InferenceGraphScalingTest # ── Apply patch ──────────────────────────────────────────────────────────────── echo "" echo "[patch] Applying: stack.contains(n) → n.active (GraphUtils.java:186)" mkdir -p "$PATCH_SRC" "$PATCH_CLASSES" cp "$SRC" "$PATCH_SRC/GraphUtils.java" sed -i 's/} else if (stack\.contains(n)) {/} else if (n.active) {/' \ "$PATCH_SRC/GraphUtils.java" if grep -q "n.active" "$PATCH_SRC/GraphUtils.java"; then echo "[patch] ✓ Patch confirmed" else echo "[patch] ✗ Patch failed — aborting" >&2; exit 1 fi $JAVAC \ --patch-module "jdk.compiler=/tmp/jt-patch" \ $EXPORTS \ -d "$PATCH_CLASSES" \ "$PATCH_SRC/GraphUtils.java" echo "[patch] ✓ Patched class compiled → $PATCH_CLASSES" # ── AFTER: patched GraphUtils ───────────────────────────────────────────────── echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " AFTER (fixed: n.active — O(V+E))" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" $JAVA \ --patch-module "jdk.compiler=$PATCH_CLASSES" \ $EXPORTS \ -cp . \ integration.InferenceGraphScalingTest # ── Cleanup ──────────────────────────────────────────────────────────────────── rm -rf /tmp/jt-patch /tmp/jt-patch-classes echo "" echo "Done."