1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/oops/constantPool.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,990 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP 1.29 +#define SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP 1.30 + 1.31 +#include "oops/arrayOop.hpp" 1.32 +#include "oops/cpCache.hpp" 1.33 +#include "oops/objArrayOop.hpp" 1.34 +#include "oops/symbol.hpp" 1.35 +#include "oops/typeArrayOop.hpp" 1.36 +#include "runtime/handles.hpp" 1.37 +#include "utilities/constantTag.hpp" 1.38 +#ifdef TARGET_ARCH_x86 1.39 +# include "bytes_x86.hpp" 1.40 +#endif 1.41 +#ifdef TARGET_ARCH_sparc 1.42 +# include "bytes_sparc.hpp" 1.43 +#endif 1.44 +#ifdef TARGET_ARCH_zero 1.45 +# include "bytes_zero.hpp" 1.46 +#endif 1.47 +#ifdef TARGET_ARCH_arm 1.48 +# include "bytes_arm.hpp" 1.49 +#endif 1.50 +#ifdef TARGET_ARCH_ppc 1.51 +# include "bytes_ppc.hpp" 1.52 +#endif 1.53 + 1.54 +// A constantPool is an array containing class constants as described in the 1.55 +// class file. 1.56 +// 1.57 +// Most of the constant pool entries are written during class parsing, which 1.58 +// is safe. For klass types, the constant pool entry is 1.59 +// modified when the entry is resolved. If a klass constant pool 1.60 +// entry is read without a lock, only the resolved state guarantees that 1.61 +// the entry in the constant pool is a klass object and not a Symbol*. 1.62 + 1.63 +class SymbolHashMap; 1.64 + 1.65 +class CPSlot VALUE_OBJ_CLASS_SPEC { 1.66 + intptr_t _ptr; 1.67 + public: 1.68 + CPSlot(intptr_t ptr): _ptr(ptr) {} 1.69 + CPSlot(Klass* ptr): _ptr((intptr_t)ptr) {} 1.70 + CPSlot(Symbol* ptr): _ptr((intptr_t)ptr | 1) {} 1.71 + 1.72 + intptr_t value() { return _ptr; } 1.73 + bool is_resolved() { return (_ptr & 1) == 0; } 1.74 + bool is_unresolved() { return (_ptr & 1) == 1; } 1.75 + 1.76 + Symbol* get_symbol() { 1.77 + assert(is_unresolved(), "bad call"); 1.78 + return (Symbol*)(_ptr & ~1); 1.79 + } 1.80 + Klass* get_klass() { 1.81 + assert(is_resolved(), "bad call"); 1.82 + return (Klass*)_ptr; 1.83 + } 1.84 +}; 1.85 + 1.86 +class KlassSizeStats; 1.87 +class ConstantPool : public Metadata { 1.88 + friend class VMStructs; 1.89 + friend class BytecodeInterpreter; // Directly extracts an oop in the pool for fast instanceof/checkcast 1.90 + friend class Universe; // For null constructor 1.91 + private: 1.92 + Array<u1>* _tags; // the tag array describing the constant pool's contents 1.93 + ConstantPoolCache* _cache; // the cache holding interpreter runtime information 1.94 + InstanceKlass* _pool_holder; // the corresponding class 1.95 + Array<u2>* _operands; // for variable-sized (InvokeDynamic) nodes, usually empty 1.96 + 1.97 + // Array of resolved objects from the constant pool and map from resolved 1.98 + // object index to original constant pool index 1.99 + jobject _resolved_references; 1.100 + Array<u2>* _reference_map; 1.101 + 1.102 + enum { 1.103 + _has_preresolution = 1, // Flags 1.104 + _on_stack = 2 1.105 + }; 1.106 + 1.107 + int _flags; // old fashioned bit twiddling 1.108 + int _length; // number of elements in the array 1.109 + 1.110 + union { 1.111 + // set for CDS to restore resolved references 1.112 + int _resolved_reference_length; 1.113 + // keeps version number for redefined classes (used in backtrace) 1.114 + int _version; 1.115 + } _saved; 1.116 + 1.117 + Monitor* _lock; 1.118 + 1.119 + void set_tags(Array<u1>* tags) { _tags = tags; } 1.120 + void tag_at_put(int which, jbyte t) { tags()->at_put(which, t); } 1.121 + void release_tag_at_put(int which, jbyte t) { tags()->release_at_put(which, t); } 1.122 + 1.123 + void set_operands(Array<u2>* operands) { _operands = operands; } 1.124 + 1.125 + int flags() const { return _flags; } 1.126 + void set_flags(int f) { _flags = f; } 1.127 + 1.128 + private: 1.129 + intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(ConstantPool)); } 1.130 + 1.131 + CPSlot slot_at(int which) { 1.132 + assert(is_within_bounds(which), "index out of bounds"); 1.133 + // Uses volatile because the klass slot changes without a lock. 1.134 + volatile intptr_t adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which)); 1.135 + assert(adr != 0 || which == 0, "cp entry for klass should not be zero"); 1.136 + return CPSlot(adr); 1.137 + } 1.138 + 1.139 + void slot_at_put(int which, CPSlot s) const { 1.140 + assert(is_within_bounds(which), "index out of bounds"); 1.141 + assert(s.value() != 0, "Caught something"); 1.142 + *(intptr_t*)&base()[which] = s.value(); 1.143 + } 1.144 + intptr_t* obj_at_addr_raw(int which) const { 1.145 + assert(is_within_bounds(which), "index out of bounds"); 1.146 + return (intptr_t*) &base()[which]; 1.147 + } 1.148 + 1.149 + jint* int_at_addr(int which) const { 1.150 + assert(is_within_bounds(which), "index out of bounds"); 1.151 + return (jint*) &base()[which]; 1.152 + } 1.153 + 1.154 + jlong* long_at_addr(int which) const { 1.155 + assert(is_within_bounds(which), "index out of bounds"); 1.156 + return (jlong*) &base()[which]; 1.157 + } 1.158 + 1.159 + jfloat* float_at_addr(int which) const { 1.160 + assert(is_within_bounds(which), "index out of bounds"); 1.161 + return (jfloat*) &base()[which]; 1.162 + } 1.163 + 1.164 + jdouble* double_at_addr(int which) const { 1.165 + assert(is_within_bounds(which), "index out of bounds"); 1.166 + return (jdouble*) &base()[which]; 1.167 + } 1.168 + 1.169 + ConstantPool(Array<u1>* tags); 1.170 + ConstantPool() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } 1.171 + public: 1.172 + static ConstantPool* allocate(ClassLoaderData* loader_data, int length, TRAPS); 1.173 + 1.174 + bool is_constantPool() const volatile { return true; } 1.175 + 1.176 + Array<u1>* tags() const { return _tags; } 1.177 + Array<u2>* operands() const { return _operands; } 1.178 + 1.179 + bool has_preresolution() const { return (_flags & _has_preresolution) != 0; } 1.180 + void set_has_preresolution() { _flags |= _has_preresolution; } 1.181 + 1.182 + // Redefine classes support. If a method refering to this constant pool 1.183 + // is on the executing stack, or as a handle in vm code, this constant pool 1.184 + // can't be removed from the set of previous versions saved in the instance 1.185 + // class. 1.186 + bool on_stack() const { return (_flags &_on_stack) != 0; } 1.187 + void set_on_stack(const bool value); 1.188 + 1.189 + // Klass holding pool 1.190 + InstanceKlass* pool_holder() const { return _pool_holder; } 1.191 + void set_pool_holder(InstanceKlass* k) { _pool_holder = k; } 1.192 + InstanceKlass** pool_holder_addr() { return &_pool_holder; } 1.193 + 1.194 + // Interpreter runtime support 1.195 + ConstantPoolCache* cache() const { return _cache; } 1.196 + void set_cache(ConstantPoolCache* cache){ _cache = cache; } 1.197 + 1.198 + // Create object cache in the constant pool 1.199 + void initialize_resolved_references(ClassLoaderData* loader_data, 1.200 + intStack reference_map, 1.201 + int constant_pool_map_length, 1.202 + TRAPS); 1.203 + 1.204 + // resolved strings, methodHandles and callsite objects from the constant pool 1.205 + objArrayOop resolved_references() const; 1.206 + // mapping resolved object array indexes to cp indexes and back. 1.207 + int object_to_cp_index(int index) { return _reference_map->at(index); } 1.208 + int cp_to_object_index(int index); 1.209 + 1.210 + // Invokedynamic indexes. 1.211 + // They must look completely different from normal indexes. 1.212 + // The main reason is that byte swapping is sometimes done on normal indexes. 1.213 + // Finally, it is helpful for debugging to tell the two apart. 1.214 + static bool is_invokedynamic_index(int i) { return (i < 0); } 1.215 + static int decode_invokedynamic_index(int i) { assert(is_invokedynamic_index(i), ""); return ~i; } 1.216 + static int encode_invokedynamic_index(int i) { assert(!is_invokedynamic_index(i), ""); return ~i; } 1.217 + 1.218 + 1.219 + // The invokedynamic points at a CP cache entry. This entry points back 1.220 + // at the original CP entry (CONSTANT_InvokeDynamic) and also (via f2) at an entry 1.221 + // in the resolved_references array (which provides the appendix argument). 1.222 + int invokedynamic_cp_cache_index(int index) const { 1.223 + assert (is_invokedynamic_index(index), "should be a invokedynamic index"); 1.224 + int cache_index = decode_invokedynamic_index(index); 1.225 + return cache_index; 1.226 + } 1.227 + ConstantPoolCacheEntry* invokedynamic_cp_cache_entry_at(int index) const { 1.228 + // decode index that invokedynamic points to. 1.229 + int cp_cache_index = invokedynamic_cp_cache_index(index); 1.230 + return cache()->entry_at(cp_cache_index); 1.231 + } 1.232 + 1.233 + // Assembly code support 1.234 + static int tags_offset_in_bytes() { return offset_of(ConstantPool, _tags); } 1.235 + static int cache_offset_in_bytes() { return offset_of(ConstantPool, _cache); } 1.236 + static int pool_holder_offset_in_bytes() { return offset_of(ConstantPool, _pool_holder); } 1.237 + static int resolved_references_offset_in_bytes() { return offset_of(ConstantPool, _resolved_references); } 1.238 + 1.239 + // Storing constants 1.240 + 1.241 + void klass_at_put(int which, Klass* k) { 1.242 + assert(k != NULL, "resolved class shouldn't be null"); 1.243 + assert(is_within_bounds(which), "index out of bounds"); 1.244 + OrderAccess::release_store_ptr((Klass* volatile *)obj_at_addr_raw(which), k); 1.245 + // The interpreter assumes when the tag is stored, the klass is resolved 1.246 + // and the Klass* is a klass rather than a Symbol*, so we need 1.247 + // hardware store ordering here. 1.248 + release_tag_at_put(which, JVM_CONSTANT_Class); 1.249 + } 1.250 + 1.251 + // For temporary use while constructing constant pool 1.252 + void klass_index_at_put(int which, int name_index) { 1.253 + tag_at_put(which, JVM_CONSTANT_ClassIndex); 1.254 + *int_at_addr(which) = name_index; 1.255 + } 1.256 + 1.257 + // Temporary until actual use 1.258 + void unresolved_klass_at_put(int which, Symbol* s) { 1.259 + release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass); 1.260 + slot_at_put(which, s); 1.261 + } 1.262 + 1.263 + void method_handle_index_at_put(int which, int ref_kind, int ref_index) { 1.264 + tag_at_put(which, JVM_CONSTANT_MethodHandle); 1.265 + *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind; 1.266 + } 1.267 + 1.268 + void method_type_index_at_put(int which, int ref_index) { 1.269 + tag_at_put(which, JVM_CONSTANT_MethodType); 1.270 + *int_at_addr(which) = ref_index; 1.271 + } 1.272 + 1.273 + void invoke_dynamic_at_put(int which, int bootstrap_specifier_index, int name_and_type_index) { 1.274 + tag_at_put(which, JVM_CONSTANT_InvokeDynamic); 1.275 + *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_specifier_index; 1.276 + } 1.277 + 1.278 + void unresolved_string_at_put(int which, Symbol* s) { 1.279 + release_tag_at_put(which, JVM_CONSTANT_String); 1.280 + *symbol_at_addr(which) = s; 1.281 + } 1.282 + 1.283 + void int_at_put(int which, jint i) { 1.284 + tag_at_put(which, JVM_CONSTANT_Integer); 1.285 + *int_at_addr(which) = i; 1.286 + } 1.287 + 1.288 + void long_at_put(int which, jlong l) { 1.289 + tag_at_put(which, JVM_CONSTANT_Long); 1.290 + // *long_at_addr(which) = l; 1.291 + Bytes::put_native_u8((address)long_at_addr(which), *((u8*) &l)); 1.292 + } 1.293 + 1.294 + void float_at_put(int which, jfloat f) { 1.295 + tag_at_put(which, JVM_CONSTANT_Float); 1.296 + *float_at_addr(which) = f; 1.297 + } 1.298 + 1.299 + void double_at_put(int which, jdouble d) { 1.300 + tag_at_put(which, JVM_CONSTANT_Double); 1.301 + // *double_at_addr(which) = d; 1.302 + // u8 temp = *(u8*) &d; 1.303 + Bytes::put_native_u8((address) double_at_addr(which), *((u8*) &d)); 1.304 + } 1.305 + 1.306 + Symbol** symbol_at_addr(int which) const { 1.307 + assert(is_within_bounds(which), "index out of bounds"); 1.308 + return (Symbol**) &base()[which]; 1.309 + } 1.310 + 1.311 + void symbol_at_put(int which, Symbol* s) { 1.312 + assert(s->refcount() != 0, "should have nonzero refcount"); 1.313 + tag_at_put(which, JVM_CONSTANT_Utf8); 1.314 + *symbol_at_addr(which) = s; 1.315 + } 1.316 + 1.317 + void string_at_put(int which, int obj_index, oop str) { 1.318 + resolved_references()->obj_at_put(obj_index, str); 1.319 + } 1.320 + 1.321 + // For temporary use while constructing constant pool 1.322 + void string_index_at_put(int which, int string_index) { 1.323 + tag_at_put(which, JVM_CONSTANT_StringIndex); 1.324 + *int_at_addr(which) = string_index; 1.325 + } 1.326 + 1.327 + void field_at_put(int which, int class_index, int name_and_type_index) { 1.328 + tag_at_put(which, JVM_CONSTANT_Fieldref); 1.329 + *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; 1.330 + } 1.331 + 1.332 + void method_at_put(int which, int class_index, int name_and_type_index) { 1.333 + tag_at_put(which, JVM_CONSTANT_Methodref); 1.334 + *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; 1.335 + } 1.336 + 1.337 + void interface_method_at_put(int which, int class_index, int name_and_type_index) { 1.338 + tag_at_put(which, JVM_CONSTANT_InterfaceMethodref); 1.339 + *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; // Not so nice 1.340 + } 1.341 + 1.342 + void name_and_type_at_put(int which, int name_index, int signature_index) { 1.343 + tag_at_put(which, JVM_CONSTANT_NameAndType); 1.344 + *int_at_addr(which) = ((jint) signature_index<<16) | name_index; // Not so nice 1.345 + } 1.346 + 1.347 + // Tag query 1.348 + 1.349 + constantTag tag_at(int which) const { return (constantTag)tags()->at_acquire(which); } 1.350 + 1.351 + // Fetching constants 1.352 + 1.353 + Klass* klass_at(int which, TRAPS) { 1.354 + constantPoolHandle h_this(THREAD, this); 1.355 + return klass_at_impl(h_this, which, CHECK_NULL); 1.356 + } 1.357 + 1.358 + Symbol* klass_name_at(int which); // Returns the name, w/o resolving. 1.359 + 1.360 + Klass* resolved_klass_at(int which) const { // Used by Compiler 1.361 + guarantee(tag_at(which).is_klass(), "Corrupted constant pool"); 1.362 + // Must do an acquire here in case another thread resolved the klass 1.363 + // behind our back, lest we later load stale values thru the oop. 1.364 + return CPSlot((Klass*)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_klass(); 1.365 + } 1.366 + 1.367 + // This method should only be used with a cpool lock or during parsing or gc 1.368 + Symbol* unresolved_klass_at(int which) { // Temporary until actual use 1.369 + Symbol* s = CPSlot((Symbol*)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_symbol(); 1.370 + // check that the klass is still unresolved. 1.371 + assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool"); 1.372 + return s; 1.373 + } 1.374 + 1.375 + // RedefineClasses() API support: 1.376 + Symbol* klass_at_noresolve(int which) { return klass_name_at(which); } 1.377 + 1.378 + jint int_at(int which) { 1.379 + assert(tag_at(which).is_int(), "Corrupted constant pool"); 1.380 + return *int_at_addr(which); 1.381 + } 1.382 + 1.383 + jlong long_at(int which) { 1.384 + assert(tag_at(which).is_long(), "Corrupted constant pool"); 1.385 + // return *long_at_addr(which); 1.386 + u8 tmp = Bytes::get_native_u8((address)&base()[which]); 1.387 + return *((jlong*)&tmp); 1.388 + } 1.389 + 1.390 + jfloat float_at(int which) { 1.391 + assert(tag_at(which).is_float(), "Corrupted constant pool"); 1.392 + return *float_at_addr(which); 1.393 + } 1.394 + 1.395 + jdouble double_at(int which) { 1.396 + assert(tag_at(which).is_double(), "Corrupted constant pool"); 1.397 + u8 tmp = Bytes::get_native_u8((address)&base()[which]); 1.398 + return *((jdouble*)&tmp); 1.399 + } 1.400 + 1.401 + Symbol* symbol_at(int which) { 1.402 + assert(tag_at(which).is_utf8(), "Corrupted constant pool"); 1.403 + return *symbol_at_addr(which); 1.404 + } 1.405 + 1.406 + oop string_at(int which, int obj_index, TRAPS) { 1.407 + constantPoolHandle h_this(THREAD, this); 1.408 + return string_at_impl(h_this, which, obj_index, THREAD); 1.409 + } 1.410 + oop string_at(int which, TRAPS) { 1.411 + int obj_index = cp_to_object_index(which); 1.412 + return string_at(which, obj_index, THREAD); 1.413 + } 1.414 + 1.415 + // Version that can be used before string oop array is created. 1.416 + oop uncached_string_at(int which, TRAPS); 1.417 + 1.418 + // A "pseudo-string" is an non-string oop that has found is way into 1.419 + // a String entry. 1.420 + // Under EnableInvokeDynamic this can happen if the user patches a live 1.421 + // object into a CONSTANT_String entry of an anonymous class. 1.422 + // Method oops internally created for method handles may also 1.423 + // use pseudo-strings to link themselves to related metaobjects. 1.424 + 1.425 + bool is_pseudo_string_at(int which) { 1.426 + // A pseudo string is a string that doesn't have a symbol in the cpSlot 1.427 + return unresolved_string_at(which) == NULL; 1.428 + } 1.429 + 1.430 + oop pseudo_string_at(int which, int obj_index) { 1.431 + assert(tag_at(which).is_string(), "Corrupted constant pool"); 1.432 + assert(unresolved_string_at(which) == NULL, "shouldn't have symbol"); 1.433 + oop s = resolved_references()->obj_at(obj_index); 1.434 + return s; 1.435 + } 1.436 + 1.437 + oop pseudo_string_at(int which) { 1.438 + assert(tag_at(which).is_string(), "Corrupted constant pool"); 1.439 + assert(unresolved_string_at(which) == NULL, "shouldn't have symbol"); 1.440 + int obj_index = cp_to_object_index(which); 1.441 + oop s = resolved_references()->obj_at(obj_index); 1.442 + return s; 1.443 + } 1.444 + 1.445 + void pseudo_string_at_put(int which, int obj_index, oop x) { 1.446 + assert(EnableInvokeDynamic, ""); 1.447 + assert(tag_at(which).is_string(), "Corrupted constant pool"); 1.448 + unresolved_string_at_put(which, NULL); // indicates patched string 1.449 + string_at_put(which, obj_index, x); // this works just fine 1.450 + } 1.451 + 1.452 + // only called when we are sure a string entry is already resolved (via an 1.453 + // earlier string_at call. 1.454 + oop resolved_string_at(int which) { 1.455 + assert(tag_at(which).is_string(), "Corrupted constant pool"); 1.456 + // Must do an acquire here in case another thread resolved the klass 1.457 + // behind our back, lest we later load stale values thru the oop. 1.458 + // we might want a volatile_obj_at in ObjArrayKlass. 1.459 + int obj_index = cp_to_object_index(which); 1.460 + return resolved_references()->obj_at(obj_index); 1.461 + } 1.462 + 1.463 + Symbol* unresolved_string_at(int which) { 1.464 + assert(tag_at(which).is_string(), "Corrupted constant pool"); 1.465 + Symbol* s = *symbol_at_addr(which); 1.466 + return s; 1.467 + } 1.468 + 1.469 + // Returns an UTF8 for a CONSTANT_String entry at a given index. 1.470 + // UTF8 char* representation was chosen to avoid conversion of 1.471 + // java_lang_Strings at resolved entries into Symbol*s 1.472 + // or vice versa. 1.473 + // Caller is responsible for checking for pseudo-strings. 1.474 + char* string_at_noresolve(int which); 1.475 + 1.476 + jint name_and_type_at(int which) { 1.477 + assert(tag_at(which).is_name_and_type(), "Corrupted constant pool"); 1.478 + return *int_at_addr(which); 1.479 + } 1.480 + 1.481 + private: 1.482 + int method_handle_ref_kind_at(int which, bool error_ok) { 1.483 + assert(tag_at(which).is_method_handle() || 1.484 + (error_ok && tag_at(which).is_method_handle_in_error()), "Corrupted constant pool"); 1.485 + return extract_low_short_from_int(*int_at_addr(which)); // mask out unwanted ref_index bits 1.486 + } 1.487 + int method_handle_index_at(int which, bool error_ok) { 1.488 + assert(tag_at(which).is_method_handle() || 1.489 + (error_ok && tag_at(which).is_method_handle_in_error()), "Corrupted constant pool"); 1.490 + return extract_high_short_from_int(*int_at_addr(which)); // shift out unwanted ref_kind bits 1.491 + } 1.492 + int method_type_index_at(int which, bool error_ok) { 1.493 + assert(tag_at(which).is_method_type() || 1.494 + (error_ok && tag_at(which).is_method_type_in_error()), "Corrupted constant pool"); 1.495 + return *int_at_addr(which); 1.496 + } 1.497 + public: 1.498 + int method_handle_ref_kind_at(int which) { 1.499 + return method_handle_ref_kind_at(which, false); 1.500 + } 1.501 + int method_handle_ref_kind_at_error_ok(int which) { 1.502 + return method_handle_ref_kind_at(which, true); 1.503 + } 1.504 + int method_handle_index_at(int which) { 1.505 + return method_handle_index_at(which, false); 1.506 + } 1.507 + int method_handle_index_at_error_ok(int which) { 1.508 + return method_handle_index_at(which, true); 1.509 + } 1.510 + int method_type_index_at(int which) { 1.511 + return method_type_index_at(which, false); 1.512 + } 1.513 + int method_type_index_at_error_ok(int which) { 1.514 + return method_type_index_at(which, true); 1.515 + } 1.516 + 1.517 + // Derived queries: 1.518 + Symbol* method_handle_name_ref_at(int which) { 1.519 + int member = method_handle_index_at(which); 1.520 + return impl_name_ref_at(member, true); 1.521 + } 1.522 + Symbol* method_handle_signature_ref_at(int which) { 1.523 + int member = method_handle_index_at(which); 1.524 + return impl_signature_ref_at(member, true); 1.525 + } 1.526 + int method_handle_klass_index_at(int which) { 1.527 + int member = method_handle_index_at(which); 1.528 + return impl_klass_ref_index_at(member, true); 1.529 + } 1.530 + Symbol* method_type_signature_at(int which) { 1.531 + int sym = method_type_index_at(which); 1.532 + return symbol_at(sym); 1.533 + } 1.534 + 1.535 + int invoke_dynamic_name_and_type_ref_index_at(int which) { 1.536 + assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); 1.537 + return extract_high_short_from_int(*int_at_addr(which)); 1.538 + } 1.539 + int invoke_dynamic_bootstrap_specifier_index(int which) { 1.540 + assert(tag_at(which).value() == JVM_CONSTANT_InvokeDynamic, "Corrupted constant pool"); 1.541 + return extract_low_short_from_int(*int_at_addr(which)); 1.542 + } 1.543 + int invoke_dynamic_operand_base(int which) { 1.544 + int bootstrap_specifier_index = invoke_dynamic_bootstrap_specifier_index(which); 1.545 + return operand_offset_at(operands(), bootstrap_specifier_index); 1.546 + } 1.547 + // The first part of the operands array consists of an index into the second part. 1.548 + // Extract a 32-bit index value from the first part. 1.549 + static int operand_offset_at(Array<u2>* operands, int bootstrap_specifier_index) { 1.550 + int n = (bootstrap_specifier_index * 2); 1.551 + assert(n >= 0 && n+2 <= operands->length(), "oob"); 1.552 + // The first 32-bit index points to the beginning of the second part 1.553 + // of the operands array. Make sure this index is in the first part. 1.554 + DEBUG_ONLY(int second_part = build_int_from_shorts(operands->at(0), 1.555 + operands->at(1))); 1.556 + assert(second_part == 0 || n+2 <= second_part, "oob (2)"); 1.557 + int offset = build_int_from_shorts(operands->at(n+0), 1.558 + operands->at(n+1)); 1.559 + // The offset itself must point into the second part of the array. 1.560 + assert(offset == 0 || offset >= second_part && offset <= operands->length(), "oob (3)"); 1.561 + return offset; 1.562 + } 1.563 + static void operand_offset_at_put(Array<u2>* operands, int bootstrap_specifier_index, int offset) { 1.564 + int n = bootstrap_specifier_index * 2; 1.565 + assert(n >= 0 && n+2 <= operands->length(), "oob"); 1.566 + operands->at_put(n+0, extract_low_short_from_int(offset)); 1.567 + operands->at_put(n+1, extract_high_short_from_int(offset)); 1.568 + } 1.569 + static int operand_array_length(Array<u2>* operands) { 1.570 + if (operands == NULL || operands->length() == 0) return 0; 1.571 + int second_part = operand_offset_at(operands, 0); 1.572 + return (second_part / 2); 1.573 + } 1.574 + 1.575 +#ifdef ASSERT 1.576 + // operand tuples fit together exactly, end to end 1.577 + static int operand_limit_at(Array<u2>* operands, int bootstrap_specifier_index) { 1.578 + int nextidx = bootstrap_specifier_index + 1; 1.579 + if (nextidx == operand_array_length(operands)) 1.580 + return operands->length(); 1.581 + else 1.582 + return operand_offset_at(operands, nextidx); 1.583 + } 1.584 + int invoke_dynamic_operand_limit(int which) { 1.585 + int bootstrap_specifier_index = invoke_dynamic_bootstrap_specifier_index(which); 1.586 + return operand_limit_at(operands(), bootstrap_specifier_index); 1.587 + } 1.588 +#endif //ASSERT 1.589 + 1.590 + // layout of InvokeDynamic bootstrap method specifier (in second part of operands array): 1.591 + enum { 1.592 + _indy_bsm_offset = 0, // CONSTANT_MethodHandle bsm 1.593 + _indy_argc_offset = 1, // u2 argc 1.594 + _indy_argv_offset = 2 // u2 argv[argc] 1.595 + }; 1.596 + 1.597 + // These functions are used in RedefineClasses for CP merge 1.598 + 1.599 + int operand_offset_at(int bootstrap_specifier_index) { 1.600 + assert(0 <= bootstrap_specifier_index && 1.601 + bootstrap_specifier_index < operand_array_length(operands()), 1.602 + "Corrupted CP operands"); 1.603 + return operand_offset_at(operands(), bootstrap_specifier_index); 1.604 + } 1.605 + int operand_bootstrap_method_ref_index_at(int bootstrap_specifier_index) { 1.606 + int offset = operand_offset_at(bootstrap_specifier_index); 1.607 + return operands()->at(offset + _indy_bsm_offset); 1.608 + } 1.609 + int operand_argument_count_at(int bootstrap_specifier_index) { 1.610 + int offset = operand_offset_at(bootstrap_specifier_index); 1.611 + int argc = operands()->at(offset + _indy_argc_offset); 1.612 + return argc; 1.613 + } 1.614 + int operand_argument_index_at(int bootstrap_specifier_index, int j) { 1.615 + int offset = operand_offset_at(bootstrap_specifier_index); 1.616 + return operands()->at(offset + _indy_argv_offset + j); 1.617 + } 1.618 + int operand_next_offset_at(int bootstrap_specifier_index) { 1.619 + int offset = operand_offset_at(bootstrap_specifier_index) + _indy_argv_offset 1.620 + + operand_argument_count_at(bootstrap_specifier_index); 1.621 + return offset; 1.622 + } 1.623 + // Compare a bootsrap specifier in the operands arrays 1.624 + bool compare_operand_to(int bootstrap_specifier_index1, constantPoolHandle cp2, 1.625 + int bootstrap_specifier_index2, TRAPS); 1.626 + // Find a bootsrap specifier in the operands array 1.627 + int find_matching_operand(int bootstrap_specifier_index, constantPoolHandle search_cp, 1.628 + int operands_cur_len, TRAPS); 1.629 + // Resize the operands array with delta_len and delta_size 1.630 + void resize_operands(int delta_len, int delta_size, TRAPS); 1.631 + // Extend the operands array with the length and size of the ext_cp operands 1.632 + void extend_operands(constantPoolHandle ext_cp, TRAPS); 1.633 + // Shrink the operands array to a smaller array with new_len length 1.634 + void shrink_operands(int new_len, TRAPS); 1.635 + 1.636 + 1.637 + int invoke_dynamic_bootstrap_method_ref_index_at(int which) { 1.638 + assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); 1.639 + int op_base = invoke_dynamic_operand_base(which); 1.640 + return operands()->at(op_base + _indy_bsm_offset); 1.641 + } 1.642 + int invoke_dynamic_argument_count_at(int which) { 1.643 + assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); 1.644 + int op_base = invoke_dynamic_operand_base(which); 1.645 + int argc = operands()->at(op_base + _indy_argc_offset); 1.646 + DEBUG_ONLY(int end_offset = op_base + _indy_argv_offset + argc; 1.647 + int next_offset = invoke_dynamic_operand_limit(which)); 1.648 + assert(end_offset == next_offset, "matched ending"); 1.649 + return argc; 1.650 + } 1.651 + int invoke_dynamic_argument_index_at(int which, int j) { 1.652 + int op_base = invoke_dynamic_operand_base(which); 1.653 + DEBUG_ONLY(int argc = operands()->at(op_base + _indy_argc_offset)); 1.654 + assert((uint)j < (uint)argc, "oob"); 1.655 + return operands()->at(op_base + _indy_argv_offset + j); 1.656 + } 1.657 + 1.658 + // The following methods (name/signature/klass_ref_at, klass_ref_at_noresolve, 1.659 + // name_and_type_ref_index_at) all expect to be passed indices obtained 1.660 + // directly from the bytecode. 1.661 + // If the indices are meant to refer to fields or methods, they are 1.662 + // actually rewritten constant pool cache indices. 1.663 + // The routine remap_instruction_operand_from_cache manages the adjustment 1.664 + // of these values back to constant pool indices. 1.665 + 1.666 + // There are also "uncached" versions which do not adjust the operand index; see below. 1.667 + 1.668 + // FIXME: Consider renaming these with a prefix "cached_" to make the distinction clear. 1.669 + // In a few cases (the verifier) there are uses before a cpcache has been built, 1.670 + // which are handled by a dynamic check in remap_instruction_operand_from_cache. 1.671 + // FIXME: Remove the dynamic check, and adjust all callers to specify the correct mode. 1.672 + 1.673 + // Lookup for entries consisting of (klass_index, name_and_type index) 1.674 + Klass* klass_ref_at(int which, TRAPS); 1.675 + Symbol* klass_ref_at_noresolve(int which); 1.676 + Symbol* name_ref_at(int which) { return impl_name_ref_at(which, false); } 1.677 + Symbol* signature_ref_at(int which) { return impl_signature_ref_at(which, false); } 1.678 + 1.679 + int klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, false); } 1.680 + int name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, false); } 1.681 + 1.682 + // Lookup for entries consisting of (name_index, signature_index) 1.683 + int name_ref_index_at(int which_nt); // == low-order jshort of name_and_type_at(which_nt) 1.684 + int signature_ref_index_at(int which_nt); // == high-order jshort of name_and_type_at(which_nt) 1.685 + 1.686 + BasicType basic_type_for_signature_at(int which); 1.687 + 1.688 + // Resolve string constants (to prevent allocation during compilation) 1.689 + void resolve_string_constants(TRAPS) { 1.690 + constantPoolHandle h_this(THREAD, this); 1.691 + resolve_string_constants_impl(h_this, CHECK); 1.692 + } 1.693 + 1.694 + // CDS support 1.695 + void remove_unshareable_info(); 1.696 + void restore_unshareable_info(TRAPS); 1.697 + bool resolve_class_constants(TRAPS); 1.698 + // The ConstantPool vtable is restored by this call when the ConstantPool is 1.699 + // in the shared archive. See patch_klass_vtables() in metaspaceShared.cpp for 1.700 + // all the gory details. SA, dtrace and pstack helpers distinguish metadata 1.701 + // by their vtable. 1.702 + void restore_vtable() { guarantee(is_constantPool(), "vtable restored by this call"); } 1.703 + 1.704 + private: 1.705 + enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 }; 1.706 + public: 1.707 + 1.708 + // Resolve late bound constants. 1.709 + oop resolve_constant_at(int index, TRAPS) { 1.710 + constantPoolHandle h_this(THREAD, this); 1.711 + return resolve_constant_at_impl(h_this, index, _no_index_sentinel, THREAD); 1.712 + } 1.713 + 1.714 + oop resolve_cached_constant_at(int cache_index, TRAPS) { 1.715 + constantPoolHandle h_this(THREAD, this); 1.716 + return resolve_constant_at_impl(h_this, _no_index_sentinel, cache_index, THREAD); 1.717 + } 1.718 + 1.719 + oop resolve_possibly_cached_constant_at(int pool_index, TRAPS) { 1.720 + constantPoolHandle h_this(THREAD, this); 1.721 + return resolve_constant_at_impl(h_this, pool_index, _possible_index_sentinel, THREAD); 1.722 + } 1.723 + 1.724 + oop resolve_bootstrap_specifier_at(int index, TRAPS) { 1.725 + constantPoolHandle h_this(THREAD, this); 1.726 + return resolve_bootstrap_specifier_at_impl(h_this, index, THREAD); 1.727 + } 1.728 + 1.729 + // Klass name matches name at offset 1.730 + bool klass_name_at_matches(instanceKlassHandle k, int which); 1.731 + 1.732 + // Sizing 1.733 + int length() const { return _length; } 1.734 + void set_length(int length) { _length = length; } 1.735 + 1.736 + // Tells whether index is within bounds. 1.737 + bool is_within_bounds(int index) const { 1.738 + return 0 <= index && index < length(); 1.739 + } 1.740 + 1.741 + // Sizing (in words) 1.742 + static int header_size() { return sizeof(ConstantPool)/HeapWordSize; } 1.743 + static int size(int length) { return align_object_size(header_size() + length); } 1.744 + int size() const { return size(length()); } 1.745 +#if INCLUDE_SERVICES 1.746 + void collect_statistics(KlassSizeStats *sz) const; 1.747 +#endif 1.748 + 1.749 + friend class ClassFileParser; 1.750 + friend class SystemDictionary; 1.751 + 1.752 + // Used by compiler to prevent classloading. 1.753 + static Method* method_at_if_loaded (constantPoolHandle this_oop, int which); 1.754 + static bool has_appendix_at_if_loaded (constantPoolHandle this_oop, int which); 1.755 + static oop appendix_at_if_loaded (constantPoolHandle this_oop, int which); 1.756 + static bool has_method_type_at_if_loaded (constantPoolHandle this_oop, int which); 1.757 + static oop method_type_at_if_loaded (constantPoolHandle this_oop, int which); 1.758 + static Klass* klass_at_if_loaded (constantPoolHandle this_oop, int which); 1.759 + static Klass* klass_ref_at_if_loaded (constantPoolHandle this_oop, int which); 1.760 + 1.761 + // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the 1.762 + // future by other Java code. These take constant pool indices rather than 1.763 + // constant pool cache indices as do the peer methods above. 1.764 + Symbol* uncached_klass_ref_at_noresolve(int which); 1.765 + Symbol* uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); } 1.766 + Symbol* uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); } 1.767 + int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); } 1.768 + int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); } 1.769 + 1.770 + // Sharing 1.771 + int pre_resolve_shared_klasses(TRAPS); 1.772 + 1.773 + // Debugging 1.774 + const char* printable_name_at(int which) PRODUCT_RETURN0; 1.775 + 1.776 +#ifdef ASSERT 1.777 + enum { CPCACHE_INDEX_TAG = 0x10000 }; // helps keep CP cache indices distinct from CP indices 1.778 +#else 1.779 + enum { CPCACHE_INDEX_TAG = 0 }; // in product mode, this zero value is a no-op 1.780 +#endif //ASSERT 1.781 + 1.782 + static int decode_cpcache_index(int raw_index, bool invokedynamic_ok = false) { 1.783 + if (invokedynamic_ok && is_invokedynamic_index(raw_index)) 1.784 + return decode_invokedynamic_index(raw_index); 1.785 + else 1.786 + return raw_index - CPCACHE_INDEX_TAG; 1.787 + } 1.788 + 1.789 + private: 1.790 + 1.791 + void set_resolved_references(jobject s) { _resolved_references = s; } 1.792 + Array<u2>* reference_map() const { return _reference_map; } 1.793 + void set_reference_map(Array<u2>* o) { _reference_map = o; } 1.794 + 1.795 + // patch JSR 292 resolved references after the class is linked. 1.796 + void patch_resolved_references(GrowableArray<Handle>* cp_patches); 1.797 + 1.798 + Symbol* impl_name_ref_at(int which, bool uncached); 1.799 + Symbol* impl_signature_ref_at(int which, bool uncached); 1.800 + int impl_klass_ref_index_at(int which, bool uncached); 1.801 + int impl_name_and_type_ref_index_at(int which, bool uncached); 1.802 + 1.803 + int remap_instruction_operand_from_cache(int operand); // operand must be biased by CPCACHE_INDEX_TAG 1.804 + 1.805 + // Used while constructing constant pool (only by ClassFileParser) 1.806 + jint klass_index_at(int which) { 1.807 + assert(tag_at(which).is_klass_index(), "Corrupted constant pool"); 1.808 + return *int_at_addr(which); 1.809 + } 1.810 + 1.811 + jint string_index_at(int which) { 1.812 + assert(tag_at(which).is_string_index(), "Corrupted constant pool"); 1.813 + return *int_at_addr(which); 1.814 + } 1.815 + 1.816 + // Performs the LinkResolver checks 1.817 + static void verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle klass, TRAPS); 1.818 + 1.819 + // Implementation of methods that needs an exposed 'this' pointer, in order to 1.820 + // handle GC while executing the method 1.821 + static Klass* klass_at_impl(constantPoolHandle this_oop, int which, TRAPS); 1.822 + static oop string_at_impl(constantPoolHandle this_oop, int which, int obj_index, TRAPS); 1.823 + 1.824 + // Resolve string constants (to prevent allocation during compilation) 1.825 + static void resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS); 1.826 + 1.827 + static oop resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS); 1.828 + static void save_and_throw_exception(constantPoolHandle this_oop, int which, int tag_value, TRAPS); 1.829 + static oop resolve_bootstrap_specifier_at_impl(constantPoolHandle this_oop, int index, TRAPS); 1.830 + 1.831 + public: 1.832 + // Merging ConstantPool* support: 1.833 + bool compare_entry_to(int index1, constantPoolHandle cp2, int index2, TRAPS); 1.834 + void copy_cp_to(int start_i, int end_i, constantPoolHandle to_cp, int to_i, TRAPS) { 1.835 + constantPoolHandle h_this(THREAD, this); 1.836 + copy_cp_to_impl(h_this, start_i, end_i, to_cp, to_i, THREAD); 1.837 + } 1.838 + static void copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i, constantPoolHandle to_cp, int to_i, TRAPS); 1.839 + static void copy_entry_to(constantPoolHandle from_cp, int from_i, constantPoolHandle to_cp, int to_i, TRAPS); 1.840 + static void copy_operands(constantPoolHandle from_cp, constantPoolHandle to_cp, TRAPS); 1.841 + int find_matching_entry(int pattern_i, constantPoolHandle search_cp, TRAPS); 1.842 + int version() const { return _saved._version; } 1.843 + void set_version(int version) { _saved._version = version; } 1.844 + void increment_and_save_version(int version) { 1.845 + _saved._version = version >= 0 ? (version + 1) : version; // keep overflow 1.846 + } 1.847 + 1.848 + void set_resolved_reference_length(int length) { _saved._resolved_reference_length = length; } 1.849 + int resolved_reference_length() const { return _saved._resolved_reference_length; } 1.850 + void set_lock(Monitor* lock) { _lock = lock; } 1.851 + Monitor* lock() { return _lock; } 1.852 + 1.853 + // Decrease ref counts of symbols that are in the constant pool 1.854 + // when the holder class is unloaded 1.855 + void unreference_symbols(); 1.856 + 1.857 + // Deallocate constant pool for RedefineClasses 1.858 + void deallocate_contents(ClassLoaderData* loader_data); 1.859 + void release_C_heap_structures(); 1.860 + 1.861 + // JVMTI accesss - GetConstantPool, RetransformClasses, ... 1.862 + friend class JvmtiConstantPoolReconstituter; 1.863 + 1.864 + private: 1.865 + jint cpool_entry_size(jint idx); 1.866 + jint hash_entries_to(SymbolHashMap *symmap, SymbolHashMap *classmap); 1.867 + 1.868 + // Copy cpool bytes into byte array. 1.869 + // Returns: 1.870 + // int > 0, count of the raw cpool bytes that have been copied 1.871 + // 0, OutOfMemory error 1.872 + // -1, Internal error 1.873 + int copy_cpool_bytes(int cpool_size, 1.874 + SymbolHashMap* tbl, 1.875 + unsigned char *bytes); 1.876 + 1.877 + public: 1.878 + // Verify 1.879 + void verify_on(outputStream* st); 1.880 + 1.881 + // Printing 1.882 + void print_on(outputStream* st) const; 1.883 + void print_value_on(outputStream* st) const; 1.884 + void print_entry_on(int index, outputStream* st); 1.885 + 1.886 + const char* internal_name() const { return "{constant pool}"; } 1.887 + 1.888 +#ifndef PRODUCT 1.889 + // Compile the world support 1.890 + static void preload_and_initialize_all_classes(ConstantPool* constant_pool, TRAPS); 1.891 +#endif 1.892 +}; 1.893 + 1.894 +class SymbolHashMapEntry : public CHeapObj<mtSymbol> { 1.895 + private: 1.896 + unsigned int _hash; // 32-bit hash for item 1.897 + SymbolHashMapEntry* _next; // Next element in the linked list for this bucket 1.898 + Symbol* _symbol; // 1-st part of the mapping: symbol => value 1.899 + u2 _value; // 2-nd part of the mapping: symbol => value 1.900 + 1.901 + public: 1.902 + unsigned int hash() const { return _hash; } 1.903 + void set_hash(unsigned int hash) { _hash = hash; } 1.904 + 1.905 + SymbolHashMapEntry* next() const { return _next; } 1.906 + void set_next(SymbolHashMapEntry* next) { _next = next; } 1.907 + 1.908 + Symbol* symbol() const { return _symbol; } 1.909 + void set_symbol(Symbol* sym) { _symbol = sym; } 1.910 + 1.911 + u2 value() const { return _value; } 1.912 + void set_value(u2 value) { _value = value; } 1.913 + 1.914 + SymbolHashMapEntry(unsigned int hash, Symbol* symbol, u2 value) 1.915 + : _hash(hash), _symbol(symbol), _value(value), _next(NULL) {} 1.916 + 1.917 +}; // End SymbolHashMapEntry class 1.918 + 1.919 + 1.920 +class SymbolHashMapBucket : public CHeapObj<mtSymbol> { 1.921 + 1.922 +private: 1.923 + SymbolHashMapEntry* _entry; 1.924 + 1.925 +public: 1.926 + SymbolHashMapEntry* entry() const { return _entry; } 1.927 + void set_entry(SymbolHashMapEntry* entry) { _entry = entry; } 1.928 + void clear() { _entry = NULL; } 1.929 + 1.930 +}; // End SymbolHashMapBucket class 1.931 + 1.932 + 1.933 +class SymbolHashMap: public CHeapObj<mtSymbol> { 1.934 + 1.935 + private: 1.936 + // Default number of entries in the table 1.937 + enum SymbolHashMap_Constants { 1.938 + _Def_HashMap_Size = 256 1.939 + }; 1.940 + 1.941 + int _table_size; 1.942 + SymbolHashMapBucket* _buckets; 1.943 + 1.944 + void initialize_table(int table_size) { 1.945 + _table_size = table_size; 1.946 + _buckets = NEW_C_HEAP_ARRAY(SymbolHashMapBucket, table_size, mtSymbol); 1.947 + for (int index = 0; index < table_size; index++) { 1.948 + _buckets[index].clear(); 1.949 + } 1.950 + } 1.951 + 1.952 + public: 1.953 + 1.954 + int table_size() const { return _table_size; } 1.955 + 1.956 + SymbolHashMap() { initialize_table(_Def_HashMap_Size); } 1.957 + SymbolHashMap(int table_size) { initialize_table(table_size); } 1.958 + 1.959 + // hash P(31) from Kernighan & Ritchie 1.960 + static unsigned int compute_hash(const char* str, int len) { 1.961 + unsigned int hash = 0; 1.962 + while (len-- > 0) { 1.963 + hash = 31*hash + (unsigned) *str; 1.964 + str++; 1.965 + } 1.966 + return hash; 1.967 + } 1.968 + 1.969 + SymbolHashMapEntry* bucket(int i) { 1.970 + return _buckets[i].entry(); 1.971 + } 1.972 + 1.973 + void add_entry(Symbol* sym, u2 value); 1.974 + SymbolHashMapEntry* find_entry(Symbol* sym); 1.975 + 1.976 + u2 symbol_to_value(Symbol* sym) { 1.977 + SymbolHashMapEntry *entry = find_entry(sym); 1.978 + return (entry == NULL) ? 0 : entry->value(); 1.979 + } 1.980 + 1.981 + ~SymbolHashMap() { 1.982 + SymbolHashMapEntry* next; 1.983 + for (int i = 0; i < _table_size; i++) { 1.984 + for (SymbolHashMapEntry* cur = bucket(i); cur != NULL; cur = next) { 1.985 + next = cur->next(); 1.986 + delete(cur); 1.987 + } 1.988 + } 1.989 + delete _buckets; 1.990 + } 1.991 +}; // End SymbolHashMap class 1.992 + 1.993 +#endif // SHARE_VM_OOPS_CONSTANTPOOLOOP_HPP