|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8258229 |
| 27 | + * @summary If a method is made not entrant while printing the assembly, hotspot crashes due to mismatched relocation information. |
| 28 | + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -XX:+DeoptimizeALot -XX:CompileCommand=print,java/math/BitSieve.bit |
| 29 | + * compiler.print.TestPrintAssemblyDeoptRace |
| 30 | + */ |
| 31 | + |
| 32 | +package compiler.print; |
| 33 | + |
| 34 | +import java.util.Arrays; |
| 35 | + |
| 36 | +import java.security.Security; |
| 37 | +import java.security.Provider; |
| 38 | +import java.security.KeyPair; |
| 39 | +import java.security.KeyPairGenerator; |
| 40 | +import java.security.interfaces.RSAPrivateKey; |
| 41 | +import java.security.interfaces.RSAPublicKey; |
| 42 | +import java.security.spec.MGF1ParameterSpec; |
| 43 | + |
| 44 | +import javax.crypto.Cipher; |
| 45 | +import javax.crypto.spec.OAEPParameterSpec; |
| 46 | +import javax.crypto.spec.PSource; |
| 47 | + |
| 48 | +public class TestPrintAssemblyDeoptRace { |
| 49 | + private static RSAPrivateKey privateKey; |
| 50 | + private static RSAPublicKey publicKey; |
| 51 | + static Provider cp; |
| 52 | + |
| 53 | + public static void main(String args[]) throws Exception { |
| 54 | + cp = Security.getProvider("SunJCE"); |
| 55 | + System.out.println("Testing provider " + cp.getName() + "..."); |
| 56 | + Provider kfp = Security.getProvider("SunRsaSign"); |
| 57 | + KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", kfp); |
| 58 | + kpg.initialize(2048); |
| 59 | + KeyPair kp = kpg.generateKeyPair(); |
| 60 | + privateKey = (RSAPrivateKey) kp.getPrivate(); |
| 61 | + publicKey = (RSAPublicKey) kp.getPublic(); |
| 62 | + testEncryptDecrypt(new OAEPParameterSpec("SHA-512/256", "MGF1", |
| 63 | + MGF1ParameterSpec.SHA512, PSource.PSpecified.DEFAULT), 190); |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + private static void testEncryptDecrypt(OAEPParameterSpec spec, |
| 68 | + int dataLength) throws Exception { |
| 69 | + |
| 70 | + Cipher c = Cipher.getInstance("RSA/ECB/OAEPPadding", cp); |
| 71 | + c.init(Cipher.ENCRYPT_MODE, publicKey, spec); |
| 72 | + |
| 73 | + byte[] data = new byte[dataLength]; |
| 74 | + byte[] enc = c.doFinal(data); |
| 75 | + c.init(Cipher.DECRYPT_MODE, privateKey, spec); |
| 76 | + } |
| 77 | +} |
0 commit comments