diff options
author | Evgeny Mandrikov <Godin@users.noreply.github.com> | 2018-03-21 05:23:26 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2018-03-21 05:23:26 +0100 |
commit | e0681662b4cc311bca7e9433261960c766fab8a8 (patch) | |
tree | 92dbf158505f69a78e6e37ab05be1ab42ce7d075 /org.jacoco.core/src/org/jacoco/core/internal | |
parent | 04e13929cff687d829c7704e345ccabb85ee6723 (diff) | |
download | jacoco-e0681662b4cc311bca7e9433261960c766fab8a8.tar.gz |
Add Java 10 support (#629)
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal')
3 files changed, 89 insertions, 9 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 new file mode 100644 index 00000000..c24828b3 --- /dev/null +++ b/org.jacoco.core/src/org/jacoco/core/internal/BytecodeVersion.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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 ae665624..b30f6366 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java @@ -83,6 +83,7 @@ public class ContentTypeDetector { case Opcodes.V1_7: case Opcodes.V1_8: case Opcodes.V9: + case BytecodeVersion.V10: return CLASSFILE; } } 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 349840b0..38d572af 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,7 @@ *******************************************************************************/ package org.jacoco.core.internal.instr; -import org.jacoco.core.internal.data.CRC64; +import org.jacoco.core.internal.BytecodeVersion; import org.jacoco.core.internal.flow.ClassProbesAdapter; import org.jacoco.core.runtime.IExecutionDataAccessorGenerator; import org.objectweb.asm.ClassReader; @@ -30,19 +30,21 @@ public final class ProbeArrayStrategyFactory { * Creates a suitable strategy instance for the class described by the given * reader. Created instance must be used only to process a class or * interface for which it has been created and must be used only once. - * + * + * @param classId + * class identifier * @param reader * reader to get information about the class * @param accessorGenerator * accessor to the coverage runtime * @return strategy instance */ - public static IProbeArrayStrategy createFor(final ClassReader reader, + public static IProbeArrayStrategy createFor(final long classId, + final ClassReader reader, final IExecutionDataAccessorGenerator accessorGenerator) { final String className = reader.getClassName(); - final int version = getVersion(reader); - final long classId = CRC64.classId(reader.b); + final int version = BytecodeVersion.get(reader.b); final boolean withFrames = version >= Opcodes.V1_6; if (isInterfaceOrModule(reader)) { @@ -68,10 +70,6 @@ public final class ProbeArrayStrategyFactory { & (Opcodes.ACC_INTERFACE | Opcodes.ACC_MODULE)) != 0; } - private static int getVersion(final ClassReader reader) { - return reader.readShort(6); - } - private static ProbeCounter getProbeCounter(final ClassReader reader) { final ProbeCounter counter = new ProbeCounter(); reader.accept(new ClassProbesAdapter(counter, false), 0); |