1 /*
   2  * Copyright (c) 2011, 2013, 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 /**
  26  * @test
  27  * @bug 6905845
  28  * @summary Server VM improperly optimizing away loop.
  29  *
  30  * @run main/timeout=480 compiler.c2.Test6905845
  31  */
  32 
  33 package compiler.c2;
  34 
  35 public class Test6905845 {
  36 
  37     public static void main(String[] args) {
  38         for (int asdf = 0; asdf < 5; asdf++) {
  39             //test block
  40             {
  41                 StringBuilder strBuf1 = new StringBuilder(65);
  42                 long start = System.currentTimeMillis();
  43                 int count = 0;
  44 
  45                 for (int i = Integer.MIN_VALUE; i < (Integer.MAX_VALUE - 80); i += 79) {
  46                     strBuf1.append(i);
  47                     count++;
  48                     strBuf1.delete(0, 65);
  49                 }
  50 
  51                 System.out.println(count);
  52                 if (count != 54366674) {
  53                     System.out.println("wrong count: " + count + ", should be 54366674");
  54                     System.exit(97);
  55                 }
  56             }
  57             //test block
  58             {
  59                 StringBuilder strBuf1 = new StringBuilder(65);
  60                 long start = System.currentTimeMillis();
  61                 int count = 0;
  62 
  63                 for (int i = Integer.MIN_VALUE; i < (Integer.MAX_VALUE - 80); i += 79) {
  64                     strBuf1.append(i);
  65                     count++;
  66                     strBuf1.delete(0, 65);
  67                 }
  68 
  69                 System.out.println(count);
  70                 if (count != 54366674) {
  71                     System.out.println("wrong count: " + count + ", should be 54366674");
  72                     System.exit(97);
  73                 }
  74             }
  75         }
  76     }
  77 }
  78