Path: blob/master/test/jdk/java/math/BigInteger/ModPowPowersof2.java
41149 views
/*1* Copyright (c) 1998, 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/* @test24@bug 409874225@summary Test biginteger modpow method26@author Michael McCloskey27@run main/othervm ModPowPowersof228*/2930import java.math.BigInteger;31import java.io.BufferedReader;32import java.io.InputStreamReader;33import java.io.File;34import java.io.IOException;3536/**37* This class tests to see if using modPow on a power38* of two crashes the vm39*40*/41public class ModPowPowersof2 {4243public static void main(String args[]) throws Exception {44// Construct a command that runs the test in other vm45String[] command = new String[4];46int n = 0;4748command[n++] = System.getProperty("java.home") + File.separator +49"bin" + File.separator + "java";50if (System.getProperty("java.class.path") != null) {51command[n++] = "-classpath";52command[n++] = System.getProperty("java.class.path");53}5455command[n++] = "ModPowPowersof2$ModTester";5657// Exec another vm to run test in58Process p = null;59p = Runtime.getRuntime().exec(command);6061// Read the result to determine if test failed62BufferedReader in = new BufferedReader(new InputStreamReader(63p.getInputStream()));64String s;65s = in.readLine();66if (s == null)67throw new RuntimeException("ModPow causes vm crash");6869}7071public static class ModTester {72public static void main(String [] args) {73BigInteger two = BigInteger.valueOf(2);74BigInteger four = BigInteger.valueOf(4);7576two.modPow(two, BigInteger.valueOf(4));77two.modPow(two, BigInteger.valueOf(8));78two.modPow(four, BigInteger.valueOf(8));7980System.out.println("success");81}82}8384}858687