hotspot/test/compiler/intrinsics/string/TestStringConstruction.java
author thartmann
Fri, 27 Nov 2015 09:36:46 +0100
changeset 34499 343abbc06572
child 40059 c2304140ed64
permissions -rw-r--r--
8142303: C2 compilation fails with "bad AD file" Summary: Move range checks into intrinsics for String methods. Reviewed-by: kvn, aph
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34499
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     1
/*
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     4
 *
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     8
 *
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    13
 * accompanied this code).
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    14
 *
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    18
 *
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    21
 * questions.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    22
 */
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    23
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    24
/*
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    25
 * @test
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    26
 * @bug 8142303
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    27
 * @summary Tests handling of invalid array indices in C2 intrinsic if explicit range check in Java code is not inlined.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    28
 * @run main/othervm -XX:CompileCommand=inline,java.lang.String::* -XX:CompileCommand=inline,java.lang.StringUTF16::* -XX:CompileCommand=exclude,java.lang.String::checkBoundsOffCount TestStringConstruction
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    29
 */
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    30
public class TestStringConstruction {
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    31
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    32
    public static void main(String[] args) {
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    33
        char[] chars = new char[42];
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    34
        for (int i = 0; i < 10_000; ++i) {
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    35
            test(chars);
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    36
        }
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    37
    }
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    38
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    39
    private static String test(char[] chars) {
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    40
        try {
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    41
            // The constructor calls String::checkBoundsOffCount(-1, 42) to perform
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    42
            // range checks on offset and count. If this method is not inlined, C2
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    43
            // does not know about the explicit range checks and does not cut off the
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    44
            // dead code. As a result, -1 is fed as offset into the StringUTF16.compress
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    45
            // intrinsic which is replaced by TOP and causes a failure in the matcher.
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    46
            return new String(chars, -1 , 42);
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    47
        } catch (Exception e) {
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    48
            return "";
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    49
        }
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    50
    }
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    51
}
343abbc06572 8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
diff changeset
    52