~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/java/lang/System.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
4
 *
 
5
 * This code is free software; you can redistribute it and/or modify it
 
6
 * under the terms of the GNU General Public License version 2 only, as
 
7
 * published by the Free Software Foundation.  Oracle designates this
 
8
 * particular file as subject to the "Classpath" exception as provided
 
9
 * by Oracle in the LICENSE file that accompanied this code.
 
10
 *
 
11
 * This code is distributed in the hope that it will be useful, but WITHOUT
 
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
14
 * version 2 for more details (a copy is included in the LICENSE file that
 
15
 * accompanied this code).
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License version
 
18
 * 2 along with this work; if not, write to the Free Software Foundation,
 
19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
20
 *
 
21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 
22
 * or visit www.oracle.com if you need additional information or have any
 
23
 * questions.
 
24
 */
 
25
package java.lang;
 
26
 
 
27
import java.io.*;
 
28
import java.util.Properties;
 
29
import java.util.PropertyPermission;
 
30
import java.util.StringTokenizer;
 
31
import java.security.AccessController;
 
32
import java.security.PrivilegedAction;
 
33
import java.security.AllPermission;
 
34
import java.nio.channels.Channel;
 
35
import java.nio.channels.spi.SelectorProvider;
 
36
 
 
37
import sun.reflect.Reflection;
 
38
import sun.security.util.SecurityConstants;
 
39
 
 
40
final class StdIO
 
41
{
 
42
    private StdIO() { }
 
43
    static InputStream in = new BufferedInputStream(new FileInputStream(FileDescriptor.in));
 
44
    static PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out), 128), true);
 
45
    static PrintStream err = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err), 128), true);
 
46
}
 
47
 
 
48
final class Props
 
49
{
 
50
    private Props() { }
 
51
 
 
52
    static Properties props;
 
53
    static String lineSeparator;
 
54
    
 
55
    static
 
56
    {
 
57
        props = new Properties();
 
58
        VMSystemProperties.initProperties(props);
 
59
        lineSeparator = props.getProperty("line.separator");
 
60
 
 
61
        // after we've initialized the system properties, we need to fixate certain
 
62
        // results that depend on system properties, because we don't want Java code to
 
63
        // be able to change the behavior by setting these system properties.
 
64
        ClassLoader.initializeLibraryPaths(props);
 
65
        sun.misc.VM.saveAndRemoveProperties(props);
 
66
        
 
67
        // now that we've initialized the system properties (which are our only
 
68
        // notion of "booting" the VM) we set the booted flag.
 
69
        sun.misc.VM.booted();
 
70
    }
 
71
}
 
72
 
 
73
/**
 
74
 * The <code>System</code> class contains several useful class fields
 
75
 * and methods. It cannot be instantiated.
 
76
 *
 
77
 * <p>Among the facilities provided by the <code>System</code> class
 
78
 * are standard input, standard output, and error output streams;
 
79
 * access to externally defined properties and environment
 
80
 * variables; a means of loading files and libraries; and a utility
 
81
 * method for quickly copying a portion of an array.
 
82
 *
 
83
 * @author  unascribed
 
84
 * @since   JDK1.0
 
85
 */
 
