core/src/main/java/com/orientechnologies/common/jna/ONative.java
private long getPhysicalMemorySize() {
    long osMemory = -1;

    try {
      final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
      final Object attribute = mBeanServer
          .getAttribute(new ObjectName("java.lang", "type", "OperatingSystem"), "TotalPhysicalMemorySize");

      if (attribute != null) {
        if (attribute instanceof Long) {
          osMemory = (Long) attribute;
        } else {
          try {
            osMemory = Long.parseLong(attribute.toString());
          } catch (final NumberFormatException e) {
            if (!OLogManager.instance().isDebugEnabled())
              OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.");
            else
              OLogManager.instance().debugNoDb(OMemory.class, "Unable to determine the amount of installed RAM.", e);
          }
        }
      } else {
        if (!OLogManager.instance().isDebugEnabled())
          OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.");
      }
    } catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
      if (!OLogManager.instance().isDebugEnabled())
        OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.");
      else
        OLogManager.instance().debugNoDb(OMemory.class, "Unable to determine the amount of installed RAM.", e);
    } catch (final RuntimeException e) {
      OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.", e);
    }

    return osMemory;
  }
private long getPhysicalMemorySize() {
    long osMemory = -1;

    try {
      final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
      final Object attribute = mBeanServer
          .getAttribute(new ObjectName("java.lang", "type", "OperatingSystem"), "TotalPhysicalMemorySize");

      if (attribute != null) {
        if (attribute instanceof Long) {
          osMemory = (Long) attribute;
        } else {
          try {
            osMemory = Long.parseLong(attribute.toString());
          } catch (final NumberFormatException e) {
            if (!OLogManager.instance().isDebugEnabled())
              OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.");
            else
              OLogManager.instance().debugNoDb(OMemory.class, "Unable to determine the amount of installed RAM.", e);
          }
        }
      } else {
        if (!OLogManager.instance().isDebugEnabled())
          OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.");
      }
    } catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
      if (!OLogManager.instance().isDebugEnabled())
        OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.");
      else
        OLogManager.instance().debugNoDb(OMemory.class, "Unable to determine the amount of installed RAM.", e);
    } catch (final RuntimeException e) {
      OLogManager.instance().warnNoDb(OMemory.class, "Unable to determine the amount of installed RAM.", e);
    }

    return osMemory;
  }
Obtains the total size in bytes of the installed physical memory on this machine. Note that on some VMs it's impossible to
obtain the physical memory size, in this case the return value will {@code -1}.

@return the total physical memory size in bytes or {@code <= 0} if the size can't be obtained.