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;
27 * Isolated class to ascertain physical memory of the system using
28 * com.sun.management.OperatingSystemMXBean class's getTotalPhysicalMemorySize
29 * method. This class is present in OpenJDK 8,9,10,11,12,13. It is present but
30 * marked as deprecated in the early-access(30) release of OpenJDK 14. In case
31 * of an alternative/unsupported JRE being used or the class/method not being
32 * implemented in an exotic architecture JRE this call has been isolated into
33 * this separate class.
43 * com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize()
46 * com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize()
47 * or -1 if this class is not present in the JRE.
49 protected static long getPhysicalMemory()
51 final OperatingSystemMXBean o = ManagementFactory
52 .getOperatingSystemMXBean();
56 if (o instanceof com.sun.management.OperatingSystemMXBean)
58 final com.sun.management.OperatingSystemMXBean osb = (com.sun.management.OperatingSystemMXBean) o;
59 return osb.getTotalPhysicalMemorySize();
61 } catch (NoClassDefFoundError e)
63 // com.sun.management.OperatingSystemMXBean doesn't exist in this JVM
65 "No com.sun.management.OperatingSystemMXBean: cannot get total physical memory size");
68 // We didn't get a com.sun.management.OperatingSystemMXBean.