86
public final class System {
 
87
 
 
88
    /** Don't let anyone instantiate this class */
 
89
    private System() {
 
90
    }
 
91
 
 
92
    /**
 
93
     * The "standard" input stream. This stream is already
 
94
     * open and ready to supply input data. Typically this stream
 
95
     * corresponds to keyboard input or another input source specified by
 
96
     * the host environment or user.
 
97
     */
 
98
    @ikvm.lang.Property(get="get_in")
 
99
    public final static InputStream in;
 
100
    
 
101
    static { in = null; }
 
102
    
 
103
    private static InputStream get_in()
 
104
    {
 
105
        return StdIO.in;
 
106
    }
 
107
 
 
108
    /**
 
109
     * The "standard" output stream. This stream is already
 
110
     * open and ready to accept output data. Typically this stream
 
111
     * corresponds to display output or another output destination
 
112
     * specified by the host environment or user.
 
113
     * <p>
 
114
     * For simple stand-alone Java applications, a typical way to write
 
115
     * a line of output data is:
 
116
     * <blockquote><pre>
 
117
     *     System.out.println(data)
 
118
     * </pre></blockquote>
 
119
     * <p>
 
120
     * See the <code>println</code> methods in class <code>PrintStream</code>.
 
121
     *
 
122
     * @see     java.io.PrintStream#println()
 
123
     * @see     java.io.PrintStream#println(boolean)
 
124
     * @see     java.io.PrintStream#println(char)
 
125
     * @see     java.io.PrintStream#println(char[])
 
126
     * @see     java.io.PrintStream#println(double)
 
127
     * @see     java.io.PrintStream#println(float)
 
128
     * @see     java.io.PrintStream#println(int)
 
129
     * @see     java.io.PrintStream#println(long)
 
130
     * @see     java.io.PrintStream#println(java.lang.Object)
 
131
     * @see     java.io.PrintStream#println(java.lang.String)
 
132
     */
 
133
    @ikvm.lang.Property(get="get_out")
 
134
    public final static PrintStream out;
 
135
    
 
136
    static { out = null; }
 
137
    
 
138
    private static PrintStream get_out()
 
139
    {
 
140
        return StdIO.out;
 
141
    }
 
142
 
 
143
    /**
 
144
     * The "standard" error output stream. This stream is already
 
145
     * open and ready to accept output data.
 
146
     * <p>
 
147
     * Typically this stream corresponds to display output or another
 
148
     * output destination specified by the host environment or user. By
 
149
     * convention, this output stream is used to display error messages
 
150
     * or other information that should come to the immediate attention
 
151
     * of a user even if the principal output stream, the value of the
 
152
     * variable <code>out</code>, has been redirected to a file or other
 
153
     * destination that is typically not continuously monitored.
 
154
     */
 
155
    @ikvm.lang.Property(get="get_err")
 
156
    public final static PrintStream err;
 
157
    
 
158
    static { err = null ; }
 
159
 
 
160
    private static PrintStream get_err()
 
161
    {
 
162
        return StdIO.err;
 
163
    }
 
164
 
 
165
    /* The security manager for the system.
 
166
     */
 
167
    private static volatile SecurityManager security;
 
168
 
 
169
    /**
 
170
     * Reassigns the "standard" input stream.
 
171
     *
 
172
     * <p>First, if there is a security manager, its <code>checkPermission</code>
 
173
     * method is called with a <code>RuntimePermission("setIO")</code> permission
 
174
     *  to see if it's ok to reassign the "standard" input stream.
 
175
     * <p>
 
176
     *
 
177
     * @param in the new standard input stream.
 
178
     *
 
179
     * @throws SecurityException
 
180
     *        if a security manager exists and its
 
181
     *        <code>checkPermission</code> method doesn't allow
 
182
     *        reassigning of the standard input stream.
 
183
     *
 
184
     * @see SecurityManager#checkPermission
 
185
     * @see java.lang.RuntimePermission
 
186
     *
 
187
     * @since   JDK1.1
 
188
     */
 
189
    public static void setIn(InputStream in) {
 
190
        checkIO();
 
191
        StdIO.in = in;
 
192
    }
 
193
 
 
194
    /**
 
195
     * Reassigns the "standard" output stream.
 
196
     *
 
197
     * <p>First, if there is a security manager, its <code>checkPermission</code>
 
198
     * method is called with a <code>RuntimePermission("setIO")</code> permission
 
199
     *  to see if it's ok to reassign the "standard" output stream.
 
200
     *
 
201
     * @param out the new standard output stream
 
202
     *
 
203
     * @throws SecurityException
 
204
     *        if a security manager exists and its
 
205
     *        <code>checkPermission</code> method doesn't allow
 
206
     *        reassigning of the standard output stream.
 
207
     *
 
208
     * @see SecurityManager#checkPermission
 
209
     * @see java.lang.RuntimePermission
 
210
     *
 
211
     * @since   JDK1.1
 
212
     */
 
213
    public static void setOut(PrintStream out) {
 
214
        checkIO();
 
215
        StdIO.out = out;
 
216
    }
 
217
 
 
218
    /**
 
219
     * Reassigns the "standard" error output stream.
 
220
     *
 
221
     * <p>First, if there is a security manager, its <code>checkPermission</code>
 
222
     * method is called with a <code>RuntimePermission("setIO")</code> permission
 
223
     *  to see if it's ok to reassign the "standard" error output stream.
 
224
     *
 
225
     * @param err the new standard error output stream.
 
226
     *
 
227
     * @throws SecurityException
 
228
     *        if a security manager exists and its
 
229
     *        <code>checkPermission</code> method doesn't allow
 
230
     *        reassigning of the standard error output stream.
 
231
     *
 
232
     * @see SecurityManager#checkPermission
 
233
     * @see java.lang.RuntimePermission
 
234
     *
 
235
     * @since   JDK1.1
 
236
     */
 
237
    public static void setErr(PrintStream err) {
 
238
        checkIO();
 
239
        StdIO.err = err;
 
240
    }
 
241
 
 
242
    private static volatile Console cons;
 
243
    /**
 
244
     * Returns the unique {@link java.io.Console Console} object associated
 
245
     * with the current Java virtual machine, if any.
 
246
     *
 
247
     * @return  The system console, if any, otherwise <tt>null</tt>.
 
248
     *
 
249
     * @since   1.6
 
250
     */
 
251
     public static Console console() {
 
252
         if (cons == null) {
 
253
             synchronized (System.class) {
 
254
                 cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
 
255
             }
 
256
         }
 
257
         return cons;
 
258
     }
 
259
 
 
260
    /**
 
261
     * Returns the channel inherited from the entity that created this
 
262
     * Java virtual machine.
 
263
     *
 
264
     * <p> This method returns the channel obtained by invoking the
 
265
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
 
266
     * inheritedChannel} method of the system-wide default
 
267
     * {@link java.nio.channels.spi.SelectorProvider} object. </p>
 
268
     *
 
269
     * <p> In addition to the network-oriented channels described in
 
270
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
 
271
     * inheritedChannel}, this method may return other kinds of
 
272
     * channels in the future.
 
273
     *
 
274
     * @return  The inherited channel, if any, otherwise <tt>null</tt>.
 
275
     *
 
276
     * @throws  IOException
 
277
     *          If an I/O error occurs
 
278
     *
 
279
     * @throws  SecurityException
 
280
     *          If a security manager is present and it does not
 
281
     *          permit access to the channel.
 
282
     *
 
283
     * @since 1.5
 
284
     */
 
285
    public static Channel inheritedChannel() throws IOException {
 
286
        return SelectorProvider.provider().inheritedChannel();
 
287
    }
 
288
 
 
289
    private static void checkIO() {
 
290
        SecurityManager sm = getSecurityManager();
 
291
        if (sm != null) {
 
292
            sm.checkPermission(new RuntimePermission("setIO"));
 
293
        }
 
294
    }
 
295
 
 
296
    /**
 
297
     * Sets the System security.
 
298
     *
 
299
     * <p> If there is a security manager already installed, this method first
 
300
     * calls the security manager's <code>checkPermission</code> method
 
301
     * with a <code>RuntimePermission("setSecurityManager")</code>
 
302
     * permission to ensure it's ok to replace the existing
 
303
     * security manager.
 
304
     * This may result in throwing a <code>SecurityException</code>.
 
305
     *
 
306
     * <p> Otherwise, the argument is established as the current
 
307
     * security manager. If the argument is <code>null</code> and no
 
308
     * security manager has been established, then no action is taken and
 
309
     * the method simply returns.
 
310
     *
 
311
     * @param      s   the security manager.
 
312
     * @exception  SecurityException  if the security manager has already
 
313
     *             been set and its <code>checkPermission</code> method
 
314
     *             doesn't allow it to be replaced.
 
315
     * @see #getSecurityManager
 
316
     * @see SecurityManager#checkPermission
 
317
     * @see java.lang.RuntimePermission
 
318
     */
 
319
    public static
 
320
    void setSecurityManager(final SecurityManager s) {
 
321
        try {
 
322
            s.checkPackageAccess("java.lang");
 
323
        } catch (Exception e) {
 
324
            // no-op
 
325
        }
 
326
        setSecurityManager0(s);
 
327
    }
 
328
 
 
329
    private static synchronized
 
330
    void setSecurityManager0(final SecurityManager s) {
 
331
        // [IKVM] force sun.misc.Launcher to initialize, because it assumes that it runs without a SecurityManager
 
332
        sun.misc.Launcher.getLauncher();
 
333
 
 
334
        SecurityManager sm = getSecurityManager();
 
335
        if (sm != null) {
 
336
            // ask the currently installed security manager if we
 
337
            // can replace it.
 
338
            sm.checkPermission(new RuntimePermission
 
339
                                     ("setSecurityManager"));
 
340
        }
 
341
 
 
342
        if ((s != null) && (s.getClass().getClassLoader() != null)) {
 
343
            // New security manager class is not on bootstrap classpath.
 
344
            // Cause policy to get initialized before we install the new
 
345
            // security manager, in order to prevent infinite loops when
 
346
            // trying to initialize the policy (which usually involves
 
347
            // accessing some security and/or system properties, which in turn
 
348
            // calls the installed security manager's checkPermission method
 
349
            // which will loop infinitely if there is a non-system class
 
350
            // (in this case: the new security manager class) on the stack).
 
351
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
 
352
                public Object run() {
 
353
                    s.getClass().getProtectionDomain().implies
 
354
                        (SecurityConstants.ALL_PERMISSION);
 
355
                    return null;
 
356
                }
 
357
            });
 
358
        }
 
