Some Review of the EA build
Johannes Kuhn
info at j-kuhn.de
Tue Jun 30 03:38:33 UTC 2020
After playing around a bit with the Early Access build, I have to say,
I'm impressed.
I only used a few toy examples, one that did help me understand the
working of virtual threads better is at [1].
I did not get yielding to work with System.in, as it still uses
synchronized blocks.
I especially like the Thread.Builder API. IMHO could be a candidate to
extract this early into the main line.
I did also look a bit at the code.
Scoped:
* Has a default constructor. Make it explicit?
* The class generation uses visitIntInsn(ALOAD, 0) several times. It
should use visitVarInsn(ALOAD, 0) instead.
* The boundClass is injected into a static final field. While I don't
see a way this could fail today, more aggressive JIT/AOT compilation
(doing it when the class is defined) could lead to errors. Consider
using class data instead.
* caller.getClass() is java.lang.Class.class (or a NPE),
Class.class.getClassLoader() is always null. (The .getClass() call is
probably not intended, but make this thing work)
* The protection domain is retrieved using getProtectionDomain, which
will most likely (default policy) fail if a SecurityManager is
installed. Consider using JLA.getProtectionDomain or c.protectionDomain
instead. That path is not taken, as caller.getClass() is Class.class.
* Classes are defined in the java.lang package of a possibly different
loader. This is normally a different package, not sure if there is code
that treats this special if the class name starts with "java.". This
path is not taken, as caller.getClass() is Class.class.
* A class in the bootstrap classloader can now strongly reference
classes in user defined class loaders, making it impossible to GC that
class loader. The class is defined to the bootstrap classloader, as
caller.getClass().getClassLoader() is always null.
Looks very WIP-ish.
I don't quite understand why this design was chosen for Scoped. I can
make some assumptions:
* As only one (static final) Scoped is used at a particular call site,
the JIT should be able to inline that mono-morphic call.
* Which would make the instanceof check cheap. The same effect might be
archived with two @Stable fields?
I would love to hear more about what the background of the Scoped design
was/is.
Continuation:
That's powerful. Don't really have a particular use in mind yet, but
time will tell. Maybe python-like generators?
Did I miss any particular thing in the EA that I might take a look at?
- Johannes
[1]: https://gist.github.com/DasBrain/ce77bb2bcada2f58d13bc06873d3eaca
More information about the loom-dev
mailing list