static long parseRightmostXmx(String javaOpts) {
    // Find the last matching -Xmx following word boundaries
    // Format: -Xmx<size>[g|G|m|M|k|K]
    Pattern JAVA_OPTS_XMX_PATTERN = Pattern.compile(".*(?:^|\\s)-Xmx(\\d+)([gGmMkK]?)(?:$|\\s).*");
    Matcher m = JAVA_OPTS_XMX_PATTERN.matcher(javaOpts);

    if (m.matches()) {
      long size = Long.parseLong(m.group(1));
      if (size <= 0) {
        return -1;
      }

      if (m.group(2).isEmpty()) {
        // -Xmx specified in bytes
        return size;
      }

      char unit = m.group(2).charAt(0);
      switch (unit) {
        case 'k':
        case 'K':
          // -Xmx specified in KB
          return size * 1024;
        case 'm':
        case 'M':
          // -Xmx specified in MB
          return size * 1024 * 1024;
        case 'g':
        case 'G':
          // -Xmx specified in GB
          return size * 1024 * 1024 * 1024;
      }
    }

    // -Xmx not specified
    return -1;
  }
Parse a Java opts string, try to find the rightmost -Xmx option value (since there may be more than one)
@param javaOpts Java opts string to parse
@return the rightmost -Xmx value in bytes. If Xmx is not set, return -1
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java