author | iignatyev |
Fri, 11 Aug 2017 16:06:55 -0700 | |
changeset 46244 | b5e5ec91094d |
parent 45694 | b27907b3cd38 |
child 48155 | 551de50b4ff7 |
permissions | -rw-r--r-- |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
1 |
/* |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39949
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
4 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
8 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
13 |
* accompanied this code). |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
14 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
18 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
21 |
* questions. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
22 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
23 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
24 |
package jdk.test.lib; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
25 |
|
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
26 |
import java.io.File; |
45453
e72b2abd7f92
8181820: jdk/test/lib/Platform should not depend on jdk/test/lib/Utils
epavlova
parents:
43394
diff
changeset
|
27 |
import java.io.IOException; |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
28 |
import java.io.RandomAccessFile; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
29 |
import java.util.regex.Pattern; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
30 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
31 |
public class Platform { |
39949
ca77d07755bc
8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents:
35439
diff
changeset
|
32 |
public static final String vmName = System.getProperty("java.vm.name"); |
ca77d07755bc
8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents:
35439
diff
changeset
|
33 |
public static final String vmInfo = System.getProperty("java.vm.info"); |
41264 | 34 |
private static final String osVersion = System.getProperty("os.version"); |
35 |
private static int osVersionMajor = -1; |
|
36 |
private static int osVersionMinor = -1; |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
37 |
private static final String osName = System.getProperty("os.name"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
38 |
private static final String dataModel = System.getProperty("sun.arch.data.model"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
39 |
private static final String vmVersion = System.getProperty("java.vm.version"); |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39949
diff
changeset
|
40 |
private static final String jdkDebug = System.getProperty("jdk.debug"); |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
41 |
private static final String osArch = System.getProperty("os.arch"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
42 |
private static final String userName = System.getProperty("user.name"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
43 |
private static final String compiler = System.getProperty("sun.management.compiler"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
44 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
45 |
public static boolean isClient() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
46 |
return vmName.endsWith(" Client VM"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
47 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
48 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
49 |
public static boolean isServer() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
50 |
return vmName.endsWith(" Server VM"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
51 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
52 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
53 |
public static boolean isGraal() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
54 |
return vmName.endsWith(" Graal VM"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
55 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
56 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
57 |
public static boolean isZero() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
58 |
return vmName.endsWith(" Zero VM"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
59 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
60 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
61 |
public static boolean isMinimal() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
62 |
return vmName.endsWith(" Minimal VM"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
63 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
64 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
65 |
public static boolean isEmbedded() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
66 |
return vmName.contains("Embedded"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
67 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
68 |
|
43394
68ed4de0f9c8
8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents:
42508
diff
changeset
|
69 |
public static boolean isEmulatedClient() { |
68ed4de0f9c8
8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents:
42508
diff
changeset
|
70 |
return vmInfo.contains(" emulated-client"); |
68ed4de0f9c8
8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents:
42508
diff
changeset
|
71 |
} |
68ed4de0f9c8
8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents:
42508
diff
changeset
|
72 |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
73 |
public static boolean isTieredSupported() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
74 |
return compiler.contains("Tiered Compilers"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
75 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
76 |
|
35439
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
77 |
public static boolean isInt() { |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
78 |
return vmInfo.contains("interpreted"); |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
79 |
} |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
80 |
|
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
81 |
public static boolean isMixed() { |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
82 |
return vmInfo.contains("mixed"); |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
83 |
} |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
84 |
|
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
85 |
public static boolean isComp() { |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
86 |
return vmInfo.contains("compiled"); |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
87 |
} |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
88 |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
89 |
public static boolean is32bit() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
90 |
return dataModel.equals("32"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
91 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
92 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
93 |
public static boolean is64bit() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
94 |
return dataModel.equals("64"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
95 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
96 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
97 |
public static boolean isAix() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
98 |
return isOs("aix"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
99 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
100 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
101 |
public static boolean isLinux() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
102 |
return isOs("linux"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
103 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
104 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
105 |
public static boolean isOSX() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
106 |
return isOs("mac"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
107 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
108 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
109 |
public static boolean isSolaris() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
110 |
return isOs("sunos"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
111 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
112 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
113 |
public static boolean isWindows() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
114 |
return isOs("win"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
115 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
116 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
117 |
private static boolean isOs(String osname) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
118 |
return osName.toLowerCase().startsWith(osname.toLowerCase()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
119 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
120 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
121 |
public static String getOsName() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
122 |
return osName; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
123 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
124 |
|
41264 | 125 |
// Os version support. |
126 |
private static void init_version() { |
|
127 |
try { |
|
128 |
final String[] tokens = osVersion.split("\\."); |
|
129 |
if (tokens.length > 0) { |
|
130 |
osVersionMajor = Integer.parseInt(tokens[0]); |
|
131 |
if (tokens.length > 1) { |
|
132 |
osVersionMinor = Integer.parseInt(tokens[1]); |
|
133 |
} |
|
134 |
} |
|
135 |
} catch (NumberFormatException e) { |
|
136 |
osVersionMajor = osVersionMinor = 0; |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
// Returns major version number from os.version system property. |
|
141 |
// E.g. 5 on Solaris 10 and 3 on SLES 11.3 (for the linux kernel version). |
|
142 |
public static int getOsVersionMajor() { |
|
143 |
if (osVersionMajor == -1) init_version(); |
|
144 |
return osVersionMajor; |
|
145 |
} |
|
146 |
||
147 |
// Returns minor version number from os.version system property. |
|
148 |
// E.g. 10 on Solaris 10 and 0 on SLES 11.3 (for the linux kernel version). |
|
149 |
public static int getOsVersionMinor() { |
|
150 |
if (osVersionMinor == -1) init_version(); |
|
151 |
return osVersionMinor; |
|
152 |
} |
|
153 |
||
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
154 |
public static boolean isDebugBuild() { |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39949
diff
changeset
|
155 |
return (jdkDebug.toLowerCase().contains("debug")); |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
156 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
157 |
|
41041
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
158 |
public static boolean isSlowDebugBuild() { |
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
159 |
return (jdkDebug.toLowerCase().equals("slowdebug")); |
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
160 |
} |
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
161 |
|
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
162 |
public static boolean isFastDebugBuild() { |
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
163 |
return (jdkDebug.toLowerCase().equals("fastdebug")); |
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
164 |
} |
9004ed3bcbd8
8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents:
40614
diff
changeset
|
165 |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
166 |
public static String getVMVersion() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
167 |
return vmVersion; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
168 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
169 |
|
42508 | 170 |
public static boolean isAArch64() { |
171 |
return isArch("aarch64"); |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
172 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
173 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
174 |
public static boolean isARM() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
175 |
return isArch("arm.*"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
176 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
177 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
178 |
public static boolean isPPC() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
179 |
return isArch("ppc.*"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
180 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
181 |
|
42508 | 182 |
// Returns true for IBM z System running linux. |
183 |
public static boolean isS390x() { |
|
184 |
return isArch("s390.*") || isArch("s/390.*") || isArch("zArch_64"); |
|
185 |
} |
|
186 |
||
187 |
// Returns true for sparc and sparcv9. |
|
188 |
public static boolean isSparc() { |
|
189 |
return isArch("sparc.*"); |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
190 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
191 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
192 |
public static boolean isX64() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
193 |
// On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64' |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
194 |
return isArch("(amd64)|(x86_64)"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
195 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
196 |
|
42508 | 197 |
public static boolean isX86() { |
198 |
// On Linux it's 'i386', Windows 'x86' without '_64' suffix. |
|
199 |
return isArch("(i386)|(x86(?!_64))"); |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
200 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
201 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
202 |
public static String getOsArch() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
203 |
return osArch; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
204 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
205 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
206 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
207 |
* Return a boolean for whether we expect to be able to attach |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
208 |
* the SA to our own processes on this system. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
209 |
*/ |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
210 |
public static boolean shouldSAAttach() throws IOException { |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
211 |
if (isAix()) { |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
212 |
return false; // SA not implemented. |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
213 |
} else if (isLinux()) { |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
214 |
if (isS390x()) { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
215 |
return false; // SA not implemented. |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
216 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
217 |
return canPtraceAttachLinux(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
218 |
} else if (isOSX()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
219 |
return canAttachOSX(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
220 |
} else { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
221 |
// Other platforms expected to work: |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
222 |
return true; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
223 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
224 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
225 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
226 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
227 |
* On Linux, first check the SELinux boolean "deny_ptrace" and return false |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
228 |
* as we expect to be denied if that is "1". Then expect permission to attach |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
229 |
* if we are root, so return true. Then return false for an expected denial |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
230 |
* if "ptrace_scope" is 1, and true otherwise. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
231 |
*/ |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
232 |
private static boolean canPtraceAttachLinux() throws IOException { |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
233 |
// SELinux deny_ptrace: |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
234 |
File deny_ptrace = new File("/sys/fs/selinux/booleans/deny_ptrace"); |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
235 |
if (deny_ptrace.exists()) { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
236 |
try (RandomAccessFile file = new RandomAccessFile(deny_ptrace, "r")) { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
237 |
if (file.readByte() != '0') { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
238 |
return false; |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
239 |
} |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
240 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
241 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
242 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
243 |
// YAMA enhanced security ptrace_scope: |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
244 |
// 0 - a process can PTRACE_ATTACH to any other process running under the same uid |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
245 |
// 1 - restricted ptrace: a process must be a children of the inferior or user is root |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
246 |
// 2 - only processes with CAP_SYS_PTRACE may use ptrace or user is root |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
247 |
// 3 - no attach: no processes may use ptrace with PTRACE_ATTACH |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
248 |
File ptrace_scope = new File("/proc/sys/kernel/yama/ptrace_scope"); |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
249 |
if (ptrace_scope.exists()) { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
250 |
try (RandomAccessFile file = new RandomAccessFile(ptrace_scope, "r")) { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
251 |
byte yama_scope = file.readByte(); |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
252 |
if (yama_scope == '3') { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
253 |
return false; |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
254 |
} |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
255 |
|
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
256 |
if (!userName.equals("root") && yama_scope != '0') { |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
257 |
return false; |
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
258 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
259 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
260 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
261 |
// Otherwise expect to be permitted: |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
262 |
return true; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
263 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
264 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
265 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
266 |
* On OSX, expect permission to attach only if we are root. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
267 |
*/ |
45694
b27907b3cd38
8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents:
45453
diff
changeset
|
268 |
private static boolean canAttachOSX() { |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
269 |
return userName.equals("root"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
270 |
} |
35439
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
271 |
|
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
272 |
private static boolean isArch(String archnameRE) { |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
273 |
return Pattern.compile(archnameRE, Pattern.CASE_INSENSITIVE) |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
274 |
.matcher(osArch) |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
275 |
.matches(); |
c82750faebf7
8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents:
34597
diff
changeset
|
276 |
} |
46244
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
277 |
|
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
278 |
/** |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
279 |
* Returns file extension of shared library, e.g. "so" on linux, "dll" on windows. |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
280 |
* @return file extension |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
281 |
*/ |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
282 |
public static String sharedLibraryExt() { |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
283 |
if (isWindows()) { |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
284 |
return "dll"; |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
285 |
} else if (isOSX()) { |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
286 |
return "dylib"; |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
287 |
} else { |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
288 |
return "so"; |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
289 |
} |
b5e5ec91094d
8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents:
45694
diff
changeset
|
290 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
291 |
} |