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