Skip to content

Instantly share code, notes, and snippets.

@maxymania
Last active September 28, 2018 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxymania/a40a2c50f8459bf9bf474fa93f631d35 to your computer and use it in GitHub Desktop.
Save maxymania/a40a2c50f8459bf9bf474fa93f631d35 to your computer and use it in GitHub Desktop.
Invokedynamic

Stuff regarding java's invokedynamic

Method signature

    public static CallSite bootstrap(
            MethodHandles.Lookup caller,
            String name,
            MethodType type
    ) throws NoSuchMethodException, IllegalAccessException {
        return null;
    }
import java.io.PrintWriter;
import jdk.internal.org.objectweb.asm.util.TraceClassVisitor;
import jdk.internal.org.objectweb.asm.util.TraceClassVisitor;
import jdk.internal.org.objectweb.asm.ClassReader;
// https://stackoverflow.com/questions/7984003/pretty-printing-a-method-in-asm-bytecode
public class DumperForClasses {
public static void x(byte[] bc){
System.out.println("-----------------------");
ClassReader c = new ClassReader(bc);
PrintWriter pw = new PrintWriter(System.out);
TraceClassVisitor tcv = new TraceClassVisitor(pw);
c.accept(tcv, ClassReader.SKIP_DEBUG);
pw.flush();
System.out.println("-----------------------");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment