Changes to MGC class library and some missing unit test files for inner class
[IRC.git] / Robust / src / ClassLibrary / MGC / gnu / Runtime.java
1 /* Runtime.java -- access to the VM process
2    Copyright (C) 1998, 2002, 2003, 2004, 2005 Free Software Foundation
3
4 This file is part of GNU Classpath.
5
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)
9 any later version.
10
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.
15
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
19 02110-1301 USA.
20
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
24 combination.
25
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. */
37
38
39 /**
40  * Runtime represents the Virtual Machine.
41  *
42  * @author John Keiser
43  * @author Eric Blake (ebb9@email.byu.edu)
44  * @author Jeroen Frijters
45  */
46 // No idea why this class isn't final, since you can't build a subclass!
47 public class Runtime
48 {
49   /**
50    * The one and only runtime instance.
51    */
52   private static final Runtime current = new Runtime();
53
54   /**
55    * Not instantiable by a user, this should only create one instance.
56    */
57   private Runtime()
58   {
59     if (current != null)
60       throw new InternalError("Attempt to recreate Runtime");
61   }
62
63   /**
64    * Get the current Runtime object for this JVM. This is necessary to access
65    * the many instance methods of this class.
66    *
67    * @return the current Runtime object
68    */
69   public static Runtime getRuntime()
70   {
71     return current;
72   }
73
74   /**
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.
78    *
79    * @return the number of processors available, at least 1
80    */
81   public native int availableProcessors();
82
83   /**
84    * Find out how much memory is still free for allocating Objects on the heap.
85    *
86    * @return the number of bytes of free memory for more Objects
87    */
88   public native long freeMemory();
89
90   /**
91    * Find out how much memory total is available on the heap for allocating
92    * Objects.
93    *
94    * @return the total number of bytes of memory for Objects
95    */
96   public native long totalMemory();
97
98   /**
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!).
102    *
103    * @return the maximum number of bytes the virtual machine will attempt
104    *         to allocate
105    */
106   public native long maxMemory();
107 } // class Runtime