!485 Fix crash in JNI's GetDoubleArrayRegion and SetDoubleArrayRegion

From: @kuenking111 
Reviewed-by: @alexanderbill 
Signed-off-by: @alexanderbill
This commit is contained in:
openeuler-ci-bot 2023-10-26 07:12:58 +00:00 committed by Gitee
commit e610e1a357
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 1951 additions and 5 deletions

View File

@ -0,0 +1,29 @@
From 42bb9ed9c5d4b0c8b07fb184ce1ab26718b376a5 Mon Sep 17 00:00:00 2001
Subject: 8148470: Metadata print routines should not print to tty
---
hotspot/src/share/vm/oops/metadata.hpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hotspot/src/share/vm/oops/metadata.hpp b/hotspot/src/share/vm/oops/metadata.hpp
index 372faa953..34dd66afd 100644
--- a/hotspot/src/share/vm/oops/metadata.hpp
+++ b/hotspot/src/share/vm/oops/metadata.hpp
@@ -60,13 +60,13 @@ class Metadata : public MetaspaceObj {
if (this == NULL)
st->print("NULL");
else
- print_on(tty);
+ print_on(st);
}
void print_value_on_maybe_null(outputStream* st) const {
if (this == NULL)
st->print("NULL");
else
- print_value_on(tty);
+ print_value_on(st);
}
virtual void print_on(outputStream* st) const; // First level print
--
2.22.0

View File

