diff options
author | Evgeny Mandrikov <138671+Godin@users.noreply.github.com> | 2019-03-08 11:02:27 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2019-03-08 11:02:27 +0100 |
commit | 5128d1b37e095d60ae27e0fc1a68ff40bbf70cc0 (patch) | |
tree | 67bfec06aea433ca4233ffb9ec8e02b8dd3d1472 | |
parent | 290bf3cf1ea3fe0e85e97f42587bf58c83aa3859 (diff) | |
download | platform_external_jacoco-5128d1b37e095d60ae27e0fc1a68ff40bbf70cc0.tar.gz platform_external_jacoco-5128d1b37e095d60ae27e0fc1a68ff40bbf70cc0.tar.bz2 platform_external_jacoco-5128d1b37e095d60ae27e0fc1a68ff40bbf70cc0.zip |
Upgrade ASM to 7.1 (#851)
6 files changed, 97 insertions, 20 deletions
diff --git a/org.jacoco.build/pom.xml b/org.jacoco.build/pom.xml index 0ac0077d..afb76b1e 100644 --- a/org.jacoco.build/pom.xml +++ b/org.jacoco.build/pom.xml @@ -138,7 +138,7 @@ <argLine>${jvm.args}</argLine> <!-- Dependencies versions --> - <asm.version>7.0</asm.version> + <asm.version>7.1</asm.version> <ant.version>1.7.1</ant.version> <args4j.version>2.0.28</args4j.version> <junit.version>4.8.2</junit.version> diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java index f9cf3c13..d679cdbb 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java @@ -71,10 +71,42 @@ public class InstrSupportTest { } @Test - public void getVersionMajor_should_return_major_version_number() { - final byte[] bytes = new byte[] { (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, - (byte) 0xBE, /* minor */ 0x00, 0x03, /* major */ 0x00, 0x2D }; - assertEquals(45, InstrSupport.getVersionMajor(bytes)); + public void getMajorVersion_should_read_unsigned_two_bytes_at_offset_6() { + final byte[] bytes = new byte[] { // + (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE, // magic + (byte) 0xFF, (byte) 0xFF, // minor_version + (byte) 0x80, (byte) 0x12 // major_version + }; + + assertEquals(32786, InstrSupport.getMajorVersion(bytes)); + } + + @Test + public void setMajorVersion_should_write_unsigned_two_bytes_at_offset_6() { + final byte[] bytes = new byte[8]; + + InstrSupport.setMajorVersion(32786, bytes); + + assertArrayEquals( + new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // magic + (byte) 0x00, (byte) 0x00, // minor_version + (byte) 0x80, (byte) 0x12 // major_version + }, bytes); + } + + @Test + public void getMajorVersion_should_read_major_version_from_ClassReader_at_offset_relative_to_constant_pool() { + final byte[] bytes = new byte[] { // + (byte) 0xFF, // before class bytes + (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE, // magic + 0x00, 0x03, // minor_version + (byte) 0x80, 0x12, // major_version + 0x00, 0x02, // constant_pool_count + 0x01, 0x00, 0x00 // constant_pool + }; + + assertEquals(32786, + InstrSupport.getMajorVersion(new ClassReader(bytes, 1, -1))); } @Test diff --git a/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java b/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java index 79748c10..561b09cb 100644 --- a/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java +++ b/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java @@ -81,7 +81,7 @@ public class Instrumenter { }; final IProbeArrayStrategy strategy = ProbeArrayStrategyFactory .createFor(classId, reader, accessorGenerator); - final int version = InstrSupport.getVersionMajor(source); + final int version = InstrSupport.getMajorVersion(reader); final ClassVisitor visitor = new ClassProbesAdapter( new ClassInstrumenter(strategy, writer), InstrSupport.needsFrames(version)); diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java index 99e00270..1e438958 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java @@ -158,18 +158,52 @@ public final class InstrSupport { */ static final int CLINIT_ACC = Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC; - private static final int MAJOR_VERSION_INDEX = 6; + /** + * Gets major version number from given bytes of class (unsigned two bytes + * at offset 6). + * + * @param b + * bytes of class + * @return major version of bytecode + * @see <a href= + * "https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.1">Java + * Virtual Machine Specification ยง4 The class File Format</a> + * @see #setMajorVersion(int, byte[]) + * @see #getMajorVersion(ClassReader) + */ + public static int getMajorVersion(final byte[] b) { + return ((b[6] & 0xFF) << 8) | (b[7] & 0xFF); + } /** - * Gets major of bytecode version number from given bytes of class. + * Sets major version number in given bytes of class (unsigned two bytes at + * offset 6). * + * @param majorVersion + * major version of bytecode to set * @param b * bytes of class - * @return version of bytecode + * @see #getMajorVersion(byte[]) + */ + public static void setMajorVersion(final int majorVersion, final byte[] b) { + b[6] = (byte) (majorVersion >>> 8); + b[7] = (byte) majorVersion; + } + + /** + * Gets major version number from given {@link ClassReader}. + * + * @param reader + * reader to get information about the class + * @return major version of bytecode + * @see ClassReader#ClassReader(byte[], int, int) + * @see #getMajorVersion(byte[]) */ - public static int getVersionMajor(final byte[] b) { - return (short) (((b[MAJOR_VERSION_INDEX] & 0xFF) << 8) - | (b[MAJOR_VERSION_INDEX + 1] & 0xFF)); + public static int getMajorVersion(final ClassReader reader) { + // relative to the beginning of constant pool because ASM provides API + // to construct ClassReader which reads from the middle of array + final int firstConstantPoolEntryOffset = reader.getItem(1) - 1; + return reader.readUnsignedShort(firstConstantPoolEntryOffset - 4); } /** @@ -237,15 +271,13 @@ public final class InstrSupport { * @return {@link ClassReader} */ public static ClassReader classReaderFor(final byte[] b) { - final byte[] originalVersion = new byte[] { b[4], b[5], b[6], b[7] }; - if (getVersionMajor(b) == Opcodes.V12 + 1) { - b[4] = (byte) (Opcodes.V12 >>> 24); - b[5] = (byte) (Opcodes.V12 >>> 16); - b[6] = (byte) (Opcodes.V12 >>> 8); - b[7] = (byte) Opcodes.V12; + final int originalVersion = getMajorVersion(b); + if (originalVersion == Opcodes.V12 + 1) { + // temporarily downgrade version to bypass check in ASM + setMajorVersion(Opcodes.V12, b); } final ClassReader classReader = new ClassReader(b); - System.arraycopy(originalVersion, 0, b, 4, originalVersion.length); + setMajorVersion(originalVersion, b); return classReader; } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeArrayStrategyFactory.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeArrayStrategyFactory.java index 72c8dd68..d5756b7f 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeArrayStrategyFactory.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeArrayStrategyFactory.java @@ -43,7 +43,7 @@ public final class ProbeArrayStrategyFactory { final IExecutionDataAccessorGenerator accessorGenerator) { final String className = reader.getClassName(); - final int version = InstrSupport.getVersionMajor(reader.b); + final int version = InstrSupport.getMajorVersion(reader); if (isInterfaceOrModule(reader)) { final ProbeCounter counter = getProbeCounter(reader); diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 15250c84..71faf94f 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -30,6 +30,13 @@ (GitHub <a href="https://github.com/jacoco/jacoco/issues/849">#849</a>).</li> </ul> +<h3>Fixed bugs</h3> +<ul> + <li>Fixed incorrect update of frames caused by bug in ASM library in case of + arrays with more than 7 dimensions + (GitHub <a href="https://github.com/jacoco/jacoco/issues/839">#839</a>).</li> +</ul> + <h3>API Changes</h3> <ul> <li>Methods <code>Instrumenter.instrument(org.objectweb.asm.ClassReader)</code> @@ -38,6 +45,12 @@ (GitHub <a href="https://github.com/jacoco/jacoco/issues/850">#850</a>).</li> </ul> +<h3>Non-functional Changes</h3> +<ul> + <li>JaCoCo now depends on ASM 7.1 + (GitHub <a href="https://github.com/jacoco/jacoco/issues/851">#851</a>).</li> +</ul> + <h2>Release 0.8.3 (2019/01/23)</h2> <h3>New Features</h3> |