hotspot/test/compiler/codegen/7184394/TestAESMain.java
author kvn
Mon, 28 Dec 2015 23:11:01 -0800
changeset 35154 a9b3c1984a01
parent 31404 63e8fcd70bfc
child 36851 03e2f4d0a421
permissions -rw-r--r--
8143925: Enhancing CounterMode.crypt() for AES Summary: Add intrinsic for CounterMode.crypt() to leverage the parallel nature of AES in Counter(CTR) Mode. Reviewed-by: kvn, ascarpino Contributed-by: kishor.kharbas@intel.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27699
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     4
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     8
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    13
 * accompanied this code).
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    14
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    18
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    21
 * questions.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    22
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    23
 */
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    24
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    25
/**
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    26
 * @test
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    27
 * @bug 7184394
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    28
 * @summary add intrinsics to use AES instructions
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 24329
diff changeset
    29
 * @library /testlibrary
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    30
 *
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27699
diff changeset
    31
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27699
diff changeset
    32
 *          java.management
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
    33
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC TestAESMain
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    34
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    35
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencOutputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    36
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DdecOutputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    37
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 -DencOutputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    38
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 TestAESMain
24329
13ccf2b92d69 8042281: compiler/7184394/TestAESMain.java fails with: javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes
kvn
parents: 24328
diff changeset
    39
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 -DpaddingStr=NoPadding -DmsgSize=640 TestAESMain
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
    40
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB TestAESMain
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    41
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    42
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencOutputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    43
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DdecOutputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    44
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 -DencOutputOffset=1 TestAESMain
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    45
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 TestAESMain
24329
13ccf2b92d69 8042281: compiler/7184394/TestAESMain.java fails with: javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes
kvn
parents: 24328
diff changeset
    46
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 -DpaddingStr=NoPadding -DmsgSize=640 TestAESMain
31404
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    47
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM TestAESMain
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    48
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM -DencInputOffset=1 TestAESMain
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    49
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM -DencOutputOffset=1 TestAESMain
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    50
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM -DdecOutputOffset=1 TestAESMain
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    51
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM -DencInputOffset=1 -DencOutputOffset=1 TestAESMain
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    52
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 TestAESMain
63e8fcd70bfc 8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
ascarpino
parents: 29678
diff changeset
    53
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=GCM -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 -DpaddingStr=NoPadding -DmsgSize=640 TestAESMain
35154
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    54
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR TestAESMain
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    55
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR -DencInputOffset=1 TestAESMain
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    56
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR -DencOutputOffset=1 TestAESMain
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    57
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR -DdecOutputOffset=1 TestAESMain
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    58
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR -DencInputOffset=1 -DencOutputOffset=1 TestAESMain
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    59
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 TestAESMain
a9b3c1984a01 8143925: Enhancing CounterMode.crypt() for AES
kvn
parents: 31404
diff changeset
    60
 * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CTR -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 -DpaddingStr=NoPadding -DmsgSize=640 TestAESMain
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    61
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    62
 * @author Tom Deneau
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    63
 */
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    64
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    65
public class TestAESMain {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    66
  public static void main(String[] args) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    67
    int iters = (args.length > 0 ? Integer.valueOf(args[0]) : 1000000);
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    68
    int warmupIters = (args.length > 1 ? Integer.valueOf(args[1]) : 20000);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    69
    System.out.println(iters + " iterations");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    70
    TestAESEncode etest = new TestAESEncode();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    71
    etest.prepare();
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    72
    // warm-up
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    73
    System.out.println("Starting encryption warm-up");
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    74
    for (int i=0; i<warmupIters; i++) {
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    75
      etest.run();
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    76
    }
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    77
    System.out.println("Finished encryption warm-up");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    78
    long start = System.nanoTime();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    79
    for (int i=0; i<iters; i++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    80
      etest.run();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    81
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    82
    long end = System.nanoTime();
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    83
    System.out.println("TestAESEncode runtime was " + (double)((end - start)/1000000.0) + " ms");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    84
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    85
    TestAESDecode dtest = new TestAESDecode();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    86
    dtest.prepare();
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    87
    // warm-up
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    88
    System.out.println("Starting decryption warm-up");
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 22505
diff changeset
    89
    for (int i=0; i<warmupIters; i++) {
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    90
      dtest.run();
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    91
    }
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    92
    System.out.println("Finished decryption warm-up");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    93
    start = System.nanoTime();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    94
    for (int i=0; i<iters; i++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    95
      dtest.run();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    96
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    97
    end = System.nanoTime();
22505
4523090c9674 8002074: Support for AES on SPARC
kvn
parents: 14834
diff changeset
    98
    System.out.println("TestAESDecode runtime was " + (double)((end - start)/1000000.0) + " ms");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    99
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   100
}