@ -0,0 +1,352 @@
From ba4213c7350e7a145a142d0cbe54718a8c92b93c Mon Sep 17 00:00:00 2001
Subject: 8193682: Infinite loop in ZipOutputStream.close()
---
.../java/util/zip/DeflaterOutputStream.java | 9 +-
.../java/util/zip/GZIPOutputStream.java | 38 +++--
.../java/util/zip/ZipOutputStream.java | 96 ++++++------
jdk/test/java/util/zip/CloseDeflaterTest.java | 147 ++++++++++++++++++
4 files changed, 226 insertions(+), 64 deletions(-)
create mode 100644 jdk/test/java/util/zip/CloseDeflaterTest.java
diff --git a/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java b/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
index a1f768cae..f4cf79693 100644
--- a/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
+++ b/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
@@ -235,9 +235,12 @@ class DeflaterOutputStream extends FilterOutputStream {
*/
public void close() throws IOException {
if (!closed) {
- finish();
- if (usesDefaultDeflater)
- def.end();
+ try {
+ finish();
+ } finally {
+ if (usesDefaultDeflater)
+ def.end();
+ }
out.close();
closed = true;
}
diff --git a/jdk/src/share/classes/java/util/zip/GZIPOutputStream.java b/jdk/src/share/classes/java/util/zip/GZIPOutputStream.java
index 2c1cd409b..1c3f8592e 100644
--- a/jdk/src/share/classes/java/util/zip/GZIPOutputStream.java
+++ b/jdk/src/share/classes/java/util/zip/GZIPOutputStream.java
@@ -154,24 +154,30 @@ class GZIPOutputStream extends DeflaterOutputStream {
*/
public void finish() throws IOException {
if (!def.finished()) {
- def.finish();
- while (!def.finished()) {
- int len = def.deflate(buf, 0, buf.length);
- if (def.finished() && len <= buf.length - TRAILER_SIZE) {
- // last deflater buffer. Fit trailer at the end
- writeTrailer(buf, len);
- len = len + TRAILER_SIZE;
- out.write(buf, 0, len);
- return;
+ try {
+ def.finish();
+ while (!def.finished()) {
+ int len = def.deflate(buf, 0, buf.length);
+ if (def.finished() && len <= buf.length - TRAILER_SIZE) {
+ // last deflater buffer. Fit trailer at the end
+ writeTrailer(buf, len);
+ len = len + TRAILER_SIZE;
+ out.write(buf, 0, len);
+ return;
+ }
+ if (len > 0)
+ out.write(buf, 0, len);
}
- if (len > 0)
- out.write(buf, 0, len);
+ // if we can't fit the trailer at the end of the last
+ // deflater buffer, we write it separately
+ byte[] trailer = new byte[TRAILER_SIZE];
+ writeTrailer(trailer, 0);
+ out.write(trailer);
+ } catch (IOException e) {
+ if (usesDefaultDeflater)
+ def.end();
+ throw e;
}
- // if we can't fit the trailer at the end of the last
- // deflater buffer, we write it separately
- byte[] trailer = new byte[TRAILER_SIZE];
- writeTrailer(trailer, 0);
- out.write(trailer);
}
}
diff --git a/jdk/src/share/classes/java/util/zip/ZipOutputStream.java b/jdk/src/share/classes/java/util/zip/ZipOutputStream.java
index 6b480aa1d..f001ddf00 100644
--- a/jdk/src/share/classes/java/util/zip/ZipOutputStream.java
+++ b/jdk/src/share/classes/java/util/zip/ZipOutputStream.java
@@ -247,59 +247,65 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
public void closeEntry() throws IOException {
ensureOpen();
if (current != null) {
- ZipEntry e = current.entry;
- switch (e.method) {
- case DEFLATED:
- def.finish();
- while (!def.finished()) {
- deflate();
- }
- if ((e.flag & 8) == 0) {
- // verify size, compressed size, and crc-32 settings
- if (e.size != def.getBytesRead()) {
- throw new ZipException(
- "invalid entry size (expected " + e.size +
- " but got " + def.getBytesRead() + " bytes)");
+ try {
+ ZipEntry e = current.entry;
+ switch (e.method) {
+ case DEFLATED:
+ def.finish();
+ while (!def.finished()) {
+ deflate();
}
- if (e.csize != def.getBytesWritten()) {
+ if ((e.flag & 8) == 0) {
+ // verify size, compressed size, and crc-32 settings
+ if (e.size != def.getBytesRead()) {
+ throw new ZipException(
+ "invalid entry size (expected " + e.size +
+ " but got " + def.getBytesRead() + " bytes)");
+ }
+ if (e.csize != def.getBytesWritten()) {
+ throw new ZipException(
+ "invalid entry compressed size (expected " +
+ e.csize + " but got " + def.getBytesWritten() + " bytes)");
+ }
+ if (e.crc != crc.getValue()) {
+ throw new ZipException(
+ "invalid entry CRC-32 (expected 0x" +
+ Long.toHexString(e.crc) + " but got 0x" +
+ Long.toHexString(crc.getValue()) + ")");
+ }
+ } else {
+ e.size = def.getBytesRead();
+ e.csize = def.getBytesWritten();
+ e.crc = crc.getValue();
+ writeEXT(e);
+ }
+ def.reset();
+ written += e.csize;
+ break;
+ case STORED:
+ // we already know that both e.size and e.csize are the same
+ if (e.size != written - locoff) {
throw new ZipException(
- "invalid entry compressed size (expected " +
- e.csize + " but got " + def.getBytesWritten() + " bytes)");
+ "invalid entry size (expected " + e.size +
+ " but got " + (written - locoff) + " bytes)");
}
if (e.crc != crc.getValue()) {
throw new ZipException(
- "invalid entry CRC-32 (expected 0x" +
- Long.toHexString(e.crc) + " but got 0x" +
- Long.toHexString(crc.getValue()) + ")");
+ "invalid entry crc-32 (expected 0x" +
+ Long.toHexString(e.crc) + " but got 0x" +
+ Long.toHexString(crc.getValue()) + ")");
}
- } else {
- e.size = def.getBytesRead();
- e.csize = def.getBytesWritten();
- e.crc = crc.getValue();
- writeEXT(e);
+ break;
+ default:
+ throw new ZipException("invalid compression method");
}
- def.reset();
- written += e.csize;
- break;
- case STORED:
- // we already know that both e.size and e.csize are the same
- if (e.size != written - locoff) {
- throw new ZipException(
- "invalid entry size (expected " + e.size +
- " but got " + (written - locoff) + " bytes)");
- }
- if (e.crc != crc.getValue()) {
- throw new ZipException(
- "invalid entry crc-32 (expected 0x" +
- Long.toHexString(e.crc) + " but got 0x" +
- Long.toHexString(crc.getValue()) + ")");
- }
- break;
- default:
- throw new ZipException("invalid compression method");
+ crc.reset();
+ current = null;
+ } catch (IOException e) {
+ if (usesDefaultDeflater && !(e instanceof ZipException))
+ def.end();
+ throw e;
}
- crc.reset();
- current = null;
}
}
diff --git a/jdk/test/java/util/zip/CloseDeflaterTest.java b/jdk/test/java/util/zip/CloseDeflaterTest.java
new file mode 100644
index 000000000..8aa4960f5
--- /dev/null
+++ b/jdk/test/java/util/zip/CloseDeflaterTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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 8193682
+ * @summary Test Infinite loop while writing on closed GZipOutputStream , ZipOutputStream and JarOutputStream.
+ * @run testng CloseDeflaterTest
+ */
+import java.io.*;
+import java.util.Random;
+import java.util.jar.JarOutputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.ZipOutputStream;
+import java.util.zip.ZipEntry;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import static org.testng.Assert.fail;
+
+
+public class CloseDeflaterTest {
+
+ //number of bytes to write
+ private static final int INPUT_LENGTH= 512;
+ //OutputStream that will throw an exception during a write operation
+ private static OutputStream outStream = new OutputStream() {
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ //throw exception during write
+ throw new IOException();
+ }
+ @Override
+ public void write(byte b[]) throws IOException {}
+ @Override
+ public void write(int b) throws IOException {}
+ };
+ private static byte[] inputBytes = new byte[INPUT_LENGTH];
+ private static Random rand = new Random();
+
+ @DataProvider(name = "testgzipinput")
+ public Object[][] testGZipInput() {
+ //testGZip will close the GZipOutputStream using close() method when the boolean
+ //useCloseMethod is set to true and finish() method if the value is set to false
+ return new Object[][] {
+ { GZIPOutputStream.class, true },
+ { GZIPOutputStream.class, false },
+ };
+ }
+
+ @DataProvider(name = "testzipjarinput")
+ public Object[][] testZipAndJarInput() {
+ //testZipAndJarInput will perfrom write/closeEntry operations on JarOutputStream when the boolean
+ //useJar is set to true and on ZipOutputStream if the value is set to false
+ return new Object[][] {
+ { JarOutputStream.class, true },
+ { ZipOutputStream.class, false },
+ };
+ }
+
+ @BeforeTest
+ public void before_test()
+ {
+ //add inputBytes array with random bytes to write into Zip
+ rand.nextBytes(inputBytes);
+ }
+
+ //Test for infinite loop by writing bytes to closed GZIPOutputStream
+ @Test(dataProvider = "testgzipinput")
+ public void testGZip(Class<?> type, boolean useCloseMethod) throws IOException {
+ GZIPOutputStream zip = new GZIPOutputStream(outStream);
+ try {
+ zip.write(inputBytes, 0, INPUT_LENGTH);
+ //close zip
+ if(useCloseMethod) {
+ zip.close();
+ } else {
+ zip.finish();
+ }
+ } catch (IOException e) {
+ //expected
+ }
+ for (int i = 0; i < 3; i++) {
+ try {
+ //write on a closed GZIPOutputStream
+ zip.write(inputBytes, 0, INPUT_LENGTH);
+ fail("Deflater closed exception not thrown");
+ } catch (NullPointerException e) {
+ //expected , Deflater has been closed exception
+ }
+ }
+ }
+
+ //Test for infinite loop by writing bytes to closed ZipOutputStream/JarOutputStream
+ @Test(dataProvider = "testzipjarinput")
+ public void testZipCloseEntry(Class<?> type,boolean useJar) throws IOException {
+ ZipOutputStream zip = null;
+ if(useJar) {
+ zip = new JarOutputStream(outStream);
+ } else {
+ zip = new ZipOutputStream(outStream);
+ }
+ try {
+ zip.putNextEntry(new ZipEntry(""));
+ } catch (IOException e) {
+ //expected to throw IOException since putNextEntry calls write method
+ }
+ try {
+ zip.write(inputBytes, 0, INPUT_LENGTH);
+ //close zip entry
+ zip.closeEntry();
+ } catch (IOException e) {
+ //expected
+ }
+ for (int i = 0; i < 3; i++) {
+ try {
+ //write on a closed ZipOutputStream
+ zip.write(inputBytes, 0, INPUT_LENGTH);
+ fail("Deflater closed exception not thrown");
+ } catch (NullPointerException e) {
+ //expected , Deflater has been closed exception
+ }
+ }
+ }
+
+}
--
2.22.0

View File

@ -0,0 +1,25 @@
From facc89d6a5776a26193c9321111c8489e4af525f Mon Sep 17 00:00:00 2001
Subject: 8263557: Possible NULL dereference in Arena::destruct_contents()
---
hotspot/src/share/vm/memory/allocation.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/hotspot/src/share/vm/memory/allocation.cpp b/hotspot/src/share/vm/memory/allocation.cpp
index 3cd30a686..abbcc6c49 100644
--- a/hotspot/src/share/vm/memory/allocation.cpp
+++ b/hotspot/src/share/vm/memory/allocation.cpp
@@ -521,7 +521,9 @@ void Arena::destruct_contents() {
// reset size before chop to avoid a rare racing condition
// that can have total arena memory exceed total chunk memory
set_size_in_bytes(0);
- _first->chop();
+ if (_first != NULL) {
+ _first->chop();
+ }
reset();
}
--
2.22.0

View File

@ -0,0 +1,238 @@
From e5bf7f105c0066f770f5cdc65f94410d45d11f0f Mon Sep 17 00:00:00 2001
Subject: 8278794: Infinite loop in DeflaterOutputStream.finish()
---
.../share/classes/java/util/zip/Deflater.java | 10 ++
.../java/util/zip/DeflaterOutputStream.java | 14 +-
.../java/util/zip/ZipOutputStream.java | 4 +-
jdk/test/java/util/zip/CloseDeflaterTest.java | 147 ------------------
4 files changed, 22 insertions(+), 153 deletions(-)
delete mode 100644 jdk/test/java/util/zip/CloseDeflaterTest.java
diff --git a/jdk/src/share/classes/java/util/zip/Deflater.java b/jdk/src/share/classes/java/util/zip/Deflater.java
index 3bb5f9901..bffa397d9 100644
--- a/jdk/src/share/classes/java/util/zip/Deflater.java
+++ b/jdk/src/share/classes/java/util/zip/Deflater.java
@@ -559,6 +559,16 @@ class Deflater {
throw new NullPointerException("Deflater has been closed");
}
+ /**
+ * Returns the value of 'finish' flag.
+ * 'finish' will be set to true if def.finish() method is called.
+ */
+ boolean shouldFinish() {
+ synchronized (zsRef) {
+ return finish;
+ }
+ }
+
private static native void initIDs();
private native static long init(int level, int strategy, boolean nowrap);
private native static void setDictionary(long addr, byte[] b, int off, int len);
diff --git a/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java b/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
index f4cf79693..c698a0147 100644
--- a/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
+++ b/jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2022, 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
@@ -221,9 +221,15 @@ class DeflaterOutputStream extends FilterOutputStream {
*/
public void finish() throws IOException {
if (!def.finished()) {
- def.finish();
- while (!def.finished()) {
- deflate();
+ try{
+ def.finish();
+ while (!def.finished()) {
+ deflate();
+ }
+ } catch(IOException e) {
+ if (usesDefaultDeflater)
+ def.end();
+ throw e;
}
}
}
diff --git a/jdk/src/share/classes/java/util/zip/ZipOutputStream.java b/jdk/src/share/classes/java/util/zip/ZipOutputStream.java
index f001ddf00..cd9194276 100644
--- a/jdk/src/share/classes/java/util/zip/ZipOutputStream.java
+++ b/jdk/src/share/classes/java/util/zip/ZipOutputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2022, 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
@@ -302,7 +302,7 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
crc.reset();
current = null;
} catch (IOException e) {
- if (usesDefaultDeflater && !(e instanceof ZipException))
+ if (def.shouldFinish() && usesDefaultDeflater && !(e instanceof ZipException))
def.end();
throw e;
}
diff --git a/jdk/test/java/util/zip/CloseDeflaterTest.java b/jdk/test/java/util/zip/CloseDeflaterTest.java
deleted file mode 100644
index 8aa4960f5..000000000
--- a/jdk/test/java/util/zip/CloseDeflaterTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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 8193682
- * @summary Test Infinite loop while writing on closed GZipOutputStream , ZipOutputStream and JarOutputStream.
- * @run testng CloseDeflaterTest
- */
-import java.io.*;
-import java.util.Random;
-import java.util.jar.JarOutputStream;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.ZipOutputStream;
-import java.util.zip.ZipEntry;
-
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import static org.testng.Assert.fail;
-
-
-public class CloseDeflaterTest {
-
- //number of bytes to write
- private static final int INPUT_LENGTH= 512;
- //OutputStream that will throw an exception during a write operation
- private static OutputStream outStream = new OutputStream() {
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- //throw exception during write
- throw new IOException();
- }
- @Override
- public void write(byte b[]) throws IOException {}
- @Override
- public void write(int b) throws IOException {}
- };
- private static byte[] inputBytes = new byte[INPUT_LENGTH];
- private static Random rand = new Random();
-
- @DataProvider(name = "testgzipinput")
- public Object[][] testGZipInput() {
- //testGZip will close the GZipOutputStream using close() method when the boolean
- //useCloseMethod is set to true and finish() method if the value is set to false
- return new Object[][] {
- { GZIPOutputStream.class, true },
- { GZIPOutputStream.class, false },
- };
- }
-
- @DataProvider(name = "testzipjarinput")
- public Object[][] testZipAndJarInput() {
- //testZipAndJarInput will perfrom write/closeEntry operations on JarOutputStream when the boolean
- //useJar is set to true and on ZipOutputStream if the value is set to false
- return new Object[][] {
- { JarOutputStream.class, true },
- { ZipOutputStream.class, false },
- };
- }
-
- @BeforeTest
- public void before_test()
- {
- //add inputBytes array with random bytes to write into Zip
- rand.nextBytes(inputBytes);
- }
-
- //Test for infinite loop by writing bytes to closed GZIPOutputStream
- @Test(dataProvider = "testgzipinput")
- public void testGZip(Class<?> type, boolean useCloseMethod) throws IOException {
- GZIPOutputStream zip = new GZIPOutputStream(outStream);
- try {
- zip.write(inputBytes, 0, INPUT_LENGTH);
- //close zip
- if(useCloseMethod) {
- zip.close();
- } else {
- zip.finish();
- }
- } catch (IOException e) {
- //expected
- }
- for (int i = 0; i < 3; i++) {
- try {
- //write on a closed GZIPOutputStream
- zip.write(inputBytes, 0, INPUT_LENGTH);
- fail("Deflater closed exception not thrown");
- } catch (NullPointerException e) {
- //expected , Deflater has been closed exception
- }
- }
- }
-
- //Test for infinite loop by writing bytes to closed ZipOutputStream/JarOutputStream
- @Test(dataProvider = "testzipjarinput")
- public void testZipCloseEntry(Class<?> type,boolean useJar) throws IOException {
- ZipOutputStream zip = null;
- if(useJar) {
- zip = new JarOutputStream(outStream);
- } else {
- zip = new ZipOutputStream(outStream);
- }
- try {
- zip.putNextEntry(new ZipEntry(""));
- } catch (IOException e) {
- //expected to throw IOException since putNextEntry calls write method
- }
- try {
- zip.write(inputBytes, 0, INPUT_LENGTH);
- //close zip entry
- zip.closeEntry();
- } catch (IOException e) {
- //expected
- }
- for (int i = 0; i < 3; i++) {
- try {
- //write on a closed ZipOutputStream
- zip.write(inputBytes, 0, INPUT_LENGTH);
- fail("Deflater closed exception not thrown");
- } catch (NullPointerException e) {
- //expected , Deflater has been closed exception
- }
- }
- }
-
-}
--
2.22.0

View File

@ -0,0 +1,33 @@
From 42884748f75ef4ea6e0cc8e537c831cb258961f8 Mon Sep 17 00:00:00 2001
Subject: 8285516: clearPassword should be called in a finally try block
---
.../share/classes/sun/security/pkcs12/PKCS12KeyStore.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java b/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
index 0457b1e5c..63e0afc2a 100644
--- a/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
+++ b/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
@@ -837,14 +837,14 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
{
SecretKey skey = null;
+ PBEKeySpec keySpec = new PBEKeySpec(password);
try {
- PBEKeySpec keySpec = new PBEKeySpec(password);
SecretKeyFactory skFac = SecretKeyFactory.getInstance("PBE");
skey = skFac.generateSecret(keySpec);
- keySpec.clearPassword();
} catch (Exception e) {
- throw new IOException("getSecretKey failed: " +
- e.getMessage(), e);
+ throw new IOException("getSecretKey failed: " + e.getMessage(), e);
+ } finally {
+ keySpec.clearPassword();
}
return skey;
}
--
2.22.0

View File

@ -0,0 +1,21 @@
From 1b17272792968ae8b888c7ccb99133a4aee6b97f Mon Sep 17 00:00:00 2001
Subject: 8293344: JDK-8242181 broke stack printing for non-attached threads
---
hotspot/src/share/vm/utilities/elfFile.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/hotspot/src/share/vm/utilities/elfFile.cpp b/hotspot/src/share/vm/utilities/elfFile.cpp
index 81bd44109..448963b2d 100644
--- a/hotspot/src/share/vm/utilities/elfFile.cpp
+++ b/hotspot/src/share/vm/utilities/elfFile.cpp
@@ -318,7 +318,6 @@ bool ElfFile::specifies_noexecstack() {
bool ElfFile::get_source_info(const uint32_t offset_in_library, char* filename, const size_t filename_len,
int* line, bool is_pc_after_call) {
- ResourceMark rm;
if (!load_dwarf_file()) {
// Some ELF libraries do not provide separate .debuginfo files. Check if the current ELF file has the required
// DWARF sections. If so, treat the current ELF file as DWARF file.
--
2.22.0

View File

@ -0,0 +1,338 @@
From 44a22ec75a0ef4200ba824e9e00b56b735b911a0 Mon Sep 17 00:00:00 2001
Subject: 8294906: Memory leak in PKCS11 NSS TLS server
---
.../pkcs11/P11TlsKeyMaterialGenerator.java | 14 ++--
.../crypto/provider/TLS/TestKeyMaterial.java | 31 ++++++++-
.../sun/crypto/provider/TLS/keymatdata.txt | 34 ++++++++++
.../security/pkcs11/tls/TestKeyMaterial.java | 65 +++++++++++++------
.../sun/security/pkcs11/tls/keymatdata.txt | 34 ++++++++++
5 files changed, 151 insertions(+), 27 deletions(-)
diff --git a/jdk/src/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java b/jdk/src/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java
index f6848278c..4242ff756 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2022, 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
@@ -193,15 +193,19 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi {
SecretKey clientMacKey, serverMacKey;
// The MAC size may be zero for GCM mode.
- //
- // PKCS11 does not support GCM mode as the author made the comment,
- // so the macBits is unlikely to be zero. It's only a place holder.
if (macBits != 0) {
clientMacKey = P11Key.secretKey
(session, out.hClientMacSecret, "MAC", macBits, attributes);
serverMacKey = P11Key.secretKey
(session, out.hServerMacSecret, "MAC", macBits, attributes);
} else {
+ // NSS allocates MAC keys even if macBits is zero
+ if (out.hClientMacSecret != CK_INVALID_HANDLE) {
+ token.p11.C_DestroyObject(session.id(), out.hClientMacSecret);
+ }
+ if (out.hServerMacSecret != CK_INVALID_HANDLE) {
+ token.p11.C_DestroyObject(session.id(), out.hServerMacSecret);
+ }
clientMacKey = null;
serverMacKey = null;
}
@@ -213,6 +217,8 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi {
serverCipherKey = P11Key.secretKey(session, out.hServerKey,
cipherAlgorithm, expandedKeyBits, attributes);
} else {
+ assert out.hClientKey == 0;
+ assert out.hServerKey == 0;
clientCipherKey = null;
serverCipherKey = null;
}
diff --git a/jdk/test/com/sun/crypto/provider/TLS/TestKeyMaterial.java b/jdk/test/com/sun/crypto/provider/TLS/TestKeyMaterial.java
index 8874070f4..6569c0c4f 100644
--- a/jdk/test/com/sun/crypto/provider/TLS/TestKeyMaterial.java
+++ b/jdk/test/com/sun/crypto/provider/TLS/TestKeyMaterial.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -60,6 +60,7 @@ public class TestKeyMaterial extends Utils {
byte[] clientRandom = null;
byte[] serverRandom = null;
String cipherAlgorithm = null;
+ String hashAlgorithm = null; // TLS1.2+ only
int keyLength = 0;
int expandedKeyLength = 0;
int ivLength = 0;
@@ -93,6 +94,8 @@ public class TestKeyMaterial extends Utils {
serverRandom = parse(data);
} else if (line.startsWith("km-cipalg:")) {
cipherAlgorithm = data;
+ } else if (line.startsWith("km-hashalg:")) {
+ hashAlgorithm = data;
} else if (line.startsWith("km-keylen:")) {
keyLength = Integer.parseInt(data);
} else if (line.startsWith("km-explen:")) {
@@ -118,14 +121,36 @@ public class TestKeyMaterial extends Utils {
n++;
KeyGenerator kg =
- KeyGenerator.getInstance("SunTlsKeyMaterial", provider);
+ KeyGenerator.getInstance(minor == 3 ?
+ "SunTls12KeyMaterial" :
+ "SunTlsKeyMaterial", provider);
SecretKey masterKey =
new SecretKeySpec(master, "TlsMasterSecret");
+ int prfHashLength, prfBlockSize;
+
+ if (hashAlgorithm != null) {
+ switch (hashAlgorithm) {
+ case "SHA-256":
+ prfHashLength = 32;
+ prfBlockSize = 64;
+ break;
+ case "SHA-384":
+ prfHashLength = 48;
+ prfBlockSize = 128;
+ break;
+ default:
+ throw new RuntimeException("Unexpected hashalg: " +
+ hashAlgorithm);
+ }
+ } else {
+ prfHashLength = -1;
+ prfBlockSize = -1;
+ }
TlsKeyMaterialParameterSpec spec =
new TlsKeyMaterialParameterSpec(masterKey, major, minor,
clientRandom, serverRandom, cipherAlgorithm,
keyLength, expandedKeyLength, ivLength, macLength,
- null, -1, -1);
+ hashAlgorithm, prfHashLength, prfBlockSize);
kg.init(spec);
TlsKeyMaterialSpec result =
diff --git a/jdk/test/com/sun/crypto/provider/TLS/keymatdata.txt b/jdk/test/com/sun/crypto/provider/TLS/keymatdata.txt
index 391f30000..a3ff869b6 100644
--- a/jdk/test/com/sun/crypto/provider/TLS/keymatdata.txt
+++ b/jdk/test/com/sun/crypto/provider/TLS/keymatdata.txt
@@ -3646,3 +3646,37 @@ km-civ: 17:bd:47:89:54:be:04:23
km-siv: 34:8a:e8:24:84:38:c4:e1
km-cmackey: e8:f0:b5:7b:a7:cc:2f:5e:43:ef:d3:dd:4e:8c:f9:6f:51:d7:84:df
km-smackey: fc:0c:77:20:c2:28:d3:11:ba:57:13:d8:0b:2d:f1:30:89:c6:35:69
+km-master: f1:05:15:45:33:be:50:d6:88:0b:03:bb:88:9b:ef:d4:3b:98:aa:40:13:71:3c:1c:d9:df:34:c7:50:75:ad:5c:0a:d4:fe:ed:d5:58:6b:ff:2b:ce:c6:12:bc:6b:7e:dc
+km-major: 3
+km-minor: 3
+km-crandom: 42:f3:36:8e:9d:c9:69:3e:c1:8a:38:d3:e0:ec:2b:58:c2:e0:0c:de:4f:f3:af:51:d2:5c:bc:b2:c3:3b:1e:56
+km-srandom: 42:f3:36:8e:fa:fd:23:3e:fd:f9:bc:88:3c:98:93:f3:c3:1d:9c:2a:4a:3b:02:a7:40:d4:64:04:59:e9:65:97
+km-cipalg: AES
+km-hashalg: SHA-256
+km-keylen: 16
+km-explen: 0
+km-ivlen: 4
+km-maclen: 0
+km-ccipkey: 60:7a:45:a9:6e:76:58:ea:d9:44:c5:25:f8:92:f1:26
+km-scipkey: 42:c0:ed:75:a2:51:21:7c:50:74:9d:78:9a:f7:35:2b
+km-civ: a1:3c:3e:4a
+km-siv: 85:ab:ee:70
+km-cmackey: (null)
+km-smackey: (null)
+km-master: f1:05:15:45:33:be:50:d6:88:0b:03:bb:88:9b:ef:d4:3b:98:aa:40:13:71:3c:1c:d9:df:34:c7:50:75:ad:5c:0a:d4:fe:ed:d5:58:6b:ff:2b:ce:c6:12:bc:6b:7e:dc
+km-major: 3
+km-minor: 3
+km-crandom: 42:f3:36:8e:9d:c9:69:3e:c1:8a:38:d3:e0:ec:2b:58:c2:e0:0c:de:4f:f3:af:51:d2:5c:bc:b2:c3:3b:1e:56
+km-srandom: 42:f3:36:8e:fa:fd:23:3e:fd:f9:bc:88:3c:98:93:f3:c3:1d:9c:2a:4a:3b:02:a7:40:d4:64:04:59:e9:65:97
+km-cipalg: AES
+km-hashalg: SHA-384
+km-keylen: 32
+km-explen: 0
+km-ivlen: 4
+km-maclen: 0
+km-ccipkey: 3c:03:17:61:1e:88:4a:aa:01:4c:ac:6c:f8:bb:91:c3:0e:ec:57:c7:bf:07:ff:eb:49:22:f9:80:12:64:72:2a
+km-scipkey: f8:00:8e:b2:dc:25:98:f1:97:00:55:28:60:a3:65:da:42:89:18:bb:40:94:53:d2:75:2a:29:e5:aa:94:1d:7a
+km-civ: 24:02:76:6f
+km-siv: 3b:6d:33:5a
+km-cmackey: (null)
+km-smackey: (null)
\ No newline at end of file
diff --git a/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java b/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java
index 534398a1a..e138a5b1d 100644
--- a/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java
+++ b/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2022, 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
@@ -21,9 +21,9 @@
* questions.
*/
-/**
+/*
* @test
- * @bug 6316539
+ * @bug 6316539 8136355 8294906
* @summary Known-answer-test for TlsKeyMaterial generator
* @author Andreas Sterbenz
* @library ..
@@ -34,12 +34,16 @@
import java.io.BufferedReader;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.security.InvalidAlgorithmParameterException;
import java.security.Provider;
+import java.security.ProviderException;
import java.util.Arrays;
+
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
+
import sun.security.internal.spec.TlsKeyMaterialParameterSpec;
import sun.security.internal.spec.TlsKeyMaterialSpec;
@@ -48,6 +52,7 @@ public class TestKeyMaterial extends PKCS11Test {
private static final int PREFIX_LENGTH = "km-master: ".length();
public static void main(String[] args) throws Exception {
+ System.out.println("NSS Version: " + getNSSVersion());
main(new TestKeyMaterial(), args);
}
@@ -70,6 +75,7 @@ public class TestKeyMaterial extends PKCS11Test {
byte[] clientRandom = null;
byte[] serverRandom = null;
String cipherAlgorithm = null;
+ String hashAlgorithm = null; // TLS1.2+ only
int keyLength = 0;
int expandedKeyLength = 0;
int ivLength = 0;
@@ -103,6 +109,8 @@ public class TestKeyMaterial extends PKCS11Test {
serverRandom = parse(data);
} else if (line.startsWith("km-cipalg:")) {
cipherAlgorithm = data;
+ } else if (line.startsWith("km-hashalg:")) {
+ hashAlgorithm = data;
} else if (line.startsWith("km-keylen:")) {
keyLength = Integer.parseInt(data);
} else if (line.startsWith("km-explen:")) {
@@ -128,30 +136,47 @@ public class TestKeyMaterial extends PKCS11Test {
n++;
KeyGenerator kg =
- KeyGenerator.getInstance("SunTlsKeyMaterial", provider);
+ KeyGenerator.getInstance(minor == 3 ?
+ "SunTls12KeyMaterial" :
+ "SunTlsKeyMaterial", provider);
SecretKey masterKey =
new SecretKeySpec(master, "TlsMasterSecret");
+ // prfHashLength and prfBlockSize are ignored by PKCS11 provider
TlsKeyMaterialParameterSpec spec =
new TlsKeyMaterialParameterSpec(masterKey, major, minor,
clientRandom, serverRandom, cipherAlgorithm,
keyLength, expandedKeyLength, ivLength, macLength,
- null, -1, -1);
-
- kg.init(spec);
- TlsKeyMaterialSpec result =
- (TlsKeyMaterialSpec)kg.generateKey();
- match(lineNumber, clientCipherBytes,
- result.getClientCipherKey(), cipherAlgorithm);
- match(lineNumber, serverCipherBytes,
- result.getServerCipherKey(), cipherAlgorithm);
- match(lineNumber, clientIv, result.getClientIv(), "");
- match(lineNumber, serverIv, result.getServerIv(), "");
- match(lineNumber, clientMacBytes, result.getClientMacKey(), "");
- match(lineNumber, serverMacBytes, result.getServerMacKey(), "");
-
- } else {
+ hashAlgorithm, -1 /*ignored*/, -1 /*ignored*/);
+
+ try {
+ kg.init(spec);
+ TlsKeyMaterialSpec result =
+ (TlsKeyMaterialSpec)kg.generateKey();
+ match(lineNumber, clientCipherBytes,
+ result.getClientCipherKey(), cipherAlgorithm);
+ match(lineNumber, serverCipherBytes,
+ result.getServerCipherKey(), cipherAlgorithm);
+ match(lineNumber, clientIv, result.getClientIv(), "");
+ match(lineNumber, serverIv, result.getServerIv(), "");
+ match(lineNumber, clientMacBytes, result.getClientMacKey(), "");
+ match(lineNumber, serverMacBytes, result.getServerMacKey(), "");
+ } catch (ProviderException pe) {
+ if (provider.getName().indexOf("NSS") != -1) {
+ Throwable t = pe.getCause();
+ if (expandedKeyLength != 0
+ && t.getMessage().indexOf(
+ "CKR_MECHANISM_PARAM_INVALID") != -1) {
+ // NSS removed support for export-grade cipher suites in 3.28,
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=1252849
+ System.out.println("Ignore known NSS failure on CKR_MECHANISM_PARAM_INVALID");
+ continue;
+ }
+ }
+ throw pe;
+ }
+ } else {
throw new Exception("Unknown line: " + line);
- }
+ }
}
if (n == 0) {
throw new Exception("no tests");
diff --git a/jdk/test/sun/security/pkcs11/tls/keymatdata.txt b/jdk/test/sun/security/pkcs11/tls/keymatdata.txt
index 391f30000..1d1ee6369 100644
--- a/jdk/test/sun/security/pkcs11/tls/keymatdata.txt
+++ b/jdk/test/sun/security/pkcs11/tls/keymatdata.txt
@@ -3646,3 +3646,37 @@ km-civ: 17:bd:47:89:54:be:04:23
km-siv: 34:8a:e8:24:84:38:c4:e1
km-cmackey: e8:f0:b5:7b:a7:cc:2f:5e:43:ef:d3:dd:4e:8c:f9:6f:51:d7:84:df
km-smackey: fc:0c:77:20:c2:28:d3:11:ba:57:13:d8:0b:2d:f1:30:89:c6:35:69
+km-master: f1:05:15:45:33:be:50:d6:88:0b:03:bb:88:9b:ef:d4:3b:98:aa:40:13:71:3c:1c:d9:df:34:c7:50:75:ad:5c:0a:d4:fe:ed:d5:58:6b:ff:2b:ce:c6:12:bc:6b:7e:dc
+km-major: 3
+km-minor: 3
+km-crandom: 42:f3:36:8e:9d:c9:69:3e:c1:8a:38:d3:e0:ec:2b:58:c2:e0:0c:de:4f:f3:af:51:d2:5c:bc:b2:c3:3b:1e:56
+km-srandom: 42:f3:36:8e:fa:fd:23:3e:fd:f9:bc:88:3c:98:93:f3:c3:1d:9c:2a:4a:3b:02:a7:40:d4:64:04:59:e9:65:97
+km-cipalg: AES
+km-hashalg: SHA-256
+km-keylen: 16
+km-explen: 0
+km-ivlen: 4
+km-maclen: 0
+km-ccipkey: 60:7a:45:a9:6e:76:58:ea:d9:44:c5:25:f8:92:f1:26
+km-scipkey: 42:c0:ed:75:a2:51:21:7c:50:74:9d:78:9a:f7:35:2b
+km-civ: a1:3c:3e:4a
+km-siv: 85:ab:ee:70
+km-cmackey: (null)
+km-smackey: (null)
+km-master: f1:05:15:45:33:be:50:d6:88:0b:03:bb:88:9b:ef:d4:3b:98:aa:40:13:71:3c:1c:d9:df:34:c7:50:75:ad:5c:0a:d4:fe:ed:d5:58:6b:ff:2b:ce:c6:12:bc:6b:7e:dc
+km-major: 3
+km-minor: 3
+km-crandom: 42:f3:36:8e:9d:c9:69:3e:c1:8a:38:d3:e0:ec:2b:58:c2:e0:0c:de:4f:f3:af:51:d2:5c:bc:b2:c3:3b:1e:56
+km-srandom: 42:f3:36:8e:fa:fd:23:3e:fd:f9:bc:88:3c:98:93:f3:c3:1d:9c:2a:4a:3b:02:a7:40:d4:64:04:59:e9:65:97
+km-cipalg: AES
+km-hashalg: SHA-384
+km-keylen: 32
+km-explen: 0
+km-ivlen: 4
+km-maclen: 0
+km-ccipkey: 3c:03:17:61:1e:88:4a:aa:01:4c:ac:6c:f8:bb:91:c3:0e:ec:57:c7:bf:07:ff:eb:49:22:f9:80:12:64:72:2a
+km-scipkey: f8:00:8e:b2:dc:25:98:f1:97:00:55:28:60:a3:65:da:42:89:18:bb:40:94:53:d2:75:2a:29:e5:aa:94:1d:7a
+km-civ: 24:02:76:6f
+km-siv: 3b:6d:33:5a
+km-cmackey: (null)
+km-smackey: (null)
--
2.22.0

View File

@ -0,0 +1,366 @@
From 941ebd7303bce4242121cc2173d5fd6dcff2226a Mon Sep 17 00:00:00 2001
Subject: 8312065: Socket.connect does not timeout when profiling
---
jdk/src/aix/native/java/net/aix_close.c | 56 +++++++++---------
jdk/src/solaris/native/java/net/bsd_close.c | 57 ++++++++++---------
jdk/src/solaris/native/java/net/linux_close.c | 57 ++++++++++---------
3 files changed, 86 insertions(+), 84 deletions(-)
diff --git a/jdk/src/aix/native/java/net/aix_close.c b/jdk/src/aix/native/java/net/aix_close.c
index 90d57b42f..3402293c6 100644
--- a/jdk/src/aix/native/java/net/aix_close.c
+++ b/jdk/src/aix/native/java/net/aix_close.c
@@ -53,8 +53,8 @@
#include <sys/uio.h>
#include <unistd.h>
#include <errno.h>
-
#include <sys/poll.h>
+#include "jvm.h"
/*
* Stack allocated by thread when doing blocking operation
@@ -376,61 +376,61 @@ int NET_SocketClose(int fd) {
/************** Basic I/O operations here ***************/
/*
- * Macro to perform a blocking IO operation. Restarts
- * automatically if interrupted by signal (other than
- * our wakeup signal)
+ * Macro to perform a blocking IO operation.
+ * If interrupted by signal (other than our wakeup signal), and if RETRY is true,
+ * then restarts automatically
*/
-#define BLOCKING_IO_RETURN_INT(FD, FUNC) { \
- int ret; \
- threadEntry_t self; \
- fdEntry_t *fdEntry = getFdEntry(FD); \
- if (fdEntry == NULL) { \
- errno = EBADF; \
- return -1; \
- } \
- do { \
- startOp(fdEntry, &self); \
- ret = FUNC; \
- endOp(fdEntry, &self); \
- } while (ret == -1 && errno == EINTR); \
- return ret; \
+#define BLOCKING_IO_RETURN_INT(FD, FUNC, RETRY) { \
+ int ret; \
+ threadEntry_t self; \
+ fdEntry_t *fdEntry = getFdEntry(FD); \
+ if (fdEntry == NULL) { \
+ errno = EBADF; \
+ return -1; \
+ } \
+ do { \
+ startOp(fdEntry, &self); \
+ ret = FUNC; \
+ endOp(fdEntry, &self); \
+ } while ((RETRY) && ret == -1 && errno == EINTR); \
+ return ret; \
}
int NET_Read(int s, void* buf, size_t len) {
- BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
+ BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0), JNI_TRUE);
}
int NET_NonBlockingRead(int s, void* buf, size_t len) {
- BLOCKING_IO_RETURN_INT(s, recv(s, buf, len, MSG_NONBLOCK));
+ BLOCKING_IO_RETURN_INT(s, recv(s, buf, len, MSG_NONBLOCK), JNI_TRUE);
}
int NET_ReadV(int s, const struct iovec * vector, int count) {
- BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
+ BLOCKING_IO_RETURN_INT( s, readv(s, vector, count), JNI_TRUE);
}
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
struct sockaddr *from, int *fromlen) {
socklen_t socklen = *fromlen;
- BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen) );
+ BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen), JNI_TRUE);
*fromlen = socklen;
}
int NET_Send(int s, void *msg, int len, unsigned int flags) {
- BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
+ BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags), JNI_TRUE);
}
int NET_WriteV(int s, const struct iovec * vector, int count) {
- BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
+ BLOCKING_IO_RETURN_INT( s, writev(s, vector, count), JNI_TRUE);
}
int NET_SendTo(int s, const void *msg, int len, unsigned int
flags, const struct sockaddr *to, int tolen) {
- BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
+ BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen), JNI_TRUE);
}
int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
socklen_t socklen = *addrlen;
- BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen) );
+ BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen), JNI_TRUE);
*addrlen = socklen;
}
@@ -490,13 +490,13 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
- BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
+ BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout), JNI_FALSE);
}
#else
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
BLOCKING_IO_RETURN_INT( s-1,
- select(s, readfds, writefds, exceptfds, timeout) );
+ select(s, readfds, writefds, exceptfds, timeout), JNI_FALSE);
}
#endif
diff --git a/jdk/src/solaris/native/java/net/bsd_close.c b/jdk/src/solaris/native/java/net/bsd_close.c
index 89a20707c..37a6e5688 100644
--- a/jdk/src/solaris/native/java/net/bsd_close.c
+++ b/jdk/src/solaris/native/java/net/bsd_close.c
@@ -39,6 +39,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/poll.h>
+#include "jvm.h"
/*
* Stack allocated by thread when doing blocking operation
@@ -347,55 +348,55 @@ int NET_SocketClose(int fd) {
/************** Basic I/O operations here ***************/
/*
- * Macro to perform a blocking IO operation. Restarts
- * automatically if interrupted by signal (other than
- * our wakeup signal)
+ * Macro to perform a blocking IO operation.
+ * If interrupted by signal (other than our wakeup signal), and if RETRY is true,
+ * then restarts automatically
*/
-#define BLOCKING_IO_RETURN_INT(FD, FUNC) { \
- int ret; \
- threadEntry_t self; \
- fdEntry_t *fdEntry = getFdEntry(FD); \
- if (fdEntry == NULL) { \
- errno = EBADF; \
- return -1; \
- } \
- do { \
- startOp(fdEntry, &self); \
- ret = FUNC; \
- endOp(fdEntry, &self); \
- } while (ret == -1 && errno == EINTR); \
- return ret; \
+#define BLOCKING_IO_RETURN_INT(FD, FUNC, RETRY) { \
+ int ret; \
+ threadEntry_t self; \
+ fdEntry_t *fdEntry = getFdEntry(FD); \
+ if (fdEntry == NULL) { \
+ errno = EBADF; \
+ return -1; \
+ } \
+ do { \
+ startOp(fdEntry, &self); \
+ ret = FUNC; \
+ endOp(fdEntry, &self); \
+ } while ((RETRY) && ret == -1 && errno == EINTR); \
+ return ret; \
}
int NET_Read(int s, void* buf, size_t len) {
- BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
+ BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0), JNI_TRUE);
}
int NET_NonBlockingRead(int s, void* buf, size_t len) {
- BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT));
+ BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT), JNI_TRUE);
}
int NET_ReadV(int s, const struct iovec * vector, int count) {
- BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
+ BLOCKING_IO_RETURN_INT( s, readv(s, vector, count), JNI_TRUE);
}
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
struct sockaddr *from, int *fromlen) {
/* casting int *fromlen -> socklen_t* Both are ints */
- BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, (socklen_t *)fromlen) );
+ BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, (socklen_t *)fromlen), JNI_TRUE);
}
int NET_Send(int s, void *msg, int len, unsigned int flags) {
- BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
+ BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags), JNI_TRUE);
}
int NET_WriteV(int s, const struct iovec * vector, int count) {
- BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
+ BLOCKING_IO_RETURN_INT( s, writev(s, vector, count), JNI_TRUE);
}
int NET_SendTo(int s, const void *msg, int len, unsigned int
flags, const struct sockaddr *to, int tolen) {
- BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
+ BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen), JNI_TRUE);
}
int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
@@ -403,22 +404,22 @@ int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
int error = accept(s, addr, &len);
if (error != -1)
*addrlen = (int)len;
- BLOCKING_IO_RETURN_INT( s, error );
+ BLOCKING_IO_RETURN_INT( s, error, JNI_TRUE);
}
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
- BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
+ BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE);
}
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
- BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
+ BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout), JNI_FALSE);
}
#else
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
BLOCKING_IO_RETURN_INT( s-1,
- select(s, readfds, writefds, exceptfds, timeout) );
+ select(s, readfds, writefds, exceptfds, timeout), JNI_FALSE);
}
#endif
diff --git a/jdk/src/solaris/native/java/net/linux_close.c b/jdk/src/solaris/native/java/net/linux_close.c
index f4c53a0d0..2a31b1591 100644
--- a/jdk/src/solaris/native/java/net/linux_close.c
+++ b/jdk/src/solaris/native/java/net/linux_close.c
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/poll.h>
+#include "jvm.h"
/*
* Stack allocated by thread when doing blocking operation
@@ -343,77 +344,77 @@ int NET_SocketClose(int fd) {
/************** Basic I/O operations here ***************/
/*
- * Macro to perform a blocking IO operation. Restarts
- * automatically if interrupted by signal (other than
- * our wakeup signal)
+ * Macro to perform a blocking IO operation.
+ * If interrupted by signal (other than our wakeup signal), and if RETRY is true,
+ * then restarts automatically
*/
-#define BLOCKING_IO_RETURN_INT(FD, FUNC) { \
- int ret; \
- threadEntry_t self; \
- fdEntry_t *fdEntry = getFdEntry(FD); \
- if (fdEntry == NULL) { \
- errno = EBADF; \
- return -1; \
- } \
- do { \
- startOp(fdEntry, &self); \
- ret = FUNC; \
- endOp(fdEntry, &self); \
- } while (ret == -1 && errno == EINTR); \
- return ret; \
+#define BLOCKING_IO_RETURN_INT(FD, FUNC, RETRY) { \
+ int ret; \
+ threadEntry_t self; \
+ fdEntry_t *fdEntry = getFdEntry(FD); \
+ if (fdEntry == NULL) { \
+ errno = EBADF; \
+ return -1; \
+ } \
+ do { \
+ startOp(fdEntry, &self); \
+ ret = FUNC; \
+ endOp(fdEntry, &self); \
+ } while ((RETRY) && ret == -1 && errno == EINTR); \
+ return ret; \
}
int NET_Read(int s, void* buf, size_t len) {
- BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
+ BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0), JNI_TRUE);
}
int NET_NonBlockingRead(int s, void* buf, size_t len) {
- BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT) );
+ BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT), JNI_TRUE);
}
int NET_ReadV(int s, const struct iovec * vector, int count) {
- BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
+ BLOCKING_IO_RETURN_INT( s, readv(s, vector, count), JNI_TRUE);
}
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
struct sockaddr *from, int *fromlen) {
socklen_t socklen = *fromlen;
- BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen) );
+ BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen), JNI_TRUE);
*fromlen = socklen;
}
int NET_Send(int s, void *msg, int len, unsigned int flags) {
- BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
+ BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags), JNI_TRUE);
}
int NET_WriteV(int s, const struct iovec * vector, int count) {
- BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
+ BLOCKING_IO_RETURN_INT( s, writev(s, vector, count), JNI_TRUE);
}
int NET_SendTo(int s, const void *msg, int len, unsigned int
flags, const struct sockaddr *to, int tolen) {
- BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
+ BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen), JNI_TRUE);
}
int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
socklen_t socklen = *addrlen;
- BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen) );
+ BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen), JNI_TRUE);
*addrlen = socklen;
}
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
- BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
+ BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE);
}
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
- BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
+ BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout), JNI_FALSE);
}
#else
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
BLOCKING_IO_RETURN_INT( s-1,
- select(s, readfds, writefds, exceptfds, timeout) );
+ select(s, readfds, writefds, exceptfds, timeout), JNI_FALSE);
}
#endif
--
2.22.0

