1 /*
2 * Copyright (c) 2013, 2019, 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 jdk.test.lib;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.RandomAccessFile;
29 import java.util.regex.Pattern;
30 import java.security.AccessController;
31 import java.security.PrivilegedAction;
32 import java.security.PrivilegedActionException;
33 import java.security.PrivilegedExceptionAction;
34
35 public class Platform {
36 public static final String vmName = privilegedGetProperty("java.vm.name");
37 public static final String vmInfo = privilegedGetProperty("java.vm.info");
38 private static final String osVersion = privilegedGetProperty("os.version");
39 private static int osVersionMajor = -1;
40 private static int osVersionMinor = -1;
41 private static final String osName = privilegedGetProperty("os.name");
42 private static final String dataModel = privilegedGetProperty("sun.arch.data.model");
43 private static final String vmVersion = privilegedGetProperty("java.vm.version");
44 private static final String jdkDebug = privilegedGetProperty("jdk.debug");
45 private static final String osArch = privilegedGetProperty("os.arch");
46 private static final String userName = privilegedGetProperty("user.name");
47 private static final String compiler = privilegedGetProperty("sun.management.compiler");
48
49 private static String privilegedGetProperty(String key) {
50 return AccessController.doPrivileged((
51 PrivilegedAction<String>) () -> System.getProperty(key));
52 }
53
54 public static boolean isClient() {
55 return vmName.endsWith(" Client VM");
56 }
57
58 public static boolean isServer() {
59 return vmName.endsWith(" Server VM");
60 }
61
62 public static boolean isZero() {
63 return vmName.endsWith(" Zero VM");
64 }
65
66 public static boolean isMinimal() {
67 return vmName.endsWith(" Minimal VM");
317 } else {
318 return "so";
319 }
320 }
321
322 /*
323 * Returns name of system variable containing paths to shared native libraries.
324 */
325 public static String sharedLibraryPathVariableName() {
326 if (isWindows()) {
327 return "PATH";
328 } else if (isOSX()) {
329 return "DYLD_LIBRARY_PATH";
330 } else if (isAix()) {
331 return "LIBPATH";
332 } else {
333 return "LD_LIBRARY_PATH";
334 }
335 }
336
337 public static boolean isDefaultCDSArchiveSupported() {
338 return (is64bit() &&
339 isServer() &&
340 (isLinux() ||
341 isOSX() ||
342 isSolaris() ||
343 isWindows()) &&
344 !isZero() &&
345 !isMinimal() &&
346 !isAArch64() &&
347 !isARM());
348 }
349
350 /*
351 * This should match the #if condition in ClassListParser::load_class_from_source().
352 */
353 public static boolean areCustomLoadersSupportedForCDS() {
354 return (is64bit() && (isLinux() || isSolaris() || isOSX()));
355 }
356 }
|
1 /*
2 * Copyright (c) 2013, 2020, 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 jdk.test.lib;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.RandomAccessFile;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.regex.Pattern;
32 import java.security.AccessController;
33 import java.security.PrivilegedAction;
34 import java.security.PrivilegedActionException;
35 import java.security.PrivilegedExceptionAction;
36
37 public class Platform {
38 public static final String vmName = privilegedGetProperty("java.vm.name");
39 public static final String vmInfo = privilegedGetProperty("java.vm.info");
40 private static final String osVersion = privilegedGetProperty("os.version");
41 private static int osVersionMajor = -1;
42 private static int osVersionMinor = -1;
43 private static final String osName = privilegedGetProperty("os.name");
44 private static final String dataModel = privilegedGetProperty("sun.arch.data.model");
45 private static final String vmVersion = privilegedGetProperty("java.vm.version");
46 private static final String jdkDebug = privilegedGetProperty("jdk.debug");
47 private static final String osArch = privilegedGetProperty("os.arch");
48 private static final String userName = privilegedGetProperty("user.name");
49 private static final String compiler = privilegedGetProperty("sun.management.compiler");
50 private static final String testJdk = privilegedGetProperty("test.jdk");
51
52 private static String privilegedGetProperty(String key) {
53 return AccessController.doPrivileged((
54 PrivilegedAction<String>) () -> System.getProperty(key));
55 }
56
57 public static boolean isClient() {
58 return vmName.endsWith(" Client VM");
59 }
60
61 public static boolean isServer() {
62 return vmName.endsWith(" Server VM");
63 }
64
65 public static boolean isZero() {
66 return vmName.endsWith(" Zero VM");
67 }
68
69 public static boolean isMinimal() {
70 return vmName.endsWith(" Minimal VM");
320 } else {
321 return "so";
322 }
323 }
324
325 /*
326 * Returns name of system variable containing paths to shared native libraries.
327 */
328 public static String sharedLibraryPathVariableName() {
329 if (isWindows()) {
330 return "PATH";
331 } else if (isOSX()) {
332 return "DYLD_LIBRARY_PATH";
333 } else if (isAix()) {
334 return "LIBPATH";
335 } else {
336 return "LD_LIBRARY_PATH";
337 }
338 }
339
340 /**
341 * Returns absolute path to directory containing JVM shared library.
342 */
343 public static Path jvmLibDir() {
344 Path dir = Paths.get(testJdk);
345 if (Platform.isWindows()) {
346 return dir.resolve("bin")
347 .resolve(variant())
348 .toAbsolutePath();
349 } else {
350 return dir.resolve("lib")
351 .resolve(variant())
352 .toAbsolutePath();
353 }
354 }
355
356 private static String variant() {
357 if (Platform.isServer()) {
358 return "server";
359 } else if (Platform.isClient()) {
360 return "client";
361 } else if (Platform.isMinimal()) {
362 return "minimal";
363 } else {
364 throw new Error("TESTBUG: unsupported vm variant");
365 }
366 }
367
368
369 public static boolean isDefaultCDSArchiveSupported() {
370 return (is64bit() &&
371 isServer() &&
372 (isLinux() ||
373 isOSX() ||
374 isSolaris() ||
375 isWindows()) &&
376 !isZero() &&
377 !isMinimal() &&
378 !isAArch64() &&
379 !isARM());
380 }
381
382 /*
383 * This should match the #if condition in ClassListParser::load_class_from_source().
384 */
385 public static boolean areCustomLoadersSupportedForCDS() {
386 return (is64bit() && (isLinux() || isSolaris() || isOSX()));
387 }
388 }
|