1 ## Copyright (C) 2010 Philip Nienhuis, <prnienhuis@users.sf.net>
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with Octave; see the file COPYING. If not, see
15 ## <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} javamem
19 ## @deftypefnx {Function File} [@var{jmem}] = javamem
20 ## Show current memory status of the Java virtual machine (JVM)
21 ## & run garbage collector.
23 ## When no return argument is given the info is echoed to the screen.
24 ## Otherwise, output cell array @var{jmem} contains Maximum, Total,
25 ## and Free memory (in bytes).
27 ## All Java-based routines are run in the JVM's shared memory pool,
28 ## a dedicated and separate part of memory claimed by the JVM from
29 ## your computer's total memory (which comprises physical RAM and
30 ## virtual memory / swap space on hard disk).
32 ## The maximum available memory can be set using the file java.opts
33 ## (in the same subdirectory where javaaddpath.m lives, see
34 ## "which javaaddpath". Usually that is: @*
35 ## [/usr]/share/octave/packages/java-<version>.
37 ## java.opts is a plain text file, one option per line. The
38 ## default initial memory size and default maximum memory size (which
39 ## are both system dependent) can be overridden like so: @*
42 ## (in megabytes in this example.)
43 ## You can adapt these values to your own requirements if your system
44 ## has limited available physical memory or when you get Java memory
47 ## "Total memory" is what the operating system has currently assigned
48 ## to the JVM and depends on actual and active memory usage.
49 ## "Free memory" is self-explanatory. During operation of Java-based
50 ## octave functions the amounts of Total and Free memory will vary,
51 ## due to Java's own cleaning up and your operating system's memory
56 ## Author: Philip Nienhuis
57 ## Created: 2010-03-25
59 ## 2010-03-26 Changed name to javamem & indentation to double spaces
60 ## 2010-08-25 Corrected text on java memory assignments
61 ## 2010-09-05 Further overhauled help text
63 function [ j_mem ] = javamem ()
65 rt = java_invoke ('java.lang.Runtime', 'getRuntime');
68 jmem{1} = rt.maxMemory ().doubleValue ();
69 jmem{2} = rt.totalMemory ().doubleValue ();
70 jmem{3} = rt.freeMemory ().doubleValue ();
73 printf ("\nJava virtual machine (JVM) memory info:\n");
74 printf ("Maximum available memory: %5d MiB;\n", jmem{1} / 1024 / 1024);
75 printf (" (...running garbage collector...)\n");
76 printf ("OK, current status:\n");
77 printf ("Total memory in virtual machine: %5d MiB;\n", jmem{2} / 1024 / 1024);
78 printf ("Free memory in virtual machine: %5d MiB;\n", jmem{3} / 1024 / 1024);
79 printf ("%d CPUs available.\n", rt.availableProcessors ());