[nestmates] Name of a hidden class and stack trace
Mandy Chung
mandy.chung at oracle.com
Thu Aug 29 18:34:25 UTC 2019
I'm writing a JEP proposal of hidden/nestmate/weak classes prototyped in
the nestmates branch (JDK-8171335). Attached describes about hidden
classes (thanks to Alex Buckley for the help) and description about
nestmates/weak will come next.
A hidden class cannot be named by other class. Ideally a hidden class
should be nameless. For troubleshooting and stack trace, a hidden
class needs a name. So the proposal has been:
Class::getName returns a name for a hidden class and the name is unique
in the runtime package namespace. That is, there is no two Class
objects with the same name in the same runtime package.
Below shows the stack trace where a hidden class throws an exception.
$ java -XX:+UnlockDiagnosticVMOptions -XX:+ShowHiddenFrames DefineClass
foo/Foo.class
java.lang.Error: error
at foo.Foo_/0x0000000800b79258.run(Foo.java:9)
at DefineClass.main(DefineClass.java:18)
The current impl includes `/` in the hidden class's name to disjoint
from the ordinary class names
(same trick as VM anonymous class).
Another class calls Class::forName with the hidden class's name which
would fail since that's not a valid binary name. If someone attempts
to spin a class referencing this hidden class's name with replace('.',
'/'), it may attempt to load a class named
'foo/Foo_/0x0000000800b79258' and may succeed if such a class file
exists and can be located by class loader. This is no difference than
today as one can spin a class file to any class names.
Class::getName may return an invalid binary name if it's a hidden
class. It will impact existing code that expects the returned name is a
valid binary name or use the name to perform class lookup. I think the
compatibility concern should not be high.
Thought?
Mandy
More information about the valhalla-dev
mailing list