Skip to content

Commit

Permalink
Merge upstream-jdk
Browse files Browse the repository at this point in the history
  • Loading branch information
corretto-github-robot committed Dec 19, 2024
2 parents 9ca224c + 23d6f74 commit b1bcaa5
Show file tree
Hide file tree
Showing 111 changed files with 2,100 additions and 1,346 deletions.
6 changes: 4 additions & 2 deletions src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ void C2_MacroAssembler::string_indexof_char(Register str1, Register cnt1,
j(NOMATCH);

bind(HIT);
ctzc_bit(trailing_char, match_mask, isL, ch1, result);
// count bits of trailing zero chars
ctzc_bits(trailing_char, match_mask, isL, ch1, result);
srli(trailing_char, trailing_char, 3);
addi(cnt1, cnt1, 8);
ble(cnt1, trailing_char, NOMATCH);
Expand Down Expand Up @@ -1536,7 +1537,8 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2,
// compute their difference.
bind(DIFFERENCE);
xorr(tmp3, tmp1, tmp2);
ctzc_bit(result, tmp3, isLL); // count zero from lsb to msb
// count bits of trailing zero chars
ctzc_bits(result, tmp3, isLL);
srl(tmp1, tmp1, result);
srl(tmp2, tmp2, result);
if (isLL) {
Expand Down
22 changes: 10 additions & 12 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5395,28 +5395,26 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
}
#endif

// Count bits of trailing zero chars from lsb to msb until first non-zero element.
// For LL case, one byte for one element, so shift 8 bits once, and for other case,
// shift 16 bits once.
void MacroAssembler::ctzc_bit(Register Rd, Register Rs, bool isLL, Register tmp1, Register tmp2) {
// Count bits of trailing zero chars from lsb to msb until first non-zero
// char seen. For the LL case, shift 8 bits once as there is only one byte
// per each char. For other cases, shift 16 bits once.
void MacroAssembler::ctzc_bits(Register Rd, Register Rs, bool isLL,
Register tmp1, Register tmp2) {
int step = isLL ? 8 : 16;
if (UseZbb) {
assert_different_registers(Rd, Rs, tmp1);
int step = isLL ? 8 : 16;
ctz(Rd, Rs);
andi(tmp1, Rd, step - 1);
sub(Rd, Rd, tmp1);
andi(Rd, Rd, -step);
return;
}

assert_different_registers(Rd, Rs, tmp1, tmp2);
assert_different_registers(Rd, tmp1, tmp2);
Label Loop;
int step = isLL ? 8 : 16;
mv(Rd, -step);
mv(tmp2, Rs);
mv(Rd, -step);

bind(Loop);
addi(Rd, Rd, step);
andi(tmp1, tmp2, ((1 << step) - 1));
zext(tmp1, tmp2, step);
srli(tmp2, tmp2, step);
beqz(tmp1, Loop);
}
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,8 @@ class MacroAssembler: public Assembler {
void inflate_lo32(Register Rd, Register Rs, Register tmp1 = t0, Register tmp2 = t1);
void inflate_hi32(Register Rd, Register Rs, Register tmp1 = t0, Register tmp2 = t1);

void ctzc_bit(Register Rd, Register Rs, bool isLL = false, Register tmp1 = t0, Register tmp2 = t1);
void ctzc_bits(Register Rd, Register Rs, bool isLL = false,
Register tmp1 = t0, Register tmp2 = t1);

void zero_words(Register base, uint64_t cnt);
address zero_words(Register ptr, Register cnt);
Expand Down
21 changes: 14 additions & 7 deletions src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,8 @@ class StubGenerator: public StubCodeGenerator {
// Find the first different characters in the longwords and
// compute their difference.
__ bind(CALCULATE_DIFFERENCE);
__ ctzc_bit(tmp4, tmp3);
// count bits of trailing zero chars
__ ctzc_bits(tmp4, tmp3);
__ srl(tmp1, tmp1, tmp4);
__ srl(tmp2, tmp2, tmp4);
__ zext(tmp1, tmp1, 16);
Expand Down Expand Up @@ -2703,7 +2704,8 @@ class StubGenerator: public StubCodeGenerator {
// Find the first different characters in the longwords and
// compute their difference.
__ bind(DIFF2);
__ ctzc_bit(tmp3, tmp4, isLL); // count zero from lsb to msb
// count bits of trailing zero chars
__ ctzc_bits(tmp3, tmp4, isLL);
__ srl(tmp5, tmp5, tmp3);
__ srl(cnt1, cnt1, tmp3);
if (isLL) {
Expand All @@ -2716,7 +2718,8 @@ class StubGenerator: public StubCodeGenerator {
__ sub(result, tmp5, cnt1);
__ j(LENGTH_DIFF);
__ bind(DIFF);
__ ctzc_bit(tmp3, tmp4, isLL); // count zero from lsb to msb
// count bits of trailing zero chars
__ ctzc_bits(tmp3, tmp4, isLL);
__ srl(tmp1, tmp1, tmp3);
__ srl(tmp2, tmp2, tmp3);
if (isLL) {
Expand Down Expand Up @@ -2862,7 +2865,8 @@ class StubGenerator: public StubCodeGenerator {
__ beqz(match_mask, NOMATCH);

__ bind(L_SMALL_HAS_ZERO_LOOP);
__ ctzc_bit(trailing_zeros, match_mask, haystack_isL, ch2, tmp); // count trailing zeros
// count bits of trailing zero chars
__ ctzc_bits(trailing_zeros, match_mask, haystack_isL, ch2, tmp);
__ addi(trailing_zeros, trailing_zeros, haystack_isL ? 7 : 15);
__ mv(ch2, wordSize / haystack_chr_size);
__ ble(needle_len, ch2, L_SMALL_CMP_LOOP_LAST_CMP2);
Expand All @@ -2881,7 +2885,8 @@ class StubGenerator: public StubCodeGenerator {

__ bind(L_SMALL_CMP_LOOP_NOMATCH);
__ beqz(match_mask, NOMATCH);
__ ctzc_bit(trailing_zeros, match_mask, haystack_isL, tmp, ch2);
// count bits of trailing zero chars
__ ctzc_bits(trailing_zeros, match_mask, haystack_isL, tmp, ch2);
__ addi(trailing_zeros, trailing_zeros, haystack_isL ? 7 : 15);
__ add(result, result, 1);
__ add(haystack, haystack, haystack_chr_size);
Expand All @@ -2900,7 +2905,8 @@ class StubGenerator: public StubCodeGenerator {

__ align(OptoLoopAlignment);
__ bind(L_HAS_ZERO);
__ ctzc_bit(trailing_zeros, match_mask, haystack_isL, tmp, ch2);
// count bits of trailing zero chars
__ ctzc_bits(trailing_zeros, match_mask, haystack_isL, tmp, ch2);
__ addi(trailing_zeros, trailing_zeros, haystack_isL ? 7 : 15);
__ slli(needle_len, needle_len, BitsPerByte * wordSize / 2);
__ orr(haystack_len, haystack_len, needle_len); // restore needle_len(32bits)
Expand Down Expand Up @@ -2929,7 +2935,8 @@ class StubGenerator: public StubCodeGenerator {

__ bind(L_CMP_LOOP_NOMATCH);
__ beqz(match_mask, L_HAS_ZERO_LOOP_NOMATCH);
__ ctzc_bit(trailing_zeros, match_mask, haystack_isL, needle_len, ch2); // find next "first" char index
// count bits of trailing zero chars
__ ctzc_bits(trailing_zeros, match_mask, haystack_isL, needle_len, ch2);
__ addi(trailing_zeros, trailing_zeros, haystack_isL ? 7 : 15);
__ add(haystack, haystack, haystack_chr_size);
__ j(L_HAS_ZERO_LOOP);
Expand Down
7 changes: 5 additions & 2 deletions src/hotspot/share/cds/archiveBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "logging/log.hpp"
#include "logging/logStream.hpp"
#include "memory/allStatic.hpp"
#include "memory/memoryReserver.hpp"
#include "memory/memRegion.hpp"
#include "memory/resourceArea.hpp"
#include "oops/compressedKlass.inline.hpp"
Expand Down Expand Up @@ -193,7 +194,7 @@ ArchiveBuilder::~ArchiveBuilder() {
delete _klasses;
delete _symbols;
if (_shared_rs.is_reserved()) {
_shared_rs.release();
MemoryReserver::release(_shared_rs);
}
}

Expand Down Expand Up @@ -347,7 +348,9 @@ size_t ArchiveBuilder::estimate_archive_size() {

address ArchiveBuilder::reserve_buffer() {
size_t buffer_size = estimate_archive_size();
ReservedSpace rs(buffer_size, MetaspaceShared::core_region_alignment(), os::vm_page_size());
ReservedSpace rs = MemoryReserver::reserve(buffer_size,
MetaspaceShared::core_region_alignment(),
os::vm_page_size());
if (!rs.is_reserved()) {
log_error(cds)("Failed to reserve " SIZE_FORMAT " bytes of output buffer.", buffer_size);
MetaspaceShared::unrecoverable_writing_error();
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/cds/archiveBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "cds/dumpAllocStats.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspaceClosure.hpp"
#include "memory/reservedSpace.hpp"
#include "memory/virtualspace.hpp"
#include "oops/array.hpp"
#include "oops/klass.hpp"
#include "runtime/os.hpp"
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/cds/dynamicArchive.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, 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 @@ -29,7 +29,6 @@
#include "classfile/compactHashtable.hpp"
#include "memory/allStatic.hpp"
#include "memory/memRegion.hpp"
#include "memory/virtualspace.hpp"
#include "oops/array.hpp"
#include "oops/oop.hpp"
#include "utilities/exceptions.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/cds/filemap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ClassFileStream;
class ClassLoaderData;
class ClassPathEntry;
class outputStream;
class ReservedSpace;

class SharedClassPathEntry : public MetaspaceObj {
enum {
Expand Down Expand Up @@ -481,7 +482,6 @@ class FileMapInfo : public CHeapObj<mtInternal> {
void unmap_region(int i);
void close();
bool is_open() { return _file_open; }
ReservedSpace reserve_shared_memory();

// JVM/TI RedefineClasses() support:
// Remap the shared readonly space to shared readwrite, private.
Expand Down
40 changes: 27 additions & 13 deletions src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "logging/log.hpp"
#include "logging/logMessage.hpp"
#include "logging/logStream.hpp"
#include "memory/memoryReserver.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspaceClosure.hpp"
#include "memory/resourceArea.hpp"
Expand Down Expand Up @@ -282,7 +283,7 @@ void MetaspaceShared::initialize_for_static_dump() {
SharedBaseAddress = (size_t)_requested_base_address;

size_t symbol_rs_size = LP64_ONLY(3 * G) NOT_LP64(128 * M);
_symbol_rs = ReservedSpace(symbol_rs_size, mtClassShared);
_symbol_rs = MemoryReserver::reserve(symbol_rs_size, mtClassShared);
if (!_symbol_rs.is_reserved()) {
log_error(cds)("Unable to reserve memory for symbols: " SIZE_FORMAT " bytes.", symbol_rs_size);
MetaspaceShared::unrecoverable_writing_error();
Expand Down Expand Up @@ -1266,7 +1267,9 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File
if (use_requested_addr) {
assert(!total_space_rs.is_reserved(), "Should not be reserved for Windows");
log_info(cds)("Windows mmap workaround: releasing archive space.");
archive_space_rs.release();
MemoryReserver::release(archive_space_rs);
// Mark as not reserved
archive_space_rs = {};
}
}
MapArchiveResult static_result = map_archive(static_mapinfo, mapped_base_address, archive_space_rs);
Expand Down Expand Up @@ -1438,8 +1441,10 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
"Archive base address unaligned: " PTR_FORMAT ", needs alignment: %zu.",
p2i(base_address), archive_space_alignment);

archive_space_rs = ReservedSpace(archive_space_size, archive_space_alignment,
os::vm_page_size(), (char*)base_address);
archive_space_rs = MemoryReserver::reserve((char*)base_address,
archive_space_size,
archive_space_alignment,
os::vm_page_size());
if (archive_space_rs.is_reserved()) {
assert(base_address == nullptr ||
(address)archive_space_rs.base() == base_address, "Sanity");
Expand Down Expand Up @@ -1505,10 +1510,14 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
// caller will not split the combined space for mapping, instead read the archive data
// via sequential file IO.
address ccs_base = base_address + archive_space_size + gap_size;
archive_space_rs = ReservedSpace(archive_space_size, archive_space_alignment,
os::vm_page_size(), (char*)base_address);
class_space_rs = ReservedSpace(class_space_size, class_space_alignment,
os::vm_page_size(), (char*)ccs_base);
archive_space_rs = MemoryReserver::reserve((char*)base_address,
archive_space_size,
archive_space_alignment,
os::vm_page_size());
class_space_rs = MemoryReserver::reserve((char*)ccs_base,
class_space_size,
class_space_alignment,
os::vm_page_size());
}
if (!archive_space_rs.is_reserved() || !class_space_rs.is_reserved()) {
release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
Expand All @@ -1519,8 +1528,10 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
MemTracker::record_virtual_memory_tag(class_space_rs.base(), mtClass);
} else {
if (use_archive_base_addr && base_address != nullptr) {
total_space_rs = ReservedSpace(total_range_size, base_address_alignment,
os::vm_page_size(), (char*) base_address);
total_space_rs = MemoryReserver::reserve((char*) base_address,
total_range_size,
base_address_alignment,
os::vm_page_size());
} else {
// We did not manage to reserve at the preferred address, or were instructed to relocate. In that
// case we reserve wherever possible, but the start address needs to be encodable as narrow Klass
Expand Down Expand Up @@ -1568,15 +1579,18 @@ void MetaspaceShared::release_reserved_spaces(ReservedSpace& total_space_rs,
ReservedSpace& class_space_rs) {
if (total_space_rs.is_reserved()) {
log_debug(cds)("Released shared space (archive + class) " INTPTR_FORMAT, p2i(total_space_rs.base()));
total_space_rs.release();
MemoryReserver::release(total_space_rs);
total_space_rs = {};
} else {
if (archive_space_rs.is_reserved()) {
log_debug(cds)("Released shared space (archive) " INTPTR_FORMAT, p2i(archive_space_rs.base()));
archive_space_rs.release();
MemoryReserver::release(archive_space_rs);
archive_space_rs = {};
}
if (class_space_rs.is_reserved()) {
log_debug(cds)("Released shared space (classes) " INTPTR_FORMAT, p2i(class_space_rs.base()));
class_space_rs.release();
MemoryReserver::release(class_space_rs);
class_space_rs = {};
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/cds/metaspaceShared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "memory/allocation.hpp"
#include "memory/memRegion.hpp"
#include "memory/reservedSpace.hpp"
#include "memory/virtualspace.hpp"
#include "oops/oop.hpp"
#include "utilities/macros.hpp"
Expand Down
10 changes: 6 additions & 4 deletions src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "logging/logStream.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/iterator.hpp"
#include "memory/memoryReserver.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/method.inline.hpp"
Expand Down Expand Up @@ -318,7 +319,7 @@ void CodeCache::initialize_heaps() {
FLAG_SET_ERGO(NonProfiledCodeHeapSize, non_profiled.size);
FLAG_SET_ERGO(ReservedCodeCacheSize, cache_size);

ReservedCodeSpace rs = reserve_heap_memory(cache_size, ps);
ReservedSpace rs = reserve_heap_memory(cache_size, ps);

// Register CodeHeaps with LSan as we sometimes embed pointers to malloc memory.
LSAN_REGISTER_ROOT_REGION(rs.base(), rs.size());
Expand Down Expand Up @@ -348,11 +349,12 @@ size_t CodeCache::page_size(bool aligned, size_t min_pages) {
os::page_size_for_region_unaligned(ReservedCodeCacheSize, min_pages);
}

ReservedCodeSpace CodeCache::reserve_heap_memory(size_t size, size_t rs_ps) {
ReservedSpace CodeCache::reserve_heap_memory(size_t size, size_t rs_ps) {
// Align and reserve space for code cache
const size_t rs_align = MAX2(rs_ps, os::vm_allocation_granularity());
const size_t rs_size = align_up(size, rs_align);
ReservedCodeSpace rs(rs_size, rs_align, rs_ps);

ReservedSpace rs = CodeMemoryReserver::reserve(rs_size, rs_align, rs_ps);
if (!rs.is_reserved()) {
vm_exit_during_initialization(err_msg("Could not reserve enough space for code cache (" SIZE_FORMAT "K)",
rs_size/K));
Expand Down Expand Up @@ -1130,7 +1132,7 @@ void CodeCache::initialize() {
// If InitialCodeCacheSize is equal to ReservedCodeCacheSize, then it's more likely
// users want to use the largest available page.
const size_t min_pages = (InitialCodeCacheSize == ReservedCodeCacheSize) ? 1 : 8;
ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize, page_size(false, min_pages));
ReservedSpace rs = reserve_heap_memory(ReservedCodeCacheSize, page_size(false, min_pages));
// Register CodeHeaps with LSan as we sometimes embed pointers to malloc memory.
LSAN_REGISTER_ROOT_REGION(rs.base(), rs.size());
add_heap(rs, "CodeCache", CodeBlobType::All);
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/code/codeCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class OopClosure;
class ShenandoahParallelCodeHeapIterator;
class NativePostCallNop;
class DeoptimizationScope;
class ReservedSpace;

#ifdef LINUX
#define DEFAULT_PERFMAP_FILENAME "/tmp/perf-%p.map"
Expand Down Expand Up @@ -122,7 +123,7 @@ class CodeCache : AllStatic {
static CodeHeap* get_code_heap(CodeBlobType code_blob_type); // Returns the CodeHeap for the given CodeBlobType
// Returns the name of the VM option to set the size of the corresponding CodeHeap
static const char* get_code_heap_flag_name(CodeBlobType code_blob_type);
static ReservedCodeSpace reserve_heap_memory(size_t size, size_t rs_ps); // Reserves one continuous chunk of memory for the CodeHeaps
static ReservedSpace reserve_heap_memory(size_t size, size_t rs_ps); // Reserves one continuous chunk of memory for the CodeHeaps

// Iteration
static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap
Expand Down
Loading

0 comments on commit b1bcaa5

Please sign in to comment.