Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8313224

Avoid calling JavaThread::current() in MemAllocator::Allocation constructor

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 22
    • 17, 21, 22
    • hotspot
    • gc
    • b11

    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);

      Attachments

        Issue Links

          Activity

            People

              iklam Ioi Lam
              iklam Ioi Lam
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: