-
Enhancement
-
Resolution: Fixed
-
P4
-
23
-
b13
compiler.compilercontrol.share.scenario.Executor is a test specific class in test/hotspot/jtreg. This class creates a ServerSocket which currently binds to "any address". To prevent interference from other hosts on the network, this test class should bind to only loopback address. The client side of this test class should then create a Socket against the loopback address.
An (untested) patch for this change would look something like:
diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java b/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java
index 424e7e80ad0..67e4263d3ae 100644
--- a/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java
+++ b/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -87,7 +87,7 @@ protected void communicate(String[] args) {
System.out.println("INFO: Client connection port = " + port);
List<String> lines;
try (
- Socket socket = new Socket(InetAddress.getLocalHost(), port);
+ Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(
diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java
index 799fabf9509..9b5b68b98c7 100644
--- a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java
+++ b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -36,6 +36,8 @@
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Executable;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
@@ -80,8 +82,9 @@ public List<OutputAnalyzer> execute() {
// Add class name that would be executed in a separate VM
vmOptions.add(execClass);
OutputAnalyzer output;
- try (ServerSocket serverSocket = new ServerSocket(0)) {
+ try (ServerSocket serverSocket = new ServerSocket()) {
{
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
// Get port test VM will connect to
int port = serverSocket.getLocalPort();
if (port == -1) {
(I haven't checked if there are other test classes which use this Executor class and thus would need to change their Socket instance creation to use the loopback address)
An (untested) patch for this change would look something like:
diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java b/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java
index 424e7e80ad0..67e4263d3ae 100644
--- a/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java
+++ b/test/hotspot/jtreg/compiler/compilercontrol/share/actions/BaseAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -87,7 +87,7 @@ protected void communicate(String[] args) {
System.out.println("INFO: Client connection port = " + port);
List<String> lines;
try (
- Socket socket = new Socket(InetAddress.getLocalHost(), port);
+ Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(
diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java
index 799fabf9509..9b5b68b98c7 100644
--- a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java
+++ b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -36,6 +36,8 @@
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Executable;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
@@ -80,8 +82,9 @@ public List<OutputAnalyzer> execute() {
// Add class name that would be executed in a separate VM
vmOptions.add(execClass);
OutputAnalyzer output;
- try (ServerSocket serverSocket = new ServerSocket(0)) {
+ try (ServerSocket serverSocket = new ServerSocket()) {
{
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
// Get port test VM will connect to
int port = serverSocket.getLocalPort();
if (port == -1) {
(I haven't checked if there are other test classes which use this Executor class and thus would need to change their Socket instance creation to use the loopback address)
- relates to
-
JDK-8327108 compiler.lib.ir_framework.shared.TestFrameworkSocket should listen on loopback address only
- Resolved
-
JDK-8326623 Tests fail with "invalid stream header: 50524920" or encounter unexpected "PRI * HTTP/2.0"
- Closed