Skip to content

Commit

Permalink
Merge tag 'jdk-24+33' into ola/24.2_jdk-24+33
Browse files Browse the repository at this point in the history
Added tag jdk-24+33 for changeset 53aa9f2
  • Loading branch information
marwan-hallaoui committed Jan 23, 2025
2 parents 5d41760 + 53aa9f2 commit ca99539
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shared/gcVMOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ void VM_GC_Operation::doit_epilogue() {
}

bool VM_GC_HeapInspection::doit_prologue() {
if (_full_gc && UseZGC) {
// ZGC cannot perform a synchronous GC cycle from within the VM thread.
if (_full_gc && (UseZGC || UseShenandoahGC)) {
// ZGC and Shenandoah cannot perform a synchronous GC cycle from within the VM thread.
// So VM_GC_HeapInspection::collect() is a noop. To respect the _full_gc
// flag a synchronous GC cycle is performed from the caller thread in the
// prologue.
Expand Down
16 changes: 15 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,18 @@ size_t ShenandoahHeap::max_tlab_size() const {
return ShenandoahHeapRegion::max_tlab_size_words();
}

void ShenandoahHeap::collect_as_vm_thread(GCCause::Cause cause) {
// These requests are ignored because we can't easily have Shenandoah jump into
// a synchronous (degenerated or full) cycle while it is in the middle of a concurrent
// cycle. We _could_ cancel the concurrent cycle and then try to run a cycle directly
// on the VM thread, but this would confuse the control thread mightily and doesn't
// seem worth the trouble. Instead, we will have the caller thread run (and wait for) a
// concurrent cycle in the prologue of the heap inspect/dump operation. This is how
// other concurrent collectors in the JVM handle this scenario as well.
assert(Thread::current()->is_VM_thread(), "Should be the VM thread");
guarantee(cause == GCCause::_heap_dump || cause == GCCause::_heap_inspection, "Invalid cause");
}

void ShenandoahHeap::collect(GCCause::Cause cause) {
control_thread()->request_gc(cause);
}
Expand Down Expand Up @@ -1548,7 +1560,9 @@ void ShenandoahHeap::set_active_generation() {
void ShenandoahHeap::on_cycle_start(GCCause::Cause cause, ShenandoahGeneration* generation) {
shenandoah_policy()->record_collection_cause(cause);

assert(gc_cause() == GCCause::_no_gc, "Over-writing cause");
const GCCause::Cause current = gc_cause();
assert(current == GCCause::_no_gc, "Over-writing cause: %s, with: %s",
GCCause::to_string(current), GCCause::to_string(cause));
assert(_gc_generation == nullptr, "Over-writing _gc_generation");

set_gc_cause(cause);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ class ShenandoahHeap : public CollectedHeap {
MemRegion reserved_region() const { return _reserved; }
bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }

void collect_as_vm_thread(GCCause::Cause cause) override;
void collect(GCCause::Cause cause) override;
void do_full_collection(bool clear_all_soft_refs) override;

Expand Down
101 changes: 73 additions & 28 deletions src/hotspot/share/opto/subnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,27 +1623,17 @@ Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
return new BoolNode( ncmp, _test.negate() );
}

// Change ((x & (m - 1)) u< m) into (m > 0)
// This is the off-by-one variant of ((x & m) u<= m)
if (cop == Op_CmpU &&
_test._test == BoolTest::lt &&
cmp1_op == Op_AndI) {
Node* l = cmp1->in(1);
Node* r = cmp1->in(2);
for (int repeat = 0; repeat < 2; repeat++) {
bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 &&
r->in(1) == cmp2;
if (match) {
// arraylength known to be non-negative, so a (arraylength != 0) is sufficient,
// but to be compatible with the array range check pattern, use (arraylength u> 0)
Node* ncmp = cmp2->Opcode() == Op_LoadRange
? phase->transform(new CmpUNode(cmp2, phase->intcon(0)))
: phase->transform(new CmpINode(cmp2, phase->intcon(0)));
return new BoolNode(ncmp, BoolTest::gt);
} else {
// commute and try again
l = cmp1->in(2);
r = cmp1->in(1);
// Transform: "((x & (m - 1)) <u m)" or "(((m - 1) & x) <u m)" into "(m >u 0)"
// This is case [CMPU_MASK] which is further described at the method comment of BoolNode::Value_cmpu_and_mask().
if (cop == Op_CmpU && _test._test == BoolTest::lt && cmp1_op == Op_AndI) {
Node* m = cmp2; // RHS: m
for (int add_idx = 1; add_idx <= 2; add_idx++) { // LHS: "(m + (-1)) & x" or "x & (m + (-1))"?
Node* maybe_m_minus_1 = cmp1->in(add_idx);
if (maybe_m_minus_1->Opcode() == Op_AddI &&
maybe_m_minus_1->in(2)->find_int_con(0) == -1 &&
maybe_m_minus_1->in(1) == m) {
Node* m_cmpu_0 = phase->transform(new CmpUNode(m, phase->intcon(0)));
return new BoolNode(m_cmpu_0, BoolTest::gt);
}
}
}
Expand Down Expand Up @@ -1809,24 +1799,79 @@ Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
// }
}

//------------------------------Value------------------------------------------
// Change ((x & m) u<= m) or ((m & x) u<= m) to always true
// Same with ((x & m) u< m+1) and ((m & x) u< m+1)
// We use the following Lemmas/insights for the following two transformations (1) and (2):
// x & y <=u y, for any x and y (Lemma 1, masking always results in a smaller unsigned number)
// y <u y + 1 is always true if y != -1 (Lemma 2, (uint)(-1 + 1) == (uint)(UINT_MAX + 1) which overflows)
// y <u 0 is always false for any y (Lemma 3, 0 == UINT_MIN and nothing can be smaller than that)
//
// (1a) Always: Change ((x & m) <=u m ) or ((m & x) <=u m ) to always true (true by Lemma 1)
// (1b) If m != -1: Change ((x & m) <u m + 1) or ((m & x) <u m + 1) to always true:
// x & m <=u m is always true // (Lemma 1)
// x & m <=u m <u m + 1 is always true // (Lemma 2: m <u m + 1, if m != -1)
//
// A counter example for (1b), if we allowed m == -1:
// (x & m) <u m + 1
// (x & -1) <u 0
// x <u 0
// which is false for any x (Lemma 3)
//
// (2) Change ((x & (m - 1)) <u m) or (((m - 1) & x) <u m) to (m >u 0)
// This is the off-by-one variant of the above.
//
// We now prove that this replacement is correct. This is the same as proving
// "m >u 0" if and only if "x & (m - 1) <u m", i.e. "m >u 0 <=> x & (m - 1) <u m"
//
// We use (Lemma 1) and (Lemma 3) from above.
//
// Case "x & (m - 1) <u m => m >u 0":
// We prove this by contradiction:
// Assume m <=u 0 which is equivalent to m == 0:
// and thus
// x & (m - 1) <u m = 0 // m == 0
// y <u 0 // y = x & (m - 1)
// by Lemma 3, this is always false, i.e. a contradiction to our assumption.
//
// Case "m >u 0 => x & (m - 1) <u m":
// x & (m - 1) <=u (m - 1) // (Lemma 1)
// x & (m - 1) <=u (m - 1) <u m // Using assumption m >u 0, no underflow of "m - 1"
//
//
// Note that the signed version of "m > 0":
// m > 0 <=> x & (m - 1) <u m
// does not hold:
// Assume m == -1 and x == -1:
// x & (m - 1) <u m
// -1 & -2 <u -1
// -2 <u -1
// UINT_MAX - 1 <u UINT_MAX // Signed to unsigned numbers
// which is true while
// m > 0
// is false which is a contradiction.
//
// (1a) and (1b) is covered by this method since we can directly return a true value as type while (2) is covered
// in BoolNode::Ideal since we create a new non-constant node (see [CMPU_MASK]).
const Type* BoolNode::Value_cmpu_and_mask(PhaseValues* phase) const {
Node* cmp = in(1);
if (cmp != nullptr && cmp->Opcode() == Op_CmpU) {
Node* cmp1 = cmp->in(1);
Node* cmp2 = cmp->in(2);

if (cmp1->Opcode() == Op_AndI) {
Node* bound = nullptr;
Node* m = nullptr;
if (_test._test == BoolTest::le) {
bound = cmp2;
// (1a) "((x & m) <=u m)", cmp2 = m
m = cmp2;
} else if (_test._test == BoolTest::lt && cmp2->Opcode() == Op_AddI && cmp2->in(2)->find_int_con(0) == 1) {
bound = cmp2->in(1);
// (1b) "(x & m) <u m + 1" and "(m & x) <u m + 1", cmp2 = m + 1
Node* rhs_m = cmp2->in(1);
const TypeInt* rhs_m_type = phase->type(rhs_m)->isa_int();
if (rhs_m_type->_lo > -1 || rhs_m_type->_hi < -1) {
// Exclude any case where m == -1 is possible.
m = rhs_m;
}
}

if (cmp1->in(2) == bound || cmp1->in(1) == bound) {
if (cmp1->in(2) == m || cmp1->in(1) == m) {
return TypeInt::ONE;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/hotspot/share/services/heapDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,11 +2349,10 @@ void VM_HeapDumper::dump_threads(AbstractDumpWriter* writer) {
}

bool VM_HeapDumper::doit_prologue() {
if (_gc_before_heap_dump && UseZGC) {
// ZGC cannot perform a synchronous GC cycle from within the VM thread.
// So ZCollectedHeap::collect_as_vm_thread() is a noop. To respect the
// _gc_before_heap_dump flag a synchronous GC cycle is performed from
// the caller thread in the prologue.
if (_gc_before_heap_dump && (UseZGC || UseShenandoahGC)) {
// ZGC and Shenandoah cannot perform a synchronous GC cycle from within the VM thread.
// So collect_as_vm_thread() is a noop. To respect the _gc_before_heap_dump flag a
// synchronous GC cycle is performed from the caller thread in the prologue.
Universe::heap()->collect(GCCause::_heap_dump);
}
return VM_GC_Operation::doit_prologue();
Expand Down
41 changes: 35 additions & 6 deletions src/java.base/share/man/java.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1994, 2025, 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 @@ -4002,11 +4002,40 @@ archive, you should make sure that the archive is created by at least version
- The CDS archive cannot be loaded if any JAR files in the class path or
module path are modified after the archive is generated.

- If any of the VM options `--upgrade-module-path`, `--patch-module` or
`--limit-modules` are specified, CDS is disabled. This means that the
JVM will execute without loading any CDS archives. In addition, if
you try to create a CDS archive with any of these 3 options specified,
the JVM will report an error.
### Module related options

The following module related options are supported by CDS: `--module-path`, `--module`,
`--add-modules`, and `--enable-native-access`.

The values for these options (if specified), should be identical when creating and using the
CDS archive. Otherwise, if there is a mismatch of any of these options, the CDS archive may be
partially or completely disabled, leading to lower performance.

- If the -XX:+AOTClassLinking options *was* used during CDS archive creation, the CDS archive
cannot be used, and the following error message is printed:

`CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used`

- If the -XX:+AOTClassLinking options *was not* used during CDS archive creation, the CDS archive
can be used, but the "archived module graph" feature will be disabled. This can lead to increased
start-up time.

To diagnose problems with the above options, you can add `-Xlog:cds` to the application's VM
arguments. For example, if `--add-modules jdk.jconcole` was specified during archive creation
and `--add-modules jdk.incubator.vector` is specified during runtime, the following messages will
be logged:

`Mismatched values for property jdk.module.addmods`

`runtime jdk.incubator.vector dump time jdk.jconsole`

`subgraph jdk.internal.module.ArchivedBootLayer cannot be used because full module graph is disabled`

If any of the VM options `--upgrade-module-path`, `--patch-module` or
`--limit-modules` are specified, CDS is disabled. This means that the
JVM will execute without loading any CDS archives. In addition, if
you try to create a CDS archive with any of these 3 options specified,
the JVM will report an error.

## Performance Tuning Examples

Expand Down
22 changes: 14 additions & 8 deletions src/java.base/windows/classes/java/lang/ProcessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ private static String[] getTokensFromCommand(String command) {
private static final int VERIFICATION_LEGACY = 3;
// See Command shell overview for documentation of special characters.
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10)
private static final char ESCAPE_VERIFICATION[][] = {
private static final String ESCAPE_VERIFICATION[] = {
// We guarantee the only command file execution for implicit [cmd.exe] run.
// http://technet.microsoft.com/en-us/library/bb490954.aspx
{' ', '\t', '\"', '<', '>', '&', '|', '^'},
{' ', '\t', '\"', '<', '>'},
{' ', '\t', '\"', '<', '>'},
{' ', '\t'}
// All space characters require quoting are checked in needsEscaping().
"\"<>&|^",
"\"<>",
"\"<>",
""
};

private static String createCommandLine(int verificationType,
Expand Down Expand Up @@ -325,9 +326,14 @@ private static boolean needsEscaping(int verificationType, String arg) {
}

if (!argIsQuoted) {
char testEscape[] = ESCAPE_VERIFICATION[verificationType];
for (int i = 0; i < testEscape.length; ++i) {
if (arg.indexOf(testEscape[i]) >= 0) {
for (int i = 0; i < arg.length(); i++) {
char ch = arg.charAt(i);
if (Character.isLetterOrDigit(ch))
continue; // skip over common characters
// All space chars require quotes and other mode specific characters
if (Character.isSpaceChar(ch) ||
Character.isWhitespace(ch) ||
ESCAPE_VERIFICATION[verificationType].indexOf(ch) >= 0) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.desktop/share/native/libawt/java2d/SurfaceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct {

#define UNSAFE_TO_SUB(a, b) \
(((b >= 0) && (a < 0) && (a < (INT_MIN + b))) || \
((b < 0) && (a >= 0) && (-b > (INT_MAX - a)))) \
((b < 0) && (a >= 0) && (a > (INT_MAX + b)))) \

/*
* The SurfaceDataRasInfo structure is used to pass in and return various
Expand Down
57 changes: 39 additions & 18 deletions test/hotspot/jtreg/compiler/c2/gvn/TestBoolNodeGVN.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,47 @@ public static boolean testShouldReplaceCpmUCase1(int x, int m) {
@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@IR(failOn = IRNode.CMP_U,
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldReplaceCpmUCase2(int x, int m) {
return !(Integer.compareUnsigned((m & x), m) > 0);
}

@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@Arguments(values = {Argument.DEFAULT, Argument.RANDOM_EACH})
@IR(failOn = IRNode.CMP_U,
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldReplaceCpmUCase3(int x, int m) {
m = Math.max(0, m);
return Integer.compareUnsigned((x & m), m + 1) < 0;
}

@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@Arguments(values = {Argument.DEFAULT, Argument.RANDOM_EACH})
@IR(failOn = IRNode.CMP_U,
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldReplaceCpmUCase4(int x, int m) {
m = Math.max(0, m);
return Integer.compareUnsigned((m & x), m + 1) < 0;
}

@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@IR(counts = {IRNode.CMP_U, "1"}, // m could be -1 and thus optimization cannot be applied
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldNotReplaceCpmUCase1(int x, int m) {
return Integer.compareUnsigned((x & m), m + 1) < 0;
}

@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@IR(counts = {IRNode.CMP_U, "1"}, // m could be -1 and thus optimization cannot be applied
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldNotReplaceCpmUCase2(int x, int m) {
return Integer.compareUnsigned((m & x), m + 1) < 0;
}

Expand All @@ -92,40 +112,41 @@ public static boolean testShouldHaveCpmUCase1(int x, int m) {
@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@IR(counts = {IRNode.CMP_U, "1"},
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldHaveCpmUCase2(int x, int m) {
return !(Integer.compareUnsigned((m & x), m - 1) > 0);
}

@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@IR(counts = {IRNode.CMP_U, "1"},
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldHaveCpmUCase3(int x, int m) {
return Integer.compareUnsigned((x & m), m + 2) < 0;
}

@Test
@Arguments(values = {Argument.DEFAULT, Argument.DEFAULT})
@IR(counts = {IRNode.CMP_U, "1"},
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
phase = CompilePhase.AFTER_PARSING,
applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"})
public static boolean testShouldHaveCpmUCase4(int x, int m) {
return Integer.compareUnsigned((m & x), m + 2) < 0;
}

private static void testCorrectness() {
int[] values = {
0, 1, 5, 8, 16, 42, 100, new Random().nextInt(0, Integer.MAX_VALUE), Integer.MAX_VALUE
-100, -42, -16, -8, -5, -1, 0, 1, 5, 8, 16, 42, 100,
new Random().nextInt(), Integer.MAX_VALUE, Integer.MIN_VALUE
};

for (int x : values) {
for (int m : values) {
if (!testShouldReplaceCpmUCase1(x, m) |
!testShouldReplaceCpmUCase2(x, m) |
!testShouldReplaceCpmUCase3(x, m) |
if (!testShouldReplaceCpmUCase1(x, m) ||
!testShouldReplaceCpmUCase2(x, m) ||
!testShouldReplaceCpmUCase3(x, m) ||
!testShouldReplaceCpmUCase4(x, m)) {
throw new RuntimeException("Bad result for x = " + x + " and m = " + m + ", expected always true");
}
Expand Down
Loading

0 comments on commit ca99539

Please sign in to comment.