359
 
 
360
        security = s;
 
361
    }
 
362
 
 
363
    /**
 
364
     * Gets the system security interface.
 
365
     *
 
366
     * @return  if a security manager has already been established for the
 
367
     *          current application, then that security manager is returned;
 
368
     *          otherwise, <code>null</code> is returned.
 
369
     * @see     #setSecurityManager
 
370
     */
 
371
    public static SecurityManager getSecurityManager() {
 
372
        return security;
 
373
    }
 
374
 
 
375
    /**
 
376
     * Returns the current time in milliseconds.  Note that
 
377
     * while the unit of time of the return value is a millisecond,
 
378
     * the granularity of the value depends on the underlying
 
379
     * operating system and may be larger.  For example, many
 
380
     * operating systems measure time in units of tens of
 
381
     * milliseconds.
 
382
     *
 
383
     * <p> See the description of the class <code>Date</code> for
 
384
     * a discussion of slight discrepancies that may arise between
 
385
     * "computer time" and coordinated universal time (UTC).
 
386
     *
 
387
     * @return  the difference, measured in milliseconds, between
 
388
     *          the current time and midnight, January 1, 1970 UTC.
 
389
     * @see     java.util.Date
 
390
     */
 
391
    public static long currentTimeMillis() {
 
392
        long january_1st_1970 = 62135596800000L;
 
393
        return cli.System.DateTime.get_UtcNow().get_Ticks() / 10000L - january_1st_1970;
 
394
    }
 
395
 
 
396
    /**
 
397
     * Returns the current value of the running Java Virtual Machine's
 
398
     * high-resolution time source, in nanoseconds.
 
399
     *
 
400
     * <p>This method can only be used to measure elapsed time and is
 
401
     * not related to any other notion of system or wall-clock time.
 
402
     * The value returned represents nanoseconds since some fixed but
 
403
     * arbitrary <i>origin</i> time (perhaps in the future, so values
 
404
     * may be negative).  The same origin is used by all invocations of
 
405
     * this method in an instance of a Java virtual machine; other
 
406
     * virtual machine instances are likely to use a different origin.
 
407
     *
 
408
     * <p>This method provides nanosecond precision, but not necessarily
 
409
     * nanosecond resolution (that is, how frequently the value changes)
 
410
     * - no guarantees are made except that the resolution is at least as
 
411
     * good as that of {@link #currentTimeMillis()}.
 
412
     *
 
413
     * <p>Differences in successive calls that span greater than
 
414
     * approximately 292 years (2<sup>63</sup> nanoseconds) will not
 
415
     * correctly compute elapsed time due to numerical overflow.
 
416
     *
 
417
     * <p>The values returned by this method become meaningful only when
 
418
     * the difference between two such values, obtained within the same
 
419
     * instance of a Java virtual machine, is computed.
 
420
     *
 
421
     * <p> For example, to measure how long some code takes to execute:
 
422
     *  <pre> {@code
 
423
     * long startTime = System.nanoTime();
 
424
     * // ... the code being measured ...
 
425
     * long estimatedTime = System.nanoTime() - startTime;}</pre>
 
426
     *
 
427
     * <p>To compare two nanoTime values
 
428
     *  <pre> {@code
 
429
     * long t0 = System.nanoTime();
 
430
     * ...
 
431
     * long t1 = System.nanoTime();}</pre>
 
432
     *
 
433
     * one should use {@code t1 - t0 < 0}, not {@code t1 < t0},
 
434
     * because of the possibility of numerical overflow.
 
435
     *
 
436
     * @return the current value of the running Java Virtual Machine's
 
437
     *         high-resolution time source, in nanoseconds
 
438
     * @since 1.5
 
439
     */
 
440
    public static long nanoTime() {
 
441
        long NANOS_PER_SEC = 1000000000;
 
442
        double current = cli.System.Diagnostics.Stopwatch.GetTimestamp();
 
443
        double freq = cli.System.Diagnostics.Stopwatch.Frequency;
 
444
        return (long)((current / freq) * NANOS_PER_SEC);
 
445
    }
 
