You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2022/11/16 05:25:32 UTC

[GitHub] [hbase] Apache9 commented on a diff in pull request #4846: HBASE-27445 fix the result of DirectMemoryUtils#getDirectMemorySize

Apache9 commented on code in PR #4846:
URL: https://github.com/apache/hbase/pull/4846#discussion_r1023516500


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/util/DirectMemoryUtils.java:
##########
@@ -77,36 +76,16 @@ public class DirectMemoryUtils {
     HAS_MEMORY_USED_ATTRIBUTE = a != null;
   }
 
-  /**
-   * @return the setting of -XX:MaxDirectMemorySize as a long. Returns 0 if -XX:MaxDirectMemorySize
-   *         is not set.
-   */
+  /** Returns the direct memory limit of the current progress */
   public static long getDirectMemorySize() {
-    RuntimeMXBean runtimemxBean = ManagementFactory.getRuntimeMXBean();
-    List<String> arguments = runtimemxBean.getInputArguments();
-    long multiplier = 1; // for the byte case.
-    for (String s : arguments) {
-      if (s.contains("-XX:MaxDirectMemorySize=")) {
-        String memSize = s.toLowerCase(Locale.ROOT).replace("-xx:maxdirectmemorysize=", "").trim();
-
-        if (memSize.contains("k")) {
-          multiplier = 1024;
-        }
-
-        else if (memSize.contains("m")) {
-          multiplier = 1048576;
-        }
-
-        else if (memSize.contains("g")) {
-          multiplier = 1073741824;
-        }
-        memSize = memSize.replaceAll("[^\\d]", "");
-
-        long retValue = Long.parseLong(memSize);
-        return retValue * multiplier;
-      }
+    try {
+      Field directMemoryLimit = PlatformDependent.class.getDeclaredField("MAX_DIRECT_MEMORY");

Review Comment:
   PlatformDependent.maxDirectMemory is enough?
   
   https://github.com/netty/netty/blob/cf670fab75ad3c77d6b37883104b259894d4bd71/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L213



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org