1 /* Runtime.java -- access to the VM process
2 Copyright (C) 1998, 2002, 2003, 2004, 2005 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 * Runtime represents the Virtual Machine.
43 * @author Eric Blake (ebb9@email.byu.edu)
44 * @author Jeroen Frijters
46 // No idea why this class isn't final, since you can't build a subclass!
50 * The one and only runtime instance.
52 private static final Runtime current = new Runtime();
55 * Not instantiable by a user, this should only create one instance.
60 throw new InternalError("Attempt to recreate Runtime");
64 * Get the current Runtime object for this JVM. This is necessary to access
65 * the many instance methods of this class.
67 * @return the current Runtime object
69 public static Runtime getRuntime()
75 * Returns the number of available processors currently available to the
76 * virtual machine. This number may change over time; so a multi-processor
77 * program want to poll this to determine maximal resource usage.
79 * @return the number of processors available, at least 1
81 public native int availableProcessors();
84 * Find out how much memory is still free for allocating Objects on the heap.
86 * @return the number of bytes of free memory for more Objects
88 public native long freeMemory();
91 * Find out how much memory total is available on the heap for allocating
94 * @return the total number of bytes of memory for Objects
96 public native long totalMemory();
99 * Returns the maximum amount of memory the virtual machine can attempt to
100 * use. This may be <code>Long.MAX_VALUE</code> if there is no inherent
101 * limit (or if you really do have a 8 exabyte memory!).
103 * @return the maximum number of bytes the virtual machine will attempt
106 public native long maxMemory();