< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page
rev 49275 : [mq]: JDK-8199781.patch


 824 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
 825                                            int index, int cache_index,
 826                                            bool* status_return, TRAPS) {
 827   oop result_oop = NULL;
 828   Handle throw_exception;
 829 
 830   if (cache_index == _possible_index_sentinel) {
 831     // It is possible that this constant is one which is cached in the objects.
 832     // We'll do a linear search.  This should be OK because this usage is rare.
 833     // FIXME: If bootstrap specifiers stress this code, consider putting in
 834     // a reverse index.  Binary search over a short array should do it.
 835     assert(index > 0, "valid index");
 836     cache_index = this_cp->cp_to_object_index(index);
 837   }
 838   assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
 839   assert(index == _no_index_sentinel || index >= 0, "");
 840 
 841   if (cache_index >= 0) {
 842     result_oop = this_cp->resolved_references()->obj_at(cache_index);
 843     if (result_oop != NULL) {
 844       if (result_oop == Universe::the_null_sentinel()) {
 845         DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
 846         assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
 847         result_oop = NULL;
 848       }
 849       if (status_return != NULL)  (*status_return) = true;
 850       return result_oop;
 851       // That was easy...
 852     }
 853     index = this_cp->object_to_cp_index(cache_index);
 854   }
 855 
 856   jvalue prim_value;  // temp used only in a few cases below
 857 
 858   constantTag tag = this_cp->tag_at(index);
 859 
 860   if (status_return != NULL) {
 861     // don't trigger resolution if the constant might need it
 862     switch (tag.value()) {
 863     case JVM_CONSTANT_Class:
 864     {


1057   default:
1058     DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
1059                               this_cp(), index, cache_index, tag.value()));
1060     assert(false, "unexpected constant tag");
1061     break;
1062   }
1063 
1064   if (cache_index >= 0) {
1065     // Benign race condition:  resolved_references may already be filled in.
1066     // The important thing here is that all threads pick up the same result.
1067     // It doesn't matter which racing thread wins, as long as only one
1068     // result is used by all threads, and all future queries.
1069     oop new_result = (result_oop == NULL ? Universe::the_null_sentinel() : result_oop);
1070     oop old_result = this_cp->resolved_references()
1071       ->atomic_compare_exchange_oop(cache_index, new_result, NULL);
1072     if (old_result == NULL) {
1073       return result_oop;  // was installed
1074     } else {
1075       // Return the winning thread's result.  This can be different than
1076       // the result here for MethodHandles.
1077       if (old_result == Universe::the_null_sentinel())
1078         old_result = NULL;
1079       return old_result;
1080     }
1081   } else {
1082     assert(result_oop != Universe::the_null_sentinel(), "");
1083     return result_oop;
1084   }
1085 }
1086 
1087 oop ConstantPool::uncached_string_at(int which, TRAPS) {
1088   Symbol* sym = unresolved_string_at(which);
1089   oop str = StringTable::intern(sym, CHECK_(NULL));
1090   assert(java_lang_String::is_instance(str), "must be string");
1091   return str;
1092 }
1093 
1094 
1095 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
1096   assert((this_cp->tag_at(index).is_invoke_dynamic() ||
1097           this_cp->tag_at(index).is_dynamic_constant()), "Corrupted constant pool");
1098   Handle bsm;
1099   int argc;
1100   {
1101     // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments
1102     // JVM_CONSTANT_Dynamic is an ordered pair of [bootm, name&ftype], plus optional arguments


1228   }
1229   // now we can loop safely
1230   int info_i = pos;
1231   for (int i = start_arg; i < end_arg; i++) {
1232     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1233     oop arg_oop;
1234     if (must_resolve) {
1235       arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
1236     } else {
1237       bool found_it = false;
1238       arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
1239       if (!found_it)  arg_oop = if_not_available();
1240     }
1241     info->obj_at_put(info_i++, arg_oop);
1242   }
1243 }
1244 
1245 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1246   // If the string has already been interned, this entry will be non-null
1247   oop str = this_cp->resolved_references()->obj_at(obj_index);
1248   assert(str != Universe::the_null_sentinel(), "");
1249   if (str != NULL) return str;
1250   Symbol* sym = this_cp->unresolved_string_at(which);
1251   str = StringTable::intern(sym, CHECK_(NULL));
1252   this_cp->string_at_put(which, obj_index, str);
1253   assert(java_lang_String::is_instance(str), "must be string");
1254   return str;
1255 }
1256 
1257 
1258 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
1259   // Names are interned, so we can compare Symbol*s directly
1260   Symbol* cp_name = klass_name_at(which);
1261   return (cp_name == k->name());
1262 }
1263 
1264 
1265 // Iterate over symbols and decrement ones which are Symbol*s
1266 // This is done during GC.
1267 // Only decrement the UTF8 symbols. Strings point to
1268 // these symbols but didn't increment the reference count.




 824 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
 825                                            int index, int cache_index,
 826                                            bool* status_return, TRAPS) {
 827   oop result_oop = NULL;
 828   Handle throw_exception;
 829 
 830   if (cache_index == _possible_index_sentinel) {
 831     // It is possible that this constant is one which is cached in the objects.
 832     // We'll do a linear search.  This should be OK because this usage is rare.
 833     // FIXME: If bootstrap specifiers stress this code, consider putting in
 834     // a reverse index.  Binary search over a short array should do it.
 835     assert(index > 0, "valid index");
 836     cache_index = this_cp->cp_to_object_index(index);
 837   }
 838   assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
 839   assert(index == _no_index_sentinel || index >= 0, "");
 840 
 841   if (cache_index >= 0) {
 842     result_oop = this_cp->resolved_references()->obj_at(cache_index);
 843     if (result_oop != NULL) {
 844       if (oopDesc::equals(result_oop, Universe::the_null_sentinel())) {
 845         DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
 846         assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
 847         result_oop = NULL;
 848       }
 849       if (status_return != NULL)  (*status_return) = true;
 850       return result_oop;
 851       // That was easy...
 852     }
 853     index = this_cp->object_to_cp_index(cache_index);
 854   }
 855 
 856   jvalue prim_value;  // temp used only in a few cases below
 857 
 858   constantTag tag = this_cp->tag_at(index);
 859 
 860   if (status_return != NULL) {
 861     // don't trigger resolution if the constant might need it
 862     switch (tag.value()) {
 863     case JVM_CONSTANT_Class:
 864     {


1057   default:
1058     DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
1059                               this_cp(), index, cache_index, tag.value()));
1060     assert(false, "unexpected constant tag");
1061     break;
1062   }
1063 
1064   if (cache_index >= 0) {
1065     // Benign race condition:  resolved_references may already be filled in.
1066     // The important thing here is that all threads pick up the same result.
1067     // It doesn't matter which racing thread wins, as long as only one
1068     // result is used by all threads, and all future queries.
1069     oop new_result = (result_oop == NULL ? Universe::the_null_sentinel() : result_oop);
1070     oop old_result = this_cp->resolved_references()
1071       ->atomic_compare_exchange_oop(cache_index, new_result, NULL);
1072     if (old_result == NULL) {
1073       return result_oop;  // was installed
1074     } else {
1075       // Return the winning thread's result.  This can be different than
1076       // the result here for MethodHandles.
1077       if (oopDesc::equals(old_result, Universe::the_null_sentinel()))
1078         old_result = NULL;
1079       return old_result;
1080     }
1081   } else {
1082     assert(!oopDesc::equals(result_oop, Universe::the_null_sentinel()), "");
1083     return result_oop;
1084   }
1085 }
1086 
1087 oop ConstantPool::uncached_string_at(int which, TRAPS) {
1088   Symbol* sym = unresolved_string_at(which);
1089   oop str = StringTable::intern(sym, CHECK_(NULL));
1090   assert(java_lang_String::is_instance(str), "must be string");
1091   return str;
1092 }
1093 
1094 
1095 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
1096   assert((this_cp->tag_at(index).is_invoke_dynamic() ||
1097           this_cp->tag_at(index).is_dynamic_constant()), "Corrupted constant pool");
1098   Handle bsm;
1099   int argc;
1100   {
1101     // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments
1102     // JVM_CONSTANT_Dynamic is an ordered pair of [bootm, name&ftype], plus optional arguments


1228   }
1229   // now we can loop safely
1230   int info_i = pos;
1231   for (int i = start_arg; i < end_arg; i++) {
1232     int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1233     oop arg_oop;
1234     if (must_resolve) {
1235       arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
1236     } else {
1237       bool found_it = false;
1238       arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
1239       if (!found_it)  arg_oop = if_not_available();
1240     }
1241     info->obj_at_put(info_i++, arg_oop);
1242   }
1243 }
1244 
1245 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1246   // If the string has already been interned, this entry will be non-null
1247   oop str = this_cp->resolved_references()->obj_at(obj_index);
1248   assert(!oopDesc::equals(str, Universe::the_null_sentinel()), "");
1249   if (str != NULL) return str;
1250   Symbol* sym = this_cp->unresolved_string_at(which);
1251   str = StringTable::intern(sym, CHECK_(NULL));
1252   this_cp->string_at_put(which, obj_index, str);
1253   assert(java_lang_String::is_instance(str), "must be string");
1254   return str;
1255 }
1256 
1257 
1258 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
1259   // Names are interned, so we can compare Symbol*s directly
1260   Symbol* cp_name = klass_name_at(which);
1261   return (cp_name == k->name());
1262 }
1263 
1264 
1265 // Iterate over symbols and decrement ones which are Symbol*s
1266 // This is done during GC.
1267 // Only decrement the UTF8 symbols. Strings point to
1268 // these symbols but didn't increment the reference count.


< prev index next >