!491 sync master to openEuler-20.03-LTS-SP4

From: @kuenking111 
Reviewed-by: @alexanderbill 
Signed-off-by: @alexanderbill
This commit is contained in:
openeuler-ci-bot 2023-11-08 02:44:06 +00:00 committed by Gitee
commit 1e0e78ab9f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
26 changed files with 2920 additions and 293 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

@ -1,25 +0,0 @@
From 5fafa8bd0a85d93ff0480bc2d163c4070742d8f5 Mon Sep 17 00:00:00 2001
Date: Fri, 22 Jan 2021 11:26:11 +0800
Subject: 8202952:C2:Unexpected dead nodes after
matching
Bug url: https://bugs.openjdk.java.net/browse/JDK-8202952
---
hotspot/src/share/vm/opto/matcher.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/hotspot/src/share/vm/opto/matcher.cpp b/hotspot/src/share/vm/opto/matcher.cpp
index 70e8af221..f5d30c3af 100644
--- a/hotspot/src/share/vm/opto/matcher.cpp
+++ b/hotspot/src/share/vm/opto/matcher.cpp
@@ -2230,6 +2230,7 @@ void Matcher::find_shared( Node *n ) {
// AtomicAdd is not an addressing expression.
// Cheap to find it by looking for screwy base.
!adr->in(AddPNode::Base)->is_top() &&
+ LP64_ONLY( off->get_long() == (int) (off->get_long()) && ) // immL32
// Are there other uses besides address expressions?
!is_visited(adr) ) {
address_visited.set(adr->_idx); // Flag as address_visited
--
2.19.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

@ -1,227 +0,0 @@
From d85c283f3bb1fd5f1d96c076e858a7409af19aae Mon Sep 17 00:00:00 2001
Subject: 8283441: C2: segmentation fault in ciMethodBlocks::make_block_at(int)
Bug url: https://bugs.openjdk.org/browse/JDK-8283441
---
hotspot/src/share/vm/c1/c1_GraphBuilder.cpp | 12 ++++--
hotspot/src/share/vm/ci/ciMethodBlocks.cpp | 17 +++++---
.../src/share/vm/compiler/methodLiveness.cpp | 9 ++--
hotspot/test/compiler/parsing/Custom.jasm | 38 +++++++++++++++++
...UnreachableBlockFallsThroughEndOfCode.java | 42 +++++++++++++++++++
5 files changed, 106 insertions(+), 12 deletions(-)
create mode 100644 hotspot/test/compiler/parsing/Custom.jasm
create mode 100644 hotspot/test/compiler/parsing/UnreachableBlockFallsThroughEndOfCode.java
diff --git a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
index eb8ffe5e5..db353541f 100644
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
@@ -206,8 +206,10 @@ void BlockListBuilder::handle_exceptions(BlockBegin* current, int cur_bci) {
}
void BlockListBuilder::handle_jsr(BlockBegin* current, int sr_bci, int next_bci) {
- // start a new block after jsr-bytecode and link this block into cfg
- make_block_at(next_bci, current);
+ if (next_bci < method()->code_size()) {
+ // start a new block after jsr-bytecode and link this block into cfg
+ make_block_at(next_bci, current);
+ }
// start a new block at the subroutine entry at mark it with special flag
BlockBegin* sr_block = make_block_at(sr_bci, current);
@@ -227,6 +229,8 @@ void BlockListBuilder::set_leaders() {
// branch target and a modification of the successor lists.
BitMap bci_block_start = method()->bci_block_start();
+ int end_bci = method()->code_size();
+
ciBytecodeStream s(method());
while (s.next() != ciBytecodeStream::EOBC()) {
int cur_bci = s.cur_bci();
@@ -297,7 +301,9 @@ void BlockListBuilder::set_leaders() {
case Bytecodes::_if_acmpne: // fall through
case Bytecodes::_ifnull: // fall through
case Bytecodes::_ifnonnull:
- make_block_at(s.next_bci(), current);
+ if (s.next_bci() < end_bci) {
+ make_block_at(s.next_bci(), current);
+ }
make_block_at(s.get_dest(), current);
current = NULL;
break;
diff --git a/hotspot/src/share/vm/ci/ciMethodBlocks.cpp b/hotspot/src/share/vm/ci/ciMethodBlocks.cpp
index 3ce828ecb..bb3937c15 100644
--- a/hotspot/src/share/vm/ci/ciMethodBlocks.cpp
+++ b/hotspot/src/share/vm/ci/ciMethodBlocks.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -33,12 +33,13 @@
ciBlock *ciMethodBlocks::block_containing(int bci) {
+ assert(bci >= 0 && bci < _code_size, "valid bytecode range");
ciBlock *blk = _bci_to_block[bci];
return blk;
}
bool ciMethodBlocks::is_block_start(int bci) {
- assert(bci >=0 && bci < _code_size, "valid bytecode range");
+ assert(bci >= 0 && bci < _code_size, "valid bytecode range");
ciBlock *b = _bci_to_block[bci];
assert(b != NULL, "must have block for bytecode");
return b->start_bci() == bci;
@@ -146,7 +147,9 @@ void ciMethodBlocks::do_analysis() {
case Bytecodes::_ifnonnull :
{
cur_block->set_control_bci(bci);
- ciBlock *fall_through = make_block_at(s.next_bci());
+ if (s.next_bci() < limit_bci) {
+ ciBlock *fall_through = make_block_at(s.next_bci());
+ }
int dest_bci = s.get_dest();
ciBlock *dest = make_block_at(dest_bci);
break;
@@ -166,7 +169,9 @@ void ciMethodBlocks::do_analysis() {
case Bytecodes::_jsr :
{
cur_block->set_control_bci(bci);
- ciBlock *ret = make_block_at(s.next_bci());
+ if (s.next_bci() < limit_bci) {
+ ciBlock *ret = make_block_at(s.next_bci());
+ }
int dest_bci = s.get_dest();
ciBlock *dest = make_block_at(dest_bci);
break;
@@ -224,7 +229,9 @@ void ciMethodBlocks::do_analysis() {
case Bytecodes::_jsr_w :
{
cur_block->set_control_bci(bci);
- ciBlock *ret = make_block_at(s.next_bci());
+ if (s.next_bci() < limit_bci) {
+ ciBlock *ret = make_block_at(s.next_bci());
+ }
int dest_bci = s.get_far_dest();
ciBlock *dest = make_block_at(dest_bci);
break;
diff --git a/hotspot/src/share/vm/compiler/methodLiveness.cpp b/hotspot/src/share/vm/compiler/methodLiveness.cpp
index eda1ab156..7fb496dc9 100644
--- a/hotspot/src/share/vm/compiler/methodLiveness.cpp
+++ b/hotspot/src/share/vm/compiler/methodLiveness.cpp
@@ -268,10 +268,11 @@ void MethodLiveness::init_basic_blocks() {
case Bytecodes::_ifnull:
case Bytecodes::_ifnonnull:
// Two way branch. Set predecessors at each destination.
- dest = _block_map->at(bytes.next_bci());
- assert(dest != NULL, "must be a block immediately following this one.");
- dest->add_normal_predecessor(current_block);
-
+ if (bytes.next_bci() < method_len) {
+ dest = _block_map->at(bytes.next_bci());
+ assert(dest != NULL, "must be a block immediately following this one.");
+ dest->add_normal_predecessor(current_block);
+ }
dest = _block_map->at(bytes.get_dest());
assert(dest != NULL, "branch desination must start a block.");
dest->add_normal_predecessor(current_block);
diff --git a/hotspot/test/compiler/parsing/Custom.jasm b/hotspot/test/compiler/parsing/Custom.jasm
new file mode 100644
index 000000000..78bfc518d
--- /dev/null
+++ b/hotspot/test/compiler/parsing/Custom.jasm
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 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
+ * 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/parsing;
+
+super public class Custom {
+
+ public static Method test:"(I)V" stack 2 locals 1 {
+ return;
+Loop:
+ // Unreachable block
+ iload_0;
+ bipush 100;
+ if_icmpge Loop;
+ // Falls through
+ }
+
+}
\ No newline at end of file
diff --git a/hotspot/test/compiler/parsing/UnreachableBlockFallsThroughEndOfCode.java b/hotspot/test/compiler/parsing/UnreachableBlockFallsThroughEndOfCode.java
new file mode 100644
index 000000000..5b1d17d97
--- /dev/null
+++ b/hotspot/test/compiler/parsing/UnreachableBlockFallsThroughEndOfCode.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 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
+ * 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 UnreachableBlockFallsThroughEndOfCode.java
+ * @bug 8283441
+ * @compile Custom.jasm UnreachableBlockFallsThroughEndOfCode.java
+ * @summary Compiling method that falls off the end of the code array
+ * @run main/othervm -XX:TieredStopAtLevel=1 -Xbatch compiler.parsing.UnreachableBlockFallsThroughEndOfCode
+ * @run main/othervm -XX:-TieredCompilation -Xbatch compiler.parsing.UnreachableBlockFallsThroughEndOfCode
+ */
+
+ package compiler.parsing;
+
+ public class UnreachableBlockFallsThroughEndOfCode {
+ public static void main(String[] strArr) {
+ for (int i = 0; i < 20000; i++) {
+ Custom.test(i);
+ }
+ }
+ }
\ No newline at end of file
--
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,708 @@
From 6926e9b83bc3f9b785d5298786a5c41e247b2a3f Mon Sep 17 00:00:00 2001
Date: Mon, 16 Oct 2023 10:56:30 +0800
Subject: [PATCH 1/5] 8308682: Enhance AES performance
Bug url: https://bugs.openjdk.org/browse/JDK-8308682
---
.../src/cpu/aarch64/vm/assembler_aarch64.hpp | 2 +
.../cpu/aarch64/vm/stubGenerator_aarch64.cpp | 451 +++++++++---------
.../compiler/codegen/aes/CTR_Wraparound.java | 169 +++++++
3 files changed, 406 insertions(+), 216 deletions(-)
create mode 100644 hotspot/test/compiler/codegen/aes/CTR_Wraparound.java
diff --git a/hotspot/src/cpu/aarch64/vm/assembler_aarch64.hpp b/hotspot/src/cpu/aarch64/vm/assembler_aarch64.hpp
index 9202e61f8..b12095aca 100644
--- a/hotspot/src/cpu/aarch64/vm/assembler_aarch64.hpp
+++ b/hotspot/src/cpu/aarch64/vm/assembler_aarch64.hpp
@@ -2140,6 +2140,8 @@ public:
INSN(sshl, 0, 0b010001);
INSN(ushl, 1, 0b010001);
+ INSN(cmhi, 1, 0b001101); // accepted arrangements: T8B, T16B, T4H, T8H, T2S, T4S, T2D
+
#undef INSN
#define INSN(NAME, opc, opc2) \
diff --git a/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp b/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp
index 565fe559c..f61028d50 100644
--- a/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp
+++ b/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp
@@ -2804,265 +2804,284 @@ class StubGenerator: public StubCodeGenerator {
return start;
}
+ // Big-endian 128-bit + 64-bit -> 128-bit addition.
+ // Inputs: 128-bits. in is preserved.
+ // The least-significant 64-bit word is in the upper dword of the vector
+ // inc (the 64-bit increment) is preserved. Its lower dword must be zero
+ // Output: result
+ void be_add_128_64(FloatRegister result, FloatRegister in,
+ FloatRegister inc, FloatRegister tmp) {
+ assert_different_registers(result, tmp, inc);
+
+ __ addv(result, __ T2D, in, inc); // Add inc to the least-significant dword of input
+ __ cmhi(tmp, __ T2D, inc, result); // Check for result overflowing
+ __ ins(tmp, __ D, tmp, 0, 1); // Move LSD of comparison result to MSD
+ __ ins(tmp, __ D, inc, 1, 0); // Move 0 to LSD of comparison result
+ __ subv(result, __ T2D, result, tmp); // Subtract -1 from MSD if there was an overflow
+ }
+
// CTR AES crypt.
- // Arguments:
- //
- // Inputs:
- // c_rarg0 - source byte array address
- // c_rarg1 - destination byte array address
- // c_rarg2 - K (key) in little endian int array
- // c_rarg3 - counter vector byte array address
- // c_rarg4 - input length
- // c_rarg5 - saved encryptedCounter start
- // c_rarg6 - saved used length
+ // Arguments:
+ //
+ // Inputs:
+ // c_rarg0 - source byte array address
+ // c_rarg1 - destination byte array address
+ // c_rarg2 - K (key) in little endian int array
+ // c_rarg3 - counter vector byte array address
+ // c_rarg4 - input length
+ // c_rarg5 - saved encryptedCounter start
+ // c_rarg6 - saved used length
+ //
+ // Output:
+ // r0 - input length
+ //
+ address generate_counterMode_AESCrypt() {
+ const Register in = c_rarg0;
+ const Register out = c_rarg1;
+ const Register key = c_rarg2;
+ const Register counter = c_rarg3;
+ const Register saved_len = c_rarg4, len = r10;
+ const Register saved_encrypted_ctr = c_rarg5;
+ const Register used_ptr = c_rarg6, used = r12;
+
+ const Register offset = r7;
+ const Register keylen = r11;
+
+ const unsigned char block_size = 16;
+ const int bulk_width = 4;
+ // NB: bulk_width can be 4 or 8. 8 gives slightly faster
+ // performance with larger data sizes, but it also means that the
+ // fast path isn't used until you have at least 8 blocks, and up
+ // to 127 bytes of data will be executed on the slow path. For
+ // that reason, and also so as not to blow away too much icache, 4
+ // blocks seems like a sensible compromise.
+
+ // Algorithm:
//
- // Output:
- // r0 - input length
+ // if (len == 0) {
+ // goto DONE;
+ // }
+ // int result = len;
+ // do {
+ // if (used >= blockSize) {
+ // if (len >= bulk_width * blockSize) {
+ // CTR_large_block();
+ // if (len == 0)
+ // goto DONE;
+ // }
+ // for (;;) {
+ // 16ByteVector v0 = counter;
+ // embeddedCipher.encryptBlock(v0, 0, encryptedCounter, 0);
+ // used = 0;
+ // if (len < blockSize)
+ // break; /* goto NEXT */
+ // 16ByteVector v1 = load16Bytes(in, offset);
+ // v1 = v1 ^ encryptedCounter;
+ // store16Bytes(out, offset);
+ // used = blockSize;
+ // offset += blockSize;
+ // len -= blockSize;
+ // if (len == 0)
+ // goto DONE;
+ // }
+ // }
+ // NEXT:
+ // out[outOff++] = (byte)(in[inOff++] ^ encryptedCounter[used++]);
+ // len--;
+ // } while (len != 0);
+ // DONE:
+ // return result;
//
- address generate_counterMode_AESCrypt() {
- const Register in = c_rarg0;
- const Register out = c_rarg1;
- const Register key = c_rarg2;
- const Register counter = c_rarg3;
- const Register saved_len = c_rarg4, len = r10;
- const Register saved_encrypted_ctr = c_rarg5;
- const Register used_ptr = c_rarg6, used = r12;
-
- const Register offset = r7;
- const Register keylen = r11;
-
- const unsigned char block_size = 16;
- const int bulk_width = 4;
- // NB: bulk_width can be 4 or 8. 8 gives slightly faster
- // performance with larger data sizes, but it also means that the
- // fast path isn't used until you have at least 8 blocks, and up
- // to 127 bytes of data will be executed on the slow path. For
- // that reason, and also so as not to blow away too much icache, 4
- // blocks seems like a sensible compromise.
-
- // Algorithm:
- //
- // if (len == 0) {
- // goto DONE;
- // }
- // int result = len;
- // do {
- // if (used >= blockSize) {
- // if (len >= bulk_width * blockSize) {
- // CTR_large_block();
- // if (len == 0)
- // goto DONE;
- // }
- // for (;;) {
- // 16ByteVector v0 = counter;
- // embeddedCipher.encryptBlock(v0, 0, encryptedCounter, 0);
- // used = 0;
- // if (len < blockSize)
- // break; /* goto NEXT */
- // 16ByteVector v1 = load16Bytes(in, offset);
- // v1 = v1 ^ encryptedCounter;
- // store16Bytes(out, offset);
- // used = blockSize;
- // offset += blockSize;
- // len -= blockSize;
- // if (len == 0)
- // goto DONE;
- // }
- // }
- // NEXT:
- // out[outOff++] = (byte)(in[inOff++] ^ encryptedCounter[used++]);
- // len--;
- // } while (len != 0);
- // DONE:
- // return result;
- //
- // CTR_large_block()
- // Wide bulk encryption of whole blocks.
+ // CTR_large_block()
+ // Wide bulk encryption of whole blocks.
- __ align(CodeEntryAlignment);
- StubCodeMark mark(this, "StubRoutines", "counterMode_AESCrypt");
- const address start = __ pc();
- __ enter();
+ __ align(CodeEntryAlignment);
+ StubCodeMark mark(this, "StubRoutines", "counterMode_AESCrypt");
+ const address start = __ pc();
+ __ enter();
- Label DONE, CTR_large_block, large_block_return;
- __ ldrw(used, Address(used_ptr));
- __ cbzw(saved_len, DONE);
+ Label DONE, CTR_large_block, large_block_return;
+ __ ldrw(used, Address(used_ptr));
+ __ cbzw(saved_len, DONE);
- __ mov(len, saved_len);
- __ mov(offset, 0);
+ __ mov(len, saved_len);
+ __ mov(offset, 0);
- // Compute #rounds for AES based on the length of the key array
- __ ldrw(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
+ // Compute #rounds for AES based on the length of the key array
+ __ ldrw(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
- __ aesenc_loadkeys(key, keylen);
+ __ aesenc_loadkeys(key, keylen);
- {
- Label L_CTR_loop, NEXT;
+ {
+ Label L_CTR_loop, NEXT;
- __ bind(L_CTR_loop);
+ __ bind(L_CTR_loop);
- __ cmp(used, block_size);
- __ br(__ LO, NEXT);
+ __ cmp(used, block_size);
+ __ br(__ LO, NEXT);
- // Maybe we have a lot of data
- __ subsw(rscratch1, len, bulk_width * block_size);
- __ br(__ HS, CTR_large_block);
- __ BIND(large_block_return);
- __ cbzw(len, DONE);
+ // Maybe we have a lot of data
+ __ subsw(rscratch1, len, bulk_width * block_size);
+ __ br(__ HS, CTR_large_block);
+ __ BIND(large_block_return);
+ __ cbzw(len, DONE);
- // Setup the counter
- __ movi(v4, __ T4S, 0);
- __ movi(v5, __ T4S, 1);
- __ ins(v4, __ S, v5, 3, 3); // v4 contains { 0, 0, 0, 1 }
+ // Setup the counter
+ __ movi(v4, __ T4S, 0);
+ __ movi(v5, __ T4S, 1);
+ __ ins(v4, __ S, v5, 2, 2); // v4 contains { 0, 1 }
- __ ld1(v0, __ T16B, counter); // Load the counter into v0
- __ rev32(v16, __ T16B, v0);
- __ addv(v16, __ T4S, v16, v4);
- __ rev32(v16, __ T16B, v16);
- __ st1(v16, __ T16B, counter); // Save the incremented counter back
+ // 128-bit big-endian increment
+ __ ld1(v0, __ T16B, counter);
+ __ rev64(v16, __ T16B, v0);
+ be_add_128_64(v16, v16, v4, /*tmp*/v5);
+ __ rev64(v16, __ T16B, v16);
+ __ st1(v16, __ T16B, counter);
+ // Previous counter value is in v0
+ // v4 contains { 0, 1 }
- {
- // We have fewer than bulk_width blocks of data left. Encrypt
- // them one by one until there is less than a full block
- // remaining, being careful to save both the encrypted counter
- // and the counter.
-
- Label inner_loop;
- __ bind(inner_loop);
- // Counter to encrypt is in v0
- __ aesecb_encrypt(noreg, noreg, keylen);
- __ st1(v0, __ T16B, saved_encrypted_ctr);
-
- // Do we have a remaining full block?
-
- __ mov(used, 0);
- __ cmp(len, block_size);
- __ br(__ LO, NEXT);
-
- // Yes, we have a full block
- __ ldrq(v1, Address(in, offset));
- __ eor(v1, __ T16B, v1, v0);
- __ strq(v1, Address(out, offset));
- __ mov(used, block_size);
- __ add(offset, offset, block_size);
-
- __ subw(len, len, block_size);
- __ cbzw(len, DONE);
-
- // Increment the counter, store it back
- __ orr(v0, __ T16B, v16, v16);
- __ rev32(v16, __ T16B, v16);
- __ addv(v16, __ T4S, v16, v4);
- __ rev32(v16, __ T16B, v16);
- __ st1(v16, __ T16B, counter); // Save the incremented counter back
-
- __ b(inner_loop);
- }
+ {
+ // We have fewer than bulk_width blocks of data left. Encrypt
+ // them one by one until there is less than a full block
+ // remaining, being careful to save both the encrypted counter
+ // and the counter.
- __ BIND(NEXT);
-
- // Encrypt a single byte, and loop.
- // We expect this to be a rare event.
- __ ldrb(rscratch1, Address(in, offset));
- __ ldrb(rscratch2, Address(saved_encrypted_ctr, used));
- __ eor(rscratch1, rscratch1, rscratch2);
- __ strb(rscratch1, Address(out, offset));
- __ add(offset, offset, 1);
- __ add(used, used, 1);
- __ subw(len, len,1);
- __ cbnzw(len, L_CTR_loop);
- }
+ Label inner_loop;
+ __ bind(inner_loop);
+ // Counter to encrypt is in v0
+ __ aesecb_encrypt(noreg, noreg, keylen);
+ __ st1(v0, __ T16B, saved_encrypted_ctr);
- __ bind(DONE);
- __ strw(used, Address(used_ptr));
- __ mov(r0, saved_len);
+ // Do we have a remaining full block?
- __ leave(); // required for proper stackwalking of RuntimeStub frame
- __ ret(lr);
+ __ mov(used, 0);
+ __ cmp(len, block_size);
+ __ br(__ LO, NEXT);
- // Bulk encryption
+ // Yes, we have a full block
+ __ ldrq(v1, Address(in, offset));
+ __ eor(v1, __ T16B, v1, v0);
+ __ strq(v1, Address(out, offset));
+ __ mov(used, block_size);
+ __ add(offset, offset, block_size);
- __ BIND (CTR_large_block);
- assert(bulk_width == 4 || bulk_width == 8, "must be");
+ __ subw(len, len, block_size);
+ __ cbzw(len, DONE);
- if (bulk_width == 8) {
- __ sub(sp, sp, 4 * 16);
- __ st1(v12, v13, v14, v15, __ T16B, Address(sp));
+ // Increment the counter, store it back
+ __ orr(v0, __ T16B, v16, v16);
+ __ rev64(v16, __ T16B, v16);
+ be_add_128_64(v16, v16, v4, /*tmp*/v5);
+ __ rev64(v16, __ T16B, v16);
+ __ st1(v16, __ T16B, counter); // Save the incremented counter back
+
+ __ b(inner_loop);
}
- __ sub(sp, sp, 4 * 16);
- __ st1(v8, v9, v10, v11, __ T16B, Address(sp));
- RegSet saved_regs = (RegSet::of(in, out, offset)
- + RegSet::of(saved_encrypted_ctr, used_ptr, len));
- __ push(saved_regs, sp);
- __ andr(len, len, -16 * bulk_width); // 8/4 encryptions, 16 bytes per encryption
- __ add(in, in, offset);
- __ add(out, out, offset);
- // Keys should already be loaded into the correct registers
+ __ BIND(NEXT);
+
+ // Encrypt a single byte, and loop.
+ // We expect this to be a rare event.
+ __ ldrb(rscratch1, Address(in, offset));
+ __ ldrb(rscratch2, Address(saved_encrypted_ctr, used));
+ __ eor(rscratch1, rscratch1, rscratch2);
+ __ strb(rscratch1, Address(out, offset));
+ __ add(offset, offset, 1);
+ __ add(used, used, 1);
+ __ subw(len, len,1);
+ __ cbnzw(len, L_CTR_loop);
+ }
- __ ld1(v0, __ T16B, counter); // v0 contains the first counter
- __ rev32(v16, __ T16B, v0); // v16 contains byte-reversed counter
+ __ bind(DONE);
+ __ strw(used, Address(used_ptr));
+ __ mov(r0, saved_len);
- // AES/CTR loop
- {
- Label L_CTR_loop;
- __ BIND(L_CTR_loop);
+ __ leave(); // required for proper stackwalking of RuntimeStub frame
+ __ ret(lr);
- // Setup the counters
- __ movi(v8, __ T4S, 0);
- __ movi(v9, __ T4S, 1);
- __ ins(v8, __ S, v9, 3, 3); // v8 contains { 0, 0, 0, 1 }
+ // Bulk encryption
- for (FloatRegister f = v0; f < v0 + bulk_width; f++) {
- __ rev32(f, __ T16B, v16);
- __ addv(v16, __ T4S, v16, v8);
- }
+ __ BIND (CTR_large_block);
+ assert(bulk_width == 4 || bulk_width == 8, "must be");
- __ ld1(v8, v9, v10, v11, __ T16B, __ post(in, 4 * 16));
+ if (bulk_width == 8) {
+ __ sub(sp, sp, 4 * 16);
+ __ st1(v12, v13, v14, v15, __ T16B, Address(sp));
+ }
+ __ sub(sp, sp, 4 * 16);
+ __ st1(v8, v9, v10, v11, __ T16B, Address(sp));
+ RegSet saved_regs = (RegSet::of(in, out, offset)
+ + RegSet::of(saved_encrypted_ctr, used_ptr, len));
+ __ push(saved_regs, sp);
+ __ andr(len, len, -16 * bulk_width); // 8/4 encryptions, 16 bytes per encryption
+ __ add(in, in, offset);
+ __ add(out, out, offset);
- // Encrypt the counters
- __ aesecb_encrypt(noreg, noreg, keylen, v0, bulk_width);
+ // Keys should already be loaded into the correct registers
- if (bulk_width == 8) {
- __ ld1(v12, v13, v14, v15, __ T16B, __ post(in, 4 * 16));
- }
+ __ ld1(v0, __ T16B, counter); // v0 contains the first counter
+ __ rev64(v16, __ T16B, v0); // v16 contains byte-reversed counter
- // XOR the encrypted counters with the inputs
- for (int i = 0; i < bulk_width; i++) {
- __ eor(v0 + i, __ T16B, v0 + i, v8 + i);
- }
+ // AES/CTR loop
+ {
+ Label L_CTR_loop;
+ __ BIND(L_CTR_loop);
- // Write the encrypted data
- __ st1(v0, v1, v2, v3, __ T16B, __ post(out, 4 * 16));
- if (bulk_width == 8) {
- __ st1(v4, v5, v6, v7, __ T16B, __ post(out, 4 * 16));
- }
+ // Setup the counters
+ __ movi(v8, __ T4S, 0);
+ __ movi(v9, __ T4S, 1);
+ __ ins(v8, __ S, v9, 2, 2); // v8 contains { 0, 1 }
- __ subw(len, len, 16 * bulk_width);
- __ cbnzw(len, L_CTR_loop);
+ for (FloatRegister f = v0; f < v0 + bulk_width; f++) {
+ __ rev64(f, __ T16B, v16);
+ be_add_128_64(v16, v16, v8, /*tmp*/v9);
}
- // Save the counter back where it goes
- __ rev32(v16, __ T16B, v16);
- __ st1(v16, __ T16B, counter);
+ __ ld1(v8, v9, v10, v11, __ T16B, __ post(in, 4 * 16));
- __ pop(saved_regs, sp);
+ // Encrypt the counters
+ __ aesecb_encrypt(noreg, noreg, keylen, v0, bulk_width);
- __ ld1(v8, v9, v10, v11, __ T16B, __ post(sp, 4 * 16));
if (bulk_width == 8) {
- __ ld1(v12, v13, v14, v15, __ T16B, __ post(sp, 4 * 16));
+ __ ld1(v12, v13, v14, v15, __ T16B, __ post(in, 4 * 16));
}
- __ andr(rscratch1, len, -16 * bulk_width);
- __ sub(len, len, rscratch1);
- __ add(offset, offset, rscratch1);
- __ mov(used, 16);
- __ strw(used, Address(used_ptr));
- __ b(large_block_return);
+ // XOR the encrypted counters with the inputs
+ for (int i = 0; i < bulk_width; i++) {
+ __ eor(v0 + i, __ T16B, v0 + i, v8 + i);
+ }
- return start;
+ // Write the encrypted data
+ __ st1(v0, v1, v2, v3, __ T16B, __ post(out, 4 * 16));
+ if (bulk_width == 8) {
+ __ st1(v4, v5, v6, v7, __ T16B, __ post(out, 4 * 16));
+ }
+
+ __ subw(len, len, 16 * bulk_width);
+ __ cbnzw(len, L_CTR_loop);
}
+ // Save the counter back where it goes
+ __ rev64(v16, __ T16B, v16);
+ __ st1(v16, __ T16B, counter);
+
+ __ pop(saved_regs, sp);
+
+ __ ld1(v8, v9, v10, v11, __ T16B, __ post(sp, 4 * 16));
+ if (bulk_width == 8) {
+ __ ld1(v12, v13, v14, v15, __ T16B, __ post(sp, 4 * 16));
+ }
+
+ __ andr(rscratch1, len, -16 * bulk_width);
+ __ sub(len, len, rscratch1);
+ __ add(offset, offset, rscratch1);
+ __ mov(used, 16);
+ __ strw(used, Address(used_ptr));
+ __ b(large_block_return);
+
+ return start;
+ }
+
// Arguments:
diff --git a/hotspot/test/compiler/codegen/aes/CTR_Wraparound.java b/hotspot/test/compiler/codegen/aes/CTR_Wraparound.java
new file mode 100644
index 000000000..f578b432c
--- /dev/null
+++ b/hotspot/test/compiler/codegen/aes/CTR_Wraparound.java
@@ -0,0 +1,169 @@
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.lang.reflect.Executable;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.concurrent.Callable;
+
+/**
+ * @test
+ * @bug 8308682
+ * @summary Check for 128-bit AES/CTR wraparound
+ * @library /testlibrary /testlibrary/whitebox /compiler/whitebox /compiler/testlibrary
+ * @build CTR_Wraparound
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:.
+ * -XX:+UnlockDiagnosticVMOptions
+ * -XX:+WhiteBoxAPI
+ * CTR_Wraparound 32
+ * @run main/othervm -Xbootclasspath/a:.
+ * -XX:+UnlockDiagnosticVMOptions
+ * -XX:+WhiteBoxAPI
+ * CTR_Wraparound 1009
+ * @run main/othervm -Xbootclasspath/a:.
+ * -XX:+UnlockDiagnosticVMOptions
+ * -XX:+WhiteBoxAPI
+ * CTR_Wraparound 2048
+ */
+
+public class CTR_Wraparound extends CompilerWhiteBoxTest {
+ private static final String ALGO = "AES/CTR/NoPadding";
+ private static final int LOOPS = 100000;
+ private int length;
+ private int maxOffset;
+
+ public CTR_Wraparound(int len,int offset){
+ super(new CTR_WraparoundTestCase());
+ length = len;
+ maxOffset = offset;
+ }
+
+ public static class CTR_WraparoundTestCase implements TestCase {
+
+ public String name() {
+ return "CTR_WraparoundTestCase";
+ }
+
+ public Executable getExecutable(){
+ try {
+ return Class.forName("com.sun.crypto.provider.CounterMode").getDeclaredMethod("implCrypt", byte[].class, int.class, int.class, byte[].class, int.class);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Test bug, method unavailable. " + e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Test bug, class unavailable. " + e);
+ }
+ }
+
+ public Callable<Integer> getCallable() {
+ return null;
+ }
+
+ public boolean isOsr() {
+ return false;
+ }
+
+ }
+
+ private static boolean isServerVM(String VMName) { return VMName.toLowerCase().contains("server");}
+
+
+
+ protected static boolean checkIntrinsicForCompilationLevel(Executable method, int compLevel) {
+ boolean intrinsicEnabled = Boolean.valueOf(getVMOption("UseAESCTRIntrinsics"));
+ boolean intrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(method,
+ compLevel);
+ if(intrinsicAvailable && intrinsicEnabled){
+ return true;
+ }
+ return false;
+ }
+
+ public static void main(String[] args) throws Exception {
+ int length = Integer.parseInt(args[0]);
+ int maxOffset = 60;
+ if (args.length > 1) {
+ maxOffset = Integer.parseInt(args[1]);
+ System.out.println("InitialOffset = " + maxOffset);
+ }
+ new CTR_Wraparound(length,maxOffset).test();
+ }
+
+ @Override
+ protected void test() throws Exception {
+
+ String VMName = System.getProperty("java.vm.name");
+ Executable intrinsicMethod = testCase.getExecutable();
+ boolean isIntrinsicEnabled = false;
+ if (isServerVM(VMName)) {
+ if (TIERED_COMPILATION) {
+ isIntrinsicEnabled = checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);
+ }
+ isIntrinsicEnabled = checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_FULL_OPTIMIZATION);
+ } else {
+ isIntrinsicEnabled = checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);
+ }
+ if(!isIntrinsicEnabled){
+ return;
+ }
+
+
+ long SEED = Long.getLong("jdk.test.lib.random.seed", new Random().nextLong());
+ Random random = new Random(SEED);
+
+ byte[] keyBytes = new byte[32];
+ Arrays.fill(keyBytes, (byte)0xff);
+ SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
+
+ byte[] ivBytes = new byte[16];
+
+ Arrays.fill(ivBytes, (byte)0xff);
+
+ byte[][] plaintext = new byte[maxOffset][];
+ byte[][] ciphertext = new byte[maxOffset][];
+
+ for (int offset = 0; offset < maxOffset; offset++) {
+ ivBytes[ivBytes.length - 1] = (byte)-offset;
+ IvParameterSpec iv = new IvParameterSpec(ivBytes);
+
+ Cipher encryptCipher = Cipher.getInstance(ALGO);
+ Cipher decryptCipher = Cipher.getInstance(ALGO);
+
+ encryptCipher.init(Cipher.ENCRYPT_MODE, key, iv);
+ decryptCipher.init(Cipher.DECRYPT_MODE, key, iv);
+
+ plaintext[offset] = new byte[length];
+ ciphertext[offset] = new byte[length];
+ random.nextBytes(plaintext[offset]);
+
+ byte[] decrypted = new byte[length];
+
+ encryptCipher.doFinal(plaintext[offset], 0, length, ciphertext[offset]);
+ decryptCipher.doFinal(ciphertext[offset], 0, length, decrypted);
+
+ if (!Arrays.equals(plaintext[offset], decrypted)) {
+ throw new Exception("mismatch in setup at offset " + offset);
+ }
+ }
+
+ for (int offset = 0; offset < maxOffset; offset++) {
+ ivBytes[ivBytes.length - 1] = (byte)-offset;
+ IvParameterSpec iv = new IvParameterSpec(ivBytes);
+
+ Cipher encryptCipher = Cipher.getInstance(ALGO);
+
+ encryptCipher.init(Cipher.ENCRYPT_MODE, key, iv);
+
+ byte[] encrypted = new byte[length];
+
+ for (int i = 0; i < LOOPS; i++) {
+ encryptCipher.doFinal(plaintext[offset], 0, length, encrypted);
+ if (!Arrays.equals(ciphertext[offset], encrypted)) {
+ throw new Exception("array mismatch at offset " + offset
+ + " with length " + length);
+ }
+ }
+ }
+ }
+}
--
2.19.1

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,39 @@
From 0778f0119083ae33aea5ce9b5a1b44f565f45397 Mon Sep 17 00:00:00 2001
Date: Thu, 19 Oct 2023 15:25:43 +0800
Subject: [PATCH 4/5] Add metaspace memory allocation failure validation
---
hotspot/src/share/vm/memory/metaspace.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp
index 0569500c1..f39ae41f3 100644
--- a/hotspot/src/share/vm/memory/metaspace.cpp
+++ b/hotspot/src/share/vm/memory/metaspace.cpp
@@ -571,7 +571,7 @@ class OccupancyMap : public CHeapObj<mtInternal> {
assert(_map_size * 8 >= num_bits, "sanity");
_map[0] = (uint8_t*) os::malloc(_map_size, mtInternal);
_map[1] = (uint8_t*) os::malloc(_map_size, mtInternal);
- assert(_map[0] != NULL && _map[1] != NULL, "Occupancy Map: allocation failed.");
+ guarantee(_map[0] != NULL && _map[1] != NULL, "Metaspace Occupancy Map: allocation failed.");
memset(_map[1], 0, _map_size);
memset(_map[0], 0, _map_size);
// Sanity test: the first respectively last possible chunk start address in
@@ -918,6 +918,14 @@ void VirtualSpaceNode::print_map(outputStream* st, bool is_class) const {
char* lines[NUM_LINES];
for (int i = 0; i < NUM_LINES; i ++) {
lines[i] = (char*)os::malloc(line_len, mtInternal);
+ // Only print the VirtualSpaceNode memory layout during metaspace OOM.
+ // If it fails,we should return instead of hanging the VM.
+ if (lines[i] == NULL) {
+ for (int j = 0; j < i; j ++) {
+ os::free(lines[j]);
+ }
+ return;
+ }
}
int pos = 0;
const MetaWord* p = bottom();
--
2.19.1

View File

@ -3047,12 +3047,8 @@ index 8dd4e6b21..6a2d8077f 100644
void SymbolTable::buckets_unlink(int start_idx, int end_idx, BucketUnlinkContext* context, size_t* memory_total) {
for (int i = start_idx; i < end_idx; ++i) {
@@ -225,10 +241,25 @@ Symbol* SymbolTable::lookup(int index, const char* name,
unsigned int SymbolTable::hash_symbol(const char* s, int len) {
return use_alternate_hashcode() ?
AltHashing::halfsiphash_32(seed(), (const uint8_t*)s, len) :
- java_lang_String::hash_code(s, len);
+ java_lang_String::hash_code((const jbyte*)s, len);
@@ -228,7 +244,22 @@ Symbol* SymbolTable::lookup(int index, const char* name,
java_lang_String::hash_code((const jbyte*)s, len);
}
+#if INCLUDE_CDS

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

@ -0,0 +1,24 @@
From 1c55195c050d26f7c3ef53ed8f4ff25f398cfa1e Mon Sep 17 00:00:00 2001
Date: Thu, 19 Oct 2023 11:24:12 +0800
Subject: [PATCH 2/5] Fix the memory leak of MetaspaceAllocationTest
---
hotspot/src/share/vm/memory/metaspace.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp
index 0569500c1..847af1ce9 100644
--- a/hotspot/src/share/vm/memory/metaspace.cpp
+++ b/hotspot/src/share/vm/memory/metaspace.cpp
@@ -5712,6 +5712,8 @@ public:
for (int i = 0; i < NUM_PARALLEL_METASPACES; i ++) {
if (_spaces[i].space != NULL) {
delete _spaces[i].space;
+ }
+ if (_spaces[i].lock != NULL) {
delete _spaces[i].lock;
}
}
--
2.19.1

View File

@ -63,7 +63,7 @@ index f4e127145..133b5a7c0 100644
+ // remove the existing normal file
+ char exist_file_name[JVM_MAXPATHLEN];
+ jio_snprintf(exist_file_name, JVM_MAXPATHLEN, "%s.%d", filename, next_num);
+ if (access(exist_file_name, F_OK) == 0) {
+ if (access(exist_file_name, 0) == 0) { // mode 0: Check whether the file exists, F_OK=0. F_OK will cause Windows build failure. Use 0 instead.
+ if (remove(exist_file_name) != 0) {
+ warning("Could not delete existing normal file %s\n", exist_file_name);
+ }

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.382.5.0.13
+8.392.8.0.13
--
2.23.0

View File

@ -0,0 +1,157 @@
From 9b431c9bba018a2dd2bb6850cfd674b51207bf49 Mon Sep 17 00:00:00 2001
Date: Thu, 19 Oct 2023 01:37:43 +0000
Subject: [PATCH 3/5] change value of GCLockerRetryAllocationCount from 2 to
1000 to avoid OOM
---
hotspot/src/share/vm/runtime/globals.hpp | 2 +-
.../g1/TestGcLockerEvacFailureThreaded.java | 124 ++++++++++++++++++
2 files changed, 125 insertions(+), 1 deletion(-)
create mode 100644 hotspot/test/gc/g1/TestGcLockerEvacFailureThreaded.java
diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp
index fdd9db149..65806a475 100644
--- a/hotspot/src/share/vm/runtime/globals.hpp
+++ b/hotspot/src/share/vm/runtime/globals.hpp
@@ -1575,7 +1575,7 @@ class CommandLineFlags {
"How much the GC can expand the eden by while the GC locker " \
"is active (as a percentage)") \
\
- diagnostic(uintx, GCLockerRetryAllocationCount, 2, \
+ diagnostic(uintx, GCLockerRetryAllocationCount, 1000, \
"Number of times to retry allocations when " \
"blocked by the GC locker") \
\
diff --git a/hotspot/test/gc/g1/TestGcLockerEvacFailureThreaded.java b/hotspot/test/gc/g1/TestGcLockerEvacFailureThreaded.java
new file mode 100644
index 000000000..74accd951
--- /dev/null
+++ b/hotspot/test/gc/g1/TestGcLockerEvacFailureThreaded.java
@@ -0,0 +1,124 @@
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.zip.GZIPOutputStream;
+
+import com.oracle.java.testlibrary.ProcessTools;
+import com.oracle.java.testlibrary.OutputAnalyzer;
+
+/*
+ * @test TestGcLockerEvacFailureThreaded.java
+ * @bug 8048556 8137099
+ * @summary Ensure that GCLocker does not cause early program termination.
+ * @key gc
+ * @library /testlibrary
+ */
+public class TestGcLockerEvacFailureThreaded {
+ public static void main(String[] args) throws Exception {
+ System.out.println("Beginning test\n");
+
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
+ "-Xmx64m",
+ TestGcLocker.class.getName());
+
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+ System.out.println("Output:\n" + output.getOutput());
+
+ output.shouldNotContain("java.lang.OutOfMemoryError");
+ output.shouldHaveExitValue(0);
+ }
+
+ /**
+ * Tests whether GCLocker terminates the application when forced to spin multiple times.
+ * We cause a long-running native call during which a GC is invoked by another thread.
+ */
+ static class TestGcLocker {
+
+ private static int gzipItemLengthBytes = 10500;
+ private static int nGzipItems = 3500;
+ private static int aliveDataItems = (int) (nGzipItems * 0.7);
+
+ private static int nThreads = 500;
+ private static int loopSize = 1000;
+
+ private static List<byte[]> dataToBeGzipped = new ArrayList<>(nGzipItems);
+
+ private static List<byte[]> aliveData = new ArrayList<>(aliveDataItems);
+
+ private static Random randomGenerator = new Random();
+
+ private static volatile boolean cont = true;
+
+ private static void createData(int gzipItemLengthBytes, int nGzipItems) throws IOException {
+ for (int gzipDataIndex = 0; gzipDataIndex < nGzipItems; gzipDataIndex++) {
+ ByteBuffer buffer = ByteBuffer.allocate(gzipItemLengthBytes);
+ for (int i = 0; i < gzipItemLengthBytes/4; i++) { // since integer is 4 bytes
+ int randomInt = randomGenerator.nextInt(100);
+ buffer.putInt(randomInt);
+ }
+ byte[] data = buffer.array();
+ dataToBeGzipped.add(data);
+ }
+
+ for (int i = 0; i < aliveDataItems; i++) {
+ aliveData.add(new byte[0]);
+ }
+
+ for (int gzipDataIndex = 0; gzipDataIndex < nGzipItems; gzipDataIndex++) {
+ native_critical_section(dataToBeGzipped.get(gzipDataIndex));
+ }
+
+ }
+
+ public static void runTest(int loopSize) {
+ try {
+ int i = 0;
+ while (cont && (i < loopSize)) {
+ i++;
+ try {
+ native_critical_section(dataToBeGzipped.get(i % nGzipItems));
+ } catch (OutOfMemoryError e) {
+ cont = false; //Remove this if you still want to continue after OOME
+ e.printStackTrace();
+ }
+ }
+
+ } catch (IOException e) {
+ cont = true;
+ e.printStackTrace();
+ }
+ }
+
+ private static void native_critical_section(byte[] data) throws IOException {
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(bos)) {
+ gzos.write(data);
+ gzos.finish();
+ byte[] compressedData = bos.toByteArray();
+ int index = randomGenerator.nextInt(aliveDataItems);
+ aliveData.set(index, compressedData);
+ }
+ }
+
+ public static void main(String[] args) throws InterruptedException, IOException {
+ createData(gzipItemLengthBytes, nGzipItems);
+
+ System.gc(); //This will tell us the resident set size
+
+ for (int i = 0; i < nThreads; i++) {
+ Thread t = new Thread() {
+ public void run() {
+ runTest(loopSize);
+ }
+ };
+ t.start();
+ }
+ System.out.println("Threads started");
+ }
+ }
+}
+
--
2.19.1

View File

@ -35,7 +35,7 @@ diff --git a/jdk/test/sun/security/lib/cacerts/VerifyCACerts.java b/jdk/test/sun
index 54e1bfa0d..c1423dc5b 100644
--- a/jdk/test/sun/security/lib/cacerts/VerifyCACerts.java
+++ b/jdk/test/sun/security/lib/cacerts/VerifyCACerts.java
@@ -53,12 +53,12 @@ public class VerifyCACerts {
@@ -54,12 +54,12 @@ public class VerifyCACerts {
+ File.separator + "security" + File.separator + "cacerts";
// The numbers of certs now.
@ -46,10 +46,10 @@ 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
@@ -111,7 +111,9 @@ public class VerifyCACerts {
"7E:37:CB:8B:4C:47:09:0C:AB:36:55:1B:A6:F4:5D:B8:40:68:0F:BA:16:6A:95:2D:B1:00:71:7F:43:05:3F:C2");
put("digicerthighassuranceevrootca [jdk]",

View File

@ -5485,7 +5485,7 @@ index 50f65eab..a388c76a 100644
+ "kae.disableKaeDispose", "read"));
if (lib != null) {
p.env("KRB5_CONFIG", CONF)
.env("KRB5_TRACE", "/dev/stderr")
.env("KRB5_TRACE", Platform.isWindows() ? "CON" : "/dev/stderr")
--
2.19.0

View File

@ -155,13 +155,13 @@
%global origin_nice OpenJDK
%global top_level_dir_name %{origin}
%global repo jdk8u
%global revision jdk8u382-b05
%global revision jdk8u392-b08
%global full_revision %{repo}-%{revision}
# Define IcedTea version used for SystemTap tapsets and desktop files
%global icedteaver 3.15.0
%global updatever 382
%global buildver b05
%global updatever 392
%global buildver b08
# priority must be 7 digits in total. The expression is workarounding tip
%global priority 1800%{updatever}
@ -925,7 +925,7 @@ Provides: java-%{javaver}-%{origin}-accessibility%{?1} = %{epoch}:%{version}-%{r
Name: java-%{javaver}-%{origin}
Version: %{javaver}.%{updatever}.%{buildver}
Release: 11
Release: 2
# 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
@ -982,7 +982,6 @@ Source20: repackReproduciblePolycies.sh
Patch8: replace-vector-to-improve-performance-of-xml.validat.patch
Patch10: 8221658.patch
Patch18: fix-vendor-info.patch
Patch21: 8202952.patch
Patch25: 8196485.patch
Patch26: disable-UseLSE-on-ARMv8.1-by-default.patch
Patch27: 8157570.patch
@ -1253,7 +1252,6 @@ Patch364: enhance-java-heap-oom-err-log.patch
Patch365: 8014628-Support-AES-Encryption-with-HMAC-SHA2-for-Ke.patch
Patch366: 8179273-sun.net.httpserver.LeftOverInputStream-shoul.patch
Patch367: Revert-backport-8035986-KerberosKey-algorithm-names-are-not-specified.patch
Patch368: 8283441-C2-segmentation-fault-in-ciMethodBlocks-make.patch
Patch369: add-0010-8301749-Tracking-malloc-pooled-memory-size.patch
Patch370: 8213397-Stack-dump-should-show-more-clearly-when-a-t.patch
Patch371: Record-the-number-of-processes-to-errlog-file.patch.patch
@ -1261,23 +1259,34 @@ Patch372: 8254723-Add-diagnostic-command-to-write-Linux-perf-m.patch
Patch373: The-OverWriteOldestGCLog-option-is-added-to-control.patch
Patch374: add-6899049-G1-Clean-up-code-in-ptrQueue.-ch-pp-and-.patch
Patch375: add-make-Appcds-jsa-rw-region-deterministic.patch
Patch376: add-8142508-To-bring-j.u.z.ZipFile-s-native-implemen.patch
Patch377: add-8198423-Improve-metaspace-chunk-allocation.patch
Patch378: add-8226530-ZipFile-reads-wrong-entry-size-from-ZIP6.patch
Patch379: add-fix-lock_fd-no-close-and-improve-KAEProvider.patch
Patch380: add-8242842-Avoid-reallocating-name-when-checking-fo.patch
Patch381: add-8170831-ZipFile-implementation-no-longer-caches-.patch
Patch382: add-8146431-j.u.z.ZipFile.getEntry-throws-AIOOBE.patch
Patch383: add-8226530-test-case-fixed.patch
Patch384: add-8147940-Modify-testcase-this-test-does-not-assum.patch
Patch385: add-8191924-Adjust-DelegatingClassLoader-s-metadata-.patch
Patch386: add-Do-not-collect_class-when-DynamicCDS-dump.patch
Patch387: add-add-Count-instance-klass-when-loading-from-jsa-f.patch
Patch388: add-Adapting-IOException-of-Zip-to-ZipException.patch
Patch389: add-8227041-runtime-memory-RunUnitTestsConcurrently.patch
Patch390: add-fix-windows-build-Dynamic-CDS-failure.patch
Patch391: add-Fix-aarch64-runtime-thread-signal-transfer-bug.patch
Patch392: 8295068-SSLEngine-throws-NPE-parsing-CertificateRequ.patch
Patch393: 8308682-Enhance-AES-performance.patch
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
#############################################
#
@ -1620,7 +1629,6 @@ pushd %{top_level_dir_name}
%patch8 -p1
%patch10 -p1
%patch18 -p1
%patch21 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
@ -1859,7 +1867,6 @@ pushd %{top_level_dir_name}
%patch365 -p1
%patch366 -p1
%patch367 -p1
%patch368 -p1
%patch369 -p1
%patch370 -p1
%patch371 -p1
@ -1867,23 +1874,32 @@ pushd %{top_level_dir_name}
%patch373 -p1
%patch374 -p1
%patch375 -p1
%patch376 -p1
%patch377 -p1
%patch378 -p1
%patch379 -p1
%patch380 -p1
%patch381 -p1
%patch382 -p1
%patch383 -p1
%patch384 -p1
%patch385 -p1
%patch386 -p1
%patch387 -p1
%patch388 -p1
%patch389 -p1
%patch390 -p1
%patch391 -p1
%patch392 -p1
%patch393 -p1
%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
@ -2527,8 +2543,43 @@ require "copy_jdk_configs.lua"
%endif
%changelog
* Thu Oct 12 2023 DXwangg <wangjiawei80@huawei.com> - 1:1.8.0.382-b05.11
- fix [EulerMaker] openjdk-1.8.0 build problem in openEuler-20.03-LTS-SP4:everything
* Mon Oct 30 2023 kuenking111 <wangkun49@huawei.com> - 1:1.8.0.392-b08.2
- remove add-8142508-To-bring-j.u.z.ZipFile-s-native-implemen.patch
- remove add-8226530-ZipFile-reads-wrong-entry-size-from-ZIP6.patch
- remove add-8242842-Avoid-reallocating-name-when-checking-fo.patch
- remove add-8170831-ZipFile-implementation-no-longer-caches-.patch
- remove add-8146431-j.u.z.ZipFile.getEntry-throws-AIOOBE.patch
- remove add-8226530-test-case-fixed.patch
- remove add-Adapting-IOException-of-Zip-to-ZipException.patch
* 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
- add Add-metaspace-memory-allocation-failure-validation.patch
- add change-value-of-GCLockerRetryAllocationCount-from-2-.patch
- del 8202952.patch
- del 8283441-C2-segmentation-fault-in-ciMethodBlocks-make.patch
- modified Dynamic-CDS-Archive.patch
- modified fix_X509TrustManagerImpl_symantec_distrust.patch
- modified kae-phase1.patch
- modified update-cacerts-and-VerifyCACerts.java-test.patch
- upgrade to jdk8u392-b08
* Mon Sep 25 2023 kuenking111 <wangkun49@huawei.com> - 1:1.8.0.382-b05.10
- del useless code

View File

@ -253,7 +253,7 @@ diff --git a/jdk/test/sun/security/lib/cacerts/VerifyCACerts.java b/jdk/test/sun
index dd107fc..791ddb6 100644
--- a/jdk/test/sun/security/lib/cacerts/VerifyCACerts.java
+++ b/jdk/test/sun/security/lib/cacerts/VerifyCACerts.java
@@ -53,12 +53,12 @@ public class VerifyCACerts {
@@ -54,12 +54,12 @@ public class VerifyCACerts {
+ File.separator + "security" + File.separator + "cacerts";
// The numbers of certs now.
@ -263,11 +263,11 @@ index dd107fc..791ddb6 100644
// 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
- = "72:C7:B8:9E:54:94:D2:D9:C0:E5:9F:F7:C3:8C:3B:18:D7:42:23:82:51:F2:AD:A1:14:26:E0:4A:F2:5F:AE:80";
- = "88:72:92:56:FF:E5:A3:E4:39:98:6D:18:0B:BA:CC:0B:66:CB:1D:6D:52:CE:D7:C8:AD:63:B7:F1:5F:02:24:52";
+ = "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";
// map of cert alias to SHA-256 fingerprint
@SuppressWarnings("serial")
private static final Map<String, String> FINGERPRINT_MAP
@@ -93,12 +93,6 @@ public class VerifyCACerts {
"E7:93:C9:B0:2F:D8:AA:13:E2:1C:31:22:8A:CC:B0:81:19:64:3B:74:9C:89:89:64:B1:74:6D:46:C3:D4:CB:D2");
put("usertrusteccca [jdk]",