View File

@ -0,0 +1,96 @@
From c8190e59dbdcb9f52af521994523bae6b893716b Mon Sep 17 00:00:00 2001
Subject: 8312200: Fix Parse::catch_call_exceptions memory leak
---
hotspot/src/share/vm/opto/doCall.cpp | 35 ++++++++++++++--------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/hotspot/src/share/vm/opto/doCall.cpp b/hotspot/src/share/vm/opto/doCall.cpp
index 1b2b77c71..f41e6d386 100644
--- a/hotspot/src/share/vm/opto/doCall.cpp
+++ b/hotspot/src/share/vm/opto/doCall.cpp
@@ -698,24 +698,25 @@ void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
Node* i_o = this->i_o();
// Add a CatchNode.
- GrowableArray<int>* bcis = new (C->node_arena()) GrowableArray<int>(C->node_arena(), 8, 0, -1);
- GrowableArray<const Type*>* extypes = new (C->node_arena()) GrowableArray<const Type*>(C->node_arena(), 8, 0, NULL);
- GrowableArray<int>* saw_unloaded = new (C->node_arena()) GrowableArray<int>(C->node_arena(), 8, 0, 0);
+ Arena tmp_mem(mtCompiler);
+ GrowableArray<int> bcis(&tmp_mem, 8, 0, -1);
+ GrowableArray<const Type*> extypes(&tmp_mem, 8, 0, NULL);
+ GrowableArray<int> saw_unloaded(&tmp_mem, 8, 0, -1);
bool default_handler = false;
for (; !handlers.is_done(); handlers.next()) {
- ciExceptionHandler* h = handlers.handler();
- int h_bci = h->handler_bci();
- ciInstanceKlass* h_klass = h->is_catch_all() ? env()->Throwable_klass() : h->catch_klass();
+ ciExceptionHandler* h = handlers.handler();
+ int h_bci = h->handler_bci();
+ ciInstanceKlass* h_klass = h->is_catch_all() ? env()->Throwable_klass() : h->catch_klass();
// Do not introduce unloaded exception types into the graph:
if (!h_klass->is_loaded()) {
- if (saw_unloaded->contains(h_bci)) {
+ if (saw_unloaded.contains(h_bci)) {
/* We've already seen an unloaded exception with h_bci,
so don't duplicate. Duplication will cause the CatchNode to be
unnecessarily large. See 4713716. */
continue;
} else {
- saw_unloaded->append(h_bci);
+ saw_unloaded.append(h_bci);
}
}
const Type* h_extype = TypeOopPtr::make_from_klass(h_klass);
@@ -723,19 +724,19 @@ void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
h_extype = h_extype->join(TypeInstPtr::NOTNULL);
assert(!h_extype->empty(), "sanity");
// Note: It's OK if the BCIs repeat themselves.
- bcis->append(h_bci);
- extypes->append(h_extype);
+ bcis.append(h_bci);
+ extypes.append(h_extype);
if (h_bci == -1) {
default_handler = true;
}
}
if (!default_handler) {
- bcis->append(-1);
- extypes->append(TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr());
+ bcis.append(-1);
+ extypes.append(TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr());
}
- int len = bcis->length();
+ int len = bcis.length();
CatchNode *cn = new (C) CatchNode(control(), i_o, len+1);
Node *catch_ = _gvn.transform(cn);
@@ -746,18 +747,18 @@ void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
PreserveJVMState pjvms(this);
// Locals are just copied from before the call.
// Get control from the CatchNode.
- int handler_bci = bcis->at(i);
+ int handler_bci = bcis.at(i);
Node* ctrl = _gvn.transform( new (C) CatchProjNode(catch_, i+1,handler_bci));
// This handler cannot happen?
if (ctrl == top()) continue;
set_control(ctrl);
// Create exception oop
- const TypeInstPtr* extype = extypes->at(i)->is_instptr();
- Node *ex_oop = _gvn.transform(new (C) CreateExNode(extypes->at(i), ctrl, i_o));
+ const TypeInstPtr* extype = extypes.at(i)->is_instptr();
+ Node *ex_oop = _gvn.transform(new (C) CreateExNode(extypes.at(i), ctrl, i_o));
// Handle unloaded exception classes.
- if (saw_unloaded->contains(handler_bci)) {
+ if (saw_unloaded.contains(handler_bci)) {
// An unloaded exception type is coming here. Do an uncommon trap.
#ifndef PRODUCT
// We do not expect the same handler bci to take both cold unloaded
--
2.22.0

View File

@ -0,0 +1,226 @@
From ca014e842f05da9d929152c7e5f7cd56d30629e5 Mon Sep 17 00:00:00 2001
Subject: 8313626: C2 crash due to unexpected exception control flow
---
hotspot/src/share/vm/opto/doCall.cpp | 4 +
.../compiler/MissingSafepointOnTryCatch.jasm | 112 ++++++++++++++++++
.../TestMissingSafepointOnTryCatch.java | 66 +++++++++++
3 files changed, 182 insertions(+)
create mode 100644 jdk/test/jdk/jfr/event/compiler/MissingSafepointOnTryCatch.jasm
create mode 100644 jdk/test/jdk/jfr/event/compiler/TestMissingSafepointOnTryCatch.java
diff --git a/hotspot/src/share/vm/opto/doCall.cpp b/hotspot/src/share/vm/opto/doCall.cpp
index 1b2b77c71..7a7aba359 100644
--- a/hotspot/src/share/vm/opto/doCall.cpp
+++ b/hotspot/src/share/vm/opto/doCall.cpp
@@ -892,6 +892,8 @@ void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
tty->print_cr(" Catching every inline exception bci:%d -> handler_bci:%d", bci(), handler_bci);
}
#endif
+ // If this is a backwards branch in the bytecodes, add safepoint
+ maybe_add_safepoint(handler_bci);
merge_exception(handler_bci); // jump to handler
return; // No more handling to be done here!
}
@@ -925,6 +927,8 @@ void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
tty->cr();
}
#endif
+ // If this is a backwards branch in the bytecodes, add safepoint
+ maybe_add_safepoint(handler_bci);
merge_exception(handler_bci);
}
set_control(not_subtype_ctrl);
diff --git a/jdk/test/jdk/jfr/event/compiler/MissingSafepointOnTryCatch.jasm b/jdk/test/jdk/jfr/event/compiler/MissingSafepointOnTryCatch.jasm
new file mode 100644
index 000000000..413736e59
--- /dev/null
+++ b/jdk/test/jdk/jfr/event/compiler/MissingSafepointOnTryCatch.jasm
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, Huawei Technologies Co., Ltd. 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.
+ */
+
+public class MissingSafepointOnTryCatch version 52:0 {
+
+ static Method m:"()V" {
+ return;
+ }
+
+ static Method test1:"()V" stack 1 {
+ try t;
+ invokestatic m:"()V";
+ return;
+
+ catch t java/lang/Throwable;
+ stack_map class java/lang/Throwable;
+ athrow;
+ endtry t;
+ }
+
+ static Method test2:"()V" stack 1 {
+ try t0;
+ try t1;
+ invokestatic m:"()V";
+ endtry t1;
+ return;
+
+ catch t1 java/lang/Exception;
+ stack_map class java/lang/Exception;
+ return;
+
+ catch t0 java/lang/Throwable;
+ stack_map class java/lang/Throwable;
+ athrow;
+ endtry t0;
+ }
+
+ public static Method th:"()V"
+ throws java/lang/Exception
+ stack 2 locals 0
+ {
+ new class java/lang/Exception;
+ dup;
+ invokespecial Method java/lang/Exception."<init>":"()V";
+ athrow;
+ }
+
+ static Method test3:"()V" stack 1 locals 2 {
+ try t;
+ invokestatic m:"()V";
+ iconst_1;
+ istore_0;
+ iconst_0;
+ istore_1;
+ return;
+ catch t java/lang/Throwable;
+ stack_map class java/lang/Throwable;
+ invokestatic th:"()V";
+ return;
+ endtry t;
+ }
+
+ static Method test4:"()V" stack 2 locals 2 {
+ try t;
+ invokestatic m:"()V";
+ iconst_1;
+ istore_0;
+ iconst_0;
+ istore_1;
+ return;
+ catch t java/lang/Throwable;
+ stack_map class java/lang/Throwable;
+ iconst_1;
+ istore_0;
+ invokestatic th:"()V";
+ return;
+ endtry t;
+ }
+
+ static Method testInfinite:"()V" stack 1 {
+ try t;
+ invokestatic th:"()V";
+ return;
+
+ catch t java/lang/Throwable;
+ stack_map class java/lang/Throwable;
+ athrow;
+ endtry t;
+ }
+
+} // end Class MissingSafepointOnTryCatch
diff --git a/jdk/test/jdk/jfr/event/compiler/TestMissingSafepointOnTryCatch.java b/jdk/test/jdk/jfr/event/compiler/TestMissingSafepointOnTryCatch.java
new file mode 100644
index 000000000..fa579b7d4
--- /dev/null
+++ b/jdk/test/jdk/jfr/event/compiler/TestMissingSafepointOnTryCatch.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, Huawei Technologies Co., Ltd. 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 8313626
+ * @library /lib /
+ * @summary assert(false) failed: malformed control flow to missing safepoint on backedge of a try-catch
+ * @compile MissingSafepointOnTryCatch.jasm
+ * @run main/othervm -XX:CompileCommand=quiet
+ * -XX:CompileCommand=compileonly,MissingSafepointOnTryCatch::test*
+ * -XX:CompileCommand=dontinline,MissingSafepointOnTryCatch::m
+ * -XX:CompileCommand=inline,MissingSafepointOnTryCatch::th
+ * -XX:-TieredCompilation -Xcomp TestMissingSafepointOnTryCatch
+ */
+
+import jdk.test.lib.Utils;
+
+public class TestMissingSafepointOnTryCatch {
+
+ public static void infiniteLoop() {
+ try {
+ Thread thread = new Thread() {
+ public void run() {
+ MissingSafepointOnTryCatch.testInfinite();
+ }
+ };
+ thread.setDaemon(true);
+ thread.start();
+ Thread.sleep(Utils.adjustTimeout(500));
+ } catch (Exception e) {}
+ }
+
+ public static void main(String[] args) {
+ try {
+ // to make sure java/lang/Exception class is resolved
+ MissingSafepointOnTryCatch.th();
+ } catch (Exception e) {}
+ MissingSafepointOnTryCatch.test1();
+ MissingSafepointOnTryCatch.test2();
+ MissingSafepointOnTryCatch.test3();
+ MissingSafepointOnTryCatch.test4();
+ infiniteLoop();
+ }
+}
--
2.22.0

