/[classpath]/classpath/vm/reference/java/lang/Runtime.java
ViewVC logotype

Diff of /classpath/vm/reference/java/lang/Runtime.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by mark, Tue Jan 22 22:27:03 2002 UTC revision 1.12 by ericb, Wed Feb 27 06:02:11 2002 UTC
# Line 1  Line 1 
1  /* java.lang.Runtime  /* Runtime.java -- access to the VM process
2     Copyright (C) 1998 Free Software Foundation     Copyright (C) 1998, 2002 Free Software Foundation
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 41  import java.util.*; Line 41  import java.util.*;
41  import java.io.*;  import java.io.*;
42    
43  /**  /**
44   ** Runtime represents the Virtual Machine.   * Runtime represents the Virtual Machine.
45   **   *
46   ** @author John Keiser   * @author John Keiser
47   ** @version 1.1.0, Aug 8 1998   * @author Eric Blake <ebb9@email.byu.edu>
48   **/   * @status still missing 1.4 functionality
49     */
50  public class Runtime {  public class Runtime
51          static Runtime current = new Runtime();  {
52          String[] libpath;    /**
53       * The one and only runtime instance.
54          /* Leave this private, and leave it in Runtime.     */
55           * It must be private to avoid security problems.    private static final Runtime current = new Runtime();
56           * See the note on getSecurityManager() to find  
57           * out why it needs to be in Runtime.    /**
58           */     * The library path, to search when loading libraries.
59          private static SecurityManager securityManager;     */
60      private String[] libpath;
61          private Runtime() {  
62                  String path = getLibraryPath();    /**
63                  if (path == null)     * The current security manager. This is located here instead of in
64                    {     * Runtime, to avoid security problems, as well as bootstrap issues.
65                      libpath = new String[0];     */
66                    }    private static SecurityManager securityManager;
67                  else  
68                    {    /**
69                  int numColons = 0;     * Not instantiable by a user, this should only create one instance.
70                  int pathLength = path.length();     */
71                  for(int i=0;i<pathLength;i++) {    private Runtime()
72                          if(path.charAt(i) == ':')    {
73                                  numColons++;      if (current != null)
74                  }        throw new InternalError("Attempt to recreate Runtime");
75        String path = getLibraryPath();
76                  libpath = new String[numColons+1];      if (path == null)
77                  int current = 0;        libpath = new String[0];
78                  int libpathIndex = 0;      else
79                  while(true) {        {
80                          int next = path.indexOf(File.pathSeparatorChar,current);          // XXX Use StringTokenizer to make this nicer.
81                          if(next == -1) {          int numColons = 0;
82                                  libpath[libpathIndex] = path.substring(current);          int pathLength = path.length();
83                                  break;          for (int i = 0; i < pathLength; i++)
84                          }            // XXX Use path.separator property.
85                          libpath[libpathIndex] = path.substring(current,next);            if (path.charAt(i) == ':')
86                          libpathIndex++;              numColons++;
87                          current = next+1;          libpath = new String[numColons + 1];
88                  }          int current = 0;
89                  }          int libpathIndex = 0;
90          }          while (true)
91              {
92          /** Get the current Runtime object for this JVM.              int next = path.indexOf(File.pathSeparatorChar, current);
93           ** @return the current Runtime object              if (next == -1)
94           **/                {
95          public static Runtime getRuntime() {                  libpath[libpathIndex] = path.substring(current);
96                  return current;                  break;
97          }                }
98                libpath[libpathIndex] = path.substring(current, next);
99          /** Exit the Java runtime. This method will either throw              libpathIndex++;
100           ** a SecurityException or it will never return.              current = next + 1;
101           ** @param status the status to exit with            }
102           ** @exception SecurityException if        }
103           **            System.getSecurityManager().checkExit(status)    }
104           **            fails.  
105           **/    /**
106          public void exit(int status) {     * Get the current Runtime object for this JVM. This is necessary to access
107                  SecurityManager sm = System.getSecurityManager();     * the many instance methods of this class.
108                  if (sm != null)     *
109                          sm.checkExit(status);     * @return the current Runtime object
110                  exitInternal(status);     */
111          }    public static Runtime getRuntime()
112      {
113          /**      return current;
114           ** Native method that actually shuts down the virtual machine    }
115           **/  
116          public native void exitInternal(int status);    /**
117       * Exit the Java runtime. This method will either throw a SecurityException
118          /** Run the garbage collector.     * or it will never return. The status code is returned to the system; often
119           ** This method is more of a suggestion than anything.     * a non-zero status code indicates an abnormal exit. Of course, there is a
120           ** All this method guarantees is that the garbage     * security check, <code>checkExit(status)</code>.
121           ** collector will have "done its best" by the time     *
122           ** it returns.     * <p>First, all shutdown hooks are run, in unspecified order, and possibly
123           **/     * concurrently. Next, if finalization on exit has been enabled, all pending
124          public native void gc();     * finalizers are run. Finally, the system calls <code>halt</code>.
125       *
126          /** Run finalization on all Objects that are waiting to be     * <p>If this is run a second time after shutdown has already started, there
127           ** finalized.  Again, a suggestion, though a stronger     * are two actions. If shutdown hooks are still executing, it blocks
128           ** one.     * indefinitely. Otherwise, if the status is nonzero it halts immediately;
129           **/     * if it is zero, it blocks indefinitely. This is typically called by
130          public native void runFinalization();     * <code>System.exit</code>.
131       *
132          /** Tell the VM to run the finalize() method on every     * @param status the status to exit with
133           ** single Object before it exits.  Note that the JVM may     * @throws SecurityException if permission is denied
134           ** still exit abnormally and not perform this, so you     * @see #addShutdownHook(Thread)
135           ** still don't have a guarantee.  This value defaults to     * @see #runFinalizersOnExit(boolean)
136           ** <CODE>false</CODE>.     * @see #runFinalization()
137           ** @param finalizeOnExit whether to finalize all Objects     * @see #halt(int)
138           **        before the JVM exits     */
139           **/    public void exit(int status)
140          public static void runFinalizersOnExit(boolean finalizeOnExit) {    {
141                  SecurityManager sm = System.getSecurityManager();      SecurityManager sm = securityManager; // Be thread-safe!
142                  if (sm != null)      if (sm != null)
143                          sm.checkExit(0);        sm.checkExit(status);
144                  runFinalizersOnExitInternal(finalizeOnExit);      //XXX Check if we are already finalizing.
145          }      //XXX Don't use exitInternal. Instead, run shutdown hooks, then call halt.
146        exitInternal(status);
147          /**    }
148           ** Native method that actually sets the finalizer setting.  
149           **/    /**
150          public static native void runFinalizersOnExitInternal(boolean value);     * Register a new shutdown hook. This is invoked when the program exits
151       * normally (because all non-daemon threads ended, or because
152          /** Load a native library using the system-dependent     * <code>System.exit</code> was invoked), or when the user terminates
153           ** filename.     * the virtual machine (such as by typing ^C, or logging off). There is
154           ** @exception SecurityException if     * a security check to add hooks,
155           **            System.getSecurityManager().checkLink(filename)     * <code>RuntimePermission("shutdownHooks")<code>.
156           **            fails.     *
157           ** @exception UnsatisfiedLinkError if the library is not     * <p>The hook must be an initialized, but unstarted Thread. The threads
158           **            found.     * are run concurrently, and started in an arbitrary order; and user
159           **/     * threads or daemons may still be running. Once shutdown hooks have
160          public void load(String filename) {     * started, they must all complete, or else you must use <code>halt</code>,
161                  SecurityManager sm = System.getSecurityManager();     * to actually finish the shutdown sequence. Attempts to modify hooks
162                  if(sm != null) {     * after shutdown has started result in IllegalStateExceptions.
163                          sm.checkLink(filename);     *
164                  }     * <p>It is imperative that you code shutdown hooks defensively, as you
165                  if(nativeLoad(filename) == 0) {     * do not want to deadlock, and have no idea what other hooks will be
166                          throw new UnsatisfiedLinkError("Could not load library " + filename + ".");     * running concurrently. It is also a good idea to finish quickly, as the
167                  }     * virtual machine really wants to shut down!
168          }     *
169       * <p>There are no guarantees that such hooks will run, as there are ways
170          /** Load a native library using a system-independent "short     * to forcibly kill a process. But in such a drastic case, shutdown hooks
171           ** name" for the library.  It will be transformed to a     * would do little for you in the first place.
172           ** correct filename in a system-dependent manner (for     *
173           ** example, in Windows, "mylib" will be turned into     * @param hook an initialized, unstarted Thread
174           ** "mylib.dll") and then passed to load(filename).     * @throws IllegalArgumentException if the hook is already registered or run
175           ** @exception SecurityException if     * @throws IllegalStateException if the virtual machine is already in
176           **            System.getSecurityManager().checkLink(filename)     *         the shutdown sequence
177           **            fails.     * @throws SecurityException if permission is denied
178           ** @exception UnsatisfiedLinkError if the library is not     * @since 1.3
179           **            found.     * @see #removeShutdownHook(Thread)
180           **/     * @see #exit(int)
181          public void loadLibrary(String libname) {     * @see #halt(int)
182                  for(int i=0;i<libpath.length;i++) {     * @XXX Add this method.
183                          try {    public void addShutdownHook(Thread hook)
184                                  String filename = nativeGetLibname(libpath[i],libname);    {
185                                  load(filename);      //XXX Implement me!
186                                  return;    }
187                          } catch(UnsatisfiedLinkError e) {     */
188                          }  
189                  }    /**
190                  throw new UnsatisfiedLinkError("Could not find library " + libname + ".");     * De-register a shutdown hook. As when you registered it, there is a
191          }     * security check to remove hooks,
192       * <code>RuntimePermission("shutdownHooks")<code>.
193          /** Create a new subprocess with the specified command     *
194           ** line.  Calls exec(cmdline, null).     * @param hook the hook to remove
195           ** @param cmdline the command to call     * @return true if the hook was successfully removed, false if it was not
196           ** @exception SecurityException if you cannot call this     *         registered in the first place
197           **            command     * @throws IllegalStateException if the virtual machine is already in
198           **/     *         the shutdown sequence
199          public Process exec(String cmdline) {     * @throws SecurityException if permission is denied
200                  return exec(cmdline,null);     * @since 1.3
201          }     * @see #addShutdownHook(Thread)
202       * @see #exit(int)
203          /** Create a new subprocess with the specified command     * @see #halt(int)
204           ** line and environment.  Parses the command line into     * @XXX Add this method.
205           ** pieces using StringTokenizer and then calls exec(cmd,env)    public boolean removeShutdownHook(Thread hook)
206           ** @param cmdline the command to call    {
207           ** @exception SecurityException if you cannot call this      // Implement me!
208           **            command      return false;
209           **/    }
210          public Process exec(String cmdline, String[] env) {     */
211                  StringTokenizer t = new StringTokenizer(cmdline);  
212                  Vector v = new Vector();    /**
213                  while(t.hasMoreTokens()) {     * Forcibly terminate the virtual machine. This call never returns. It is
214                          v.addElement(t.nextElement());     * much more severe than <code>exit</code>, as it bypasses all shutdown
215                  }     * hooks and initializers. Use caution in calling this! Of course, there is
216                  String[] cmd = new String[v.size()];     * a security check, <code>checkExit(status)</code>.
217                  v.copyInto(cmd);     *
218                  return exec(cmd, env);     * @param status the status to exit with
219          }     * @throws SecurityException if permission is denied
220       * @since 1.3
221          /** Create a new subprocess with the specified command     * @see #exit(int)
222           ** line.  Calls exec(cmd,null).     * @see #addShutdownHook(Thread)
223           ** @param cmd the command line, already separated     * XXX Add this method.
224           ** @exception SecurityException if you cannot call this    public void halt(int status)
225           **            command.    {
226           **/      SecurityManager sm = securityManager; // Be thread-safe!
227          public Process exec(String[] cmd) {      if (sm != null)
228                  return exec(cmd,null);        sm.checkExit(status);
229          }      exitInternal(status);
230      }
231          /** Create a new subprocess with the specified command     */
232           ** line.  Calls exec(cmd,null).  
233           ** @param cmd the command line, already separated    /**
234           ** @exception SecurityException if you cannot call this     * Native method that actually shuts down the virtual machine.
235           **            command (checks using     *
236           **            <CODE>System.getSecuritymanager().checkExec(cmd[0])</CODE>.     * @param status the status to end the process with
237           **/     */
238          public Process exec(String[] cmd, String[] env) {    native void exitInternal(int status);
239                  SecurityManager sm = System.getSecurityManager();  
240                  if (sm != null)    /**
241                    sm.checkExec(cmd[0]);     * Tell the VM to run the finalize() method on every single Object before
242                  return execInternal(cmd,env);     * it exits.  Note that the JVM may still exit abnormally and not perform
243          }     * this, so you still don't have a guarantee. And besides that, this is
244       * inherently unsafe in multi-threaded code, as it may result in deadlock
245          /** Find out how much memory is still free for allocating     * as multiple threads compete to manipulate objects. This value defaults to
246           ** Objects on the heap.     * <code>false</code>. There is a security check, <code>checkExit(0)</code>.
247           ** @return the amount of free memory for more Objects.     *
248           **/     * @param finalizeOnExit whether to finalize all Objects on exit
249          public native long freeMemory();     * @throws SecurityException if permission is denied
250       * @see #exit(int)
251          /** Find out how much memory total is available on the     * @see #gc()
252           ** heap for allocating Objects.     * @since 1.1
253           ** @return the total amount of memory for Objects.     * @deprecated never rely on finalizers to do a clean, thread-safe,
254           **/     *             mop-up from your code
255          public native long totalMemory();     */
256      public static void runFinalizersOnExit(boolean finalizeOnExit)
257          /** Tell the VM to trace every bytecode instruction that    {
258           ** executes (print out a trace of it).  No guarantees      SecurityManager sm = securityManager; // Be thread-safe!
259           ** are made as to where it will be printed, and the VM is      if (sm != null)
260           ** allowed to ignore this request.        sm.checkExit(0);
261           ** @param on whether to turn instruction tracing on      runFinalizersOnExitInternal(finalizeOnExit);
262           **/    }
263          public native void traceInstructions(boolean on);  
264      /**
265          /** Tell the VM to trace every method call that executes     * Create a new subprocess with the specified command line. Calls
266           ** (print out a trace of it).  No guarantees are made as     * <code>exec(cmdline, null, null)<code>. A security check is performed,
267           ** to where it will be printed, and the VM is allowed to     * <code>checkExec</code>.
268           ** ignore this request.     *
269           ** @param on whether to turn method tracing on     * @param cmdline the command to call
270           **/     * @return the Process object
271          public native void traceMethodCalls(boolean on);     * @throws SecurityException if permission is denied
272       * @throws IOException if an I/O error occurs
273          /** Return a localized version of this InputStream,     * @throws NullPointerException if cmdline is null
274           ** meaning all characters are localized before they come     * @throws IndexOutOfBoundsException if cmdline is ""
275           ** out the other end.     */
276           ** @XXX I must confess I have absolutely no idea how to    public Process exec(String cmdline) throws IOException
277           **      do this, and the thing is deprecated now anyway,    {
278           **      so I await Mr. Localization to work on it.      //XXX Use this:    return exec(cmdline, null, null);
279           **/      return exec(cmdline, null);
280          public InputStream getLocalizedInputStream(InputStream in) {    }
281                  return in;  
282          }    /**
283       * Create a new subprocess with the specified command line and environment.
284          /** Return a localized version of this InputStream,     * If the environment is null, the process inherits the environment of
285           ** meaning all characters are localized before they come     * this process. Calls <code>exec(cmdline, env, null)</code>. A security
286           ** out the other end.     * check is performed, <code>checkExec</code>.
287           ** @XXX I must confess I have absolutely no idea how to     *
288           **      do this, and the thing is deprecated now anyway,     * @param cmdline the command to call
289           **      so I await Mr. Localization to work on it.     * @param env the environment to use, in the format name=value
290           **/     * @return the Process object
291          public OutputStream getLocalizedOutputStream(OutputStream out) {     * @throws SecurityException if permission is denied
292                  return out;     * @throws IOException if an I/O error occurs
293          }     * @throws NullPointerException if cmdline is null, or env has null entries
294       * @throws IndexOutOfBoundsException if cmdline is ""
295          /* This was moved to Runtime so that Runtime would no     */
296           * longer trigger System's class initializer.  Runtime does    public Process exec(String cmdline, String[] env) throws IOException
297           * native library loading, and the System class initializer    {
298           * requires native libraries to have been loaded.      //XXX Use this:    return exec(cmdline, env, null);
299           */      StringTokenizer t = new StringTokenizer(cmdline);
300      static void setSecurityManager(SecurityManager securityManager) {      Vector v = new Vector();
301                  if(Runtime.securityManager != null) {      while (t.hasMoreTokens())
302                          throw new SecurityException("Security Manager already set");        v.addElement(t.nextElement());
303                  }      String[] cmd = new String[v.size()];
304                  Runtime.securityManager = securityManager;      v.copyInto(cmd);
305          }      return exec(cmd, env);
306      }
307          /* See setSecurityManager() for why this is in Runtime.  
308           */    /**
309          static SecurityManager getSecurityManager() {     * Create a new subprocess with the specified command line, environment, and
310                  return Runtime.securityManager;     * working directory. If the environment is null, the process inherits the
311          }     * environment of this process. If the directory is null, the process uses
312       * the current working directory. This splits cmdline into an array, using
313          native int nativeLoad(String filename);     * the default StringTokenizer, then calls
314          native String nativeGetLibname(String pathname, String libname);     * <code>exec(cmdArray, env, dir)</code>. A security check is performed,
315          native Process execInternal(String[] cmd, String[] env);     * <code>checkExec</code>.
316          static native String getLibraryPath();     *
317       * @param cmdline the command to call
318       * @param env the environment to use, in the format name=value
319       * @param dir the working directory to use
320       * @return the Process object
321       * @throws SecurityException if permission is denied
322       * @throws IOException if an I/O error occurs
323       * @throws NullPointerException if cmdline is null, or env has null entries
324       * @throws IndexOutOfBoundsException if cmdline is ""
325       * @since 1.3
326       * @XXX Add this method.
327      public Process exec(String cmdline, String[] env, File dir)
328        throws IOException
329      {
330        StringTokenizer t = new StringTokenizer(cmdline);
331        String[] cmd = new String[t.countTokens()];
332        for (int i = 0; i < cmd.length; i++)
333          cmd[i] = t.nextToken();
334        return exec(cmd, env, dir);
335      }
336       */
337    
338      /**
339       * Create a new subprocess with the specified command line, already
340       * tokenized. Calls <code>exec(cmd, null, null)</code>. A security check
341       * is performed, <code>checkExec</code>.
342       *
343       * @param cmd the command to call
344       * @return the Process object
345       * @throws SecurityException if permission is denied
346       * @throws IOException if an I/O error occurs
347       * @throws NullPointerException if cmd is null, or has null entries
348       * @throws IndexOutOfBoundsException if cmd is length 0
349       */
350      public Process exec(String[] cmd) throws IOException
351      {
352        //XXX Use this:    return exec(cmd, null, null);
353        return exec(cmd, null);
354      }
355    
356      /**
357       * Create a new subprocess with the specified command line, already
358       * tokenized, and specified environment. If the environment is null, the
359       * process inherits the environment of this process. Calls
360       * <code>exec(cmd, env, null)</code>. A security check is performed,
361       * <code>checkExec</code>.
362       *
363       * @param cmd the command to call
364       * @param env the environment to use, in the format name=value
365       * @return the Process object
366       * @throws SecurityException if permission is denied
367       * @throws IOException if an I/O error occurs
368       * @throws NullPointerException if cmd is null, or cmd or env has null
369       *         entries
370       * @throws IndexOutOfBoundsException if cmd is length 0
371       */
372      public Process exec(String[] cmd, String[] env) throws IOException
373      {
374        //XXX Use this:    return exec(cmd, env, null);
375        SecurityManager sm = securityManager; // Be thread-safe!
376        if (sm != null)
377          sm.checkExec(cmd[0]);
378        return execInternal(cmd, env);
379      }
380    
381      /**
382       * Create a new subprocess with the specified command line, already
383       * tokenized, and the specified environment and working directory. If the
384       * environment is null, the process inherits the environment of this
385       * process. If the directory is null, the process uses the current working
386       * directory. A security check is performed, <code>checkExec</code>.
387       *
388       * @param cmd the command to call
389       * @param env the environment to use, in the format name=value
390       * @param dir the working directory to use
391       * @return the Process object
392       * @throws SecurityException if permission is denied
393       * @throws IOException if an I/O error occurs
394       * @throws NullPointerException if cmd is null, or cmd or env has null
395       *         entries
396       * @throws IndexOutOfBoundsException if cmd is length 0
397       * @since 1.3
398       * @XXX Add this method.
399      public Process exec(String[] cmd, String[] env, File dir)
400        throws IOException
401      {
402        SecurityManager sm = securityManager; // Be thread-safe!
403        if (sm != null)
404          sm.checkExec(cmd[0]);
405        if (env == null)
406          env = new String[0];
407        return execInternal(cmd, env, dir);
408      }
409       */
410    
411      /**
412       * Returns the number of available processors currently available to the
413       * virtual machine. This number may change over time; so a multi-processor
414       * program want to poll this to determine maximal resource usage.
415       *
416       * @return the number of processors available, at least 1
417       * @XXX Add this method
418      public native int availableProcessors();
419       */
420    
421      /**
422       * Find out how much memory is still free for allocating Objects on the heap.
423       *
424       * @return the number of bytes of free memory for more Objects
425       */
426      public native long freeMemory();
427    
428      /**
429       * Find out how much memory total is available on the heap for allocating
430       * Objects.
431       *
432       * @return the total number of bytes of memory for Objects
433       */
434      public native long totalMemory();
435    
436      /**
437       * Returns the maximum amount of memory the virtual machine can attempt to
438       * use. This may be <code>Long.MAX_VALUE</code> if there is no inherent
439       * limit (or if you really do have a 8 exabyte memory!).
440       *
441       * @return the maximum number of bytes the virtual machine will attempt
442       *         to allocate
443       * @XXX Add this method.
444      public native long maxMemory();
445       */
446    
447      /**
448       * Run the garbage collector. This method is more of a suggestion than
449       * anything. All this method guarantees is that the garbage collector will
450       * have "done its best" by the time it returns. Notice that garbage
451       * collection takes place even without calling this method.
452       */
453      public native void gc();
454    
455      /**
456       * Run finalization on all Objects that are waiting to be finalized. Again,
457       * a suggestion, though a stronger one than {@link #gc()}. This calls the
458       * <code>finalize</code> method of all objects waiting to be collected.
459       *
460       * @see #finalize()
461       */
462      public native void runFinalization();
463    
464      /**
465       * Tell the VM to trace every bytecode instruction that executes (print out
466       * a trace of it).  No guarantees are made as to where it will be printed,
467       * and the VM is allowed to ignore this request.
468       *
469       * @param on whether to turn instruction tracing on
470       */
471      public native void traceInstructions(boolean on);
472    
473      /**
474       * Tell the VM to trace every method call that executes (print out a trace
475       * of it).  No guarantees are made as to where it will be printed, and the
476       * VM is allowed to ignore this request.
477       *
478       * @param on whether to turn method tracing on
479       */
480      public native void traceMethodCalls(boolean on);
481    
482      /**
483       * Load a native library using the system-dependent filename. This is similar
484       * to loadLibrary, except the only name mangling done is inserting "_g"
485       * before the final ".so" if the VM was invoked by the name "java_g". There
486       * may be a security check, of <code>checkLink</code>.
487       *
488       * @param filename the file to load
489       * @throws SecurityException if permission is denied
490       * @throws UnsatisfiedLinkError if the library is not found
491       */
492      public void load(String filename)
493      {
494        SecurityManager sm = securityManager; // Be thread-safe!
495        if (sm != null)
496          sm.checkLink(filename);
497        if (nativeLoad(filename) == 0)
498          throw new UnsatisfiedLinkError("Could not load library " + filename);
499      }
500    
501      /**
502       * Load a native library using a system-independent "short name" for the
503       * library.  It will be transformed to a correct filename in a
504       * system-dependent manner, via <code>System.mapLibraryName</code> (for
505       * example, in Windows, "mylib" will be turned into "mylib.dll"), and then
506       * passed to load(filename). There may be a security check, of
507       * <code>checkLink</code>.
508       *
509       * @param filename the file to load
510       * @throws SecurityException if permission is denied
511       * @throws UnsatisfiedLinkError if the library is not found
512       */
513      public void loadLibrary(String libname)
514      {
515        // XXX First, check ClassLoader.findLibrary(libname)
516        for (int i = 0; i < libpath.length; i++)
517          {
518            try
519              {
520                // XXX use this:
521                // load(libpath[i] + System.mapLibraryName(libname));
522                String filename = nativeGetLibname(libpath[i],libname);
523                load(filename);
524                return;
525              }
526            catch(UnsatisfiedLinkError e)
527              {
528                // Try next path element.
529              }
530          }
531        throw new UnsatisfiedLinkError("Could not find library " + libname + ".");
532      }
533    
534      /**
535       * Return a localized version of this InputStream, meaning all characters
536       * are localized before they come out the other end.
537       *
538       * @param in the stream to localize
539       * @return the localized stream
540       * @deprecated <code>InputStreamReader</code> is the preferred way to read
541       *             local encodings
542       * @XXX This implementation does not localize, yet.
543       */
544      public InputStream getLocalizedInputStream(InputStream in)
545      {
546        return in;
547      }
548    
549      /**
550       * Return a localized version of this OutputStream, meaning all characters
551       * are localized before they are sent to the other end.
552       *
553       * @param out the stream to localize
554       * @return the localized stream
555       * @deprecated <code>OutputStreamWriter</code> is the preferred way to write
556       *             local encodings
557       * @XXX This implementation does not localize, yet.
558       */
559      public OutputStream getLocalizedOutputStream(OutputStream out)
560      {
561        return out;
562      }
563    
564      /**
565       * Native method that actually sets the finalizer setting.
566       *
567       * @param value whether to run finalizers on exit
568       */
569      private static native void runFinalizersOnExitInternal(boolean value);
570    
571      /**
572       * This was moved to Runtime so that Runtime would no longer trigger
573       * System's class initializer.  Runtime does native library loading, and
574       * the System class initializer requires native libraries to have been
575       * loaded.
576       *
577       * @param manager the new security manager
578       * @throws SecurityException if permission is denied
579       */
580      static void setSecurityManager(SecurityManager manager)
581      {
582        // XXX Synchronize, for thread safety
583        if (securityManager != null)
584          // XXX Check RuntimePermission("setSecurityManager")
585          throw new SecurityException("Security Manager already set");
586        securityManager = manager;
587      }
588    
589      /**
590       * Get the security manager. This is here instead of system because of
591       * bootstrap issues.
592       *
593       * @return the security manager
594       */
595      static SecurityManager getSecurityManager()
596      {
597        return securityManager;
598      }
599    
600      /**
601       * Load a file. If it has already been loaded, do nothing. The name has
602       * already been mapped to a true filename.
603       *
604       * @param filename the file to load
605       * @return 0 on success, nonzero on failure
606       */
607      native int nativeLoad(String filename);
608    
609      /**
610       * Map a system-independent "short name" to the full file name, and append
611       * it to the path.
612       * XXX This method is being replaced by System.mapLibraryName.
613       *
614       * @param pathname the path
615       * @param libname the short version of the library name
616       * @return the full filename
617       */
618      native String nativeGetLibname(String pathname, String libname);
619    
620      /**
621       * Execute a process. The command line has already been tokenized, and
622       * the environment should contain name=value mappings. If directory is null,
623       * use the current working directory; otherwise start the process in that
624       * directory.
625       * XXX Add directory support.
626       *
627       * @param cmd the non-null command tokens
628       * @param env the non-null environment setup
629       * @param dir the directory to use, may be null
630       * @return the newly created process
631       */
632      //  native Process execInternal(String[] cmd, String[] env, File dir);
633      native Process execInternal(String[] cmd, String[] env);
634    
635      /**
636       * Get the library path.
637       *
638       * @return the library path
639       * XXX Use the java.library.path property
640       */
641      static native String getLibraryPath();
642  }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26