src/share/vm/classfile/symbolTable.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8145940.03 Sdiff src/share/vm/classfile

src/share/vm/classfile/symbolTable.hpp

Print this page




  25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
  26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
  27 
  28 #include "memory/allocation.inline.hpp"
  29 #include "oops/symbol.hpp"
  30 #include "utilities/hashtable.hpp"
  31 
  32 // The symbol table holds all Symbol*s and corresponding interned strings.
  33 // Symbol*s and literal strings should be canonicalized.
  34 //
  35 // The interned strings are created lazily.
  36 //
  37 // It is implemented as an open hash table with a fixed number of buckets.
  38 //
  39 // %note:
  40 //  - symbolTableEntrys are allocated in blocks to reduce the space overhead.
  41 
  42 class BoolObjectClosure;
  43 class outputStream;
  44 
  45 // Class to hold a newly created or referenced Symbol* temporarily in scope.
  46 // new_symbol() and lookup() will create a Symbol* if not already in the









  47 // symbol table and add to the symbol's reference count.
  48 // probe() and lookup_only() will increment the refcount if symbol is found.
  49 class TempNewSymbol : public StackObj {
  50   Symbol* _temp;
  51 
  52  public:
  53   TempNewSymbol() : _temp(NULL) {}
  54   // Creating or looking up a symbol increments the symbol's reference count


  55   TempNewSymbol(Symbol *s) : _temp(s) {}
  56 
  57   // Operator= increments reference count.
  58   void operator=(const TempNewSymbol &s) {
  59     //clear();  //FIXME
  60     _temp = s._temp;
  61     if (_temp !=NULL) _temp->increment_refcount();
  62   }
  63 
  64   // Decrement reference counter so it can go away if it's unique
  65   void clear() { if (_temp != NULL)  _temp->decrement_refcount();  _temp = NULL; }






  66 
  67   ~TempNewSymbol() { clear(); }





  68 
  69   // Operators so they can be used like Symbols
  70   Symbol* operator -> () const                   { return _temp; }
  71   bool    operator == (Symbol* o) const          { return _temp == o; }
  72   // Sneaky conversion function
  73   operator Symbol*()                             { return _temp; }
  74 };
  75 
  76 template <class T, class N> class CompactHashtable;
  77 
  78 class SymbolTable : public RehashableHashtable<Symbol*, mtSymbol> {
  79   friend class VMStructs;
  80   friend class ClassFileParser;
  81 
  82 private:
  83   // The symbol table
  84   static SymbolTable* _the_table;
  85 
  86   // Set if one bucket is out of balance due to hash algorithm deficiency
  87   static bool _needs_rehashing;
  88   static bool _lookup_shared_first;
  89 
  90   // For statistics
  91   static int _symbols_removed;
  92   static int _symbols_counted;




  25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
  26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
  27 
  28 #include "memory/allocation.inline.hpp"
  29 #include "oops/symbol.hpp"
  30 #include "utilities/hashtable.hpp"
  31 
  32 // The symbol table holds all Symbol*s and corresponding interned strings.
  33 // Symbol*s and literal strings should be canonicalized.
  34 //
  35 // The interned strings are created lazily.
  36 //
  37 // It is implemented as an open hash table with a fixed number of buckets.
  38 //
  39 // %note:
  40 //  - symbolTableEntrys are allocated in blocks to reduce the space overhead.
  41 
  42 class BoolObjectClosure;
  43 class outputStream;
  44 
  45 // TempNewSymbol acts as a handle class in a handle/body idiom and is
  46 // responsible for proper resource management of the body (which is a Symbol*).
  47 // The body is resource managed by a reference counting scheme.
  48 // TempNewSymbol can therefore be used to properly hold a newly created or referenced
  49 // Symbol* temporarily in scope.
  50 //
  51 // Routines in SymbolTable will initialize the reference count of a Symbol* before
  52 // it becomes "managed" by TempNewSymbol instances. As a handle class, TempNewSymbol
  53 // needs to maintain proper reference counting in context of copy semantics.
  54 //
  55 // In SymbolTable, new_symbol() and lookup() will create a Symbol* if not already in the
  56 // symbol table and add to the symbol's reference count.
  57 // probe() and lookup_only() will increment the refcount if symbol is found.
  58 class TempNewSymbol : public StackObj {
  59   Symbol* _temp;
  60 
  61  public:
  62   TempNewSymbol() : _temp(NULL) {}
  63 
  64   // Conversion from a Symbol* to a TempNewSymbol.
  65   // Does not increment the current reference count.
  66   TempNewSymbol(Symbol *s) : _temp(s) {}
  67 
  68   // Copy constructor increments reference count.
  69   TempNewSymbol(const TempNewSymbol& rhs) : _temp(rhs._temp) {
  70     if (_temp != NULL) {
  71       _temp->increment_refcount();
  72     }
  73   }
  74 
  75   // Assignment operator uses a c++ trick called copy and swap idiom.
  76   // The rhs is a copied so gets the new value incremented and is given the old
  77   // temp which gets refcount for old _temp decremented.
  78   void operator=(TempNewSymbol rhs) {
  79     Symbol* tmp = rhs._temp;
  80     rhs._temp = _temp;
  81     _temp = tmp;
  82   }
  83 
  84   // Decrement reference counter so it can go away if it's unique
  85   ~TempNewSymbol() {
  86     if (_temp != NULL) {
  87       _temp->decrement_refcount();
  88     }
  89   }
  90 
  91   // Symbol* conversion operators
  92   Symbol* operator -> () const                   { return _temp; }
  93   bool    operator == (Symbol* o) const          { return _temp == o; }

  94   operator Symbol*()                             { return _temp; }
  95 };
  96 
  97 template <class T, class N> class CompactHashtable;
  98 
  99 class SymbolTable : public RehashableHashtable<Symbol*, mtSymbol> {
 100   friend class VMStructs;
 101   friend class ClassFileParser;
 102 
 103 private:
 104   // The symbol table
 105   static SymbolTable* _the_table;
 106 
 107   // Set if one bucket is out of balance due to hash algorithm deficiency
 108   static bool _needs_rehashing;
 109   static bool _lookup_shared_first;
 110 
 111   // For statistics
 112   static int _symbols_removed;
 113   static int _symbols_counted;


src/share/vm/classfile/symbolTable.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File