View File

@ -0,0 +1,127 @@
From 11bd45aac555a00c705c8bf480a179bb063b1c44 Mon Sep 17 00:00:00 2001
Subject: 8314236: Overflow in Collections.rotate
---
.../share/classes/java/util/Collections.java | 9 +-
.../java/util/Collections/RotateHuge.java | 85 +++++++++++++++++++
2 files changed, 90 insertions(+), 4 deletions(-)
create mode 100644 jdk/test/java/util/Collections/RotateHuge.java
diff --git a/jdk/src/share/classes/java/util/Collections.java b/jdk/src/share/classes/java/util/Collections.java
index 3ab4c5ec0..9aa373841 100644
--- a/jdk/src/share/classes/java/util/Collections.java
+++ b/jdk/src/share/classes/java/util/Collections.java
@@ -789,15 +789,16 @@ public class Collections {
if (distance == 0)
return;
- for (int cycleStart = 0, nMoved = 0; nMoved != size; cycleStart++) {
+ int bound = size - distance;
+ for (int cycleStart = 0, nMoved = 0; nMoved < size; cycleStart++) {
T displaced = list.get(cycleStart);
int i = cycleStart;
do {
- i += distance;
- if (i >= size)
+ if (i >= bound)
i -= size;
+ i += distance;
displaced = list.set(i, displaced);
- nMoved ++;
+ nMoved++;
} while (i != cycleStart);
}
}
diff --git a/jdk/test/java/util/Collections/RotateHuge.java b/jdk/test/java/util/Collections/RotateHuge.java
new file mode 100644
index 000000000..a6f8f739c
--- /dev/null
+++ b/jdk/test/java/util/Collections/RotateHuge.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, Huawei Technologies Co., Ltd. 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 8314236
+ * @summary Overflow in Collections.rotate
+ */
+
+import com.sun.crypto.provider.Preconditions;
+
+import java.util.AbstractList;
+import java.util.Collections;
+import java.util.List;
+import java.util.RandomAccess;
+
+public class RotateHuge {
+
+ private static final class MockList extends AbstractList<Object>
+ implements RandomAccess {
+ private final int size;
+
+ public MockList(final int size) {
+ if (size < 0)
+ throw new IllegalArgumentException("Illegal size: " + size);
+ this.size = size;
+ }
+
+ @Override
+ public Object get(final int index) {
+ Preconditions.checkIndex(index, size, null);
+ return null;
+ }
+
+ @Override
+ public Object set(final int index, final Object element) {
+ Preconditions.checkIndex(index, size, null);
+ return null;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+ }
+
+ public static void main(final String[] args) {
+ testRotate((1 << 30) + 1, -(1 << 30) - 2);
+ testRotate((1 << 30) + 1, 1 << 30);
+ testRotate(Integer.MAX_VALUE, Integer.MIN_VALUE);
+ testRotate(Integer.MAX_VALUE, Integer.MIN_VALUE + 3);
+ testRotate(Integer.MAX_VALUE, 2);
+ testRotate(Integer.MAX_VALUE, Integer.MAX_VALUE - 1);
+ }
+
+ /*
+ * This test covers only index computations.
+ * Correctness of elements rotation is not checked.
+ */
+ private static void testRotate(final int size, final int distance) {
+ final List<Object> list = new MockList(size);
+ Collections.rotate(list, distance);
+ }
+}
--
2.22.0

View File

@ -0,0 +1,53 @@
From ff782010bb5610fb9bb9e9ebbf131ba71124d299 Mon Sep 17 00:00:00 2001
Subject: Fix crash in JNI's GetDoubleArrayRegion and SetDoubleArrayRegion
---
hotspot/src/share/vm/prims/jni.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/hotspot/src/share/vm/prims/jni.cpp b/hotspot/src/share/vm/prims/jni.cpp
index 953300ebc..c0d789b42 100644
--- a/hotspot/src/share/vm/prims/jni.cpp
+++ b/hotspot/src/share/vm/prims/jni.cpp
@@ -3805,7 +3805,7 @@ jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start,
int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \
memcpy((u_char*) buf, \
(u_char*) src->Tag##_at_addr(start), \
- len << sc); \
+ (size_t)len << sc); \
} \
} \
JNI_END
@@ -3840,7 +3840,7 @@ jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start,
int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \
memcpy((u_char*) buf, \
(u_char*) src->Tag##_at_addr(start), \
- len << sc); \
+ (size_t)len << sc); \
} \
} \
JNI_END
@@ -3888,8 +3888,8 @@ jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start,
if (len > 0) { \
int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \
memcpy((u_char*) dst->Tag##_at_addr(start), \
- (u_char*) buf, \
- len << sc); \
+ (u_char*) buf, \
+ (size_t)len << sc); \
} \
} \
JNI_END
@@ -3923,8 +3923,8 @@ jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start,
if (len > 0) { \
int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \
memcpy((u_char*) dst->Tag##_at_addr(start), \
- (u_char*) buf, \
- len << sc); \
+ (u_char*) buf, \
+ (size_t)len << sc); \
} \
} \
JNI_END
--
2.22.0

