hotspot/test/compiler/7179138/Test7179138_1.java
author ccheung
Fri, 04 Oct 2013 21:00:43 -0700
changeset 20384 49bfb2ec8f8f
parent 13111 e8a578a9b20a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13111
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     1
/*
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     2
 * Copyright 2012 Skip Balk.  All Rights Reserved.
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     4
 *
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     8
 *
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    13
 * accompanied this code).
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    14
 *
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    18
 *
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    21
 * questions.
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    22
 */
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    23
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    24
/*
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    25
 * @test
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    26
 * @bug 7179138
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    27
 * @summary Incorrect result with String concatenation optimization
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    28
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation Test7179138_1
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    29
 *
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    30
 * @author Skip Balk
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    31
 */
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    32
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    33
public class Test7179138_1 {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    35
        System.out.println("Java Version: " + System.getProperty("java.vm.version"));
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    36
        long[] durations = new long[60];
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    37
        for (int i = 0; i < 100000; i++) {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    38
            // this empty for-loop is required to reproduce this bug
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    39
            for (long duration : durations) {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    40
                // do nothing
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    41
            }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    42
            {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    43
                String s = "test";
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    44
                int len = s.length();
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    45
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    46
                s = new StringBuilder(String.valueOf(s)).append(s).toString();
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    47
                len = len + len;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    48
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    49
                s = new StringBuilder(String.valueOf(s)).append(s).toString();
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    50
                len = len + len;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    51
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    52
                s = new StringBuilder(String.valueOf(s)).append(s).toString();
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    53
                len = len + len;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    54
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    55
                if (s.length() != len) {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    56
                    System.out.println("Failed at iteration: " + i);
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    57
                    System.out.println("Length mismatch: " + s.length() + " <> " + len);
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    58
                    System.out.println("Expected: \"" + "test" + "test" + "test" + "test" + "test" + "test" + "test" + "test" + "\"");
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    59
                    System.out.println("Actual:   \"" + s + "\"");
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    60
                    System.exit(97);
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    61
                }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    62
            }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    63
        }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    64
    }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    65
}
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    66