#LayerPrimitives aka allowing to add private package at runtime to a module ?

mark.reinhold at oracle.com mark.reinhold at oracle.com
Thu Mar 16 14:55:32 UTC 2017


2017/3/16 4:33:27 -0700, forax at univ-mlv.fr:
> ...
> 
> With JPMS, a module is now part of the Java language, so it seems
> weird to make it mutable the same way, a java.lang.Class is not
> mutable in Java.  But that's not true, in fact a java.lang.Class is
> mutable in Java, but you can only mutate it using an agent.
> 
> I'm pretty sure that if we do not make the content of a module
> mutable, people will hack the JPMS implementation to make it mutable,
> because during the development you want to be able to add private
> package like you want to add new method in an existing class without
> having to restart the program (think things like JRebel or Vert.x
> here).

JVM TI and the `java.lang.instrument` API cannot be used to add methods
to an existing class, or really do very much at all except redefine
existing methods.  The specification of the `RetransformClasses`
function [1] is very clear about this:

  The retransformation may change method bodies, the constant pool and
  attributes.  The retransformation must not add, remove or rename
  fields or methods, change the signatures of methods, change modifiers,
  or change inheritance.

There is equivalent wording in the specification of the `RedefineClasses`
function [2].

The JVM TI specification also states that "these restrictions may be
lifted in future versions".  If that ever comes to pass [3] then that
would be a reasonable time to consider extending JVM TI also to support
the addition of packages to modules by agents at run time.

JRebel and similar tools work by doing load-time instrumentation to add
a level of indirection between a class and its content, so that methods
can appear to be added on-the-fly [4].

- Mark


[1] http://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#RetransformClasses
[2] http://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#RedefineClasses
[3] http://openjdk.java.net/jeps/159
[4] https://zeroturnaround.com/rebellabs/reloading_java_classes_401_hotswap_jrebel


More information about the jpms-spec-experts mailing list