Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[GR-46641] Merge in jdk-21+27.
Browse files Browse the repository at this point in the history
PullRequest: labsjdk-ce-21/12
  • Loading branch information
marwan-hallaoui committed Jun 15, 2023
2 parents 7b863eb + 3e3b6b9 commit 9a695ae
Show file tree
Hide file tree
Showing 55 changed files with 1,143 additions and 709 deletions.
2 changes: 1 addition & 1 deletion ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ local contains(str, needle) = std.findSubstr(needle, str) != [];
# Downstream Graal branch to test against. If you change this value to anything but
# "master", you must create an ol-jira issue to change it back to master once the
# next JVMCI release has been made. Add the issue id as a comment here.
local downstream_branch = "je/fix-jdk21-b26-GR-46574",
local downstream_branch = "master",

local clone_graal(defs) = {
# Checkout the graal-enterprise repo to the "_gate" version of the
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/z/zPhysicalMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ void ZPhysicalMemoryManager::nmt_commit(zoffset offset, size_t size) const {
// When this function is called we don't know where in the virtual memory
// this physical memory will be mapped. So we fake that the virtual memory
// address is the heap base + the given offset.
const zaddress addr = ZOffset::address(offset);
MemTracker::record_virtual_memory_commit((void*)untype(addr), size, CALLER_PC);
const uintptr_t addr = ZAddressHeapBase + untype(offset);
MemTracker::record_virtual_memory_commit((void*)addr, size, CALLER_PC);
}

void ZPhysicalMemoryManager::nmt_uncommit(zoffset offset, size_t size) const {
if (MemTracker::enabled()) {
const zaddress addr = ZOffset::address(offset);
const uintptr_t addr = ZAddressHeapBase + untype(offset);
Tracker tracker(Tracker::uncommit);
tracker.record((address)untype(addr), size);
tracker.record((address)addr, size);
}
}

Expand Down
26 changes: 11 additions & 15 deletions src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,20 @@ static size_t write_storage(JfrStorage& storage, JfrChunkWriter& chunkwriter) {
return invoke(fs);
}

typedef Content<JfrStringPool, &JfrStringPool::write> StringPool;
typedef WriteCheckpointEvent<StringPool> WriteStringPool;
typedef Content<JfrStringPool, &JfrStringPool::flush> FlushStringPoolFunctor;
typedef Content<JfrStringPool, &JfrStringPool::write> WriteStringPoolFunctor;
typedef WriteCheckpointEvent<FlushStringPoolFunctor> FlushStringPool;
typedef WriteCheckpointEvent<WriteStringPoolFunctor> WriteStringPool;

static u4 flush_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) {
StringPool sp(string_pool);
WriteStringPool wsp(chunkwriter, sp, TYPE_STRING);
return invoke(wsp);
FlushStringPoolFunctor fspf(string_pool);
FlushStringPool fsp(chunkwriter, fspf, TYPE_STRING);
return invoke(fsp);
}

static u4 write_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) {
StringPool sp(string_pool);
WriteStringPool wsp(chunkwriter, sp, TYPE_STRING);
WriteStringPoolFunctor wspf(string_pool);
WriteStringPool wsp(chunkwriter, wspf, TYPE_STRING);
return invoke(wsp);
}

