Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/java-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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 <n> classes alone (includes=com.example.shop.*)
INFO: Keploy dedup: started JaCoCo 0.8.16 on the app's <n> classes alone (includes=com.example.shop.*)
```

When the SDK cannot tell the app's classes from its libraries, it says so at
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion keploy-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jacoco.version>0.8.15</jacoco.version>
<jacoco.version>0.8.16</jacoco.version>
<!-- The test JVM's heap. Left to the JVM, it is a quarter of the machine's RAM (of the host's when the
JVM does not see its container's limit), and the build table rows allocate enough for JDK 8's
collector to grow the heap past a 4 GiB container's limit. -DargLine=... overrides it. -->
Expand Down
14 changes: 7 additions & 7 deletions keploy-sdk/src/main/resources/META-INF/THIRD-PARTY-NOTICES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
*
* <p>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, "<init>", "()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", "<init>", "()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<BuildTable.ClassFile> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jv1-91aa3fda68544563b2a8cca5ad1dde54
jv1-0d58cc7984b9d647a658b6ea350f1083
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jv1-d2b0c051a964d63b882ad20b37ebda64
jv1-04626a1d2f798b7b0916a095c6a240bc
Loading
Loading