446
 
 
447
    /**
 
448
     * Copies an array from the specified source array, beginning at the
 
449
     * specified position, to the specified position of the destination array.
 
450
     * A subsequence of array components are copied from the source
 
451
     * array referenced by <code>src</code> to the destination array
 
452
     * referenced by <code>dest</code>. The number of components copied is
 
453
     * equal to the <code>length</code> argument. The components at
 
454
     * positions <code>srcPos</code> through
 
455
     * <code>srcPos+length-1</code> in the source array are copied into
 
456
     * positions <code>destPos</code> through
 
457
     * <code>destPos+length-1</code>, respectively, of the destination
 
458
     * array.
 
459
     * <p>
 
460
     * If the <code>src</code> and <code>dest</code> arguments refer to the
 
461
     * same array object, then the copying is performed as if the
 
462
     * components at positions <code>srcPos</code> through
 
463
     * <code>srcPos+length-1</code> were first copied to a temporary
 
464
     * array with <code>length</code> components and then the contents of
 
465
     * the temporary array were copied into positions
 
466
     * <code>destPos</code> through <code>destPos+length-1</code> of the
 
467
     * destination array.
 
468
     * <p>
 
469
     * If <code>dest</code> is <code>null</code>, then a
 
470
     * <code>NullPointerException</code> is thrown.
 
471
     * <p>
 
472
     * If <code>src</code> is <code>null</code>, then a
 
473
     * <code>NullPointerException</code> is thrown and the destination
 
474
     * array is not modified.
 
475
     * <p>
 
476
     * Otherwise, if any of the following is true, an
 
477
     * <code>ArrayStoreException</code> is thrown and the destination is
 
478
     * not modified:
 
479
     * <ul>
 
480
     * <li>The <code>src</code> argument refers to an object that is not an
 
481
     *     array.
 
482
     * <li>The <code>dest</code> argument refers to an object that is not an
 
483
     *     array.
 
484
     * <li>The <code>src</code> argument and <code>dest</code> argument refer
 
485
     *     to arrays whose component types are different primitive types.
 
486
     * <li>The <code>src</code> argument refers to an array with a primitive
 
487
     *    component type and the <code>dest</code> argument refers to an array
 
488
     *     with a reference component type.
 
489
     * <li>The <code>src</code> argument refers to an array with a reference
 
490
     *    component type and the <code>dest</code> argument refers to an array
 
491
     *     with a primitive component type.
 
492
     * </ul>
 
493
     * <p>
 
494
     * Otherwise, if any of the following is true, an
 
495
     * <code>IndexOutOfBoundsException</code> is
 
496
     * thrown and the destination is not modified:
 
497
     * <ul>
 
498
     * <li>The <code>srcPos</code> argument is negative.
 
499
     * <li>The <code>destPos</code> argument is negative.
 
500
     * <li>The <code>length</code> argument is negative.
 
501
     * <li><code>srcPos+length</code> is greater than
 
502
     *     <code>src.length</code>, the length of the source array.
 
503
     * <li><code>destPos+length</code> is greater than
 
504
     *     <code>dest.length</code>, the length of the destination array.
 
505
     * </ul>
 
506
     * <p>
 
507
     * Otherwise, if any actual component of the source array from
 
508
     * position <code>srcPos</code> through
 
509
     * <code>srcPos+length-1</code> cannot be converted to the component
 
510
     * type of the destination array by assignment conversion, an
 
511
     * <code>ArrayStoreException</code> is thrown. In this case, let
 
512
     * <b><i>k</i></b> be the smallest nonnegative integer less than
 
513
     * length such that <code>src[srcPos+</code><i>k</i><code>]</code>
 
514
     * cannot be converted to the component type of the destination
 
515
     * array; when the exception is thrown, source array components from
 
516
     * positions <code>srcPos</code> through
 
517
     * <code>srcPos+</code><i>k</i><code>-1</code>
 
518
     * will already have been copied to destination array positions
 
519
     * <code>destPos</code> through
 
520
     * <code>destPos+</code><i>k</I><code>-1</code> and no other
 
521
     * positions of the destination array will have been modified.
 
522
     * (Because of the restrictions already itemized, this
 
523
     * paragraph effectively applies only to the situation where both
 
524
     * arrays have component types that are reference types.)
 
525
     *
 
526
     * @param      src      the source array.
 
527
     * @param      srcPos   starting position in the source array.
 
528
     * @param      dest     the destination array.
 
529
     * @param      destPos  starting position in the destination data.
 
530
     * @param      length   the number of array elements to be copied.
 
531
     * @exception  IndexOutOfBoundsException  if copying would cause
 
532
     *               access of data outside array bounds.
 
533
     * @exception  ArrayStoreException  if an element in the <code>src</code>
 
534
     *               array could not be stored into the <code>dest</code> array
 
535
     *               because of a type mismatch.
 
536
     * @exception  NullPointerException if either <code>src</code> or
 
537
     *               <code>dest</code> is <code>null</code>.
 
538
     */
 
539
    public static native void arraycopy(Object src,  int  srcPos,
 
540
                                        Object dest, int destPos,
 
541
                                        int length);
 
542
 
 
543
    /**
 
544
     * Returns the same hash code for the given object as
 
545
     * would be returned by the default method hashCode(),
 
546
     * whether or not the given object's class overrides
 
547
     * hashCode().
 
548
     * The hash code for the null reference is zero.
 
549
     *
 
550
     * @param x object for which the hashCode is to be calculated
 
551
     * @return  the hashCode
 
552
     * @since   JDK1.1
 
553
     */
 
554
    public static int identityHashCode(Object x) {
 
555
        return cli.System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(x);
 
556
    }
 
557
 
 
558
    /**
 
559
     * System properties. The following properties are guaranteed to be defined:
 
560
     * <dl>
 
561
     * <dt>java.version         <dd>Java version number
 
562
     * <dt>java.vendor          <dd>Java vendor specific string
 
563
     * <dt>java.vendor.url      <dd>Java vendor URL
 
564
     * <dt>java.home            <dd>Java installation directory
 
565
     * <dt>java.class.version   <dd>Java class version number
 
566
     * <dt>java.class.path      <dd>Java classpath
 
567
     * <dt>os.name              <dd>Operating System Name
 
568
     * <dt>os.arch              <dd>Operating System Architecture
 
569
     * <dt>os.version           <dd>Operating System Version
 
570
     * <dt>file.separator       <dd>File separator ("/" on Unix)
 
571
     * <dt>path.separator       <dd>Path separator (":" on Unix)
 
572
     * <dt>line.separator       <dd>Line separator ("\n" on Unix)
 
573
     * <dt>user.name            <dd>User account name
 
574
     * <dt>user.home            <dd>User home directory
 
575
     * <dt>user.dir             <dd>User's current working directory
 
576
     * </dl>
 
577
     */
 
578
 
 
579
    //private static native Properties initProperties(Properties props);
 
