1
1
/*
2
- * Copyright (c) 1997, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1997, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -158,7 +158,7 @@ void ConstantPool::metaspace_pointers_do(MetaspaceClosure* it) {
158
158
}
159
159
160
160
objArrayOop ConstantPool::resolved_references () const {
161
- return (objArrayOop) _cache->resolved_references ();
161
+ return _cache->resolved_references ();
162
162
}
163
163
164
164
// Called from outside constant pool resolution where a resolved_reference array
@@ -167,10 +167,22 @@ objArrayOop ConstantPool::resolved_references_or_null() const {
167
167
if (_cache == NULL ) {
168
168
return NULL ;
169
169
} else {
170
- return (objArrayOop) _cache->resolved_references ();
170
+ return _cache->resolved_references ();
171
171
}
172
172
}
173
173
174
+ oop ConstantPool::resolved_reference_at (int index) const {
175
+ oop result = resolved_references ()->obj_at (index );
176
+ assert (oopDesc::is_oop_or_null (result), " Must be oop" );
177
+ return result;
178
+ }
179
+
180
+ // Use a CAS for multithreaded access
181
+ oop ConstantPool::set_resolved_reference_at (int index, oop new_result) {
182
+ assert (oopDesc::is_oop_or_null (new_result), " Must be oop" );
183
+ return resolved_references ()->replace_if_null (index , new_result);
184
+ }
185
+
174
186
// Create resolved_references array and mapping array for original cp indexes
175
187
// The ldc bytecode was rewritten to have the resolved reference array index so need a way
176
188
// to map it back for resolving and some unlikely miscellaneous uses.
@@ -446,7 +458,8 @@ int ConstantPool::cp_to_object_index(int cp_index) {
446
458
}
447
459
448
460
void ConstantPool::string_at_put (int which, int obj_index, oop str) {
449
- resolved_references ()->obj_at_put (obj_index, str);
461
+ oop result = set_resolved_reference_at (obj_index, str);
462
+ assert (result == nullptr || result == str, " Only set once or to the same string." );
450
463
}
451
464
452
465
void ConstantPool::trace_class_resolution (const constantPoolHandle& this_cp, Klass* k) {
@@ -936,7 +949,7 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
936
949
assert (index == _no_index_sentinel || index >= 0 , " " );
937
950
938
951
if (cache_index >= 0 ) {
939
- result_oop = this_cp->resolved_references ()-> obj_at (cache_index);
952
+ result_oop = this_cp->resolved_reference_at (cache_index);
940
953
if (result_oop != NULL ) {
941
954
if (result_oop == Universe::the_null_sentinel ()) {
942
955
DEBUG_ONLY (int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index (cache_index)));
@@ -1159,9 +1172,8 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
1159
1172
// It doesn't matter which racing thread wins, as long as only one
1160
1173
// result is used by all threads, and all future queries.
1161
1174
oop new_result = (result_oop == NULL ? Universe::the_null_sentinel () : result_oop);
1162
- oop old_result = this_cp->resolved_references ()
1163
- ->atomic_compare_exchange_oop (cache_index, new_result, NULL );
1164
- if (old_result == NULL ) {
1175
+ oop old_result = this_cp->set_resolved_reference_at (cache_index, new_result);
1176
+ if (old_result == nullptr ) {
1165
1177
return result_oop; // was installed
1166
1178
} else {
1167
1179
// Return the winning thread's result. This can be different than
@@ -1222,7 +1234,7 @@ void ConstantPool::copy_bootstrap_arguments_at_impl(const constantPoolHandle& th
1222
1234
1223
1235
oop ConstantPool::string_at_impl (const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
1224
1236
// If the string has already been interned, this entry will be non-null
1225
- oop str = this_cp->resolved_references ()-> obj_at (obj_index);
1237
+ oop str = this_cp->resolved_reference_at (obj_index);
1226
1238
assert (str != Universe::the_null_sentinel (), " " );
1227
1239
if (str != NULL ) return str;
1228
1240
Symbol* sym = this_cp->unresolved_string_at (which);
1 commit comments
openjdk-notifier[bot] commentedon Jan 6, 2023
Review
Issues