Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/t/t013/t013.java
40948 views
1
/*
2
* Copyright (c) 2008, 2020, 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
* @test
26
*
27
* @summary converted from VM Testbase jit/t/t013.
28
* VM Testbase keywords: [jit, quick]
29
*
30
* @library /vmTestbase
31
* /test/lib
32
* @run main/othervm jit.t.t013.t013
33
*/
34
35
package jit.t.t013;
36
37
import nsk.share.TestFailure;
38
import nsk.share.GoldChecker;
39
40
class Globals {
41
static public int NumDisks;
42
static public int MaxDisks = 64; // this will do!
43
}
44
45
public class t013 {
46
47
public static final GoldChecker goldChecker = new GoldChecker( "t013" );
48
49
static Peg peg1 = new Peg(1),
50
peg2 = new Peg(2),
51
peg3 = new Peg(3);
52
53
public static void main(String args[]) {
54
55
Globals.NumDisks = 4;
56
57
t013.goldChecker.println("moving " + Globals.NumDisks + " disks...");
58
59
if (Globals.NumDisks > Globals.MaxDisks)
60
Globals.NumDisks = Globals.MaxDisks;
61
62
for (int i = Globals.NumDisks; i > 0; i--)
63
peg1.addDisk(i);
64
65
long start = System.currentTimeMillis();
66
67
moveDisks(Globals.NumDisks, peg1, peg3, peg2);
68
69
long stop = System.currentTimeMillis();
70
71
long t = (stop - start) / 100;
72
73
t013.goldChecker.println("finished, but I won't tell you how long it took");
74
t013.goldChecker.check();
75
}
76
77
public static void moveDisks(int numDisks, Peg fromPeg, Peg toPeg, Peg usingPeg) {
78
t013.goldChecker.println
79
(
80
"moveDisks(" +
81
numDisks +
82
", " +
83
fromPeg.pegNum +
84
", " +
85
toPeg.pegNum +
86
", " +
87
usingPeg.pegNum +
88
")"
89
);
90
if (numDisks == 1) {
91
int disk;
92
toPeg.addDisk(disk = fromPeg.removeDisk());
93
} else {
94
moveDisks(numDisks - 1, fromPeg, usingPeg, toPeg);
95
moveDisks(1, fromPeg, toPeg, usingPeg);
96
moveDisks(numDisks - 1, usingPeg, toPeg, fromPeg);
97
}
98
}
99
}
100
101
class Peg {
102
103
int pegNum;
104
int disks[] = new int[64];
105
int nDisks;
106
107
public Peg(int n) {
108
t013.goldChecker.println("Peg(" + n + ")");
109
pegNum = n;
110
for (int i = 0; i < Globals.NumDisks; i++)
111
disks[i] = 0;
112
nDisks = 0;
113
}
114
115
public int pegNum() {
116
return pegNum;
117
}
118
119
public void addDisk(int diskNum) {
120
t013.goldChecker.println("addDisk(" + diskNum + ", " + pegNum() +")");
121
disks[nDisks++] = diskNum;
122
}
123
124
public int removeDisk() {
125
t013.goldChecker.println("removeDisk(" + pegNum() + ")");
126
return disks[--nDisks];
127
}
128
129
}
130
131