580
 
 
581
    /**
 
582
     * Determines the current system properties.
 
583
     * <p>
 
584
     * First, if there is a security manager, its
 
585
     * <code>checkPropertiesAccess</code> method is called with no
 
586
     * arguments. This may result in a security exception.
 
587
     * <p>
 
588
     * The current set of system properties for use by the
 
589
     * {@link #getProperty(String)} method is returned as a
 
590
     * <code>Properties</code> object. If there is no current set of
 
591
     * system properties, a set of system properties is first created and
 
592
     * initialized. This set of system properties always includes values
 
593
     * for the following keys:
 
594
     * <table summary="Shows property keys and associated values">
 
595
     * <tr><th>Key</th>
 
596
     *     <th>Description of Associated Value</th></tr>
 
597
     * <tr><td><code>java.version</code></td>
 
598
     *     <td>Java Runtime Environment version</td></tr>
 
599
     * <tr><td><code>java.vendor</code></td>
 
600
     *     <td>Java Runtime Environment vendor</td></tr
 
601
     * <tr><td><code>java.vendor.url</code></td>
 
602
     *     <td>Java vendor URL</td></tr>
 
603
     * <tr><td><code>java.home</code></td>
 
604
     *     <td>Java installation directory</td></tr>
 
605
     * <tr><td><code>java.vm.specification.version</code></td>
 
606
     *     <td>Java Virtual Machine specification version</td></tr>
 
607
     * <tr><td><code>java.vm.specification.vendor</code></td>
 
608
     *     <td>Java Virtual Machine specification vendor</td></tr>
 
609
     * <tr><td><code>java.vm.specification.name</code></td>
 
610
     *     <td>Java Virtual Machine specification name</td></tr>
 
611
     * <tr><td><code>java.vm.version</code></td>
 
612
     *     <td>Java Virtual Machine implementation version</td></tr>
 
613
     * <tr><td><code>java.vm.vendor</code></td>
 
614
     *     <td>Java Virtual Machine implementation vendor</td></tr>
 
615
     * <tr><td><code>java.vm.name</code></td>
 
616
     *     <td>Java Virtual Machine implementation name</td></tr>
 
617
     * <tr><td><code>java.specification.version</code></td>
 
618
     *     <td>Java Runtime Environment specification  version</td></tr>
 
619
     * <tr><td><code>java.specification.vendor</code></td>
 
620
     *     <td>Java Runtime Environment specification  vendor</td></tr>
 
621
     * <tr><td><code>java.specification.name</code></td>
 
622
     *     <td>Java Runtime Environment specification  name</td></tr>
 
623
     * <tr><td><code>java.class.version</code></td>
 
624
     *     <td>Java class format version number</td></tr>
 
625
     * <tr><td><code>java.class.path</code></td>
 
626
     *     <td>Java class path</td></tr>
 
627
     * <tr><td><code>java.library.path</code></td>
 
628
     *     <td>List of paths to search when loading libraries</td></tr>
 
629
     * <tr><td><code>java.io.tmpdir</code></td>
 
630
     *     <td>Default temp file path</td></tr>
 
631
     * <tr><td><code>java.compiler</code></td>
 
632
     *     <td>Name of JIT compiler to use</td></tr>
 
633
     * <tr><td><code>java.ext.dirs</code></td>
 
634
     *     <td>Path of extension directory or directories</td></tr>
 
635
     * <tr><td><code>os.name</code></td>
 
636
     *     <td>Operating system name</td></tr>
 
637
     * <tr><td><code>os.arch</code></td>
 
638
     *     <td>Operating system architecture</td></tr>
 
639
     * <tr><td><code>os.version</code></td>
 
640
     *     <td>Operating system version</td></tr>
 
641
     * <tr><td><code>file.separator</code></td>
 
642
     *     <td>File separator ("/" on UNIX)</td></tr>
 
643
     * <tr><td><code>path.separator</code></td>
 
644
     *     <td>Path separator (":" on UNIX)</td></tr>
 
645
     * <tr><td><code>line.separator</code></td>
 
646
     *     <td>Line separator ("\n" on UNIX)</td></tr>
 
647
     * <tr><td><code>user.name</code></td>
 
648
     *     <td>User's account name</td></tr>
 
649
     * <tr><td><code>user.home</code></td>
 
650
     *     <td>User's home directory</td></tr>
 
651
     * <tr><td><code>user.dir</code></td>
 
652
     *     <td>User's current working directory</td></tr>
 
653
     * </table>
 
654
     * <p>
 
655
     * Multiple paths in a system property value are separated by the path
 
656
     * separator character of the platform.
 
657
     * <p>
 
658
     * Note that even if the security manager does not permit the
 
659
     * <code>getProperties</code> operation, it may choose to permit the
 
660
     * {@link #getProperty(String)} operation.
 
661
     *
 
662
     * @return     the system properties
 
663
     * @exception  SecurityException  if a security manager exists and its
 
664
     *             <code>checkPropertiesAccess</code> method doesn't allow access
 
665
     *              to the system properties.
 
666
     * @see        #setProperties
 
667
     * @see        java.lang.SecurityException
 
668
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
 
669
     * @see        java.util.Properties
 
670
     */
 
671
    public static Properties getProperties() {
 
672
        SecurityManager sm = getSecurityManager();
 
673
        if (sm != null) {
 
674
            sm.checkPropertiesAccess();
 
675
        }
 
676
 
 
677
        return Props.props;
 
678
    }
 
679
 
 
680
    /**
 
681
     * Returns the system-dependent line separator string.  It always
 
682
     * returns the same value - the initial value of the {@linkplain
 
683
     * #getProperty(String) system property} {@code line.separator}.
 
684
     *
 
685
     * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
 
686
     * Windows systems it returns {@code "\r\n"}.
 
687
     */
 
688
    public static String lineSeparator() {
 
689
        return Props.lineSeparator;
 
690
    }
 
691
 
 
692
    /**
 
693
     * Sets the system properties to the <code>Properties</code>
 
694
     * argument.
 
695
     * <p>
 
696
     * First, if there is a security manager, its
 
697
     * <code>checkPropertiesAccess</code> method is called with no
 
698
     * arguments. This may result in a security exception.
 
699
     * <p>
 
700
     * The argument becomes the current set of system properties for use
 
701
     * by the {@link #getProperty(String)} method. If the argument is
 
702
     * <code>null</code>, then the current set of system properties is
 
703
     * forgotten.
 
704
     *
 
705
     * @param      props   the new system properties.
 
706
     * @exception  SecurityException  if a security manager exists and its
 
707
     *             <code>checkPropertiesAccess</code> method doesn't allow access
 
708
     *              to the system properties.
 
709
     * @see        #getProperties
 
710
     * @see        java.util.Properties
 
711
     * @see        java.lang.SecurityException
 
712
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
 
713
     */
 
714
    public static void setProperties(Properties props) {
 
715
        SecurityManager sm = getSecurityManager();
 
716
        if (sm != null) {
 
717
            sm.checkPropertiesAccess();
 
718
        }
 
719
        if (props == null) {
 
720
            props = new Properties();
 
721
            VMSystemProperties.initProperties(props);
 
722
        }
 
723
        Props.props = props;
 
724
    }
 
