source: trunk/src/gcc/libjava/java/lang/Runtime.java@ 1389

Last change on this file since 1389 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.8 KB
Line 
1// Runtime.java - Runtime class.
2
3/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11package java.lang;
12
13import java.io.IOException;
14import java.io.InputStream;
15import java.io.OutputStream;
16import java.util.StringTokenizer;
17
18/**
19 * @author Tom Tromey <[email protected]>
20 * @date August 27, 1998
21 */
22
23/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
24 * "The Java Language Specification", ISBN 0-201-63451-1
25 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
26 * Status: All 1.1 methods exist. exec() is not fully implemented.
27 */
28
29public class Runtime
30{
31 public Process exec (String prog) throws IOException
32 {
33 return exec (prog, null);
34 }
35
36 public Process exec (String prog, String[] envp) throws IOException
37 {
38 StringTokenizer st = new StringTokenizer(prog);
39 String[] a = new String[st.countTokens ()];
40 for (int i = 0; i < a.length; i++)
41 a[i] = st.nextToken ();
42 return exec (a, envp);
43 }
44
45 public Process exec (String[] progarray) throws IOException
46 {
47 return exec (progarray, null);
48 }
49
50 public Process exec (String[] progarray, String[] envp) throws IOException
51 {
52 SecurityManager s = System.getSecurityManager();
53 if (s != null)
54 s.checkExec(progarray[0]);
55 return new ConcreteProcess (progarray, envp);
56 }
57
58 private final static void checkExit (int status)
59 {
60 SecurityManager s = System.getSecurityManager();
61 if (s != null)
62 s.checkExit(status);
63 }
64
65 public native void exit (int status);
66
67 // Shutdown the runtime without a SecurityManager check. libgcj uses this
68 // exit function internally.
69 final native void _exit (int status);
70
71 public native long freeMemory ();
72 public native void gc ();
73
74 // Deprecated in 1.1. We implement what the JCL book says.
75 public InputStream getLocalizedInputStream (InputStream in)
76 {
77 return in;
78 }
79
80 // Deprecated in 1.1. We implement what the JCL book says.
81 public OutputStream getLocalizedOutputStream (OutputStream out)
82 {
83 return out;
84 }
85
86 public static Runtime getRuntime ()
87 {
88 return self;
89 }
90
91 private final void checkLink (String lib)
92 {
93 if (lib == null)
94 throw new NullPointerException ();
95 SecurityManager s = System.getSecurityManager();
96 if (s != null)
97 s.checkLink(lib);
98 }
99
100 private native void _load (String pathname, boolean do_search);
101
102 public void load (String pathname)
103 {
104 _load (pathname, false);
105 }
106
107 public void loadLibrary (String libname)
108 {
109 _load (libname, true);
110 }
111
112 // This is a helper function for the ClassLoader which can load
113 // compiled libraries. Returns true if library (which is just the
114 // base name -- path searching is done by this function) was loaded,
115 // false otherwise.
116 native boolean loadLibraryInternal (String libname);
117
118 public native void runFinalization ();
119
120 // This method is static in JDK 1.1, but isn't listed as static in
121 // the books. It is marked as static in the 1.2 docs.
122 public static void runFinalizersOnExit (boolean run)
123 {
124 // The status we pass to the security check is unspecified.
125 checkExit (0);
126 self.finalize_on_exit = run;
127 }
128
129 public native long totalMemory ();
130 public native void traceInstructions (boolean on);
131 public native void traceMethodCalls (boolean on);
132
133 // A helper for the constructor.
134 private final native void init ();
135
136 // The sole constructor.
137 private Runtime ()
138 {
139 init ();
140 }
141
142 // Private data.
143 private static Runtime self = new Runtime ();
144 // FIXME: for now this can't be static. If it is, our compiler will
145 // mark it as local, and it will be inaccessible to natRuntime.cc.
146 private boolean finalize_on_exit;
147}
Note: See TracBrowser for help on using the repository browser.