author | vdeshpande |
Fri, 26 Aug 2016 12:20:09 -0700 | |
changeset 41362 | e09e871860a7 |
parent 40059 | c2304140ed64 |
child 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
35573
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
1 |
/* |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
4 |
* |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
8 |
* |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
13 |
* accompanied this code). |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
14 |
* |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
18 |
* |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
21 |
* questions. |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
22 |
*/ |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
23 |
|
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
24 |
/* |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
25 |
* @test |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
26 |
* @bug 8144212 |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
27 |
* @summary Check for correct memory flow with the String compress/inflate intrinsics. |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
35573
diff
changeset
|
28 |
* @modules java.base/jdk.internal.misc |
35573
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
29 |
* @library /testlibrary |
40059 | 30 |
* |
31 |
* @run main compiler.intrinsics.string.TestStringIntrinsicMemoryFlow |
|
35573
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
32 |
*/ |
40059 | 33 |
|
34 |
package compiler.intrinsics.string; |
|
35 |
||
36 |
import jdk.test.lib.Asserts; |
|
37 |
||
35573
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
38 |
public class TestStringIntrinsicMemoryFlow { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
39 |
|
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
40 |
public static void main(String[] args) { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
41 |
for (int i = 0; i < 100_000; ++i) { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
42 |
String s = "MyString"; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
43 |
char[] c = {'M'}; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
44 |
char res = testInflate1(s); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
45 |
Asserts.assertEquals(res, 'M', "testInflate1 failed"); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
46 |
res = testInflate2(s); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
47 |
Asserts.assertEquals(res, (char)42, "testInflate2 failed"); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
48 |
res = testCompress1(c); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
49 |
Asserts.assertEquals(res, 'M', "testCompress1 failed"); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
50 |
byte resB = testCompress2(c); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
51 |
Asserts.assertEquals(resB, (byte)42, "testCompress2 failed"); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
52 |
} |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
53 |
} |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
54 |
|
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
55 |
private static char testInflate1(String s) { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
56 |
char c[] = new char[1]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
57 |
// Inflate String from byte[] to char[] |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
58 |
s.getChars(0, 1, c, 0); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
59 |
// Read char[] memory written by inflate intrinsic |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
60 |
return c[0]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
61 |
} |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
62 |
|
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
63 |
private static char testInflate2(String s) { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
64 |
char c1[] = new char[1]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
65 |
char c2[] = new char[1]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
66 |
c2[0] = 42; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
67 |
// Inflate String from byte[] to char[] |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
68 |
s.getChars(0, 1, c1, 0); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
69 |
// Read char[] memory written before inflation |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
70 |
return c2[0]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
71 |
} |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
72 |
|
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
73 |
private static char testCompress1(char[] c) { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
74 |
// Compress String from char[] to byte[] |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
75 |
String s = new String(c); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
76 |
// Read the memory written by compress intrinsic |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
77 |
return s.charAt(0); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
78 |
} |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
79 |
|
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
80 |
private static byte testCompress2(char[] c) { |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
81 |
byte b1[] = new byte[1]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
82 |
b1[0] = 42; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
83 |
// Compress String from char[] to byte[] |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
84 |
new String(c); |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
85 |
// Read byte[] memory written before compression |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
86 |
return b1[0]; |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
87 |
} |
e6c6e7a3b036
8144212: JDK 9 b93 breaks Apache Lucene due to compact strings
thartmann
parents:
diff
changeset
|
88 |
} |