2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.lang.management.ManagementFactory;
24 import java.lang.management.OperatingSystemMXBean;
26 import jalview.util.ErrorLog;
29 * Isolated class to ascertain physical memory of the system using
30 * com.sun.management.OperatingSystemMXBean class's getTotalPhysicalMemorySize
31 * method. This class is present in OpenJDK 8,9,10,11,12,13. It is present but
32 * marked as deprecated in the early-access(30) release of OpenJDK 14. In case
33 * of an alternative/unsupported JRE being used or the class/method not being
34 * implemented in an exotic architecture JRE this call has been isolated into
35 * this separate class.
45 * com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize()
48 * com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize()
49 * or -1 if this class is not present in the JRE.
51 protected static long getPhysicalMemory()
53 final OperatingSystemMXBean o = ManagementFactory
54 .getOperatingSystemMXBean();
58 if (o instanceof com.sun.management.OperatingSystemMXBean)
60 final com.sun.management.OperatingSystemMXBean osb = (com.sun.management.OperatingSystemMXBean) o;
61 return osb.getTotalPhysicalMemorySize();
63 } catch (NoClassDefFoundError e)
65 // com.sun.management.OperatingSystemMXBean doesn't exist in this JVM
67 "No com.sun.management.OperatingSystemMXBean: cannot get total physical memory size");
70 // We didn't get a com.sun.management.OperatingSystemMXBean.