blob: 0738788350f3d3636e4ab57fcc3fdcaf646a5961 [file] [log] [blame]
darcy32db4492009-01-26 19:49:26 -08001/*
ohair2283b9d2010-05-25 15:58:33 -07002 * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
darcy32db4492009-01-26 19:49:26 -08003 * 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 *
ohair2283b9d2010-05-25 15:58:33 -070019 * 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.
darcy32db4492009-01-26 19:49:26 -080022 */
23
24/* @test
25 @bug 4098742
26 @summary Test biginteger modpow method
27 @author Michael McCloskey
28 @run main/othervm ModPowPowersof2
29*/
30
31import java.math.BigInteger;
32import java.io.BufferedReader;
33import java.io.InputStreamReader;
34import java.io.File;
35import java.io.IOException;
36
37/**
38 * This class tests to see if using modPow on a power
39 * of two crashes the vm
40 *
41 */
42public class ModPowPowersof2 {
43
44 public static void main(String args[]) throws Exception {
45 // Construct a command that runs the test in other vm
46 String[] command = new String[4];
47 int n = 0;
48
49 command[n++] = System.getProperty("java.home") + File.separator +
50 "bin" + File.separator + "java";
51 if (System.getProperty("java.class.path") != null) {
52 command[n++] = "-classpath";
53 command[n++] = System.getProperty("java.class.path");
54 }
55
56 command[n++] = "ModPowPowersof2$ModTester";
57
58 // Exec another vm to run test in
59 Process p = null;
60 p = Runtime.getRuntime().exec(command);
61
62 // Read the result to determine if test failed
63 BufferedReader in = new BufferedReader(new InputStreamReader(
64 p.getInputStream()));
65 String s;
66 s = in.readLine();
67 if (s == null)
68 throw new RuntimeException("ModPow causes vm crash");
69
70 }
71
72 public static class ModTester {
73 public static void main(String [] args) {
74 BigInteger two = BigInteger.valueOf(2);
75 BigInteger four = BigInteger.valueOf(4);
76
77 two.modPow(two, BigInteger.valueOf(4));
78 two.modPow(two, BigInteger.valueOf(8));
79 two.modPow(four, BigInteger.valueOf(8));
80
81 System.out.println("success");
82 }
83 }
84
85}