annotate graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java @ 21526:1da7aef31a08

created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 19 May 2015 23:16:07 +0200
parents b04f579c803f
children 5324104ac4f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
21343
ce95a5e36927 removed unnecessary Intrinsic interface
Doug Simon <doug.simon@oracle.com>
parents: 21311
diff changeset
25 import static com.oracle.graal.graphbuilderconf.IntrinsicContext.CompilationContext.*;
20850
9d4a36560833 converted @MethodSubstitutions for AES crypto methods to MethodSubstitutionPlugins
Doug Simon <doug.simon@oracle.com>
parents: 20166
diff changeset
26
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import java.io.*;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.lang.reflect.*;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 import java.security.*;
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 javax.crypto.*;
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 org.junit.*;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.api.code.*;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.api.meta.*;
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
37 import com.oracle.graal.graphbuilderconf.*;
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
38 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
21526
1da7aef31a08 created com.oracle.graal.hotspot.jvmci package and moved classes destined for future JVMCI module into it (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21414
diff changeset
39 import com.oracle.graal.hotspot.jvmci.*;
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.hotspot.meta.*;
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
41 import com.oracle.graal.java.*;
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.nodes.*;
21343
ce95a5e36927 removed unnecessary Intrinsic interface
Doug Simon <doug.simon@oracle.com>
parents: 21311
diff changeset
43 import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions;
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
44 import com.oracle.graal.phases.*;
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 /**
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
47 * Tests the intrinsification of certain crypto methods.
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 */
18531
cdb9c605051a removed some static accesses to HotSpotGraalRuntime from some tests
Doug Simon <doug.simon@oracle.com>
parents: 18176
diff changeset
49 public class HotSpotCryptoSubstitutionTest extends HotSpotGraalCompilerTest {
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 @Override
10019
6e4b72bcc97f Remove graph from HotSpotNMethod
Christos Kotselidis <christos.kotselidis@oracle.com>
parents: 9767
diff changeset
52 protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 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
54 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
55 HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(hsMethod, compResult);
21414
b04f579c803f removed unnecessary CompilerToVM.CodeInstallResult enum (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21343
diff changeset
56 int result = runtime().getCompilerToVM().installCode(compiledNmethod, installedCode, null);
b04f579c803f removed unnecessary CompilerToVM.CodeInstallResult enum (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21343
diff changeset
57 HotSpotVMConfig config = runtime().getConfig();
b04f579c803f removed unnecessary CompilerToVM.CodeInstallResult enum (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21343
diff changeset
58 Assert.assertEquals("Error installing method " + method + ": " + config.getCodeInstallResultDescription(result), result, config.codeInstallResultOk);
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59
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
60 // HotSpotRuntime hsRuntime = (HotSpotRuntime) getCodeCache();
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 // TTY.println(hsMethod.toString());
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 // TTY.println(hsRuntime.disassemble(installedCode));
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 return installedCode;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
66 SecretKey aesKey;
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
67 SecretKey desKey;
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
68 byte[] input;
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
69 ByteArrayOutputStream aesExpected = new ByteArrayOutputStream();
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
70 ByteArrayOutputStream desExpected = new ByteArrayOutputStream();
19840
cd6821e84e59 disabled crypto intrinsics until partial intrinsification (i.e., self recursive intrinsics) bug is fixed
Doug Simon <doug.simon@oracle.com>
parents: 18531
diff changeset
71
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
72 public HotSpotCryptoSubstitutionTest() throws Exception {
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 byte[] seed = {0x4, 0x7, 0x1, 0x1};
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 SecureRandom random = new SecureRandom(seed);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 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
76 KeyGenerator desKeyGen = KeyGenerator.getInstance("DESede");
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 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
78 desKeyGen.init(168, random);
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
79 aesKey = aesKeyGen.generateKey();
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
80 desKey = desKeyGen.generateKey();
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
81 input = readClassfile16(getClass());
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
82
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
83 aesExpected.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding"));
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
84 aesExpected.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding"));
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
86 desExpected.write(runEncryptDecrypt(desKey, "DESede/CBC/NoPadding"));
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
87 desExpected.write(runEncryptDecrypt(desKey, "DESede/CBC/PKCS5Padding"));
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
88 }
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
90 @Test
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
91 public void testAESCryptIntrinsics() throws Exception {
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
92 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
93 ByteArrayOutputStream actual = new ByteArrayOutputStream();
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
94 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding"));
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
95 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding"));
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
96 Assert.assertArrayEquals(aesExpected.toByteArray(), actual.toByteArray());
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 }
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
98 }
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
100 @Test
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
101 public void testCipherBlockChainingIntrinsics() throws Exception {
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 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
103 ByteArrayOutputStream actual = new ByteArrayOutputStream();
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
104 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding"));
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
105 actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding"));
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
106 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
107
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
108 actual.reset();
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
109 actual.write(runEncryptDecrypt(desKey, "DESede/CBC/NoPadding"));
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
110 actual.write(runEncryptDecrypt(desKey, "DESede/CBC/PKCS5Padding"));
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
111 Assert.assertArrayEquals(desExpected.toByteArray(), actual.toByteArray());
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
114
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
115 /**
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
116 * 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
117 * 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
118 *
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
119 * @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
120 * @param methodNames the names of the substituted methods
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
121 * @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
122 */
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
123 private boolean compileAndInstall(String className, String... methodNames) {
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124 boolean atLeastOneCompiled = false;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125 for (String methodName : methodNames) {
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126 Method method = lookup(className, methodName);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
127 if (method != null) {
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11830
diff changeset
128 ResolvedJavaMethod installedCodeOwner = getMetaAccess().lookupJavaMethod(method);
20935
30cbb666e512 expand API for retrieving method substitution graphs to indicate the BCI of the invoke being inlined or -1 if the request is not in the context of inlining
Doug Simon <doug.simon@oracle.com>
parents: 20901
diff changeset
129 StructuredGraph subst = getReplacements().getSubstitution(installedCodeOwner, 0);
20166
28a85fa57b27 renamed getMethodSubstitution to getSubstitution in Replacements API and removed getMethodSubstitutionMethod
Doug Simon <doug.simon@oracle.com>
parents: 19994
diff changeset
130 ResolvedJavaMethod substMethod = subst == null ? null : subst.method();
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
131 if (substMethod != null) {
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
132 StructuredGraph graph = new StructuredGraph(substMethod, AllowAssumptions.YES);
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
133 Plugins plugins = new Plugins(((HotSpotProviders) getProviders()).getGraphBuilderPlugins());
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
134 GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
21311
710fc7216c56 consolidated ReplacementContext and IntrinsicContext
Doug Simon <doug.simon@oracle.com>
parents: 21289
diff changeset
135 IntrinsicContext initialReplacementContext = new IntrinsicContext(installedCodeOwner, substMethod, ROOT_COMPILATION);
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
136 new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), getConstantReflection(), config, OptimisticOptimizations.NONE, initialReplacementContext).apply(graph);
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
137 Assert.assertNotNull(getCode(installedCodeOwner, graph, true));
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138 atLeastOneCompiled = true;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
139 } else {
12431
7080a96be216 rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents: 12054
diff changeset
140 Assert.assertFalse(runtime().getConfig().useAESIntrinsics);
9766
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 return atLeastOneCompiled;
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
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
147 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
148 Class<?> c;
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 try {
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 c = Class.forName(className);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 for (Method m : c.getDeclaredMethods()) {
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
152 if (m.getName().equals(methodName)) {
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
153 return m;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
154 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156 // 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
157 throw new NoSuchMethodError(className + "." + methodName);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 } catch (ClassNotFoundException e) {
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
159 // 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
160 // may have been installed
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 return null;
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
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
165 AlgorithmParameters algorithmParameters;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
166
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
167 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
168
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
169 byte[] result = indata;
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 Cipher c = Cipher.getInstance(algorithm);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
172 c.init(Cipher.ENCRYPT_MODE, key);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 algorithmParameters = c.getParameters();
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
174
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
175 byte[] r1 = c.update(result);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
176 byte[] r2 = c.doFinal();
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
177
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
178 result = new byte[r1.length + r2.length];
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
179 System.arraycopy(r1, 0, result, 0, r1.length);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
180 System.arraycopy(r2, 0, result, r1.length, r2.length);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
181
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 return result;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
184
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185 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
186
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
187 byte[] result = indata;
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 Cipher c = Cipher.getInstance(algorithm);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 c.init(Cipher.DECRYPT_MODE, key, algorithmParameters);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
192 byte[] r1 = c.update(result);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
193 byte[] r2 = c.doFinal();
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
194
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
195 result = new byte[r1.length + r2.length];
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
196 System.arraycopy(r1, 0, result, 0, r1.length);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
197 System.arraycopy(r2, 0, result, r1.length, r2.length);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
198 return result;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
199 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
200
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 14559
diff changeset
201 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
202 String classFilePath = "/" + c.getName().replace('.', '/') + ".class";
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
203 InputStream stream = c.getResourceAsStream(classFilePath);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
204 int bytesToRead = stream.available();
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
205 bytesToRead -= bytesToRead % 16;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
206 byte[] classFile = new byte[bytesToRead];
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
207 new DataInputStream(stream).readFully(classFile);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
208 return classFile;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
209 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
210
19991
4187aa9d6a10 factored out common code in HotSpotCryptoSubstitutionTest
Doug Simon <doug.simon@oracle.com>
parents: 19840
diff changeset
211 public byte[] runEncryptDecrypt(SecretKey key, String algorithm) throws Exception {
9766
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
212 byte[] indata = input.clone();
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
213 byte[] cipher = encrypt(indata, key, algorithm);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 byte[] plain = decrypt(cipher, key, algorithm);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
215 Assert.assertArrayEquals(indata, plain);
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
216 return plain;
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
217 }
a2074a73aeef added test for AES intrinsification
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
218 }