src/share/vm/classfile/symbolTable.hpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 435
a61af66fc99e
child 1100
c89f86385056
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

     1 /*
     2  * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // The symbol table holds all symbolOops and corresponding interned strings.
    26 // symbolOops and literal strings should be canonicalized.
    27 //
    28 // The interned strings are created lazily.
    29 //
    30 // It is implemented as an open hash table with a fixed number of buckets.
    31 //
    32 // %note:
    33 //  - symbolTableEntrys are allocated in blocks to reduce the space overhead.
    35 class BoolObjectClosure;
    38 class SymbolTable : public Hashtable {
    39   friend class VMStructs;
    41 private:
    42   // The symbol table
    43   static SymbolTable* _the_table;
    45   // Adding elements
    46   symbolOop basic_add(int index, u1* name, int len,
    47                       unsigned int hashValue, TRAPS);
    48   bool basic_add(constantPoolHandle cp, int names_count,
    49                  const char** names, int* lengths, int* cp_indices,
    50                  unsigned int* hashValues, TRAPS);
    52   // Table size
    53   enum {
    54     symbol_table_size = 20011
    55   };
    57   symbolOop lookup(int index, const char* name, int len, unsigned int hash);
    59   SymbolTable()
    60     : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
    62   SymbolTable(HashtableBucket* t, int number_of_entries)
    63     : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
    64                 number_of_entries) {}
    67 public:
    68   enum {
    69     symbol_alloc_batch_size = 8
    70   };
    72   // The symbol table
    73   static SymbolTable* the_table() { return _the_table; }
    75   static void create_table() {
    76     assert(_the_table == NULL, "One symbol table allowed.");
    77     _the_table = new SymbolTable();
    78   }
    80   static void create_table(HashtableBucket* t, int length,
    81                            int number_of_entries) {
    82     assert(_the_table == NULL, "One symbol table allowed.");
    83     assert(length == symbol_table_size * sizeof(HashtableBucket),
    84            "bad shared symbol size.");
    85     _the_table = new SymbolTable(t, number_of_entries);
    86   }
    88   static symbolOop lookup(const char* name, int len, TRAPS);
    89   // lookup only, won't add. Also calculate hash.
    90   static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
    91   // Only copy to C string to be added if lookup failed.
    92   static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
    94   static void add(constantPoolHandle cp, int names_count,
    95                   const char** names, int* lengths, int* cp_indices,
    96                   unsigned int* hashValues, TRAPS);
    98   // GC support
    99   //   Delete pointers to otherwise-unreachable objects.
   100   static void unlink(BoolObjectClosure* cl) {
   101     the_table()->Hashtable::unlink(cl);
   102   }
   104   // Invoke "f->do_oop" on the locations of all oops in the table.
   105   static void oops_do(OopClosure* f) {
   106     the_table()->Hashtable::oops_do(f);
   107   }
   109   // Symbol lookup
   110   static symbolOop lookup(int index, const char* name, int len, TRAPS);
   112   // Needed for preloading classes in signatures when compiling.
   113   // Returns the symbol is already present in symbol table, otherwise
   114   // NULL.  NO ALLOCATION IS GUARANTEED!
   115   static symbolOop probe(const char* name, int len);
   117   // Histogram
   118   static void print_histogram()     PRODUCT_RETURN;
   120   // Debugging
   121   static void verify();
   123   // Sharing
   124   static void copy_buckets(char** top, char*end) {
   125     the_table()->Hashtable::copy_buckets(top, end);
   126   }
   127   static void copy_table(char** top, char*end) {
   128     the_table()->Hashtable::copy_table(top, end);
   129   }
   130   static void reverse(void* boundary = NULL) {
   131     ((Hashtable*)the_table())->reverse(boundary);
   132   }
   133 };
   136 class StringTable : public Hashtable {
   137   friend class VMStructs;
   139 private:
   140   // The string table
   141   static StringTable* _the_table;
   143   static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
   144   oop basic_add(int index, Handle string_or_null, jchar* name, int len,
   145                 unsigned int hashValue, TRAPS);
   147   // Table size
   148   enum {
   149     string_table_size = 1009
   150   };
   152   oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
   154   StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
   156   StringTable(HashtableBucket* t, int number_of_entries)
   157     : Hashtable(string_table_size, sizeof (HashtableEntry), t,
   158                 number_of_entries) {}
   160 public:
   161   // The string table
   162   static StringTable* the_table() { return _the_table; }
   164   static void create_table() {
   165     assert(_the_table == NULL, "One string table allowed.");
   166     _the_table = new StringTable();
   167   }
   169   static void create_table(HashtableBucket* t, int length,
   170                            int number_of_entries) {
   171     assert(_the_table == NULL, "One string table allowed.");
   172     assert(length == string_table_size * sizeof(HashtableBucket),
   173            "bad shared string size.");
   174     _the_table = new StringTable(t, number_of_entries);
   175   }
   178   static int hash_string(jchar* s, int len);
   181   // GC support
   182   //   Delete pointers to otherwise-unreachable objects.
   183   static void unlink(BoolObjectClosure* cl) {
   184     the_table()->Hashtable::unlink(cl);
   185   }
   187   // Invoke "f->do_oop" on the locations of all oops in the table.
   188   static void oops_do(OopClosure* f) {
   189     the_table()->Hashtable::oops_do(f);
   190   }
   192   // Probing
   193   static oop lookup(symbolOop symbol);
   195   // Interning
   196   static oop intern(symbolOop symbol, TRAPS);
   197   static oop intern(oop string, TRAPS);
   198   static oop intern(const char *utf8_string, TRAPS);
   200   // Debugging
   201   static void verify();
   203   // Sharing
   204   static void copy_buckets(char** top, char*end) {
   205     the_table()->Hashtable::copy_buckets(top, end);
   206   }
   207   static void copy_table(char** top, char*end) {
   208     the_table()->Hashtable::copy_table(top, end);
   209   }
   210   static void reverse() {
   211     ((BasicHashtable*)the_table())->reverse();
   212   }
   213 };

mercurial