823 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
824 int index, int cache_index,
825 bool* status_return, TRAPS) {
826 oop result_oop = NULL;
827 Handle throw_exception;
828
829 if (cache_index == _possible_index_sentinel) {
830 // It is possible that this constant is one which is cached in the objects.
831 // We'll do a linear search. This should be OK because this usage is rare.
832 // FIXME: If bootstrap specifiers stress this code, consider putting in
833 // a reverse index. Binary search over a short array should do it.
834 assert(index > 0, "valid index");
835 cache_index = this_cp->cp_to_object_index(index);
836 }
837 assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
838 assert(index == _no_index_sentinel || index >= 0, "");
839
840 if (cache_index >= 0) {
841 result_oop = this_cp->resolved_references()->obj_at(cache_index);
842 if (result_oop != NULL) {
843 if (result_oop == Universe::the_null_sentinel()) {
844 DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
845 assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
846 result_oop = NULL;
847 }
848 if (status_return != NULL) (*status_return) = true;
849 return result_oop;
850 // That was easy...
851 }
852 index = this_cp->object_to_cp_index(cache_index);
853 }
854
855 jvalue prim_value; // temp used only in a few cases below
856
857 constantTag tag = this_cp->tag_at(index);
858
859 if (status_return != NULL) {
860 // don't trigger resolution if the constant might need it
861 switch (tag.value()) {
862 case JVM_CONSTANT_Class:
|
823 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
824 int index, int cache_index,
825 bool* status_return, TRAPS) {
826 oop result_oop = NULL;
827 Handle throw_exception;
828
829 if (cache_index == _possible_index_sentinel) {
830 // It is possible that this constant is one which is cached in the objects.
831 // We'll do a linear search. This should be OK because this usage is rare.
832 // FIXME: If bootstrap specifiers stress this code, consider putting in
833 // a reverse index. Binary search over a short array should do it.
834 assert(index > 0, "valid index");
835 cache_index = this_cp->cp_to_object_index(index);
836 }
837 assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
838 assert(index == _no_index_sentinel || index >= 0, "");
839
840 if (cache_index >= 0) {
841 result_oop = this_cp->resolved_references()->obj_at(cache_index);
842 if (result_oop != NULL) {
843 if (oopDesc::equals(result_oop, Universe::the_null_sentinel())) {
844 DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
845 assert(this_cp->tag_at(temp_index).is_dynamic_constant(), "only condy uses the null sentinel");
846 result_oop = NULL;
847 }
848 if (status_return != NULL) (*status_return) = true;
849 return result_oop;
850 // That was easy...
851 }
852 index = this_cp->object_to_cp_index(cache_index);
853 }
854
855 jvalue prim_value; // temp used only in a few cases below
856
857 constantTag tag = this_cp->tag_at(index);
858
859 if (status_return != NULL) {
860 // don't trigger resolution if the constant might need it
861 switch (tag.value()) {
862 case JVM_CONSTANT_Class:
|
1056 default:
1057 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
1058 this_cp(), index, cache_index, tag.value()));
1059 assert(false, "unexpected constant tag");
1060 break;
1061 }
1062
1063 if (cache_index >= 0) {
1064 // Benign race condition: resolved_references may already be filled in.
1065 // The important thing here is that all threads pick up the same result.
1066 // It doesn't matter which racing thread wins, as long as only one
1067 // result is used by all threads, and all future queries.
1068 oop new_result = (result_oop == NULL ? Universe::the_null_sentinel() : result_oop);
1069 oop old_result = this_cp->resolved_references()
1070 ->atomic_compare_exchange_oop(cache_index, new_result, NULL);
1071 if (old_result == NULL) {
1072 return result_oop; // was installed
1073 } else {
1074 // Return the winning thread's result. This can be different than
1075 // the result here for MethodHandles.
1076 if (old_result == Universe::the_null_sentinel())
1077 old_result = NULL;
1078 return old_result;
1079 }
1080 } else {
1081 assert(result_oop != Universe::the_null_sentinel(), "");
1082 return result_oop;
1083 }
1084 }
1085
1086 oop ConstantPool::uncached_string_at(int which, TRAPS) {
1087 Symbol* sym = unresolved_string_at(which);
1088 oop str = StringTable::intern(sym, CHECK_(NULL));
1089 assert(java_lang_String::is_instance(str), "must be string");
1090 return str;
1091 }
1092
1093
1094 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
1095 assert((this_cp->tag_at(index).is_invoke_dynamic() ||
1096 this_cp->tag_at(index).is_dynamic_constant()), "Corrupted constant pool");
1097 Handle bsm;
1098 int argc;
1099 {
1100 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments
|
1056 default:
1057 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
1058 this_cp(), index, cache_index, tag.value()));
1059 assert(false, "unexpected constant tag");
1060 break;
1061 }
1062
1063 if (cache_index >= 0) {
1064 // Benign race condition: resolved_references may already be filled in.
1065 // The important thing here is that all threads pick up the same result.
1066 // It doesn't matter which racing thread wins, as long as only one
1067 // result is used by all threads, and all future queries.
1068 oop new_result = (result_oop == NULL ? Universe::the_null_sentinel() : result_oop);
1069 oop old_result = this_cp->resolved_references()
1070 ->atomic_compare_exchange_oop(cache_index, new_result, NULL);
1071 if (old_result == NULL) {
1072 return result_oop; // was installed
1073 } else {
1074 // Return the winning thread's result. This can be different than
1075 // the result here for MethodHandles.
1076 if (oopDesc::equals(old_result, Universe::the_null_sentinel()))
1077 old_result = NULL;
1078 return old_result;
1079 }
1080 } else {
1081 assert(!oopDesc::equals(result_oop, Universe::the_null_sentinel()), "");
1082 return result_oop;
1083 }
1084 }
1085
1086 oop ConstantPool::uncached_string_at(int which, TRAPS) {
1087 Symbol* sym = unresolved_string_at(which);
1088 oop str = StringTable::intern(sym, CHECK_(NULL));
1089 assert(java_lang_String::is_instance(str), "must be string");
1090 return str;
1091 }
1092
1093
1094 oop ConstantPool::resolve_bootstrap_specifier_at_impl(const constantPoolHandle& this_cp, int index, TRAPS) {
1095 assert((this_cp->tag_at(index).is_invoke_dynamic() ||
1096 this_cp->tag_at(index).is_dynamic_constant()), "Corrupted constant pool");
1097 Handle bsm;
1098 int argc;
1099 {
1100 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&mtype], plus optional arguments
|
1227 }
1228 // now we can loop safely
1229 int info_i = pos;
1230 for (int i = start_arg; i < end_arg; i++) {
1231 int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1232 oop arg_oop;
1233 if (must_resolve) {
1234 arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
1235 } else {
1236 bool found_it = false;
1237 arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
1238 if (!found_it) arg_oop = if_not_available();
1239 }
1240 info->obj_at_put(info_i++, arg_oop);
1241 }
1242 }
1243
1244 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1245 // If the string has already been interned, this entry will be non-null
1246 oop str = this_cp->resolved_references()->obj_at(obj_index);
1247 assert(str != Universe::the_null_sentinel(), "");
1248 if (str != NULL) return str;
1249 Symbol* sym = this_cp->unresolved_string_at(which);
1250 str = StringTable::intern(sym, CHECK_(NULL));
1251 this_cp->string_at_put(which, obj_index, str);
1252 assert(java_lang_String::is_instance(str), "must be string");
1253 return str;
1254 }
1255
1256
1257 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
1258 // Names are interned, so we can compare Symbol*s directly
1259 Symbol* cp_name = klass_name_at(which);
1260 return (cp_name == k->name());
1261 }
1262
1263
1264 // Iterate over symbols and decrement ones which are Symbol*s
1265 // This is done during GC.
1266 // Only decrement the UTF8 symbols. Strings point to
|
1227 }
1228 // now we can loop safely
1229 int info_i = pos;
1230 for (int i = start_arg; i < end_arg; i++) {
1231 int arg_index = this_cp->invoke_dynamic_argument_index_at(index, i);
1232 oop arg_oop;
1233 if (must_resolve) {
1234 arg_oop = this_cp->resolve_possibly_cached_constant_at(arg_index, CHECK);
1235 } else {
1236 bool found_it = false;
1237 arg_oop = this_cp->find_cached_constant_at(arg_index, found_it, CHECK);
1238 if (!found_it) arg_oop = if_not_available();
1239 }
1240 info->obj_at_put(info_i++, arg_oop);
1241 }
1242 }
1243
1244 oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1245 // If the string has already been interned, this entry will be non-null
1246 oop str = this_cp->resolved_references()->obj_at(obj_index);
1247 assert(!oopDesc::equals(str, Universe::the_null_sentinel()), "");
1248 if (str != NULL) return str;
1249 Symbol* sym = this_cp->unresolved_string_at(which);
1250 str = StringTable::intern(sym, CHECK_(NULL));
1251 this_cp->string_at_put(which, obj_index, str);
1252 assert(java_lang_String::is_instance(str), "must be string");
1253 return str;
1254 }
1255
1256
1257 bool ConstantPool::klass_name_at_matches(const InstanceKlass* k, int which) {
1258 // Names are interned, so we can compare Symbol*s directly
1259 Symbol* cp_name = klass_name_at(which);
1260 return (cp_name == k->name());
1261 }
1262
1263
1264 // Iterate over symbols and decrement ones which are Symbol*s
1265 // This is done during GC.
1266 // Only decrement the UTF8 symbols. Strings point to
|