Disallow C-Heap allocations from within dynamic C++ initialization?
Thomas Stüfe
thomas.stuefe at gmail.com
Tue Feb 23 10:03:17 UTC 2021
Hi,
I currently investigate how NMT could be made "late-initializable" - so,
not to rely anymore on the awkward combination of the NMT environment
variable and command line argument.
For details see: https://bugs.openjdk.java.net/browse/JDK-8256844
There are some difficult problems when letting NMT late-initialize, all
stemming from the fact that allocations can happen before argument parsing
happens and NMT is initialized. These problems are solvable, and I have
several approaches, but they make NMT more complicated, which I dislike.
The easiest approach would be to simply disallow early C-Heap allocations.
So lets say I do this:
- move (a part of) NMT initialization very close to the start of
Thread::create_vm()
- disallow and rewrite all code which does C-Heap allocation earlier
(during dynamic C++ initialization)
Would that be an acceptable and maintainable stance? Since that would mean
that we disallow global C++ objects which do C-Heap allocation in their
constructors somewhere.
I did a quick test, and I think that this is doable and would not affect
too much code. Most of which can be rewritten to use explicit
initialization. Personally I think explicit initialization is cleaner than
relying on dynamic C++ initialization anyway since it makes the order of
initialization more predictable.
Wrt to NMT, this also would have other advantages, e.g. we could allocate
certain NMT structures only if NMT is on which are now unconditionally
allocated (eg MallocSiteTable).
What are your opinions?
Thanks a lot,
Thomas
More information about the hotspot-dev
mailing list