725
 
 
726
    /**
 
727
     * Gets the system property indicated by the specified key.
 
728
     * <p>
 
729
     * First, if there is a security manager, its
 
730
     * <code>checkPropertyAccess</code> method is called with the key as
 
731
     * its argument. This may result in a SecurityException.
 
732
     * <p>
 
733
     * If there is no current set of system properties, a set of system
 
734
     * properties is first created and initialized in the same manner as
 
735
     * for the <code>getProperties</code> method.
 
736
     *
 
737
     * @param      key   the name of the system property.
 
738
     * @return     the string value of the system property,
 
739
     *             or <code>null</code> if there is no property with that key.
 
740
     *
 
741
     * @exception  SecurityException  if a security manager exists and its
 
742
     *             <code>checkPropertyAccess</code> method doesn't allow
 
743
     *              access to the specified system property.
 
744
     * @exception  NullPointerException if <code>key</code> is
 
745
     *             <code>null</code>.
 
746
     * @exception  IllegalArgumentException if <code>key</code> is empty.
 
747
     * @see        #setProperty
 
748
     * @see        java.lang.SecurityException
 
749
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
 
750
     * @see        java.lang.System#getProperties()
 
751
     */
 
752
    public static String getProperty(String key) {
 
753
        checkKey(key);
 
754
        SecurityManager sm = getSecurityManager();
 
755
        if (sm != null) {
 
756
            sm.checkPropertyAccess(key);
 
757
        }
 
758
 
 
759
        return Props.props.getProperty(key);
 
760
    }
 
761
 
 
762
    /**
 
763
     * Gets the system property indicated by the specified key.
 
764
     * <p>
 
765
     * First, if there is a security manager, its
 
766
     * <code>checkPropertyAccess</code> method is called with the
 
767
     * <code>key</code> as its argument.
 
768
     * <p>
 
769
     * If there is no current set of system properties, a set of system
 
770
     * properties is first created and initialized in the same manner as
 
771
     * for the <code>getProperties</code> method.
 
772
     *
 
773
     * @param      key   the name of the system property.
 
774
     * @param      def   a default value.
 
775
     * @return     the string value of the system property,
 
776
     *             or the default value if there is no property with that key.
 
777
     *
 
778
     * @exception  SecurityException  if a security manager exists and its
 
779
     *             <code>checkPropertyAccess</code> method doesn't allow
 
780
     *             access to the specified system property.
 
781
     * @exception  NullPointerException if <code>key</code> is
 
782
     *             <code>null</code>.
 
783
     * @exception  IllegalArgumentException if <code>key</code> is empty.
 
784
     * @see        #setProperty
 
785
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
 
786
     * @see        java.lang.System#getProperties()
 
787
     */
 
788
    public static String getProperty(String key, String def) {
 
789
        checkKey(key);
 
790
        SecurityManager sm = getSecurityManager();
 
791
        if (sm != null) {
 
792
            sm.checkPropertyAccess(key);
 
793
        }
 
794
 
 
795
        return Props.props.getProperty(key, def);
 
796
    }
 
797
 
 
798
    /**
 
799
     * Sets the system property indicated by the specified key.
 
800
     * <p>
 
801
     * First, if a security manager exists, its
 
802
     * <code>SecurityManager.checkPermission</code> method
 
803
     * is called with a <code>PropertyPermission(key, "write")</code>
 
804
     * permission. This may result in a SecurityException being thrown.
 
805
     * If no exception is thrown, the specified property is set to the given
 
806
     * value.
 
807
     * <p>
 
808
     *
 
809
     * @param      key   the name of the system property.
 
810
     * @param      value the value of the system property.
 
811
     * @return     the previous value of the system property,
 
812
     *             or <code>null</code> if it did not have one.
 
813
     *
 
814
     * @exception  SecurityException  if a security manager exists and its
 
815
     *             <code>checkPermission</code> method doesn't allow
 
816
     *             setting of the specified property.
 
817
     * @exception  NullPointerException if <code>key</code> or
 
818
     *             <code>value</code> is <code>null</code>.
 
819
     * @exception  IllegalArgumentException if <code>key</code> is empty.
 
820
     * @see        #getProperty
 
821
     * @see        java.lang.System#getProperty(java.lang.String)
 
822
     * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
 
823
     * @see        java.util.PropertyPermission
 
824
     * @see        SecurityManager#checkPermission
 
825
     * @since      1.2
 
826
     */
 
827
    public static String setProperty(String key, String value) {
 
828
        checkKey(key);
 
829
        SecurityManager sm = getSecurityManager();
 
830
        if (sm != null) {
 
831
            sm.checkPermission(new PropertyPermission(key,
 
832
                SecurityConstants.PROPERTY_WRITE_ACTION));
 
833
        }
 
834
 
 
835
        return (String) Props.props.setProperty(key, value);
 
836
    }
 
837
 
 
838
    /**
 
839
     * Removes the system property indicated by the specified key.
 
840
     * <p>
 
841
     * First, if a security manager exists, its
 
842
     * <code>SecurityManager.checkPermission</code> method
 
843
     * is called with a <code>PropertyPermission(key, "write")</code>
 
844
     * permission. This may result in a SecurityException being thrown.
 
845
     * If no exception is thrown, the specified property is removed.
 
846
     * <p>
 
847
     *
 
848
     * @param      key   the name of the system property to be removed.
 
849
     * @return     the previous string value of the system property,
 
850
     *             or <code>null</code> if there was no property with that key.
 
851
     *
 
852
     * @exception  SecurityException  if a security manager exists and its
 
853
     *             <code>checkPropertyAccess</code> method doesn't allow
 
854
     *              access to the specified system property.
 
855
     * @exception  NullPointerException if <code>key</code> is
 
856
     *             <code>null</code>.
 
857
     * @exception  IllegalArgumentException if <code>key</code> is empty.
 
858
     * @see        #getProperty
 
859
     * @see        #setProperty
 
860
     * @see        java.util.Properties
 
861
     * @see        java.lang.SecurityException
 
862
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
 
863
     * @since 1.5
 
864
     */
 
865
    public static String clearProperty(String key) {
 
866
        checkKey(key);
 
867
        SecurityManager sm = getSecurityManager();
 
868
        if (sm != null) {
 
869
            sm.checkPermission(new PropertyPermission(key, "write"));
 
870
        }
 
871
 
 
872
        return (String) Props.props.remove(key);
 
873
    }
 
874
 
 
875
    private static void checkKey(String key) {
 
876
        if (key == null) {
 
877
            throw new NullPointerException("key can't be null");
 
878
        }
 
879
        if (key.equals("")) {
 
880
            throw new IllegalArgumentException("key can't be empty");
 
881
        }
 
882
    }
 
