1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
80 |
80 |
81 // For statistics |
81 // For statistics |
82 static int symbols_removed; |
82 static int symbols_removed; |
83 static int symbols_counted; |
83 static int symbols_counted; |
84 |
84 |
85 Symbol* allocate_symbol(const u1* name, int len, TRAPS); // Assumes no characters larger than 0x7F |
85 Symbol* allocate_symbol(const u1* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F |
86 bool allocate_symbols(int names_count, const u1** names, int* lengths, Symbol** syms, TRAPS); |
|
87 |
86 |
88 // Adding elements |
87 // Adding elements |
89 Symbol* basic_add(int index, u1* name, int len, |
88 Symbol* basic_add(int index, u1* name, int len, unsigned int hashValue, |
90 unsigned int hashValue, TRAPS); |
89 bool c_heap, TRAPS); |
91 bool basic_add(constantPoolHandle cp, int names_count, |
90 |
|
91 bool basic_add(Handle class_loader, constantPoolHandle cp, int names_count, |
92 const char** names, int* lengths, int* cp_indices, |
92 const char** names, int* lengths, int* cp_indices, |
93 unsigned int* hashValues, TRAPS); |
93 unsigned int* hashValues, TRAPS); |
94 |
94 |
95 static void new_symbols(constantPoolHandle cp, int names_count, |
95 static void new_symbols(Handle class_loader, constantPoolHandle cp, |
|
96 int names_count, |
96 const char** name, int* lengths, |
97 const char** name, int* lengths, |
97 int* cp_indices, unsigned int* hashValues, |
98 int* cp_indices, unsigned int* hashValues, |
98 TRAPS) { |
99 TRAPS) { |
99 add(cp, names_count, name, lengths, cp_indices, hashValues, THREAD); |
100 add(class_loader, cp, names_count, name, lengths, cp_indices, hashValues, THREAD); |
100 } |
101 } |
101 |
|
102 |
102 |
103 // Table size |
103 // Table size |
104 enum { |
104 enum { |
105 symbol_table_size = 20011 |
105 symbol_table_size = 20011 |
106 }; |
106 }; |
112 |
112 |
113 SymbolTable(HashtableBucket* t, int number_of_entries) |
113 SymbolTable(HashtableBucket* t, int number_of_entries) |
114 : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t, |
114 : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t, |
115 number_of_entries) {} |
115 number_of_entries) {} |
116 |
116 |
117 |
117 // Arena for permanent symbols (null class loader) that are never unloaded |
|
118 static Arena* _arena; |
|
119 static Arena* arena() { return _arena; } // called for statistics |
|
120 |
|
121 static void initialize_symbols(int arena_alloc_size = 0); |
118 public: |
122 public: |
119 enum { |
123 enum { |
120 symbol_alloc_batch_size = 8 |
124 symbol_alloc_batch_size = 8, |
|
125 // Pick initial size based on java -version size measurements |
|
126 symbol_alloc_arena_size = 360*K |
121 }; |
127 }; |
122 |
128 |
123 // The symbol table |
129 // The symbol table |
124 static SymbolTable* the_table() { return _the_table; } |
130 static SymbolTable* the_table() { return _the_table; } |
125 |
131 |
126 static void create_table() { |
132 static void create_table() { |
127 assert(_the_table == NULL, "One symbol table allowed."); |
133 assert(_the_table == NULL, "One symbol table allowed."); |
128 _the_table = new SymbolTable(); |
134 _the_table = new SymbolTable(); |
|
135 initialize_symbols(symbol_alloc_arena_size); |
129 } |
136 } |
130 |
137 |
131 static void create_table(HashtableBucket* t, int length, |
138 static void create_table(HashtableBucket* t, int length, |
132 int number_of_entries) { |
139 int number_of_entries) { |
133 assert(_the_table == NULL, "One symbol table allowed."); |
140 assert(_the_table == NULL, "One symbol table allowed."); |
134 assert(length == symbol_table_size * sizeof(HashtableBucket), |
141 assert(length == symbol_table_size * sizeof(HashtableBucket), |
135 "bad shared symbol size."); |
142 "bad shared symbol size."); |
136 _the_table = new SymbolTable(t, number_of_entries); |
143 _the_table = new SymbolTable(t, number_of_entries); |
|
144 // if CDS give symbol table a default arena size since most symbols |
|
145 // are already allocated in the shared misc section. |
|
146 initialize_symbols(); |
137 } |
147 } |
138 |
148 |
139 static Symbol* lookup(const char* name, int len, TRAPS); |
149 static Symbol* lookup(const char* name, int len, TRAPS); |
140 // lookup only, won't add. Also calculate hash. |
150 // lookup only, won't add. Also calculate hash. |
141 static Symbol* lookup_only(const char* name, int len, unsigned int& hash); |
151 static Symbol* lookup_only(const char* name, int len, unsigned int& hash); |
149 |
159 |
150 // jchar (utf16) version of lookups |
160 // jchar (utf16) version of lookups |
151 static Symbol* lookup_unicode(const jchar* name, int len, TRAPS); |
161 static Symbol* lookup_unicode(const jchar* name, int len, TRAPS); |
152 static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash); |
162 static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash); |
153 |
163 |
154 static void add(constantPoolHandle cp, int names_count, |
164 static void add(Handle class_loader, constantPoolHandle cp, int names_count, |
155 const char** names, int* lengths, int* cp_indices, |
165 const char** names, int* lengths, int* cp_indices, |
156 unsigned int* hashValues, TRAPS); |
166 unsigned int* hashValues, TRAPS); |
157 |
167 |
158 // Release any dead symbols |
168 // Release any dead symbols |
159 static void unlink(); |
169 static void unlink(); |
171 } |
181 } |
172 static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) { |
182 static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) { |
173 assert(begin <= end && end <= sym->utf8_length(), "just checking"); |
183 assert(begin <= end && end <= sym->utf8_length(), "just checking"); |
174 return lookup(sym, begin, end, THREAD); |
184 return lookup(sym, begin, end, THREAD); |
175 } |
185 } |
|
186 |
|
187 // Create a symbol in the arena for symbols that are not deleted |
|
188 static Symbol* new_permanent_symbol(const char* name, TRAPS); |
176 |
189 |
177 // Symbol lookup |
190 // Symbol lookup |
178 static Symbol* lookup(int index, const char* name, int len, TRAPS); |
191 static Symbol* lookup(int index, const char* name, int len, TRAPS); |
179 |
192 |
180 // Needed for preloading classes in signatures when compiling. |
193 // Needed for preloading classes in signatures when compiling. |