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 8027445
27 * @summary String.equals() may be called with a length whose upper bits are not cleared
28 * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation TestStringEqualsBadLength
29 *
30 */
31
32 import java.util.Arrays;
33
34 public class TestStringEqualsBadLength {
35
36 int v1;
37 int v2;
38
39 boolean m(String s1) {
40 int l = v2 - v1; // 0 - (-1) = 1. On 64 bit: 0xffffffff00000001
41 char[] arr = new char[l];
42 arr[0] = 'a';
43 String s2 = new String(arr);
44 // The string length is not reloaded but the value computed is
45 // reused so pointer computation must not use
46 // 0xffffffff00000001
47 return s2.equals(s1);
48 }
49
50 // Same thing with String.compareTo()
51 int m2(String s1) {
|
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 8027445
27 * @summary String.equals() may be called with a length whose upper bits are not cleared
28 *
29 * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation
30 * compiler.intrinsics.string.TestStringEqualsBadLength
31 */
32
33 package compiler.intrinsics.string;
34
35 import java.util.Arrays;
36
37 public class TestStringEqualsBadLength {
38
39 int v1;
40 int v2;
41
42 boolean m(String s1) {
43 int l = v2 - v1; // 0 - (-1) = 1. On 64 bit: 0xffffffff00000001
44 char[] arr = new char[l];
45 arr[0] = 'a';
46 String s2 = new String(arr);
47 // The string length is not reloaded but the value computed is
48 // reused so pointer computation must not use
49 // 0xffffffff00000001
50 return s2.equals(s1);
51 }
52
53 // Same thing with String.compareTo()
54 int m2(String s1) {
|