Hacker News new | ask | show | jobs
by srean 5487 days ago
I believe JVM now supports some restricted form of class re-definition at run time in debug mode. But it is quite limited. This is probably old hat for JVM hackers, I do not keep myself updated on the Java/JVM side of things.

I came across Sun's (now Oracle's?) open-source(GPL) fork of the JVM that allows for changing class internals on the fly. The following analogy comes to mind DCE VM : JVM :: DLR : CLR

I quote:

  The class data structures of the Java HotSpot virtual
  machine are immutable during the execution of a program.
  While new classes can be loaded, it is not possible to
  change existing classes (e.g. add/remove methods or
  fields). This projects tries to relax this condition to
  allow arbitrary changes to existing Java classes
  (including changes to the class hierarchy) while running
  a Java program.
This looks interesting http://ssw.jku.at/dcevm/ and wonder if runtimes of dynamic languages could make use of this.
1 comments

I'm not familiar with the DCE VM, but DLR is a library on top of the CLR, not a different version of the CLR.
It is a library on top of the CLR, but it cannot function without CLR-specific capabilities.

For example DynamicMethod, which represents a method reference that can be created at runtime and garbage-collected when no longer in use; similar to the lightweight method handlers in JSR 292.

That said, modifying existing classes on top of the CLR is not possible, unless it inherits from something like ExpandoObject, but you can pull the same trick in Java (though not as easily until JSR 292 comes out).