JDK-8313224 : Avoid calling JavaThread::current() in MemAllocator::Allocation constructor
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 17,21,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-07-27
  • Updated: 2023-08-14
  • Resolved: 2023-08-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 masterFixed
Related Reports
Relates :  
Description
The constructor of MemAllocator::Allocation calls JavaThread::current()

https://github.com/openjdk/jdk/blob/a9d21c61fb12a11e18c6bb8aa903e5a8e42473f1/src/hotspot/share/gc/shared/memAllocator.cpp#L73

  Allocation(const MemAllocator& allocator, oop* obj_ptr)
    : _allocator(allocator),
      _thread(JavaThread::current()),

This can cause slow down when we allocate a lot of objects inside a tight loop in native code (E.g., JDK-8310823)

Since the code assumes that the current thread by a Java thread, we can replace the JavaThread::current() call with:

    assert(Thread::current()->is_Java_thread(), "must be used by JavaThreads only");
    assert(Thread::current() == allocator._thread, "must be");
    _thread = JavaThread::cast(allocator._thread);


Comments
Changeset: 43462a36 Author: Ioi Lam <iklam@openjdk.org> Date: 2023-08-11 03:39:39 +0000 URL: https://git.openjdk.org/jdk/commit/43462a36ab02b67d426c04d345868bd420b30c25
11-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15058 Date: 2023-07-27 18:34:16 +0000
27-07-2023