1 /* 2 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /** 26 * @test 27 * @bug 6663621 28 * @summary JVM crashes while trying to execute api/java_security/Signature/SignatureTests.html#initSign tests. 29 * 30 * @run main compiler.c2.IVTest 31 */ 32 33 package compiler.c2; 34 35 public class IVTest { 36 static int paddedSize; 37 38 static void padV15(byte[] padded) { 39 int psSize = padded.length; 40 int k = 0; 41 while (psSize-- > 0) { 42 padded[k++] = (byte)0xff; 43 } 44 } 45 46 static void padV15_2(int paddedSize) { 47 byte[] padded = new byte[paddedSize]; 48 int psSize = padded.length; 49 int k = 0; 50 while (psSize-- > 0) { 51 padded[k++] = (byte)0xff; 52 } 53 } 54 55 static void padV15_3() { 56 byte[] padded = new byte[paddedSize]; 57 int psSize = padded.length; 58 int k = 0; 59 while (psSize-- > 0) { 60 padded[k++] = (byte)0xff; 61 } 62 } 63 64 static void padV15_4() { 65 byte[] padded = new byte[paddedSize]; 66 int psSize = padded.length; 67 for (int k = 0;psSize > 0; psSize--) { 68 int i = padded.length - psSize; 69 padded[i] = (byte)0xff; 70 } 71 } 72 73 static void padV15_5() { 74 byte[] padded = new byte[paddedSize]; 75 int psSize = padded.length; 76 int k = psSize - 1; 77 for (int i = 0; i < psSize; i++) { 78 padded[k--] = (byte)0xff; 79 } 80 } 81 82 public static void main(String argv[]) { 83 int bounds = 1024; 84 int lim = 500000; 85 long start = System.currentTimeMillis(); 86 for (int j = 0; j < lim; j++) { 87 paddedSize = j % bounds; 88 padV15(new byte[paddedSize]); 89 } 90 long end = System.currentTimeMillis(); 91 System.out.println(end - start); 92 start = System.currentTimeMillis(); 93 for (int j = 0; j < lim; j++) { 94 paddedSize = j % bounds; 95 padV15_2(paddedSize); 96 } 97 end = System.currentTimeMillis(); 98 System.out.println(end - start); 99 start = System.currentTimeMillis(); 100 for (int j = 0; j < lim; j++) { 101 paddedSize = j % bounds; 102 padV15_3(); 103 } 104 end = System.currentTimeMillis(); 105 System.out.println(end - start); 106 start = System.currentTimeMillis(); 107 for (int j = 0; j < lim; j++) { 108 paddedSize = j % bounds; 109 padV15_4(); 110 } 111 end = System.currentTimeMillis(); 112 System.out.println(end - start); 113 start = System.currentTimeMillis(); 114 for (int j = 0; j < lim; j++) { 115 paddedSize = j % bounds; 116 padV15_5(); 117 } 118 end = System.currentTimeMillis(); 119 System.out.println(end - start); 120 } 121 }