Giter Club home page Giter Club logo

proxy-vs-invokedynamic's Introduction

Proxy vs Invokedynamic

This code was first created from Rémi Forax. It's a proof of concept for using InvokeDynamics vs classical Java proxy in 'magical' frameworks.

What is showed

This maven project has 2 modules : proxy and invokedynamic. Both modules do the same : call a service method on witch a security annotation was added (defined for the purpose of the test). In this service we do throw an exception to show the stack trace.

Proxy version gives a verbose and proxy stack trace while InvokeDynamic version shows a clean stack trace with only defined classes in it.

Pre-requsisites to run this poc

You'll need a JDK 1.7 (tested with update 45). The code is not running under Java 8 right now due to API change in java.lang.invoke between java 7 and 8. You'll also need maven 3.x

Compiling the code

As we have to rewrite bytecode after compilation in invokedynamic module, it's important that you compile the code from Maven (and not your IDE). a simple mvn clean package will do it.

Run the code

You can run the code from maven as well or from you IDE (be careful that your IDE doesn't recompile the code or if it does be sure that process-class maven phase is also launch to weave the code)

Go to proxy module and enter

mvn -Dtest=ProxyTest

The result stack trace will be :

java.lang.RuntimeException: There should be a lot of noise in the stacktrace
    org.jboss.research.proxy.UserServiceImpl.addUser(UserServiceImpl.java:8)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:606)
    org.jboss.research.proxy.EffectiveCallAdvice.chain(EffectiveCallAdvice.java:15)
    org.jboss.research.proxy.Container$AdviceContextImpl.call(Container.java:26)
    org.jboss.research.proxy.CheckRoleAdvice.chain(CheckRoleAdvice.java:19)
    org.jboss.research.proxy.Container$AdviceContextImpl.call(Container.java:26)
    org.jboss.research.proxy.Container$1.invoke(Container.java:45)
    com.sun.proxy.$Proxy4.addUser(Unknown Source)
    org.jboss.research.proxy.ProxyTest.proxy(ProxyTest.java:16)

Go to the invokedynamic module and launch

mvn -Dtest=InvokeDynamicProxyTest

Stack trace will be less verbose :

java.lang.RuntimeException: Let's look at the clean stack trace
    org.jboss.research.invokedynamic.UserServiceImpl.addUser(UserServiceImpl.java:15)
    org.jboss.research.invokedynamic.InvokeDynamicTest.invokeDynamic(InvokeDynamicTest.java:44)

Going further

From this code I hope to produce a JBoss Weld version using partly InvokeDynamic to simplify the framework, provides better performance (to be tested) and most specially to have better stack traces for users.

proxy-vs-invokedynamic's People

Contributors

framiere avatar antoinesd avatar forax avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.