Skip to content

Commit babd610

Browse files
author
duke
committed
Added webrev for crac/9
1 parent 779628b commit babd610

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

crac/9/00/commits.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"commit":{"message":"Reseed NativePRNG on checkpoint restore"},"files":[{"filename":"src\/java.base\/unix\/classes\/sun\/security\/provider\/NativePRNG.java"},{"filename":"test\/jdk\/jdk\/crac\/SecureRandom\/Test.java"},{"filename":"test\/jdk\/jdk\/crac\/SecureRandom\/Test.sh"}],"sha":"894576ee46dddb6ec118f49213610e8e86dcb098"}]

crac/9/00/comparison.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"files":[{"patch":"@@ -32,0 +32,1 @@\n+import java.util.concurrent.locks.ReentrantLock;\n@@ -33,0 +34,3 @@\n+import jdk.crac.Context;\n+import jdk.crac.Resource;\n+import jdk.internal.crac.JDKResource;\n@@ -332,1 +336,1 @@\n- private static class RandomIO {\n+ private static class RandomIO implements JDKResource {\n@@ -386,0 +390,3 @@\n+ \/\/ lock for checkpoint\/restore\n+ private final ReentrantLock crLock = new ReentrantLock();\n+\n@@ -478,1 +485,6 @@\n- getMixRandom().engineSetSeed(seed);\n+ crLock.lock();\n+ try {\n+ getMixRandom().engineSetSeed(seed);\n+ } finally {\n+ crLock.unlock();\n+ }\n@@ -536,0 +548,1 @@\n+ crLock.lock();\n@@ -569,0 +582,2 @@\n+ } finally {\n+ crLock.unlock();\n@@ -571,0 +586,15 @@\n+\n+ @Override\n+ public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {\n+ crLock.lock();\n+ mixRandom = null;\n+ buffered = 0;\n+ lastRead = 0;\n+ for(int i=0; i<nextBuffer.length; i++) {\n+ nextBuffer[i] = 0;\n+ }\n+ }\n+\n+ @Override\n+ public void afterRestore(Context<? extends Resource> context) throws Exception {\n+ crLock.unlock();\n@@ -572,0 +602,7 @@\n+\n+ @Override\n+ public int getPriority() {\n+ return 0;\n+ }\n+\n+ }\n","filename":"src\/java.base\/unix\/classes\/sun\/security\/provider\/NativePRNG.java","additions":39,"deletions":2,"binary":false,"changes":41,"status":"modified"},{"patch":"@@ -0,0 +1,160 @@\n+\/\/ Copyright 2019-2021 Azul Systems, Inc. All Rights Reserved.\n+\/\/ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n+\/\/\n+\/\/ This code is free software; you can redistribute it and\/or modify it under\n+\/\/ the terms of the GNU General Public License version 2 only, as published by\n+\/\/ the Free Software Foundation.\n+\/\/\n+\/\/ This code is distributed in the hope that it will be useful, but WITHOUT ANY\n+\/\/ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n+\/\/ A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more\n+\/\/ details (a copy is included in the LICENSE file that accompanied this code).\n+\/\/\n+\/\/ You should have received a copy of the GNU General Public License version 2\n+\/\/ along with this work; if not, write to the Free Software Foundation, Inc.,\n+\/\/ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n+\/\/\n+\/\/ Please contact Azul Systems, 385 Moffett Park Drive, Suite 115, Sunnyvale,\n+\/\/ CA 94089 USA or visit www.azul.com if you need additional information or\n+\/\/ have any questions.\n+\n+\n+import jdk.crac.*;\n+import java.util.Random;\n+import java.security.SecureRandom;\n+import java.util.concurrent.atomic.AtomicLong;\n+\n+public class Test implements Resource {\n+\n+ private static final AtomicLong counter = new AtomicLong(0);\n+ private static boolean stop = false;\n+ private static final long MIN_TIMEOUT = 100;\n+ private static final long MAX_TIMEOUT = 1000;\n+ private static SecureRandom sr;\n+ private static String algName = null;\n+\n+ private static class TestThread1 extends Thread {\n+ private long timeout;\n+\n+ TestThread1(long timeout) {\n+ this.timeout = timeout;\n+ }\n+\n+ @Override\n+ public void run() {\n+ while (!stop) {\n+ Test.set();\n+ }\n+ }\n+ };\n+\n+ private static class TestThread2 extends Thread implements Resource {\n+ private long timeout;\n+ private SecureRandom sr;\n+\n+ synchronized void set() {\n+ sr.nextInt();\n+ }\n+ synchronized void clean() {\n+ sr.nextInt();\n+ }\n+\n+ TestThread2(long timeout) throws Exception {\n+ this.timeout = timeout;\n+ sr = SecureRandom.getInstance(algName);\n+ Core.getGlobalContext().register(this);\n+ }\n+\n+ @Override\n+ public void run() {\n+ while (!stop) {\n+ set();\n+ }\n+ }\n+\n+ @Override\n+ public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {\n+ clean();\n+ }\n+\n+ @Override\n+ public void afterRestore(Context<? extends Resource> context) throws Exception {\n+ set();\n+ }\n+ };\n+\n+ synchronized static void clean() {\n+ sr.nextInt();\n+ }\n+\n+ synchronized static void set() {\n+ sr.nextInt();\n+ }\n+\n+ @Override\n+ public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {\n+ try {\n+ clean();\n+ } catch(Exception e) {\n+ e.printStackTrace(System.out);\n+ };\n+ }\n+\n+ @Override\n+ public void afterRestore(Context<? extends Resource> context) throws Exception {\n+ set();\n+ stop = true;\n+ }\n+\n+ public static void main(String args[]) throws Exception {\n+ if (args.length < 1) { throw new RuntimeException(\"Alg name is not provided\"); }\n+ if (args.length < 2) { throw new RuntimeException(\"number of threads is missing\"); }\n+ algName = args[0];\n+ int numThreads;\n+ try{\n+ numThreads = Integer.parseInt(args[1]);\n+ } catch (NumberFormatException ex){\n+ throw new RuntimeException(\"invalid number of threads\");\n+ }\n+ Test test = new Test();\n+ test.sr = SecureRandom.getInstance(algName);\n+ Core.getGlobalContext().register(test);\n+\n+ Random random = new Random();\n+ Thread[] threads = new Thread[numThreads];\n+ for(int i=0; i<numThreads; i++) {\n+ threads[i] = (i%2==0)?\n+ new TestThread1(random.nextLong(MAX_TIMEOUT - MIN_TIMEOUT) + MIN_TIMEOUT):\n+ new TestThread2(random.nextLong(MAX_TIMEOUT - MIN_TIMEOUT) + MIN_TIMEOUT);\n+ threads[i].start();\n+ };\n+ Thread.currentThread().sleep(MIN_TIMEOUT);\n+ set();\n+ Thread.currentThread().sleep(MIN_TIMEOUT);\n+\n+ Object checkpointLock = new Object();\n+ Thread checkpointThread = new Thread(\"checkpointThread\") {\n+ public void run() {\n+ synchronized (checkpointLock) {\n+ try {\n+ jdk.crac.Core.checkpointRestore();\n+ } catch (CheckpointException e) {\n+ throw new RuntimeException(\"Checkpoint ERROR \" + e);\n+ } catch (RestoreException e) {\n+ throw new RuntimeException(\"Restore ERROR \" + e);\n+ }\n+ checkpointLock.notify();\n+ }\n+ }\n+ };\n+ synchronized (checkpointLock) {\n+ try {\n+ checkpointThread.start();\n+ checkpointLock.wait(MAX_TIMEOUT * 2);\n+ } catch(Exception e){\n+ throw new RuntimeException(\"Checkpoint\/Restore ERROR \" + e);\n+ }\n+ }\n+ Thread.currentThread().sleep(MAX_TIMEOUT);\n+ }\n+}\n","filename":"test\/jdk\/jdk\/crac\/SecureRandom\/Test.java","additions":160,"deletions":0,"binary":false,"changes":160,"status":"added"},{"patch":"@@ -0,0 +1,45 @@\n+#!\/bin\/sh\n+\n+# Copyright 2019-2021 Azul Systems, Inc. All Rights Reserved.\n+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n+#\n+# This code is free software; you can redistribute it and\/or modify it under\n+# the terms of the GNU General Public License version 2 only, as published by\n+# the Free Software Foundation.\n+#\n+# This code is distributed in the hope that it will be useful, but WITHOUT ANY\n+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n+# A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more\n+# details (a copy is included in the LICENSE file that accompanied this code).\n+#\n+# You should have received a copy of the GNU General Public License version 2\n+# along with this work; if not, write to the Free Software Foundation, Inc.,\n+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n+#\n+# Please contact Azul Systems, 385 Moffett Park Drive, Suite 115, Sunnyvale,\n+# CA 94089 USA or visit www.azul.com if you need additional information or\n+# have any questions.\n+\n+\n+##\n+## @test Test.sh\n+## @summary verify that secure random is not interlocked during checkpoint\/restore\n+## @compile Test.java\n+## @run shell\/timeout=60 Test.sh\n+##\n+\n+set -x\n+\n+AlgNames = \"SHA1PRNG NativePRNGBlocking NativePRNGNonBlocking NativePRNG\"\n+for alg in $AlgNames; do\n+set +e\n+${TESTJAVA}\/bin\/java -cp ${TESTCLASSPATH} -XX:CRaCCheckpointTo=cr Test $alg 100\n+e=$?\n+\n+set -e\n+[ $e -eq 137 ]\n+\n+${TESTJAVA}\/bin\/java -cp ${TESTCLASSPATH} -XX:CRaCRestoreFrom=cr Test $alg 100\n+\n+echo PASSED\n+done\n","filename":"test\/jdk\/jdk\/crac\/SecureRandom\/Test.sh","additions":45,"deletions":0,"binary":false,"changes":45,"status":"added"}]}

crac/9/00/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"head":{"repo":{"full_name":"alexeybakhtin\/crac-new","html_url":"https:\/\/github.com\/alexeybakhtin\/crac-new"},"sha":"894576ee46dddb6ec118f49213610e8e86dcb098"},"created_at":"2021-12-23T11:48:02.716234520Z","base":{"repo":{"full_name":"openjdk\/crac","html_url":"https:\/\/git.openjdk.java.net\/crac"},"sha":"f25eb7b886f59306346b0f19dc935dd7ab3114c6"}}

0 commit comments

Comments
 (0)