Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frames are re-calculated for large methods #177

Merged
merged 10 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.jacoco.ant/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Import-Package: org.jacoco.agent;bundle-version="[0.7.9,0.7.10)",
org.jacoco.report.csv;bundle-version="[0.7.9,0.7.10)",
org.jacoco.report.html;bundle-version="[0.7.9,0.7.10)",
org.jacoco.report.xml;bundle-version="[0.7.9,0.7.10)",
org.objectweb.asm;version="[5.1.0,5.2.0)"
org.objectweb.asm;version="[5.2.0,5.3.0)"
2 changes: 1 addition & 1 deletion org.jacoco.build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<argLine>${jvm.args}</argLine>

<!-- Dependencies versions -->
<asm.version>5.1</asm.version>
<asm.version>5.2</asm.version>
<ant.version>1.7.1</ant.version>
<junit.version>4.8.2</junit.version>

Expand Down
2 changes: 1 addition & 1 deletion org.jacoco.core.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Fragment-Host: org.jacoco.core
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.junit;version="[4.8.0,5.0.0)",
org.junit.rules;version="[4.8.0,5.0.0)",
org.objectweb.asm.util;version="[5.1.0,5.2.0)"
org.objectweb.asm.util;version="[5.2.0,5.3.0)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*******************************************************************************
* Copyright (c) 2009, 2017 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.test.validation;

import static org.junit.Assert.assertEquals;

import org.jacoco.core.instr.Instrumenter;
import org.jacoco.core.runtime.IRuntime;
import org.jacoco.core.runtime.RuntimeData;
import org.jacoco.core.runtime.SystemPropertiesRuntime;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
* Test of ASM bug <a href=
* "http://forge.ow2.org/tracker/?func=detail&aid=317630&group_id=23&atid=100023">#317630</a>
* that caused {@code java.lang.ClassNotFoundException}.
*/
public class ResizeInstructionsTest {

private final IRuntime runtime = new SystemPropertiesRuntime();
private final Instrumenter instrumenter = new Instrumenter(runtime);

private boolean computedCommonSuperClass = false;

@Before
public void setup() throws Exception {
runtime.startup(new RuntimeData());
}

@After
public void teardown() {
runtime.shutdown();
}

@Test
public void test() throws Exception {
final String className = "Example";

final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES) {
@Override
protected String getCommonSuperClass(final String type1,
final String type2) {
computedCommonSuperClass = true;
return "java/lang/Object";
}
};
cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, className, null,
"java/lang/Object", null);
final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "m", "()V",
null, null);
mv.visitCode();
addCauseOfResizeInstructions(mv);
addCauseOfGetCommonSuperClass(mv);
mv.visitMaxs(1, 1);
mv.visitEnd();
cw.visitEnd();
final byte[] original = cw.toByteArray();
assertEquals(true, computedCommonSuperClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer assertTrue(computedCommonSuperClass) and I think we use it consistently in other tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right. Fixed.


load(className, original);
instrumenter.instrument(original, className);
}

private static void load(final String className, final byte[] bytes)
throws ClassNotFoundException {
new ClassLoader() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use existing TargetLoader instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Override
protected Class<?> loadClass(final String name,
final boolean resolve) throws ClassNotFoundException {
if (name.equals(className)) {
return defineClass(name, bytes, 0, bytes.length);
}
return super.loadClass(name, resolve);
}
}.loadClass(className);
}

/**
* Adds code that requires
* {@link ClassWriter#getCommonSuperClass(String, String)}.
*
* <pre>
* Object o = this;
* while (true) {
* o = (Integer) null;
* }
* </pre>
*/
private static void addCauseOfGetCommonSuperClass(final MethodVisitor mv) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Opcodes.ASTORE, 1);
Label label = new Label();
mv.visitLabel(label);
mv.visitInsn(Opcodes.ACONST_NULL);
mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Integer");
mv.visitVarInsn(Opcodes.ASTORE, 1);
mv.visitJumpInsn(Opcodes.GOTO, label);
}

/**
* Adds code that triggers usage of
* {@link org.objectweb.asm.MethodWriter#INSERTED_FRAMES} during
* instrumentation.
*/
private static void addCauseOfResizeInstructions(final MethodVisitor mv) {
mv.visitInsn(Opcodes.ICONST_0);
mv.visitInsn(Opcodes.ICONST_1);
final Label target = new Label();
mv.visitJumpInsn(Opcodes.IFLE, target);
for (int i = 0; i < Short.MAX_VALUE; i++) {
mv.visitInsn(Opcodes.NOP);
}
mv.visitLabel(target);
}

}
6 changes: 3 additions & 3 deletions org.jacoco.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Export-Package: org.jacoco.core;version="0.7.9",
org.jacoco.core.internal.analysis;version="0.7.9";x-internal=true,
org.jacoco.core.runtime;version="0.7.9",
org.jacoco.core.tools;version="0.7.9"
Import-Package: org.objectweb.asm;version="[5.1.0,5.2.0)",
org.objectweb.asm.tree;version="[5.1.0,5.2.0)",
org.objectweb.asm.commons;version="[5.1.0,5.2.0)"
Import-Package: org.objectweb.asm;version="[5.2.0,5.3.0)",
org.objectweb.asm.tree;version="[5.2.0,5.3.0)",
org.objectweb.asm.commons;version="[5.2.0,5.3.0)"
8 changes: 8 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ <h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>

<h3>Fixed Bugs</h3>
<ul>
<li>Do not recompute frames in case of large methods, otherwise
<code>java.lang.ClassNotFoundException</code> might be thrown
(GitHub <a href="https://github.com/jacoco/jacoco/issues/177">#177</a>).</li>
<li><code>ExecutionDataWriter.FORMAT_VERSION</code> is not a compile-time constant
(GitHub <a href="https://github.com/jacoco/jacoco/issues/474">#474</a>).</li>
</ul>
Expand All @@ -32,6 +35,11 @@ <h3>API Changes</h3>
(GitHub <a href="https://github.com/jacoco/jacoco/issues/474">#474</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
<ul>
<li>JaCoCo now depends on ASM 5.2.</li>
</ul>

<h2>Release 0.7.8 (2016/12/09)</h2>

<h3>New Features</h3>
Expand Down
2 changes: 1 addition & 1 deletion org.jacoco.examples/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Import-Package: org.jacoco.core.analysis;bundle-version="[0.7.9,0.7.10)",
org.jacoco.core.tools;bundle-version="[0.7.9,0.7.10)",
org.jacoco.report;bundle-version="[0.7.9,0.7.10)",
org.jacoco.report.html;bundle-version="[0.7.9,0.7.10)",
org.objectweb.asm;version="[5.1.0,5.2.0)"
org.objectweb.asm;version="[5.2.0,5.3.0)"
2 changes: 1 addition & 1 deletion org.jacoco.report/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Import-Package: org.jacoco.core;bundle-version="[0.7.9,0.7.10)",
org.jacoco.core.analysis;bundle-version="[0.7.9,0.7.10)",
org.jacoco.core.data;bundle-version="[0.7.9,0.7.10)",
org.jacoco.core.runtime;bundle-version="[0.7.9,0.7.10)",
org.objectweb.asm;version="[5.1.0,5.2.0)"
org.objectweb.asm;version="[5.2.0,5.3.0)"