Skip to content

Commit 3caea47

Browse files
committed
8262739: String inflation C2 intrinsic prevents insertion of anti-dependencies
Reviewed-by: neliasso, chagedorn
1 parent 19a6ac4 commit 3caea47

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/hotspot/share/adlc/formssel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ bool InstructForm::captures_bottom_type(FormDict &globals) const {
781781
!strcmp(_matrule->_rChild->_opType,"ShenandoahCompareAndExchangeP") ||
782782
!strcmp(_matrule->_rChild->_opType,"ShenandoahCompareAndExchangeN") ||
783783
#endif
784+
!strcmp(_matrule->_rChild->_opType,"StrInflatedCopy") ||
784785
!strcmp(_matrule->_rChild->_opType,"VectorMaskGen")||
785786
!strcmp(_matrule->_rChild->_opType,"CompareAndExchangeP") ||
786787
!strcmp(_matrule->_rChild->_opType,"CompareAndExchangeN"))) return true;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8262739
27+
* @summary Test correct insertion of anti-dependencies after String inflation.
28+
* @run main/othervm -Xbatch
29+
* compiler.controldependency.TestAntiDependencyAfterStringInflation
30+
*/
31+
32+
package compiler.controldependency;
33+
34+
public class TestAntiDependencyAfterStringInflation {
35+
36+
static String reverseString(String str) {
37+
int size = str.length();
38+
char[] buffer = new char[size];
39+
reverse(str, buffer, size);
40+
return new String(buffer, 0, size);
41+
}
42+
43+
static void reverse(String str, char[] buffer, int size) {
44+
// Inflate String.value byte[] to char[]
45+
str.getChars(0, size, buffer, 0);
46+
// Reverse String by copying buffer elements. This will fail
47+
// if C2 does not insert anti-dependencies between loads/stores.
48+
int half = size / 2;
49+
for (int l = 0, r = size - 1; l < half; l++, r--) {
50+
char tmp = buffer[l];
51+
buffer[l] = buffer[r];
52+
buffer[r] = tmp;
53+
}
54+
}
55+
56+
public static void main(String[] args) throws Exception {
57+
for (int i = 0; i < 50_000; i++) {
58+
String res = reverseString("0123456789");
59+
if (!res.equals("9876543210")) {
60+
throw new RuntimeException("Unexpected result: " + res);
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)