1// SPDX-License-Identifier: EPL-2.0 and Apache-2.0 2// These patches apply to JaCoCo (https://github.com/jacoco/jacoco) and are hereby made available under the terms of the 3// Eclipse Public License 2.0 available at: 4// http://www.eclipse.org/legal/epl-2.0 5diff --git org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java 6index 476c9e34..bc192dc6 100644 7--- org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java 8+++ org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java 9@@ -24,6 +24,7 @@ import org.objectweb.asm.MethodVisitor; 10 public class ClassInstrumenter extends ClassProbesVisitor { 11 12 private final IProbeArrayStrategy probeArrayStrategy; 13+ private final IProbeInserterFactory probeInserterFactory; 14 15 private String className; 16 17@@ -40,6 +41,22 @@ public class ClassInstrumenter extends ClassProbesVisitor { 18 final ClassVisitor cv) { 19 super(cv); 20 this.probeArrayStrategy = probeArrayStrategy; 21+ this.probeInserterFactory = new IProbeInserterFactory() { 22+ @Override 23+ public ProbeInserter makeProbeInserter(int access, String name, 24+ String desc, MethodVisitor mv, 25+ IProbeArrayStrategy arrayStrategy) { 26+ return new ProbeInserter(access, name, desc, mv, arrayStrategy); 27+ } 28+ }; 29+ } 30+ 31+ public ClassInstrumenter(final IProbeArrayStrategy probeArrayStrategy, 32+ final IProbeInserterFactory probeInserterFactory, 33+ final ClassVisitor cv) { 34+ super(cv); 35+ this.probeArrayStrategy = probeArrayStrategy; 36+ this.probeInserterFactory = probeInserterFactory; 37 } 38 39 @Override 40@@ -71,8 +88,9 @@ public class ClassInstrumenter extends ClassProbesVisitor { 41 return null; 42 } 43 final MethodVisitor frameEliminator = new DuplicateFrameEliminator(mv); 44- final ProbeInserter probeVariableInserter = new ProbeInserter(access, 45- name, desc, frameEliminator, probeArrayStrategy); 46+ final ProbeInserter probeVariableInserter = 47+ probeInserterFactory.makeProbeInserter(access, name, desc, 48+ frameEliminator, probeArrayStrategy); 49 return new MethodInstrumenter(probeVariableInserter, 50 probeVariableInserter); 51 } 52diff --git org.jacoco.core/src/org/jacoco/core/internal/instr/IProbeInserterFactory.java org.jacoco.core/src/org/jacoco/core/internal/instr/IProbeInserterFactory.java 53new file mode 100644 54index 00000000..19c2a7e2 55--- /dev/null 56+++ org.jacoco.core/src/org/jacoco/core/internal/instr/IProbeInserterFactory.java 57@@ -0,0 +1,8 @@ 58+package org.jacoco.core.internal.instr; 59+ 60+import org.objectweb.asm.MethodVisitor; 61+ 62+public interface IProbeInserterFactory { 63+ ProbeInserter makeProbeInserter(int access, String name, String desc, 64+ MethodVisitor mv, IProbeArrayStrategy arrayStrategy); 65+} 66diff --git org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java 67index 71808ac8..3df93f63 100644 68--- org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java 69+++ org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java 70@@ -78,7 +78,7 @@ public final class InstrSupport { 71 * Data type of the field that stores coverage information for a class ( 72 * <code>boolean[]</code>). 73 */ 74- public static final String DATAFIELD_DESC = "[Z"; 75+ public static final String DATAFIELD_DESC = "java/nio/ByteBuffer"; 76 77 // === Init Method === 78 79diff --git org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java 80index 0f5b99ff..ba5daa6d 100644 81--- org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java 82+++ org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java 83@@ -25,7 +25,7 @@ import org.objectweb.asm.TypePath; 84 * addition the probe array has to be retrieved at the beginning of the method 85 * and stored in a local variable. 86 */ 87-class ProbeInserter extends MethodVisitor implements IProbeInserter { 88+public class ProbeInserter extends MethodVisitor implements IProbeInserter { 89 90 private final IProbeArrayStrategy arrayStrategy; 91 92@@ -36,7 +36,7 @@ class ProbeInserter extends MethodVisitor implements IProbeInserter { 93 private final boolean clinit; 94 95 /** Position of the inserted variable. */ 96- private final int variable; 97+ protected final int variable; 98 99 /** Maximum stack usage of the code to access the probe array. */ 100 private int accessorStackSize; 101@@ -56,7 +56,7 @@ class ProbeInserter extends MethodVisitor implements IProbeInserter { 102 * callback to create the code that retrieves the reference to 103 * the probe array 104 */ 105- ProbeInserter(final int access, final String name, final String desc, 106+ public ProbeInserter(final int access, final String name, final String desc, 107 final MethodVisitor mv, final IProbeArrayStrategy arrayStrategy) { 108 super(InstrSupport.ASM_API_VERSION, mv); 109 this.clinit = InstrSupport.CLINIT_NAME.equals(name); 110