0 Replies Latest reply on Apr 25, 2010 8:07 PM by Stuart Douglas

    JVM advice needed

    Stuart Douglas Master

      I am using javassist on an open source project that aims to bring run time class reloading to java, without discarding the classloader.


      It aims to expand on the hotswap capabilities of the JVM, by recompiling the classes as they are loaded to allow the schema to be changed.


      For instance an Object[] field is added to all classes as they are loaded, if the user then adds a field all gets/puts to this field are re-written to be array access to this array. The reflection API is also instrumented so it appears the new field behaves as expected with regard to reflection, and the fields/methods added at load time do not show up. This instrumentation also allows for annotations to be modified.


      I similar approach is taken with static methods, a general purpose method is added at compile time:


      static public Object FAKEREPALCE_ADDED_METHOD(int mno, Object[] args)


      and the bytecode from the added method is placed in the method body of this method inside a conditional based on the method number.


      This approach works quite well, mostly because you know that no existing code references the new field or method. However with virtual methods this is not the case as the user can add a new method that overrides a superclass method, so existing code will not be aware of the added method and the superclass method will continue to be called.



      The only way i can see to get around this is to add overriden methods to all classes as they are loaded that call the corresponding superclass method, e.g.:


      public String toString()


           return super.toString();



      Obviously this will result in a lot of extra methods being generated, and may result in quite a significant performance degradation.


      I was wondering if anyone can think of a better / less invasive way to accomplish this?


      If anyone is interested the project is here: http://code.google.com/p/fakereplace/