Skip to content

Commit 1e99729

Browse files
committedJan 6, 2023
8299274: Add elements to resolved_references consistently
Reviewed-by: iklam, dholmes, rehn, fparain
1 parent 8cc1669 commit 1e99729

11 files changed

+52
-37
lines changed
 

‎src/hotspot/share/cds/cdsProtectionDomain.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -293,7 +293,7 @@ void CDSProtectionDomain::atomic_set_array_index(OopHandle array, int index, oop
293293
// The important thing here is that all threads pick up the same result.
294294
// It doesn't matter which racing thread wins, as long as only one
295295
// result is used by all threads, and all future queries.
296-
((objArrayOop)array.resolve())->atomic_compare_exchange_oop(index, o, NULL);
296+
((objArrayOop)array.resolve())->replace_if_null(index, o);
297297
}
298298

299299
oop CDSProtectionDomain::shared_protection_domain(int index) {

‎src/hotspot/share/ci/ciEnv.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -692,7 +692,7 @@ ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt)
692692
//
693693
ciConstant ciEnv::get_resolved_constant(const constantPoolHandle& cpool, int obj_index) {
694694
assert(obj_index >= 0, "");
695-
oop obj = cpool->resolved_references()->obj_at(obj_index);
695+
oop obj = cpool->resolved_reference_at(obj_index);
696696
if (obj == NULL) {
697697
// Unresolved constant. It is resolved when the corresponding slot contains a non-null reference.
698698
// Null constant is represented as a sentinel (non-null) value.

‎src/hotspot/share/interpreter/interpreterRuntime.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -194,7 +194,7 @@ JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::
194194
if (rindex < 0)
195195
rindex = m->constants()->cp_to_object_index(ldc2.pool_index());
196196
if (rindex >= 0) {
197-
oop coop = m->constants()->resolved_references()->obj_at(rindex);
197+
oop coop = m->constants()->resolved_reference_at(rindex);
198198
oop roop = (result == NULL ? Universe::the_null_sentinel() : result);
199199
assert(roop == coop, "expected result for assembly code");
200200
}

‎src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -2127,7 +2127,7 @@ void BytecodeInterpreter::run(interpreterState istate) {
21272127

21282128
case JVM_CONSTANT_String:
21292129
{
2130-
oop result = constants->resolved_references()->obj_at(index);
2130+
oop result = constants->resolved_reference_at(index);
21312131
if (result == NULL) {
21322132
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
21332133
SET_STACK_OBJECT(THREAD->vm_result(), 0);
@@ -2232,7 +2232,7 @@ void BytecodeInterpreter::run(interpreterState istate) {
22322232
// This kind of CP cache entry does not need to match the flags byte, because
22332233
// there is a 1-1 relation between bytecode type and CP entry type.
22342234
ConstantPool* constants = METHOD->constants();
2235-
oop result = constants->resolved_references()->obj_at(index);
2235+
oop result = constants->resolved_reference_at(index);
22362236
if (result == NULL) {
22372237
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),
22382238
handle_exception);

‎src/hotspot/share/oops/constantPool.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -158,7 +158,7 @@ void ConstantPool::metaspace_pointers_do(MetaspaceClosure* it) {
158158
}
159159

160160
objArrayOop ConstantPool::resolved_references() const {
161-
return (objArrayOop)_cache->resolved_references();
161+
return _cache->resolved_references();
162162
}
163163

164164
// Called from outside constant pool resolution where a resolved_reference array
@@ -167,10 +167,22 @@ objArrayOop ConstantPool::resolved_references_or_null() const {
167167
if (_cache == NULL) {
168168
return NULL;
169169
} else {
170-
return (objArrayOop)_cache->resolved_references();
170+
return _cache->resolved_references();
171171
}
172172
}
173173

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+
174186
// Create resolved_references array and mapping array for original cp indexes
175187
// The ldc bytecode was rewritten to have the resolved reference array index so need a way
176188
// to map it back for resolving and some unlikely miscellaneous uses.
@@ -446,7 +458,8 @@ int ConstantPool::cp_to_object_index(int cp_index) {
446458
}
447459

448460
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.");
450463
}
451464

452465
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,
936949
assert(index == _no_index_sentinel || index >= 0, "");
937950

938951
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);
940953
if (result_oop != NULL) {
941954
if (result_oop == Universe::the_null_sentinel()) {
942955
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,
11591172
// It doesn't matter which racing thread wins, as long as only one
11601173
// result is used by all threads, and all future queries.
11611174
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) {
11651177
return result_oop; // was installed
11661178
} else {
11671179
// 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
12221234

12231235
oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
12241236
// 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);
12261238
assert(str != Universe::the_null_sentinel(), "");
12271239
if (str != NULL) return str;
12281240
Symbol* sym = this_cp->unresolved_string_at(which);

‎src/hotspot/share/oops/constantPool.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -236,6 +236,9 @@ class ConstantPool : public Metadata {
236236
// resolved strings, methodHandles and callsite objects from the constant pool
237237
objArrayOop resolved_references() const;
238238
objArrayOop resolved_references_or_null() const;
239+
oop resolved_reference_at(int obj_index) const;
240+
oop set_resolved_reference_at(int index, oop new_value);
241+
239242
// mapping resolved object array indexes to cp indexes and back.
240243
int object_to_cp_index(int index) { return reference_map()->at(index); }
241244
int cp_to_object_index(int index);
@@ -474,7 +477,7 @@ class ConstantPool : public Metadata {
474477
// behind our back, lest we later load stale values thru the oop.
475478
// we might want a volatile_obj_at in ObjArrayKlass.
476479
int obj_index = cp_to_object_index(which);
477-
return resolved_references()->obj_at(obj_index);
480+
return resolved_reference_at(obj_index);
478481
}
479482

480483
Symbol* unresolved_string_at(int which) {

‎src/hotspot/share/oops/cpCache.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -432,10 +432,8 @@ void ConstantPoolCacheEntry::set_method_handle_common(const constantPoolHandle&
432432
// Store appendix, if any.
433433
if (has_appendix) {
434434
const int appendix_index = f2_as_index();
435-
objArrayOop resolved_references = cpool->resolved_references();
436-
assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob");
437-
assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
438-
resolved_references->obj_at_put(appendix_index, appendix());
435+
oop old_oop = cpool->set_resolved_reference_at(appendix_index, appendix());
436+
assert(old_oop == nullptr, "init just once");
439437
}
440438

441439
release_set_f1(adapter); // This must be the last one to set (see NOTE above)!
@@ -531,8 +529,7 @@ oop ConstantPoolCacheEntry::appendix_if_resolved(const constantPoolHandle& cpool
531529
if (!has_appendix())
532530
return NULL;
533531
const int ref_index = f2_as_index();
534-
objArrayOop resolved_references = cpool->resolved_references();
535-
return resolved_references->obj_at(ref_index);
532+
return cpool->resolved_reference_at(ref_index);
536533
}
537534

538535

‎src/hotspot/share/oops/cpCache.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -447,7 +447,7 @@ class ConstantPoolCache: public MetaspaceObj {
447447
void set_archived_references(oop o) NOT_CDS_JAVA_HEAP_RETURN;
448448
void clear_archived_references() NOT_CDS_JAVA_HEAP_RETURN;
449449

450-
inline oop resolved_references();
450+
inline objArrayOop resolved_references();
451451
void set_resolved_references(OopHandle s) { _resolved_references = s; }
452452
Array<u2>* reference_map() const { return _reference_map; }
453453
void set_reference_map(Array<u2>* o) { _reference_map = o; }

‎src/hotspot/share/oops/cpCache.inline.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -99,6 +99,10 @@ inline ConstantPoolCache::ConstantPoolCache(int length,
9999
}
100100
}
101101

102-
inline oop ConstantPoolCache::resolved_references() { return _resolved_references.resolve(); }
102+
inline objArrayOop ConstantPoolCache::resolved_references() {
103+
oop obj = _resolved_references.resolve();
104+
assert(obj == nullptr || obj->is_objArray(), "should be objArray");
105+
return (objArrayOop)obj;
106+
}
103107

104108
#endif // SHARE_OOPS_CPCACHE_INLINE_HPP

‎src/hotspot/share/oops/objArrayOop.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,15 +28,14 @@
2828
#include "oops/objArrayOop.inline.hpp"
2929
#include "oops/oop.inline.hpp"
3030

31-
oop objArrayOopDesc::atomic_compare_exchange_oop(int index, oop exchange_value,
32-
oop compare_value) {
31+
oop objArrayOopDesc::replace_if_null(int index, oop exchange_value) {
3332
ptrdiff_t offs;
3433
if (UseCompressedOops) {
3534
offs = objArrayOopDesc::obj_at_offset<narrowOop>(index);
3635
} else {
3736
offs = objArrayOopDesc::obj_at_offset<oop>(index);
3837
}
39-
return HeapAccess<IS_ARRAY>::oop_atomic_cmpxchg_at(as_oop(), offs, compare_value, exchange_value);
38+
return HeapAccess<IS_ARRAY>::oop_atomic_cmpxchg_at(as_oop(), offs, (oop)nullptr, exchange_value);
4039
}
4140

4241
Klass* objArrayOopDesc::element_klass() {

‎src/hotspot/share/oops/objArrayOop.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -90,7 +90,7 @@ class objArrayOopDesc : public arrayOopDesc {
9090

9191
void obj_at_put(int index, oop value);
9292

93-
oop atomic_compare_exchange_oop(int index, oop exchange_value, oop compare_value);
93+
oop replace_if_null(int index, oop exchange_value);
9494

9595
// Sizing
9696
static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jan 6, 2023

@openjdk-notifier[bot]
Please sign in to comment.