hotspot/test/compiler/c2/Test7179138_2.java
author sspitsyn
Wed, 03 May 2017 02:32:02 +0000
changeset 46426 02a1fc064144
parent 40059 c2304140ed64
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
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    29
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    30
 *      compiler.c2.Test7179138_2
13111
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
 * @author Skip Balk
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    33
 */
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    34
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    35
package compiler.c2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    36
13111
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    37
public class Test7179138_2 {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    39
        System.out.println("Java Version: " + System.getProperty("java.vm.version"));
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    40
        long[] durations = new long[60];
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    41
        for (int i = 0; i < 100000; i++) {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    42
            // this empty for-loop is required to reproduce this bug
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    43
            for (long duration : durations) {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    44
                // do nothing
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
            {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    47
                String s = "test";
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    48
                int len = s.length();
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    49
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    50
                s = s + s;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    51
                len = len + len;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    52
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    53
                s = s + s;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    54
                len = len + len;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    55
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    56
                s = s + s;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    57
                len = len + len;
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    58
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    59
                if (s.length() != len) {
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    60
                    System.out.println("Failed at iteration: " + i);
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    61
                    System.out.println("Length mismatch: " + s.length() + " <> " + len);
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    62
                    System.out.println("Expected: \"" + "test" + "test" + "test" + "test" + "test" + "test" + "test" + "test" + "\"");
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    63
                    System.out.println("Actual:   \"" + s + "\"");
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    64
                    System.exit(0);
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
            }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    67
        }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    68
    }
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    69
}
e8a578a9b20a 7179138: Incorrect result with String concatenation optimization
kvn
parents:
diff changeset
    70