Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/compiler/5091921/Test6959129.java
32285 views
/*1* Copyright (c) 2011, 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*22*/2324/**25* @test26* @bug 695912927* @summary COMPARISON WITH INTEGER.MAX_INT DOES NOT WORK CORRECTLY IN THE CLIENT VM.28*29* @run main/othervm -ea Test695912930*/3132public class Test6959129 {3334public static void main(String[] args) {35long start = System.currentTimeMillis();36int min = Integer.MAX_VALUE-30000;37int max = Integer.MAX_VALUE;38long maxmoves = 0;39try {40maxmoves = maxMoves(min, max);41} catch (AssertionError e) {42System.out.println("Passed");43System.exit(95);44}45System.out.println("maxMove:" + maxmoves);46System.out.println("FAILED");47System.exit(97);48}49/**50* Imperative implementation that returns the length hailstone moves51* for a given number.52*/53public static long hailstoneLengthImp(long n) {54long moves = 0;55while (n != 1) {56assert n > 1;57if (isEven(n)) {58n = n / 2;59} else {60n = 3 * n + 1;61}62++moves;63}64return moves;65}6667private static boolean isEven(long n) {68return n % 2 == 0;69}7071/**72* Returns the maximum length of the hailstone sequence for numbers73* between min to max.74*75* For rec1 - Assume that min is bigger than max.76*/77public static long maxMoves(int min, int max) {78long maxmoves = 0;79for (int n = min; n <= max; n++) {80if ((n & 1023) == 0) System.out.println(n);81long moves = hailstoneLengthImp(n);82if (moves > maxmoves) {83maxmoves = moves;84}85}86return maxmoves;87}88}89909192