1 |
14 |
jlechner |
/* VMRuntime.java -- VM interface to Runtime
|
2 |
|
|
Copyright (C) 2003 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 |
|
|
package java.lang;
|
39 |
|
|
|
40 |
|
|
import java.io.File;
|
41 |
|
|
import java.io.IOException;
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* VMRuntime represents the interface to the Virtual Machine.
|
45 |
|
|
*
|
46 |
|
|
* @author Jeroen Frijters
|
47 |
|
|
*/
|
48 |
|
|
final class VMRuntime
|
49 |
|
|
{
|
50 |
|
|
/**
|
51 |
|
|
* No instance is ever created.
|
52 |
|
|
*/
|
53 |
|
|
private VMRuntime()
|
54 |
|
|
{
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Returns the number of available processors currently available to the
|
59 |
|
|
* virtual machine. This number may change over time; so a multi-processor
|
60 |
|
|
* program want to poll this to determine maximal resource usage.
|
61 |
|
|
*
|
62 |
|
|
* @return the number of processors available, at least 1
|
63 |
|
|
*/
|
64 |
|
|
static native int availableProcessors();
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* Find out how much memory is still free for allocating Objects on the heap.
|
68 |
|
|
*
|
69 |
|
|
* @return the number of bytes of free memory for more Objects
|
70 |
|
|
*/
|
71 |
|
|
static native long freeMemory();
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Find out how much memory total is available on the heap for allocating
|
75 |
|
|
* Objects.
|
76 |
|
|
*
|
77 |
|
|
* @return the total number of bytes of memory for Objects
|
78 |
|
|
*/
|
79 |
|
|
static native long totalMemory();
|
80 |
|
|
|
81 |
|
|
/**
|
82 |
|
|
* Returns the maximum amount of memory the virtual machine can attempt to
|
83 |
|
|
* use. This may be <code>Long.MAX_VALUE</code> if there is no inherent
|
84 |
|
|
* limit (or if you really do have a 8 exabyte memory!).
|
85 |
|
|
*
|
86 |
|
|
* @return the maximum number of bytes the virtual machine will attempt
|
87 |
|
|
* to allocate
|
88 |
|
|
*/
|
89 |
|
|
static native long maxMemory();
|
90 |
|
|
|
91 |
|
|
/**
|
92 |
|
|
* Run the garbage collector. This method is more of a suggestion than
|
93 |
|
|
* anything. All this method guarantees is that the garbage collector will
|
94 |
|
|
* have "done its best" by the time it returns. Notice that garbage
|
95 |
|
|
* collection takes place even without calling this method.
|
96 |
|
|
*/
|
97 |
|
|
static native void gc();
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* Run finalization on all Objects that are waiting to be finalized. Again,
|
101 |
|
|
* a suggestion, though a stronger one than {@link #gc()}. This calls the
|
102 |
|
|
* <code>finalize</code> method of all objects waiting to be collected.
|
103 |
|
|
*
|
104 |
|
|
* @see #finalize()
|
105 |
|
|
*/
|
106 |
|
|
static native void runFinalization();
|
107 |
|
|
|
108 |
|
|
/**
|
109 |
|
|
* Run finalization on all finalizable Objects (even live ones). This
|
110 |
|
|
* should only be called immediately prior to VM termination.
|
111 |
|
|
*
|
112 |
|
|
* @see #finalize()
|
113 |
|
|
*/
|
114 |
|
|
static native void runFinalizationForExit();
|
115 |
|
|
|
116 |
|
|
/**
|
117 |
|
|
* Tell the VM to trace every bytecode instruction that executes (print out
|
118 |
|
|
* a trace of it). No guarantees are made as to where it will be printed,
|
119 |
|
|
* and the VM is allowed to ignore this request.
|
120 |
|
|
*
|
121 |
|
|
* @param on whether to turn instruction tracing on
|
122 |
|
|
*/
|
123 |
|
|
static native void traceInstructions(boolean on);
|
124 |
|
|
|
125 |
|
|
/**
|
126 |
|
|
* Tell the VM to trace every method call that executes (print out a trace
|
127 |
|
|
* of it). No guarantees are made as to where it will be printed, and the
|
128 |
|
|
* VM is allowed to ignore this request.
|
129 |
|
|
*
|
130 |
|
|
* @param on whether to turn method tracing on
|
131 |
|
|
*/
|
132 |
|
|
static native void traceMethodCalls(boolean on);
|
133 |
|
|
|
134 |
|
|
/**
|
135 |
|
|
* Native method that actually sets the finalizer setting.
|
136 |
|
|
*
|
137 |
|
|
* @param value whether to run finalizers on exit
|
138 |
|
|
*/
|
139 |
|
|
static native void runFinalizersOnExit(boolean value);
|
140 |
|
|
|
141 |
|
|
/**
|
142 |
|
|
* Native method that actually shuts down the virtual machine.
|
143 |
|
|
*
|
144 |
|
|
* @param status the status to end the process with
|
145 |
|
|
*/
|
146 |
|
|
static native void exit(int status);
|
147 |
|
|
|
148 |
|
|
/**
|
149 |
|
|
* Load a file. If it has already been loaded, do nothing. The name has
|
150 |
|
|
* already been mapped to a true filename.
|
151 |
|
|
*
|
152 |
|
|
* @param filename the file to load
|
153 |
|
|
* @param loader class loader, or <code>null</code> for the boot loader
|
154 |
|
|
* @return 0 on failure, nonzero on success
|
155 |
|
|
*/
|
156 |
|
|
static native int nativeLoad(String filename, ClassLoader loader);
|
157 |
|
|
|
158 |
|
|
/**
|
159 |
|
|
* Map a system-independent "short name" to the full file name.
|
160 |
|
|
*
|
161 |
|
|
* @param libname the short version of the library name
|
162 |
|
|
* @return the full filename
|
163 |
|
|
*/
|
164 |
|
|
static native String mapLibraryName(String libname);
|
165 |
|
|
|
166 |
|
|
/**
|
167 |
|
|
* Execute a process. The command line has already been tokenized, and
|
168 |
|
|
* the environment should contain name=value mappings. If directory is null,
|
169 |
|
|
* use the current working directory; otherwise start the process in that
|
170 |
|
|
* directory. If env is null, then the new process should inherit
|
171 |
|
|
* the environment of this process.
|
172 |
|
|
*
|
173 |
|
|
* @param cmd the non-null command tokens
|
174 |
|
|
* @param env the environment setup
|
175 |
|
|
* @param dir the directory to use, may be null
|
176 |
|
|
* @return the newly created process
|
177 |
|
|
* @throws NullPointerException if cmd or env have null elements
|
178 |
|
|
*/
|
179 |
|
|
static Process exec(String[] cmd, String[] env, File dir)
|
180 |
|
|
throws IOException {
|
181 |
|
|
return VMProcess.exec(cmd, env, dir);
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
/**
|
185 |
|
|
* This method is called by Runtime.addShutdownHook() when it is
|
186 |
|
|
* called for the first time. It enables the VM to lazily setup
|
187 |
|
|
* an exit handler, should it so desire.
|
188 |
|
|
*/
|
189 |
|
|
static void enableShutdownHooks()
|
190 |
|
|
{
|
191 |
|
|
}
|
192 |
|
|
} // class VMRuntime
|