diff --git a/src/java.base/share/classes/java/net/HttpURLConnection.java b/src/java.base/share/classes/java/net/HttpURLConnection.java
index b405fb10a1655..625fd30424eea 100644
--- a/src/java.base/share/classes/java/net/HttpURLConnection.java
+++ b/src/java.base/share/classes/java/net/HttpURLConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -373,8 +373,7 @@ protected HttpURLConnection (URL u) {
/**
* Sets whether HTTP redirects (requests with response code 3xx) should
- * be automatically followed by this class. True by default. Applets
- * cannot change this variable.
+ * be automatically followed by this class. True by default.
*
* If there is a security manager, this method first calls
* the security manager's {@code checkSetFactory} method
diff --git a/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java b/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java
index 87ff0d07854ef..11d36ee242d56 100644
--- a/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java
+++ b/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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,7 +36,7 @@
* zero-argument constructor and some number of associated charset
* implementation classes. Charset providers may be installed in an instance
* of the Java platform as extensions. Providers may also be made available by
- * adding them to the applet or application class path or by some other
+ * adding them to the application class path or by some other
* platform-specific means. Charset providers are looked up via the current
* thread's {@link java.lang.Thread#getContextClassLoader() context class
* loader}.
diff --git a/src/java.base/share/classes/javax/crypto/CryptoPermission.java b/src/java.base/share/classes/javax/crypto/CryptoPermission.java
index f13eec7a1d92a..46b5b5fdef6b6 100644
--- a/src/java.base/share/classes/javax/crypto/CryptoPermission.java
+++ b/src/java.base/share/classes/javax/crypto/CryptoPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -39,7 +39,7 @@
* The {@code CryptoPermission} class extends the
* {@code java.security.Permission} class. A
* {@code CryptoPermission} object is used to represent
- * the ability of an application/applet to use certain
+ * the ability of an application to use certain
* algorithms with certain key sizes and other
* restrictions in certain environments.
*
diff --git a/src/java.base/share/classes/javax/crypto/ExemptionMechanism.java b/src/java.base/share/classes/javax/crypto/ExemptionMechanism.java
index c08187d88a646..d360b3577a01c 100644
--- a/src/java.base/share/classes/javax/crypto/ExemptionMechanism.java
+++ b/src/java.base/share/classes/javax/crypto/ExemptionMechanism.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -43,7 +43,7 @@
* of which are key recovery, key weakening, and
* key escrow.
*
- *
Applications or applets that use an exemption mechanism may be granted
+ *
Applications that use an exemption mechanism may be granted
* stronger encryption capabilities than those which don't.
*
* @since 1.4
diff --git a/src/java.base/share/classes/javax/crypto/JceSecurityManager.java b/src/java.base/share/classes/javax/crypto/JceSecurityManager.java
index e9c408a2a56c0..b178c8bfb0253 100644
--- a/src/java.base/share/classes/javax/crypto/JceSecurityManager.java
+++ b/src/java.base/share/classes/javax/crypto/JceSecurityManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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,9 +36,9 @@
* The JCE security manager.
*
*
The JCE security manager is responsible for determining the maximum
- * allowable cryptographic strength for a given applet/application, for a given
+ * allowable cryptographic strength for a given application, for a given
* algorithm, by consulting the configured jurisdiction policy files and
- * the cryptographic permissions bundled with the applet/application.
+ * the cryptographic permissions bundled with the application.
*
* @author Jan Luehe
*
@@ -85,7 +85,7 @@ private JceSecurityManager() {
/**
* Returns the maximum allowable crypto strength for the given
- * applet/application, for the given algorithm.
+ * application, for the given algorithm.
*/
CryptoPermission getCryptoPermission(String theAlg) {
diff --git a/src/java.base/share/classes/javax/net/SocketFactory.java b/src/java.base/share/classes/javax/net/SocketFactory.java
index dd351e9275881..9ef82caf3f9f0 100644
--- a/src/java.base/share/classes/javax/net/SocketFactory.java
+++ b/src/java.base/share/classes/javax/net/SocketFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -60,7 +60,7 @@
*
*
Factory classes are specified by environment-specific configuration
* mechanisms. For example, the getDefault method could return
- * a factory that was appropriate for a particular user or applet, and a
+ * a factory that was appropriate for a particular application, and a
* framework could use a factory customized to its own purposes.
*
* @since 1.4
From bc36ace72c1189dcd6d0c05d40d8c568acd89b01 Mon Sep 17 00:00:00 2001
From: Prasanta Sadhukhan
Date: Thu, 19 Sep 2024 16:22:17 +0000
Subject: [PATCH 012/110] 8340271: Open source several AWT Robot tests
Reviewed-by: abhiscxk, honkar
---
.../java/awt/Robot/CreateScreenCapture.java | 81 ++++++++++++++
test/jdk/java/awt/Robot/RobotScrollTest.java | 101 ++++++++++++++++++
2 files changed, 182 insertions(+)
create mode 100644 test/jdk/java/awt/Robot/CreateScreenCapture.java
create mode 100644 test/jdk/java/awt/Robot/RobotScrollTest.java
diff --git a/test/jdk/java/awt/Robot/CreateScreenCapture.java b/test/jdk/java/awt/Robot/CreateScreenCapture.java
new file mode 100644
index 0000000000000..8060240ba8f1d
--- /dev/null
+++ b/test/jdk/java/awt/Robot/CreateScreenCapture.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4292503
+ * @summary OutOfMemoryError with lots of Robot.createScreenCapture
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @requires (os.family == "linux")
+ * @run main/manual CreateScreenCapture
+*/
+
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.TextArea;
+
+public class CreateScreenCapture {
+
+ static TextArea messageText;
+
+ private static final String INSTRUCTIONS = """
+ This test is linux only!
+ Once you see these instructions, run 'top' program.
+ Watch for java process.
+ The memory size used by this process should stop growing after several steps.
+ Numbers of steps test is performing are displayed in output window.
+ After 5-7 steps the size taken by the process should become stable.
+ If this happens, then test passed otherwise test failed.
+
+ Small oscillations of the memory size are, however, acceptable.""";
+
+ public static void main(String[] args) throws Exception {
+ Robot robot = new Robot();
+ PassFailJFrame passFail = new PassFailJFrame(INSTRUCTIONS);
+ Dialog dialog = new Dialog(new Frame(), "Instructions");
+ messageText = new TextArea("", 5, 80, TextArea.SCROLLBARS_BOTH);
+ dialog.add(messageText);
+ PassFailJFrame.addTestWindow(dialog);
+ PassFailJFrame.positionTestWindow(dialog, PassFailJFrame.Position.HORIZONTAL);
+ dialog.setSize(200, 300);
+ dialog.setVisible(true);
+ Rectangle rect = new Rectangle(0, 0, 1000, 1000);
+ for (int i = 0; i < 100; i++) {
+ Image image = robot.createScreenCapture(rect);
+ image.flush();
+ image = null;
+ robot.delay(200);
+ log("step #" + i);
+ }
+ passFail.awaitAndCheck();
+ }
+
+ private static void log(String messageIn) {
+ messageText.append(messageIn + "\n");
+ }
+}
+
diff --git a/test/jdk/java/awt/Robot/RobotScrollTest.java b/test/jdk/java/awt/Robot/RobotScrollTest.java
new file mode 100644
index 0000000000000..20dc9f2f4ebd9
--- /dev/null
+++ b/test/jdk/java/awt/Robot/RobotScrollTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2001, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4374578
+ * @summary Test robot wheel scrolling of Text
+ * @requires (os.family == "Windows") | (os.family == "linux")
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual RobotScrollTest
+*/
+
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.TextArea;
+
+public class RobotScrollTest {
+
+ static TextArea ta;
+ static Robot robot;
+
+ private static final String INSTRUCTIONS = """
+ 0. DON'T TOUCH ANYTHING!
+ 1. This test is for Windows and Linux only.
+ 2. Just sit back, and watch the Robot move the mouse to the TextArea.
+ 3. Once the pointer is on the text area, the Robot will use the mouse wheel
+ to scroll the text.
+ If the text scrolled, press PASS, else, press FAIL.""";
+
+ public static void main(String[] args) throws Exception {
+ robot = new Robot();
+ robot.setAutoDelay(100);
+ PassFailJFrame passFail = new PassFailJFrame(INSTRUCTIONS);
+ createTestUI();
+ passFail.awaitAndCheck();
+ }
+
+ private static void createTestUI() {
+ Frame f = new Frame("RobotScrollTest");
+ ta = new TextArea();
+ for (int i = 0; i < 100; i++) {
+ ta.append(i + "\n");
+ }
+ f.add(ta);
+ f.setLocation(0, 400);
+ f.pack();
+ PassFailJFrame.addTestWindow(f);
+ PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
+ f.setVisible(true);
+ doTest();
+ }
+
+ private static void doTest() {
+ robot.waitForIdle();
+ robot.delay(1000);
+ // get loc of TextArea
+ Point taAt = ta.getLocationOnScreen();
+ // get bounds of button
+ Rectangle bounds = ta.getBounds();
+
+ // move mouse to middle of button
+ robot.mouseMove(taAt.x + bounds.width / 2,
+ taAt.y + bounds.height / 2);
+
+ // rotate wheel a few times
+ for (int j = 1; j < 8; j++) {
+ for (int k = 0; k < 5; k++) {
+ robot.mouseWheel(j);
+ }
+
+ for (int k = 0; k < 5; k++) {
+ robot.mouseWheel(-1 * j);
+ }
+ }
+ }
+
+}
+
From d1d824008d1dc70029013820814fd03c40b4e309 Mon Sep 17 00:00:00 2001
From: Alexey Ivanov
Date: Thu, 19 Sep 2024 16:59:51 +0000
Subject: [PATCH 013/110] 8340308: PassFailJFrame: Make rows default to number
of lines in instructions
Reviewed-by: honkar, azvegint
---
.../awt/regtesthelpers/PassFailJFrame.java | 36 ++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java b/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java
index 51433faa303fa..e2693e7c555f4 100644
--- a/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java
+++ b/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java
@@ -1184,11 +1184,45 @@ public Builder testTimeOut(long testTimeOut) {
return this;
}
+ /**
+ * Sets the number of rows for displaying the instruction text.
+ * The default value is the number of lines in the text plus 1:
+ * {@code ((int) instructions.lines().count() + 1)}.
+ *
+ * @param rows the number of rows for instruction text
+ * @return this builder
+ */
public Builder rows(int rows) {
this.rows = rows;
return this;
}
+ private int getDefaultRows() {
+ return (int) instructions.lines().count() + 1;
+ }
+
+ /**
+ * Adds a certain number of rows for displaying the instruction text.
+ *
+ * @param rowsAdd the number of rows to add to the number of rows
+ * @return this builder
+ * @see #rows
+ */
+ public Builder rowsAdd(int rowsAdd) {
+ if (rows == 0) {
+ rows = getDefaultRows();
+ }
+ rows += rowsAdd;
+
+ return this;
+ }
+
+ /**
+ * Sets the number of columns for displaying the instruction text.
+ *
+ * @param columns the number of columns for instruction text
+ * @return this builder
+ */
public Builder columns(int columns) {
this.columns = columns;
return this;
@@ -1483,7 +1517,7 @@ private void validate() {
}
if (rows == 0) {
- rows = ROWS;
+ rows = getDefaultRows();
}
if (columns == 0) {
From ec3cba02963b5128480bcf62431ab03ecdb26db6 Mon Sep 17 00:00:00 2001
From: Joe Darcy
Date: Thu, 19 Sep 2024 17:10:23 +0000
Subject: [PATCH 014/110] 8340399: Update comment in SourceVersion for language
evolution history
Reviewed-by: iris
---
.../share/classes/javax/lang/model/SourceVersion.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java
index 4e32f0cdcd88e..871487b98e6f4 100644
--- a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java
+++ b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java
@@ -70,8 +70,14 @@ public enum SourceVersion {
* 21: pattern matching for switch and record patterns (string
* templates in preview, unnamed patterns and variables in
* preview, unnamed classes and instance main methods in preview)
- * 22: Unnamed Variables & Patterns (Statements before super(...)
- * in Preview)
+ * 22: unnamed variables & patterns (statements before super(...)
+ * in preview, string templates in second preview, implicitly
+ * declared classes and instance main methods in second preview)
+ * 23: no changes (primitive Types in Patterns, instanceof, and
+ * switch in preview, module Import Declarations in preview,
+ * implicitly declared classes and instance main in third
+ * preview, flexible constructor bodies in second preview)
+ * 24: tbd
*/
/**
From 15ae1155a11b401e3d1dd39177c209f17f077119 Mon Sep 17 00:00:00 2001
From: Aleksey Shipilev
Date: Thu, 19 Sep 2024 17:47:08 +0000
Subject: [PATCH 015/110] 8340166: [REDO] CDS: Trim down minimum GC region
alignment
Reviewed-by: ccheung, iklam
---
src/hotspot/share/cds/archiveHeapWriter.hpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/hotspot/share/cds/archiveHeapWriter.hpp b/src/hotspot/share/cds/archiveHeapWriter.hpp
index 961d2b52133f8..29ea50ba5fe86 100644
--- a/src/hotspot/share/cds/archiveHeapWriter.hpp
+++ b/src/hotspot/share/cds/archiveHeapWriter.hpp
@@ -111,11 +111,10 @@ class ArchiveHeapWriter : AllStatic {
public:
static const intptr_t NOCOOPS_REQUESTED_BASE = 0x10000000;
- // The minimum region size of all collectors that are supported by CDS in
- // ArchiveHeapLoader::can_map() mode. Currently only G1 is supported. G1's region size
- // depends on -Xmx, but can never be smaller than 1 * M.
- // (TODO: Perhaps change to 256K to be compatible with Shenandoah)
- static constexpr int MIN_GC_REGION_ALIGNMENT = 1 * M;
+ // The minimum region size of all collectors that are supported by CDS.
+ // G1 heap region size can never be smaller than 1M.
+ // Shenandoah heap region size can never be smaller than 256K.
+ static constexpr int MIN_GC_REGION_ALIGNMENT = 256 * K;
private:
class EmbeddedOopRelocator;
From 75d5e117770590d2432fcfe8d89734c7038d4e55 Mon Sep 17 00:00:00 2001
From: William Kemper
Date: Thu, 19 Sep 2024 17:55:23 +0000
Subject: [PATCH 016/110] 8340400: Shenandoah: Whitebox breakpoint GC requests
may cause assertions
Reviewed-by: shade
---
.../gc/shenandoah/shenandoahControlThread.cpp | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp b/src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
index 95a70de5790e9..8a4ef63b8e38b 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
@@ -371,6 +371,16 @@ void ShenandoahControlThread::request_gc(GCCause::Cause cause) {
}
void ShenandoahControlThread::handle_requested_gc(GCCause::Cause cause) {
+ // For normal requested GCs (System.gc) we want to block the caller. However,
+ // for whitebox requested GC, we want to initiate the GC and return immediately.
+ // The whitebox caller thread will arrange for itself to wait until the GC notifies
+ // it that has reached the requested breakpoint (phase in the GC).
+ if (cause == GCCause::_wb_breakpoint) {
+ _requested_gc_cause = cause;
+ _gc_requested.set();
+ return;
+ }
+
// Make sure we have at least one complete GC cycle before unblocking
// from the explicit GC request.
//
@@ -390,9 +400,7 @@ void ShenandoahControlThread::handle_requested_gc(GCCause::Cause cause) {
_requested_gc_cause = cause;
_gc_requested.set();
- if (cause != GCCause::_wb_breakpoint) {
- ml.wait();
- }
+ ml.wait();
current_gc_id = get_gc_id();
}
}
From fde8508379d2983fa70784faef60699c81f9c359 Mon Sep 17 00:00:00 2001
From: Alexander Zuev
Date: Thu, 19 Sep 2024 19:51:05 +0000
Subject: [PATCH 017/110] 8339902: Open source couple TextField related tests
Reviewed-by: honkar
---
.../CaretPositionTest/CaretPositionTest.java | 105 +++++++++++++++
.../SetBoundsTest/SetBoundsTest.java | 124 ++++++++++++++++++
.../SetEchoCharTest4/SetEchoCharTest4.java | 102 ++++++++++++++
.../SetPasswordTest/SetPasswordTest.java | 106 +++++++++++++++
.../ZeroEchoCharTest/ZeroEchoCharTest.java | 90 +++++++++++++
5 files changed, 527 insertions(+)
create mode 100644 test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java
create mode 100644 test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java
create mode 100644 test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java
create mode 100644 test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java
create mode 100644 test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java
diff --git a/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java b/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java
new file mode 100644
index 0000000000000..d55353c4d1fc5
--- /dev/null
+++ b/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * summary:
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.AWTException;
+import java.awt.Button;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.TextField;
+import java.awt.event.InputEvent;
+import java.lang.reflect.InvocationTargetException;
+
+/*
+ * @test
+ * @bug 4038580
+ * @key headful
+ * @requires os.family != "windows"
+ * @summary Caret position not accurate in presence of selected areas
+ * @run main CaretPositionTest
+ */
+
+public class CaretPositionTest extends Frame {
+ private TextField text_field;
+ private Button caretpos_button;
+ private Point onScreen;
+ private Dimension size;
+ String text = "12 45 789";
+ private static volatile int position = -1;
+
+ public static void main(String[] args) throws InterruptedException,
+ InvocationTargetException, AWTException {
+ CaretPositionTest test = new CaretPositionTest();
+ EventQueue.invokeAndWait(test::setupGUI);
+ try {
+ test.test();
+ if (position != 9) {
+ throw new RuntimeException("Caret position should be at the end of the string");
+ }
+ } finally {
+ EventQueue.invokeAndWait(test::dispose);
+ }
+ }
+
+ public void setupGUI() {
+ setLocationRelativeTo(null);
+ setTitle("CaretPositionTest");
+ setLayout(new FlowLayout());
+ text_field = new TextField(text, 9);
+ caretpos_button=new Button("CaretPosition");
+ add(text_field);
+ add(caretpos_button);
+ pack();
+ setVisible(true);
+ toFront();
+ }
+
+ public void test() throws AWTException, InterruptedException,
+ InvocationTargetException {
+ EventQueue.invokeAndWait(() -> {
+ onScreen = text_field.getLocationOnScreen();
+ size = text_field.getSize();
+ });
+ Robot robot = new Robot();
+ robot.setAutoDelay(50);
+ robot.delay(1000);
+ int y = onScreen.y + (size.height / 2);
+ robot.mouseMove(onScreen.x + (size.width / 2), y);
+ robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+ robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+ robot.mouseMove(onScreen.x + 3, y);
+ robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+ for (int x = onScreen.x + 5; x < onScreen.x + size.width; x += 2) {
+ robot.mouseMove(x, y);
+ }
+ robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+ robot.waitForIdle();
+ EventQueue.invokeAndWait(() -> {
+ position = text_field.getCaretPosition();
+ });
+ }
+}
diff --git a/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java b/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java
new file mode 100644
index 0000000000000..68d5d1132a916
--- /dev/null
+++ b/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * summary:
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.Panel;
+import java.awt.ScrollPane;
+import java.awt.TextArea;
+import java.awt.TextField;
+import java.lang.reflect.InvocationTargetException;
+
+/*
+ * @test
+ * @bug 6198290 6277332
+ * @summary TextField painting is broken when placed on a Scrollpane, XToolkit
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual SetBoundsTest
+ */
+
+public class SetBoundsTest extends Frame {
+
+ private static final String INSTRUCTIONS = """
+ 1) Make active a frame with a scrollpane and a few components.
+ 2) Please, focus attention on the text components
+ placed on the upper half of the frame
+ 3) Make sure, that the scrollbar of the frame
+ have the same position during the test.
+ 4) Bring focus to TextField, try deleting the text.
+ If the text never gets erased, the test failed
+ 5) Bring focus to TextArea, try deleting the text.
+ If the text never gets erased, the test failed
+ 6) Please, focus attention on the text components
+ placed on the lower half of the frame
+ 7) Try input something into TextField.
+ If you can not input anything into TextField, the test failed
+ 8) Try input something into TextArea.
+ If you can not input anything into TextArea, the test failed
+ 9) The test passed
+ """;
+
+ public SetBoundsTest() {
+ setTitle("SetBoundsTest Test Frame");
+ setLayout(new GridLayout(2, 1));
+ Panel hw = new Panel();
+ ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
+ Container lw = new Container();
+ fill(hw);
+ fill(lw);
+
+ sp.add(hw);
+ add(sp);
+ add(lw);
+
+ setSize(600, 600);
+ sp.setScrollPosition(20, 0);
+
+ }
+
+ private void fill(Container c) {
+ Button button = new Button("button");
+ c.add(button);
+ button.setBackground(new Color(0xd3ceac));
+ button.setForeground(new Color(0x000000));
+ button.move(60, 80);
+ button.resize(400, 60);
+ button.show(true);
+
+ TextField textfield = new TextField("textfield");
+ c.add(textfield);
+ textfield.setBackground(new Color(0xd3ceac));
+ textfield.setForeground(new Color(0x000000));
+ textfield.move(60, 20);
+ textfield.resize(400, 40);
+ textfield.show(true);
+
+ TextArea textarea = new TextArea("textarea");
+ c.add(textarea);
+ textarea.setBackground(new Color(0xd3ceac));
+ textarea.setForeground(new Color(0x000000));
+ textarea.move(60, 80);
+ textarea.resize(400, 60);
+ textarea.show(true);
+
+ c.setLayout (new FlowLayout());
+ }
+
+ public static void main(String[] args) throws InterruptedException,
+ InvocationTargetException {
+ PassFailJFrame.builder()
+ .title("Set Bounds Test Instructions")
+ .instructions(INSTRUCTIONS)
+ .testUI(SetBoundsTest::new)
+ .rows((int) INSTRUCTIONS.lines().count() + 1)
+ .columns(40)
+ .build()
+ .awaitAndCheck();
+ }
+}
diff --git a/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java b/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java
new file mode 100644
index 0000000000000..471e42f3f8934
--- /dev/null
+++ b/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * summary:
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Button;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.lang.reflect.InvocationTargetException;
+
+/*
+ * @test
+ * @bug 4226580
+ * @summary TextField with echoChar add+remove+add seems to be broken
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual SetEchoCharTest4
+ */
+
+public class SetEchoCharTest4 extends Frame implements ActionListener {
+ TextField tf1 = new TextField(8);
+ TextField tf2 = new TextField(8);
+ TextField tf3 = new TextField(8);
+ Button b = new Button("Click Several Times");
+
+ static final String INSTRUCTIONS = """
+ Type in the first text field and * characters will echo.
+ Type in the second text field and $ characters will echo.
+ Type in the third text field and # characters will echo.
+
+ Hit the button several times. All characters should remain
+ the same and the test should not crash.
+
+ Make sure the actual text matches what you typed in for each field.
+ Press Pass if everything's ok, otherwise Fail
+ """;
+
+ public SetEchoCharTest4() {
+ setLayout(new FlowLayout());
+ tf1.setEchoChar('*');
+ tf2.setEchoChar('$');
+ tf3.setEchoChar('#');
+ addStuff();
+ b.addActionListener(this);
+ setSize (200,200);
+ }
+
+ private void addStuff() {
+ add(tf1);
+ add(tf2);
+ add(tf3);
+ add(b);
+ }
+
+ public void actionPerformed(ActionEvent ae) {
+ PassFailJFrame.log("TextField1 = " + tf1.getText());
+ PassFailJFrame.log("TextField2 = " + tf2.getText());
+ PassFailJFrame.log("TextField3 = " + tf3.getText());
+ PassFailJFrame.log("--------------");
+ setVisible(false);
+ remove(tf1);
+ remove(tf2);
+ remove(tf3);
+ remove(b);
+ addStuff();
+ }
+
+ public static void main(String[] args) throws InterruptedException,
+ InvocationTargetException {
+ PassFailJFrame.builder()
+ .title("Set Echo Character Test")
+ .testUI(SetEchoCharTest4::new)
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 1)
+ .columns(40)
+ .logArea()
+ .build()
+ .awaitAndCheck();
+ }
+}
diff --git a/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java b/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java
new file mode 100644
index 0000000000000..d865ea1451133
--- /dev/null
+++ b/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * summary:
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Button;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.lang.reflect.InvocationTargetException;
+
+/*
+ * @test
+ * @bug 4084454
+ * @summary Make sure that you can set the text in a "password mode"
+ * text field and that it echoes as the current echo char.
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual SetPasswordTest
+ */
+
+public class SetPasswordTest extends Frame implements ActionListener {
+ private String setText = "Set text";
+ private String getText = "Get text";
+ private TextField tfPassword;
+
+ static final String INSTRUCTIONS = """
+ The purpose of this test is to ensure that when using a textField for
+ password entry that text set programmatically is not shown in the clear.
+
+ We also test "pasting" text into the text field.
+
+ 1. Press the "Set Text" button
+ Text should appear as '*' chars
+ - if the string "secret" appears then the test is failed.
+ 2. Use the mouse to select (highlight) all the text and press the DELETE key
+ 3. Use the system's copy/paste functionality to copy a text string from the
+ desktop or this window, and paste it into the text field.
+ 4. Text should appear in the text field as '*' chars
+ - if the string you pasted appears then the test is failed.
+ 5. press the "Get Text" button and the string you pasted
+ should be printed in the log area
+ - if it prints echo symbols instead the test is failed.
+ """;
+
+ public SetPasswordTest() {
+ setLayout(new FlowLayout());
+ tfPassword = new TextField("Initial text", 30);
+ tfPassword.setEchoChar('*');
+ add(tfPassword);
+
+ Button b1 = new Button(setText);
+ b1.addActionListener(this);
+ add(b1);
+
+ Button b2 = new Button(getText);
+ b2.addActionListener(this);
+ add(b2);
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent evt) {
+ String ac = evt.getActionCommand();
+ if (setText.equals(ac)) {
+ tfPassword.setText("secret");
+ }
+
+ if (getText.equals(ac)) {
+ PassFailJFrame.log("Text: \"" + tfPassword.getText() + "\"");
+ }
+ }
+
+ public static void main(String[] args) throws InterruptedException,
+ InvocationTargetException {
+ PassFailJFrame.builder()
+ .title("Set Password Test")
+ .testUI(SetPasswordTest::new)
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 1)
+ .columns(40)
+ .logArea()
+ .build()
+ .awaitAndCheck();
+ }
+}
diff --git a/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java b/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java
new file mode 100644
index 0000000000000..7bdb8ebf4c3ea
--- /dev/null
+++ b/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * summary:
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Button;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.lang.reflect.InvocationTargetException;
+
+/*
+ * @test
+ * @bug 4307281
+ * @summary verify that after setting the echo char to 0 disguises are
+ * removed and user input is echoed to the screen unchanged.
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual ZeroEchoCharTest
+ */
+
+public class ZeroEchoCharTest extends Frame implements ActionListener {
+ private final TextField textfield = new TextField();
+ private final Button button1 = new Button("Set echo char to *");
+ private final Button button2 = new Button("Set echo char to 0");
+ static final String INSTRUCTIONS = """
+ 1.Type in the text field. The user input must be echoed unchanged.
+ 2.Set echo char to '*' by pressing the corresponding button.
+ If all characters in the text field aren't immediately replaced
+ with '*', the test fails.
+ 3.Set echo char to 0 by pressing the corresponding button.
+ If disguises in the text field don't immediately revert to
+ the original characters, the test fails.
+ 4.Type in the text field. If the input is echoed unchanged,
+ the test passes. Otherwise, the test fails.
+ """;
+
+ public ZeroEchoCharTest() {
+ button1.addActionListener(this);
+ button2.addActionListener(this);
+
+ setLayout(new GridLayout(3, 1));
+
+ add(textfield);
+ add(button1);
+ add(button2);
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ if (event.getSource() == button1) {
+ textfield.setEchoChar('*');
+ } else if (event.getSource() == button2) {
+ textfield.setEchoChar((char)0);
+ }
+ }
+
+ public static void main(String[] args) throws InterruptedException,
+ InvocationTargetException {
+ PassFailJFrame.builder()
+ .title("Zero Echo Char Test")
+ .testUI(ZeroEchoCharTest::new)
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 1)
+ .columns(40)
+ .build()
+ .awaitAndCheck();
+ }
+}
From 296b49634eed83bca6cfdee514b9c7c4f8252d59 Mon Sep 17 00:00:00 2001
From: Kim Barrett
Date: Thu, 19 Sep 2024 21:06:46 +0000
Subject: [PATCH 018/110] 8340353: Remove CompressedOops::ptrs_base
Reviewed-by: stefank, coleenp, shade, mli
---
src/hotspot/cpu/aarch64/aarch64.ad | 2 +-
src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp | 6 +++---
src/hotspot/cpu/riscv/macroAssembler_riscv.cpp | 4 ++--
src/hotspot/cpu/x86/macroAssembler_x86.cpp | 6 +++---
src/hotspot/share/oops/compressedOops.hpp | 6 ++----
5 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad
index fced9cfc35e57..39eae43a287e7 100644
--- a/src/hotspot/cpu/aarch64/aarch64.ad
+++ b/src/hotspot/cpu/aarch64/aarch64.ad
@@ -1244,7 +1244,7 @@ source %{
// r27 is not allocatable when compressed oops is on and heapbase is not
// zero, compressed klass pointers doesn't use r27 after JDK-8234794
- if (UseCompressedOops && (CompressedOops::ptrs_base() != nullptr)) {
+ if (UseCompressedOops && (CompressedOops::base() != nullptr)) {
_NO_SPECIAL_REG32_mask.Remove(OptoReg::as_OptoReg(r27->as_VMReg()));
_NO_SPECIAL_REG_mask.Remove(OptoReg::as_OptoReg(r27->as_VMReg()));
_NO_SPECIAL_PTR_REG_mask.Remove(OptoReg::as_OptoReg(r27->as_VMReg()));
diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
index 08b69b34a9462..c5c02619d446e 100644
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
@@ -2967,7 +2967,7 @@ void MacroAssembler::verify_heapbase(const char* msg) {
if (CheckCompressedOops) {
Label ok;
push(1 << rscratch1->encoding(), sp); // cmpptr trashes rscratch1
- cmpptr(rheapbase, ExternalAddress(CompressedOops::ptrs_base_addr()));
+ cmpptr(rheapbase, ExternalAddress(CompressedOops::base_addr()));
br(Assembler::EQ, ok);
stop(msg);
bind(ok);
@@ -3133,9 +3133,9 @@ void MacroAssembler::reinit_heapbase()
{
if (UseCompressedOops) {
if (Universe::is_fully_initialized()) {
- mov(rheapbase, CompressedOops::ptrs_base());
+ mov(rheapbase, CompressedOops::base());
} else {
- lea(rheapbase, ExternalAddress(CompressedOops::ptrs_base_addr()));
+ lea(rheapbase, ExternalAddress(CompressedOops::base_addr()));
ldr(rheapbase, Address(rheapbase));
}
}
diff --git a/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp b/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
index de0df45bbf507..dc25172da259e 100644
--- a/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
+++ b/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
@@ -1970,9 +1970,9 @@ int MacroAssembler::patch_oop(address insn_addr, address o) {
void MacroAssembler::reinit_heapbase() {
if (UseCompressedOops) {
if (Universe::is_fully_initialized()) {
- mv(xheapbase, CompressedOops::ptrs_base());
+ mv(xheapbase, CompressedOops::base());
} else {
- ExternalAddress target(CompressedOops::ptrs_base_addr());
+ ExternalAddress target(CompressedOops::base_addr());
relocate(target.rspec(), [&] {
int32_t offset;
la(xheapbase, target.target(), offset);
diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp
index d634c1e575799..893ae4e844ba4 100644
--- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp
@@ -5756,7 +5756,7 @@ void MacroAssembler::verify_heapbase(const char* msg) {
assert (Universe::heap() != nullptr, "java heap should be initialized");
if (CheckCompressedOops) {
Label ok;
- ExternalAddress src2(CompressedOops::ptrs_base_addr());
+ ExternalAddress src2(CompressedOops::base_addr());
const bool is_src2_reachable = reachable(src2);
if (!is_src2_reachable) {
push(rscratch1); // cmpptr trashes rscratch1
@@ -6047,10 +6047,10 @@ void MacroAssembler::reinit_heapbase() {
if (CompressedOops::base() == nullptr) {
MacroAssembler::xorptr(r12_heapbase, r12_heapbase);
} else {
- mov64(r12_heapbase, (int64_t)CompressedOops::ptrs_base());
+ mov64(r12_heapbase, (int64_t)CompressedOops::base());
}
} else {
- movptr(r12_heapbase, ExternalAddress(CompressedOops::ptrs_base_addr()));
+ movptr(r12_heapbase, ExternalAddress(CompressedOops::base_addr()));
}
}
}
diff --git a/src/hotspot/share/oops/compressedOops.hpp b/src/hotspot/share/oops/compressedOops.hpp
index cd3f00393ca44..a33c8e0c10380 100644
--- a/src/hotspot/share/oops/compressedOops.hpp
+++ b/src/hotspot/share/oops/compressedOops.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 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
@@ -88,15 +88,13 @@ class CompressedOops : public AllStatic {
static void set_use_implicit_null_checks(bool use);
static address base() { return _narrow_oop._base; }
+ static address base_addr() { return (address)&_narrow_oop._base; }
static address begin() { return (address)_heap_address_range.start(); }
static address end() { return (address)_heap_address_range.end(); }
static bool is_base(void* addr) { return (base() == (address)addr); }
static int shift() { return _narrow_oop._shift; }
static bool use_implicit_null_checks() { return _narrow_oop._use_implicit_null_checks; }
- static address ptrs_base_addr() { return (address)&_narrow_oop._base; }
- static address ptrs_base() { return _narrow_oop._base; }
-
static bool is_in(void* addr);
static bool is_in(MemRegion mr);
From fdc16a373459cb2311316448c765b1bee5c73694 Mon Sep 17 00:00:00 2001
From: Phil Race
Date: Thu, 19 Sep 2024 22:20:05 +0000
Subject: [PATCH 019/110] 8340480: Bad copyright notices in changes from
JDK-8339902
Reviewed-by: kcr, bpb, kizune
---
.../java/awt/TextField/CaretPositionTest/CaretPositionTest.java | 1 -
test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java | 1 -
.../java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java | 1 -
test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java | 1 -
.../java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java | 1 -
5 files changed, 5 deletions(-)
diff --git a/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java b/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java
index d55353c4d1fc5..56a39758874e6 100644
--- a/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java
+++ b/test/jdk/java/awt/TextField/CaretPositionTest/CaretPositionTest.java
@@ -2,7 +2,6 @@
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * summary:
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
diff --git a/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java b/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java
index 68d5d1132a916..e37f69232ebec 100644
--- a/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java
+++ b/test/jdk/java/awt/TextField/SetBoundsTest/SetBoundsTest.java
@@ -2,7 +2,6 @@
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * summary:
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
diff --git a/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java b/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java
index 471e42f3f8934..c1cc07afac0ad 100644
--- a/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java
+++ b/test/jdk/java/awt/TextField/SetEchoCharTest4/SetEchoCharTest4.java
@@ -2,7 +2,6 @@
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * summary:
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
diff --git a/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java b/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java
index d865ea1451133..cff5e3750173e 100644
--- a/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java
+++ b/test/jdk/java/awt/TextField/SetPasswordTest/SetPasswordTest.java
@@ -2,7 +2,6 @@
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * summary:
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
diff --git a/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java b/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java
index 7bdb8ebf4c3ea..274cec225729c 100644
--- a/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java
+++ b/test/jdk/java/awt/TextField/ZeroEchoCharTest/ZeroEchoCharTest.java
@@ -2,7 +2,6 @@
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * summary:
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
From 969c2af95387992c55a2e1768de848a354e74127 Mon Sep 17 00:00:00 2001
From: David Holmes
Date: Thu, 19 Sep 2024 23:45:26 +0000
Subject: [PATCH 020/110] 8339192: Native annotation parsing code of deprecated
annotations causes crash
Reviewed-by: jrose, mgronlun
---
.../share/classfile/classFileParser.cpp | 46 +++--
.../BadContendedGroupBadCPIndex.jcod | 123 +++++++++++++
.../BadContendedGroupWrongType.jcod | 123 +++++++++++++
.../BadDeprecatedExtraMemberAtEnd.jcod | 163 ++++++++++++++++++
.../BadDeprecatedExtraMemberAtStart.jcod | 163 ++++++++++++++++++
.../BadDeprecatedForRemovalBadCPIndex.jcod | 155 +++++++++++++++++
.../BadDeprecatedForRemovalWrongType.jcod | 155 +++++++++++++++++
.../BadDeprecatedSinceWrongType.jcod | 155 +++++++++++++++++
.../Annotations/TestBadAnnotations.java | 64 +++++++
9 files changed, 1134 insertions(+), 13 deletions(-)
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadContendedGroupBadCPIndex.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadContendedGroupWrongType.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtEnd.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtStart.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalBadCPIndex.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalWrongType.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/BadDeprecatedSinceWrongType.jcod
create mode 100644 test/hotspot/jtreg/runtime/Annotations/TestBadAnnotations.java
diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp
index 60fed287df594..c8e95149b7c1a 100644
--- a/src/hotspot/share/classfile/classFileParser.cpp
+++ b/src/hotspot/share/classfile/classFileParser.cpp
@@ -1150,30 +1150,40 @@ static void parse_annotations(const ConstantPool* const cp,
if (AnnotationCollector::_unknown == id) continue;
coll->set_annotation(id);
if (AnnotationCollector::_java_lang_Deprecated == id) {
- assert(count <= 2, "change this if more element-value pairs are added to the @Deprecated annotation");
- // @Deprecated can specify forRemoval=true
+ // @Deprecated can specify forRemoval=true, which we need
+ // to record for JFR to use. If the annotation is not well-formed
+ // then we may not be able to determine that.
const u1* offset = abase + member_off;
- for (int i = 0; i < count; ++i) {
+ // There are only 2 members in @Deprecated.
+ int n_members = MIN2(count, 2);
+ for (int i = 0; i < n_members; ++i) {
int member_index = Bytes::get_Java_u2((address)offset);
offset += 2;
member = check_symbol_at(cp, member_index);
- if (member == vmSymbols::since()) {
- assert(*((address)offset) == s_tag_val, "invariant");
+ if (member == vmSymbols::since() &&
+ (*((address)offset) == s_tag_val)) {
+ // Found `since` first so skip over it
offset += 3;
- continue;
}
- if (member == vmSymbols::for_removal()) {
- assert(*((address)offset) == b_tag_val, "invariant");
+ else if (member == vmSymbols::for_removal() &&
+ (*((address)offset) == b_tag_val)) {
const u2 boolean_value_index = Bytes::get_Java_u2((address)offset + 1);
- if (cp->int_at(boolean_value_index) == 1) {
+ // No guarantee the entry is valid so check it refers to an int in the CP.
+ if (cp->is_within_bounds(boolean_value_index) &&
+ cp->tag_at(boolean_value_index).is_int() &&
+ cp->int_at(boolean_value_index) == 1) {
// forRemoval == true
coll->set_annotation(AnnotationCollector::_java_lang_Deprecated_for_removal);
}
+ break; // no need to check further
+ }
+ else {
+ // This @Deprecated annotation is malformed so we don't try to
+ // determine whether forRemoval is set.
break;
}
-
}
- continue;
+ continue; // proceed to next annotation
}
if (AnnotationCollector::_jdk_internal_vm_annotation_Contended == id) {
@@ -1194,11 +1204,21 @@ static void parse_annotations(const ConstantPool* const cp,
&& s_tag_val == *(abase + tag_off)
&& member == vmSymbols::value_name()) {
group_index = Bytes::get_Java_u2((address)abase + s_con_off);
- if (cp->symbol_at(group_index)->utf8_length() == 0) {
- group_index = 0; // default contended group
+ // No guarantee the group_index is valid so check it refers to a
+ // symbol in the CP.
+ if (cp->is_within_bounds(group_index) &&
+ cp->tag_at(group_index).is_utf8()) {
+ // Seems valid, so check for empty string and reset
+ if (cp->symbol_at(group_index)->utf8_length() == 0) {
+ group_index = 0; // default contended group
+ }
+ } else {
+ // Not valid so use the default
+ group_index = 0;
}
}
coll->set_contended_group(group_index);
+ continue; // proceed to next annotation
}
}
}
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadContendedGroupBadCPIndex.jcod b/test/hotspot/jtreg/runtime/Annotations/BadContendedGroupBadCPIndex.jcod
new file mode 100644
index 0000000000000..4802548926b42
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadContendedGroupBadCPIndex.jcod
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ * public class ContendedField {
+ * @Contended("group1")
+ * public int field;
+ * }
+ *
+ * We change the value of "value" so it refers to an invalid CP entry
+ */
+
+class BadContendedGroupBadCPIndex {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [19] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadContendedGroupBadCPIndex"; // #8 at 0x3C
+ Utf8 "field"; // #9 at 0x4D
+ Utf8 "I"; // #10 at 0x55
+ Utf8 "RuntimeVisibleAnnotations"; // #11 at 0x59
+ Utf8 "Ljdk/internal/vm/annotation/Contended;"; // #12 at 0x75
+ Utf8 "value"; // #13 at 0x9E
+ Utf8 "group1"; // #14 at 0xA6
+ Utf8 "Code"; // #15 at 0xAF
+ Utf8 "LineNumberTable"; // #16 at 0xB6
+ Utf8 "SourceFile"; // #17 at 0xC8
+ Utf8 "BadContendedGroupBadCPIndex.java"; // #18 at 0xD5
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [1] { // Fields
+ { // field at 0xF5
+ 0x0001; // access
+ #9; // name_index : field
+ #10; // descriptor_index : I
+ [1] { // Attributes
+ Attr(#11, 11) { // RuntimeVisibleAnnotations at 0xFD
+ [1] { // annotations
+ { // annotation
+ #12;
+ [1] { // element_value_pairs
+ { // element value pair
+ #13;
+ { // element_value
+ 's';
+ #1400; // Changed from #14 to #1400
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Fields
+
+ [1] { // Methods
+ { // method at 0x0110
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#15, 29) { // Code at 0x0118
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#16, 6) { // LineNumberTable at 0x012F
+ [1] { // line_number_table
+ 0 2; // at 0x013B
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#17, 2) { // SourceFile at 0x013D
+ #18;
+ } // end SourceFile
+ } // Attributes
+} // end class BadContendedGroupBadCPIndex
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadContendedGroupWrongType.jcod b/test/hotspot/jtreg/runtime/Annotations/BadContendedGroupWrongType.jcod
new file mode 100644
index 0000000000000..6fa53f939b3dd
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadContendedGroupWrongType.jcod
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ * public class ContendedField {
+ * @Contended("group1")
+ * public int field;
+ * }
+ *
+ * We change the value of "value" so it refers to the wrong type of CP entry
+ */
+
+class BadContendedGroupWrongType {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [19] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadContendedGroupWrongType"; // #8 at 0x3C
+ Utf8 "field"; // #9 at 0x4D
+ Utf8 "I"; // #10 at 0x55
+ Utf8 "RuntimeVisibleAnnotations"; // #11 at 0x59
+ Utf8 "Ljdk/internal/vm/annotation/Contended;"; // #12 at 0x75
+ Utf8 "value"; // #13 at 0x9E
+ Utf8 "group1"; // #14 at 0xA6
+ Utf8 "Code"; // #15 at 0xAF
+ Utf8 "LineNumberTable"; // #16 at 0xB6
+ Utf8 "SourceFile"; // #17 at 0xC8
+ Utf8 "BadContendedGroupWrongType.java"; // #18 at 0xD5
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [1] { // Fields
+ { // field at 0xF5
+ 0x0001; // access
+ #9; // name_index : field
+ #10; // descriptor_index : I
+ [1] { // Attributes
+ Attr(#11, 11) { // RuntimeVisibleAnnotations at 0xFD
+ [1] { // annotations
+ { // annotation
+ #12;
+ [1] { // element_value_pairs
+ { // element value pair
+ #13;
+ { // element_value
+ 's';
+ #7; // Changed from #14 (utf8) to #7 (class)
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Fields
+
+ [1] { // Methods
+ { // method at 0x0110
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#15, 29) { // Code at 0x0118
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#16, 6) { // LineNumberTable at 0x012F
+ [1] { // line_number_table
+ 0 2; // at 0x013B
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#17, 2) { // SourceFile at 0x013D
+ #18;
+ } // end SourceFile
+ } // Attributes
+} // end class BadContendedGroupWrongType
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtEnd.jcod b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtEnd.jcod
new file mode 100644
index 0000000000000..991c4c832b3dc
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtEnd.jcod
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ *
+ * public class DeprecatedMethod {
+ * @Deprecated(forRemoval=true, since="now")
+ * public static void m() {}
+ * }
+ *
+ * We add an extra junk member at the end.
+ */
+
+class BadDeprecatedExtraMemberAtEnd {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [21] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadDeprecatedExtraMemberAtEnd"; // #8 at 0x3C
+ Utf8 "Code"; // #9 at 0x4F
+ Utf8 "LineNumberTable"; // #10 at 0x56
+ Utf8 "m"; // #11 at 0x68
+ Utf8 "Deprecated"; // #12 at 0x6C
+ Utf8 "RuntimeVisibleAnnotations"; // #13 at 0x79
+ Utf8 "Ljava/lang/Deprecated;"; // #14 at 0x95
+ Utf8 "forRemoval"; // #15 at 0xAE
+ int 0x00000001; // #16 at 0xBB
+ Utf8 "since"; // #17 at 0xC0
+ Utf8 "now"; // #18 at 0xC8
+ Utf8 "SourceFile"; // #19 at 0xCE
+ Utf8 "BadDeprecatedExtraMemberAtEnd.java"; // #20 at 0xDB
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [0] { // Fields
+ } // Fields
+
+ [2] { // Methods
+ { // method at 0xFF
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#9, 29) { // Code at 0x0107
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x011E
+ [1] { // line_number_table
+ 0 1; // at 0x012A
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ ;
+ { // method at 0x012A
+ 0x0009; // access
+ #11; // name_index : m
+ #6; // descriptor_index : ()V
+ [3] { // Attributes
+ Attr(#9, 25) { // Code at 0x0132
+ 0; // max_stack
+ 0; // max_locals
+ Bytes[1]{
+ 0xB1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x0145
+ [1] { // line_number_table
+ 0 4; // at 0x0151
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ ;
+ Attr(#12, 0) { // Deprecated at 0x0151
+ } // end Deprecated
+ ;
+ Attr(#13, 21) { // RuntimeVisibleAnnotations at 0x0157 (length changed from 16 to 21)
+ [1] { // annotations
+ { // annotation
+ #14;
+ [3] { // element_value_pairs <= extra pair added
+ { // element value pair
+ #15;
+ { // element_value
+ 'Z';
+ #16;
+ } // element_value
+ } // element value pair
+ ;
+ { // element value pair
+ #17;
+ { // element_value
+ 's';
+ #18;
+ } // element_value
+ } // element value pair
+ ;
+ { // Extra element value pair: now=true
+ #18;
+ { // element_value
+ 'Z';
+ #16;
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#19, 2) { // SourceFile at 0x016F
+ #20;
+ } // end SourceFile
+ } // Attributes
+} // end class BadDeprecatedExtraMemberAtEnd
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtStart.jcod b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtStart.jcod
new file mode 100644
index 0000000000000..0adf08049fd6e
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedExtraMemberAtStart.jcod
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ *
+ * public class DeprecatedMethod {
+ * @Deprecated(forRemoval=true, since="now")
+ * public static void m() {}
+ * }
+ *
+ * We add an extra junk member at the start.
+ */
+
+class BadDeprecatedExtraMemberAtStart {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [21] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadDeprecatedExtraMemberAtStart"; // #8 at 0x3C
+ Utf8 "Code"; // #9 at 0x4F
+ Utf8 "LineNumberTable"; // #10 at 0x56
+ Utf8 "m"; // #11 at 0x68
+ Utf8 "Deprecated"; // #12 at 0x6C
+ Utf8 "RuntimeVisibleAnnotations"; // #13 at 0x79
+ Utf8 "Ljava/lang/Deprecated;"; // #14 at 0x95
+ Utf8 "forRemoval"; // #15 at 0xAE
+ int 0x00000001; // #16 at 0xBB
+ Utf8 "since"; // #17 at 0xC0
+ Utf8 "now"; // #18 at 0xC8
+ Utf8 "SourceFile"; // #19 at 0xCE
+ Utf8 "BadDeprecatedExtraMemberAtStart.java"; // #20 at 0xDB
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [0] { // Fields
+ } // Fields
+
+ [2] { // Methods
+ { // method at 0xFF
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#9, 29) { // Code at 0x0107
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x011E
+ [1] { // line_number_table
+ 0 1; // at 0x012A
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ ;
+ { // method at 0x012A
+ 0x0009; // access
+ #11; // name_index : m
+ #6; // descriptor_index : ()V
+ [3] { // Attributes
+ Attr(#9, 25) { // Code at 0x0132
+ 0; // max_stack
+ 0; // max_locals
+ Bytes[1]{
+ 0xB1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x0145
+ [1] { // line_number_table
+ 0 4; // at 0x0151
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ ;
+ Attr(#12, 0) { // Deprecated at 0x0151
+ } // end Deprecated
+ ;
+ Attr(#13, 21) { // RuntimeVisibleAnnotations at 0x0157 (length changed from 16 to 21)
+ [1] { // annotations
+ { // annotation
+ #14;
+ [3] { // element_value_pairs <= extra pair added
+ { // Extra element value pair: now=true
+ #18;
+ { // element_value
+ 'Z';
+ #16;
+ } // element_value
+ } // element value pair
+ ;
+ { // element value pair
+ #15;
+ { // element_value
+ 'Z';
+ #16;
+ } // element_value
+ } // element value pair
+ ;
+ { // element value pair
+ #17;
+ { // element_value
+ 's';
+ #18;
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#19, 2) { // SourceFile at 0x016F
+ #20;
+ } // end SourceFile
+ } // Attributes
+} // end class BadDeprecatedExtraMemberAtStart
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalBadCPIndex.jcod b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalBadCPIndex.jcod
new file mode 100644
index 0000000000000..e8648e0c705bb
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalBadCPIndex.jcod
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ *
+ * public class DeprecatedMethod {
+ * @Deprecated(forRemoval=true, since="now")
+ * public static void m() {}
+ * }
+ *
+ * We change the CP index for the value of forRemoval to a junk value
+ */
+
+class BadDeprecatedForRemovalBadCPIndex {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [21] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadDeprecatedForRemovalBadCPIndex"; // #8 at 0x3C
+ Utf8 "Code"; // #9 at 0x4F
+ Utf8 "LineNumberTable"; // #10 at 0x56
+ Utf8 "m"; // #11 at 0x68
+ Utf8 "Deprecated"; // #12 at 0x6C
+ Utf8 "RuntimeVisibleAnnotations"; // #13 at 0x79
+ Utf8 "Ljava/lang/Deprecated;"; // #14 at 0x95
+ Utf8 "forRemoval"; // #15 at 0xAE
+ int 0x00000001; // #16 at 0xBB
+ Utf8 "since"; // #17 at 0xC0
+ Utf8 "now"; // #18 at 0xC8
+ Utf8 "SourceFile"; // #19 at 0xCE
+ Utf8 "BadDeprecatedForRemovalBadCPIndex.java"; // #20 at 0xDB
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [0] { // Fields
+ } // Fields
+
+ [2] { // Methods
+ { // method at 0xFF
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#9, 29) { // Code at 0x0107
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x011E
+ [1] { // line_number_table
+ 0 1; // at 0x012A
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ ;
+ { // method at 0x012A
+ 0x0009; // access
+ #11; // name_index : m
+ #6; // descriptor_index : ()V
+ [3] { // Attributes
+ Attr(#9, 25) { // Code at 0x0132
+ 0; // max_stack
+ 0; // max_locals
+ Bytes[1]{
+ 0xB1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x0145
+ [1] { // line_number_table
+ 0 4; // at 0x0151
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ ;
+ Attr(#12, 0) { // Deprecated at 0x0151
+ } // end Deprecated
+ ;
+ Attr(#13, 16) { // RuntimeVisibleAnnotations at 0x0157
+ [1] { // annotations
+ { // annotation
+ #14;
+ [2] { // element_value_pairs
+ { // element value pair
+ #17;
+ { // element_value
+ 's';
+ #18;
+ } // element_value
+ } // element value pair
+ ;
+ { // element value pair
+ #15;
+ { // element_value
+ 'Z';
+ #1600; // Changed from #16 to #1600
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#19, 2) { // SourceFile at 0x016F
+ #20;
+ } // end SourceFile
+ } // Attributes
+} // end class BadDeprecatedForRemovalBadCPIndex
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalWrongType.jcod b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalWrongType.jcod
new file mode 100644
index 0000000000000..9a2a536d664e3
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedForRemovalWrongType.jcod
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ *
+ * public class DeprecatedMethod {
+ * @Deprecated(forRemoval=true, since="now")
+ * public static void m() {}
+ * }
+ *
+ * We change the type of forRemoval from 'Z' to 's' but don't change the value
+ */
+
+class BadDeprecatedForRemovalWrongType {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [21] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadDeprecatedForRemovalWrongType"; // #8 at 0x3C
+ Utf8 "Code"; // #9 at 0x4F
+ Utf8 "LineNumberTable"; // #10 at 0x56
+ Utf8 "m"; // #11 at 0x68
+ Utf8 "Deprecated"; // #12 at 0x6C
+ Utf8 "RuntimeVisibleAnnotations"; // #13 at 0x79
+ Utf8 "Ljava/lang/Deprecated;"; // #14 at 0x95
+ Utf8 "forRemoval"; // #15 at 0xAE
+ int 0x00000001; // #16 at 0xBB
+ Utf8 "since"; // #17 at 0xC0
+ Utf8 "now"; // #18 at 0xC8
+ Utf8 "SourceFile"; // #19 at 0xCE
+ Utf8 "BadDeprecatedForRemovalWrongType.java"; // #20 at 0xDB
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [0] { // Fields
+ } // Fields
+
+ [2] { // Methods
+ { // method at 0xFF
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#9, 29) { // Code at 0x0107
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x011E
+ [1] { // line_number_table
+ 0 1; // at 0x012A
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ ;
+ { // method at 0x012A
+ 0x0009; // access
+ #11; // name_index : m
+ #6; // descriptor_index : ()V
+ [3] { // Attributes
+ Attr(#9, 25) { // Code at 0x0132
+ 0; // max_stack
+ 0; // max_locals
+ Bytes[1]{
+ 0xB1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x0145
+ [1] { // line_number_table
+ 0 4; // at 0x0151
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ ;
+ Attr(#12, 0) { // Deprecated at 0x0151
+ } // end Deprecated
+ ;
+ Attr(#13, 16) { // RuntimeVisibleAnnotations at 0x0157
+ [1] { // annotations
+ { // annotation
+ #14;
+ [2] { // element_value_pairs
+ { // element value pair
+ #17;
+ { // element_value
+ 's';
+ #18;
+ } // element_value
+ } // element value pair
+ ;
+ { // element value pair
+ #15;
+ { // element_value
+ 's'; // Changed from Z to s
+ #16;
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#19, 2) { // SourceFile at 0x016F
+ #20;
+ } // end SourceFile
+ } // Attributes
+} // end class BadDeprecatedForRemovalWrongType
diff --git a/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedSinceWrongType.jcod b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedSinceWrongType.jcod
new file mode 100644
index 0000000000000..85863ea3b86a1
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/BadDeprecatedSinceWrongType.jcod
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* Based on source:
+ *
+ * public class DeprecatedMethod {
+ * @Deprecated(forRemoval=true, since="now")
+ * public static void m() {}
+ * }
+ *
+ * We change the type of since from 's' to 'Z'
+ */
+
+class BadDeprecatedSinceWrongType {
+ 0xCAFEBABE;
+ 0; // minor version
+ 65; // version
+ [21] { // Constant Pool
+ ; // first element is empty
+ Method #2 #3; // #1 at 0x0A
+ class #4; // #2 at 0x0F
+ NameAndType #5 #6; // #3 at 0x12
+ Utf8 "java/lang/Object"; // #4 at 0x17
+ Utf8 ""; // #5 at 0x2A
+ Utf8 "()V"; // #6 at 0x33
+ class #8; // #7 at 0x39
+ Utf8 "BadDeprecatedSinceWrongType"; // #8 at 0x3C
+ Utf8 "Code"; // #9 at 0x4F
+ Utf8 "LineNumberTable"; // #10 at 0x56
+ Utf8 "m"; // #11 at 0x68
+ Utf8 "Deprecated"; // #12 at 0x6C
+ Utf8 "RuntimeVisibleAnnotations"; // #13 at 0x79
+ Utf8 "Ljava/lang/Deprecated;"; // #14 at 0x95
+ Utf8 "forRemoval"; // #15 at 0xAE
+ int 0x00000001; // #16 at 0xBB
+ Utf8 "since"; // #17 at 0xC0
+ Utf8 "now"; // #18 at 0xC8
+ Utf8 "SourceFile"; // #19 at 0xCE
+ Utf8 "BadDeprecatedSinceWrongType.java"; // #20 at 0xDB
+ } // Constant Pool
+
+ 0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+ #7;// this_cpx
+ #2;// super_cpx
+
+ [0] { // Interfaces
+ } // Interfaces
+
+ [0] { // Fields
+ } // Fields
+
+ [2] { // Methods
+ { // method at 0xFF
+ 0x0001; // access
+ #5; // name_index :
+ #6; // descriptor_index : ()V
+ [1] { // Attributes
+ Attr(#9, 29) { // Code at 0x0107
+ 1; // max_stack
+ 1; // max_locals
+ Bytes[5]{
+ 0x2AB70001B1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x011E
+ [1] { // line_number_table
+ 0 1; // at 0x012A
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ } // Attributes
+ }
+ ;
+ { // method at 0x012A
+ 0x0009; // access
+ #11; // name_index : m
+ #6; // descriptor_index : ()V
+ [3] { // Attributes
+ Attr(#9, 25) { // Code at 0x0132
+ 0; // max_stack
+ 0; // max_locals
+ Bytes[1]{
+ 0xB1;
+ }
+ [0] { // Traps
+ } // end Traps
+ [1] { // Attributes
+ Attr(#10, 6) { // LineNumberTable at 0x0145
+ [1] { // line_number_table
+ 0 4; // at 0x0151
+ }
+ } // end LineNumberTable
+ } // Attributes
+ } // end Code
+ ;
+ Attr(#12, 0) { // Deprecated at 0x0151
+ } // end Deprecated
+ ;
+ Attr(#13, 16) { // RuntimeVisibleAnnotations at 0x0157
+ [1] { // annotations
+ { // annotation
+ #14;
+ [2] { // element_value_pairs
+ { // element value pair
+ #17;
+ { // element_value
+ 'Z'; // Changed from 's' to 'Z'
+ #18;
+ } // element_value
+ } // element value pair
+ ;
+ { // element value pair
+ #15;
+ { // element_value
+ 'Z';
+ #16;
+ } // element_value
+ } // element value pair
+ } // element_value_pairs
+ } // annotation
+ }
+ } // end RuntimeVisibleAnnotations
+ } // Attributes
+ }
+ } // Methods
+
+ [1] { // Attributes
+ Attr(#19, 2) { // SourceFile at 0x016F
+ #20;
+ } // end SourceFile
+ } // Attributes
+} // end class BadDeprecatedSinceWrongType
diff --git a/test/hotspot/jtreg/runtime/Annotations/TestBadAnnotations.java b/test/hotspot/jtreg/runtime/Annotations/TestBadAnnotations.java
new file mode 100644
index 0000000000000..6617858d61bf2
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/Annotations/TestBadAnnotations.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8339192
+ * @summary Check that malformed annotations don't cause crashes
+ * @compile BadDeprecatedExtraMemberAtEnd.jcod
+ * BadDeprecatedExtraMemberAtStart.jcod
+ * BadDeprecatedSinceWrongType.jcod
+ * BadDeprecatedForRemovalWrongType.jcod
+ * BadDeprecatedForRemovalBadCPIndex.jcod
+ * BadContendedGroupBadCPIndex.jcod
+ * BadContendedGroupWrongType.jcod
+ * @modules java.base/jdk.internal.vm.annotation
+ * @run main/othervm -XX:-RestrictContended TestBadAnnotations
+ */
+import java.lang.annotation.Annotation;
+import java.lang.reflect.*;
+
+// None of the malformed nnotations should cause assertion failures or
+// other crashes, nor exceptions - we simply don't process them. Note that
+// even if the annotation is malformed the class will still be marked as having
+// that annotation; it is only the "forRemoval" state of @Deprecated, and
+// the "group" value of @Contended that is potentially afffected.
+// There is no API to query what annotations the VM considers applied
+// to a class/field/method, so we don't try to read anything back.
+
+// The testcases defined reflect the changes that were made to the code under
+// 8339192 - we do not try to define exhaustive tests for every potential
+// malformation. Each of these test case will trigger an assert prior to
+// the fix.
+
+public class TestBadAnnotations {
+ public static void main(String[] args) throws Throwable {
+ Class> c = Class.forName("BadDeprecatedExtraMemberAtEnd");
+ c = Class.forName("BadDeprecatedExtraMemberAtStart");
+ c = Class.forName("BadDeprecatedSinceWrongType");
+ c = Class.forName("BadDeprecatedForRemovalWrongType");
+ c = Class.forName("BadDeprecatedForRemovalBadCPIndex");
+ c = Class.forName("BadContendedGroupBadCPIndex");
+ c = Class.forName("BadContendedGroupWrongType");
+ }
+}
From 94c33179b6a1205100d7c125f3a7c11e29621db9 Mon Sep 17 00:00:00 2001
From: Prasanta Sadhukhan
Date: Fri, 20 Sep 2024 03:05:22 +0000
Subject: [PATCH 021/110] 8339895: Open source several AWT focus tests - series
3
Reviewed-by: prr
---
test/jdk/ProblemList.txt | 1 +
.../jdk/java/awt/Focus/ActivateFocusTest.java | 148 ++++++++++++
.../Focus/CanvasPanelFocusOnClickTest.java | 212 ++++++++++++++++++
test/jdk/java/awt/Focus/FocusPolicyTest.java | 177 +++++++++++++++
.../awt/Focus/RequestInInactiveFrame.java | 106 +++++++++
5 files changed, 644 insertions(+)
create mode 100644 test/jdk/java/awt/Focus/ActivateFocusTest.java
create mode 100644 test/jdk/java/awt/Focus/CanvasPanelFocusOnClickTest.java
create mode 100644 test/jdk/java/awt/Focus/FocusPolicyTest.java
create mode 100644 test/jdk/java/awt/Focus/RequestInInactiveFrame.java
diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt
index 5c5f2d2fc6567..8990b02c1601f 100644
--- a/test/jdk/ProblemList.txt
+++ b/test/jdk/ProblemList.txt
@@ -136,6 +136,7 @@ java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java 8169096
java/awt/Focus/TestDisabledAutoTransfer.java 8159871 macosx-all,windows-all
java/awt/Focus/TestDisabledAutoTransferSwing.java 6962362 windows-all
java/awt/Focus/ActivateOnProperAppContextTest.java 8136516 macosx-all
+java/awt/Focus/FocusPolicyTest.java 7160904 linux-all
java/awt/EventQueue/6980209/bug6980209.java 8198615 macosx-all
java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java 7080150 macosx-all
java/awt/event/InputEvent/EventWhenTest/EventWhenTest.java 8168646 generic-all
diff --git a/test/jdk/java/awt/Focus/ActivateFocusTest.java b/test/jdk/java/awt/Focus/ActivateFocusTest.java
new file mode 100644
index 0000000000000..09f5bbb172ca8
--- /dev/null
+++ b/test/jdk/java/awt/Focus/ActivateFocusTest.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2001, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4369903
+ * @summary Focus on window activation does not work correctly
+ * @key headful
+ * @run main ActivateFocusTest
+ */
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Toolkit;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+public class ActivateFocusTest {
+
+ public static void main(final String[] args) {
+ ActivateFocusTest app = new ActivateFocusTest();
+ app.doTest();
+ }
+
+ public void doTest() {
+ ActivateFocus[] af = new ActivateFocus[2];
+ boolean testFailed = false;
+ Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
+ for (int i = 0; i < 2; i++) {
+ af[i] = new ActivateFocus(i);
+ af[i].setLocation(i * 160 + scrSize.width / 2, scrSize.height / 2);
+ af[i].setVisible(true);
+ }
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ie) {
+ throw new RuntimeException("TEST FAILED - thread was interrupted");
+ }
+ for (int i = 0; i < 2; i++) {
+ testFailed = (af[i].lw.focusCounter > 1);
+ }
+ if (testFailed) {
+ throw new RuntimeException("TEST FAILED - focus is gained more than one time");
+ } else {
+ System.out.println("TEST PASSED");
+ }
+ }
+
+ }
+
+class ActivateFocus extends Frame {
+
+ public LightWeight lw = null;
+ int num;
+
+ public String toString() {
+ return ("Window " + num);
+ }
+
+ public ActivateFocus(int i) {
+ setTitle("Window " + i);
+ lw = new LightWeight(i);
+ num=i;
+ addWindowListener(new WindowAdapter() {
+ public void windowActivated(WindowEvent e) {
+ if(lw != null) {
+ lw.requestFocus();
+ }
+ }
+ });
+ add(lw);
+ pack();
+ }
+
+ // A very simple lightweight component
+ class LightWeight extends Component implements FocusListener {
+
+ boolean focused = false;
+ int num;
+ public int focusCounter = 0;
+
+ public LightWeight(int num) {
+ this.num = num;
+ addFocusListener(this);
+ }
+
+ public void paint(Graphics g) {
+ Dimension size = getSize();
+ int w = size.width;
+ int h = size.height;
+ g.setColor(getBackground());
+ g.fillRect(0, 0, w, h);
+ g.setColor(Color.black);
+ g.drawOval(0, 0, w-1, h-1);
+ if (focused) {
+ g.drawLine(w/2, 0, w/2, h);
+ g.drawLine(0, h/2, w, h/2);
+ }
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(150, 150);
+ }
+
+ public void focusGained(FocusEvent e) {
+ focused = true;
+ focusCounter++;
+ System.out.println("focusGained on " + e.getComponent());
+ repaint();
+ }
+
+ public void focusLost(FocusEvent e) {
+ focused = false;
+ System.out.println("focusLost on " + e.getComponent());
+ repaint();
+ }
+
+ public String toString() {
+ return ("Component " + num);
+ }
+ }
+}
diff --git a/test/jdk/java/awt/Focus/CanvasPanelFocusOnClickTest.java b/test/jdk/java/awt/Focus/CanvasPanelFocusOnClickTest.java
new file mode 100644
index 0000000000000..8df21ba0f0a67
--- /dev/null
+++ b/test/jdk/java/awt/Focus/CanvasPanelFocusOnClickTest.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4041703 4096228 4032657 4066152 4149866 4025223
+ * @summary Ensures that an Panel/Canvas without heavyweight children
+ receives focus on mouse click
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual CanvasPanelFocusOnClickTest
+ */
+
+import java.awt.Button;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.Panel;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+public class CanvasPanelFocusOnClickTest {
+
+ private static final String INSTRUCTIONS = """
+
+ Click on the red Canvas. Verify that it has focus by key pressing.
+ Click on the yellow Panel. Verify that it has focus by key pressing.
+ Click on the blue heavyweight Panel (NOT ON THE BUTTON!).
+ Verify that it doesn't have focus by key pressing.
+ If two empty containers are able to the get focus by a mouse click
+ and the container with heavyweight children are unable to get
+ the focus by a mouse click which can be verified through messages in message dialog
+ the test passes.""";
+
+ public static void main(String[] args) throws Exception {
+ PassFailJFrame.builder()
+ .title("CanvasPanelFocusOnClickTest Instructions")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(CanvasPanelFocusOnClickTest::createTestUI)
+ .logArea()
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static Frame createTestUI() {
+ Canvas canvas = new Canvas();;
+ Panel emptyPanel = new Panel();
+ Panel panel = new Panel();
+ Button buttonInPanel = new Button("BUTTON ON PANEL");
+
+ Frame frame = new Frame("CanvasPanelFocusOnClickTest Frame");
+ frame.setLayout(new GridLayout(3, 1));
+ canvas.setBackground(Color.red);
+ canvas.setName("RED CANVAS");
+ canvas.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ println(e.toString());
+ }
+ public void focusLost(FocusEvent e) {
+ println(e.toString());
+ }
+ });
+ canvas.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyTyped(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyReleased(KeyEvent e) {
+ printKey(e);
+ }
+ });
+ frame.add(canvas);
+
+ emptyPanel.setBackground(Color.yellow);
+ emptyPanel.setName("YELLOW PANEL");
+ emptyPanel.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ println(e.toString());
+ }
+ public void focusLost(FocusEvent e) {
+ println(e.toString());
+ }
+ });
+ emptyPanel.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyTyped(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyReleased(KeyEvent e) {
+ printKey(e);
+ }
+ });
+ frame.add(emptyPanel);
+
+ panel.setBackground(Color.blue);
+ panel.setName("BLUE PANEL");
+ buttonInPanel.setName("BUTTON ON PANEL");
+ buttonInPanel.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ println(e.toString());
+ }
+ public void focusLost(FocusEvent e) {
+ println(e.toString());
+ }
+ });
+ buttonInPanel.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyTyped(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyReleased(KeyEvent e) {
+ printKey(e);
+ }
+ });
+ panel.add(buttonInPanel);
+ panel.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ println(e.toString());
+ }
+ public void focusLost(FocusEvent e) {
+ println(e.toString());
+ }
+ });
+ panel.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyTyped(KeyEvent e) {
+ printKey(e);
+ }
+
+ public void keyReleased(KeyEvent e) {
+ printKey(e);
+ }
+ });
+ frame.add(panel);
+
+ frame.setSize(200, 200);
+
+ return frame;
+
+ }
+
+ static void printKey(KeyEvent e) {
+ String typeStr;
+ switch(e.getID()) {
+ case KeyEvent.KEY_PRESSED:
+ typeStr = "KEY_PRESSED";
+ break;
+ case KeyEvent.KEY_RELEASED:
+ typeStr = "KEY_RELEASED";
+ break;
+ case KeyEvent.KEY_TYPED:
+ typeStr = "KEY_TYPED";
+ break;
+ default:
+ typeStr = "unknown type";
+ }
+
+ Object source = e.getSource();
+ if (source instanceof Component) {
+ typeStr += " on " + ((Component)source).getName();
+ } else {
+ typeStr += " on " + source;
+ }
+
+ println(typeStr);
+ }
+
+ static void println(String messageIn) {
+ PassFailJFrame.log(messageIn);
+ }
+}
diff --git a/test/jdk/java/awt/Focus/FocusPolicyTest.java b/test/jdk/java/awt/Focus/FocusPolicyTest.java
new file mode 100644
index 0000000000000..3ec362acaf085
--- /dev/null
+++ b/test/jdk/java/awt/Focus/FocusPolicyTest.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2003, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4897459
+ * @key headful
+ * @summary The key does not switches focus in the internal frames in Swing apps.
+ * @run main FocusPolicyTest
+ */
+
+import java.awt.Container;
+import java.awt.Component;
+import java.awt.DefaultFocusTraversalPolicy;
+import java.awt.Dialog;
+import java.awt.FocusTraversalPolicy;
+import java.awt.Frame;
+import java.awt.KeyboardFocusManager;
+import java.awt.Toolkit;
+import java.awt.Window;
+import javax.swing.JDialog;
+import javax.swing.JInternalFrame;
+import javax.swing.JFrame;
+import javax.swing.JWindow;
+import javax.swing.LayoutFocusTraversalPolicy;
+
+public class FocusPolicyTest {
+ static int stageNum;
+ static FocusTraversalPolicy customPolicy = new CustomPolicy();
+ final static Class awtDefaultPolicy = DefaultFocusTraversalPolicy.class;
+ final static Class swingDefaultPolicy = LayoutFocusTraversalPolicy.class;
+
+ public static void main(String[] args) {
+ final boolean isXawt = "sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName());
+
+ System.err.println("isXawt = " + isXawt);
+
+ // 1. Check default policy
+ if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
+ getDefaultFocusTraversalPolicy().getClass() != awtDefaultPolicy) {
+ throw new RuntimeException("Error: stage 1: default policy is not DefaultFocusTraversalPolicy");
+ }
+
+ // 2. Check AWT top-levels policies
+ stageNum = 2;
+ checkAWTPoliciesFor(awtDefaultPolicy);
+
+ // 3. Check Swing top-levels policies
+ stageNum = 3;
+ checkSwingPoliciesFor(swingDefaultPolicy);
+
+ // 4. Check default policy if not XToolkit
+ if (!isXawt) {
+ if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
+ getDefaultFocusTraversalPolicy().getClass() != swingDefaultPolicy) {
+ throw new RuntimeException("Error: stage 4: default policy is not LayoutFocusTraversalPolicy");
+ }
+ }
+
+ // 5. Check AWT top-levels policies
+ // this is a bug in XAWT we should change the test as soon as
+ // we will be able to fix this bug.
+ stageNum = 5;
+ Class defaultPolicy = swingDefaultPolicy;
+ if (isXawt) {
+ defaultPolicy = awtDefaultPolicy;
+ }
+ checkAWTPoliciesFor(defaultPolicy);
+
+ // Set custom policy as default
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalPolicy(customPolicy);
+
+ // 6. Check AWT top-levels policies for custom
+ stageNum = 6;
+ checkAWTPoliciesFor(customPolicy.getClass());
+
+ // 7. Check Swing top-levels policies for custom
+ stageNum = 7;
+ checkSwingPoliciesFor(customPolicy.getClass());
+
+ return;
+ }
+
+ public static void checkAWTPoliciesFor(Class expectedPolicyClass) {
+ Window[] tlvs = new Window[7];
+
+ tlvs[0] = new Frame("");
+ tlvs[1] = new Frame("", tlvs[0].getGraphicsConfiguration());
+ tlvs[2] = new Window((Frame)tlvs[0]);
+ tlvs[3] = new Dialog((Frame)tlvs[0], "", false);
+ tlvs[4] = new Dialog((Frame)tlvs[0], "", false, tlvs[0].getGraphicsConfiguration());
+ tlvs[5] = new Dialog((Dialog)tlvs[3], "", false);
+ tlvs[6] = new Dialog((Dialog)tlvs[3], "", false, tlvs[0].getGraphicsConfiguration());
+
+ for (int i = 0; i < 7; i++) {
+ Class policyClass = tlvs[i].getFocusTraversalPolicy().getClass();
+ if (policyClass != expectedPolicyClass) {
+ throw new RuntimeException("Error: stage " + stageNum + ": "
+ + tlvs[i].getClass().getName()
+ + "'s policy is " + policyClass.getName()
+ + " but not " + expectedPolicyClass.getName());
+ }
+ }
+ }
+
+ public static void checkSwingPoliciesFor(Class expectedPolicyClass) {
+ Container[] tlvs = new Container[12];
+
+ tlvs[0] = new JFrame();
+ tlvs[1] = new JFrame(tlvs[0].getGraphicsConfiguration());
+ tlvs[2] = new JFrame("");
+ tlvs[3] = new JFrame("", tlvs[0].getGraphicsConfiguration());
+ tlvs[4] = new JWindow((Frame)tlvs[0]);
+ tlvs[5] = new JWindow((Window)tlvs[4]);
+ tlvs[6] = new JWindow((Window)tlvs[4], tlvs[0].getGraphicsConfiguration());
+ tlvs[7] = new JDialog((Frame)tlvs[0], "", false);
+ tlvs[8] = new JDialog((Frame)tlvs[0], "", false, tlvs[0].getGraphicsConfiguration());
+ tlvs[9] = new JDialog((Dialog)tlvs[7], "", false);
+ tlvs[10] = new JDialog((Dialog)tlvs[7], "", false, tlvs[0].getGraphicsConfiguration());
+ tlvs[11] = new JInternalFrame("", false, false, false, false);
+
+ for (int i = 0; i < tlvs.length; i++) {
+ Class policyClass = tlvs[i].getFocusTraversalPolicy().getClass();
+ if (policyClass != expectedPolicyClass) {
+ throw new RuntimeException("Error: stage " + stageNum
+ + ": " + tlvs[i].getClass().getName()
+ + "'s policy is " + policyClass.getName() + " but not "
+ + expectedPolicyClass.getName());
+ }
+ }
+ }
+
+ // Dummy policy.
+ static class CustomPolicy extends FocusTraversalPolicy {
+ public Component getComponentAfter(Container focusCycleRoot,
+ Component aComponent) {
+ return null;
+ }
+
+ public Component getComponentBefore(Container focusCycleRoot,
+ Component aComponent) {
+ return null;
+ }
+
+ public Component getFirstComponent(Container focusCycleRoot) {
+ return null;
+ }
+
+ public Component getLastComponent(Container focusCycleRoot) {
+ return null;
+ }
+
+ public Component getDefaultComponent(Container focusCycleRoot) {
+ return null;
+ }
+ }
+}
diff --git a/test/jdk/java/awt/Focus/RequestInInactiveFrame.java b/test/jdk/java/awt/Focus/RequestInInactiveFrame.java
new file mode 100644
index 0000000000000..3297fe17501a1
--- /dev/null
+++ b/test/jdk/java/awt/Focus/RequestInInactiveFrame.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2011, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6458497
+ * @summary check focus requests in inactive frames
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual RequestInInactiveFrame
+ */
+
+import java.util.ArrayList;
+
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.Window;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+public class RequestInInactiveFrame {
+
+ private static final String INSTRUCTIONS = """
+ After the tests starts you will see two frames: \"test frame\" and \"opposite frame\"
+ activate the former by click on its title
+ Focus should be on \"press me\" button (if it's not, the test fails)
+ press on \"press me\" button and activate \"opposite frame\"
+ wait for several seconds.
+ Focus should either remain on button in the \"opposite frame\"
+ or goes to \"focus target\" button (in this case \"test frame\" should be activated
+ if it's not, the test failed.
+ Activate \"test frame\" one more time, press on \"press me\" button and switch focus
+ to some native window. Wait for several seconds,
+ If you see focus border around
+ \"focus target\" and \"test frame\" is not active then the test failed.
+ if focus transfered to that button and the frame is activated, or if there is no focus
+ in java - tests passed.""";
+
+ public static void main(String[] args) throws Exception {
+ PassFailJFrame.builder()
+ .title("RequestInInactiveFrame Instructions")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(RequestInInactiveFrame::createTestUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static ArrayList createTestUI() {
+ JFrame frame = new JFrame("test frame");
+ final JButton btn2 = new JButton("focus target");
+ JButton btn1 = new JButton("press me");
+ btn1.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("waiting...");
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException ie) {
+ ie.printStackTrace();
+ }
+ System.out.println("requesting focus");
+ btn2.requestFocus();
+ }
+ });
+ frame.setLayout(new FlowLayout());
+ frame.add(btn1);
+ frame.add(btn2);
+ frame.pack();
+ frame.setLocation(200, 100);
+
+ JFrame frame2 = new JFrame("opposite frame");
+ JButton btn3 = new JButton("just a button");
+ frame2.add(btn3);
+ frame2.pack();
+ frame2.setLocation(200, 200);
+
+ ArrayList list = new ArrayList<>();
+ list.add(frame);
+ list.add(frame2);
+ return list;
+ }
+
+}
From 0f7d9e599593bb8e31e7e33a559d25ec803c7ba4 Mon Sep 17 00:00:00 2001
From: Kim Barrett
Date: Fri, 20 Sep 2024 04:15:55 +0000
Subject: [PATCH 022/110] 8340436: Remove unused
CompressedOops::AnyNarrowOopMode
Reviewed-by: haosun, dholmes
---
src/hotspot/share/oops/compressedOops.hpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/hotspot/share/oops/compressedOops.hpp b/src/hotspot/share/oops/compressedOops.hpp
index a33c8e0c10380..a9446469c8781 100644
--- a/src/hotspot/share/oops/compressedOops.hpp
+++ b/src/hotspot/share/oops/compressedOops.hpp
@@ -73,8 +73,7 @@ class CompressedOops : public AllStatic {
UnscaledNarrowOop = 0,
ZeroBasedNarrowOop = 1,
DisjointBaseNarrowOop = 2,
- HeapBasedNarrowOop = 3,
- AnyNarrowOopMode = 4
+ HeapBasedNarrowOop = 3
};
// The representation type for narrowOop is assumed to be uint32_t.
From f4e401791efb920b9773f2886b34904c95106727 Mon Sep 17 00:00:00 2001
From: Abhishek Kumar
Date: Fri, 20 Sep 2024 04:19:12 +0000
Subject: [PATCH 023/110] 8339984: Open source AWT MenuItem related tests
Reviewed-by: aivanov
---
test/jdk/java/awt/MenuItem/GiantFontTest.java | 83 +++++++++++++
.../awt/MenuItem/LotsOfMenuItemsTest.java | 117 ++++++++++++++++++
.../java/awt/MenuItem/MenuSetFontTest.java | 72 +++++++++++
.../MenuItem/NullOrEmptyStringLabelTest.java | 105 ++++++++++++++++
.../awt/MenuItem/UnicodeMenuItemTest.java | 91 ++++++++++++++
5 files changed, 468 insertions(+)
create mode 100644 test/jdk/java/awt/MenuItem/GiantFontTest.java
create mode 100644 test/jdk/java/awt/MenuItem/LotsOfMenuItemsTest.java
create mode 100644 test/jdk/java/awt/MenuItem/MenuSetFontTest.java
create mode 100644 test/jdk/java/awt/MenuItem/NullOrEmptyStringLabelTest.java
create mode 100644 test/jdk/java/awt/MenuItem/UnicodeMenuItemTest.java
diff --git a/test/jdk/java/awt/MenuItem/GiantFontTest.java b/test/jdk/java/awt/MenuItem/GiantFontTest.java
new file mode 100644
index 0000000000000..f1e352373bb1e
--- /dev/null
+++ b/test/jdk/java/awt/MenuItem/GiantFontTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2002, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+
+/*
+ * @test
+ * @bug 4700350
+ * @requires os.family != "mac"
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary Tests menu item font is big
+ * @run main/manual GiantFontTest
+ */
+
+public class GiantFontTest {
+
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ A frame with one menu will appear.
+ On Linux, the menu's (present on menu bar) font should
+ be quite large (48 point).
+ If not, test fails.
+
+ On Windows, the menu's (present on menu bar) font
+ should be normal size.
+ If the menu text is clipped by the title bar, or is painted over
+ the title bar or client area, the test fails.
+
+ On both Windows and Linux, the menu items in the popup
+ menu should be large.
+
+ If so, test passes.""";
+
+ PassFailJFrame.builder()
+ .title("GiantFontTest")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(GiantFontTest::createAndShowUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static Frame createAndShowUI() {
+ Font giantFont = new Font("Dialog", Font.PLAIN, 48);
+ Frame f = new Frame("GiantFontTest");
+ MenuBar mb = new MenuBar();
+ Menu m = new Menu("My font is too big!");
+ m.setFont(giantFont);
+ for (int i = 0; i < 5; i++) {
+ m.add(new MenuItem("Some MenuItems"));
+ }
+ mb.add(m);
+ f.setMenuBar(mb);
+ f.setSize(450, 400);
+ return f;
+ }
+}
diff --git a/test/jdk/java/awt/MenuItem/LotsOfMenuItemsTest.java b/test/jdk/java/awt/MenuItem/LotsOfMenuItemsTest.java
new file mode 100644
index 0000000000000..7a528205d27d8
--- /dev/null
+++ b/test/jdk/java/awt/MenuItem/LotsOfMenuItemsTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 1998, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+
+/*
+ * @test
+ * @bug 4175790
+ * @requires os.family == "windows"
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary Win32: Running out of command ids for menu items
+ * @run main/manual LotsOfMenuItemsTest
+ */
+
+public class LotsOfMenuItemsTest extends ComponentAdapter {
+ private static final int NUM_WINDOWS = 400;
+ private static TestFrame firstFrame;
+
+ public static void main(String[] args) throws Exception {
+ LotsOfMenuItemsTest obj = new LotsOfMenuItemsTest();
+ String INSTRUCTIONS = """
+ This test creates lots of frames with menu bars.
+ When it's done you will see two frames.
+ Try to select menu items from each of them.
+
+ If everything seems to work - test passed.
+ Click "Pass" button in the test harness window.
+
+ If test crashes on you - test failed.""";
+
+ PassFailJFrame.builder()
+ .title("LotsOfMenuItemsTest")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(obj::createAndShowUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private Frame createAndShowUI() {
+ firstFrame = new TestFrame("First frame");
+ firstFrame.addComponentListener(this);
+ return firstFrame;
+ }
+
+ @Override
+ public void componentShown(ComponentEvent e) {
+ final int x = firstFrame.getX();
+ final int y = firstFrame.getY() + firstFrame.getHeight() + 8;
+ TestFrame testFrame;
+ for (int i = 1; i < NUM_WINDOWS - 1; ++i) {
+ testFrame = new TestFrame("Running(" + i + ")...", x, y);
+ testFrame.setVisible(false);
+ testFrame.dispose();
+ }
+ testFrame = new TestFrame("Last Frame", x, y);
+ PassFailJFrame.addTestWindow(testFrame);
+ }
+
+ private static class TestFrame extends Frame {
+ static int n = 0;
+
+ public TestFrame(String title) {
+ this(title, 0, 0, false);
+ }
+
+ public TestFrame(String s, int x, int y) {
+ this(s, x, y, true);
+ }
+
+ private TestFrame(String title, int x, int y, boolean visible) {
+ super(title);
+ MenuBar mb = new MenuBar();
+ for (int i = 0; i < 10; ++i) {
+ Menu m = new Menu("Menu_" + (i + 1));
+ for (int j = 0; j < 20; ++j) {
+ MenuItem mi = new MenuItem("Menu item " + ++n);
+ m.add(mi);
+ }
+ mb.add(m);
+ }
+ setMenuBar(mb);
+ setLocation(x, y);
+ setSize(450, 150);
+ if (visible) {
+ setVisible(true);
+ }
+ }
+ }
+}
diff --git a/test/jdk/java/awt/MenuItem/MenuSetFontTest.java b/test/jdk/java/awt/MenuItem/MenuSetFontTest.java
new file mode 100644
index 0000000000000..9a4e8f8583905
--- /dev/null
+++ b/test/jdk/java/awt/MenuItem/MenuSetFontTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2000, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+
+/*
+ * @test
+ * @bug 4066657 8009454
+ * @requires os.family != "mac"
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary Tests that setting a font on the Menu with MenuItem takes effect.
+ * @run main/manual MenuSetFontTest
+ */
+
+public class MenuSetFontTest {
+
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ Look at the menu in the upper left corner of the 'SetFont Test' frame.
+ Click on the "File" menu. You will see "menu item" item.
+ Press Pass if menu item is displayed using bold and large font,
+ otherwise press Fail.
+ If you do not see menu at all, press Fail.""";
+
+ PassFailJFrame.builder()
+ .title("MenuSetFontTest")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(MenuSetFontTest::createAndShowUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static Frame createAndShowUI() {
+ Frame frame = new Frame("SetFont Test");
+ MenuBar menuBar = new MenuBar();
+ Menu menu = new Menu("File");
+ MenuItem item = new MenuItem("menu item");
+ menu.add(item);
+ menuBar.add(menu);
+ menuBar.setFont(new Font(Font.MONOSPACED, Font.BOLD, 24));
+ frame.setMenuBar(menuBar);
+ frame.setSize(300, 200);
+ return frame;
+ }
+}
diff --git a/test/jdk/java/awt/MenuItem/NullOrEmptyStringLabelTest.java b/test/jdk/java/awt/MenuItem/NullOrEmptyStringLabelTest.java
new file mode 100644
index 0000000000000..79d4c02ad246a
--- /dev/null
+++ b/test/jdk/java/awt/MenuItem/NullOrEmptyStringLabelTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/*
+ * @test
+ * @bug 4251036
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary MenuItem setLabel(null/"") behaves differently under Win32 and Solaris
+ * @run main/manual NullOrEmptyStringLabelTest
+ */
+
+public class NullOrEmptyStringLabelTest {
+
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ The bug is reproducible under Win32 and Solaris.
+ Setting 'null' and "" as a label of menu item
+ should set blank label on all platforms according to the specification.
+ But under Solaris setting "" as a label of menu item used to
+ cause some garbage to be set as label.
+ Under Win32 setting 'null' as a label used to result in
+ throwing NullPointerException.
+
+ If you see any of these things happen test fails otherwise
+ it passes.""";
+
+ PassFailJFrame.builder()
+ .title("NullOrEmptyStringLabelTest")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(NullOrEmptyStringLabelTest::createAndShowUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static Frame createAndShowUI() {
+ Frame frame = new Frame("Null Or Empty String Label Test");
+ Menu menu = new Menu("Menu");
+ MenuItem mi = new MenuItem("Item");
+ MenuBar mb = new MenuBar();
+ Button button1 = new Button("Set MenuItem label to 'null'");
+ Button button2 = new Button("Set MenuItem label to \"\"");
+ Button button3 = new Button("Set MenuItem label to 'text'");
+ button1.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ System.out.println("Setting MenuItem label to null");
+ mi.setLabel(null);
+ }
+ });
+ button2.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ System.out.println("Setting MenuItem label to \"\"");
+ mi.setLabel("");
+ }
+ });
+ button3.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ System.out.println("Setting MenuItem label to 'text'");
+ mi.setLabel("text");
+ }
+ });
+ menu.add(mi);
+ mb.add(menu);
+ frame.add(button1, BorderLayout.NORTH);
+ frame.add(button2, BorderLayout.CENTER);
+ frame.add(button3, BorderLayout.SOUTH);
+ frame.setMenuBar(mb);
+ frame.setSize(200, 135);
+ return frame;
+ }
+}
diff --git a/test/jdk/java/awt/MenuItem/UnicodeMenuItemTest.java b/test/jdk/java/awt/MenuItem/UnicodeMenuItemTest.java
new file mode 100644
index 0000000000000..b73fe954af6db
--- /dev/null
+++ b/test/jdk/java/awt/MenuItem/UnicodeMenuItemTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+
+/*
+ * @test
+ * @bug 4099695
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary menu items with Unicode labels treated as separators
+ * @run main/manual UnicodeMenuItemTest
+ */
+
+public class UnicodeMenuItemTest {
+
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ Click on the "Menu" on the top-left corner of frame.
+
+ The menu should have four entries:
+ 1) a row of five unicode characters: \u00c4\u00cb\u00cf\u00d6\u00dc
+ 2) a menu separator
+ 3) a unicode character: \u012d
+ 4) a unicode character: \u022d
+
+ If the menu items look like the list above, the test passes.
+ It is okay if the unicode characters look like empty boxes
+ or something - as long as they are not separators.
+
+ If either of the last two menu items show up as separators,
+ the test FAILS.
+
+ Press 'Pass' if above instructions hold good else press 'Fail'.""";
+
+ PassFailJFrame.builder()
+ .title("UnicodeMenuItemTest")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(UnicodeMenuItemTest::createAndShowUI)
+ .build()
+ .awaitAndCheck();
+ }
+ private static Frame createAndShowUI() {
+ Frame frame = new Frame("Unicode MenuItem Test");
+ MenuBar mb = new MenuBar();
+ Menu m = new Menu("Menu");
+
+ MenuItem mi1 = new MenuItem("\u00c4\u00cb\u00cf\u00d6\u00dc");
+ m.add(mi1);
+
+ MenuItem separator = new MenuItem("-");
+ m.add(separator);
+
+ MenuItem mi2 = new MenuItem("\u012d");
+ m.add(mi2);
+
+ MenuItem mi3 = new MenuItem("\u022d");
+ m.add(mi3);
+
+ mb.add(m);
+
+ frame.setMenuBar(mb);
+ frame.setSize(450, 150);
+ return frame;
+ }
+}
From 46b02f49bcc730d94e37cf17fa996fdd12bdb990 Mon Sep 17 00:00:00 2001
From: Prasanta Sadhukhan
Date: Fri, 20 Sep 2024 06:06:27 +0000
Subject: [PATCH 024/110] 8339906: Open source several AWT focus tests - series
4
Reviewed-by: abhiscxk, prr
---
test/jdk/java/awt/Focus/AltTabEventsTest.java | 151 +++++++++++++++++
.../awt/Focus/ComponentLostFocusTest.java | 154 ++++++++++++++++++
test/jdk/java/awt/Focus/FocusKeepTest.java | 103 ++++++++++++
test/jdk/java/awt/Focus/KeyStrokeTest.java | 118 ++++++++++++++
4 files changed, 526 insertions(+)
create mode 100644 test/jdk/java/awt/Focus/AltTabEventsTest.java
create mode 100644 test/jdk/java/awt/Focus/ComponentLostFocusTest.java
create mode 100644 test/jdk/java/awt/Focus/FocusKeepTest.java
create mode 100644 test/jdk/java/awt/Focus/KeyStrokeTest.java
diff --git a/test/jdk/java/awt/Focus/AltTabEventsTest.java b/test/jdk/java/awt/Focus/AltTabEventsTest.java
new file mode 100644
index 0000000000000..15d679ce7295a
--- /dev/null
+++ b/test/jdk/java/awt/Focus/AltTabEventsTest.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2002, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4524015
+ * @summary Tests that when user switches between windows using Alt-tab then the appropriate events are generated
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @run main/manual AltTabEventsTest
+ */
+
+import java.awt.Button;
+import java.awt.Choice;
+import java.awt.Component;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.PopupMenu;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+public class AltTabEventsTest {
+
+ private static final String INSTRUCTIONS = """
+ This test verifies that when user switches between windows using Alt-tab
+ key combination then appropriate window events are generated. Also, when
+ user interacts with Menu bar, Popup menu, Choice then no excessive window
+ event is generated.
+
+ After test started you will see Frame('Test for 4524015')-F1 with some
+ components and Frame('Another frame')-F2 with no components.
+ 1. Make F1 active by clicking on it.
+ 2. Press Alt-tab.
+ In the messqge dialog area you should see that
+ WINDOW_DEACTIVATED, WINDOW_LOST_FOCUS event were generated.
+ If you switched to F2 then also WINDOW_ACTIVATED, WINDOW_GAINED_FOCUS
+ were generated.
+ If no events were generated the test FAILED.
+ Repeat the 2) with different circumstances.
+
+ 3. Make F1 active by clicking on it.
+ 4. Click on Menu bar/Button 'popup'/Choice and select some item from
+ the list shown. If any of the window events appeared in the output then
+ the test FAILED.
+
+ else the test PASSED.""";
+
+ public static void main(String[] args) throws Exception {
+ PassFailJFrame.builder()
+ .title("AltTabEventsTest Instructions")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 5)
+ .columns(35)
+ .testUI(Test::new)
+ .logArea()
+ .build()
+ .awaitAndCheck();
+ }
+
+}
+
+
+class Test extends Frame {
+ PopupMenu pop;
+ Frame f;
+
+ void println(String messageIn) {
+ PassFailJFrame.log(messageIn);
+ }
+
+ public Test() {
+ super("Test for 4524015");
+ WindowAdapter wa = new WindowAdapter() {
+ public void windowActivated(WindowEvent e) {
+ println(e.toString());
+ }
+ public void windowDeactivated(WindowEvent e) {
+ println(e.toString());
+ }
+ public void windowGainedFocus(WindowEvent e) {
+ println(e.toString());
+ }
+ public void windowLostFocus(WindowEvent e) {
+ println(e.toString());
+ }
+ };
+ addWindowListener(wa);
+ addWindowFocusListener(wa);
+
+ f = new Frame("Another frame");
+ f.addWindowListener(wa);
+ f.addWindowFocusListener(wa);
+ f.setBounds(800, 300, 300, 100);
+ f.setVisible(true);
+
+ setLayout(new FlowLayout());
+ Button b = new Button("popup");
+ add(b);
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pop.show((Component)e.getSource(), 10, 10);
+ }
+ });
+ Choice cho = new Choice();
+ add(cho);
+ cho.addItem("1");
+ cho.addItem("2");
+ cho.addItem("3");
+
+ MenuBar bar = new MenuBar();
+ Menu menu = new Menu("menu");
+ MenuItem item = new MenuItem("first");
+ menu.add(item);
+ item = new MenuItem("second");
+ menu.add(item);
+ bar.add(menu);
+ setMenuBar(bar);
+
+ pop = new PopupMenu();
+ pop.add("1");
+ pop.add("@");
+ add(pop);
+ setSize(300, 100);
+ }
+}
+
diff --git a/test/jdk/java/awt/Focus/ComponentLostFocusTest.java b/test/jdk/java/awt/Focus/ComponentLostFocusTest.java
new file mode 100644
index 0000000000000..6af8322b2cd82
--- /dev/null
+++ b/test/jdk/java/awt/Focus/ComponentLostFocusTest.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2004, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4982943
+ * @key headful
+ * @summary focus lost in text fields or text areas, unable to enter characters from keyboard
+ * @run main ComponentLostFocusTest
+ */
+
+import java.awt.Dialog;
+import java.awt.EventQueue;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.KeyboardFocusManager;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.TextField;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+public class ComponentLostFocusTest {
+
+ static Frame frame;
+ static TextField tf;
+ static Robot r;
+ static Dialog dialog = null;
+ static volatile boolean passed;
+ static volatile Point loc;
+ static volatile int width;
+ static volatile int top;
+
+ private static void createTestUI() {
+
+ dialog = new Dialog(frame, "Dialog", true);
+
+ frame = new Frame("ComponentLostFocusTest Frame");
+ frame.setLayout(new FlowLayout());
+ frame.addWindowFocusListener(new WindowAdapter() {
+ public void windowGainedFocus(WindowEvent e) {
+ System.out.println("Frame gained focus: "+e);
+ }
+ });
+ tf = new TextField("Text Field");
+ frame.add(tf);
+ frame.setSize(400,300);
+ frame.setVisible(true);
+ frame.setLocationRelativeTo(null);
+ frame.validate();
+ }
+
+ public static void doTest() {
+ System.out.println("dialog.setVisible.... ");
+ new Thread(new Runnable() {
+ public void run() {
+ dialog.setVisible(true);
+ }
+ }).start();
+
+ // The bug is that this construction leads to the redundant xRequestFocus
+ // By the way, the requestFocusInWindow() works fine before the fix
+ System.out.println("requesting.... ");
+ frame.requestFocus();
+
+ r.delay(1000);
+
+ // Returning the focus to the initial frame will work correctly after the fix
+ System.out.println("disposing.... ");
+ dialog.dispose();
+
+ r.delay(1000);
+
+ // We want to track the GAIN_FOCUS from this time
+ tf.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ System.out.println("TextField gained focus: " + e);
+ passed = true;
+ }
+ });
+
+ }
+
+ private static void doRequestFocusToTextField() {
+ // do activation using press title
+ r.mouseMove(loc.x + width / 2, loc.y + top / 2);
+ r.waitForIdle();
+ r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+ r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+ r.waitForIdle();
+
+ // request focus to the text field
+ tf.requestFocus();
+ }
+
+ public static final void main(String args[]) throws Exception {
+ r = new Robot();
+ r.setAutoDelay(100);
+
+ EventQueue.invokeAndWait(() -> createTestUI());
+ r.waitForIdle();
+ r.delay(1000);
+ try {
+ EventQueue.invokeAndWait(() -> {
+ doTest();
+ loc = frame.getLocationOnScreen();
+ width = frame.getWidth();
+ top = frame.getInsets().top;
+ });
+ doRequestFocusToTextField();
+
+ System.out.println("Focused window: " +
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().
+ getFocusedWindow());
+ System.out.println("Focus owner: " +
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().
+ getFocusOwner());
+
+ if (!passed) {
+ throw new RuntimeException("TextField got no focus! Test failed.");
+ }
+ } finally {
+ EventQueue.invokeAndWait(() -> {
+ if (frame != null) {
+ frame.dispose();
+ }
+ });
+ }
+ }
+}
+
diff --git a/test/jdk/java/awt/Focus/FocusKeepTest.java b/test/jdk/java/awt/Focus/FocusKeepTest.java
new file mode 100644
index 0000000000000..0adc463f5d9ae
--- /dev/null
+++ b/test/jdk/java/awt/Focus/FocusKeepTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4128659
+ * @summary Tests whether a focus request will work on a focus lost event.
+ * @key headful
+ * @run main FocusKeepTest
+ */
+
+import java.awt.BorderLayout;
+import java.awt.KeyboardFocusManager;
+import java.awt.Robot;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+
+public class FocusKeepTest {
+
+ static JFrame frame;
+ static JTextField tf;
+
+ public static void main(String[] args) throws Exception {
+ Robot robot = new Robot();
+ robot.setAutoDelay(100);
+ try {
+ SwingUtilities.invokeAndWait(() -> createTestUI());
+ robot.waitForIdle();
+ robot.delay(1000);
+ robot.keyPress(KeyEvent.VK_TAB);
+ robot.keyRelease(KeyEvent.VK_TAB);
+ if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() instanceof JTextField tf1) {
+ if (!tf1.getText().equals("TextField 1")) {
+ throw new RuntimeException("Focus on wrong textfield");
+ }
+ } else {
+ throw new RuntimeException("Focus not on correct component");
+ }
+ } finally {
+ SwingUtilities.invokeAndWait(() -> {
+ if (frame != null) {
+ frame.dispose();
+ }
+ });
+ }
+ }
+
+ private static void createTestUI() {
+ frame = new JFrame("FocusKeepTest");
+ tf = new JTextField("TextField 1");
+ tf.addFocusListener(new MyFocusAdapter("TextField 1"));
+ frame.add(tf, BorderLayout.NORTH);
+
+ tf = new JTextField("TextField 2");
+ tf.addFocusListener(new MyFocusAdapter("TextField 2"));
+ frame.add(tf, BorderLayout.SOUTH);
+
+ frame.pack();
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ }
+
+ static class MyFocusAdapter extends FocusAdapter {
+ private String myName;
+
+ public MyFocusAdapter (String name) {
+ myName = name;
+ }
+
+ public void focusLost (FocusEvent e) {
+ if (myName.equals ("TextField 1")) {
+ e.getComponent().requestFocus ();
+ }
+ }
+
+ public void focusGained (FocusEvent e) {
+ }
+ }
+}
diff --git a/test/jdk/java/awt/Focus/KeyStrokeTest.java b/test/jdk/java/awt/Focus/KeyStrokeTest.java
new file mode 100644
index 0000000000000..7c462ce8f22d6
--- /dev/null
+++ b/test/jdk/java/awt/Focus/KeyStrokeTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2003, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4845868
+ * @summary REGRESSION: First keystroke after JDialog is closed is lost
+ * @key headful
+ * @run main KeyStrokeTest
+ */
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.Robot;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+public class KeyStrokeTest {
+ static boolean keyTyped;
+ static Frame frame;
+
+ public static void main(String[] args) throws Exception {
+ try {
+ KeyStrokeTest test = new KeyStrokeTest();
+ test.doTest();
+ } finally {
+ if (frame != null) {
+ frame.dispose();
+ }
+ }
+ }
+
+ private static void doTest() throws Exception {
+ final Object monitor = new Object();
+ frame = new Frame();
+ TextField textField = new TextField() {
+ public void transferFocus() {
+ System.err.println("transferFocus()");
+ final Dialog dialog = new Dialog(frame, true);
+ Button btn = new Button("Close It");
+ btn.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.err.println("action performed");
+ dialog.setVisible(false);
+ }
+ });
+ dialog.add(btn);
+ dialog.setSize(200, 200);
+ dialog.setVisible(true);
+ }
+ };
+
+ textField.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ System.err.println(e);
+ if (e.getKeyChar() == 'a') {
+ keyTyped = true;
+ }
+
+ synchronized (monitor) {
+ monitor.notifyAll();
+ }
+ }
+ });
+ frame.add(textField);
+ frame.setSize(400, 400);
+ frame.setVisible(true);
+
+ Robot robot = new Robot();
+ robot.waitForIdle();
+ robot.delay(1000);
+ robot.keyPress(KeyEvent.VK_TAB);
+ robot.keyRelease(KeyEvent.VK_TAB);
+
+ robot.delay(1000);
+ robot.keyPress(KeyEvent.VK_SPACE);
+ robot.keyRelease(KeyEvent.VK_SPACE);
+
+ robot.delay(1000);
+ synchronized (monitor) {
+ robot.keyPress(KeyEvent.VK_A);
+ robot.keyRelease(KeyEvent.VK_A);
+ monitor.wait(3000);
+ }
+
+ if (!keyTyped) {
+ throw new RuntimeException("TEST FAILED");
+ }
+
+ System.out.println("Test passed");
+ }
+
+}
From 9d76c7c60ff3133c1078892d7c50a2cfc9ff9c1b Mon Sep 17 00:00:00 2001
From: Aleksey Shipilev
Date: Fri, 20 Sep 2024 07:00:38 +0000
Subject: [PATCH 025/110] 8340418: GHA: MacOS AArch64 bundles can be removed
prematurely
Reviewed-by: erikj
---
.github/workflows/main.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index e4c05acb684b7..d5958853701ca 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -384,6 +384,7 @@ jobs:
- build-windows-aarch64
- test-linux-x64
- test-macos-x64
+ - test-macos-aarch64
- test-windows-x64
steps:
From 5d611c0377d4b5d5495d3941a6a63b128142a2dc Mon Sep 17 00:00:00 2001
From: SendaoYan
Date: Fri, 20 Sep 2024 07:34:26 +0000
Subject: [PATCH 026/110] 8340439: AArch64: Extra entry declaration for
assember test
Reviewed-by: haosun, lmesnik, mli
---
.../cpu/aarch64/templateInterpreterGenerator_aarch64.cpp | 6 ------
1 file changed, 6 deletions(-)
diff --git a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp
index 38d48b86f23b0..3210789bbbdfa 100644
--- a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp
@@ -69,12 +69,6 @@ int TemplateInterpreter::InterpreterCodeSize = 200 * 1024;
#define __ _masm->
-//-----------------------------------------------------------------------------
-
-extern "C" void entry(CodeBuffer*);
-
-//-----------------------------------------------------------------------------
-
address TemplateInterpreterGenerator::generate_slow_signature_handler() {
address entry = __ pc();
From a50440fadcd1aa9d8bfddc153dbde6fd55ceb9fa Mon Sep 17 00:00:00 2001
From: Claes Redestad
Date: Fri, 20 Sep 2024 09:21:12 +0000
Subject: [PATCH 027/110] 8340456: Reduce overhead of proxying Object methods
in ProxyGenerator
Reviewed-by: liach
---
.../java/lang/reflect/ProxyGenerator.java | 52 ++++++++-----
.../reflect/{Proxy => proxy}/ProxyBench.java | 0
.../ProxyGeneratorBench.java} | 78 ++++++-------------
3 files changed, 55 insertions(+), 75 deletions(-)
rename test/micro/org/openjdk/bench/java/lang/reflect/{Proxy => proxy}/ProxyBench.java (100%)
rename test/micro/org/openjdk/bench/java/lang/reflect/{Proxy/ProxyPerf.java => proxy/ProxyGeneratorBench.java} (57%)
diff --git a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
index 2e56d03c6ad89..abdcaf5ae1fa2 100644
--- a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
+++ b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
@@ -114,11 +114,18 @@ final class ProxyGenerator {
private static final Method OBJECT_EQUALS_METHOD;
private static final Method OBJECT_TO_STRING_METHOD;
+ private static final String OBJECT_HASH_CODE_SIG;
+ private static final String OBJECT_EQUALS_SIG;
+ private static final String OBJECT_TO_STRING_SIG;
+
static {
try {
OBJECT_HASH_CODE_METHOD = Object.class.getMethod("hashCode");
+ OBJECT_HASH_CODE_SIG = OBJECT_HASH_CODE_METHOD.toShortSignature();
OBJECT_EQUALS_METHOD = Object.class.getMethod("equals", Object.class);
+ OBJECT_EQUALS_SIG = OBJECT_EQUALS_METHOD.toShortSignature();
OBJECT_TO_STRING_METHOD = Object.class.getMethod("toString");
+ OBJECT_TO_STRING_SIG = OBJECT_TO_STRING_METHOD.toShortSignature();
} catch (NoSuchMethodException e) {
throw new NoSuchMethodError(e.getMessage());
}
@@ -446,9 +453,9 @@ private byte[] generateClassFile() {
* java.lang.Object take precedence over duplicate methods in the
* proxy interfaces.
*/
- addProxyMethod(new ProxyMethod(OBJECT_HASH_CODE_METHOD, "m0"));
- addProxyMethod(new ProxyMethod(OBJECT_EQUALS_METHOD, "m1"));
- addProxyMethod(new ProxyMethod(OBJECT_TO_STRING_METHOD, "m2"));
+ addProxyMethod(new ProxyMethod(OBJECT_HASH_CODE_METHOD, OBJECT_HASH_CODE_SIG, "m0"));
+ addProxyMethod(new ProxyMethod(OBJECT_EQUALS_METHOD, OBJECT_EQUALS_SIG, "m1"));
+ addProxyMethod(new ProxyMethod(OBJECT_TO_STRING_METHOD, OBJECT_TO_STRING_SIG, "m2"));
/*
* Accumulate all of the methods from the proxy interfaces.
@@ -526,7 +533,7 @@ private void addProxyMethod(Method m, Class> fromClass) {
return;
}
}
- sigmethods.add(new ProxyMethod(m, sig, m.getSharedParameterTypes(), returnType,
+ sigmethods.add(new ProxyMethod(m, sig, returnType,
exceptionTypes, fromClass, "m" + proxyMethodCount++));
}
@@ -617,11 +624,11 @@ private void generateLookupAccessor(ClassBuilder clb) {
Label failLabel = cob.newLabel();
ClassEntry mhl = cp.classEntry(CD_MethodHandles_Lookup);
ClassEntry iae = cp.classEntry(CD_IllegalAccessException);
- cob.aload(cob.parameterSlot(0))
+ cob.aload(0)
.invokevirtual(cp.methodRefEntry(mhl, cp.nameAndTypeEntry("lookupClass", MTD_Class)))
.ldc(proxyCE)
.if_acmpne(failLabel)
- .aload(cob.parameterSlot(0))
+ .aload(0)
.invokevirtual(cp.methodRefEntry(mhl, cp.nameAndTypeEntry("hasFullPrivilegeAccess", MTD_boolean)))
.ifeq(failLabel)
.invokestatic(CD_MethodHandles, "lookup", MTD_MethodHandles$Lookup)
@@ -629,7 +636,7 @@ private void generateLookupAccessor(ClassBuilder clb) {
.labelBinding(failLabel)
.new_(iae)
.dup()
- .aload(cob.parameterSlot(0))
+ .aload(0)
.invokevirtual(cp.methodRefEntry(mhl, cp.nameAndTypeEntry("toString", MTD_String)))
.invokespecial(cp.methodRefEntry(iae, exInit))
.athrow()
@@ -650,18 +657,16 @@ private class ProxyMethod {
private final Method method;
private final String shortSignature;
private final Class> fromClass;
- private final Class>[] parameterTypes;
private final Class> returnType;
private final String methodFieldName;
private Class>[] exceptionTypes;
private final FieldRefEntry methodField;
- private ProxyMethod(Method method, String sig, Class>[] parameterTypes,
+ private ProxyMethod(Method method, String sig,
Class> returnType, Class>[] exceptionTypes,
Class> fromClass, String methodFieldName) {
this.method = method;
this.shortSignature = sig;
- this.parameterTypes = parameterTypes;
this.returnType = returnType;
this.exceptionTypes = exceptionTypes;
this.fromClass = fromClass;
@@ -670,14 +675,17 @@ private ProxyMethod(Method method, String sig, Class>[] parameterTypes,
cp.nameAndTypeEntry(methodFieldName, CD_Method));
}
+ private Class>[] parameterTypes() {
+ return method.getSharedParameterTypes();
+ }
+
/**
* Create a new specific ProxyMethod with a specific field name
*
* @param method The method for which to create a proxy
*/
- private ProxyMethod(Method method, String methodFieldName) {
- this(method, method.toShortSignature(),
- method.getSharedParameterTypes(), method.getReturnType(),
+ private ProxyMethod(Method method, String sig, String methodFieldName) {
+ this(method, sig, method.getReturnType(),
method.getSharedExceptionTypes(), method.getDeclaringClass(), methodFieldName);
}
@@ -685,17 +693,18 @@ private ProxyMethod(Method method, String methodFieldName) {
* Generate this method, including the code and exception table entry.
*/
private void generateMethod(ClassBuilder clb) {
- var desc = methodTypeDesc(returnType, parameterTypes);
+ var desc = methodTypeDesc(returnType, parameterTypes());
int accessFlags = (method.isVarArgs()) ? ACC_VARARGS | ACC_PUBLIC | ACC_FINAL
: ACC_PUBLIC | ACC_FINAL;
- var catchList = computeUniqueCatchList(exceptionTypes);
clb.withMethod(method.getName(), desc, accessFlags, mb ->
mb.with(ExceptionsAttribute.of(toClassEntries(cp, List.of(exceptionTypes))))
.withCode(cob -> {
+ var catchList = computeUniqueCatchList(exceptionTypes);
cob.aload(cob.receiverSlot())
.getfield(handlerField)
.aload(cob.receiverSlot())
.getstatic(methodField);
+ Class>[] parameterTypes = parameterTypes();
if (parameterTypes.length > 0) {
// Create an array and fill with the parameters converting primitives to wrappers
cob.loadConstant(parameterTypes.length)
@@ -784,6 +793,7 @@ private void codeFieldInitialization(CodeBuilder cob) {
var cp = cob.constantPool();
codeClassForName(cob, fromClass);
+ Class>[] parameterTypes = parameterTypes();
cob.ldc(method.getName())
.loadConstant(parameterTypes.length)
.anewarray(classCE);
@@ -817,10 +827,14 @@ private void codeFieldInitialization(CodeBuilder cob) {
* loader is anticipated at local variable index 0.
*/
private void codeClassForName(CodeBuilder cob, Class> cl) {
- cob.ldc(cl.getName())
- .iconst_0() // false
- .aload(0)// classLoader
- .invokestatic(classForName);
+ if (cl == Object.class) {
+ cob.ldc(objectCE);
+ } else {
+ cob.ldc(cl.getName())
+ .iconst_0() // false
+ .aload(0)// classLoader
+ .invokestatic(classForName);
+ }
}
@Override
diff --git a/test/micro/org/openjdk/bench/java/lang/reflect/Proxy/ProxyBench.java b/test/micro/org/openjdk/bench/java/lang/reflect/proxy/ProxyBench.java
similarity index 100%
rename from test/micro/org/openjdk/bench/java/lang/reflect/Proxy/ProxyBench.java
rename to test/micro/org/openjdk/bench/java/lang/reflect/proxy/ProxyBench.java
diff --git a/test/micro/org/openjdk/bench/java/lang/reflect/Proxy/ProxyPerf.java b/test/micro/org/openjdk/bench/java/lang/reflect/proxy/ProxyGeneratorBench.java
similarity index 57%
rename from test/micro/org/openjdk/bench/java/lang/reflect/Proxy/ProxyPerf.java
rename to test/micro/org/openjdk/bench/java/lang/reflect/proxy/ProxyGeneratorBench.java
index 22fe4d3ef28db..3393431730080 100644
--- a/test/micro/org/openjdk/bench/java/lang/reflect/Proxy/ProxyPerf.java
+++ b/test/micro/org/openjdk/bench/java/lang/reflect/proxy/ProxyGeneratorBench.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -26,7 +26,6 @@
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.CompilerControl;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
@@ -36,37 +35,29 @@
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.infra.Blackhole;
-
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.util.concurrent.TimeUnit;
/**
* Benchmark measuring java.lang.reflect.ProxyGenerator.generateProxyClass.
* It bypasses the cache of proxies to measure the time to construct a proxy.
*/
-@Warmup(iterations = 5)
-@Measurement(iterations = 10)
-@Fork(value = 1)
+@Warmup(iterations = 5, time = 2)
+@Measurement(iterations = 5, time = 2)
+@Fork(value = 1, jvmArgsPrepend = "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED")
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
-public class ProxyPerf {
+public class ProxyGeneratorBench {
/**
* Sample results from a Dell T7610.
* Benchmark Mode Cnt Score Error Units
* ProxyPerf.genIntf_1 avgt 10 35325.428 +/- 780.459 ns/op
- * ProxyPerf.genIntf_1_V49 avgt 10 34309.423 +/- 727.188 ns/op
* ProxyPerf.genStringsIntf_3 avgt 10 46600.366 +/- 663.812 ns/op
- * ProxyPerf.genStringsIntf_3_V49 avgt 10 45911.817 +/- 1598.536 ns/op
* ProxyPerf.genZeroParams avgt 10 33245.048 +/- 437.988 ns/op
- * ProxyPerf.genZeroParams_V49 avgt 10 32954.254 +/- 1041.932 ns/op
- * ProxyPerf.getPrimsIntf_2 avgt 10 43987.819 +/- 837.443 ns/op
- * ProxyPerf.getPrimsIntf_2_V49 avgt 10 42863.462 +/- 1193.480 ns/op
+ * ProxyPerf.genPrimsIntf_2 avgt 10 43987.819 +/- 837.443 ns/op
*/
public interface Intf_1 {
@@ -84,7 +75,6 @@ public interface Intf_3 {
public String m2String(String s1, String s2);
}
- private InvocationHandler handler;
private ClassLoader classloader;
private Method proxyGen;
private Method proxyGenV49;
@@ -92,19 +82,11 @@ public interface Intf_3 {
@Setup
public void setup() {
try {
- handler = (Object proxy, Method method, Object[] args) -> null;
classloader = ClassLoader.getSystemClassLoader();
Class> proxyGenClass = Class.forName("java.lang.reflect.ProxyGenerator");
proxyGen = proxyGenClass.getDeclaredMethod("generateProxyClass",
ClassLoader.class, String.class, java.util.List.class, int.class);
proxyGen.setAccessible(true);
-
- // Init access to the old Proxy generator
- Class> proxyGenClassV49 = Class.forName("java.lang.reflect.ProxyGenerator_v49");
- proxyGenV49 = proxyGenClassV49.getDeclaredMethod("generateProxyClass",
- String.class, java.util.List.class, int.class);
- proxyGenV49.setAccessible(true);
-
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException("ProxyClass setup fails", ex);
@@ -112,51 +94,35 @@ public void setup() {
}
@Benchmark
- public void genZeroParams(Blackhole bh) throws Exception {
+ public Object genZeroParams() throws Exception {
List> interfaces = List.of(Runnable.class);
- bh.consume(proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1));
+ return proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1);
}
@Benchmark
- public void genIntf_1(Blackhole bh) throws Exception {
+ public Object genIntf_1() throws Exception {
List> interfaces = List.of(Intf_1.class);
- bh.consume(proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1));
+ return proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1);
}
@Benchmark
- public void getPrimsIntf_2(Blackhole bh) throws Exception {
+ public Object genPrimsIntf_2() throws Exception {
List> interfaces = List.of(Intf_2.class);
- bh.consume(proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1));
- }
- @Benchmark
- public void genStringsIntf_3(Blackhole bh) throws Exception {
- List> interfaces = List.of(Intf_3.class);
- bh.consume(proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1));
+ return proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1);
}
- // Generate using the V49inal generator for comparison
-
@Benchmark
- public void genZeroParams_V49(Blackhole bh) throws Exception {
- List> interfaces = List.of(Runnable.class);
- bh.consume(proxyGenV49.invoke(null, "ProxyImpl", interfaces, 1));
- }
-
- @Benchmark
- public void genIntf_1_V49(Blackhole bh) throws Exception {
- List> interfaces = List.of(Intf_1.class);
- bh.consume(proxyGenV49.invoke(null, "ProxyImpl", interfaces, 1));
- }
-
- @Benchmark
- public void getPrimsIntf_2_V49(Blackhole bh) throws Exception {
- List> interfaces = List.of(Intf_2.class);
- bh.consume(proxyGenV49.invoke(null, "ProxyImpl", interfaces, 1));
- }
- @Benchmark
- public void genStringsIntf_3_V49(Blackhole bh) throws Exception {
+ public Object genStringsIntf_3() throws Exception {
List> interfaces = List.of(Intf_3.class);
- bh.consume(proxyGenV49.invoke(null, "ProxyImpl", interfaces, 1));
+ return proxyGen.invoke(null, classloader, "ProxyImpl", interfaces, 1);
}
+ public static void main(String... args) throws Exception {
+ var benchmark = new ProxyGeneratorBench();
+ benchmark.setup();
+ benchmark.genZeroParams();
+ benchmark.genIntf_1();
+ benchmark.genPrimsIntf_2();
+ benchmark.genStringsIntf_3();
+ }
}
From 3ad6e31d81bb8a47dc73a6342a6524a901f07687 Mon Sep 17 00:00:00 2001
From: Hamlin Li
Date: Fri, 20 Sep 2024 09:33:31 +0000
Subject: [PATCH 028/110] 8340438: RISC-V: minor improvement in base64
Reviewed-by: fyang
---
src/hotspot/cpu/riscv/stubGenerator_riscv.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp b/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
index 9162c1d520027..ee14d045407a0 100644
--- a/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
+++ b/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
@@ -5491,9 +5491,7 @@ class StubGenerator: public StubCodeGenerator {
Register stepSrcM2 = doff;
Register stepDst = isURL;
Register size = x29; // t4
- Register minusOne = x30; // t5
- __ mv(minusOne, -1);
__ mv(size, MaxVectorSize * 2);
__ mv(stepSrcM1, MaxVectorSize * 4);
__ slli(stepSrcM2, stepSrcM1, 1);
@@ -5513,7 +5511,8 @@ class StubGenerator: public StubCodeGenerator {
__ sub(length, length, stepSrcM2);
// error check
- __ bne(failedIdx, minusOne, Exit);
+ // valid value of failedIdx can only be -1 when < 0
+ __ bgez(failedIdx, Exit);
__ bge(length, stepSrcM2, ProcessM2);
@@ -5533,7 +5532,8 @@ class StubGenerator: public StubCodeGenerator {
__ sub(length, length, stepSrcM1);
// error check
- __ bne(failedIdx, minusOne, Exit);
+ // valid value of failedIdx can only be -1 when < 0
+ __ bgez(failedIdx, Exit);
__ BIND(ProcessScalar);
__ beqz(length, Exit);
From 3c22d83c0fb9eee2e2b87e607680b96363849c16 Mon Sep 17 00:00:00 2001
From: Alexey Ivanov
Date: Fri, 20 Sep 2024 10:07:03 +0000
Subject: [PATCH 029/110] 8340008: KeyEvent/KeyTyped/Numpad1KeyTyped.java has
15 seconds timeout
Reviewed-by: azvegint, prr
---
.../KeyEvent/KeyTyped/Numpad1KeyTyped.java | 178 ++++++++++++++++++
1 file changed, 178 insertions(+)
create mode 100644 test/jdk/java/awt/event/KeyEvent/KeyTyped/Numpad1KeyTyped.java
diff --git a/test/jdk/java/awt/event/KeyEvent/KeyTyped/Numpad1KeyTyped.java b/test/jdk/java/awt/event/KeyEvent/KeyTyped/Numpad1KeyTyped.java
new file mode 100644
index 0000000000000..a944be855810a
--- /dev/null
+++ b/test/jdk/java/awt/event/KeyEvent/KeyTyped/Numpad1KeyTyped.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2002, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Frame;
+import java.awt.Robot;
+import java.awt.TextField;
+import java.awt.Toolkit;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.util.concurrent.CountDownLatch;
+
+import jdk.test.lib.Platform;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/*
+ * @test
+ * @bug 4724007
+ * @key headful
+ * @summary Tests that KeyTyped events are fired for the Numpad1 key
+ * @library /test/lib
+ * @build jdk.test.lib.Platform
+ * @run main Numpad1KeyTyped
+ */
+public final class Numpad1KeyTyped extends FocusAdapter implements KeyListener {
+
+ private static final String ORIGINAL = "0123456789";
+ private static final String EXPECTED = "10123456789";
+
+ private final CountDownLatch typedNum1 = new CountDownLatch(1);
+ private final CountDownLatch focusGained = new CountDownLatch(1);
+
+ public static void main(String[] args) throws Exception {
+ Numpad1KeyTyped test = new Numpad1KeyTyped();
+ test.start();
+ }
+
+ private void start() throws Exception {
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ Boolean oldState = null;
+
+ Robot robot = new Robot();
+ robot.setAutoDelay(100);
+
+ Frame frame = new Frame("Numpad1KeyTyped");
+ TextField tf = new TextField(ORIGINAL, 20);
+ frame.add(tf);
+ tf.addKeyListener(this);
+
+ tf.addFocusListener(this);
+
+ frame.setSize(300, 100);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ tf.requestFocusInWindow();
+
+ if (!focusGained.await(2, SECONDS)) {
+ throw new RuntimeException("TextField didn't receive focus");
+ }
+ robot.waitForIdle();
+
+ try {
+ // Move cursor to start of TextField
+ robot.keyPress(KeyEvent.VK_HOME);
+ robot.keyRelease(KeyEvent.VK_HOME);
+ robot.waitForIdle();
+
+ if (Platform.isLinux()) {
+ // Press but don't release NumLock
+ robot.keyPress(KeyEvent.VK_NUM_LOCK);
+ }
+ if (Platform.isWindows()) {
+ oldState = toolkit.getLockingKeyState(KeyEvent.VK_NUM_LOCK);
+ toolkit.setLockingKeyState(KeyEvent.VK_NUM_LOCK, true);
+ }
+
+ // Press and release Numpad-1
+ robot.keyPress(KeyEvent.VK_NUMPAD1);
+ robot.keyRelease(KeyEvent.VK_NUMPAD1);
+
+ if (!typedNum1.await(2, SECONDS)) {
+ throw new RuntimeException("TextField didn't receive keyTyped('1') - too slow");
+ }
+
+ final String text = tf.getText();
+ if (!text.equals(EXPECTED)) {
+ throw new RuntimeException("Test FAILED: wrong string '"
+ + text + "' vs "
+ + "expected '" + EXPECTED + "'");
+ }
+ System.out.println("Test PASSED");
+ } finally {
+ if (Platform.isLinux()) {
+ // "release" + "press and release" NumLock to disable numlock
+ robot.keyRelease(KeyEvent.VK_NUM_LOCK);
+ robot.keyPress(KeyEvent.VK_NUM_LOCK);
+ robot.keyRelease(KeyEvent.VK_NUM_LOCK);
+ }
+ if (oldState != null) {
+ toolkit.setLockingKeyState(KeyEvent.VK_NUM_LOCK, oldState);
+ }
+
+ frame.dispose();
+ }
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ System.out.println("tf.focusGained");
+ focusGained.countDown();
+ }
+
+ @Override
+ public void keyPressed(KeyEvent evt) {
+ printKey(evt);
+ }
+
+ @Override
+ public void keyTyped(KeyEvent evt) {
+ printKey(evt);
+
+ int keychar = evt.getKeyChar();
+ if (keychar == '1') {
+ typedNum1.countDown();
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent evt) {
+ printKey(evt);
+ System.out.println();
+ }
+
+ private static void printKey(KeyEvent evt) {
+ int id = evt.getID();
+ if (id != KeyEvent.KEY_TYPED
+ && id != KeyEvent.KEY_PRESSED
+ && id != KeyEvent.KEY_RELEASED) {
+
+ System.out.println("Other Event");
+ return;
+ }
+
+ System.out.println("params= " + evt.paramString() + " \n" +
+ "KeyChar: " + evt.getKeyChar() + " = " + (int) evt.getKeyChar() +
+ " KeyCode: " + evt.getKeyCode() +
+ " Modifiers: " + evt.getModifiersEx());
+
+ if (evt.isActionKey()) {
+ System.out.println(" Action Key");
+ }
+
+ System.out.println("keyText= " + KeyEvent.getKeyText(evt.getKeyCode()) + "\n");
+ }
+
+}
From fe80618bf3f80094a93239dd43d4a9b515c5fa18 Mon Sep 17 00:00:00 2001
From: Andrey Turbanov
Date: Fri, 20 Sep 2024 12:43:57 +0000
Subject: [PATCH 030/110] 8339972: Make a few fields in
SortingFocusTraversalPolicy static
Reviewed-by: azvegint, aivanov
---
.../classes/javax/swing/SortingFocusTraversalPolicy.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java b/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java
index 384a805996289..92f98fdfc992f 100644
--- a/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java
+++ b/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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,8 +87,8 @@ public class SortingFocusTraversalPolicy
private static final SwingContainerOrderFocusTraversalPolicy
fitnessTestPolicy = new SwingContainerOrderFocusTraversalPolicy();
- private final int FORWARD_TRAVERSAL = 0;
- private final int BACKWARD_TRAVERSAL = 1;
+ private static final int FORWARD_TRAVERSAL = 0;
+ private static final int BACKWARD_TRAVERSAL = 1;
/*
* When true (by default), the legacy merge-sort algo is used to sort an FTP cycle.
From ae63aaaa5847a68542e1483ecf1f0d5a3704e741 Mon Sep 17 00:00:00 2001
From: Thomas Stuefe
Date: Fri, 20 Sep 2024 14:10:39 +0000
Subject: [PATCH 031/110] 8340540: Problemlist DcmdMBeanPermissionsTest.java
and SystemDumpMapTest.java
Reviewed-by: kevinw
---
test/hotspot/jtreg/ProblemList.txt | 2 ++
test/jdk/ProblemList.txt | 2 ++
2 files changed, 4 insertions(+)
diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt
index 2086bc2ed054b..b1a56bcce12c8 100644
--- a/test/hotspot/jtreg/ProblemList.txt
+++ b/test/hotspot/jtreg/ProblemList.txt
@@ -136,6 +136,8 @@ serviceability/jvmti/vthread/GetThreadStateMountedTest/GetThreadStateMountedTest
serviceability/jvmti/vthread/GetSetLocalTest/GetSetLocalTest.java 8286836 generic-all
serviceability/jvmti/vthread/CarrierThreadEventNotification/CarrierThreadEventNotification.java 8333681 generic-all
serviceability/dcmd/gc/RunFinalizationTest.java 8227120 generic-all
+serviceability/dcmd/vm/SystemDumpMapTest.java 8340401 windows-all
+serviceability/dcmd/vm/SystemMapTest.java 8340401 windows-all
serviceability/sa/ClhsdbCDSCore.java 8267433,8318754 macosx-x64,macosx-aarch64
serviceability/sa/ClhsdbFindPC.java#xcomp-core 8267433,8318754 macosx-x64,macosx-aarch64
diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt
index 8990b02c1601f..0990e1da457fd 100644
--- a/test/jdk/ProblemList.txt
+++ b/test/jdk/ProblemList.txt
@@ -516,6 +516,8 @@ java/io/pathNames/GeneralWin32.java 8180264 windows-
com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java 8030957 aix-all
com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957 aix-all
+com/sun/management/DiagnosticCommandMBean/DcmdMBeanPermissionsTest.java 8340401 windows-all
+
java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all
java/lang/management/MemoryMXBean/PendingAllGC.sh 8158837 generic-all
From 9bcde4ffca20941b010ed454b2fcb948d24b3cac Mon Sep 17 00:00:00 2001
From: Amit Kumar
Date: Fri, 20 Sep 2024 14:46:10 +0000
Subject: [PATCH 032/110] 8338658: New Object to ObjectMonitor mapping: s390x
implementation
Reviewed-by: lucy, mdoerr
---
.../cpu/s390/c1_MacroAssembler_s390.cpp | 2 +-
.../cpu/s390/c2_MacroAssembler_s390.cpp | 4 +-
src/hotspot/cpu/s390/interp_masm_s390.cpp | 2 +-
src/hotspot/cpu/s390/macroAssembler_s390.cpp | 199 ++++++++++++------
src/hotspot/cpu/s390/macroAssembler_s390.hpp | 6 +-
src/hotspot/cpu/s390/sharedRuntime_s390.cpp | 4 +-
.../share/runtime/basicLock.inline.hpp | 2 +-
7 files changed, 144 insertions(+), 75 deletions(-)
diff --git a/src/hotspot/cpu/s390/c1_MacroAssembler_s390.cpp b/src/hotspot/cpu/s390/c1_MacroAssembler_s390.cpp
index f3fa19ddb31e0..f6dd20db3d67f 100644
--- a/src/hotspot/cpu/s390/c1_MacroAssembler_s390.cpp
+++ b/src/hotspot/cpu/s390/c1_MacroAssembler_s390.cpp
@@ -79,7 +79,7 @@ void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox
assert(LockingMode != LM_MONITOR, "LM_MONITOR is already handled, by emit_lock()");
if (LockingMode == LM_LIGHTWEIGHT) {
- lightweight_lock(Roop, Rmark, tmp, slow_case);
+ lightweight_lock(Rbox, Roop, Rmark, tmp, slow_case);
} else if (LockingMode == LM_LEGACY) {
NearLabel done;
diff --git a/src/hotspot/cpu/s390/c2_MacroAssembler_s390.cpp b/src/hotspot/cpu/s390/c2_MacroAssembler_s390.cpp
index 3641d82dabea9..025ef4c8915cd 100644
--- a/src/hotspot/cpu/s390/c2_MacroAssembler_s390.cpp
+++ b/src/hotspot/cpu/s390/c2_MacroAssembler_s390.cpp
@@ -34,12 +34,12 @@
#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Register temp1, Register temp2) {
- compiler_fast_lock_lightweight_object(obj, temp1, temp2);
+ compiler_fast_lock_lightweight_object(obj, box, temp1, temp2);
}
void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register box, Register temp1, Register temp2) {
- compiler_fast_unlock_lightweight_object(obj, temp1, temp2);
+ compiler_fast_unlock_lightweight_object(obj, box, temp1, temp2);
}
//------------------------------------------------------
diff --git a/src/hotspot/cpu/s390/interp_masm_s390.cpp b/src/hotspot/cpu/s390/interp_masm_s390.cpp
index e56beaa9f569c..d00b6c3e2cc2e 100644
--- a/src/hotspot/cpu/s390/interp_masm_s390.cpp
+++ b/src/hotspot/cpu/s390/interp_masm_s390.cpp
@@ -1012,7 +1012,7 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
}
if (LockingMode == LM_LIGHTWEIGHT) {
- lightweight_lock(object, header, tmp, slow_case);
+ lightweight_lock(monitor, object, header, tmp, slow_case);
} else if (LockingMode == LM_LEGACY) {
// Load markWord from object into header.
diff --git a/src/hotspot/cpu/s390/macroAssembler_s390.cpp b/src/hotspot/cpu/s390/macroAssembler_s390.cpp
index 65a7d3abe90af..6c26e17d5ce3b 100644
--- a/src/hotspot/cpu/s390/macroAssembler_s390.cpp
+++ b/src/hotspot/cpu/s390/macroAssembler_s390.cpp
@@ -6007,10 +6007,10 @@ SkipIfEqual::~SkipIfEqual() {
// - obj: the object to be locked, contents preserved.
// - temp1, temp2: temporary registers, contents destroyed.
// Note: make sure Z_R1 is not manipulated here when C2 compiler is in play
-void MacroAssembler::lightweight_lock(Register obj, Register temp1, Register temp2, Label& slow) {
+void MacroAssembler::lightweight_lock(Register basic_lock, Register obj, Register temp1, Register temp2, Label& slow) {
assert(LockingMode == LM_LIGHTWEIGHT, "only used with new lightweight locking");
- assert_different_registers(obj, temp1, temp2);
+ assert_different_registers(basic_lock, obj, temp1, temp2);
Label push;
const Register top = temp1;
@@ -6022,6 +6022,11 @@ void MacroAssembler::lightweight_lock(Register obj, Register temp1, Register tem
// instruction emitted as it is part of C1's null check semantics.
z_lg(mark, Address(obj, mark_offset));
+ if (UseObjectMonitorTable) {
+ // Clear cache in case fast locking succeeds.
+ const Address om_cache_addr = Address(basic_lock, BasicObjectLock::lock_offset() + in_ByteSize((BasicLock::object_monitor_cache_offset_in_bytes())));
+ z_mvghi(om_cache_addr, 0);
+ }
// First we need to check if the lock-stack has room for pushing the object reference.
z_lgf(top, Address(Z_thread, ls_top_offset));
@@ -6145,8 +6150,8 @@ void MacroAssembler::lightweight_unlock(Register obj, Register temp1, Register t
bind(unlocked);
}
-void MacroAssembler::compiler_fast_lock_lightweight_object(Register obj, Register tmp1, Register tmp2) {
- assert_different_registers(obj, tmp1, tmp2);
+void MacroAssembler::compiler_fast_lock_lightweight_object(Register obj, Register box, Register tmp1, Register tmp2) {
+ assert_different_registers(obj, box, tmp1, tmp2);
// Handle inflated monitor.
NearLabel inflated;
@@ -6155,6 +6160,11 @@ void MacroAssembler::compiler_fast_lock_lightweight_object(Register obj, Registe
// Finish fast lock unsuccessfully. MUST branch to with flag == EQ
NearLabel slow_path;
+ if (UseObjectMonitorTable) {
+ // Clear cache in case fast locking succeeds.
+ z_mvghi(Address(box, BasicLock::object_monitor_cache_offset_in_bytes()), 0);
+ }
+
if (DiagnoseSyncOnValueBasedClasses != 0) {
load_klass(tmp1, obj);
z_tm(Address(tmp1, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
@@ -6219,33 +6229,77 @@ void MacroAssembler::compiler_fast_lock_lightweight_object(Register obj, Registe
{ // Handle inflated monitor.
bind(inflated);
+ const Register tmp1_monitor = tmp1;
if (!UseObjectMonitorTable) {
- // mark contains the tagged ObjectMonitor*.
- const Register tagged_monitor = mark;
- const Register zero = tmp2;
-
- // Try to CAS m->owner from null to current thread.
- // If m->owner is null, then csg succeeds and sets m->owner=THREAD and CR=EQ.
- // Otherwise, register zero is filled with the current owner.
- z_lghi(zero, 0);
- z_csg(zero, Z_thread, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner), tagged_monitor);
- z_bre(locked);
-
- // Check if recursive.
- z_cgr(Z_thread, zero); // zero contains the owner from z_csg instruction
- z_brne(slow_path);
-
- // Recursive
- z_agsi(Address(tagged_monitor, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions)), 1ll);
- z_cgr(zero, zero);
- // z_bru(locked);
- // Uncomment above line in the future, for now jump address is right next to us.
+ assert(tmp1_monitor == mark, "should be the same here");
} else {
- // OMCache lookup not supported yet. Take the slowpath.
- // Set flag to NE
- z_ltgr(obj, obj);
+ NearLabel monitor_found;
+
+ // load cache address
+ z_la(tmp1, Address(Z_thread, JavaThread::om_cache_oops_offset()));
+
+ const int num_unrolled = 2;
+ for (int i = 0; i < num_unrolled; i++) {
+ z_cg(obj, Address(tmp1));
+ z_bre(monitor_found);
+ add2reg(tmp1, in_bytes(OMCache::oop_to_oop_difference()));
+ }
+
+ NearLabel loop;
+ // Search for obj in cache
+
+ bind(loop);
+
+ // check for match.
+ z_cg(obj, Address(tmp1));
+ z_bre(monitor_found);
+
+ // search until null encountered, guaranteed _null_sentinel at end.
+ add2reg(tmp1, in_bytes(OMCache::oop_to_oop_difference()));
+ z_cghsi(0, tmp1, 0);
+ z_brne(loop); // if not EQ to 0, go for another loop
+
+ // we reached to the end, cache miss
+ z_ltgr(obj, obj); // set CC to NE
z_bru(slow_path);
+
+ // cache hit
+ bind(monitor_found);
+ z_lg(tmp1_monitor, Address(tmp1, OMCache::oop_to_monitor_difference()));
}
+ NearLabel monitor_locked;
+ // lock the monitor
+
+ // mark contains the tagged ObjectMonitor*.
+ const Register tagged_monitor = mark;
+ const Register zero = tmp2;
+
+ const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast(markWord::monitor_value));
+ const Address owner_address(tmp1_monitor, ObjectMonitor::owner_offset() - monitor_tag);
+ const Address recursions_address(tmp1_monitor, ObjectMonitor::recursions_offset() - monitor_tag);
+
+
+ // Try to CAS m->owner from null to current thread.
+ // If m->owner is null, then csg succeeds and sets m->owner=THREAD and CR=EQ.
+ // Otherwise, register zero is filled with the current owner.
+ z_lghi(zero, 0);
+ z_csg(zero, Z_thread, owner_address);
+ z_bre(monitor_locked);
+
+ // Check if recursive.
+ z_cgr(Z_thread, zero); // zero contains the owner from z_csg instruction
+ z_brne(slow_path);
+
+ // Recursive
+ z_agsi(recursions_address, 1ll);
+
+ bind(monitor_locked);
+ if (UseObjectMonitorTable) {
+ // Cache the monitor for unlock
+ z_stg(tmp1_monitor, Address(box, BasicLock::object_monitor_cache_offset_in_bytes()));
+ }
+ // set the CC now
+ z_cgr(obj, obj);
}
BLOCK_COMMENT("} handle_inflated_monitor_lightweight_locking");
@@ -6270,11 +6324,11 @@ void MacroAssembler::compiler_fast_lock_lightweight_object(Register obj, Registe
// C2 uses the value of flag (NE vs EQ) to determine the continuation.
}
-void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Register tmp1, Register tmp2) {
- assert_different_registers(obj, tmp1, tmp2);
+void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Register box, Register tmp1, Register tmp2) {
+ assert_different_registers(obj, box, tmp1, tmp2);
// Handle inflated monitor.
- NearLabel inflated, inflated_load_monitor;
+ NearLabel inflated, inflated_load_mark;
// Finish fast unlock successfully. MUST reach to with flag == EQ.
NearLabel unlocked;
// Finish fast unlock unsuccessfully. MUST branch to with flag == NE.
@@ -6294,7 +6348,7 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Regis
z_aghi(top, -oopSize);
z_cg(obj, Address(Z_thread, top));
- branch_optimized(bcondNotEqual, inflated_load_monitor);
+ branch_optimized(bcondNotEqual, inflated_load_mark);
// Pop lock-stack.
#ifdef ASSERT
@@ -6315,6 +6369,9 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Regis
// Not recursive
// Check for monitor (0b10).
+ // Because we got here by popping (meaning we pushed in locked)
+ // there will be no monitor in the box. So we need to push back the obj
+ // so that the runtime can fix any potential anonymous owner.
z_lg(mark, Address(obj, mark_offset));
z_tmll(mark, markWord::monitor_value);
if (!UseObjectMonitorTable) {
@@ -6353,7 +6410,7 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Regis
{ // Handle inflated monitor.
- bind(inflated_load_monitor);
+ bind(inflated_load_mark);
z_lg(mark, Address(obj, mark_offset));
@@ -6378,49 +6435,61 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Regis
bind(check_done);
#endif // ASSERT
+ const Register tmp1_monitor = tmp1;
+
if (!UseObjectMonitorTable) {
- // mark contains the tagged ObjectMonitor*.
- const Register monitor = mark;
+ assert(tmp1_monitor == mark, "should be the same here");
+ } else {
+ // Uses ObjectMonitorTable. Look for the monitor in our BasicLock on the stack.
+ z_lg(tmp1_monitor, Address(box, BasicLock::object_monitor_cache_offset_in_bytes()));
+ // null check with ZF == 0, no valid pointer below alignof(ObjectMonitor*)
+ z_cghi(tmp1_monitor, alignof(ObjectMonitor*));
- NearLabel not_recursive;
- const Register recursions = tmp2;
+ z_brl(slow_path);
+ }
- // Check if recursive.
- load_and_test_long(recursions, Address(monitor, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions)));
- z_bre(not_recursive); // if 0 then jump, it's not recursive locking
+ // mark contains the tagged ObjectMonitor*.
+ const Register monitor = mark;
- // Recursive unlock
- z_agsi(Address(monitor, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions)), -1ll);
- z_cgr(monitor, monitor); // set the CC to EQUAL
- z_bru(unlocked);
+ const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast(markWord::monitor_value));
+ const Address recursions_address{monitor, ObjectMonitor::recursions_offset() - monitor_tag};
+ const Address cxq_address{monitor, ObjectMonitor::cxq_offset() - monitor_tag};
+ const Address EntryList_address{monitor, ObjectMonitor::EntryList_offset() - monitor_tag};
+ const Address owner_address{monitor, ObjectMonitor::owner_offset() - monitor_tag};
- bind(not_recursive);
+ NearLabel not_recursive;
+ const Register recursions = tmp2;
- NearLabel not_ok;
- // Check if the entry lists are empty.
- load_and_test_long(tmp2, Address(monitor, OM_OFFSET_NO_MONITOR_VALUE_TAG(EntryList)));
- z_brne(not_ok);
- load_and_test_long(tmp2, Address(monitor, OM_OFFSET_NO_MONITOR_VALUE_TAG(cxq)));
- z_brne(not_ok);
+ // Check if recursive.
+ load_and_test_long(recursions, recursions_address);
+ z_bre(not_recursive); // if 0 then jump, it's not recursive locking
- z_release();
- z_stg(tmp2 /*=0*/, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner), monitor);
+ // Recursive unlock
+ z_agsi(recursions_address, -1ll);
+ z_cgr(monitor, monitor); // set the CC to EQUAL
+ z_bru(unlocked);
- z_bru(unlocked); // CC = EQ here
+ bind(not_recursive);
- bind(not_ok);
+ NearLabel not_ok;
+ // Check if the entry lists are empty.
+ load_and_test_long(tmp2, EntryList_address);
+ z_brne(not_ok);
+ load_and_test_long(tmp2, cxq_address);
+ z_brne(not_ok);
- // The owner may be anonymous, and we removed the last obj entry in
- // the lock-stack. This loses the information about the owner.
- // Write the thread to the owner field so the runtime knows the owner.
- z_stg(Z_thread, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner), monitor);
- z_bru(slow_path); // CC = NE here
- } else {
- // OMCache lookup not supported yet. Take the slowpath.
- // Set flag to NE
- z_ltgr(obj, obj);
- z_bru(slow_path);
- }
+ z_release();
+ z_stg(tmp2 /*=0*/, owner_address);
+
+ z_bru(unlocked); // CC = EQ here
+
+ bind(not_ok);
+
+ // The owner may be anonymous, and we removed the last obj entry in
+ // the lock-stack. This loses the information about the owner.
+ // Write the thread to the owner field so the runtime knows the owner.
+ z_stg(Z_thread, owner_address);
+ z_bru(slow_path); // CC = NE here
}
bind(unlocked);
diff --git a/src/hotspot/cpu/s390/macroAssembler_s390.hpp b/src/hotspot/cpu/s390/macroAssembler_s390.hpp
index c380f4dec1029..5d3a4c2994091 100644
--- a/src/hotspot/cpu/s390/macroAssembler_s390.hpp
+++ b/src/hotspot/cpu/s390/macroAssembler_s390.hpp
@@ -752,10 +752,10 @@ class MacroAssembler: public Assembler {
void compiler_fast_lock_object(Register oop, Register box, Register temp1, Register temp2);
void compiler_fast_unlock_object(Register oop, Register box, Register temp1, Register temp2);
- void lightweight_lock(Register obj, Register tmp1, Register tmp2, Label& slow);
+ void lightweight_lock(Register basic_lock, Register obj, Register tmp1, Register tmp2, Label& slow);
void lightweight_unlock(Register obj, Register tmp1, Register tmp2, Label& slow);
- void compiler_fast_lock_lightweight_object(Register obj, Register tmp1, Register tmp2);
- void compiler_fast_unlock_lightweight_object(Register obj, Register tmp1, Register tmp2);
+ void compiler_fast_lock_lightweight_object(Register obj, Register box, Register tmp1, Register tmp2);
+ void compiler_fast_unlock_lightweight_object(Register obj, Register box, Register tmp1, Register tmp2);
void resolve_jobject(Register value, Register tmp1, Register tmp2);
void resolve_global_jobject(Register value, Register tmp1, Register tmp2);
diff --git a/src/hotspot/cpu/s390/sharedRuntime_s390.cpp b/src/hotspot/cpu/s390/sharedRuntime_s390.cpp
index 9954c78ce1efa..65c94db09dcc8 100644
--- a/src/hotspot/cpu/s390/sharedRuntime_s390.cpp
+++ b/src/hotspot/cpu/s390/sharedRuntime_s390.cpp
@@ -1713,7 +1713,7 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
// Try fastpath for locking.
if (LockingMode == LM_LIGHTWEIGHT) {
// Fast_lock kills r_temp_1, r_temp_2.
- __ compiler_fast_lock_lightweight_object(r_oop, r_tmp1, r_tmp2);
+ __ compiler_fast_lock_lightweight_object(r_oop, r_box, r_tmp1, r_tmp2);
} else {
// Fast_lock kills r_temp_1, r_temp_2.
__ compiler_fast_lock_object(r_oop, r_box, r_tmp1, r_tmp2);
@@ -1917,7 +1917,7 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
// Try fastpath for unlocking.
if (LockingMode == LM_LIGHTWEIGHT) {
// Fast_unlock kills r_tmp1, r_tmp2.
- __ compiler_fast_unlock_lightweight_object(r_oop, r_tmp1, r_tmp2);
+ __ compiler_fast_unlock_lightweight_object(r_oop, r_box, r_tmp1, r_tmp2);
} else {
// Fast_unlock kills r_tmp1, r_tmp2.
__ compiler_fast_unlock_object(r_oop, r_box, r_tmp1, r_tmp2);
diff --git a/src/hotspot/share/runtime/basicLock.inline.hpp b/src/hotspot/share/runtime/basicLock.inline.hpp
index 1f3bf15a8769d..30abd575da46a 100644
--- a/src/hotspot/share/runtime/basicLock.inline.hpp
+++ b/src/hotspot/share/runtime/basicLock.inline.hpp
@@ -39,7 +39,7 @@ inline void BasicLock::set_displaced_header(markWord header) {
inline ObjectMonitor* BasicLock::object_monitor_cache() const {
assert(UseObjectMonitorTable, "must be");
-#if defined(X86) || defined(AARCH64) || defined(RISCV64) || defined(PPC64)
+#if defined(X86) || defined(AARCH64) || defined(RISCV64) || defined(PPC64) || defined(S390)
return reinterpret_cast(get_metadata());
#else
// Other platforms do not make use of the cache yet,
From e087edeb256a9743d1fdb6c295cb5add78d4552e Mon Sep 17 00:00:00 2001
From: Amit Kumar
Date: Fri, 20 Sep 2024 14:48:11 +0000
Subject: [PATCH 033/110] 8340269: [s390x] TestLargeStub.java failure after
8338123
Reviewed-by: mdoerr, lucy
---
src/hotspot/cpu/s390/downcallLinker_s390.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/hotspot/cpu/s390/downcallLinker_s390.cpp b/src/hotspot/cpu/s390/downcallLinker_s390.cpp
index 383a32448745c..85ddc5bf18548 100644
--- a/src/hotspot/cpu/s390/downcallLinker_s390.cpp
+++ b/src/hotspot/cpu/s390/downcallLinker_s390.cpp
@@ -36,8 +36,8 @@
#define __ _masm->
-static const int native_invoker_code_base_size = 512;
-static const int native_invoker_size_per_args = 8;
+static const int native_invoker_code_base_size = 384;
+static const int native_invoker_size_per_args = 12;
RuntimeStub* DowncallLinker::make_downcall_stub(BasicType* signature,
int num_args,
From 90d3a64b0afd5810981287b174c6687f0f604f36 Mon Sep 17 00:00:00 2001
From: Jaikiran Pai
Date: Fri, 20 Sep 2024 16:02:25 +0000
Subject: [PATCH 034/110] 8340537: Typo in javadoc of java.util.jar.JarFile
Reviewed-by: mullan, lancea, iris
---
src/java.base/share/classes/java/util/jar/JarFile.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/java.base/share/classes/java/util/jar/JarFile.java b/src/java.base/share/classes/java/util/jar/JarFile.java
index 77dfed3b84f2e..3dc3a49dc778e 100644
--- a/src/java.base/share/classes/java/util/jar/JarFile.java
+++ b/src/java.base/share/classes/java/util/jar/JarFile.java
@@ -90,7 +90,7 @@
*
If the {@code verify} flag is on when opening a signed jar file, the content
* of the jar entry is verified against the signature embedded inside the manifest
* that is associated with its {@link JarEntry#getRealName() path name}. For a
- * multi-release jar file, the content of a versioned entry is verfieid against
+ * multi-release jar file, the content of a versioned entry is verified against
* its own signature and {@link JarEntry#getCodeSigners()} returns its own signers.
*
* Please note that the verification process does not include validating the
From ab81197d0ded93b82eea9f8fb35d1647c4520f1e Mon Sep 17 00:00:00 2001
From: Chen Liang
Date: Fri, 20 Sep 2024 16:11:39 +0000
Subject: [PATCH 035/110] 8339198: Remove tag field from AbstractPoolEntry
Reviewed-by: asotona, redestad
---
.../classfile/impl/AbstractPoolEntry.java | 179 +++++++++++++-----
1 file changed, 136 insertions(+), 43 deletions(-)
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java
index 7ef005eaf6a98..5cc08d06ec3ee 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java
@@ -57,6 +57,8 @@
import jdk.internal.util.ArraysSupport;
import jdk.internal.vm.annotation.Stable;
+import static java.lang.classfile.ClassFile.*;
+
public abstract sealed class AbstractPoolEntry {
/*
Invariant: a {CP,BSM} entry for pool P refer only to {CP,BSM} entries
@@ -96,12 +98,10 @@ public static T maybeClone(ConstantPoolBuilder cp, T entry
}
final ConstantPool constantPool;
- public final byte tag;
private final int index;
private final int hash;
- private AbstractPoolEntry(ConstantPool constantPool, int tag, int index, int hash) {
- this.tag = (byte) tag;
+ private AbstractPoolEntry(ConstantPool constantPool, int index, int hash) {
this.index = index;
this.hash = hash;
this.constantPool = constantPool;
@@ -116,12 +116,10 @@ public int hashCode() {
return hash;
}
- public byte tag() {
- return tag;
- }
+ public abstract byte tag();
public int width() {
- return (tag == ClassFile.TAG_LONG || tag == ClassFile.TAG_DOUBLE) ? 2 : 1;
+ return 1;
}
abstract void writeTo(BufWriterImpl buf);
@@ -159,7 +157,7 @@ enum State { RAW, BYTE, CHAR, STRING }
Utf8EntryImpl(ConstantPool cpm, int index,
byte[] rawBytes, int offset, int rawLen) {
- super(cpm, ClassFile.TAG_UTF8, index, 0);
+ super(cpm, index, 0);
this.rawBytes = rawBytes;
this.offset = offset;
this.rawLen = rawLen;
@@ -171,7 +169,7 @@ enum State { RAW, BYTE, CHAR, STRING }
}
Utf8EntryImpl(ConstantPool cpm, int index, String s, int hash) {
- super(cpm, ClassFile.TAG_UTF8, index, 0);
+ super(cpm, index, 0);
this.rawBytes = null;
this.offset = 0;
this.rawLen = 0;
@@ -182,7 +180,7 @@ enum State { RAW, BYTE, CHAR, STRING }
}
Utf8EntryImpl(ConstantPool cpm, int index, Utf8EntryImpl u) {
- super(cpm, ClassFile.TAG_UTF8, index, 0);
+ super(cpm, index, 0);
this.rawBytes = u.rawBytes;
this.offset = u.offset;
this.rawLen = u.rawLen;
@@ -194,6 +192,11 @@ enum State { RAW, BYTE, CHAR, STRING }
this.typeSym = u.typeSym;
}
+ @Override
+ public byte tag() {
+ return TAG_UTF8;
+ }
+
/**
* {@jvms 4.4.7} String content is encoded in modified UTF-8.
*
@@ -417,7 +420,7 @@ public boolean equalsString(String s) {
@Override
void writeTo(BufWriterImpl pool) {
- pool.writeU1(tag);
+ pool.writeU1(TAG_UTF8);
if (rawBytes != null) {
pool.writeU2(rawLen);
pool.writeBytes(rawBytes, offset, rawLen);
@@ -449,7 +452,7 @@ abstract static sealed class AbstractRefEntry extends Abstr
protected final T ref1;
public AbstractRefEntry(ConstantPool constantPool, int tag, int index, T ref1) {
- super(constantPool, tag, index, hash1(tag, ref1.index()));
+ super(constantPool, index, hash1(tag, ref1.index()));
this.ref1 = ref1;
}
@@ -458,7 +461,7 @@ public T ref1() {
}
void writeTo(BufWriterImpl pool) {
- pool.writeU1(tag);
+ pool.writeU1(tag());
pool.writeU2(ref1.index());
}
@@ -474,7 +477,7 @@ abstract static sealed class AbstractRefsEntry
Date: Fri, 20 Sep 2024 17:54:06 +0000
Subject: [PATCH 036/110] 8340232: Optimize DataInputStream::readUTF
Reviewed-by: liach, bpb
---
.../classes/java/io/DataInputStream.java | 54 ++++++++++++++-----
1 file changed, 40 insertions(+), 14 deletions(-)
diff --git a/src/java.base/share/classes/java/io/DataInputStream.java b/src/java.base/share/classes/java/io/DataInputStream.java
index eab7a6e2f189a..59377aca429ca 100644
--- a/src/java.base/share/classes/java/io/DataInputStream.java
+++ b/src/java.base/share/classes/java/io/DataInputStream.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2024, Alibaba Group Holding Limited. 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
@@ -25,8 +26,11 @@
package java.io;
+import jdk.internal.access.JavaLangAccess;
+import jdk.internal.access.SharedSecrets;
import jdk.internal.util.ByteArray;
+import java.nio.charset.StandardCharsets;
import java.util.Objects;
/**
@@ -45,6 +49,7 @@
* @since 1.0
*/
public class DataInputStream extends FilterInputStream implements DataInput {
+ private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private static final char[] EMPTY_CHAR_ARRAY = new char[0];
@@ -573,18 +578,16 @@ public final String readUTF() throws IOException {
*/
public static final String readUTF(DataInput in) throws IOException {
int utflen = in.readUnsignedShort();
- byte[] bytearr;
- char[] chararr;
+ byte[] bytearr = null;
if (in instanceof DataInputStream dis) {
- if (dis.bytearr.length < utflen) {
- dis.bytearr = new byte[utflen*2];
- dis.chararr = new char[utflen*2];
+ if (dis.bytearr.length >= utflen) {
+ bytearr = dis.bytearr;
}
- chararr = dis.chararr;
- bytearr = dis.bytearr;
- } else {
+ }
+ boolean trusted = false;
+ if (bytearr == null) {
bytearr = new byte[utflen];
- chararr = new char[utflen];
+ trusted = true;
}
int c, char2, char3;
@@ -592,12 +595,35 @@ public static final String readUTF(DataInput in) throws IOException {
int chararr_count=0;
in.readFully(bytearr, 0, utflen);
+ int ascii = JLA.countPositives(bytearr, 0, utflen);
+ if (ascii == utflen) {
+ String str;
+ if (trusted) {
+ str = JLA.newStringNoRepl(bytearr, StandardCharsets.ISO_8859_1);
+ } else {
+ str = new String(bytearr, 0, utflen, StandardCharsets.ISO_8859_1);
+ }
+ return str;
+ }
+ if (trusted && in instanceof DataInputStream dis) {
+ dis.bytearr = bytearr;
+ trusted = false;
+ }
- while (count < utflen) {
- c = (int) bytearr[count] & 0xff;
- if (c > 127) break;
- count++;
- chararr[chararr_count++]=(char)c;
+ char[] chararr;
+ if (in instanceof DataInputStream dis) {
+ if (dis.chararr.length < (utflen << 1)) {
+ dis.chararr = new char[utflen << 1];
+ }
+ chararr = dis.chararr;
+ } else {
+ chararr = new char[utflen];
+ }
+
+ if (ascii != 0) {
+ JLA.inflateBytesToChars(bytearr, 0, chararr, 0, ascii);
+ count += ascii;
+ chararr_count += ascii;
}
while (count < utflen) {
From 5cffddc689a0134e1aaacb432d2f0fdd61dd74b1 Mon Sep 17 00:00:00 2001
From: Coleen Phillimore
Date: Fri, 20 Sep 2024 18:38:29 +0000
Subject: [PATCH 037/110] 8338471: Assert deleted methods not returned by
CallInfo
Reviewed-by: shade, jwaters, dholmes
---
src/hotspot/share/code/compiledIC.cpp | 3 +++
src/hotspot/share/interpreter/linkResolver.cpp | 12 ++++++------
src/hotspot/share/interpreter/linkResolver.hpp | 1 -
src/hotspot/share/oops/cpCache.cpp | 1 +
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/hotspot/share/code/compiledIC.cpp b/src/hotspot/share/code/compiledIC.cpp
index 079c8199b1870..f142e306a6b02 100644
--- a/src/hotspot/share/code/compiledIC.cpp
+++ b/src/hotspot/share/code/compiledIC.cpp
@@ -83,6 +83,7 @@ void CompiledICData::initialize(CallInfo* call_info, Klass* receiver_klass) {
_speculated_klass = (uintptr_t)receiver_klass;
}
if (call_info->call_kind() == CallInfo::itable_call) {
+ assert(call_info->resolved_method() != nullptr, "virtual or interface method must be found");
_itable_defc_klass = call_info->resolved_method()->method_holder();
_itable_refc_klass = call_info->resolved_klass();
}
@@ -238,6 +239,7 @@ void CompiledIC::set_to_megamorphic(CallInfo* call_info) {
return;
}
#ifdef ASSERT
+ assert(call_info->resolved_method() != nullptr, "virtual or interface method must be found");
int index = call_info->resolved_method()->itable_index();
assert(index == itable_index, "CallInfo pre-computes this");
InstanceKlass* k = call_info->resolved_method()->method_holder();
@@ -254,6 +256,7 @@ void CompiledIC::set_to_megamorphic(CallInfo* call_info) {
}
}
+ assert(call_info->selected_method() != nullptr, "virtual or interface method must be found");
log_trace(inlinecache)("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT,
p2i(_call->instruction_address()), call_info->selected_method()->print_value_string(), p2i(entry));
diff --git a/src/hotspot/share/interpreter/linkResolver.cpp b/src/hotspot/share/interpreter/linkResolver.cpp
index cadc3e8a2e802..36847580d9c63 100644
--- a/src/hotspot/share/interpreter/linkResolver.cpp
+++ b/src/hotspot/share/interpreter/linkResolver.cpp
@@ -87,7 +87,7 @@ void CallInfo::set_interface(Klass* resolved_klass,
// we should pick the vtable index from the resolved method.
// In that case, the caller must call set_virtual instead of set_interface.
assert(resolved_method->method_holder()->is_interface(), "");
- assert(itable_index == resolved_method()->itable_index(), "");
+ assert(itable_index == resolved_method->itable_index(), "");
set_common(resolved_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK);
}
@@ -1541,7 +1541,7 @@ void LinkResolver::runtime_resolve_interface_method(CallInfo& result,
}
// resolve the method in the receiver class, unless it is private
- if (!is_abstract_interpretation && !resolved_method()->is_private()) {
+ if (!is_abstract_interpretation && !resolved_method->is_private()) {
// do lookup based on receiver klass
// This search must match the linktime preparation search for itable initialization
// to correctly enforce loader constraints for interface method inheritance.
@@ -1590,17 +1590,17 @@ void LinkResolver::runtime_resolve_interface_method(CallInfo& result,
assert(is_abstract_interpretation || vtable_index == selected_method->vtable_index(), "sanity check");
result.set_virtual(resolved_klass, resolved_method, selected_method, vtable_index, CHECK);
} else if (resolved_method->has_itable_index()) {
- int itable_index = resolved_method()->itable_index();
+ int itable_index = resolved_method->itable_index();
log_develop_trace(itables)(" -- itable index: %d", itable_index);
result.set_interface(resolved_klass, resolved_method, selected_method, itable_index, CHECK);
} else {
int index = resolved_method->vtable_index();
log_develop_trace(itables)(" -- non itable/vtable index: %d", index);
assert(index == Method::nonvirtual_vtable_index, "Oops hit another case!");
- assert(resolved_method()->is_private() ||
- (resolved_method()->is_final() && resolved_method->method_holder() == vmClasses::Object_klass()),
+ assert(resolved_method->is_private() ||
+ (resolved_method->is_final() && resolved_method->method_holder() == vmClasses::Object_klass()),
"Should only have non-virtual invokeinterface for private or final-Object methods!");
- assert(resolved_method()->can_be_statically_bound(), "Should only have non-virtual invokeinterface for statically bound methods!");
+ assert(resolved_method->can_be_statically_bound(), "Should only have non-virtual invokeinterface for statically bound methods!");
// This sets up the nonvirtual form of "virtual" call (as needed for final and private methods)
result.set_virtual(resolved_klass, resolved_method, resolved_method, index, CHECK);
}
diff --git a/src/hotspot/share/interpreter/linkResolver.hpp b/src/hotspot/share/interpreter/linkResolver.hpp
index 340c7d412d599..69bdf56137d41 100644
--- a/src/hotspot/share/interpreter/linkResolver.hpp
+++ b/src/hotspot/share/interpreter/linkResolver.hpp
@@ -99,7 +99,6 @@ class CallInfo : public StackObj {
// Materialize a java.lang.invoke.ResolvedMethodName for this resolved_method
void set_resolved_method_name(TRAPS);
- BasicType result_type() const { return selected_method()->result_type(); }
CallKind call_kind() const { return _call_kind; }
int vtable_index() const {
// Even for interface calls the vtable index could be non-negative.
diff --git a/src/hotspot/share/oops/cpCache.cpp b/src/hotspot/share/oops/cpCache.cpp
index 817a35959f348..321d8add75594 100644
--- a/src/hotspot/share/oops/cpCache.cpp
+++ b/src/hotspot/share/oops/cpCache.cpp
@@ -604,6 +604,7 @@ void ConstantPoolCache::adjust_method_entries(bool * trace_name_printed) {
if (old_method == nullptr || !old_method->is_old()) {
continue;
}
+ assert(!old_method->is_deleted(), "cannot delete these methods");
Method* new_method = old_method->get_new_method();
resolved_indy_entry_at(j)->adjust_method_entry(new_method);
log_adjust("indy", old_method, new_method, trace_name_printed);
From 64275e6bbf1377c9a9d77fe3c3ed8d4143138f11 Mon Sep 17 00:00:00 2001
From: Severin Gehwolf
Date: Fri, 20 Sep 2024 19:34:24 +0000
Subject: [PATCH 038/110] 8340092: [Linux]
containers/systemd/SystemdMemoryAwarenessTest.java failing on some systems
Reviewed-by: mbaesken
---
.../jtreg/containers/systemd/TEST.properties | 24 +++++++
.../containers/systemd/SystemdTestUtils.java | 62 +++++++++++++------
2 files changed, 68 insertions(+), 18 deletions(-)
create mode 100644 test/hotspot/jtreg/containers/systemd/TEST.properties
diff --git a/test/hotspot/jtreg/containers/systemd/TEST.properties b/test/hotspot/jtreg/containers/systemd/TEST.properties
new file mode 100644
index 0000000000000..d563e5f166403
--- /dev/null
+++ b/test/hotspot/jtreg/containers/systemd/TEST.properties
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+exclusiveAccess.dirs=.
diff --git a/test/lib/jdk/test/lib/containers/systemd/SystemdTestUtils.java b/test/lib/jdk/test/lib/containers/systemd/SystemdTestUtils.java
index 341b24c3e051a..9acff93aaca23 100644
--- a/test/lib/jdk/test/lib/containers/systemd/SystemdTestUtils.java
+++ b/test/lib/jdk/test/lib/containers/systemd/SystemdTestUtils.java
@@ -28,6 +28,7 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -92,19 +93,23 @@ public static OutputAnalyzer buildAndRunSystemdJava(SystemdRunOptions opts) thro
try {
return SystemdTestUtils.systemdRunJava(opts);
} finally {
- try {
- if (files.memory() != null) {
- Files.delete(files.memory());
- }
- if (files.cpu() != null) {
- Files.delete(files.cpu());
- }
- if (files.sliceDotDDir() != null) {
- FileUtils.deleteFileTreeUnchecked(files.sliceDotDDir());
- }
- } catch (NoSuchFileException e) {
- // ignore
+ cleanupFiles(files);
+ }
+ }
+
+ private static void cleanupFiles(ResultFiles files) throws IOException {
+ try {
+ if (files.memory() != null) {
+ Files.delete(files.memory());
}
+ if (files.cpu() != null) {
+ Files.delete(files.cpu());
+ }
+ if (files.sliceDotDDir() != null) {
+ FileUtils.deleteFileTreeUnchecked(files.sliceDotDDir());
+ }
+ } catch (NoSuchFileException e) {
+ // ignore
}
}
@@ -135,15 +140,23 @@ private static ResultFiles buildSystemdSlices(SystemdRunOptions runOpts) throws
if (runOpts.hasSliceDLimit()) {
String dirName = String.format("%s.slice.d", SLICE_NAMESPACE_PREFIX);
sliceDotDDir = SYSTEMD_CONFIG_HOME.resolve(Path.of(dirName));
- Files.createDirectory(sliceDotDDir);
+ // Using createDirectories since we only need to ensure the directory
+ // exists. Ignore it if already existent.
+ Files.createDirectories(sliceDotDDir);
if (runOpts.sliceDMemoryLimit != null) {
Path memoryConfig = sliceDotDDir.resolve(Path.of(SLICE_D_MEM_CONFIG_FILE));
- Files.writeString(memoryConfig, getMemoryDSliceContent(runOpts));
+ Files.writeString(memoryConfig,
+ getMemoryDSliceContent(runOpts),
+ StandardOpenOption.TRUNCATE_EXISTING,
+ StandardOpenOption.CREATE);
}
if (runOpts.sliceDCpuLimit != null) {
Path cpuConfig = sliceDotDDir.resolve(Path.of(SLICE_D_CPU_CONFIG_FILE));
- Files.writeString(cpuConfig, getCPUDSliceContent(runOpts));
+ Files.writeString(cpuConfig,
+ getCPUDSliceContent(runOpts),
+ StandardOpenOption.TRUNCATE_EXISTING,
+ StandardOpenOption.CREATE);
}
}
@@ -159,7 +172,7 @@ private static ResultFiles buildSystemdSlices(SystemdRunOptions runOpts) throws
throw new AssertionError("Failed to write systemd slice files");
}
- systemdDaemonReload(cpu);
+ systemdDaemonReload(cpu, memory, sliceDotDDir);
return new ResultFiles(memory, cpu, sliceDotDDir);
}
@@ -175,12 +188,25 @@ private static String sliceNameCpu(SystemdRunOptions runOpts) {
return String.format("%s-cpu", slice);
}
- private static void systemdDaemonReload(Path cpu) throws Exception {
+ private static void systemdDaemonReload(Path cpu, Path memory, Path sliceDdir) throws Exception {
List daemonReload = systemCtl();
daemonReload.add("daemon-reload");
if (execute(daemonReload).getExitValue() != 0) {
- throw new AssertionError("Failed to reload systemd daemon");
+ if (RUN_AS_USER) {
+ cleanupFiles(new ResultFiles(cpu, memory, sliceDdir));
+ // When run as user the systemd user manager needs to be
+ // accessible and working. This is usually the case when
+ // connected via SSH or user login, but may not work for
+ // sessions set up via 'su ' or similar.
+ // In that case, 'systemctl --user status' usually doesn't
+ // work. There is no other option than skip the test.
+ String msg = "Service user@.service not properly configured. " +
+ "Skipping the test!";
+ throw new SkippedException(msg);
+ } else {
+ throw new AssertionError("Failed to reload systemd daemon");
+ }
}
}
From 08b25611f688ae85c05242afc4cee5b538db4f67 Mon Sep 17 00:00:00 2001
From: Joe Darcy
Date: Fri, 20 Sep 2024 21:27:22 +0000
Subject: [PATCH 039/110] 8339781: Better use of Javadoc tags in
javax.lang.model
Reviewed-by: jjg
---
.../annotation/processing/Processor.java | 21 ++++++++++---------
.../javax/lang/model/AnnotatedConstruct.java | 14 ++++++-------
.../javax/lang/model/element/NestingKind.java | 4 ++--
.../classes/javax/lang/model/util/Types.java | 2 +-
4 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/src/java.compiler/share/classes/javax/annotation/processing/Processor.java b/src/java.compiler/share/classes/javax/annotation/processing/Processor.java
index 01de039d2c2c8..4be159868fa10 100644
--- a/src/java.compiler/share/classes/javax/annotation/processing/Processor.java
+++ b/src/java.compiler/share/classes/javax/annotation/processing/Processor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -32,14 +32,15 @@
import javax.lang.model.SourceVersion;
/**
- * The interface for an annotation processor.
- *
- *
Annotation processing happens in a sequence of {@linkplain
- * javax.annotation.processing.RoundEnvironment rounds}. On each
- * round, a processor may be asked to {@linkplain #process process} a
- * subset of the annotations found on the source and class files
- * produced by a prior round. The inputs to the first round of
- * processing are the initial inputs to a run of the tool; these
+ * The interface for an {@index "annotation processor"}.
+ *
+ *
Annotation processing happens in a sequence of rounds.
+ * On each
+ * {@linkplain RoundEnvironment round}, a processor may be asked to {@linkplain #process process} a
+ * subset of the annotations found on the
+ * {@linkplain RoundEnvironment#getRootElements() source and class files
+ * produced by a prior round}. The inputs to the first round of
+ * processing are the {@index "initial inputs"} to a run of the tool; these
* initial inputs can be regarded as the output of a virtual zeroth
* round of processing. If a processor was asked to process on a
* given round, it will be asked to process on subsequent rounds,
@@ -77,7 +78,7 @@
* protocol being followed, then the processor's behavior is not
* defined by this interface specification.
*
- *
The tool uses a discovery process to find annotation
+ *
The tool uses a {@index "discovery process"} to find annotation
* processors and decide whether or not they should be run. By
* configuring the tool, the set of potential processors can be
* controlled. For example, for a {@link javax.tools.JavaCompiler
diff --git a/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java b/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java
index 10363b5a618d1..6dc1b1ccab129 100644
--- a/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java
+++ b/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -41,8 +41,8 @@
*
* As defined by The Java Language Specification
* section {@jls 9.7.4}, an annotation on an element is a
- * declaration annotation and an annotation on a type is a
- * type annotation.
+ * {@index "declaration annotation"} and an annotation on a type is a
+ * {@index "type annotation"}.
*
* The terms directly present, present,
* indirectly present, and associated are used
@@ -54,7 +54,7 @@
* annotation interface AI. If AI is a repeatable annotation
* interface, the type of the containing annotation is AIC.
*
- *
Annotation A is directly present on a construct
+ *
Annotation A is {@index "directly present"} on a construct
* C if either:
*
*
@@ -87,7 +87,7 @@
*
*
*
- *
An annotation A is present on a
+ *
An annotation A is {@index "present"} on a
* construct C if either:
*
*
@@ -99,7 +99,7 @@
*
*
*
- * An annotation A is indirectly present on a construct
+ * An annotation A is {@index "indirectly present"} on a construct
* C if both:
*
*
@@ -114,7 +114,7 @@
*
*
*
- * An annotation A is associated with a construct
+ * An annotation A is {@index "associated"} with a construct
* C if either:
*
*
diff --git a/src/java.compiler/share/classes/javax/lang/model/element/NestingKind.java b/src/java.compiler/share/classes/javax/lang/model/element/NestingKind.java
index 138f093be2f57..1faae30df5723 100644
--- a/src/java.compiler/share/classes/javax/lang/model/element/NestingKind.java
+++ b/src/java.compiler/share/classes/javax/lang/model/element/NestingKind.java
@@ -26,7 +26,7 @@
package javax.lang.model.element;
/**
- * The nesting kind of a type element.
+ * The nesting kind of a type element.
* Type elements come in four varieties:
* top-level, member, local, and anonymous.
* Nesting kind is a non-standard term used here to denote this
@@ -107,7 +107,7 @@ public enum NestingKind {
/**
* Does this constant correspond to a nested type element?
- * A nested type element is any that is not top-level.
+ * A nested type element is any that is not top-level.
* More specifically, an inner type element is any nested type element that
* is not {@linkplain Modifier#STATIC static}.
* @return whether or not the constant is nested
diff --git a/src/java.compiler/share/classes/javax/lang/model/util/Types.java b/src/java.compiler/share/classes/javax/lang/model/util/Types.java
index 0cea2734e213c..bbbf4e3d95e6a 100644
--- a/src/java.compiler/share/classes/javax/lang/model/util/Types.java
+++ b/src/java.compiler/share/classes/javax/lang/model/util/Types.java
@@ -185,7 +185,7 @@ public interface Types {
/**
* {@return the class of a boxed value of the primitive type argument}
- * That is, boxing conversion is applied.
+ * That is, boxing conversion is applied.
*
* @param p the primitive type to be converted
* @jls 5.1.7 Boxing Conversion
From 2461263aac35b25e2a48b6fc84da49e4b553dbc3 Mon Sep 17 00:00:00 2001
From: Shaojin Wen
Date: Sat, 21 Sep 2024 00:21:04 +0000
Subject: [PATCH 040/110] 8339217: Optimize ClassFile API loadConstant
Reviewed-by: liach, redestad, asotona
---
.../java/lang/classfile/CodeBuilder.java | 93 +++++++++++++------
.../lang/invoke/InvokerBytecodeGenerator.java | 2 +-
2 files changed, 68 insertions(+), 27 deletions(-)
diff --git a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java
index 5f4e5b72a1919..16f513801a249 100644
--- a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java
+++ b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java
@@ -615,36 +615,77 @@ default CodeBuilder loadConstant(ConstantDesc value) {
if (value == null || value == ConstantDescs.NULL)
return aconst_null();
if (value instanceof Number) {
- if (value instanceof Integer iVal)
- return switch (iVal) {
- case -1 -> iconst_m1();
- case 0 -> iconst_0();
- case 1 -> iconst_1();
- case 2 -> iconst_2();
- case 3 -> iconst_3();
- case 4 -> iconst_4();
- case 5 -> iconst_5();
- default -> (iVal >= Byte.MIN_VALUE && iVal <= Byte.MAX_VALUE) ? bipush(iVal)
- : (iVal >= Short.MIN_VALUE && iVal <= Short.MAX_VALUE) ? sipush(iVal)
- : ldc(constantPool().intEntry(iVal));
- };
- if (value instanceof Long lVal)
- return lVal == 0L ? lconst_0()
- : lVal == 1L ? lconst_1()
- : ldc(constantPool().longEntry(lVal));
- if (value instanceof Float fVal)
- return Float.floatToRawIntBits(fVal) == 0 ? fconst_0()
- : fVal == 1.0f ? fconst_1()
- : fVal == 2.0f ? fconst_2()
- : ldc(constantPool().floatEntry(fVal));
- if (value instanceof Double dVal)
- return Double.doubleToRawLongBits(dVal) == 0L ? dconst_0()
- : dVal == 1.0d ? dconst_1()
- : ldc(constantPool().doubleEntry(dVal));
+ if (value instanceof Integer) return loadConstant((int) value);
+ if (value instanceof Long ) return loadConstant((long) value);
+ if (value instanceof Float ) return loadConstant((float) value);
+ if (value instanceof Double ) return loadConstant((double) value);
}
return ldc(value);
}
+
+ /**
+ * Generate an instruction pushing a constant int value onto the operand stack.
+ * This is identical to {@link #loadConstant(ConstantDesc) loadConstant(Integer.valueOf(value))}.
+ * @param value the int value
+ * @return this builder
+ * @since 24
+ */
+ default CodeBuilder loadConstant(int value) {
+ return switch (value) {
+ case -1 -> iconst_m1();
+ case 0 -> iconst_0();
+ case 1 -> iconst_1();
+ case 2 -> iconst_2();
+ case 3 -> iconst_3();
+ case 4 -> iconst_4();
+ case 5 -> iconst_5();
+ default -> (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE ) ? bipush(value)
+ : (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) ? sipush(value)
+ : ldc(constantPool().intEntry(value));
+ };
+ }
+
+ /**
+ * Generate an instruction pushing a constant long value onto the operand stack.
+ * This is identical to {@link #loadConstant(ConstantDesc) loadConstant(Long.valueOf(value))}.
+ * @param value the long value
+ * @return this builder
+ * @since 24
+ */
+ default CodeBuilder loadConstant(long value) {
+ return value == 0l ? lconst_0()
+ : value == 1l ? lconst_1()
+ : ldc(constantPool().longEntry(value));
+ }
+
+ /**
+ * Generate an instruction pushing a constant float value onto the operand stack.
+ * This is identical to {@link #loadConstant(ConstantDesc) loadConstant(Float.valueOf(value))}.
+ * @param value the float value
+ * @return this builder
+ * @since 24
+ */
+ default CodeBuilder loadConstant(float value) {
+ return Float.floatToRawIntBits(value) == 0 ? fconst_0()
+ : value == 1.0f ? fconst_1()
+ : value == 2.0f ? fconst_2()
+ : ldc(constantPool().floatEntry(value));
+ }
+
+ /**
+ * Generate an instruction pushing a constant double value onto the operand stack.
+ * This is identical to {@link #loadConstant(ConstantDesc) loadConstant(Double.valueOf(value))}.
+ * @param value the double value
+ * @return this builder
+ * @since 24
+ */
+ default CodeBuilder loadConstant(double value) {
+ return Double.doubleToRawLongBits(value) == 0l ? dconst_0()
+ : value == 1.0d ? dconst_1()
+ : ldc(constantPool().doubleEntry(value));
+ }
+
/**
* Generate a do nothing instruction
* @return this builder
diff --git a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
index 6031b55a107b2..4a905a3030b9a 100644
--- a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
+++ b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
@@ -1645,7 +1645,7 @@ private void bogusMethod(ClassBuilder clb, Object os) {
clb.withMethodBody("dummy", MTD_void, ACC_STATIC, new Consumer<>() {
@Override
public void accept(CodeBuilder cob) {
- cob.loadConstant(os.toString());
+ cob.ldc(os.toString());
cob.pop();
cob.return_();
}
From ab06a878f888827026424530781f0af414a8a611 Mon Sep 17 00:00:00 2001
From: Shaojin Wen
Date: Sun, 22 Sep 2024 01:01:31 +0000
Subject: [PATCH 041/110] 8340544: Optimize setLocalsFromArg
Reviewed-by: redestad, liach
---
.../classfile/impl/StackMapGenerator.java | 41 ++++++++++---------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
index c6564c289d6f5..f5cd9b80af844 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
@@ -1043,34 +1043,37 @@ private void setLocalRawInternal(int index, Type type) {
void setLocalsFromArg(String name, MethodTypeDesc methodDesc, boolean isStatic, Type thisKlass) {
int localsSize = 0;
// Pre-emptively create a locals array that encompass all parameter slots
- checkLocal(methodDesc.parameterCount() + (isStatic ? -1 : 0));
+ checkLocal(Util.parameterSlots(methodDesc) + (isStatic ? -1 : 0));
+ Type type;
+ Type[] locals = this.locals;
if (!isStatic) {
- localsSize++;
if (OBJECT_INITIALIZER_NAME.equals(name) && !CD_Object.equals(thisKlass.sym)) {
- setLocal(0, Type.UNITIALIZED_THIS_TYPE);
+ type = Type.UNITIALIZED_THIS_TYPE;
flags |= FLAG_THIS_UNINIT;
} else {
- setLocalRawInternal(0, thisKlass);
+ type = thisKlass;
}
+ locals[localsSize++] = type;
}
for (int i = 0; i < methodDesc.parameterCount(); i++) {
var desc = methodDesc.parameterType(i);
- if (!desc.isPrimitive()) {
- setLocalRawInternal(localsSize++, Type.referenceType(desc));
- } else switch (desc.descriptorString().charAt(0)) {
- case 'J' -> {
- setLocalRawInternal(localsSize++, Type.LONG_TYPE);
- setLocalRawInternal(localsSize++, Type.LONG2_TYPE);
- }
- case 'D' -> {
- setLocalRawInternal(localsSize++, Type.DOUBLE_TYPE);
- setLocalRawInternal(localsSize++, Type.DOUBLE2_TYPE);
+ if (desc == CD_long) {
+ locals[localsSize ] = Type.LONG_TYPE;
+ locals[localsSize + 1] = Type.LONG2_TYPE;
+ localsSize += 2;
+ } else if (desc == CD_double) {
+ locals[localsSize ] = Type.DOUBLE_TYPE;
+ locals[localsSize + 1] = Type.DOUBLE2_TYPE;
+ localsSize += 2;
+ } else {
+ if (desc instanceof ReferenceClassDescImpl) {
+ type = Type.referenceType(desc);
+ } else if (desc == CD_float) {
+ type = Type.FLOAT_TYPE;
+ } else {
+ type = Type.INTEGER_TYPE;
}
- case 'I', 'Z', 'B', 'C', 'S' ->
- setLocalRawInternal(localsSize++, Type.INTEGER_TYPE);
- case 'F' ->
- setLocalRawInternal(localsSize++, Type.FLOAT_TYPE);
- default -> throw new AssertionError("Should not reach here");
+ locals[localsSize++] = type;
}
}
this.localsSize = localsSize;
From dd498794f20df0ac1a73d84e54591905c8a5a5c7 Mon Sep 17 00:00:00 2001
From: Kim Barrett
Date: Mon, 23 Sep 2024 05:48:42 +0000
Subject: [PATCH 042/110] 8340524: Remove NarrowPtrStruct
Reviewed-by: shade, jwaters
---
src/hotspot/share/oops/compressedOops.cpp | 18 +++++++-----
src/hotspot/share/oops/compressedOops.hpp | 29 ++++++++-----------
src/hotspot/share/runtime/vmStructs.cpp | 6 ++--
.../sun/jvm/hotspot/oops/CompressedOops.java | 6 ++--
4 files changed, 28 insertions(+), 31 deletions(-)
diff --git a/src/hotspot/share/oops/compressedOops.cpp b/src/hotspot/share/oops/compressedOops.cpp
index 08f78b1d7734c..98a4438383a79 100644
--- a/src/hotspot/share/oops/compressedOops.cpp
+++ b/src/hotspot/share/oops/compressedOops.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 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
@@ -35,8 +35,10 @@
#include "runtime/globals.hpp"
// For UseCompressedOops.
-NarrowPtrStruct CompressedOops::_narrow_oop = { nullptr, 0, true };
-MemRegion CompressedOops::_heap_address_range;
+address CompressedOops::_base = nullptr;
+int CompressedOops::_shift = 0;
+bool CompressedOops::_use_implicit_null_checks = true;
+MemRegion CompressedOops::_heap_address_range;
// Choose the heap base address and oop encoding mode
// when compressed oops are used:
@@ -88,16 +90,16 @@ void CompressedOops::initialize(const ReservedHeapSpace& heap_space) {
void CompressedOops::set_base(address base) {
assert(UseCompressedOops, "no compressed oops?");
- _narrow_oop._base = base;
+ _base = base;
}
void CompressedOops::set_shift(int shift) {
- _narrow_oop._shift = shift;
+ _shift = shift;
}
void CompressedOops::set_use_implicit_null_checks(bool use) {
assert(UseCompressedOops, "no compressed ptrs?");
- _narrow_oop._use_implicit_null_checks = use;
+ _use_implicit_null_checks = use;
}
bool CompressedOops::is_in(void* addr) {
@@ -148,14 +150,14 @@ bool CompressedOops::is_disjoint_heap_base_address(address addr) {
// Check for disjoint base compressed oops.
bool CompressedOops::base_disjoint() {
- return _narrow_oop._base != nullptr && is_disjoint_heap_base_address(_narrow_oop._base);
+ return _base != nullptr && is_disjoint_heap_base_address(_base);
}
// Check for real heapbased compressed oops.
// We must subtract the base as the bits overlap.
// If we negate above function, we also get unscaled and zerobased.
bool CompressedOops::base_overlaps() {
- return _narrow_oop._base != nullptr && !is_disjoint_heap_base_address(_narrow_oop._base);
+ return _base != nullptr && !is_disjoint_heap_base_address(_base);
}
void CompressedOops::print_mode(outputStream* st) {
diff --git a/src/hotspot/share/oops/compressedOops.hpp b/src/hotspot/share/oops/compressedOops.hpp
index a9446469c8781..33af420305cba 100644
--- a/src/hotspot/share/oops/compressedOops.hpp
+++ b/src/hotspot/share/oops/compressedOops.hpp
@@ -34,23 +34,18 @@
class outputStream;
class ReservedHeapSpace;
-struct NarrowPtrStruct {
+class CompressedOops : public AllStatic {
+ friend class VMStructs;
+
// Base address for oop-within-java-object materialization.
// null if using wide oops or zero based narrow oops.
- address _base;
+ static address _base;
// Number of shift bits for encoding/decoding narrow ptrs.
- // 0 if using wide ptrs or zero based unscaled narrow ptrs,
+ // 0 if using wide oops or zero based unscaled narrow oops,
// LogMinObjAlignmentInBytes otherwise.
- int _shift;
- // Generate code with implicit null checks for narrow ptrs.
- bool _use_implicit_null_checks;
-};
-
-class CompressedOops : public AllStatic {
- friend class VMStructs;
-
- // For UseCompressedOops.
- static NarrowPtrStruct _narrow_oop;
+ static int _shift;
+ // Generate code with implicit null checks for narrow oops.
+ static bool _use_implicit_null_checks;
// The address range of the heap
static MemRegion _heap_address_range;
@@ -86,13 +81,13 @@ class CompressedOops : public AllStatic {
static void set_shift(int shift);
static void set_use_implicit_null_checks(bool use);
- static address base() { return _narrow_oop._base; }
- static address base_addr() { return (address)&_narrow_oop._base; }
+ static address base() { return _base; }
+ static address base_addr() { return (address)&_base; }
static address begin() { return (address)_heap_address_range.start(); }
static address end() { return (address)_heap_address_range.end(); }
static bool is_base(void* addr) { return (base() == (address)addr); }
- static int shift() { return _narrow_oop._shift; }
- static bool use_implicit_null_checks() { return _narrow_oop._use_implicit_null_checks; }
+ static int shift() { return _shift; }
+ static bool use_implicit_null_checks() { return _use_implicit_null_checks; }
static bool is_in(void* addr);
static bool is_in(MemRegion mr);
diff --git a/src/hotspot/share/runtime/vmStructs.cpp b/src/hotspot/share/runtime/vmStructs.cpp
index 483b96fccf382..e0a36330687dc 100644
--- a/src/hotspot/share/runtime/vmStructs.cpp
+++ b/src/hotspot/share/runtime/vmStructs.cpp
@@ -373,9 +373,9 @@
/* CompressedOops */ \
/******************/ \
\
- static_field(CompressedOops, _narrow_oop._base, address) \
- static_field(CompressedOops, _narrow_oop._shift, int) \
- static_field(CompressedOops, _narrow_oop._use_implicit_null_checks, bool) \
+ static_field(CompressedOops, _base, address) \
+ static_field(CompressedOops, _shift, int) \
+ static_field(CompressedOops, _use_implicit_null_checks, bool) \
\
/***************************/ \
/* CompressedKlassPointers */ \
diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/CompressedOops.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/CompressedOops.java
index 056d75199579c..01c9974153392 100644
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/CompressedOops.java
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/CompressedOops.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -64,8 +64,8 @@ private static boolean typeExists(TypeDataBase db, String type) {
private static synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("CompressedOops");
- baseField = type.getAddressField("_narrow_oop._base");
- shiftField = type.getCIntegerField("_narrow_oop._shift");
+ baseField = type.getAddressField("_base");
+ shiftField = type.getCIntegerField("_shift");
}
public CompressedOops() {
From 34cddfbedd20d5804cab8044fbc402564e98eb9c Mon Sep 17 00:00:00 2001
From: Matthias Baesken
Date: Mon, 23 Sep 2024 06:40:33 +0000
Subject: [PATCH 043/110] 8340387: Update OS detection code to recognize
Windows Server 2025
Reviewed-by: mdoerr, jwaters, dholmes
---
src/hotspot/os/windows/os_windows.cpp | 5 ++++-
src/java.base/windows/native/libjava/java_props_md.c | 9 +++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp
index 1acce2540a855..ed62fe612aae3 100644
--- a/src/hotspot/os/windows/os_windows.cpp
+++ b/src/hotspot/os/windows/os_windows.cpp
@@ -1947,7 +1947,10 @@ void os::win32::print_windows_version(outputStream* st) {
// - 2016 GA 10/2016 build: 14393
// - 2019 GA 11/2018 build: 17763
// - 2022 GA 08/2021 build: 20348
- if (build_number > 20347) {
+ // - 2025 Preview build : 26040
+ if (build_number > 26039) {
+ st->print("Server 2025");
+ } else if (build_number > 20347) {
st->print("Server 2022");
} else if (build_number > 17762) {
st->print("Server 2019");
diff --git a/src/java.base/windows/native/libjava/java_props_md.c b/src/java.base/windows/native/libjava/java_props_md.c
index 5eefb6a9fc9e8..357c697ab5f30 100644
--- a/src/java.base/windows/native/libjava/java_props_md.c
+++ b/src/java.base/windows/native/libjava/java_props_md.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -444,6 +444,8 @@ GetJavaProperties(JNIEnv* env)
* where (buildNumber > 17762)
* Windows Server 2022 10 0 (!VER_NT_WORKSTATION)
* where (buildNumber > 20347)
+ * Windows Server 2025 10 0 (!VER_NT_WORKSTATION)
+ * where (buildNumber > 26039)
*
* This mapping will presumably be augmented as new Windows
* versions are released.
@@ -527,7 +529,10 @@ GetJavaProperties(JNIEnv* env)
case 0:
/* Windows server 2019 GA 10/2018 build number is 17763 */
/* Windows server 2022 build number is 20348 */
- if (buildNumber > 20347) {
+ /* Windows server 2025 Preview build is 26040 */
+ if (buildNumber > 26039) {
+ sprops.os_name = "Windows Server 2025";
+ } else if (buildNumber > 20347) {
sprops.os_name = "Windows Server 2022";
} else if (buildNumber > 17762) {
sprops.os_name = "Windows Server 2019";
From f31f97ddb6f1fca1a74761e3e3eeef497f8a7416 Mon Sep 17 00:00:00 2001
From: Aleksey Shipilev
Date: Mon, 23 Sep 2024 07:02:48 +0000
Subject: [PATCH 044/110] 8340171: CDS: Enhance bitmap truncation
Reviewed-by: matsaave, iklam
---
src/hotspot/share/cds/archiveHeapWriter.cpp | 12 +++---
src/hotspot/share/cds/filemap.cpp | 41 ++++++++++-----------
src/hotspot/share/cds/filemap.hpp | 2 +-
3 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/src/hotspot/share/cds/archiveHeapWriter.cpp b/src/hotspot/share/cds/archiveHeapWriter.cpp
index 17d78b6b44cfe..853d459c691dd 100644
--- a/src/hotspot/share/cds/archiveHeapWriter.cpp
+++ b/src/hotspot/share/cds/archiveHeapWriter.cpp
@@ -248,11 +248,16 @@ void ArchiveHeapWriter::copy_roots_to_buffer(GrowableArrayCHeap_rank;
int rank_b = b->_rank;
diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp
index 7bbb9688015e7..c935541d7cf0a 100644
--- a/src/hotspot/share/cds/filemap.cpp
+++ b/src/hotspot/share/cds/filemap.cpp
@@ -1581,39 +1581,38 @@ static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset)
return offset + size_in_bytes;
}
-// The start of the archived heap has many primitive arrays (String
-// bodies) that are not marked by the oop/ptr maps. So we must have
-// lots of leading zeros.
-size_t FileMapInfo::remove_bitmap_leading_zeros(CHeapBitMap* map) {
- size_t old_zeros = map->find_first_set_bit(0);
+// The sorting code groups the objects with non-null oop/ptrs together.
+// Relevant bitmaps then have lots of leading and trailing zeros, which
+// we do not have to store.
+size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
+ BitMap::idx_t first_set = map->find_first_set_bit(0);
+ BitMap::idx_t last_set = map->find_last_set_bit(0);
size_t old_size = map->size();
// Slice and resize bitmap
- map->truncate(old_zeros, map->size());
+ map->truncate(first_set, last_set + 1);
- DEBUG_ONLY(
- size_t new_zeros = map->find_first_set_bit(0);
- assert(new_zeros == 0, "Should have removed leading zeros");
- )
+ assert(map->at(0), "First bit should be set");
+ assert(map->at(map->size() - 1), "Last bit should be set");
assert(map->size() <= old_size, "sanity");
- return old_zeros;
+
+ return first_set;
}
char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, ArchiveHeapInfo* heap_info,
size_t &size_in_bytes) {
- size_t removed_rw_zeros = remove_bitmap_leading_zeros(rw_ptrmap);
- size_t removed_ro_zeros = remove_bitmap_leading_zeros(ro_ptrmap);
- header()->set_rw_ptrmap_start_pos(removed_rw_zeros);
- header()->set_ro_ptrmap_start_pos(removed_ro_zeros);
+ size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
+ size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
+ header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
+ header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes();
if (heap_info->is_used()) {
- // Remove leading zeros
- size_t removed_oop_zeros = remove_bitmap_leading_zeros(heap_info->oopmap());
- size_t removed_ptr_zeros = remove_bitmap_leading_zeros(heap_info->ptrmap());
-
- header()->set_heap_oopmap_start_pos(removed_oop_zeros);
- header()->set_heap_ptrmap_start_pos(removed_ptr_zeros);
+ // Remove leading and trailing zeros
+ size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
+ size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
+ header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
+ header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
size_in_bytes += heap_info->oopmap()->size_in_bytes();
size_in_bytes += heap_info->ptrmap()->size_in_bytes();
diff --git a/src/hotspot/share/cds/filemap.hpp b/src/hotspot/share/cds/filemap.hpp
index aa728b9d4949f..1bf2510a3351c 100644
--- a/src/hotspot/share/cds/filemap.hpp
+++ b/src/hotspot/share/cds/filemap.hpp
@@ -445,7 +445,7 @@ class FileMapInfo : public CHeapObj {
void write_header();
void write_region(int region, char* base, size_t size,
bool read_only, bool allow_exec);
- size_t remove_bitmap_leading_zeros(CHeapBitMap* map);
+ size_t remove_bitmap_zeros(CHeapBitMap* map);
char* write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, ArchiveHeapInfo* heap_info,
size_t &size_in_bytes);
size_t write_heap_region(ArchiveHeapInfo* heap_info);
From 0f253d11033a26d15ea20df19db6765bb274a848 Mon Sep 17 00:00:00 2001
From: Aleksey Shipilev
Date: Mon, 23 Sep 2024 07:02:59 +0000
Subject: [PATCH 045/110] 8340392: Handle OopStorage in location decoder
Reviewed-by: kbarrett, dholmes
---
src/hotspot/share/gc/shared/oopStorage.cpp | 20 +++++
src/hotspot/share/gc/shared/oopStorage.hpp | 1 +
.../share/gc/shared/oopStorage.inline.hpp | 2 +
src/hotspot/share/gc/shared/oopStorageSet.cpp | 17 ++++
src/hotspot/share/gc/shared/oopStorageSet.hpp | 3 +
src/hotspot/share/runtime/os.cpp | 6 ++
.../gtest/gc/shared/test_oopStorageSet.cpp | 84 ++++++++++++++++++-
7 files changed, 132 insertions(+), 1 deletion(-)
diff --git a/src/hotspot/share/gc/shared/oopStorage.cpp b/src/hotspot/share/gc/shared/oopStorage.cpp
index 6c5e57c947952..568888ac7d97e 100644
--- a/src/hotspot/share/gc/shared/oopStorage.cpp
+++ b/src/hotspot/share/gc/shared/oopStorage.cpp
@@ -1135,6 +1135,26 @@ void OopStorage::BasicParState::report_num_dead() const {
const char* OopStorage::name() const { return _name; }
+bool OopStorage::print_containing(const oop* addr, outputStream* st) {
+ if (addr != nullptr) {
+ Block* block = find_block_or_null(addr);
+ if (block != nullptr && block->print_containing(addr, st)) {
+ st->print(" in oop storage \"%s\"", name());
+ return true;
+ }
+ }
+ return false;
+}
+
+bool OopStorage::Block::print_containing(const oop* addr, outputStream* st) {
+ if (contains(addr)) {
+ st->print(PTR_FORMAT " is a pointer %u/%zu into block %zu",
+ p2i(addr), get_index(addr), ARRAY_SIZE(_data), _active_index);
+ return true;
+ }
+ return false;
+}
+
#ifndef PRODUCT
void OopStorage::print_on(outputStream* st) const {
diff --git a/src/hotspot/share/gc/shared/oopStorage.hpp b/src/hotspot/share/gc/shared/oopStorage.hpp
index f78746fc14a27..96cc5a23d6a91 100644
--- a/src/hotspot/share/gc/shared/oopStorage.hpp
+++ b/src/hotspot/share/gc/shared/oopStorage.hpp
@@ -213,6 +213,7 @@ class OopStorage : public CHeapObjBase {
// Debugging and logging support.
const char* name() const;
void print_on(outputStream* st) const PRODUCT_RETURN;
+ bool print_containing(const oop* addr, outputStream* st);
// Provides access to storage internals, for unit testing.
// Declare, but not define, the public class OopStorage::TestAccess.
diff --git a/src/hotspot/share/gc/shared/oopStorage.inline.hpp b/src/hotspot/share/gc/shared/oopStorage.inline.hpp
index ce78e507efc12..545da0be0a76e 100644
--- a/src/hotspot/share/gc/shared/oopStorage.inline.hpp
+++ b/src/hotspot/share/gc/shared/oopStorage.inline.hpp
@@ -196,6 +196,8 @@ class OopStorage::Block /* No base class, to avoid messing up alignment. */ {
template bool iterate(F f);
template bool iterate(F f) const;
+
+ bool print_containing(const oop* addr, outputStream* st);
}; // class Block
inline OopStorage::Block* OopStorage::AllocationList::head() {
diff --git a/src/hotspot/share/gc/shared/oopStorageSet.cpp b/src/hotspot/share/gc/shared/oopStorageSet.cpp
index d061fc7763868..c6947590d96fb 100644
--- a/src/hotspot/share/gc/shared/oopStorageSet.cpp
+++ b/src/hotspot/share/gc/shared/oopStorageSet.cpp
@@ -82,6 +82,23 @@ template OopStorage* OopStorageSet::get_storage(StrongId);
template OopStorage* OopStorageSet::get_storage(WeakId);
template OopStorage* OopStorageSet::get_storage(Id);
+bool OopStorageSet::print_containing(const void* addr, outputStream* st) {
+ if (addr != nullptr) {
+ const void* aligned_addr = align_down(addr, alignof(oop));
+ for (OopStorage* storage : Range()) {
+ if (storage->print_containing((oop*) aligned_addr, st)) {
+ if (aligned_addr != addr) {
+ st->print_cr(" (unaligned)");
+ } else {
+ st->cr();
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
#ifdef ASSERT
void OopStorageSet::verify_initialized(uint index) {
diff --git a/src/hotspot/share/gc/shared/oopStorageSet.hpp b/src/hotspot/share/gc/shared/oopStorageSet.hpp
index 273a769dd59d4..867172c41ad74 100644
--- a/src/hotspot/share/gc/shared/oopStorageSet.hpp
+++ b/src/hotspot/share/gc/shared/oopStorageSet.hpp
@@ -26,6 +26,7 @@
#define SHARE_GC_SHARED_OOPSTORAGESET_HPP
#include "nmt/memTag.hpp"
+#include "oops/oop.hpp"
#include "utilities/debug.hpp"
#include "utilities/enumIterator.hpp"
#include "utilities/globalDefinitions.hpp"
@@ -89,6 +90,8 @@ class OopStorageSet : public AllStatic {
template
static void strong_oops_do(Closure* cl);
+ // Debugging: print location info, if in storage.
+ static bool print_containing(const void* addr, outputStream* st);
};
ENUMERATOR_VALUE_RANGE(OopStorageSet::StrongId,
diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp
index 9c9dfbc62306d..8b1c52a5d33cc 100644
--- a/src/hotspot/share/runtime/os.cpp
+++ b/src/hotspot/share/runtime/os.cpp
@@ -32,6 +32,7 @@
#include "code/codeCache.hpp"
#include "code/vtableStubs.hpp"
#include "gc/shared/gcVMOperations.hpp"
+#include "gc/shared/oopStorageSet.hpp"
#include "interpreter/interpreter.hpp"
#include "jvm.h"
#include "logging/log.hpp"
@@ -1317,6 +1318,11 @@ void os::print_location(outputStream* st, intptr_t x, bool verbose) {
}
#endif
+ // Ask if any OopStorage knows about this address.
+ if (OopStorageSet::print_containing(addr, st)) {
+ return;
+ }
+
// Still nothing? If NMT is enabled, we can ask what it thinks...
if (MemTracker::print_containing_region(addr, st)) {
return;
diff --git a/test/hotspot/gtest/gc/shared/test_oopStorageSet.cpp b/test/hotspot/gtest/gc/shared/test_oopStorageSet.cpp
index c8ada2574c0e7..947ff120d15fe 100644
--- a/test/hotspot/gtest/gc/shared/test_oopStorageSet.cpp
+++ b/test/hotspot/gtest/gc/shared/test_oopStorageSet.cpp
@@ -23,15 +23,21 @@
*/
#include "precompiled.hpp"
-#include "gc/shared/oopStorage.hpp"
+#include "gc/shared/oopStorage.inline.hpp"
#include "gc/shared/oopStorageSet.hpp"
#include "memory/allocation.inline.hpp"
+#include "runtime/interfaceSupport.inline.hpp"
+#include "runtime/vmOperations.hpp"
+#include "runtime/vmThread.hpp"
#include "utilities/debug.hpp"
#include "utilities/enumIterator.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#include "unittest.hpp"
+using ::testing::HasSubstr;
+using ::testing::Not;
+
class OopStorageSetTest : public ::testing::Test {
protected:
// Returns index of s in storages, or size if not found.
@@ -83,6 +89,8 @@ class OopStorageSetTest : public ::testing::Test {
EnumRange(),
&OopStorageSet::fill_all);
}
+
+ class VM_PrintAtSafepoint;
};
TEST_VM_F(OopStorageSetTest, strong_iteration) {
@@ -96,3 +104,77 @@ TEST_VM_F(OopStorageSetTest, weak_iteration) {
TEST_VM_F(OopStorageSetTest, all_iteration) {
test_all_iteration();
}
+
+class OopStorageSetTest::VM_PrintAtSafepoint : public VM_GTestExecuteAtSafepoint {
+private:
+ class PrintContainingClosure : public Closure {
+ public:
+ void do_oop(oop* addr) {
+ // Direct slot hit.
+ {
+ stringStream ss;
+ bool printed = OopStorageSet::print_containing(addr, &ss);
+ ASSERT_TRUE(printed);
+ ASSERT_THAT(ss.freeze(), HasSubstr("is a pointer"));
+ ASSERT_THAT(ss.freeze(), HasSubstr("into block"));
+ ASSERT_THAT(ss.freeze(), HasSubstr("in oop storage"));
+ ASSERT_THAT(ss.freeze(), Not(HasSubstr("(unaligned)")));
+ }
+
+ // Unaligned pointer to adjacent slot, should still be in oop storage range.
+ {
+ char* unaligned_addr = (char*)addr + 1;
+ stringStream ss;
+ bool printed = OopStorageSet::print_containing(unaligned_addr, &ss);
+ ASSERT_TRUE(printed);
+ ASSERT_THAT(ss.freeze(), HasSubstr("is a pointer"));
+ ASSERT_THAT(ss.freeze(), HasSubstr("into block"));
+ ASSERT_THAT(ss.freeze(), HasSubstr("in oop storage"));
+ ASSERT_THAT(ss.freeze(), HasSubstr("(unaligned)"));
+ }
+ }
+ };
+
+public:
+ void doit() {
+ PrintContainingClosure cl;
+ for (OopStorage* storage : OopStorageSet::Range()) {
+ storage->oops_do(&cl);
+ }
+ }
+};
+
+TEST_VM_F(OopStorageSetTest, print_containing) {
+ // nullptrs print nothing
+ {
+ stringStream ss;
+ bool printed = OopStorageSet::print_containing(nullptr, &ss);
+ ASSERT_FALSE(printed);
+ EXPECT_STREQ("", ss.freeze());
+ }
+
+ // Goofy values print nothing: unaligned out of storage pointer.
+ {
+ stringStream ss;
+ bool printed = OopStorageSet::print_containing((char*)0x1, &ss);
+ ASSERT_FALSE(printed);
+ EXPECT_STREQ("", ss.freeze());
+ }
+
+ // Goofy values print nothing: aligned out of storage pointer.
+ {
+ stringStream ss;
+ bool printed = OopStorageSet::print_containing((char*)alignof(oop), &ss);
+ ASSERT_FALSE(printed);
+ EXPECT_STREQ("", ss.freeze());
+ }
+
+ // All slot addresses should print well.
+ {
+ VM_PrintAtSafepoint op;
+ {
+ ThreadInVMfromNative invm(JavaThread::current());
+ VMThread::execute(&op);
+ }
+ }
+}
From a07052e83d20e107f21fd0d266ab638043531c8a Mon Sep 17 00:00:00 2001
From: Kim Barrett
Date: Mon, 23 Sep 2024 08:02:16 +0000
Subject: [PATCH 046/110] 8340573: Remove unused
G1ParScanThreadState::_partial_objarray_chunk_size
Reviewed-by: tschatzl
---
src/hotspot/share/gc/g1/g1ParScanThreadState.hpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/hotspot/share/gc/g1/g1ParScanThreadState.hpp b/src/hotspot/share/gc/g1/g1ParScanThreadState.hpp
index 1cfd6fca08a6f..3f7fefd8a07a6 100644
--- a/src/hotspot/share/gc/g1/g1ParScanThreadState.hpp
+++ b/src/hotspot/share/gc/g1/g1ParScanThreadState.hpp
@@ -87,8 +87,6 @@ class G1ParScanThreadState : public CHeapObj {
// Indicates whether in the last generation (old) there is no more space
// available for allocation.
bool _old_gen_is_full;
- // Size (in elements) of a partial objArray task chunk.
- size_t _partial_objarray_chunk_size;
PartialArrayStateAllocator* _partial_array_state_allocator;
PartialArrayTaskStepper _partial_array_stepper;
StringDedup::Requests _string_dedup_requests;
From bc7c0dc45dcd66d24ece8ebbd5c1b25e131eae67 Mon Sep 17 00:00:00 2001
From: Abhishek Kumar
Date: Mon, 23 Sep 2024 08:02:36 +0000
Subject: [PATCH 047/110] 8340084: Open source AWT Frame related tests
Reviewed-by: psadhukhan, honkar
---
.../java/awt/Frame/DefaultLocationTest.java | 66 +++++++++++++
test/jdk/java/awt/Frame/EmptyFrameTest.java | 99 +++++++++++++++++++
test/jdk/java/awt/Frame/FrameLayoutTest.java | 70 +++++++++++++
.../awt/Frame/FrameSetMinimumSizeTest.java | 91 +++++++++++++++++
test/jdk/java/awt/Frame/PackTwiceTest.java | 67 +++++++++++++
5 files changed, 393 insertions(+)
create mode 100644 test/jdk/java/awt/Frame/DefaultLocationTest.java
create mode 100644 test/jdk/java/awt/Frame/EmptyFrameTest.java
create mode 100644 test/jdk/java/awt/Frame/FrameLayoutTest.java
create mode 100644 test/jdk/java/awt/Frame/FrameSetMinimumSizeTest.java
create mode 100644 test/jdk/java/awt/Frame/PackTwiceTest.java
diff --git a/test/jdk/java/awt/Frame/DefaultLocationTest.java b/test/jdk/java/awt/Frame/DefaultLocationTest.java
new file mode 100644
index 0000000000000..dfeb5e93e3c89
--- /dev/null
+++ b/test/jdk/java/awt/Frame/DefaultLocationTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 1998, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.Label;
+
+/*
+ * @test
+ * @bug 4085599
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary Test default location for frame
+ * @run main/manual DefaultLocationTest
+ */
+
+public class DefaultLocationTest {
+ private static Frame f;
+
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ A small frame containing the label 'Hello World' should
+ appear in the upper left hand corner of the screen. The
+ exact location is dependent upon the window manager.
+
+ On Linux and Mac machines, the default location for frame
+ is below the taskbar or close to top-left corner.
+
+ Upon test completion, click Pass or Fail appropriately.""";
+
+ PassFailJFrame passFailJFrame = new PassFailJFrame("DefaultLocationTest " +
+ " Instructions", INSTRUCTIONS, 5, 10, 40);
+ EventQueue.invokeAndWait(DefaultLocationTest::createAndShowUI);
+ passFailJFrame.awaitAndCheck();
+ }
+
+ private static void createAndShowUI() {
+ f = new Frame("DefaultLocation");
+ f.add("Center", new Label("Hello World"));
+ f.pack();
+ PassFailJFrame.addTestWindow(f);
+ PassFailJFrame.positionTestWindow(
+ null, PassFailJFrame.Position.HORIZONTAL);
+ f.setVisible(true);
+ }
+}
diff --git a/test/jdk/java/awt/Frame/EmptyFrameTest.java b/test/jdk/java/awt/Frame/EmptyFrameTest.java
new file mode 100644
index 0000000000000..7a324a3cbc994
--- /dev/null
+++ b/test/jdk/java/awt/Frame/EmptyFrameTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+/*
+ * @test
+ * @bug 4237529
+ * @key headful
+ * @summary Test repainting of an empty frame
+ * @run main EmptyFrameTest
+ */
+
+public class EmptyFrameTest {
+ private static Frame f;
+ private static Robot robot;
+ private static volatile Point p;
+ private static volatile Dimension d;
+ private static final int TOLERANCE = 5;
+ public static void main(String[] args) throws Exception {
+ robot = new Robot();
+ robot.setAutoDelay(100);
+ try {
+ EventQueue.invokeAndWait(() -> {
+ createAndShowUI();
+ });
+ robot.delay(1000);
+ f.setSize(50, 50);
+ robot.delay(500);
+ EventQueue.invokeAndWait(() -> {
+ p = f.getLocation();
+ d = f.getSize();
+ });
+ Rectangle rect = new Rectangle(p, d);
+ BufferedImage img = robot.createScreenCapture(rect);
+ if (chkImgBackgroundColor(img)) {
+ try {
+ ImageIO.write(img, "png", new File("Frame.png"));
+ } catch (IOException ignored) {}
+ throw new RuntimeException("Frame doesn't repaint itself on resize");
+ }
+ } finally {
+ EventQueue.invokeAndWait(() -> {
+ if (f != null) {
+ f.dispose();
+ }
+ });
+ }
+ }
+
+ private static void createAndShowUI() {
+ f = new Frame("EmptyFrameTest");
+ f.setUndecorated(true);
+ f.setBackground(Color.RED);
+ f.setVisible(true);
+ }
+
+ private static boolean chkImgBackgroundColor(BufferedImage img) {
+ for (int x = 1; x < img.getWidth() - 1; ++x) {
+ for (int y = 1; y < img.getHeight() - 1; ++y) {
+ Color c = new Color(img.getRGB(x, y));
+ if ((c.getRed() - Color.RED.getRed()) > TOLERANCE) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/test/jdk/java/awt/Frame/FrameLayoutTest.java b/test/jdk/java/awt/Frame/FrameLayoutTest.java
new file mode 100644
index 0000000000000..d6e994beaace0
--- /dev/null
+++ b/test/jdk/java/awt/Frame/FrameLayoutTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1999, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Frame;
+
+/*
+ * @test
+ * @bug 4173503
+ * @library /java/awt/regtesthelpers
+ * @requires (os.family == "windows")
+ * @build PassFailJFrame
+ * @summary Tests that frame layout is performed when frame is maximized from taskbar
+ * @run main/manual FrameLayoutTest
+ */
+
+public class FrameLayoutTest {
+
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ Right-click on the taskbar button for this test. In the menu appeared,
+ choose Maximize. The frame will be maximized. Check if buttons inside
+ the frame are laid out properly, i.e. they occupy the frame entirely.
+
+ If so, test passes. If buttons occupy small rectangle in the top left
+ corner, test fails.""";
+
+ PassFailJFrame.builder()
+ .title("Frame's Layout Test Instruction")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(FrameLayoutTest::createUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static Frame createUI() {
+ Frame f = new Frame("Maximize Test");
+ f.add(new Button("North"), BorderLayout.NORTH);
+ f.add(new Button("South"), BorderLayout.SOUTH);
+ f.add(new Button("East"), BorderLayout.EAST);
+ f.add(new Button("West"), BorderLayout.WEST);
+ f.add(new Button("Cent"), BorderLayout.CENTER);
+ f.pack();
+ f.setState(Frame.ICONIFIED);
+ return f;
+ }
+}
diff --git a/test/jdk/java/awt/Frame/FrameSetMinimumSizeTest.java b/test/jdk/java/awt/Frame/FrameSetMinimumSizeTest.java
new file mode 100644
index 0000000000000..929a36e773e40
--- /dev/null
+++ b/test/jdk/java/awt/Frame/FrameSetMinimumSizeTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2005, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.Frame;
+
+/*
+ * @test
+ * @bug 4320050
+ * @key headful
+ * @summary Minimum size for java.awt.Frame is not being enforced.
+ * @run main FrameSetMinimumSizeTest
+ */
+
+public class FrameSetMinimumSizeTest {
+ private static Frame f;
+ private static volatile boolean passed;
+
+ public static void main(String[] args) throws Exception {
+ EventQueue.invokeAndWait(() -> {
+ try {
+ createAndShowUI();
+
+ f.setSize(200, 200);
+ passed = verifyFrameSize(new Dimension(300, 300));
+ isFrameSizeOk(passed);
+
+ f.setSize(200, 400);
+ passed = verifyFrameSize(new Dimension(300, 400));
+ isFrameSizeOk(passed);
+
+ f.setSize(400, 200);
+ passed = verifyFrameSize(new Dimension(400, 300));
+ isFrameSizeOk(passed);
+
+ f.setMinimumSize(null);
+
+ f.setSize(200, 200);
+ passed = verifyFrameSize(new Dimension(200, 200));
+ isFrameSizeOk(passed);
+ } finally {
+ if (f != null) {
+ f.dispose();
+ }
+ }
+ });
+ }
+
+ private static void createAndShowUI() {
+ f = new Frame("Minimum Size Test");
+ f.setSize(300, 300);
+ f.setMinimumSize(new Dimension(300, 300));
+ f.setVisible(true);
+ }
+
+ private static boolean verifyFrameSize(Dimension expected) {
+
+ if (f.getSize().width != expected.width || f.getSize().height != expected.height) {
+ return false;
+ }
+ return true;
+ }
+
+ private static void isFrameSizeOk(boolean passed) {
+ if (!passed) {
+ throw new RuntimeException("Frame's setMinimumSize not honoured for the" +
+ " frame size: " + f.getSize());
+ }
+ }
+}
diff --git a/test/jdk/java/awt/Frame/PackTwiceTest.java b/test/jdk/java/awt/Frame/PackTwiceTest.java
new file mode 100644
index 0000000000000..63cd20612f0d3
--- /dev/null
+++ b/test/jdk/java/awt/Frame/PackTwiceTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2001, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Frame;
+import java.awt.TextField;
+
+/*
+ * @test
+ * @bug 4097744
+ * @library /java/awt/regtesthelpers
+ * @build PassFailJFrame
+ * @summary packing a frame twice stops it resizing
+ * @run main/manual PackTwiceTest
+ */
+
+public class PackTwiceTest {
+ public static void main(String[] args) throws Exception {
+ String INSTRUCTIONS = """
+ 1. You would see a Frame titled 'TestFrame'
+ 2. The Frame displays a text as below:
+ 'I am a lengthy sentence...can you see me?'
+ 3. If you can see the full text without resizing the frame
+ using mouse, press 'Pass' else press 'Fail'.""";
+
+ PassFailJFrame.builder()
+ .title("PackTwiceTest Instruction")
+ .instructions(INSTRUCTIONS)
+ .rows((int) INSTRUCTIONS.lines().count() + 2)
+ .columns(40)
+ .testUI(PackTwiceTest::createUI)
+ .build()
+ .awaitAndCheck();
+ }
+
+ private static Frame createUI() {
+ Frame f = new Frame("PackTwiceTest TestFrame");
+ TextField tf = new TextField();
+ f.add(tf, "Center");
+ tf.setText("I am a short sentence");
+ f.pack();
+ f.pack();
+ tf.setText("I am a lengthy sentence...can you see me?");
+ f.pack();
+ f.requestFocus();
+ return f;
+ }
+}
From 67448b0eb2e83501b9c1dd0c79c7fe03aaef6b09 Mon Sep 17 00:00:00 2001
From: Pavel Rappo
Date: Mon, 23 Sep 2024 10:32:58 +0000
Subject: [PATCH 048/110] 8339852: Fix typos in java.compiler documentation
Reviewed-by: liach, darcy
---
.../processing/AbstractProcessor.java | 4 ++--
.../processing/RoundEnvironment.java | 6 ++---
.../javax/lang/model/AnnotatedConstruct.java | 13 ++++++-----
.../javax/lang/model/SourceVersion.java | 23 +++++++++----------
.../lang/model/element/AnnotationMirror.java | 4 ++--
.../lang/model/element/ExecutableElement.java | 4 ++--
.../javax/lang/model/element/TypeElement.java | 6 ++---
.../lang/model/element/package-info.java | 4 ++--
.../javax/lang/model/util/Elements.java | 18 +++++++--------
.../classes/javax/lang/model/util/Types.java | 8 +++----
.../javax/tools/ForwardingFileObject.java | 4 ++--
.../tools/ForwardingJavaFileManager.java | 4 ++--
.../javax/tools/ForwardingJavaFileObject.java | 4 ++--
.../classes/javax/tools/JavaFileManager.java | 6 ++---
.../javax/tools/StandardJavaFileManager.java | 4 ++--
.../classes/javax/tools/ToolProvider.java | 6 ++---
16 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java b/src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java
index 3d65d200c0d1a..108e3789d287f 100644
--- a/src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java
+++ b/src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -157,7 +157,7 @@ public SourceVersion getSupportedSourceVersion() {
*
* @implSpec
* Initializes the processor with the processing environment by
- * setting the {@code processingEnv} field to the value of the
+ * setting the {@link #processingEnv} field to the value of the
* {@code processingEnv} argument. An {@code
* IllegalStateException} will be thrown if this method is called
* more than once on the same object.
diff --git a/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java b/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java
index 49e94faf179e4..d0c43d929c8d9 100644
--- a/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java
+++ b/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -146,7 +146,7 @@ default Set extends Element> getElementsAnnotatedWithAny(TypeElement... annota
* processing. The set of annotation interfaces present in the runtime
* context may differ from the set of annotation interfaces present in
* the context of annotation processing in a particular
- * environmental configuration. If an runtime annotation interface is
+ * environmental configuration. If a runtime annotation interface is
* not present in the annotation processing context, the situation
* is not treated as an error and no elements are found for that
* annotation interface.
@@ -173,7 +173,7 @@ default Set extends Element> getElementsAnnotatedWithAny(TypeElement... annota
* processing. The set of annotation interfaces present in the runtime
* context may differ from the set of annotation interfaces present in
* the context of annotation processing in a particular
- * environmental configuration. If an runtime annotation interface is
+ * environmental configuration. If a runtime annotation interface is
* not present in the annotation processing context, the situation
* is not treated as an error and no elements are found for that
* annotation interface.
diff --git a/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java b/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java
index 6dc1b1ccab129..2bb275a046b09 100644
--- a/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java
+++ b/src/java.compiler/share/classes/javax/lang/model/AnnotatedConstruct.java
@@ -45,14 +45,14 @@
* {@index "type annotation"}.
*
* The terms directly present, present,
- * indirectly present, and associated are used
+ * indirectly present, and associated are used
* throughout this interface to describe precisely which annotations,
* either declaration annotations or type annotations, are returned by
* the methods in this interface.
*
*
In the definitions below, an annotation A has an
* annotation interface AI. If AI is a repeatable annotation
- * interface, the type of the containing annotation is AIC.
+ * interface, the type of the container annotation is AIC.
*
*
Annotation A is {@index "directly present"} on a construct
* C if either:
@@ -78,7 +78,7 @@
* Specification (JLS {@jls 8.10.1}).
*
* If there are multiple annotations of type AI present on
- * C, then if AI is repeatable annotation interface, an
+ * C, then if AI is a repeatable annotation interface, an
* annotation of type AIC is {@linkplain javax.lang.model.util.Elements#getOrigin(AnnotatedConstruct, AnnotationMirror) implicitly declared} on C.
*
A representation of A appears in the executable output
* for C, such as the {@code RuntimeVisibleAnnotations} (JVMS {@jvms 4.7.16}) or
@@ -189,10 +189,11 @@ public interface AnnotatedConstruct {
A getAnnotation(Class annotationType);
/**
- * Returns annotations that are associated with this construct.
+ * Returns annotations of the specified type that are associated
+ * with this construct.
*
- * If there are no annotations associated with this construct, the
- * return value is an array of length 0.
+ * If there are no annotations of the specified type associated with this
+ * construct, the return value is an array of length 0.
*
* The order of annotations which are directly or indirectly
* present on a construct C is computed as if indirectly present
diff --git a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java
index 871487b98e6f4..adc45006601ed 100644
--- a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java
+++ b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java
@@ -208,7 +208,7 @@ public enum SourceVersion {
* @see
* JEP 213: Milling Project Coin
*/
- RELEASE_9,
+ RELEASE_9,
/**
* The version introduced by the Java Platform, Standard Edition
@@ -476,7 +476,7 @@ private static SourceVersion getLatestSupported() {
*
* @apiNote This method is included alongside {@link latest} to
* allow identification of situations where the language model API
- * is running on a platform version different than the latest
+ * is running on a platform version different from the latest
* version modeled by the API. One way that sort of situation can
* occur is if an IDE or similar tool is using the API to model
* source version N while running on platform version
@@ -502,8 +502,7 @@ public static SourceVersion latestSupported() {
* followed only by characters for which {@link
* Character#isJavaIdentifierPart(int)} returns {@code true}.
* This pattern matches regular identifiers, keywords, contextual
- * keywords, and the literals {@code "true"},
- * {@code "false"}, {@code "null"}.
+ * keywords, boolean literals, and the null literal.
*
* The method returns {@code false} for all other strings.
*
@@ -596,14 +595,14 @@ public static boolean isName(CharSequence name, SourceVersion version) {
}
/**
- * Returns whether or not {@code s} is a keyword, boolean literal,
- * or null literal in the latest source version.
+ * Returns whether or not {@code s} is a keyword, a boolean literal,
+ * or the null literal in the latest source version.
* This method returns {@code false} for contextual
* keywords.
*
* @param s the string to check
- * @return {@code true} if {@code s} is a keyword, or boolean
- * literal, or null literal, {@code false} otherwise.
+ * @return {@code true} if {@code s} is a keyword, boolean
+ * literal, or the null literal, {@code false} otherwise.
* @jls 3.9 Keywords
* @jls 3.10.3 Boolean Literals
* @jls 3.10.8 The Null Literal
@@ -613,15 +612,15 @@ public static boolean isKeyword(CharSequence s) {
}
/**
- * Returns whether or not {@code s} is a keyword, boolean literal,
- * or null literal in the given source version.
+ * Returns whether or not {@code s} is a keyword, a boolean literal,
+ * or the null literal in the given source version.
* This method returns {@code false} for contextual
* keywords.
*
* @param s the string to check
* @param version the version to use
- * @return {@code true} if {@code s} is a keyword, or boolean
- * literal, or null literal, {@code false} otherwise.
+ * @return {@code true} if {@code s} is a keyword, boolean
+ * literal, or the null literal, {@code false} otherwise.
* @jls 3.9 Keywords
* @jls 3.10.3 Boolean Literals
* @jls 3.10.8 The Null Literal
diff --git a/src/java.compiler/share/classes/javax/lang/model/element/AnnotationMirror.java b/src/java.compiler/share/classes/javax/lang/model/element/AnnotationMirror.java
index 908d171e9c7f8..2d92504edb68f 100644
--- a/src/java.compiler/share/classes/javax/lang/model/element/AnnotationMirror.java
+++ b/src/java.compiler/share/classes/javax/lang/model/element/AnnotationMirror.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -47,7 +47,7 @@ public interface AnnotationMirror {
/**
* Returns the values of this annotation's elements.
- * This is returned in the form of a map that associates elements
+ * These are returned in the form of a map that associates elements
* with their corresponding values.
* Only those elements with values explicitly present in the
* annotation are included, not those that are implicitly assuming
diff --git a/src/java.compiler/share/classes/javax/lang/model/element/ExecutableElement.java b/src/java.compiler/share/classes/javax/lang/model/element/ExecutableElement.java
index 8bff37483947c..18923463248e2 100644
--- a/src/java.compiler/share/classes/javax/lang/model/element/ExecutableElement.java
+++ b/src/java.compiler/share/classes/javax/lang/model/element/ExecutableElement.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -34,7 +34,7 @@
* elements.
* Annotation interface elements are methods restricted to have no
* formal parameters, no type parameters, and no {@code throws}
- * clause, among other restrictions; see JLS {@jls 9.6.1} for details
+ * clause, among other restrictions; see JLS {@jls 9.6.1} for details.
*
* @see ExecutableType
* @since 1.6
diff --git a/src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java b/src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java
index 3f34b1799929d..abf95bcefad50 100644
--- a/src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java
+++ b/src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java
@@ -58,14 +58,14 @@
* javax.lang.model.util.Elements#getFileObjectOf(Element) reference
* representation} (either source code or executable output). Multiple
* classes and interfaces can share the same reference representation
- * backing construct. For example, multiple classes and interface can
- * be declared in the same source file, including, but are not limited
+ * backing construct. For example, multiple classes and interfaces can
+ * be declared in the same source file, including, but not limited
* to:
*
*
a {@linkplain NestingKind#TOP_LEVEL top-level} class or
* interface and auxiliary classes and interfaces
*
a top-level class or interface and {@linkplain
- * NestingKind#isNested() nested class and interfaces} within it
+ * NestingKind#isNested() nested classes and interfaces} within it
*
*
In the context of annotation processing, a type element can
* be:
diff --git a/src/java.compiler/share/classes/javax/lang/model/element/package-info.java b/src/java.compiler/share/classes/javax/lang/model/element/package-info.java
index 56edb89d3e35c..ab4eeb1e747ec 100644
--- a/src/java.compiler/share/classes/javax/lang/model/element/package-info.java
+++ b/src/java.compiler/share/classes/javax/lang/model/element/package-info.java
@@ -30,7 +30,7 @@
* elements, the declared entities that make up a program. Elements
* include classes, interfaces, methods, constructors, and fields.
* The interfaces in this package do not model the structure of a
- * program inside a method body; for example there is no
+ * program inside a method body; for example, there is no
* representation of a {@code for} loop or {@code try}-{@code finally}
* block. Concretely, there is no model of any abstract syntax tree
* (AST) structure of a Java program. However, the interfaces can
@@ -84,7 +84,7 @@
* javax.lang.model.util.Elements#isBridge(ExecutableElement)
* bridge methods} used in implementing covariant returns, are
* translation artifacts strictly outside of this model. However, when
- * operating on class files, it is helpful be able to operate on such
+ * operating on class files, it is helpful to be able to operate on such
* elements, screening them out when appropriate.
*
*
During annotation processing, operating on incomplete or
diff --git a/src/java.compiler/share/classes/javax/lang/model/util/Elements.java b/src/java.compiler/share/classes/javax/lang/model/util/Elements.java
index 2faf3f5ec32b2..5159ac26e3bfa 100644
--- a/src/java.compiler/share/classes/javax/lang/model/util/Elements.java
+++ b/src/java.compiler/share/classes/javax/lang/model/util/Elements.java
@@ -56,11 +56,11 @@ public interface Elements {
*
*
find non-empty packages with the given name returned by
* {@link #getPackageElement(ModuleElement, CharSequence)},
- * where the provided ModuleSymbol is any
+ * where the provided ModuleElement is any
* {@linkplain java.lang.module##root-modules root module},
*
*
if the above yields an empty list, search
- * {@link #getAllModuleElements() all modules} for observable
+ * {@linkplain #getAllModuleElements() all modules} for observable
* packages with the given name
*
find type elements with the given name returned by
* {@link #getTypeElement(ModuleElement, CharSequence)},
- * where the provided ModuleSymbol is any
+ * where the provided ModuleElement is any
* {@linkplain java.lang.module##root-modules root module},
*
*
if the above yields an empty list, search
- * {@link #getAllModuleElements() all modules} for observable
+ * {@linkplain #getAllModuleElements() all modules} for observable
* type elements with the given name
*
*
@@ -617,7 +617,7 @@ default ModuleElement getModuleOf(Element e) {
/**
* Returns all members of a type element, whether inherited or
- * declared directly. For a class the result also includes its
+ * declared directly. For a class, the result also includes its
* constructors, but not local or anonymous classes.
*
* @apiNote Elements of certain kinds can be isolated using
@@ -878,10 +878,10 @@ default TypeElement getEnumConstantBody(VariableElement enumConstant) {
* accessor.
*
* @implSpec The default implementation of this method checks if the element
- * enclosing the accessor has kind {@link ElementKind#RECORD RECORD} if that is
- * the case, then all the record components on the accessor's enclosing element
- * are retrieved by invoking {@link ElementFilter#recordComponentsIn(Iterable)}.
- * If the accessor of at least one of the record components retrieved happen to
+ * enclosing the accessor has kind {@link ElementKind#RECORD RECORD}, if that is
+ * the case, then all the record components of the accessor's enclosing element
+ * are isolated by invoking {@link ElementFilter#recordComponentsIn(Iterable)}.
+ * If the accessor of at least one of the record components retrieved happens to
* be equal to the accessor passed as a parameter to this method, then that
* record component is returned, in any other case {@code null} is returned.
*
diff --git a/src/java.compiler/share/classes/javax/lang/model/util/Types.java b/src/java.compiler/share/classes/javax/lang/model/util/Types.java
index bbbf4e3d95e6a..266d63178ba08 100644
--- a/src/java.compiler/share/classes/javax/lang/model/util/Types.java
+++ b/src/java.compiler/share/classes/javax/lang/model/util/Types.java
@@ -40,7 +40,7 @@
* ExecutableType Executable types} and the pseudo-types for
* {@linkplain TypeKind#PACKAGE packages} and {@linkplain
* TypeKind#MODULE modules} are generally out of scope for these
- * methods. One or more out of scope arguments will typically result
+ * methods. One or more out-of-scope arguments will typically result
* in a method throwing an {@link IllegalArgumentException}.
*
*
Where a method returns a type mirror or a collection of type
@@ -165,7 +165,7 @@ public interface Types {
* the direct supertypes of a type mirror representing {@code
* java.lang.Object}.
*
- * Annotations on the direct super types are preserved.
+ * Annotations on the direct supertypes are preserved.
*
* @param t the type being examined
* @return the direct supertypes, or an empty list if none
@@ -318,7 +318,7 @@ WildcardType getWildcardType(TypeMirror extendsBound,
* Annotations on the type arguments are preserved.
*
*
If the containing type is a parameterized type,
- * the number of type arguments must equal the
+ * the number of type arguments must be equal to the
* number of {@code typeElem}'s formal type parameters.
* If it is not parameterized or if it is {@code null}, this method is
* equivalent to {@code getDeclaredType(typeElem, typeArgs)}.
@@ -354,7 +354,7 @@ DeclaredType getDeclaredType(DeclaredType containing,
/**
* {@return a type mirror equivalent to the argument, but with no annotations}
* If the type mirror is a composite type, such as an array type
- * or a wildcard type, any constitute types, such as the
+ * or a wildcard type, any constituent types, such as the
* component type of an array and the type of the bounds of a
* wildcard type, also have no annotations, recursively.
*
diff --git a/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java b/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java
index 98bb5a650a406..d61198c6aef8b 100644
--- a/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java
+++ b/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -39,7 +39,7 @@
* additional fields and methods.
*
*
Unless stated otherwise, references in this class to "this file object"
- * should be interpreted as referring indirectly to the {@link #fileObject delegate file object}.
+ * should be interpreted as referring indirectly to the {@linkplain #fileObject delegate file object}.
*
* @param the kind of file object forwarded to by this object
* @since 1.6
diff --git a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java
index 40224abbd509d..9db757f05a242 100644
--- a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java
+++ b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -39,7 +39,7 @@
* additional fields and methods.
*
*
Unless stated otherwise, references in this class to "this file manager"
- * should be interpreted as referring indirectly to the {@link #fileManager delegate file manager}.
+ * should be interpreted as referring indirectly to the {@linkplain #fileManager delegate file manager}.
*
* @param the kind of file manager forwarded to by this object
* @since 1.6
diff --git a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileObject.java b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileObject.java
index a940b23009d8e..e8db8919750a3 100644
--- a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileObject.java
+++ b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -34,7 +34,7 @@
* additional fields and methods.
*
*
Unless stated otherwise, references in this class to "this file object"
- * should be interpreted as referring indirectly to the {@link #fileObject delegate file object}.
+ * should be interpreted as referring indirectly to the {@linkplain #fileObject delegate file object}.
*
* @param the kind of file object forwarded to by this object
* @since 1.6
diff --git a/src/java.compiler/share/classes/javax/tools/JavaFileManager.java b/src/java.compiler/share/classes/javax/tools/JavaFileManager.java
index 327064b5a5215..da2a3b534acf1 100644
--- a/src/java.compiler/share/classes/javax/tools/JavaFileManager.java
+++ b/src/java.compiler/share/classes/javax/tools/JavaFileManager.java
@@ -52,7 +52,7 @@
*
*
Some methods in this interface use class names. Such class
* names must be given in the Java Virtual Machine internal form of
- * fully qualified class and interface names. For convenience '.'
+ * fully qualified class and interface names. For convenience, '.'
* and '/' are interchangeable. The internal form is defined in
* chapter four of
* The Java Virtual Machine Specification.
@@ -239,7 +239,7 @@ Iterable list(Location location,
String inferBinaryName(Location location, JavaFileObject file);
/**
- * Compares two file objects and return true if they represent the
+ * Compares two file objects and returns true if they represent the
* same underlying object.
*
* @param a a file object
@@ -255,7 +255,7 @@ Iterable list(Location location,
/**
* Handles one option. If {@code current} is an option to this
- * file manager it will consume any arguments to that option from
+ * file manager, it will consume any arguments to that option from
* {@code remaining} and return true, otherwise return false.
*
* @param current current option
diff --git a/src/java.compiler/share/classes/javax/tools/StandardJavaFileManager.java b/src/java.compiler/share/classes/javax/tools/StandardJavaFileManager.java
index 769856535acee..277f6d57b0eb5 100644
--- a/src/java.compiler/share/classes/javax/tools/StandardJavaFileManager.java
+++ b/src/java.compiler/share/classes/javax/tools/StandardJavaFileManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -142,7 +142,7 @@
*
*
*
All implementations of this interface must support Path objects representing
- * files in the {@linkplain java.nio.file.FileSystems#getDefault() default file system.}
+ * files in the {@linkplain java.nio.file.FileSystems#getDefault() default file system}.
* It is recommended that implementations should support Path objects from any filesystem.
*
*
diff --git a/src/java.compiler/share/classes/javax/tools/ToolProvider.java b/src/java.compiler/share/classes/javax/tools/ToolProvider.java
index d05b65b0ffe94..8cdfd63b17ded 100644
--- a/src/java.compiler/share/classes/javax/tools/ToolProvider.java
+++ b/src/java.compiler/share/classes/javax/tools/ToolProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -90,8 +90,8 @@ public static DocumentationTool getSystemDocumentationTool() {
* @implSpec This implementation always returns {@code null}.
* @deprecated This method is subject to removal in a future version of
* Java SE.
- * Use the {@link java.util.spi.ToolProvider system tool provider} or
- * {@link java.util.ServiceLoader service loader} mechanisms to
+ * Use the {@linkplain java.util.spi.ToolProvider system tool provider} or
+ * {@linkplain java.util.ServiceLoader service loader} mechanisms to
* locate system tools as well as user-installed tools.
* @return a class loader, or {@code null}
*/
From 384deda65fd63e23d4caaaa9762f2ac80de78029 Mon Sep 17 00:00:00 2001
From: Per Minborg
Date: Mon, 23 Sep 2024 10:57:43 +0000
Subject: [PATCH 049/110] 8325949: Create an internal utility method for
creating VarHandle instances
Reviewed-by: rriggs
---
.../classes/java/lang/ThreadBuilders.java | 15 ++--
.../classes/java/lang/invoke/Invokers.java | 14 +---
.../share/classes/java/net/Socket.java | 13 ++--
.../java/nio/channels/SelectionKey.java | 16 ++--
.../channels/spi/AbstractSelectionKey.java | 14 +---
.../nio/channels/spi/AbstractSelector.java | 14 ++--
.../util/concurrent/CompletableFuture.java | 14 ++--
.../java/util/concurrent/Exchanger.java | 16 ++--
.../java/util/concurrent/FutureTask.java | 14 ++--
.../classes/java/util/concurrent/Phaser.java | 12 +--
.../concurrent/PriorityBlockingQueue.java | 16 ++--
.../util/concurrent/StructuredTaskScope.java | 24 ++----
.../util/concurrent/SubmissionPublisher.java | 16 ++--
.../concurrent/ThreadPerTaskExecutor.java | 26 ++-----
.../util/concurrent/atomic/AtomicBoolean.java | 13 +---
.../atomic/AtomicMarkableReference.java | 14 +---
.../concurrent/atomic/AtomicReference.java | 13 +---
.../atomic/AtomicStampedReference.java | 14 +---
.../util/concurrent/atomic/Striped64.java | 31 +++-----
.../classes/java/util/stream/ForEachOps.java | 15 ++--
.../classes/java/util/stream/GathererOp.java | 13 +---
.../jdk/internal/foreign/ConfinedSession.java | 14 +---
.../internal/foreign/MemorySessionImpl.java | 15 ++--
.../jdk/internal/foreign/SharedSession.java | 14 +---
.../internal/foreign/abi/DowncallLinker.java | 19 ++---
.../foreign/layout/AbstractLayout.java | 13 +---
.../classes/jdk/internal/invoke/MhUtil.java | 78 +++++++++++++++++++
.../jdk/internal/misc/ThreadFlock.java | 13 ++--
.../reflect/DirectMethodHandleAccessor.java | 18 ++---
.../internal/vm/SharedThreadContainer.java | 15 ++--
.../sun/nio/ch/DatagramChannelImpl.java | 13 +---
31 files changed, 232 insertions(+), 317 deletions(-)
create mode 100644 src/java.base/share/classes/jdk/internal/invoke/MhUtil.java
diff --git a/src/java.base/share/classes/java/lang/ThreadBuilders.java b/src/java.base/share/classes/java/lang/ThreadBuilders.java
index ca29dc4f53589..234807d4cc2a7 100644
--- a/src/java.base/share/classes/java/lang/ThreadBuilders.java
+++ b/src/java.base/share/classes/java/lang/ThreadBuilders.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 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
@@ -34,6 +34,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadFactory;
import jdk.internal.misc.Unsafe;
+import jdk.internal.invoke.MhUtil;
import jdk.internal.vm.ContinuationSupport;
/**
@@ -273,15 +274,9 @@ public ThreadFactory factory() {
* Base ThreadFactory implementation.
*/
private abstract static class BaseThreadFactory implements ThreadFactory {
- private static final VarHandle COUNT;
- static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- COUNT = l.findVarHandle(BaseThreadFactory.class, "count", long.class);
- } catch (Exception e) {
- throw new InternalError(e);
- }
- }
+ private static final VarHandle COUNT = MhUtil.findVarHandle(
+ MethodHandles.lookup(), "count", long.class);
+
private final String name;
private final int characteristics;
private final UncaughtExceptionHandler uhe;
diff --git a/src/java.base/share/classes/java/lang/invoke/Invokers.java b/src/java.base/share/classes/java/lang/invoke/Invokers.java
index 1f4314f5421d2..9990370ae25b6 100644
--- a/src/java.base/share/classes/java/lang/invoke/Invokers.java
+++ b/src/java.base/share/classes/java/lang/invoke/Invokers.java
@@ -25,6 +25,7 @@
package java.lang.invoke;
+import jdk.internal.invoke.MhUtil;
import jdk.internal.vm.annotation.DontInline;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Hidden;
@@ -681,16 +682,9 @@ private static NamedFunction getNamedFunction(String name, MethodType type)
}
private static class Lazy {
- private static final MethodHandle MH_asSpreader;
-
- static {
- try {
- MH_asSpreader = IMPL_LOOKUP.findVirtual(MethodHandle.class, "asSpreader",
- MethodType.methodType(MethodHandle.class, Class.class, int.class));
- } catch (ReflectiveOperationException ex) {
- throw newInternalError(ex);
- }
- }
+ private static final MethodHandle MH_asSpreader = MhUtil.findVirtual(
+ IMPL_LOOKUP, MethodHandle.class, "asSpreader",
+ MethodType.methodType(MethodHandle.class, Class.class, int.class));
}
static {
diff --git a/src/java.base/share/classes/java/net/Socket.java b/src/java.base/share/classes/java/net/Socket.java
index 23c225fbb2d29..309fa7a80d099 100644
--- a/src/java.base/share/classes/java/net/Socket.java
+++ b/src/java.base/share/classes/java/net/Socket.java
@@ -27,6 +27,7 @@
import jdk.internal.event.SocketReadEvent;
import jdk.internal.event.SocketWriteEvent;
+import jdk.internal.invoke.MhUtil;
import sun.security.util.SecurityConstants;
import java.io.InputStream;
@@ -102,14 +103,10 @@
public class Socket implements java.io.Closeable {
private static final VarHandle STATE, IN, OUT;
static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- STATE = l.findVarHandle(Socket.class, "state", int.class);
- IN = l.findVarHandle(Socket.class, "in", InputStream.class);
- OUT = l.findVarHandle(Socket.class, "out", OutputStream.class);
- } catch (Exception e) {
- throw new InternalError(e);
- }
+ MethodHandles.Lookup l = MethodHandles.lookup();
+ STATE = MhUtil.findVarHandle(l, "state", int.class);
+ IN = MhUtil.findVarHandle(l, "in", InputStream.class);
+ OUT = MhUtil.findVarHandle(l, "out", OutputStream.class);
}
// the underlying SocketImpl, may be null, may be swapped when connecting
diff --git a/src/java.base/share/classes/java/nio/channels/SelectionKey.java b/src/java.base/share/classes/java/nio/channels/SelectionKey.java
index ca6df2a7aa054..79029e6365353 100644
--- a/src/java.base/share/classes/java/nio/channels/SelectionKey.java
+++ b/src/java.base/share/classes/java/nio/channels/SelectionKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -25,6 +25,8 @@
package java.nio.channels;
+import jdk.internal.invoke.MhUtil;
+
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@@ -429,15 +431,9 @@ public final boolean isAcceptable() {
// -- Attachments --
- private static final VarHandle ATTACHMENT;
- static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- ATTACHMENT = l.findVarHandle(SelectionKey.class, "attachment", Object.class);
- } catch (Exception e) {
- throw new InternalError(e);
- }
- }
+ private static final VarHandle ATTACHMENT = MhUtil.findVarHandle(
+ MethodHandles.lookup(), "attachment", Object.class);
+
private volatile Object attachment;
/**
diff --git a/src/java.base/share/classes/java/nio/channels/spi/AbstractSelectionKey.java b/src/java.base/share/classes/java/nio/channels/spi/AbstractSelectionKey.java
index 0a79ca321dd33..3005fc9522c64 100644
--- a/src/java.base/share/classes/java/nio/channels/spi/AbstractSelectionKey.java
+++ b/src/java.base/share/classes/java/nio/channels/spi/AbstractSelectionKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -30,6 +30,7 @@
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
+import jdk.internal.invoke.MhUtil;
import sun.nio.ch.SelectionKeyImpl;
import sun.nio.ch.SelectorImpl;
@@ -46,15 +47,8 @@
public abstract class AbstractSelectionKey
extends SelectionKey
{
- private static final VarHandle INVALID;
- static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- INVALID = l.findVarHandle(AbstractSelectionKey.class, "invalid", boolean.class);
- } catch (Exception e) {
- throw new InternalError(e);
- }
- }
+ private static final VarHandle INVALID = MhUtil.findVarHandle(
+ MethodHandles.lookup(), "invalid", boolean.class);
/**
* Initializes a new instance of this class.
diff --git a/src/java.base/share/classes/java/nio/channels/spi/AbstractSelector.java b/src/java.base/share/classes/java/nio/channels/spi/AbstractSelector.java
index 7ea5f89221834..71dc8620eb804 100644
--- a/src/java.base/share/classes/java/nio/channels/spi/AbstractSelector.java
+++ b/src/java.base/share/classes/java/nio/channels/spi/AbstractSelector.java
@@ -32,6 +32,8 @@
import java.nio.channels.Selector;
import java.util.HashSet;
import java.util.Set;
+
+import jdk.internal.invoke.MhUtil;
import sun.nio.ch.Interruptible;
import sun.nio.ch.SelectorImpl;
@@ -72,15 +74,9 @@
public abstract class AbstractSelector
extends Selector
{
- private static final VarHandle CLOSED;
- static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- CLOSED = l.findVarHandle(AbstractSelector.class, "closed", boolean.class);
- } catch (Exception e) {
- throw new InternalError(e);
- }
- }
+ private static final VarHandle CLOSED = MhUtil.findVarHandle(
+ MethodHandles.lookup(), "closed", boolean.class);
+
private volatile boolean closed;
// The provider that created this selector
diff --git a/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java b/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java
index 8adfd106eebb4..d690494405085 100644
--- a/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java
+++ b/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java
@@ -35,6 +35,8 @@
package java.util.concurrent;
+import jdk.internal.invoke.MhUtil;
+
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.LockSupport;
@@ -3079,14 +3081,10 @@ static final class MinimalStage extends CompletableFuture {
private static final VarHandle STACK;
private static final VarHandle NEXT;
static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- RESULT = l.findVarHandle(CompletableFuture.class, "result", Object.class);
- STACK = l.findVarHandle(CompletableFuture.class, "stack", Completion.class);
- NEXT = l.findVarHandle(Completion.class, "next", Completion.class);
- } catch (ReflectiveOperationException e) {
- throw new ExceptionInInitializerError(e);
- }
+ MethodHandles.Lookup l = MethodHandles.lookup();
+ RESULT = MhUtil.findVarHandle(l, "result", Object.class);
+ STACK = MhUtil.findVarHandle(l, "stack", Completion.class);
+ NEXT = MhUtil.findVarHandle(l, Completion.class, "next", Completion.class);
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773
diff --git a/src/java.base/share/classes/java/util/concurrent/Exchanger.java b/src/java.base/share/classes/java/util/concurrent/Exchanger.java
index 8674ea9af39bc..75de69b3e5283 100644
--- a/src/java.base/share/classes/java/util/concurrent/Exchanger.java
+++ b/src/java.base/share/classes/java/util/concurrent/Exchanger.java
@@ -36,6 +36,8 @@
package java.util.concurrent;
+import jdk.internal.invoke.MhUtil;
+
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.LockSupport;
@@ -530,15 +532,11 @@ public V exchange(V x, long timeout, TimeUnit unit)
private static final VarHandle ENTRY;
private static final VarHandle AA;
static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- BOUND = l.findVarHandle(Exchanger.class, "bound", int.class);
- MATCH = l.findVarHandle(Node.class, "match", Object.class);
- ENTRY = l.findVarHandle(Slot.class, "entry", Node.class);
- AA = MethodHandles.arrayElementVarHandle(Slot[].class);
- } catch (ReflectiveOperationException e) {
- throw new ExceptionInInitializerError(e);
- }
+ MethodHandles.Lookup l = MethodHandles.lookup();
+ BOUND = MhUtil.findVarHandle(l, "bound", int.class);
+ MATCH = MhUtil.findVarHandle(l, Node.class, "match", Object.class);
+ ENTRY = MhUtil.findVarHandle(l, Slot.class, "entry", Node.class);
+ AA = MethodHandles.arrayElementVarHandle(Slot[].class);
}
}
diff --git a/src/java.base/share/classes/java/util/concurrent/FutureTask.java b/src/java.base/share/classes/java/util/concurrent/FutureTask.java
index 627e69559c856..b905e71aeef95 100644
--- a/src/java.base/share/classes/java/util/concurrent/FutureTask.java
+++ b/src/java.base/share/classes/java/util/concurrent/FutureTask.java
@@ -35,6 +35,8 @@
package java.util.concurrent;
+import jdk.internal.invoke.MhUtil;
+
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.LockSupport;
@@ -582,14 +584,10 @@ public String toString() {
private static final VarHandle RUNNER;
private static final VarHandle WAITERS;
static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- STATE = l.findVarHandle(FutureTask.class, "state", int.class);
- RUNNER = l.findVarHandle(FutureTask.class, "runner", Thread.class);
- WAITERS = l.findVarHandle(FutureTask.class, "waiters", WaitNode.class);
- } catch (ReflectiveOperationException e) {
- throw new ExceptionInInitializerError(e);
- }
+ MethodHandles.Lookup l = MethodHandles.lookup();
+ STATE = MhUtil.findVarHandle(l, "state", int.class);
+ RUNNER = MhUtil.findVarHandle(l, "runner", Thread.class);
+ WAITERS = MhUtil.findVarHandle(l, "waiters", WaitNode.class);
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773
diff --git a/src/java.base/share/classes/java/util/concurrent/Phaser.java b/src/java.base/share/classes/java/util/concurrent/Phaser.java
index 22e2f663cb9a7..9cd2376d84714 100644
--- a/src/java.base/share/classes/java/util/concurrent/Phaser.java
+++ b/src/java.base/share/classes/java/util/concurrent/Phaser.java
@@ -35,6 +35,8 @@
package java.util.concurrent;
+import jdk.internal.invoke.MhUtil;
+
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.atomic.AtomicReference;
@@ -1137,15 +1139,9 @@ public boolean block() {
}
// VarHandle mechanics
- private static final VarHandle STATE;
+ private static final VarHandle STATE = MhUtil.findVarHandle(
+ MethodHandles.lookup(), "state", long.class);
static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- STATE = l.findVarHandle(Phaser.class, "state", long.class);
- } catch (ReflectiveOperationException e) {
- throw new ExceptionInInitializerError(e);
- }
-
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773
Class> ensureLoaded = LockSupport.class;
diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
index fdb0128b7a755..f51e356736dea 100644
--- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
+++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
@@ -53,6 +53,7 @@
import java.util.function.Consumer;
import java.util.function.Predicate;
import jdk.internal.access.SharedSecrets;
+import jdk.internal.invoke.MhUtil;
import jdk.internal.util.ArraysSupport;
/**
@@ -1093,15 +1094,8 @@ public void forEach(Consumer super E> action) {
}
// VarHandle mechanics
- private static final VarHandle ALLOCATIONSPINLOCK;
- static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- ALLOCATIONSPINLOCK = l.findVarHandle(PriorityBlockingQueue.class,
- "allocationSpinLock",
- int.class);
- } catch (ReflectiveOperationException e) {
- throw new ExceptionInInitializerError(e);
- }
- }
+ private static final VarHandle ALLOCATIONSPINLOCK =
+ MhUtil.findVarHandle(
+ MethodHandles.lookup(), "allocationSpinLock", int.class);
+
}
diff --git a/src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java b/src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java
index 31b4cd6c6a613..edb2708934d90 100644
--- a/src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java
+++ b/src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 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
@@ -37,6 +37,7 @@
import java.util.function.Supplier;
import jdk.internal.javac.PreviewFeature;
import jdk.internal.misc.ThreadFlock;
+import jdk.internal.invoke.MhUtil;
/**
* A basic API for structured concurrency. {@code StructuredTaskScope} supports
@@ -990,13 +991,9 @@ public static final class ShutdownOnSuccess extends StructuredTaskScope {
private static final VarHandle FIRST_RESULT;
private static final VarHandle FIRST_EXCEPTION;
static {
- try {
- MethodHandles.Lookup l = MethodHandles.lookup();
- FIRST_RESULT = l.findVarHandle(ShutdownOnSuccess.class, "firstResult", Object.class);
- FIRST_EXCEPTION = l.findVarHandle(ShutdownOnSuccess.class, "firstException", Throwable.class);
- } catch (Exception e) {
- throw new ExceptionInInitializerError(e);
- }
+ MethodHandles.Lookup l = MethodHandles.lookup();
+ FIRST_RESULT = MhUtil.findVarHandle(l, "firstResult", Object.class);
+ FIRST_EXCEPTION = MhUtil.findVarHandle(l, "firstException", Throwable.class);
}
private volatile Object firstResult;
private volatile Throwable firstException;
@@ -1177,15 +1174,8 @@ public T result(Function esf) thro
*/
@PreviewFeature(feature = PreviewFeature.Feature.STRUCTURED_CONCURRENCY)
public static final class ShutdownOnFailure extends StructuredTaskScope