File tree Expand file tree Collapse file tree 7 files changed +53
-12
lines changed
Expand file tree Collapse file tree 7 files changed +53
-12
lines changed Original file line number Diff line number Diff line change 99
1010b = java .lang .management .ManagementFactory .getOperatingSystemMXBean();
1111
12- L = b .getSystemCpuLoad(); % deprecated, but Matlab R2023b didn't have getCpuLoad() yet
12+ if stdlib .java_api() < 14
13+ L = b .getSystemCpuLoad();
14+ else
15+ L = b .getCpuLoad();
16+ end
17+
18+ % https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html#getSystemCpuLoad()
1319
1420end
Original file line number Diff line number Diff line change 3232 elseif Val(1 )==' '' ' % single-quoted string
3333 Val = strtok(Val , ' '' ' );
3434 else
35- Val = strtok(Val , ' ; ' ); % remove inline comment
36- Val = strtok(Val , ' # ' ); % remove inline comment
35+ Val = strtok(Val , " ; " ); % remove inline comment
36+ Val = strtok(Val , " # " ); % remove inline comment
3737 Val = strtrim(Val ); % remove spaces before comment
3838
39- [val , status ] = str2num( Val );
39+ [val , status ] = double(string( Val ) );
4040 if status , Val = val ; end % convert string to number(s)
4141 end
4242
Original file line number Diff line number Diff line change 1+ function api = java_api()
2+
3+ v = stdlib .java_version();
4+
5+ % major version is first number before "."
6+
7+ a = split(v , " ." );
8+ if a(1 ) == " 1"
9+ api = double(a(2 ));
10+ else
11+ api = double(a(1 ));
12+ end
13+
14+ end
Original file line number Diff line number Diff line change 22% get version of Java Virtual Machine
33 v = string(java .lang .System .getProperty(" java.version" ));
44
5+ % this gives a long string with more detail
6+ % version("-java")
7+
58% these give the Matlab version, not the JVM version.
69% java.lang.Runtime.version()
710% java.lang.Runtime.getRuntime().version
Original file line number Diff line number Diff line change 11function bytes = ram_total()
22%% ram_total()
33% get total physical RAM across operating systems
4- % https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html#getTotalMemorySize ()
4+ % https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html#getTotalPhysicalMemorySize ()
55%
66% %% Outputs
77% * bytes: total physical RAM [bytes]
88
9- import java .lang .management .ManagementFactory
10-
11- b = ManagementFactory .getOperatingSystemMXBean();
9+ b = java .lang .management .ManagementFactory .getOperatingSystemMXBean();
1210
13- bytes = b .getTotalPhysicalMemorySize(); % deprecated but Matlab R2023b doesn't have getPhysicalMemorySize() yet
11+ bytes = b .getTotalPhysicalMemorySize();
12+ % deprecated but Matlab doesn't have Java 14 getPhysicalMemorySize() yet
13+ % https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html#getTotalMemorySize()
1414
1515end
Original file line number Diff line number Diff line change 1212% r: logical
1313
1414arguments
15- in (1 ,1 ) string
16- ref (1 ,1 ) string
15+ in (1 ,1 ) string
16+ ref (1 ,1 ) string
1717end
1818
1919in = split(in , ' ' );
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ buildtool
1717
1818[ API Documentation] ( https://geospace-code.github.io/matlab-stdlib )
1919
20- ## Developer notes
20+ ## Java details
2121
2222The "matlab-stdlib" package uses Java functions throughout, with the higher-level
2323[ java.nio.Files] ( https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html )
@@ -28,6 +28,24 @@ That is, if Matlab was started with
2828[ -nojvm] ( https://www.mathworks.com/help/matlab/matlab_env/commonly-used-startup-options.html ) ,
2929many of the stdlib filesystem function do not work.
3030
31+ Get the JVM version with
32+
33+ ``` matlab
34+ version("-java")
35+ ```
36+
37+ The Matlab default
38+ [ JVM can be configured] ( https://www.mathworks.com/help/matlab/matlab_external/configure-your-system-to-use-java.html )
39+ to
40+ [ compatible JRE] ( https://www.mathworks.com/support/requirements/language-interfaces.html )
41+ across
42+ [ Matlab versions] ( https://www.mathworks.com/support/requirements/openjdk.html )
43+ by using the
44+ [ jenv] ( https://www.mathworks.com/help/matlab/ref/jenv.html )
45+ Matlab function.
46+
47+ Matlab-stdlib has been test with JVM from version 8 to 17.
48+
3149## Acknowledgements
3250
3351Stdlib for Matlab was partly funded by NASA NNH19ZDA001N-HDEE grant 80NSSC20K0176.
You can’t perform that action at this time.
0 commit comments