1 /* |
1 /* |
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. |
2 * Copyright 1997-2009 Sun Microsystems, Inc. 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. |
107 int index = the_table()->hash_to_index(hash); |
107 int index = the_table()->hash_to_index(hash); |
108 |
108 |
109 return the_table()->lookup(index, name, len, hash); |
109 return the_table()->lookup(index, name, len, hash); |
110 } |
110 } |
111 |
111 |
|
112 // Suggestion: Push unicode-based lookup all the way into the hashing |
|
113 // and probing logic, so there is no need for convert_to_utf8 until |
|
114 // an actual new symbolOop is created. |
|
115 symbolOop SymbolTable::lookup_unicode(const jchar* name, int utf16_length, TRAPS) { |
|
116 int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); |
|
117 char stack_buf[128]; |
|
118 if (utf8_length < (int) sizeof(stack_buf)) { |
|
119 char* chars = stack_buf; |
|
120 UNICODE::convert_to_utf8(name, utf16_length, chars); |
|
121 return lookup(chars, utf8_length, THREAD); |
|
122 } else { |
|
123 ResourceMark rm(THREAD); |
|
124 char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; |
|
125 UNICODE::convert_to_utf8(name, utf16_length, chars); |
|
126 return lookup(chars, utf8_length, THREAD); |
|
127 } |
|
128 } |
|
129 |
|
130 symbolOop SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length, |
|
131 unsigned int& hash) { |
|
132 int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); |
|
133 char stack_buf[128]; |
|
134 if (utf8_length < (int) sizeof(stack_buf)) { |
|
135 char* chars = stack_buf; |
|
136 UNICODE::convert_to_utf8(name, utf16_length, chars); |
|
137 return lookup_only(chars, utf8_length, hash); |
|
138 } else { |
|
139 ResourceMark rm; |
|
140 char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; |
|
141 UNICODE::convert_to_utf8(name, utf16_length, chars); |
|
142 return lookup_only(chars, utf8_length, hash); |
|
143 } |
|
144 } |
|
145 |
112 void SymbolTable::add(constantPoolHandle cp, int names_count, |
146 void SymbolTable::add(constantPoolHandle cp, int names_count, |
113 const char** names, int* lengths, int* cp_indices, |
147 const char** names, int* lengths, int* cp_indices, |
114 unsigned int* hashValues, TRAPS) { |
148 unsigned int* hashValues, TRAPS) { |
115 SymbolTable* table = the_table(); |
149 SymbolTable* table = the_table(); |
116 bool added = table->basic_add(cp, names_count, names, lengths, |
150 bool added = table->basic_add(cp, names_count, names, lengths, |
123 hashValues[i], CHECK); |
157 hashValues[i], CHECK); |
124 cp->symbol_at_put(cp_indices[i], sym); |
158 cp->symbol_at_put(cp_indices[i], sym); |
125 } |
159 } |
126 } |
160 } |
127 } |
161 } |
128 |
|
129 // Needed for preloading classes in signatures when compiling. |
|
130 |
|
131 symbolOop SymbolTable::probe(const char* name, int len) { |
|
132 unsigned int hashValue = hash_symbol(name, len); |
|
133 int index = the_table()->hash_to_index(hashValue); |
|
134 return the_table()->lookup(index, name, len, hashValue); |
|
135 } |
|
136 |
|
137 |
162 |
138 symbolOop SymbolTable::basic_add(int index, u1 *name, int len, |
163 symbolOop SymbolTable::basic_add(int index, u1 *name, int len, |
139 unsigned int hashValue, TRAPS) { |
164 unsigned int hashValue, TRAPS) { |
140 assert(!Universe::heap()->is_in_reserved(name) || GC_locker::is_active(), |
165 assert(!Universe::heap()->is_in_reserved(name) || GC_locker::is_active(), |
141 "proposed name of symbol must be stable"); |
166 "proposed name of symbol must be stable"); |