View File

@ -31,7 +31,7 @@ index 2ee40289..8ab268b5 100644
@@ -1,6 +1,8 @@
/*
* @test
+ * @author zhangli
+ * @author zl
* @bug 8203699
+ * @summary see https://code.huawei.com/HuaweiJDK/JVM-team/JVM/issues/1368
* @run testng/othervm test.java.lang.invoke.lookup.TestDefenderMethodLookup
@ -51,7 +51,7 @@ index 00000000..bd22ba83
+ * @build com.huawei.openjdk.adaptiveheap.TestAdaptiveHeap
+ * @run main/othervm com.huawei.openjdk.adaptiveheap.TestAdaptiveHeap -Xms16G -Xmx16G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1PeriodicGCLoadThreshold=20 -XX:G1PeriodicGCInterval=15000 -XX:+G1Uncommit
+ * @summary test adaptheap
+ * @author wangruishun
+ * @author wrs
+ */
+
+import com.oracle.java.testlibrary.OutputAnalyzer;
@ -91,7 +91,7 @@ index 00000000..9b614024
--- /dev/null
+++ b/version.txt
@@ -0,0 +1 @@
+8.392.5.0.13
+8.392.8.0.13
--
2.23.0

View File

@ -46,7 +46,7 @@ index 54e1bfa0d..c1423dc5b 100644
// shasum -a 256 cacerts | sed -e 's/../&:/g' | tr '[:lower:]' '[:upper:]' | cut -c1-95
private static final String CHECKSUM
- = "2D:04:88:6C:52:53:54:EB:38:2D:BC:E0:AF:B7:82:F4:9E:32:A8:1A:1B:A3:AE:CF:25:CB:C2:F6:0F:4E:E1:20";
+ = "81:65:90:49:CF:39:8A:7B:B6:7E:88:9D:A3:E9:D4:31:0E:9B:D0:50:9E:09:76:37:E9:2A:14:74:17:6E:12:EF";
+ = "C2:9A:86:5C:47:0F:15:58:FB:D8:31:B5:29:BB:BE:A1:09:6F:9B:60:10:AF:8E:77:4A:AE:B7:66:BB:B1:58:34";
// map of cert alias to SHA-256 fingerprint
@SuppressWarnings("serial")
private static final Map<String, String> FINGERPRINT_MAP

