< prev index next >

src/share/vm/classfile/symbolTable.hpp

Print this page
rev 9826 : [mq]: 8145940


  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) {
  70     _temp = rhs._temp;
  71     if (_temp != NULL) {
  72       _temp->increment_refcount();
  73     }
  74   }
  75 
  76   // Assignment operator decrements the reference count for any
  77   // existing resource. It increments the reference count
  78   // for the newly assigned resource.
  79   const TempNewSymbol& operator=(const TempNewSymbol &rhs) {
  80     if (this != &rhs && _temp != rhs._temp) {
  81       clear();
  82       _temp = rhs._temp;
  83       if (_temp != NULL) {
  84         _temp->increment_refcount();
  85       }
  86     }
  87     return *this;
  88   }
  89 
  90   // Decrement reference counter so it can go away if it's unique
  91   void clear() {
  92     if (_temp != NULL) {
  93       _temp->decrement_refcount();
  94     }
  95   }
  96 
  97   ~TempNewSymbol() { clear(); }
  98 
  99   // Symbol* conversion operators
 100   Symbol* operator -> () const                   { return _temp; }
 101   bool    operator == (Symbol* o) const          { return _temp == o; }

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


< prev index next >