RFR: 8252921: NMT overwrite memory type for region assert when building dynamic archive [v3]

Zhengyu Gu zgu at openjdk.java.net
Thu Sep 17 00:07:50 UTC 2020


On Wed, 16 Sep 2020 23:17:39 GMT, Ioi Lam <iklam at openjdk.org> wrote:

> This code in
> [virtualMemoryTracker.cpp](https://github.com/openjdk/jdk/blob/9a7dcdcdbad34e061a8988287fe691abfd4df305/src/hotspot/share/services/virtualMemoryTracker.cpp#L350)
> still looks buggy to me:  ```
>     if (reserved_rgn->same_region(base_addr, size)) {
>       reserved_rgn->set_call_stack(stack);
>       reserved_rgn->set_flag(flag);
>       return true;
>     } else {
>       assert(reserved_rgn->overlap_region(base_addr, size), "Must be");
> 
>       // Overlapped reservation.
>       // It can happen when the regions are thread stacks, as JNI
>       // thread does not detach from VM before exits, and leads to
>       // leak JavaThread object
>       if (reserved_rgn->flag() == mtThreadStack) {
>         guarantee(!CheckJNICalls, "Attached JNI thread exited without being detached");
>         // Overwrite with new region
> ```
> 
> Why is the "Overlapped reservation" fix not done when the two regions are exactly the same?
> 
The same region branch was to deal with different scenario: recursive reservation, where os::reserve() ->
pd_reserve() -> os::reserve()

> If a JNI thread has exited without detaching, and its stack happens to be picked for a future memory reservation of the
> exact size, I think we will get the same assert as in this bug report.
Right. CheckJNICalls should catch that.

-------------

PR: https://git.openjdk.java.net/jdk/pull/185


More information about the hotspot-runtime-dev mailing list