Class Utils

java.lang.Object
org.openjdk.jmh.util.Utils

public class Utils extends Object
  • Field Details

    • U

      private static final sun.misc.Unsafe U
  • Constructor Details

    • Utils

      private Utils()
  • Method Details

    • min

      public static <T extends Comparable<T>> T min(Collection<T> ts)
    • max

      public static <T extends Comparable<T>> T max(Collection<T> ts)
    • concat

      public static String[] concat(String[] t1, String[] t2)
    • join

      public static String join(Collection<String> src, String delim)
    • join

      public static String join(String[] src, String delim)
    • splitQuotedEscape

      public static Collection<String> splitQuotedEscape(String src)
    • sum

      public static int sum(int[] arr)
    • roundUp

      public static int roundUp(int v, int quant)
    • throwableToString

      public static String throwableToString(Throwable t)
    • unmarshalIntArray

      public static int[] unmarshalIntArray(String src)
    • marshalIntArray

      public static String marshalIntArray(int[] arr)
    • figureOutHotCPUs

      public static int figureOutHotCPUs()
      Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity. Some systems, notably embedded Linuxes, power down the idle CPUs and so availableProcessors() may report lower CPU count than would be present after the load-up.
      Returns:
      max CPU count
    • setAccessible

      private static void setAccessible(Object holder, AccessibleObject o) throws IllegalAccessException
      Throws:
      IllegalAccessException
    • guessConsoleEncoding

      public static Charset guessConsoleEncoding()
    • reflow

      public static void reflow(PrintWriter pw, String src, int width, int indent)
    • indent

      private static void indent(PrintWriter pw, int indent)
    • rewrap

      public static Collection<String> rewrap(String lines)
    • check

      public static void check(Class<?> klass, String... fieldNames)
    • check

      public static void check(Class<?> klass, String fieldName)
    • getOffset

      public static long getOffset(Class<?> klass, String fieldName)
    • isWindows

      public static boolean isWindows()
    • getCurrentJvm

      public static String getCurrentJvm()
    • getCurrentJvmVersion

      public static String getCurrentJvmVersion()
    • getCurrentOSVersion

      public static String getCurrentOSVersion()
    • getPid

      public static long getPid()
      Gets PID of the current JVM.
      Returns:
      PID.
    • getPid

      public static long getPid(Process process)
      Gets the PID of the target process.
      Parameters:
      process - to poll
      Returns:
      PID, or zero if no PID is found
    • tryWith

      public static Collection<String> tryWith(String... cmd)
    • runAsync

      public static Process runAsync(String... cmd)
    • runWith

      public static Collection<String> runWith(List<String> cmd)
    • getRecordedSystemProperties

      public static Properties getRecordedSystemProperties()
      We don't access the complete system properties via System.getProperties() because this would require read/write permissions to the properties. Just copy the properties we want to record in the result.
      Returns:
      Copy of system properties we want to record in the results.
    • readPropertiesFromCommand

      public static Properties readPropertiesFromCommand(List<String> cmd)
    • adaptForLoop

      public static <T> Iterable<T> adaptForLoop(Iterator<T> it)
      Adapts Iterator for Iterable. Can be iterated only once!
      Type Parameters:
      T - element type
      Parameters:
      it - iterator
      Returns:
      iterable for given iterator