diff --git a/src/main/java/com/code_intelligence/jazzer/agent/RuntimeInstrumentor.kt b/src/main/java/com/code_intelligence/jazzer/agent/RuntimeInstrumentor.kt index f83cf00d7..8b8dcc994 100644 --- a/src/main/java/com/code_intelligence/jazzer/agent/RuntimeInstrumentor.kt +++ b/src/main/java/com/code_intelligence/jazzer/agent/RuntimeInstrumentor.kt @@ -214,12 +214,9 @@ class RuntimeInstrumentor( } return ClassInstrumentor(internalClassName, bytecode).run { if (fullInstrumentation) { - // Hook instrumentation must be performed after data flow tracing as the injected - // bytecode would trigger the GEP callbacks for byte[]. Coverage instrumentation - // must be performed after hook instrumentation as the injected bytecode would - // trigger the GEP callbacks for ByteBuffer. - traceDataFlow(instrumentationTypes) - hooks(includedHooks + customHooks, classWithHooksEnabledField) + // Coverage instrumentation must be performed before any other code updates + // or there will be additional coverage points injected if any calls are inserted + // and JaCoCo will produce a broken coverage report. coverageIdSynchronizer.withIdForClass(internalClassName) { firstId -> coverage(firstId).also { actualNumEdgeIds -> CoverageRecorder.recordInstrumentedClass( @@ -230,6 +227,10 @@ class RuntimeInstrumentor( ) } } + // Hook instrumentation must be performed after data flow tracing as the injected + // bytecode would trigger the GEP callbacks for byte[]. + traceDataFlow(instrumentationTypes) + hooks(includedHooks + customHooks, classWithHooksEnabledField) } else { hooks(customHooks, classWithHooksEnabledField) } diff --git a/tests/src/test/java/com/example/CoverageFuzzer.java b/tests/src/test/java/com/example/CoverageFuzzer.java index 0e84ef6b5..1d65d3b7d 100644 --- a/tests/src/test/java/com/example/CoverageFuzzer.java +++ b/tests/src/test/java/com/example/CoverageFuzzer.java @@ -171,7 +171,7 @@ private static void assertCoverageDump() throws IOException { assertEquals(7, countHits(coverageFuzzerCoverage.getProbes())); assertEquals("com/example/CoverageFuzzer$ClassToCover", classToCoverCoverage.getName()); - assertEquals(11, countHits(classToCoverCoverage.getProbes())); + assertEquals(10, countHits(classToCoverCoverage.getProbes())); } private static int countHits(boolean[] probes) {