Skip to main content

ASM 4 RC1 released

Posted by forax on April 17, 2011 at 10:46 AM PDT

I'm proud with Eric and Eugene to announce the release of ASM4 RC1.

This release is available to download here:
http://forge.ow2.org/projects/asm/

So what's new ?
- Full support of Java 7.
  Because Java 7 introduces several changes in the bytecode format,
  all other versions of ASM aren't able to deal with this new format.
  That why I strongly recommend you to use ASM4.

- Overhaul of the support of invokedynamic to support the new encoding
  and bootstrap method arguments.
  Practically, this means that invokedynamic doesn't trigger a call to 
  MethodVisitor.visitMethodInsn but use a specific new method:
  visitInvokeDynamicInsn(String name, String desc, MethodHandle bsm, Object... args)

- Two new constants org.objectweb.asm.MethodHandle and org.objectweb.asm.MethodType
   can be used either in visitLdcInsn() or as last arguments of visitInvokeDynamicInsn.
   org.objectweb.asm.MethodHandle encodes a constant method handle and
   org.objectweb.asm.MethodType encodes a constant method type.

Here is the snippet of how generate an instruction invokedynamic foo()V that will
call as bootstrap method bootstrapName with two bootstrap constants "bar" and 3.

MethodVisitor mv = ...
[prettify]MethodHandle bootstrap = new
MethodHandle(Opcodes.MH_GETSTATIC, "BoostrapClass", "boostrapName",   "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;I)Ljava/lang/invoke/CallSite;"); mv.visitInvokeDynamicInsn("foo", "()V", bootstrap, "bar", 3);[/prettify]

- ASM4 API has been generified to use generics and varargs
  but almost all jars are still small and 1.2 compatible.
  In fact, there is a trick, the API is 1.5 compatible but the bytecode is downgraded
  to be 1.2 compatible using a bytecode rewriter (our own dog food).
 
  To use the 1.5 compatible API you have to compile using all/asm-debug-all-*.jar
  which is 1.5 compatible and also contains the debug information.
  When running you can use all/asm-all-*.jar or several asm-*jar depending on your usage.
  Except all/asm-debug-all-*.jar all other jars are 1.2 compatible and optimized.
  If you want debug information at runtime you have to use all/asm-debug-all-*.jar.
 
  ASM4 API has been generified to be as compatible as possible with 3.3 API.
  So some methods now return an array of parametrized type which are not type safe
  (not less than before in fact) if you store something in it.
  The other solution should have been to use a List instead of an array
  but this introduces too many non-compatible changes.
  The package org.asm.tree.analysis is now fully typesafe but during that process,
  we have changed some signatures in Interpreter subtypes so if your code
  uses an ad-hoc interpreter it has to be updated.

cheers,
Rémi
 

Related Topics >>

Comments

<p>My 2 cents:&nbsp;dump backwards compatibility, especially ...

My 2 cents: dump backwards compatibility, especially where Java 1.2 is concerned. Who the heck is using a version of Java that was released over 13 years ago?!
If you have to drop some backwards compatibility to add type-safety, do so.

Hi Gili, by 1.2 compatibility, I mean 1.2, 1.3 and ...

Hi Gili,
by 1.2 compatibility, I mean 1.2, 1.3 and 1.4.
Unfortunately, there is still to many WebSphere 5.1/6 used nowadays.


Also, using List instead of array has some performance implications even
if the jdk7 shows some incredible performance improvement.

Rémi