]> Creatis software - CreaPhase.git/blob - octave_packages/java-1.2.8/javamem.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / java-1.2.8 / javamem.m
1 ## Copyright (C) 2010 Philip Nienhuis, <prnienhuis@users.sf.net>
2 ## 
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.
7 ## 
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.
12 ## 
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/>.
16
17 ## -*- texinfo -*-
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.
22 ##
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).
26 ##
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).
31 ##
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>.
36 ##
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: @*
40 ## -Xms64m @*
41 ## -Xmx512m @*
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
45 ## errors.
46 ##
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
52 ## management.
53 ##
54 ## @end deftypefn
55
56 ## Author: Philip Nienhuis
57 ## Created: 2010-03-25
58 ## Updates: 
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
62
63 function [ j_mem ] = javamem ()
64
65   rt = java_invoke ('java.lang.Runtime', 'getRuntime');
66   rt.gc;
67   jmem = cell (3, 1);
68   jmem{1} = rt.maxMemory ().doubleValue ();
69   jmem{2} = rt.totalMemory ().doubleValue ();
70   jmem{3} = rt.freeMemory ().doubleValue ();
71
72   if (nargout < 1)
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 ());
80   else
81     j_mem = jmem;
82   endif
83
84 endfunction