Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.bin

File GetMemory.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
27% of files have more coverage

Code metrics

2
7
1
1
72
24
3
0.43
7
1
3

Classes

Class Line # Actions
GetMemory 38 7 3
0.770%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.bin;
22   
23    import java.lang.management.ManagementFactory;
24    import java.lang.management.OperatingSystemMXBean;
25   
26    /**
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.
34    *
35    * @author bsoares
36    *
37    */
 
38    class GetMemory
39    {
40   
41    /**
42    * Wrapper for
43    * com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize()
44    *
45    * @return Result of
46    * com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize()
47    * or -1 if this class is not present in the JRE.
48    */
 
49  16 toggle protected static long getPhysicalMemory()
50    {
51  16 final OperatingSystemMXBean o = ManagementFactory
52    .getOperatingSystemMXBean();
53   
54  16 try
55    {
56  16 if (o instanceof com.sun.management.OperatingSystemMXBean)
57    {
58  16 final com.sun.management.OperatingSystemMXBean osb = (com.sun.management.OperatingSystemMXBean) o;
59  16 return osb.getTotalPhysicalMemorySize();
60    }
61    } catch (NoClassDefFoundError e)
62    {
63    // com.sun.management.OperatingSystemMXBean doesn't exist in this JVM
64  0 System.err.println(
65    "No com.sun.management.OperatingSystemMXBean: cannot get total physical memory size");
66    }
67   
68    // We didn't get a com.sun.management.OperatingSystemMXBean.
69  0 return -1;
70    }
71   
72    }