Class JvmUtils


  • public class JvmUtils
    extends Object
    • Constructor Detail

      • JvmUtils

        public JvmUtils()
    • Method Detail

      • majorVersion

        public static int majorVersion()
        Returns the major version of the current Java runtime for Java 9 and above. For example: 9, 11, 17, etc. Returns 1 for Java 8 and earlier. Returns UNKNOWN_VERSION if the major version cannot be determined. This is a negative number and is therefore lower than all valid versions.
      • isIsJava9Compatible

        public static boolean isIsJava9Compatible()
      • getRuntimeInfo

        public static RuntimeInfo getRuntimeInfo()
      • isThreadCpuTimeEnabled

        public static boolean isThreadCpuTimeEnabled()
      • safeGetThreadCpuTime

        public static long safeGetThreadCpuTime()
      • getCurrentThreadCpuTime

        public static long getCurrentThreadCpuTime()
        Returns the total CPU time for current thread. This method should be called after verifying that cpu time measurement for current thread is supported by JVM
        Returns:
        total CPU time for the current thread in nanoseconds.
        Throws:
        UnsupportedOperationException - if the Java virtual machine does not support CPU time measurement for the current thread.
      • safeAccumulateThreadCpuTime

        public static <T> T safeAccumulateThreadCpuTime​(AtomicLong accumulator,
                                                        Supplier<T> function)
        Executes and returns the value of function. Also accumulates the CPU time taken for the function (as reported by getCurrentThreadCpuTime() into {@param accumulator}.
      • systemClassPath

        public static List<URL> systemClassPath()
      • resetTestsToDefaultRuntimeInfo

        public static void resetTestsToDefaultRuntimeInfo()
        Only for testing.