From 865fa604f89e5c0d609986f1d104061f3985dd18 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 8 Nov 2023 01:01:12 +0000 Subject: [PATCH 1/6] 8273831: PrintServiceLookup spawns 2 threads in the current classloader, getting orphaned Backport-of: 687567822a5380fb7d8c5b54ae548b2a5c848187 --- .../sun/print/PrintServiceLookupProvider.java | 20 +++-- .../sun/print/PrintServiceLookupProvider.java | 29 +++++-- .../FlushCustomClassLoader.java | 84 +++++++++++++++++++ 3 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java diff --git a/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java b/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java index eeff669dfce..876913553af 100644 --- a/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java +++ b/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java @@ -26,10 +26,8 @@ package sun.print; import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.IOException; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Vector; import java.security.AccessController; @@ -54,6 +52,8 @@ import java.net.URL; import java.nio.file.Files; +import sun.awt.util.ThreadGroupUtils; + /* * Remind: This class uses solaris commands. We also need a linux * version @@ -204,14 +204,18 @@ static int getBSDCommandIndex() { return BSD_LPD; } - + @SuppressWarnings("removal") public PrintServiceLookupProvider() { // start the printer listener thread if (pollServices) { - Thread thr = new Thread(null, new PrinterChangeListener(), - "PrinterListener", 0, false); - thr.setDaemon(true); - thr.start(); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(), + new PrinterChangeListener(), + "PrinterListener", 0, false); + thr.setContextClassLoader(null); + thr.setDaemon(true); + return thr; + }).start(); IPPPrintService.debug_println(debugPrefix+"polling turned on"); } } diff --git a/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java b/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java index 1d76ebae479..28055c1afec 100644 --- a/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java +++ b/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java @@ -25,6 +25,8 @@ package sun.print; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import javax.print.DocFlavor; @@ -41,6 +43,8 @@ import javax.print.attribute.PrintServiceAttributeSet; import javax.print.attribute.standard.PrinterName; +import sun.awt.util.ThreadGroupUtils; + public class PrintServiceLookupProvider extends PrintServiceLookup { private PrintService defaultPrintService; @@ -81,22 +85,31 @@ public static PrintServiceLookupProvider getWin32PrintLUS() { return win32PrintLUS; } + @SuppressWarnings("removal") public PrintServiceLookupProvider() { if (win32PrintLUS == null) { win32PrintLUS = this; // start the local printer listener thread - Thread thr = new Thread(null, new PrinterChangeListener(), - "PrinterListener", 0, false); - thr.setDaemon(true); - thr.start(); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(), + new PrinterChangeListener(), + "PrinterListener", 0, false); + thr.setContextClassLoader(null); + thr.setDaemon(true); + return thr; + }).start(); // start the remote printer listener thread - Thread remThr = new Thread(null, new RemotePrinterChangeListener(), - "RemotePrinterListener", 0, false); - remThr.setDaemon(true); - remThr.start(); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(), + new RemotePrinterChangeListener(), + "RemotePrinterListener", 0, false); + thr.setContextClassLoader(null); + thr.setDaemon(true); + return thr; + }).start(); } /* else condition ought to never happen! */ } diff --git a/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java new file mode 100644 index 00000000000..6e0a25a69d0 --- /dev/null +++ b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java @@ -0,0 +1,84 @@ +/* + * Copyright Amazon.com Inc. 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.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.net.URL; +import java.net.URLClassLoader; + +import javax.print.DocFlavor; +import javax.print.PrintServiceLookup; + +/** + * @test + * @bug 8273831 + * @summary Tests custom class loader cleanup + */ +public final class FlushCustomClassLoader { + + public static void main(String[] args) throws Exception { + Reference loader = getLoader("testMethod"); + + int attempt = 0; + while (loader.get() != null) { + if (++attempt > 10) { + throw new RuntimeException("Too many attempts: " + attempt); + } + System.gc(); + Thread.sleep(1000); + System.out.println("Not freed, attempt: " + attempt); + } + } + + public static void testMethod() { + DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; + PrintServiceLookup.lookupPrintServices(flavor, null); + } + + private static Reference getLoader(String m) throws Exception { + /* + * The print services are stored per the AppContext, and each AppContext + * caches the "current" class loader during creation. + * see javax.print.PrintServiceLookup. + * + * To prevent AppContext from cache our test loader we force AppContext + * creation early by the invokeAndWait. + * The "EventQueue.invokeAndWait(() -> {});" can be removed when the + * AppContext usage will be deleted in the PrintServiceLookup + */ + EventQueue.invokeAndWait(() -> {}); + + URL url = FlushCustomClassLoader.class.getProtectionDomain() + .getCodeSource().getLocation(); + URLClassLoader loader = new URLClassLoader(new URL[]{url}, null); + + Thread ct = Thread.currentThread(); + ct.setContextClassLoader(loader); + Class cls = Class.forName("FlushCustomClassLoader", true, loader); + cls.getDeclaredMethod(m).invoke(null); + ct.setContextClassLoader(null); + loader.close(); + return new WeakReference<>(loader); + } +} From 205e72d93a27adf6832ed2a3b5efdc7e2b064d81 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 8 Nov 2023 05:40:09 +0000 Subject: [PATCH 2/6] 8276819: javax/print/PrintServiceLookup/FlushCustomClassLoader.java fails to free Backport-of: 7c2c58587d4eda5523331eae45e7d897252dc097 --- .../PrintServiceLookup/FlushCustomClassLoader.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java index 6e0a25a69d0..4ec95fb7535 100644 --- a/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java +++ b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java @@ -34,6 +34,9 @@ * @test * @bug 8273831 * @summary Tests custom class loader cleanup + * @library /javax/swing/regtesthelpers + * @build Util + * @run main/timeout=60/othervm -mx32m FlushCustomClassLoader */ public final class FlushCustomClassLoader { @@ -42,12 +45,8 @@ public static void main(String[] args) throws Exception { int attempt = 0; while (loader.get() != null) { - if (++attempt > 10) { - throw new RuntimeException("Too many attempts: " + attempt); - } - System.gc(); - Thread.sleep(1000); - System.out.println("Not freed, attempt: " + attempt); + Util.generateOOME(); + System.out.println("Not freed, attempt: " + attempt++); } } From c996b6fc7c07dc53aafb6dab8e17c9c7a8cea4cd Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Wed, 8 Nov 2023 20:53:16 +0000 Subject: [PATCH 3/6] 8316461: Fix: make test outputs TEST SUCCESS after unsuccessful exit Backport-of: e30e3564420c631f08ac3d613ab91c93227a00b3 --- make/RunTests.gmk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/make/RunTests.gmk b/make/RunTests.gmk index ebc96272d66..9a0eb11d040 100644 --- a/make/RunTests.gmk +++ b/make/RunTests.gmk @@ -841,8 +841,9 @@ define SetupRunJtregTestBody endif endif - clean-workdir-$1: + clean-outputdirs-$1: $$(RM) -r $$($1_TEST_SUPPORT_DIR) + $$(RM) -r $$($1_TEST_RESULTS_DIR) $1_COMMAND_LINE := \ $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \ @@ -887,7 +888,7 @@ define SetupRunJtregTestBody done endif - run-test-$1: pre-run-test clean-workdir-$1 + run-test-$1: pre-run-test clean-outputdirs-$1 $$(call LogWarn) $$(call LogWarn, Running test '$$($1_TEST)') $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR) \ @@ -924,9 +925,9 @@ define SetupRunJtregTestBody $$(eval $1_TOTAL := 1) \ ) - $1: run-test-$1 parse-test-$1 clean-workdir-$1 + $1: run-test-$1 parse-test-$1 clean-outputdirs-$1 - TARGETS += $1 run-test-$1 parse-test-$1 clean-workdir-$1 + TARGETS += $1 run-test-$1 parse-test-$1 clean-outputdirs-$1 TEST_TARGETS += parse-test-$1 endef From 0077619ded7b843e299d0a613c00e5dcf4fd8a2e Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Thu, 9 Nov 2023 14:55:41 +0000 Subject: [PATCH 4/6] 8317374: Add Let's Encrypt ISRG Root X2 Reviewed-by: mdoerr Backport-of: e6f46a43268808d0cbbb3bb93c73aa8e4cbfad83 --- make/data/cacerts/letsencryptisrgx2 | 21 +++++++++++++++++++ .../certification/CAInterop.java | 14 ++++++++++++- .../security/lib/cacerts/VerifyCACerts.java | 8 ++++--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 make/data/cacerts/letsencryptisrgx2 diff --git a/make/data/cacerts/letsencryptisrgx2 b/make/data/cacerts/letsencryptisrgx2 new file mode 100644 index 00000000000..455822e13a8 --- /dev/null +++ b/make/data/cacerts/letsencryptisrgx2 @@ -0,0 +1,21 @@ +Owner: CN=ISRG Root X2, O=Internet Security Research Group, C=US +Issuer: CN=ISRG Root X2, O=Internet Security Research Group, C=US +Serial number: 41d29dd172eaeea780c12c6ce92f8752 +Valid from: Fri Sep 04 00:00:00 GMT 2020 until: Mon Sep 17 16:00:00 GMT 2040 +Signature algorithm name: SHA384withECDSA +Subject Public Key Algorithm: 384-bit EC (secp384r1) key +Version: 3 +-----BEGIN CERTIFICATE----- +MIICGzCCAaGgAwIBAgIQQdKd0XLq7qeAwSxs6S+HUjAKBggqhkjOPQQDAzBPMQsw +CQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2gg +R3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMjAeFw0yMDA5MDQwMDAwMDBaFw00 +MDA5MTcxNjAwMDBaME8xCzAJBgNVBAYTAlVTMSkwJwYDVQQKEyBJbnRlcm5ldCBT +ZWN1cml0eSBSZXNlYXJjaCBHcm91cDEVMBMGA1UEAxMMSVNSRyBSb290IFgyMHYw +EAYHKoZIzj0CAQYFK4EEACIDYgAEzZvVn4CDCuwJSvMWSj5cz3es3mcFDR0HttwW ++1qLFNvicWDEukWVEYmO6gbf9yoWHKS5xcUy4APgHoIYOIvXRdgKam7mAHf7AlF9 +ItgKbppbd9/w+kHsOdx1ymgHDB/qo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0T +AQH/BAUwAwEB/zAdBgNVHQ4EFgQUfEKWrt5LSDv6kviejM9ti6lyN5UwCgYIKoZI +zj0EAwMDaAAwZQIwe3lORlCEwkSHRhtFcP9Ymd70/aTSVaYgLXTWNLxBo1BfASdW +tL4ndQavEi51mI38AjEAi/V3bNTIZargCyzuFJ0nN6T5U6VR5CmD1/iQMVtCnwr1 +/q4AaOeMSQ+2b1tbFfLn +-----END CERTIFICATE----- diff --git a/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java b/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java index dbdcb810c47..a890040e3a1 100644 --- a/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java +++ b/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java @@ -136,12 +136,21 @@ /* * @test id=letsencryptisrgx1 * @bug 8189131 - * @summary Interoperability tests with Let's Encrypt CA + * @summary Interoperability tests with Let's Encrypt ISRG Root X1 CA * @library /test/lib * @build jtreg.SkippedException ValidatePathWithURL CAInterop * @run main/othervm -Djava.security.debug=certpath,ocsp CAInterop letsencryptisrgx1 DEFAULT */ +/* + * @test id=letsencryptisrgx2 + * @bug 8317374 + * @summary Interoperability tests with Let's Encrypt ISRG Root X2 CA + * @library /test/lib + * @build jtreg.SkippedException ValidatePathWithURL CAInterop + * @run main/othervm -Djava.security.debug=certpath,ocsp CAInterop letsencryptisrgx2 DEFAULT + */ + /* * @test id=globalsignrootcar6 * @bug 8216577 @@ -455,6 +464,9 @@ private CATestURLs getTestURLs(String alias) { case "letsencryptisrgx1" -> new CATestURLs("https://valid-isrgrootx1.letsencrypt.org", "https://revoked-isrgrootx1.letsencrypt.org"); + case "letsencryptisrgx2" -> + new CATestURLs("https://valid-isrgrootx2.letsencrypt.org", + "https://revoked-isrgrootx2.letsencrypt.org"); case "globalsignrootcar6" -> new CATestURLs("https://valid.r6.roots.globalsign.com", diff --git a/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java b/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java index f8d8be1f425..5084c77e25c 100644 --- a/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java +++ b/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java @@ -28,7 +28,7 @@ * 8209452 8209506 8210432 8195793 8216577 8222089 8222133 8222137 8222136 * 8223499 8225392 8232019 8234245 8233223 8225068 8225069 8243321 8243320 * 8243559 8225072 8258630 8259312 8256421 8225081 8225082 8225083 8245654 - * 8305975 8304760 8307134 8295894 8314960 8317373 + * 8305975 8304760 8307134 8295894 8314960 8317373 8317374 * @summary Check root CA entries in cacerts file */ import java.io.ByteArrayInputStream; @@ -47,12 +47,12 @@ public class VerifyCACerts { + File.separator + "security" + File.separator + "cacerts"; // The numbers of certs now. - private static final int COUNT = 98; + private static final int COUNT = 99; // SHA-256 of cacerts, can be generated with // shasum -a 256 cacerts | sed -e 's/../&:/g' | tr '[:lower:]' '[:upper:]' | cut -c1-95 private static final String CHECKSUM - = "63:A7:1F:4F:8E:4B:A1:04:DE:BB:EC:2E:31:35:5B:5A:19:D4:B1:C0:59:62:B1:13:65:C3:AE:C7:DB:78:9A:1E"; + = "DA:61:45:1C:93:F3:6A:30:24:68:C6:72:BC:C5:E6:E4:E3:BA:6A:AE:36:29:7B:45:53:B7:10:53:52:7D:7E:A5"; // Hex formatter to upper case with ":" delimiter private static final HexFormat HEX = HexFormat.ofDelimiter(":").withUpperCase(); @@ -146,6 +146,8 @@ public class VerifyCACerts { "5D:56:49:9B:E4:D2:E0:8B:CF:CA:D0:8A:3E:38:72:3D:50:50:3B:DE:70:69:48:E4:2F:55:60:30:19:E5:28:AE"); put("letsencryptisrgx1 [jdk]", "96:BC:EC:06:26:49:76:F3:74:60:77:9A:CF:28:C5:A7:CF:E8:A3:C0:AA:E1:1A:8F:FC:EE:05:C0:BD:DF:08:C6"); + put("letsencryptisrgx2 [jdk]", + "69:72:9B:8E:15:A8:6E:FC:17:7A:57:AF:B7:17:1D:FC:64:AD:D2:8C:2F:CA:8C:F1:50:7E:34:45:3C:CB:14:70"); put("luxtrustglobalrootca [jdk]", "A1:B2:DB:EB:64:E7:06:C6:16:9E:3C:41:18:B2:3B:AA:09:01:8A:84:27:66:6D:8B:F0:E2:88:91:EC:05:19:50"); put("quovadisrootca [jdk]", From a37a9bcf6f4dcde3ab6c2af17530f22754b25908 Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Fri, 10 Nov 2023 15:18:56 +0000 Subject: [PATCH 5/6] 8312126: NullPointerException in CertStore.getCRLs after 8297955 Backport-of: 3c743cfea00692d0b938cb1cbde936084eecf369 --- .../security/provider/certpath/ldap/LDAPCertStoreImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/java.naming/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreImpl.java b/src/java.naming/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreImpl.java index caff5e76104..39a787bf4fb 100644 --- a/src/java.naming/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreImpl.java +++ b/src/java.naming/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreImpl.java @@ -779,9 +779,13 @@ synchronized Collection getCRLs(X509CRLSelector xsel, } catch (IllegalArgumentException e) { continue; } - } else { + } else if (nameObject instanceof String) { issuerName = (String)nameObject; + } else { + throw new CertStoreException( + "unrecognized issuerName: must be String or byte[]"); } + // If all we want is CA certs, try to get the (probably shorter) ARL Collection entryCRLs = Collections.emptySet(); if (certChecking == null || certChecking.getBasicConstraints() != -1) { From 55b4c123bd331f70806bc4017a99bb11d2d59355 Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Mon, 13 Nov 2023 22:03:24 +0000 Subject: [PATCH 6/6] 8268433: serviceability/dcmd/framework/VMVersionTest.java fails with Unable to send object throw not established PipeIO Listener Thread connection Backport-of: 280f2d57d1f78b3d15dd98e726267a100eb0b5db --- test/hotspot/jtreg/ProblemList-zgc.txt | 4 ---- .../serviceability/dcmd/framework/TestProcessLauncher.java | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/hotspot/jtreg/ProblemList-zgc.txt b/test/hotspot/jtreg/ProblemList-zgc.txt index d81f604ca9b..0a96a797d41 100644 --- a/test/hotspot/jtreg/ProblemList-zgc.txt +++ b/test/hotspot/jtreg/ProblemList-zgc.txt @@ -44,7 +44,3 @@ serviceability/sa/TestJmapCoreMetaspace.java 8268722,8268636 serviceability/sa/TestJhsdbJstackMixed.java 8248912 generic-all serviceability/sa/ClhsdbPstack.java#id0 8248912 generic-all serviceability/sa/ClhsdbPstack.java#id1 8248912 generic-all - -serviceability/dcmd/framework/HelpTest.java 8268433 windows-x64 -serviceability/dcmd/framework/InvalidCommandTest.java 8268433 windows-x64 -serviceability/dcmd/framework/VMVersionTest.java 8268433 windows-x64 diff --git a/test/hotspot/jtreg/serviceability/dcmd/framework/TestProcessLauncher.java b/test/hotspot/jtreg/serviceability/dcmd/framework/TestProcessLauncher.java index 8953c8586dc..ec41c8b10de 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/framework/TestProcessLauncher.java +++ b/test/hotspot/jtreg/serviceability/dcmd/framework/TestProcessLauncher.java @@ -77,7 +77,11 @@ public Process launch() { public void quit() { if (pipe != null) { - pipe.println("quit"); + if (pipe.isConnected()) { + pipe.println("quit"); + } else { + System.out.println("WARNING: IOPipe is not connected"); + } } }