Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/sysdict/share/BTreeGen.java
41161 views
1
/*
2
* Copyright (c) 2002, 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
package nsk.sysdict.share;
25
26
import java.io.*;
27
28
/**
29
* This tools generates a binary tree of classes.
30
* For more details, use:
31
* <pre>
32
* java BTreeGen -help
33
* </pre>
34
*/
35
public class BTreeGen {
36
private static final int HEIGHT = 12; // default tree height
37
private static final int WEIGHT = 200; // as many longs in each node
38
39
private static void explain(Object x) {
40
System.err.println("# " + x);
41
}
42
43
public static void main(String args[]) {
44
if (args.length < 1 || args[0].toLowerCase().startsWith("-h")) {
45
explain("This tools generates a binary tree of classes:");
46
explain("");
47
explain(" BTree0");
48
explain(" / \\");
49
explain(" BTree0L BTree0R");
50
explain(" / \\ / \\");
51
explain(" ... ... ... ...");
52
explain("");
53
explain("Use:");
54
explain(" java BTreeGen { $HEIGHT [ $WEIGHT ] | \"default\" }");
55
explain("");
56
explain("Generates:");
57
explain(" BTree.java class having HEIGHT constant.");
58
explain(" BTree0.java defining a classes tree.");
59
explain("");
60
explain("Here:");
61
explain(" HEIGHT and WEIGHT must be positive integers.");
62
explain(" Default HEIGHT is " + HEIGHT + " ("
63
+ ((1<<HEIGHT)-1) + " classes in a tree).");
64
explain(" Default WEIGHT is " + WEIGHT + ".");
65
System.exit(1);
66
};
67
int height = HEIGHT;
68
int weight = WEIGHT;
69
if (!args[0].toLowerCase().equals("default")) {
70
height = Integer.parseInt(args[0]);
71
if (args.length > 1)
72
weight = Integer.parseInt(args[1]);
73
};
74
try {
75
doit(height, weight);
76
} catch (IOException exception) {
77
exception.printStackTrace(System.err);
78
System.exit(1);
79
}
80
}
81
82
private static void doit(int height, int weight)
83
throws FileNotFoundException
84
{
85
// Constant definition:
86
PrintStream info;
87
info = new PrintStream(new FileOutputStream(new File("BTreeInfo.java")));
88
info.println("// This file is generated by: BTreeGen.java");
89
info.println("package nsk.sysdict.share;");
90
info.println("import nsk.share.*;");
91
info.println("public class BTreeInfo {");
92
info.println(" public static final int HEIGHT = " + height + ";");
93
info.println(" private static final int WEIGHT = " + weight + ";");
94
info.println(" public static final String rootName = \"BTree0\";");
95
info.println(" public static final Denotation nodesDenotation");
96
info.println(" = new TreeNodesDenotation(\"LR\");");
97
info.println("}");
98
info.close();
99
// Generate ta classes tree:
100
PrintStream btree;
101
btree = new PrintStream(new FileOutputStream(new File("BTree.java")));
102
btree.println("// This file is generated by: BTreeGen.java");
103
btree.println("package nsk.sysdict.share;");
104
new BTreeGen(btree).generate(height,weight);
105
btree.close();
106
}
107
108
private PrintStream stream;
109
private BTreeGen(PrintStream stream) {
110
this.stream = stream;
111
}
112
private void println(String s) {
113
stream.println(s);
114
}
115
116
private void generate(int height, int weight) {
117
if (height < 1)
118
throw new IllegalArgumentException("bad height: " + height);
119
if (weight < 1)
120
throw new IllegalArgumentException("bad weight: " + weight);
121
String basename = "BTree0";
122
genClass(null,basename,weight);
123
gen(basename,height,weight);
124
}
125
126
private void gen(String name, int height, int weight) {
127
if (height == 1)
128
return;
129
String nameL = name + "L";
130
String nameR = name + "R";
131
genClass(name, nameL, weight);
132
genClass(name, nameR, weight);
133
gen(nameL, height-1, weight);
134
gen(nameR, height-1, weight);
135
}
136
137
private void genClass(String baseName, String className, int weight) {
138
println("class " + className
139
+ (baseName!=null? " extends " + baseName: "") + " {");
140
for (int w=1; w<=weight; w++)
141
println(" static long fill_" + className + "_" + w + ";");
142
println("}");
143
}
144
}
145
146