diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2018-10-03 21:16:27 +0200 |
---|---|---|
committer | Evgeny Mandrikov <Godin@users.noreply.github.com> | 2018-10-03 21:16:27 +0200 |
commit | 01b961b755bd47164739896d2d9c0960e882fd40 (patch) | |
tree | d0e9a32f95837032d3c14a326a84a76435be1a6e /org.jacoco.core/src/org/jacoco/core/internal | |
parent | 9dfd348cc084a469e41623ee335aaaace97692e3 (diff) | |
download | jacoco-01b961b755bd47164739896d2d9c0960e882fd40.tar.gz |
No need to modify class bytes for Java 10 support (#740)
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal')
4 files changed, 17 insertions, 84 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/BytecodeVersion.java b/org.jacoco.core/src/org/jacoco/core/internal/BytecodeVersion.java deleted file mode 100644 index c24828b3..00000000 --- a/org.jacoco.core/src/org/jacoco/core/internal/BytecodeVersion.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Evgeny Mandrikov - initial API and implementation - * - *******************************************************************************/ -package org.jacoco.core.internal; - -import org.objectweb.asm.Opcodes; - -/** - * Utilities to read and modify bytecode version in bytes of class. Main purpose - * of this class is to deal with bytecode versions which are not yet supported - * by ASM. - */ -public final class BytecodeVersion { - - private static final int VERSION_INDEX = 6; - - /** - * Version of the Java 10 class file format. - */ - public static final int V10 = Opcodes.V9 + 1; - - private BytecodeVersion() { - } - - /** - * Gets major of bytecode version number from given bytes of class. - * - * @param b - * bytes of class - * @return version of bytecode - */ - public static int get(final byte[] b) { - return (short) (((b[VERSION_INDEX] & 0xFF) << 8) - | (b[VERSION_INDEX + 1] & 0xFF)); - } - - /** - * Sets major of bytecode version in given bytes of class. - * - * @param b - * bytes of class - * @param version - * version of bytecode to set - */ - public static void set(final byte[] b, final int version) { - b[VERSION_INDEX] = (byte) (version >>> 8); - b[VERSION_INDEX + 1] = (byte) version; - } - - /** - * Returns given bytes of class if its major bytecode version is less that - * {@link #V10}, otherwise returns copy where major version set to - * {@link Opcodes#V9}. - * - * @param version - * version of bytecode - * @param source - * bytes of class - * @return given bytes of class if version is less than {@link #V10}, - * otherwise copy where version set to {@link Opcodes#V9} - */ - public static byte[] downgradeIfNeeded(final int version, - final byte[] source) { - if (V10 != version) { - return source; - } - final byte[] b = new byte[source.length]; - System.arraycopy(source, 0, b, 0, source.length); - set(b, Opcodes.V9); - return b; - } - -} diff --git a/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java b/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java index c74d3374..5ef3a9a0 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java @@ -83,7 +83,7 @@ public class ContentTypeDetector { case Opcodes.V1_7: case Opcodes.V1_8: case Opcodes.V9: - case BytecodeVersion.V10: + case Opcodes.V10: case Opcodes.V11: case Opcodes.V11 | Opcodes.V_PREVIEW_EXPERIMENTAL: case Opcodes.V12: 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 1d4cf2a3..c4569c28 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 @@ -13,6 +13,7 @@ package org.jacoco.core.internal.instr; import static java.lang.String.format; +import org.objectweb.asm.ClassReader; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -157,6 +158,20 @@ 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 of bytecode version number from given bytes of class. + * + * @param b + * bytes of class + * @return version of bytecode + */ + public static int getVersionMajor(final byte[] b) { + return (short) (((b[MAJOR_VERSION_INDEX] & 0xFF) << 8) + | (b[MAJOR_VERSION_INDEX + 1] & 0xFF)); + } + /** * Determines whether the given class file version requires stackmap frames. * 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 a4fb82b0..4e1938f2 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 @@ -11,7 +11,6 @@ *******************************************************************************/ package org.jacoco.core.internal.instr; -import org.jacoco.core.internal.BytecodeVersion; import org.jacoco.core.internal.flow.ClassProbesAdapter; import org.jacoco.core.runtime.IExecutionDataAccessorGenerator; import org.objectweb.asm.ClassReader; @@ -44,7 +43,7 @@ public final class ProbeArrayStrategyFactory { final IExecutionDataAccessorGenerator accessorGenerator) { final String className = reader.getClassName(); - final int version = BytecodeVersion.get(reader.b); + final int version = InstrSupport.getVersionMajor(reader.b); if (isInterfaceOrModule(reader)) { final ProbeCounter counter = getProbeCounter(reader); |