883
 
 
884
    /**
 
885
     * Gets the value of the specified environment variable. An
 
886
     * environment variable is a system-dependent external named
 
887
     * value.
 
888
     *
 
889
     * <p>If a security manager exists, its
 
890
     * {@link SecurityManager#checkPermission checkPermission}
 
891
     * method is called with a
 
892
     * <code>{@link RuntimePermission}("getenv."+name)</code>
 
893
     * permission.  This may result in a {@link SecurityException}
 
894
     * being thrown.  If no exception is thrown the value of the
 
895
     * variable <code>name</code> is returned.
 
896
     *
 
897
     * <p><a name="EnvironmentVSSystemProperties"><i>System
 
898
     * properties</i> and <i>environment variables</i></a> are both
 
899
     * conceptually mappings between names and values.  Both
 
900
     * mechanisms can be used to pass user-defined information to a
 
901
     * Java process.  Environment variables have a more global effect,
 
902
     * because they are visible to all descendants of the process
 
903
     * which defines them, not just the immediate Java subprocess.
 
904
     * They can have subtly different semantics, such as case
 
905
     * insensitivity, on different operating systems.  For these
 
906
     * reasons, environment variables are more likely to have
 
907
     * unintended side effects.  It is best to use system properties
 
908
     * where possible.  Environment variables should be used when a
 
909
     * global effect is desired, or when an external system interface
 
910
     * requires an environment variable (such as <code>PATH</code>).
 
911
     *
 
912
     * <p>On UNIX systems the alphabetic case of <code>name</code> is
 
913
     * typically significant, while on Microsoft Windows systems it is
 
914
     * typically not.  For example, the expression
 
915
     * <code>System.getenv("FOO").equals(System.getenv("foo"))</code>
 
916
     * is likely to be true on Microsoft Windows.
 
917
     *
 
918
     * @param  name the name of the environment variable
 
919
     * @return the string value of the variable, or <code>null</code>
 
920
     *         if the variable is not defined in the system environment
 
921
     * @throws NullPointerException if <code>name</code> is <code>null</code>
 
922
     * @throws SecurityException
 
923
     *         if a security manager exists and its
 
924
     *         {@link SecurityManager#checkPermission checkPermission}
 
925
     *         method doesn't allow access to the environment variable
 
926
     *         <code>name</code>
 
927
     * @see    #getenv()
 
928
     * @see    ProcessBuilder#environment()
 
929
     */
 
930
    public static String getenv(String name) {
 
931
        SecurityManager sm = getSecurityManager();
 
932
        if (sm != null) {
 
933
            sm.checkPermission(new RuntimePermission("getenv."+name));
 
934
        }
 
935
 
 
936
        return ProcessEnvironment.getenv(name);
 
937
    }
 
938
 
 
939
 
 
940
    /**
 
941
     * Returns an unmodifiable string map view of the current system environment.
 
942
     * The environment is a system-dependent mapping from names to
 
943
     * values which is passed from parent to child processes.
 
944
     *
 
945
     * <p>If the system does not support environment variables, an
 
946
     * empty map is returned.
 
947
     *
 
948
     * <p>The returned map will never contain null keys or values.
 
949
     * Attempting to query the presence of a null key or value will
 
950
     * throw a {@link NullPointerException}.  Attempting to query
 
951
     * the presence of a key or value which is not of type
 
952
     * {@link String} will throw a {@link ClassCastException}.
 
953
     *
 
954
     * <p>The returned map and its collection views may not obey the
 
955
     * general contract of the {@link Object#equals} and
 
956
     * {@link Object#hashCode} methods.
 
957
     *
 
958
     * <p>The returned map is typically case-sensitive on all platforms.
 
959
     *
 
960
     * <p>If a security manager exists, its
 
961
     * {@link SecurityManager#checkPermission checkPermission}
 
962
     * method is called with a
 
963
     * <code>{@link RuntimePermission}("getenv.*")</code>
 
964
     * permission.  This may result in a {@link SecurityException} being
 
965
     * thrown.
 
966
     *
 
967
     * <p>When passing information to a Java subprocess,
 
968
     * <a href=#EnvironmentVSSystemProperties>system properties</a>
 
969
     * are generally preferred over environment variables.
 
970
     *
 
971
     * @return the environment as a map of variable names to values
 
972
     * @throws SecurityException
 
973
     *         if a security manager exists and its
 
974
     *         {@link SecurityManager#checkPermission checkPermission}
 
975
     *         method doesn't allow access to the process environment
 
976
     * @see    #getenv(String)
 
977
     * @see    ProcessBuilder#environment()
 
978
     * @since  1.5
 
979
     */
 
980
    public static java.util.Map<String,String> getenv() {
 
981
        SecurityManager sm = getSecurityManager();
 
982
        if (sm != null) {
 
983
            sm.checkPermission(new RuntimePermission("getenv.*"));
 
984
        }
 
985
 
 
986
        return ProcessEnvironment.getenv();
 
987
    }
 
988
 
 
989
    /**
 
990
     * Terminates the currently running Java Virtual Machine. The
 
991
     * argument serves as a status code; by convention, a nonzero status
 
992
     * code indicates abnormal termination.
 
993
     * <p>
 
994
     * This method calls the <code>exit</code> method in class
 
995
     * <code>Runtime</code>. This method never returns normally.
 
996
     * <p>
 
997
     * The call <code>System.exit(n)</code> is effectively equivalent to
 
998
     * the call:
 
999
     * <blockquote><pre>
 
1000
     * Runtime.getRuntime().exit(n)
 
1001
     * </pre></blockquote>
 
1002
     *
 
1003
     * @param      status   exit status.
 
1004
     * @throws  SecurityException
 
1005
     *        if a security manager exists and its <code>checkExit</code>
 
1006
     *        method doesn't allow exit with the specified status.
 
1007
     * @see        java.lang.Runtime#exit(int)
 
1008
     */
 
1009
    public static void exit(int status) {
 
1010
        Runtime.getRuntime().exit(status);
 
1011
    }
 
1012
 
 
1013
    /**
 
1014
     * Runs the garbage collector.
 
1015
     * <p>
 
1016
     * Calling the <code>gc</code> method suggests that the Java Virtual
 
1017
     * Machine expend effort toward recycling unused objects in order to
 
1018
     * make the memory they currently occupy available for quick reuse.
 
1019
     * When control returns from the method call, the Java Virtual
 
1020
     * Machine has made a best effort to reclaim space from all discarded
 
1021
     * objects.
 
1022
     * <p>
 
1023
     * The call <code>System.gc()</code> is effectively equivalent to the
 
1024
     * call:
 
1025
     * <blockquote><pre>
 
1026
     * Runtime.getRuntime().gc()
 
1027
     * </pre></blockquote>
 
1028
     *
 
1029
     * @see     java.lang.Runtime#gc()
 
1030
     */
 
