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

Using alias template to unify hashtables in AsyncLogWriter

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 20
    • 20
    • hotspot
    • b17
    • generic
    • generic

      This change is only for clear code. No functional change is intended.

      Currently, there are two hashtables. one is this on c_heap.
      ```
        using AsyncLogMap = ResourceHashtable<LogFileStreamOutput*,
                                uint32_t,
                                17, /*table_size*/
                                ResourceObj::C_HEAP,
                                mtLogging>;
      ```
      and the other one is its mirror on ResourceArena. It's not accident. The 2nd one is the snapshot of prior one. We use this approach to release lock early.
      Flushing snapshot doesn't require lock protection and therefore won't block logsites.

      ```
        ResourceMark rm;
        // Similar to AsyncLogMap but on resource_area
        ResourceHashtable<LogFileStreamOutput*, uint32_t,
                                17/*table_size*/, ResourceObj::RESOURCE_AREA,
                                mtLogging> snapshot;
      ```
      C++11 has a new feature called "alias template". https://en.cppreference.com/w/cpp/language/type_alias

      I would like to use it to unify two types. proposal of change.

      diff --git a/src/hotspot/share/logging/logAsyncWriter.cpp b/src/hotspot/share/logging/logAsyncWriter.cpp
      index c9ce7fbdbf2..3c56c506528 100644
      --- a/src/hotspot/share/logging/logAsyncWriter.cpp
      +++ b/src/hotspot/share/logging/logAsyncWriter.cpp
      @@ -116,10 +116,7 @@ AsyncLogWriter::AsyncLogWriter()

       void AsyncLogWriter::write() {
         ResourceMark rm;
      - // Similar to AsyncLogMap but on resource_area
      - ResourceHashtable<LogFileStreamOutput*, uint32_t,
      - 17/*table_size*/, ResourceObj::RESOURCE_AREA,
      - mtLogging> snapshot;
      + AsyncLogMap<ResourceObj::RESOURCE_AREA> snapshot;

         // lock protection. This guarantees I/O jobs don't block logsites.
         {
      diff --git a/src/hotspot/share/logging/logAsyncWriter.hpp b/src/hotspot/share/logging/logAsyncWriter.hpp
      index 549c5d9f3a5..8a103b367ea 100644
      --- a/src/hotspot/share/logging/logAsyncWriter.hpp
      +++ b/src/hotspot/share/logging/logAsyncWriter.hpp
      @@ -58,11 +58,11 @@ class AsyncLogWriter : public NonJavaThread {
         friend class AsyncLogTest;
         friend class AsyncLogTest_logBuffer_vm_Test;
         class AsyncLogLocker;
      +
      + template <ResourceObj::allocation_type ALLOC_TYPE>
         using AsyncLogMap = ResourceHashtable<LogFileStreamOutput*,
      - uint32_t,
      - 17, /*table_size*/
      - ResourceObj::C_HEAP,
      - mtLogging>;
      + uint32_t, 17, /*table_size*/
      + ALLOC_TYPE, mtLogging>;

         // Messsage is the envelop of a log line and its associative data.
         // Its length is variable because of the zero-terminated c-str. It is only valid when we create it using placement new
      @@ -154,7 +154,7 @@ class AsyncLogWriter : public NonJavaThread {
         PlatformMonitor _lock;
         bool _data_available;
         volatile bool _initialized;
      - AsyncLogMap _stats; // statistics for dropped messages
      + AsyncLogMap<ResourceObj::C_HEAP> _stats; // statistics for dropped messages

         // ping-pong buffers
         Buffer* _buffer;

            xliu Xin Liu
            xliu Xin Liu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: