Skip to content

Commit

Permalink
Merge branch 'upstream-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Datadog Syncup Service committed Oct 27, 2023
2 parents bbf8e17 + 2915d74 commit 33be2a4
Show file tree
Hide file tree
Showing 641 changed files with 6,867 additions and 3,838 deletions.
2 changes: 1 addition & 1 deletion make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
# do this on s390x also for libjvm (where serviceability agent is not supported)
if test "x$ENABLE_LINKTIME_GC" = xtrue; then
TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -ffunction-sections -fdata-sections"
if test "x$OPENJDK_TARGET_CPU" = xs390x; then
if test "x$OPENJDK_TARGET_CPU" = xs390x && test "x$DEBUG_LEVEL" == xrelease; then
TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -fdata-sections"
fi
fi
Expand Down
10 changes: 7 additions & 3 deletions src/hotspot/cpu/riscv/c1_LIRAssembler_arith_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void LIR_Assembler::arithmetic_idiv(LIR_Code code, LIR_Opr left, LIR_Opr right,
}
} else {
Register rreg = right->as_register();
__ corrected_idivl(dreg, lreg, rreg, is_irem);
__ corrected_idivl(dreg, lreg, rreg, is_irem, /* is_signed */ true);
}
}

Expand Down Expand Up @@ -172,8 +172,12 @@ void LIR_Assembler::arith_op_double_cpu(LIR_Code code, LIR_Opr left, LIR_Opr rig
case lir_add: __ add(dest->as_register_lo(), lreg_lo, rreg_lo); break;
case lir_sub: __ sub(dest->as_register_lo(), lreg_lo, rreg_lo); break;
case lir_mul: __ mul(dest->as_register_lo(), lreg_lo, rreg_lo); break;
case lir_div: __ corrected_idivq(dest->as_register_lo(), lreg_lo, rreg_lo, false); break;
case lir_rem: __ corrected_idivq(dest->as_register_lo(), lreg_lo, rreg_lo, true); break;
case lir_div: __ corrected_idivq(dest->as_register_lo(), lreg_lo, rreg_lo,
/* want_remainder */ false, /* is_signed */ true);
break;
case lir_rem: __ corrected_idivq(dest->as_register_lo(), lreg_lo, rreg_lo,
/* want_remainder */ true, /* is_signed */ true);
break;
default:
ShouldNotReachHere();
}
Expand Down
16 changes: 12 additions & 4 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ void MacroAssembler::store_heap_oop_null(Address dst) {
}

int MacroAssembler::corrected_idivl(Register result, Register rs1, Register rs2,
bool want_remainder)
bool want_remainder, bool is_signed)
{
// Full implementation of Java idiv and irem. The function
// returns the (pc) offset of the div instruction - may be needed
Expand All @@ -2402,15 +2402,19 @@ int MacroAssembler::corrected_idivl(Register result, Register rs1, Register rs2,

int idivl_offset = offset();
if (!want_remainder) {
divw(result, rs1, rs2);
if (is_signed) {
divw(result, rs1, rs2);
} else {
divuw(result, rs1, rs2);
}
} else {
remw(result, rs1, rs2); // result = rs1 % rs2;
}
return idivl_offset;
}

int MacroAssembler::corrected_idivq(Register result, Register rs1, Register rs2,
bool want_remainder)
bool want_remainder, bool is_signed)
{
// Full implementation of Java ldiv and lrem. The function
// returns the (pc) offset of the div instruction - may be needed
Expand All @@ -2425,7 +2429,11 @@ int MacroAssembler::corrected_idivq(Register result, Register rs1, Register rs2,

int idivq_offset = offset();
if (!want_remainder) {
div(result, rs1, rs2);
if (is_signed) {
div(result, rs1, rs2);
} else {
divu(result, rs1, rs2);
}
} else {
rem(result, rs1, rs2); // result = rs1 % rs2;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ class MacroAssembler: public Assembler {

// idiv variant which deals with MINLONG as dividend and -1 as divisor
int corrected_idivl(Register result, Register rs1, Register rs2,
bool want_remainder);
bool want_remainder, bool is_signed);
int corrected_idivq(Register result, Register rs1, Register rs2,
bool want_remainder);
bool want_remainder, bool is_signed);

// interface method calling
void lookup_interface_method(Register recv_klass,
Expand Down
43 changes: 39 additions & 4 deletions src/hotspot/cpu/riscv/riscv.ad
Original file line number Diff line number Diff line change
Expand Up @@ -2443,31 +2443,47 @@ encode %{
Register dst_reg = as_Register($dst$$reg);
Register src1_reg = as_Register($src1$$reg);
Register src2_reg = as_Register($src2$$reg);
__ corrected_idivl(dst_reg, src1_reg, src2_reg, false);
__ corrected_idivl(dst_reg, src1_reg, src2_reg, /* want_remainder */ false, /* is_signed */ true);
%}

enc_class riscv_enc_divuw(iRegI dst, iRegI src1, iRegI src2) %{
C2_MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
Register src1_reg = as_Register($src1$$reg);
Register src2_reg = as_Register($src2$$reg);
__ corrected_idivl(dst_reg, src1_reg, src2_reg, /* want_remainder */ false, /* is_signed */ false);
%}

enc_class riscv_enc_div(iRegI dst, iRegI src1, iRegI src2) %{
C2_MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
Register src1_reg = as_Register($src1$$reg);
Register src2_reg = as_Register($src2$$reg);
__ corrected_idivq(dst_reg, src1_reg, src2_reg, false);
__ corrected_idivq(dst_reg, src1_reg, src2_reg, /* want_remainder */ false, /* is_signed */ true);
%}

enc_class riscv_enc_divu(iRegI dst, iRegI src1, iRegI src2) %{
C2_MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
Register src1_reg = as_Register($src1$$reg);
Register src2_reg = as_Register($src2$$reg);
__ corrected_idivq(dst_reg, src1_reg, src2_reg, /* want_remainder */ false, /* is_signed */ false);
%}

enc_class riscv_enc_modw(iRegI dst, iRegI src1, iRegI src2) %{
C2_MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
Register src1_reg = as_Register($src1$$reg);
Register src2_reg = as_Register($src2$$reg);
__ corrected_idivl(dst_reg, src1_reg, src2_reg, true);
__ corrected_idivl(dst_reg, src1_reg, src2_reg, /* want_remainder */ true, /* is_signed */ true);
%}

enc_class riscv_enc_mod(iRegI dst, iRegI src1, iRegI src2) %{
C2_MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
Register src1_reg = as_Register($src1$$reg);
Register src2_reg = as_Register($src2$$reg);
__ corrected_idivq(dst_reg, src1_reg, src2_reg, true);
__ corrected_idivq(dst_reg, src1_reg, src2_reg, /* want_remainder */ true, /* is_signed */ true);
%}

enc_class riscv_enc_tail_call(iRegP jump_target) %{
Expand Down Expand Up @@ -6673,6 +6689,15 @@ instruct divI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{
ins_pipe(idiv_reg_reg);
%}

instruct UdivI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{
match(Set dst (UDivI src1 src2));
ins_cost(IDIVSI_COST);
format %{ "divuw $dst, $src1, $src2\t#@UdivI"%}

ins_encode(riscv_enc_divuw(dst, src1, src2));
ins_pipe(idiv_reg_reg);
%}

instruct signExtract(iRegINoSp dst, iRegIorL2I src1, immI_31 div1, immI_31 div2) %{
match(Set dst (URShiftI (RShiftI src1 div1) div2));
ins_cost(ALU_COST);
Expand All @@ -6695,6 +6720,16 @@ instruct divL(iRegLNoSp dst, iRegL src1, iRegL src2) %{
ins_pipe(ldiv_reg_reg);
%}

instruct UdivL(iRegLNoSp dst, iRegL src1, iRegL src2) %{
match(Set dst (UDivL src1 src2));
ins_cost(IDIVDI_COST);

format %{ "divu $dst, $src1, $src2\t#@UdivL" %}

ins_encode(riscv_enc_divu(dst, src1, src2));
ins_pipe(ldiv_reg_reg);
%}

instruct signExtractL(iRegLNoSp dst, iRegL src1, immI_63 div1, immI_63 div2) %{
match(Set dst (URShiftL (RShiftL src1 div1) div2));
ins_cost(ALU_COST);
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/cpu/riscv/templateTable_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ void TemplateTable::idiv() {
__ bind(no_div0);
__ pop_i(x11);
// x10 <== x11 idiv x10
__ corrected_idivl(x10, x11, x10, /* want_remainder */ false);
__ corrected_idivl(x10, x11, x10, /* want_remainder */ false, /* is_signed */ true);
}

void TemplateTable::irem() {
Expand All @@ -1331,7 +1331,7 @@ void TemplateTable::irem() {
__ bind(no_div0);
__ pop_i(x11);
// x10 <== x11 irem x10
__ corrected_idivl(x10, x11, x10, /* want_remainder */ true);
__ corrected_idivl(x10, x11, x10, /* want_remainder */ true, /* is_signed */ true);
}

void TemplateTable::lmul() {
Expand All @@ -1350,7 +1350,7 @@ void TemplateTable::ldiv() {
__ bind(no_div0);
__ pop_l(x11);
// x10 <== x11 ldiv x10
__ corrected_idivq(x10, x11, x10, /* want_remainder */ false);
__ corrected_idivq(x10, x11, x10, /* want_remainder */ false, /* is_signed */ true);
}

void TemplateTable::lrem() {
Expand All @@ -1363,7 +1363,7 @@ void TemplateTable::lrem() {
__ bind(no_div0);
__ pop_l(x11);
// x10 <== x11 lrem x10
__ corrected_idivq(x10, x11, x10, /* want_remainder */ true);
__ corrected_idivq(x10, x11, x10, /* want_remainder */ true, /* is_signed */ true);
}

void TemplateTable::lshl() {
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ CodeBlob* CodeCache::allocate(int size, CodeBlobType code_blob_type, bool handle
CompileBroker::handle_full_code_cache(orig_code_blob_type);
}
return nullptr;
} else {
OrderAccess::release(); // ensure heap expansion is visible to an asynchronous observer (e.g. CodeHeapPool::get_memory_usage())
}
if (PrintCodeCacheExtension) {
ResourceMark rm;
Expand Down
11 changes: 7 additions & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ void ShenandoahControlThread::handle_requested_gc(GCCause::Cause cause) {
}
}

void ShenandoahControlThread::handle_alloc_failure(ShenandoahAllocRequest& req) {
void ShenandoahControlThread::handle_alloc_failure(ShenandoahAllocRequest& req, bool block) {
ShenandoahHeap* heap = ShenandoahHeap::heap();

assert(current()->is_Java_thread(), "expect Java thread here");
Expand All @@ -539,9 +539,12 @@ void ShenandoahControlThread::handle_alloc_failure(ShenandoahAllocRequest& req)
heap->cancel_gc(GCCause::_allocation_failure);
}

MonitorLocker ml(&_alloc_failure_waiters_lock);
while (is_alloc_failure_gc()) {
ml.wait();

if (block) {
MonitorLocker ml(&_alloc_failure_waiters_lock);
while (is_alloc_failure_gc()) {
ml.wait();
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ class ShenandoahControlThread: public ConcurrentGCThread {
ShenandoahControlThread();
~ShenandoahControlThread();

// Handle allocation failure from normal allocation.
// Blocks until memory is available.
void handle_alloc_failure(ShenandoahAllocRequest& req);
// Handle allocation failure from a mutator allocation.
// Optionally blocks while collector is handling the failure. If the GC
// threshold has been exceeded, the mutator allocation will not block so
// that the out of memory error can be raised promptly.
void handle_alloc_failure(ShenandoahAllocRequest& req, bool block = true);

// Handle allocation failure from evacuation path.
// Optionally blocks while collector is handling the failure.
void handle_alloc_failure_evac(size_t words);

void request_gc(GCCause::Cause cause);
Expand Down
23 changes: 21 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) :
_num_regions(0),
_regions(nullptr),
_update_refs_iterator(this),
_gc_no_progress_count(0),
_control_thread(nullptr),
_shenandoah_policy(policy),
_gc_mode(nullptr),
Expand Down Expand Up @@ -873,7 +874,19 @@ HeapWord* ShenandoahHeap::allocate_memory(ShenandoahAllocRequest& req) {
result = allocate_memory_under_lock(req, in_new_region);
}

// Allocation failed, block until control thread reacted, then retry allocation.
// Check that gc overhead is not exceeded.
//
// Shenandoah will grind along for quite a while allocating one
// object at a time using shared (non-tlab) allocations. This check
// is testing that the GC overhead limit has not been exceeded.
// This will notify the collector to start a cycle, but will raise
// an OOME to the mutator if the last Full GCs have not made progress.
if (result == nullptr && !req.is_lab_alloc() && get_gc_no_progress_count() > ShenandoahNoProgressThreshold) {
control_thread()->handle_alloc_failure(req, false);
return nullptr;
}

// Block until control thread reacted, then retry allocation.
//
// It might happen that one of the threads requesting allocation would unblock
// way later after GC happened, only to fail the second allocation, because
Expand All @@ -882,10 +895,16 @@ HeapWord* ShenandoahHeap::allocate_memory(ShenandoahAllocRequest& req) {
// one full GC has completed).
size_t original_count = shenandoah_policy()->full_gc_count();
while (result == nullptr
&& (_progress_last_gc.is_set() || original_count == shenandoah_policy()->full_gc_count())) {
&& (get_gc_no_progress_count() == 0 || original_count == shenandoah_policy()->full_gc_count())) {
control_thread()->handle_alloc_failure(req);
result = allocate_memory_under_lock(req, in_new_region);
}

if (log_is_enabled(Debug, gc, alloc)) {
ResourceMark rm;
log_debug(gc, alloc)("Thread: %s, Result: " PTR_FORMAT ", Request: %s, Size: " SIZE_FORMAT ", Original: " SIZE_FORMAT ", Latest: " SIZE_FORMAT,
Thread::current()->name(), p2i(result), req.type_string(), req.size(), original_count, get_gc_no_progress_count());
}
} else {
assert(req.is_gc_alloc(), "Can only accept GC allocs here");
result = allocate_memory_under_lock(req, in_new_region);
Expand Down
8 changes: 5 additions & 3 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
ShenandoahSharedFlag _degenerated_gc_in_progress;
ShenandoahSharedFlag _full_gc_in_progress;
ShenandoahSharedFlag _full_gc_move_in_progress;
ShenandoahSharedFlag _progress_last_gc;
ShenandoahSharedFlag _concurrent_strong_root_in_progress;

size_t _gc_no_progress_count;

void set_gc_state_all_threads(char state);
void set_gc_state_mask(uint mask, bool value);

Expand Down Expand Up @@ -370,8 +371,9 @@ class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
void rendezvous_threads();
void recycle_trash();
public:
void notify_gc_progress() { _progress_last_gc.set(); }
void notify_gc_no_progress() { _progress_last_gc.unset(); }
void notify_gc_progress();
void notify_gc_no_progress();
size_t get_gc_no_progress_count() const;

//
// Mark support
Expand Down
12 changes: 12 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ inline WorkerThreads* ShenandoahHeap::safepoint_workers() {
return _safepoint_workers;
}

inline void ShenandoahHeap::notify_gc_progress() {
Atomic::store(&_gc_no_progress_count, (size_t) 0);

}
inline void ShenandoahHeap::notify_gc_no_progress() {
Atomic::inc(&_gc_no_progress_count);
}

inline size_t ShenandoahHeap::get_gc_no_progress_count() const {
return Atomic::load(&_gc_no_progress_count);
}

inline size_t ShenandoahHeap::heap_region_index_containing(const void* addr) const {
uintptr_t region_start = ((uintptr_t) addr);
uintptr_t index = (region_start - (uintptr_t) base()) >> ShenandoahHeapRegion::region_size_bytes_shift();
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoah_globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@
"How many back-to-back Degenerated GCs should happen before " \
"going to a Full GC.") \
\
product(uintx, ShenandoahNoProgressThreshold, 5, EXPERIMENTAL, \
"After this number of consecutive Full GCs fail to make " \
"progress, Shenandoah will raise out of memory errors. Note " \
"that progress is determined by ShenandoahCriticalFreeThreshold") \
\
product(bool, ShenandoahImplicitGCInvokesConcurrent, false, EXPERIMENTAL, \
"Should internally-caused GC requests invoke concurrent cycles, " \
"should they do the stop-the-world (Degenerated / Full GC)? " \
Expand Down
8 changes: 2 additions & 6 deletions src/hotspot/share/runtime/jniHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,9 @@ jobjectRefType JNIHandles::handle_type(JavaThread* thread, jobject handle) {
default:
ShouldNotReachHere();
}
} else {
} else if (is_local_handle(thread, handle) || is_frame_handle(thread, handle)) {
// Not in global storage. Might be a local handle.
if (is_local_handle(thread, handle) || is_frame_handle(thread, handle)) {
result = JNILocalRefType;
} else {
ShouldNotReachHere();
}
result = JNILocalRefType;
}
return result;
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/services/memoryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ CodeHeapPool::CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_us

MemoryUsage CodeHeapPool::get_memory_usage() {
size_t used = used_in_bytes();
OrderAccess::acquire(); // ensure possible cache expansion in CodeCache::allocate is seen
size_t committed = _codeHeap->capacity();
size_t maxSize = (available_for_allocation() ? max_size() : 0);

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/utilities/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ u_char JSON::skip_line_comment() {
return 0;
}
next();
return next();
return peek();
}

/*
Expand Down
Loading

0 comments on commit 33be2a4

Please sign in to comment.