Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/string/TestHasNegatives.java
41153 views
1
/*
2
* Copyright (c) 2016, 2018, 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 8054307
27
* @summary Validates StringCoding.hasNegatives intrinsic with a small range of tests.
28
* @library /compiler/patches
29
*
30
* @build java.base/java.lang.Helper
31
* @run main compiler.intrinsics.string.TestHasNegatives
32
*/
33
34
package compiler.intrinsics.string;
35
36
/*
37
* @summary Validates StringCoding.hasNegatives intrinsic with a small
38
* range of tests.
39
*/
40
public class TestHasNegatives {
41
42
private static byte[] tBa = new byte[4096 + 16];
43
44
/**
45
* Completely initialize the test array, preparing it for tests of the
46
* StringCoding.hasNegatives method with a given array segment offset,
47
* length, and number of negative bytes.
48
*/
49
public static void initialize(int off, int len, int neg) {
50
assert (len + off <= tBa.length);
51
// insert "canary" (negative) values before offset
52
for (int i = 0; i < off; ++i) {
53
tBa[i] = (byte) (((i + 15) & 0x7F) | 0x80);
54
}
55
// fill the array segment
56
for (int i = off; i < len + off; ++i) {
57
tBa[i] = (byte) (((i - off + 15) & 0x7F));
58
}
59
if (neg != 0) {
60
// modify a number (neg) disparate array bytes inside
61
// segment to be negative.
62
int div = (neg > 1) ? (len - 1) / (neg - 1) : 0;
63
int idx;
64
for (int i = 0; i < neg; ++i) {
65
idx = off + (len - 1) - div * i;
66
tBa[idx] = (byte) (0x80 | tBa[idx]);
67
}
68
}
69
// insert "canary" negative values after array segment
70
for (int i = len + off; i < tBa.length; ++i) {
71
tBa[i] = (byte) (((i + 15) & 0x7F) | 0x80);
72
}
73
}
74
75
/** Sizes of array segments to test. */
76
private static int sizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 17, 19, 23, 37, 61, 131,
77
4099 };
78
79
/**
80
* Test different array segment sizes, offsets, and number of negative
81
* bytes.
82
*/
83
public static void test_hasNegatives() throws Exception {
84
int len, off;
85
int ng;
86
boolean r;
87
88
for (ng = 0; ng < 57; ++ng) { // number of negatives in array segment
89
for (off = 0; off < 8; ++off) { // starting offset of array segment
90
for (int i = 0; i < sizes.length; ++i) { // array segment size
91
// choice
92
len = sizes[i];
93
if (len + off > tBa.length)
94
continue;
95
initialize(off, len, ng);
96
r = Helper.StringCodingHasNegatives(tBa, off, len);
97
if (r ^ ((ng == 0) ? false : true)) {
98
throw new Exception("Failed test hasNegatives " + "offset: " + off + " "
99
+ "length: " + len + " " + "return: " + r + " " + "negatives: "
100
+ ng);
101
}
102
}
103
}
104
}
105
}
106
107
public void run() throws Exception {
108
// iterate to eventually get intrinsic inlined
109
for (int j = 0; j < 1000; ++j) {
110
test_hasNegatives();
111
}
112
}
113
114
public static void main(String[] args) throws Exception {
115
(new TestHasNegatives()).run();
116
System.out.println("hasNegatives validated");
117
}
118
}
119
120