Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/zip/TestAdler32.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 813208126* @summary C2 support for Adler32 on SPARC27*28* @run main/othervm/timeout=600 -Xbatch compiler.intrinsics.zip.TestAdler32 -m29*/3031package compiler.intrinsics.zip;3233import java.nio.ByteBuffer;34import java.util.zip.Adler32;35import java.util.zip.Checksum;3637public class TestAdler32 {38public static void main(String[] args) {39int offset = Integer.getInteger("offset", 0);40int msgSize = Integer.getInteger("msgSize", 512);41boolean multi = false;42int iters = 20000;43int warmupIters = 20000;4445if (args.length > 0) {46if (args[0].equals("-m")) {47multi = true;48} else {49iters = Integer.valueOf(args[0]);50}51if (args.length > 1) {52warmupIters = Integer.valueOf(args[1]);53}54}5556if (multi) {57test_multi(warmupIters);58return;59}6061System.out.println(" offset = " + offset);62System.out.println("msgSize = " + msgSize + " bytes");63System.out.println(" iters = " + iters);6465byte[] b = initializedBytes(msgSize, offset);6667Adler32 adler0 = new Adler32();68Adler32 adler1 = new Adler32();69Adler32 adler2 = new Adler32();7071adler0.update(b, offset, msgSize);7273System.out.println("-------------------------------------------------------");7475/* warm up */76for (int i = 0; i < warmupIters; i++) {77adler1.reset();78adler1.update(b, offset, msgSize);79}8081/* measure performance */82long start = System.nanoTime();83for (int i = 0; i < iters; i++) {84adler1.reset();85adler1.update(b, offset, msgSize);86}87long end = System.nanoTime();88double total = (double)(end - start)/1e9; // in seconds89double thruput = (double)msgSize*iters/1e6/total; // in MB/s90System.out.println("Adler32.update(byte[]) runtime = " + total + " seconds");91System.out.println("Adler32.update(byte[]) throughput = " + thruput + " MB/s");9293/* check correctness */94for (int i = 0; i < iters; i++) {95adler1.reset();96adler1.update(b, offset, msgSize);97if (!check(adler0, adler1)) break;98}99report("Adlers", adler0, adler1);100101System.out.println("-------------------------------------------------------");102103ByteBuffer buf = ByteBuffer.allocateDirect(msgSize);104buf.put(b, offset, msgSize);105buf.flip();106107/* warm up */108for (int i = 0; i < warmupIters; i++) {109adler2.reset();110adler2.update(buf);111buf.rewind();112}113114/* measure performance */115start = System.nanoTime();116for (int i = 0; i < iters; i++) {117adler2.reset();118adler2.update(buf);119buf.rewind();120}121end = System.nanoTime();122total = (double)(end - start)/1e9; // in seconds123thruput = (double)msgSize*iters/1e6/total; // in MB/s124System.out.println("Adler32.update(ByteBuffer) runtime = " + total + " seconds");125System.out.println("Adler32.update(ByteBuffer) throughput = " + thruput + " MB/s");126127/* check correctness */128for (int i = 0; i < iters; i++) {129adler2.reset();130adler2.update(buf);131buf.rewind();132if (!check(adler0, adler2)) break;133}134report("Adlers", adler0, adler1);135136System.out.println("-------------------------------------------------------");137}138139private static void report(String s, Checksum adler0, Checksum adler1) {140System.out.printf("%s: adler0 = %08x, adler1 = %08x\n",141s, adler0.getValue(), adler1.getValue());142}143144private static boolean check(Checksum adler0, Checksum adler1) {145if (adler0.getValue() != adler1.getValue()) {146System.err.printf("ERROR: adler0 = %08x, adler1 = %08x\n",147adler0.getValue(), adler1.getValue());148return false;149}150return true;151}152153private static byte[] initializedBytes(int M, int offset) {154byte[] bytes = new byte[M + offset];155for (int i = 0; i < offset; i++) {156bytes[i] = (byte) i;157}158for (int i = offset; i < bytes.length; i++) {159bytes[i] = (byte) (i - offset);160}161return bytes;162}163164private static void test_multi(int iters) {165int len1 = 8; // the 8B/iteration loop166int len2 = 32; // the 32B/iteration loop167int len3 = 4096; // the 4KB/iteration loop168169byte[] b = initializedBytes(len3*16, 0);170int[] offsets = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256, 512 };171int[] sizes = { 0, 1, 2, 3, 4, 5, 6, 7,172len1, len1+1, len1+2, len1+3, len1+4, len1+5, len1+6, len1+7,173len1*2, len1*2+1, len1*2+3, len1*2+5, len1*2+7,174len2, len2+1, len2+3, len2+5, len2+7,175len2*2, len2*4, len2*8, len2*16, len2*32, len2*64,176len3, len3+1, len3+3, len3+5, len3+7,177len3*2, len3*4, len3*8,178len1+len2, len1+len2+1, len1+len2+3, len1+len2+5, len1+len2+7,179len1+len3, len1+len3+1, len1+len3+3, len1+len3+5, len1+len3+7,180len2+len3, len2+len3+1, len2+len3+3, len2+len3+5, len2+len3+7,181len1+len2+len3, len1+len2+len3+1, len1+len2+len3+3,182len1+len2+len3+5, len1+len2+len3+7,183(len1+len2+len3)*2, (len1+len2+len3)*2+1, (len1+len2+len3)*2+3,184(len1+len2+len3)*2+5, (len1+len2+len3)*2+7,185(len1+len2+len3)*3, (len1+len2+len3)*3-1, (len1+len2+len3)*3-3,186(len1+len2+len3)*3-5, (len1+len2+len3)*3-7 };187Adler32[] adler0 = new Adler32[offsets.length*sizes.length];188Adler32[] adler1 = new Adler32[offsets.length*sizes.length];189int i, j, k;190191System.out.printf("testing %d cases ...\n", offsets.length*sizes.length);192193/* set the result from interpreter as reference */194for (i = 0; i < offsets.length; i++) {195for (j = 0; j < sizes.length; j++) {196adler0[i*sizes.length + j] = new Adler32();197adler1[i*sizes.length + j] = new Adler32();198adler0[i*sizes.length + j].update(b, offsets[i], sizes[j]);199}200}201202/* warm up the JIT compiler and get result */203for (k = 0; k < iters; k++) {204for (i = 0; i < offsets.length; i++) {205for (j = 0; j < sizes.length; j++) {206adler1[i*sizes.length + j].reset();207adler1[i*sizes.length + j].update(b, offsets[i], sizes[j]);208}209}210}211212/* check correctness */213for (i = 0; i < offsets.length; i++) {214for (j = 0; j < sizes.length; j++) {215if (!check(adler0[i*sizes.length + j], adler1[i*sizes.length + j])) {216System.out.printf("offsets[%d] = %d", i, offsets[i]);217System.out.printf("\tsizes[%d] = %d\n", j, sizes[j]);218}219}220}221}222}223224225