diff --git a/.github/workflows/java-agent.yml b/.github/workflows/java-agent.yml index 3c799022..726fc7c5 100644 --- a/.github/workflows/java-agent.yml +++ b/.github/workflows/java-agent.yml @@ -78,3 +78,30 @@ jobs: run: | mvn -B -P release -Dgpg.skip -DskipTests verify sha256sum -c "$RUNNER_TEMP/keploy-sdk-jars.sha256" + + smoke-jdk27: + name: JDK 27 embedded JaCoCo smoke + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 21 to build keploy-sdk + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + cache: maven + + - name: Build keploy-sdk jar + run: mvn -B -DskipTests package + + - name: Set up JDK 27 for target app runtime + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "27" + + - name: Smoke test JDK 27 app (class major 71) with embedded JaCoCo 0.8.16 + run: ./scripts/smoke-jdk27.sh diff --git a/README.md b/README.md index 274fd3cb..c34c2e3c 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ It collects per-testcase Java coverage during Keploy replay and sends that cover The repository contains only the dedup-focused `keploy-sdk` module. -Supported runtimes in CI today are Java 8, 17, and 21. +Supported runtimes in CI today are Java 8, 11, 17, and 21 (+ JDK 27 smoke). -Dynamic dedup works on applications compiled up to **Java 26**. See +Dynamic dedup works on applications compiled up to **Java 27**. See [Supported Java versions](#supported-java-versions) for where that ceiling comes from and how to raise it. @@ -91,7 +91,7 @@ test's coverage would be measured. Application code should not import `io.keploy java -javaagent:/path/to/keploy-sdk.jar -jar your-app.jar ``` -It carries the JaCoCo agent (`jacocoagent.jar`, JaCoCo 0.8.15, EPL-2.0, +It carries the JaCoCo agent (`jacocoagent.jar`, JaCoCo 0.8.16, EPL-2.0, unchanged, at `io/keploy/dedup/jacocoagent.jar`; see `META-INF/THIRD-PARTY-NOTICES.txt` in the jar) and starts it itself, before the app's `main`, with `includes=` set to the app's own classes, which it finds from @@ -100,7 +100,7 @@ how the JVM was launched (Spring Boot, Jib, shaded and plain jars, class dirs; classes, not every library class the app loads. The startup log says which: ``` -INFO: Keploy dedup: started JaCoCo 0.8.15 on the app's classes alone (includes=com.example.shop.*) +INFO: Keploy dedup: started JaCoCo 0.8.16 on the app's classes alone (includes=com.example.shop.*) ``` When the SDK cannot tell the app's classes from its libraries, it says so at @@ -110,7 +110,7 @@ app's class dirs and jars to fix that. An app that ships its own `org.jacoco.agent` (any JaCoCo version) keeps it, and the SDK keeps its own: `keploy-sdk.jar` holds none of that artifact's classes, and its `jacocoagent.jar` is not where that artifact's `AgentJar` looks, so the -SDK starts JaCoCo 0.8.15 whether the app's jar comes before or after +SDK starts JaCoCo 0.8.16 whether the app's jar comes before or after `keploy-sdk.jar` on the class path, and the app's `AgentJar` reads the app's own `jacocoagent.jar`, also in a Spring Boot fat jar. @@ -173,10 +173,10 @@ supported ceiling is the lower of two limits — not one: | Component | Role | Reads up to | | --- | --- | --- | -| `jacocoagent.jar` (carried in `keploy-sdk.jar`; on k8s, the k8s-proxy init image's) | analyzes coverage | Java 26 (JaCoCo 0.8.15) | -| `keploy-sdk.jar` (this repo) | instruments the app, via the ASM shaded in through `org.jacoco:org.jacoco.core` | Java 26 (jacoco.core 0.8.15) | +| `jacocoagent.jar` (carried in `keploy-sdk.jar`; on k8s, the k8s-proxy init image's) | analyzes coverage | Java 27 (JaCoCo 0.8.16) | +| `keploy-sdk.jar` (this repo) | instruments the app, via the ASM shaded in through `org.jacoco:org.jacoco.core` | Java 27 (jacoco.core 0.8.16) | -Both currently sit at **Java 26**, so that is the effective ceiling. +Both currently sit at **Java 27**, so that is the effective ceiling. The floor is **Java 8**. keploy-sdk's and keploy-junit5's own code is compiled for Java 8 (class file version 52), and, when built on JDK 9 or later (the @@ -208,10 +208,14 @@ reason instead of failing silently. 1. Bump `jacoco.version` in `keploy-sdk/pom.xml` (both `org.jacoco.core` and the `jacocoagent.jar` the SDK carries), change the JaCoCo and ASM versions named in `keploy-sdk/src/main/resources/META-INF/THIRD-PARTY-NOTICES.txt` and in this - README to match, and cut a release. -2. In k8s-proxy, bump `KEPLOY_SDK_VERSION` (`build/dedup-jars/build.sh`) to that - release, and set `BundledJaCoCoVersion`, `JaCoCoOfficialMaxJava` and - `SDKShadedASMMaxJava` in `pkg/platform/dedupinject/jacocompat.go`. + README to match, update the build-table `.build` goldens (`java-dedup.build` + and `edge.build`), update `Java27BytecodeSupportTest` and + `scripts/smoke-jdk27.sh` for the new ceiling, and cut a release. +2. In k8s-proxy, update `BundledJaCoCoVersion`, `BundledJaCoCoZipSHA256`, + `JaCoCoOfficialMaxJava`, `SDKShadedASMMaxJava`, `BundledJavaSDKVersion`, + `BundledJavaSDKJarSHA256`, and `BundledDedupJarsRevision` in + `pkg/platform/dedupinject/jacocompat.go` (alongside + `.woodpecker/dedup-images-release.yml` and `tools/imagelicenses/images.go`). Take the Java number from JaCoCo's [release notes](https://www.jacoco.org/jacoco/trunk/doc/changes.html) — the diff --git a/keploy-sdk/pom.xml b/keploy-sdk/pom.xml index cabdebbe..1adba3fd 100644 --- a/keploy-sdk/pom.xml +++ b/keploy-sdk/pom.xml @@ -19,7 +19,7 @@ UTF-8 UTF-8 - 0.8.15 + 0.8.16 diff --git a/keploy-sdk/src/main/resources/META-INF/THIRD-PARTY-NOTICES.txt b/keploy-sdk/src/main/resources/META-INF/THIRD-PARTY-NOTICES.txt index f4c8e5ed..0a739f99 100644 --- a/keploy-sdk/src/main/resources/META-INF/THIRD-PARTY-NOTICES.txt +++ b/keploy-sdk/src/main/resources/META-INF/THIRD-PARTY-NOTICES.txt @@ -4,27 +4,27 @@ keploy-sdk/; the build that makes the jar, renaming the packages below, is keploy-sdk/pom.xml. keploy-sdk.jar also carries the third-party software below, which stays under its own license. -JaCoCo 0.8.15 - Eclipse Public License 2.0 (META-INF/LICENSE-EPL-2.0.txt in +JaCoCo 0.8.16 - Eclipse Public License 2.0 (META-INF/LICENSE-EPL-2.0.txt in the jar; https://www.eclipse.org/legal/epl-2.0/) Copyright (c) 2009, 2026 Mountainminds GmbH & Co. KG and Contributors JaCoCo's source code is available under the EPL-2.0 at - https://github.com/jacoco/jacoco, tag v0.8.15 (jacocoagent.jar is built + https://github.com/jacoco/jacoco, tag v0.8.16 (jacocoagent.jar is built from its org.jacoco.agent.rt module), and org.jacoco.core's also from - Maven Central as org.jacoco:org.jacoco.core:0.8.15:sources. - - jacocoagent.jar, unchanged, from org.jacoco:org.jacoco.agent:0.8.15, at + Maven Central as org.jacoco:org.jacoco.core:0.8.16:sources. + - jacocoagent.jar, unchanged, from org.jacoco:org.jacoco.agent:0.8.16, at io/keploy/dedup/jacocoagent.jar in the jar; keploy-sdk starts it when the JVM attaches no JaCoCo agent of its own. It holds its own about.html, which is also org.jacoco.agent's. - - the classes of org.jacoco:org.jacoco.core:0.8.15, unchanged but for their + - the classes of org.jacoco:org.jacoco.core:0.8.16, unchanged but for their package, renamed from org.jacoco.core to io.keploy.shaded.org.jacoco.core (maven-shade-plugin relocation, keploy-sdk/pom.xml), so that they never meet an app's own JaCoCo. about.html at the root of the jar is org.jacoco.core's, unchanged. Neither it nor the one inside jacocoagent.jar covers the rest of the jar. -ASM 9.10.1 - BSD 3-Clause License +ASM 9.11.1 - BSD 3-Clause License Source: https://gitlab.ow2.org/asm/asm - - the classes of org.ow2.asm:asm, asm-commons and asm-tree 9.10.1, which + - the classes of org.ow2.asm:asm, asm-commons and asm-tree 9.11.1, which org.jacoco.core depends on, unchanged but for their package, renamed from org.objectweb.asm to io.keploy.shaded.org.objectweb.asm. - the copy of ASM inside jacocoagent.jar, whose version the about.html diff --git a/keploy-sdk/src/test/java/io/keploy/dedup/Java27BytecodeSupportTest.java b/keploy-sdk/src/test/java/io/keploy/dedup/Java27BytecodeSupportTest.java new file mode 100644 index 00000000..4fe5aa4e --- /dev/null +++ b/keploy-sdk/src/test/java/io/keploy/dedup/Java27BytecodeSupportTest.java @@ -0,0 +1,150 @@ +package io.keploy.dedup; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.jacoco.core.internal.data.CRC64; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Guards JaCoCo 0.8.16 / ASM 9.11.1 bytecode support for Java 27 (class-file major 71). + * + *

Synthesizes a real major-71 class file with branching instructions and line numbers so + * this test runs on every JDK in the build matrix (8, 11, 17, 21, ...) while exercising + * {@link BuildTable}, {@link CoverageReporter}, and ASM {@link ClassReader} on Java 27 bytecode. + */ +public class Java27BytecodeSupportTest { + + @Rule + public final TemporaryFolder tmp = new TemporaryFolder(); + + private static byte[] java27BranchingClass(String internalName) { + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cw.visit(Opcodes.V27, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, internalName, null, "java/lang/Object", null); + cw.visitSource("Jdk27Sample.java", null); + + MethodVisitor init = cw.visitMethod(Opcodes.ACC_PUBLIC, "", "()V", null, null); + init.visitCode(); + Label initLine = new Label(); + init.visitLabel(initLine); + init.visitLineNumber(4, initLine); + init.visitVarInsn(Opcodes.ALOAD, 0); + init.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "", "()V", false); + init.visitInsn(Opcodes.RETURN); + init.visitMaxs(0, 0); + init.visitEnd(); + + // static int classify(int x) { if (x > 0) return x + 1; return -x; } + MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "classify", "(I)I", null, null); + mv.visitCode(); + Label l10 = new Label(); + Label elseLbl = new Label(); + mv.visitLabel(l10); + mv.visitLineNumber(10, l10); + mv.visitVarInsn(Opcodes.ILOAD, 0); + mv.visitJumpInsn(Opcodes.IFLE, elseLbl); + Label l11 = new Label(); + mv.visitLabel(l11); + mv.visitLineNumber(11, l11); + mv.visitVarInsn(Opcodes.ILOAD, 0); + mv.visitInsn(Opcodes.ICONST_1); + mv.visitInsn(Opcodes.IADD); + mv.visitInsn(Opcodes.IRETURN); + mv.visitLabel(elseLbl); + mv.visitLineNumber(13, elseLbl); + mv.visitVarInsn(Opcodes.ILOAD, 0); + mv.visitInsn(Opcodes.INEG); + mv.visitInsn(Opcodes.IRETURN); + mv.visitMaxs(0, 0); + mv.visitEnd(); + + cw.visitEnd(); + return cw.toByteArray(); + } + + @Test + public void jacocoVersionAndAsmCeilingMatch0816() { + assertEquals("0.8.16", IndexReport.Analyzer.JACOCO); + assertEquals(71, Opcodes.V27); + assertEquals(72, Opcodes.V28); + } + + @Test + public void buildTableAndCoverageReporterAnalyzeJava27ClassFiles() throws Exception { + final String vmName = "com/example/jdk27/Jdk27Sample"; + byte[] classBytes = java27BranchingClass(vmName); + + // Confirm the synthesized header is actually Java 27 (class-file major 71). + int major = ((classBytes[6] & 0xFF) << 8) | (classBytes[7] & 0xFF); + assertEquals(71, major); + + // ASM ClassReader reads the major-71 class cleanly. + assertEquals(vmName, new ClassReader(classBytes).getClassName()); + + // BuildTable maps lines, branches, and probes for major-71 bytecode with 0 unmeasured classes. + BuildTableTest.Collect tableOut = new BuildTableTest.Collect(); + BuildTableTest.Collect probesOut = new BuildTableTest.Collect(); + List files = Collections.singletonList(new BuildTable.ClassFile(vmName, classBytes)); + BuildTable.Summary summary = BuildTable.write(files, tableOut, probesOut); + assertEquals(1, summary.records); + assertEquals(0, summary.notMeasured); + assertEquals(0, summary.noLines); + assertEquals(1, tableOut.records.size()); + assertEquals(1, probesOut.records.size()); + + JsonObject unit = JsonParser.parseString(tableOut.records.get(0)).getAsJsonObject(); + assertEquals("ok", unit.get("state").getAsString()); + assertEquals("c:" + vmName, unit.get("id").getAsString()); + + JsonObject probeRec = JsonParser.parseString(probesOut.records.get(0)).getAsJsonObject(); + int probeCount = probeRec.getAsJsonArray("probes").size(); + assertTrue("expected probes for Java 27 branching class, got " + probeCount, probeCount >= 3); + + // CoverageReporter reconstructs line + branch coverage from fired probes on the major-71 class. + File classesDir = tmp.newFolder("classes"); + Path classFile = classesDir.toPath().resolve(vmName + ".class"); + Files.createDirectories(classFile.getParent()); + Files.write(classFile, classBytes); + + String hexId = String.format("%016x", CRC64.classId(classBytes)); + StringBuilder allProbes = new StringBuilder("["); + for (int i = 0; i < probeCount; i++) { + if (i > 0) { + allProbes.append(','); + } + allProbes.append(i); + } + allProbes.append(']'); + + Path unionFile = tmp.newFile("union.json").toPath(); + Files.write(unionFile, ("{\"" + vmName + "\":" + allProbes + "}").getBytes(StandardCharsets.UTF_8)); + Path manifestFile = tmp.newFile("manifest.json").toPath(); + Files.write(manifestFile, + ("{\"" + vmName + "\":{\"id\":\"" + hexId + "\",\"probeCount\":" + probeCount + "}}") + .getBytes(StandardCharsets.UTF_8)); + + CoverageReporter.CoverageResult res = CoverageReporter.compute(classesDir.toPath(), unionFile, manifestFile); + assertEquals(1, res.classCount); + assertEquals(1, res.hitClassCount); + assertTrue("expected lineTotal > 0, got " + res.lineTotal, res.lineTotal > 0); + assertEquals(res.lineTotal, res.lineCovered); + assertTrue("expected branchTotal >= 2, got " + res.branchTotal, res.branchTotal >= 2); + assertEquals(res.branchTotal, res.branchCovered); + } +} diff --git a/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/edge.build b/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/edge.build index 876c4c16..1e74a1e6 100644 --- a/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/edge.build +++ b/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/edge.build @@ -1 +1 @@ -jv1-91aa3fda68544563b2a8cca5ad1dde54 +jv1-0d58cc7984b9d647a658b6ea350f1083 diff --git a/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/java-dedup.build b/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/java-dedup.build index 1179d0ee..15e35329 100644 --- a/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/java-dedup.build +++ b/keploy-sdk/src/test/resources/io/keploy/dedup/buildtable/java-dedup.build @@ -1 +1 @@ -jv1-d2b0c051a964d63b882ad20b37ebda64 +jv1-04626a1d2f798b7b0916a095c6a240bc diff --git a/scripts/smoke-jdk27.sh b/scripts/smoke-jdk27.sh new file mode 100755 index 00000000..9ce52861 --- /dev/null +++ b/scripts/smoke-jdk27.sh @@ -0,0 +1,229 @@ +#!/usr/bin/env bash +# Smoke test keploy-sdk.jar's embedded JaCoCo 0.8.16 agent on a real JDK 27 app +# (class-file major version 71). +# +# Compiles a small branching app with the active JDK's javac, asserts the +# compiled class header is major 71 (Java 27), runs it with ONLY +# `-javaagent:keploy-sdk.jar` (embedded JaCoCo, matching k8s-proxy's replay +# injection), and verifies: +# 1. INDEX reports jacoco="embedded" and jacocoVersion="0.8.16"; +# 2. two calls along the same branch produce identical non-empty probe sets +# (dedup candidate); +# 3. a call along a different branch produces a distinct non-empty probe set. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +module_dir="${repo_root}/keploy-sdk" +agent_jar="${KEPLOY_SDK_JAR:-}" +if [[ -z "${agent_jar}" && -d "${module_dir}/target" ]]; then + agent_jar="$(find "${module_dir}/target" -maxdepth 1 -type f -name 'keploy-sdk-*.jar' \ + ! -name 'original-*' ! -name '*-sources.jar' ! -name '*-javadoc.jar' | sort | head -n 1)" +fi + +if [[ -z "${agent_jar}" || ! -f "${agent_jar}" ]]; then + echo "Missing agent jar under ${module_dir}/target (run mvn -B -DskipTests package first)" >&2 + exit 1 +fi + +work_dir="$(mktemp -d)" +cleanup() { + rm -rf "${work_dir}" + rm -f /tmp/coverage_control.sock /tmp/coverage_data.sock +} +trap cleanup EXIT + +mkdir -p "${work_dir}/src/smoke27" "${work_dir}/classes" + +cat > "${work_dir}/src/smoke27/BranchApp.java" <<'JAVA' +package smoke27; + +final class BranchApp { + private BranchApp() {} + + static int branchA(int n) { + int acc = 0; + for (int i = 0; i <= n; i++) { + acc += i; + } + return acc; + } + + static int branchB(int n) { + int acc = 1; + for (int i = 1; i <= n; i++) { + acc *= i; + } + return acc; + } +} +JAVA + +cat > "${work_dir}/src/smoke27/Jdk27SmokeHarness.java" <<'JAVA' +package smoke27; + +import org.newsclub.net.unix.AFUNIXServerSocket; +import org.newsclub.net.unix.AFUNIXSocket; +import org.newsclub.net.unix.AFUNIXSocketAddress; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +public final class Jdk27SmokeHarness { + private static final File CONTROL_SOCKET = new File("/tmp/coverage_control.sock"); + private static final File DATA_SOCKET = new File("/tmp/coverage_data.sock"); + + public static void main(String[] args) throws Exception { + Path classFile = Paths.get(args[0]); + byte[] header = Files.readAllBytes(classFile); + int major = ((header[6] & 0xFF) << 8) | (header[7] & 0xFF); + if (major != 71) { + throw new IllegalStateException("expected Java 27 class major 71, got " + major); + } + + if (DATA_SOCKET.exists() && !DATA_SOCKET.delete()) { + throw new IllegalStateException("failed to delete " + DATA_SOCKET); + } + final BlockingQueue records = new LinkedBlockingQueue<>(); + final CountDownLatch receiverBound = new CountDownLatch(1); + Thread receiver = new Thread(() -> { + try (AFUNIXServerSocket server = AFUNIXServerSocket.newInstance()) { + server.bind(AFUNIXSocketAddress.of(DATA_SOCKET), 8); + receiverBound.countDown(); + for (;;) { + try (AFUNIXSocket socket = server.accept()) { + records.add(readAll(socket.getInputStream())); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + }, "jdk27-smoke-receiver"); + receiver.setDaemon(true); + receiver.start(); + + if (!receiverBound.await(10, TimeUnit.SECONDS)) { + throw new IllegalStateException("timed out waiting for receiver to bind " + DATA_SOCKET); + } + + command("START test-set-0/a1", true); + if (BranchApp.branchA(5) != 15) { + throw new IllegalStateException("branchA returned wrong value"); + } + command("END test-set-0/a1", false); + + String first = next(records); + String indexReport = null; + String covA1 = first; + if (first.startsWith("{\"kind\":\"index\",")) { + indexReport = first; + covA1 = next(records); + } + if (indexReport == null + || !indexReport.contains("\"jacoco\":\"embedded\"") + || !indexReport.contains("\"jacocoVersion\":\"0.8.16\"")) { + throw new IllegalStateException("expected embedded JaCoCo 0.8.16 INDEX report, got: " + indexReport); + } + + command("START test-set-0/a2", false); + if (BranchApp.branchA(5) != 15) { + throw new IllegalStateException("branchA returned wrong value"); + } + command("END test-set-0/a2", false); + String covA2 = next(records); + + command("START test-set-0/b1", false); + if (BranchApp.branchB(5) != 120) { + throw new IllegalStateException("branchB returned wrong value"); + } + command("END test-set-0/b1", false); + String covB1 = next(records); + + String probesA1 = extractBranchAppProbes(covA1); + String probesA2 = extractBranchAppProbes(covA2); + String probesB1 = extractBranchAppProbes(covB1); + if (probesA1.isEmpty() || probesA2.isEmpty() || probesB1.isEmpty()) { + throw new IllegalStateException("missing smoke27/BranchApp probes: a1=" + covA1 + " a2=" + covA2 + " b1=" + covB1); + } + if (!probesA1.equals(probesA2)) { + throw new IllegalStateException("identical branchA calls produced different probes: " + probesA1 + " vs " + probesA2); + } + if (probesA1.equals(probesB1)) { + throw new IllegalStateException("distinct branchA and branchB calls produced identical probes: " + probesA1); + } + if (covA1.contains("\"classMismatch\"") || covA2.contains("\"classMismatch\"") || covB1.contains("\"classMismatch\"")) { + throw new IllegalStateException("unexpected classMismatch on Java 27 app: " + covA1 + " / " + covB1); + } + System.out.println("smoke-jdk27: PASS (class major=" + major + ", jacocoVersion=0.8.16, a1==a2=" + probesA1 + ", b1=" + probesB1 + ")"); + } + + private static String extractBranchAppProbes(String json) { + String key = "\"smoke27/BranchApp\":["; + int start = json.indexOf(key); + if (start < 0) { + return ""; + } + int end = json.indexOf(']', start + key.length()); + if (end < 0) { + return ""; + } + return json.substring(start + key.length(), end); + } + + private static void command(String cmd, boolean wantWindowCut) throws Exception { + try (AFUNIXSocket socket = AFUNIXSocket.newInstance()) { + socket.connect(AFUNIXSocketAddress.of(CONTROL_SOCKET), 3000); + socket.setSoTimeout(5000); + OutputStream output = socket.getOutputStream(); + output.write((cmd + "\n").getBytes(StandardCharsets.UTF_8)); + output.flush(); + String ack = readAll(socket.getInputStream()); + String pattern = "^ACK proto=3 caps=windowCut=" + wantWindowCut + + ",contaminated=true,classMismatch=true,background=true,ackId=true,asyncExecutors=" + + (wantWindowCut ? "(true|false)" : "false") + + ",listenerContamination=(true|false)\\n$"; + if (!ack.matches(pattern)) { + throw new IllegalStateException("unexpected ACK for " + cmd + " (wantWindowCut=" + + wantWindowCut + "): " + ack); + } + } + } + + private static String next(BlockingQueue records) throws InterruptedException { + String r = records.poll(10, TimeUnit.SECONDS); + if (r == null) { + throw new IllegalStateException("timed out waiting for coverage record"); + } + return r; + } + + private static String readAll(InputStream input) throws Exception { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int n; + while ((n = input.read(buf)) != -1) { + output.write(buf, 0, n); + } + return new String(output.toByteArray(), StandardCharsets.UTF_8); + } +} +JAVA + +javac -cp "${agent_jar}" -d "${work_dir}/classes" \ + "${work_dir}/src/smoke27/BranchApp.java" \ + "${work_dir}/src/smoke27/Jdk27SmokeHarness.java" + +rm -f /tmp/coverage_control.sock /tmp/coverage_data.sock +timeout 180 java \ + -javaagent:"${agent_jar}" \ + -cp "${work_dir}/classes:${agent_jar}" \ + smoke27.Jdk27SmokeHarness "${work_dir}/classes/smoke27/BranchApp.class"