Skip to content

Commit

Permalink
8299274: Add elements to resolved_references consistently
Browse files Browse the repository at this point in the history
Reviewed-by: iklam, dholmes, rehn, fparain
  • Loading branch information
coleenp committed Jan 6, 2023
1 parent 8cc1669 commit 1e99729
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/cds/cdsProtectionDomain.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -293,7 +293,7 @@ void CDSProtectionDomain::atomic_set_array_index(OopHandle array, int index, oop
// The important thing here is that all threads pick up the same result.
// It doesn't matter which racing thread wins, as long as only one
// result is used by all threads, and all future queries.
((objArrayOop)array.resolve())->atomic_compare_exchange_oop(index, o, NULL);
((objArrayOop)array.resolve())->replace_if_null(index, o);
}

oop CDSProtectionDomain::shared_protection_domain(int index) {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/ci/ciEnv.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -692,7 +692,7 @@ ciConstant ciEnv::unbox_primitive_value(ciObject* cibox, BasicType expected_bt)
//
ciConstant ciEnv::get_resolved_constant(const constantPoolHandle& cpool, int obj_index) {
assert(obj_index >= 0, "");
oop obj = cpool->resolved_references()->obj_at(obj_index);
oop obj = cpool->resolved_reference_at(obj_index);
if (obj == NULL) {
// Unresolved constant. It is resolved when the corresponding slot contains a non-null reference.
// Null constant is represented as a sentinel (non-null) value.
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/interpreter/interpreterRuntime.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -194,7 +194,7 @@ JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::
if (rindex < 0)
rindex = m->constants()->cp_to_object_index(ldc2.pool_index());
if (rindex >= 0) {
oop coop = m->constants()->resolved_references()->obj_at(rindex);
oop coop = m->constants()->resolved_reference_at(rindex);
oop roop = (result == NULL ? Universe::the_null_sentinel() : result);
assert(roop == coop, "expected result for assembly code");
}
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -2127,7 +2127,7 @@ void BytecodeInterpreter::run(interpreterState istate) {

case JVM_CONSTANT_String:
{
oop result = constants->resolved_references()->obj_at(index);
oop result = constants->resolved_reference_at(index);
if (result == NULL) {
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
SET_STACK_OBJECT(THREAD->vm_result(), 0);
Expand Down Expand Up @@ -2232,7 +2232,7 @@ void BytecodeInterpreter::run(interpreterState istate) {
// This kind of CP cache entry does not need to match the flags byte, because
// there is a 1-1 relation between bytecode type and CP entry type.
ConstantPool* constants = METHOD->constants();
oop result = constants->resolved_references()->obj_at(index);
oop result = constants->resolved_reference_at(index);
if (result == NULL) {
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),
handle_exception);
Expand Down
30 changes: 21 additions & 9 deletions src/hotspot/share/oops/constantPool.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -158,7 +158,7 @@ void ConstantPool::metaspace_pointers_do(MetaspaceClosure* it) {
}

objArrayOop ConstantPool::resolved_references() const {
return (objArrayOop)_cache->resolved_references();
return _cache->resolved_references();
}

// Called from outside constant pool resolution where a resolved_reference array
Expand All @@ -167,10 +167,22 @@ objArrayOop ConstantPool::resolved_references_or_null() const {
if (_cache == NULL) {
return NULL;
} else {
return (objArrayOop)_cache->resolved_references();
return _cache->resolved_references();
}
}

oop ConstantPool::resolved_reference_at(int index) const {
oop result = resolved_references()->obj_at(index);
assert(oopDesc::is_oop_or_null(result), "Must be oop");
return result;
}

// Use a CAS for multithreaded access
oop ConstantPool::set_resolved_reference_at(int index, oop new_result) {
assert(oopDesc::is_oop_or_null(new_result), "Must be oop");
return resolved_references()->replace_if_null(index, new_result);
}

// Create resolved_references array and mapping array for original cp indexes
// The ldc bytecode was rewritten to have the resolved reference array index so need a way
// to map it back for resolving and some unlikely miscellaneous uses.
Expand Down Expand Up @@ -446,7 +458,8 @@ int ConstantPool::cp_to_object_index(int cp_index) {
}

void ConstantPool::string_at_put(int which, int obj_index, oop str) {
resolved_references()->obj_at_put(obj_index, str);
oop result = set_resolved_reference_at(obj_index, str);
assert(result == nullptr || result == str, "Only set once or to the same string.");
}

void ConstantPool::trace_class_resolution(const constantPoolHandle& this_cp, Klass* k) {
Expand Down Expand Up @@ -936,7 +949,7 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
assert(index == _no_index_sentinel || index >= 0, "");

if (cache_index >= 0) {
result_oop = this_cp->resolved_references()->obj_at(cache_index);
result_oop = this_cp->resolved_reference_at(cache_index);
if (result_oop != NULL) {
if (result_oop == Universe::the_null_sentinel()) {
DEBUG_ONLY(int temp_index = (index >= 0 ? index : this_cp->object_to_cp_index(cache_index)));
Expand Down Expand Up @@ -1159,9 +1172,8 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
// It doesn't matter which racing thread wins, as long as only one
// result is used by all threads, and all future queries.
oop new_result = (result_oop == NULL ? Universe::the_null_sentinel() : result_oop);
oop old_result = this_cp->resolved_references()
->atomic_compare_exchange_oop(cache_index, new_result, NULL);
if (old_result == NULL) {
oop old_result = this_cp->set_resolved_reference_at(cache_index, new_result);
if (old_result == nullptr) {
return result_oop; // was installed
} else {
// Return the winning thread's result. This can be different than
Expand Down Expand Up @@ -1222,7 +1234,7 @@ void ConstantPool::copy_bootstrap_arguments_at_impl(const constantPoolHandle& th

oop ConstantPool::string_at_impl(const constantPoolHandle& this_cp, int which, int obj_index, TRAPS) {
// If the string has already been interned, this entry will be non-null
oop str = this_cp->resolved_references()->obj_at(obj_index);
oop str = this_cp->resolved_reference_at(obj_index);
assert(str != Universe::the_null_sentinel(), "");
if (str != NULL) return str;
Symbol* sym = this_cp->unresolved_string_at(which);
Expand Down
7 changes: 5 additions & 2 deletions src/hotspot/share/oops/constantPool.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -236,6 +236,9 @@ class ConstantPool : public Metadata {
// resolved strings, methodHandles and callsite objects from the constant pool
objArrayOop resolved_references() const;
objArrayOop resolved_references_or_null() const;
oop resolved_reference_at(int obj_index) const;
oop set_resolved_reference_at(int index, oop new_value);

// mapping resolved object array indexes to cp indexes and back.
int object_to_cp_index(int index) { return reference_map()->at(index); }
int cp_to_object_index(int index);
Expand Down Expand Up @@ -474,7 +477,7 @@ class ConstantPool : public Metadata {
// behind our back, lest we later load stale values thru the oop.
// we might want a volatile_obj_at in ObjArrayKlass.
int obj_index = cp_to_object_index(which);
return resolved_references()->obj_at(obj_index);
return resolved_reference_at(obj_index);
}

Symbol* unresolved_string_at(int which) {
Expand Down
11 changes: 4 additions & 7 deletions src/hotspot/share/oops/cpCache.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -432,10 +432,8 @@ void ConstantPoolCacheEntry::set_method_handle_common(const constantPoolHandle&
// Store appendix, if any.
if (has_appendix) {
const int appendix_index = f2_as_index();
objArrayOop resolved_references = cpool->resolved_references();
assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob");
assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
resolved_references->obj_at_put(appendix_index, appendix());
oop old_oop = cpool->set_resolved_reference_at(appendix_index, appendix());
assert(old_oop == nullptr, "init just once");
}

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


Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/oops/cpCache.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -447,7 +447,7 @@ class ConstantPoolCache: public MetaspaceObj {
void set_archived_references(oop o) NOT_CDS_JAVA_HEAP_RETURN;
void clear_archived_references() NOT_CDS_JAVA_HEAP_RETURN;

inline oop resolved_references();
inline objArrayOop resolved_references();
void set_resolved_references(OopHandle s) { _resolved_references = s; }
Array<u2>* reference_map() const { return _reference_map; }
void set_reference_map(Array<u2>* o) { _reference_map = o; }
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/oops/cpCache.inline.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -99,6 +99,10 @@ inline ConstantPoolCache::ConstantPoolCache(int length,
}
}

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

#endif // SHARE_OOPS_CPCACHE_INLINE_HPP
7 changes: 3 additions & 4 deletions src/hotspot/share/oops/objArrayOop.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,15 +28,14 @@
#include "oops/objArrayOop.inline.hpp"
#include "oops/oop.inline.hpp"

oop objArrayOopDesc::atomic_compare_exchange_oop(int index, oop exchange_value,
oop compare_value) {
oop objArrayOopDesc::replace_if_null(int index, oop exchange_value) {
ptrdiff_t offs;
if (UseCompressedOops) {
offs = objArrayOopDesc::obj_at_offset<narrowOop>(index);
} else {
offs = objArrayOopDesc::obj_at_offset<oop>(index);
}
return HeapAccess<IS_ARRAY>::oop_atomic_cmpxchg_at(as_oop(), offs, compare_value, exchange_value);
return HeapAccess<IS_ARRAY>::oop_atomic_cmpxchg_at(as_oop(), offs, (oop)nullptr, exchange_value);
}

Klass* objArrayOopDesc::element_klass() {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/oops/objArrayOop.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -90,7 +90,7 @@ class objArrayOopDesc : public arrayOopDesc {

void obj_at_put(int index, oop value);

oop atomic_compare_exchange_oop(int index, oop exchange_value, oop compare_value);
oop replace_if_null(int index, oop exchange_value);

// Sizing
static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }
Expand Down

1 comment on commit 1e99729

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.