1031
    public static void gc() {
 
1032
        Runtime.getRuntime().gc();
 
1033
    }
 
1034
 
 
1035
    /**
 
1036
     * Runs the finalization methods of any objects pending finalization.
 
1037
     * <p>
 
1038
     * Calling this method suggests that the Java Virtual Machine expend
 
1039
     * effort toward running the <code>finalize</code> methods of objects
 
1040
     * that have been found to be discarded but whose <code>finalize</code>
 
1041
     * methods have not yet been run. When control returns from the
 
1042
     * method call, the Java Virtual Machine has made a best effort to
 
1043
     * complete all outstanding finalizations.
 
1044
     * <p>
 
1045
     * The call <code>System.runFinalization()</code> is effectively
 
1046
     * equivalent to the call:
 
1047
     * <blockquote><pre>
 
1048
     * Runtime.getRuntime().runFinalization()
 
1049
     * </pre></blockquote>
 
1050
     *
 
1051
     * @see     java.lang.Runtime#runFinalization()
 
1052
     */
 
1053
    public static void runFinalization() {
 
1054
        Runtime.getRuntime().runFinalization();
 
1055
    }
 
1056
 
 
1057
    /**
 
1058
     * Enable or disable finalization on exit; doing so specifies that the
 
1059
     * finalizers of all objects that have finalizers that have not yet been
 
1060
     * automatically invoked are to be run before the Java runtime exits.
 
1061
     * By default, finalization on exit is disabled.
 
1062
     *
 
1063
     * <p>If there is a security manager,
 
1064
     * its <code>checkExit</code> method is first called
 
1065
     * with 0 as its argument to ensure the exit is allowed.
 
1066
     * This could result in a SecurityException.
 
1067
     *
 
1068
     * @deprecated  This method is inherently unsafe.  It may result in
 
1069
     *      finalizers being called on live objects while other threads are
 
1070
     *      concurrently manipulating those objects, resulting in erratic
 
1071
     *      behavior or deadlock.
 
1072
     * @param value indicating enabling or disabling of finalization
 
1073
     * @throws  SecurityException
 
1074
     *        if a security manager exists and its <code>checkExit</code>
 
1075
     *        method doesn't allow the exit.
 
1076
     *
 
1077
     * @see     java.lang.Runtime#exit(int)
 
1078
     * @see     java.lang.Runtime#gc()
 
1079
     * @see     java.lang.SecurityManager#checkExit(int)
 
1080
     * @since   JDK1.1
 
1081
     */
 
1082
    @Deprecated
 
1083
    public static void runFinalizersOnExit(boolean value) {
 
1084
        Runtime.getRuntime().runFinalizersOnExit(value);
 
1085
    }
 
1086
 
 
1087
    /**
 
1088
     * Loads a code file with the specified filename from the local file
 
1089
     * system as a dynamic library. The filename
 
1090
     * argument must be a complete path name.
 
1091
     * <p>
 
1092
     * The call <code>System.load(name)</code> is effectively equivalent
 
1093
     * to the call:
 
1094
     * <blockquote><pre>
 
1095
     * Runtime.getRuntime().load(name)
 
1096
     * </pre></blockquote>
 
1097
     *
 
1098
     * @param      filename   the file to load.
 
1099
     * @exception  SecurityException  if a security manager exists and its
 
1100
     *             <code>checkLink</code> method doesn't allow
 
1101
     *             loading of the specified dynamic library
 
1102
     * @exception  UnsatisfiedLinkError  if the file does not exist.
 
1103
     * @exception  NullPointerException if <code>filename</code> is
 
1104
     *             <code>null</code>
 
1105
     * @see        java.lang.Runtime#load(java.lang.String)
 
1106
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 
1107
     */
 
1108
    @ikvm.internal.HasCallerID
 
1109
    public static void load(String filename) {
 
1110
        Runtime.getRuntime().load0(Reflection.getCallerClass(2), filename);
 
1111
    }
 
1112
 
 
1113
    /**
 
1114
     * Loads the system library specified by the <code>libname</code>
 
1115
     * argument. The manner in which a library name is mapped to the
 
1116
     * actual system library is system dependent.
 
1117
     * <p>
 
1118
     * The call <code>System.loadLibrary(name)</code> is effectively
 
1119
     * equivalent to the call
 
1120
     * <blockquote><pre>
 
1121
     * Runtime.getRuntime().loadLibrary(name)
 
1122
     * </pre></blockquote>
 
1123
     *
 
1124
     * @param      libname   the name of the library.
 
1125
     * @exception  SecurityException  if a security manager exists and its
 
1126
     *             <code>checkLink</code> method doesn't allow
 
1127
     *             loading of the specified dynamic library
 
1128
     * @exception  UnsatisfiedLinkError  if the library does not exist.
 
1129
     * @exception  NullPointerException if <code>libname</code> is
 
1130
     *             <code>null</code>
 
1131
     * @see        java.lang.Runtime#loadLibrary(java.lang.String)
 
1132
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 
1133
     */
 
1134
    @ikvm.internal.HasCallerID
 
1135
    public static void loadLibrary(String libname) {
 
1136
        Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(2), libname);
 
1137
    }
 
1138
 
 
1139
    /**
 
1140
     * Maps a library name into a platform-specific string representing
 
1141
     * a native library.
 
1142
     *
 
1143
     * @param      libname the name of the library.
 
1144
     * @return     a platform-dependent native library name.
 
1145
     * @exception  NullPointerException if <code>libname</code> is
 
1146
     *             <code>null</code>
 
1147
     * @see        java.lang.System#loadLibrary(java.lang.String)
 
1148
     * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
 
1149
     * @since      1.2
 
1150
     */
 
1151
    public static String mapLibraryName(String libname) {
 
1152
        if (libname == null) {
 
1153
            throw new NullPointerException();
 
1154
        }
 
1155
        if (ikvm.internal.Util.WINDOWS) {
 
1156
            return libname + ".dll";
 
1157
        } else if (ikvm.internal.Util.MACOSX) {
 
1158
            return "lib" + libname + ".jnilib";
 
1159
        } else {
 
1160
            return "lib" + libname + ".so";
 
1161
        }
 
1162
    }
 
1163
 
 
1164
    /* returns the class of the caller. */
 
1165
    static Class<?> getCallerClass() {
 
1166
        // NOTE use of more generic Reflection.getCallerClass()
 
1167
        return Reflection.getCallerClass(3);
 
1168
    }
 
1169
}