Menu

#103 Generate stack map frames required in Java 7

open
nobody
None
5
2011-11-01
2011-11-01
No

In Java 6, the StackMapTable attribute was introduced. At that time it was already announced that this would become required in Java 7. This patch makes ASM regenerate those attributes from the modified byte code, avoiding VerifyErrors in the instrumented class files.

Discussion

  • Bas de Bakker

    Bas de Bakker - 2011-11-01

    Patch to generate stack map frames

     
  • John Lewis

    John Lewis - 2012-11-21

    Thanks for the patch. Is there anything else required or left out of the patch? The net.sourceforge.cobertura.test.FunctionalTest.simpleFunctionalTest() fails when this patch is applied. Is a later version of ASM needed? Here is the error:

    [cobertura-instrument] Cobertura null - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
    [cobertura-instrument] Instrumenting 2 files to C:\Users\jwlewi\AppData\Local\Temp\cobertura_test1353512654190\instrument
    [cobertura-instrument] DEBUG - Instrumenting class C:\Users\jwlewi\AppData\Local\Temp\cobertura_test1353512654190\src\mypackage\Main.class
    [cobertura-instrument] WARN - Unable to instrument file C:\Users\jwlewi\AppData\Local\Temp\cobertura_test1353512654190\src\mypackage\Main.class
    [cobertura-instrument] java.lang.RuntimeException: java.lang.ClassNotFoundException: mypackage.Simple
    [cobertura-instrument] Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: mypackage.Simple
    [cobertura-instrument] at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.ClassWriter.a(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.ClassWriter.a(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.Frame.a(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.Frame.a(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.Frame.a(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.Frame.a(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.MethodAdapter.visitMaxs(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.MethodAdapter.visitMaxs(Unknown Source)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.SecondPassMethodInstrumenter.visitMaxs(SecondPassMethodInstrumenter.java:353)
    [cobertura-instrument] at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.FirstPassMethodInstrumenter.visitEnd(FirstPassMethodInstrumenter.java:171)
    [cobertura-instrument] at org.objectweb.asm.ClassReader.accept(Unknown Source)
    [cobertura-instrument] at org.objectweb.asm.ClassReader.accept(Unknown Source)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:367)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.SecondPassMethodInstrumenter.visitMaxs(SecondPassMethodInstrumenter.java:353)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:425)
    [cobertura-instrument] at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:511)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.FirstPassMethodInstrumenter.visitEnd(FirstPassMethodInstrumenter.java:171)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.main(Main.java:533)
    [cobertura-instrument] at org.objectweb.asm.ClassReader.accept(Unknown Source)
    [cobertura-instrument] Caused by: java.lang.ClassNotFoundException: mypackage.Simple
    [cobertura-instrument] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    [cobertura-instrument] at org.objectweb.asm.ClassReader.accept(Unknown Source)
    [cobertura-instrument] at java.security.AccessController.doPrivileged(Native Method)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:367)
    [cobertura-instrument] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:425)
    [cobertura-instrument] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:511)
    [cobertura-instrument] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.main(Main.java:533)
    [cobertura-instrument] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    [cobertura-instrument] Caused by: java.lang.ClassNotFoundException: mypackage.Simple
    [cobertura-instrument] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    [cobertura-instrument] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    [cobertura-instrument] at java.lang.Class.forName0(Native Method)
    [cobertura-instrument] at java.security.AccessController.doPrivileged(Native Method)
    [cobertura-instrument] at java.lang.Class.forName(Class.java:164)
    [cobertura-instrument] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    [cobertura-instrument] ... 15 more
    [cobertura-instrument] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    [cobertura-instrument] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    [cobertura-instrument] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    [cobertura-instrument] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    [cobertura-instrument] at java.lang.Class.forName0(Native Method)
    [cobertura-instrument] at java.lang.Class.forName(Class.java:164)
    [cobertura-instrument] ... 15 more

     
  • Bas de Bakker

    Bas de Bakker - 2012-11-22

    The asm feature to compute the stack map tables may need to load the classes. Here's a quote from page 45 of the asm 4.0 manual: "Note also that, in order to compute frames automatically, it is sometimes necessary to compute the common super class of two given classes. By default the ClassWriter class computes this, in the getCommonSuperClass method, by loading the two classes into the JVM and by using the reflection API."

    What I did in our project was to add the uninstrumented class files to the classpath of the coberture-instrument task in the ant taskdef call.

     
  • Rob Moore

    Rob Moore - 2012-12-18

    Any chance that this fix will be included in a release soon? Thanks!

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.