author | vdeshpande |
Fri, 26 Aug 2016 12:20:09 -0700 | |
changeset 41362 | e09e871860a7 |
parent 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
21523
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
1 |
/* |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
4 |
* |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
8 |
* |
49c80d56e5e3
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 |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
49c80d56e5e3
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 |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
13 |
* accompanied this code). |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
14 |
* |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
18 |
* |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
21 |
* questions. |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
22 |
*/ |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
23 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
24 |
/* |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
25 |
* @test |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
26 |
* @bug 8027445 |
49c80d56e5e3
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 |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
28 |
* |
40059 | 29 |
* @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation |
30 |
* compiler.intrinsics.string.TestStringEqualsBadLength |
|
21523
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
31 |
*/ |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
32 |
|
40059 | 33 |
package compiler.intrinsics.string; |
34 |
||
21523
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
35 |
import java.util.Arrays; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
36 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
37 |
public class TestStringEqualsBadLength { |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
38 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
39 |
int v1; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
40 |
int v2; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
41 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
42 |
boolean m(String s1) { |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
43 |
int l = v2 - v1; // 0 - (-1) = 1. On 64 bit: 0xffffffff00000001 |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
44 |
char[] arr = new char[l]; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
45 |
arr[0] = 'a'; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
46 |
String s2 = new String(arr); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
47 |
// The string length is not reloaded but the value computed is |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
48 |
// reused so pointer computation must not use |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
49 |
// 0xffffffff00000001 |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
50 |
return s2.equals(s1); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
51 |
} |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
52 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
53 |
// Same thing with String.compareTo() |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
54 |
int m2(String s1) { |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
55 |
int l = v2 - v1; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
56 |
char[] arr = new char[l+1]; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
57 |
arr[0] = 'a'; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
58 |
arr[1] = 'b'; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
59 |
String s2 = new String(arr); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
60 |
return s2.compareTo(s1); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
61 |
} |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
62 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
63 |
// Same thing with equals() for arrays |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
64 |
boolean m3(char[] arr1) { |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
65 |
int l = v2 - v1; // 0 - (-1) = 1. On 64 bit: 0xffffffff00000001 |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
66 |
char[] arr2 = new char[l]; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
67 |
arr2[0] = 'a'; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
68 |
return Arrays.equals(arr2, arr1); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
69 |
} |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
70 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
71 |
static public void main(String[] args) { |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
72 |
TestStringEqualsBadLength tse = new TestStringEqualsBadLength(); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
73 |
tse.v1 = -1; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
74 |
tse.v2 = 0; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
75 |
char[] arr = new char[1]; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
76 |
arr[0] = 'a'; |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
77 |
for (int i = 0; i < 20000; i++) { |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
78 |
tse.m("a"); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
79 |
tse.m2("ab"); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
80 |
tse.m3(arr); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
81 |
} |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
82 |
|
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
83 |
System.out.println("TEST PASSED"); |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
84 |
} |
49c80d56e5e3
8027445: SIGSEGV at TestFloatingDecimal.testAppendToDouble()I
roland
parents:
diff
changeset
|
85 |
} |