Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/graph/test6.java
40948 views
1
/*
2
* Copyright (c) 2008, 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
package jit.graph;
25
26
import jdk.test.lib.Utils;
27
import nsk.share.TestFailure;
28
29
import java.lang.reflect.InvocationTargetException;
30
import java.util.Random;
31
import java.util.Vector;
32
33
public class test6 {
34
private static final int[] MethodID = {Globals.MethodID_Array[11]};
35
36
private static Random localNumGen = new Random(Utils.SEED);
37
private static final int maxEntries = 25;
38
39
// flattens the binary tree into an array
40
private void getSortedArray(Node root, int[] dataArray, int[] index) {
41
if ((root != null) && (root != RBTree.treeNull)) {
42
getSortedArray(root.getNode(Node.Left_son), dataArray, index);
43
dataArray[index[0]++] = root.getKey();
44
getSortedArray(root.getNode(Node.Right_son), dataArray, index);
45
}
46
}
47
48
public synchronized void rbTest(Vector summation, Vector ID, Long functionDepth, Integer staticFunctionDepth)
49
throws InvocationTargetException {
50
Globals.appendSumToSummationVector(MethodID[0], summation);
51
52
if (CGT.shouldFinish()) {
53
return;
54
}
55
if (Globals.VERBOSE) {
56
System.out.println("test6.rbTest");
57
}
58
59
if ((functionDepth.longValue() <= 0) && (staticFunctionDepth.intValue() <= 0)) {
60
return;
61
}
62
MethodData methodCallStr;
63
Long numFcalls;
64
Integer staticFcalls;
65
66
if (staticFunctionDepth.intValue() > 0) {
67
numFcalls = functionDepth;
68
staticFcalls = Integer.valueOf(staticFunctionDepth.intValue() - 1);
69
methodCallStr = Globals.returnNextStaticMethod(MethodID[0]);
70
} else {
71
numFcalls = Long.valueOf(functionDepth.longValue() - 1);
72
staticFcalls = staticFunctionDepth;
73
methodCallStr = Globals.nextRandomMethod();
74
}
75
76
RBTree myTree = new RBTree();
77
int numElements = 1 + localNumGen.nextInt(maxEntries);
78
int dataArray[] = new int[numElements];
79
boolean insertArray[] = new boolean[numElements];
80
81
Vector temp = new Vector(numElements);
82
// code guarantees no duplicates
83
for (int i = 0; i < numElements; i++) {
84
int nextKey = localNumGen.nextInt(16385);
85
while (temp.indexOf(Integer.valueOf(nextKey)) != -1) {
86
nextKey = localNumGen.nextInt(16385);
87
}
88
89
temp.addElement(Integer.valueOf(nextKey));
90
dataArray[i] = nextKey;
91
92
insertArray[i] = false;
93
}
94
temp = null;
95
96
int numLoops = 10 + localNumGen.nextInt(1024);
97
for (int i = 0; i < numLoops; i++) {
98
int nextIndex = localNumGen.nextInt(numElements);
99
if (!insertArray[nextIndex]) {
100
myTree.RBInsert(dataArray[nextIndex]);
101
insertArray[nextIndex] = true;
102
} else {
103
myTree.RBDelete(dataArray[nextIndex]);
104
insertArray[nextIndex] = false;
105
}
106
}
107
108
int numValid = 0;
109
for (int i = 0; i < numElements; i++) {
110
Node searchNode = myTree.Search(dataArray[i]);
111
if (insertArray[i] && (searchNode == RBTree.treeNull)) {
112
throw new TestFailure("Valid Node Not Found in Binary Tree. Node " + dataArray[i]);
113
} else if ((!insertArray[i]) && (searchNode != RBTree.treeNull)) {
114
throw new TestFailure("Deleted Node Found in Binary Tree. Node " + dataArray[i]);
115
} else if (insertArray[i]) {
116
numValid++;
117
}
118
// so that verification is only done once
119
insertArray[i] = true;
120
}
121
122
int[] sortedArray = new int[numValid];
123
getSortedArray(myTree.getRoot(), sortedArray, new int[]{0});
124
125
for (int i = 1; i < numValid; i++) {
126
if (sortedArray[i] <= sortedArray[i - 1]) {
127
StringBuilder outStr = new StringBuilder("Actual ");
128
for (int aSortedArray : sortedArray) {
129
outStr.append(aSortedArray)
130
.append(", ");
131
}
132
System.out.println("Binary Tree Property Not Held");
133
System.out.println("Root " + myTree.getRoot()
134
.getKey());
135
throw new TestFailure(outStr.toString());
136
}
137
}
138
139
Globals.addFunctionIDToVector(methodCallStr.id, ID);
140
Globals.callMethod(methodCallStr, summation, ID, numFcalls, staticFcalls);
141
}
142
}
143
144