3464N/A/*
3464N/A * Copyright 2012 Skip Balk. All Rights Reserved.
3464N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3464N/A *
3464N/A * This code is free software; you can redistribute it and/or modify it
3464N/A * under the terms of the GNU General Public License version 2 only, as
3464N/A * published by the Free Software Foundation.
3464N/A *
3464N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3464N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3464N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3464N/A * version 2 for more details (a copy is included in the LICENSE file that
3464N/A * accompanied this code).
3464N/A *
3464N/A * You should have received a copy of the GNU General Public License version
3464N/A * 2 along with this work; if not, write to the Free Software Foundation,
3464N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3464N/A *
3464N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3464N/A * or visit www.oracle.com if you need additional information or have any
3464N/A * questions.
3464N/A */
3464N/A
3464N/A/*
3464N/A * @test
3464N/A * @bug 7179138
3464N/A * @summary Incorrect result with String concatenation optimization
3464N/A * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation Test7179138_2
3464N/A *
3464N/A * @author Skip Balk
3464N/A */
3464N/A
3464N/Apublic class Test7179138_2 {
3464N/A public static void main(String[] args) throws Exception {
3464N/A System.out.println("Java Version: " + System.getProperty("java.vm.version"));
3464N/A long[] durations = new long[60];
3464N/A for (int i = 0; i < 100000; i++) {
3464N/A // this empty for-loop is required to reproduce this bug
3464N/A for (long duration : durations) {
3464N/A // do nothing
3464N/A }
3464N/A {
3464N/A String s = "test";
3464N/A int len = s.length();
3464N/A
3464N/A s = s + s;
3464N/A len = len + len;
3464N/A
3464N/A s = s + s;
3464N/A len = len + len;
3464N/A
3464N/A s = s + s;
3464N/A len = len + len;
3464N/A
3464N/A if (s.length() != len) {
3464N/A System.out.println("Failed at iteration: " + i);
3464N/A System.out.println("Length mismatch: " + s.length() + " <> " + len);
3464N/A System.out.println("Expected: \"" + "test" + "test" + "test" + "test" + "test" + "test" + "test" + "test" + "\"");
3464N/A System.out.println("Actual: \"" + s + "\"");
3464N/A System.exit(0);
3464N/A }
3464N/A }
3464N/A }
3464N/A }
3464N/A}
3464N/A