Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/math/BigInteger/ModPowPowersof2.java
41149 views
1
/*
2
* Copyright (c) 1998, 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
/* @test
25
@bug 4098742
26
@summary Test biginteger modpow method
27
@author Michael McCloskey
28
@run main/othervm ModPowPowersof2
29
*/
30
31
import java.math.BigInteger;
32
import java.io.BufferedReader;
33
import java.io.InputStreamReader;
34
import java.io.File;
35
import 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
*/
42
public 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
}
86
87