Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/t/t013/t013.java
40948 views
/*1* Copyright (c) 2008, 2020, 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/*24* @test25*26* @summary converted from VM Testbase jit/t/t013.27* VM Testbase keywords: [jit, quick]28*29* @library /vmTestbase30* /test/lib31* @run main/othervm jit.t.t013.t01332*/3334package jit.t.t013;3536import nsk.share.TestFailure;37import nsk.share.GoldChecker;3839class Globals {40static public int NumDisks;41static public int MaxDisks = 64; // this will do!42}4344public class t013 {4546public static final GoldChecker goldChecker = new GoldChecker( "t013" );4748static Peg peg1 = new Peg(1),49peg2 = new Peg(2),50peg3 = new Peg(3);5152public static void main(String args[]) {5354Globals.NumDisks = 4;5556t013.goldChecker.println("moving " + Globals.NumDisks + " disks...");5758if (Globals.NumDisks > Globals.MaxDisks)59Globals.NumDisks = Globals.MaxDisks;6061for (int i = Globals.NumDisks; i > 0; i--)62peg1.addDisk(i);6364long start = System.currentTimeMillis();6566moveDisks(Globals.NumDisks, peg1, peg3, peg2);6768long stop = System.currentTimeMillis();6970long t = (stop - start) / 100;7172t013.goldChecker.println("finished, but I won't tell you how long it took");73t013.goldChecker.check();74}7576public static void moveDisks(int numDisks, Peg fromPeg, Peg toPeg, Peg usingPeg) {77t013.goldChecker.println78(79"moveDisks(" +80numDisks +81", " +82fromPeg.pegNum +83", " +84toPeg.pegNum +85", " +86usingPeg.pegNum +87")"88);89if (numDisks == 1) {90int disk;91toPeg.addDisk(disk = fromPeg.removeDisk());92} else {93moveDisks(numDisks - 1, fromPeg, usingPeg, toPeg);94moveDisks(1, fromPeg, toPeg, usingPeg);95moveDisks(numDisks - 1, usingPeg, toPeg, fromPeg);96}97}98}99100class Peg {101102int pegNum;103int disks[] = new int[64];104int nDisks;105106public Peg(int n) {107t013.goldChecker.println("Peg(" + n + ")");108pegNum = n;109for (int i = 0; i < Globals.NumDisks; i++)110disks[i] = 0;111nDisks = 0;112}113114public int pegNum() {115return pegNum;116}117118public void addDisk(int diskNum) {119t013.goldChecker.println("addDisk(" + diskNum + ", " + pegNum() +")");120disks[nDisks++] = diskNum;121}122123public int removeDisk() {124t013.goldChecker.println("removeDisk(" + pegNum() + ")");125return disks[--nDisks];126}127128}129130131