From c76a809e8dbdfe768f9b9c542c69a38c8353bbd0 Mon Sep 17 00:00:00 2001 From: Andrew Dinn Date: Thu, 5 Mar 2026 12:04:52 +0000 Subject: [PATCH] use constant for UnsafeMemoryAccess table columns count --- .../cpu/aarch64/stubGenerator_aarch64.cpp | 6 ++-- .../x86/stubGenerator_x86_64_arraycopy.cpp | 28 +++++++++---------- src/hotspot/share/runtime/stubRoutines.hpp | 2 ++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp index 88d3d8ab2b1..4680481a194 100644 --- a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp @@ -1849,7 +1849,7 @@ class StubGenerator: public StubCodeGenerator { assert(nopush_entry != nullptr, "all disjoint copy stubs export a nopush entry"); bool add_extras = !is_oop && (!aligned || sizeof(jlong) == size); - int extra_count = ((add_extras ? 1 : 0) * 3); + int extra_count = ((add_extras ? 1 : 0) * UnsafeMemoryAccess::COLUMN_COUNT); GrowableArray
entries; GrowableArray
extras; GrowableArray
*extras_ptr = (extra_count > 0 ? &extras : nullptr); @@ -2044,7 +2044,7 @@ class StubGenerator: public StubCodeGenerator { // We need to protect memory accesses in certain cases bool add_extras = !is_oop && (!aligned || sizeof(jlong) == size); - int extra_count = ((add_extras ? 1 : 0) * 3); + int extra_count = ((add_extras ? 1 : 0) * UnsafeMemoryAccess::COLUMN_COUNT); GrowableArray
entries; GrowableArray
extras; GrowableArray
*entries_ptr = (nopush_entry != nullptr ? &entries : nullptr); @@ -2975,7 +2975,7 @@ class StubGenerator: public StubCodeGenerator { assert(entry_count == 1, "sanity check"); // we expect one set of extra unsafememory access handler entries GrowableArray
extras; - int extra_count = 3; + int extra_count = 1 * UnsafeMemoryAccess::COLUMN_COUNT; address start = load_archive_data(stub_id, nullptr, &extras); if (start != nullptr) { assert(extras.length() == extra_count, diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64_arraycopy.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64_arraycopy.cpp index b663c806f9f..197072a6cb2 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64_arraycopy.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64_arraycopy.cpp @@ -579,7 +579,7 @@ address StubGenerator::generate_disjoint_copy_avx3_masked(StubId stub_id, addres // when MaxVectorSize == 64 So we may expect 0, 3 or 6 extras. int handlers_count = (MaxVectorSize == 64 ? 2 : 1); int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_extra_count = 3 * (add_handlers ? handlers_count : 0); // 0/1/2 x UMAM {start,end,handler} + int expected_extra_count = (add_handlers ? handlers_count : 0) * UnsafeMemoryAccess::COLUMN_COUNT; // 0/1/2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -657,7 +657,7 @@ address StubGenerator::generate_disjoint_copy_avx3_masked(StubId stub_id, addres int threshold[] = { 4096, 2048, 1024, 512}; // UnsafeMemoryAccess page error: continue after unsafe access - UnsafeMemoryAccessMark umam(this, !is_oop && !aligned, true); + UnsafeMemoryAccessMark umam(this, add_handlers, true); // 'from', 'to' and 'count' are now valid // temp1 holds remaining count and temp4 holds running count used to compute @@ -826,7 +826,7 @@ address StubGenerator::generate_disjoint_copy_avx3_masked(StubId stub_id, addres if (MaxVectorSize == 64) { __ BIND(L_copy_large); - UnsafeMemoryAccessMark umam(this, !is_oop && !aligned, false, ucme_exit_pc); + UnsafeMemoryAccessMark umam(this, add_handlers, false, ucme_exit_pc); arraycopy_avx3_large(to, from, temp1, temp2, temp3, temp4, count, xmm1, xmm2, xmm3, xmm4, shift); __ jmp(L_finish); } @@ -968,7 +968,7 @@ address StubGenerator::generate_conjoint_copy_avx3_masked(StubId stub_id, addres bool add_relocs = UseZGC && is_oop; bool add_extras = add_handlers || add_relocs; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = 3 * (add_handlers ? 1 : 0); // 0/1 x UMAM {start,end,handler} + int expected_handler_count = (add_handlers ? 1 : 0) * UnsafeMemoryAccess::COLUMN_COUNT; // 0/1 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -1493,7 +1493,7 @@ address StubGenerator::generate_disjoint_byte_copy(address* entry) { GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = (2 * 3); // 2 x UMAM {start,end,handler} + int expected_handler_count = (2 * UnsafeMemoryAccess::COLUMN_COUNT); // 2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -1643,7 +1643,7 @@ address StubGenerator::generate_conjoint_byte_copy(address nooverlap_target, add GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = (2 * 3); // 2 x UMAM {start,end,handler} + int expected_handler_count = (2 * UnsafeMemoryAccess::COLUMN_COUNT); // 2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -1787,7 +1787,7 @@ address StubGenerator::generate_disjoint_short_copy(address *entry) { GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = (2 * 3); // 2 x UMAM {start,end,handler} + int expected_handler_count = (2 * UnsafeMemoryAccess::COLUMN_COUNT); // 2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -1997,7 +1997,7 @@ address StubGenerator::generate_conjoint_short_copy(address nooverlap_target, ad GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = (2 * 3); // 2 x UMAM {start,end,handler} + int expected_handler_count = (2 * UnsafeMemoryAccess::COLUMN_COUNT); // 2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -2158,7 +2158,7 @@ address StubGenerator::generate_disjoint_int_oop_copy(StubId stub_id, address* e bool add_relocs = UseZGC && is_oop; bool add_extras = add_handlers || add_relocs; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = 3 * (add_handlers ? 2 : 0); // 0/2 x UMAM {start,end,handler} + int expected_handler_count = (add_handlers ? 2 : 0) * UnsafeMemoryAccess::COLUMN_COUNT; // 0/2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -2340,7 +2340,7 @@ address StubGenerator::generate_conjoint_int_oop_copy(StubId stub_id, address no GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = 3 * (add_handlers ? 2 : 0); // 0/2 x UMAM {start,end,handler} + int expected_handler_count = (add_handlers ? 2 : 0) * UnsafeMemoryAccess::COLUMN_COUNT; // 0/2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -2523,7 +2523,7 @@ address StubGenerator::generate_disjoint_long_oop_copy(StubId stub_id, address * GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = 3 * (add_handlers ? 2 : 0); // 0/2 x UMAM {start,end,handler} + int expected_handler_count = (add_handlers ? 2 : 0) * UnsafeMemoryAccess::COLUMN_COUNT; // 0/2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -2706,7 +2706,7 @@ address StubGenerator::generate_conjoint_long_oop_copy(StubId stub_id, address n GrowableArray
entries; GrowableArray
extras; int expected_entry_count = (entry != nullptr ? 2 : 1); - int expected_handler_count = 3 * (add_handlers ? 2 : 0); // 0/2 x UMAM {start,end,handler} + int expected_handler_count = (add_handlers ? 2 : 0) * UnsafeMemoryAccess::COLUMN_COUNT; // 0/2 x UMAM {start,end,handler} int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == expected_entry_count, "sanity check"); GrowableArray
* entries_ptr = (entry_count == 1 ? nullptr : &entries); @@ -3285,9 +3285,9 @@ address StubGenerator::generate_unsafe_setmemory(address unsafe_byte_fill) { StubId stub_id = StubId::stubgen_unsafe_setmemory_id; int entry_count = StubInfo::entry_count(stub_id); assert(entry_count == 1, "sanity check"); - // we expect one set of extra unsafememory access handler entries + // we expect three set of extra unsafememory access handler entries GrowableArray
extras; - int expected_handler_count = 3 * 3; + int expected_handler_count = 3 * UnsafeMemoryAccess::COLUMN_COUNT; address start = load_archive_data(stub_id, nullptr, &extras); if (start != nullptr) { assert(extras.length() == expected_handler_count, diff --git a/src/hotspot/share/runtime/stubRoutines.hpp b/src/hotspot/share/runtime/stubRoutines.hpp index bfd230a4f80..894bd47faab 100644 --- a/src/hotspot/share/runtime/stubRoutines.hpp +++ b/src/hotspot/share/runtime/stubRoutines.hpp @@ -112,6 +112,8 @@ class UnsafeMemoryAccess : public CHeapObj { address _end_pc; address _error_exit_pc; public: + // each table entry requires 3 addresses + static const int COLUMN_COUNT = 3; static address _common_exit_stub_pc; static UnsafeMemoryAccess* _table; static int _table_length;