src/share/vm/oops/constantPool.hpp

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

mercurial