Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/misc/Version/Version.java
38838 views
1
/*
2
* Copyright (c) 2010, 2014, 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
/* @test
25
* @bug 6994413
26
* @summary Check the JDK and JVM version returned by sun.misc.Version
27
* matches the versions defined in the system properties
28
* @compile -XDignore.symbol.file Version.java
29
* @run main Version
30
*/
31
32
import java.util.regex.*;
33
import static sun.misc.Version.*;
34
35
public class Version {
36
37
public static void main(String[] args) throws Exception {
38
VersionInfo jdk = jdkVersionInfo(System.getProperty("java.runtime.version"));
39
VersionInfo v1 = new VersionInfo(jdkMajorVersion(),
40
jdkMinorVersion(),
41
jdkMicroVersion(),
42
jdkUpdateVersion(),
43
jdkSpecialVersion(),
44
jdkBuildNumber());
45
System.out.println("JDK version = " + jdk + " " + v1);
46
if (!jdk.equals(v1)) {
47
throw new RuntimeException("Unmatched version: " + jdk + " vs " + v1);
48
}
49
VersionInfo jvm = jvmVersionInfo(System.getProperty("java.vm.version"));
50
VersionInfo v2 = new VersionInfo(jvmMajorVersion(),
51
jvmMinorVersion(),
52
jvmMicroVersion(),
53
jvmUpdateVersion(),
54
jvmSpecialVersion(),
55
jvmBuildNumber());
56
System.out.println("JVM version = " + jvm + " " + v2);
57
if (!jvm.equals(v2)) {
58
throw new RuntimeException("Unmatched version: " + jvm + " vs " + v2);
59
}
60
}
61
62
static class VersionInfo {
63
final int major;
64
final int minor;
65
final int micro;
66
final int update;
67
final String special;
68
final int build;
69
VersionInfo(int major, int minor, int micro,
70
int update, String special, int build) {
71
this.major = major;
72
this.minor = minor;
73
this.micro = micro;
74
this.update = update;
75
this.special = special;
76
this.build = build;
77
}
78
79
public boolean equals(VersionInfo v) {
80
return (this.major == v.major && this.minor == v.minor &&
81
this.micro == v.micro && this.update == v.update &&
82
this.special.equals(v.special) && this.build == v.build);
83
}
84
85
public String toString() {
86
StringBuilder sb = new StringBuilder();
87
sb.append(major + "." + minor + "." + micro);
88
if (update > 0) {
89
sb.append("_" + update);
90
}
91
92
if (!special.isEmpty()) {
93
sb.append(special);
94
}
95
sb.append("-b" + build);
96
return sb.toString();
97
}
98
}
99
100
private static VersionInfo jdkVersionInfo(String version) throws Exception {
101
// valid format of the version string is:
102
// <major>.<minor>[.<micro>][_uu[c]][-<identifier>]-bxx
103
int major = 0;
104
int minor = 0;
105
int micro = 0;
106
int update = 0;
107
String special = "";
108
int build = 0;
109
110
String regex = "^([0-9]{1,2})"; // major
111
regex += "\\."; // separator
112
regex += "([0-9]{1,2})"; // minor
113
regex += "(\\."; // separator
114
regex += "([0-9]{1,2})"; // micro
115
regex += ")?"; // micro is optional
116
regex += "(_";
117
regex += "([0-9]{2,3})"; // update
118
regex += "([a-z])?"; // special char (optional)
119
regex += ")?"; // _uu[c] is optional
120
regex += ".*"; // -<identifier>
121
regex += "(\\-b([0-9]{1,3}$))"; // JDK -bxx
122
123
Pattern p = Pattern.compile(regex);
124
Matcher m = p.matcher(version);
125
m.matches();
126
127
major = Integer.parseInt(m.group(1));
128
minor = Integer.parseInt(m.group(2));
129
micro = (m.group(4) == null) ? 0 : Integer.parseInt(m.group(4));
130
update = (m.group(6) == null) ? 0 : Integer.parseInt(m.group(6));
131
special = (m.group(7) == null) ? "" : m.group(7);
132
build = Integer.parseInt(m.group(9));
133
134
VersionInfo vi = new VersionInfo(major, minor, micro, update, special, build);
135
System.out.printf("jdkVersionInfo: input=%s output=%s\n", version, vi);
136
return vi;
137
}
138
139
private static VersionInfo jvmVersionInfo(String version) throws Exception {
140
try {
141
// valid format of the version string is:
142
// <major>.<minor>-bxx[-<identifier>][-<debug_flavor>]
143
int major = 0;
144
int minor = 0;
145
int build = 0;
146
147
String regex = "^([0-9]{1,2})"; // major
148
regex += "\\."; // separator
149
regex += "([0-9]{1,3})"; // minor
150
regex += "(\\-b([0-9]{1,3}))"; // JVM -bxx
151
regex += ".*";
152
153
Pattern p = Pattern.compile(regex);
154
Matcher m = p.matcher(version);
155
m.matches();
156
157
major = Integer.parseInt(m.group(1));
158
minor = Integer.parseInt(m.group(2));
159
build = Integer.parseInt(m.group(4));
160
161
VersionInfo vi = new VersionInfo(major, minor, 0, 0, "", build);
162
System.out.printf("jvmVersionInfo: input=%s output=%s\n", version, vi);
163
return vi;
164
} catch (IllegalStateException e) {
165
// local builds may also follow the jdkVersionInfo format
166
return jdkVersionInfo(version);
167
}
168
}
169
}
170
171