RFR: 8286331: jni_GetStringUTFChars() uses wrong heap allocator
Dean Long
dlong at openjdk.java.net
Fri May 6 20:49:55 UTC 2022
On Fri, 6 May 2022 17:54:45 GMT, Zhengyu Gu <zgu at openjdk.org> wrote:
> jni_GetStringUTFChars() calls `AllocateHeap(length + 1, mtInternal, 0, AllocFailStrategy::RETURN_NULL);` to allocate memory, where it passes `0` as `NativeCallStack` reference, that results construction of `NativeCallStack`.
>
> In `NativeCallStack`'s constructor, it performs stack walk to capture native call stack. This is unnecessary, if NMT detail tracking is not enabled.
>
> It should use `char* AllocateHeap(size_t size,
> MEMFLAGS flags,
> AllocFailType alloc_failmode /* = AllocFailStrategy::EXIT_OOM*/)` heap allocator instead.
The changes looks correct, but I don't think it will give the desired behavior. It looks like there is a bug in the 3-parameter version of AllocateHeap where it ignores the alloc_failmode argument. You will need to fix that too for your change to work correctly. Try forcing an allocation failure and verify that it returns NULL instead of exiting with OOM.
-------------
Changes requested by dlong (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/8579
More information about the hotspot-dev
mailing list