-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4dc7420
(wip) add test
Godin 36e7412
(wip) upgrade ASM to 5.2
Godin ae98e69
(wip) update changelog
Godin 2fa7c74
Merge branch 'master' into issue-177
Godin 9f74dc7
Happy New Year 2017!
Godin ce4edff
(wip) use assertTrue instead of assertEquals
Godin cfd54a0
(wip) use TargetLoader
Godin 1873e16
(wip) demonstrate that getCommonSuperClass requires loading of constr…
Godin 31d7e26
(wip) forbid execution of getCommonSuperClass
Godin 0ad3368
Merge branch 'master' into issue-177
Godin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
org.jacoco.core.test/src/org/jacoco/core/test/validation/ResizeInstructionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
load(className, original); | ||
instrumenter.instrument(original, className); | ||
} | ||
|
||
private static void load(final String className, final byte[] bytes) | ||
throws ClassNotFoundException { | ||
new ClassLoader() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use existing There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right. Fixed.