src/share/vm/oops/constantPool.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/constantPool.cpp

Print this page




 795 
 796   return info();
 797 }
 798 
 799 oop ConstantPool::string_at_impl(constantPoolHandle this_cp, int which, int obj_index, TRAPS) {
 800   // If the string has already been interned, this entry will be non-null
 801   oop str = this_cp->resolved_references()->obj_at(obj_index);
 802   if (str != NULL) return str;
 803   Symbol* sym = this_cp->unresolved_string_at(which);
 804   str = StringTable::intern(sym, CHECK_(NULL));
 805   this_cp->string_at_put(which, obj_index, str);
 806   assert(java_lang_String::is_instance(str), "must be string");
 807   return str;
 808 }
 809 
 810 
 811 bool ConstantPool::klass_name_at_matches(instanceKlassHandle k,
 812                                                 int which) {
 813   // Names are interned, so we can compare Symbol*s directly
 814   Symbol* cp_name = klass_name_at(which);
 815   return (cp_name == k->name());
 816 }
 817 
 818 
 819 // Iterate over symbols and decrement ones which are Symbol*s
 820 // This is done during GC.
 821 // Only decrement the UTF8 symbols. Unresolved classes and strings point to
 822 // these symbols but didn't increment the reference count.
 823 void ConstantPool::unreference_symbols() {
 824   for (int index = 1; index < length(); index++) { // Index 0 is unused
 825     constantTag tag = tag_at(index);
 826     if (tag.is_symbol()) {
 827       symbol_at(index)->decrement_refcount();
 828     }
 829   }
 830 }
 831 
 832 
 833 // Compare this constant pool's entry at index1 to the constant pool
 834 // cp2's entry at index2.
 835 bool ConstantPool::compare_entry_to(int index1, constantPoolHandle cp2,


 934       if (match) {
 935         return true;
 936       }
 937     }
 938   } break;
 939 
 940   case JVM_CONSTANT_StringIndex:
 941   {
 942     int recur1 = string_index_at(index1);
 943     int recur2 = cp2->string_index_at(index2);
 944     bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
 945     if (match) {
 946       return true;
 947     }
 948   } break;
 949 
 950   case JVM_CONSTANT_UnresolvedClass:
 951   {
 952     Symbol* k1 = klass_name_at(index1);
 953     Symbol* k2 = cp2->klass_name_at(index2);
 954     if (k1 == k2) {
 955       return true;
 956     }
 957   } break;
 958 
 959   case JVM_CONSTANT_MethodType:
 960   {
 961     int k1 = method_type_index_at_error_ok(index1);
 962     int k2 = cp2->method_type_index_at_error_ok(index2);
 963     bool match = compare_entry_to(k1, cp2, k2, CHECK_false);
 964     if (match) {
 965       return true;
 966     }
 967   } break;
 968 
 969   case JVM_CONSTANT_MethodHandle:
 970   {
 971     int k1 = method_handle_ref_kind_at_error_ok(index1);
 972     int k2 = cp2->method_handle_ref_kind_at_error_ok(index2);
 973     if (k1 == k2) {
 974       int i1 = method_handle_index_at_error_ok(index1);


 979       }
 980     }
 981   } break;
 982 
 983   case JVM_CONSTANT_InvokeDynamic:
 984   {
 985     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
 986     int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
 987     int i1 = invoke_dynamic_bootstrap_specifier_index(index1);
 988     int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2);
 989     // separate statements and variables because CHECK_false is used
 990     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
 991     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
 992     return (match_entry && match_operand);
 993   } break;
 994 
 995   case JVM_CONSTANT_String:
 996   {
 997     Symbol* s1 = unresolved_string_at(index1);
 998     Symbol* s2 = cp2->unresolved_string_at(index2);
 999     if (s1 == s2) {
1000       return true;
1001     }
1002   } break;
1003 
1004   case JVM_CONSTANT_Utf8:
1005   {
1006     Symbol* s1 = symbol_at(index1);
1007     Symbol* s2 = cp2->symbol_at(index2);
1008     if (s1 == s2) {
1009       return true;
1010     }
1011   } break;
1012 
1013   // Invalid is used as the tag for the second constant pool entry
1014   // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
1015   // not be seen by itself.
1016   case JVM_CONSTANT_Invalid: // fall through
1017 
1018   default:
1019     ShouldNotReachHere();
1020     break;
1021   }
1022 
1023   return false;
1024 } // end compare_entry_to()
1025 
1026 
1027 // Resize the operands array with delta_len and delta_size.
1028 // Used in RedefineClasses for CP merge.


