src/share/vm/classfile/symbolTable.hpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

     1 /*
     2  * Copyright 1997-2009 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   // jchar (utf16) version of lookups
    95   static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
    96   static symbolOop lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
    98   static void add(constantPoolHandle cp, int names_count,
    99                   const char** names, int* lengths, int* cp_indices,
   100                   unsigned int* hashValues, TRAPS);
   102   // GC support
   103   //   Delete pointers to otherwise-unreachable objects.
   104   static void unlink(BoolObjectClosure* cl) {
   105     the_table()->Hashtable::unlink(cl);
   106   }
   108   // Invoke "f->do_oop" on the locations of all oops in the table.
   109   static void oops_do(OopClosure* f) {
   110     the_table()->Hashtable::oops_do(f);
   111   }
   113   // Symbol lookup
   114   static symbolOop lookup(int index, const char* name, int len, TRAPS);
   116   // Needed for preloading classes in signatures when compiling.
   117   // Returns the symbol is already present in symbol table, otherwise
   118   // NULL.  NO ALLOCATION IS GUARANTEED!
   119   static symbolOop probe(const char* name, int len) {
   120     unsigned int ignore_hash;
   121     return lookup_only(name, len, ignore_hash);
   122   }
   123   static symbolOop probe_unicode(const jchar* name, int len) {
   124     unsigned int ignore_hash;
   125     return lookup_only_unicode(name, len, ignore_hash);
   126   }
   128   // Histogram
   129   static void print_histogram()     PRODUCT_RETURN;
   131   // Debugging
   132   static void verify();
   134   // Sharing
   135   static void copy_buckets(char** top, char*end) {
   136     the_table()->Hashtable::copy_buckets(top, end);
   137   }
   138   static void copy_table(char** top, char*end) {
   139     the_table()->Hashtable::copy_table(top, end);
   140   }
   141   static void reverse(void* boundary = NULL) {
   142     ((Hashtable*)the_table())->reverse(boundary);
   143   }
   144 };
   147 class StringTable : public Hashtable {
   148   friend class VMStructs;
   150 private:
   151   // The string table
   152   static StringTable* _the_table;
   154   static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
   155   oop basic_add(int index, Handle string_or_null, jchar* name, int len,
   156                 unsigned int hashValue, TRAPS);
   158   // Table size
   159   enum {
   160     string_table_size = 1009
   161   };
   163   oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
   165   StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
   167   StringTable(HashtableBucket* t, int number_of_entries)
   168     : Hashtable(string_table_size, sizeof (HashtableEntry), t,
   169                 number_of_entries) {}
   171 public:
   172   // The string table
   173   static StringTable* the_table() { return _the_table; }
   175   static void create_table() {
   176     assert(_the_table == NULL, "One string table allowed.");
   177     _the_table = new StringTable();
   178   }
   180   static void create_table(HashtableBucket* t, int length,
   181                            int number_of_entries) {
   182     assert(_the_table == NULL, "One string table allowed.");
   183     assert(length == string_table_size * sizeof(HashtableBucket),
   184            "bad shared string size.");
   185     _the_table = new StringTable(t, number_of_entries);
   186   }
   189   static int hash_string(jchar* s, int len);
   192   // GC support
   193   //   Delete pointers to otherwise-unreachable objects.
   194   static void unlink(BoolObjectClosure* cl) {
   195     the_table()->Hashtable::unlink(cl);
   196   }
   198   // Invoke "f->do_oop" on the locations of all oops in the table.
   199   static void oops_do(OopClosure* f) {
   200     the_table()->Hashtable::oops_do(f);
   201   }
   203   // Probing
   204   static oop lookup(symbolOop symbol);
   206   // Interning
   207   static oop intern(symbolOop symbol, TRAPS);
   208   static oop intern(oop string, TRAPS);
   209   static oop intern(const char *utf8_string, TRAPS);
   211   // Debugging
   212   static void verify();
   214   // Sharing
   215   static void copy_buckets(char** top, char*end) {
   216     the_table()->Hashtable::copy_buckets(top, end);
   217   }
   218   static void copy_table(char** top, char*end) {
   219     the_table()->Hashtable::copy_table(top, end);
   220   }
   221   static void reverse() {
   222     ((BasicHashtable*)the_table())->reverse();
   223   }
   224 };

mercurial