Class InstrSupport
- java.lang.Object
-
- org.jacoco.core.internal.instr.InstrSupport
-
public final class InstrSupport extends java.lang.Object
Constants and utilities for byte code instrumentation.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ASM_API_VERSION
ASM API version(package private) static int
CLINIT_ACC
Access flags of the interface initialization method generated by JaCoCo.(package private) static java.lang.String
CLINIT_DESC
Descriptor of the interface initialization method.(package private) static java.lang.String
CLINIT_NAME
Name of the interface initialization method.static int
DATAFIELD_ACC
Access modifiers of the field that stores coverage information of a class.static java.lang.String
DATAFIELD_DESC
Data type of the field that stores coverage information for a class (boolean[]
).static int
DATAFIELD_INTF_ACC
Access modifiers of the field that stores coverage information of a Java 8 interface.static java.lang.String
DATAFIELD_NAME
Name of the field that stores coverage information of a class.static int
INITMETHOD_ACC
Access modifiers of the initialization method.static java.lang.String
INITMETHOD_DESC
Descriptor of the initialization method.static java.lang.String
INITMETHOD_NAME
Name of the initialization method.
-
Constructor Summary
Constructors Modifier Constructor Description private
InstrSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertNotInstrumented(java.lang.String member, java.lang.String owner)
Ensures that the given member does not correspond to a internal member created by the instrumentation process.static org.objectweb.asm.ClassReader
classReaderFor(byte[] b)
Creates aClassReader
instance for given bytes of class even if its version not yet supported by ASM.static int
getMajorVersion(byte[] b)
Gets major version number from given bytes of class (unsigned two bytes at offset 6).static int
getMajorVersion(org.objectweb.asm.ClassReader reader)
Gets major version number from givenClassReader
.static boolean
needsFrames(int version)
Determines whether the given class file version requires stackmap frames.static void
push(org.objectweb.asm.MethodVisitor mv, int value)
Generates the instruction to push the given int value on the stack.static void
setMajorVersion(int majorVersion, byte[] b)
Sets major version number in given bytes of class (unsigned two bytes at offset 6).
-
-
-
Field Detail
-
ASM_API_VERSION
public static final int ASM_API_VERSION
ASM API version- See Also:
- Constant Field Values
-
DATAFIELD_NAME
public static final java.lang.String DATAFIELD_NAME
Name of the field that stores coverage information of a class.- See Also:
- Constant Field Values
-
DATAFIELD_ACC
public static final int DATAFIELD_ACC
Access modifiers of the field that stores coverage information of a class. According to Java Virtual Machine Specification §6.5.putstatic this field must not be final:if the field is final, it must be declared in the current class, and the instruction must occur in the
<clinit>
method of the current class.- See Also:
- Constant Field Values
-
DATAFIELD_INTF_ACC
public static final int DATAFIELD_INTF_ACC
Access modifiers of the field that stores coverage information of a Java 8 interface. According to Java Virtual Machine Specification §4.5:Fields of interfaces must have their ACC_PUBLIC, ACC_STATIC, and ACC_FINAL flags set; they may have their ACC_SYNTHETIC flag set and must not have any of the other flags.
- See Also:
- Constant Field Values
-
DATAFIELD_DESC
public static final java.lang.String DATAFIELD_DESC
Data type of the field that stores coverage information for a class (boolean[]
).- See Also:
- Constant Field Values
-
INITMETHOD_NAME
public static final java.lang.String INITMETHOD_NAME
Name of the initialization method.- See Also:
- Constant Field Values
-
INITMETHOD_DESC
public static final java.lang.String INITMETHOD_DESC
Descriptor of the initialization method.- See Also:
- Constant Field Values
-
INITMETHOD_ACC
public static final int INITMETHOD_ACC
Access modifiers of the initialization method.- See Also:
- Constant Field Values
-
CLINIT_NAME
static final java.lang.String CLINIT_NAME
Name of the interface initialization method. According to Java Virtual Machine Specification §2.9:A class or interface has at most one class or interface initialization method and is initialized by invoking that method. The initialization method of a class or interface has the special name
<clinit>
, takes no arguments, and is void.Other methods named
<clinit>
in a class file are of no consequence. They are not class or interface initialization methods. They cannot be invoked by any Java Virtual Machine instruction and are never invoked by the Java Virtual Machine itself.In a class file whose version number is 51.0 or above, the method must additionally have its ACC_STATIC flag set in order to be the class or interface initialization method.
This requirement was introduced in Java SE 7. In a class file whose version number is 50.0 or below, a method named
<clinit>
that is void and takes no arguments is considered the class or interface initialization method regardless of the setting of its ACC_STATIC flag.Class and interface initialization methods are called implicitly by the Java Virtual Machine. The value of their access_flags item is ignored except for the setting of the ACC_STRICT flag.
- See Also:
- Constant Field Values
-
CLINIT_DESC
static final java.lang.String CLINIT_DESC
Descriptor of the interface initialization method.- See Also:
CLINIT_NAME
, Constant Field Values
-
CLINIT_ACC
static final int CLINIT_ACC
Access flags of the interface initialization method generated by JaCoCo.- See Also:
CLINIT_NAME
, Constant Field Values
-
-
Method Detail
-
getMajorVersion
public static int getMajorVersion(byte[] b)
Gets major version number from given bytes of class (unsigned two bytes at offset 6).- Parameters:
b
- bytes of class- Returns:
- major version of bytecode
- See Also:
- Java
Virtual Machine Specification §4 The class File Format,
setMajorVersion(int, byte[])
,getMajorVersion(ClassReader)
-
setMajorVersion
public static void setMajorVersion(int majorVersion, byte[] b)
Sets major version number in given bytes of class (unsigned two bytes at offset 6).- Parameters:
majorVersion
- major version of bytecode to setb
- bytes of class- See Also:
getMajorVersion(byte[])
-
getMajorVersion
public static int getMajorVersion(org.objectweb.asm.ClassReader reader)
Gets major version number from givenClassReader
.- Parameters:
reader
- reader to get information about the class- Returns:
- major version of bytecode
- See Also:
ClassReader(byte[], int, int)
,getMajorVersion(byte[])
-
needsFrames
public static boolean needsFrames(int version)
Determines whether the given class file version requires stackmap frames.- Parameters:
version
- class file version- Returns:
true
if frames are required
-
assertNotInstrumented
public static void assertNotInstrumented(java.lang.String member, java.lang.String owner) throws java.lang.IllegalStateException
Ensures that the given member does not correspond to a internal member created by the instrumentation process. This would mean that the class is already instrumented.- Parameters:
member
- name of the member to checkowner
- name of the class owning the member- Throws:
java.lang.IllegalStateException
- thrown if the member has the same name than the instrumentation member
-
push
public static void push(org.objectweb.asm.MethodVisitor mv, int value)
Generates the instruction to push the given int value on the stack. Implementation taken fromGeneratorAdapter.push(int)
.- Parameters:
mv
- visitor to emit the instructionvalue
- the value to be pushed on the stack.
-
classReaderFor
public static org.objectweb.asm.ClassReader classReaderFor(byte[] b)
Creates aClassReader
instance for given bytes of class even if its version not yet supported by ASM.- Parameters:
b
- bytes of class- Returns:
ClassReader
-
-