Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,25 @@ void ShenandoahControlThread::service_concurrent_normal_cycle(GCCause::Cause cau
}

bool ShenandoahControlThread::check_cancellation_or_degen(ShenandoahGC::ShenandoahDegenPoint point) {
// Only read the cancellation cause once. Other threads may change it.
ShenandoahHeap* heap = ShenandoahHeap::heap();
if (heap->cancelled_gc()) {
if (heap->cancelled_cause() == GCCause::_shenandoah_stop_vm) {
return true;
}
const GCCause::Cause cancelled_cause = heap->cancelled_cause();
if (cancelled_cause == GCCause::_no_gc) {
return false;
}

if (ShenandoahCollectorPolicy::is_allocation_failure(heap->cancelled_cause())) {
assert (_degen_point == ShenandoahGC::_degenerated_outside_cycle,
"Should not be set yet: %s", ShenandoahGC::degen_point_to_string(_degen_point));
_degen_point = point;
return true;
}
if (cancelled_cause == GCCause::_shenandoah_stop_vm) {
return true;
}

fatal("Unexpected reason for cancellation: %s", GCCause::to_string(heap->cancelled_cause()));
if (ShenandoahCollectorPolicy::is_allocation_failure(cancelled_cause)) {
assert (_degen_point == ShenandoahGC::_degenerated_outside_cycle,
"Should not be set yet: %s", ShenandoahGC::degen_point_to_string(_degen_point));
_degen_point = point;
return true;
}
return false;

fatal("Unexpected reason for cancellation: %s", GCCause::to_string(cancelled_cause));
}

void ShenandoahControlThread::stop_service() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,30 +586,31 @@ void ShenandoahGenerationalControlThread::service_concurrent_cycle(ShenandoahGen
}

bool ShenandoahGenerationalControlThread::check_cancellation_or_degen(ShenandoahGC::ShenandoahDegenPoint point) {
if (!_heap->cancelled_gc()) {
// Only read the cancellation cause once. Other threads may change it.
const GCCause::Cause cancelled_cause = _heap->cancelled_cause();
if (cancelled_cause == GCCause::_no_gc) {
return false;
}

if (_heap->cancelled_cause() == GCCause::_shenandoah_stop_vm
|| _heap->cancelled_cause() == GCCause::_shenandoah_concurrent_gc) {
log_debug(gc, thread)("Cancellation detected, reason: %s", GCCause::to_string(_heap->cancelled_cause()));
if (cancelled_cause == GCCause::_shenandoah_stop_vm
|| cancelled_cause == GCCause::_shenandoah_concurrent_gc) {
log_debug(gc, thread)("Cancellation detected, reason: %s", GCCause::to_string(cancelled_cause));
return true;
}

if (ShenandoahCollectorPolicy::is_allocation_failure(_heap->cancelled_cause())) {
if (ShenandoahCollectorPolicy::is_allocation_failure(cancelled_cause)) {
assert(_degen_point == ShenandoahGC::_degenerated_unset,
"Should not be set yet: %s", ShenandoahGC::degen_point_to_string(_degen_point));
MonitorLocker ml(&_control_lock, Mutex::_no_safepoint_check_flag);
_requested_gc_cause = _heap->cancelled_cause();
_requested_gc_cause = cancelled_cause;
_degen_point = point;
log_debug(gc, thread)("Cancellation detected:, reason: %s, degen point: %s",
GCCause::to_string(_heap->cancelled_cause()),
GCCause::to_string(cancelled_cause),
ShenandoahGC::degen_point_to_string(_degen_point));
return true;
}

fatal("Cancel GC either for alloc failure GC, or gracefully exiting, or to pause old generation marking");
return false;
}

void ShenandoahGenerationalControlThread::service_stw_full_cycle(GCCause::Cause cause) {
Expand Down
14 changes: 12 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2257,8 +2257,18 @@ size_t ShenandoahHeap::tlab_used() const {
}

bool ShenandoahHeap::try_cancel_gc(GCCause::Cause cause) {
const GCCause::Cause prev = _cancelled_gc.xchg(cause);
return prev == GCCause::_no_gc || prev == GCCause::_shenandoah_concurrent_gc;
while (true) {
const GCCause::Cause prev = _cancelled_gc.get();
if (prev != GCCause::_no_gc && prev != GCCause::_shenandoah_concurrent_gc && cause != GCCause::_shenandoah_stop_vm) {
// Only when the gc has not been cancelled, or it has been cancelled to interrupt an old marking cycle
// do we allow the new cancellation request to happen. We make an exception for stopping the VM.
return false;
}

if (_cancelled_gc.cmpxchg(cause, prev) == prev) {
return true;
}
}
}

void ShenandoahHeap::cancel_concurrent_mark() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<!--
Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2026, 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 @@ -65,6 +65,10 @@ <h1 id="ValueBased">{@index "Value-based Classes"}</h1>
because the programmer cannot guarantee exclusive ownership of the
associated monitor.</p>

<p>Use of instances of value-based classes as referents in {@linkplain
java.lang.ref.Reference reference objects} is strongly discouraged,
because these instances do not have reliable identity.</p>

<p>Identity-related behavior of value-based classes may change in a future release.
For example, synchronization may fail.</p>

Expand Down
6 changes: 6 additions & 0 deletions src/java.base/share/classes/java/util/LazyCollections.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@ private static <T> T orElseComputeSlowPath(final T[] array,
final long offset = offsetFor(index);
final Object mutex = mutexes.acquireMutex(offset);
if (mutex == null) {
// There might be a race where the value is already computed and
// the mutex is cleared, so we need to re-check the value again
final T t = (T) UNSAFE.getReferenceAcquire(array, offset);
if (t != null) {
return t;
}
throwIfPreviousException(index, throwables, input);
// There must be an exception
throw cannotReachHere(functionHolder, input);
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/java/net/MulticastSocket/NoLoopbackPackets.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2026, 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 @@ -56,7 +56,7 @@ public static void main(String[] args) throws Exception {
}

NetworkConfiguration nc = NetworkConfiguration.probe();
if (IPSupport.hasIPv6() && nc.hasTestableIPv6Address()) {
if (IPSupport.hasIPv6() && nc.ip6MulticastInterfaces().findAny().isPresent()) {
groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), port));
groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), port));
}
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/java/net/MulticastSocket/Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2026, 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 @@ -141,7 +141,7 @@ void allTests() throws IOException {
doTest("224.80.80.80");

// If IPv6 is enabled perform multicast tests with various scopes
if (nc.hasTestableIPv6Address()) {
if (nc.ip6MulticastInterfaces().findAny().isPresent()) {
doTest("ff01::a");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, 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 @@ -32,13 +32,15 @@
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import jdk.test.lib.security.SecurityUtils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.security.SecurityUtils;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
Expand All @@ -50,29 +52,32 @@
public class DisabledCipherSuitesNotNegotiated {
private static final String TLS_PROTOCOL = "TLSv1.2";
private static volatile int serverPort = 0;
private static volatile Exception serverException = null;

private static final CountDownLatch waitForServer = new CountDownLatch(1);
private static final int WAIT_FOR_SERVER_SECS = 5;
private static final int WAIT_FOR_SERVER_SECS = (int)Utils.adjustTimeout(5);

private static final String DISABLED_CIPHERSUITE = "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384";
private static final String DISABLED_CIPHER_WILDCARD = "TLS_ECDH*WITH_AES_256_GCM_*";
private static volatile Exception serverException = null;

private static void runServer(boolean disabledInClient) throws Exception {
SSLContext ctx = SSLContext.getInstance(TLS_PROTOCOL);
ctx.init(null, null, null);
SSLServerSocketFactory factory = ctx.getServerSocketFactory();
InetAddress address = InetAddress.getLoopbackAddress();
System.out.println("SERVER listening on " + address);
try(SSLServerSocket serverSocket = (SSLServerSocket)factory
.createServerSocket(0, -1, InetAddress.getLoopbackAddress())) {
serverPort = serverSocket.getLocalPort();
waitForServer.countDown();

.createServerSocket(0, -1, address)) {
if (disabledInClient) {
// set cipher suite to disabled ciphersuite
serverSocket.setEnabledCipherSuites(new String[]{DISABLED_CIPHERSUITE});
}

try(SSLSocket clientSocket = (SSLSocket) serverSocket.accept()) {
serverPort = serverSocket.getLocalPort();
serverSocket.setSoTimeout(WAIT_FOR_SERVER_SECS * 3000);
waitForServer.countDown();

try(SSLSocket clientSocket = (SSLSocket)serverSocket.accept()) {
try {
clientSocket.getInputStream().readAllBytes();
throw new Exception("SERVER: The expected handshake exception was not thrown.");
Expand All @@ -88,7 +93,9 @@ private static void runClient(boolean disableInClient, int portNumber) throws Ex
SSLContext ctx = SSLContext.getInstance(TLS_PROTOCOL);
ctx.init(null, null, null);
SSLSocketFactory factory = ctx.getSocketFactory();
try(SSLSocket socket = (SSLSocket)factory.createSocket("localhost", portNumber)) {
InetAddress address = InetAddress.getLoopbackAddress();
System.out.println("CLIENT: Connecting to " + address);
try(SSLSocket socket = (SSLSocket)factory.createSocket(address, portNumber)) {
if (!disableInClient) {
socket.setEnabledCipherSuites(new String[]{DISABLED_CIPHERSUITE});
}
Expand All @@ -104,49 +111,15 @@ private static void runClient(boolean disableInClient, int portNumber) throws Ex

public static void main(String [] args) throws Exception {
if (args.length == 1) {
// run server-side
final boolean disabledInClient = args[0].equals("client");
if (!disabledInClient) {
SecurityUtils.addToDisabledTlsAlgs(DISABLED_CIPHER_WILDCARD);
}
try(ExecutorService executorService = Executors.newSingleThreadExecutor()) {
executorService.submit(() -> {
try {
runServer(disabledInClient);
} catch (Exception exc) {
System.out.println("Server Exception:");
exc.printStackTrace(System.out);
serverException = exc;
throw new RuntimeException(exc);
}
});

if (!waitForServer.await(WAIT_FOR_SERVER_SECS, TimeUnit.SECONDS)) {
throw new Exception("Server did not start within " +
WAIT_FOR_SERVER_SECS + " seconds.");
}

System.out.printf("Server listening on port %d.%nStarting client process...",
serverPort);

OutputAnalyzer oa = ProcessTools.executeProcess(
ProcessTools.createTestJavaProcessBuilder("DisabledCipherSuitesNotNegotiated",
"" + disabledInClient, "" + serverPort));
oa.shouldHaveExitValue(0);
System.out.println("Client output:");
System.out.println(oa.getOutput());
if (serverException != null) {
throw new Exception ("Server-side threw an unexpected exception: "
+ serverException);
}
}
runTest(args[0].equals("client"));

} else if (args.length == 2) {
// run client-side
boolean disabledInClient = Boolean.parseBoolean(args[0]);
if (disabledInClient) {
SecurityUtils.addToDisabledTlsAlgs(DISABLED_CIPHER_WILDCARD);
}

runClient(Boolean.parseBoolean(args[0]), Integer.parseInt(args[1]));

} else {
Expand All @@ -155,4 +128,48 @@ public static void main(String [] args) throws Exception {
}
}

private static void runTest(final boolean disabledInClient) throws Exception {
try(ExecutorService executorService = Executors.newSingleThreadExecutor()) {
Future<?> serverThread = executorService.submit(() -> {
try {
if (!disabledInClient) {
SecurityUtils.addToDisabledTlsAlgs(DISABLED_CIPHER_WILDCARD);
}
runServer(disabledInClient);
} catch (Exception exc) {
serverException = exc;
}
});


if (!waitForServer.await(WAIT_FOR_SERVER_SECS, TimeUnit.SECONDS)) {
throw new Exception("Server did not start within " +
WAIT_FOR_SERVER_SECS + " seconds.");
}

System.out.printf("Server listening on port %d.%nStarting client process...",
serverPort);

OutputAnalyzer oa = ProcessTools.executeProcess(
ProcessTools.createTestJavaProcessBuilder(
"DisabledCipherSuitesNotNegotiated",
"" + disabledInClient, "" + serverPort));
oa.waitFor();
serverThread.get();

System.out.printf("Client process return %d%nCLIENT OUTPUT%n%s%n",
oa.getExitValue(), oa.getOutput());
if (serverException != null) {
System.out.printf(
"Server thread threw an unexpected exception: %s%n",
serverException);
throw serverException;
} else if (oa.getExitValue() != 0) {
throw new Exception(String.format("Client exit code is non-zero (%d). "+
"Server did not throw an exception.",
oa.getExitValue()));
}
}
}

}
Loading