2033     guarantee(cache()->is_constantPoolCache(), "should be constant pool cache");
2034   }
2035   if (pool_holder() != NULL) {
2036     // Note: pool_holder() can be NULL in temporary constant pools
2037     // used during constant pool merging
2038     guarantee(pool_holder()->is_klass(),    "should be klass");
2039   }
2040 }
2041 
2042 
2043 void SymbolHashMap::add_entry(Symbol* sym, u2 value) {
2044   char *str = sym->as_utf8();
2045   unsigned int hash = compute_hash(str, sym->utf8_length());
2046   unsigned int index = hash % table_size();
2047 
2048   // check if already in map
2049   // we prefer the first entry since it is more likely to be what was used in
2050   // the class file
2051   for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
2052     assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
2053     if (en->hash() == hash && en->symbol() == sym) {
2054         return;  // already there
2055     }
2056   }
2057 
2058   SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
2059   entry->set_next(bucket(index));
2060   _buckets[index].set_entry(entry);
2061   assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
2062 }
2063 
2064 SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) {
2065   assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
2066   char *str = sym->as_utf8();
2067   int   len = sym->utf8_length();
2068   unsigned int hash = SymbolHashMap::compute_hash(str, len);
2069   unsigned int index = hash % table_size();
2070   for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
2071     assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
2072     if (en->hash() == hash && en->symbol() == sym) {
2073       return en;
2074     }
2075   }
2076   return NULL;
2077 }


 795 
 796   return info();
 797 }
 798 
 799 oop ConstantPool::string_at_impl(constantPoolHandle this_cp, int which, int obj_index, TRAPS) {
 800   // If the string has already been interned, this entry will be non-null
 801   oop str = this_cp->resolved_references()->obj_at(obj_index);
 802   if (str != NULL) return str;
 803   Symbol* sym = this_cp->unresolved_string_at(which);
 804   str = StringTable::intern(sym, CHECK_(NULL));
 805   this_cp->string_at_put(which, obj_index, str);
 806   assert(java_lang_String::is_instance(str), "must be string");
 807   return str;
 808 }
 809 
 810 
 811 bool ConstantPool::klass_name_at_matches(instanceKlassHandle k,
 812                                                 int which) {
 813   // Names are interned, so we can compare Symbol*s directly
 814   Symbol* cp_name = klass_name_at(which);
 815   return (cp_name->equals(k->name()));
 816 }
 817 
 818 
 819 // Iterate over symbols and decrement ones which are Symbol*s
 820 // This is done during GC.
 821 // Only decrement the UTF8 symbols. Unresolved classes and strings point to
 822 // these symbols but didn't increment the reference count.
 823 void ConstantPool::unreference_symbols() {
 824   for (int index = 1; index < length(); index++) { // Index 0 is unused
 825     constantTag tag = tag_at(index);
 826     if (tag.is_symbol()) {
 827       symbol_at(index)->decrement_refcount();
 828     }
 829   }
 830 }
 831 
 832 
 833 // Compare this constant pool's entry at index1 to the constant pool
 834 // cp2's entry at index2.
 835 bool ConstantPool::compare_entry_to(int index1, constantPoolHandle cp2,


 934       if (match) {
 935         return true;
 936       }
 937     }
 938   } break;
 939 
 940   case JVM_CONSTANT_StringIndex:
 941   {
 942     int recur1 = string_index_at(index1);
 943     int recur2 = cp2->string_index_at(index2);
 944     bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
 945     if (match) {
 946       return true;
 947     }
 948   } break;
 949 
 950   case JVM_CONSTANT_UnresolvedClass:
 951   {
 952     Symbol* k1 = klass_name_at(index1);
 953     Symbol* k2 = cp2->klass_name_at(index2);
 954     if (k1->equals(k2)) {
 955       return true;
 956     }
 957   } break;
 958 
 959   case JVM_CONSTANT_MethodType:
 960   {
 961     int k1 = method_type_index_at_error_ok(index1);
 962     int k2 = cp2->method_type_index_at_error_ok(index2);
 963     bool match = compare_entry_to(k1, cp2, k2, CHECK_false);
 964     if (match) {
 965       return true;
 966     }
 967   } break;
 968 
 969   case JVM_CONSTANT_MethodHandle:
 970   {
 971     int k1 = method_handle_ref_kind_at_error_ok(index1);
 972     int k2 = cp2->method_handle_ref_kind_at_error_ok(index2);
 973     if (k1 == k2) {
 974       int i1 = method_handle_index_at_error_ok(index1);


 979       }
 980     }
 981   } break;
 982 
 983   case JVM_CONSTANT_InvokeDynamic:
 984   {
 985     int k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
 986     int k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
 987     int i1 = invoke_dynamic_bootstrap_specifier_index(index1);
 988     int i2 = cp2->invoke_dynamic_bootstrap_specifier_index(index2);
 989     // separate statements and variables because CHECK_false is used
 990     bool match_entry = compare_entry_to(k1, cp2, k2, CHECK_false);
 991     bool match_operand = compare_operand_to(i1, cp2, i2, CHECK_false);
 992     return (match_entry && match_operand);
 993   } break;
 994 
 995   case JVM_CONSTANT_String:
 996   {
 997     Symbol* s1 = unresolved_string_at(index1);
 998     Symbol* s2 = cp2->unresolved_string_at(index2);
 999     if (s1->equals(s2)) {
1000       return true;
1001     }
1002   } break;
1003 
1004   case JVM_CONSTANT_Utf8:
1005   {
1006     Symbol* s1 = symbol_at(index1);
1007     Symbol* s2 = cp2->symbol_at(index2);
1008     if (s1->equals(s2)) {
1009       return true;
1010     }
1011   } break;
1012 
1013   // Invalid is used as the tag for the second constant pool entry
1014   // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
1015   // not be seen by itself.
1016   case JVM_CONSTANT_Invalid: // fall through
1017 
1018   default:
1019     ShouldNotReachHere();
1020     break;
1021   }
1022 
1023   return false;
1024 } // end compare_entry_to()
1025 
1026 
1027 // Resize the operands array with delta_len and delta_size.
1028 // Used in RedefineClasses for CP merge.