Expand Down Expand Up @@ -461,7 +463,6 @@ void JfrRecorderService::clear() {

void JfrRecorderService::pre_safepoint_clear() {
clear_object_allocation_sampling();
_string_pool.clear();
_storage.clear();
JfrStackTraceRepository::clear();
}
Expand All @@ -475,14 +476,14 @@ void JfrRecorderService::invoke_safepoint_clear() {
void JfrRecorderService::safepoint_clear() {
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
_checkpoint_manager.begin_epoch_shift();
_string_pool.clear();
_storage.clear();
_chunkwriter.set_time_stamp();
JfrStackTraceRepository::clear();
_checkpoint_manager.end_epoch_shift();
}

void JfrRecorderService::post_safepoint_clear() {
_string_pool.clear();
_checkpoint_manager.clear();
}

Expand Down Expand Up @@ -567,9 +568,6 @@ void JfrRecorderService::pre_safepoint_write() {
// The sampler is released (unlocked) later in post_safepoint_write.
ObjectSampleCheckpoint::on_rotation(ObjectSampler::acquire());
}
if (_string_pool.is_modified()) {
write_stringpool(_string_pool, _chunkwriter);
}
write_storage(_storage, _chunkwriter);
if (_stack_trace_repository.is_modified()) {
write_stacktrace(_stack_trace_repository, _chunkwriter, false);
Expand All @@ -587,9 +585,6 @@ void JfrRecorderService::safepoint_write() {
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
_checkpoint_manager.begin_epoch_shift();
JfrStackTraceRepository::clear_leak_profiler();
if (_string_pool.is_modified()) {
write_stringpool(_string_pool, _chunkwriter);
}
_checkpoint_manager.on_rotation();
_storage.write_at_safepoint();
_chunkwriter.set_time_stamp();
Expand All @@ -603,6 +598,7 @@ void JfrRecorderService::post_safepoint_write() {
// Type tagging is epoch relative which entails we are able to write out the
// already tagged artifacts for the previous epoch. We can accomplish this concurrently
// with threads now tagging artifacts in relation to the new, now updated, epoch and remain outside of a safepoint.
write_stringpool(_string_pool, _chunkwriter);
_checkpoint_manager.write_type_set();
if (LeakProfiler::is_running()) {
// The object sampler instance was exclusively acquired and locked in pre_safepoint_write.
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/jfr/recorder/storage/jfrStorageUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,11 @@ class EpochDispatchOp {
size_t elements() const { return _elements; }
};

template <typename T>
class ReinitializationOp {
public:
typedef T Type;
bool process(Type* t);
};

#endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,13 @@ size_t EpochDispatchOp<Operation>::dispatch(bool previous_epoch, const u1* eleme
return elements;
}

template <typename T>
bool ReinitializationOp<T>::process(T* t) {
assert(t != nullptr, "invariant");
assert(t->identity() != nullptr, "invariant");
t->reinitialize();
t->release();
return true;
}

#endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
41 changes: 29 additions & 12 deletions src/hotspot/share/jfr/recorder/stringpool/jfrStringPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ static const size_t string_pool_buffer_size = 512 * K;
bool JfrStringPool::initialize() {
assert(_mspace == nullptr, "invariant");
_mspace = create_mspace<JfrStringPoolMspace>(string_pool_buffer_size,
string_pool_cache_count, // cache limit
string_pool_cache_count, // cache preallocate count
false, // preallocate_to_free_list (== preallocate directly to live list)
0,
0, // cache preallocate count
false,
this);

// preallocate buffer count to each of the epoch live lists
for (size_t i = 0; i < string_pool_cache_count * 2; ++i) {
Buffer* const buffer = mspace_allocate(string_pool_buffer_size, _mspace);
_mspace->add_to_live_list(buffer, i % 2 == 0);
}
assert(_mspace->free_list_is_empty(), "invariant");
return _mspace != nullptr;
}

Expand All @@ -95,11 +102,7 @@ static void release(BufferPtr buffer, Thread* thread) {
assert(buffer->lease(), "invariant");
assert(buffer->acquired_by_self(), "invariant");
buffer->clear_lease();
if (buffer->transient()) {
buffer->set_retired();
} else {
buffer->release();
}
buffer->release();
}

BufferPtr JfrStringPool::flush(BufferPtr old, size_t used, size_t requested, Thread* thread) {
Expand Down Expand Up @@ -180,30 +183,44 @@ typedef StringPoolOp<UnBufferedWriteToChunk> WriteOperation;
typedef StringPoolOp<StringPoolDiscarderStub> DiscardOperation;
typedef ExclusiveOp<WriteOperation> ExclusiveWriteOperation;
typedef ExclusiveOp<DiscardOperation> ExclusiveDiscardOperation;
typedef ReinitializationOp<JfrStringPoolBuffer> ReinitializationOperation;
typedef ReleaseWithExcisionOp<JfrStringPoolMspace, JfrStringPoolMspace::LiveList> ReleaseOperation;
typedef CompositeOperation<ExclusiveWriteOperation, ReleaseOperation> WriteReleaseOperation;
typedef CompositeOperation<ExclusiveWriteOperation, ReinitializationOperation> WriteReinitializeOperation;
typedef CompositeOperation<ExclusiveDiscardOperation, ReleaseOperation> DiscardReleaseOperation;

size_t JfrStringPool::write() {
Thread* const thread = Thread::current();
WriteOperation wo(_chunkwriter, thread);
ExclusiveWriteOperation ewo(wo);
assert(_mspace->free_list_is_empty(), "invariant");
ReleaseOperation ro(_mspace, _mspace->live_list());
ReleaseOperation ro(_mspace, _mspace->live_list(true)); // previous epoch list
WriteReleaseOperation wro(&ewo, &ro);
assert(_mspace->live_list_is_nonempty(), "invariant");
process_live_list(wro, _mspace);
process_live_list(wro, _mspace, true); // previous epoch list
return wo.processed();
}

size_t JfrStringPool::flush() {
Thread* const thread = Thread::current();
WriteOperation wo(_chunkwriter, thread);
ExclusiveWriteOperation ewo(wo);
ReinitializationOperation rio;
WriteReinitializeOperation wro(&ewo, &rio);
assert(_mspace->free_list_is_empty(), "invariant");
assert(_mspace->live_list_is_nonempty(), "invariant");
process_live_list(wro, _mspace); // current epoch list
return wo.processed();
}

size_t JfrStringPool::clear() {
DiscardOperation discard_operation;
ExclusiveDiscardOperation edo(discard_operation);
assert(_mspace->free_list_is_empty(), "invariant");
ReleaseOperation ro(_mspace, _mspace->live_list());
ReleaseOperation ro(_mspace, _mspace->live_list(true)); // previous epoch list
DiscardReleaseOperation discard_op(&edo, &ro);
assert(_mspace->live_list_is_nonempty(), "invariant");
process_live_list(discard_op, _mspace);
process_live_list(discard_op, _mspace, true); // previous epoch list
return discard_operation.processed();
}

Expand Down
8 changes: 5 additions & 3 deletions src/hotspot/share/jfr/recorder/stringpool/jfrStringPool.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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 @@ -35,7 +35,7 @@ class JavaThread;
class JfrChunkWriter;
class JfrStringPool;

typedef JfrMemorySpace<JfrStringPool, JfrMspaceRetrieval, JfrLinkedList<JfrStringPoolBuffer> > JfrStringPoolMspace;
typedef JfrMemorySpace<JfrStringPool, JfrMspaceRetrieval, JfrLinkedList<JfrStringPoolBuffer>, JfrLinkedList<JfrStringPoolBuffer>, true > JfrStringPoolMspace;

//
// Although called JfrStringPool, a more succinct description would be
Expand All @@ -45,8 +45,10 @@ typedef JfrMemorySpace<JfrStringPool, JfrMspaceRetrieval, JfrLinkedList<JfrStrin
//
class JfrStringPool : public JfrCHeapObj {
public:
size_t write();
size_t clear();
size_t flush();
size_t write();

static jboolean add(jlong id, jstring string, JavaThread* jt);

typedef JfrStringPoolMspace::Node Buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

/**
* A value layout used to model the address of some region of memory. The carrier associated with an address layout is
* {@code MemorySegment.class}. The size and alignment of an address layout are platform dependent
* {@code MemorySegment.class}. The size and alignment of an address layout are platform-dependent
* (e.g. on a 64-bit platform, the size and alignment of an address layout are set to 8 bytes).
* <p>
* An address layout may optionally feature a {@linkplain #targetLayout() target layout}. An address layout with
Expand Down Expand Up @@ -113,9 +113,9 @@ public sealed interface AddressLayout extends ValueLayout permits ValueLayouts.O

/**
* Returns an address layout with the same carrier, alignment constraint, name and order as this address layout,
* but without any specified target layout.
* <p>
* This can be useful to compare two address layouts that have different target layouts, but are otherwise equal.
* but with no target layout.
*
* @apiNote This can be useful to compare two address layouts that have different target layouts, but are otherwise equal.
*
* @return an address layout with same characteristics as this layout, but with no target layout.
* @see #targetLayout()
Expand Down
29 changes: 16 additions & 13 deletions src/java.base/share/classes/java/lang/foreign/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* Alternatively, clients can obtain an {@linkplain Arena#ofAuto() automatic arena}, that is an arena
* which features a <em>bounded lifetime</em> that is managed, automatically, by the garbage collector. As such, the regions
* of memory backing memory segments allocated with the automatic arena are deallocated at some unspecified time
* <em>after</em> the automatic arena (and all the segments allocated by it) become
* <em>after</em> the automatic arena (and all the segments allocated by it) becomes
* <a href="../../../java/lang/ref/package.html#reachability">unreachable</a>, as shown below:
* {@snippet lang = java:
* MemorySegment segment = Arena.ofAuto().allocate(100, 1); // @highlight regex='ofAuto()'
Expand Down Expand Up @@ -202,7 +202,7 @@ public interface Arena extends SegmentAllocator, AutoCloseable {

/**
* Creates a new arena that is managed, automatically, by the garbage collector.
* Segments obtained with the returned arena can be
* Segments allocated with the returned arena can be
* {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by any thread.
* Calling {@link #close()} on the returned arena will result in an {@link UnsupportedOperationException}.
*
Expand All @@ -213,7 +213,7 @@ static Arena ofAuto() {
}

/**
* Obtains the global arena. Segments obtained with the global arena can be
* Obtains the global arena. Segments allocated with the global arena can be
* {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by any thread.
* Calling {@link #close()} on the returned arena will result in an {@link UnsupportedOperationException}.
*
Expand All @@ -227,14 +227,17 @@ class Holder {
}

/**
* {@return a new confined arena, owned by the current thread}
* {@return a new confined arena} Segments allocated with the confined arena can be
* {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by the thread that created the arena,
* the arena's <em>owner thread</em>.
*/
static Arena ofConfined() {
return MemorySessionImpl.createConfined(Thread.currentThread()).asArena();
}

/**
* {@return a new shared arena}
* {@return a new shared arena} Segments allocated with the global arena can be
* {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by any thread.
*/
static Arena ofShared() {
return MemorySessionImpl.createShared().asArena();
Expand All @@ -244,7 +247,7 @@ static Arena ofShared() {
* Returns a native memory segment with the given size (in bytes) and alignment constraint (in bytes).
* The returned segment is associated with this {@linkplain #scope() arena scope}.
* The segment's {@link MemorySegment#address() address} is the starting address of the
* allocated off-heap memory region backing the segment, and the address is
* allocated off-heap region of memory backing the segment, and the address is
* aligned according the provided alignment constraint.
*
* @implSpec
Expand All @@ -256,14 +259,14 @@ static Arena ofShared() {
* S1.asOverlappingSlice(S2).isEmpty() == true
* }
*
* @param byteSize the size (in bytes) of the off-heap memory block backing the native memory segment.
* @param byteSize the size (in bytes) of the off-heap region of memory backing the native memory segment.
* @param byteAlignment the alignment constraint (in bytes) of the off-heap region of memory backing the native memory segment.
* @return a new native memory segment.
* @throws IllegalArgumentException if {@code bytesSize < 0}, {@code alignmentBytes <= 0}, or if {@code alignmentBytes}
* @throws IllegalArgumentException if {@code bytesSize < 0}, {@code byteAlignment <= 0}, or if {@code byteAlignment}
* is not a power of 2.
* @throws IllegalStateException if this arena has already been {@linkplain #close() closed}.
* @throws WrongThreadException if this arena is confined, and this method is called from a thread {@code T}
* other than the arena owner thread.
* @throws WrongThreadException if this arena is confined, and this method is called from a thread
* other than the arena's owner thread.
*/
@Override
default MemorySegment allocate(long byteSize, long byteAlignment) {
Expand Down Expand Up @@ -293,9 +296,9 @@ default MemorySegment allocate(long byteSize, long byteAlignment) {
* @throws IllegalStateException if the arena has already been closed.
* @throws IllegalStateException if a segment associated with this arena is being accessed concurrently, e.g.
* by a {@linkplain Linker#downcallHandle(FunctionDescriptor, Linker.Option...) downcall method handle}.
* @throws WrongThreadException if this arena is confined, and this method is called from a thread {@code T}
* other than the arena owner thread.
* @throws UnsupportedOperationException if this arena does not support explicit closure.
* @throws WrongThreadException if this arena is confined, and this method is called from a thread
* other than the arena's owner thread.
* @throws UnsupportedOperationException if this arena cannot be closed explicitly.
*/
@Override
void close();
Expand Down
Loading

0 comments on commit 9a695ae

Please sign in to comment.