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