Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/c1/ArithmeticRemRCE.java
41152 views
1
/*
2
* Copyright (c) 2021, Alibaba Group Holding Limited. 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
/*
26
* @test
27
* @bug 8267239
28
* @author Yi Yang
29
* @summary apply RCE for % operations
30
* @requires vm.compiler1.enabled
31
* @library /test/lib
32
* @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation
33
* -XX:CompileCommand=compileonly,*ArithmeticRemRCE.test*
34
* compiler.c1.ArithmeticRemRCE
35
*/
36
37
package compiler.c1;
38
39
import jdk.test.lib.Asserts;
40
41
public class ArithmeticRemRCE {
42
static int field = 1000;
43
44
static void test1() {
45
// seq should be loop invariant, so we can not put it into static fields
46
int[] seq = new int[1000];
47
for (int i = 0; i < seq.length; i++) {
48
seq[i] = i;
49
}
50
51
for (int i = 0; i < 1024; i++) {
52
int constVal = 10;
53
Asserts.assertTrue(0 <= seq[i % 5] && seq[i % 5] <= 4);
54
Asserts.assertTrue(0 <= seq[i % -5] && seq[i % -5] <= 4);
55
56
Asserts.assertTrue(0 <= seq[i % constVal] && seq[i % constVal] <= 9);
57
Asserts.assertTrue(0 <= seq[i % -constVal] && seq[i % -constVal] <= 9);
58
59
Asserts.assertTrue(seq[i % 1] == 0);
60
61
// will not apply RCE
62
Asserts.assertTrue(0 <= seq[i % field] && seq[i % field] <= 999);
63
Asserts.assertTrue(0 <= seq[i % -field] && seq[i % -field] <= 999);
64
}
65
}
66
67
public static void main(String... args) throws Exception {
68
for (int i = 0; i < 10_000; i++) {
69
test1();
70
}
71
}
72
}
73
74