View File

@ -925,7 +925,7 @@ Provides: java-%{javaver}-%{origin}-accessibility%{?1} = %{epoch}:%{version}-%{r
Name: java-%{javaver}-%{origin}
Version: %{javaver}.%{updatever}.%{buildver}
Release: 0
Release: 1
# java-1.5.0-ibm from jpackage.org set Epoch to 1 for unknown reasons
# and this change was brought into RHEL-4. java-1.5.0-ibm packages
# also included the epoch in their virtual provides. This created a
@ -1281,6 +1281,20 @@ Patch394: Fix-the-memory-leak-of-MetaspaceAllocationTest.patch
Patch395: Add-metaspace-memory-allocation-failure-validation.patch
Patch396: change-value-of-GCLockerRetryAllocationCount-from-2-.patch
#392
Patch397: Fix-crash-in-JNI-s-GetDoubleArrayRegion-and-SetDoubl.patch
Patch398: 8263557-Possible-NULL-dereference-in-Arena-destruct_.patch
Patch399: 8294906-Memory-leak-in-PKCS11-NSS-TLS-server.patch
Patch400: 8314236-Overflow-in-Collections.rotate.patch
Patch401: 8313626-C2-crash-due-to-unexpected-exception-control.patch
Patch402: 8312200-Fix-Parse-catch_call_exceptions-memory-leak.patch
Patch403: 8193682-Infinite-loop-in-ZipOutputStream.close.patch
Patch404: 8285516-clearPassword-should-be-called-in-a-finally-.patch
Patch405: 8148470-Metadata-print-routines-should-not-print-to-.patch
Patch406: 8293344-JDK-8242181-broke-stack-printing-for-non-att.patch
Patch407: 8278794-Infinite-loop-in-DeflaterOutputStream.finish.patch
Patch408: 8312065-Socket.connect-does-not-timeout-when-profili.patch
#############################################
#
# Upstreamable patches
@ -1888,6 +1902,18 @@ pushd %{top_level_dir_name}
%patch394 -p1
%patch395 -p1
%patch396 -p1
%patch397 -p1
%patch398 -p1
%patch399 -p1
%patch400 -p1
%patch401 -p1
%patch402 -p1
%patch403 -p1
%patch404 -p1
%patch405 -p1
%patch406 -p1
%patch407 -p1
%patch408 -p1
%ifarch riscv64
%patch2000 -p1
@ -2533,6 +2559,22 @@ cjc.mainProgram(arg)
%endif
%changelog
* Wed Oct 25 2023 kuenking111 <wangkun49@huawei.com> - 1:1.8.0.392-b08.1
- add Fix-crash-in-JNI-s-GetDoubleArrayRegion-and-SetDoubl.patch
- add 8263557-Possible-NULL-dereference-in-Arena-destruct_.patch
- add 8294906-Memory-leak-in-PKCS11-NSS-TLS-server.patch
- add 8314236-Overflow-in-Collections.rotate.patch
- add 8313626-C2-crash-due-to-unexpected-exception-control.patch
- add 8312200-Fix-Parse-catch_call_exceptions-memory-leak.patch
- add 8193682-Infinite-loop-in-ZipOutputStream.close.patch
- add 8285516-clearPassword-should-be-called-in-a-finally-.patch
- add 8148470-Metadata-print-routines-should-not-print-to-.patch
- add 8293344-JDK-8242181-broke-stack-printing-for-non-att.patch
- add 8278794-Infinite-loop-in-DeflaterOutputStream.finish.patch
- add 8312065-Socket.connect-does-not-timeout-when-profili.patch
- modified fix_X509TrustManagerImpl_symantec_distrust.patch
- modified add-missing-test-case.patch
* Fri Oct 20 2023 Autistic_boyya <wangzhongyi7@huawei.com> - 1:1.8.0.392-b08.0
- add 8308682-Enhance-AES-performance.patch
- add Fix-the-memory-leak-of-MetaspaceAllocationTest.patch