From 48d6fef3ea94f8c6fa1485385493186cdf2e8a6d Mon Sep 17 00:00:00 2001 From: Saravana Kumar Vijayasekaran Date: Thu, 29 Jul 2021 12:22:42 +0000 Subject: [PATCH 001/253] 8271463: Updating RE Configs for Upcoming CPU Release 17.0.2 on master branch for jdk17u-cpu and jdk17u-cpu-open repos. Reviewed-by: vaibhav, ssahoo, coffeys --- make/conf/version-numbers.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make/conf/version-numbers.conf b/make/conf/version-numbers.conf index 5e967cae3fa..6cf6b4ec5b6 100644 --- a/make/conf/version-numbers.conf +++ b/make/conf/version-numbers.conf @@ -28,12 +28,12 @@ DEFAULT_VERSION_FEATURE=17 DEFAULT_VERSION_INTERIM=0 -DEFAULT_VERSION_UPDATE=1 +DEFAULT_VERSION_UPDATE=2 DEFAULT_VERSION_PATCH=0 DEFAULT_VERSION_EXTRA1=0 DEFAULT_VERSION_EXTRA2=0 DEFAULT_VERSION_EXTRA3=0 -DEFAULT_VERSION_DATE=2021-10-19 +DEFAULT_VERSION_DATE=2022-01-18 DEFAULT_VERSION_CLASSFILE_MAJOR=61 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`" DEFAULT_VERSION_CLASSFILE_MINOR=0 DEFAULT_VERSION_DOCS_API_SINCE=11 From d26ecc330c7a3d28e215710927c511d98c09ce34 Mon Sep 17 00:00:00 2001 From: Jamsheed Mohammed C M Date: Tue, 3 Aug 2021 06:57:31 +0000 Subject: [PATCH 002/253] 8269624: Enhance method selection support Backport-of: acd1fa5d8fabd424ec3b125b56e5ca482b25f2d9 --- src/hotspot/share/code/dependencies.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/hotspot/share/code/dependencies.cpp b/src/hotspot/share/code/dependencies.cpp index f3ba73109da..87e01ce4e77 100644 --- a/src/hotspot/share/code/dependencies.cpp +++ b/src/hotspot/share/code/dependencies.cpp @@ -1835,6 +1835,26 @@ Klass* Dependencies::find_witness_AME(InstanceKlass* ctxk, Method* m, KlassDepCh return NULL; } +// This function is used by find_unique_concrete_method(non vtable based) +// to check whether subtype method overrides the base method. +static bool overrides(Method* sub_m, Method* base_m) { + assert(base_m != NULL, "base method should be non null"); + if (sub_m == NULL) { + return false; + } + /** + * If base_m is public or protected then sub_m always overrides. + * If base_m is !public, !protected and !private (i.e. base_m is package private) + * then sub_m should be in the same package as that of base_m. + * For package private base_m this is conservative approach as it allows only subset of all allowed cases in + * the jvm specification. + **/ + if (base_m->is_public() || base_m->is_protected() || + base_m->method_holder()->is_same_class_package(sub_m->method_holder())) { + return true; + } + return false; +} // Find the set of all non-abstract methods under ctxk that match m. // (The method m must be defined or inherited in ctxk.) @@ -1872,6 +1892,9 @@ Method* Dependencies::find_unique_concrete_method(InstanceKlass* ctxk, Method* m } else if (Dependencies::find_witness_AME(ctxk, fm) != NULL) { // Found a concrete subtype which does not override abstract root method. return NULL; + } else if (!overrides(fm, m)) { + // Found method doesn't override abstract root method. + return NULL; } assert(Dependencies::is_concrete_root_method(fm, ctxk) == Dependencies::is_concrete_method(m, ctxk), "mismatch"); #ifndef PRODUCT From 13937b2a4a498044cee4197438c59d711cd037de Mon Sep 17 00:00:00 2001 From: Jamsheed Mohammed C M Date: Tue, 3 Aug 2021 11:04:13 +0000 Subject: [PATCH 003/253] 8271723: Unproblemlist runtime/InvocationTests/invokevirtualTests.java Backport-of: 058379cdf91fd46793744a6bd7450c669f3bf787 --- test/hotspot/jtreg/ProblemList.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index aa8a556c7be..f4615e8bc8e 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -91,7 +91,6 @@ gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java 8241293 macosx-x64 runtime/cds/appcds/jigsaw/modulepath/ModulePathAndCP_JFR.java 8253437 windows-x64 runtime/cds/DeterministicDump.java 8253495 generic-all -runtime/InvocationTests/invokevirtualTests.java 8271125 generic-all runtime/jni/terminatedThread/TestTerminatedThread.java 8219652 aix-ppc64 runtime/os/TestTracePageSizes.java#no-options 8267460 linux-aarch64 runtime/os/TestTracePageSizes.java#explicit-large-page-size 8267460 linux-aarch64 From a93833d88f85eb693077ac3d4fdfdf67fc1e572c Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Wed, 4 Aug 2021 11:01:55 +0000 Subject: [PATCH 004/253] 8270893: IndexOutOfBoundsException while reading large TIFF file Backport-of: efcdcc7fb792c77aef1da69b1fcc652b401115f7 --- .../com/sun/imageio/plugins/tiff/TIFFIFD.java | 14 ++-- .../plugins/tiff/LargeTIFFTagTest.java | 76 +++++++++++++++++++ 2 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 test/jdk/javax/imageio/plugins/tiff/LargeTIFFTagTest.java diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java index 49f899c09a2..5c0334abbef 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2021, 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 @@ -319,7 +319,7 @@ private static int readFieldValue(ImageInputStream stream, while (bytesToRead != 0) { int sz = Math.min(bytesToRead, UNIT_SIZE); byte[] unit = new byte[sz]; - stream.readFully(unit, bytesRead, sz); + stream.readFully(unit, 0, sz); bufs.add(unit); bytesRead += sz; bytesToRead -= sz; @@ -455,7 +455,7 @@ private static int readFieldValue(ImageInputStream stream, while (shortsToRead != 0) { int sz = Math.min(shortsToRead, SSHORT_TILE_SIZE); short[] unit = new short[sz]; - stream.readFully(unit, shortsRead, sz); + stream.readFully(unit, 0, sz); bufs.add(unit); shortsRead += sz; shortsToRead -= sz; @@ -486,7 +486,7 @@ private static int readFieldValue(ImageInputStream stream, while (intsToRead != 0) { int sz = Math.min(intsToRead, INT_TILE_SIZE); int[] unit = new int[sz]; - stream.readFully(unit, intsToRead, sz); + stream.readFully(unit, 0, sz); bufs.add(unit); intsRead += sz; intsToRead -= sz; @@ -518,7 +518,7 @@ private static int readFieldValue(ImageInputStream stream, while (srationalsToRead != 0) { int sz = Math.min(srationalsToRead, SRATIONAL_TILE_SIZE); int[] unit = new int[sz * 2]; - stream.readFully(unit, (srationalsToRead * 2), (sz * 2)); + stream.readFully(unit, 0, (sz * 2)); bufs.add(unit); srationalsRead += sz; srationalsToRead -= sz; @@ -552,7 +552,7 @@ private static int readFieldValue(ImageInputStream stream, while (floatsToRead != 0) { int sz = Math.min(floatsToRead, FLOAT_TILE_SIZE); float[] unit = new float[sz]; - stream.readFully(unit, floatsToRead, sz); + stream.readFully(unit, 0, sz); bufs.add(unit); floatsRead += sz; floatsToRead -= sz; @@ -583,7 +583,7 @@ private static int readFieldValue(ImageInputStream stream, while (doublesToRead != 0) { int sz = Math.min(doublesToRead, DOUBLE_TILE_SIZE); double[] unit = new double[sz]; - stream.readFully(unit, doublesToRead, sz); + stream.readFully(unit, 0, sz); bufs.add(unit); doublesRead += sz; doublesToRead -= sz; diff --git a/test/jdk/javax/imageio/plugins/tiff/LargeTIFFTagTest.java b/test/jdk/javax/imageio/plugins/tiff/LargeTIFFTagTest.java new file mode 100644 index 00000000000..dad0dd462ff --- /dev/null +++ b/test/jdk/javax/imageio/plugins/tiff/LargeTIFFTagTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021, 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 8270893 + * @summary Ensure that we don't throw IndexOutOfBoundsException when + * we read TIFF tag with content more than 1024000 bytes + * @run main LargeTIFFTagTest + */ + +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.stream.ImageInputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Iterator; + +public class LargeTIFFTagTest { + public static void main(String[] args) throws IOException { + // TIFF stream length to hold 22 bytes of TIFF header + // plus 1024002 bytes of data in one TIFFTag + int length = 1024024; + byte[] ba = new byte[length]; + // Little endian TIFF stream with header and only one + // IFD entry at offset 22 having count value 1024002. + byte[] header = new byte[] { (byte)0x49, (byte) 0x49, + (byte)0x2a, (byte)0x00, (byte)0x08, (byte)0x00, + (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, + (byte)0x73, (byte)0x87, (byte)0x07, (byte)0x00, + (byte)0x02, (byte)0xA0, (byte)0x0F, (byte)0x00, + (byte)0x16, (byte)0x00, (byte)0x00, (byte)0x00}; + // copy first 22 bytes of TIFF header to byte array + for (int i = 0; i < 22; i++) { + ba[i] = header[i]; + } + ByteArrayInputStream bais = new ByteArrayInputStream(ba); + ImageInputStream stream = ImageIO.createImageInputStream(bais); + Iterator readers = ImageIO.getImageReaders(stream); + + if(readers.hasNext()) { + ImageReader reader = readers.next(); + reader.setInput(stream); + try { + reader.readAll(0, null); + } catch (IllegalArgumentException e) { + // do nothing we expect IllegalArgumentException but we + // should not throw IndexOutOfBoundsException. + System.out.println(e.toString()); + System.out.println("Caught IllegalArgumentException ignore it"); + } + } else { + throw new RuntimeException("No readers available for TIFF format"); + } + } +} From 84aad735a199cc60ad3e0d46ccba4cf1ee94e440 Mon Sep 17 00:00:00 2001 From: Ravi Reddy Date: Wed, 4 Aug 2021 17:03:57 +0000 Subject: [PATCH 005/253] 8265776: Improve Stream handling for SSL Backport-of: 345c6d3045e4e37e4f8dca30f5b1104c5eb403a9 --- .../share/classes/sun/net/httpserver/SSLStreams.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/SSLStreams.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/SSLStreams.java index 6d4ebaf31b8..7433986f1e7 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/SSLStreams.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/SSLStreams.java @@ -515,7 +515,7 @@ public int read (byte[] buf, int off, int len) throws IOException { throw new IOException ("SSL stream is closed"); } if (eof) { - return 0; + return -1; } int available=0; if (!needData) { @@ -528,7 +528,7 @@ public int read (byte[] buf, int off, int len) throws IOException { bbuf = r.buf== bbuf? bbuf: r.buf; if ((available=bbuf.remaining()) == 0) { eof = true; - return 0; + return -1; } else { needData = false; } @@ -579,7 +579,7 @@ public long skip (long s) throws IOException { /** * close the SSL connection. All data must have been consumed * before this is called. Otherwise an exception will be thrown. - * [Note. May need to revisit this. not quite the normal close() symantics + * [Note. May need to revisit this. not quite the normal close() semantics */ public void close () throws IOException { eof = true; @@ -593,8 +593,11 @@ public int read (byte[] buf) throws IOException { byte single[] = new byte [1]; public int read () throws IOException { + if (eof) { + return -1; + } int n = read (single, 0, 1); - if (n == 0) { + if (n <= 0) { return -1; } else { return single[0] & 0xFF; From 53866eb2af3a2de4ac1a7d9ee33e0c163b1c7062 Mon Sep 17 00:00:00 2001 From: Prasadrao Koppula Date: Thu, 5 Aug 2021 09:10:04 +0000 Subject: [PATCH 006/253] 8266689: More Constrained Delegation Backport-of: 723438b38868c373d1b8d7e6db576835be392932 --- .../sun/security/jgss/krb5/SubjectComber.java | 160 ++++++++++-------- .../security/auth/module/Krb5LoginModule.java | 8 +- 2 files changed, 91 insertions(+), 77 deletions(-) diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/SubjectComber.java b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/SubjectComber.java index 1bc1bf7d629..964f1eac80a 100644 --- a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/SubjectComber.java +++ b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/SubjectComber.java @@ -25,6 +25,7 @@ package sun.security.jgss.krb5; +import sun.security.krb5.JavaxSecurityAuthKerberosAccess; import sun.security.krb5.KerberosSecrets; import javax.security.auth.kerberos.KerberosTicket; @@ -150,83 +151,58 @@ private static Object findAux(Subject subject, String serverPrincipal, Iterator iterator = pcs.iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); - if (obj instanceof KerberosTicket) { - @SuppressWarnings("unchecked") - KerberosTicket ticket = (KerberosTicket)obj; - if (DEBUG) { - System.out.println("Found ticket for " - + ticket.getClient() - + " to go to " - + ticket.getServer() - + " expiring on " - + ticket.getEndTime()); - } - if (!ticket.isCurrent()) { - // let us remove the ticket from the Subject - // Note that both TGT and service ticket will be - // removed upon expiration - if (!subject.isReadOnly()) { - iterator.remove(); - try { - ticket.destroy(); - if (DEBUG) { - System.out.println("Removed and destroyed " - + "the expired Ticket \n" - + ticket); - - } - } catch (DestroyFailedException dfe) { - if (DEBUG) { - System.out.println("Expired ticket not" + - " detroyed successfully. " + dfe); - } - } + if (!(obj instanceof KerberosTicket)) { + continue; + } + @SuppressWarnings("unchecked") + KerberosTicket ticket = (KerberosTicket)obj; + if (DEBUG) { + System.out.println("Found ticket for " + + ticket.getClient() + + " to go to " + + ticket.getServer() + + " expiring on " + + ticket.getEndTime()); + } + if (!ticket.isCurrent()) { + // let us remove the ticket from the Subject + // Note that both TGT and service ticket will be + // removed upon expiration + if (!subject.isReadOnly()) { + iterator.remove(); + try { + ticket.destroy(); + if (DEBUG) { + System.out.println("Removed and destroyed " + + "the expired Ticket \n" + + ticket); + } + } catch (DestroyFailedException dfe) { + if (DEBUG) { + System.out.println("Expired ticket not" + + " detroyed successfully. " + dfe); + } } - } else { - KerberosPrincipal serverAlias = KerberosSecrets - .getJavaxSecurityAuthKerberosAccess() - .kerberosTicketGetServerAlias(ticket); - if (serverPrincipal == null || - ticket.getServer().getName().equals(serverPrincipal) || - (serverAlias != null && - serverPrincipal.equals( - serverAlias.getName()))) { - KerberosPrincipal clientAlias = KerberosSecrets - .getJavaxSecurityAuthKerberosAccess() - .kerberosTicketGetClientAlias(ticket); - if (clientPrincipal == null || - clientPrincipal.equals( - ticket.getClient().getName()) || - (clientAlias != null && - clientPrincipal.equals( - clientAlias.getName()))) { - if (oneOnly) { - return ticket; - } else { - // Record names so that tickets will - // all belong to same principals - if (clientPrincipal == null) { - if (clientAlias == null) { - clientPrincipal = - ticket.getClient().getName(); - } else { - clientPrincipal = - clientAlias.getName(); - } - } - if (serverPrincipal == null) { - if (serverAlias == null) { - serverPrincipal = - ticket.getServer().getName(); - } else { - serverPrincipal = - serverAlias.getName(); - } - } - answer.add(credClass.cast(ticket)); - } + } + continue; + } + String serverMatch = findServerMatch(serverPrincipal, ticket); + if (serverMatch != null) { + String clientMatch = findClientMatch(clientPrincipal, ticket); + if (clientMatch != null) { + if (oneOnly) { + return ticket; + } else { + // Record names so that tickets will + // all belong to same principals + if (clientPrincipal == null) { + clientPrincipal = clientMatch; + } + if (serverPrincipal == null) { + serverPrincipal = serverMatch; } + answer.add(credClass.cast(ticket)); } } } @@ -236,4 +212,40 @@ private static Object findAux(Subject subject, String serverPrincipal, return answer; } } + + private static String findServerMatch(String input, KerberosTicket ticket) { + KerberosPrincipal serverAlias = KerberosSecrets + .getJavaxSecurityAuthKerberosAccess() + .kerberosTicketGetServerAlias(ticket); + if (input != null) { + return ((serverAlias != null && input.equals(serverAlias.getName())) || + input.equals(ticket.getServer().getName())) + ? input : null; + } else { + return serverAlias != null + ? serverAlias.getName() + : ticket.getServer().getName(); + } + } + + private static String findClientMatch(String input, KerberosTicket ticket) { + JavaxSecurityAuthKerberosAccess access = KerberosSecrets + .getJavaxSecurityAuthKerberosAccess(); + KerberosPrincipal clientAlias = access.kerberosTicketGetClientAlias(ticket); + KerberosTicket proxy = access.kerberosTicketGetProxy(ticket); + if (input != null) { + return ((clientAlias != null && input.equals(clientAlias.getName())) || + (proxy != null && input.equals(proxy.getClient().getName())) || + (proxy == null && input.equals(ticket.getClient().getName()))) + ? input : null; + } else { + if (clientAlias != null) { + return clientAlias.getName(); + } else if (proxy != null) { + return proxy.getClient().getName(); + } else { + return ticket.getClient().getName(); + } + } + } } diff --git a/src/jdk.security.auth/share/classes/com/sun/security/auth/module/Krb5LoginModule.java b/src/jdk.security.auth/share/classes/com/sun/security/auth/module/Krb5LoginModule.java index 2e42e73fff4..91d4b41be4d 100644 --- a/src/jdk.security.auth/share/classes/com/sun/security/auth/module/Krb5LoginModule.java +++ b/src/jdk.security.auth/share/classes/com/sun/security/auth/module/Krb5LoginModule.java @@ -663,9 +663,11 @@ private void attemptAuthentication(boolean getPasswdFromSharedState) } if (cred != null) { - // get the principal name from the ticket cache - if (principal == null) { - principal = cred.getClient(); + // get the principal name from the ticket cache + if (principal == null) { + principal = cred.getProxy() != null + ? cred.getProxy().getClient() + : cred.getClient(); } } if (debug) { From b7573f6d5ea67c7335722e6d52df3e93d487282b Mon Sep 17 00:00:00 2001 From: Prasadrao Koppula Date: Thu, 5 Aug 2021 09:45:24 +0000 Subject: [PATCH 007/253] 8266103: Better specified spec values Backport-of: 9bd20b57e1d79bd2bb386fb5df48e681fbbbd981 --- .../classes/javax/crypto/spec/IvParameterSpec.java | 11 +++++++---- .../classes/javax/crypto/spec/RC5ParameterSpec.java | 9 +++++++-- .../classes/javax/crypto/spec/SecretKeySpec.java | 9 ++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/java.base/share/classes/javax/crypto/spec/IvParameterSpec.java b/src/java.base/share/classes/javax/crypto/spec/IvParameterSpec.java index 243c848ff41..6a3d311eb14 100644 --- a/src/java.base/share/classes/javax/crypto/spec/IvParameterSpec.java +++ b/src/java.base/share/classes/javax/crypto/spec/IvParameterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -76,13 +76,16 @@ public IvParameterSpec(byte[] iv, int offset, int len) { if (iv == null) { throw new IllegalArgumentException("IV missing"); } - if (iv.length - offset < len) { - throw new IllegalArgumentException - ("IV buffer too short for given offset/length combination"); + if (offset < 0) { + throw new ArrayIndexOutOfBoundsException("offset is negative"); } if (len < 0) { throw new ArrayIndexOutOfBoundsException("len is negative"); } + if (iv.length - offset < len) { + throw new IllegalArgumentException + ("IV buffer too short for given offset/length combination"); + } this.iv = new byte[len]; System.arraycopy(iv, offset, this.iv, 0, len); } diff --git a/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java b/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java index 22d1c6a7c58..ced87331bce 100644 --- a/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java +++ b/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2021, 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 @@ -114,7 +114,12 @@ public RC5ParameterSpec(int version, int rounds, int wordSize, this.version = version; this.rounds = rounds; this.wordSize = wordSize; - if (iv == null) throw new IllegalArgumentException("IV missing"); + if (iv == null) { + throw new IllegalArgumentException("IV missing"); + } + if (offset < 0) { + throw new ArrayIndexOutOfBoundsException("offset is negative"); + } int blockSize = (wordSize / 8) * 2; if (iv.length - offset < blockSize) { throw new IllegalArgumentException("IV too short"); diff --git a/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java b/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java index de8245074d4..41d4acab748 100644 --- a/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java +++ b/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java @@ -157,13 +157,16 @@ public SecretKeySpec(byte[] key, int offset, int len, String algorithm) { if (key.length == 0) { throw new IllegalArgumentException("Empty key"); } - if (key.length-offset < len) { - throw new IllegalArgumentException - ("Invalid offset/length combination"); + if (offset < 0) { + throw new ArrayIndexOutOfBoundsException("offset is negative"); } if (len < 0) { throw new ArrayIndexOutOfBoundsException("len is negative"); } + if (key.length - offset < len) { + throw new IllegalArgumentException + ("Invalid offset/length combination"); + } this.key = new byte[len]; System.arraycopy(key, offset, this.key, 0, len); this.algorithm = algorithm; From 91ad1223906f54cea33ab23f2ffba537bc3ac9ef Mon Sep 17 00:00:00 2001 From: Prajwal Kumaraswamy Date: Thu, 5 Aug 2021 10:00:55 +0000 Subject: [PATCH 008/253] 8263314: Enhance XML Dsig modes Reviewed-by: coffeys, pkoppula Backport-of: fe318432e184c2df95d802212b4eb510d3729459 --- .../dsig/internal/dom/DOMURIDereferencer.java | 25 ++++++++++++++++--- .../xml/crypto/dsig/GenerationTests.java | 7 +++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMURIDereferencer.java b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMURIDereferencer.java index e6b88e7d4d2..6b728e236cb 100644 --- a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMURIDereferencer.java +++ b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMURIDereferencer.java @@ -37,6 +37,7 @@ import javax.xml.crypto.*; import javax.xml.crypto.dom.*; +import java.net.URI; /** * DOM-based implementation of URIDereferencer. @@ -70,9 +71,27 @@ public Data dereference(URIReference uriRef, XMLCryptoContext context) boolean secVal = Utils.secureValidation(context); - if (secVal && Policy.restrictReferenceUriScheme(uri)) { - throw new URIReferenceException( - "Uri " + uri + " is forbidden when secure validation is enabled"); + if (secVal) { + try { + if (Policy.restrictReferenceUriScheme(uri)) { + throw new URIReferenceException( + "URI " + uri + " is forbidden when secure validation is enabled"); + } + + if (uri != null && !uri.isEmpty() && uri.charAt(0) != '#' && URI.create(uri).getScheme() == null) { + // beseURI will be used to dereference a relative uri + try { + if (Policy.restrictReferenceUriScheme(baseURI)) { + throw new URIReferenceException( + "Base URI " + baseURI + " is forbidden when secure validation is enabled"); + } + } catch (IllegalArgumentException e) { // thrown by Policy.restrictReferenceUriScheme + throw new URIReferenceException("Invalid base URI " + baseURI); + } + } + } catch (IllegalArgumentException e) { // thrown by Policy.restrictReferenceUriScheme or URI.create + throw new URIReferenceException("Invalid URI " + uri); + } } // Check if same-document URI and already registered on the context diff --git a/test/jdk/javax/xml/crypto/dsig/GenerationTests.java b/test/jdk/javax/xml/crypto/dsig/GenerationTests.java index 3120dcc4333..5f1e217ab8b 100644 --- a/test/jdk/javax/xml/crypto/dsig/GenerationTests.java +++ b/test/jdk/javax/xml/crypto/dsig/GenerationTests.java @@ -1454,7 +1454,6 @@ private static void dumpDocument(Document doc, Writer w) throws Exception { DOMValidateContext dvc = new DOMValidateContext (ks, doc.getDocumentElement()); File f = new File(DATA_DIR); - dvc.setBaseURI(f.toURI().toString()); dvc.setURIDereferencer(httpUd); XMLSignature sig2 = fac.unmarshalXMLSignature(dvc); @@ -2195,6 +2194,12 @@ public Data dereference(final URIReference ref, XMLCryptoContext ctx) (DATA_DIR, uri.substring(uri.lastIndexOf('/')))); return new OctetStreamData(fis,ref.getURI(),ref.getType()); } catch (Exception e) { throw new URIReferenceException(e); } + } else if (uri.startsWith("certs/")) { + try { + FileInputStream fis = new FileInputStream(new File + (DATA_DIR, uri)); + return new OctetStreamData(fis,ref.getURI(),ref.getType()); + } catch (Exception e) { throw new URIReferenceException(e); } } // fallback on builtin deref From 97fa97d64ac1b43d400954c7a95d4e07c385e195 Mon Sep 17 00:00:00 2001 From: Evan Whelan Date: Thu, 5 Aug 2021 13:46:47 +0000 Subject: [PATCH 009/253] 8267712: Better LDAP reference processing Backport-of: 0d2a239cb4b7fdc88adb54eb66b36f5f5157418f --- src/java.naming/share/classes/com/sun/jndi/ldap/Obj.java | 8 +++++++- .../share/classes/com/sun/jndi/ldap/VersionHelper.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/Obj.java b/src/java.naming/share/classes/com/sun/jndi/ldap/Obj.java index 8ea0a5d7dee..5c4b9ab0f6c 100644 --- a/src/java.naming/share/classes/com/sun/jndi/ldap/Obj.java +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/Obj.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2021, 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 @@ -466,6 +466,12 @@ private static Reference decodeReference(Attributes attrs, // Empty content refAddrList.setElementAt(new StringRefAddr(type, null), posn); } else if (val.charAt(start) == separator) { + // Check if deserialization of binary RefAddr is allowed from + // 'javaReferenceAddress' LDAP attribute. + if (!VersionHelper.isSerialDataAllowed()) { + throw new NamingException("Object deserialization is not allowed"); + } + // Double separators indicate a non-StringRefAddr // Content is a Base64-encoded serialized RefAddr diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java b/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java index edb43f73e8b..4d7ce28a841 100644 --- a/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java @@ -82,7 +82,7 @@ static VersionHelper getVersionHelper() { /** * Returns true if deserialization of objects from 'javaSerializedData' - * LDAP attribute is allowed. + * and 'javaReferenceAddress' LDAP attributes is allowed. * * @return true if deserialization is allowed; false - otherwise */ From 40db0bde4c16b488896e4b4033c9023297508342 Mon Sep 17 00:00:00 2001 From: Sean Coffey Date: Mon, 9 Aug 2021 08:46:50 +0000 Subject: [PATCH 010/253] 8271730: Client authentication using RSASSA-PSS fails after correct certificate requests Backport-of: 5891fccf178797ef12e429637897d4149a7ae59a --- .../classes/sun/security/ssl/CertificateRequest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/sun/security/ssl/CertificateRequest.java b/src/java.base/share/classes/sun/security/ssl/CertificateRequest.java index 84b128b23a0..4def03c6785 100644 --- a/src/java.base/share/classes/sun/security/ssl/CertificateRequest.java +++ b/src/java.base/share/classes/sun/security/ssl/CertificateRequest.java @@ -752,7 +752,13 @@ private static SSLPossession choosePossession(HandshakeContext hc, } // Put the CR key type into a more friendly format for searching - List crKeyTypes = Arrays.asList(crm.getKeyTypes()); + List crKeyTypes = new ArrayList<>( + Arrays.asList(crm.getKeyTypes())); + // For TLS 1.2 only if RSA is a requested key type then we + // should also allow RSASSA-PSS. + if (crKeyTypes.contains("RSA")) { + crKeyTypes.add("RSASSA-PSS"); + } Collection checkedKeyTypes = new HashSet<>(); for (SignatureScheme ss : hc.peerRequestedCertSignSchemes) { From f9c7b4f5b0ce74209ae061a65c7ddf4fdfd13bf3 Mon Sep 17 00:00:00 2001 From: Harold Seigel Date: Thu, 12 Aug 2021 12:29:36 +0000 Subject: [PATCH 011/253] 8271968: Better canonical naming Backport-of: a716aacb662bb49aa5b1e805175196c29d8cb77a --- .../share/classfile/classFileParser.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index 0999d7dced7..052d013368a 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -3044,6 +3044,7 @@ static int inner_classes_jump_to_outer(const Array* inner_classes, int inner static bool inner_classes_check_loop_through_outer(const Array* inner_classes, int idx, const ConstantPool* cp, int length) { int slow = inner_classes->at(idx + InstanceKlass::inner_class_inner_class_info_offset); int fast = inner_classes->at(idx + InstanceKlass::inner_class_outer_class_info_offset); + while (fast != -1 && fast != 0) { if (slow != 0 && (cp->klass_name_at(slow) == cp->klass_name_at(fast))) { return true; // found a circularity @@ -3073,14 +3074,15 @@ bool ClassFileParser::check_inner_classes_circularity(const ConstantPool* cp, in for (int y = idx + InstanceKlass::inner_class_next_offset; y < length; y += InstanceKlass::inner_class_next_offset) { - // To maintain compatibility, throw an exception if duplicate inner classes - // entries are found. - guarantee_property((_inner_classes->at(idx) != _inner_classes->at(y) || - _inner_classes->at(idx+1) != _inner_classes->at(y+1) || - _inner_classes->at(idx+2) != _inner_classes->at(y+2) || - _inner_classes->at(idx+3) != _inner_classes->at(y+3)), - "Duplicate entry in InnerClasses attribute in class file %s", - CHECK_(true)); + // 4347400: make sure there's no duplicate entry in the classes array + if (_major_version >= JAVA_1_5_VERSION) { + guarantee_property((_inner_classes->at(idx) != _inner_classes->at(y) || + _inner_classes->at(idx+1) != _inner_classes->at(y+1) || + _inner_classes->at(idx+2) != _inner_classes->at(y+2) || + _inner_classes->at(idx+3) != _inner_classes->at(y+3)), + "Duplicate entry in InnerClasses attribute in class file %s", + CHECK_(true)); + } // Return true if there are two entries with the same inner_class_info_index. if (_inner_classes->at(y) == _inner_classes->at(idx)) { return true; @@ -3173,10 +3175,9 @@ u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStrea inner_classes->at_put(index++, inner_access_flags.as_short()); } - // 4347400: make sure there's no duplicate entry in the classes array - // Also, check for circular entries. + // Check for circular and duplicate entries. bool has_circularity = false; - if (_need_verify && _major_version >= JAVA_1_5_VERSION) { + if (_need_verify) { has_circularity = check_inner_classes_circularity(cp, length * 4, CHECK_0); if (has_circularity) { // If circularity check failed then ignore InnerClasses attribute. From 757afdc5d4a8ec009529d35e0492edba13747570 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Mon, 16 Aug 2021 19:15:40 +0000 Subject: [PATCH 012/253] 8270952: Improve TIFF file handling Backport-of: 4db9acd53f549cac1603c6c41566b16ee939c04b --- .../plugins/tiff/TIFFNullDecompressor.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFNullDecompressor.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFNullDecompressor.java index 6ffc1f0acb7..9b5a746eec1 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFNullDecompressor.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFNullDecompressor.java @@ -136,12 +136,7 @@ public void decodeRaw(byte[] b, int lastRow = activeSrcHeight - 1; for (int y = 0; y < activeSrcHeight; y++) { - int bytesRead = stream.read(b, dstOffset, activeBytesPerRow); - if (bytesRead < 0) { - throw new EOFException(); - } else if (bytesRead != activeBytesPerRow) { - break; - } + stream.readFully(b, dstOffset, activeBytesPerRow); dstOffset += scanlineStride; // Skip unneeded bytes (row suffix + row prefix). @@ -154,17 +149,10 @@ public void decodeRaw(byte[] b, stream.seek(offset); int bytesPerRow = (srcWidth*bitsPerPixel + 7)/8; if(bytesPerRow == scanlineStride) { - if (stream.read(b, dstOffset, bytesPerRow*srcHeight) < 0) { - throw new EOFException(); - } + stream.readFully(b, dstOffset, bytesPerRow*srcHeight); } else { for (int y = 0; y < srcHeight; y++) { - int bytesRead = stream.read(b, dstOffset, bytesPerRow); - if (bytesRead < 0) { - throw new EOFException(); - } else if (bytesRead != bytesPerRow) { - break; - } + stream.readFully(b, dstOffset, bytesPerRow); dstOffset += scanlineStride; } } From 48aa0ef109497304905f93a1c0acfc27f803bc9f Mon Sep 17 00:00:00 2001 From: Prajwal Kumaraswamy Date: Tue, 17 Aug 2021 08:17:18 +0000 Subject: [PATCH 013/253] 8269944: Better HTTP transport redux Backport-of: 0e123d6e0e50cdac714a001b9f67dfc7c1c2b293 --- .../sun/net/httpserver/FixedLengthInputStream.java | 3 +++ .../sun/net/httpserver/FixedLengthOutputStream.java | 3 +++ .../share/classes/sun/net/httpserver/Request.java | 6 ++++-- .../share/classes/sun/net/httpserver/ServerImpl.java | 9 +++++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthInputStream.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthInputStream.java index c875a1ab9b4..ac6fb7be005 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthInputStream.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthInputStream.java @@ -41,6 +41,9 @@ class FixedLengthInputStream extends LeftOverInputStream { FixedLengthInputStream (ExchangeImpl t, InputStream src, long len) { super (t, src); + if (len < 0) { + throw new IllegalArgumentException("Content-Length: " + len); + } this.remaining = len; } diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthOutputStream.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthOutputStream.java index 8b431645ceb..4935214c2e1 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthOutputStream.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthOutputStream.java @@ -47,6 +47,9 @@ class FixedLengthOutputStream extends FilterOutputStream FixedLengthOutputStream (ExchangeImpl t, OutputStream src, long len) { super (src); + if (len < 0) { + throw new IllegalArgumentException("Content-Length: " + len); + } this.t = t; this.remaining = len; } diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/Request.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/Request.java index e8d719f3a5a..03e2a9ee8f5 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/Request.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/Request.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2021, 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 @@ -206,7 +206,9 @@ Headers headers () throws IOException { "sun.net.httpserver.maxReqHeaders) exceeded, " + ServerConfig.getMaxReqHeaders() + "."); } - + if (k == null) { // Headers disallows null keys, use empty string + k = ""; // instead to represent invalid key + } hdrs.add (k,v); len = 0; } diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java index 9e5bcbf83ed..748dcfd4815 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java @@ -615,6 +615,11 @@ public void run () { headerValue = headers.getFirst("Content-Length"); if (headerValue != null) { clen = Long.parseLong(headerValue); + if (clen < 0) { + reject(Code.HTTP_BAD_REQUEST, requestLine, + "Illegal Content-Length value"); + return; + } } if (clen == 0) { requestCompleted(connection); @@ -937,7 +942,7 @@ static long getTimeMillis(long secs) { * Validates a RFC 7230 header-key. */ static boolean isValidHeaderKey(String token) { - if (token == null) return false; + if (token == null || token.isEmpty()) return false; boolean isValidChar; char[] chars = token.toCharArray(); @@ -950,6 +955,6 @@ static boolean isValidHeaderKey(String token) { return false; } } - return !token.isEmpty(); + return true; } } From 4dc0e9e2df5ffc3601a24514c5f78f2e8ffb18af Mon Sep 17 00:00:00 2001 From: Phil Race Date: Tue, 17 Aug 2021 21:48:02 +0000 Subject: [PATCH 014/253] 8271962: Better TrueType font loading Backport-of: 27827c186c43a7a2d983788f6d5e8b7f31e5e079 --- .../share/classes/sun/font/TrueTypeFont.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/java.desktop/share/classes/sun/font/TrueTypeFont.java b/src/java.desktop/share/classes/sun/font/TrueTypeFont.java index b3afe089132..856297643cf 100644 --- a/src/java.desktop/share/classes/sun/font/TrueTypeFont.java +++ b/src/java.desktop/share/classes/sun/font/TrueTypeFont.java @@ -503,7 +503,9 @@ protected void init(int fIndex) throws FontFormatException { /* checksum */ ibuffer.get(); table.offset = ibuffer.get() & 0x7FFFFFFF; table.length = ibuffer.get() & 0x7FFFFFFF; - if (table.offset + table.length > fileSize) { + if ((table.offset + table.length < table.length) || + (table.offset + table.length > fileSize)) + { throw new FontFormatException("bad table, tag="+table.tag); } } @@ -798,8 +800,11 @@ ByteBuffer getTableBuffer(int tag) { break; } } + if (entry == null || entry.length == 0 || - entry.offset+entry.length > fileSize) { + (entry.offset + entry.length < entry.length) || + (entry.offset + entry.length > fileSize)) + { return null; } @@ -888,6 +893,9 @@ boolean useEmbeddedBitmapsForSize(int ptSize) { return false; } ByteBuffer eblcTable = getTableBuffer(EBLCTag); + if (eblcTable == null) { + return false; + } int numSizes = eblcTable.getInt(4); /* The bitmapSizeTable's start at offset of 8. * Each bitmapSizeTable entry is 48 bytes. From 5211317613f1a31cc5d83438f87ef16ba9e6605a Mon Sep 17 00:00:00 2001 From: Prajwal Kumaraswamy Date: Thu, 19 Aug 2021 11:50:39 +0000 Subject: [PATCH 015/253] 8268512: More content for ContentInfo Backport-of: 4a1ea63840ec90e52c036c408baef4a1cf0abdff --- .../share/classes/sun/security/pkcs/ContentInfo.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/sun/security/pkcs/ContentInfo.java b/src/java.base/share/classes/sun/security/pkcs/ContentInfo.java index 125da2c9e2c..fbc6a46fc00 100644 --- a/src/java.base/share/classes/sun/security/pkcs/ContentInfo.java +++ b/src/java.base/share/classes/sun/security/pkcs/ContentInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2021, 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 @@ -127,7 +127,9 @@ public ContentInfo(DerInputStream derin, boolean oldStyle) if (oldStyle) { // JDK1.1.x-style encoding - content = typeAndContent[1]; + if (typeAndContent.length > 1) { // content is OPTIONAL + content = typeAndContent[1]; + } } else { // This is the correct, standards-compliant encoding. // Parse the content (OPTIONAL field). From bb350989c7afffcdfb4dca86cafe45d7289d082d Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Fri, 20 Aug 2021 12:49:15 +0000 Subject: [PATCH 016/253] 8268494: Better inlining of inlined interfaces Backport-of: 3c7fbbd703a50a9762e7f7dbafa8d44191346f52 --- src/hotspot/share/c1/c1_GraphBuilder.cpp | 12 +++++----- src/hotspot/share/code/dependencies.cpp | 28 ++++++++++++++++++++++++ src/hotspot/share/code/dependencies.hpp | 12 ++++++++-- src/hotspot/share/opto/doCall.cpp | 4 +++- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/hotspot/share/c1/c1_GraphBuilder.cpp b/src/hotspot/share/c1/c1_GraphBuilder.cpp index a7a47781447..1c93452d478 100644 --- a/src/hotspot/share/c1/c1_GraphBuilder.cpp +++ b/src/hotspot/share/c1/c1_GraphBuilder.cpp @@ -1989,19 +1989,19 @@ void GraphBuilder::invoke(Bytecodes::Code code) { cha_monomorphic_target = target->find_monomorphic_target(calling_klass, declared_interface, singleton); if (cha_monomorphic_target != NULL) { if (cha_monomorphic_target->holder() != compilation()->env()->Object_klass()) { - // If CHA is able to bind this invoke then update the class - // to match that class, otherwise klass will refer to the - // interface. - klass = cha_monomorphic_target->holder(); + ciInstanceKlass* holder = cha_monomorphic_target->holder(); + ciInstanceKlass* constraint = (holder->is_subtype_of(singleton) ? holder : singleton); // avoid upcasts actual_recv = declared_interface; // insert a check it's really the expected class. - CheckCast* c = new CheckCast(klass, receiver, copy_state_for_exception()); + CheckCast* c = new CheckCast(constraint, receiver, copy_state_for_exception()); c->set_incompatible_class_change_check(); - c->set_direct_compare(klass->is_final()); + c->set_direct_compare(constraint->is_final()); // pass the result of the checkcast so that the compiler has // more accurate type info in the inlinee better_receiver = append_split(c); + + dependency_recorder()->assert_unique_implementor(declared_interface, singleton); } else { cha_monomorphic_target = NULL; // subtype check against Object is useless } diff --git a/src/hotspot/share/code/dependencies.cpp b/src/hotspot/share/code/dependencies.cpp index 87e01ce4e77..306280dfc43 100644 --- a/src/hotspot/share/code/dependencies.cpp +++ b/src/hotspot/share/code/dependencies.cpp @@ -116,6 +116,12 @@ void Dependencies::assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, } } +void Dependencies::assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) { + check_ctxk(ctxk); + check_unique_implementor(ctxk, uniqk); + assert_common_2(unique_implementor, ctxk, uniqk); +} + void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) { check_ctxk(ctxk); assert_common_1(no_finalizable_subclasses, ctxk); @@ -173,6 +179,13 @@ void Dependencies::assert_abstract_with_unique_concrete_subtype(Klass* ctxk, Kla assert_common_2(abstract_with_unique_concrete_subtype, ctxk_dv, conck_dv); } +void Dependencies::assert_unique_implementor(InstanceKlass* ctxk, InstanceKlass* uniqk) { + check_ctxk(ctxk); + assert(ctxk->is_interface(), "not an interface"); + assert(ctxk->implementor() == uniqk, "not a unique implementor"); + assert_common_2(unique_implementor, DepValue(_oop_recorder, ctxk), DepValue(_oop_recorder, uniqk)); +} + void Dependencies::assert_unique_concrete_method(Klass* ctxk, Method* uniqm) { check_ctxk(ctxk); check_unique_method(ctxk, uniqm); @@ -573,6 +586,7 @@ const char* Dependencies::_dep_name[TYPE_LIMIT] = { "abstract_with_unique_concrete_subtype", "unique_concrete_method_2", "unique_concrete_method_4", + "unique_implementor", "no_finalizable_subclasses", "call_site_target_value" }; @@ -584,6 +598,7 @@ int Dependencies::_dep_args[TYPE_LIMIT] = { 2, // abstract_with_unique_concrete_subtype ctxk, k 2, // unique_concrete_method_2 ctxk, m 4, // unique_concrete_method_4 ctxk, m, resolved_klass, resolved_method + 2, // unique_implementor ctxk, implementor 1, // no_finalizable_subclasses ctxk 2 // call_site_target_value call_site, method_handle }; @@ -1806,6 +1821,16 @@ Klass* Dependencies::check_unique_concrete_method(InstanceKlass* ctxk, return NULL; } +Klass* Dependencies::check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes) { + assert(ctxk->is_interface(), "sanity"); + assert(ctxk->nof_implementors() > 0, "no implementors"); + if (ctxk->nof_implementors() == 1) { + assert(ctxk->implementor() == uniqk, "sanity"); + return NULL; + } + return ctxk; // no unique implementor +} + // Search for AME. // There are two version of checks. // 1) Spot checking version(Classload time). Newly added class is checked for AME. @@ -2055,6 +2080,9 @@ Klass* Dependencies::DepStream::check_new_klass_dependency(NewKlassDepChange* ch case unique_concrete_method_4: witness = check_unique_concrete_method(context_type(), method_argument(1), type_argument(2), method_argument(3), changes); break; + case unique_implementor: + witness = check_unique_implementor(context_type(), type_argument(1), changes); + break; case no_finalizable_subclasses: witness = check_has_no_finalizable_subclasses(context_type(), changes); break; diff --git a/src/hotspot/share/code/dependencies.hpp b/src/hotspot/share/code/dependencies.hpp index 104fc9ee649..0d8fa9fa48c 100644 --- a/src/hotspot/share/code/dependencies.hpp +++ b/src/hotspot/share/code/dependencies.hpp @@ -143,6 +143,9 @@ class Dependencies: public ResourceObj { // of the analysis. unique_concrete_method_4, // one unique concrete method under CX + // This dependency asserts that interface CX has a unique implementor class. + unique_implementor, // one unique implementor under CX + // This dependency asserts that no instances of class or it's // subclasses require finalization registration. no_finalizable_subclasses, @@ -329,7 +332,10 @@ class Dependencies: public ResourceObj { assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract"); } static void check_unique_method(ciKlass* ctxk, ciMethod* m) { - assert(!m->can_be_statically_bound(ctxk->as_instance_klass()), "redundant"); + assert(!m->can_be_statically_bound(ctxk->as_instance_klass()) || ctxk->is_interface(), "redundant"); + } + static void check_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) { + assert(ctxk->implementor() == uniqk, "not a unique implementor"); } void assert_common_1(DepType dept, ciBaseObject* x); @@ -343,9 +349,9 @@ class Dependencies: public ResourceObj { void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck); void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm); void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, ciKlass* resolved_klass, ciMethod* resolved_method); + void assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk); void assert_has_no_finalizable_subclasses(ciKlass* ctxk); void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle); - #if INCLUDE_JVMCI private: static void check_ctxk(Klass* ctxk) { @@ -366,6 +372,7 @@ class Dependencies: public ResourceObj { void assert_evol_method(Method* m); void assert_has_no_finalizable_subclasses(Klass* ctxk); void assert_leaf_type(Klass* ctxk); + void assert_unique_implementor(InstanceKlass* ctxk, InstanceKlass* uniqk); void assert_unique_concrete_method(Klass* ctxk, Method* uniqm); void assert_abstract_with_unique_concrete_subtype(Klass* ctxk, Klass* conck); void assert_call_site_target_value(oop callSite, oop methodHandle); @@ -413,6 +420,7 @@ class Dependencies: public ResourceObj { static Klass* check_evol_method(Method* m); static Klass* check_leaf_type(InstanceKlass* ctxk); static Klass* check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk, Klass* conck, NewKlassDepChange* changes = NULL); + static Klass* check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes = NULL); static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, NewKlassDepChange* changes = NULL); static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, Klass* resolved_klass, Method* resolved_method, KlassDepChange* changes = NULL); static Klass* check_has_no_finalizable_subclasses(InstanceKlass* ctxk, NewKlassDepChange* changes = NULL); diff --git a/src/hotspot/share/opto/doCall.cpp b/src/hotspot/share/opto/doCall.cpp index 4a371eb7064..09e3d855425 100644 --- a/src/hotspot/share/opto/doCall.cpp +++ b/src/hotspot/share/opto/doCall.cpp @@ -328,8 +328,10 @@ CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool CallGenerator* miss_cg = CallGenerator::for_uncommon_trap(callee, Deoptimization::Reason_class_check, Deoptimization::Action_none); - CallGenerator* cg = CallGenerator::for_guarded_call(holder, miss_cg, hit_cg); + ciKlass* constraint = (holder->is_subclass_of(singleton) ? holder : singleton); // avoid upcasts + CallGenerator* cg = CallGenerator::for_guarded_call(constraint, miss_cg, hit_cg); if (hit_cg != NULL && cg != NULL) { + dependencies()->assert_unique_implementor(declared_interface, singleton); dependencies()->assert_unique_concrete_method(declared_interface, cha_monomorphic_target, declared_interface, callee); return cg; } From f8eb9abe034f7c6bea4da05a9ea42017b3f80730 Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Mon, 23 Aug 2021 05:24:18 +0000 Subject: [PATCH 017/253] 8270386: Better verification of scan methods Reviewed-by: coleenp Backport-of: ac329cef45979bd0159ecd1347e36f7129bb2ce4 --- src/hotspot/share/oops/instanceKlass.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index cdc67e970bf..a91b8dfaff9 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -2375,7 +2375,9 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) { } else { it->push(&_default_vtable_indices); } - it->push(&_fields); + + // _fields might be written into by Rewriter::scan_method() -> fd.set_has_initialized_final_update() + it->push(&_fields, MetaspaceClosure::_writable); if (itable_length() > 0) { itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); From f79ea82331718509b34c01297df869851c8641e1 Mon Sep 17 00:00:00 2001 From: Ramkumar Sunderbabu Date: Fri, 27 Aug 2021 08:55:53 +0000 Subject: [PATCH 018/253] 8266988: compiler/jvmci/compilerToVM/IsMatureTest.java fails with Unexpected isMature state for multiple times invoked method: expected false to equal true Backport-of: 7468bbcd647dc525ca75c7fb29d52c26c9c5e528 --- .../compiler/jvmci/compilerToVM/IsMatureTest.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/hotspot/jtreg/compiler/jvmci/compilerToVM/IsMatureTest.java b/test/hotspot/jtreg/compiler/jvmci/compilerToVM/IsMatureTest.java index 534ab86db51..87f4d3df6cc 100644 --- a/test/hotspot/jtreg/compiler/jvmci/compilerToVM/IsMatureTest.java +++ b/test/hotspot/jtreg/compiler/jvmci/compilerToVM/IsMatureTest.java @@ -78,10 +78,13 @@ public void test() throws Exception { && compLevel != CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE) { Asserts.assertNE(methodData, 0L, "Multiple times invoked method should have method data"); - /* a method is not mature in Xcomp mode with tiered compilation disabled, - see NonTieredCompPolicy::is_mature */ - Asserts.assertEQ(isMature, !(Platform.isComp() && !TIERED), - "Unexpected isMature state for multiple times invoked method"); + // The method may or may not be mature if it's compiled with limited profile. + if (compLevel != CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE) { + /* a method is not mature in Xcomp mode with tiered compilation disabled, + see NonTieredCompPolicy::is_mature */ + Asserts.assertEQ(isMature, !(Platform.isComp() && !TIERED), + "Unexpected isMature state for multiple times invoked method"); + } } } } From 3a0e2b45a74b859088457f39a72c84c3f8916aad Mon Sep 17 00:00:00 2001 From: Prajwal Kumaraswamy Date: Mon, 6 Sep 2021 13:18:32 +0000 Subject: [PATCH 019/253] 8269151: Better construction of EncryptedPrivateKeyInfo Backport-of: 9fd7b2d4f333834f03a0e4fbc1e2a7d867331961 --- .../javax/crypto/EncryptedPrivateKeyInfo.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/java.base/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java b/src/java.base/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java index 59b4a07f349..09c69748d5a 100644 --- a/src/java.base/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java +++ b/src/java.base/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java @@ -77,15 +77,18 @@ public class EncryptedPrivateKeyInfo { * @exception NullPointerException if the encoded is null. * @exception IOException if error occurs when parsing the ASN.1 encoding. */ - public EncryptedPrivateKeyInfo(byte[] encoded) - throws IOException { + public EncryptedPrivateKeyInfo(byte[] encoded) throws IOException { if (encoded == null) { throw new NullPointerException("the encoded parameter " + - "must be non-null"); + "must be non-null"); } - this.encoded = encoded.clone(); - DerValue val = new DerValue(this.encoded); + DerValue val = new DerValue(encoded); + if (val.tag != DerValue.tag_Sequence) { + throw new IOException("DER header error: no SEQ tag"); + } + + this.encoded = encoded.clone(); DerValue[] seq = new DerValue[2]; seq[0] = val.data.getDerValue(); From b300e880c4edf6b8b1bdc91c44dda17d9f814130 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 6 Sep 2021 21:24:51 +0000 Subject: [PATCH 020/253] 8272272: Enhance jcmd communication Backport-of: 1a67dd1ba853d535c718840dcdada12e1b312eb8 --- src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c b/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c index a21ce9fa73b..f08a7c004b3 100644 --- a/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c +++ b/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2021, 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 @@ -399,6 +399,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_enqueue /* * Setup data to copy to target process */ + memset(&data, 0, sizeof(data)); data._GetModuleHandle = _GetModuleHandle; data._GetProcAddress = _GetProcAddress; From ef65147a0686884445d5c9eca65fa4cae5cbf261 Mon Sep 17 00:00:00 2001 From: Prasadrao Koppula Date: Tue, 7 Sep 2021 13:26:25 +0000 Subject: [PATCH 021/253] 8268488: More valuable DerValues Backport-of: 99f72cf1c44c58682d93a81ee76ef9c3707152a9 --- .../com/sun/crypto/provider/KeyProtector.java | 4 ++++ .../com/sun/crypto/provider/OAEPParameters.java | 15 ++++++++++++--- .../classes/sun/security/pkcs/SignerInfo.java | 12 ++++++++++-- .../classes/sun/security/rsa/PSSParameters.java | 9 +++++++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/java.base/share/classes/com/sun/crypto/provider/KeyProtector.java b/src/java.base/share/classes/com/sun/crypto/provider/KeyProtector.java index b13a1a905d7..570aca63e09 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/KeyProtector.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/KeyProtector.java @@ -177,6 +177,10 @@ Key recover(EncryptedPrivateKeyInfo encrInfo) byte[] encodedParams = encrInfo.getAlgorithm().getEncodedParams(); + if (encodedParams == null) { + throw new IOException("Missing PBE parameters"); + } + // parse the PBE parameters into the corresponding spec AlgorithmParameters pbeParams = AlgorithmParameters.getInstance("PBE"); diff --git a/src/java.base/share/classes/com/sun/crypto/provider/OAEPParameters.java b/src/java.base/share/classes/com/sun/crypto/provider/OAEPParameters.java index 57261376d78..e4879b50dc4 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/OAEPParameters.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/OAEPParameters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2021, 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 @@ -110,8 +110,12 @@ protected void engineInit(byte[] encoded) if (!val.getOID().equals(OID_MGF1)) { throw new IOException("Only MGF1 mgf is supported"); } + byte[] encodedParams = val.getEncodedParams(); + if (encodedParams == null) { + throw new IOException("Missing MGF1 parameters"); + } AlgorithmId params = AlgorithmId.parse( - new DerValue(val.getEncodedParams())); + new DerValue(encodedParams)); String mgfDigestName = params.getName(); if (mgfDigestName.equals("SHA-1")) { mgfSpec = MGF1ParameterSpec.SHA1; @@ -137,7 +141,12 @@ protected void engineInit(byte[] encoded) if (!val.getOID().equals(OID_PSpecified)) { throw new IOException("Wrong OID for pSpecified"); } - DerInputStream dis = new DerInputStream(val.getEncodedParams()); + byte[] encodedParams = val.getEncodedParams(); + if (encodedParams == null) { + throw new IOException("Missing pSpecified label"); + } + + DerInputStream dis = new DerInputStream(encodedParams); p = dis.getOctetString(); if (dis.available() != 0) { throw new IOException("Extra data for pSpecified"); diff --git a/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java b/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java index 1689672b7a9..6a7b69663e1 100644 --- a/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java +++ b/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java @@ -380,8 +380,15 @@ SignerInfo verify(PKCS7 block, byte[] data) if (digestAlgName.equals("SHAKE256") || digestAlgName.equals("SHAKE256-LEN")) { if (digestAlgName.equals("SHAKE256-LEN")) { - int v = new DerValue(digestAlgorithmId - .getEncodedParams()).getInteger(); + // RFC8419: for EdDSA in CMS, the id-shake256-len + // algorithm id must contain parameter value 512 + // encoded as a positive integer value + byte[] params = digestAlgorithmId.getEncodedParams(); + if (params == null) { + throw new SignatureException( + "id-shake256-len oid missing length"); + } + int v = new DerValue(params).getInteger(); if (v != 512) { throw new SignatureException( "Unsupported id-shake256-" + v); @@ -523,6 +530,7 @@ public static String makeSigAlg(AlgorithmId digAlgId, AlgorithmId encAlgId, if (spec == null) { throw new NoSuchAlgorithmException("Missing PSSParameterSpec for RSASSA-PSS algorithm"); } + if (!AlgorithmId.get(spec.getDigestAlgorithm()).equals(digAlgId)) { throw new NoSuchAlgorithmException("Incompatible digest algorithm"); } diff --git a/src/java.base/share/classes/sun/security/rsa/PSSParameters.java b/src/java.base/share/classes/sun/security/rsa/PSSParameters.java index fef496ed50c..c2f4039a3ea 100644 --- a/src/java.base/share/classes/sun/security/rsa/PSSParameters.java +++ b/src/java.base/share/classes/sun/security/rsa/PSSParameters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, 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 @@ -102,8 +102,13 @@ protected void engineInit(byte[] encoded) throws IOException { if (!val.getOID().equals(AlgorithmId.MGF1_oid)) { throw new IOException("Only MGF1 mgf is supported"); } + + byte[] encodedParams = val.getEncodedParams(); + if (encodedParams == null) { + throw new IOException("Missing MGF1 parameters"); + } AlgorithmId params = AlgorithmId.parse( - new DerValue(val.getEncodedParams())); + new DerValue(encodedParams)); String mgfDigestName = params.getName(); switch (mgfDigestName) { case "SHA-1": From f78d4194f17d2e55fbdfc612812b5e566f0bab63 Mon Sep 17 00:00:00 2001 From: Harold Seigel Date: Wed, 8 Sep 2021 12:50:57 +0000 Subject: [PATCH 022/253] 8271987: Manifest improved manifest entries Backport-of: 885f3699edf517d11d17607aad41e32d059f547a --- src/hotspot/share/classfile/classLoader.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/classfile/classLoader.cpp b/src/hotspot/share/classfile/classLoader.cpp index 724ecfcd586..0287b73e503 100644 --- a/src/hotspot/share/classfile/classLoader.cpp +++ b/src/hotspot/share/classfile/classLoader.cpp @@ -303,13 +303,19 @@ u1* ClassPathZipEntry::open_entry(JavaThread* current, const char* name, jint* f } // read contents into resource array - int size = (*filesize) + ((nul_terminate) ? 1 : 0); + size_t size = (uint32_t)(*filesize); + if (nul_terminate) { + if (sizeof(size) == sizeof(uint32_t) && size == UINT_MAX) { + return NULL; // 32-bit integer overflow will occur. + } + size++; + } buffer = NEW_RESOURCE_ARRAY(u1, size); if (!(*ReadEntry)(_zip, entry, buffer, filename)) return NULL; // return result if (nul_terminate) { - buffer[*filesize] = 0; + buffer[size - 1] = 0; } return buffer; } From ad0426940b187090c422b17059c03d0240f2b023 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 8 Sep 2021 14:57:28 +0000 Subject: [PATCH 023/253] 8269924: Shenandoah: Introduce weak/strong marking asserts Backport-of: 515113d8589875e76980ebf7473cb81f778bb86f --- .../share/gc/shenandoah/shenandoahAsserts.cpp | 22 +++++++++++++++++ .../share/gc/shenandoah/shenandoahAsserts.hpp | 24 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp index 898db1a8df9..87cf1c41d3f 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp @@ -316,6 +316,28 @@ void ShenandoahAsserts::assert_marked(void *interior_loc, oop obj, const char *f } } +void ShenandoahAsserts::assert_marked_weak(void *interior_loc, oop obj, const char *file, int line) { + assert_correct(interior_loc, obj, file, line); + + ShenandoahHeap* heap = ShenandoahHeap::heap(); + if (!heap->marking_context()->is_marked_weak(obj)) { + print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked_weak failed", + "Object should be marked weakly", + file, line); + } +} + +void ShenandoahAsserts::assert_marked_strong(void *interior_loc, oop obj, const char *file, int line) { + assert_correct(interior_loc, obj, file, line); + + ShenandoahHeap* heap = ShenandoahHeap::heap(); + if (!heap->marking_context()->is_marked_strong(obj)) { + print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked_strong failed", + "Object should be marked strongly", + file, line); + } +} + void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char* file, int line) { assert_correct(interior_loc, obj, file, line); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp index 61779b447d6..c730eafb89d 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp @@ -61,6 +61,8 @@ class ShenandoahAsserts { static void assert_forwarded(void* interior_loc, oop obj, const char* file, int line); static void assert_not_forwarded(void* interior_loc, oop obj, const char* file, int line); static void assert_marked(void* interior_loc, oop obj, const char* file, int line); + static void assert_marked_weak(void* interior_loc, oop obj, const char* file, int line); + static void assert_marked_strong(void* interior_loc, oop obj, const char* file, int line); static void assert_in_cset(void* interior_loc, oop obj, const char* file, int line); static void assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line); static void assert_not_in_cset_loc(void* interior_loc, const char* file, int line); @@ -107,6 +109,20 @@ class ShenandoahAsserts { #define shenandoah_assert_marked(interior_loc, obj) \ ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__) +#define shenandoah_assert_marked_weak_if(interior_loc, obj, condition) \ + if (condition) ShenandoahAsserts::assert_marked_weak(interior_loc, obj, __FILE__, __LINE__) +#define shenandoah_assert_marked_weak_except(interior_loc, obj, exception) \ + if (!(exception)) ShenandoahAsserts::assert_marked_weak(interior_loc, obj, __FILE__, __LINE__) +#define shenandoah_assert_marked_weak(interior_loc, obj) \ + ShenandoahAsserts::assert_marked_weak(interior_loc, obj, __FILE__, __LINE__) + +#define shenandoah_assert_marked_strong_if(interior_loc, obj, condition) \ + if (condition) ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__) +#define shenandoah_assert_marked_strong_except(interior_loc, obj, exception) \ + if (!(exception)) ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__) +#define shenandoah_assert_marked_strong(interior_loc, obj) \ + ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__) + #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) \ if (condition) ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__) #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) \ @@ -168,6 +184,14 @@ class ShenandoahAsserts { #define shenandoah_assert_marked_except(interior_loc, obj, exception) #define shenandoah_assert_marked(interior_loc, obj) +#define shenandoah_assert_marked_weak_if(interior_loc, obj, condition) +#define shenandoah_assert_marked_weak_except(interior_loc, obj, exception) +#define shenandoah_assert_marked_weak(interior_loc, obj) + +#define shenandoah_assert_marked_strong_if(interior_loc, obj, condition) +#define shenandoah_assert_marked_strong_except(interior_loc, obj, exception) +#define shenandoah_assert_marked_strong(interior_loc, obj) + #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) #define shenandoah_assert_in_cset(interior_loc, obj) From e1cd6c78138098f3f2328a2fe978313d0b5b7394 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 8 Sep 2021 15:36:30 +0000 Subject: [PATCH 024/253] 8269280: (bf) Replace StringBuffer in *Buffer.toString() Backport-of: 3a8f3d6cac0ab859704db533bf1f63431fbd9253 --- .../classes/java/nio/X-Buffer.java.template | 15 +-- .../jdk/java/nio/Buffer/Basic-X.java.template | 22 ++++ test/jdk/java/nio/Buffer/BasicByte.java | 22 ++++ test/jdk/java/nio/Buffer/BasicChar.java | 101 +++++++++++++++++- test/jdk/java/nio/Buffer/BasicDouble.java | 101 +++++++++++++++++- test/jdk/java/nio/Buffer/BasicFloat.java | 101 +++++++++++++++++- test/jdk/java/nio/Buffer/BasicInt.java | 101 +++++++++++++++++- test/jdk/java/nio/Buffer/BasicLong.java | 101 +++++++++++++++++- test/jdk/java/nio/Buffer/BasicShort.java | 101 +++++++++++++++++- 9 files changed, 649 insertions(+), 16 deletions(-) diff --git a/src/java.base/share/classes/java/nio/X-Buffer.java.template b/src/java.base/share/classes/java/nio/X-Buffer.java.template index 6950e519a85..aa52f575f19 100644 --- a/src/java.base/share/classes/java/nio/X-Buffer.java.template +++ b/src/java.base/share/classes/java/nio/X-Buffer.java.template @@ -1666,16 +1666,11 @@ public abstract class $Type$Buffer * @return A summary string */ public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(getClass().getName()); - sb.append("[pos="); - sb.append(position()); - sb.append(" lim="); - sb.append(limit()); - sb.append(" cap="); - sb.append(capacity()); - sb.append("]"); - return sb.toString(); + return getClass().getName() + + "[pos=" + position() + + " lim=" + limit() + + " cap=" + capacity() + + "]"; } #end[!char] diff --git a/test/jdk/java/nio/Buffer/Basic-X.java.template b/test/jdk/java/nio/Buffer/Basic-X.java.template index 0879a61c61c..0c328c89baf 100644 --- a/test/jdk/java/nio/Buffer/Basic-X.java.template +++ b/test/jdk/java/nio/Buffer/Basic-X.java.template @@ -1134,6 +1134,26 @@ public class Basic$Type$ #end[byte] } + public static void testToString() { + final int cap = 10; + +#if[byte] + $Type$Buffer direct1 = $Type$Buffer.allocateDirect(cap); + if (!direct1.toString().equals(Basic.toString(direct1))) { + fail("Direct buffer toString is incorrect: " + + direct1.toString() + " vs " + Basic.toString(direct1)); + } +#end[byte] + +#if[!char] + $Type$Buffer nondirect1 = $Type$Buffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } +#end[!char] + } + public static void test() { testAllocate(); test(0, $Type$Buffer.allocate(7 * 1024), false); @@ -1155,6 +1175,8 @@ public class Basic$Type$ #else[byte] putBuffer(); #end[byte] + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicByte.java b/test/jdk/java/nio/Buffer/BasicByte.java index f4790e72483..cbcebb1040e 100644 --- a/test/jdk/java/nio/Buffer/BasicByte.java +++ b/test/jdk/java/nio/Buffer/BasicByte.java @@ -1134,6 +1134,26 @@ private static void testAllocate() { } + public static void testToString() { + final int cap = 10; + + + ByteBuffer direct1 = ByteBuffer.allocateDirect(cap); + if (!direct1.toString().equals(Basic.toString(direct1))) { + fail("Direct buffer toString is incorrect: " + + direct1.toString() + " vs " + Basic.toString(direct1)); + } + + + + ByteBuffer nondirect1 = ByteBuffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } + + } + public static void test() { testAllocate(); test(0, ByteBuffer.allocate(7 * 1024), false); @@ -1155,6 +1175,8 @@ public static void test() { + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicChar.java b/test/jdk/java/nio/Buffer/BasicChar.java index 6b927c8d782..08c247841ef 100644 --- a/test/jdk/java/nio/Buffer/BasicChar.java +++ b/test/jdk/java/nio/Buffer/BasicChar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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,9 +30,19 @@ // -- This file was mechanically generated: Do not edit! -- // + + + + import java.nio.*; + + + + + + public class BasicChar extends Basic { @@ -451,6 +461,73 @@ private static void checkSlice(CharBuffer b, CharBuffer slice) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1055,6 +1132,26 @@ private static void testAllocate() { + } + + public static void testToString() { + final int cap = 10; + + + + + + + + + + + + + + + + } public static void test() { @@ -1078,6 +1175,8 @@ public static void test() { putBuffer(); + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicDouble.java b/test/jdk/java/nio/Buffer/BasicDouble.java index 8811cff7d13..c569955e7e2 100644 --- a/test/jdk/java/nio/Buffer/BasicDouble.java +++ b/test/jdk/java/nio/Buffer/BasicDouble.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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,9 +30,19 @@ // -- This file was mechanically generated: Do not edit! -- // + + + + import java.nio.*; + + + + + + public class BasicDouble extends Basic { @@ -451,6 +461,73 @@ private static void checkSlice(DoubleBuffer b, DoubleBuffer slice) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1055,6 +1132,26 @@ private static void testAllocate() { + } + + public static void testToString() { + final int cap = 10; + + + + + + + + + + + DoubleBuffer nondirect1 = DoubleBuffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } + } public static void test() { @@ -1078,6 +1175,8 @@ public static void test() { putBuffer(); + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicFloat.java b/test/jdk/java/nio/Buffer/BasicFloat.java index f11b79225d6..15f1e3c86ee 100644 --- a/test/jdk/java/nio/Buffer/BasicFloat.java +++ b/test/jdk/java/nio/Buffer/BasicFloat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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,9 +30,19 @@ // -- This file was mechanically generated: Do not edit! -- // + + + + import java.nio.*; + + + + + + public class BasicFloat extends Basic { @@ -451,6 +461,73 @@ private static void checkSlice(FloatBuffer b, FloatBuffer slice) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1055,6 +1132,26 @@ private static void testAllocate() { + } + + public static void testToString() { + final int cap = 10; + + + + + + + + + + + FloatBuffer nondirect1 = FloatBuffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } + } public static void test() { @@ -1078,6 +1175,8 @@ public static void test() { putBuffer(); + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicInt.java b/test/jdk/java/nio/Buffer/BasicInt.java index ca0d040998b..4d424b0c279 100644 --- a/test/jdk/java/nio/Buffer/BasicInt.java +++ b/test/jdk/java/nio/Buffer/BasicInt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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,9 +30,19 @@ // -- This file was mechanically generated: Do not edit! -- // + + + + import java.nio.*; + + + + + + public class BasicInt extends Basic { @@ -451,6 +461,73 @@ private static void checkSlice(IntBuffer b, IntBuffer slice) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1055,6 +1132,26 @@ private static void testAllocate() { + } + + public static void testToString() { + final int cap = 10; + + + + + + + + + + + IntBuffer nondirect1 = IntBuffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } + } public static void test() { @@ -1078,6 +1175,8 @@ public static void test() { putBuffer(); + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicLong.java b/test/jdk/java/nio/Buffer/BasicLong.java index ab28e859b15..b8ed196757f 100644 --- a/test/jdk/java/nio/Buffer/BasicLong.java +++ b/test/jdk/java/nio/Buffer/BasicLong.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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,9 +30,19 @@ // -- This file was mechanically generated: Do not edit! -- // + + + + import java.nio.*; + + + + + + public class BasicLong extends Basic { @@ -451,6 +461,73 @@ private static void checkSlice(LongBuffer b, LongBuffer slice) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1055,6 +1132,26 @@ private static void testAllocate() { + } + + public static void testToString() { + final int cap = 10; + + + + + + + + + + + LongBuffer nondirect1 = LongBuffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } + } public static void test() { @@ -1078,6 +1175,8 @@ public static void test() { putBuffer(); + + testToString(); } } diff --git a/test/jdk/java/nio/Buffer/BasicShort.java b/test/jdk/java/nio/Buffer/BasicShort.java index e9458dde906..d9eb7c3d413 100644 --- a/test/jdk/java/nio/Buffer/BasicShort.java +++ b/test/jdk/java/nio/Buffer/BasicShort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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,9 +30,19 @@ // -- This file was mechanically generated: Do not edit! -- // + + + + import java.nio.*; + + + + + + public class BasicShort extends Basic { @@ -451,6 +461,73 @@ private static void checkSlice(ShortBuffer b, ShortBuffer slice) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1055,6 +1132,26 @@ private static void testAllocate() { + } + + public static void testToString() { + final int cap = 10; + + + + + + + + + + + ShortBuffer nondirect1 = ShortBuffer.allocate(cap); + if (!nondirect1.toString().equals(Basic.toString(nondirect1))) { + fail("Heap buffer toString is incorrect: " + + nondirect1.toString() + " vs " + Basic.toString(nondirect1)); + } + } public static void test() { @@ -1078,6 +1175,8 @@ public static void test() { putBuffer(); + + testToString(); } } From 271403bccccd20e103f336819235c98fb4860027 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Thu, 9 Sep 2021 05:39:28 +0000 Subject: [PATCH 025/253] 8269031: linux x86_64 check for binutils 2.25 or higher after 8265783 Backport-of: 18a1dd261cec6fa1c5820dce2df47d488417afff --- make/autoconf/toolchain.m4 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/make/autoconf/toolchain.m4 b/make/autoconf/toolchain.m4 index 78895888095..69540e1608e 100644 --- a/make/autoconf/toolchain.m4 +++ b/make/autoconf/toolchain.m4 @@ -221,6 +221,12 @@ AC_DEFUN_ONCE([TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE], AC_ARG_WITH(toolchain-type, [AS_HELP_STRING([--with-toolchain-type], [the toolchain type (or family) to use, use '--help' to show possible values @<:@platform dependent@:>@])]) + # Linux x86_64 needs higher binutils after 8265783 + # (this really is a dependency on as version, but we take ld as a check for a general binutils version) + if test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then + TOOLCHAIN_MINIMUM_LD_VERSION_gcc="2.25" + fi + # Use indirect variable referencing toolchain_var_name=VALID_TOOLCHAINS_$OPENJDK_BUILD_OS VALID_TOOLCHAINS=${!toolchain_var_name} @@ -677,9 +683,10 @@ AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_CORE], TOOLCHAIN_PREPARE_FOR_LD_VERSION_COMPARISONS if test "x$TOOLCHAIN_MINIMUM_LD_VERSION" != x; then + AC_MSG_NOTICE([comparing linker version to minimum version $TOOLCHAIN_MINIMUM_LD_VERSION]) TOOLCHAIN_CHECK_LINKER_VERSION(VERSION: $TOOLCHAIN_MINIMUM_LD_VERSION, IF_OLDER_THAN: [ - AC_MSG_WARN([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.]) + AC_MSG_ERROR([You are using a linker older than $TOOLCHAIN_MINIMUM_LD_VERSION. This is not a supported configuration.]) ] ) fi From ea6e678c957c9a96743b64a29d7e2b5f0c9cb938 Mon Sep 17 00:00:00 2001 From: Thejasvi Voniadka Date: Thu, 9 Sep 2021 05:48:12 +0000 Subject: [PATCH 026/253] 8271560: sun/security/ssl/DHKeyExchange/LegacyDHEKeyExchange.java still fails due to "An established connection was aborted by the software in your host machine" Backport-of: f18c0fac11aac833edfdc484e221518c55daa9a7 --- .../ssl/DHKeyExchange/LegacyDHEKeyExchange.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/jdk/sun/security/ssl/DHKeyExchange/LegacyDHEKeyExchange.java b/test/jdk/sun/security/ssl/DHKeyExchange/LegacyDHEKeyExchange.java index 45903469fa8..206761025c4 100644 --- a/test/jdk/sun/security/ssl/DHKeyExchange/LegacyDHEKeyExchange.java +++ b/test/jdk/sun/security/ssl/DHKeyExchange/LegacyDHEKeyExchange.java @@ -32,8 +32,10 @@ * @run main/othervm -Djdk.tls.ephemeralDHKeySize=legacy LegacyDHEKeyExchange */ +import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLSocket; +import java.net.SocketException; import java.util.concurrent.CountDownLatch; public class LegacyDHEKeyExchange extends SSLSocketTemplate{ @@ -53,6 +55,10 @@ protected void runServerApplication(SSLSocket socket) throws Exception { throw she; } System.out.println("Expected exception thrown in server"); + } catch (SSLException | SocketException se) { + // The client side may have closed the socket. + System.out.println("Server exception:"); + se.printStackTrace(System.out); } finally { connDoneLatch.countDown(); connDoneLatch.await(); @@ -75,6 +81,10 @@ protected void runClientApplication(SSLSocket socket) throws Exception { throw she; } System.out.println("Expected exception thrown in client"); + } catch (SSLException | SocketException se) { + // The server side may have closed the socket. + System.out.println("Client exception:"); + se.printStackTrace(System.out); } finally { connDoneLatch.countDown(); connDoneLatch.await(); From 0ced2aa756cc6a763da5ee90d485d0e1b5471a9f Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 9 Sep 2021 07:06:27 +0000 Subject: [PATCH 027/253] 8272473: Parsing epoch seconds at a DST transition with a non-UTC parser is wrong Backport-of: fe7d70886cc9985478c5810eff0790648a9aae41 --- .../share/classes/java/time/format/Parsed.java | 9 +++++---- .../test/java/time/format/TestDateTimeParsing.java | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/java.base/share/classes/java/time/format/Parsed.java b/src/java.base/share/classes/java/time/format/Parsed.java index 377b5aa1ef6..567c2700a15 100644 --- a/src/java.base/share/classes/java/time/format/Parsed.java +++ b/src/java.base/share/classes/java/time/format/Parsed.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -354,10 +354,11 @@ private void resolveInstantFields() { } private void resolveInstantFields0(ZoneId selectedZone) { - Instant instant = Instant.ofEpochSecond(fieldValues.remove(INSTANT_SECONDS)); + Instant instant = Instant.ofEpochSecond(fieldValues.get(INSTANT_SECONDS)); ChronoZonedDateTime zdt = chrono.zonedDateTime(instant, selectedZone); updateCheckConflict(zdt.toLocalDate()); updateCheckConflict(INSTANT_SECONDS, SECOND_OF_DAY, (long) zdt.toLocalTime().toSecondOfDay()); + updateCheckConflict(INSTANT_SECONDS, OFFSET_SECONDS, (long) zdt.getOffset().getTotalSeconds()); } //----------------------------------------------------------------------- @@ -641,9 +642,9 @@ private void resolveFractional() { } private void resolveInstant() { - // add instant seconds if we have date, time and zone + // add instant seconds (if not present) if we have date, time and zone // Offset (if present) will be given priority over the zone. - if (date != null && time != null) { + if (!fieldValues.containsKey(INSTANT_SECONDS) && date != null && time != null) { Long offsetSecs = fieldValues.get(OFFSET_SECONDS); if (offsetSecs != null) { ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue()); diff --git a/test/jdk/java/time/test/java/time/format/TestDateTimeParsing.java b/test/jdk/java/time/test/java/time/format/TestDateTimeParsing.java index 1067e020b52..d5110d5f5d2 100644 --- a/test/jdk/java/time/test/java/time/format/TestDateTimeParsing.java +++ b/test/jdk/java/time/test/java/time/format/TestDateTimeParsing.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2021, 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,11 +88,12 @@ /** * @test * @summary Test parsing of edge cases. - * @bug 8223773 + * @bug 8223773 8272473 */ public class TestDateTimeParsing { private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); + private static final ZoneId NEW_YORK = ZoneId.of("America/New_York"); private static final ZoneOffset OFFSET_0230 = ZoneOffset.ofHoursMinutes(2, 30); private static final DateTimeFormatter LOCALFIELDS = new DateTimeFormatterBuilder() @@ -107,6 +108,7 @@ public class TestDateTimeParsing { .appendInstant().toFormatter(); private static final DateTimeFormatter INSTANT_WITH_PARIS = INSTANT.withZone(PARIS); private static final DateTimeFormatter INSTANT_WITH_0230 = INSTANT.withZone(OFFSET_0230); + private static final DateTimeFormatter INSTANT_WITH_NEW_YORK = INSTANT.withZone(NEW_YORK); private static final DateTimeFormatter INSTANT_OFFSETID = new DateTimeFormatterBuilder() .appendInstant().appendLiteral(' ').appendOffsetId().toFormatter(); private static final DateTimeFormatter INSTANT_OFFSETSECONDS = new DateTimeFormatterBuilder() @@ -119,6 +121,7 @@ public class TestDateTimeParsing { private static final DateTimeFormatter INSTANTSECONDS_NOS_WITH_PARIS = INSTANTSECONDS_NOS.withZone(PARIS); private static final DateTimeFormatter INSTANTSECONDS_OFFSETSECONDS = new DateTimeFormatterBuilder() .appendValue(INSTANT_SECONDS).appendLiteral(' ').appendValue(OFFSET_SECONDS).toFormatter(); + private static final DateTimeFormatter INSTANTSECONDS_WITH_NEW_YORK = INSTANTSECONDS.withZone(NEW_YORK); private static final String DTPE_MESSAGE = "Invalid value for HourOfAmPm (valid values 0 - 11): 12"; @@ -133,11 +136,15 @@ Object[][] data_instantZones() { {LOCALFIELDS_WITH_0230, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)}, {INSTANT_WITH_PARIS, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(PARIS)}, {INSTANT_WITH_0230, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)}, + {INSTANT_WITH_NEW_YORK, "2020-11-01T05:00:00Z", ZonedDateTime.of(2020, 11, 1, 5, 0, 0, 0, ZoneOffset.UTC).withZoneSameInstant(NEW_YORK)}, + {INSTANT_WITH_NEW_YORK, "2020-11-01T06:00:00Z", ZonedDateTime.of(2020, 11, 1, 6, 0, 0, 0, ZoneOffset.UTC).withZoneSameInstant(NEW_YORK)}, {INSTANT_OFFSETID, "2014-06-30T01:02:03Z +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)}, {INSTANT_OFFSETSECONDS, "2014-06-30T01:02:03Z 9000", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)}, {INSTANTSECONDS_WITH_PARIS, "86402", Instant.ofEpochSecond(86402).atZone(PARIS)}, {INSTANTSECONDS_NOS_WITH_PARIS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789).atZone(PARIS)}, {INSTANTSECONDS_OFFSETSECONDS, "86402 9000", Instant.ofEpochSecond(86402).atZone(OFFSET_0230)}, + {INSTANTSECONDS_WITH_NEW_YORK, "1604206800", Instant.ofEpochSecond(1604206800).atZone(NEW_YORK)}, // 2020-11-01T05:00:00 UTC + {INSTANTSECONDS_WITH_NEW_YORK, "1604210400", Instant.ofEpochSecond(1604210400).atZone(NEW_YORK)}, // 2020-11-01T06:00:00 UTC }; } From f32703f81de883550d4a24d5a45c5b2312754479 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Thu, 9 Sep 2021 07:54:39 +0000 Subject: [PATCH 028/253] 8272783: Epsilon: Refactor tests to improve performance Backport-of: 7f80683cfeee3c069f48d5bce45fa92b2381b518 --- .../jtreg/gc/epsilon/TestAlignment.java | 22 ++++++-- .../jtreg/gc/epsilon/TestAlwaysPretouch.java | 32 +++++++++--- .../gc/epsilon/TestArraycopyCheckcast.java | 23 ++++++-- .../jtreg/gc/epsilon/TestByteArrays.java | 50 +++++++++++++----- .../hotspot/jtreg/gc/epsilon/TestClasses.java | 5 +- .../jtreg/gc/epsilon/TestDieDefault.java | 17 ++---- .../jtreg/gc/epsilon/TestDieWithHeapDump.java | 18 ++----- .../jtreg/gc/epsilon/TestDieWithOnError.java | 18 ++----- .../jtreg/gc/epsilon/TestElasticTLAB.java | 34 +++++++++--- .../gc/epsilon/TestElasticTLABDecay.java | 23 +++++--- .../jtreg/gc/epsilon/TestEpsilonEnabled.java | 5 +- .../jtreg/gc/epsilon/TestHelloWorld.java | 3 +- .../jtreg/gc/epsilon/TestLogTrace.java | 5 +- .../jtreg/gc/epsilon/TestManyThreads.java | 46 ++++++++++++---- .../hotspot/jtreg/gc/epsilon/TestMaxTLAB.java | 52 +++++++++++++++---- .../jtreg/gc/epsilon/TestMemoryMXBeans.java | 18 +++++-- .../jtreg/gc/epsilon/TestMemoryPools.java | 7 ++- .../hotspot/jtreg/gc/epsilon/TestObjects.java | 46 ++++++++++++---- .../jtreg/gc/epsilon/TestPrintHeapSteps.java | 18 +++++-- .../jtreg/gc/epsilon/TestRefArrays.java | 48 +++++++++++++---- .../gc/epsilon/TestUpdateCountersSteps.java | 24 +++++++-- 21 files changed, 378 insertions(+), 136 deletions(-) diff --git a/test/hotspot/jtreg/gc/epsilon/TestAlignment.java b/test/hotspot/jtreg/gc/epsilon/TestAlignment.java index e4328f5ac4d..c4eb329d3f6 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestAlignment.java +++ b/test/hotspot/jtreg/gc/epsilon/TestAlignment.java @@ -28,10 +28,24 @@ * @requires vm.gc.Epsilon * @summary Check Epsilon runs fine with (un)usual alignments * @bug 8212005 - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:+UseTLAB gc.epsilon.TestAlignment - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:-UseTLAB gc.epsilon.TestAlignment - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:+UseTLAB -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 gc.epsilon.TestAlignment - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:-UseTLAB -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 gc.epsilon.TestAlignment + * + * @run main/othervm -Xmx64m -XX:+UseTLAB + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlignment + * + * @run main/othervm -Xmx64m -XX:-UseTLAB + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlignment + * + * @run main/othervm -Xmx64m -XX:+UseTLAB + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * gc.epsilon.TestAlignment + * + * @run main/othervm -Xmx64m -XX:-UseTLAB + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * gc.epsilon.TestAlignment */ public class TestAlignment { diff --git a/test/hotspot/jtreg/gc/epsilon/TestAlwaysPretouch.java b/test/hotspot/jtreg/gc/epsilon/TestAlwaysPretouch.java index 75b0edf0058..b8ac4c802e4 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestAlwaysPretouch.java +++ b/test/hotspot/jtreg/gc/epsilon/TestAlwaysPretouch.java @@ -24,13 +24,31 @@ /** * @test TestAlwaysPretouch * @requires vm.gc.Epsilon - * @summary Basic sanity test for Epsilon - * @run main/othervm -Xms128m -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestAlwaysPretouch - * @run main/othervm -Xms128m -Xmx1g -XX:-AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestAlwaysPretouch - * @run main/othervm -Xms128m -Xmx1g -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestAlwaysPretouch - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestAlwaysPretouch - * @run main/othervm -Xmx1g -XX:-AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestAlwaysPretouch - * @run main/othervm -Xmx1g -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestAlwaysPretouch + * @summary Test that pre-touch works + * + * @run main/othervm -Xms64m -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlwaysPretouch + * + * @run main/othervm -Xms64m -Xmx256m -XX:-AlwaysPreTouch + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlwaysPretouch + * + * @run main/othervm -Xms64m -Xmx256m -XX:+AlwaysPreTouch + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlwaysPretouch + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlwaysPretouch + * + * @run main/othervm -Xmx256m -XX:-AlwaysPreTouch + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlwaysPretouch + * + * @run main/othervm -Xmx256m -XX:+AlwaysPreTouch + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestAlwaysPretouch */ package gc.epsilon; diff --git a/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java b/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java index ca9eaf6d7d9..632137b644c 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java +++ b/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java @@ -30,11 +30,24 @@ * @library /test/lib * @bug 8215724 * - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast - * @run main/othervm -Xmx1g -Xint -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestArraycopyCheckcast + * + * @run main/othervm -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestArraycopyCheckcast + * + * @run main/othervm -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestArraycopyCheckcast + * + * @run main/othervm -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestArraycopyCheckcast */ public class TestArraycopyCheckcast { diff --git a/test/hotspot/jtreg/gc/epsilon/TestByteArrays.java b/test/hotspot/jtreg/gc/epsilon/TestByteArrays.java index 79219566b88..fac70baeda0 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestByteArrays.java +++ b/test/hotspot/jtreg/gc/epsilon/TestByteArrays.java @@ -26,28 +26,54 @@ /** * @test TestByteArrays * @key randomness - * @requires vm.gc.Epsilon & os.maxMemory > 1G + * @requires vm.gc.Epsilon * @summary Epsilon is able to allocate arrays, and does not corrupt their state * @library /test/lib * - * @run main/othervm -Xmx1g -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays * - * @run main/othervm -Xmx1g -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xint -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestByteArrays + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays + * + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays + * + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestByteArrays */ import java.util.Random; import jdk.test.lib.Utils; public class TestByteArrays { - static int COUNT = Integer.getInteger("count", 3000); // ~500 MB allocation + static int COUNT = Integer.getInteger("count", 500); // ~100 MB allocation static byte[][] arr; diff --git a/test/hotspot/jtreg/gc/epsilon/TestClasses.java b/test/hotspot/jtreg/gc/epsilon/TestClasses.java index 5f0ae333f11..aa081eeaf65 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestClasses.java +++ b/test/hotspot/jtreg/gc/epsilon/TestClasses.java @@ -31,7 +31,10 @@ * @modules java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.misc * - * @run main/othervm -Xmx1g -XX:MetaspaceSize=1m -XX:MaxMetaspaceSize=64m -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -Xlog:gc+metaspace gc.epsilon.TestClasses + * @run main/othervm -Xmx256m + * -XX:MetaspaceSize=1m -XX:MaxMetaspaceSize=64m -Xlog:gc -Xlog:gc+metaspace + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestClasses */ import jdk.internal.org.objectweb.asm.ClassWriter; diff --git a/test/hotspot/jtreg/gc/epsilon/TestDieDefault.java b/test/hotspot/jtreg/gc/epsilon/TestDieDefault.java index b8a72660aaf..a883eb9f27c 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestDieDefault.java +++ b/test/hotspot/jtreg/gc/epsilon/TestDieDefault.java @@ -53,31 +53,24 @@ public static void failWith(String... args) throws Exception { } public static void main(String[] args) throws Exception { - passWith("-Xmx128m", + passWith("-Xmx64m", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-Dcount=1", TestDieDefault.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", TestDieDefault.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xint", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", TestDieDefault.Workload.class.getName()); - failWith("-Xmx128m", - "-Xbatch", - "-Xcomp", - "-XX:+UnlockExperimentalVMOptions", - "-XX:+UseEpsilonGC", - TestDieDefault.Workload.class.getName()); - - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xbatch", "-Xcomp", "-XX:TieredStopAtLevel=1", @@ -85,7 +78,7 @@ public static void main(String[] args) throws Exception { "-XX:+UseEpsilonGC", TestDieDefault.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xbatch", "-Xcomp", "-XX:-TieredCompilation", diff --git a/test/hotspot/jtreg/gc/epsilon/TestDieWithHeapDump.java b/test/hotspot/jtreg/gc/epsilon/TestDieWithHeapDump.java index b1df98c9ade..c717b493330 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestDieWithHeapDump.java +++ b/test/hotspot/jtreg/gc/epsilon/TestDieWithHeapDump.java @@ -59,35 +59,27 @@ public static void failWith(String... args) throws Exception { } public static void main(String[] args) throws Exception { - passWith("-Xmx128m", + passWith("-Xmx64m", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-Dcount=1", "-XX:+HeapDumpOnOutOfMemoryError", TestDieWithHeapDump.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-XX:+HeapDumpOnOutOfMemoryError", TestDieWithHeapDump.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xint", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-XX:+HeapDumpOnOutOfMemoryError", TestDieWithHeapDump.Workload.class.getName()); - failWith("-Xmx128m", - "-Xbatch", - "-Xcomp", - "-XX:+UnlockExperimentalVMOptions", - "-XX:+UseEpsilonGC", - "-XX:+HeapDumpOnOutOfMemoryError", - TestDieWithHeapDump.Workload.class.getName()); - - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xbatch", "-Xcomp", "-XX:TieredStopAtLevel=1", @@ -96,7 +88,7 @@ public static void main(String[] args) throws Exception { "-XX:+HeapDumpOnOutOfMemoryError", TestDieWithHeapDump.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xbatch", "-Xcomp", "-XX:-TieredCompilation", diff --git a/test/hotspot/jtreg/gc/epsilon/TestDieWithOnError.java b/test/hotspot/jtreg/gc/epsilon/TestDieWithOnError.java index c87658e3eea..2cac3843b0e 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestDieWithOnError.java +++ b/test/hotspot/jtreg/gc/epsilon/TestDieWithOnError.java @@ -57,35 +57,27 @@ public static void failWith(String... args) throws Exception { } public static void main(String[] args) throws Exception { - passWith("-Xmx128m", + passWith("-Xmx64m", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-Dcount=1", "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, TestDieWithOnError.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, TestDieWithOnError.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xint", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseEpsilonGC", "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, TestDieWithOnError.Workload.class.getName()); - failWith("-Xmx128m", - "-Xbatch", - "-Xcomp", - "-XX:+UnlockExperimentalVMOptions", - "-XX:+UseEpsilonGC", - "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, - TestDieWithOnError.Workload.class.getName()); - - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xbatch", "-Xcomp", "-XX:TieredStopAtLevel=1", @@ -94,7 +86,7 @@ public static void main(String[] args) throws Exception { "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, TestDieWithOnError.Workload.class.getName()); - failWith("-Xmx128m", + failWith("-Xmx64m", "-Xbatch", "-Xcomp", "-XX:-TieredCompilation", diff --git a/test/hotspot/jtreg/gc/epsilon/TestElasticTLAB.java b/test/hotspot/jtreg/gc/epsilon/TestElasticTLAB.java index 4ea46ea0dd1..6a312ac198f 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestElasticTLAB.java +++ b/test/hotspot/jtreg/gc/epsilon/TestElasticTLAB.java @@ -26,23 +26,41 @@ /** * @test TestElasticTLAB * @key randomness - * @requires vm.gc.Epsilon & os.maxMemory > 1G + * @requires vm.gc.Epsilon * @summary Epsilon is able to work with/without elastic TLABs * @library /test/lib * - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-EpsilonElasticTLAB gc.epsilon.TestElasticTLAB - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=1 gc.epsilon.TestElasticTLAB - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=1.1 gc.epsilon.TestElasticTLAB - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=2.0 gc.epsilon.TestElasticTLAB - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=42 gc.epsilon.TestElasticTLAB - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=100 gc.epsilon.TestElasticTLAB + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:-EpsilonElasticTLAB + * gc.epsilon.TestElasticTLAB + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=1 + * gc.epsilon.TestElasticTLAB + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=1.1 + * gc.epsilon.TestElasticTLAB + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=2.0 + * gc.epsilon.TestElasticTLAB + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:EpsilonTLABElasticity=100 + * gc.epsilon.TestElasticTLAB */ import java.util.Random; import jdk.test.lib.Utils; public class TestElasticTLAB { - static int COUNT = Integer.getInteger("count", 3000); // ~500 MB allocation + static int COUNT = Integer.getInteger("count", 500); // ~100 MB allocation static byte[][] arr; diff --git a/test/hotspot/jtreg/gc/epsilon/TestElasticTLABDecay.java b/test/hotspot/jtreg/gc/epsilon/TestElasticTLABDecay.java index 751f67911fc..c81ad29c059 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestElasticTLABDecay.java +++ b/test/hotspot/jtreg/gc/epsilon/TestElasticTLABDecay.java @@ -26,20 +26,31 @@ /** * @test TestElasticTLABDecay * @key randomness - * @requires vm.gc.Epsilon & os.maxMemory > 1G - * @summary Epsilon is able to work with/without elastic TLABs + * @requires vm.gc.Epsilon + * @summary Epsilon is able to work with/without elastic TLABs decay * @library /test/lib * - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:-EpsilonElasticTLABDecay gc.epsilon.TestElasticTLABDecay - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:+EpsilonElasticTLABDecay -XX:EpsilonTLABDecayTime=1 gc.epsilon.TestElasticTLABDecay - * @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:+EpsilonElasticTLAB -XX:+EpsilonElasticTLABDecay -XX:EpsilonTLABDecayTime=100 gc.epsilon.TestElasticTLABDecay + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:-EpsilonElasticTLABDecay + * gc.epsilon.TestElasticTLABDecay + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:+EpsilonElasticTLABDecay -XX:EpsilonTLABDecayTime=1 + * gc.epsilon.TestElasticTLABDecay + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:+EpsilonElasticTLAB -XX:+EpsilonElasticTLABDecay -XX:EpsilonTLABDecayTime=100 + * gc.epsilon.TestElasticTLABDecay */ import java.util.Random; import jdk.test.lib.Utils; public class TestElasticTLABDecay { - static int COUNT = Integer.getInteger("count", 3000); // ~500 MB allocation + static int COUNT = Integer.getInteger("count", 500); // ~100 MB allocation static byte[][] arr; diff --git a/test/hotspot/jtreg/gc/epsilon/TestEpsilonEnabled.java b/test/hotspot/jtreg/gc/epsilon/TestEpsilonEnabled.java index 5908ed6a29f..32ada0dc373 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestEpsilonEnabled.java +++ b/test/hotspot/jtreg/gc/epsilon/TestEpsilonEnabled.java @@ -28,7 +28,10 @@ * @requires vm.gc.Epsilon * @summary Basic sanity test for Epsilon * @library /test/lib - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestEpsilonEnabled + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestEpsilonEnabled */ import java.lang.management.GarbageCollectorMXBean; diff --git a/test/hotspot/jtreg/gc/epsilon/TestHelloWorld.java b/test/hotspot/jtreg/gc/epsilon/TestHelloWorld.java index c045411bf56..9d47cc4e292 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestHelloWorld.java +++ b/test/hotspot/jtreg/gc/epsilon/TestHelloWorld.java @@ -27,7 +27,8 @@ * @test TestHelloWorld * @requires vm.gc.Epsilon * @summary Basic sanity test for Epsilon - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestHelloWorld + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestHelloWorld */ public class TestHelloWorld { diff --git a/test/hotspot/jtreg/gc/epsilon/TestLogTrace.java b/test/hotspot/jtreg/gc/epsilon/TestLogTrace.java index 1dcb73046e8..c79295c3391 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestLogTrace.java +++ b/test/hotspot/jtreg/gc/epsilon/TestLogTrace.java @@ -28,7 +28,10 @@ * @test TestLogTrace * @requires vm.gc.Epsilon * @summary Test that tracing does not crash Epsilon - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc*=trace gc.epsilon.TestLogTrace + * + * @run main/othervm -Xmx256m -Xlog:gc*=trace + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestLogTrace */ public class TestLogTrace { diff --git a/test/hotspot/jtreg/gc/epsilon/TestManyThreads.java b/test/hotspot/jtreg/gc/epsilon/TestManyThreads.java index 8d9b2044829..5a03785cae4 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestManyThreads.java +++ b/test/hotspot/jtreg/gc/epsilon/TestManyThreads.java @@ -28,17 +28,43 @@ * @requires vm.gc.Epsilon * @summary Test allocations from many threads * - * @run main/othervm -Xmx128m -Xss512k -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xint -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xbatch -Xcomp -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xbatch -Xcomp -XX:-TieredCompilation -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads + * @run main/othervm -XX:-UseTLAB -Xmx256m -Xss512k + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads * - * @run main/othervm -Xmx128m -Xss512k -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xbatch -Xcomp -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads - * @run main/othervm -Xmx128m -Xss512k -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestManyThreads + * @run main/othervm -XX:-UseTLAB -Xmx256m -Xss512k + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads + * + * @run main/othervm -XX:-UseTLAB -Xmx256m -Xss512k + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads + * + * @run main/othervm -XX:-UseTLAB -Xmx256m -Xss512k + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads + * + * @run main/othervm -XX:+UseTLAB -Xmx256m -Xss512k + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads + * + * @run main/othervm -XX:+UseTLAB -Xmx256m -Xss512k + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads + * + * @run main/othervm -XX:+UseTLAB -Xmx256m -Xss512k + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads + * + * @run main/othervm -XX:+UseTLAB -Xmx256m -Xss512k + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestManyThreads */ import java.util.concurrent.atomic.*; diff --git a/test/hotspot/jtreg/gc/epsilon/TestMaxTLAB.java b/test/hotspot/jtreg/gc/epsilon/TestMaxTLAB.java index a345af6206c..c3ad148f014 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestMaxTLAB.java +++ b/test/hotspot/jtreg/gc/epsilon/TestMaxTLAB.java @@ -29,15 +29,49 @@ * @summary Check EpsilonMaxTLAB options * @bug 8212177 * - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=1 gc.epsilon.TestMaxTLAB - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=1K gc.epsilon.TestMaxTLAB - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=1M gc.epsilon.TestMaxTLAB - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=12345 gc.epsilon.TestMaxTLAB - * - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=1 -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 gc.epsilon.TestMaxTLAB - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=1K -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 gc.epsilon.TestMaxTLAB - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=1M -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 gc.epsilon.TestMaxTLAB - * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:EpsilonMaxTLABSize=12345 -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 gc.epsilon.TestMaxTLAB + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=1 + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=1K + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=1M + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=12345 + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=1 + * -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=1K + * -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=1M + * -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * gc.epsilon.TestMaxTLAB + * + * @run main/othervm -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonMaxTLABSize=12345 + * -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * gc.epsilon.TestMaxTLAB */ public class TestMaxTLAB { diff --git a/test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java b/test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java index 597ce76f829..a9ff8d00ba0 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java +++ b/test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java @@ -30,9 +30,21 @@ * @summary Test JMX memory beans * @modules java.base/jdk.internal.misc * java.management - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx1g gc.epsilon.TestMemoryMXBeans -1 1024 - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xms1g -Xmx1g gc.epsilon.TestMemoryMXBeans 1024 1024 - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xms128m -Xmx1g gc.epsilon.TestMemoryMXBeans 128 1024 + * + * @run main/othervm -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestMemoryMXBeans + * -1 256 + * + * @run main/othervm -Xmx256m -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestMemoryMXBeans + * 256 256 + * + * @run main/othervm -Xms64m -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestMemoryMXBeans + * 64 256 */ import java.lang.management.*; diff --git a/test/hotspot/jtreg/gc/epsilon/TestMemoryPools.java b/test/hotspot/jtreg/gc/epsilon/TestMemoryPools.java index 90b5471cb7f..e05a257edc7 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestMemoryPools.java +++ b/test/hotspot/jtreg/gc/epsilon/TestMemoryPools.java @@ -26,11 +26,14 @@ /** * @test TestMemoryPools - * @requires vm.gc.Epsilon & os.maxMemory >= 2G + * @requires vm.gc.Epsilon * @summary Test JMX memory pools * @modules java.base/jdk.internal.misc * java.management - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx1g -Xms1g gc.epsilon.TestMemoryPools + * + * @run main/othervm -Xms64m -Xmx64m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestMemoryPools */ import java.lang.management.*; diff --git a/test/hotspot/jtreg/gc/epsilon/TestObjects.java b/test/hotspot/jtreg/gc/epsilon/TestObjects.java index 7cb5c4a8ae3..a63896fd19b 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestObjects.java +++ b/test/hotspot/jtreg/gc/epsilon/TestObjects.java @@ -30,17 +30,43 @@ * @summary Epsilon is able to allocate objects, and does not corrupt their state * @library /test/lib * - * @run main/othervm -Xmx128m -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects * - * @run main/othervm -Xmx128m -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xint -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects - * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:-TieredCompilation -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestObjects + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects + * + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects + * + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestObjects */ import java.util.Random; diff --git a/test/hotspot/jtreg/gc/epsilon/TestPrintHeapSteps.java b/test/hotspot/jtreg/gc/epsilon/TestPrintHeapSteps.java index 5feef31b381..fb131b86eaa 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestPrintHeapSteps.java +++ b/test/hotspot/jtreg/gc/epsilon/TestPrintHeapSteps.java @@ -27,9 +27,21 @@ * @test TestPrintSteps * @requires vm.gc.Epsilon * @summary Tests -XX:EpsilonPrintHeapSteps works - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonPrintHeapSteps=0 gc.epsilon.TestPrintHeapSteps - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonPrintHeapSteps=1 gc.epsilon.TestPrintHeapSteps - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonPrintHeapSteps=1000 gc.epsilon.TestPrintHeapSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonPrintHeapSteps=0 + * gc.epsilon.TestPrintHeapSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonPrintHeapSteps=1 + * gc.epsilon.TestPrintHeapSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonPrintHeapSteps=1000 + * gc.epsilon.TestPrintHeapSteps */ public class TestPrintHeapSteps { diff --git a/test/hotspot/jtreg/gc/epsilon/TestRefArrays.java b/test/hotspot/jtreg/gc/epsilon/TestRefArrays.java index 0dac53e4832..2be731eba62 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestRefArrays.java +++ b/test/hotspot/jtreg/gc/epsilon/TestRefArrays.java @@ -30,24 +30,50 @@ * @summary Epsilon is able to allocate arrays, and does not corrupt their state * @library /test/lib * - * @run main/othervm -Xmx1g -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays * - * @run main/othervm -Xmx1g -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xint -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays - * @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays + * + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays + * + * @run main/othervm -XX:+UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xint + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:TieredStopAtLevel=1 + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays + * + * @run main/othervm -XX:-UseTLAB -Xmx256m + * -Xbatch -Xcomp -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * gc.epsilon.TestRefArrays */ import java.util.Random; import jdk.test.lib.Utils; public class TestRefArrays { - static int COUNT = Integer.getInteger("count", 1000); // ~500 MB allocation + static int COUNT = Integer.getInteger("count", 200); // ~100 MB allocation static MyObject[][] arr; diff --git a/test/hotspot/jtreg/gc/epsilon/TestUpdateCountersSteps.java b/test/hotspot/jtreg/gc/epsilon/TestUpdateCountersSteps.java index 94e743f65c6..6bf15805313 100644 --- a/test/hotspot/jtreg/gc/epsilon/TestUpdateCountersSteps.java +++ b/test/hotspot/jtreg/gc/epsilon/TestUpdateCountersSteps.java @@ -27,10 +27,26 @@ * @test TestUpdateCountersSteps * @requires vm.gc.Epsilon * @summary Test EpsilonUpdateCountersStep works - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonUpdateCountersStep=1 gc.epsilon.TestUpdateCountersSteps - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonUpdateCountersStep=10 gc.epsilon.TestUpdateCountersSteps - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonUpdateCountersStep=100 gc.epsilon.TestUpdateCountersSteps - * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xlog:gc -XX:EpsilonUpdateCountersStep=1000 gc.epsilon.TestUpdateCountersSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonUpdateCountersStep=1 + * gc.epsilon.TestUpdateCountersSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonUpdateCountersStep=10 + * gc.epsilon.TestUpdateCountersSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonUpdateCountersStep=100 + * gc.epsilon.TestUpdateCountersSteps + * + * @run main/othervm -Xmx64m -Xlog:gc + * -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC + * -XX:EpsilonUpdateCountersStep=1000 + * gc.epsilon.TestUpdateCountersSteps */ public class TestUpdateCountersSteps { From c96cfed51d86a428b46a86355c6ec6095c9d4644 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Thu, 9 Sep 2021 07:56:06 +0000 Subject: [PATCH 029/253] 8270171: Shenandoah: Cleanup TestStringDedup and TestStringDedupStress tests Backport-of: e4c24f01ef97de1c9a5a5faca5dd8ea2ad8c62d9 --- .../hotspot/jtreg/gc/shenandoah/TestStringDedup.java | 9 --------- .../jtreg/gc/shenandoah/TestStringDedupStress.java | 12 +----------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/test/hotspot/jtreg/gc/shenandoah/TestStringDedup.java b/test/hotspot/jtreg/gc/shenandoah/TestStringDedup.java index e7fd4d70c41..94691432f38 100644 --- a/test/hotspot/jtreg/gc/shenandoah/TestStringDedup.java +++ b/test/hotspot/jtreg/gc/shenandoah/TestStringDedup.java @@ -49,7 +49,6 @@ * @key randomness * @requires vm.gc.Shenandoah * @library /test/lib - * @modules java.base/jdk.internal.misc:open * @modules java.base/java.lang:open * java.management * @@ -72,7 +71,6 @@ * @key randomness * @requires vm.gc.Shenandoah * @library /test/lib - * @modules java.base/jdk.internal.misc:open * @modules java.base/java.lang:open * java.management * @@ -89,11 +87,8 @@ import java.util.*; import jdk.test.lib.Utils; -import sun.misc.*; - public class TestStringDedup { private static Field valueField; - private static Unsafe unsafe; private static final int UniqueStrings = 20; // How many GC cycles are needed to complete deduplication. @@ -101,10 +96,6 @@ public class TestStringDedup { static { try { - Field field = Unsafe.class.getDeclaredField("theUnsafe"); - field.setAccessible(true); - unsafe = (Unsafe) field.get(null); - valueField = String.class.getDeclaredField("value"); valueField.setAccessible(true); } catch (Exception e) { diff --git a/test/hotspot/jtreg/gc/shenandoah/TestStringDedupStress.java b/test/hotspot/jtreg/gc/shenandoah/TestStringDedupStress.java index 49e03aca088..90b383d0587 100644 --- a/test/hotspot/jtreg/gc/shenandoah/TestStringDedupStress.java +++ b/test/hotspot/jtreg/gc/shenandoah/TestStringDedupStress.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * Copyright (c) 2017, 2021, Red Hat, Inc. 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 @@ -28,7 +28,6 @@ * @key randomness * @requires vm.gc.Shenandoah * @library /test/lib - * @modules java.base/jdk.internal.misc:open * @modules java.base/java.lang:open * java.management * @@ -49,7 +48,6 @@ * @key randomness * @requires vm.gc.Shenandoah * @library /test/lib - * @modules java.base/jdk.internal.misc:open * @modules java.base/java.lang:open * java.management * @@ -80,7 +78,6 @@ * @key randomness * @requires vm.gc.Shenandoah * @library /test/lib - * @modules java.base/jdk.internal.misc:open * @modules java.base/java.lang:open * java.management * @@ -111,11 +108,8 @@ import java.util.*; import jdk.test.lib.Utils; -import sun.misc.*; - public class TestStringDedupStress { private static Field valueField; - private static Unsafe unsafe; private static final int TARGET_STRINGS = Integer.getInteger("targetStrings", 2_500_000); private static final long MAX_REWRITE_GC_CYCLES = 6; @@ -125,10 +119,6 @@ public class TestStringDedupStress { static { try { - Field field = Unsafe.class.getDeclaredField("theUnsafe"); - field.setAccessible(true); - unsafe = (Unsafe) field.get(null); - valueField = String.class.getDeclaredField("value"); valueField.setAccessible(true); } catch (Exception e) { From d561554fdfd9a00b4e9a4a02f0f5d819fca3ac54 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Thu, 9 Sep 2021 07:57:56 +0000 Subject: [PATCH 030/253] 8270110: Shenandoah: Add test for JDK-8269661 Backport-of: 548bb3119cf792bb1e65e15e990a4addc9155312 --- .../share/gc/shenandoah/shenandoahHeap.cpp | 5 +- .../jni/TestStringCriticalWithDedup.java | 166 ++++++++++++++++++ .../jni/libTestStringCriticalWithDedup.c | 38 ++++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java create mode 100644 test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index f0f40495ade..495ddef5965 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -1926,7 +1926,10 @@ oop ShenandoahHeap::pin_object(JavaThread* thr, oop o) { } void ShenandoahHeap::unpin_object(JavaThread* thr, oop o) { - heap_region_containing(o)->record_unpin(); + ShenandoahHeapRegion* r = heap_region_containing(o); + assert(r != NULL, "Sanity"); + assert(r->pin_count() > 0, "Region " SIZE_FORMAT " should have non-zero pins", r->index()); + r->record_unpin(); } void ShenandoahHeap::sync_pinned_region_status() { diff --git a/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java b/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java new file mode 100644 index 00000000000..8bd3d88951c --- /dev/null +++ b/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. All rights reserved. + * + * 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 TestStringCriticalWithDedup + * @summary Test string deduplication should not cause string critical to crash VM + * @requires vm.gc.Shenandoah + * @modules java.base/java.lang:open + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx512m + * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive -XX:+UseStringDeduplication -XX:-CompactStrings + * -XX:+ShenandoahVerify -XX:+ShenandoahDegeneratedGC -XX:ShenandoahTargetNumRegions=4096 + * TestStringCriticalWithDedup + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx512m + * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive -XX:+UseStringDeduplication -XX:-CompactStrings + * -XX:+ShenandoahVerify -XX:-ShenandoahDegeneratedGC -XX:ShenandoahTargetNumRegions=4096 + * TestStringCriticalWithDedup + */ + +/* @test TestPinnedGarbage + * @summary Test string deduplication should not cause string critical to crash VM + * @requires vm.gc.Shenandoah + * @modules java.base/java.lang:open + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx512m + * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+UseStringDeduplication -XX:-CompactStrings + * -XX:ShenandoahTargetNumRegions=4096 + * TestStringCriticalWithDedup + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx256m + * -XX:+UseShenandoahGC -XX:+UseStringDeduplication -XX:-CompactStrings + * -XX:ShenandoahTargetNumRegions=4096 -XX:+ShenandoahVerify + * TestStringCriticalWithDedup + */ + +import java.util.List; +import java.util.ArrayList; +import java.util.concurrent.*; +import java.lang.reflect.*; + +public class TestStringCriticalWithDedup { + private static Field valueField; + + static { + System.loadLibrary("TestStringCriticalWithDedup"); + try { + valueField = String.class.getDeclaredField("value"); + valueField.setAccessible(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static final int NUM_RUNS = 100; + private static final int STRING_COUNT = 1 << 16; + private static final int LITTLE_GARBAGE_COUNT = 1 << 5; + private static final int PINNED_STRING_COUNT = 1 << 4; + + private static native long pin(String s); + private static native void unpin(String s, long p); + + + private static volatile MyClass sink; + public static void main(String[] args) { + ThreadLocalRandom rng = ThreadLocalRandom.current(); + for (int i = 0; i < NUM_RUNS; i++) { + test(rng); + } + } + + private static Object getValue(String string) { + try { + return valueField.get(string); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static void pissiblePinString(ThreadLocalRandom rng, List pinnedList, String s) { + int oneInCounter = STRING_COUNT / PINNED_STRING_COUNT; + if (rng.nextInt(oneInCounter) == 1) { + long v = pin(s); + Object value = getValue(s); + pinnedList.add(new Tuple(s, value, v)); + } + } + + private static void test(ThreadLocalRandom rng) { + String[] strArray = new String[STRING_COUNT]; + List pinnedStrings = new ArrayList<>(PINNED_STRING_COUNT); + for (int i = 0; i < STRING_COUNT; i++) { + // Create some garbage inbetween, so strings can be scattered in + // different regions + createLittleGarbage(rng); + + strArray[i] = new String("Hello" + (i % 10)); + pissiblePinString(rng, pinnedStrings, strArray[i]); + } + + // Let deduplication thread to run a bit + try { + Thread.sleep(10); + } catch(Exception e) { + } + + for (int i = 0; i < pinnedStrings.size(); i ++) { + Tuple p = pinnedStrings.get(i); + String s = p.getString(); + if (getValue(s) != p.getValue()) { + System.out.println(getValue(s) + " != " + p.getValue()); + throw new RuntimeException("String value should be pinned"); + } + unpin(p.getString(), p.getValuePointer()); + } + } + + private static void createLittleGarbage(ThreadLocalRandom rng) { + int count = rng.nextInt(LITTLE_GARBAGE_COUNT); + for (int index = 0; index < count; index ++) { + sink = new MyClass(); + } + } + + private static class Tuple { + String s; + Object value; + long valuePointer; + public Tuple(String s, Object value, long vp) { + this.s = s; + this.value = value; + this.valuePointer = vp; + } + + public String getString() { + return s; + } + public Object getValue() { return value; } + public long getValuePointer() { + return valuePointer; + } + } + + private static class MyClass { + public long[] payload = new long[10]; + } +} diff --git a/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c b/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c new file mode 100644 index 00000000000..665ae585545 --- /dev/null +++ b/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. All rights reserved. + * + * 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. + * + */ + +#include +#include +#include + +JNIEXPORT jlong JNICALL +Java_TestStringCriticalWithDedup_pin(JNIEnv *env, jclass unused, jstring s) { + const jchar* a = (*env)->GetStringCritical(env, s, NULL); + return (jlong)(uintptr_t)a; +} + +JNIEXPORT void JNICALL +Java_TestStringCriticalWithDedup_unpin(JNIEnv *env, jclass unused, jstring s, jlong v) { + jchar* a = (jchar*)(uintptr_t)v; + (*env)->ReleaseStringCritical(env, s, a); +} From f1c8fa62d3274128cf02889c3de82d3c79987242 Mon Sep 17 00:00:00 2001 From: Per Liden Date: Thu, 9 Sep 2021 09:04:02 +0000 Subject: [PATCH 031/253] 8271121: ZGC: stack overflow (segv) when -Xlog:gc+start=debug Reviewed-by: eosterlund, ayang Backport-of: 18dd4d469d120276d05e74607d780f01056f1a8b --- src/hotspot/share/gc/z/zStat.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/gc/z/zStat.cpp b/src/hotspot/share/gc/z/zStat.cpp index 1d1067b9bb6..0df9d061087 100644 --- a/src/hotspot/share/gc/z/zStat.cpp +++ b/src/hotspot/share/gc/z/zStat.cpp @@ -760,8 +760,10 @@ ZStatCriticalPhase::ZStatCriticalPhase(const char* name, bool verbose) : _verbose(verbose) {} void ZStatCriticalPhase::register_start(const Ticks& start) const { - LogTarget(Debug, gc, start) log; - log_start(log, true /* thread */); + // This is called from sensitive contexts, for example before an allocation stall + // has been resolved. This means we must not access any oops in here since that + // could lead to infinite recursion. Without access to the thread name we can't + // really log anything useful here. } void ZStatCriticalPhase::register_end(const Ticks& start, const Ticks& end) const { From 6a7542fed04f4f161e023dde7b04643e39a3ef0b Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Thu, 9 Sep 2021 13:45:16 +0000 Subject: [PATCH 032/253] 8272973: Incorrect compile command used by TestIllegalArrayCopyBeforeInfiniteLoop Backport-of: 9166ba37b631aa7ae641488f6167cdbd7fcdff00 --- .../arraycopy/TestIllegalArrayCopyBeforeInfiniteLoop.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/compiler/arraycopy/TestIllegalArrayCopyBeforeInfiniteLoop.java b/test/hotspot/jtreg/compiler/arraycopy/TestIllegalArrayCopyBeforeInfiniteLoop.java index 33c0506a278..0b3572d6afa 100644 --- a/test/hotspot/jtreg/compiler/arraycopy/TestIllegalArrayCopyBeforeInfiniteLoop.java +++ b/test/hotspot/jtreg/compiler/arraycopy/TestIllegalArrayCopyBeforeInfiniteLoop.java @@ -27,7 +27,7 @@ * @requires vm.compiler2.enabled * @summary ArrayCopy with negative index before infinite loop * @run main/othervm -Xbatch -XX:-TieredCompilation - * -XX:CompileCommand=compileonly,"*TestIllegalArrayCopyBeforeInfiniteLoop::foo" + * -XX:CompileCommand=compileonly,compiler.arraycopy.TestIllegalArrayCopyBeforeInfiniteLoop::foo * compiler.arraycopy.TestIllegalArrayCopyBeforeInfiniteLoop */ @@ -38,7 +38,7 @@ public class TestIllegalArrayCopyBeforeInfiniteLoop { private static char src[] = new char[10]; private static int count = 0; - private static final int iter = 10_000; + private static final int iter = 20_000; public static void main(String[] args) throws Exception { for (int i = 0; i < iter; ++i) { From 9f7de5900603f89a2d87a2135acc125a84778669 Mon Sep 17 00:00:00 2001 From: Saravana Kumar Vijayasekaran Date: Thu, 9 Sep 2021 18:24:13 +0000 Subject: [PATCH 033/253] 8263773: Reenable German localization for builds at Oracle Reviewed-by: erikj --- make/conf/jib-profiles.js | 2 +- test/jdk/build/translations/VerifyTranslations.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js index 0140dee7d5c..b16475c2f08 100644 --- a/make/conf/jib-profiles.js +++ b/make/conf/jib-profiles.js @@ -249,7 +249,7 @@ var getJibProfilesCommon = function (input, data) { dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh", "jcov"], default_make_targets: ["product-bundles", "test-bundles", "static-libs-bundles"], configure_args: concat("--enable-jtreg-failure-handler", - "--with-exclude-translations=de,es,fr,it,ko,pt_BR,sv,ca,tr,cs,sk,ja_JP_A,ja_JP_HA,ja_JP_HI,ja_JP_I,zh_TW,zh_HK", + "--with-exclude-translations=es,fr,it,ko,pt_BR,sv,ca,tr,cs,sk,ja_JP_A,ja_JP_HA,ja_JP_HI,ja_JP_I,zh_TW,zh_HK", "--disable-manpages", "--disable-jvm-feature-shenandoahgc", versionArgs(input, common)) diff --git a/test/jdk/build/translations/VerifyTranslations.java b/test/jdk/build/translations/VerifyTranslations.java index aa25a28cb9e..e9fa101da18 100644 --- a/test/jdk/build/translations/VerifyTranslations.java +++ b/test/jdk/build/translations/VerifyTranslations.java @@ -45,7 +45,7 @@ public class VerifyTranslations { * The set of translations we want to see in an Oracle built image */ private static final Set VALID_TRANSLATION_SUFFIXES = Set.of( - "_en", "_en_US", "_en_US_POSIX", "_ja", "_zh_CN" + "_en", "_en_US", "_en_US_POSIX", "_ja", "_zh_CN", "_de" ); /** From cef269f89633331a68c9549a08d2d88d5534b8fa Mon Sep 17 00:00:00 2001 From: Clive Verghese Date: Thu, 9 Sep 2021 19:21:18 +0000 Subject: [PATCH 034/253] 8270317: Large Allocation in CipherSuite Backport-of: e627caec84c169c99c04e0d355c29b806a0266ed --- .../classes/sun/security/ssl/CipherSuite.java | 108 ++++++++---------- .../bench/java/security/CipherSuiteBench.java | 58 ++++++++++ 2 files changed, 106 insertions(+), 60 deletions(-) create mode 100644 test/micro/org/openjdk/bench/java/security/CipherSuiteBench.java diff --git a/src/java.base/share/classes/sun/security/ssl/CipherSuite.java b/src/java.base/share/classes/sun/security/ssl/CipherSuite.java index 95246513a30..8500ae7e188 100644 --- a/src/java.base/share/classes/sun/security/ssl/CipherSuite.java +++ b/src/java.base/share/classes/sun/security/ssl/CipherSuite.java @@ -25,12 +25,8 @@ package sun.security.ssl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; +import java.util.*; + import static sun.security.ssl.CipherSuite.HashAlg.*; import static sun.security.ssl.CipherSuite.KeyExchange.*; import static sun.security.ssl.CipherSuite.MacAlg.*; @@ -857,6 +853,39 @@ enum CipherSuite { final boolean exportable; + private static final Map cipherSuiteIds; + private static final Map cipherSuiteNames; + private static final List allowedCipherSuites; + private static final List defaultCipherSuites; + + static { + Map ids = new HashMap<>(); + Map names = new HashMap<>(); + List allowedCS = new ArrayList<>(); + List defaultCS = new ArrayList<>(); + + for(CipherSuite cs : CipherSuite.values()) { + ids.put(cs.id, cs); + names.put(cs.name, cs); + for (String alias : cs.aliases) { + names.put(alias, cs); + } + + if (!cs.supportedProtocols.isEmpty()) { + allowedCS.add(cs); + } + + if (cs.isDefaultEnabled) { + defaultCS.add(cs); + } + } + + cipherSuiteIds = Map.copyOf(ids); + cipherSuiteNames = Map.copyOf(names); + allowedCipherSuites = List.copyOf(allowedCS); + defaultCipherSuites = List.copyOf(defaultCS); + } + // known but unsupported cipher suite private CipherSuite(String name, int id) { this(id, false, name, "", @@ -894,62 +923,29 @@ private CipherSuite(int id, boolean isDefaultEnabled, } static CipherSuite nameOf(String ciperSuiteName) { - for (CipherSuite cs : CipherSuite.values()) { - if (cs.name.equals(ciperSuiteName) || - cs.aliases.contains(ciperSuiteName)) { - return cs; - } - } - - return null; + return cipherSuiteNames.get(ciperSuiteName); } static CipherSuite valueOf(int id) { - for (CipherSuite cs : CipherSuite.values()) { - if (cs.id == id) { - return cs; - } - } - - return null; + return cipherSuiteIds.get(id); } static String nameOf(int id) { - for (CipherSuite cs : CipherSuite.values()) { - if (cs.id == id) { - return cs.name; - } + CipherSuite cs = cipherSuiteIds.get(id); + + if (cs != null) { + return cs.name; } return "UNKNOWN-CIPHER-SUITE(" + Utilities.byte16HexString(id) + ")"; } static Collection allowedCipherSuites() { - Collection cipherSuites = new LinkedList<>(); - for (CipherSuite cs : CipherSuite.values()) { - if (!cs.supportedProtocols.isEmpty()) { - cipherSuites.add(cs); - } else { - // values() is ordered, remaining cipher suites are - // not supported. - break; - } - } - return cipherSuites; + return allowedCipherSuites; } static Collection defaultCipherSuites() { - Collection cipherSuites = new LinkedList<>(); - for (CipherSuite cs : CipherSuite.values()) { - if (cs.isDefaultEnabled) { - cipherSuites.add(cs); - } else { - // values() is ordered, remaining cipher suites are - // not enabled. - break; - } - } - return cipherSuites; + return defaultCipherSuites; } /** @@ -972,19 +968,11 @@ static List validValuesOf(String[] names) { } boolean found = false; - for (CipherSuite cs : CipherSuite.values()) { - if (!cs.supportedProtocols.isEmpty()) { - if (cs.name.equals(name) || - cs.aliases.contains(name)) { - cipherSuites.add(cs); - found = true; - break; - } - } else { - // values() is ordered, remaining cipher suites are - // not supported. - break; - } + CipherSuite cs; + if ((cs = cipherSuiteNames.get(name)) != null + && !cs.supportedProtocols.isEmpty()) { + cipherSuites.add(cs); + found = true; } if (!found) { throw new IllegalArgumentException( diff --git a/test/micro/org/openjdk/bench/java/security/CipherSuiteBench.java b/test/micro/org/openjdk/bench/java/security/CipherSuiteBench.java new file mode 100644 index 00000000000..8703e85fef0 --- /dev/null +++ b/test/micro/org/openjdk/bench/java/security/CipherSuiteBench.java @@ -0,0 +1,58 @@ +/* + * 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. + * + */ +package org.openjdk.bench.java.security; + +import org.openjdk.jmh.annotations.*; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.concurrent.TimeUnit; + + +@Fork(jvmArgsAppend = {"--add-exports", "java.base/sun.security.ssl=ALL-UNNAMED", "--add-opens", "java.base/sun.security.ssl=ALL-UNNAMED"}) +@State(Scope.Benchmark) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@BenchmarkMode(Mode.Throughput) +public class CipherSuiteBench { + + Method nameOf; + + @Param({"TLS_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" }) + String cipherSuite; + + @Setup + public void initilizeClass() throws ClassNotFoundException, NoSuchMethodException { + Class cs = Class.forName("sun.security.ssl.CipherSuite"); + nameOf = cs.getDeclaredMethod("nameOf", String.class); + nameOf.setAccessible(true); + } + + @Benchmark + public Object benchmarkCipherSuite() throws InvocationTargetException, IllegalAccessException { + return nameOf.invoke(null,cipherSuite); + } +} From a37254c79fa5973465d90f4b52ab88fe68016c9f Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Thu, 9 Sep 2021 19:31:35 +0000 Subject: [PATCH 035/253] 8271868: Warn user when using mac-sign option with unsigned app-image. Reviewed-by: asemenyuk --- .../jdk/jpackage/internal/MacAppBundler.java | 3 ++- .../jpackage/internal/MacAppImageBuilder.java | 14 ++----------- .../internal/MacBaseInstallerBundler.java | 16 +++++++++++++++ .../jdk/jpackage/internal/MacPkgBundler.java | 5 +++-- .../resources/MacResources.properties | 3 ++- .../resources/MacResources_ja.properties | 1 + .../resources/MacResources_zh_CN.properties | 1 + .../jdk/jpackage/internal/AppImageFile.java | 20 ++++++++++++++++--- .../internal/StandardBundlerParam.java | 10 ++++++++++ 9 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java index ae10e64abde..9d79baaa22b 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java @@ -35,6 +35,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.MAIN_CLASS; import static jdk.jpackage.internal.StandardBundlerParam.VERBOSE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class MacAppBundler extends AppImageBundler { public MacAppBundler() { @@ -125,7 +126,7 @@ private static void doValidate(Map params) } // reject explicitly set sign to true and no valid signature key - if (Optional.ofNullable(MacAppImageBuilder. + if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { String signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params); diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java index 06af1ed2db0..f1eed5f5f15 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, 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 @@ -66,6 +66,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class MacAppImageBuilder extends AbstractAppImageBuilder { @@ -143,16 +144,6 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder { }, (s, p) -> Path.of(s)); - public static final StandardBundlerParam SIGN_BUNDLE = - new StandardBundlerParam<>( - Arguments.CLIOptions.MAC_SIGN.getId(), - Boolean.class, - params -> false, - // valueOf(null) is false, we actually do want null in some cases - (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? - null : Boolean.valueOf(s) - ); - public static final StandardBundlerParam APP_STORE = new StandardBundlerParam<>( Arguments.CLIOptions.MAC_APP_STORE.getId(), @@ -863,5 +854,4 @@ private static String extractBundleIdentifier(Map params) { return null; } - } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java index 8e1bbfc5883..28eee6bdc4e 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; @@ -41,6 +42,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR; import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public abstract class MacBaseInstallerBundler extends AbstractBundler { @@ -134,6 +136,20 @@ protected void validateAppImageAndBundeler( I18N.getString( "message.app-image-requires-app-name.advice")); } + if (Optional.ofNullable( + SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { + // if signing bundle with app-image, warn user if app-image + // is not allready signed. + try { + if (!(AppImageFile.load(applicationImage).isSigned())) { + Log.info(MessageFormat.format(I18N.getString( + "warning.unsigned.app.image"), getID())); + } + } catch (IOException ioe) { + // Ignore - In case of a forign or tampered with app-image, + // user is notified of this when the name is extracted. + } + } } else { appImageBundler.validate(params); } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java index 2d436c244dc..df9755b08dd 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java @@ -46,6 +46,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN; import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER; import static jdk.jpackage.internal.MacAppImageBuilder.APP_STORE; @@ -499,7 +500,7 @@ private Path createPKG(Map params, commandLine.add(CONFIG_ROOT.fetchFrom(params).toAbsolutePath().toString()); // maybe sign - if (Optional.ofNullable(MacAppImageBuilder. + if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { if (Platform.getMajorVersion() > 10 || (Platform.getMajorVersion() == 10 && @@ -603,7 +604,7 @@ public boolean validate(Map params) } // reject explicitly set sign to true and no valid signature key - if (Optional.ofNullable(MacAppImageBuilder. + if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { String signingIdentity = DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties index 71075354542..23a4f9d0437 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2021, 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,3 +88,4 @@ message.preparing-distribution-dist=Preparing distribution.dist: {0}. message.signing.pkg=Warning: For signing PKG, you might need to set "Always Trust" for your certificate using "Keychain Access" tool. message.setfile.dmg=Setting custom icon on DMG file skipped because 'SetFile' utility was not found. Installing Xcode with Command Line Tools should resolve this issue. message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. +warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties index 08cd0819495..d9da226ec92 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties @@ -87,3 +87,4 @@ message.preparing-distribution-dist=distribution.dist\u3092\u6E96\u5099\u3057\u3 message.signing.pkg=\u8B66\u544A: PKG\u3078\u306E\u7F72\u540D\u306E\u5834\u5408\u3001\u300C\u30AD\u30FC\u30C1\u30A7\u30FC\u30F3\u30FB\u30A2\u30AF\u30BB\u30B9\u300D\u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A3C\u660E\u66F8\u306B\u300C\u5E38\u306B\u4FE1\u983C\u3059\u308B\u300D\u3092\u8A2D\u5B9A\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\u3002 message.setfile.dmg='SetFile'\u30E6\u30FC\u30C6\u30A3\u30EA\u30C6\u30A3\u304C\u898B\u3064\u304B\u3089\u306A\u3044\u305F\u3081\u3001DMG\u30D5\u30A1\u30A4\u30EB\u3067\u306E\u30AB\u30B9\u30BF\u30E0\u30FB\u30A2\u30A4\u30B3\u30F3\u306E\u8A2D\u5B9A\u304C\u30B9\u30AD\u30C3\u30D7\u3055\u308C\u307E\u3057\u305F\u3002Xcode\u3068\u30B3\u30DE\u30F3\u30C9\u30FB\u30E9\u30A4\u30F3\u30FB\u30C4\u30FC\u30EB\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3059\u308B\u3068\u3001\u3053\u306E\u554F\u984C\u306F\u89E3\u6C7A\u3055\u308C\u307E\u3059\u3002 message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. +warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties index c2bfdf96963..d6f47a7bc85 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties @@ -87,3 +87,4 @@ message.preparing-distribution-dist=\u6B63\u5728\u51C6\u5907 distribution.dist: message.signing.pkg=\u8B66\u544A\uFF1A\u8981\u5BF9 PKG \u8FDB\u884C\u7B7E\u540D\uFF0C\u53EF\u80FD\u9700\u8981\u4F7F\u7528\u201C\u5BC6\u94A5\u94FE\u8BBF\u95EE\u201D\u5DE5\u5177\u4E3A\u8BC1\u4E66\u8BBE\u7F6E\u201C\u59CB\u7EC8\u4FE1\u4EFB\u201D\u3002 message.setfile.dmg=\u7531\u4E8E\u672A\u627E\u5230 'SetFile' \u5B9E\u7528\u7A0B\u5E8F\uFF0C\u8DF3\u8FC7\u4E86\u9488\u5BF9 DMG \u6587\u4EF6\u8BBE\u7F6E\u5B9A\u5236\u56FE\u6807\u7684\u64CD\u4F5C\u3002\u5B89\u88C5\u5E26\u547D\u4EE4\u884C\u5DE5\u5177\u7684 Xcode \u5E94\u80FD\u89E3\u51B3\u6B64\u95EE\u9898\u3002 message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. +warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java index dd1993f179c..655a0d10f25 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java @@ -46,6 +46,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class AppImageFile { @@ -54,6 +55,7 @@ public class AppImageFile { private final String creatorPlatform; private final String launcherName; private final List addLauncherNames; + private final boolean signed; private static final String FILENAME = ".jpackage.xml"; @@ -63,15 +65,16 @@ public class AppImageFile { private AppImageFile() { - this(null, null, null, null); + this(null, null, null, null, null); } private AppImageFile(String launcherName, List addLauncherNames, - String creatorVersion, String creatorPlatform) { + String creatorVersion, String creatorPlatform, String signedStr) { this.launcherName = launcherName; this.addLauncherNames = addLauncherNames; this.creatorVersion = creatorVersion; this.creatorPlatform = creatorPlatform; + this.signed = "true".equals(signedStr); } /** @@ -90,6 +93,10 @@ String getLauncherName() { return launcherName; } + boolean isSigned() { + return signed; + } + void verifyCompatible() throws ConfigException { // Just do nothing for now. } @@ -125,6 +132,10 @@ static void save(Path appImageDir, Map params) xml.writeCharacters(APP_NAME.fetchFrom(params)); xml.writeEndElement(); + xml.writeStartElement("signed"); + xml.writeCharacters(SIGN_BUNDLE.fetchFrom(params).toString()); + xml.writeEndElement(); + List> addLaunchers = ADD_LAUNCHERS.fetchFrom(params); @@ -164,6 +175,9 @@ static AppImageFile load(Path appImageDir) throws IOException { String version = xpathQueryNullable(xPath, "/jpackage-state/@version", doc); + String signedStr = xpathQueryNullable(xPath, + "/jpackage-state/@signed", doc); + NodeList launcherNameNodes = (NodeList) xPath.evaluate( "/jpackage-state/add-launcher/text()", doc, XPathConstants.NODESET); @@ -173,7 +187,7 @@ static AppImageFile load(Path appImageDir) throws IOException { } AppImageFile file = new AppImageFile( - mainLauncher, addLaunchers, version, platform); + mainLauncher, addLaunchers, version, platform, signedStr); if (!file.isValid()) { file = new AppImageFile(); } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java index edf6e368fd4..113dc0d4749 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java @@ -467,6 +467,16 @@ private static Path findPathOfModule( List modulePath, String moduleName) (s, p) -> new LinkedHashSet<>(Arrays.asList(s.split(","))) ); + static final StandardBundlerParam SIGN_BUNDLE = + new StandardBundlerParam<>( + Arguments.CLIOptions.MAC_SIGN.getId(), + Boolean.class, + params -> false, + (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? + null : Boolean.valueOf(s) + ); + + static boolean isRuntimeInstaller(Map params) { if (params.containsKey(MODULE.getID()) || params.containsKey(MAIN_JAR.getID()) || From f7f9a73a1e73576fd276fdc2a6305c136a2dde52 Mon Sep 17 00:00:00 2001 From: Rob McKenna Date: Thu, 9 Sep 2021 21:57:38 +0000 Subject: [PATCH 036/253] 8270498: Improve SAX Parser configuration management Reviewed-by: joehw --- .../internal/impl/XMLEntityManager.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java index 7dbdf607513..8a01f74e790 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java @@ -91,7 +91,7 @@ * @author K.Venugopal SUN Microsystems * @author Neeraj Bajaj SUN Microsystems * @author Sunitha Reddy SUN Microsystems - * @LastModified: May 2021 + * @LastModified: Aug 2021 */ public class XMLEntityManager implements XMLComponent, XMLEntityResolver { @@ -1235,7 +1235,7 @@ public void startEntity(boolean isGE, String entityName, boolean literal) externalEntity = (Entity.ExternalEntity)entity; extLitSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getLiteralSystemId() : null); extBaseSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getBaseSystemId() : null); - expandedSystemId = expandSystemId(extLitSysId, extBaseSysId); + expandedSystemId = expandSystemId(extLitSysId, extBaseSysId, fStrictURI); boolean unparsed = entity.isUnparsed(); boolean parameter = entityName.startsWith("%"); boolean general = !parameter; @@ -1312,15 +1312,13 @@ public void startEntity(boolean isGE, String entityName, boolean literal) */ xmlInputSource = staxInputSource.getXMLInputSource() ; if (!fISCreatedByResolver) { - //let the not-LoadExternalDTD or not-SupportDTD process to handle the situation - if (fLoadExternalDTD) { - String accessError = SecuritySupport.checkAccess(expandedSystemId, fAccessExternalDTD, JdkConstants.ACCESS_EXTERNAL_ALL); - if (accessError != null) { - fErrorReporter.reportError(this.getEntityScanner(),XMLMessageFormatter.XML_DOMAIN, - "AccessExternalEntity", - new Object[] { SecuritySupport.sanitizePath(expandedSystemId), accessError }, - XMLErrorReporter.SEVERITY_FATAL_ERROR); - } + String accessError = SecuritySupport.checkAccess(expandedSystemId, + fAccessExternalDTD, JdkConstants.ACCESS_EXTERNAL_ALL); + if (accessError != null) { + fErrorReporter.reportError(this.getEntityScanner(),XMLMessageFormatter.XML_DOMAIN, + "AccessExternalEntity", + new Object[] { SecuritySupport.sanitizePath(expandedSystemId), accessError }, + XMLErrorReporter.SEVERITY_FATAL_ERROR); } } } From 4afbcaf55383ec2f5da53282a1547bac3d099e9d Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Fri, 10 Sep 2021 14:17:45 +0000 Subject: [PATCH 037/253] 8273592: Backout JDK-8271868 Reviewed-by: kcr, asemenyuk --- .../jdk/jpackage/internal/MacAppBundler.java | 3 +-- .../jpackage/internal/MacAppImageBuilder.java | 14 +++++++++++-- .../internal/MacBaseInstallerBundler.java | 16 --------------- .../jdk/jpackage/internal/MacPkgBundler.java | 5 ++--- .../resources/MacResources.properties | 3 +-- .../resources/MacResources_ja.properties | 1 - .../resources/MacResources_zh_CN.properties | 1 - .../jdk/jpackage/internal/AppImageFile.java | 20 +++---------------- .../internal/StandardBundlerParam.java | 10 ---------- 9 files changed, 19 insertions(+), 54 deletions(-) diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java index 9d79baaa22b..ae10e64abde 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java @@ -35,7 +35,6 @@ import static jdk.jpackage.internal.StandardBundlerParam.MAIN_CLASS; import static jdk.jpackage.internal.StandardBundlerParam.VERBOSE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; -import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class MacAppBundler extends AppImageBundler { public MacAppBundler() { @@ -126,7 +125,7 @@ private static void doValidate(Map params) } // reject explicitly set sign to true and no valid signature key - if (Optional.ofNullable( + if (Optional.ofNullable(MacAppImageBuilder. SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { String signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params); diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java index f1eed5f5f15..06af1ed2db0 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2020, 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 @@ -66,7 +66,6 @@ import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; -import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class MacAppImageBuilder extends AbstractAppImageBuilder { @@ -144,6 +143,16 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder { }, (s, p) -> Path.of(s)); + public static final StandardBundlerParam SIGN_BUNDLE = + new StandardBundlerParam<>( + Arguments.CLIOptions.MAC_SIGN.getId(), + Boolean.class, + params -> false, + // valueOf(null) is false, we actually do want null in some cases + (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? + null : Boolean.valueOf(s) + ); + public static final StandardBundlerParam APP_STORE = new StandardBundlerParam<>( Arguments.CLIOptions.MAC_APP_STORE.getId(), @@ -854,4 +863,5 @@ private static String extractBundleIdentifier(Map params) { return null; } + } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java index 28eee6bdc4e..8e1bbfc5883 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; @@ -42,7 +41,6 @@ import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR; import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; -import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public abstract class MacBaseInstallerBundler extends AbstractBundler { @@ -136,20 +134,6 @@ protected void validateAppImageAndBundeler( I18N.getString( "message.app-image-requires-app-name.advice")); } - if (Optional.ofNullable( - SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { - // if signing bundle with app-image, warn user if app-image - // is not allready signed. - try { - if (!(AppImageFile.load(applicationImage).isSigned())) { - Log.info(MessageFormat.format(I18N.getString( - "warning.unsigned.app.image"), getID())); - } - } catch (IOException ioe) { - // Ignore - In case of a forign or tampered with app-image, - // user is notified of this when the name is extracted. - } - } } else { appImageBundler.validate(params); } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java index df9755b08dd..2d436c244dc 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java @@ -46,7 +46,6 @@ import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; -import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN; import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER; import static jdk.jpackage.internal.MacAppImageBuilder.APP_STORE; @@ -500,7 +499,7 @@ private Path createPKG(Map params, commandLine.add(CONFIG_ROOT.fetchFrom(params).toAbsolutePath().toString()); // maybe sign - if (Optional.ofNullable( + if (Optional.ofNullable(MacAppImageBuilder. SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { if (Platform.getMajorVersion() > 10 || (Platform.getMajorVersion() == 10 && @@ -604,7 +603,7 @@ public boolean validate(Map params) } // reject explicitly set sign to true and no valid signature key - if (Optional.ofNullable( + if (Optional.ofNullable(MacAppImageBuilder. SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { String signingIdentity = DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties index 23a4f9d0437..71075354542 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2020, 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,4 +88,3 @@ message.preparing-distribution-dist=Preparing distribution.dist: {0}. message.signing.pkg=Warning: For signing PKG, you might need to set "Always Trust" for your certificate using "Keychain Access" tool. message.setfile.dmg=Setting custom icon on DMG file skipped because 'SetFile' utility was not found. Installing Xcode with Command Line Tools should resolve this issue. message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. -warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties index d9da226ec92..08cd0819495 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties @@ -87,4 +87,3 @@ message.preparing-distribution-dist=distribution.dist\u3092\u6E96\u5099\u3057\u3 message.signing.pkg=\u8B66\u544A: PKG\u3078\u306E\u7F72\u540D\u306E\u5834\u5408\u3001\u300C\u30AD\u30FC\u30C1\u30A7\u30FC\u30F3\u30FB\u30A2\u30AF\u30BB\u30B9\u300D\u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A3C\u660E\u66F8\u306B\u300C\u5E38\u306B\u4FE1\u983C\u3059\u308B\u300D\u3092\u8A2D\u5B9A\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\u3002 message.setfile.dmg='SetFile'\u30E6\u30FC\u30C6\u30A3\u30EA\u30C6\u30A3\u304C\u898B\u3064\u304B\u3089\u306A\u3044\u305F\u3081\u3001DMG\u30D5\u30A1\u30A4\u30EB\u3067\u306E\u30AB\u30B9\u30BF\u30E0\u30FB\u30A2\u30A4\u30B3\u30F3\u306E\u8A2D\u5B9A\u304C\u30B9\u30AD\u30C3\u30D7\u3055\u308C\u307E\u3057\u305F\u3002Xcode\u3068\u30B3\u30DE\u30F3\u30C9\u30FB\u30E9\u30A4\u30F3\u30FB\u30C4\u30FC\u30EB\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3059\u308B\u3068\u3001\u3053\u306E\u554F\u984C\u306F\u89E3\u6C7A\u3055\u308C\u307E\u3059\u3002 message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. -warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties index d6f47a7bc85..c2bfdf96963 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties @@ -87,4 +87,3 @@ message.preparing-distribution-dist=\u6B63\u5728\u51C6\u5907 distribution.dist: message.signing.pkg=\u8B66\u544A\uFF1A\u8981\u5BF9 PKG \u8FDB\u884C\u7B7E\u540D\uFF0C\u53EF\u80FD\u9700\u8981\u4F7F\u7528\u201C\u5BC6\u94A5\u94FE\u8BBF\u95EE\u201D\u5DE5\u5177\u4E3A\u8BC1\u4E66\u8BBE\u7F6E\u201C\u59CB\u7EC8\u4FE1\u4EFB\u201D\u3002 message.setfile.dmg=\u7531\u4E8E\u672A\u627E\u5230 'SetFile' \u5B9E\u7528\u7A0B\u5E8F\uFF0C\u8DF3\u8FC7\u4E86\u9488\u5BF9 DMG \u6587\u4EF6\u8BBE\u7F6E\u5B9A\u5236\u56FE\u6807\u7684\u64CD\u4F5C\u3002\u5B89\u88C5\u5E26\u547D\u4EE4\u884C\u5DE5\u5177\u7684 Xcode \u5E94\u80FD\u89E3\u51B3\u6B64\u95EE\u9898\u3002 message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. -warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java index 655a0d10f25..dd1993f179c 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java @@ -46,7 +46,6 @@ import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; -import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class AppImageFile { @@ -55,7 +54,6 @@ public class AppImageFile { private final String creatorPlatform; private final String launcherName; private final List addLauncherNames; - private final boolean signed; private static final String FILENAME = ".jpackage.xml"; @@ -65,16 +63,15 @@ public class AppImageFile { private AppImageFile() { - this(null, null, null, null, null); + this(null, null, null, null); } private AppImageFile(String launcherName, List addLauncherNames, - String creatorVersion, String creatorPlatform, String signedStr) { + String creatorVersion, String creatorPlatform) { this.launcherName = launcherName; this.addLauncherNames = addLauncherNames; this.creatorVersion = creatorVersion; this.creatorPlatform = creatorPlatform; - this.signed = "true".equals(signedStr); } /** @@ -93,10 +90,6 @@ String getLauncherName() { return launcherName; } - boolean isSigned() { - return signed; - } - void verifyCompatible() throws ConfigException { // Just do nothing for now. } @@ -132,10 +125,6 @@ static void save(Path appImageDir, Map params) xml.writeCharacters(APP_NAME.fetchFrom(params)); xml.writeEndElement(); - xml.writeStartElement("signed"); - xml.writeCharacters(SIGN_BUNDLE.fetchFrom(params).toString()); - xml.writeEndElement(); - List> addLaunchers = ADD_LAUNCHERS.fetchFrom(params); @@ -175,9 +164,6 @@ static AppImageFile load(Path appImageDir) throws IOException { String version = xpathQueryNullable(xPath, "/jpackage-state/@version", doc); - String signedStr = xpathQueryNullable(xPath, - "/jpackage-state/@signed", doc); - NodeList launcherNameNodes = (NodeList) xPath.evaluate( "/jpackage-state/add-launcher/text()", doc, XPathConstants.NODESET); @@ -187,7 +173,7 @@ static AppImageFile load(Path appImageDir) throws IOException { } AppImageFile file = new AppImageFile( - mainLauncher, addLaunchers, version, platform, signedStr); + mainLauncher, addLaunchers, version, platform); if (!file.isValid()) { file = new AppImageFile(); } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java index 113dc0d4749..edf6e368fd4 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java @@ -467,16 +467,6 @@ private static Path findPathOfModule( List modulePath, String moduleName) (s, p) -> new LinkedHashSet<>(Arrays.asList(s.split(","))) ); - static final StandardBundlerParam SIGN_BUNDLE = - new StandardBundlerParam<>( - Arguments.CLIOptions.MAC_SIGN.getId(), - Boolean.class, - params -> false, - (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? - null : Boolean.valueOf(s) - ); - - static boolean isRuntimeInstaller(Map params) { if (params.containsKey(MODULE.getID()) || params.containsKey(MAIN_JAR.getID()) || From 0e847cfb151d1485483b7edd938c9113d703cd4b Mon Sep 17 00:00:00 2001 From: Lutz Schmidt Date: Sat, 11 Sep 2021 20:23:39 +0000 Subject: [PATCH 038/253] 8271490: [ppc] [s390]: Crash in JavaThread::pd_get_top_frame_for_profiling Backport-of: 276b07b36af01d339e48baada7a512451fe34afe --- src/hotspot/cpu/ppc/frame_ppc.cpp | 35 +++++++++++------- src/hotspot/cpu/s390/frame_s390.cpp | 37 +++++++++++-------- .../os_cpu/linux_ppc/thread_linux_ppc.cpp | 13 +++++++ .../os_cpu/linux_s390/thread_linux_s390.cpp | 37 +++++++++++++++++++ 4 files changed, 93 insertions(+), 29 deletions(-) diff --git a/src/hotspot/cpu/ppc/frame_ppc.cpp b/src/hotspot/cpu/ppc/frame_ppc.cpp index 36585185812..e59cc9e5128 100644 --- a/src/hotspot/cpu/ppc/frame_ppc.cpp +++ b/src/hotspot/cpu/ppc/frame_ppc.cpp @@ -52,7 +52,6 @@ void RegisterMap::check_location_valid() { #endif // ASSERT bool frame::safe_for_sender(JavaThread *thread) { - bool safe = false; address sp = (address)_sp; address fp = (address)_fp; address unextended_sp = (address)_unextended_sp; @@ -70,28 +69,23 @@ bool frame::safe_for_sender(JavaThread *thread) { // An fp must be within the stack and above (but not equal) sp. bool fp_safe = thread->is_in_stack_range_excl(fp, sp); - // An interpreter fp must be within the stack and above (but not equal) sp. - // Moreover, it must be at least the size of the ijava_state structure. + // An interpreter fp must be fp_safe. + // Moreover, it must be at a distance at least the size of the ijava_state structure. bool fp_interp_safe = fp_safe && ((fp - sp) >= ijava_state_size); // We know sp/unextended_sp are safe, only fp is questionable here // If the current frame is known to the code cache then we can attempt to - // to construct the sender and do some validation of it. This goes a long way + // construct the sender and do some validation of it. This goes a long way // toward eliminating issues when we get in frame construction code if (_cb != NULL ){ - // Entry frame checks - if (is_entry_frame()) { - // An entry frame must have a valid fp. - return fp_safe && is_entry_frame_valid(thread); - } - // Now check if the frame is complete and the test is - // reliable. Unfortunately we can only check frame completeness for - // runtime stubs and nmethods. Other generic buffer blobs are more - // problematic so we just assume they are OK. Adapter blobs never have a - // complete frame and are never OK + // First check if the frame is complete and the test is reliable. + // Unfortunately we can only check frame completeness for runtime stubs + // and nmethods. Other generic buffer blobs are more problematic + // so we just assume they are OK. + // Adapter blobs never have a complete frame and are never OK if (!_cb->is_frame_complete_at(_pc)) { if (_cb->is_compiled() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) { return false; @@ -103,10 +97,23 @@ bool frame::safe_for_sender(JavaThread *thread) { return false; } + // Entry frame checks + if (is_entry_frame()) { + // An entry frame must have a valid fp. + return fp_safe && is_entry_frame_valid(thread); + } + if (is_interpreted_frame() && !fp_interp_safe) { return false; } + // At this point, there still is a chance that fp_safe is false. + // In particular, (fp == NULL) might be true. So let's check and + // bail out before we actually dereference from fp. + if (!fp_safe) { + return false; + } + abi_minframe* sender_abi = (abi_minframe*) fp; intptr_t* sender_sp = (intptr_t*) fp; address sender_pc = (address) sender_abi->lr;; diff --git a/src/hotspot/cpu/s390/frame_s390.cpp b/src/hotspot/cpu/s390/frame_s390.cpp index 2486c6c6360..dd322c5c423 100644 --- a/src/hotspot/cpu/s390/frame_s390.cpp +++ b/src/hotspot/cpu/s390/frame_s390.cpp @@ -55,7 +55,6 @@ void RegisterMap::check_location_valid() { // Profiling/safepoint support bool frame::safe_for_sender(JavaThread *thread) { - bool safe = false; address sp = (address)_sp; address fp = (address)_fp; address unextended_sp = (address)_unextended_sp; @@ -73,28 +72,23 @@ bool frame::safe_for_sender(JavaThread *thread) { // An fp must be within the stack and above (but not equal) sp. bool fp_safe = thread->is_in_stack_range_excl(fp, sp); - // An interpreter fp must be within the stack and above (but not equal) sp. - // Moreover, it must be at least the size of the z_ijava_state structure. + // An interpreter fp must be fp_safe. + // Moreover, it must be at a distance at least the size of the z_ijava_state structure. bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size); // We know sp/unextended_sp are safe, only fp is questionable here // If the current frame is known to the code cache then we can attempt to - // to construct the sender and do some validation of it. This goes a long way + // construct the sender and do some validation of it. This goes a long way // toward eliminating issues when we get in frame construction code if (_cb != NULL ) { - // Entry frame checks - if (is_entry_frame()) { - // An entry frame must have a valid fp. - return fp_safe && is_entry_frame_valid(thread); - } - // Now check if the frame is complete and the test is - // reliable. Unfortunately we can only check frame completeness for - // runtime stubs. Other generic buffer blobs are more - // problematic so we just assume they are OK. Adapter blobs never have a - // complete frame and are never OK. nmethods should be OK on s390. + // First check if the frame is complete and the test is reliable. + // Unfortunately we can only check frame completeness for runtime stubs. + // Other generic buffer blobs are more problematic so we just assume they are OK. + // Adapter blobs never have a complete frame and are never OK. + // nmethods should be OK on s390. if (!_cb->is_frame_complete_at(_pc)) { if (_cb->is_adapter_blob() || _cb->is_runtime_stub()) { return false; @@ -106,13 +100,26 @@ bool frame::safe_for_sender(JavaThread *thread) { return false; } + // Entry frame checks + if (is_entry_frame()) { + // An entry frame must have a valid fp. + return fp_safe && is_entry_frame_valid(thread); + } + if (is_interpreted_frame() && !fp_interp_safe) { return false; } + // At this point, there still is a chance that fp_safe is false. + // In particular, (fp == NULL) might be true. So let's check and + // bail out before we actually dereference from fp. + if (!fp_safe) { + return false; + } + z_abi_160* sender_abi = (z_abi_160*) fp; intptr_t* sender_sp = (intptr_t*) sender_abi->callers_sp; - address sender_pc = (address) sender_abi->return_pc; + address sender_pc = (address) sender_abi->return_pc; // We must always be able to find a recognizable pc. CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); diff --git a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp index 9f779456640..d09608c6aa7 100644 --- a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp +++ b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp @@ -35,6 +35,8 @@ frame JavaThread::pd_last_frame() { address pc = _anchor.last_Java_pc(); // Last_Java_pc ist not set, if we come here from compiled code. + // Assume spill slot for link register contains a suitable pc. + // Should have been filled by method entry code. if (pc == NULL) { pc = (address) *(sp + 2); } @@ -64,6 +66,17 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, return false; } + if (ret_frame.fp() == NULL) { + // The found frame does not have a valid frame pointer. + // Bail out because this will create big trouble later on, either + // - when using istate, calculated as (NULL - ijava_state_size) or + // - when using fp() directly in safe_for_sender() + // + // There is no conclusive description (yet) how this could happen, but it does. + // For more details on what was observed, see thread_linux_s390.cpp + return false; + } + if (ret_frame.is_interpreted_frame()) { frame::ijava_state *istate = ret_frame.get_ijava_state(); const Method *m = (const Method*)(istate->method); diff --git a/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp b/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp index eeaf2f47fc6..d06b851a99f 100644 --- a/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp +++ b/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp @@ -35,6 +35,8 @@ frame JavaThread::pd_last_frame() { address pc = _anchor.last_Java_pc(); // Last_Java_pc ist not set if we come here from compiled code. + // Assume spill slot for Z_R14 (return register) contains a suitable pc. + // Should have been filled by method entry code. if (pc == NULL) { pc = (address) *(sp + 14); } @@ -51,6 +53,9 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, return true; } + // At this point, we don't have a last_Java_frame, so + // we try to glean some information out of the ucontext + // if we were running Java code when SIGPROF came in. if (isInJava) { ucontext_t* uc = (ucontext_t*) ucontext; frame ret_frame((intptr_t*)uc->uc_mcontext.gregs[15/*Z_SP*/], @@ -61,6 +66,38 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, return false; } + if (ret_frame.fp() == NULL) { + // The found frame does not have a valid frame pointer. + // Bail out because this will create big trouble later on, either + // - when using istate, calculated as (NULL - z_ijava_state_size (= 0x70 (dbg) or 0x68 (rel)) or + // - when using fp() directly in safe_for_sender() + // + // There is no conclusive description (yet) how this could happen, but it does: + // + // We observed a SIGSEGV with the following stack trace (openjdk.jdk11u-dev, 2021-07-07, linuxs390x fastdebug) + // V [libjvm.so+0x12c8f12] JavaThread::pd_get_top_frame_for_profiling(frame*, void*, bool)+0x142 + // V [libjvm.so+0xb1020c] JfrGetCallTrace::get_topframe(void*, frame&)+0x3c + // V [libjvm.so+0xba0b08] OSThreadSampler::protected_task(os::SuspendedThreadTaskContext const&)+0x98 + // V [libjvm.so+0xff33c4] os::SuspendedThreadTask::internal_do_task()+0x14c + // V [libjvm.so+0xfe3c9c] os::SuspendedThreadTask::run()+0x24 + // V [libjvm.so+0xba0c66] JfrThreadSampleClosure::sample_thread_in_java(JavaThread*, JfrStackFrame*, unsigned int)+0x66 + // V [libjvm.so+0xba1718] JfrThreadSampleClosure::do_sample_thread(JavaThread*, JfrStackFrame*, unsigned int, JfrSampleType)+0x278 + // V [libjvm.so+0xba4f54] JfrThreadSampler::task_stacktrace(JfrSampleType, JavaThread**) [clone .constprop.62]+0x284 + // V [libjvm.so+0xba5e54] JfrThreadSampler::run()+0x2ec + // V [libjvm.so+0x12adc9c] Thread::call_run()+0x9c + // V [libjvm.so+0xff5ab0] thread_native_entry(Thread*)+0x128 + // siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0xfffffffffffff000 + // failing instruction: e320 6008 0004 LG r2,8(r0,r6) + // contents of r6: 0xffffffffffffff90 + // + // Here is the sequence of what happens: + // - ret_frame is constructed with _fp == NULL (for whatever reason) + // - ijava_state_unchecked() calculates it's result as + // istate = fp() - z_ijava_state_size() = NULL - 0x68 DEBUG_ONLY(-8) + // - istate->method dereferences memory at offset 8 from istate + return false; + } + if (ret_frame.is_interpreted_frame()) { frame::z_ijava_state* istate = ret_frame.ijava_state_unchecked(); if (is_in_full_stack((address)istate)) { From 4dff991d7b45942fe36a324471c0c0c12cfeebed Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Tue, 14 Sep 2021 07:51:16 +0000 Subject: [PATCH 039/253] 8269687: pauth_aarch64.hpp include name is incorrect Backport-of: b690f29699180149d33b6a83de10697790587a87 --- src/hotspot/cpu/aarch64/pauth_aarch64.hpp | 6 +++--- src/hotspot/os_cpu/bsd_aarch64/pauth_bsd_aarch64.inline.hpp | 6 +++--- .../os_cpu/windows_aarch64/pauth_windows_aarch64.inline.hpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hotspot/cpu/aarch64/pauth_aarch64.hpp b/src/hotspot/cpu/aarch64/pauth_aarch64.hpp index 6109964458f..e12a671daf1 100644 --- a/src/hotspot/cpu/aarch64/pauth_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/pauth_aarch64.hpp @@ -22,8 +22,8 @@ * */ -#ifndef CPU_AARCH64_PAUTH_AARCH64_INLINE_HPP -#define CPU_AARCH64_PAUTH_AARCH64_INLINE_HPP +#ifndef CPU_AARCH64_PAUTH_AARCH64_HPP +#define CPU_AARCH64_PAUTH_AARCH64_HPP #include OS_CPU_HEADER_INLINE(pauth) @@ -32,4 +32,4 @@ inline bool pauth_ptr_is_raw(address ptr) { return ptr == pauth_strip_pointer(ptr); } -#endif // CPU_AARCH64_PAUTH_AARCH64_INLINE_HPP +#endif // CPU_AARCH64_PAUTH_AARCH64_HPP diff --git a/src/hotspot/os_cpu/bsd_aarch64/pauth_bsd_aarch64.inline.hpp b/src/hotspot/os_cpu/bsd_aarch64/pauth_bsd_aarch64.inline.hpp index 21193e181f2..a4d416d384e 100644 --- a/src/hotspot/os_cpu/bsd_aarch64/pauth_bsd_aarch64.inline.hpp +++ b/src/hotspot/os_cpu/bsd_aarch64/pauth_bsd_aarch64.inline.hpp @@ -22,8 +22,8 @@ * */ -#ifndef OS_CPU_LINUX_AARCH64_PAUTH_BSD_AARCH64_INLINE_HPP -#define OS_CPU_LINUX_AARCH64_PAUTH_BSD_AARCH64_INLINE_HPP +#ifndef OS_CPU_BSD_AARCH64_PAUTH_BSD_AARCH64_INLINE_HPP +#define OS_CPU_BSD_AARCH64_PAUTH_BSD_AARCH64_INLINE_HPP #ifdef __APPLE__ #include @@ -49,5 +49,5 @@ inline address pauth_strip_pointer(address ptr) { #undef XPACLRI -#endif // OS_CPU_LINUX_AARCH64_PAUTH_BSD_AARCH64_INLINE_HPP +#endif // OS_CPU_BSD_AARCH64_PAUTH_BSD_AARCH64_INLINE_HPP diff --git a/src/hotspot/os_cpu/windows_aarch64/pauth_windows_aarch64.inline.hpp b/src/hotspot/os_cpu/windows_aarch64/pauth_windows_aarch64.inline.hpp index bf1d2aa99e1..844291ee1e4 100644 --- a/src/hotspot/os_cpu/windows_aarch64/pauth_windows_aarch64.inline.hpp +++ b/src/hotspot/os_cpu/windows_aarch64/pauth_windows_aarch64.inline.hpp @@ -22,13 +22,13 @@ * */ -#ifndef OS_CPU_LINUX_AARCH64_PAUTH_WINDOWS_AARCH64_INLINE_HPP -#define OS_CPU_LINUX_AARCH64_PAUTH_WINDOWS_AARCH64_INLINE_HPP +#ifndef OS_CPU_WINDOWS_AARCH64_PAUTH_WINDOWS_AARCH64_INLINE_HPP +#define OS_CPU_WINDOWS_AARCH64_PAUTH_WINDOWS_AARCH64_INLINE_HPP inline address pauth_strip_pointer(address ptr) { // No PAC support in windows as of yet. return ptr; } -#endif // OS_CPU_LINUX_AARCH64_PAUTH_WINDOWS_AARCH64_INLINE_HPP +#endif // OS_CPU_WINDOWS_AARCH64_PAUTH_WINDOWS_AARCH64_INLINE_HPP From ec0b85ab5fd4cee7586911ab4f3448469b171bbb Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Tue, 14 Sep 2021 18:11:12 +0000 Subject: [PATCH 040/253] 8273593: [REDO] Warn user when using mac-sign option with unsigned app-image. Reviewed-by: kcr, asemenyuk --- .../jdk/jpackage/internal/MacAppBundler.java | 3 ++- .../jpackage/internal/MacAppImageBuilder.java | 14 ++----------- .../internal/MacBaseInstallerBundler.java | 16 +++++++++++++++ .../jdk/jpackage/internal/MacPkgBundler.java | 5 +++-- .../resources/MacResources.properties | 3 ++- .../resources/MacResources_ja.properties | 1 + .../resources/MacResources_zh_CN.properties | 1 + .../jdk/jpackage/internal/AppImageFile.java | 20 ++++++++++++++++--- .../internal/StandardBundlerParam.java | 10 ++++++++++ 9 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java index ae10e64abde..9d79baaa22b 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppBundler.java @@ -35,6 +35,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.MAIN_CLASS; import static jdk.jpackage.internal.StandardBundlerParam.VERBOSE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class MacAppBundler extends AppImageBundler { public MacAppBundler() { @@ -125,7 +126,7 @@ private static void doValidate(Map params) } // reject explicitly set sign to true and no valid signature key - if (Optional.ofNullable(MacAppImageBuilder. + if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { String signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params); diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java index 06af1ed2db0..f1eed5f5f15 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, 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 @@ -66,6 +66,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class MacAppImageBuilder extends AbstractAppImageBuilder { @@ -143,16 +144,6 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder { }, (s, p) -> Path.of(s)); - public static final StandardBundlerParam SIGN_BUNDLE = - new StandardBundlerParam<>( - Arguments.CLIOptions.MAC_SIGN.getId(), - Boolean.class, - params -> false, - // valueOf(null) is false, we actually do want null in some cases - (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? - null : Boolean.valueOf(s) - ); - public static final StandardBundlerParam APP_STORE = new StandardBundlerParam<>( Arguments.CLIOptions.MAC_APP_STORE.getId(), @@ -863,5 +854,4 @@ private static String extractBundleIdentifier(Map params) { return null; } - } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java index 8e1bbfc5883..28eee6bdc4e 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; @@ -41,6 +42,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR; import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public abstract class MacBaseInstallerBundler extends AbstractBundler { @@ -134,6 +136,20 @@ protected void validateAppImageAndBundeler( I18N.getString( "message.app-image-requires-app-name.advice")); } + if (Optional.ofNullable( + SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { + // if signing bundle with app-image, warn user if app-image + // is not allready signed. + try { + if (!(AppImageFile.load(applicationImage).isSigned())) { + Log.info(MessageFormat.format(I18N.getString( + "warning.unsigned.app.image"), getID())); + } + } catch (IOException ioe) { + // Ignore - In case of a forign or tampered with app-image, + // user is notified of this when the name is extracted. + } + } } else { appImageBundler.validate(params); } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java index 2d436c244dc..df9755b08dd 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java @@ -46,6 +46,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN; import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER; import static jdk.jpackage.internal.MacAppImageBuilder.APP_STORE; @@ -499,7 +500,7 @@ private Path createPKG(Map params, commandLine.add(CONFIG_ROOT.fetchFrom(params).toAbsolutePath().toString()); // maybe sign - if (Optional.ofNullable(MacAppImageBuilder. + if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { if (Platform.getMajorVersion() > 10 || (Platform.getMajorVersion() == 10 && @@ -603,7 +604,7 @@ public boolean validate(Map params) } // reject explicitly set sign to true and no valid signature key - if (Optional.ofNullable(MacAppImageBuilder. + if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { String signingIdentity = DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties index 71075354542..23a4f9d0437 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2021, 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,3 +88,4 @@ message.preparing-distribution-dist=Preparing distribution.dist: {0}. message.signing.pkg=Warning: For signing PKG, you might need to set "Always Trust" for your certificate using "Keychain Access" tool. message.setfile.dmg=Setting custom icon on DMG file skipped because 'SetFile' utility was not found. Installing Xcode with Command Line Tools should resolve this issue. message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. +warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties index 08cd0819495..d9da226ec92 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_ja.properties @@ -87,3 +87,4 @@ message.preparing-distribution-dist=distribution.dist\u3092\u6E96\u5099\u3057\u3 message.signing.pkg=\u8B66\u544A: PKG\u3078\u306E\u7F72\u540D\u306E\u5834\u5408\u3001\u300C\u30AD\u30FC\u30C1\u30A7\u30FC\u30F3\u30FB\u30A2\u30AF\u30BB\u30B9\u300D\u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A3C\u660E\u66F8\u306B\u300C\u5E38\u306B\u4FE1\u983C\u3059\u308B\u300D\u3092\u8A2D\u5B9A\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\u3002 message.setfile.dmg='SetFile'\u30E6\u30FC\u30C6\u30A3\u30EA\u30C6\u30A3\u304C\u898B\u3064\u304B\u3089\u306A\u3044\u305F\u3081\u3001DMG\u30D5\u30A1\u30A4\u30EB\u3067\u306E\u30AB\u30B9\u30BF\u30E0\u30FB\u30A2\u30A4\u30B3\u30F3\u306E\u8A2D\u5B9A\u304C\u30B9\u30AD\u30C3\u30D7\u3055\u308C\u307E\u3057\u305F\u3002Xcode\u3068\u30B3\u30DE\u30F3\u30C9\u30FB\u30E9\u30A4\u30F3\u30FB\u30C4\u30FC\u30EB\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3059\u308B\u3068\u3001\u3053\u306E\u554F\u984C\u306F\u89E3\u6C7A\u3055\u308C\u307E\u3059\u3002 message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. +warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties index c2bfdf96963..d6f47a7bc85 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources_zh_CN.properties @@ -87,3 +87,4 @@ message.preparing-distribution-dist=\u6B63\u5728\u51C6\u5907 distribution.dist: message.signing.pkg=\u8B66\u544A\uFF1A\u8981\u5BF9 PKG \u8FDB\u884C\u7B7E\u540D\uFF0C\u53EF\u80FD\u9700\u8981\u4F7F\u7528\u201C\u5BC6\u94A5\u94FE\u8BBF\u95EE\u201D\u5DE5\u5177\u4E3A\u8BC1\u4E66\u8BBE\u7F6E\u201C\u59CB\u7EC8\u4FE1\u4EFB\u201D\u3002 message.setfile.dmg=\u7531\u4E8E\u672A\u627E\u5230 'SetFile' \u5B9E\u7528\u7A0B\u5E8F\uFF0C\u8DF3\u8FC7\u4E86\u9488\u5BF9 DMG \u6587\u4EF6\u8BBE\u7F6E\u5B9A\u5236\u56FE\u6807\u7684\u64CD\u4F5C\u3002\u5B89\u88C5\u5E26\u547D\u4EE4\u884C\u5DE5\u5177\u7684 Xcode \u5E94\u80FD\u89E3\u51B3\u6B64\u95EE\u9898\u3002 message.install-dir-ignored=Warning: "--install-dir" is not supported by DMG and will be default to /Applications. +warning.unsigned.app.image=Warning: Using unsigned app-image to build signed {0}. diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java index dd1993f179c..655a0d10f25 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java @@ -46,6 +46,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; +import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; public class AppImageFile { @@ -54,6 +55,7 @@ public class AppImageFile { private final String creatorPlatform; private final String launcherName; private final List addLauncherNames; + private final boolean signed; private static final String FILENAME = ".jpackage.xml"; @@ -63,15 +65,16 @@ public class AppImageFile { private AppImageFile() { - this(null, null, null, null); + this(null, null, null, null, null); } private AppImageFile(String launcherName, List addLauncherNames, - String creatorVersion, String creatorPlatform) { + String creatorVersion, String creatorPlatform, String signedStr) { this.launcherName = launcherName; this.addLauncherNames = addLauncherNames; this.creatorVersion = creatorVersion; this.creatorPlatform = creatorPlatform; + this.signed = "true".equals(signedStr); } /** @@ -90,6 +93,10 @@ String getLauncherName() { return launcherName; } + boolean isSigned() { + return signed; + } + void verifyCompatible() throws ConfigException { // Just do nothing for now. } @@ -125,6 +132,10 @@ static void save(Path appImageDir, Map params) xml.writeCharacters(APP_NAME.fetchFrom(params)); xml.writeEndElement(); + xml.writeStartElement("signed"); + xml.writeCharacters(SIGN_BUNDLE.fetchFrom(params).toString()); + xml.writeEndElement(); + List> addLaunchers = ADD_LAUNCHERS.fetchFrom(params); @@ -164,6 +175,9 @@ static AppImageFile load(Path appImageDir) throws IOException { String version = xpathQueryNullable(xPath, "/jpackage-state/@version", doc); + String signedStr = xpathQueryNullable(xPath, + "/jpackage-state/@signed", doc); + NodeList launcherNameNodes = (NodeList) xPath.evaluate( "/jpackage-state/add-launcher/text()", doc, XPathConstants.NODESET); @@ -173,7 +187,7 @@ static AppImageFile load(Path appImageDir) throws IOException { } AppImageFile file = new AppImageFile( - mainLauncher, addLaunchers, version, platform); + mainLauncher, addLaunchers, version, platform, signedStr); if (!file.isValid()) { file = new AppImageFile(); } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java index edf6e368fd4..113dc0d4749 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java @@ -467,6 +467,16 @@ private static Path findPathOfModule( List modulePath, String moduleName) (s, p) -> new LinkedHashSet<>(Arrays.asList(s.split(","))) ); + static final StandardBundlerParam SIGN_BUNDLE = + new StandardBundlerParam<>( + Arguments.CLIOptions.MAC_SIGN.getId(), + Boolean.class, + params -> false, + (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? + null : Boolean.valueOf(s) + ); + + static boolean isRuntimeInstaller(Map params) { if (params.containsKey(MODULE.getID()) || params.containsKey(MAIN_JAR.getID()) || From 808356abec941a91ba531ad098898bb74c41cb50 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Tue, 14 Sep 2021 19:55:30 +0000 Subject: [PATCH 041/253] 8273358: macOS Monterey does not have the font Times needed by Serif Backport-of: efe3ed1e705a6f3785761e64f7187de809daa731 --- .../macosx/classes/sun/font/CFontManager.java | 17 +++++-- .../java/awt/FontClass/LogicalFontsTest.java | 51 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 test/jdk/java/awt/FontClass/LogicalFontsTest.java diff --git a/src/java.desktop/macosx/classes/sun/font/CFontManager.java b/src/java.desktop/macosx/classes/sun/font/CFontManager.java index dd45ce8eb1e..85182158ec1 100644 --- a/src/java.desktop/macosx/classes/sun/font/CFontManager.java +++ b/src/java.desktop/macosx/classes/sun/font/CFontManager.java @@ -225,7 +225,7 @@ public Object run() { String defaultFallback = "Lucida Grande"; setupLogicalFonts("Dialog", defaultFont, defaultFallback); - setupLogicalFonts("Serif", "Times", "Times"); + setupLogicalFonts("Serif", "Times", "Times New Roman"); setupLogicalFonts("SansSerif", defaultFont, defaultFallback); setupLogicalFonts("Monospaced", "Menlo", "Courier"); setupLogicalFonts("DialogInput", defaultFont, defaultFallback); @@ -251,7 +251,13 @@ protected FontFamily getFontFamilyWithExtraTry(String logicalName, String realNa family = getFontFamily(realName, fallbackName); if (family != null) return family; - System.err.println("Warning: the fonts \"" + realName + "\" and \"" + fallbackName + "\" are not available for the Java logical font \"" + logicalName + "\", which may have unexpected appearance or behavior. Re-enable the \""+ realName +"\" font to remove this warning."); + if (FontUtilities.debugFonts()) { + FontUtilities.logSevere( + "The fonts \"" + realName + "\" and \"" + fallbackName + + "\" are not available for the Java logical font \"" + logicalName + + "\", which may have unexpected appearance or behavior. Re-enable the \""+ + realName +"\" font to remove this warning."); + } return null; } @@ -261,7 +267,12 @@ protected FontFamily getFontFamily(String realName, String fallbackName){ family = FontFamily.getFamily(fallbackName); if (family != null){ - System.err.println("Warning: the font \"" + realName + "\" is not available, so \"" + fallbackName + "\" has been substituted, but may have unexpected appearance or behavor. Re-enable the \""+ realName +"\" font to remove this warning."); + if (FontUtilities.debugFonts()) { + FontUtilities.logWarning( + "The font \"" + realName + "\" is not available, so \"" + fallbackName + + "\" has been substituted, but may have unexpected appearance or behavor. Re-enable the \"" + + realName +"\" font to remove this warning."); + } return family; } diff --git a/test/jdk/java/awt/FontClass/LogicalFontsTest.java b/test/jdk/java/awt/FontClass/LogicalFontsTest.java new file mode 100644 index 00000000000..f15bf67adb1 --- /dev/null +++ b/test/jdk/java/awt/FontClass/LogicalFontsTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021, 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 8273358 + * @summary Verify logical fonts are as expected. + * @run main/othervm LogicalFontsTest + */ + +import java.awt.Font; + +public class LogicalFontsTest { + + public static void main(String[] args) { + test(Font.SANS_SERIF); + test(Font.SERIF); + test(Font.MONOSPACED); + test(Font.DIALOG); + test(Font.DIALOG_INPUT); + } + + static void test(String fontName) { + System.out.println("name="+fontName); + Font font = new Font(fontName, Font.PLAIN, 12); + System.out.println("font = " + font); + if (!fontName.equalsIgnoreCase(font.getFamily())) { + throw new RuntimeException("Requested " + fontName + " but got " + font); + } + } +} From f8ecff4877db36afee2c81186988ac55b8772ec9 Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Tue, 14 Sep 2021 21:18:18 +0000 Subject: [PATCH 042/253] 8269951: [macos] Focus not painted in JButton when setBorderPainted(false) is invoked Backport-of: 481c1f0549e361e8e83fcf0530acc4ebdb60104b --- .../classes/com/apple/laf/AquaButtonUI.java | 31 ++++++- .../swing/plaf/aqua/AquaButtonFocusTest.java | 91 +++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 test/jdk/javax/swing/plaf/aqua/AquaButtonFocusTest.java diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java index e6164131f59..38f409f81fd 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, 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 @@ -326,6 +326,35 @@ public void paint(final Graphics g, final JComponent c) { } } + protected void paintFocus(Graphics g, AbstractButton b, + Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { + Graphics2D g2d = null; + Stroke oldStroke = null; + Object oldAntialiasingHint = null; + Color oldColor = g.getColor(); + if (g instanceof Graphics2D) { + g2d = (Graphics2D)g; + oldStroke = g2d.getStroke(); + oldAntialiasingHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING); + g2d.setStroke(new BasicStroke(3)); + g2d.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + } + Color ringColor = UIManager.getColor("Focus.color"); + g.setColor(ringColor); + g.drawRoundRect(5, 3, b.getWidth() - 10, b.getHeight() - 7, 15, 15); + if (g2d != null) { + // Restore old state of Java2D renderer + g2d.setStroke(oldStroke); + g2d.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, + oldAntialiasingHint); + } + g.setColor(oldColor); + } + protected String layoutAndGetText(final Graphics g, final AbstractButton b, final AquaButtonBorder aquaBorder, final Insets i, Rectangle viewRect, Rectangle iconRect, Rectangle textRect) { // re-initialize the view rect to the selected insets viewRect.x = i.left; diff --git a/test/jdk/javax/swing/plaf/aqua/AquaButtonFocusTest.java b/test/jdk/javax/swing/plaf/aqua/AquaButtonFocusTest.java new file mode 100644 index 00000000000..c36f9e24b6f --- /dev/null +++ b/test/jdk/javax/swing/plaf/aqua/AquaButtonFocusTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021, 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 + * @requires (os.family == "mac") + * @bug 8269951 + * @summary Test checks that focus is painted on JButton even + * when borders turned off + * @library ../../regtesthelpers + * @build Util + * @run main AquaButtonFocusTest + */ + + +import javax.swing.JButton; +import javax.swing.UIManager; +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +public class AquaButtonFocusTest { + public static void main(String[] args) { + new AquaButtonFocusTest().performTest(); + } + + public void performTest() { + try { + UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); + } catch (Exception e) { + throw new RuntimeException("Can not initialize Aqua L&F"); + } + + FocusableButton one = new FocusableButton("One"); + one.setSize(100, 100); + one.setBorderPainted(false); + BufferedImage noFocus = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB); + Graphics g = noFocus.createGraphics(); + one.paint(g); + g.dispose(); + BufferedImage focus = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB); + one.setFocusOwner(true); + g = focus.createGraphics(); + one.paint(g); + g.dispose(); + if (Util.compareBufferedImages(noFocus, focus)) { + throw new RuntimeException("Focus is not painted on JButton"); + } + } + + class FocusableButton extends JButton { + private boolean focusOwner = false; + + public FocusableButton(String label) { + super(label); + } + + public void setFocusOwner(boolean focused) { + this.focusOwner = focused; + } + + @Override + public boolean isFocusOwner() { + return focusOwner; + } + + @Override + public boolean hasFocus() { + return this.focusOwner; + } + } +} From 20be766ed90849703e32dfc4481505612400e0e6 Mon Sep 17 00:00:00 2001 From: Richard Reingruber Date: Wed, 15 Sep 2021 12:50:13 +0000 Subject: [PATCH 043/253] 8271722: [TESTBUG] gc/g1/TestMixedGCLiveThreshold.java can fail if G1 Full GC uses >1 workers Backport-of: 4abe5311407c68d04fb0babb87fa279e35d5fabc --- test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java b/test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java index 88012b68fe7..7dff9d88da2 100644 --- a/test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java +++ b/test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java @@ -81,6 +81,8 @@ private static OutputAnalyzer testWithMixedGCLiveThresholdPercent(int percent) t "-XX:+UnlockDiagnosticVMOptions", "-XX:+UnlockExperimentalVMOptions", "-XX:+WhiteBoxAPI", + // Parallel full gc can distribute live objects into different regions. + "-XX:ParallelGCThreads=1", "-Xlog:gc+remset+tracking=trace", "-Xms10M", "-Xmx10M"}); From 94f41162f4cb14cd48860e002a1c97e50f42a556 Mon Sep 17 00:00:00 2001 From: Evan Whelan Date: Wed, 15 Sep 2021 14:30:40 +0000 Subject: [PATCH 044/253] 8270416: Enhance construction of Identity maps Reviewed-by: jboes Backport-of: d445bf3f60c654bee77dcabe86f6fa28eaf5abfa --- .../share/classes/java/util/Hashtable.java | 37 +++++++++++++------ .../classes/java/util/IdentityHashMap.java | 22 ++++++----- .../util/Hashtable/DeserializedLength.java | 4 +- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index c103df55790..2b6f6e72540 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2021, 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 @@ -1254,7 +1254,7 @@ final void defaultWriteHashtable(java.io.ObjectOutputStream s, int length, * Reconstitute the Hashtable from a stream (i.e., deserialize it). */ @java.io.Serial - private void readObject(java.io.ObjectInputStream s) + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { readHashtable(s); } @@ -1263,14 +1263,16 @@ private void readObject(java.io.ObjectInputStream s) * Perform deserialization of the Hashtable from an ObjectInputStream. * The Properties class overrides this method. */ - void readHashtable(java.io.ObjectInputStream s) + void readHashtable(ObjectInputStream s) throws IOException, ClassNotFoundException { - // Read in the threshold and loadFactor - s.defaultReadObject(); - // Validate loadFactor (ignore threshold - it will be re-computed) - if (loadFactor <= 0 || Float.isNaN(loadFactor)) - throw new StreamCorruptedException("Illegal Load: " + loadFactor); + ObjectInputStream.GetField fields = s.readFields(); + + // Read and validate loadFactor (ignore threshold - it will be re-computed) + float lf = fields.get("loadFactor", 0.75f); + if (lf <= 0 || Float.isNaN(lf)) + throw new StreamCorruptedException("Illegal load factor: " + lf); + lf = Math.min(Math.max(0.25f, lf), 4.0f); // Read the original length of the array and number of elements int origlength = s.readInt(); @@ -1282,13 +1284,13 @@ void readHashtable(java.io.ObjectInputStream s) // Clamp original length to be more than elements / loadFactor // (this is the invariant enforced with auto-growth) - origlength = Math.max(origlength, (int)(elements / loadFactor) + 1); + origlength = Math.max(origlength, (int)(elements / lf) + 1); // Compute new length with a bit of room 5% + 3 to grow but // no larger than the clamped original length. Make the length // odd if it's large enough, this helps distribute the entries. // Guard against the length ending up zero, that's not valid. - int length = (int)((elements + elements / 20) / loadFactor) + 3; + int length = (int)((elements + elements / 20) / lf) + 3; if (length > elements && (length & 1) == 0) length--; length = Math.min(length, origlength); @@ -1300,8 +1302,9 @@ void readHashtable(java.io.ObjectInputStream s) // Check Map.Entry[].class since it's the nearest public type to // what we're actually creating. SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, length); + Hashtable.UnsafeHolder.putLoadFactor(this, lf); table = new Entry[length]; - threshold = (int)Math.min(length * loadFactor, MAX_ARRAY_SIZE + 1); + threshold = (int)Math.min(length * lf, MAX_ARRAY_SIZE + 1); count = 0; // Read the number of elements and then all the key/value objects @@ -1315,6 +1318,18 @@ void readHashtable(java.io.ObjectInputStream s) } } + // Support for resetting final field during deserializing + private static final class UnsafeHolder { + private UnsafeHolder() { throw new InternalError(); } + private static final jdk.internal.misc.Unsafe unsafe + = jdk.internal.misc.Unsafe.getUnsafe(); + private static final long LF_OFFSET + = unsafe.objectFieldOffset(Hashtable.class, "loadFactor"); + static void putLoadFactor(Hashtable table, float lf) { + unsafe.putFloat(table, LF_OFFSET, lf); + } + } + /** * The put method used by readObject. This is provided because put * is overridable and should not be called in readObject since the diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 34d6722ac09..4795c30b3d5 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2021, 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.util; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.lang.reflect.Array; import java.util.function.BiConsumer; import java.util.function.BiFunction; @@ -1267,12 +1269,12 @@ public Spliterator> spliterator() { * particular order. */ @java.io.Serial - private void writeObject(java.io.ObjectOutputStream s) + private void writeObject(ObjectOutputStream s) throws java.io.IOException { - // Write out and any hidden stuff + // Write out size (number of mappings) and any hidden stuff s.defaultWriteObject(); - // Write out size (number of Mappings) + // Write out size again (maintained for backward compatibility) s.writeInt(size); // Write out keys and values (alternating) @@ -1291,18 +1293,20 @@ private void writeObject(java.io.ObjectOutputStream s) * deserializes it). */ @java.io.Serial - private void readObject(java.io.ObjectInputStream s) + private void readObject(ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { - // Read in any hidden stuff - s.defaultReadObject(); + // Size (number of mappings) is written to the stream twice + // Read first size value and ignore it + s.readFields(); - // Read in size (number of Mappings) + // Read second size value, validate and assign to size field int size = s.readInt(); if (size < 0) throw new java.io.StreamCorruptedException ("Illegal mappings count: " + size); int cap = capacity(size); - SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, cap); + SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, cap*2); + this.size = size; init(cap); // Read the keys and values, and put the mappings in the table diff --git a/test/jdk/java/util/Hashtable/DeserializedLength.java b/test/jdk/java/util/Hashtable/DeserializedLength.java index 376c1f026d0..d515878fd36 100644 --- a/test/jdk/java/util/Hashtable/DeserializedLength.java +++ b/test/jdk/java/util/Hashtable/DeserializedLength.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2021, 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 @@ -100,7 +100,7 @@ public static void main(String[] args) throws Exception { ); for (int elements : new int[]{10, 50, 500, 5000}) { - for (float loadFactor : new float[]{0.15f, 0.5f, 0.75f, 1.0f, 2.5f}) { + for (float loadFactor : new float[]{0.25f, 0.5f, 0.75f, 1.0f, 2.5f}) { ok &= testDeserializedLength(elements, loadFactor); } } From 171e90cbf5ad53296e7e7bca667e354e6f1cba02 Mon Sep 17 00:00:00 2001 From: Fairoz Matte Date: Thu, 16 Sep 2021 05:33:08 +0000 Subject: [PATCH 045/253] 8270320: JDK-8270110 committed invalid copyright headers Backport-of: 353e9c8607e3a433aac786bd7b818d77ff75dd11 --- .../jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java | 1 + .../jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c | 1 + 2 files changed, 2 insertions(+) diff --git a/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java b/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java index 8bd3d88951c..4eaf93f72ca 100644 --- a/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java +++ b/test/hotspot/jtreg/gc/shenandoah/jni/TestStringCriticalWithDedup.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Red Hat, Inc. 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 diff --git a/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c b/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c index 665ae585545..6b09818b045 100644 --- a/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c +++ b/test/hotspot/jtreg/gc/shenandoah/jni/libTestStringCriticalWithDedup.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Red Hat, Inc. 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 From da1c0fea12ea96e626b292043499b5553c3f880b Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Fri, 17 Sep 2021 17:59:10 +0000 Subject: [PATCH 046/253] 8272639: jpackaged applications using microphone on mac Reviewed-by: asemenyuk --- .../classes/jdk/jpackage/internal/MacBaseInstallerBundler.java | 2 +- .../jdk/jpackage/internal/resources/Info-lite.plist.template | 2 ++ .../classes/jdk/jpackage/internal/resources/sandbox.plist | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java index 28eee6bdc4e..77677369a17 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java @@ -139,7 +139,7 @@ protected void validateAppImageAndBundeler( if (Optional.ofNullable( SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { // if signing bundle with app-image, warn user if app-image - // is not allready signed. + // is not already signed. try { if (!(AppImageFile.load(applicationImage).isSigned())) { Log.info(MessageFormat.format(I18N.getString( diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/Info-lite.plist.template b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/Info-lite.plist.template index 632dcd31b94..b981dc41d65 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/Info-lite.plist.template +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/Info-lite.plist.template @@ -33,5 +33,7 @@ DEPLOY_BUNDLE_COPYRIGHTDEPLOY_FILE_ASSOCIATIONS NSHighResolutionCapable true + NSMicrophoneUsageDescription + The application DEPLOY_LAUNCHER_NAME is requesting access to the microphone. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/sandbox.plist b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/sandbox.plist index ad48d4f9517..408f95f1d2a 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/sandbox.plist +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/sandbox.plist @@ -14,5 +14,7 @@ com.apple.security.cs.debugger + com.apple.security.device.audio-input + From 6b74b1ba275deecb01a4f77e7c3d6270a0303131 Mon Sep 17 00:00:00 2001 From: Rob McKenna Date: Fri, 17 Sep 2021 19:46:05 +0000 Subject: [PATCH 047/253] 8270646: Improved scanning of XML entities Backport-of: 2b6dad98a6739df983a01b96cffea971268d1523 --- .../impl/XML11DocumentScannerImpl.java | 14 +- .../internal/impl/XML11EntityScanner.java | 210 +---------- .../internal/impl/XMLEntityScanner.java | 355 ++++++------------ .../xerces/internal/impl/XMLScanner.java | 10 +- .../xerces/internal/util/XMLStringBuffer.java | 88 +---- .../apache/xerces/internal/xni/XMLString.java | 81 +++- 6 files changed, 209 insertions(+), 549 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java index 1ec084e93a6..67f6478f135 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -54,7 +54,7 @@ * @author Andy Clark, IBM * @author Arnaud Le Hors, IBM * @author Eric Ye, IBM - * + * @LastModified: Aug 2021 */ public class XML11DocumentScannerImpl extends XMLDocumentScannerImpl { @@ -278,16 +278,6 @@ else if (c == '%' || c == ']') { + fStringBuffer.toString() + "\""); } } - // note that none of these characters should ever get through - // XML11EntityScanner. Not sure why - // this check was originally necessary. - NG - else if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) { - fEntityScanner.scanChar(null); - fStringBuffer.append(' '); - if (entityDepth == fEntityDepth) { - fStringBuffer2.append('\n'); - } - } else if (c != -1 && XMLChar.isHighSurrogate(c)) { fStringBuffer3.clear(); if (scanSurrogates(fStringBuffer3)) { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java index 4be8d68e153..332aeb54206 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java @@ -21,6 +21,7 @@ package com.sun.org.apache.xerces.internal.impl; +import static com.sun.org.apache.xerces.internal.impl.Constants.XML_VERSION_1_1; import com.sun.org.apache.xerces.internal.impl.XMLScanner.NameType; import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; import com.sun.org.apache.xerces.internal.util.XML11Char; @@ -40,7 +41,7 @@ * @author Michael Glavassevich, IBM * @author Neil Graham, IBM * - * @LastModified: Apr 2021 + * @LastModified: Aug 2021 */ public class XML11EntityScanner @@ -116,7 +117,7 @@ protected int scanChar(NameType nt) throws IOException { load(1, false, false); offset = 0; } - if (c == '\r' && external) { + if (c == '\r' && external && fCurrentEntity.position < fCurrentEntity.count) { int cc = fCurrentEntity.ch[fCurrentEntity.position++]; if (cc != '\n' && cc != 0x85) { fCurrentEntity.position--; @@ -761,71 +762,12 @@ else if (fCurrentEntity.position == fCurrentEntity.count - 1) { } // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; - boolean counted = false; - boolean external = fCurrentEntity.isExternal(); - if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) { - do { - c = fCurrentEntity.ch[fCurrentEntity.position++]; - if ((c == '\r' ) && external) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - checkEntityLimit(null, fCurrentEntity, offset, newlines); - offset = 0; - fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); - fCurrentEntity.position = newlines; - fCurrentEntity.startPosition = newlines; - if (load(newlines, false, true)) { - counted = true; - break; - } - } - int cc = fCurrentEntity.ch[fCurrentEntity.position]; - if (cc == '\n' || cc == 0x85) { - fCurrentEntity.position++; - offset++; - } - /*** NEWLINE NORMALIZATION ***/ - else { - newlines++; - } - } - else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - checkEntityLimit(null, fCurrentEntity, offset, newlines); - offset = 0; - fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); - fCurrentEntity.position = newlines; - fCurrentEntity.startPosition = newlines; - if (load(newlines, false, true)) { - counted = true; - break; - } - } - } - else { - fCurrentEntity.position--; - break; - } - } while (fCurrentEntity.position < fCurrentEntity.count - 1); - for (int i = offset; i < fCurrentEntity.position; i++) { - fCurrentEntity.ch[i] = '\n'; - } - int length = fCurrentEntity.position - offset; - if (fCurrentEntity.position == fCurrentEntity.count - 1) { - checkEntityLimit(null, fCurrentEntity, offset, length); - content.setValues(fCurrentEntity.ch, offset, length); - return -1; - } + if (normalizeNewlines(XML_VERSION_1_1, content, false, false, null)) { + return -1; } + int c; + boolean external = fCurrentEntity.isExternal(); // inner loop, scanning for content if (external) { while (fCurrentEntity.position < fCurrentEntity.count) { @@ -913,65 +855,12 @@ else if (fCurrentEntity.position == fCurrentEntity.count - 1) { } // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; - boolean external = fCurrentEntity.isExternal(); - if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) { - do { - c = fCurrentEntity.ch[fCurrentEntity.position++]; - if ((c == '\r' ) && external) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); - fCurrentEntity.position = newlines; - fCurrentEntity.startPosition = newlines; - if (load(newlines, false, true)) { - break; - } - } - int cc = fCurrentEntity.ch[fCurrentEntity.position]; - if (cc == '\n' || cc == 0x85) { - fCurrentEntity.position++; - offset++; - } - /*** NEWLINE NORMALIZATION ***/ - else { - newlines++; - } - } - else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); - fCurrentEntity.position = newlines; - fCurrentEntity.startPosition = newlines; - if (load(newlines, false, true)) { - break; - } - } - } - else { - fCurrentEntity.position--; - break; - } - } while (fCurrentEntity.position < fCurrentEntity.count - 1); - for (int i = offset; i < fCurrentEntity.position; i++) { - fCurrentEntity.ch[i] = '\n'; - } - int length = fCurrentEntity.position - offset; - if (fCurrentEntity.position == fCurrentEntity.count - 1) { - content.setValues(fCurrentEntity.ch, offset, length); - return -1; - } + if (normalizeNewlines(XML_VERSION_1_1, content, false, true, null)) { + return -1; } + int c; + boolean external = fCurrentEntity.isExternal(); // scan literal value if (external) { while (fCurrentEntity.position < fCurrentEntity.count) { @@ -1093,66 +982,11 @@ protected boolean scanData(String delimiter, XMLStringBuffer buffer, int chunkLi } // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; - if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) { - do { - c = fCurrentEntity.ch[fCurrentEntity.position++]; - if ((c == '\r' ) && external) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); - fCurrentEntity.position = newlines; - fCurrentEntity.startPosition = newlines; - if (load(newlines, false, true)) { - break; - } - } - int cc = fCurrentEntity.ch[fCurrentEntity.position]; - if (cc == '\n' || cc == 0x85) { - fCurrentEntity.position++; - offset++; - } - /*** NEWLINE NORMALIZATION ***/ - else { - newlines++; - } - } - else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); - fCurrentEntity.position = newlines; - fCurrentEntity.startPosition = newlines; - fCurrentEntity.count = newlines; - if (load(newlines, false, true)) { - break; - } - } - } - else { - fCurrentEntity.position--; - break; - } - } while (fCurrentEntity.position < fCurrentEntity.count - 1); - for (int i = offset; i < fCurrentEntity.position; i++) { - fCurrentEntity.ch[i] = '\n'; - } - int length = fCurrentEntity.position - offset; - if (fCurrentEntity.position == fCurrentEntity.count - 1) { - checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length); - buffer.append(fCurrentEntity.ch, offset, length); - return true; - } + if (normalizeNewlines(XML_VERSION_1_1, buffer, true, false, NameType.COMMENT)) { + return true; } + int c; // iterate over buffer looking for delimiter OUTER: while (fCurrentEntity.position < fCurrentEntity.count) { c = fCurrentEntity.ch[fCurrentEntity.position++]; @@ -1256,22 +1090,6 @@ else if (c == '\n' && ((cc == 0x2028 || cc == 0x85) && fCurrentEntity.isExternal checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset); return true; } - else if (c == '\n' && (cc == '\r' ) && fCurrentEntity.isExternal()) { - // handle newlines - if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(1); - fCurrentEntity.ch[0] = (char)cc; - load(1, false, false); - } - int ccc = fCurrentEntity.ch[++fCurrentEntity.position]; - if (ccc == '\n' || ccc == 0x85) { - fCurrentEntity.position++; - } - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset); - return true; - } // character was not skipped return false; diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java index c48ed8f70be..89adb81b05b 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java @@ -21,6 +21,8 @@ package com.sun.org.apache.xerces.internal.impl; +import static com.sun.org.apache.xerces.internal.impl.Constants.XML_VERSION_1_0; +import static com.sun.org.apache.xerces.internal.impl.Constants.XML_VERSION_1_1; import com.sun.org.apache.xerces.internal.impl.XMLScanner.NameType; import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader; import com.sun.org.apache.xerces.internal.impl.io.UCSReader; @@ -55,7 +57,7 @@ * @author Arnaud Le Hors, IBM * @author K.Venugopal Sun Microsystems * - * @LastModified: Apr 2021 + * @LastModified: Aug 2021 */ public class XMLEntityScanner implements XMLLocator { @@ -149,6 +151,15 @@ public Throwable fillInStackTrace() { // indicates that the operation is for detecting XML version boolean detectingVersion = false; + // offset of the current cursor position + int offset = 0; + + // number of newlines in the current process + int newlines = 0; + + // indicating whether the content has been counted towards limit + boolean counted = false; + // // Constructors // @@ -553,7 +564,7 @@ protected int scanChar(NameType nt) throws IOException { } // scan character - int offset = fCurrentEntity.position; + offset = fCurrentEntity.position; int c = fCurrentEntity.ch[fCurrentEntity.position++]; if (c == '\n' || (c == '\r' && isExternal)) { fCurrentEntity.lineNumber++; @@ -561,10 +572,10 @@ protected int scanChar(NameType nt) throws IOException { if (fCurrentEntity.position == fCurrentEntity.count) { invokeListeners(1); fCurrentEntity.ch[0] = (char)c; - load(1, false, false); + load(1, true, false); offset = 0; } - if (c == '\r' && isExternal) { + if (c == '\r' && isExternal && fCurrentEntity.position < fCurrentEntity.count) { if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n') { fCurrentEntity.position--; } @@ -614,7 +625,7 @@ protected String scanNmtoken() throws IOException { } // scan nmtoken - int offset = fCurrentEntity.position; + offset = fCurrentEntity.position; boolean vc = false; char c; while (true){ @@ -695,7 +706,7 @@ protected String scanName(NameType nt) throws IOException { } // scan name - int offset = fCurrentEntity.position; + offset = fCurrentEntity.position; int length; if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) { if (++fCurrentEntity.position == fCurrentEntity.count) { @@ -788,7 +799,7 @@ protected boolean scanQName(QName qname, NameType nt) throws IOException { } // scan qualified name - int offset = fCurrentEntity.position; + offset = fCurrentEntity.position; //making a check if if the specified character is a valid name start character //as defined by production [5] in the XML 1.0 specification. @@ -1043,81 +1054,11 @@ protected int scanContent(XMLString content) throws IOException { } // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; - boolean counted = false; - if (c == '\n' || (c == '\r' && isExternal)) { - if (DEBUG_BUFFER) { - System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } - do { - c = fCurrentEntity.ch[fCurrentEntity.position++]; - if (c == '\r' && isExternal) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - checkEntityLimit(null, fCurrentEntity, offset, newlines); - offset = 0; - fCurrentEntity.position = newlines; - if (load(newlines, false, true)) { - counted = true; - break; - } - } - if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') { - fCurrentEntity.position++; - offset++; - } - /*** NEWLINE NORMALIZATION ***/ - else { - newlines++; - } - } else if (c == '\n') { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - checkEntityLimit(null, fCurrentEntity, offset, newlines); - offset = 0; - fCurrentEntity.position = newlines; - if (load(newlines, false, true)) { - counted = true; - break; - } - } - } else { - fCurrentEntity.position--; - break; - } - } while (fCurrentEntity.position < fCurrentEntity.count - 1); - for (int i = offset; i < fCurrentEntity.position; i++) { - fCurrentEntity.ch[i] = '\n'; - } - int length = fCurrentEntity.position - offset; - if (fCurrentEntity.position == fCurrentEntity.count - 1) { - checkEntityLimit(null, fCurrentEntity, offset, length); - //CHANGED: dont replace the value.. append to the buffer. This gives control to the callee - //on buffering the data.. - content.setValues(fCurrentEntity.ch, offset, length); - //content.append(fCurrentEntity.ch, offset, length); - if (DEBUG_BUFFER) { - System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } - return -1; - } - if (DEBUG_BUFFER) { - System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } + if (normalizeNewlines(XML_VERSION_1_0, content, false, false, null)) { + return -1; } + int c; while (fCurrentEntity.position < fCurrentEntity.count) { c = fCurrentEntity.ch[fCurrentEntity.position++]; if (!XMLChar.isContent(c)) { @@ -1202,85 +1143,14 @@ protected int scanLiteral(int quote, XMLString content, boolean isNSURI) } // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; if(whiteSpaceInfoNeeded) whiteSpaceLen=0; - if (c == '\n' || (c == '\r' && isExternal)) { - if (DEBUG_BUFFER) { - System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } - do { - c = fCurrentEntity.ch[fCurrentEntity.position++]; - if (c == '\r' && isExternal) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.position = newlines; - if (load(newlines, false, true)) { - break; - } - } - if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') { - fCurrentEntity.position++; - offset++; - } - /*** NEWLINE NORMALIZATION ***/ - else { - newlines++; - } - /***/ - } else if (c == '\n') { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.position = newlines; - if (load(newlines, false, true)) { - break; - } - } - /*** NEWLINE NORMALIZATION *** - * if (fCurrentEntity.ch[fCurrentEntity.position] == '\r' - * && external) { - * fCurrentEntity.position++; - * offset++; - * } - * /***/ - } else { - fCurrentEntity.position--; - break; - } - } while (fCurrentEntity.position < fCurrentEntity.count - 1); - int i=0; - for ( i = offset; i < fCurrentEntity.position; i++) { - fCurrentEntity.ch[i] = '\n'; - storeWhiteSpace(i); - } - int length = fCurrentEntity.position - offset; - if (fCurrentEntity.position == fCurrentEntity.count - 1) { - content.setValues(fCurrentEntity.ch, offset, length); - if (DEBUG_BUFFER) { - System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } - return -1; - } - if (DEBUG_BUFFER) { - System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } + if (normalizeNewlines(XML_VERSION_1_0, content, false, true, null)) { + return -1; } + int c; // scan literal value for (; fCurrentEntity.position= whiteSpaceLookup.length) { int [] tmp = new int[whiteSpaceLookup.length + 100]; System.arraycopy(whiteSpaceLookup, 0, tmp, 0, whiteSpaceLookup.length); @@ -1415,75 +1285,11 @@ protected boolean scanData(String delimiter, XMLStringBuffer buffer, int chunkLi return false; } - // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; - if (c == '\n' || (c == '\r' && isExternal)) { - if (DEBUG_BUFFER) { - System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } - do { - c = fCurrentEntity.ch[fCurrentEntity.position++]; - if (c == '\r' && isExternal) { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.position = newlines; - if (load(newlines, false, true)) { - break; - } - } - if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') { - fCurrentEntity.position++; - offset++; - } - /*** NEWLINE NORMALIZATION ***/ - else { - newlines++; - } - } else if (c == '\n') { - newlines++; - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (fCurrentEntity.position == fCurrentEntity.count) { - offset = 0; - fCurrentEntity.position = newlines; - fCurrentEntity.count = newlines; - if (load(newlines, false, true)) { - break; - } - } - } else { - fCurrentEntity.position--; - break; - } - } while (fCurrentEntity.position < fCurrentEntity.count - 1); - for (int i = offset; i < fCurrentEntity.position; i++) { - fCurrentEntity.ch[i] = '\n'; - } - int length = fCurrentEntity.position - offset; - if (fCurrentEntity.position == fCurrentEntity.count - 1) { - checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length); - buffer.append(fCurrentEntity.ch, offset, length); - if (DEBUG_BUFFER) { - System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } - return true; - } - if (DEBUG_BUFFER) { - System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); - print(); - System.out.println(); - } + if (normalizeNewlines(XML_VERSION_1_0, buffer, true, false, NameType.COMMENT)) { + return true; } + int c; // iterate over buffer looking for delimiter OUTER: while (fCurrentEntity.position < fCurrentEntity.count) { c = fCurrentEntity.ch[fCurrentEntity.position++]; @@ -1570,7 +1376,7 @@ protected boolean skipChar(int c, NameType nt) throws IOException { } // skip character - int offset = fCurrentEntity.position; + offset = fCurrentEntity.position; int cc = fCurrentEntity.ch[fCurrentEntity.position]; if (cc == c) { fCurrentEntity.position++; @@ -1587,26 +1393,6 @@ protected boolean skipChar(int c, NameType nt) throws IOException { } checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset); return true; - } else if (c == '\n' && cc == '\r' && isExternal) { - // handle newlines - if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(1); - fCurrentEntity.ch[0] = (char)cc; - load(1, false, false); - } - fCurrentEntity.position++; - if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') { - fCurrentEntity.position++; - } - fCurrentEntity.lineNumber++; - fCurrentEntity.columnNumber = 1; - if (DEBUG_BUFFER) { - System.out.print(")skipChar, '"+(char)c+"': "); - print(); - System.out.println(" -> true"); - } - checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset); - return true; } // character was not skipped @@ -1659,7 +1445,7 @@ protected boolean skipSpaces() throws IOException { // skip spaces int c = fCurrentEntity.ch[fCurrentEntity.position]; - int offset = fCurrentEntity.position - 1; + offset = fCurrentEntity.position - 1; if (XMLChar.isSpace(c)) { do { boolean entityChanged = false; @@ -2332,5 +2118,86 @@ protected final boolean skipDeclSpaces() throws IOException { } // skipDeclSpaces():boolean + /** + * Normalizes newlines. As specified in XML specification, this method + * converts newlines, '\n', '\r' and '\r\n' to '\n' as 2.11 End-of-Line Handling. + * Further, it may put them in a cache for later process as needed, for example + * as specified in 3.3.3 Attribute-Value Normalization. + * + * @ImplNote this method does not limit to processing external parsed entities + * as 2.11 required. It handles all cases where newlines need to be processed. + * + * @param buffer the current content buffer + * @param append a flag indicating whether to append to the buffer + * @param storeWS a flag indicating whether the whitespaces need to be stored + * for later processing + * @param nt the type of the entity + * @return true if the cursor is at the end of the current entity, false otherwise. + * @throws IOException + */ + protected boolean normalizeNewlines(short version, XMLString buffer, boolean append, + boolean storeWS, NameType nt) + throws IOException { + // normalize newlines + offset = fCurrentEntity.position; + int c = fCurrentEntity.ch[offset]; + newlines = 0; + // how this information is used is determined by the caller of this method + counted = false; + if ((c == '\n' || c == '\r') || + (version == XML_VERSION_1_1 && (c == 0x85 || c == 0x2028))) { + do { + c = fCurrentEntity.ch[fCurrentEntity.position++]; + if ((c == '\n' || c == '\r') || + (version == XML_VERSION_1_1 && (c == 0x85 || c == 0x2028))) { + newlines++; + fCurrentEntity.lineNumber++; + fCurrentEntity.columnNumber = 1; + if (fCurrentEntity.position == fCurrentEntity.count) { + checkEntityLimit(nt, fCurrentEntity, offset, newlines); + offset = 0; + fCurrentEntity.position = newlines; + if (load(newlines, false, true)) { + counted = true; + break; + } + } + if (c == '\r') { + int cc = fCurrentEntity.ch[fCurrentEntity.position]; + if (cc == '\n' || (version == XML_VERSION_1_1 && cc == 0x85)) { + fCurrentEntity.position++; + offset++; + } + /*** NEWLINE NORMALIZATION ***/ + else { + newlines++; + } + } + } else { + fCurrentEntity.position--; + break; + } + } while (fCurrentEntity.position < fCurrentEntity.count - 1); + + for (int i = offset; i < fCurrentEntity.position; i++) { + fCurrentEntity.ch[i] = '\n'; + if (storeWS) { + storeWhiteSpace(i); + } + } + int length = fCurrentEntity.position - offset; + if (fCurrentEntity.position == fCurrentEntity.count - 1) { + checkEntityLimit(nt, fCurrentEntity, offset, length); + if (append) { + buffer.append(fCurrentEntity.ch, offset, length); + } else { + buffer.setValues(fCurrentEntity.ch, offset, length); + } + + return true; + } + } + return false; + } } // class XMLEntityScanner diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java index 6a6362199c5..2102b8558fa 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -67,7 +67,7 @@ * @author Eric Ye, IBM * @author K.Venugopal SUN Microsystems * @author Sunitha Reddy, SUN Microsystems - * @LastModified: Feb 2020 + * @LastModified: Aug 2021 */ public abstract class XMLScanner implements XMLComponent { @@ -956,12 +956,6 @@ protected void scanAttributeValue(XMLString value, XMLString nonNormalizedValue, System.out.println("** valueF: \"" + stringBuffer.toString() + "\""); } - } else if (c == '\n' || c == '\r') { - fEntityScanner.scanChar(null); - stringBuffer.append(' '); - if (entityDepth == fEntityDepth && fNeedNonNormalizedValue) { - fStringBuffer2.append('\n'); - } } else if (c != -1 && XMLChar.isHighSurrogate(c)) { fStringBuffer3.clear(); if (scanSurrogates(fStringBuffer3)) { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/XMLStringBuffer.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/XMLStringBuffer.java index 9e915738423..118aeb7ad96 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/XMLStringBuffer.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/XMLStringBuffer.java @@ -1,6 +1,5 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -41,19 +40,11 @@ * * @author Andy Clark, IBM * @author Eric Ye, IBM - * + * @LastModified: Aug 2021 */ public class XMLStringBuffer extends XMLString { - // - // Constants - // - - - /** Default buffer size (32). */ - public static final int DEFAULT_SIZE = 32; - // // Data // @@ -112,79 +103,4 @@ public void clear() { length = 0; } - /** - * append - * - * @param c - */ - public void append(char c) { - if(this.length + 1 > this.ch.length){ - int newLength = this.ch.length * 2 ; - if(newLength < this.ch.length + DEFAULT_SIZE){ - newLength = this.ch.length + DEFAULT_SIZE; - } - char [] tmp = new char[newLength]; - System.arraycopy(this.ch, 0, tmp, 0, this.length); - this.ch = tmp; - } - this.ch[this.length] = c ; - this.length++; - } // append(char) - - /** - * append - * - * @param s - */ - public void append(String s) { - int length = s.length(); - if (this.length + length > this.ch.length) { - int newLength = this.ch.length * 2 ; - if(newLength < this.ch.length + length + DEFAULT_SIZE){ - newLength = this.ch.length + length+ DEFAULT_SIZE; - } - - char[] newch = new char[newLength]; - System.arraycopy(this.ch, 0, newch, 0, this.length); - this.ch = newch; - } - s.getChars(0, length, this.ch, this.length); - this.length += length; - } // append(String) - - /** - * append - * - * @param ch - * @param offset - * @param length - */ - public void append(char[] ch, int offset, int length) { - if (this.length + length > this.ch.length) { - int newLength = this.ch.length * 2 ; - if(newLength < this.ch.length + length + DEFAULT_SIZE){ - newLength = this.ch.length + length + DEFAULT_SIZE; - } - char[] newch = new char[newLength]; - System.arraycopy(this.ch, 0, newch, 0, this.length); - this.ch = newch; - } - //making the code more robust as it would handle null or 0 length data, - //add the data only when it contains some thing - if(ch != null && length > 0){ - System.arraycopy(ch, offset, this.ch, this.length, length); - this.length += length; - } - } // append(char[],int,int) - - /** - * append - * - * @param s - */ - public void append(XMLString s) { - append(s.ch, s.offset, s.length); - } // append(XMLString) - - } // class XMLStringBuffer diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xni/XMLString.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xni/XMLString.java index f63e1d20aa6..9d26c252651 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xni/XMLString.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xni/XMLString.java @@ -1,6 +1,5 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -42,9 +41,11 @@ * * @author Eric Ye, IBM * @author Andy Clark, IBM - * + * @LastModified: Aug 2021 */ public class XMLString { + /** Default buffer size (32). */ + public static final int DEFAULT_SIZE = 32; // // Data @@ -189,4 +190,78 @@ public String toString() { return length > 0 ? new String(ch, offset, length) : ""; } // toString():String + /** + * Appends a char to the buffer. + * + * @param c the char + */ + public void append(char c) { + if(this.length + 1 > this.ch.length){ + int newLength = this.ch.length * 2 ; + if(newLength < this.ch.length + DEFAULT_SIZE){ + newLength = this.ch.length + DEFAULT_SIZE; + } + char [] tmp = new char[newLength]; + System.arraycopy(this.ch, 0, tmp, 0, this.length); + this.ch = tmp; + } + this.ch[this.length] = c ; + this.length++; + } // append(char) + + /** + * Appends a string to the buffer. + * + * @param s the string + */ + public void append(String s) { + int length = s.length(); + if (this.length + length > this.ch.length) { + int newLength = this.ch.length * 2 ; + if(newLength < this.ch.length + length + DEFAULT_SIZE){ + newLength = this.ch.length + length+ DEFAULT_SIZE; + } + + char[] newch = new char[newLength]; + System.arraycopy(this.ch, 0, newch, 0, this.length); + this.ch = newch; + } + s.getChars(0, length, this.ch, this.length); + this.length += length; + } // append(String) + + /** + * Appends a number of characters to the buffer. + * + * @param ch the char array + * @param offset the offset + * @param length the length + */ + public void append(char[] ch, int offset, int length) { + if (this.length + length > this.ch.length) { + int newLength = this.ch.length * 2 ; + if(newLength < this.ch.length + length + DEFAULT_SIZE){ + newLength = this.ch.length + length + DEFAULT_SIZE; + } + char[] newch = new char[newLength]; + System.arraycopy(this.ch, 0, newch, 0, this.length); + this.ch = newch; + } + //making the code more robust as it would handle null or 0 length data, + //add the data only when it contains some thing + if(ch != null && length > 0){ + System.arraycopy(ch, offset, this.ch, this.length, length); + this.length += length; + } + } // append(char[],int,int) + + /** + * Appends another buffer to this buffer + * + * @param s another buffer + */ + public void append(XMLString s) { + append(s.ch, s.offset, s.length); + } // append(XMLString) + } // class XMLString From 759cbcba6ddf624d401249b8c87bd095ae2a97b3 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 16:54:36 +0000 Subject: [PATCH 048/253] 8272838: Move CriticalJNI tests out of tier1 Backport-of: f55d5ab5177b6e08e8499abc181a320a98b28a5f --- test/hotspot/jtreg/TEST.groups | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups index 89071c0fcba..b59eb2220f5 100644 --- a/test/hotspot/jtreg/TEST.groups +++ b/test/hotspot/jtreg/TEST.groups @@ -197,6 +197,7 @@ tier1_gc = \ :tier1_gc_2 \ :tier1_gc_gcold \ :tier1_gc_gcbasher \ + :tier1_gc_epsilon \ :tier1_gc_shenandoah hotspot_not_fast_gc = \ @@ -204,21 +205,27 @@ hotspot_not_fast_gc = \ -:tier1_gc tier1_gc_1 = \ - :gc_epsilon \ gc/g1/ \ -gc/g1/ihop/TestIHOPErgo.java tier1_gc_2 = \ gc/ \ - -:gc_epsilon \ + -gc/CriticalNativeArgs.java \ -gc/g1/ \ -gc/logging/TestUnifiedLoggingSwitchStress.java \ -gc/stress \ -gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java \ + -gc/epsilon \ -gc/shenandoah -gc_epsilon = \ - gc/epsilon/ \ +hotspot_gc_epsilon = \ + :tier1_gc_epsilon \ + :tier2_gc_epsilon + +tier1_gc_epsilon = \ + gc/epsilon/ + +tier2_gc_epsilon = \ gc/CriticalNativeArgs.java \ gc/stress/CriticalNativeStress.java @@ -237,8 +244,7 @@ tier1_gc_shenandoah = \ gc/shenandoah/compiler/ \ gc/shenandoah/mxbeans/ \ gc/shenandoah/TestSmallHeap.java \ - gc/shenandoah/oom/ \ - gc/CriticalNativeArgs.java + gc/shenandoah/oom/ tier2_gc_shenandoah = \ runtime/MemberName/MemberNameLeak.java \ @@ -260,9 +266,10 @@ tier2_gc_shenandoah = \ gc/logging/TestUnifiedLoggingSwitchStress.java \ runtime/Metaspace/DefineClass.java \ gc/shenandoah/ \ + gc/CriticalNativeArgs.java \ + gc/stress/CriticalNativeStress.java \ serviceability/sa/TestHeapDumpForInvokeDynamic.java \ -gc/shenandoah/TestStringDedupStress.java \ - -gc/stress/CriticalNativeStress.java \ -:tier1_gc_shenandoah tier3_gc_shenandoah = \ @@ -271,7 +278,6 @@ tier3_gc_shenandoah = \ gc/stress/gclocker/TestGCLockerWithShenandoah.java \ gc/stress/systemgc/TestSystemGCWithShenandoah.java \ gc/shenandoah/TestStringDedupStress.java \ - gc/stress/CriticalNativeStress.java \ -:tier2_gc_shenandoah hotspot_gc_shenandoah = \ From fc8078a09a0596613dcb8b8e3c4d862f754b0f90 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 16:55:51 +0000 Subject: [PATCH 049/253] 8263375: Support stack watermarks in Zero VM Backport-of: 857a930bde8b53f77a23737f4ca6ff8f3da2af66 --- src/hotspot/cpu/zero/frame_zero.cpp | 14 +++++++--- src/hotspot/cpu/zero/vm_version_zero.hpp | 2 ++ src/hotspot/cpu/zero/zeroInterpreter_zero.cpp | 26 +++++++++++++++++++ src/hotspot/cpu/zero/zeroInterpreter_zero.hpp | 3 +++ .../interpreter/zero/bytecodeInterpreter.cpp | 20 +++----------- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/hotspot/cpu/zero/frame_zero.cpp b/src/hotspot/cpu/zero/frame_zero.cpp index 972b835cd4b..8a735f3f563 100644 --- a/src/hotspot/cpu/zero/frame_zero.cpp +++ b/src/hotspot/cpu/zero/frame_zero.cpp @@ -34,6 +34,7 @@ #include "runtime/frame.inline.hpp" #include "runtime/handles.inline.hpp" #include "runtime/signature.hpp" +#include "runtime/stackWatermarkSet.hpp" #include "vmreg_zero.inline.hpp" #ifdef ASSERT @@ -82,10 +83,15 @@ frame frame::sender(RegisterMap* map) const { // sender_for_xxx methods update this accordingly. map->set_include_argument_oops(false); - if (is_entry_frame()) - return sender_for_entry_frame(map); - else - return sender_for_nonentry_frame(map); + frame result = zeroframe()->is_entry_frame() ? + sender_for_entry_frame(map) : + sender_for_nonentry_frame(map); + + if (map->process_frames()) { + StackWatermarkSet::on_iteration(map->thread(), result); + } + + return result; } BasicObjectLock* frame::interpreter_frame_monitor_begin() const { diff --git a/src/hotspot/cpu/zero/vm_version_zero.hpp b/src/hotspot/cpu/zero/vm_version_zero.hpp index 84e1abb5894..c63a47719e5 100644 --- a/src/hotspot/cpu/zero/vm_version_zero.hpp +++ b/src/hotspot/cpu/zero/vm_version_zero.hpp @@ -32,6 +32,8 @@ class VM_Version : public Abstract_VM_Version { public: static void initialize(); + + constexpr static bool supports_stack_watermark_barrier() { return true; } }; #endif // CPU_ZERO_VM_VERSION_ZERO_HPP diff --git a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp index 14fc8c0b00c..e56fa162fda 100644 --- a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp +++ b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp @@ -200,6 +200,18 @@ void ZeroInterpreter::main_loop(int recurse, TRAPS) { } fixup_after_potential_safepoint(); + // If we are unwinding, notify the stack watermarks machinery. + // Should do this before resetting the frame anchor. + if (istate->msg() == BytecodeInterpreter::return_from_method || + istate->msg() == BytecodeInterpreter::do_osr) { + stack_watermark_unwind_check(thread); + } else { + assert(istate->msg() == BytecodeInterpreter::call_method || + istate->msg() == BytecodeInterpreter::more_monitors || + istate->msg() == BytecodeInterpreter::throwing_exception, + "Should be one of these otherwise"); + } + // Clear the frame anchor thread->reset_last_Java_frame(); @@ -436,6 +448,10 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { thread->set_thread_state(_thread_in_Java); fixup_after_potential_safepoint(); + // Notify the stack watermarks machinery that we are unwinding. + // Should do this before resetting the frame anchor. + stack_watermark_unwind_check(thread); + // Clear the frame anchor thread->reset_last_Java_frame(); @@ -869,3 +885,13 @@ address ZeroInterpreter::remove_activation_early_entry(TosState state) { bool ZeroInterpreter::contains(address pc) { return false; // make frame::print_value_on work } + +void ZeroInterpreter::stack_watermark_unwind_check(JavaThread* thread) { + // If frame pointer is in the danger zone, notify the runtime that + // it needs to act before continuing the unwinding. + uintptr_t fp = (uintptr_t)thread->last_Java_fp(); + uintptr_t watermark = thread->poll_data()->get_polling_word(); + if (fp > watermark) { + InterpreterRuntime::at_unwind(thread); + } +} diff --git a/src/hotspot/cpu/zero/zeroInterpreter_zero.hpp b/src/hotspot/cpu/zero/zeroInterpreter_zero.hpp index 2d1d28f4da5..3761dfc5814 100644 --- a/src/hotspot/cpu/zero/zeroInterpreter_zero.hpp +++ b/src/hotspot/cpu/zero/zeroInterpreter_zero.hpp @@ -39,6 +39,9 @@ static int empty_entry(Method* method, intptr_t UNUSED, TRAPS); static int Reference_get_entry(Method* method, intptr_t UNUSED, TRAPS); + // Stack watermark machinery + static void stack_watermark_unwind_check(JavaThread* thread); + public: // Main loop of normal_entry static void main_loop(int recurse, TRAPS); diff --git a/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp b/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp index e10a86361b9..87d7a19b099 100644 --- a/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp +++ b/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp @@ -107,7 +107,7 @@ There really shouldn't be any handles remaining to trash but this is cheap in relation to a safepoint. */ -#define SAFEPOINT \ +#define RETURN_SAFEPOINT \ if (SafepointMechanism::should_process(THREAD)) { \ HandleMarkCleaner __hmc(THREAD); \ CALL_VM(SafepointMechanism::process_if_requested_with_exit_check(THREAD, true /* check asyncs */), \ @@ -1336,23 +1336,15 @@ void BytecodeInterpreter::run(interpreterState istate) { CASE(_areturn): CASE(_ireturn): CASE(_freturn): - { - // Allow a safepoint before returning to frame manager. - SAFEPOINT; - - goto handle_return; - } - CASE(_lreturn): CASE(_dreturn): - { + CASE(_return): { // Allow a safepoint before returning to frame manager. - SAFEPOINT; + RETURN_SAFEPOINT; goto handle_return; } CASE(_return_register_finalizer): { - oop rcvr = LOCALS_OBJECT(0); VERIFY_OOP(rcvr); if (rcvr->klass()->has_finalizer()) { @@ -1360,12 +1352,6 @@ void BytecodeInterpreter::run(interpreterState istate) { } goto handle_return; } - CASE(_return): { - - // Allow a safepoint before returning to frame manager. - SAFEPOINT; - goto handle_return; - } /* Array access byte-codes */ From c2dc88fe56a21b66058d3d64ffd5b3bfd936b791 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 16:58:14 +0000 Subject: [PATCH 050/253] 8272850: Drop zapping values in the Zap* option descriptions Backport-of: c5a271259d9761aaae9298e9f29ebd93d734fb0e --- src/hotspot/share/runtime/globals.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 8779036b440..8c61e6a05ae 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -456,22 +456,22 @@ const intx ObjectAlignmentInBytes = 8; "Use only malloc/free for allocation (no resource area/arena)") \ \ develop(bool, ZapResourceArea, trueInDebug, \ - "Zap freed resource/arena space with 0xABABABAB") \ + "Zap freed resource/arena space") \ \ notproduct(bool, ZapVMHandleArea, trueInDebug, \ - "Zap freed VM handle space with 0xBCBCBCBC") \ + "Zap freed VM handle space") \ \ notproduct(bool, ZapStackSegments, trueInDebug, \ - "Zap allocated/freed stack segments with 0xFADFADED") \ + "Zap allocated/freed stack segments") \ \ develop(bool, ZapUnusedHeapArea, trueInDebug, \ - "Zap unused heap space with 0xBAADBABE") \ + "Zap unused heap space") \ \ develop(bool, CheckZapUnusedHeapArea, false, \ "Check zapping of unused heap space") \ \ develop(bool, ZapFillerObjects, trueInDebug, \ - "Zap filler objects with 0xDEAFBABE") \ + "Zap filler objects") \ \ product(bool, ExecutingUnitTests, false, \ "Whether the JVM is running unit tests or not") \ From 92ff65241676905f12bcf9a7d68970884828eae9 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 17:01:07 +0000 Subject: [PATCH 051/253] 8272970: Parallelize runtime/InvocationTests/ Backport-of: 6cfe314262dacd6ca1a74c000d045b1cabd374db --- test/hotspot/jtreg/ProblemList.txt | 4 +- .../InvocationTests/invocationC1Tests.java | 57 ++++++++++++++---- .../invocationOldCHATests.java | 55 ++++++++++++++---- .../InvocationTests/invokeinterfaceTests.java | 58 ++++++++++++++++--- .../InvocationTests/invokespecialTests.java | 56 +++++++++++++++--- .../InvocationTests/invokevirtualTests.java | 56 +++++++++++++++--- 6 files changed, 238 insertions(+), 48 deletions(-) diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index aa8a556c7be..32b371dcc4c 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -91,7 +91,9 @@ gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java 8241293 macosx-x64 runtime/cds/appcds/jigsaw/modulepath/ModulePathAndCP_JFR.java 8253437 windows-x64 runtime/cds/DeterministicDump.java 8253495 generic-all -runtime/InvocationTests/invokevirtualTests.java 8271125 generic-all +runtime/InvocationTests/invokevirtualTests.java#current-int 8271125 generic-all +runtime/InvocationTests/invokevirtualTests.java#current-comp 8271125 generic-all +runtime/InvocationTests/invokevirtualTests.java#old-int 8271125 generic-all runtime/jni/terminatedThread/TestTerminatedThread.java 8219652 aix-ppc64 runtime/os/TestTracePageSizes.java#no-options 8267460 linux-aarch64 runtime/os/TestTracePageSizes.java#explicit-large-page-size 8267460 linux-aarch64 diff --git a/test/hotspot/jtreg/runtime/InvocationTests/invocationC1Tests.java b/test/hotspot/jtreg/runtime/InvocationTests/invocationC1Tests.java index 759f7440840..38b785de232 100644 --- a/test/hotspot/jtreg/runtime/InvocationTests/invocationC1Tests.java +++ b/test/hotspot/jtreg/runtime/InvocationTests/invocationC1Tests.java @@ -23,20 +23,41 @@ */ /* - * @test + * @test id=special * @bug 8226956 * @summary Run invocation tests against C1 compiler * @library /test/lib * @modules java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.misc - * @compile shared/AbstractGenerator.java shared/AccessCheck.java shared/AccessType.java - * shared/Caller.java shared/ExecutorGenerator.java shared/Utils.java - * shared/ByteArrayClassLoader.java shared/Checker.java shared/GenericClassGenerator.java * @compile invokespecial/Checker.java invokespecial/ClassGenerator.java invokespecial/Generator.java - * invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java - * invokeinterface/Checker.java invokeinterface/ClassGenerator.java invokeinterface/Generator.java * - * @run driver/timeout=1800 invocationC1Tests + * @run driver/timeout=1800 invocationC1Tests special + */ + +/* + * @test id=virtual + * @bug 8226956 + * @summary Run invocation tests against C1 compiler + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java + * + * @run driver/timeout=1800 invocationC1Tests virtual + */ + +/* + * @test id=interface + * @bug 8226956 + * @summary Run invocation tests against C1 compiler + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokeinterface/Checker.java invokeinterface/ClassGenerator.java invokeinterface/Generator.java + * + * @run driver/timeout=1800 invocationC1Tests interface */ import jdk.test.lib.process.ProcessTools; @@ -72,11 +93,27 @@ public static void runTest(String whichTests, String classFileVersion) throws Th } public static void main(String args[]) throws Throwable { + if (args.length < 1) { + throw new IllegalArgumentException("Should provide the test name"); + } + String testName = args[0]; + // Get current major class file version and test with it. byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }"); int major_version = klassbuf[6] << 8 | klassbuf[7]; - runTest("invokespecial.Generator", String.valueOf(major_version)); - runTest("invokeinterface.Generator", String.valueOf(major_version)); - runTest("invokevirtual.Generator", String.valueOf(major_version)); + + switch (testName) { + case "special": + runTest("invokespecial.Generator", String.valueOf(major_version)); + break; + case "virtual": + runTest("invokevirtual.Generator", String.valueOf(major_version)); + break; + case "interface": + runTest("invokeinterface.Generator", String.valueOf(major_version)); + break; + default: + throw new IllegalArgumentException("Unknown test name: " + testName); + } } } diff --git a/test/hotspot/jtreg/runtime/InvocationTests/invocationOldCHATests.java b/test/hotspot/jtreg/runtime/InvocationTests/invocationOldCHATests.java index 3326a72bb7d..4ae6d2157e5 100644 --- a/test/hotspot/jtreg/runtime/InvocationTests/invocationOldCHATests.java +++ b/test/hotspot/jtreg/runtime/InvocationTests/invocationOldCHATests.java @@ -23,19 +23,38 @@ */ /* - * @test + * @test id=special * @summary Run invocation tests with old CHA (-XX:-UseVtableBasedCHA) * @library /test/lib * @modules java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.misc - * @compile shared/AbstractGenerator.java shared/AccessCheck.java shared/AccessType.java - * shared/Caller.java shared/ExecutorGenerator.java shared/Utils.java - * shared/ByteArrayClassLoader.java shared/Checker.java shared/GenericClassGenerator.java * @compile invokespecial/Checker.java invokespecial/ClassGenerator.java invokespecial/Generator.java - * invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java - * invokeinterface/Checker.java invokeinterface/ClassGenerator.java invokeinterface/Generator.java * - * @run driver/timeout=1800 invocationOldCHATests + * @run driver/timeout=1800 invocationOldCHATests special + */ + +/* + * @test id=virtual + * @summary Run invocation tests with old CHA (-XX:-UseVtableBasedCHA) + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java + * + * @run driver/timeout=1800 invocationOldCHATests virtual + */ + +/* + * @test id=interface + * @summary Run invocation tests with old CHA (-XX:-UseVtableBasedCHA) + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokeinterface/Checker.java invokeinterface/ClassGenerator.java invokeinterface/Generator.java + * + * @run driver/timeout=1800 invocationOldCHATests interface */ import jdk.test.lib.process.ProcessTools; @@ -71,11 +90,27 @@ public static void runTest(String whichTests, String classFileVersion) throws Th } public static void main(String args[]) throws Throwable { + if (args.length < 1) { + throw new IllegalArgumentException("Should provide the test name"); + } + String testName = args[0]; + // Get current major class file version and test with it. byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }"); int major_version = klassbuf[6] << 8 | klassbuf[7]; - runTest("invokespecial.Generator", String.valueOf(major_version)); - runTest("invokeinterface.Generator", String.valueOf(major_version)); - runTest("invokevirtual.Generator", String.valueOf(major_version)); + + switch (testName) { + case "special": + runTest("invokespecial.Generator", String.valueOf(major_version)); + break; + case "virtual": + runTest("invokevirtual.Generator", String.valueOf(major_version)); + break; + case "interface": + runTest("invokeinterface.Generator", String.valueOf(major_version)); + break; + default: + throw new IllegalArgumentException("Unknown test name: " + testName); + } } } diff --git a/test/hotspot/jtreg/runtime/InvocationTests/invokeinterfaceTests.java b/test/hotspot/jtreg/runtime/InvocationTests/invokeinterfaceTests.java index 5efccfeaa19..7f449a7e4c4 100644 --- a/test/hotspot/jtreg/runtime/InvocationTests/invokeinterfaceTests.java +++ b/test/hotspot/jtreg/runtime/InvocationTests/invokeinterfaceTests.java @@ -23,19 +23,44 @@ */ /* - * @test + * @test id=current-int * @bug 8224137 * @summary Run invokeinterface invocation tests * @library /test/lib * @modules java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.misc - * @compile shared/AbstractGenerator.java shared/AccessCheck.java shared/AccessType.java - * shared/Caller.java shared/ExecutorGenerator.java shared/Utils.java - * shared/ByteArrayClassLoader.java shared/Checker.java shared/GenericClassGenerator.java * @compile invokeinterface/Checker.java invokeinterface/ClassGenerator.java * invokeinterface/Generator.java * - * @run driver/timeout=1800 invokeinterfaceTests + * @run driver/timeout=1800 invokeinterfaceTests current-int + */ + +/* + * @test id=current-comp + * @bug 8224137 + * @summary Run invokeinterface invocation tests + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokeinterface/Checker.java invokeinterface/ClassGenerator.java + * invokeinterface/Generator.java + * + * @run driver/timeout=1800 invokeinterfaceTests current-comp + */ + +/* + * @test id=old-int + * @bug 8224137 + * @summary Run invokeinterface invocation tests + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokeinterface/Checker.java invokeinterface/ClassGenerator.java + * invokeinterface/Generator.java + * + * @run driver/timeout=1800 invokeinterfaceTests old-int */ import jdk.test.lib.process.ProcessTools; @@ -70,13 +95,28 @@ public static void runTest(String classFileVersion, String option) throws Throwa } public static void main(String args[]) throws Throwable { + if (args.length < 1) { + throw new IllegalArgumentException("Should provide the test name"); + } + String testName = args[0]; + // Get current major class file version and test with it. byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }"); int major_version = klassbuf[6] << 8 | klassbuf[7]; - runTest(String.valueOf(major_version), "-Xint"); - runTest(String.valueOf(major_version), "-Xcomp"); - // Test old class file version. - runTest("51", "-Xint"); // JDK-7 + switch (testName) { + case "current-int": + runTest(String.valueOf(major_version), "-Xint"); + break; + case "current-comp": + runTest(String.valueOf(major_version), "-Xcomp"); + break; + case "old-int": + // Test old class file version. + runTest("51", "-Xint"); // JDK-7 + break; + default: + throw new IllegalArgumentException("Unknown test name: " + testName); + } } } diff --git a/test/hotspot/jtreg/runtime/InvocationTests/invokespecialTests.java b/test/hotspot/jtreg/runtime/InvocationTests/invokespecialTests.java index a37cca5681c..2635f5ae54f 100644 --- a/test/hotspot/jtreg/runtime/InvocationTests/invokespecialTests.java +++ b/test/hotspot/jtreg/runtime/InvocationTests/invokespecialTests.java @@ -23,18 +23,41 @@ */ /* - * @test + * @test id=current-int * @bug 8224137 * @summary Run invokespecial invocation tests * @library /test/lib * @modules java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.misc - * @compile shared/AbstractGenerator.java shared/AccessCheck.java shared/AccessType.java - * shared/Caller.java shared/ExecutorGenerator.java shared/Utils.java - * shared/ByteArrayClassLoader.java shared/Checker.java shared/GenericClassGenerator.java * @compile invokespecial/Checker.java invokespecial/ClassGenerator.java invokespecial/Generator.java * - * @run driver/timeout=1800 invokespecialTests + * @run driver/timeout=1800 invokespecialTests current-int + */ + +/* + * @test id=current-comp + * @bug 8224137 + * @summary Run invokespecial invocation tests + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokespecial/Checker.java invokespecial/ClassGenerator.java invokespecial/Generator.java + * + * @run driver/timeout=1800 invokespecialTests current-comp + */ + +/* + * @test id=old-int + * @bug 8224137 + * @summary Run invokespecial invocation tests + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokespecial/Checker.java invokespecial/ClassGenerator.java invokespecial/Generator.java + * + * @run driver/timeout=1800 invokespecialTests old-int */ import jdk.test.lib.process.ProcessTools; @@ -69,13 +92,28 @@ public static void runTest(String classFileVersion, String option) throws Throwa } public static void main(String args[]) throws Throwable { + if (args.length < 1) { + throw new IllegalArgumentException("Should provide the test name"); + } + String testName = args[0]; + // Get current major class file version and test with it. byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }"); int major_version = klassbuf[6] << 8 | klassbuf[7]; - runTest(String.valueOf(major_version), "-Xint"); - runTest(String.valueOf(major_version), "-Xcomp"); - // Test old class file version. - runTest("51", "-Xint"); // JDK-7 + switch (testName) { + case "current-int": + runTest(String.valueOf(major_version), "-Xint"); + break; + case "current-comp": + runTest(String.valueOf(major_version), "-Xcomp"); + break; + case "old-int": + // Test old class file version. + runTest("51", "-Xint"); // JDK-7 + break; + default: + throw new IllegalArgumentException("Unknown test name: " + testName); + } } } diff --git a/test/hotspot/jtreg/runtime/InvocationTests/invokevirtualTests.java b/test/hotspot/jtreg/runtime/InvocationTests/invokevirtualTests.java index a8892ad42d7..eb73dd8ccd7 100644 --- a/test/hotspot/jtreg/runtime/InvocationTests/invokevirtualTests.java +++ b/test/hotspot/jtreg/runtime/InvocationTests/invokevirtualTests.java @@ -23,18 +23,41 @@ */ /* - * @test + * @test id=current-int * @bug 8224137 * @summary Run invokevirtual invocation tests * @library /test/lib * @modules java.base/jdk.internal.org.objectweb.asm * java.base/jdk.internal.misc - * @compile shared/AbstractGenerator.java shared/AccessCheck.java shared/AccessType.java - * shared/Caller.java shared/ExecutorGenerator.java shared/Utils.java - * shared/ByteArrayClassLoader.java shared/Checker.java shared/GenericClassGenerator.java * @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java * - * @run driver/timeout=1800 invokevirtualTests + * @run driver/timeout=1800 invokevirtualTests current-int + */ + +/* + * @test id=current-comp + * @bug 8224137 + * @summary Run invokevirtual invocation tests + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java + * + * @run driver/timeout=1800 invokevirtualTests current-comp + */ + +/* + * @test id=old-int + * @bug 8224137 + * @summary Run invokevirtual invocation tests + * @requires vm.flagless + * @library /test/lib + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.misc + * @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java + * + * @run driver/timeout=1800 invokevirtualTests old-int */ import jdk.test.lib.process.ProcessTools; @@ -69,13 +92,28 @@ public static void runTest(String classFileVersion, String option) throws Throwa } public static void main(String args[]) throws Throwable { + if (args.length < 1) { + throw new IllegalArgumentException("Should provide the test name"); + } + String testName = args[0]; + // Get current major class file version and test with it. byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }"); int major_version = klassbuf[6] << 8 | klassbuf[7]; - runTest(String.valueOf(major_version), "-Xint"); - runTest(String.valueOf(major_version), "-Xcomp"); - // Test old class file version. - runTest("51", "-Xint"); // JDK-7 + switch (testName) { + case "current-int": + runTest(String.valueOf(major_version), "-Xint"); + break; + case "current-comp": + runTest(String.valueOf(major_version), "-Xcomp"); + break; + case "old-int": + // Test old class file version. + runTest("51", "-Xint"); // JDK-7 + break; + default: + throw new IllegalArgumentException("Unknown test name: " + testName); + } } } From bf788eee88040f0bbcd8f9dd9e59a71ee23b9f95 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 17:02:21 +0000 Subject: [PATCH 052/253] 8271862: C2 intrinsic for Reference.refersTo() is often not used Backport-of: 3f723ca4577b9cffeb6153ee386edd75f1dfb1c6 --- .../share/classes/java/lang/ref/PhantomReference.java | 6 +++++- .../share/classes/java/lang/ref/Reference.java | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/java.base/share/classes/java/lang/ref/PhantomReference.java b/src/java.base/share/classes/java/lang/ref/PhantomReference.java index 9aba41feb02..2c1532b8eb2 100644 --- a/src/java.base/share/classes/java/lang/ref/PhantomReference.java +++ b/src/java.base/share/classes/java/lang/ref/PhantomReference.java @@ -69,8 +69,12 @@ public T get() { * do reference processing concurrently. */ @Override + boolean refersToImpl(T obj) { + return refersTo0(obj); + } + @IntrinsicCandidate - native final boolean refersTo0(Object o); + private native boolean refersTo0(Object o); /** * Creates a new phantom reference that refers to the given object and diff --git a/src/java.base/share/classes/java/lang/ref/Reference.java b/src/java.base/share/classes/java/lang/ref/Reference.java index 0a312f97422..24fc7dc5f4e 100644 --- a/src/java.base/share/classes/java/lang/ref/Reference.java +++ b/src/java.base/share/classes/java/lang/ref/Reference.java @@ -363,13 +363,20 @@ public T get() { * @since 16 */ public final boolean refersTo(T obj) { - return refersTo0(obj); + return refersToImpl(obj); } /* Implementation of refersTo(), overridden for phantom references. + * This method exists only to avoid making refersTo0() virtual. Making + * refersTo0() virtual has the undesirable effect of C2 often preferring + * to call the native implementation over the intrinsic. */ + boolean refersToImpl(T obj) { + return refersTo0(obj); + } + @IntrinsicCandidate - native boolean refersTo0(Object o); + private native boolean refersTo0(Object o); /** * Clears this reference object. Invoking this method will not cause this From 3a650aa64133aa530849a4c2330b30352e17f693 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 17:03:48 +0000 Subject: [PATCH 053/253] 8271605: Update JMH devkit to 1.32 Backport-of: e74537f9241e57b4668ff542364220936e920330 --- make/devkit/createJMHBundle.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make/devkit/createJMHBundle.sh b/make/devkit/createJMHBundle.sh index 9e0b9c06e4f..848e8e1e432 100644 --- a/make/devkit/createJMHBundle.sh +++ b/make/devkit/createJMHBundle.sh @@ -1,6 +1,6 @@ #!/bin/bash -e # -# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, 2021, 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,7 @@ # Create a bundle in the build directory, containing what's needed to # build and run JMH microbenchmarks from the OpenJDK build. -JMH_VERSION=1.28 +JMH_VERSION=1.32 COMMONS_MATH3_VERSION=3.2 JOPT_SIMPLE_VERSION=4.6 From cd1d3e018958660a2946c7ea97e9c2cd536f8b5f Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 20 Sep 2021 17:06:06 +0000 Subject: [PATCH 054/253] 8272318: Improve performance of HeapDumpAllTest Backport-of: 73da66ffb707abf6dc38368a12e337d52597de25 --- .../serviceability/dcmd/gc/HeapDumpAllTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpAllTest.java b/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpAllTest.java index d811493c1d3..0d7d23eecc8 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpAllTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpAllTest.java @@ -21,6 +21,10 @@ * questions. */ +import java.io.IOException; + +import jdk.test.lib.dcmd.CommandExecutor; + /* * @test * @summary Test of diagnostic command GC.heap_dump -all=true @@ -37,6 +41,14 @@ public HeapDumpAllTest() { heapDumpArgs = "-all=true"; } + @Override + public void run(CommandExecutor executor, boolean overwrite) throws IOException { + // Trigger gc by hand, so the created heap dump isnt't too large and + // takes too long to parse. + System.gc(); + super.run(executor, overwrite); + } + /* See HeapDumpTest for test cases */ } From 793d08a74b6dc6e78233a4f60c232a1ee7e832ba Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Mon, 20 Sep 2021 17:08:01 +0000 Subject: [PATCH 055/253] 8214761: Bug in parallel Kahan summation implementation Backport-of: dd871819a05886ee09fc00c7c778268440ebedb7 --- .../java/util/DoubleSummaryStatistics.java | 6 +- .../classes/java/util/stream/Collectors.java | 17 ++- .../java/util/stream/DoublePipeline.java | 8 +- .../DoubleStreamSums/CompensatedSums.java | 141 ++++++++++++++++++ .../NegativeCompensation.java | 73 +++++++++ 5 files changed, 235 insertions(+), 10 deletions(-) create mode 100644 test/jdk/java/util/DoubleStreamSums/CompensatedSums.java create mode 100644 test/jdk/java/util/DoubleSummaryStatistics/NegativeCompensation.java diff --git a/src/java.base/share/classes/java/util/DoubleSummaryStatistics.java b/src/java.base/share/classes/java/util/DoubleSummaryStatistics.java index 91628353c62..06cd7aadfe2 100644 --- a/src/java.base/share/classes/java/util/DoubleSummaryStatistics.java +++ b/src/java.base/share/classes/java/util/DoubleSummaryStatistics.java @@ -156,7 +156,9 @@ public void combine(DoubleSummaryStatistics other) { count += other.count; simpleSum += other.simpleSum; sumWithCompensation(other.sum); - sumWithCompensation(other.sumCompensation); + + // Subtract compensation bits + sumWithCompensation(-other.sumCompensation); min = Math.min(min, other.min); max = Math.max(max, other.max); } @@ -241,7 +243,7 @@ public final long getCount() { */ public final double getSum() { // Better error bounds to add both terms as the final sum - double tmp = sum + sumCompensation; + double tmp = sum - sumCompensation; if (Double.isNaN(tmp) && Double.isInfinite(simpleSum)) // If the compensated sum is spuriously NaN from // accumulating one or more same-signed infinite values, diff --git a/src/java.base/share/classes/java/util/stream/Collectors.java b/src/java.base/share/classes/java/util/stream/Collectors.java index 0cf8cdbc7f7..94780d2ae16 100644 --- a/src/java.base/share/classes/java/util/stream/Collectors.java +++ b/src/java.base/share/classes/java/util/stream/Collectors.java @@ -734,7 +734,8 @@ public static Collector collectingAndThen(Collector dow a[2] += val;}, (a, b) -> { sumWithCompensation(a, b[0]); a[2] += b[2]; - return sumWithCompensation(a, b[1]); }, + // Subtract compensation bits + return sumWithCompensation(a, -b[1]); }, a -> computeFinalSum(a), CH_NOID); } @@ -765,8 +766,8 @@ static double[] sumWithCompensation(double[] intermediateSum, double value) { * correctly-signed infinity stored in the simple sum. */ static double computeFinalSum(double[] summands) { - // Better error bounds to add both terms as the final sum - double tmp = summands[0] + summands[1]; + // Final sum with better error bounds subtract second summand as it is negated + double tmp = summands[0] - summands[1]; double simpleSum = summands[summands.length - 1]; if (Double.isNaN(tmp) && Double.isInfinite(simpleSum)) return simpleSum; @@ -840,13 +841,19 @@ static double computeFinalSum(double[] summands) { /* * In the arrays allocated for the collect operation, index 0 * holds the high-order bits of the running sum, index 1 holds - * the low-order bits of the sum computed via compensated + * the negated low-order bits of the sum computed via compensated * summation, and index 2 holds the number of values seen. */ return new CollectorImpl<>( () -> new double[4], (a, t) -> { double val = mapper.applyAsDouble(t); sumWithCompensation(a, val); a[2]++; a[3]+= val;}, - (a, b) -> { sumWithCompensation(a, b[0]); sumWithCompensation(a, b[1]); a[2] += b[2]; a[3] += b[3]; return a; }, + (a, b) -> { + sumWithCompensation(a, b[0]); + // Subtract compensation bits + sumWithCompensation(a, -b[1]); + a[2] += b[2]; a[3] += b[3]; + return a; + }, a -> (a[2] == 0) ? 0.0d : (computeFinalSum(a) / a[2]), CH_NOID); } diff --git a/src/java.base/share/classes/java/util/stream/DoublePipeline.java b/src/java.base/share/classes/java/util/stream/DoublePipeline.java index 66d4ed719ee..9771440f8aa 100644 --- a/src/java.base/share/classes/java/util/stream/DoublePipeline.java +++ b/src/java.base/share/classes/java/util/stream/DoublePipeline.java @@ -442,7 +442,7 @@ public final double sum() { /* * In the arrays allocated for the collect operation, index 0 * holds the high-order bits of the running sum, index 1 holds - * the low-order bits of the sum computed via compensated + * the negated low-order bits of the sum computed via compensated * summation, and index 2 holds the simple sum used to compute * the proper result if the stream contains infinite values of * the same sign. @@ -454,7 +454,8 @@ public final double sum() { }, (ll, rr) -> { Collectors.sumWithCompensation(ll, rr[0]); - Collectors.sumWithCompensation(ll, rr[1]); + // Subtract compensation bits + Collectors.sumWithCompensation(ll, -rr[1]); ll[2] += rr[2]; }); @@ -497,7 +498,8 @@ public final OptionalDouble average() { }, (ll, rr) -> { Collectors.sumWithCompensation(ll, rr[0]); - Collectors.sumWithCompensation(ll, rr[1]); + // Subtract compensation bits + Collectors.sumWithCompensation(ll, -rr[1]); ll[2] += rr[2]; ll[3] += rr[3]; }); diff --git a/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java b/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java new file mode 100644 index 00000000000..a4967c26884 --- /dev/null +++ b/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021, 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 8214761 + * @run testng CompensatedSums + * @summary + */ + +import java.util.Random; +import java.util.function.BiConsumer; +import java.util.function.ObjDoubleConsumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.DoubleStream; + +import static org.testng.Assert.assertTrue; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class CompensatedSums { + + @Test + public void testCompensatedSums() { + double naive = 0; + double jdkSequentialStreamError = 0; + double goodSequentialStreamError = 0; + double jdkParallelStreamError = 0; + double goodParallelStreamError = 0; + double badParallelStreamError = 0; + + for (int loop = 0; loop < 100; loop++) { + // sequence of random numbers of varying magnitudes, both positive and negative + double[] rand = new Random().doubles(1_000_000) + .map(Math::log) + .map(x -> (Double.doubleToLongBits(x) % 2 == 0) ? x : -x) + .toArray(); + + // base case: standard Kahan summation + double[] sum = new double[2]; + for (int i=0; i < rand.length; i++) { + sumWithCompensation(sum, rand[i]); + } + + // All error is the squared difference of the standard Kahan Sum vs JDK Stream sum implementation + // Older less accurate implementations included here as the baseline. + + // squared error of naive sum by reduction - should be large + naive += Math.pow(DoubleStream.of(rand).reduce((x, y) -> x+y).getAsDouble() - sum[0], 2); + + // squared error of sequential sum - should be 0 + jdkSequentialStreamError += Math.pow(DoubleStream.of(rand).sum() - sum[0], 2); + + goodSequentialStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0], 2); + + // squared error of parallel sum from the JDK + jdkParallelStreamError += Math.pow(DoubleStream.of(rand).parallel().sum() - sum[0], 2); + + // squared error of parallel sum + goodParallelStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0], 2); + + // the bad parallel stream + badParallelStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,badCollectorConsumer)) - sum[0], 2); + + + } + + Assert.assertEquals(goodSequentialStreamError, 0.0); + Assert.assertEquals(goodSequentialStreamError, jdkSequentialStreamError); + + Assert.assertTrue(jdkParallelStreamError <= goodParallelStreamError); + Assert.assertTrue(badParallelStreamError > goodParallelStreamError); + + Assert.assertTrue(naive > jdkSequentialStreamError); + Assert.assertTrue(naive > jdkParallelStreamError); + + } + + // from OpenJDK8 Collectors, unmodified + static double[] sumWithCompensation(double[] intermediateSum, double value) { + double tmp = value - intermediateSum[1]; + double sum = intermediateSum[0]; + double velvel = sum + tmp; // Little wolf of rounding error + intermediateSum[1] = (velvel - sum) - tmp; + intermediateSum[0] = velvel; + return intermediateSum; + } + + // from OpenJDK8 Collectors, unmodified + static double computeFinalSum(double[] summands) { + double tmp = summands[0] + summands[1]; + double simpleSum = summands[summands.length - 1]; + if (Double.isNaN(tmp) && Double.isInfinite(simpleSum)) + return simpleSum; + else + return tmp; + } + + //Suppliers and consumers for Double Stream summation collection. + static Supplier doubleSupplier = () -> new double[3]; + static ObjDoubleConsumer objDoubleConsumer = (double[] ll, double d) -> { + sumWithCompensation(ll, d); + ll[2] += d; + }; + static BiConsumer badCollectorConsumer = + (ll, rr) -> { + sumWithCompensation(ll, rr[0]); + sumWithCompensation(ll, rr[1]); + ll[2] += rr[2]; + }; + + static BiConsumer goodCollectorConsumer = + (ll, rr) -> { + sumWithCompensation(ll, rr[0]); + sumWithCompensation(ll, -rr[1]); + ll[2] += rr[2]; + }; + +} \ No newline at end of file diff --git a/test/jdk/java/util/DoubleSummaryStatistics/NegativeCompensation.java b/test/jdk/java/util/DoubleSummaryStatistics/NegativeCompensation.java new file mode 100644 index 00000000000..b43db37794c --- /dev/null +++ b/test/jdk/java/util/DoubleSummaryStatistics/NegativeCompensation.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021, 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 8214761 + * @run testng NegativeCompensation + * @summary When combining two DoubleSummaryStatistics, the compensation + * has to be subtracted. + */ + +import java.util.DoubleSummaryStatistics; +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +public class NegativeCompensation { + static final double VAL = 1.000000001; + static final int LOG_ITER = 21; + + @Test + public static void testErrorComparision() { + DoubleSummaryStatistics stat0 = new DoubleSummaryStatistics(); + DoubleSummaryStatistics stat1 = new DoubleSummaryStatistics(); + DoubleSummaryStatistics stat2 = new DoubleSummaryStatistics(); + + stat1.accept(VAL); + stat1.accept(VAL); + stat2.accept(VAL); + stat2.accept(VAL); + stat2.accept(VAL); + + for (int i = 0; i < LOG_ITER; ++i) { + stat1.combine(stat2); + stat2.combine(stat1); + } + + for (long i = 0, iend = stat2.getCount(); i < iend; ++i) { + stat0.accept(VAL); + } + + double res = 0; + for(long i = 0, iend = stat2.getCount(); i < iend; ++i) { + res += VAL; + } + + double absErrN = Math.abs(res - stat2.getSum()); + double absErr = Math.abs(stat0.getSum() - stat2.getSum()); + assertTrue(absErrN >= absErr, + "Naive sum error is not greater than or equal to Summary sum"); + assertEquals(absErr, 0.0, "Absolute error is not zero"); + } +} \ No newline at end of file From 74de3ef2a9899fe72391414881d4ee80e7ed239b Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Mon, 20 Sep 2021 17:41:45 +0000 Subject: [PATCH 056/253] 8273514: java/util/DoubleStreamSums/CompensatedSums.java failure Backport-of: f531b5c79633a12efa56c55366e0b7196350e896 --- .../DoubleStreamSums/CompensatedSums.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java b/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java index a4967c26884..13761e1efbc 100644 --- a/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java +++ b/test/jdk/java/util/DoubleStreamSums/CompensatedSums.java @@ -32,11 +32,8 @@ import java.util.function.BiConsumer; import java.util.function.ObjDoubleConsumer; import java.util.function.Supplier; -import java.util.stream.Collectors; import java.util.stream.DoubleStream; -import static org.testng.Assert.assertTrue; - import org.testng.Assert; import org.testng.annotations.Test; @@ -68,36 +65,38 @@ public void testCompensatedSums() { // Older less accurate implementations included here as the baseline. // squared error of naive sum by reduction - should be large - naive += Math.pow(DoubleStream.of(rand).reduce((x, y) -> x+y).getAsDouble() - sum[0], 2); + naive += square(DoubleStream.of(rand).reduce((x, y) -> x+y).getAsDouble() - sum[0]); // squared error of sequential sum - should be 0 - jdkSequentialStreamError += Math.pow(DoubleStream.of(rand).sum() - sum[0], 2); + jdkSequentialStreamError += square(DoubleStream.of(rand).sum() - sum[0]); - goodSequentialStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0], 2); + goodSequentialStreamError += square(computeFinalSum(DoubleStream.of(rand).collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0]); // squared error of parallel sum from the JDK - jdkParallelStreamError += Math.pow(DoubleStream.of(rand).parallel().sum() - sum[0], 2); + jdkParallelStreamError += square(DoubleStream.of(rand).parallel().sum() - sum[0]); // squared error of parallel sum - goodParallelStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0], 2); + goodParallelStreamError += square(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0]); // the bad parallel stream - badParallelStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,badCollectorConsumer)) - sum[0], 2); + badParallelStreamError += square(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,badCollectorConsumer)) - sum[0]); } - Assert.assertEquals(goodSequentialStreamError, 0.0); - Assert.assertEquals(goodSequentialStreamError, jdkSequentialStreamError); - Assert.assertTrue(jdkParallelStreamError <= goodParallelStreamError); - Assert.assertTrue(badParallelStreamError > goodParallelStreamError); + Assert.assertTrue(badParallelStreamError > jdkParallelStreamError); + Assert.assertTrue(goodSequentialStreamError >= jdkSequentialStreamError); Assert.assertTrue(naive > jdkSequentialStreamError); Assert.assertTrue(naive > jdkParallelStreamError); } + private static double square(double arg) { + return arg * arg; + } + // from OpenJDK8 Collectors, unmodified static double[] sumWithCompensation(double[] intermediateSum, double value) { double tmp = value - intermediateSum[1]; From 912ae51344e7694be3a9c1f3d60306ffcdd2fe38 Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Mon, 20 Sep 2021 18:00:16 +0000 Subject: [PATCH 057/253] 8272342: [TEST_BUG] java/awt/print/PrinterJob/PageDialogMarginTest.java catches all exceptions Backport-of: a5ad7720d235610ad45fc341c61f164805f82a54 --- .../PrinterJob/PageDialogMarginTest.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/test/jdk/java/awt/print/PrinterJob/PageDialogMarginTest.java b/test/jdk/java/awt/print/PrinterJob/PageDialogMarginTest.java index 3efc1125049..de47e70f639 100644 --- a/test/jdk/java/awt/print/PrinterJob/PageDialogMarginTest.java +++ b/test/jdk/java/awt/print/PrinterJob/PageDialogMarginTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, 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 @@ -28,9 +28,10 @@ * entry is working * @run main/manual PageDialogMarginTest */ -import java.awt.Component; + import java.awt.print.PageFormat; import java.awt.print.PrinterJob; +import java.util.Locale; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.MediaPrintableArea; @@ -39,35 +40,31 @@ public class PageDialogMarginTest { - public static void main(String args[]) throws Exception { + public static void main(String[] args) throws Exception { + Locale.setDefault(Locale.US); String[] instructions = { "Page Dialog will be shown.", "Change top(in) margin value from 1.0 to 2.0", "Then select OK." }; - SwingUtilities.invokeAndWait(() -> { - JOptionPane.showMessageDialog((Component) null, - instructions, "Instructions", - JOptionPane.INFORMATION_MESSAGE); - }); + SwingUtilities.invokeAndWait(() -> JOptionPane.showMessageDialog(null, + instructions, "Instructions", + JOptionPane.INFORMATION_MESSAGE)); PrinterJob pj = PrinterJob.getPrinterJob(); - try { - HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); - PageFormat pf; - pf = pj.pageDialog(aset); - double left = pf.getImageableX(); - double top = pf.getImageableY(); - System.out.println("pageDialog - left/top from pageFormat: " + left / 72 - + " " + top / 72); - System.out.println("pageDialog - left/top from attribute set: " - + getPrintableXFromASet(aset) + " " - + getPrintableYFromASet(aset)); - if (top / 72 != 2.0f || getPrintableYFromASet(aset) != 2.0f) { - throw new RuntimeException("Top margin value not updated"); - } - } catch (Exception e) { - e.printStackTrace(); + + HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + PageFormat pf = pj.pageDialog(aset); + double left = pf.getImageableX(); + double top = pf.getImageableY(); + + System.out.println("pageDialog - left/top from pageFormat: " + left / 72 + + " " + top / 72); + System.out.println("pageDialog - left/top from attribute set: " + + getPrintableXFromASet(aset) + " " + + getPrintableYFromASet(aset)); + if (top / 72 != 2.0f || getPrintableYFromASet(aset) != 2.0f) { + throw new RuntimeException("Top margin value not updated"); } } From 73d605bdc61a60734e950cad7c040a1d800cdba0 Mon Sep 17 00:00:00 2001 From: Alexander Zuev Date: Tue, 21 Sep 2021 17:09:48 +0000 Subject: [PATCH 058/253] 8273290: Enhance sound handling Backport-of: 5d4a8f3c9ca82ed501944c670823b5de5e1ba344 --- .../classes/com/sun/media/sound/StandardMidiFileReader.java | 4 ++++ .../classes/com/sun/media/sound/WaveFloatFileReader.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileReader.java b/src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileReader.java index e13bae6ce92..6f5a4bbf3c9 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileReader.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileReader.java @@ -392,6 +392,10 @@ void readTrack(Track track) throws IOException, InvalidMidiDataException { // meta int metaType = readUnsigned(); int metaLength = (int) readVarInt(); + if (metaLength < 0) { + throw new InvalidMidiDataException("length out of bounds: " + + metaLength); + } final byte[] metaData; try { metaData = new byte[metaLength]; diff --git a/src/java.desktop/share/classes/com/sun/media/sound/WaveFloatFileReader.java b/src/java.desktop/share/classes/com/sun/media/sound/WaveFloatFileReader.java index 2c3be1507fc..f8365f71780 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/WaveFloatFileReader.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/WaveFloatFileReader.java @@ -73,6 +73,10 @@ StandardFileFormat getAudioFileFormatImpl(final InputStream stream) samplerate = chunk.readUnsignedInt(); /* framerate = */chunk.readUnsignedInt(); framesize = chunk.readUnsignedShort(); + if (framesize == 0) { + throw new UnsupportedAudioFileException( + "Can not process audio format with 0 frame size"); + } bits = chunk.readUnsignedShort(); } if (chunk.getFormat().equals("data")) { From cb6a08c04415a39993d87948915b5390d1d21beb Mon Sep 17 00:00:00 2001 From: Thejasvi Voniadka Date: Thu, 23 Sep 2021 05:24:05 +0000 Subject: [PATCH 059/253] 8273646: Add openssl from path variable also in to Default System Openssl Path in OpensslArtifactFetcher Backport-of: a5108a605e6a1e427d90dbeeb8630a3d01d6b405 --- test/lib/jdk/test/lib/security/OpensslArtifactFetcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/jdk/test/lib/security/OpensslArtifactFetcher.java b/test/lib/jdk/test/lib/security/OpensslArtifactFetcher.java index d70f187301e..55ff8c9ef98 100644 --- a/test/lib/jdk/test/lib/security/OpensslArtifactFetcher.java +++ b/test/lib/jdk/test/lib/security/OpensslArtifactFetcher.java @@ -82,8 +82,8 @@ private static String getOpensslFromSystemProp(String version) { } private static String getDefaultSystemOpensslPath(String version) { - if (verifyOpensslVersion("/usr/bin/openssl", version)) { - return "/usr/bin/openssl"; + if (verifyOpensslVersion("openssl", version)) { + return "openssl"; } else if (verifyOpensslVersion("/usr/local/bin/openssl", version)) { return "/usr/local/bin/openssl"; } From 4583bb037c57d2d81fb51c9e6a03d5176e1bdffb Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Thu, 23 Sep 2021 13:29:37 +0000 Subject: [PATCH 060/253] 8273756: Enhance BMP image support Backport-of: 2ee2053a0dde445237924f136c859c8b18ab882e --- .../imageio/plugins/bmp/BMPImageReader.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java index df283e8102c..8271c5cf263 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java @@ -52,6 +52,7 @@ import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import javax.imageio.IIOException; import javax.imageio.ImageIO; import javax.imageio.ImageReadParam; @@ -223,6 +224,33 @@ private void checkIndex(int imageIndex) { } } + private void readColorPalette(int sizeOfPalette) throws IOException { + final int UNIT_SIZE = 1024000; + if (sizeOfPalette < UNIT_SIZE) { + palette = new byte[sizeOfPalette]; + iis.readFully(palette, 0, sizeOfPalette); + } else { + int bytesToRead = sizeOfPalette; + int bytesRead = 0; + List bufs = new ArrayList<>(); + while (bytesToRead != 0) { + int sz = Math.min(bytesToRead, UNIT_SIZE); + byte[] unit = new byte[sz]; + iis.readFully(unit, 0, sz); + bufs.add(unit); + bytesRead += sz; + bytesToRead -= sz; + } + byte[] paletteData = new byte[bytesRead]; + int copiedBytes = 0; + for (byte[] ba : bufs) { + System.arraycopy(ba, 0, paletteData, copiedBytes, ba.length); + copiedBytes += ba.length; + } + palette = paletteData; + } + } + /** * Process the image header. * @@ -305,8 +333,7 @@ protected void readHeader() throws IOException, IllegalArgumentException { // Read in the palette int numberOfEntries = (int)((bitmapOffset - 14 - size) / 3); int sizeOfPalette = numberOfEntries*3; - palette = new byte[sizeOfPalette]; - iis.readFully(palette, 0, sizeOfPalette); + readColorPalette(sizeOfPalette); metadata.palette = palette; metadata.paletteSize = numberOfEntries; } else { @@ -343,8 +370,7 @@ protected void readHeader() throws IOException, IllegalArgumentException { } int numberOfEntries = (int)((bitmapOffset-14-size) / 4); int sizeOfPalette = numberOfEntries * 4; - palette = new byte[sizeOfPalette]; - iis.readFully(palette, 0, sizeOfPalette); + readColorPalette(sizeOfPalette); metadata.palette = palette; metadata.paletteSize = numberOfEntries; @@ -404,8 +430,7 @@ protected void readHeader() throws IOException, IllegalArgumentException { if (colorsUsed != 0) { // there is a palette sizeOfPalette = (int)colorsUsed*4; - palette = new byte[sizeOfPalette]; - iis.readFully(palette, 0, sizeOfPalette); + readColorPalette(sizeOfPalette); metadata.palette = palette; metadata.paletteSize = (int)colorsUsed; @@ -430,8 +455,7 @@ protected void readHeader() throws IOException, IllegalArgumentException { // Read in the palette int numberOfEntries = (int)((bitmapOffset-14-size) / 4); int sizeOfPalette = numberOfEntries*4; - palette = new byte[sizeOfPalette]; - iis.readFully(palette, 0, sizeOfPalette); + readColorPalette(sizeOfPalette); metadata.palette = palette; metadata.paletteSize = numberOfEntries; @@ -529,8 +553,7 @@ else if (size == 124) // Read in the palette int numberOfEntries = (int)((bitmapOffset-14-size) / 4); int sizeOfPalette = numberOfEntries*4; - palette = new byte[sizeOfPalette]; - iis.readFully(palette, 0, sizeOfPalette); + readColorPalette(sizeOfPalette); metadata.palette = palette; metadata.paletteSize = numberOfEntries; From 536d1b6de57cce299e69fe6676938d132ee3b809 Mon Sep 17 00:00:00 2001 From: Rob McKenna Date: Thu, 23 Sep 2021 16:36:56 +0000 Subject: [PATCH 061/253] 8268813: Better String matching Reviewed-by: igraves Backport-of: c1b73a786d5881315cb7119d89f719b79c6a0c67 --- src/java.base/share/classes/java/util/regex/Pattern.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index 5032ecfdab5..33080683c6a 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -3428,8 +3428,8 @@ private int N() { private static final int countChars(CharSequence seq, int index, int lengthInCodePoints) { // optimization - if (lengthInCodePoints == 1 && !Character.isHighSurrogate(seq.charAt(index))) { - assert (index >= 0 && index < seq.length()); + if (lengthInCodePoints == 1 && index >= 0 && index < seq.length() && + !Character.isHighSurrogate(seq.charAt(index))) { return 1; } int length = seq.length(); From 0c9807d8b336830e737e40bba122168664d6d20d Mon Sep 17 00:00:00 2001 From: Rob McKenna Date: Thu, 23 Sep 2021 17:47:38 +0000 Subject: [PATCH 062/253] 8273308: PatternMatchTest.java fails on CI Backport-of: 1a5bacfcf8e0c22e49b29c0f484f0e879227dc05 --- src/java.base/share/classes/java/util/regex/Pattern.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index 33080683c6a..1e03f56e38e 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -3435,7 +3435,7 @@ private static final int countChars(CharSequence seq, int index, int length = seq.length(); int x = index; if (lengthInCodePoints >= 0) { - assert (index >= 0 && index < length); + assert ((length == 0 && index == 0) || index >= 0 && index < length); for (int i = 0; x < length && i < lengthInCodePoints; i++) { if (Character.isHighSurrogate(seq.charAt(x++))) { if (x < length && Character.isLowSurrogate(seq.charAt(x))) { From 8cd93192a470a81daf233a3bc9a2e2cd31841892 Mon Sep 17 00:00:00 2001 From: Rajan Halade Date: Thu, 23 Sep 2021 19:36:24 +0000 Subject: [PATCH 063/253] 8274215: Remove globalsignr2ca root from 17.0.2 Reviewed-by: mullan --- make/data/cacerts/globalsignr2ca | 29 ------------------- .../security/lib/cacerts/VerifyCACerts.java | 8 ++--- 2 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 make/data/cacerts/globalsignr2ca diff --git a/make/data/cacerts/globalsignr2ca b/make/data/cacerts/globalsignr2ca deleted file mode 100644 index 746d1fab985..00000000000 --- a/make/data/cacerts/globalsignr2ca +++ /dev/null @@ -1,29 +0,0 @@ -Owner: CN=GlobalSign, O=GlobalSign, OU=GlobalSign Root CA - R2 -Issuer: CN=GlobalSign, O=GlobalSign, OU=GlobalSign Root CA - R2 -Serial number: 400000000010f8626e60d -Valid from: Fri Dec 15 08:00:00 GMT 2006 until: Wed Dec 15 08:00:00 GMT 2021 -Signature algorithm name: SHA1withRSA -Subject Public Key Algorithm: 2048-bit RSA key -Version: 3 ------BEGIN CERTIFICATE----- -MIIDujCCAqKgAwIBAgILBAAAAAABD4Ym5g0wDQYJKoZIhvcNAQEFBQAwTDEgMB4G -A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjIxEzARBgNVBAoTCkdsb2JhbFNp -Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDYxMjE1MDgwMDAwWhcNMjExMjE1 -MDgwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEG -A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI -hvcNAQEBBQADggEPADCCAQoCggEBAKbPJA6+Lm8omUVCxKs+IVSbC9N/hHD6ErPL -v4dfxn+G07IwXNb9rfF73OX4YJYJkhD10FPe+3t+c4isUoh7SqbKSaZeqKeMWhG8 -eoLrvozps6yWJQeXSpkqBy+0Hne/ig+1AnwblrjFuTosvNYSuetZfeLQBoZfXklq -tTleiDTsvHgMCJiEbKjNS7SgfQx5TfC4LcshytVsW33hoCmEofnTlEnLJGKRILzd -C9XZzPnqJworc5HGnRusyMvo4KD0L5CLTfuwNhv2GXqF4G3yYROIXJ/gkwpRl4pa -zq+r1feqCapgvdzZX99yqWATXgAByUr6P6TqBwMhAo6CygPCm48CAwEAAaOBnDCB -mTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUm+IH -V2ccHsBqBt5ZtJot39wZhi4wNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL2NybC5n -bG9iYWxzaWduLm5ldC9yb290LXIyLmNybDAfBgNVHSMEGDAWgBSb4gdXZxwewGoG -3lm0mi3f3BmGLjANBgkqhkiG9w0BAQUFAAOCAQEAmYFThxxol4aR7OBKuEQLq4Gs -J0/WwbgcQ3izDJr86iw8bmEbTUsp9Z8FHSbBuOmDAGJFtqkIk7mpM0sYmsL4h4hO -291xNBrBVNpGP+DTKqttVCL1OmLNIG+6KYnX3ZHu01yiPqFbQfXf5WRDLenVOavS -ot+3i9DAgBkcRcAtjOj4LaR0VknFBbVPFd5uRHg5h6h+u/N5GJG79G+dwfCMNYxd -AfvDbbnvRG15RjF+Cv6pgsH/76tuIMRQyV+dTZsXjAzlAcmgQWpzU/qlULRuJQ/7 -TBj0/VLZjmmx6BEP3ojY+x1J96relc8geMJgEtslQIxq/H5COEBkEveegeGTLg== ------END CERTIFICATE----- diff --git a/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java b/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java index bb0a51ed5fb..930aeee3167 100644 --- a/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java +++ b/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java @@ -27,7 +27,7 @@ * @bug 8189131 8198240 8191844 8189949 8191031 8196141 8204923 8195774 8199779 * 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 + * 8243559 8225072 8258630 8259312 8256421 8225081 8225082 8225083 * @summary Check root CA entries in cacerts file */ import java.io.ByteArrayInputStream; @@ -54,12 +54,12 @@ public class VerifyCACerts { + File.separator + "security" + File.separator + "cacerts"; // The numbers of certs now. - private static final int COUNT = 90; + private static final int COUNT = 89; // 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 - = "A2:36:27:B7:F6:99:7A:C7:7E:2D:55:47:66:57:08:3F:F8:8C:F2:28:77:29:30:40:A2:D3:6D:1A:B6:C7:32:6F"; + = "CC:AD:BB:49:70:97:3F:42:AD:73:91:A0:A2:C4:B8:AA:D1:95:59:F3:B3:22:09:2A:1F:2C:AB:04:47:08:EF:AA"; // Hex formatter to upper case with ":" delimiter private static final HexFormat HEX = HexFormat.ofDelimiter(":").withUpperCase(); @@ -220,8 +220,6 @@ public class VerifyCACerts { "17:9F:BC:14:8A:3D:D0:0F:D2:4E:A1:34:58:CC:43:BF:A7:F5:9C:81:82:D7:83:A5:13:F6:EB:EC:10:0C:89:24"); put("globalsigneccrootcar4 [jdk]", "BE:C9:49:11:C2:95:56:76:DB:6C:0A:55:09:86:D7:6E:3B:A0:05:66:7C:44:2C:97:62:B4:FB:B7:73:DE:22:8C"); - put("globalsignr2ca [jdk]", - "CA:42:DD:41:74:5F:D0:B8:1E:B9:02:36:2C:F9:D8:BF:71:9D:A1:BD:1B:1E:FC:94:6F:5B:4C:99:F4:2C:1B:9E"); put("teliasonerarootcav1 [jdk]", "DD:69:36:FE:21:F8:F0:77:C1:23:A1:A5:21:C1:22:24:F7:22:55:B7:3E:03:A7:26:06:93:E8:A2:4B:0F:A3:89"); put("globalsignrootcar6 [jdk]", From f2cb3d0f6cf16d12abd811b42484a0b7df8fd124 Mon Sep 17 00:00:00 2001 From: Sean Coffey Date: Fri, 24 Sep 2021 11:13:49 +0000 Subject: [PATCH 064/253] 8272026: Verify Jar Verification Backport-of: 0e2b2951adc965d6b71ffbc63b4293fd9fb68eaa --- .../classes/java/util/jar/Attributes.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index a33d1086285..3b59f74275f 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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,7 @@ package java.util.jar; +import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Collection; @@ -366,7 +367,7 @@ void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException { int read(Manifest.FastInputStream is, byte[] lbuf, String filename, int lineNumber) throws IOException { String name = null, value; - byte[] lastline = null; + ByteArrayOutputStream fullLine = new ByteArrayOutputStream(); int len; while ((len = is.readLine(lbuf)) != -1) { @@ -392,15 +393,12 @@ int read(Manifest.FastInputStream is, byte[] lbuf, String filename, int lineNumb + Manifest.getErrorPosition(filename, lineNumber) + ")"); } lineContinued = true; - byte[] buf = new byte[lastline.length + len - 1]; - System.arraycopy(lastline, 0, buf, 0, lastline.length); - System.arraycopy(lbuf, 1, buf, lastline.length, len - 1); + fullLine.write(lbuf, 1, len - 1); if (is.peek() == ' ') { - lastline = buf; continue; } - value = new String(buf, 0, buf.length, UTF_8.INSTANCE); - lastline = null; + value = fullLine.toString(UTF_8.INSTANCE); + fullLine.reset(); } else { while (lbuf[i++] != ':') { if (i >= len) { @@ -414,8 +412,8 @@ int read(Manifest.FastInputStream is, byte[] lbuf, String filename, int lineNumb } name = new String(lbuf, 0, i - 2, UTF_8.INSTANCE); if (is.peek() == ' ') { - lastline = new byte[len - i]; - System.arraycopy(lbuf, i, lastline, 0, len - i); + fullLine.reset(); + fullLine.write(lbuf, i, len - i); continue; } value = new String(lbuf, i, len - i, UTF_8.INSTANCE); From 9d590fc13b8a82fc3522bed65bb14ce77b1f4d94 Mon Sep 17 00:00:00 2001 From: Sergey Nazarkin Date: Fri, 24 Sep 2021 15:22:18 +0000 Subject: [PATCH 065/253] 8261236: C2: ClhsdbJstackXcompStress test fails when StressGCM is enabled Backport-of: 752b6df34c92c02ac0992566e3efa7bc22b96aa1 --- .../hotspot/compiler/ImmutableOopMapSet.java | 20 ++++++------ .../jvm/hotspot/compiler/OopMapStream.java | 31 +++---------------- .../ui/classbrowser/HTMLGenerator.java | 25 +++++++++------ 3 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/ImmutableOopMapSet.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/ImmutableOopMapSet.java index 4149643d133..540dcb682df 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/ImmutableOopMapSet.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/ImmutableOopMapSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2021, 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 @@ -201,11 +201,14 @@ public static void allDo(Frame fr, CodeBlob cb, RegisterMap regMap, OopMapVisito // changed before derived pointer offset has been collected) OopMapValue omv; { - for (OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE); !oms.isDone(); oms.next()) { + for (OopMapStream oms = new OopMapStream(map); !oms.isDone(); oms.next()) { + omv = oms.getCurrent(); + if (omv.getType() != OopMapValue.OopTypes.DERIVED_OOP_VALUE) { + continue; + } if (VM.getVM().isClientCompiler()) { Assert.that(false, "should not reach here"); } - omv = oms.getCurrent(); Address loc = fr.oopMapRegToLocation(omv.getReg(), regMap); if (loc != null) { Address baseLoc = fr.oopMapRegToLocation(omv.getContentReg(), regMap); @@ -216,12 +219,8 @@ public static void allDo(Frame fr, CodeBlob cb, RegisterMap regMap, OopMapVisito } // We want narow oop and oop oop_types - OopMapValue.OopTypes[] values = new OopMapValue.OopTypes[] { - OopMapValue.OopTypes.OOP_VALUE, OopMapValue.OopTypes.NARROWOOP_VALUE - }; - { - for (OopMapStream oms = new OopMapStream(map, values); !oms.isDone(); oms.next()) { + for (OopMapStream oms = new OopMapStream(map); !oms.isDone(); oms.next()) { omv = oms.getCurrent(); Address loc = fr.oopMapRegToLocation(omv.getReg(), regMap); if (loc != null) { @@ -278,8 +277,11 @@ public static void updateRegisterMap(Frame fr, CodeBlob cb, RegisterMap regMap, } OopMapValue omv = null; - for (OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE); !oms.isDone(); oms.next()) { + for (OopMapStream oms = new OopMapStream(map); !oms.isDone(); oms.next()) { omv = oms.getCurrent(); + if (omv.getType() != OopMapValue.OopTypes.CALLEE_SAVED_VALUE) { + continue; + } if (Assert.ASSERTS_ENABLED) { Assert.that(nofCallee < 2 * REG_COUNT, "overflow"); } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/OopMapStream.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/OopMapStream.java index 3dc1556a53e..6b0c2368a7d 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/OopMapStream.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/OopMapStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2021, 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 @@ -29,24 +29,13 @@ public class OopMapStream { private CompressedReadStream stream; private ImmutableOopMap oopMap; - private int mask; private int size; private int position; private OopMapValue omv; private boolean omvValid; public OopMapStream(ImmutableOopMap oopMap) { - this(oopMap, (OopMapValue.OopTypes[]) null); - } - - public OopMapStream(ImmutableOopMap oopMap, OopMapValue.OopTypes type) { - this(oopMap, (OopMapValue.OopTypes[]) null); - mask = type.getValue(); - } - - public OopMapStream(ImmutableOopMap oopMap, OopMapValue.OopTypes[] types) { stream = new CompressedReadStream(oopMap.getData()); - mask = computeMask(types); size = (int) oopMap.getCount(); position = 0; omv = new OopMapValue(); @@ -72,23 +61,11 @@ public OopMapValue getCurrent() { // Internals only below this point // - private int computeMask(OopMapValue.OopTypes[] types) { - mask = 0; - if (types != null) { - for (int i = 0; i < types.length; i++) { - mask |= types[i].getValue(); - } - } - return mask; - } - private void findNext() { - while (position++ < size) { + if (position++ < size) { omv.readFrom(stream); - if ((omv.getType().getValue() & mask) > 0) { - omvValid = true; - return; - } + omvValid = true; + return; } omvValid = false; } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java index 9a65fcc0d18..bf2ddffcb83 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java @@ -1180,7 +1180,8 @@ protected String genHTMLForOopMap(ImmutableOopMap map) { Formatter buf = new Formatter(genHTML); final class OopMapValueIterator { - final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) { + final Formatter iterate(OopMapStream oms, String type, boolean printContentReg, + OopMapValue.OopTypes filter) { Formatter tmpBuf = new Formatter(genHTML); boolean found = false; tmpBuf.beginTag("tr"); @@ -1188,7 +1189,7 @@ final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) tmpBuf.append(type); for (; ! oms.isDone(); oms.next()) { OopMapValue omv = oms.getCurrent(); - if (omv == null) { + if (omv == null || omv.getType() != filter) { continue; } found = true; @@ -1224,17 +1225,21 @@ final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) buf.beginTable(0); OopMapValueIterator omvIterator = new OopMapValueIterator(); - OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.OOP_VALUE); - buf.append(omvIterator.iterate(oms, "Oops:", false)); + OopMapStream oms = new OopMapStream(map); + buf.append(omvIterator.iterate(oms, "Oops:", false, + OopMapValue.OopTypes.OOP_VALUE)); - oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE); - buf.append(omvIterator.iterate(oms, "NarrowOops:", false)); + oms = new OopMapStream(map); + buf.append(omvIterator.iterate(oms, "NarrowOops:", false, + OopMapValue.OopTypes.NARROWOOP_VALUE)); - oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE); - buf.append(omvIterator.iterate(oms, "Callee saved:", true)); + oms = new OopMapStream(map); + buf.append(omvIterator.iterate(oms, "Callee saved:", true, + OopMapValue.OopTypes.CALLEE_SAVED_VALUE)); - oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE); - buf.append(omvIterator.iterate(oms, "Derived oops:", true)); + oms = new OopMapStream(map); + buf.append(omvIterator.iterate(oms, "Derived oops:", true, + OopMapValue.OopTypes.DERIVED_OOP_VALUE)); buf.endTag("table"); return buf.toString(); From 227e159de1dd5b387a52a63c0111bf5abcb1424f Mon Sep 17 00:00:00 2001 From: Olga Mikhaltsova Date: Mon, 27 Sep 2021 14:12:49 +0000 Subject: [PATCH 066/253] 8273375: Remove redundant 'new String' calls after concatenation in java.desktop Backport-of: 59c9f750414e4f131c906a5bc20f32f2f9cfe9ec --- .../laf/AquaTabbedPaneCopyFromBasicUI.java | 7 +++++-- .../classes/sun/java2d/IntegerNIORaster.java | 12 ++++++------ .../classes/java/awt/image/ColorModel.java | 13 ++++++------- .../java/awt/image/DirectColorModel.java | 11 +++++------ .../classes/java/awt/image/IndexColorModel.java | 17 ++++++++--------- .../classes/sun/awt/image/ByteBandedRaster.java | 12 +++++++----- .../sun/awt/image/ByteComponentRaster.java | 13 +++++++------ .../sun/awt/image/ByteInterleavedRaster.java | 13 +++++++------ .../classes/sun/awt/image/BytePackedRaster.java | 11 ++++++----- .../sun/awt/image/IntegerComponentRaster.java | 17 +++++++++-------- .../sun/awt/image/IntegerInterleavedRaster.java | 15 ++++++++------- .../sun/awt/image/ShortBandedRaster.java | 11 ++++++----- .../sun/awt/image/ShortComponentRaster.java | 11 ++++++----- .../sun/awt/image/ShortInterleavedRaster.java | 11 ++++++----- .../unix/classes/sun/awt/X11/InfoWindow.java | 2 +- 15 files changed, 93 insertions(+), 83 deletions(-) diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java index ddfbe76e6ed..5722b28e576 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, 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 @@ -3206,7 +3206,10 @@ public void actionPerformed(final ActionEvent e) { } public String toString() { - return new String("viewport.viewSize=" + viewport.getViewSize() + "\n" + "viewport.viewRectangle=" + viewport.getViewRect() + "\n" + "leadingTabIndex=" + leadingTabIndex + "\n" + "tabViewPosition=" + tabViewPosition); + return "viewport.viewSize=" + viewport.getViewSize() + "\n" + + "viewport.viewRectangle=" + viewport.getViewRect() + "\n" + + "leadingTabIndex=" + leadingTabIndex + "\n" + + "tabViewPosition=" + tabViewPosition; } } diff --git a/src/java.desktop/macosx/classes/sun/java2d/IntegerNIORaster.java b/src/java.desktop/macosx/classes/sun/java2d/IntegerNIORaster.java index d3d040e7856..a09bf9b5435 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/IntegerNIORaster.java +++ b/src/java.desktop/macosx/classes/sun/java2d/IntegerNIORaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, 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,10 +87,10 @@ public IntBuffer getBuffer() { } public String toString() { - return new String ("IntegerNIORaster: width = "+width - +" height = " + height - +" #Bands = " + numBands - +" xOff = "+sampleModelTranslateX - +" yOff = "+sampleModelTranslateY); + return "IntegerNIORaster: width = " + width + + " height = " + height + + " #Bands = " + numBands + + " xOff = " + sampleModelTranslateX + + " yOff = " + sampleModelTranslateY; } } diff --git a/src/java.desktop/share/classes/java/awt/image/ColorModel.java b/src/java.desktop/share/classes/java/awt/image/ColorModel.java index 0a1f8749da6..37c6a5d66d7 100644 --- a/src/java.desktop/share/classes/java/awt/image/ColorModel.java +++ b/src/java.desktop/share/classes/java/awt/image/ColorModel.java @@ -1673,13 +1673,12 @@ public WritableRaster getAlphaRaster(WritableRaster raster) { * {@code ColorModel} object. */ public String toString() { - return new String("ColorModel: #pixelBits = "+pixel_bits - + " numComponents = "+numComponents - + " color space = "+colorSpace - + " transparency = "+transparency - + " has alpha = "+supportsAlpha - + " isAlphaPre = "+isAlphaPremultiplied - ); + return "ColorModel: #pixelBits = " + pixel_bits + + " numComponents = " + numComponents + + " color space = " + colorSpace + + " transparency = " + transparency + + " has alpha = " + supportsAlpha + + " isAlphaPre = " + isAlphaPremultiplied; } static int getDefaultTransferType(int pixel_bits) { diff --git a/src/java.desktop/share/classes/java/awt/image/DirectColorModel.java b/src/java.desktop/share/classes/java/awt/image/DirectColorModel.java index cb83727b8cd..bf7ad07a22e 100644 --- a/src/java.desktop/share/classes/java/awt/image/DirectColorModel.java +++ b/src/java.desktop/share/classes/java/awt/image/DirectColorModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2021, 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 @@ -1407,10 +1407,9 @@ private void setFields() { * {@code DirectColorModel}. */ public String toString() { - return new String("DirectColorModel: rmask=" - +Integer.toHexString(red_mask)+" gmask=" - +Integer.toHexString(green_mask)+" bmask=" - +Integer.toHexString(blue_mask)+" amask=" - +Integer.toHexString(alpha_mask)); + return "DirectColorModel: rmask=" + Integer.toHexString(red_mask) + + " gmask=" + Integer.toHexString(green_mask) + + " bmask=" + Integer.toHexString(blue_mask) + + " amask=" + Integer.toHexString(alpha_mask); } } diff --git a/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java b/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java index 51b5504de64..1d9e6e59b75 100644 --- a/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java +++ b/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2021, 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 @@ -1536,14 +1536,13 @@ public void finalize() { * {@code ColorModel} object. */ public String toString() { - return new String("IndexColorModel: #pixelBits = "+pixel_bits - + " numComponents = "+numComponents - + " color space = "+colorSpace - + " transparency = "+transparency - + " transIndex = "+transparent_index - + " has alpha = "+supportsAlpha - + " isAlphaPre = "+isAlphaPremultiplied - ); + return "IndexColorModel: #pixelBits = " + pixel_bits + + " numComponents = " + numComponents + + " color space = " + colorSpace + + " transparency = " + transparency + + " transIndex = " + transparent_index + + " has alpha = " + supportsAlpha + + " isAlphaPre = " + isAlphaPremultiplied; } /** diff --git a/src/java.desktop/share/classes/sun/awt/image/ByteBandedRaster.java b/src/java.desktop/share/classes/sun/awt/image/ByteBandedRaster.java index b2145eebedb..882881f13b9 100644 --- a/src/java.desktop/share/classes/sun/awt/image/ByteBandedRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/ByteBandedRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -818,10 +819,11 @@ private void verify() { } public String toString() { - return new String ("ByteBandedRaster: width = "+width+" height = " - + height - +" #bands "+numDataElements - +" minX = "+minX+" minY = "+minY); + return "ByteBandedRaster: width = " + width + + " height = " + height + + " #bands " + numDataElements + + " minX = " + minX + + " minY = " + minY; } } diff --git a/src/java.desktop/share/classes/sun/awt/image/ByteComponentRaster.java b/src/java.desktop/share/classes/sun/awt/image/ByteComponentRaster.java index d8c4fdf5527..6a92748330c 100644 --- a/src/java.desktop/share/classes/sun/awt/image/ByteComponentRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/ByteComponentRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -945,11 +946,11 @@ protected final void verify() { } public String toString() { - return new String ("ByteComponentRaster: width = "+width+" height = " - + height - +" #numDataElements "+numDataElements - // +" xOff = "+xOffset+" yOff = "+yOffset - +" dataOff[0] = "+dataOffsets[0]); + return "ByteComponentRaster: width = " + width + + " height = " + height + + " #numDataElements " + numDataElements + // +" xOff = "+xOffset+" yOff = "+yOffset + + " dataOff[0] = " + dataOffsets[0]; } // /** diff --git a/src/java.desktop/share/classes/sun/awt/image/ByteInterleavedRaster.java b/src/java.desktop/share/classes/sun/awt/image/ByteInterleavedRaster.java index 2d0e1673d30..796f0835972 100644 --- a/src/java.desktop/share/classes/sun/awt/image/ByteInterleavedRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/ByteInterleavedRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -1288,11 +1289,11 @@ public WritableRaster createCompatibleWritableRaster() { } public String toString() { - return new String ("ByteInterleavedRaster: width = "+width+" height = " - + height - +" #numDataElements "+numDataElements - // +" xOff = "+xOffset+" yOff = "+yOffset - +" dataOff[0] = "+dataOffsets[0]); + return "ByteInterleavedRaster: width = " + width + + " height = " + height + + " #numDataElements " + numDataElements + // +" xOff = "+xOffset+" yOff = "+yOffset + + " dataOff[0] = " + dataOffsets[0]; } // /** diff --git a/src/java.desktop/share/classes/sun/awt/image/BytePackedRaster.java b/src/java.desktop/share/classes/sun/awt/image/BytePackedRaster.java index 0d77e945e84..d721eee5739 100644 --- a/src/java.desktop/share/classes/sun/awt/image/BytePackedRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/BytePackedRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -1425,9 +1425,10 @@ private void verify (boolean strictCheck) { } public String toString() { - return new String ("BytePackedRaster: width = "+width+" height = "+height - +" #channels "+numBands - +" xOff = "+sampleModelTranslateX - +" yOff = "+sampleModelTranslateY); + return "BytePackedRaster: width = " + width + + " height = " + height + + " #channels " + numBands + + " xOff = " + sampleModelTranslateX + + " yOff = " + sampleModelTranslateY; } } diff --git a/src/java.desktop/share/classes/sun/awt/image/IntegerComponentRaster.java b/src/java.desktop/share/classes/sun/awt/image/IntegerComponentRaster.java index 09d066e84c3..3b110e77eca 100644 --- a/src/java.desktop/share/classes/sun/awt/image/IntegerComponentRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/IntegerComponentRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -714,13 +715,13 @@ protected final void verify() { } public String toString() { - return new String ("IntegerComponentRaster: width = "+width - +" height = " + height - +" #Bands = " + numBands - +" #DataElements "+numDataElements - +" xOff = "+sampleModelTranslateX - +" yOff = "+sampleModelTranslateY - +" dataOffset[0] "+dataOffsets[0]); + return "IntegerComponentRaster: width = " + width + + " height = " + height + + " #Bands = " + numBands + + " #DataElements " + numDataElements + + " xOff = " + sampleModelTranslateX + + " yOff = " + sampleModelTranslateY + + " dataOffset[0] " + dataOffsets[0]; } // /** diff --git a/src/java.desktop/share/classes/sun/awt/image/IntegerInterleavedRaster.java b/src/java.desktop/share/classes/sun/awt/image/IntegerInterleavedRaster.java index 808b6aa703b..cb84024ae22 100644 --- a/src/java.desktop/share/classes/sun/awt/image/IntegerInterleavedRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/IntegerInterleavedRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -537,12 +538,12 @@ public WritableRaster createCompatibleWritableRaster() { } public String toString() { - return new String ("IntegerInterleavedRaster: width = "+width - +" height = " + height - +" #Bands = " + numBands - +" xOff = "+sampleModelTranslateX - +" yOff = "+sampleModelTranslateY - +" dataOffset[0] "+dataOffsets[0]); + return "IntegerInterleavedRaster: width = " + width + + " height = " + height + + " #Bands = " + numBands + + " xOff = " + sampleModelTranslateX + + " yOff = " + sampleModelTranslateY + + " dataOffset[0] " + dataOffsets[0]; } // /** diff --git a/src/java.desktop/share/classes/sun/awt/image/ShortBandedRaster.java b/src/java.desktop/share/classes/sun/awt/image/ShortBandedRaster.java index 328758fb4c0..d8403926567 100644 --- a/src/java.desktop/share/classes/sun/awt/image/ShortBandedRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/ShortBandedRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -802,10 +803,10 @@ private void verify() { } public String toString() { - return new String ("ShortBandedRaster: width = "+width+" height = " - + height - +" #numBands " + numBands - +" #dataElements "+numDataElements); + return "ShortBandedRaster: width = " + width + + " height = " + height + + " #numBands " + numBands + + " #dataElements " + numDataElements; } diff --git a/src/java.desktop/share/classes/sun/awt/image/ShortComponentRaster.java b/src/java.desktop/share/classes/sun/awt/image/ShortComponentRaster.java index aa1c1c8fa72..3e95f652d33 100644 --- a/src/java.desktop/share/classes/sun/awt/image/ShortComponentRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/ShortComponentRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -877,10 +878,10 @@ protected final void verify() { } public String toString() { - return new String ("ShortComponentRaster: width = "+width - +" height = " + height - +" #numDataElements "+numDataElements); - // +" xOff = "+xOffset+" yOff = "+yOffset); + return "ShortComponentRaster: width = " + width + + " height = " + height + + " #numDataElements " + numDataElements; + // +" xOff = "+xOffset+" yOff = "+yOffset); } } diff --git a/src/java.desktop/share/classes/sun/awt/image/ShortInterleavedRaster.java b/src/java.desktop/share/classes/sun/awt/image/ShortInterleavedRaster.java index 33f779f76b8..d4926bb295e 100644 --- a/src/java.desktop/share/classes/sun/awt/image/ShortInterleavedRaster.java +++ b/src/java.desktop/share/classes/sun/awt/image/ShortInterleavedRaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2021, 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 @@ -24,6 +24,7 @@ */ package sun.awt.image; + import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.awt.image.RasterFormatException; @@ -758,10 +759,10 @@ public WritableRaster createCompatibleWritableRaster() { } public String toString() { - return new String ("ShortInterleavedRaster: width = "+width - +" height = " + height - +" #numDataElements "+numDataElements); - // +" xOff = "+xOffset+" yOff = "+yOffset); + return "ShortInterleavedRaster: width = " + width + + " height = " + height + + " #numDataElements " + numDataElements; + // +" xOff = "+xOffset+" yOff = "+yOffset); } } diff --git a/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java b/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java index 7052e607e4c..f6739cb075e 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java @@ -389,7 +389,7 @@ private void _display(String caption, String text, String messageType) { if (nLines == BALLOON_WORD_LINE_MAX_COUNT) { if (end != BreakIterator.DONE) { lineLabels[nLines - 1].setText( - new String(lineLabels[nLines - 1].getText() + " ...")); + lineLabels[nLines - 1].getText() + " ..."); } break; } From 00f7c45a4cc073519c0009c0daa51373f8227895 Mon Sep 17 00:00:00 2001 From: Olga Mikhaltsova Date: Mon, 27 Sep 2021 14:16:19 +0000 Subject: [PATCH 067/253] 8273451: Remove unreachable return in mutexLocker::wait Backport-of: 9b5991e811b789fe8b60701657c2f0dd2c222c2e --- src/hotspot/share/runtime/mutexLocker.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/runtime/mutexLocker.hpp b/src/hotspot/share/runtime/mutexLocker.hpp index 16b7401f5ad..d45c62dadc8 100644 --- a/src/hotspot/share/runtime/mutexLocker.hpp +++ b/src/hotspot/share/runtime/mutexLocker.hpp @@ -260,12 +260,8 @@ class MonitorLocker: public MutexLocker { } bool wait(int64_t timeout = 0) { - if (_flag == Mutex::_safepoint_check_flag) { - return as_monitor()->wait(timeout); - } else { - return as_monitor()->wait_without_safepoint_check(timeout); - } - return false; + return _flag == Mutex::_safepoint_check_flag ? + as_monitor()->wait(timeout) : as_monitor()->wait_without_safepoint_check(timeout); } void notify_all() { From 7b67581a2f436084eef148fad6e9cc41542db2fd Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Mon, 27 Sep 2021 14:34:26 +0000 Subject: [PATCH 068/253] 8269850: Most JDK releases report macOS version 12 as 10.16 instead of 12.0 Backport-of: 3b1b8fc646493eae5f4df828afe29abb75fa5e60 --- .../macosx/native/libjava/java_props_macosx.c | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/java.base/macosx/native/libjava/java_props_macosx.c b/src/java.base/macosx/native/libjava/java_props_macosx.c index 2189c1f94e3..1935c202f99 100644 --- a/src/java.base/macosx/native/libjava/java_props_macosx.c +++ b/src/java.base/macosx/native/libjava/java_props_macosx.c @@ -234,6 +234,7 @@ void setOSNameAndVersion(java_props_t *sprops) { // Hardcode os_name, and fill in os_version sprops->os_name = strdup("Mac OS X"); + NSString *nsVerStr = NULL; char* osVersionCStr = NULL; // Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function, // but it's not in the 10.9 SDK. So, call it via NSInvocation. @@ -246,7 +247,6 @@ void setOSNameAndVersion(java_props_t *sprops) { [invoke invokeWithTarget:[NSProcessInfo processInfo]]; [invoke getReturnValue:&osVer]; - NSString *nsVerStr; // Copy out the char* if running on version other than 10.16 Mac OS (10.16 == 11.x) // or explicitly requesting version compatibility if (!((long)osVer.majorVersion == 10 && (long)osVer.minorVersion >= 16) || @@ -258,36 +258,30 @@ void setOSNameAndVersion(java_props_t *sprops) { nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld", (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion]; } - // Copy out the char* - osVersionCStr = strdup([nsVerStr UTF8String]); } else { // Version 10.16, without explicit env setting of SYSTEM_VERSION_COMPAT - // AKA 11.x; compute the version number from the letter in the ProductBuildVersion + // AKA 11+ Read the *real* ProductVersion from the hidden link to avoid SYSTEM_VERSION_COMPAT + // If not found, fallback below to the SystemVersion.plist NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : - @"/System/Library/CoreServices/SystemVersion.plist"]; + @"/System/Library/CoreServices/.SystemVersionPlatform.plist"]; if (version != NULL) { - NSString *nsBuildVerStr = [version objectForKey : @"ProductBuildVersion"]; - if (nsBuildVerStr != NULL && nsBuildVerStr.length >= 3) { - int letter = [nsBuildVerStr characterAtIndex:2]; - if (letter >= 'B' && letter <= 'Z') { - int vers = letter - 'A' - 1; - asprintf(&osVersionCStr, "11.%d", vers); - } - } + nsVerStr = [version objectForKey : @"ProductVersion"]; } } } // Fallback if running on pre-10.9 Mac OS - if (osVersionCStr == NULL) { + if (nsVerStr == NULL) { NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : @"/System/Library/CoreServices/SystemVersion.plist"]; if (version != NULL) { - NSString *nsVerStr = [version objectForKey : @"ProductVersion"]; - if (nsVerStr != NULL) { - osVersionCStr = strdup([nsVerStr UTF8String]); - } + nsVerStr = [version objectForKey : @"ProductVersion"]; } } + + if (nsVerStr != NULL) { + // Copy out the char* + osVersionCStr = strdup([nsVerStr UTF8String]); + } if (osVersionCStr == NULL) { osVersionCStr = strdup("Unknown"); } From 6f3ace565330e3d0029600a50e206f08c462b552 Mon Sep 17 00:00:00 2001 From: Evan Whelan Date: Mon, 27 Sep 2021 15:59:23 +0000 Subject: [PATCH 069/253] 8272236: Improve serial forms for transport Reviewed-by: rriggs Backport-of: ed0621893e7c365673ed87fbd4aca2bca27b9b73 --- src/java.base/share/classes/java/io/ObjectInputStream.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/java.base/share/classes/java/io/ObjectInputStream.java b/src/java.base/share/classes/java/io/ObjectInputStream.java index edcda187d79..8da669886cf 100644 --- a/src/java.base/share/classes/java/io/ObjectInputStream.java +++ b/src/java.base/share/classes/java/io/ObjectInputStream.java @@ -2516,6 +2516,13 @@ private IOException readFatalException() throws IOException { throw new InternalError(); } clear(); + // Check that an object follows the TC_EXCEPTION typecode + byte tc = bin.peekByte(); + if (tc != TC_OBJECT && + tc != TC_REFERENCE) { + throw new StreamCorruptedException( + String.format("invalid type code: %02X", tc)); + } return (IOException) readObject0(Object.class, false); } From d46a5ae71e2d1096646591f33bdebf478236f249 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Mon, 27 Sep 2021 16:45:14 +0000 Subject: [PATCH 070/253] 8274056: JavaAccessibilityUtilities leaks JNI objects Backport-of: 42d5d2abaad8a88a5e1326ea8b4494aeb8b5748b --- .../libawt_lwawt/awt/JavaAccessibilityUtilities.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m index 12817e63ecd..33ccaaf3d10 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m @@ -56,11 +56,14 @@ NSSize getAxComponentSize(JNIEnv *env, jobject axComponent, jobject component) DECLARE_STATIC_METHOD_RETURN(jm_getSize, sjc_CAccessibility, "getSize", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Dimension;", NSZeroSize); - jobject dimension = (*env)->CallStaticObjectMethod(env, jc_Dimension, jm_getSize, axComponent, component); + jobject dimension = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getSize, axComponent, component); CHECK_EXCEPTION(); if (dimension == NULL) return NSZeroSize; - return NSMakeSize((*env)->GetIntField(env, dimension, jf_width), (*env)->GetIntField(env, dimension, jf_height)); + + NSSize size = NSMakeSize((*env)->GetIntField(env, dimension, jf_width), (*env)->GetIntField(env, dimension, jf_height)); + (*env)->DeleteLocalRef(env, dimension); + return size; } NSString *getJavaRole(JNIEnv *env, jobject axComponent, jobject component) @@ -211,7 +214,9 @@ NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject axComponent, component); CHECK_EXCEPTION(); if (jpoint == NULL) return NSZeroPoint; - return NSMakePoint((*env)->GetIntField(env, jpoint, sjf_X), (*env)->GetIntField(env, jpoint, sjf_Y)); + NSPoint p = NSMakePoint((*env)->GetIntField(env, jpoint, sjf_X), (*env)->GetIntField(env, jpoint, sjf_Y)); + (*env)->DeleteLocalRef(env, jpoint); + return p; } jint getAxTextCharCount(JNIEnv *env, jobject axText, jobject component) From 926a815f6720211366478b6fcbf4a8d168750a31 Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Mon, 27 Sep 2021 17:03:27 +0000 Subject: [PATCH 071/253] 8273902: Memory leak in OopStorage due to bug in OopHandle::release() Backport-of: bc48a0ac297b99a997482dcb59f85acc1cdb0c47 --- src/hotspot/share/oops/oopHandle.inline.hpp | 2 +- src/hotspot/share/prims/jvmtiImpl.cpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/oops/oopHandle.inline.hpp b/src/hotspot/share/oops/oopHandle.inline.hpp index 44362499a2c..20de5146ec3 100644 --- a/src/hotspot/share/oops/oopHandle.inline.hpp +++ b/src/hotspot/share/oops/oopHandle.inline.hpp @@ -48,7 +48,7 @@ inline OopHandle::OopHandle(OopStorage* storage, oop obj) : } inline void OopHandle::release(OopStorage* storage) { - if (peek() != NULL) { + if (_obj != NULL) { // Clear the OopHandle first NativeAccess<>::oop_store(_obj, (oop)NULL); storage->release(_obj); diff --git a/src/hotspot/share/prims/jvmtiImpl.cpp b/src/hotspot/share/prims/jvmtiImpl.cpp index ea5ba609f95..ba79e19392c 100644 --- a/src/hotspot/share/prims/jvmtiImpl.cpp +++ b/src/hotspot/share/prims/jvmtiImpl.cpp @@ -206,9 +206,7 @@ JvmtiBreakpoint::JvmtiBreakpoint(Method* m_method, jlocation location) } JvmtiBreakpoint::~JvmtiBreakpoint() { - if (_class_holder.peek() != NULL) { - _class_holder.release(JvmtiExport::jvmti_oop_storage()); - } + _class_holder.release(JvmtiExport::jvmti_oop_storage()); } void JvmtiBreakpoint::copy(JvmtiBreakpoint& bp) { From c4dfa5759c5f66953a038ade636d8a1d1013e356 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Tue, 28 Sep 2021 01:59:15 +0000 Subject: [PATCH 072/253] 8273638: javax/swing/JTable/4235420/bug4235420.java fails in GTK L&F Backport-of: 6cf70f5f0809276904094bf8eba8786892bf034e --- test/jdk/javax/swing/JTable/4235420/bug4235420.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/jdk/javax/swing/JTable/4235420/bug4235420.java b/test/jdk/javax/swing/JTable/4235420/bug4235420.java index 7e613a910ea..8bde3b8ea9c 100644 --- a/test/jdk/javax/swing/JTable/4235420/bug4235420.java +++ b/test/jdk/javax/swing/JTable/4235420/bug4235420.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -50,7 +50,7 @@ public static void main(String[] argv) throws Exception { System.out.println("Testing L&F: " + LF.getClassName()); if ("Nimbus".equals(UIManager.getLookAndFeel().getName()) || - "GTK".equals(UIManager.getLookAndFeel().getName())) { + "GTK".equals(UIManager.getLookAndFeel().getID())) { System.out.println("The test is skipped for Nimbus and GTK"); continue; From 7add1580b27da23a7fc8590299ca7449db1b6ef3 Mon Sep 17 00:00:00 2001 From: Ravi Reddy Date: Tue, 28 Sep 2021 08:34:45 +0000 Subject: [PATCH 073/253] 8273968: JCK javax_xml tests fail in CI Backport-of: d1910329352e878badf8fdc6634a177dd4745d4a --- .../sun/org/apache/xerces/internal/impl/XMLEntityScanner.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java index 89adb81b05b..33ffe9831b8 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java @@ -57,7 +57,7 @@ * @author Arnaud Le Hors, IBM * @author K.Venugopal Sun Microsystems * - * @LastModified: Aug 2021 + * @LastModified: Sep 2021 */ public class XMLEntityScanner implements XMLLocator { @@ -2145,7 +2145,7 @@ protected boolean normalizeNewlines(short version, XMLString buffer, boolean app // how this information is used is determined by the caller of this method counted = false; if ((c == '\n' || c == '\r') || - (version == XML_VERSION_1_1 && (c == 0x85 || c == 0x2028))) { + (version == XML_VERSION_1_1 && (c == 0x85 || c == 0x2028) && isExternal)) { do { c = fCurrentEntity.ch[fCurrentEntity.position++]; if ((c == '\n' || c == '\r') || From d93500168cd120165fedb9609fdf2e10458976dd Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Tue, 28 Sep 2021 08:52:37 +0000 Subject: [PATCH 074/253] 8268893: jcmd to trim the glibc heap Backport-of: 6096dd9765eaf280890f65c0ff1ab64864b9316a --- src/hotspot/os/linux/os_linux.cpp | 57 +++++++------ src/hotspot/os/linux/os_linux.hpp | 17 ++++ src/hotspot/os/linux/trimCHeapDCmd.cpp | 79 +++++++++++++++++++ src/hotspot/os/linux/trimCHeapDCmd.hpp | 52 ++++++++++++ .../share/services/diagnosticCommand.cpp | 5 +- .../dcmd/vm/TrimLibcHeapTest.java | 55 +++++++++++++ 6 files changed, 239 insertions(+), 26 deletions(-) create mode 100644 src/hotspot/os/linux/trimCHeapDCmd.cpp create mode 100644 src/hotspot/os/linux/trimCHeapDCmd.hpp create mode 100644 test/hotspot/jtreg/serviceability/dcmd/vm/TrimLibcHeapTest.java diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index b4c89b5181d..c1efd76a360 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2137,44 +2137,51 @@ void os::Linux::print_system_memory_info(outputStream* st) { "/sys/kernel/mm/transparent_hugepage/defrag", st); } -void os::Linux::print_process_memory_info(outputStream* st) { - - st->print_cr("Process Memory:"); - - // Print virtual and resident set size; peak values; swap; and for - // rss its components if the kernel is recent enough. - ssize_t vmsize = -1, vmpeak = -1, vmswap = -1, - vmrss = -1, vmhwm = -1, rssanon = -1, rssfile = -1, rssshmem = -1; - const int num_values = 8; - int num_found = 0; +bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) { FILE* f = ::fopen("/proc/self/status", "r"); + const int num_values = sizeof(os::Linux::meminfo_t) / sizeof(size_t); + int num_found = 0; char buf[256]; + info->vmsize = info->vmpeak = info->vmrss = info->vmhwm = info->vmswap = + info->rssanon = info->rssfile = info->rssshmem = -1; if (f != NULL) { while (::fgets(buf, sizeof(buf), f) != NULL && num_found < num_values) { - if ( (vmsize == -1 && sscanf(buf, "VmSize: " SSIZE_FORMAT " kB", &vmsize) == 1) || - (vmpeak == -1 && sscanf(buf, "VmPeak: " SSIZE_FORMAT " kB", &vmpeak) == 1) || - (vmswap == -1 && sscanf(buf, "VmSwap: " SSIZE_FORMAT " kB", &vmswap) == 1) || - (vmhwm == -1 && sscanf(buf, "VmHWM: " SSIZE_FORMAT " kB", &vmhwm) == 1) || - (vmrss == -1 && sscanf(buf, "VmRSS: " SSIZE_FORMAT " kB", &vmrss) == 1) || - (rssanon == -1 && sscanf(buf, "RssAnon: " SSIZE_FORMAT " kB", &rssanon) == 1) || - (rssfile == -1 && sscanf(buf, "RssFile: " SSIZE_FORMAT " kB", &rssfile) == 1) || - (rssshmem == -1 && sscanf(buf, "RssShmem: " SSIZE_FORMAT " kB", &rssshmem) == 1) + if ( (info->vmsize == -1 && sscanf(buf, "VmSize: " SSIZE_FORMAT " kB", &info->vmsize) == 1) || + (info->vmpeak == -1 && sscanf(buf, "VmPeak: " SSIZE_FORMAT " kB", &info->vmpeak) == 1) || + (info->vmswap == -1 && sscanf(buf, "VmSwap: " SSIZE_FORMAT " kB", &info->vmswap) == 1) || + (info->vmhwm == -1 && sscanf(buf, "VmHWM: " SSIZE_FORMAT " kB", &info->vmhwm) == 1) || + (info->vmrss == -1 && sscanf(buf, "VmRSS: " SSIZE_FORMAT " kB", &info->vmrss) == 1) || + (info->rssanon == -1 && sscanf(buf, "RssAnon: " SSIZE_FORMAT " kB", &info->rssanon) == 1) || // Needs Linux 4.5 + (info->rssfile == -1 && sscanf(buf, "RssFile: " SSIZE_FORMAT " kB", &info->rssfile) == 1) || // Needs Linux 4.5 + (info->rssshmem == -1 && sscanf(buf, "RssShmem: " SSIZE_FORMAT " kB", &info->rssshmem) == 1) // Needs Linux 4.5 ) { num_found ++; } } fclose(f); + return true; + } + return false; +} + +void os::Linux::print_process_memory_info(outputStream* st) { - st->print_cr("Virtual Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", vmsize, vmpeak); - st->print("Resident Set Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", vmrss, vmhwm); - if (rssanon != -1) { // requires kernel >= 4.5 + st->print_cr("Process Memory:"); + + // Print virtual and resident set size; peak values; swap; and for + // rss its components if the kernel is recent enough. + meminfo_t info; + if (query_process_memory_info(&info)) { + st->print_cr("Virtual Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", info.vmsize, info.vmpeak); + st->print("Resident Set Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", info.vmrss, info.vmhwm); + if (info.rssanon != -1) { // requires kernel >= 4.5 st->print(" (anon: " SSIZE_FORMAT "K, file: " SSIZE_FORMAT "K, shmem: " SSIZE_FORMAT "K)", - rssanon, rssfile, rssshmem); + info.rssanon, info.rssfile, info.rssshmem); } st->cr(); - if (vmswap != -1) { // requires kernel >= 2.6.34 - st->print_cr("Swapped out: " SSIZE_FORMAT "K", vmswap); + if (info.vmswap != -1) { // requires kernel >= 2.6.34 + st->print_cr("Swapped out: " SSIZE_FORMAT "K", info.vmswap); } } else { st->print_cr("Could not open /proc/self/status to get process memory related information"); @@ -2195,7 +2202,7 @@ void os::Linux::print_process_memory_info(outputStream* st) { struct glibc_mallinfo mi = _mallinfo(); total_allocated = (size_t)(unsigned)mi.uordblks; // Since mallinfo members are int, glibc values may have wrapped. Warn about this. - might_have_wrapped = (vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX); + might_have_wrapped = (info.vmrss * K) > UINT_MAX && (info.vmrss * K) > (total_allocated + UINT_MAX); } if (_mallinfo2 != NULL || _mallinfo != NULL) { st->print_cr("C-Heap outstanding allocations: " SIZE_FORMAT "K%s", diff --git a/src/hotspot/os/linux/os_linux.hpp b/src/hotspot/os/linux/os_linux.hpp index ada8db6977e..692dae042ab 100644 --- a/src/hotspot/os/linux/os_linux.hpp +++ b/src/hotspot/os/linux/os_linux.hpp @@ -174,6 +174,23 @@ class Linux { // Return the namespace pid if so, otherwise -1. static int get_namespace_pid(int vmid); + // Output structure for query_process_memory_info() + struct meminfo_t { + ssize_t vmsize; // current virtual size + ssize_t vmpeak; // peak virtual size + ssize_t vmrss; // current resident set size + ssize_t vmhwm; // peak resident set size + ssize_t vmswap; // swapped out + ssize_t rssanon; // resident set size (anonymous mappings, needs 4.5) + ssize_t rssfile; // resident set size (file mappings, needs 4.5) + ssize_t rssshmem; // resident set size (shared mappings, needs 4.5) + }; + + // Attempts to query memory information about the current process and return it in the output structure. + // May fail (returns false) or succeed (returns true) but not all output fields are available; unavailable + // fields will contain -1. + static bool query_process_memory_info(meminfo_t* info); + // Stack repair handling // none present diff --git a/src/hotspot/os/linux/trimCHeapDCmd.cpp b/src/hotspot/os/linux/trimCHeapDCmd.cpp new file mode 100644 index 00000000000..ee93ac5e8c8 --- /dev/null +++ b/src/hotspot/os/linux/trimCHeapDCmd.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2021 SAP SE. All rights reserved. + * Copyright (c) 2021, 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. + * + */ + +#include "precompiled.hpp" +#include "logging/log.hpp" +#include "runtime/os.hpp" +#include "utilities/debug.hpp" +#include "utilities/ostream.hpp" +#include "trimCHeapDCmd.hpp" + +#include + +void TrimCLibcHeapDCmd::execute(DCmdSource source, TRAPS) { +#ifdef __GLIBC__ + stringStream ss_report(1024); // Note: before calling trim + + os::Linux::meminfo_t info1; + os::Linux::meminfo_t info2; + // Query memory before... + bool have_info1 = os::Linux::query_process_memory_info(&info1); + + _output->print_cr("Attempting trim..."); + ::malloc_trim(0); + _output->print_cr("Done."); + + // ...and after trim. + bool have_info2 = os::Linux::query_process_memory_info(&info2); + + // Print report both to output stream as well to UL + bool wrote_something = false; + if (have_info1 && have_info2) { + if (info1.vmsize != -1 && info2.vmsize != -1) { + ss_report.print_cr("Virtual size before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", + info1.vmsize, info2.vmsize, (info2.vmsize - info1.vmsize)); + wrote_something = true; + } + if (info1.vmrss != -1 && info2.vmrss != -1) { + ss_report.print_cr("RSS before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", + info1.vmrss, info2.vmrss, (info2.vmrss - info1.vmrss)); + wrote_something = true; + } + if (info1.vmswap != -1 && info2.vmswap != -1) { + ss_report.print_cr("Swap before: " SSIZE_FORMAT "k, after: " SSIZE_FORMAT "k, (" SSIZE_FORMAT "k)", + info1.vmswap, info2.vmswap, (info2.vmswap - info1.vmswap)); + wrote_something = true; + } + } + if (!wrote_something) { + ss_report.print_raw("No details available."); + } + + _output->print_raw(ss_report.base()); + log_info(os)("malloc_trim:\n%s", ss_report.base()); +#else + _output->print_cr("Not available."); +#endif +} diff --git a/src/hotspot/os/linux/trimCHeapDCmd.hpp b/src/hotspot/os/linux/trimCHeapDCmd.hpp new file mode 100644 index 00000000000..4c5b5cc2219 --- /dev/null +++ b/src/hotspot/os/linux/trimCHeapDCmd.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 SAP SE. All rights reserved. + * Copyright (c) 2021, 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. + * + */ + +#ifndef OS_LINUX_TRIMCHEAPDCMD_HPP +#define OS_LINUX_TRIMCHEAPDCMD_HPP + +#include "services/diagnosticCommand.hpp" + +class outputStream; + +class TrimCLibcHeapDCmd : public DCmd { +public: + TrimCLibcHeapDCmd(outputStream* output, bool heap) : DCmd(output, heap) {} + static const char* name() { + return "System.trim_native_heap"; + } + static const char* description() { + return "Attempts to free up memory by trimming the C-heap."; + } + static const char* impact() { + return "Low"; + } + static const JavaPermission permission() { + JavaPermission p = { "java.lang.management.ManagementPermission", "control", NULL }; + return p; + } + virtual void execute(DCmdSource source, TRAPS); +}; + +#endif // OS_LINUX_TRIMCHEAPDCMD_HPP diff --git a/src/hotspot/share/services/diagnosticCommand.cpp b/src/hotspot/share/services/diagnosticCommand.cpp index 795d1fda1db..51f47421c50 100644 --- a/src/hotspot/share/services/diagnosticCommand.cpp +++ b/src/hotspot/share/services/diagnosticCommand.cpp @@ -58,7 +58,9 @@ #include "utilities/events.hpp" #include "utilities/formatBuffer.hpp" #include "utilities/macros.hpp" - +#ifdef LINUX +#include "trimCHeapDCmd.hpp" +#endif static void loadAgentModule(TRAPS) { ResourceMark rm(THREAD); @@ -118,6 +120,7 @@ void DCmdRegistrant::register_dcmds(){ DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); #ifdef LINUX DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); #endif // LINUX DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); diff --git a/test/hotspot/jtreg/serviceability/dcmd/vm/TrimLibcHeapTest.java b/test/hotspot/jtreg/serviceability/dcmd/vm/TrimLibcHeapTest.java new file mode 100644 index 00000000000..2688c8e8fe7 --- /dev/null +++ b/test/hotspot/jtreg/serviceability/dcmd/vm/TrimLibcHeapTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 SAP SE. All rights reserved. + * Copyright (c) 2021, 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 org.testng.annotations.Test; +import jdk.test.lib.dcmd.CommandExecutor; +import jdk.test.lib.dcmd.JMXExecutor; +import jdk.test.lib.process.OutputAnalyzer; + +/* + * @test + * @summary Test of diagnostic command VM.trim_libc_heap + * @library /test/lib + * @requires os.family == "linux" + * @modules java.base/jdk.internal.misc + * java.compiler + * java.management + * jdk.internal.jvmstat/sun.jvmstat.monitor + * @run testng TrimLibcHeapTest + */ +public class TrimLibcHeapTest { + public void run(CommandExecutor executor) { + OutputAnalyzer output = executor.execute("System.trim_native_heap"); + output.reportDiagnosticSummary(); + output.shouldMatch("(Done|Not available)"); // Not available could happen on Linux + non-glibc (eg. muslc) + if (output.firstMatch("Done") != null) { + output.shouldMatch("(Virtual size before|RSS before|Swap before|No details available)"); + } + } + + @Test + public void jmx() { + run(new JMXExecutor()); + } +} From 4e707bc1fa5a1da5b31b7a94febdd24f8bc3f6c6 Mon Sep 17 00:00:00 2001 From: Guoxiong Li Date: Tue, 28 Sep 2021 11:37:25 +0000 Subject: [PATCH 075/253] 8268894: forged ASTs can provoke an AIOOBE at com.sun.tools.javac.jvm.ClassWriter::writePosition Backport-of: a9188f237ec23d4ca2a172e9a7897cb6e2b69857 --- .../javac/code/TypeAnnotationPosition.java | 1 - .../TypeAnnotationPositionProcessor.java | 86 +++++++++++++++++++ .../position/TypeAnnotationPositionTest.java | 47 ++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionProcessor.java create mode 100644 test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionTest.java diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java index d98367567ea..92fe41adb5b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java @@ -297,7 +297,6 @@ public boolean matchesPos(int pos) { public void updatePosOffset(int to) { offset = to; - lvarOffset = new int[]{to}; isValidOffset = true; } diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionProcessor.java b/test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionProcessor.java new file mode 100644 index 00000000000..e9af281754a --- /dev/null +++ b/test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionProcessor.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021, 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 com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree; +import com.sun.source.util.TreeScanner; +import com.sun.source.util.Trees; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.*; + +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; +import java.util.Set; + +@SupportedAnnotationTypes("*") +public class TypeAnnotationPositionProcessor extends AbstractProcessor { + private Trees trees; + private boolean processed = false; + + @Override + public void init(ProcessingEnvironment pe) { + super.init(pe); + trees = Trees.instance(pe); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (processed) { + return false; + } else { + processed = true; + } + Set elements = roundEnv.getRootElements(); + TypeElement typeElement = null; + for (TypeElement te : ElementFilter.typesIn(elements)) { + if ("TypeAnnotationPositionTest".equals(te.getSimpleName().toString())) { + typeElement = te; + break; + } + } + for (ExecutableElement m : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { + if ("test".equals(m.getSimpleName().toString())) { + MethodTree methodTree = trees.getTree(m); + new PositionVisitor().scan(methodTree, ((JCMethodDecl) methodTree).pos); + } + } + return false; + } + + private static class PositionVisitor extends TreeScanner { + @Override + public Void scan(Tree tree, Integer p) { + if (tree != null) ((JCTree) tree).pos = p; + return super.scan(tree, p); + } + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } +} diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionTest.java new file mode 100644 index 00000000000..23527fd1688 --- /dev/null +++ b/test/langtools/tools/javac/annotations/typeAnnotations/position/TypeAnnotationPositionTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021, 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 8268894 + * @summary Updating the type annotation position offset causes ArrayIndexOutOfBoundsException in ClassWriter + * @modules jdk.compiler/com.sun.tools.javac.tree + * @compile TypeAnnotationPositionProcessor.java + * @compile -processor TypeAnnotationPositionProcessor TypeAnnotationPositionTest.java + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +public class TypeAnnotationPositionTest { + TypeAnnotationPositionTest(char @MyTest [] bar) { } + + @Target({ElementType.TYPE_USE}) + @interface MyTest { + } + + TypeAnnotationPositionTest test() { + char @MyTest [] val = new char[]{'1'}; + return new TypeAnnotationPositionTest(val); + } +} From ed4e3dbacd0ff08414fe8ec214a88507dd35f419 Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Tue, 28 Sep 2021 13:30:27 +0000 Subject: [PATCH 076/253] 8273838: Enhanced BMP processing Backport-of: f5cc6f23a46bee06731fdd2b257c8ea8007eebad --- .../classes/com/sun/imageio/plugins/bmp/BMPImageReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java index 8271c5cf263..2e1c2db03ca 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java @@ -615,7 +615,7 @@ else if (size == 124) } if (metadata.compression == BI_RGB) { - long imageDataSize = (width * height * (bitsPerPixel / 8)); + long imageDataSize = ((long)width * height * (bitsPerPixel / 8)); if (imageDataSize > (bitmapFileSize - bitmapOffset)) { throw new IIOException(I18N.getString("BMPImageReader9")); } From ded4b31601bb5c5c84b63e0e69eb48745c9e0209 Mon Sep 17 00:00:00 2001 From: Alexander Zuev Date: Tue, 28 Sep 2021 20:15:42 +0000 Subject: [PATCH 077/253] 8272462: Enhance image handling Backport-of: 3d1745d54b93a62a7f404e33c70211db0e31d536 --- .../com/sun/imageio/plugins/gif/GIFImageReader.java | 7 ++++++- .../com/sun/imageio/plugins/jpeg/JPEGImageReader.java | 7 +++++++ .../com/sun/imageio/plugins/png/PNGImageReader.java | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java index 2bedc9440ee..9632e37d1d4 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2021, 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 @@ -1007,6 +1007,11 @@ public BufferedImage read(int imageIndex, ImageReadParam param) } } + if (tableIndex >= prefix.length) { + throw new IIOException("Code buffer limit reached," + + " no End of Image tag present, possibly data is corrupted. "); + } + int ti = tableIndex; int oc = oldCode; diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java index 11eed2e94e0..9d8cd29a950 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java @@ -1156,6 +1156,13 @@ private Raster readInternal(int imageIndex, throw new IIOException("Unsupported Image Type"); } + if ((long)width * height > Integer.MAX_VALUE - 2) { + // We are not able to properly decode image that has number + // of pixels greater than Integer.MAX_VALUE - 2 + throw new IIOException("Can not read image of the size " + + width + " by " + height); + } + image = getDestination(param, imageTypes, width, height); imRas = image.getRaster(); diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java index 25bfef7f14c..8576419a4bf 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java @@ -1418,6 +1418,13 @@ private void readImage(ImageReadParam param) throws IIOException { int width = metadata.IHDR_width; int height = metadata.IHDR_height; + if ((long)width * height > Integer.MAX_VALUE - 2) { + // We are not able to properly decode image that has number + // of pixels greater than Integer.MAX_VALUE - 2 + throw new IIOException("Can not read image of the size " + + width + " by " + height); + } + // Init default values sourceXSubsampling = 1; sourceYSubsampling = 1; From b55ec5b4024dfd8b548ae15fbb09bd3ba749f6db Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Tue, 28 Sep 2021 21:04:43 +0000 Subject: [PATCH 078/253] 8271718: Crash when during color transformation the color profile is replaced Backport-of: 148935279d177e66a08a7003975bce3077104e07 --- .../classes/sun/java2d/cmm/lcms/LCMS.java | 36 +++-- .../MTTransformReplacedProfile.java | 136 ++++++++++++++++++ 2 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java diff --git a/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java b/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java index f3a966d5075..405f9490179 100644 --- a/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java +++ b/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java @@ -27,6 +27,7 @@ import java.awt.color.CMMException; import java.awt.color.ICC_Profile; +import java.util.concurrent.locks.StampedLock; import sun.java2d.cmm.ColorTransform; import sun.java2d.cmm.PCMM; @@ -34,6 +35,11 @@ final class LCMS implements PCMM { + /** + * Prevent changing profiles data during transform creation. + */ + private static final StampedLock lock = new StampedLock(); + /* methods invoked from ICC_Profile */ @Override public Profile loadProfile(byte[] data) { @@ -80,8 +86,13 @@ public byte[] getTagData(Profile p, int tagSignature) { } @Override - public synchronized void setTagData(Profile p, int tagSignature, byte[] data) { - getLcmsProfile(p).setTag(tagSignature, data); + public void setTagData(Profile p, int tagSignature, byte[] data) { + long stamp = lock.writeLock(); + try { + getLcmsProfile(p).setTag(tagSignature, data); + } finally { + lock.unlockWrite(stamp); + } } static synchronized native LCMSProfile getProfileID(ICC_Profile profile); @@ -94,15 +105,20 @@ static long createTransform( Object disposerRef) { long[] ptrs = new long[profiles.length]; - - for (int i = 0; i < profiles.length; i++) { - if (profiles[i] == null) throw new CMMException("Unknown profile ID"); - - ptrs[i] = profiles[i].getLcmsPtr(); + long stamp = lock.readLock(); + try { + for (int i = 0; i < profiles.length; i++) { + if (profiles[i] == null) { + throw new CMMException("Unknown profile ID"); + } + ptrs[i] = profiles[i].getLcmsPtr(); + } + + return createNativeTransform(ptrs, renderType, inFormatter, + isInIntPacked, outFormatter, isOutIntPacked, disposerRef); + } finally { + lock.unlockRead(stamp); } - - return createNativeTransform(ptrs, renderType, inFormatter, - isInIntPacked, outFormatter, isOutIntPacked, disposerRef); } private static native long createNativeTransform( diff --git a/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java b/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java new file mode 100644 index 00000000000..df66f29ecec --- /dev/null +++ b/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java @@ -0,0 +1,136 @@ +/* + * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. + * Copyright (c) 2021, 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.ColorSpace; +import java.awt.color.ICC_ColorSpace; +import java.awt.color.ICC_Profile; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * @test + * @bug 8271718 + * @summary Verifies MT safety of color transformation while profile is changed + */ +public final class MTTransformReplacedProfile { + + private static volatile long endtime; + + public static void main(String[] args) throws Exception { + ICC_Profile[] profiles = { + ICC_Profile.getInstance(ColorSpace.CS_sRGB), + ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB), + ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ), + ICC_Profile.getInstance(ColorSpace.CS_PYCC), + ICC_Profile.getInstance(ColorSpace.CS_GRAY) + }; + + List tags = new ArrayList<>(); + for (Field field : ICC_Profile.class.getDeclaredFields()) { + if (Modifier.isStatic(field.getModifiers()) + && Modifier.isPublic(field.getModifiers()) + && Modifier.isFinal(field.getModifiers()) + && field.getType() == int.class) { + tags.add(field.getInt(null)); + } + } + + List tasks = new ArrayList<>(); + for (int tag : tags) { + for (ICC_Profile profile1 : profiles) { + for (ICC_Profile profile2 : profiles) { + byte[] d1 = profile1.getData(tag); + byte[] d2 = profile2.getData(tag); + if (d1 == null || d2 == null) { + continue; + } + tasks.add(new Thread(() -> { + try { + test(profile1.getData(), d1, d2, tag); + } catch (Throwable ignored) { + // only the crash is the test failure + } + })); + } + } + } + + // Try to run the test no more than 15 seconds + endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15); + for (Thread t : tasks) { + t.start(); + } + for (Thread t : tasks) { + t.join(); + } + } + + private static void test(byte[] all, byte[] data1, byte[] data2, int tag) + throws Exception { + ICC_Profile icc = ICC_Profile.getInstance(all); + ColorSpace cs = new ICC_ColorSpace(icc); + AtomicBoolean stop = new AtomicBoolean(); + Thread swap = new Thread(() -> { + try { + while (!isComplete()) { + icc.setData(tag, data1); + icc.setData(tag, data2); + } + } catch (Throwable ignored) { + // only the crash is the test failure + } + stop.set(true); + }); + + float[] colorvalue = new float[3]; + Thread transform = new Thread(() -> { + boolean rgb = true; + while (!stop.get()) { + try { + if (rgb) { + cs.toRGB(colorvalue); + } else { + cs.toCIEXYZ(colorvalue); + } + } catch (Throwable ignored) { + // only the crash is the test failure + } + rgb = !rgb; + } + }); + + swap.start(); + transform.start(); + swap.join(); + transform.join(); + } + + private static boolean isComplete() { + return endtime - System.nanoTime() < 0; + } +} From f48db899d313cc2d68b6fae703d9cbd52b90f730 Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Tue, 28 Sep 2021 21:31:39 +0000 Subject: [PATCH 079/253] 8272328: java.library.path is not set properly by Windows jpackage app launcher Backport-of: cd2dbe5f007baf81ae9262c1152917e620970621 --- .../share/native/applauncher/AppLauncher.cpp | 26 +++++++++- .../share/native/applauncher/AppLauncher.h | 2 + .../native/applauncher/WinLauncher.cpp | 48 +++++++++++++++++-- .../windows/native/common/WinSysInfo.cpp | 6 +-- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/jdk.jpackage/share/native/applauncher/AppLauncher.cpp b/src/jdk.jpackage/share/native/applauncher/AppLauncher.cpp index 566c57fd9a5..8381facb488 100644 --- a/src/jdk.jpackage/share/native/applauncher/AppLauncher.cpp +++ b/src/jdk.jpackage/share/native/applauncher/AppLauncher.cpp @@ -91,6 +91,24 @@ tstring findJvmLib(const CfgFile& cfgFile, const tstring& defaultRuntimePath, } } // namespace +bool AppLauncher::libEnvVariableContainsAppDir() const { + tstring value = SysInfo::getEnvVariable(std::nothrow, + libEnvVarName, tstring()); +#ifdef _WIN32 + value = tstrings::toLower(value); +#endif + + const tstring_array tokens = tstrings::split(value, + tstring(1, FileUtils::pathSeparator)); + return tokens.end() != std::find(tokens.begin(), tokens.end(), +#ifdef _WIN32 + tstrings::toLower(appDirPath) +#else + appDirPath +#endif + ); +} + Jvm* AppLauncher::createJvmLauncher() const { const tstring cfgFilePath = FileUtils::mkpath() << appDirPath << FileUtils::stripExeSuffix( @@ -112,8 +130,12 @@ Jvm* AppLauncher::createJvmLauncher() const { PropertyName::arguments, args); } - SysInfo::setEnvVariable(libEnvVarName, SysInfo::getEnvVariable( - std::nothrow, libEnvVarName) + FileUtils::pathSeparator + appDirPath); + if (!libEnvVariableContainsAppDir()) { + SysInfo::setEnvVariable(libEnvVarName, SysInfo::getEnvVariable( + std::nothrow, libEnvVarName) + + FileUtils::pathSeparator + + appDirPath); + } std::unique_ptr jvm(new Jvm()); diff --git a/src/jdk.jpackage/share/native/applauncher/AppLauncher.h b/src/jdk.jpackage/share/native/applauncher/AppLauncher.h index a318d49ba70..306233a5d85 100644 --- a/src/jdk.jpackage/share/native/applauncher/AppLauncher.h +++ b/src/jdk.jpackage/share/native/applauncher/AppLauncher.h @@ -65,6 +65,8 @@ class AppLauncher { return *this; } + bool libEnvVariableContainsAppDir() const; + Jvm* createJvmLauncher() const; void launch() const; diff --git a/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp b/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp index ffc2572fd38..a3b8f150082 100644 --- a/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp +++ b/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp @@ -138,17 +138,55 @@ void launchApp() { const tstring launcherPath = SysInfo::getProcessModulePath(); const tstring appImageRoot = FileUtils::dirname(launcherPath); + const tstring appDirPath = FileUtils::mkpath() << appImageRoot << _T("app"); const tstring runtimeBinPath = FileUtils::mkpath() << appImageRoot << _T("runtime") << _T("bin"); - std::unique_ptr jvm(AppLauncher() - .setImageRoot(appImageRoot) + const AppLauncher appLauncher = AppLauncher().setImageRoot(appImageRoot) .addJvmLibName(_T("bin\\jli.dll")) - .setAppDir(FileUtils::mkpath() << appImageRoot << _T("app")) + .setAppDir(appDirPath) .setLibEnvVariableName(_T("PATH")) .setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot - << _T("runtime")) - .createJvmLauncher()); + << _T("runtime")); + + const bool restart = !appLauncher.libEnvVariableContainsAppDir(); + + std::unique_ptr jvm(appLauncher.createJvmLauncher()); + + if (restart) { + jvm = std::unique_ptr(); + + STARTUPINFOW si; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + + PROCESS_INFORMATION pi; + ZeroMemory(&pi, sizeof(pi)); + + if (!CreateProcessW(launcherPath.c_str(), GetCommandLineW(), + NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { + JP_THROW(SysError(tstrings::any() << "CreateProcessW() failed", + CreateProcessW)); + } + + WaitForSingleObject(pi.hProcess, INFINITE); + + UniqueHandle childProcessHandle(pi.hProcess); + UniqueHandle childThreadHandle(pi.hThread); + + DWORD exitCode; + if (!GetExitCodeProcess(pi.hProcess, &exitCode)) { + JP_THROW(SysError(tstrings::any() << "GetExitCodeProcess() failed", + GetExitCodeProcess)); + } + + if (exitCode != 0) { + JP_THROW(tstrings::any() << "Child process exited with code " + << exitCode); + } + + return; + } // zip.dll may be loaded by java without full path // make sure it will look in runtime/bin diff --git a/src/jdk.jpackage/windows/native/common/WinSysInfo.cpp b/src/jdk.jpackage/windows/native/common/WinSysInfo.cpp index 9398fc67f22..55c0b7bee2d 100644 --- a/src/jdk.jpackage/windows/native/common/WinSysInfo.cpp +++ b/src/jdk.jpackage/windows/native/common/WinSysInfo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, 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 @@ -122,10 +122,6 @@ void setEnvVariable(const tstring& name, const tstring& value) << name << ", " << value << ") failed", SetEnvironmentVariable)); } - - if (0 != _tputenv_s(name.c_str(), value.c_str())) { - JP_THROW(tstrings::any() << "_tputenv_s(" << name << ", " << value << ") failed: " << lastCRTError()); - } } tstring getCurrentModulePath() From c2d1db9c50702d1fa5b3c607040e1978fac8ee16 Mon Sep 17 00:00:00 2001 From: Thejasvi Voniadka Date: Wed, 29 Sep 2021 04:56:05 +0000 Subject: [PATCH 080/253] 8273961: jdk/nio/zipfs/ZipFSTester.java fails if file path contains '+' character Backport-of: 7f78803b0926ea194334ad9b3c9f06cbe17a83dd --- test/jdk/jdk/nio/zipfs/ZipFSTester.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/jdk/jdk/nio/zipfs/ZipFSTester.java b/test/jdk/jdk/nio/zipfs/ZipFSTester.java index b3ef2abe300..48244bfc46b 100644 --- a/test/jdk/jdk/nio/zipfs/ZipFSTester.java +++ b/test/jdk/jdk/nio/zipfs/ZipFSTester.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021, 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 @@ -73,7 +73,7 @@ * @test * @bug 6990846 7009092 7009085 7015391 7014948 7005986 7017840 7007596 * 7157656 8002390 7012868 7012856 8015728 8038500 8040059 8069211 - * 8131067 8034802 8210899 + * 8131067 8034802 8210899 8273961 * @summary Test Zip filesystem provider * @modules jdk.zipfs * @run main ZipFSTester @@ -687,10 +687,19 @@ private static FileSystem newZipFileSystem(Path path, Map env) throws Exception { // Use URLDecoder (for test only) to remove the double escaped space - // character + // character. For the path which is not encoded by UTF-8, we need to + // replace "+" by "%2b" manually before feeding into the decoder. + // Otherwise, the URLDecoder would replace "+" by " ", which may + // raise NoSuchFileException. + // + // eg. var path = "file:///jdk-18+9/basic.jar"; + // URLDecoder.decode(path, "utf8") -> file:///jdk-18 9/basic.jar + // + // Also, we should not use URLEncoder in case of the path has been + // encoded. return FileSystems.newFileSystem( - new URI("jar", URLDecoder.decode(path.toUri().toString(), "utf8"), - null), env, null); + new URI("jar", URLDecoder.decode(path.toUri().toString() + .replace("+", "%2b"), "utf8"), null), env, null); } private static Path getTempPath() throws IOException From dd705127beb61b3a5e7e4ea63c0fcbea77f4eb52 Mon Sep 17 00:00:00 2001 From: Guoxiong Li Date: Wed, 29 Sep 2021 05:20:14 +0000 Subject: [PATCH 081/253] 8273408: java.lang.AssertionError: typeSig ERROR on generated class property of record Backport-of: e07ab82ee555f27921287a871ba582e0906ad45c --- .../com/sun/tools/javac/code/Symbol.java | 18 +- .../GenerateTypeProcessor.java | 59 ++++++ .../RecordComponentTypeTest.java | 168 ++++++++++++++++++ 3 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 test/langtools/tools/javac/records/recordComponent/GenerateTypeProcessor.java create mode 100644 test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java index 085e5bf1ac3..1715efb10c7 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java @@ -1504,16 +1504,30 @@ public RecordComponent getRecordComponent(VarSymbol field) { } public RecordComponent getRecordComponent(JCVariableDecl var, boolean addIfMissing, List annotations) { + RecordComponent toRemove = null; for (RecordComponent rc : recordComponents) { /* it could be that a record erroneously declares two record components with the same name, in that * case we need to use the position to disambiguate */ if (rc.name == var.name && var.pos == rc.pos) { - return rc; + if (rc.type.hasTag(TypeTag.ERROR) && !var.sym.type.hasTag(TypeTag.ERROR)) { + // Found a record component with an erroneous type: save it so that it can be removed later. + // If the class type of the record component is generated by annotation processor, it should + // use the new actual class type and symbol instead of the old dummy ErrorType. + toRemove = rc; + } else { + // Found a good record component: just return. + return rc; + } } } RecordComponent rc = null; - if (addIfMissing) { + if (toRemove != null) { + // Found a record component with an erroneous type: remove it and create a new one + recordComponents = List.filter(recordComponents, toRemove); + recordComponents = recordComponents.append(rc = new RecordComponent(var.sym, annotations)); + } else if (addIfMissing) { + // Didn't find the record component: create one. recordComponents = recordComponents.append(rc = new RecordComponent(var.sym, annotations)); } return rc; diff --git a/test/langtools/tools/javac/records/recordComponent/GenerateTypeProcessor.java b/test/langtools/tools/javac/records/recordComponent/GenerateTypeProcessor.java new file mode 100644 index 00000000000..230f3708f8b --- /dev/null +++ b/test/langtools/tools/javac/records/recordComponent/GenerateTypeProcessor.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 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 javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Set; + +@SupportedAnnotationTypes("*") +public class GenerateTypeProcessor extends AbstractProcessor { + + private String code = "public class GeneratedType { }"; + + private boolean firstTime = true; + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + // Create a new class: GeneratedType + if (firstTime) { + try (OutputStream out = + processingEnv.getFiler().createSourceFile("GeneratedType").openOutputStream()) { + out.write(code.getBytes()); + } catch (IOException ex) { + ex.printStackTrace(); + } + firstTime = false; + } + return false; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } +} diff --git a/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java b/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java new file mode 100644 index 00000000000..46418a66d83 --- /dev/null +++ b/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2021, 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 8273408 + * @summary The compiler shouldn't crash when record component uses the class generated by the annotation processor. + * @library /tools/lib + * @modules jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.main + * jdk.jdeps/com.sun.tools.classfile + * @compile GenerateTypeProcessor.java + * @run main RecordComponentTypeTest + */ + +import com.sun.tools.classfile.*; + +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; + +import toolbox.JavacTask; +import toolbox.TestRunner; +import toolbox.ToolBox; +import toolbox.Task; + +public class RecordComponentTypeTest extends TestRunner { + + ToolBox tb; + ClassFile cf; + + public RecordComponentTypeTest() { + super(System.err); + tb = new ToolBox(); + } + + public static void main(String[] args) throws Exception { + RecordComponentTypeTest t = new RecordComponentTypeTest(); + t.runTests(); + } + + @Test + public void testRecordComponentUsingGeneratedType() throws Exception { + String code = "public record RecordComponentUsingGeneratedType(GeneratedType generatedType) { }"; + Path curPath = Path.of("."); + + // Have no annotation processor. + List output = new JavacTask(tb) + .sources(code) + .outdir(curPath) + .options("-XDrawDiagnostics") + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + List expected = Arrays.asList( + "RecordComponentUsingGeneratedType.java:1:49: compiler.err.cant.resolve.location: kindname.class, " + + "GeneratedType, , , (compiler.misc.location: kindname.class, RecordComponentUsingGeneratedType, null)", + "1 error"); + tb.checkEqual(expected, output); + + // Have annotation processor, and processor generates expected type. + new JavacTask(tb) + .sources(code) + .options("-processor", "GenerateTypeProcessor") + .outdir(curPath) + .run(); + } + + @Test + public void testRecordComponentUsingUnknownType() throws Exception { + String code = "public record RecordComponentUsingUnknownType(UnknownType unknownType) { }"; + Path curPath = Path.of("."); + + // Have no annotation processor. + List output = new JavacTask(tb) + .sources(code) + .outdir(curPath) + .options("-XDrawDiagnostics") + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + List expected = Arrays.asList( + "RecordComponentUsingUnknownType.java:1:47: compiler.err.cant.resolve.location: kindname.class, " + + "UnknownType, , , (compiler.misc.location: kindname.class, RecordComponentUsingUnknownType, null)", + "1 error"); + tb.checkEqual(expected, output); + + // Have annotation processor, but processor doesn't generate the expected type. + List output2 = new JavacTask(tb) + .sources(code) + .outdir(curPath) + .options("-XDrawDiagnostics", "-processor", "GenerateTypeProcessor") + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + List expected2 = Arrays.asList( + "RecordComponentUsingUnknownType.java:1:47: compiler.err.cant.resolve.location: kindname.class, " + + "UnknownType, , , (compiler.misc.location: kindname.class, RecordComponentUsingUnknownType, null)", + "1 error"); + tb.checkEqual(expected2, output2); + } + + + @Test + public void testRecordComponentUsingGeneratedTypeWithAnnotation() throws Exception { + String code = """ + import java.lang.annotation.Retention; + import java.lang.annotation.RetentionPolicy; + public record RecordComponentUsingGeneratedTypeWithAnnotation(@TestAnnotation GeneratedType generatedType) { } + + @Retention(RetentionPolicy.RUNTIME) + @interface TestAnnotation { } + """; + Path curPath = Path.of("."); + new JavacTask(tb) + .sources(code) + .options("-processor", "GenerateTypeProcessor") + .outdir(curPath) + .run(); + cf = ClassFile.read(curPath.resolve("RecordComponentUsingGeneratedTypeWithAnnotation.class")); + + for (Field field : cf.fields) { + if ("generatedType".equals(field.getName(cf.constant_pool))) { + checkRuntimeVisibleAnnotation(field.attributes); + } + } + + for (Method method : cf.methods) { + if ("generatedType".equals(method.getName(cf.constant_pool))) { + checkRuntimeVisibleAnnotation(method.attributes); + } + } + } + + private void checkRuntimeVisibleAnnotation(Attributes attributes) throws Exception { + RuntimeVisibleAnnotations_attribute annotations = + (RuntimeVisibleAnnotations_attribute) attributes.get(Attribute.RuntimeVisibleAnnotations); + boolean hasAnnotation = false; + for (Annotation annotation : annotations.annotations) { + if ("LTestAnnotation;".equals(cf.constant_pool.getUTF8Value(annotation.type_index))) { + hasAnnotation = true; + } + } + if (!hasAnnotation) { + throw new AssertionError("Expected RuntimeVisibleAnnotation doesn't appear"); + } + } +} From 108e1bd1e8ca853ea10fc960d65eede1c3c56ca9 Mon Sep 17 00:00:00 2001 From: Guoxiong Li Date: Wed, 29 Sep 2021 05:21:55 +0000 Subject: [PATCH 082/253] 8271254: javac generates unreachable code when using empty semicolon statement Backport-of: fe89dd3b0d47807c7dbfe24d17f6aca152fc8908 --- .../classes/com/sun/tools/javac/jvm/Gen.java | 14 ++- .../DeadCodeGeneratedForEmptyTryTest.java | 96 ++++++++++++++++++- 2 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java index d43cfc64502..9ef735e1543 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -1510,8 +1510,8 @@ void afterBody() { //where /** Generate code for a try or synchronized statement * @param body The body of the try or synchronized statement. - * @param catchers The lis of catch clauses. - * @param env the environment current for the body. + * @param catchers The list of catch clauses. + * @param env The current environment of the body. */ void genTry(JCTree body, List catchers, Env env) { int limit = code.nextreg; @@ -1523,7 +1523,13 @@ void genTry(JCTree body, List catchers, Env env) { code.statBegin(TreeInfo.endPos(body)); genFinalizer(env); code.statBegin(TreeInfo.endPos(env.tree)); - Chain exitChain = code.branch(goto_); + Chain exitChain; + boolean actualTry = env.tree.hasTag(TRY); + if (startpc == endpc && actualTry) { + exitChain = code.branch(dontgoto); + } else { + exitChain = code.branch(goto_); + } endFinalizerGap(env); env.info.finalize.afterBody(); boolean hasFinalizer = @@ -1541,7 +1547,7 @@ void genTry(JCTree body, List catchers, Env env) { } endFinalizerGap(env); } - if (hasFinalizer) { + if (hasFinalizer && (startpc != endpc || !actualTry)) { // Create a new register segment to avoid allocating // the same variables in finalizers and other statements. code.newRegSegment(); diff --git a/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java b/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java index a35def71312..a443b04c4e1 100644 --- a/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java +++ b/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8022186 + * @bug 8022186 8271254 * @summary javac generates dead code if a try with an empty body has a finalizer * @modules jdk.jdeps/com.sun.tools.classfile * jdk.compiler/com.sun.tools.javac.util @@ -53,8 +53,10 @@ public static void main(String[] args) throws Exception { } void run() throws Exception { - checkClassFile(Paths.get(System.getProperty("test.classes"), - this.getClass().getName() + "$Test.class")); + for (int i = 1; i <= 8; i++) { + checkClassFile(Paths.get(System.getProperty("test.classes"), + this.getClass().getName() + "$Test" + i + ".class")); + } } int utf8Index; @@ -62,6 +64,7 @@ void run() throws Exception { ConstantPool constantPool; void checkClassFile(final Path path) throws Exception { + numberOfRefToStr = 0; ClassFile classFile = ClassFile.read( new BufferedInputStream(Files.newInputStream(path))); constantPool = classFile.constant_pool; @@ -155,9 +158,92 @@ public Void visitUnknown(Instruction instr, Void p) { } - public class Test { + public class Test1 { + void methodToLookFor() { + try { + // empty intentionally + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test2 { + void methodToLookFor() { + try { + // empty intentionally + } catch (Exception e) { + System.out.println("EXCEPTION"); + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test3 { + void methodToLookFor() { + try { + ; // skip statement intentionally + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test4 { + void methodToLookFor() { + try { + ; // skip statement intentionally + } catch (Exception e) { + System.out.println("EXCEPTION"); + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test5 { + void methodToLookFor() { + try { + // empty try statement + try { } finally { } + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test6 { + void methodToLookFor() { + try { + // empty try statement + try { } catch (Exception e) { } finally { } + } catch (Exception e) { + System.out.println("EXCEPTION"); + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test7 { + void methodToLookFor() { + try { + // empty try statement with skip statement + try { ; } finally { } + } finally { + System.out.println("STR_TO_LOOK_FOR"); + } + } + } + + public class Test8 { void methodToLookFor() { try { + // empty try statement with skip statement + try { ; } catch (Exception e) { } finally { } + } catch (Exception e) { + System.out.println("EXCEPTION"); } finally { System.out.println("STR_TO_LOOK_FOR"); } From ff3e90f5cdc38d99c0b154f19ac84322c86043c2 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:04:22 +0000 Subject: [PATCH 083/253] 8272570: C2: crash in PhaseCFG::global_code_motion Backport-of: 0f428ca533627e758cdca599d4589f39c21e27b6 --- src/hotspot/share/opto/lcm.cpp | 4 +- .../regalloc/TestGCMRecalcPressureNodes.java | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/regalloc/TestGCMRecalcPressureNodes.java diff --git a/src/hotspot/share/opto/lcm.cpp b/src/hotspot/share/opto/lcm.cpp index 014c6e596bf..0548e6493dc 100644 --- a/src/hotspot/share/opto/lcm.cpp +++ b/src/hotspot/share/opto/lcm.cpp @@ -518,7 +518,7 @@ Node* PhaseCFG::select( uint score = 0; // Bigger is better int idx = -1; // Index in worklist int cand_cnt = 0; // Candidate count - bool block_size_threshold_ok = (block->number_of_nodes() > 10) ? true : false; + bool block_size_threshold_ok = (recalc_pressure_nodes != NULL) && (block->number_of_nodes() > 10); for( uint i=0; i& ready_cnt, Vecto return true; } - bool block_size_threshold_ok = (block->number_of_nodes() > 10) ? true : false; + bool block_size_threshold_ok = (recalc_pressure_nodes != NULL) && (block->number_of_nodes() > 10); // We track the uses of local definitions as input dependences so that // we know when a given instruction is avialable to be scheduled. diff --git a/test/hotspot/jtreg/compiler/regalloc/TestGCMRecalcPressureNodes.java b/test/hotspot/jtreg/compiler/regalloc/TestGCMRecalcPressureNodes.java new file mode 100644 index 00000000000..fe2fd7e4444 --- /dev/null +++ b/test/hotspot/jtreg/compiler/regalloc/TestGCMRecalcPressureNodes.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 THL A29 Limited, a Tencent company. 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 8272570 + * @summary crash in PhaseCFG::global_code_motion + * @requires vm.compiler2.enabled + * + * @run main/othervm -Xbatch TestGCMRecalcPressureNodes + */ + +public class TestGCMRecalcPressureNodes { + public boolean bo0; + public boolean bo1; + public void foo() { + int sh12 = 61; + for (int i = 0; i < 50; i++) { + sh12 *= 34; + } + Math.tan(1.0); + bo0 = true; + bo1 = true; + } + public static void main(String[] args) { + TestGCMRecalcPressureNodes instance = new TestGCMRecalcPressureNodes(); + for (int i = 0; i < 50000; i++) { + instance.foo(); + } + } +} + From 056eca0c2de210355d09071a50e19765e977a206 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:08:59 +0000 Subject: [PATCH 084/253] 8273165: GraphKit::combine_exception_states fails with "matching stack sizes" assert Backport-of: 632a7e0885596b70d34be319bd09d4df8e151d12 --- src/hotspot/share/opto/callGenerator.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hotspot/share/opto/callGenerator.cpp b/src/hotspot/share/opto/callGenerator.cpp index d65747bc5a2..42aed2e57fb 100644 --- a/src/hotspot/share/opto/callGenerator.cpp +++ b/src/hotspot/share/opto/callGenerator.cpp @@ -513,6 +513,12 @@ bool LateInlineVirtualCallGenerator::do_late_inline_check(Compile* C, JVMState* // Method handle linker case is handled in CallDynamicJavaNode::Ideal(). // Unless inlining is performed, _override_symbolic_info bit will be set in DirectCallGenerator::generate(). + // Implicit receiver null checks introduce problems when exception states are combined. + Node* receiver = jvms->map()->argument(jvms, 0); + const Type* recv_type = C->initial_gvn()->type(receiver); + if (recv_type->maybe_null()) { + return false; + } // Even if inlining is not allowed, a virtual call can be strength-reduced to a direct call. bool allow_inline = C->inlining_incrementally(); if (!allow_inline && _callee->holder()->is_interface()) { From da77acb8f2eb2e2841b0c7137878798fae4bfa62 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:10:58 +0000 Subject: [PATCH 085/253] 8271954: C2: assert(false) failed: Bad graph detected in build_loop_late Backport-of: c86e24d4be1e1a26a2a8323ef7ddbab6326bbf3a --- src/hotspot/share/opto/loopPredicate.cpp | 111 +++++- src/hotspot/share/opto/loopnode.hpp | 20 +- .../loopopts/TestUnswitchWithSunkNodes.java | 325 ++++++++++++++++++ 3 files changed, 442 insertions(+), 14 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/loopopts/TestUnswitchWithSunkNodes.java diff --git a/src/hotspot/share/opto/loopPredicate.cpp b/src/hotspot/share/opto/loopPredicate.cpp index fdb2bdbf7ad..3364049b513 100644 --- a/src/hotspot/share/opto/loopPredicate.cpp +++ b/src/hotspot/share/opto/loopPredicate.cpp @@ -107,8 +107,9 @@ void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred, // Otherwise, the continuation projection is set up to be the false // projection. This code is also used to clone predicates to cloned loops. ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, - Deoptimization::DeoptReason reason, - int opcode, bool if_cont_is_true_proj) { + Deoptimization::DeoptReason reason, int opcode, + bool if_cont_is_true_proj, Node_List* old_new, + UnswitchingAction unswitching_action) { assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!"); IfNode* iff = cont_proj->in(0)->as_If(); @@ -193,11 +194,40 @@ ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* if (use->is_Phi() && use->outcnt() > 0) { assert(use->in(0) == rgn, ""); _igvn.rehash_node_delayed(use); - use->add_req(use->in(proj_index)); + Node* phi_input = use->in(proj_index); + if (unswitching_action == UnswitchingAction::FastLoopCloning + && !phi_input->is_CFG() && !phi_input->is_Phi() && get_ctrl(phi_input) == uncommon_proj) { + // There are some control dependent nodes on the uncommon projection and we are currently copying predicates + // to the fast loop in loop unswitching (first step, slow loop is processed afterwards). For the fast loop, + // we need to clone all the data nodes in the chain from the phi ('use') up until the node whose control input + // is the uncommon_proj. The slow loop can reuse the old data nodes and thus only needs to update the control + // input to the uncommon_proj (done on the next invocation of this method when 'unswitch_is_slow_loop' is true. + assert(LoopUnswitching, "sanity check"); + phi_input = clone_data_nodes_for_fast_loop(phi_input, uncommon_proj, if_uct, old_new); + } else if (unswitching_action == UnswitchingAction::SlowLoopRewiring) { + // Replace phi input for the old predicate path with TOP as the predicate is dying anyways. This avoids the need + // to clone the data nodes again for the slow loop. + assert(LoopUnswitching, "sanity check"); + _igvn.replace_input_of(use, proj_index, C->top()); + } + use->add_req(phi_input); has_phi = true; } } assert(!has_phi || rgn->req() > 3, "no phis when region is created"); + if (unswitching_action == UnswitchingAction::SlowLoopRewiring) { + // Rewire the control dependent data nodes for the slow loop from the old to the new uncommon projection. + assert(uncommon_proj->outcnt() > 1 && old_new == NULL, "sanity"); + for (DUIterator_Fast jmax, j = uncommon_proj->fast_outs(jmax); j < jmax; j++) { + Node* data = uncommon_proj->fast_out(j); + if (!data->is_CFG()) { + _igvn.replace_input_of(data, 0, if_uct); + set_ctrl(data, if_uct); + --j; + --jmax; + } + } + } if (new_entry == NULL) { // Attach if_cont to iff @@ -209,9 +239,70 @@ ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* return if_cont->as_Proj(); } +// Clone data nodes for the fast loop while creating a new If with create_new_if_for_predicate. Returns the node which is +// used for the uncommon trap phi input. +Node* PhaseIdealLoop::clone_data_nodes_for_fast_loop(Node* phi_input, ProjNode* uncommon_proj, Node* if_uct, Node_List* old_new) { + // Step 1: Clone all nodes on the data chain but do not rewire anything, yet. Keep track of the cloned nodes + // by using the old_new mapping. This mapping is then used in step 2 to rewire the cloned nodes accordingly. + DEBUG_ONLY(uint last_idx = C->unique();) + Unique_Node_List list; + list.push(phi_input); + for (uint j = 0; j < list.size(); j++) { + Node* next = list.at(j); + Node* clone = next->clone(); + _igvn.register_new_node_with_optimizer(clone); + old_new->map(next->_idx, clone); + for (uint k = 1; k < next->req(); k++) { + Node* in = next->in(k); + if (!in->is_Phi() && get_ctrl(in) == uncommon_proj) { + list.push(in); + } + } + } + + // Step 2: All nodes are cloned. Rewire them by using the old_new mapping. + for (uint j = 0; j < list.size(); j++) { + Node* next = list.at(j); + Node* clone = old_new->at(next->_idx); + assert(clone != NULL && clone->_idx >= last_idx, "must exist and be a proper clone"); + if (next->in(0) == uncommon_proj) { + // All data nodes with a control input to the uncommon projection in the chain need to be rewired to the new uncommon + // projection (could not only be the last data node in the chain but also, for example, a DivNode within the chain). + _igvn.replace_input_of(clone, 0, if_uct); + set_ctrl(clone, if_uct); + } + + // Rewire the inputs of the cloned nodes to the old nodes to the new clones. + for (uint k = 1; k < next->req(); k++) { + Node* in = next->in(k); + if (!in->is_Phi()) { + assert(!in->is_CFG(), "must be data node"); + Node* in_clone = old_new->at(in->_idx); + if (in_clone != NULL) { + assert(in_clone->_idx >= last_idx, "must be a valid clone"); + _igvn.replace_input_of(clone, k, in_clone); + set_ctrl(clone, if_uct); + } + } + } + } + Node* clone_phi_input = old_new->at(phi_input->_idx); + assert(clone_phi_input != NULL && clone_phi_input->_idx >= last_idx, "must exist and be a proper clone"); + return clone_phi_input; +} //--------------------------clone_predicate----------------------- -ProjNode* PhaseIdealLoop::clone_predicate_to_unswitched_loop(ProjNode* predicate_proj, Node* new_entry, Deoptimization::DeoptReason reason) { - ProjNode* new_predicate_proj = create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If); +ProjNode* PhaseIdealLoop::clone_predicate_to_unswitched_loop(ProjNode* predicate_proj, Node* new_entry, + Deoptimization::DeoptReason reason, Node_List* old_new) { + UnswitchingAction unswitching_action; + if (predicate_proj->other_if_proj()->outcnt() > 1) { + // There are some data dependencies that need to be taken care of when cloning a predicate. + unswitching_action = old_new == NULL ? UnswitchingAction::SlowLoopRewiring : UnswitchingAction::FastLoopCloning; + } else { + unswitching_action = UnswitchingAction::None; + } + + ProjNode* new_predicate_proj = create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If, + true, old_new, unswitching_action); IfNode* iff = new_predicate_proj->in(0)->as_If(); Node* ctrl = iff->in(0); @@ -319,7 +410,7 @@ ProjNode* PhaseIdealLoop::clone_skeleton_predicate_for_unswitched_loops(Node* if //--------------------------clone_loop_predicates----------------------- // Clone loop predicates to cloned loops when unswitching a loop. -void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, ProjNode*& iffast_pred, ProjNode*& ifslow_pred) { +void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, Node_List& old_new, ProjNode*& iffast_pred, ProjNode*& ifslow_pred) { LoopNode* head = loop->_head->as_Loop(); bool clone_limit_check = !head->is_CountedLoop(); Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl); @@ -343,7 +434,7 @@ void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, co } if (predicate_proj != NULL) { // right pattern that can be used by loop predication // clone predicate - iffast_pred = clone_predicate_to_unswitched_loop(predicate_proj, iffast_pred, Deoptimization::Reason_predicate); + iffast_pred = clone_predicate_to_unswitched_loop(predicate_proj, iffast_pred, Deoptimization::Reason_predicate, &old_new); ifslow_pred = clone_predicate_to_unswitched_loop(predicate_proj, ifslow_pred, Deoptimization::Reason_predicate); clone_skeleton_predicates_to_unswitched_loop(loop, old_new, Deoptimization::Reason_predicate, predicate_proj, iffast_pred, ifslow_pred); @@ -352,7 +443,7 @@ void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, co } if (profile_predicate_proj != NULL) { // right pattern that can be used by loop predication // clone predicate - iffast_pred = clone_predicate_to_unswitched_loop(profile_predicate_proj, iffast_pred, Deoptimization::Reason_profile_predicate); + iffast_pred = clone_predicate_to_unswitched_loop(profile_predicate_proj, iffast_pred, Deoptimization::Reason_profile_predicate, &old_new); ifslow_pred = clone_predicate_to_unswitched_loop(profile_predicate_proj, ifslow_pred, Deoptimization::Reason_profile_predicate); clone_skeleton_predicates_to_unswitched_loop(loop, old_new, Deoptimization::Reason_profile_predicate, profile_predicate_proj, iffast_pred, ifslow_pred); @@ -363,7 +454,7 @@ void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, co // Clone loop limit check last to insert it before loop. // Don't clone a limit check which was already finalized // for this counted loop (only one limit check is needed). - iffast_pred = clone_predicate_to_unswitched_loop(limit_check_proj, iffast_pred, Deoptimization::Reason_loop_limit_check); + iffast_pred = clone_predicate_to_unswitched_loop(limit_check_proj, iffast_pred, Deoptimization::Reason_loop_limit_check, &old_new); ifslow_pred = clone_predicate_to_unswitched_loop(limit_check_proj, ifslow_pred, Deoptimization::Reason_loop_limit_check); check_created_predicate_for_unswitching(iffast_pred); @@ -372,7 +463,7 @@ void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, co } #ifndef PRODUCT -void PhaseIdealLoop::check_created_predicate_for_unswitching(const Node* new_entry) const { +void PhaseIdealLoop::check_created_predicate_for_unswitching(const Node* new_entry) { assert(new_entry != NULL, "IfTrue or IfFalse after clone predicate"); if (TraceLoopPredicate) { tty->print("Loop Predicate cloned: "); diff --git a/src/hotspot/share/opto/loopnode.hpp b/src/hotspot/share/opto/loopnode.hpp index d2a9c4d6aa4..488101507eb 100644 --- a/src/hotspot/share/opto/loopnode.hpp +++ b/src/hotspot/share/opto/loopnode.hpp @@ -1275,9 +1275,20 @@ class PhaseIdealLoop : public PhaseTransform { // Return true if exp is a scaled induction var plus (or minus) constant bool is_scaled_iv_plus_offset(Node* exp, Node* iv, int* p_scale, Node** p_offset, int depth = 0); + // Enum to determine the action to be performed in create_new_if_for_predicate() when processing phis of UCT regions. + enum class UnswitchingAction { + None, // No special action. + FastLoopCloning, // Need to clone nodes for the fast loop. + SlowLoopRewiring // Need to rewire nodes for the slow loop. + }; + // Create a new if above the uncommon_trap_if_pattern for the predicate to be promoted ProjNode* create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, Deoptimization::DeoptReason reason, - int opcode, bool if_cont_is_true_proj = true); + int opcode, bool if_cont_is_true_proj = true, Node_List* old_new = NULL, + UnswitchingAction unswitching_action = UnswitchingAction::None); + + // Clone data nodes for the fast loop while creating a new If with create_new_if_for_predicate. + Node* clone_data_nodes_for_fast_loop(Node* phi_input, ProjNode* uncommon_proj, Node* if_uct, Node_List* old_new); void register_control(Node* n, IdealLoopTree *loop, Node* pred, bool update_body = true); @@ -1563,13 +1574,14 @@ class PhaseIdealLoop : public PhaseTransform { } // Clone loop predicates to slow and fast loop when unswitching a loop - void clone_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, ProjNode*& iffast_pred, ProjNode*& ifslow_pred); - ProjNode* clone_predicate_to_unswitched_loop(ProjNode* predicate_proj, Node* new_entry, Deoptimization::DeoptReason reason); + void clone_predicates_to_unswitched_loop(IdealLoopTree* loop, Node_List& old_new, ProjNode*& iffast_pred, ProjNode*& ifslow_pred); + ProjNode* clone_predicate_to_unswitched_loop(ProjNode* predicate_proj, Node* new_entry, Deoptimization::DeoptReason reason, + Node_List* old_new = NULL); void clone_skeleton_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, Deoptimization::DeoptReason reason, ProjNode* old_predicate_proj, ProjNode* iffast_pred, ProjNode* ifslow_pred); ProjNode* clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate, Node* uncommon_proj, Deoptimization::DeoptReason reason, ProjNode* output_proj, IdealLoopTree* loop); - void check_created_predicate_for_unswitching(const Node* new_entry) const PRODUCT_RETURN; + static void check_created_predicate_for_unswitching(const Node* new_entry) PRODUCT_RETURN; bool _created_loop_node; #ifdef ASSERT diff --git a/test/hotspot/jtreg/compiler/loopopts/TestUnswitchWithSunkNodes.java b/test/hotspot/jtreg/compiler/loopopts/TestUnswitchWithSunkNodes.java new file mode 100644 index 00000000000..08dc7afde2c --- /dev/null +++ b/test/hotspot/jtreg/compiler/loopopts/TestUnswitchWithSunkNodes.java @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2021, 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 8271954 + * @requires vm.compiler2.enabled + * @summary A pinned Cast node on the UCT projection of a predicate is as input for the UCT phi node for the original + * loop, the fast and slow loop resulting in a dominance failure. These data nodes need to be updated while + * unswitching a loop. + * @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.loopopts.TestUnswitchWithSunkNodes::test* + * compiler.loopopts.TestUnswitchWithSunkNodes + */ + +package compiler.loopopts; + +public class TestUnswitchWithSunkNodes { + static int iFld, iFld2, iFld3 = 1, iFld4 = 1; + static long instanceCount; + static double dFld; + static boolean bFld; + static int iArrFld[] = new int[10]; + + static { + init(iArrFld); + } + + public static void main(String[] strArr) { + // The testcases with Divisions have additional control inputs which need to be taken care of + testNoDiamond(); + testNoDiamondDiv(); + testWithDiamond(); + testWithDiamondDiv1(); + testWithDiamondDiv2(); + testWithDiamondOneLongOneShortPath(); + testWithDiamondComplex(); + testWithDiamondComplexDiv(); + } + + static void testNoDiamond() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + i2 = (((i2 + 3) + iFld2) + iFld3) - iFld4; + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testNoDiamondDiv() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + i2 = (((i2 + 3) + iFld2) + iFld3) / iFld4; + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testWithDiamond() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + double d1 = (double) i2; + i2 = (int)((d1 + iFld4) - (d1 + iFld)); + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testWithDiamondDiv1() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + i2 = (i2 / iFld4) - (i2 / iFld3); + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testWithDiamondDiv2() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + int i3 = (int)d; + i2 = (i3 / iFld4) - (i3 / iFld3); + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testWithDiamondOneLongOneShortPath() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + double d1 = (double)i2; + i2 = (int)((d1 + 3 + iFld2 + iFld3 + iFld4) - (d1 + iFld)); + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testWithDiamondComplex() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + i2 += 4; + float l = (float)i2; + i2 = (int)((l + 3) - (l + iFld)); + double d1 = (double)i2; + i2 = (int)((d1 + 3) - (d1 + iFld) - (d1 * iFld2)); + i2 = (int)((l + 3) - (l + iFld) - (l * iFld2) + (d1 - iFld2) + (d1 / iFld3)); + d1 = (double)i2; + i2 = (int)((d1 + 3) - (d1 + iFld) - (d1 * iFld2) + (d1 - iFld2) + (d1 / iFld3)); + i2 += dFld; + l = (float)i2; + i2 = (int)((l + 3) - (l + iFld) - (l * iFld2) + (d1 - iFld2) + (d1 / iFld3) - (d1 + iFld) - (d1 * iFld2) + (d1 - iFld2) + (d1 / iFld3)); + d1 = (double)i2; + i2 = (int)((d1 + 3) - (d1 + iFld) - (d1 * iFld2) + (d1 - iFld2) + (d1 / iFld3) + (d1 + 3) - (d1 + iFld) - (d1 * iFld2) + (d1 - iFld2) + (d1 / iFld3)); + d1 = (double) i2; + i2 = (int) ((d1 + 3 + iFld2 + iFld3 + iFld4) - (d1 + iFld)); + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + static void testWithDiamondComplexDiv() { + int i, i2 = 10, i21, i22, i24, i26 = 41724, iArr2[] = new int[10]; + double d; + float f2; + init(iArr2); + i = 1; + while (++i < 219) { + for (d = 15; 305 > d; ++d) { + if (bFld) { + instanceCount = i2; + int i3 = (int)d; + i2 = (i3 / iFld4) - (i3 / iFld3); + double d1 = (double) i2; + i3 = (int)((d1 + iFld4) - (d1 + iFld)); + i2 = (i3 / iFld4) - (i3 / iFld3); + } + for (f2 = 5; 87 > f2; ++f2) { + i2 = (int) instanceCount; + for (i22 = 1; 2 > i22; i22++) { + if (bFld) { + iArr2[1] += 190L; + } + } + for (i24 = 1; 2 > i24; i24++) { + switch (i) { + case 88: + i26 += (i24); + } + } + } + } + } + } + + public static void init(int[] a) { + for (int j = 0; j < a.length; j++) { + a[j] = j; + } + } +} From 2b393f926385c8b47f0b3d7ce9810ee8fd3b0a74 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:12:42 +0000 Subject: [PATCH 086/253] 8272574: C2: assert(false) failed: Bad graph detected in build_loop_late Backport-of: 16c3ad1ff4d9a0e21f15656c73a96a6c143c811a --- src/hotspot/share/opto/loopPredicate.cpp | 21 +++++- src/hotspot/share/opto/loopnode.hpp | 2 +- src/hotspot/share/opto/memnode.cpp | 9 ++- .../loopopts/TestLoopPredicateDep.java | 69 +++++++++++++++++++ 4 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/loopopts/TestLoopPredicateDep.java diff --git a/src/hotspot/share/opto/loopPredicate.cpp b/src/hotspot/share/opto/loopPredicate.cpp index 3364049b513..60581759c45 100644 --- a/src/hotspot/share/opto/loopPredicate.cpp +++ b/src/hotspot/share/opto/loopPredicate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, 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 @@ -712,7 +712,7 @@ class Invariance : public StackObj { // Returns true if the predicate of iff is in "scale*iv + offset u< load_range(ptr)" format // Note: this function is particularly designed for loop predication. We require load_range // and offset to be loop invariant computed on the fly by "invar" -bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const { +bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar DEBUG_ONLY(COMMA ProjNode *predicate_proj)) const { if (!is_loop_exit(iff)) { return false; } @@ -753,6 +753,21 @@ bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invari if (offset && !invar.is_invariant(offset)) { // offset must be invariant return false; } +#ifdef ASSERT + if (offset && phase->has_ctrl(offset)) { + Node* offset_ctrl = phase->get_ctrl(offset); + if (phase->get_loop(predicate_proj) == phase->get_loop(offset_ctrl) && + phase->is_dominator(predicate_proj, offset_ctrl)) { + // If the control of offset is loop predication promoted by previous pass, + // then it will lead to cyclic dependency. + // Previously promoted loop predication is in the same loop of predication + // point. + // This situation can occur when pinning nodes too conservatively - can we do better? + assert(false, "cyclic dependency prevents range check elimination, idx: offset %d, offset_ctrl %d, predicate_proj %d", + offset->_idx, offset_ctrl->_idx, predicate_proj->_idx); + } + } +#endif return true; } @@ -1232,7 +1247,7 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree *loop, ProjNode* loop->dump_head(); } #endif - } else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) { + } else if (cl != NULL && loop->is_range_check_if(iff, this, invar DEBUG_ONLY(COMMA predicate_proj))) { // Range check for counted loops const Node* cmp = bol->in(1)->as_Cmp(); Node* idx = cmp->in(1); diff --git a/src/hotspot/share/opto/loopnode.hpp b/src/hotspot/share/opto/loopnode.hpp index 488101507eb..47fa319466a 100644 --- a/src/hotspot/share/opto/loopnode.hpp +++ b/src/hotspot/share/opto/loopnode.hpp @@ -737,7 +737,7 @@ class IdealLoopTree : public ResourceObj { bool policy_range_check( PhaseIdealLoop *phase ) const; // Return TRUE if "iff" is a range check. - bool is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const; + bool is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar DEBUG_ONLY(COMMA ProjNode *predicate_proj)) const; // Estimate the number of nodes required when cloning a loop (body). uint est_loop_clone_sz(uint factor) const; diff --git a/src/hotspot/share/opto/memnode.cpp b/src/hotspot/share/opto/memnode.cpp index c348492bd08..03625081218 100644 --- a/src/hotspot/share/opto/memnode.cpp +++ b/src/hotspot/share/opto/memnode.cpp @@ -1625,7 +1625,14 @@ Node *LoadNode::split_through_phi(PhaseGVN *phase) { the_clone = x; // Remember for possible deletion. // Alter data node to use pre-phi inputs if (this->in(0) == region) { - x->set_req(0, in); + if (mem->is_Phi() && (mem->in(0) == region) && mem->in(i)->in(0) != NULL && + MemNode::all_controls_dominate(address, region)) { + // Enable other optimizations such as loop predication which does not work + // if we directly pin the node to node `in` + x->set_req(0, mem->in(i)->in(0)); // Use same control as memory + } else { + x->set_req(0, in); + } } else { x->set_req(0, NULL); } diff --git a/test/hotspot/jtreg/compiler/loopopts/TestLoopPredicateDep.java b/test/hotspot/jtreg/compiler/loopopts/TestLoopPredicateDep.java new file mode 100644 index 00000000000..ca651a20750 --- /dev/null +++ b/test/hotspot/jtreg/compiler/loopopts/TestLoopPredicateDep.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 THL A29 Limited, a Tencent company. 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 8272574 + * @summary Crashes in PhaseIdealLoop::build_loop_late_post_work + * @requires vm.compiler2.enabled + * + * @run main TestLoopPredicateDep + * + */ + +public class TestLoopPredicateDep { + public static void getPermutations(byte[] inputArray, byte[][] outputArray) { + int[] indexes = new int[]{0, 2}; + + for (int a = 0; a < a + 16; a++) { + int oneIdx = indexes[0]++; + for (int b = a + 1; b < inputArray.length; b++) { + int twoIdx = indexes[1]++; + outputArray[twoIdx][0] = inputArray[a]; + outputArray[twoIdx][1] = inputArray[b]; + } + } + } + + public static void main(String[] args) { + final byte[] inputArray = new byte[]{0, 1}; + final byte[][] outputArray = new byte[3][2]; + + for (int i = 0; i < 10; ++i) { + Thread t = new Thread(new Runnable() { + public void run() { + for (int i = 0; i < 1000000; i++) { + getPermutations(inputArray, outputArray); + } + } + }); + t.setDaemon(true); + t.start(); + try { + Thread.sleep(100); + } catch (Exception e) { + } + } + } + +} From 23fa88b18b9a604fbb6f9f4ae6ad2693fe6cac48 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:14:46 +0000 Subject: [PATCH 087/253] 8272413: Incorrect num of element count calculation for vector cast Backport-of: 7e662e7b9d7ea5113f568418e0acac4234ebfb88 --- src/hotspot/share/opto/vectorIntrinsics.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/opto/vectorIntrinsics.cpp b/src/hotspot/share/opto/vectorIntrinsics.cpp index d1a8ede4f5f..06f4914199d 100644 --- a/src/hotspot/share/opto/vectorIntrinsics.cpp +++ b/src/hotspot/share/opto/vectorIntrinsics.cpp @@ -1672,8 +1672,7 @@ bool LibraryCallKit::inline_vector_convert() { if (num_elem_from < num_elem_to) { // Since input and output number of elements are not consistent, we need to make sure we // properly size. Thus, first make a cast that retains the number of elements from source. - // In case the size exceeds the arch size, we do the minimum. - int num_elem_for_cast = MIN2(num_elem_from, Matcher::max_vector_size(elem_bt_to)); + int num_elem_for_cast = num_elem_from; // It is possible that arch does not support this intermediate vector size // TODO More complex logic required here to handle this corner case for the sizes. @@ -1692,7 +1691,7 @@ bool LibraryCallKit::inline_vector_convert() { } else if (num_elem_from > num_elem_to) { // Since number elements from input is larger than output, simply reduce size of input (we are supposed to // drop top elements anyway). - int num_elem_for_resize = MAX2(num_elem_to, Matcher::min_vector_size(elem_bt_from)); + int num_elem_for_resize = num_elem_to; // It is possible that arch does not support this intermediate vector size // TODO More complex logic required here to handle this corner case for the sizes. From e4bf9f9014b32e4250790ec55a4ad846a7a50b46 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:16:39 +0000 Subject: [PATCH 088/253] 8271340: Crash PhaseIdealLoop::clone_outer_loop Backport-of: 2abf3b3b2743947282300ee8416611559e49fca0 --- .../gc/shenandoah/c2/shenandoahSupport.cpp | 104 +++++++++++------- .../gc/shenandoah/c2/shenandoahSupport.hpp | 2 + src/hotspot/share/opto/cfgnode.cpp | 2 +- .../loopopts/TestInfiniteLoopCCP.java | 77 +++++++++++++ 4 files changed, 142 insertions(+), 43 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/loopopts/TestInfiniteLoopCCP.java diff --git a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp index 45de2647375..5ba3828b2d3 100644 --- a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp @@ -2170,48 +2170,7 @@ void MemoryGraphFixer::collect_memory_nodes() { assert(call->is_Call(), ""); mem = call->in(TypeFunc::Memory); } else if (in->Opcode() == Op_NeverBranch) { - Node* head = in->in(0); - assert(head->is_Region(), "unexpected infinite loop graph shape"); - - Node* phi_mem = NULL; - for (DUIterator_Fast jmax, j = head->fast_outs(jmax); j < jmax; j++) { - Node* u = head->fast_out(j); - if (u->is_Phi() && u->bottom_type() == Type::MEMORY) { - if (_phase->C->get_alias_index(u->adr_type()) == _alias) { - assert(phi_mem == NULL || phi_mem->adr_type() == TypePtr::BOTTOM, ""); - phi_mem = u; - } else if (u->adr_type() == TypePtr::BOTTOM) { - assert(phi_mem == NULL || _phase->C->get_alias_index(phi_mem->adr_type()) == _alias, ""); - if (phi_mem == NULL) { - phi_mem = u; - } - } - } - } - if (phi_mem == NULL) { - for (uint j = 1; j < head->req(); j++) { - Node* tail = head->in(j); - if (!_phase->is_dominator(head, tail)) { - continue; - } - Node* c = tail; - while (c != head) { - if (c->is_SafePoint() && !c->is_CallLeaf()) { - Node* m =c->in(TypeFunc::Memory); - if (m->is_MergeMem()) { - m = m->as_MergeMem()->memory_at(_alias); - } - assert(mem == NULL || mem == m, "several memory states"); - mem = m; - } - c = _phase->idom(c); - } - assert(mem != NULL, "should have found safepoint"); - } - assert(mem != NULL, "should have found safepoint"); - } else { - mem = phi_mem; - } + mem = collect_memory_for_infinite_loop(in); } } } else { @@ -2435,6 +2394,67 @@ void MemoryGraphFixer::collect_memory_nodes() { } } +Node* MemoryGraphFixer::collect_memory_for_infinite_loop(const Node* in) { + Node* mem = NULL; + Node* head = in->in(0); + assert(head->is_Region(), "unexpected infinite loop graph shape"); + + Node* phi_mem = NULL; + for (DUIterator_Fast jmax, j = head->fast_outs(jmax); j < jmax; j++) { + Node* u = head->fast_out(j); + if (u->is_Phi() && u->bottom_type() == Type::MEMORY) { + if (_phase->C->get_alias_index(u->adr_type()) == _alias) { + assert(phi_mem == NULL || phi_mem->adr_type() == TypePtr::BOTTOM, ""); + phi_mem = u; + } else if (u->adr_type() == TypePtr::BOTTOM) { + assert(phi_mem == NULL || _phase->C->get_alias_index(phi_mem->adr_type()) == _alias, ""); + if (phi_mem == NULL) { + phi_mem = u; + } + } + } + } + if (phi_mem == NULL) { + ResourceMark rm; + Node_Stack stack(0); + stack.push(head, 1); + do { + Node* n = stack.node(); + uint i = stack.index(); + if (i >= n->req()) { + stack.pop(); + } else { + stack.set_index(i + 1); + Node* c = n->in(i); + assert(c != head, "should have found a safepoint on the way"); + if (stack.size() != 1 || _phase->is_dominator(head, c)) { + for (;;) { + if (c->is_Region()) { + stack.push(c, 1); + break; + } else if (c->is_SafePoint() && !c->is_CallLeaf()) { + Node* m = c->in(TypeFunc::Memory); + if (m->is_MergeMem()) { + m = m->as_MergeMem()->memory_at(_alias); + } + assert(mem == NULL || mem == m, "several memory states"); + mem = m; + break; + } else { + assert(c != c->in(0), ""); + c = c->in(0); + } + } + } + } + } while (stack.size() > 0); + assert(mem != NULL, "should have found safepoint"); + } else { + mem = phi_mem; + } + return mem; +} + Node* MemoryGraphFixer::get_ctrl(Node* n) const { Node* c = _phase->get_ctrl(n); if (n->is_Proj() && n->in(0) != NULL && n->in(0)->is_Call()) { diff --git a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp index 1890c40ad58..6632e42b36f 100644 --- a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp @@ -131,6 +131,8 @@ class MemoryGraphFixer : public ResourceObj { Node* find_mem(Node* ctrl, Node* n) const; void fix_mem(Node* ctrl, Node* region, Node* mem, Node* mem_for_ctrl, Node* mem_phi, Unique_Node_List& uses); int alias() const { return _alias; } + + Node* collect_memory_for_infinite_loop(const Node* in); }; class ShenandoahCompareAndSwapPNode : public CompareAndSwapPNode { diff --git a/src/hotspot/share/opto/cfgnode.cpp b/src/hotspot/share/opto/cfgnode.cpp index e44842e3fb6..b1b32dee3de 100644 --- a/src/hotspot/share/opto/cfgnode.cpp +++ b/src/hotspot/share/opto/cfgnode.cpp @@ -2717,7 +2717,7 @@ const Type* NeverBranchNode::Value(PhaseGVN* phase) const { //------------------------------Ideal------------------------------------------ // Check for no longer being part of a loop Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) { - if (can_reshape && !in(0)->is_Loop()) { + if (can_reshape && !in(0)->is_Region()) { // Dead code elimination can sometimes delete this projection so // if it's not there, there's nothing to do. Node* fallthru = proj_out_or_null(0); diff --git a/test/hotspot/jtreg/compiler/loopopts/TestInfiniteLoopCCP.java b/test/hotspot/jtreg/compiler/loopopts/TestInfiniteLoopCCP.java new file mode 100644 index 00000000000..770621e21f6 --- /dev/null +++ b/test/hotspot/jtreg/compiler/loopopts/TestInfiniteLoopCCP.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. 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 8271340 + * @summary Crash PhaseIdealLoop::clone_outer_loop + * @library /test/lib + * + * @run main/othervm TestInfiniteLoopCCP + * + */ + +import jdk.test.lib.Utils; + +public class TestInfiniteLoopCCP { + + public boolean m3 (long a_lo0, short a_sh1){ + long loa6[][] = new long[560][1792]; + + loa6[-128][0] = 1345348328L; + + return false; + } + + public void mainTest (String[] args){ + short sh16 = (short)-32; + for (int i17 = 0; i17 < 29; i17++) { + if (i17 == 8) { + i17 = 129; + for (int i18 = 0; i18 < 27; i18++) { + i18 = 16; + } + } + } + + try { + m3(4130511410L, (short)(sh16 % sh16)); + } catch (ArithmeticException a_e) {} + } + + + public static void main(String[] args) throws Exception{ + Thread thread = new Thread() { + public void run() { + TestInfiniteLoopCCP instance = new TestInfiniteLoopCCP(); + for (int i = 0; i < 100; ++i) { + instance.mainTest(args); + } + } + }; + // Give thread some time to trigger compilation + thread.setDaemon(true); + thread.start(); + Thread.sleep(Utils.adjustTimeout(4000)); + } +} From 5761056e3a71fc8d22075431a2933887fee29dfc Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:18:27 +0000 Subject: [PATCH 089/253] 8270886: Crash in PhaseIdealLoop::verify_strip_mined_scheduling Backport-of: 6afcf5f5a243be10e2ec61229819c298ccce3267 --- src/hotspot/share/opto/compile.cpp | 8 +- .../c2/TestRenumberLiveNodesInfiniteLoop.java | 167 ++++++++++++++++++ 2 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/c2/TestRenumberLiveNodesInfiniteLoop.java diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index 09191f4563a..b40ebf6a746 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -2108,10 +2108,6 @@ void Compile::Optimize() { if (failing()) return; } - // Now that all inlining is over, cut edge from root to loop - // safepoints - remove_root_to_sfpts_edges(igvn); - // Remove the speculative part of types and clean up the graph from // the extra CastPP nodes whose only purpose is to carry them. Do // that early so that optimizations are not disrupted by the extra @@ -2148,6 +2144,10 @@ void Compile::Optimize() { set_for_igvn(save_for_igvn); } + // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop + // safepoints + remove_root_to_sfpts_edges(igvn); + // Perform escape analysis if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) { if (has_loops()) { diff --git a/test/hotspot/jtreg/compiler/c2/TestRenumberLiveNodesInfiniteLoop.java b/test/hotspot/jtreg/compiler/c2/TestRenumberLiveNodesInfiniteLoop.java new file mode 100644 index 00000000000..8b04eecb514 --- /dev/null +++ b/test/hotspot/jtreg/compiler/c2/TestRenumberLiveNodesInfiniteLoop.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. 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 8270886 + * @library /test/lib + * @summary Crash in PhaseIdealLoop::verify_strip_mined_scheduling + * + * @run main TestRenumberLiveNodesInfiniteLoop + * + */ + +import jdk.test.lib.Utils; + +public class TestRenumberLiveNodesInfiniteLoop { + public long m2 (double a_do0, byte a_by1){ + double do3 = -2074076350.2364243247; + int in4 = 129; + do3 = do3; + return -3480877547L; + } + + public void mainTest (String[] args){ + byte by14 = (byte)9; + long lo15 = 1502432357L; + short sha16[] = new short[473]; + + for (short sh17 : sha16) { + try { + sha16[2] = (short)23; + for (int i18 = 0; i18 < 17; i18++) { + sha16[i18] = sh17; + m2(1120187380.53448312, by14); + } + } catch (ArithmeticException a_e) {} + sha16[1] = sh17; + sha16[2] = sh17; + } + m2(825278101.1289499682, by14); + by14 = (byte)(by14 - by14); + for (int i19 = 0; i19 < 20; i19++) { + if (i19 == i19) { + sha16[i19] *= (short)-24; + i19 = i19; + } + for (short sh20 : sha16) { + for (int i21 = 0; i21 < 83; i21++) { + sha16[0] -= (short)-46; + i19 += 127; + } + for (int i22 = 0; i22 < 89; i22++) { + i22 = 8; + } + } + ; + } + ; + ; + for (int i23 = 0; i23 < 33; i23++) { + sha16[i23] = (short)46; + for (int i24 = 0; i24 < 94; i24++) { + sha16[2] = (short)-3; + } + } + sha16[0] = (short)14; + for (int i25 = 0; i25 < 35; i25++) { + for (short sh26 : sha16) { + if (i25 > 5) { + m2(1121925038.1118634045, by14); + } + } + m2(-1914069692.1375346593, (byte)16); + } + ; + for (int i27 = 0; i27 < 10; i27++) { + for (int i28 = 0; i28 < 44; i28++) { + if (i28 == i28) { + break; + } + sha16[i27] = (short)62; + for (int i29 = 0; i29 < 95; i29++) { + sha16[2] = (short)50; + sha16[2] = (short)30; + m2(1250986231.1599386644, by14); + } + } + sha16[2] = (short)28; + m2(672818118.3111172289, (byte)0); + } + sha16[0] = (short)19; + sha16[5] = (short)((short)-11 * (short)60); + for (int i30 = 0; i30 < 38; i30++) { + sha16[i30] = (short)43; + sha16[i30] = (short)49; + try { + for (short sh31 : sha16) { + m2(720645491.3777510146, by14); + sha16[i30] -= (short)-44; + sha16[i30] = (short)58; + } + for (short sh32 : sha16) { + m2(-3548500610.1703635180 % -2696439975.1456774235 % 2299457624.855537726, by14); + sha16[2] = (short)12; + sha16[i30] = (short)8; + } + i30 = 4; + } catch (ArithmeticException a_e) {} + } + for (int i33 = 0; i33 < 31; i33++) { + for (int i34 = 0; i34 < i33; i34++) { + try { + sha16[i34] /= (short)-25; + i34 = -65536; + i33 = i33; + } catch (ArithmeticException a_e) {} + for (short sh35 : sha16) { + sha16[i34] += sha16[i33]; + sha16[i34] = sh35; + sha16[i33] = (short)15; + } + for (short sh36 : sha16) { + m2(3573835015.2140351447, by14); + m2(2984270380.1830267895, by14); + } + } + sha16[i33] = (short)57; + m2(-3061961160.3118322232, (byte)-4); + } + sha16[256] -= (short)50; + } + + public static void main(String[] args) throws Exception{ + Thread thread = new Thread() { + public void run() { + TestRenumberLiveNodesInfiniteLoop instance = new TestRenumberLiveNodesInfiniteLoop(); + for (int i = 0; i < 100; ++i) { + instance.mainTest(args); + } + } + }; + // Give thread some time to trigger compilation + thread.setDaemon(true); + thread.start(); + Thread.sleep(Utils.adjustTimeout(4000)); + } +} From 6141fccd1964504471c3e7be1d6b4f8ddd9d20a5 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:19:25 +0000 Subject: [PATCH 090/253] 8271600: C2: CheckCastPP which should closely follow Allocate is sunk of a loop Backport-of: 2ff4c01d42f1afcc53abd48e074356fb4a700754 --- src/hotspot/share/opto/loopopts.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hotspot/share/opto/loopopts.cpp b/src/hotspot/share/opto/loopopts.cpp index d86a5db0718..5df0c71f53d 100644 --- a/src/hotspot/share/opto/loopopts.cpp +++ b/src/hotspot/share/opto/loopopts.cpp @@ -1435,12 +1435,16 @@ void PhaseIdealLoop::split_if_with_blocks_post(Node *n) { // like various versions of induction variable+offset. Clone the // computation per usage to allow it to sink out of the loop. void PhaseIdealLoop::try_sink_out_of_loop(Node* n) { + bool is_raw_to_oop_cast = n->is_ConstraintCast() && + n->in(1)->bottom_type()->isa_rawptr() && + !n->bottom_type()->isa_rawptr(); if (has_ctrl(n) && !n->is_Phi() && !n->is_Bool() && !n->is_Proj() && !n->is_MergeMem() && !n->is_CMove() && + !is_raw_to_oop_cast && // don't extend live ranges of raw oops n->Opcode() != Op_Opaque4) { Node *n_ctrl = get_ctrl(n); IdealLoopTree *n_loop = get_loop(n_ctrl); From 7298db5b38aab5fb5c21cf9ec4aa842f25954f0a Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:21:50 +0000 Subject: [PATCH 091/253] 8223923: C2: Missing interference with mismatched unsafe accesses Backport-of: 86add21a85ec57de00aecb0a18bc99567a91d0d8 --- src/hotspot/share/opto/memnode.cpp | 17 +++-- .../unsafe/MismatchedUnsafeAccessTest.java | 73 +++++++++++++++++++ 2 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/unsafe/MismatchedUnsafeAccessTest.java diff --git a/src/hotspot/share/opto/memnode.cpp b/src/hotspot/share/opto/memnode.cpp index 03625081218..bde3a0fa2eb 100644 --- a/src/hotspot/share/opto/memnode.cpp +++ b/src/hotspot/share/opto/memnode.cpp @@ -596,7 +596,7 @@ Node* LoadNode::find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, N ArrayCopyNode* MemNode::find_array_copy_clone(PhaseTransform* phase, Node* ld_alloc, Node* mem) const { if (mem->is_Proj() && mem->in(0) != NULL && (mem->in(0)->Opcode() == Op_MemBarStoreStore || - mem->in(0)->Opcode() == Op_MemBarCPUOrder)) { + mem->in(0)->Opcode() == Op_MemBarCPUOrder)) { if (ld_alloc != NULL) { // Check if there is an array copy for a clone Node* mb = mem->in(0); @@ -1061,7 +1061,6 @@ Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const { // This is more general than load from boxing objects. if (skip_through_membars(atp, tp, phase->C->eliminate_boxing())) { uint alias_idx = atp->index(); - bool final = !atp->is_rewritable(); Node* result = NULL; Node* current = st; // Skip through chains of MemBarNodes checking the MergeMems for @@ -1069,17 +1068,19 @@ Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const { // kind of node is encountered. Loads from final memory can skip // through any kind of MemBar but normal loads shouldn't skip // through MemBarAcquire since the could allow them to move out of - // a synchronized region. + // a synchronized region. It is not safe to step over MemBarCPUOrder, + // because alias info above them may be inaccurate (e.g., due to + // mixed/mismatched unsafe accesses). + bool is_final_mem = !atp->is_rewritable(); while (current->is_Proj()) { int opc = current->in(0)->Opcode(); - if ((final && (opc == Op_MemBarAcquire || - opc == Op_MemBarAcquireLock || - opc == Op_LoadFence)) || + if ((is_final_mem && (opc == Op_MemBarAcquire || + opc == Op_MemBarAcquireLock || + opc == Op_LoadFence)) || opc == Op_MemBarRelease || opc == Op_StoreFence || opc == Op_MemBarReleaseLock || - opc == Op_MemBarStoreStore || - opc == Op_MemBarCPUOrder) { + opc == Op_MemBarStoreStore) { Node* mem = current->in(0)->in(TypeFunc::Memory); if (mem->is_MergeMem()) { MergeMemNode* merge = mem->as_MergeMem(); diff --git a/test/hotspot/jtreg/compiler/unsafe/MismatchedUnsafeAccessTest.java b/test/hotspot/jtreg/compiler/unsafe/MismatchedUnsafeAccessTest.java new file mode 100644 index 00000000000..be07a3bfc8e --- /dev/null +++ b/test/hotspot/jtreg/compiler/unsafe/MismatchedUnsafeAccessTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021, 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 8223923 + * @modules java.base/jdk.internal.misc + * @run main/othervm -Xbatch compiler.unsafe.MismatchedUnsafeAccessTest + */ +package compiler.unsafe; + +import jdk.internal.misc.Unsafe; + +public class MismatchedUnsafeAccessTest { + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); + + public static class Test { + public int x = 0; + public int y = 0; + + public static final long offsetX; + public static final long offsetY; + + static { + try { + offsetX = UNSAFE.objectFieldOffset(Test.class.getField("x")); + offsetY = UNSAFE.objectFieldOffset(Test.class.getField("y")); + } catch (NoSuchFieldException e) { + throw new InternalError(e); + } + // Validate offsets + if (offsetX >= offsetY || offsetY - offsetX != 4) { + throw new InternalError("Wrong offsets: " + offsetX + " " + offsetY); + } + } + } + + public static int test(long l) { + Test a = new Test(); + UNSAFE.putLong(a, Test.offsetX, l); // mismatched access; interferes with subsequent load + return UNSAFE.getInt(a, Test.offsetY); + } + + public static void main(String[] args) { + for (int i = 0; i < 20_000; i++) { + int res = test(-1L); + if (res != -1) { + throw new AssertionError("Wrong result: " + res); + } + } + System.out.println("TEST PASSED"); + } +} From 962f3937b658a8af919513b02a3c2c3570e80f40 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:23:40 +0000 Subject: [PATCH 092/253] 8244675: assert(IncrementalInline || (_late_inlines.length() == 0 && !has_mh_late_inlines())) Backport-of: 28ba78e64721529fd764a7c09a7142a96c245f05 --- src/hotspot/share/opto/callGenerator.cpp | 4 +- src/hotspot/share/opto/doCall.cpp | 2 +- .../compiler/vectorapi/TestNoInline.java | 49 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/vectorapi/TestNoInline.java diff --git a/src/hotspot/share/opto/callGenerator.cpp b/src/hotspot/share/opto/callGenerator.cpp index 42aed2e57fb..a0746c763b2 100644 --- a/src/hotspot/share/opto/callGenerator.cpp +++ b/src/hotspot/share/opto/callGenerator.cpp @@ -459,7 +459,9 @@ class LateInlineVirtualCallGenerator : public VirtualCallGenerator { public: LateInlineVirtualCallGenerator(ciMethod* method, int vtable_index, float prof_factor) : VirtualCallGenerator(method, vtable_index, true /*separate_io_projs*/), - _unique_id(0), _inline_cg(NULL), _callee(NULL), _is_pure_call(false), _prof_factor(prof_factor) {} + _unique_id(0), _inline_cg(NULL), _callee(NULL), _is_pure_call(false), _prof_factor(prof_factor) { + assert(IncrementalInlineVirtual, "required"); + } virtual bool is_late_inline() const { return true; } diff --git a/src/hotspot/share/opto/doCall.cpp b/src/hotspot/share/opto/doCall.cpp index 4a371eb7064..c9e5a80005e 100644 --- a/src/hotspot/share/opto/doCall.cpp +++ b/src/hotspot/share/opto/doCall.cpp @@ -136,7 +136,7 @@ CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool if (cg->does_virtual_dispatch()) { cg_intrinsic = cg; cg = NULL; - } else if (should_delay_vector_inlining(callee, jvms)) { + } else if (IncrementalInline && should_delay_vector_inlining(callee, jvms)) { return CallGenerator::for_late_inline(callee, cg); } else { return cg; diff --git a/test/hotspot/jtreg/compiler/vectorapi/TestNoInline.java b/test/hotspot/jtreg/compiler/vectorapi/TestNoInline.java new file mode 100644 index 00000000000..f200323a92e --- /dev/null +++ b/test/hotspot/jtreg/compiler/vectorapi/TestNoInline.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021, 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. + */ + +package compiler.vectorapi; + +import jdk.incubator.vector.IntVector; +import jdk.incubator.vector.VectorSpecies; + +/* + * @test + * @bug 8244675 + * @modules jdk.incubator.vector + * + * @run main/othervm -Xbatch -XX:-Inline compiler.vectorapi.TestNoInline + * @run main/othervm -Xbatch -XX:-IncrementalInline compiler.vectorapi.TestNoInline + */ +public class TestNoInline { + static final VectorSpecies I_SPECIES = IntVector.SPECIES_PREFERRED; + + static IntVector test(int[] arr) { + return IntVector.fromArray(I_SPECIES, arr, 0); + } + public static void main(String[] args) { + int[] arr = new int[64]; + for (int i = 0; i < 20_000; i++) { + test(arr); + } + } +} From fd81865b96c267390fada2e2546227a4241a58a6 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:25:01 +0000 Subject: [PATCH 093/253] 8273359: CI: ciInstanceKlass::get_canonical_holder() doesn't respect instance size Backport-of: f7e9f56e235dc50daae0a85c9790d5b04c9c60f0 --- src/hotspot/share/c1/c1_LIRGenerator.cpp | 2 +- src/hotspot/share/ci/ciInstanceKlass.cpp | 8 ++- src/hotspot/share/ci/ciInstanceKlass.hpp | 3 + src/hotspot/share/opto/compile.cpp | 7 ++- .../compiler/unsafe/AlignmentGapAccess.java | 55 +++++++++++++++++++ 5 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/unsafe/AlignmentGapAccess.java diff --git a/src/hotspot/share/c1/c1_LIRGenerator.cpp b/src/hotspot/share/c1/c1_LIRGenerator.cpp index e3e6dc786b9..5404fe27681 100644 --- a/src/hotspot/share/c1/c1_LIRGenerator.cpp +++ b/src/hotspot/share/c1/c1_LIRGenerator.cpp @@ -663,7 +663,7 @@ void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, bool is_unr assert(klass->is_loaded(), "must be loaded"); // allocate space for instance - assert(klass->size_helper() >= 0, "illegal instance size"); + assert(klass->size_helper() > 0, "illegal instance size"); const int instance_size = align_object_size(klass->size_helper()); __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4, oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path); diff --git a/src/hotspot/share/ci/ciInstanceKlass.cpp b/src/hotspot/share/ci/ciInstanceKlass.cpp index a9fa3855607..31d1d92c8c9 100644 --- a/src/hotspot/share/ci/ciInstanceKlass.cpp +++ b/src/hotspot/share/ci/ciInstanceKlass.cpp @@ -205,12 +205,12 @@ ciConstantPoolCache* ciInstanceKlass::field_cache() { // ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) { #ifdef ASSERT - if (!(offset >= 0 && offset < layout_helper())) { + if (!(offset >= 0 && offset < layout_helper_size_in_bytes())) { tty->print("*** get_canonical_holder(%d) on ", offset); this->print(); tty->print_cr(" ***"); }; - assert(offset >= 0 && offset < layout_helper(), "offset must be tame"); + assert(offset >= 0 && offset < layout_helper_size_in_bytes(), "offset must be tame"); #endif if (offset < instanceOopDesc::base_offset_in_bytes()) { @@ -227,7 +227,9 @@ ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) { for (;;) { assert(self->is_loaded(), "must be loaded to have size"); ciInstanceKlass* super = self->super(); - if (super == NULL || super->nof_nonstatic_fields() == 0) { + if (super == NULL || + super->nof_nonstatic_fields() == 0 || + super->layout_helper_size_in_bytes() <= offset) { return self; } else { self = super; // return super->get_canonical_holder(offset) diff --git a/src/hotspot/share/ci/ciInstanceKlass.hpp b/src/hotspot/share/ci/ciInstanceKlass.hpp index 1e4a0a9ae6c..28652a3c78e 100644 --- a/src/hotspot/share/ci/ciInstanceKlass.hpp +++ b/src/hotspot/share/ci/ciInstanceKlass.hpp @@ -165,6 +165,9 @@ class ciInstanceKlass : public ciKlass { return compute_shared_has_subklass(); } + jint layout_helper_size_in_bytes() { + return Klass::layout_helper_size_in_bytes(layout_helper()); + } jint size_helper() { return (Klass::layout_helper_size_in_bytes(layout_helper()) >> LogHeapWordSize); diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index b40ebf6a746..47fcbf62a0d 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -1352,7 +1352,7 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const { ciInstanceKlass *k = to->klass()->as_instance_klass(); if( ptr == TypePtr::Constant ) { if (to->klass() != ciEnv::current()->Class_klass() || - offset < k->size_helper() * wordSize) { + offset < k->layout_helper_size_in_bytes()) { // No constant oop pointers (such as Strings); they alias with // unknown strings. assert(!is_known_inst, "not scalarizable allocation"); @@ -1376,7 +1376,7 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const { if (!is_known_inst) { // Do it only for non-instance types tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset); } - } else if (offset < 0 || offset >= k->size_helper() * wordSize) { + } else if (offset < 0 || offset >= k->layout_helper_size_in_bytes()) { // Static fields are in the space above the normal instance // fields in the java.lang.Class instance. if (to->klass() != ciEnv::current()->Class_klass()) { @@ -1386,6 +1386,7 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const { } } else { ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset); + assert(offset < canonical_holder->layout_helper_size_in_bytes(), ""); if (!k->equals(canonical_holder) || tj->offset() != offset) { if( is_known_inst ) { tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id()); @@ -1658,7 +1659,7 @@ Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_cr ciField* field; if (tinst->const_oop() != NULL && tinst->klass() == ciEnv::current()->Class_klass() && - tinst->offset() >= (tinst->klass()->as_instance_klass()->size_helper() * wordSize)) { + tinst->offset() >= (tinst->klass()->as_instance_klass()->layout_helper_size_in_bytes())) { // static field ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass(); field = k->get_field_by_offset(tinst->offset(), true); diff --git a/test/hotspot/jtreg/compiler/unsafe/AlignmentGapAccess.java b/test/hotspot/jtreg/compiler/unsafe/AlignmentGapAccess.java new file mode 100644 index 00000000000..ac3c4b0278a --- /dev/null +++ b/test/hotspot/jtreg/compiler/unsafe/AlignmentGapAccess.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021, 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 8273359 + * + * @modules java.base/jdk.internal.misc:+open + * @run main/othervm -Xbatch compiler.unsafe.AlignmentGapAccess + */ + +package compiler.unsafe; + +import jdk.internal.misc.Unsafe; + +public class AlignmentGapAccess { + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); + + static class A { int fa; } + static class B extends A { byte fb; } + + static final long FA_OFFSET = UNSAFE.objectFieldOffset(A.class, "fa"); + static final long FB_OFFSET = UNSAFE.objectFieldOffset(B.class, "fb"); + + static int test(B obj) { + return UNSAFE.getInt(obj, FB_OFFSET + 1); + } + + public static void main(String[] args) { + for (int i = 0; i < 20_000; i++) { + test(new B()); + } + System.out.println("TEST PASSED"); + } +} From f4a0b13d8609f3461faf0ec20eaaaf96a4caecd3 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 06:26:06 +0000 Subject: [PATCH 094/253] 8271341: Opcode() != Op_If && Opcode() != Op_RangeCheck) || outcnt() == 2 assert failure with Test7179138_1.java Backport-of: 99fb12c798ad24cc4a671a666930ba42c3cd10c9 --- src/hotspot/share/opto/stringopts.cpp | 15 +++++++++++++++ test/hotspot/jtreg/compiler/c2/Test7179138_1.java | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/opto/stringopts.cpp b/src/hotspot/share/opto/stringopts.cpp index 6392cd8ca02..809a446f52b 100644 --- a/src/hotspot/share/opto/stringopts.cpp +++ b/src/hotspot/share/opto/stringopts.cpp @@ -277,6 +277,20 @@ void StringConcat::eliminate_unneeded_control() { C->gvn_replace_by(n, n->in(0)->in(0)); // get rid of the other projection C->gvn_replace_by(n->in(0)->as_If()->proj_out(false), C->top()); + } else if (n->is_Region()) { + Node* iff = n->in(1)->in(0); + assert(n->req() == 3 && n->in(2)->in(0) == iff, "not a diamond"); + assert(iff->is_If(), "no if for the diamond"); + Node* bol = iff->in(1); + assert(bol->is_Bool(), "unexpected if shape"); + Node* cmp = bol->in(1); + assert(cmp->is_Cmp(), "unexpected if shape"); + if (cmp->in(1)->is_top() || cmp->in(2)->is_top()) { + // This region should lose its Phis and be optimized out by igvn but there's a chance the if folds to top first + // which then causes a reachable part of the graph to become dead. + Compile* C = _stringopts->C; + C->gvn_replace_by(n, iff->in(0)); + } } } } @@ -1003,6 +1017,7 @@ bool StringConcat::validate_control_flow() { // The IGVN will make this simple diamond go away when it // transforms the Region. Make sure it sees it. Compile::current()->record_for_igvn(ptr); + _control.push(ptr); ptr = ptr->in(1)->in(0)->in(0); continue; } diff --git a/test/hotspot/jtreg/compiler/c2/Test7179138_1.java b/test/hotspot/jtreg/compiler/c2/Test7179138_1.java index 6cdbed4e5bd..1df3fd3691b 100644 --- a/test/hotspot/jtreg/compiler/c2/Test7179138_1.java +++ b/test/hotspot/jtreg/compiler/c2/Test7179138_1.java @@ -23,11 +23,13 @@ /* * @test - * @bug 7179138 + * @bug 7179138 8271341 * @summary Incorrect result with String concatenation optimization * * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation * compiler.c2.Test7179138_1 + * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation + * -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -XX:RepeatCompilation=100 compiler.c2.Test7179138_1 * * @author Skip Balk */ @@ -67,4 +69,3 @@ public static void main(String[] args) throws Exception { } } } - From c4b3d62c7fbf9567404be28eaf9635bad435e06b Mon Sep 17 00:00:00 2001 From: Yoshiki Sato Date: Wed, 29 Sep 2021 13:04:44 +0000 Subject: [PATCH 095/253] 8273924: ArrayIndexOutOfBoundsException thrown in java.util.JapaneseImperialCalendar.add() Backport-of: d39aad92308fbc28bd2de164e331062ebf62da85 --- .../sun/util/calendar/BaseCalendar.java | 6 +++++- .../CalendarTestScripts/JapaneseTests.java | 2 +- .../japanese/japanese_add.cts | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java b/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java index 3c07431274c..8a7ffc6344d 100644 --- a/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java +++ b/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2021, 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 @@ -277,6 +277,10 @@ void normalizeMonth(CalendarDate date) { long xm = 1L - month; year -= (int)((xm / 12) + 1); month = 13 - (xm % 12); + if (month == 13) { + year++; + month = 1; + } bdate.setNormalizedYear(year); bdate.setMonth((int) month); } else if (month > DECEMBER) { diff --git a/test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseTests.java b/test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseTests.java index 403e483affa..4f21b33baaa 100644 --- a/test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseTests.java +++ b/test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseTests.java @@ -24,7 +24,7 @@ /* * @test * @summary tests Japanese Calendar. - * @bug 4609228 8187649 + * @bug 4609228 8187649 8273924 * @modules java.base/sun.util * java.base/sun.util.calendar * @compile diff --git a/test/jdk/java/util/Calendar/CalendarTestScripts/japanese/japanese_add.cts b/test/jdk/java/util/Calendar/CalendarTestScripts/japanese/japanese_add.cts index b698b785815..c0f6be479a1 100644 --- a/test/jdk/java/util/Calendar/CalendarTestScripts/japanese/japanese_add.cts +++ b/test/jdk/java/util/Calendar/CalendarTestScripts/japanese/japanese_add.cts @@ -354,6 +354,26 @@ test add MONTH # check date Heisei $max Aug 16 # check timeofday 23 59 59 999 +# JDK-8273924 + set date Reiwa 2 Mar 1 + add month -10 + check date Reiwa 1 May 1 + set date Reiwa 2 Mar 1 + add month -11 + check date Heisei 31 Apr 1 + set date Reiwa 2 Mar 1 + add month -12 + check date Heisei 31 Mar 1 + set date Reiwa 2 Mar 1 + add month -13 + check date Heisei 31 Feb 1 + set date Reiwa 2 Mar 1 + add month -14 + check date Heisei 31 Jan 1 + set date Reiwa 2 Mar 1 + add month -15 + check date Heisei 30 Dec 1 + test add WEEK_OF_YEAR use jcal clear all From 84f6cb4ae418af42e0c8d38ef3070411ba0de18a Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 29 Sep 2021 13:08:57 +0000 Subject: [PATCH 096/253] 8273498: compiler/c2/Test7179138_1.java timed out Reviewed-by: chagedorn Backport-of: c81690d7166c32caff6ef3a55fe9b157049e2b56 --- test/hotspot/jtreg/compiler/c2/Test7179138_1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/c2/Test7179138_1.java b/test/hotspot/jtreg/compiler/c2/Test7179138_1.java index 1df3fd3691b..a1241369bf4 100644 --- a/test/hotspot/jtreg/compiler/c2/Test7179138_1.java +++ b/test/hotspot/jtreg/compiler/c2/Test7179138_1.java @@ -29,7 +29,7 @@ * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation * compiler.c2.Test7179138_1 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation - * -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -XX:RepeatCompilation=100 compiler.c2.Test7179138_1 + * -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN compiler.c2.Test7179138_1 * * @author Skip Balk */ From 592542fb28e26479ac591e9c08f83bd4a3988070 Mon Sep 17 00:00:00 2001 From: Ravi Reddy Date: Wed, 29 Sep 2021 14:35:52 +0000 Subject: [PATCH 097/253] 8270492: Better resolution of URIs Backport-of: ceda336a2ddea62e2ff8df653f54e08d45fc197a --- .../internal/xsltc/dom/LoadDocument.java | 5 ++- .../xsltc/runtime/AbstractTranslet.java | 19 +++++++++++- .../internal/xsltc/trax/TransformerImpl.java | 31 +++++++++++++++++-- .../xml/internal/utils/SystemIDResolver.java | 7 +++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/LoadDocument.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/LoadDocument.java index bc7194411f0..39084c87f0b 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/LoadDocument.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/LoadDocument.java @@ -39,7 +39,7 @@ /** * @author Morten Jorgensen - * @LastModified: May 2021 + * @LastModified: Sept 2021 */ public final class LoadDocument { @@ -190,6 +190,9 @@ private static DTMAxisIterator document(String uri, String base, if (cache != null) { newdom = cache.retrieveDocument(base, originalUri, translet); if (newdom == null) { + if (translet.getAccessError() != null) { + throw new Exception(translet.getAccessError()); + } final Exception e = new FileNotFoundException(originalUri); throw new TransletException(e); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java index 58b8f433e8e..1612fd61923 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java @@ -54,7 +54,7 @@ * @author Morten Jorgensen * @author G. Todd Miller * @author John Howard, JohnH@schemasoft.com - * @LastModified: May 2021 + * @LastModified: Sept 2021 */ public abstract class AbstractTranslet implements Translet { @@ -116,6 +116,9 @@ public abstract class AbstractTranslet implements Translet { */ private String _accessExternalStylesheet = JdkConstants.EXTERNAL_ACCESS_DEFAULT; + // The error message when access to exteranl resources is rejected + private String _accessErr = null; + /************************************************************************ * Debugging ************************************************************************/ @@ -786,6 +789,20 @@ public void setAllowedProtocols(String protocols) { _accessExternalStylesheet = protocols; } + /** + * Returns the access error. + */ + public String getAccessError() { + return _accessErr; + } + + /** + * Sets the access error. + */ + public void setAccessError(String accessErr) { + this._accessErr = accessErr; + } + /************************************************************************ * DOMImplementation caching for basis library ************************************************************************/ diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java index 9e266eec28f..b58eabc54d5 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java @@ -101,7 +101,7 @@ * @author Morten Jorgensen * @author G. Todd Miller * @author Santiago Pericas-Geertsen - * @LastModified: June 2021 + * @LastModified: Sept 2021 */ public final class TransformerImpl extends Transformer implements DOMCache @@ -1351,8 +1351,33 @@ public DOM retrieveDocument(String baseURI, String href, Translet translet) { } if (resolvedSource == null) { - StreamSource streamSource = new StreamSource( - SystemIDResolver.getAbsoluteURI(href, baseURI)); + /** + * Uses the translet to carry over error msg. + * Performs the access check without any interface changes + * (e.g. Translet and DOMCache). + */ + @SuppressWarnings("unchecked") //AbstractTranslet is the sole impl. + AbstractTranslet t = (AbstractTranslet)translet; + String systemId = SystemIDResolver.getAbsoluteURI(href, baseURI); + String errMsg = null; + try { + String accessError = SecuritySupport.checkAccess(systemId, + t.getAllowedProtocols(), + JdkConstants.ACCESS_EXTERNAL_ALL); + if (accessError != null) { + ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR, + SecuritySupport.sanitizePath(href), accessError); + errMsg = msg.toString(); + } + } catch (IOException ioe) { + errMsg = ioe.getMessage(); + } + if (errMsg != null) { + t.setAccessError(errMsg); + return null; + } + + StreamSource streamSource = new StreamSource(systemId); return getDOM(streamSource) ; } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/SystemIDResolver.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/SystemIDResolver.java index de383ca3e9d..caf2a4b1ba7 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/SystemIDResolver.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/SystemIDResolver.java @@ -1,6 +1,5 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -35,6 +34,8 @@ * fact that it's declared to throw TransformerException. Please * see code comments for details on how resolution is performed.

* @xsl.usage internal + * + * @LastModified: Sept 2021 */ public class SystemIDResolver { @@ -275,7 +276,7 @@ public static String getAbsoluteURI(String systemId) public static String getAbsoluteURI(String urlString, String base) throws TransformerException { - if (base == null) + if (base == null || base.length() == 0) return getAbsoluteURI(urlString); String absoluteBase = getAbsoluteURI(base); From a7028380c81f8b20e44b6c647a0d8996c2f59a52 Mon Sep 17 00:00:00 2001 From: Rajat Mahajan Date: Wed, 29 Sep 2021 17:35:19 +0000 Subject: [PATCH 098/253] 8270116: Expand ButtonGroupLayoutTraversalTest.java to run in all LaFs, including Aqua on macOS Backport-of: cb368802815c465f8eef7aa930d6cbb6540d0fa8 --- .../ButtonGroupLayoutTraversalTest.java | 156 ++++++++++-------- 1 file changed, 86 insertions(+), 70 deletions(-) diff --git a/test/jdk/java/awt/Focus/FocusTraversalPolicy/ButtonGroupLayoutTraversal/ButtonGroupLayoutTraversalTest.java b/test/jdk/java/awt/Focus/FocusTraversalPolicy/ButtonGroupLayoutTraversal/ButtonGroupLayoutTraversalTest.java index 40c2df3be04..e7ddad6576f 100644 --- a/test/jdk/java/awt/Focus/FocusTraversalPolicy/ButtonGroupLayoutTraversal/ButtonGroupLayoutTraversalTest.java +++ b/test/jdk/java/awt/Focus/FocusTraversalPolicy/ButtonGroupLayoutTraversal/ButtonGroupLayoutTraversalTest.java @@ -37,6 +37,7 @@ import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; +import java.util.Arrays; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; @@ -50,98 +51,113 @@ public class ButtonGroupLayoutTraversalTest { - static int nx = 3; - static int ny = 3; + private static final int NX = 3; + private static final int NY = 3; + + private static final int[] focusCnt = new int[NX * NY]; - static int focusCnt[] = new int[nx * ny]; private static JFrame window; + private static Robot robot; public static void main(String[] args) throws Exception { + robot = new Robot(); + robot.setAutoDelay(100); - try { - SwingUtilities.invokeAndWait(() -> changeLAF()); - SwingUtilities.invokeAndWait(() -> initLayout(nx, ny)); - Robot robot = new Robot(); - robot.setAutoDelay(100); - robot.waitForIdle(); - robot.delay(1000); - - for (int i = 0; i < nx * ny - nx * ny / 2 - 1; i++) { - robot.keyPress(KeyEvent.VK_RIGHT); - robot.keyRelease(KeyEvent.VK_RIGHT); - robot.waitForIdle(); + for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { + try { + SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); + SwingUtilities.invokeAndWait(() -> initLayout(NX, NY)); + test(); + } finally { + SwingUtilities.invokeAndWait(() -> { + if (window != null) { + window.dispose(); + } + window = null; + synchronized (focusCnt) { + Arrays.fill(focusCnt, 0); + } + }); } + } + } - for (int i = 0; i < nx * ny / 2; i++) { - robot.keyPress(KeyEvent.VK_TAB); - robot.keyRelease(KeyEvent.VK_TAB); - robot.waitForIdle(); - } - robot.delay(200); + private static void test() { + robot.waitForIdle(); + robot.delay(1000); + + for (int i = 0; i < NX * NY - NX * NY / 2 - 1; i++) { + robot.keyPress(KeyEvent.VK_RIGHT); + robot.keyRelease(KeyEvent.VK_RIGHT); + robot.waitForIdle(); + } + + for (int i = 0; i < NX * NY / 2; i++) { + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + robot.waitForIdle(); + } - for (int i = 0; i < nx * ny; i++) { + robot.delay(200); + + synchronized (focusCnt) { + for (int i = 0; i < NX * NY; i++) { if (focusCnt[i] < 1) { throw new RuntimeException("Component " + i - + " is not reachable in the forward focus cycle"); + + " is not reachable in the forward focus cycle"); } else if (focusCnt[i] > 1) { throw new RuntimeException("Component " + i - + " got focus more than once in the forward focus cycle"); + + " got focus more than once in the forward focus cycle"); } } + } - for (int i = 0; i < nx * ny / 2; i++) { - robot.keyPress(KeyEvent.VK_SHIFT); - robot.keyPress(KeyEvent.VK_TAB); - robot.keyRelease(KeyEvent.VK_TAB); - robot.keyRelease(KeyEvent.VK_SHIFT); - robot.waitForIdle(); - } - - for (int i = 0; i < nx * ny - nx * ny / 2 - 1; i++) { - robot.keyPress(KeyEvent.VK_LEFT); - robot.keyRelease(KeyEvent.VK_LEFT); - robot.waitForIdle(); - } - + for (int i = 0; i < NX * NY / 2; i++) { robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); robot.waitForIdle(); + } - robot.delay(200); + for (int i = 0; i < NX * NY - NX * NY / 2 - 1; i++) { + robot.keyPress(KeyEvent.VK_LEFT); + robot.keyRelease(KeyEvent.VK_LEFT); + robot.waitForIdle(); + } - for (int i = 0; i < nx * ny; i++) { + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.waitForIdle(); + + robot.delay(200); + + synchronized (focusCnt) { + for (int i = 0; i < NX * NY; i++) { if (focusCnt[i] < 2) { throw new RuntimeException("Component " + i - + " is not reachable in the backward focus cycle"); + + " is not reachable in the backward focus cycle"); } else if (focusCnt[i] > 2) { throw new RuntimeException("Component " + i - + " got focus more than once in the backward focus cycle"); + + " got focus more than once in the backward focus cycle"); } } - } finally { - SwingUtilities.invokeAndWait(() -> { - if (window != null) { - window.dispose(); - } - }); } + } - private static void changeLAF() { - String currentLAF = UIManager.getLookAndFeel().toString(); - currentLAF = currentLAF.toLowerCase(); - if (currentLAF.contains("aqua") || currentLAF.contains("nimbus")) { - try { - UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); - } catch (ClassNotFoundException - | IllegalAccessException - | InstantiationException - | UnsupportedLookAndFeelException ex) { - ex.printStackTrace(); - } + private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println(laf.getName()); + } catch (UnsupportedLookAndFeelException ignored){ + System.out.println("Unsupported LookAndFeel: " + laf.getClassName()); + } catch (ClassNotFoundException | InstantiationException | + IllegalAccessException e) { + throw new RuntimeException(e); } } @@ -168,16 +184,16 @@ public static void initLayout(int nx, int ny) { comp.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { - focusCnt[fi]++; - if (focusCnt[fi] == 1) { - ((JComponent) e.getSource()) - .setBackground(Color.yellow); - } else if (focusCnt[fi] == 2) { - ((JComponent) e.getSource()) - .setBackground(Color.green); - } else { - ((JComponent) e.getSource()) - .setBackground(Color.red); + synchronized (focusCnt) { + focusCnt[fi]++; + JComponent btn = (JComponent) e.getSource(); + if (focusCnt[fi] == 1) { + btn.setBackground(Color.yellow); + } else if (focusCnt[fi] == 2) { + btn.setBackground(Color.green); + } else { + btn.setBackground(Color.red); + } } } }); From d6d5a9a538bd5dc928ecf168d40ee270ffacf247 Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Wed, 29 Sep 2021 21:31:11 +0000 Subject: [PATCH 099/253] 8271170: Add unit test for what jpackage app launcher puts in the environment Backport-of: 44f137ff9c0229ab2d5eccd9ebaadf8db11f386d --- .../jpackage/apps/{image => }/Hello.java | 0 test/jdk/tools/jpackage/apps/PrintEnv.java | 54 +++++++++ .../tools/jpackage/apps/installer/Hello.java | 113 ------------------ .../helpers/jdk/jpackage/test/HelloApp.java | 22 ++-- .../jdk/jpackage/test/JavaAppDesc.java | 32 ++++- .../tools/jpackage/share/AddLauncherTest.java | 12 +- .../jpackage/share/AppLauncherEnvTest.java | 111 +++++++++++++++++ 7 files changed, 214 insertions(+), 130 deletions(-) rename test/jdk/tools/jpackage/apps/{image => }/Hello.java (100%) create mode 100644 test/jdk/tools/jpackage/apps/PrintEnv.java delete mode 100644 test/jdk/tools/jpackage/apps/installer/Hello.java create mode 100644 test/jdk/tools/jpackage/share/AppLauncherEnvTest.java diff --git a/test/jdk/tools/jpackage/apps/image/Hello.java b/test/jdk/tools/jpackage/apps/Hello.java similarity index 100% rename from test/jdk/tools/jpackage/apps/image/Hello.java rename to test/jdk/tools/jpackage/apps/Hello.java diff --git a/test/jdk/tools/jpackage/apps/PrintEnv.java b/test/jdk/tools/jpackage/apps/PrintEnv.java new file mode 100644 index 00000000000..251138b2388 --- /dev/null +++ b/test/jdk/tools/jpackage/apps/PrintEnv.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021, 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.util.List; +import java.util.ArrayList; + +public class PrintEnv { + + public static void main(String[] args) { + List lines = printArgs(args); + lines.forEach(System.out::println); + } + + private static List printArgs(String[] args) { + List lines = new ArrayList<>(); + + for (String arg : args) { + if (arg.startsWith(PRINT_ENV_VAR)) { + String name = arg.substring(PRINT_ENV_VAR.length()); + lines.add(name + "=" + System.getenv(name)); + } else if (arg.startsWith(PRINT_SYS_PROP)) { + String name = arg.substring(PRINT_SYS_PROP.length()); + lines.add(name + "=" + System.getProperty(name)); + } else { + throw new IllegalArgumentException(); + } + } + + return lines; + } + + private final static String PRINT_ENV_VAR = "--print-env-var="; + private final static String PRINT_SYS_PROP = "--print-sys-prop="; +} diff --git a/test/jdk/tools/jpackage/apps/installer/Hello.java b/test/jdk/tools/jpackage/apps/installer/Hello.java deleted file mode 100644 index 18ac1e4db0d..00000000000 --- a/test/jdk/tools/jpackage/apps/installer/Hello.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2018, 2019, 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.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.awt.Desktop; -import java.awt.desktop.OpenFilesEvent; -import java.awt.desktop.OpenFilesHandler; -import java.util.List; - -public class Hello implements OpenFilesHandler { - - private static final String MSG = "jpackage test application"; - private static final int EXPECTED_NUM_OF_PARAMS = 3; // Starts at 1 - private static List files; - - public static void main(String[] args) { - if(Desktop.getDesktop().isSupported(Desktop.Action.APP_OPEN_FILE)) { - Desktop.getDesktop().setOpenFileHandler(new Hello()); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - printToStdout(args); - if (args.length == 1 || (files != null && files.size() == 1)) { // Called via file association - printToFile(args); - } - } - - private static void printToStdout(String[] args) { - System.out.println(MSG); - - System.out.println("args.length: " + (files == null ? args.length : args.length + files.size())); - - for (String arg : args) { - System.out.println(arg); - } - - if (files != null) { - for (File file : files) { - System.out.println(file.getAbsolutePath()); - } - } - - for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) { - String value = System.getProperty("param" + index); - if (value != null) { - System.out.println("-Dparam" + index + "=" + value); - } - } - } - - private static void printToFile(String[] args) { - File inputFile = files == null ? new File(args[0]) : files.get(0); - String outputFile = inputFile.getParent() + File.separator + "appOutput.txt"; - File file = new File(outputFile); - - try (PrintWriter out - = new PrintWriter(new BufferedWriter(new FileWriter(file)))) { - out.println(MSG); - - out.println("args.length: " + (files == null ? args.length : args.length + files.size())); - - for (String arg : args) { - out.println(arg); - } - - if (files != null) { - for (File f : files) { - out.println(f.getAbsolutePath()); - } - } - - for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) { - String value = System.getProperty("param" + index); - if (value != null) { - out.println("-Dparam" + index + "=" + value); - } - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - } - } - - @Override - public void openFiles(OpenFilesEvent e) { - files = e.getFiles(); - } -} diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java index 2ba5902e376..71561a51cf3 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2021, 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 @@ -56,6 +56,8 @@ public final class HelloApp { } private JarBuilder prepareSources(Path srcDir) throws IOException { + final String srcClassName = appDesc.srcClassName(); + final String qualifiedClassName = appDesc.className(); final String className = qualifiedClassName.substring( @@ -83,9 +85,9 @@ private JarBuilder prepareSources(Path srcDir) throws IOException { // Add package directive and replace class name in java source file. // Works with simple test Hello.java. // Don't expect too much from these regexps! - Pattern classNameRegex = Pattern.compile("\\bHello\\b"); + Pattern classNameRegex = Pattern.compile("\\b" + srcClassName + "\\b"); Pattern classDeclaration = Pattern.compile( - "(^.*\\bclass\\s+)\\bHello\\b(.*$)"); + "(^.*\\bclass\\s+)\\b" + srcClassName + "\\b(.*$)"); Pattern importDirective = Pattern.compile( "(?<=import (?:static )?+)[^;]+"); AtomicBoolean classDeclared = new AtomicBoolean(); @@ -97,7 +99,8 @@ private JarBuilder prepareSources(Path srcDir) throws IOException { System.lineSeparator(), line); }); - Files.write(srcFile, Files.readAllLines(HELLO_JAVA).stream().map(line -> { + Files.write(srcFile, + Files.readAllLines(appDesc.srcJavaPath()).stream().map(line -> { Matcher m; if (classDeclared.getPlain()) { if ((m = classNameRegex.matcher(line)).find()) { @@ -144,13 +147,14 @@ void addTo(JPackageCommand cmd) { return cmd.getArgumentValue("--module-path", cmd::inputDir, Path::of); }; - if (moduleName == null && CLASS_NAME.equals(qualifiedClassName)) { + if (moduleName == null && CLASS_NAME.equals(qualifiedClassName) + && HELLO_JAVA.equals(appDesc.srcJavaPath())) { // Use Hello.java as is. cmd.addPrerequisiteAction((self) -> { if (self.inputDir() != null) { Path jarFile = self.inputDir().resolve(appDesc.jarFileName()); createJarBuilder().setOutputJar(jarFile).addSourceFile( - HELLO_JAVA).create(); + appDesc.srcJavaPath()).create(); } }); } else if (appDesc.jmodFileName() != null) { @@ -159,7 +163,7 @@ void addTo(JPackageCommand cmd) { createBundle(appDesc, getModulePath.get()); }); } else { - // Modular app in .jar file + // Modular/non-modular app in .jar file cmd.addPrerequisiteAction(unused -> { final Path jarFile; if (moduleName == null) { @@ -195,7 +199,7 @@ void addTo(JPackageCommand cmd) { } static JavaAppDesc createDefaltAppDesc() { - return new JavaAppDesc().setClassName(CLASS_NAME).setBundleFileName("hello.jar"); + return new JavaAppDesc().setSrcJavaPath(HELLO_JAVA).setClassName(CLASS_NAME).setBundleFileName("hello.jar"); } static void verifyOutputFile(Path outputFile, List args, @@ -462,7 +466,7 @@ public static AppOutputVerifier assertApp(Path helloAppLauncher) { private final JavaAppDesc appDesc; private static final Path HELLO_JAVA = TKit.TEST_SRC_ROOT.resolve( - "apps/image/Hello.java"); + "apps/Hello.java"); private final static String CLASS_NAME = HELLO_JAVA.getFileName().toString().split( "\\.", 2)[0]; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java index a5db716faa9..6a798012ca7 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2021, 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,11 @@ public final class JavaAppDesc { public JavaAppDesc() { } + public JavaAppDesc setSrcJavaPath(Path v) { + srcJavaPath = v; + return this; + } + public JavaAppDesc setClassName(String v) { qualifiedClassName = v; return this; @@ -55,6 +60,15 @@ public JavaAppDesc setWithMainClass(boolean v) { return this; } + public Path srcJavaPath() { + return srcJavaPath; + } + + public String srcClassName() { + String fname = srcJavaPath().getFileName().toString(); + return fname.substring(0, fname.lastIndexOf('.')); + } + public String className() { return qualifiedClassName; } @@ -113,6 +127,9 @@ public boolean isWithMainClass() { @Override public String toString() { StringBuilder sb = new StringBuilder(); + if (srcJavaPath != null) { + sb.append(srcJavaPath.toString()).append('*'); + } if (bundleFileName != null) { sb.append(bundleFileName).append(':'); } @@ -135,7 +152,7 @@ public String toString() { * Create Java application description form encoded string value. * * Syntax of encoded Java application description is - * [(jar_file|jmods_file|exploded_jmods_file):][module_name/]qualified_class_name[!][@module_version]. + * [src_java_file*][(jar_file|jmods_file|exploded_jmods_file):][module_name/]qualified_class_name[!][@module_version]. * * E.g.: `duke.jar:com.other/com.other.foo.bar.Buz!@3.7` encodes modular * application. Module name is `com.other`. Main class is @@ -168,8 +185,16 @@ public static JavaAppDesc parse(final String javaAppDesc) { return desc; } + String srcJavaPathAndOther = Functional.identity(() -> { + String[] components = javaAppDesc.split("\\*", 2); + if (components.length == 2) { + desc.setSrcJavaPath(Path.of(components[0])); + } + return components[components.length - 1]; + }).get(); + String moduleNameAndOther = Functional.identity(() -> { - String[] components = javaAppDesc.split(":", 2); + String[] components = srcJavaPathAndOther.split(":", 2); if (components.length == 2) { desc.setBundleFileName(components[0]); } @@ -206,6 +231,7 @@ public static JavaAppDesc parse(final String javaAppDesc) { return desc; } + private Path srcJavaPath; private String qualifiedClassName; private String moduleName; private String bundleFileName; diff --git a/test/jdk/tools/jpackage/share/AddLauncherTest.java b/test/jdk/tools/jpackage/share/AddLauncherTest.java index 9bd45549eef..d1eca67b336 100644 --- a/test/jdk/tools/jpackage/share/AddLauncherTest.java +++ b/test/jdk/tools/jpackage/share/AddLauncherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, 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 @@ -185,9 +185,13 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) { cmd.ignoreDefaultRuntime(true); // because of --add-modules } + final String expectedMod = JavaAppDesc.parse(modularAppDesc.toString()) + .setBundleFileName(null) + .setSrcJavaPath(null) + .toString(); + new AdditionalLauncher("ModularAppLauncher") - .addRawProperties(Map.entry("module", JavaAppDesc.parse( - modularAppDesc.toString()).setBundleFileName(null).toString())) + .addRawProperties(Map.entry("module", expectedMod)) .addRawProperties(Map.entry("main-jar", "")) .applyTo(cmd); @@ -208,8 +212,6 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) { String moduleValue = cfg.getValue("Application", "app.mainmodule"); String mainClass = null; String classpath = null; - String expectedMod = JavaAppDesc.parse( - modularAppDesc.toString()).setBundleFileName(null).toString(); TKit.assertEquals(expectedMod, moduleValue, String.format("Check value of app.mainmodule=[%s]" + "in ModularAppLauncher cfg file is as expected", expectedMod)); diff --git a/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java b/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java new file mode 100644 index 00000000000..6e7d35d37b7 --- /dev/null +++ b/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021, 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.io.File; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.function.BiFunction; +import jdk.jpackage.test.JPackageCommand; +import jdk.jpackage.test.Annotations.Test; +import jdk.jpackage.test.Executor; +import jdk.jpackage.test.TKit; + +/** + * Tests values of environment variables altered by jpackage launcher. + */ + +/* + * @test + * @summary Tests values of environment variables altered by jpackage launcher + * @library ../helpers + * @library /test/lib + * @build AppLauncherEnvTest + * @build jdk.jpackage.test.* + * @build AppLauncherEnvTest + * @modules jdk.jpackage/jdk.jpackage.internal + * @run main/othervm -Xmx512m jdk.jpackage.test.Main + * --jpt-run=AppLauncherEnvTest + */ +public class AppLauncherEnvTest { + + @Test + public static void test() throws Exception { + final String testAddDirProp = "jpackage.test.AppDir"; + + JPackageCommand cmd = JPackageCommand + .helloAppImage(TEST_APP_JAVA + "*Hello") + .addArguments("--java-options", "-D" + testAddDirProp + + "=$APPDIR"); + + cmd.executeAndAssertImageCreated(); + + final String envVarName = envVarName(); + + final int attempts = 3; + final int waitBetweenAttemptsSeconds = 5; + List output = new Executor() + .saveOutput() + .setExecutable(cmd.appLauncherPath().toAbsolutePath()) + .addArguments("--print-env-var=" + envVarName) + .addArguments("--print-sys-prop=" + testAddDirProp) + .addArguments("--print-sys-prop=" + "java.library.path") + .executeAndRepeatUntilExitCode(0, attempts, + waitBetweenAttemptsSeconds).getOutput(); + + BiFunction getValue = (idx, name) -> { + return output.get(idx).substring((name + "=").length()); + }; + + final String actualEnvVarValue = getValue.apply(0, envVarName); + final String appDir = getValue.apply(1, testAddDirProp); + + final String expectedEnvVarValue = Optional.ofNullable(System.getenv( + envVarName)).orElse("") + File.pathSeparator + appDir; + + TKit.assertEquals(expectedEnvVarValue, actualEnvVarValue, String.format( + "Check value of %s env variable", envVarName)); + + final String javaLibraryPath = getValue.apply(2, "java.library.path"); + TKit.assertTrue( + List.of(javaLibraryPath.split(File.pathSeparator)).contains( + appDir), String.format( + "Check java.library.path system property [%s] contains app dir [%s]", + javaLibraryPath, appDir)); + } + + private static String envVarName() { + if (TKit.isLinux()) { + return "LD_LIBRARY_PATH"; + } else if (TKit.isWindows()) { + return "PATH"; + } else if (TKit.isOSX()) { + return "DYLD_LIBRARY_PATH"; + } else { + throw new IllegalStateException(); + } + } + + private static final Path TEST_APP_JAVA = TKit.TEST_SRC_ROOT.resolve( + "apps/PrintEnv.java"); +} From 2586eb08b1480f600e0fc0b15bf5bdf1aa8dbffa Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Wed, 29 Sep 2021 21:34:06 +0000 Subject: [PATCH 100/253] 8274087: Windows DLL path not set correctly. Backport-of: f36a2bbd15d94d4371c2117ce08b7f04a0d59da4 --- src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp b/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp index a3b8f150082..d68521a13a5 100644 --- a/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp +++ b/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp @@ -139,8 +139,6 @@ void launchApp() { const tstring launcherPath = SysInfo::getProcessModulePath(); const tstring appImageRoot = FileUtils::dirname(launcherPath); const tstring appDirPath = FileUtils::mkpath() << appImageRoot << _T("app"); - const tstring runtimeBinPath = FileUtils::mkpath() - << appImageRoot << _T("runtime") << _T("bin"); const AppLauncher appLauncher = AppLauncher().setImageRoot(appImageRoot) .addJvmLibName(_T("bin\\jli.dll")) @@ -188,9 +186,11 @@ void launchApp() { return; } - // zip.dll may be loaded by java without full path + // zip.dll (and others) may be loaded by java without full path // make sure it will look in runtime/bin + const tstring runtimeBinPath = FileUtils::dirname(jvm->getPath()); SetDllDirectory(runtimeBinPath.c_str()); + LOG_TRACE(tstrings::any() << "SetDllDirectory to: " << runtimeBinPath); const DllWrapper jliDll(jvm->getPath()); std::unique_ptr splashDll; From cdd4075663200e830c38f967242a8d58ee314289 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 29 Sep 2021 22:28:48 +0000 Subject: [PATCH 101/253] 8273135: java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java crashes in liblcms.dylib with NULLSeek+0x7 Backport-of: 1017a2c2d7ae99e0076abcfaf5e730fec3cb9c6c --- src/java.desktop/share/native/liblcms/cmsio0.c | 3 ++- .../awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/java.desktop/share/native/liblcms/cmsio0.c b/src/java.desktop/share/native/liblcms/cmsio0.c index 70be6a6ad14..6d5afc0d319 100644 --- a/src/java.desktop/share/native/liblcms/cmsio0.c +++ b/src/java.desktop/share/native/liblcms/cmsio0.c @@ -1532,7 +1532,7 @@ cmsBool IsTypeSupported(cmsTagDescriptor* TagDescriptor, cmsTagTypeSignature Typ void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig) { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; - cmsIOHANDLER* io = Icc ->IOhandler; + cmsIOHANDLER* io; cmsTagTypeHandler* TypeHandler; cmsTagTypeHandler LocalTypeHandler; cmsTagDescriptor* TagDescriptor; @@ -1573,6 +1573,7 @@ void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig) if (TagSize < 8) goto Error; + io = Icc ->IOhandler; // Seek to its location if (!io -> Seek(io, Offset)) goto Error; diff --git a/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java b/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java index df66f29ecec..7d0b501e72b 100644 --- a/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java +++ b/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java @@ -34,7 +34,7 @@ /** * @test - * @bug 8271718 + * @bug 8271718 8273135 * @summary Verifies MT safety of color transformation while profile is changed */ public final class MTTransformReplacedProfile { From 20afdfdcfe01b87ce2b43da27a4cc49372656dbe Mon Sep 17 00:00:00 2001 From: jovanstevanovic Date: Thu, 30 Sep 2021 04:58:46 +0000 Subject: [PATCH 102/253] 8273278: Support XSLT on GraalVM Native Image--deterministic bytecode generation in XSLT Backport-of: f690a01f1e5de4ace39aefad656cb7c99f9ec4e1 --- .../internal/xsltc/compiler/LiteralElement.java | 7 ++++--- .../xalan/internal/xsltc/compiler/Mode.java | 17 ++++++++++------- .../xalan/internal/xsltc/compiler/Number.java | 6 +++--- .../xsltc/compiler/util/MethodGenerator.java | 11 ++++++----- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LiteralElement.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LiteralElement.java index 80fdb4a3b8a..c7c2b9072b8 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LiteralElement.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LiteralElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -33,6 +33,7 @@ import com.sun.org.apache.xml.internal.serializer.ToHTMLStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -42,7 +43,7 @@ * @author Jacek Ambroziak * @author Santiago Pericas-Geertsen * @author Morten Jorgensen - * @LastModified: Oct 2017 + * @LastModified: Sep 2021 */ final class LiteralElement extends Instruction { @@ -202,7 +203,7 @@ public Type typeCheck(SymbolTable stable) throws TypeCheckError { * to _ANY_ namespace URI. Used by literal result elements to determine */ public Set> getNamespaceScope(SyntaxTreeNode node) { - Map all = new HashMap<>(); + Map all = new LinkedHashMap<>(); while (node != null) { Map mapping = node.getPrefixMapping(); diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java index 5bd99bcd854..2c1f7e64551 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -48,6 +48,7 @@ import com.sun.org.apache.xml.internal.dtm.DTM; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -62,7 +63,7 @@ * @author Morten Jorgensen * @author Erwin Bolwidt * @author G. Todd Miller - * @LastModified: Nov 2017 + * @LastModified: Sep 2021 */ final class Mode implements Constants { @@ -129,13 +130,15 @@ final class Mode implements Constants { /** * A mapping between templates and test sequences. + * {@link LinkedHashMap} is necessary to make traversal order consistent across runs. */ - private Map _neededTemplates = new HashMap<>(); + private Map _neededTemplates = new LinkedHashMap<>(); /** * A mapping between named templates and Mode objects. + * {@link LinkedHashMap} is necessary to make traversal order consistent across runs. */ - private Map _namedTemplates = new HashMap<>(); + private Map _namedTemplates = new LinkedHashMap<>(); /** * A mapping between templates and instruction handles. @@ -198,7 +201,7 @@ public String functionName() { public String functionName(int min, int max) { if (_importLevels == null) { - _importLevels = new HashMap<>(); + _importLevels = new LinkedHashMap<>(); } _importLevels.put(max, min); return _methodName + '_' + max; @@ -1053,8 +1056,8 @@ public void compileApplyImports(ClassGenerator classGen, int min, int max) { final List names = xsltc.getNamesIndex(); // Clear some datastructures - _namedTemplates = new HashMap<>(); - _neededTemplates = new HashMap<>(); + _namedTemplates = new LinkedHashMap<>(); + _neededTemplates = new LinkedHashMap<>(); _templateIHs = new HashMap<>(); _templateILs = new HashMap<>(); _patternGroups = (List[])new ArrayList[32]; diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java index 4d192a65ec7..8461e535514 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -53,7 +53,7 @@ /** * @author Jacek Ambroziak * @author Santiago Pericas-Geertsen - * @LastModified: Nov 2017 + * @LastModified: Sep 2021 */ final class Number extends Instruction implements Closure { private static final int LEVEL_SINGLE = 0; @@ -383,7 +383,7 @@ private void compilePatterns(ClassGenerator classGen, _className = getXSLTC().getHelperClassName(); nodeCounterGen = new NodeCounterGenerator(_className, ClassNames[_level], - toString(), + getClass().getName(), // Name of this node should be consistent across runs. ACC_PUBLIC | ACC_SUPER, null, classGen.getStylesheet()); diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java index 1d4a7b9c267..7011d9e2025 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -67,6 +67,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -75,7 +76,7 @@ /** * @author Jacek Ambroziak * @author Santiago Pericas-Geertsen - * @LastModified: July 2019 + * @LastModified: Sep 2021 */ public class MethodGenerator extends MethodGen implements com.sun.org.apache.xalan.internal.xsltc.compiler.Constants { @@ -283,7 +284,7 @@ protected class LocalVariableRegistry { /** * Maps a name to a {@link LocalVariableGen} */ - protected Map _nameToLVGMap = new HashMap<>(); + protected Map _nameToLVGMap = new LinkedHashMap<>(); /** * Registers a {@link org.apache.bcel.generic.LocalVariableGen} @@ -1330,8 +1331,8 @@ public boolean isExternal() { // to local variables in the outlined method. HashMap localVarMap = new HashMap<>(); - HashMap revisedLocalVarStart = new HashMap<>(); - HashMap revisedLocalVarEnd = new HashMap<>(); + HashMap revisedLocalVarStart = new LinkedHashMap<>(); + HashMap revisedLocalVarEnd = new LinkedHashMap<>(); // Pass 1: Make copies of all instructions, append them to the new list // and associate old instruction references with the new ones, i.e., From a9981fb0ff11965128761ffd1d8fae1c44c7b9fb Mon Sep 17 00:00:00 2001 From: Artem Semenov Date: Thu, 30 Sep 2021 10:36:50 +0000 Subject: [PATCH 103/253] 8274381: missing CAccessibility definitions in JNI code Reviewed-by: ant Backport-of: be4037374520917d5a0ed54eebb3d5d6d100d429 --- .../macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m index 33ccaaf3d10..54dbe0d5e2a 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m @@ -50,6 +50,7 @@ NSSize getAxComponentSize(JNIEnv *env, jobject axComponent, jobject component) { + GET_CACCESSIBILITY_CLASS_RETURN(NSZeroSize); DECLARE_CLASS_RETURN(jc_Dimension, "java/awt/Dimension", NSZeroSize); DECLARE_FIELD_RETURN(jf_width, jc_Dimension, "width", "I", NSZeroSize); DECLARE_FIELD_RETURN(jf_height, jc_Dimension, "height", "I", NSZeroSize); From c26cd97cb7d28e673e75080b47d26aa0e26e3c75 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 30 Sep 2021 16:50:31 +0000 Subject: [PATCH 104/253] 8274326: [macos] Ensure initialisation of sun/lwawt/macosx/CAccessibility in JavaComponentAccessibility.m Backport-of: 2cffe4c8e0b8e6d5843b7e9545e4b4408c56465c --- .../macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m index 33e838b070a..648963aaa53 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -1404,6 +1404,7 @@ - (BOOL)accessibilityIsIgnored - (id)accessibilityHitTest:(NSPoint)point withEnv:(JNIEnv *)env { + GET_CACCESSIBILITY_CLASS_RETURN(nil); DECLARE_CLASS_RETURN(jc_Container, "java/awt/Container", nil); DECLARE_STATIC_METHOD_RETURN(jm_accessibilityHitTest, sjc_CAccessibility, "accessibilityHitTest", "(Ljava/awt/Container;FF)Ljavax/accessibility/Accessible;", nil); From 91dd244f3429449d61677aa9086e13e3498cd0bd Mon Sep 17 00:00:00 2001 From: Guoxiong Li Date: Thu, 30 Sep 2021 17:08:49 +0000 Subject: [PATCH 105/253] 8266239: Some duplicated javac command-line options have repeated effect Backport-of: d05494f98bad351532cdb769c9da6b6e2359b16e --- .../com/sun/tools/javac/main/Option.java | 5 +++++ .../javac/options/modes/InfoOptsTest.java | 20 ++++++++++++++++++- .../options/modes/OptionModesTester.java | 18 ++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java index a6d050b0a6f..033539c2c16 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java @@ -1154,6 +1154,11 @@ public void handleOption(OptionHelper helper, String arg, Iterator rest) } process(helper, option, operand); } else { + if ((this == HELP || this == X || this == HELP_LINT || this == VERSION || this == FULLVERSION) + && (helper.get(this) != null)) { + // avoid processing the info options repeatedly + return; + } process(helper, arg); } } diff --git a/test/langtools/tools/javac/options/modes/InfoOptsTest.java b/test/langtools/tools/javac/options/modes/InfoOptsTest.java index 9818dc2e82a..6b72378f902 100644 --- a/test/langtools/tools/javac/options/modes/InfoOptsTest.java +++ b/test/langtools/tools/javac/options/modes/InfoOptsTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8044859 8230623 + * @bug 8044859 8230623 8266239 * @summary test support for info options -help -X -version -fullversion --help-lint * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file @@ -66,4 +66,22 @@ void testInfoOpt(String opt, String... expect) { runParse(opts, files) .checkIllegalArgumentException(); } + + @Test + void testUniqueInfoOpts() throws IOException { + testUniqueInfoOpt(new String[] {"--help", "--help"}, "possible options"); + testUniqueInfoOpt(new String[] {"-X", "-X"}, "extra options"); + testUniqueInfoOpt(new String[] {"--help-lint", "--help-lint"}, "supported keys"); + + String specVersion = System.getProperty("java.specification.version"); + testUniqueInfoOpt(new String[] {"-version", "-version"}, "javac", specVersion); + testUniqueInfoOpt(new String[] {"-fullversion", "-fullversion"}, "javac", specVersion); + } + + void testUniqueInfoOpt(String[] opts, String... expect) { + String[] files = { }; + runMain(opts, files) + .checkOK() + .checkUniqueLog(expect); + } } diff --git a/test/langtools/tools/javac/options/modes/OptionModesTester.java b/test/langtools/tools/javac/options/modes/OptionModesTester.java index 462d1607115..ce25ac31887 100644 --- a/test/langtools/tools/javac/options/modes/OptionModesTester.java +++ b/test/langtools/tools/javac/options/modes/OptionModesTester.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2021, 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 @@ -269,6 +269,22 @@ TestResult checkLog(Log l, String... expects) { return this; } + TestResult checkUniqueLog(String... uniqueExpects) { + return checkUniqueLog(Log.DIRECT, uniqueExpects); + } + + TestResult checkUniqueLog(Log l, String... uniqueExpects) { + String log = logs.get(l); + for (String e : uniqueExpects) { + if (!log.contains(e)) { + error("Expected string not found: " + e); + } else if (log.indexOf(e) != log.lastIndexOf(e)) { + error("Expected string appears more than once: " + e); + } + } + return this; + } + TestResult checkIllegalArgumentException() { return checkThrown(IllegalArgumentException.class); } From de6899b66e22aae4dfc093ce9a561d05c059baf8 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Thu, 30 Sep 2021 18:25:45 +0000 Subject: [PATCH 106/253] 8273935: (zipfs) Files.getFileAttributeView() throws UOE instead of returning null when view not supported Backport-of: 161fdb4afbc6e67cc7580fe753112c4d894a9b6b --- .../share/classes/jdk/nio/zipfs/ZipPath.java | 2 +- test/jdk/jdk/nio/zipfs/TestPosix.java | 6 +- .../testng/test/PosixAttributeViewTest.java | 102 ++++++++++++++++++ .../nio/zipfs/testng/util/ZipFsBaseTest.java | 4 +- 4 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 test/jdk/jdk/nio/zipfs/testng/test/PosixAttributeViewTest.java diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java index 8d64187cc47..5cccce8d113 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java @@ -713,7 +713,7 @@ V getFileAttributeView(Class type) { if (type == FileOwnerAttributeView.class) return (V)new ZipPosixFileAttributeView(this,true); } - throw new UnsupportedOperationException("view <" + type + "> is not supported"); + return null; } private ZipFileAttributeView getFileAttributeView(String type) { diff --git a/test/jdk/jdk/nio/zipfs/TestPosix.java b/test/jdk/jdk/nio/zipfs/TestPosix.java index c9dc600b8cb..2be70758fbc 100644 --- a/test/jdk/jdk/nio/zipfs/TestPosix.java +++ b/test/jdk/jdk/nio/zipfs/TestPosix.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 SAP SE. All rights reserved. + * Copyright (c) 2019, 2021, SAP SE. 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 @@ -68,7 +68,7 @@ /** * @test - * @bug 8213031 + * @bug 8213031 8273935 * @modules jdk.zipfs * jdk.jartool * @run testng TestPosix @@ -595,7 +595,7 @@ public void testPosixDefaults() throws IOException { assertTrue(throwsUOE(()->Files.setPosixFilePermissions(entry, UW))); assertTrue(throwsUOE(()->Files.getOwner(entry))); assertTrue(throwsUOE(()->Files.setOwner(entry, DUMMY_USER))); - assertTrue(throwsUOE(()->Files.getFileAttributeView(entry, PosixFileAttributeView.class))); + assertNull(Files.getFileAttributeView(entry, PosixFileAttributeView.class)); } // test with posix = true -> default values diff --git a/test/jdk/jdk/nio/zipfs/testng/test/PosixAttributeViewTest.java b/test/jdk/jdk/nio/zipfs/testng/test/PosixAttributeViewTest.java new file mode 100644 index 00000000000..7734ea733c9 --- /dev/null +++ b/test/jdk/jdk/nio/zipfs/testng/test/PosixAttributeViewTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021, 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. + * + */ +package test; + +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import util.ZipFsBaseTest; + +import java.io.IOException; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.PosixFileAttributeView; +import java.util.Map; +import java.util.zip.ZipEntry; + +/** + * @test + * @bug 8273935 + * @summary Validate that Files.getFileAttributeView will not throw an + * Exception when the attribute view PosixFileAttributeView is not available + */ +public class PosixAttributeViewTest extends ZipFsBaseTest { + public static final String ZIP_ENTRY = "Entry-0"; + private static final Path ZIP_FILE = Path.of("posixTest.zip"); + + /** + * Create initial Zip File + * @throws IOException if an error occurs + */ + @BeforeTest + public void setup() throws IOException { + Files.deleteIfExists(ZIP_FILE); + Entry entry = Entry.of(ZIP_ENTRY, ZipEntry.DEFLATED, + "Tennis Anyone"); + zip(ZIP_FILE, Map.of("create", "true"), entry); + } + + /** + * Remove Zip File used by Test + * @throws IOException if an error occurs + */ + @AfterTest + public void cleanup() throws IOException { + Files.deleteIfExists(ZIP_FILE); + } + + /** + * DataProvider used to specify the Map indicating whether Posix + * file attributes have been enabled + * @return map of the Zip FS properties to configure + */ + @DataProvider + protected Object[][] zipfsMap() { + return new Object[][]{ + {Map.of()}, + {Map.of("enablePosixFileAttributes", "true")} + }; + } + + /** + * Verify that Files.getFileAttributeView will not throw + * an Exception when the attribute view + * PosixFileAttributeView is not available + * @param env map of the Zip FS properties to configure + * @throws Exception if an error occurs + */ + @Test(dataProvider = "zipfsMap") + public void testPosixAttributeView(Map env) throws Exception { + try (FileSystem fs = FileSystems.newFileSystem(ZIP_FILE, env)) { + Path entry = fs.getPath(ZIP_ENTRY); + PosixFileAttributeView view = Files.getFileAttributeView(entry, + PosixFileAttributeView.class); + System.out.printf("View returned: %s, Map= %s%n", view, + formatMap(env)); + } + } +} diff --git a/test/jdk/jdk/nio/zipfs/testng/util/ZipFsBaseTest.java b/test/jdk/jdk/nio/zipfs/testng/util/ZipFsBaseTest.java index 37b8a55309a..a6dbe9b8054 100644 --- a/test/jdk/jdk/nio/zipfs/testng/util/ZipFsBaseTest.java +++ b/test/jdk/jdk/nio/zipfs/testng/util/ZipFsBaseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, 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 @@ -105,7 +105,7 @@ protected Object[][] compressionMethods() { * @param env Map to format * @return Formatted string of the Map entries */ - private static String formatMap(Map env) { + protected static String formatMap(Map env) { return env.entrySet().stream() .map(e -> format("(%s:%s)", e.getKey(), e.getValue())) .collect(joining(", ")); From 845494aa6e995b1bb92401c264ffbcc60f2d6065 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 30 Sep 2021 19:37:07 +0000 Subject: [PATCH 107/253] 8273887: [macos] java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java timed out Backport-of: 1bd11a7f2ca433f4aa9c545a20960e0778ec545e --- .../awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java b/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java index 7d0b501e72b..d9e10785cff 100644 --- a/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java +++ b/test/jdk/java/awt/color/ICC_ColorSpace/MTTransformReplacedProfile.java @@ -110,7 +110,7 @@ private static void test(byte[] all, byte[] data1, byte[] data2, int tag) float[] colorvalue = new float[3]; Thread transform = new Thread(() -> { boolean rgb = true; - while (!stop.get()) { + while (!stop.get() && !isComplete()) { try { if (rgb) { cs.toRGB(colorvalue); From c136c188b519aa315985c9dd0bbe9fedbf182175 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 1 Oct 2021 06:25:41 +0000 Subject: [PATCH 108/253] 8273378: Shenandoah: Remove the remaining uses of os::is_MP Backport-of: fc546d6de9a3ed33cf4b04e24e62714332b069cb --- .../gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp index 32d9050fcc8..2fa9dbe4ef7 100644 --- a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp @@ -682,13 +682,14 @@ void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, // // Try to CAS with given arguments. If successful, then we are done. - if (os::is_MP()) __ lock(); #ifdef _LP64 if (UseCompressedOops) { + __ lock(); __ cmpxchgl(newval, addr); } else #endif { + __ lock(); __ cmpxchgptr(newval, addr); } __ jcc(Assembler::equal, L_success); @@ -765,13 +766,14 @@ void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, } #endif - if (os::is_MP()) __ lock(); #ifdef _LP64 if (UseCompressedOops) { + __ lock(); __ cmpxchgl(tmp2, addr); } else #endif { + __ lock(); __ cmpxchgptr(tmp2, addr); } @@ -791,13 +793,14 @@ void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, __ movptr(oldval, tmp2); } - if (os::is_MP()) __ lock(); #ifdef _LP64 if (UseCompressedOops) { + __ lock(); __ cmpxchgl(newval, addr); } else #endif { + __ lock(); __ cmpxchgptr(newval, addr); } if (!exchange) { From 268c0159253b3de5d72eb826ef2329b27bb33fea Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Fri, 1 Oct 2021 07:06:17 +0000 Subject: [PATCH 109/253] 8272014: Better array indexing Reviewed-by: thartmann Backport-of: 937c31d896d05aa24543b74e98a2ea9f05b5d86f --- src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp index ba18ce30cfa..b99f16fea05 100644 --- a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp +++ b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp @@ -192,8 +192,32 @@ LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_o LIR_Address* addr; if (index_opr->is_constant()) { int elem_size = type2aelembytes(type); - addr = new LIR_Address(array_opr, - offset_in_bytes + (intx)(index_opr->as_jint()) * elem_size, type); +#ifdef _LP64 + jint index = index_opr->as_jint(); + jlong disp = offset_in_bytes + (jlong)(index) * elem_size; + if (disp > max_jint) { + // Displacement overflow. Cannot directly use instruction with 32-bit displacement for 64-bit addresses. + // Convert array index to long to do array offset computation with 64-bit values. + index_opr = new_register(T_LONG); + __ move(LIR_OprFact::longConst(index), index_opr); + addr = new LIR_Address(array_opr, index_opr, LIR_Address::scale(type), offset_in_bytes, type); + } else { + addr = new LIR_Address(array_opr, (intx)disp, type); + } +#else + // A displacement overflow can also occur for x86 but that is not a problem due to the 32-bit address range! + // Let's assume an array 'a' and an access with displacement 'disp'. When disp overflows, then "a + disp" will + // always be negative (i.e. underflows the 32-bit address range): + // Let N = 2^32: a + signed_overflow(disp) = a + disp - N. + // "a + disp" is always smaller than N. If an index was chosen which would point to an address beyond N, then + // range checks would catch that and throw an exception. Thus, a + disp < 0 holds which means that it always + // underflows the 32-bit address range: + // unsigned_underflow(a + signed_overflow(disp)) = unsigned_underflow(a + disp - N) + // = (a + disp - N) + N = a + disp + // This shows that we still end up at the correct address with a displacement overflow due to the 32-bit address + // range limitation. This overflow only needs to be handled if addresses can be larger as on 64-bit platforms. + addr = new LIR_Address(array_opr, offset_in_bytes + (intx)(index_opr->as_jint()) * elem_size, type); +#endif // _LP64 } else { #ifdef _LP64 if (index_opr->type() == T_INT) { From 24903860dd401dcf742d750388aae09efb0e8a1e Mon Sep 17 00:00:00 2001 From: Thejasvi Voniadka Date: Fri, 1 Oct 2021 12:12:18 +0000 Subject: [PATCH 110/253] 8271287: jdk/jshell/CommandCompletionTest.java fails with "lists don't have the same size expected" Backport-of: 71788c69dbae854331f3393044dab458c906045f --- test/langtools/jdk/jshell/CommandCompletionTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/langtools/jdk/jshell/CommandCompletionTest.java b/test/langtools/jdk/jshell/CommandCompletionTest.java index 32c7b623e3e..9f2bbdb0beb 100644 --- a/test/langtools/jdk/jshell/CommandCompletionTest.java +++ b/test/langtools/jdk/jshell/CommandCompletionTest.java @@ -332,14 +332,22 @@ public void testClassPath() throws IOException { public void testUserHome() throws IOException { List completions; Path home = Paths.get(System.getProperty("user.home")); + String selectedFile; + try (Stream content = Files.list(home)) { + selectedFile = content.filter(CLASSPATH_FILTER) + .findAny() + .map(file -> file.getFileName().toString()) + .get(); + } try (Stream content = Files.list(home)) { completions = content.filter(CLASSPATH_FILTER) + .filter(file -> file.getFileName().toString().startsWith(selectedFile)) .map(file -> file.getFileName().toString() + (Files.isDirectory(file) ? "/" : "")) .sorted() .collect(Collectors.toList()); } testNoStartUp( - a -> assertCompletion(a, "/env --class-path ~/|", false, completions.toArray(new String[completions.size()])) + a -> assertCompletion(a, "/env --class-path ~/" + selectedFile + "|", false, completions.toArray(new String[completions.size()])) ); } From 58487fb0de2ae7a26928dce6f5657b41dda21193 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 10:13:40 +0000 Subject: [PATCH 111/253] 8273361: InfoOptsTest is failing in tier1 Backport-of: 267c61a16a916e35762e8df5737ec74b06defae8 --- .../javac/options/modes/InfoOptsTest.java | 24 +++++++++++-------- .../options/modes/OptionModesTester.java | 17 ++++++------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/test/langtools/tools/javac/options/modes/InfoOptsTest.java b/test/langtools/tools/javac/options/modes/InfoOptsTest.java index 6b72378f902..58391c7d9d6 100644 --- a/test/langtools/tools/javac/options/modes/InfoOptsTest.java +++ b/test/langtools/tools/javac/options/modes/InfoOptsTest.java @@ -69,19 +69,23 @@ void testInfoOpt(String opt, String... expect) { @Test void testUniqueInfoOpts() throws IOException { - testUniqueInfoOpt(new String[] {"--help", "--help"}, "possible options"); - testUniqueInfoOpt(new String[] {"-X", "-X"}, "extra options"); - testUniqueInfoOpt(new String[] {"--help-lint", "--help-lint"}, "supported keys"); + testUniqueInfoOpt(new String[] {"--help"}, new String[] {"--help", "--help"}); + testUniqueInfoOpt(new String[] {"-X"}, new String[] {"-X", "-X"}); + testUniqueInfoOpt(new String[] {"--help-lint"}, new String[] {"--help-lint", "--help-lint"}); - String specVersion = System.getProperty("java.specification.version"); - testUniqueInfoOpt(new String[] {"-version", "-version"}, "javac", specVersion); - testUniqueInfoOpt(new String[] {"-fullversion", "-fullversion"}, "javac", specVersion); + testUniqueInfoOpt(new String[] {"-version"}, new String[] {"-version", "-version"}); + testUniqueInfoOpt(new String[] {"-fullversion"}, new String[] {"-fullversion", "-fullversion"}); } - void testUniqueInfoOpt(String[] opts, String... expect) { + void testUniqueInfoOpt(String[] baseOpts, String[] testOpts) { String[] files = { }; - runMain(opts, files) - .checkOK() - .checkUniqueLog(expect); + + TestResult base = runMain(baseOpts, files) + .checkOK(); + + TestResult test = runMain(testOpts, files) + .checkOK(); + + base.checkSameLog(test); } } diff --git a/test/langtools/tools/javac/options/modes/OptionModesTester.java b/test/langtools/tools/javac/options/modes/OptionModesTester.java index ce25ac31887..fd4feb21506 100644 --- a/test/langtools/tools/javac/options/modes/OptionModesTester.java +++ b/test/langtools/tools/javac/options/modes/OptionModesTester.java @@ -269,18 +269,15 @@ TestResult checkLog(Log l, String... expects) { return this; } - TestResult checkUniqueLog(String... uniqueExpects) { - return checkUniqueLog(Log.DIRECT, uniqueExpects); + TestResult checkSameLog(TestResult other) { + return checkSameLog(Log.DIRECT, other); } - TestResult checkUniqueLog(Log l, String... uniqueExpects) { - String log = logs.get(l); - for (String e : uniqueExpects) { - if (!log.contains(e)) { - error("Expected string not found: " + e); - } else if (log.indexOf(e) != log.lastIndexOf(e)) { - error("Expected string appears more than once: " + e); - } + TestResult checkSameLog(Log l, TestResult other) { + String thisLog = logs.get(l); + String otherLog = other.logs.get(l); + if (!thisLog.equals(otherLog)) { + error("Logs are not the same.\nThis:\n" + thisLog + "\nOther:\n" + otherLog); } return this; } From 32678f7d42adaf093514510a33efbaf4bf13699e Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 10:41:49 +0000 Subject: [PATCH 112/253] 8272914: Create hotspot:tier2 and hotspot:tier3 test groups Backport-of: 5ee5dd9b18fb5adc563a65bd1a29779eda675d61 --- test/hotspot/jtreg/TEST.groups | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups index b59eb2220f5..773a5167565 100644 --- a/test/hotspot/jtreg/TEST.groups +++ b/test/hotspot/jtreg/TEST.groups @@ -450,6 +450,17 @@ tier1 = \ :tier1_runtime \ :tier1_serviceability +tier2 = \ + :hotspot_tier2_runtime \ + :hotspot_tier2_runtime_platform_agnostic \ + :hotspot_tier2_serviceability \ + :tier2_gc_epsilon \ + :tier2_gc_shenandoah + +tier3 = \ + :hotspot_tier3_runtime \ + :tier3_gc_shenandoah + hotspot_tier2_runtime = \ runtime/ \ -runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java \ From c5446c191d0d630ba30e71110d9e3f97d52db1f0 Mon Sep 17 00:00:00 2001 From: Ekaterina Vergizova Date: Mon, 4 Oct 2021 11:38:15 +0000 Subject: [PATCH 113/253] 8274435: EXCEPTION_ACCESS_VIOLATION in BFSClosure::closure_impl Backport-of: c05dc268acaf87236f30cf700ea3ac778e3b20e5 --- src/hotspot/share/jfr/leakprofiler/chains/bitset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/jfr/leakprofiler/chains/bitset.cpp b/src/hotspot/share/jfr/leakprofiler/chains/bitset.cpp index 359de35d04a..7616d615a45 100644 --- a/src/hotspot/share/jfr/leakprofiler/chains/bitset.cpp +++ b/src/hotspot/share/jfr/leakprofiler/chains/bitset.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2021, 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 @@ -33,7 +33,7 @@ BitSet::BitSet() : _bitmap_fragments(32), _fragment_list(NULL), _last_fragment_bits(NULL), - _last_fragment_granule(0) { + _last_fragment_granule(UINTPTR_MAX) { } BitSet::~BitSet() { From b5d40609b7d2d2f86bbfedc439cb728a3ad8c48b Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 11:55:24 +0000 Subject: [PATCH 114/253] 8273373: Zero: Cannot invoke JVM in primordial threads on Zero Backport-of: 0f31d0fb2c0d5db305e75e1d61bcc44de3e77839 --- src/hotspot/os/linux/os_linux.cpp | 3 +++ .../os_cpu/linux_zero/os_linux_zero.cpp | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index c1efd76a360..59dccc6d7b2 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -3354,6 +3354,9 @@ bool os::pd_create_stack_guard_pages(char* addr, size_t size) { if (mincore((address)stack_extent, os::vm_page_size(), vec) == -1) { // Fallback to slow path on all errors, including EAGAIN + assert((uintptr_t)addr >= stack_extent, + "Sanity: addr should be larger than extent, " PTR_FORMAT " >= " PTR_FORMAT, + p2i(addr), stack_extent); stack_extent = (uintptr_t) get_stack_commited_bottom( os::Linux::initial_thread_stack_bottom(), (size_t)addr - stack_extent); diff --git a/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp b/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp index 0360bcb6943..51a7fa8b0fc 100644 --- a/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp +++ b/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp @@ -199,6 +199,20 @@ size_t os::Posix::default_stack_size(os::ThreadType thr_type) { } static void current_stack_region(address *bottom, size_t *size) { + if (os::is_primordial_thread()) { + // primordial thread needs special handling because pthread_getattr_np() + // may return bogus value. + address stack_bottom = os::Linux::initial_thread_stack_bottom(); + size_t stack_bytes = os::Linux::initial_thread_stack_size(); + + assert(os::current_stack_pointer() >= stack_bottom, "should do"); + assert(os::current_stack_pointer() < stack_bottom + stack_bytes, "should do"); + + *bottom = stack_bottom; + *size = stack_bytes; + return; + } + pthread_attr_t attr; int res = pthread_getattr_np(pthread_self(), &attr); if (res != 0) { @@ -247,18 +261,6 @@ static void current_stack_region(address *bottom, size_t *size) { pthread_attr_destroy(&attr); - // The initial thread has a growable stack, and the size reported - // by pthread_attr_getstack is the maximum size it could possibly - // be given what currently mapped. This can be huge, so we cap it. - if (os::is_primordial_thread()) { - stack_bytes = stack_top - stack_bottom; - - if (stack_bytes > JavaThread::stack_size_at_create()) - stack_bytes = JavaThread::stack_size_at_create(); - - stack_bottom = stack_top - stack_bytes; - } - assert(os::current_stack_pointer() >= stack_bottom, "should do"); assert(os::current_stack_pointer() < stack_top, "should do"); From d59e97da0046e21ac133c410e320b162ba53b7c2 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:24:41 +0000 Subject: [PATCH 115/253] 8273606: Zero: SPARC64 build fails with si_band type mismatch Backport-of: 241ac89f120f9bcfef65962aa05b51b9f847c4ce --- src/hotspot/os/posix/signals_posix.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hotspot/os/posix/signals_posix.cpp b/src/hotspot/os/posix/signals_posix.cpp index c2e5d50bb95..2c020a79408 100644 --- a/src/hotspot/os/posix/signals_posix.cpp +++ b/src/hotspot/os/posix/signals_posix.cpp @@ -1145,7 +1145,11 @@ void os::print_siginfo(outputStream* os, const void* si0) { os->print(", si_addr: " PTR_FORMAT, p2i(si->si_addr)); #ifdef SIGPOLL } else if (sig == SIGPOLL) { - os->print(", si_band: %ld", si->si_band); + // siginfo_t.si_band is defined as "long", and it is so in most + // implementations. But SPARC64 glibc has a bug: si_band is "int". + // Cast si_band to "long" to prevent format specifier mismatch. + // See: https://sourceware.org/bugzilla/show_bug.cgi?id=23821 + os->print(", si_band: %ld", (long) si->si_band); #endif } } From 82788f2fe9b552b3014ea8ce74c1204f13961407 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:30:03 +0000 Subject: [PATCH 116/253] 8273333: Zero should warn about unimplemented -XX:+LogTouchedMethods Backport-of: 81c719be3995fa54974e8b8826ad81bf07bd012f --- src/hotspot/share/runtime/arguments.cpp | 5 +++++ .../jtreg/runtime/CommandLine/PrintTouchedMethods.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 2504527c233..3587b08f309 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -4048,6 +4048,11 @@ jint Arguments::apply_ergo() { // Clear flags not supported on zero. FLAG_SET_DEFAULT(ProfileInterpreter, false); FLAG_SET_DEFAULT(UseBiasedLocking, false); + + if (LogTouchedMethods) { + warning("LogTouchedMethods is not supported for Zero"); + FLAG_SET_DEFAULT(LogTouchedMethods, false); + } #endif // ZERO if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { diff --git a/test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java b/test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java index 5db346a633e..0c8eb71dcfb 100644 --- a/test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java +++ b/test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java @@ -23,7 +23,8 @@ /* * @test - * @bug 8025692 + * @bug 8025692 8273333 + * @requires vm.flavor != "zero" * @modules java.base/jdk.internal.misc * java.management * @library /test/lib From 9c6178906bffb55c264abab923b5b8b4b7c94425 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:30:46 +0000 Subject: [PATCH 117/253] 8273440: Zero: Disable runtime/Unsafe/InternalErrorTest.java Backport-of: 286a1f6b7c6d7c598ced456f1a5f63cac1be8539 --- test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java b/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java index f48f47466d3..51693411011 100644 --- a/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java +++ b/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java @@ -25,6 +25,7 @@ * @test * @bug 8191278 * @requires os.family != "windows" + * @requires vm.flavor != "zero" * @summary Check that SIGBUS errors caused by memory accesses in Unsafe_CopyMemory() * and UnsafeCopySwapMemory() get converted to java.lang.InternalError exceptions. * @modules java.base/jdk.internal.misc From 3cc4dc22618d058ebf97519c368db15fbc174685 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:31:32 +0000 Subject: [PATCH 118/253] 8273483: Zero: Clear pending JNI exception check in native method handler Backport-of: aa9311182ae88312a70b18afd85939718415b77c --- src/hotspot/cpu/zero/zeroInterpreter_zero.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp index e56fa162fda..84fcd7e420d 100644 --- a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp +++ b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp @@ -562,6 +562,12 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { } } + // Already did every pending exception check here. + // If HAS_PENDING_EXCEPTION is true, the interpreter would handle the rest. + if (CheckJNICalls) { + THREAD->clear_pending_jni_exception_check(); + } + // No deoptimized frames on the stack return 0; } From 94ec379c3bcb0a145c22734713057d960f9cb1d4 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:32:20 +0000 Subject: [PATCH 119/253] 8273335: compiler/blackhole tests should not run with interpreter-only VMs Backport-of: 4d25e6f6c7ee855771ab9c05ae85a9d92c866941 --- .../blackhole/BlackholeExistingIntrinsicWarningTest.java | 1 + .../compiler/blackhole/BlackholeExperimentalUnlockTest.java | 1 + .../hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java | 1 + .../jtreg/compiler/blackhole/BlackholeNonEmptyWarningTest.java | 1 + .../jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.java | 1 + .../jtreg/compiler/blackhole/BlackholeNonVoidWarningTest.java | 1 + 6 files changed, 6 insertions(+) diff --git a/test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java b/test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java index 1a1891f808d..8d43b1e85a3 100644 --- a/test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java +++ b/test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java @@ -25,6 +25,7 @@ * @test * @library /test/lib / * @requires vm.flagless + * @requires vm.compMode != "Xint" * @run driver compiler.blackhole.BlackholeExistingIntrinsicWarningTest */ diff --git a/test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java b/test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java index c0be4a53079..226c28251f2 100644 --- a/test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java +++ b/test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java @@ -25,6 +25,7 @@ * @test * @library /test/lib / * @requires vm.flagless + * @requires vm.compMode != "Xint" * @run driver compiler.blackhole.BlackholeExperimentalUnlockTest */ diff --git a/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java b/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java index e0ac62beb94..65c0e84d87d 100644 --- a/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java +++ b/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java @@ -25,6 +25,7 @@ * @test * @library /test/lib / * @requires vm.flagless + * @requires vm.compMode != "Xint" * @run driver compiler.blackhole.BlackholeIntrinsicTest */ diff --git a/test/hotspot/jtreg/compiler/blackhole/BlackholeNonEmptyWarningTest.java b/test/hotspot/jtreg/compiler/blackhole/BlackholeNonEmptyWarningTest.java index 764f39e0a84..43cbdfd773b 100644 --- a/test/hotspot/jtreg/compiler/blackhole/BlackholeNonEmptyWarningTest.java +++ b/test/hotspot/jtreg/compiler/blackhole/BlackholeNonEmptyWarningTest.java @@ -25,6 +25,7 @@ * @test * @library /test/lib / * @requires vm.flagless + * @requires vm.compMode != "Xint" * @run driver compiler.blackhole.BlackholeNonEmptyWarningTest */ diff --git a/test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.java b/test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.java index 7e23fe6a442..f9e12ba3f9d 100644 --- a/test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.java +++ b/test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.java @@ -25,6 +25,7 @@ * @test * @library /test/lib / * @requires vm.flagless + * @requires vm.compMode != "Xint" * @run driver compiler.blackhole.BlackholeNonStaticWarningTest */ diff --git a/test/hotspot/jtreg/compiler/blackhole/BlackholeNonVoidWarningTest.java b/test/hotspot/jtreg/compiler/blackhole/BlackholeNonVoidWarningTest.java index 388485b3715..555f6779124 100644 --- a/test/hotspot/jtreg/compiler/blackhole/BlackholeNonVoidWarningTest.java +++ b/test/hotspot/jtreg/compiler/blackhole/BlackholeNonVoidWarningTest.java @@ -25,6 +25,7 @@ * @test * @library /test/lib / * @requires vm.flagless + * @requires vm.compMode != "Xint" * @run driver compiler.blackhole.BlackholeNonVoidWarningTest */ From 88d2053798ed73673874cc46d21f4c26533426ed Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:33:08 +0000 Subject: [PATCH 120/253] 8273807: Zero: Drop incorrect test block from compiler/startup/NumCompilerThreadsCheck.java Backport-of: 1c5de8b86b038f5d5c313c504a8868e36fc80bde --- .../jtreg/compiler/startup/NumCompilerThreadsCheck.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/hotspot/jtreg/compiler/startup/NumCompilerThreadsCheck.java b/test/hotspot/jtreg/compiler/startup/NumCompilerThreadsCheck.java index a8d1b279835..9761002c051 100644 --- a/test/hotspot/jtreg/compiler/startup/NumCompilerThreadsCheck.java +++ b/test/hotspot/jtreg/compiler/startup/NumCompilerThreadsCheck.java @@ -47,11 +47,6 @@ public static void main(String[] args) throws Exception { String expectedOutput = "outside the allowed range"; out.shouldContain(expectedOutput); - - if (Platform.isZero()) { - String expectedLowWaterMarkText = "must be at least 0"; - out.shouldContain(expectedLowWaterMarkText); - } } } From e6675c789c0dd41e444dfcb74fa7791912a6949b Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:33:59 +0000 Subject: [PATCH 121/253] 8273806: compiler/cpuflags/TestSSE4Disabled.java should test for CPU feature explicitly Backport-of: 09ecb11927f0042ddc0c5c23d747b275ab70b36b --- test/hotspot/jtreg/compiler/cpuflags/TestSSE4Disabled.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/cpuflags/TestSSE4Disabled.java b/test/hotspot/jtreg/compiler/cpuflags/TestSSE4Disabled.java index 812c7061a65..ae1dae0631f 100644 --- a/test/hotspot/jtreg/compiler/cpuflags/TestSSE4Disabled.java +++ b/test/hotspot/jtreg/compiler/cpuflags/TestSSE4Disabled.java @@ -24,7 +24,7 @@ /* * @test TestSSE4Disabled * @bug 8158214 - * @requires (vm.simpleArch == "x64") + * @requires vm.cpu.features ~= ".*sse4.*" * @summary Test correct execution without SSE 4. * * @run main/othervm -Xcomp -XX:UseSSE=3 compiler.cpuflags.TestSSE4Disabled From 609c919ffcdc3cb2dfb0df592979ddfd1fc099e6 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:34:45 +0000 Subject: [PATCH 122/253] 8273894: ConcurrentModificationException raised every time ReferralsCache drops referral Backport-of: 2166ed136917bb68f8155a25e4f4a6c5c7115566 --- .../sun/security/krb5/internal/ReferralsCache.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/ReferralsCache.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/ReferralsCache.java index 36d5fbc3fa0..c8f7414877b 100644 --- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/ReferralsCache.java +++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/ReferralsCache.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -174,10 +175,11 @@ private static void pruneExpired(ReferralCacheKey k) { Date now = new Date(); Map entries = referralsMap.get(k); if (entries != null) { - for (Entry mapEntry : - entries.entrySet()) { + Iterator> it = entries.entrySet().iterator(); + while (it.hasNext()) { + Entry mapEntry = it.next(); if (mapEntry.getValue().getCreds().getEndTime().before(now)) { - entries.remove(mapEntry.getKey()); + it.remove(); } } } From 1e9126a627f93d987ff2e2f70f528e5a8abd029d Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:35:16 +0000 Subject: [PATCH 123/253] 8272836: Limit run time for java/lang/invoke/LFCaching tests Backport-of: a3308af0605bf936d9a9fb7093787a315ccc1e2a --- test/jdk/java/lang/invoke/LFCaching/LambdaFormTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/java/lang/invoke/LFCaching/LambdaFormTestCase.java b/test/jdk/java/lang/invoke/LFCaching/LambdaFormTestCase.java index c23254e6084..afece8bdb17 100644 --- a/test/jdk/java/lang/invoke/LFCaching/LambdaFormTestCase.java +++ b/test/jdk/java/lang/invoke/LFCaching/LambdaFormTestCase.java @@ -46,7 +46,7 @@ public abstract class LambdaFormTestCase { private static final long TIMEOUT = Helper.IS_THOROUGH ? - 0L : (long) (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) * 0.9); + 0L : (long) (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) * 0.2); /** * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is From b002cc94cc3d631b2fd1150cddf9d4238d892c75 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:36:00 +0000 Subject: [PATCH 124/253] 8273315: Parallelize and increase timeouts for java/foreign/TestMatrix.java test Backport-of: dc33bd8b6cfa9a9cd71d7065d284a807774750a2 --- test/jdk/java/foreign/TestMatrix.java | 315 +++++++++++++++++++++----- 1 file changed, 253 insertions(+), 62 deletions(-) diff --git a/test/jdk/java/foreign/TestMatrix.java b/test/jdk/java/foreign/TestMatrix.java index 0c9f4f0e3a0..d5d6072a55f 100644 --- a/test/jdk/java/foreign/TestMatrix.java +++ b/test/jdk/java/foreign/TestMatrix.java @@ -1,255 +1,446 @@ /* - * @test + * Note: to run this test manually, you need to build the tests first to get native + * libraries compiled, and then execute it with plain jtreg, like: + * + * $ bin/jtreg -jdk: \ + * -nativepath:/support/test/jdk/jtreg/native/lib/ \ + * -concurrency:auto \ + * ./test/jdk/java/foreign/TestMatrix.java + */ + +/* + * @test id=UpcallHighArity-FFTT * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" * @modules jdk.incubator.foreign/jdk.internal.foreign - * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity TestUpcall TestDowncall + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TFTT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-FTTT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TTTT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity + */ + +/* @test id=UpcallHighArity-FFTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TFTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-FTTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TTTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity + */ + +/* @test id=UpcallHighArity-FFFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TFFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-FTFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TTFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcallHighArity + */ + +/* @test id=UpcallHighArity-FFFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TFFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-FTFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity - * @run testng/othervm/native + */ + +/* @test id=UpcallHighArity-TTFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity + * + * @run testng/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcallHighArity + */ + +/* @test id=Downcall-FF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestDowncall * - * @run testng/othervm + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * TestDowncall - * @run testng/othervm + */ + +/* @test id=Downcall-TF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestDowncall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * TestDowncall - * @run testng/othervm + */ + +/* @test id=Downcall-FT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestDowncall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * TestDowncall - * @run testng/othervm + */ + +/* @test id=Downcall-TT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestDowncall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * TestDowncall + */ + +/* @test id=Upcall-TFTT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall * - * @run testng/othervm - * --enable-native-access=ALL-UNNAMED - * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true - * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true - * TestUpcall - * @run testng/othervm + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-FTTT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-TTTT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcall + */ + +/* @test id=Upcall-TFTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall * - * @run testng/othervm - * --enable-native-access=ALL-UNNAMED - * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true - * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false - * TestUpcall - * @run testng/othervm + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-FTTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-TTTF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcall + */ + +/* @test id=Upcall-TFFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall * - * @run testng/othervm - * --enable-native-access=ALL-UNNAMED - * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true - * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true - * TestUpcall - * @run testng/othervm + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-FTFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-TTFT + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=true * TestUpcall + */ + +/* @test id=Upcall-TFFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall * - * @run testng/othervm - * --enable-native-access=ALL-UNNAMED - * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true - * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false - * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false - * TestUpcall - * @run testng/othervm + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-FTFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_SPEC=false * -Djdk.internal.foreign.ProgrammableUpcallHandler.USE_INTRINSICS=false * TestUpcall - * @run testng/othervm + */ + +/* @test id=Upcall-TTFF + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" + * @modules jdk.incubator.foreign/jdk.internal.foreign + * @build NativeTestHelper CallGeneratorHelper TestUpcall + * + * @run testng/othervm/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.ProgrammableInvoker.USE_SPEC=true * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true From 2a4b0425da204287709e48b699d43402b7e088ee Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 12:36:41 +0000 Subject: [PATCH 125/253] 8273318: Some containers/docker/TestJFREvents.java configs are running out of memory Backport-of: 7d24a3342129d4c71fad0d8d50d20758291d64b7 --- .../jtreg/containers/docker/TestJFREvents.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/hotspot/jtreg/containers/docker/TestJFREvents.java b/test/hotspot/jtreg/containers/docker/TestJFREvents.java index 8e252d16d25..8faa347aa4f 100644 --- a/test/hotspot/jtreg/containers/docker/TestJFREvents.java +++ b/test/hotspot/jtreg/containers/docker/TestJFREvents.java @@ -82,13 +82,14 @@ public static void main(String[] args) throws Exception { } private static void containerInfoTestCase() throws Exception { - // leave one CPU for system and tools, otherwise this test may be unstable - int maxNrOfAvailableCpus = availableCPUs - 1; - for (int i=1; i < maxNrOfAvailableCpus; i = i * 2) { - for (int j=64; j <= 256; j *= 2) { - testContainerInfo(i, j); - } + // Leave one CPU for system and tools, otherwise this test may be unstable. + // Try the memory sizes that were verified by testMemory tests before. + int maxNrOfAvailableCpus = availableCPUs - 1; + for (int cpus = 1; cpus < maxNrOfAvailableCpus; cpus *= 2) { + for (int mem : new int[]{ 200, 500, 1024 }) { + testContainerInfo(cpus, mem); } + } } private static void testContainerInfo(int expectedCPUs, int expectedMemoryMB) throws Exception { From 973911e9a528937d4f3a1a4a0247fa04b0347026 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 14:53:23 +0000 Subject: [PATCH 126/253] 8273314: Add tier4 test groups Backport-of: 1f8af524ffe2d2d1469d8f07887b1f61c6e4d7b8 --- test/hotspot/jtreg/TEST.groups | 7 +++++++ test/jaxp/TEST.groups | 3 +++ test/jdk/TEST.groups | 7 +++++++ test/langtools/TEST.groups | 3 +++ 4 files changed, 20 insertions(+) diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups index 773a5167565..763d28f9679 100644 --- a/test/hotspot/jtreg/TEST.groups +++ b/test/hotspot/jtreg/TEST.groups @@ -461,6 +461,13 @@ tier3 = \ :hotspot_tier3_runtime \ :tier3_gc_shenandoah +# Everything that is not in other tiers, but not apps +tier4 = \ + :hotspot_all_no_apps \ + -:tier1 \ + -:tier2 \ + -:tier3 + hotspot_tier2_runtime = \ runtime/ \ -runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java \ diff --git a/test/jaxp/TEST.groups b/test/jaxp/TEST.groups index 91d4e999021..0b67ed428b9 100644 --- a/test/jaxp/TEST.groups +++ b/test/jaxp/TEST.groups @@ -32,5 +32,8 @@ tier2 = \ # No tier 3 tests. tier3 = +# No tier 4 tests. +tier4 = + jaxp_all = \ javax/xml/jaxp diff --git a/test/jdk/TEST.groups b/test/jdk/TEST.groups index dd5b089e9b0..58e7ac3f836 100644 --- a/test/jdk/TEST.groups +++ b/test/jdk/TEST.groups @@ -76,6 +76,13 @@ tier3 = \ :jdk_rmi \ :jdk_jfr_tier3 +# Everything not in other tiers +tier4 = \ + / \ + -:tier1 \ + -:tier2 \ + -:tier3 + ############################################################################### # # Other test definitions; generally smaller granularity than tiers diff --git a/test/langtools/TEST.groups b/test/langtools/TEST.groups index d97a6859535..8df9dcaadf5 100644 --- a/test/langtools/TEST.groups +++ b/test/langtools/TEST.groups @@ -87,3 +87,6 @@ tier2 = \ # No langtools tests are tier 3 either. tier3 = + +# No langtools tests are tier 4 either. +tier4 = From 5e90da94f4af225de1af8c0cd96c800a1924048b Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Mon, 4 Oct 2021 14:54:12 +0000 Subject: [PATCH 127/253] 8274083: Update testing docs to mention tiered testing Backport-of: 971aa353aae51222ca33ebfdd61b91672a6c871a --- doc/testing.html | 14 ++++++++++++++ doc/testing.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/doc/testing.html b/doc/testing.html index 49227421dcf..97960a7e994 100644 --- a/doc/testing.html +++ b/doc/testing.html @@ -27,6 +27,7 @@

Testing the JDK

  • Configuration
  • Test selection