Disallow C-Heap allocations from within dynamic C++ initialization?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Disallow C-Heap allocations from within dynamic C++ initialization?

tstuefe
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
Reply | Threaded
Open this post in threaded view
|

Re: Disallow C-Heap allocations from within dynamic C++ initialization?

Florian Weimer-5
* Thomas Stüfe:

> 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.

What is a C-Heap allocation in this context?

With glibc, initializing a C++ object which has a non-trivial destructor
can call malloc.

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: Disallow C-Heap allocations from within dynamic C++ initialization?

tstuefe
Hi Florian,

On Tue, Feb 23, 2021 at 4:23 PM Florian Weimer <[hidden email]> wrote:

> * Thomas Stüfe:
>
> > 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.
>
> What is a C-Heap allocation in this context?
>
>
Any call going through os::malloc().


> With glibc, initializing a C++ object which has a non-trivial destructor
> can call malloc.
>
> Thanks,
> Florian
>

Thanks, Thomas