2033     guarantee(cache()->is_constantPoolCache(), "should be constant pool cache");
2034   }
2035   if (pool_holder() != NULL) {
2036     // Note: pool_holder() can be NULL in temporary constant pools
2037     // used during constant pool merging
2038     guarantee(pool_holder()->is_klass(),    "should be klass");
2039   }
2040 }
2041 
2042 
2043 void SymbolHashMap::add_entry(Symbol* sym, u2 value) {
2044   char *str = sym->as_utf8();
2045   unsigned int hash = compute_hash(str, sym->utf8_length());
2046   unsigned int index = hash % table_size();
2047 
2048   // check if already in map
2049   // we prefer the first entry since it is more likely to be what was used in
2050   // the class file
2051   for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
2052     assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
2053     if (en->hash() == hash && en->symbol()->equals(sym)) {
2054         return;  // already there
2055     }
2056   }
2057 
2058   SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
2059   entry->set_next(bucket(index));
2060   _buckets[index].set_entry(entry);
2061   assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
2062 }
2063 
2064 SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) {
2065   assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
2066   char *str = sym->as_utf8();
2067   int   len = sym->utf8_length();
2068   unsigned int hash = SymbolHashMap::compute_hash(str, len);
2069   unsigned int index = hash % table_size();
2070   for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
2071     assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
2072     if (en->hash() == hash && en->symbol()->equals(sym)) {
2073       return en;
2074     }
2075   }
2076   return NULL;
2077 }
src/share/vm/oops/constantPool.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File