Mercurial > hg > truffle
annotate test/compiler/intrinsics/stringequals/TestStringEqualsBadLength.java @ 15338:5e544920ad9f
Rename Backend.newNodeLIRGenerator to Backend.newNodeLIRBuilder.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 23 Apr 2014 13:18:58 +0200 |
parents | 208ebea980f8 |
children |
rev | line source |
---|---|
13042
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
1 /* |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
4 * |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
8 * |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
13 * accompanied this code). |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
14 * |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
18 * |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
21 * questions. |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
22 */ |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
23 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
24 /* |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
25 * @test |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
26 * @bug 8027445 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
27 * @summary String.equals() may be called with a length whose upper bits are not cleared |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
28 * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation TestStringEqualsBadLength |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
29 * |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
30 */ |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
31 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
32 import java.util.Arrays; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
33 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
34 public class TestStringEqualsBadLength { |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
35 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
36 int v1; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
37 int v2; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
38 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
39 boolean m(String s1) { |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
40 int l = v2 - v1; // 0 - (-1) = 1. On 64 bit: 0xffffffff00000001 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
41 char[] arr = new char[l]; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
42 arr[0] = 'a'; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
43 String s2 = new String(arr); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
44 // The string length is not reloaded but the value computed is |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
45 // reused so pointer computation must not use |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
46 // 0xffffffff00000001 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
47 return s2.equals(s1); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
48 } |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
49 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
50 // Same thing with String.compareTo() |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
51 int m2(String s1) { |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
52 int l = v2 - v1; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
53 char[] arr = new char[l+1]; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
54 arr[0] = 'a'; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
55 arr[1] = 'b'; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
56 String s2 = new String(arr); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
57 return s2.compareTo(s1); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
58 } |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
59 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
60 // Same thing with equals() for arrays |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
61 boolean m3(char[] arr1) { |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
62 int l = v2 - v1; // 0 - (-1) = 1. On 64 bit: 0xffffffff00000001 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
63 char[] arr2 = new char[l]; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
64 arr2[0] = 'a'; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
65 return Arrays.equals(arr2, arr1); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
66 } |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
67 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
68 static public void main(String[] args) { |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
69 TestStringEqualsBadLength tse = new TestStringEqualsBadLength(); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
70 tse.v1 = -1; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
71 tse.v2 = 0; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
72 char[] arr = new char[1]; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
73 arr[0] = 'a'; |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
74 for (int i = 0; i < 20000; i++) { |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
75 tse.m("a"); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
76 tse.m2("ab"); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
77 tse.m3(arr); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
78 } |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
79 |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
80 System.out.println("TEST PASSED"); |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
81 } |
208ebea980f8
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
82 } |