Mercurial > hg > truffle
annotate graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java @ 19001:5a79fa76b489
Run eclipse format.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 28 Jan 2015 04:05:07 +0100 |
parents | cdb9c605051a |
children | cd6821e84e59 |
rev | line source |
---|---|
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
18176
c2270ad35f57
Better construction of data section and data patches.
Roland Schatz <roland.schatz@oracle.com>
parents:
18127
diff
changeset
|
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.hotspot.test; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import java.lang.reflect.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import java.security.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 import javax.crypto.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 import org.junit.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.api.code.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.api.meta.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.hotspot.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 import com.oracle.graal.hotspot.bridge.CompilerToVM.CodeInstallResult; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 import com.oracle.graal.hotspot.meta.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 import com.oracle.graal.nodes.*; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 /** |
9767
e415e58e0db2
changed location of debug scope so that a subclass that overrides 'addMethod' still matches -G:Dump=CodeInstall option
Doug Simon <doug.simon@oracle.com>
parents:
9766
diff
changeset
|
41 * Tests the intrinsification of certain crypto methods. |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 */ |
18531
cdb9c605051a
removed some static accesses to HotSpotGraalRuntime from some tests
Doug Simon <doug.simon@oracle.com>
parents:
18176
diff
changeset
|
43 public class HotSpotCryptoSubstitutionTest extends HotSpotGraalCompilerTest { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 @Override |
10019
6e4b72bcc97f
Remove graph from HotSpotNMethod
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
9767
diff
changeset
|
46 protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; |
12517
b2882f4ab612
Add an optional name to HotSpotNmethod. Print it during deopt. Use it when installing a Truffle compilation
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12431
diff
changeset
|
48 HotSpotNmethod installedCode = new HotSpotNmethod(hsMethod, compResult.getName(), true); |
18176
c2270ad35f57
Better construction of data section and data patches.
Roland Schatz <roland.schatz@oracle.com>
parents:
18127
diff
changeset
|
49 HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(hsMethod, compResult); |
12431
7080a96be216
rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents:
12054
diff
changeset
|
50 CodeInstallResult result = runtime().getCompilerToVM().installCode(compiledNmethod, installedCode, null); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 Assert.assertEquals("Error installing method " + method + ": " + result, result, CodeInstallResult.OK); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 |
12045
0fc653a9e019
made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12043
diff
changeset
|
53 // HotSpotRuntime hsRuntime = (HotSpotRuntime) getCodeCache(); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 // TTY.println(hsMethod.toString()); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 // TTY.println(hsRuntime.disassemble(installedCode)); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 return installedCode; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 @Test |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
60 public void testEncryptSubstitution() throws Exception { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 byte[] seed = {0x4, 0x7, 0x1, 0x1}; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 SecureRandom random = new SecureRandom(seed); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 KeyGenerator aesKeyGen = KeyGenerator.getInstance("AES"); |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
64 KeyGenerator desKeyGen = KeyGenerator.getInstance("DESede"); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 aesKeyGen.init(128, random); |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
66 desKeyGen.init(168, random); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 SecretKey aesKey = aesKeyGen.generateKey(); |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
68 SecretKey desKey = desKeyGen.generateKey(); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 byte[] input = readClassfile16(getClass()); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
71 ByteArrayOutputStream aesExpected = new ByteArrayOutputStream(); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
72 aesExpected.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
73 aesExpected.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 |
18127
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
75 if (compileAndInstall("com.sun.crypto.provider.AESCrypt", "encryptBlock", "decryptBlock")) { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
79 Assert.assertArrayEquals(aesExpected.toByteArray(), actual.toByteArray()); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
82 ByteArrayOutputStream desExpected = new ByteArrayOutputStream(); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
83 desExpected.write(runEncryptDecrypt(desKey, "DESede/CBC/NoPadding", input)); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
84 desExpected.write(runEncryptDecrypt(desKey, "DESede/CBC/PKCS5Padding", input)); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
85 |
18127
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
86 if (compileAndInstall("com.sun.crypto.provider.CipherBlockChaining", "encrypt", "decrypt")) { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); |
11830
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
90 Assert.assertArrayEquals(aesExpected.toByteArray(), actual.toByteArray()); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
91 |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
92 actual.reset(); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
93 actual.write(runEncryptDecrypt(desKey, "DESede/CBC/NoPadding", input)); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
94 actual.write(runEncryptDecrypt(desKey, "DESede/CBC/PKCS5Padding", input)); |
6ce3677f09f5
enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths
Doug Simon <doug.simon@oracle.com>
parents:
10052
diff
changeset
|
95 Assert.assertArrayEquals(desExpected.toByteArray(), actual.toByteArray()); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 /** |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 * Compiles and installs the substitution for some specified methods. Once installed, the next |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 * execution of the methods will use the newly installed code. |
18127
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
102 * |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 * @param className the name of the class for which substitutions are available |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 * @param methodNames the names of the substituted methods |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 * @return true if at least one substitution was compiled and installed |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 */ |
18127
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
107 private boolean compileAndInstall(String className, String... methodNames) { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 boolean atLeastOneCompiled = false; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 for (String methodName : methodNames) { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 Method method = lookup(className, methodName); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 if (method != null) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11830
diff
changeset
|
112 ResolvedJavaMethod installedCodeOwner = getMetaAccess().lookupJavaMethod(method); |
18127
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
113 StructuredGraph subst = getReplacements().getMethodSubstitution(installedCodeOwner); |
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
114 if (subst != null) { |
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
15040
diff
changeset
|
115 StructuredGraph graph = subst.copy(); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 Assert.assertNotNull(getCode(installedCodeOwner, graph, true)); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 atLeastOneCompiled = true; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 } else { |
12431
7080a96be216
rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents:
12054
diff
changeset
|
119 Assert.assertFalse(runtime().getConfig().useAESIntrinsics); |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 return atLeastOneCompiled; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
125 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
126 private static Method lookup(String className, String methodName) { |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14559
diff
changeset
|
127 Class<?> c; |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
128 try { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
129 c = Class.forName(className); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
130 for (Method m : c.getDeclaredMethods()) { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
131 if (m.getName().equals(methodName)) { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
132 return m; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
133 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
134 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
135 // If the expected security provider exists, the specific method should also exist |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 throw new NoSuchMethodError(className + "." + methodName); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 } catch (ClassNotFoundException e) { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
138 // It's ok to not find the class - a different security provider |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
139 // may have been installed |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
140 return null; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
141 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
142 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
143 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
144 AlgorithmParameters algorithmParameters; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
145 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
146 private byte[] encrypt(byte[] indata, SecretKey key, String algorithm) throws Exception { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
147 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
148 byte[] result = indata; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
149 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
150 Cipher c = Cipher.getInstance(algorithm); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
151 c.init(Cipher.ENCRYPT_MODE, key); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
152 algorithmParameters = c.getParameters(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
153 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
154 byte[] r1 = c.update(result); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
155 byte[] r2 = c.doFinal(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
156 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
157 result = new byte[r1.length + r2.length]; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
158 System.arraycopy(r1, 0, result, 0, r1.length); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
159 System.arraycopy(r2, 0, result, r1.length, r2.length); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
160 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
161 return result; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
162 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
164 private byte[] decrypt(byte[] indata, SecretKey key, String algorithm) throws Exception { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
165 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
166 byte[] result = indata; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
168 Cipher c = Cipher.getInstance(algorithm); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
169 c.init(Cipher.DECRYPT_MODE, key, algorithmParameters); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
170 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
171 byte[] r1 = c.update(result); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
172 byte[] r2 = c.doFinal(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
173 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
174 result = new byte[r1.length + r2.length]; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 System.arraycopy(r1, 0, result, 0, r1.length); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
176 System.arraycopy(r2, 0, result, r1.length, r2.length); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
177 return result; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
179 |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14559
diff
changeset
|
180 private static byte[] readClassfile16(Class<? extends HotSpotCryptoSubstitutionTest> c) throws IOException { |
9766
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
181 String classFilePath = "/" + c.getName().replace('.', '/') + ".class"; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
182 InputStream stream = c.getResourceAsStream(classFilePath); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
183 int bytesToRead = stream.available(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
184 bytesToRead -= bytesToRead % 16; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
185 byte[] classFile = new byte[bytesToRead]; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
186 new DataInputStream(stream).readFully(classFile); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
187 return classFile; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
188 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
189 |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
190 public byte[] runEncryptDecrypt(SecretKey key, String algorithm, byte[] input) throws Exception { |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
191 byte[] indata = input.clone(); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
192 byte[] cipher = encrypt(indata, key, algorithm); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
193 byte[] plain = decrypt(cipher, key, algorithm); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
194 Assert.assertArrayEquals(indata, plain); |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
195 return plain; |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
196 } |
a2074a73aeef
added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
197 } |