< prev index next >

src/hotspot/share/oops/symbolHandle.hpp

Print this page
@@ -26,10 +26,20 @@
  #define SHARE_OOPS_SYMBOLHANDLE_HPP
  
  #include "memory/allocation.hpp"
  #include "oops/symbol.hpp"
  
+ class TempSymbolCleanupDelayer : AllStatic {
+   static Symbol* volatile _queue[];
+   static volatile uint _index;
+ 
+ public:
+   static const uint QueueSize = 128;
+   static void delay_cleanup(Symbol* s);
+   static void drain_queue();
+ };
+ 
  // TempNewSymbol acts as a handle class in a handle/body idiom and is
  // responsible for proper resource management of the body (which is a Symbol*).
  // The body is resource managed by a reference counting scheme.
  // TempNewSymbol can therefore be used to properly hold a newly created or referenced
  // Symbol* temporarily in scope.

@@ -47,14 +57,21 @@
  
  public:
    SymbolHandleBase() : _temp(nullptr) { }
  
    // Conversion from a Symbol* to a SymbolHandleBase.
-   // Does not increment the current reference count if temporary.
    SymbolHandleBase(Symbol *s) : _temp(s) {
      if (!TEMP) {
        Symbol::maybe_increment_refcount(_temp);
+       return;
+     }
+ 
+     // Delay cleanup for temp symbols. Refcount is incremented while in
+     // queue. But don't requeue existing entries, or entries that are held
+     // elsewhere - it's a waste of effort.
+     if (s != nullptr && s->refcount() == 1) {
+       TempSymbolCleanupDelayer::delay_cleanup(s);
      }
    }
  
    // Copy constructor increments reference count.
    SymbolHandleBase(const SymbolHandleBase& rhs) : _temp(rhs._temp) {
< prev index next >