1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 package java.lang;
27 
28 import dalvik.annotation.optimization.CriticalNative;
29 import dalvik.annotation.optimization.FastNative;
30 import android.system.ErrnoException;
31 import android.system.StructUtsname;
32 import dalvik.system.VMRuntime;
33 import java.io.*;
34 import java.nio.channels.Channel;
35 import java.nio.channels.spi.SelectorProvider;
36 import java.util.Locale;
37 import java.util.Map;
38 import java.util.Properties;
39 import java.util.PropertyPermission;
40 import java.util.function.BiFunction;
41 import java.util.function.Function;
42 
43 import libcore.icu.ICU;
44 import libcore.io.Libcore;
45 
46 import sun.reflect.CallerSensitive;
47 import sun.reflect.Reflection;
48 import sun.security.util.SecurityConstants;
49 /**
50  * The <code>System</code> class contains several useful class fields
51  * and methods. It cannot be instantiated.
52  *
53  * <p>Among the facilities provided by the <code>System</code> class
54  * are standard input, standard output, and error output streams;
55  * access to externally defined properties and environment
56  * variables; a means of loading files and libraries; and a utility
57  * method for quickly copying a portion of an array.
58  *
59  * @author  unascribed
60  * @since   JDK1.0
61  */
62 public final class System {
63     /** Don't let anyone instantiate this class */
System()64     private System() {
65     }
66 
67     /**
68      * The "standard" input stream. This stream is already
69      * open and ready to supply input data. Typically this stream
70      * corresponds to keyboard input or another input source specified by
71      * the host environment or user.
72      */
73     public final static InputStream in;
74 
75     /**
76      * The "standard" output stream. This stream is already
77      * open and ready to accept output data. Typically this stream
78      * corresponds to display output or another output destination
79      * specified by the host environment or user.
80      * <p>
81      * For simple stand-alone Java applications, a typical way to write
82      * a line of output data is:
83      * <blockquote><pre>
84      *     System.out.println(data)
85      * </pre></blockquote>
86      * <p>
87      * See the <code>println</code> methods in class <code>PrintStream</code>.
88      *
89      * @see     java.io.PrintStream#println()
90      * @see     java.io.PrintStream#println(boolean)
91      * @see     java.io.PrintStream#println(char)
92      * @see     java.io.PrintStream#println(char[])
93      * @see     java.io.PrintStream#println(double)
94      * @see     java.io.PrintStream#println(float)
95      * @see     java.io.PrintStream#println(int)
96      * @see     java.io.PrintStream#println(long)
97      * @see     java.io.PrintStream#println(java.lang.Object)
98      * @see     java.io.PrintStream#println(java.lang.String)
99      */
100     public final static PrintStream out;
101 
102     /**
103      * The "standard" error output stream. This stream is already
104      * open and ready to accept output data.
105      * <p>
106      * Typically this stream corresponds to display output or another
107      * output destination specified by the host environment or user. By
108      * convention, this output stream is used to display error messages
109      * or other information that should come to the immediate attention
110      * of a user even if the principal output stream, the value of the
111      * variable <code>out</code>, has been redirected to a file or other
112      * destination that is typically not continuously monitored.
113      */
114     public final static PrintStream err;
115 
116     /**
117      * Dedicated lock for GC / Finalization logic.
118      */
119     private static final Object LOCK = new Object();
120 
121     /**
122      * Whether or not we need to do a GC before running the finalizers.
123      */
124     private static boolean runGC;
125 
126     /**
127      * If we just ran finalization, we might want to do a GC to free the finalized objects.
128      * This lets us do gc/runFinlization/gc sequences but prevents back to back System.gc().
129      */
130     private static boolean justRanFinalization;
131 
132     /**
133      * Reassigns the "standard" input stream.
134      *
135      * <p>First, if there is a security manager, its <code>checkPermission</code>
136      * method is called with a <code>RuntimePermission("setIO")</code> permission
137      *  to see if it's ok to reassign the "standard" input stream.
138      * <p>
139      *
140      * @param in the new standard input stream.
141      *
142      * @throws SecurityException
143      *        if a security manager exists and its
144      *        <code>checkPermission</code> method doesn't allow
145      *        reassigning of the standard input stream.
146      *
147      * @see SecurityManager#checkPermission
148      * @see java.lang.RuntimePermission
149      *
150      * @since   JDK1.1
151      */
setIn(InputStream in)152     public static void setIn(InputStream in) {
153         setIn0(in);
154     }
155 
156     /**
157      * Reassigns the "standard" output stream.
158      *
159      * <p>First, if there is a security manager, its <code>checkPermission</code>
160      * method is called with a <code>RuntimePermission("setIO")</code> permission
161      *  to see if it's ok to reassign the "standard" output stream.
162      *
163      * @param out the new standard output stream
164      *
165      * @throws SecurityException
166      *        if a security manager exists and its
167      *        <code>checkPermission</code> method doesn't allow
168      *        reassigning of the standard output stream.
169      *
170      * @see SecurityManager#checkPermission
171      * @see java.lang.RuntimePermission
172      *
173      * @since   JDK1.1
174      */
setOut(PrintStream out)175     public static void setOut(PrintStream out) {
176         setOut0(out);
177     }
178 
179     /**
180      * Reassigns the "standard" error output stream.
181      *
182      * <p>First, if there is a security manager, its <code>checkPermission</code>
183      * method is called with a <code>RuntimePermission("setIO")</code> permission
184      *  to see if it's ok to reassign the "standard" error output stream.
185      *
186      * @param err the new standard error output stream.
187      *
188      * @throws SecurityException
189      *        if a security manager exists and its
190      *        <code>checkPermission</code> method doesn't allow
191      *        reassigning of the standard error output stream.
192      *
193      * @see SecurityManager#checkPermission
194      * @see java.lang.RuntimePermission
195      *
196      * @since   JDK1.1
197      */
setErr(PrintStream err)198     public static void setErr(PrintStream err) {
199         setErr0(err);
200     }
201 
202     private static volatile Console cons = null;
203     /**
204      * Returns the unique {@link java.io.Console Console} object associated
205      * with the current Java virtual machine, if any.
206      *
207      * @return  The system console, if any, otherwise <tt>null</tt>.
208      *
209      * @since   1.6
210      */
console()211      public static Console console() {
212          // Android-changed: Added proper double checked locking for cons access
213          if (cons == null) {
214              synchronized (System.class) {
215                  if (cons == null) {
216                      cons = Console.console();
217                  }
218              }
219          }
220          return cons;
221      }
222 
223     /**
224      * Returns the channel inherited from the entity that created this
225      * Java virtual machine.
226      *
227      * <p> This method returns the channel obtained by invoking the
228      * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
229      * inheritedChannel} method of the system-wide default
230      * {@link java.nio.channels.spi.SelectorProvider} object. </p>
231      *
232      * <p> In addition to the network-oriented channels described in
233      * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
234      * inheritedChannel}, this method may return other kinds of
235      * channels in the future.
236      *
237      * @return  The inherited channel, if any, otherwise <tt>null</tt>.
238      *
239      * @throws  IOException
240      *          If an I/O error occurs
241      *
242      * @throws  SecurityException
243      *          If a security manager is present and it does not
244      *          permit access to the channel.
245      *
246      * @since 1.5
247      */
inheritedChannel()248     public static Channel inheritedChannel() throws IOException {
249         return SelectorProvider.provider().inheritedChannel();
250     }
251 
setIn0(InputStream in)252     private static native void setIn0(InputStream in);
setOut0(PrintStream out)253     private static native void setOut0(PrintStream out);
setErr0(PrintStream err)254     private static native void setErr0(PrintStream err);
255 
256     /**
257      * Throws {@code SecurityException} (except in case {@code sm == null}).
258      *
259      * <p>Security managers do <i>not</i> provide a secure environment for
260      * executing untrusted code and are unsupported on Android. Untrusted code
261      * cannot be safely isolated within a single VM on Android, so this method
262      * <i>always</i> throws a {@code SecurityException} when passed a non-null SecurityManager
263      *
264      * @param s a security manager
265      * @throws SecurityException always, unless {@code sm == null}
266      */
267     public static
setSecurityManager(final SecurityManager s)268     void setSecurityManager(final SecurityManager s) {
269         if (s != null) {
270             throw new SecurityException();
271         }
272     }
273 
274     /**
275      * Always returns {@code null} in Android
276      *
277      * @return  {@code null} in Android
278      */
getSecurityManager()279     public static SecurityManager getSecurityManager() {
280         // No-op on android.
281         return null;
282     }
283 
284     /**
285      * Returns the current time in milliseconds.  Note that
286      * while the unit of time of the return value is a millisecond,
287      * the granularity of the value depends on the underlying
288      * operating system and may be larger.  For example, many
289      * operating systems measure time in units of tens of
290      * milliseconds.
291      *
292      * <p> See the description of the class <code>Date</code> for
293      * a discussion of slight discrepancies that may arise between
294      * "computer time" and coordinated universal time (UTC).
295      *
296      * @return  the difference, measured in milliseconds, between
297      *          the current time and midnight, January 1, 1970 UTC.
298      * @see     java.util.Date
299      */
300     @CriticalNative
currentTimeMillis()301     public static native long currentTimeMillis();
302 
303     // Android-added: Note on elapse time and deep sleep.
304     /**
305      * Returns the current value of the running Java Virtual Machine's
306      * high-resolution time source, in nanoseconds.
307      *
308      * <p>This method can only be used to measure elapsed time and is
309      * not related to any other notion of system or wall-clock time.
310      * The value returned represents nanoseconds since some fixed but
311      * arbitrary <i>origin</i> time (perhaps in the future, so values
312      * may be negative).  The same origin is used by all invocations of
313      * this method in an instance of a Java virtual machine; other
314      * virtual machine instances are likely to use a different origin.
315      *
316      * <p>This method provides nanosecond precision, but not necessarily
317      * nanosecond resolution (that is, how frequently the value changes)
318      * - no guarantees are made except that the resolution is at least as
319      * good as that of {@link #currentTimeMillis()}.
320      *
321      * <p>Differences in successive calls that span greater than
322      * approximately 292 years (2<sup>63</sup> nanoseconds) will not
323      * correctly compute elapsed time due to numerical overflow.
324      *
325      * <p>The values returned by this method become meaningful only when
326      * the difference between two such values, obtained within the same
327      * instance of a Java virtual machine, is computed.
328      *
329      * <p> For example, to measure how long some code takes to execute:
330      *  <pre> {@code
331      * long startTime = System.nanoTime();
332      * // ... the code being measured ...
333      * long estimatedTime = System.nanoTime() - startTime;}</pre>
334      *
335      * <p>To compare two nanoTime values
336      *  <pre> {@code
337      * long t0 = System.nanoTime();
338      * ...
339      * long t1 = System.nanoTime();}</pre>
340      *
341      * one should use {@code t1 - t0 < 0}, not {@code t1 < t0},
342      * because of the possibility of numerical overflow.
343      *
344      * <p>The value returned by this method does not account for elapsed
345      * time during deep sleep. For timekeeping facilities available on
346      * Android see {@link android.os.SystemClock}.
347      *
348      * @return the current value of the running Java Virtual Machine's
349      *         high-resolution time source, in nanoseconds
350      * @since 1.5
351      */
352     @CriticalNative
nanoTime()353     public static native long nanoTime();
354 
355     /**
356      * Copies an array from the specified source array, beginning at the
357      * specified position, to the specified position of the destination array.
358      * A subsequence of array components are copied from the source
359      * array referenced by <code>src</code> to the destination array
360      * referenced by <code>dest</code>. The number of components copied is
361      * equal to the <code>length</code> argument. The components at
362      * positions <code>srcPos</code> through
363      * <code>srcPos+length-1</code> in the source array are copied into
364      * positions <code>destPos</code> through
365      * <code>destPos+length-1</code>, respectively, of the destination
366      * array.
367      * <p>
368      * If the <code>src</code> and <code>dest</code> arguments refer to the
369      * same array object, then the copying is performed as if the
370      * components at positions <code>srcPos</code> through
371      * <code>srcPos+length-1</code> were first copied to a temporary
372      * array with <code>length</code> components and then the contents of
373      * the temporary array were copied into positions
374      * <code>destPos</code> through <code>destPos+length-1</code> of the
375      * destination array.
376      * <p>
377      * If <code>dest</code> is <code>null</code>, then a
378      * <code>NullPointerException</code> is thrown.
379      * <p>
380      * If <code>src</code> is <code>null</code>, then a
381      * <code>NullPointerException</code> is thrown and the destination
382      * array is not modified.
383      * <p>
384      * Otherwise, if any of the following is true, an
385      * <code>ArrayStoreException</code> is thrown and the destination is
386      * not modified:
387      * <ul>
388      * <li>The <code>src</code> argument refers to an object that is not an
389      *     array.
390      * <li>The <code>dest</code> argument refers to an object that is not an
391      *     array.
392      * <li>The <code>src</code> argument and <code>dest</code> argument refer
393      *     to arrays whose component types are different primitive types.
394      * <li>The <code>src</code> argument refers to an array with a primitive
395      *    component type and the <code>dest</code> argument refers to an array
396      *     with a reference component type.
397      * <li>The <code>src</code> argument refers to an array with a reference
398      *    component type and the <code>dest</code> argument refers to an array
399      *     with a primitive component type.
400      * </ul>
401      * <p>
402      * Otherwise, if any of the following is true, an
403      * <code>IndexOutOfBoundsException</code> is
404      * thrown and the destination is not modified:
405      * <ul>
406      * <li>The <code>srcPos</code> argument is negative.
407      * <li>The <code>destPos</code> argument is negative.
408      * <li>The <code>length</code> argument is negative.
409      * <li><code>srcPos+length</code> is greater than
410      *     <code>src.length</code>, the length of the source array.
411      * <li><code>destPos+length</code> is greater than
412      *     <code>dest.length</code>, the length of the destination array.
413      * </ul>
414      * <p>
415      * Otherwise, if any actual component of the source array from
416      * position <code>srcPos</code> through
417      * <code>srcPos+length-1</code> cannot be converted to the component
418      * type of the destination array by assignment conversion, an
419      * <code>ArrayStoreException</code> is thrown. In this case, let
420      * <b><i>k</i></b> be the smallest nonnegative integer less than
421      * length such that <code>src[srcPos+</code><i>k</i><code>]</code>
422      * cannot be converted to the component type of the destination
423      * array; when the exception is thrown, source array components from
424      * positions <code>srcPos</code> through
425      * <code>srcPos+</code><i>k</i><code>-1</code>
426      * will already have been copied to destination array positions
427      * <code>destPos</code> through
428      * <code>destPos+</code><i>k</I><code>-1</code> and no other
429      * positions of the destination array will have been modified.
430      * (Because of the restrictions already itemized, this
431      * paragraph effectively applies only to the situation where both
432      * arrays have component types that are reference types.)
433      *
434      * @param      src      the source array.
435      * @param      srcPos   starting position in the source array.
436      * @param      dest     the destination array.
437      * @param      destPos  starting position in the destination data.
438      * @param      length   the number of array elements to be copied.
439      * @exception  IndexOutOfBoundsException  if copying would cause
440      *               access of data outside array bounds.
441      * @exception  ArrayStoreException  if an element in the <code>src</code>
442      *               array could not be stored into the <code>dest</code> array
443      *               because of a type mismatch.
444      * @exception  NullPointerException if either <code>src</code> or
445      *               <code>dest</code> is <code>null</code>.
446      */
447     @FastNative
arraycopy(Object src, int srcPos, Object dest, int destPos, int length)448     public static native void arraycopy(Object src,  int  srcPos,
449                                         Object dest, int destPos,
450                                         int length);
451 
452 
453     // BEGIN Android-changed
454     /**
455      * The char array length threshold below which to use a Java
456      * (non-native) version of arraycopy() instead of the native
457      * version. See b/7103825.
458      */
459     private static final int ARRAYCOPY_SHORT_CHAR_ARRAY_THRESHOLD = 32;
460 
461     /**
462      * The char[] specialized version of arraycopy().
463      * Note: This method is required for runtime ART compiler optimizations.
464      * Do not remove or change the signature.
465      */
466     @SuppressWarnings("unused")
arraycopy(char[] src, int srcPos, char[] dst, int dstPos, int length)467     private static void arraycopy(char[] src, int srcPos, char[] dst, int dstPos, int length) {
468         if (src == null) {
469             throw new NullPointerException("src == null");
470         }
471         if (dst == null) {
472             throw new NullPointerException("dst == null");
473         }
474         if (srcPos < 0 || dstPos < 0 || length < 0 ||
475             srcPos > src.length - length || dstPos > dst.length - length) {
476             throw new ArrayIndexOutOfBoundsException(
477                 "src.length=" + src.length + " srcPos=" + srcPos +
478                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
479         }
480         if (length <= ARRAYCOPY_SHORT_CHAR_ARRAY_THRESHOLD) {
481             // Copy char by char for shorter arrays.
482             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
483                 // Copy backward (to avoid overwriting elements before
484                 // they are copied in case of an overlap on the same
485                 // array.)
486                 for (int i = length - 1; i >= 0; --i) {
487                     dst[dstPos + i] = src[srcPos + i];
488                 }
489             } else {
490                 // Copy forward.
491                 for (int i = 0; i < length; ++i) {
492                     dst[dstPos + i] = src[srcPos + i];
493                 }
494             }
495         } else {
496             // Call the native version for longer arrays.
497             arraycopyCharUnchecked(src, srcPos, dst, dstPos, length);
498         }
499     }
500 
501     /**
502      * The char[] specialized, unchecked, native version of
503      * arraycopy(). This assumes error checking has been done.
504      */
505     @FastNative
arraycopyCharUnchecked(char[] src, int srcPos, char[] dst, int dstPos, int length)506     private static native void arraycopyCharUnchecked(char[] src, int srcPos,
507         char[] dst, int dstPos, int length);
508 
509     /**
510      * The byte array length threshold below which to use a Java
511      * (non-native) version of arraycopy() instead of the native
512      * version. See b/7103825.
513      */
514     private static final int ARRAYCOPY_SHORT_BYTE_ARRAY_THRESHOLD = 32;
515 
516     /**
517      * The byte[] specialized version of arraycopy().
518      * Note: This method is required for runtime ART compiler optimizations.
519      * Do not remove or change the signature.
520      */
521     @SuppressWarnings("unused")
arraycopy(byte[] src, int srcPos, byte[] dst, int dstPos, int length)522     private static void arraycopy(byte[] src, int srcPos, byte[] dst, int dstPos, int length) {
523         if (src == null) {
524             throw new NullPointerException("src == null");
525         }
526         if (dst == null) {
527             throw new NullPointerException("dst == null");
528         }
529         if (srcPos < 0 || dstPos < 0 || length < 0 ||
530             srcPos > src.length - length || dstPos > dst.length - length) {
531             throw new ArrayIndexOutOfBoundsException(
532                 "src.length=" + src.length + " srcPos=" + srcPos +
533                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
534         }
535         if (length <= ARRAYCOPY_SHORT_BYTE_ARRAY_THRESHOLD) {
536             // Copy byte by byte for shorter arrays.
537             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
538                 // Copy backward (to avoid overwriting elements before
539                 // they are copied in case of an overlap on the same
540                 // array.)
541                 for (int i = length - 1; i >= 0; --i) {
542                     dst[dstPos + i] = src[srcPos + i];
543                 }
544             } else {
545                 // Copy forward.
546                 for (int i = 0; i < length; ++i) {
547                     dst[dstPos + i] = src[srcPos + i];
548                 }
549             }
550         } else {
551             // Call the native version for longer arrays.
552             arraycopyByteUnchecked(src, srcPos, dst, dstPos, length);
553         }
554     }
555 
556     /**
557      * The byte[] specialized, unchecked, native version of
558      * arraycopy(). This assumes error checking has been done.
559      */
560     @FastNative
arraycopyByteUnchecked(byte[] src, int srcPos, byte[] dst, int dstPos, int length)561     private static native void arraycopyByteUnchecked(byte[] src, int srcPos,
562         byte[] dst, int dstPos, int length);
563 
564     /**
565      * The short array length threshold below which to use a Java
566      * (non-native) version of arraycopy() instead of the native
567      * version. See b/7103825.
568      */
569     private static final int ARRAYCOPY_SHORT_SHORT_ARRAY_THRESHOLD = 32;
570 
571     /**
572      * The short[] specialized version of arraycopy().
573      * Note: This method is required for runtime ART compiler optimizations.
574      * Do not remove or change the signature.
575      */
576     @SuppressWarnings("unused")
arraycopy(short[] src, int srcPos, short[] dst, int dstPos, int length)577     private static void arraycopy(short[] src, int srcPos, short[] dst, int dstPos, int length) {
578         if (src == null) {
579             throw new NullPointerException("src == null");
580         }
581         if (dst == null) {
582             throw new NullPointerException("dst == null");
583         }
584         if (srcPos < 0 || dstPos < 0 || length < 0 ||
585             srcPos > src.length - length || dstPos > dst.length - length) {
586             throw new ArrayIndexOutOfBoundsException(
587                 "src.length=" + src.length + " srcPos=" + srcPos +
588                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
589         }
590         if (length <= ARRAYCOPY_SHORT_SHORT_ARRAY_THRESHOLD) {
591             // Copy short by short for shorter arrays.
592             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
593                 // Copy backward (to avoid overwriting elements before
594                 // they are copied in case of an overlap on the same
595                 // array.)
596                 for (int i = length - 1; i >= 0; --i) {
597                     dst[dstPos + i] = src[srcPos + i];
598                 }
599             } else {
600                 // Copy forward.
601                 for (int i = 0; i < length; ++i) {
602                     dst[dstPos + i] = src[srcPos + i];
603                 }
604             }
605         } else {
606             // Call the native version for longer arrays.
607             arraycopyShortUnchecked(src, srcPos, dst, dstPos, length);
608         }
609     }
610 
611     /**
612      * The short[] specialized, unchecked, native version of
613      * arraycopy(). This assumes error checking has been done.
614      */
615     @FastNative
arraycopyShortUnchecked(short[] src, int srcPos, short[] dst, int dstPos, int length)616     private static native void arraycopyShortUnchecked(short[] src, int srcPos,
617         short[] dst, int dstPos, int length);
618 
619     /**
620      * The short array length threshold below which to use a Java
621      * (non-native) version of arraycopy() instead of the native
622      * version. See b/7103825.
623      */
624     private static final int ARRAYCOPY_SHORT_INT_ARRAY_THRESHOLD = 32;
625 
626     /**
627      * The int[] specialized version of arraycopy().
628      * Note: This method is required for runtime ART compiler optimizations.
629      * Do not remove or change the signature.
630      */
631     @SuppressWarnings("unused")
arraycopy(int[] src, int srcPos, int[] dst, int dstPos, int length)632     private static void arraycopy(int[] src, int srcPos, int[] dst, int dstPos, int length) {
633         if (src == null) {
634             throw new NullPointerException("src == null");
635         }
636         if (dst == null) {
637             throw new NullPointerException("dst == null");
638         }
639         if (srcPos < 0 || dstPos < 0 || length < 0 ||
640             srcPos > src.length - length || dstPos > dst.length - length) {
641             throw new ArrayIndexOutOfBoundsException(
642                 "src.length=" + src.length + " srcPos=" + srcPos +
643                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
644         }
645         if (length <= ARRAYCOPY_SHORT_INT_ARRAY_THRESHOLD) {
646             // Copy int by int for shorter arrays.
647             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
648                 // Copy backward (to avoid overwriting elements before
649                 // they are copied in case of an overlap on the same
650                 // array.)
651                 for (int i = length - 1; i >= 0; --i) {
652                     dst[dstPos + i] = src[srcPos + i];
653                 }
654             } else {
655                 // Copy forward.
656                 for (int i = 0; i < length; ++i) {
657                     dst[dstPos + i] = src[srcPos + i];
658                 }
659             }
660         } else {
661             // Call the native version for longer arrays.
662             arraycopyIntUnchecked(src, srcPos, dst, dstPos, length);
663         }
664     }
665 
666     /**
667      * The int[] specialized, unchecked, native version of
668      * arraycopy(). This assumes error checking has been done.
669      */
670     @FastNative
arraycopyIntUnchecked(int[] src, int srcPos, int[] dst, int dstPos, int length)671     private static native void arraycopyIntUnchecked(int[] src, int srcPos,
672         int[] dst, int dstPos, int length);
673 
674     /**
675      * The short array length threshold below which to use a Java
676      * (non-native) version of arraycopy() instead of the native
677      * version. See b/7103825.
678      */
679     private static final int ARRAYCOPY_SHORT_LONG_ARRAY_THRESHOLD = 32;
680 
681     /**
682      * The long[] specialized version of arraycopy().
683      * Note: This method is required for runtime ART compiler optimizations.
684      * Do not remove or change the signature.
685      */
686     @SuppressWarnings("unused")
arraycopy(long[] src, int srcPos, long[] dst, int dstPos, int length)687     private static void arraycopy(long[] src, int srcPos, long[] dst, int dstPos, int length) {
688         if (src == null) {
689             throw new NullPointerException("src == null");
690         }
691         if (dst == null) {
692             throw new NullPointerException("dst == null");
693         }
694         if (srcPos < 0 || dstPos < 0 || length < 0 ||
695             srcPos > src.length - length || dstPos > dst.length - length) {
696             throw new ArrayIndexOutOfBoundsException(
697                 "src.length=" + src.length + " srcPos=" + srcPos +
698                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
699         }
700         if (length <= ARRAYCOPY_SHORT_LONG_ARRAY_THRESHOLD) {
701             // Copy long by long for shorter arrays.
702             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
703                 // Copy backward (to avoid overwriting elements before
704                 // they are copied in case of an overlap on the same
705                 // array.)
706                 for (int i = length - 1; i >= 0; --i) {
707                     dst[dstPos + i] = src[srcPos + i];
708                 }
709             } else {
710                 // Copy forward.
711                 for (int i = 0; i < length; ++i) {
712                     dst[dstPos + i] = src[srcPos + i];
713                 }
714             }
715         } else {
716             // Call the native version for longer arrays.
717             arraycopyLongUnchecked(src, srcPos, dst, dstPos, length);
718         }
719     }
720 
721     /**
722      * The long[] specialized, unchecked, native version of
723      * arraycopy(). This assumes error checking has been done.
724      */
725     @FastNative
arraycopyLongUnchecked(long[] src, int srcPos, long[] dst, int dstPos, int length)726     private static native void arraycopyLongUnchecked(long[] src, int srcPos,
727         long[] dst, int dstPos, int length);
728 
729     /**
730      * The short array length threshold below which to use a Java
731      * (non-native) version of arraycopy() instead of the native
732      * version. See b/7103825.
733      */
734     private static final int ARRAYCOPY_SHORT_FLOAT_ARRAY_THRESHOLD = 32;
735 
736     /**
737      * The float[] specialized version of arraycopy().
738      * Note: This method is required for runtime ART compiler optimizations.
739      * Do not remove or change the signature.
740      */
741     @SuppressWarnings("unused")
arraycopy(float[] src, int srcPos, float[] dst, int dstPos, int length)742     private static void arraycopy(float[] src, int srcPos, float[] dst, int dstPos, int length) {
743         if (src == null) {
744             throw new NullPointerException("src == null");
745         }
746         if (dst == null) {
747             throw new NullPointerException("dst == null");
748         }
749         if (srcPos < 0 || dstPos < 0 || length < 0 ||
750             srcPos > src.length - length || dstPos > dst.length - length) {
751             throw new ArrayIndexOutOfBoundsException(
752                 "src.length=" + src.length + " srcPos=" + srcPos +
753                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
754         }
755         if (length <= ARRAYCOPY_SHORT_FLOAT_ARRAY_THRESHOLD) {
756             // Copy float by float for shorter arrays.
757             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
758                 // Copy backward (to avoid overwriting elements before
759                 // they are copied in case of an overlap on the same
760                 // array.)
761                 for (int i = length - 1; i >= 0; --i) {
762                     dst[dstPos + i] = src[srcPos + i];
763                 }
764             } else {
765                 // Copy forward.
766                 for (int i = 0; i < length; ++i) {
767                     dst[dstPos + i] = src[srcPos + i];
768                 }
769             }
770         } else {
771             // Call the native version for floater arrays.
772             arraycopyFloatUnchecked(src, srcPos, dst, dstPos, length);
773         }
774     }
775 
776     /**
777      * The float[] specialized, unchecked, native version of
778      * arraycopy(). This assumes error checking has been done.
779      */
780     @FastNative
arraycopyFloatUnchecked(float[] src, int srcPos, float[] dst, int dstPos, int length)781     private static native void arraycopyFloatUnchecked(float[] src, int srcPos,
782         float[] dst, int dstPos, int length);
783 
784     /**
785      * The short array length threshold below which to use a Java
786      * (non-native) version of arraycopy() instead of the native
787      * version. See b/7103825.
788      */
789     private static final int ARRAYCOPY_SHORT_DOUBLE_ARRAY_THRESHOLD = 32;
790 
791     /**
792      * The double[] specialized version of arraycopy().
793      * Note: This method is required for runtime ART compiler optimizations.
794      * Do not remove or change the signature.
795      */
796     @SuppressWarnings("unused")
arraycopy(double[] src, int srcPos, double[] dst, int dstPos, int length)797     private static void arraycopy(double[] src, int srcPos, double[] dst, int dstPos, int length) {
798         if (src == null) {
799             throw new NullPointerException("src == null");
800         }
801         if (dst == null) {
802             throw new NullPointerException("dst == null");
803         }
804         if (srcPos < 0 || dstPos < 0 || length < 0 ||
805             srcPos > src.length - length || dstPos > dst.length - length) {
806             throw new ArrayIndexOutOfBoundsException(
807                 "src.length=" + src.length + " srcPos=" + srcPos +
808                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
809         }
810         if (length <= ARRAYCOPY_SHORT_DOUBLE_ARRAY_THRESHOLD) {
811             // Copy double by double for shorter arrays.
812             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
813                 // Copy backward (to avoid overwriting elements before
814                 // they are copied in case of an overlap on the same
815                 // array.)
816                 for (int i = length - 1; i >= 0; --i) {
817                     dst[dstPos + i] = src[srcPos + i];
818                 }
819             } else {
820                 // Copy forward.
821                 for (int i = 0; i < length; ++i) {
822                     dst[dstPos + i] = src[srcPos + i];
823                 }
824             }
825         } else {
826             // Call the native version for floater arrays.
827             arraycopyDoubleUnchecked(src, srcPos, dst, dstPos, length);
828         }
829     }
830 
831     /**
832      * The double[] specialized, unchecked, native version of
833      * arraycopy(). This assumes error checking has been done.
834      */
835     @FastNative
arraycopyDoubleUnchecked(double[] src, int srcPos, double[] dst, int dstPos, int length)836     private static native void arraycopyDoubleUnchecked(double[] src, int srcPos,
837         double[] dst, int dstPos, int length);
838 
839     /**
840      * The short array length threshold below which to use a Java
841      * (non-native) version of arraycopy() instead of the native
842      * version. See b/7103825.
843      */
844     private static final int ARRAYCOPY_SHORT_BOOLEAN_ARRAY_THRESHOLD = 32;
845 
846     /**
847      * The boolean[] specialized version of arraycopy().
848      * Note: This method is required for runtime ART compiler optimizations.
849      * Do not remove or change the signature.
850      */
851     @SuppressWarnings("unused")
arraycopy(boolean[] src, int srcPos, boolean[] dst, int dstPos, int length)852     private static void arraycopy(boolean[] src, int srcPos, boolean[] dst, int dstPos, int length) {
853         if (src == null) {
854             throw new NullPointerException("src == null");
855         }
856         if (dst == null) {
857             throw new NullPointerException("dst == null");
858         }
859         if (srcPos < 0 || dstPos < 0 || length < 0 ||
860             srcPos > src.length - length || dstPos > dst.length - length) {
861             throw new ArrayIndexOutOfBoundsException(
862                 "src.length=" + src.length + " srcPos=" + srcPos +
863                 " dst.length=" + dst.length + " dstPos=" + dstPos + " length=" + length);
864         }
865         if (length <= ARRAYCOPY_SHORT_BOOLEAN_ARRAY_THRESHOLD) {
866             // Copy boolean by boolean for shorter arrays.
867             if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
868                 // Copy backward (to avoid overwriting elements before
869                 // they are copied in case of an overlap on the same
870                 // array.)
871                 for (int i = length - 1; i >= 0; --i) {
872                     dst[dstPos + i] = src[srcPos + i];
873                 }
874             } else {
875                 // Copy forward.
876                 for (int i = 0; i < length; ++i) {
877                     dst[dstPos + i] = src[srcPos + i];
878                 }
879             }
880         } else {
881             // Call the native version for floater arrays.
882             arraycopyBooleanUnchecked(src, srcPos, dst, dstPos, length);
883         }
884     }
885 
886     /**
887      * The boolean[] specialized, unchecked, native version of
888      * arraycopy(). This assumes error checking has been done.
889      */
890     @FastNative
arraycopyBooleanUnchecked(boolean[] src, int srcPos, boolean[] dst, int dstPos, int length)891     private static native void arraycopyBooleanUnchecked(boolean[] src, int srcPos,
892         boolean[] dst, int dstPos, int length);
893     // END Android-changed
894 
895     /**
896      * Returns the same hash code for the given object as
897      * would be returned by the default method hashCode(),
898      * whether or not the given object's class overrides
899      * hashCode().
900      * The hash code for the null reference is zero.
901      *
902      * @param x object for which the hashCode is to be calculated
903      * @return  the hashCode
904      * @since   JDK1.1
905      */
identityHashCode(Object x)906     public static int identityHashCode(Object x) {
907         if (x == null) {
908             return 0;
909         }
910         return Object.identityHashCode(x);
911     }
912 
913     /**
914      * System properties. The following properties are guaranteed to be defined:
915      * <dl>
916      * <dt>java.version         <dd>Java version number
917      * <dt>java.vendor          <dd>Java vendor specific string
918      * <dt>java.vendor.url      <dd>Java vendor URL
919      * <dt>java.home            <dd>Java installation directory
920      * <dt>java.class.version   <dd>Java class version number
921      * <dt>java.class.path      <dd>Java classpath
922      * <dt>os.name              <dd>Operating System Name
923      * <dt>os.arch              <dd>Operating System Architecture
924      * <dt>os.version           <dd>Operating System Version
925      * <dt>file.separator       <dd>File separator ("/" on Unix)
926      * <dt>path.separator       <dd>Path separator (":" on Unix)
927      * <dt>line.separator       <dd>Line separator ("\n" on Unix)
928      * <dt>user.name            <dd>User account name
929      * <dt>user.home            <dd>User home directory
930      * <dt>user.dir             <dd>User's current working directory
931      * </dl>
932      */
933 
934     private static Properties props;
935     private static Properties unchangeableProps;
936 
specialProperties()937     private static native String[] specialProperties();
938 
939     static final class PropertiesWithNonOverrideableDefaults extends Properties {
PropertiesWithNonOverrideableDefaults(Properties defaults)940         PropertiesWithNonOverrideableDefaults(Properties defaults) {
941             super(defaults);
942         }
943 
944         @Override
compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction)945         public synchronized Object compute(Object key,
946                 BiFunction<? super Object, ? super Object, ?> remappingFunction) {
947             if (defaults == null || !defaults.containsKey(key)) {
948                 return super.compute(key, remappingFunction);
949             } else {
950                 logE("Ignoring attempt to modify property " + key);
951                 // No new value is associated with the key, hence null.
952                 return null;
953             }
954         }
955 
956         @Override
computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction)957         public synchronized Object computeIfAbsent(Object key,
958                 Function<? super Object, ?> mappingFunction) {
959             if (defaults == null || !defaults.containsKey(key)) {
960                 return super.computeIfAbsent(key, mappingFunction);
961             } else {
962                 logE("Ignoring attempt to modify property " + key);
963                 return defaults.get(key);
964             }
965         }
966 
967         @Override
computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction)968         public synchronized Object computeIfPresent(Object key,
969                 BiFunction<? super Object, ? super Object, ?> remappingFunction) {
970             if (defaults == null || !defaults.containsKey(key)) {
971                 return super.computeIfPresent(key, remappingFunction);
972             } else {
973                 logE("Ignoring attempt to modify property " + key);
974                 return defaults.get(key);
975             }
976         }
977 
978         @Override
merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction)979         public synchronized Object merge(Object key, Object value,
980                 BiFunction<? super Object, ? super Object, ?> remappingFunction) {
981             if (defaults == null || !defaults.containsKey(key)) {
982                 return super.merge(key, value, remappingFunction);
983             } else {
984                 logE("Ignoring attempt to modify property " + key);
985                 // No new value is associated with the key, but
986                 return defaults.get(key);
987             }
988         }
989 
990         @Override
put(Object key, Object value)991         public Object put(Object key, Object value) {
992             if (defaults.containsKey(key)) {
993                 logE("Ignoring attempt to set property \"" + key +
994                         "\" to value \"" + value + "\".");
995                 return defaults.get(key);
996             }
997 
998             return super.put(key, value);
999         }
1000 
1001         @Override
putAll(Map<?, ?> m)1002         public synchronized void putAll(Map<?, ?> m) {
1003             m.forEach(this::put);
1004         }
1005 
1006         @Override
putIfAbsent(Object key, Object value)1007         public synchronized Object putIfAbsent(Object key, Object value) {
1008             if (defaults == null || !defaults.containsKey(key)) {
1009                 return super.putIfAbsent(key, value);
1010             } else {
1011                 logE("Ignoring attempt to modify property " + key);
1012                 // Returned values is in sync with put(Object, Object).
1013                 return defaults.get(key);
1014             }
1015         }
1016 
1017         @Override
remove(Object key)1018         public Object remove(Object key) {
1019             if (defaults.containsKey(key)) {
1020                 logE("Ignoring attempt to remove property \"" + key + "\".");
1021                 return null;
1022             }
1023 
1024             return super.remove(key);
1025         }
1026 
1027 
1028         @Override
replace(Object key, Object value)1029         public synchronized Object replace(Object key, Object value) {
1030             if (defaults == null || !defaults.containsKey(key)) {
1031                 return super.replace(key, value);
1032             } else {
1033                 logE("Ignoring attempt to replace property \"" + key + "\".");
1034                 return defaults.get(key);
1035             }
1036         }
1037 
1038         @Override
replace(Object key, Object oldValue, Object newValue)1039         public synchronized boolean replace(Object key, Object oldValue, Object newValue) {
1040             if (defaults == null || !defaults.containsKey(key)) {
1041                 return super.replace(key, oldValue, newValue);
1042             } else {
1043                 logE("Ignoring attempt to replace property \"" + key + "\".");
1044                 // As it was not changed.
1045                 return false;
1046             }
1047         }
1048     }
1049 
parsePropertyAssignments(Properties p, String[] assignments)1050     private static void parsePropertyAssignments(Properties p, String[] assignments) {
1051         for (String assignment : assignments) {
1052             int split = assignment.indexOf('=');
1053             String key = assignment.substring(0, split);
1054             String value = assignment.substring(split + 1);
1055             p.put(key, value);
1056         }
1057     }
1058 
initUnchangeableSystemProperties()1059     private static Properties initUnchangeableSystemProperties() {
1060         VMRuntime runtime = VMRuntime.getRuntime();
1061         Properties p = new Properties();
1062 
1063         // Set non-static properties.
1064         p.put("java.boot.class.path", runtime.bootClassPath());
1065         p.put("java.class.path", runtime.classPath());
1066 
1067         // This is probably not useful, but it's documented as being present.
1068         // ANDROID_ART_ROOT is defined in `system/core/rootdir/init.environ.rc.in`.
1069         String javaHome = getenv("ANDROID_ART_ROOT");
1070         if (javaHome == null) {
1071             javaHome = "/apex/com.android.art";
1072         }
1073         p.put("java.home", javaHome);
1074 
1075         p.put("java.vm.version", runtime.vmVersion());
1076 
1077         String userName;
1078         try {
1079             userName = Libcore.os.getpwuid(Libcore.os.getuid()).pw_name;
1080         } catch (ErrnoException exception) {
1081             userName = "unknown";
1082         }
1083         p.put("user.name", userName);
1084 
1085         StructUtsname info = Libcore.os.uname();
1086         p.put("os.arch", info.machine);
1087         // os.name was previously hardcoded to "Linux", but was reverted due to support
1088         // for Fuchsia. b/121268567 shows initialization regressions.
1089         p.put("os.name", info.sysname);
1090         p.put("os.version", info.release);
1091 
1092         // Android-added: Undocumented properties that exist only on Android.
1093         p.put("android.icu.library.version", ICU.getIcuVersion());
1094         p.put("android.icu.unicode.version", ICU.getUnicodeVersion());
1095         p.put("android.icu.cldr.version", ICU.getCldrVersion());
1096 
1097         parsePropertyAssignments(p, specialProperties());
1098 
1099         // Override built-in properties with settings from the command line.
1100         // Note: it is not possible to override hardcoded values.
1101         parsePropertyAssignments(p, runtime.properties());
1102 
1103         // Set static hardcoded properties.
1104         // These come last, as they must be guaranteed to agree with what a backend compiler
1105         // may assume when compiling the boot image on Android.
1106         for (String[] pair : AndroidHardcodedSystemProperties.STATIC_PROPERTIES) {
1107             if (p.containsKey(pair[0])) {
1108                 logE("Ignoring command line argument: -D" + pair[0]);
1109             }
1110             if (pair[1] == null) {
1111                 p.remove(pair[0]);
1112             } else {
1113                 p.put(pair[0], pair[1]);
1114             }
1115         }
1116 
1117         return p;
1118     }
1119 
initProperties()1120     private static Properties initProperties() {
1121         Properties p = new PropertiesWithNonOverrideableDefaults(unchangeableProps);
1122         setDefaultChangeableProperties(p);
1123         return p;
1124     }
1125 
setDefaultChangeableProperties(Properties p)1126     private static Properties setDefaultChangeableProperties(Properties p) {
1127         // On Android, "java.io.tmpdir" is set in android.app.ActivityThread. Each app gets its
1128         // own location, a typical value would be "/data/user/0/com.android.deskclock/cache.
1129         // The value set here is just a fallback default for host.
1130         // We check first if the property has not been set already: note that it
1131         // can only be set from the command line through the '-Djava.io.tmpdir=' option.
1132         if (!unchangeableProps.containsKey("java.io.tmpdir")) {
1133             p.put("java.io.tmpdir", "/tmp");
1134         }
1135 
1136         // Android has always had an empty "user.home" (see docs for getProperty).
1137         // This is not useful for normal android apps which need to use android specific
1138         // APIs such as {@code Context.getFilesDir} and {@code Context.getCacheDir} but
1139         // we make it changeable for backward compatibility, so that they can change it
1140         // to a writeable location if required.
1141         // We check first if the property has not been set already: note that it
1142         // can only be set from the command line through the '-Duser.home=' option.
1143         if (!unchangeableProps.containsKey("user.home")) {
1144             p.put("user.home", "");
1145         }
1146 
1147         return p;
1148     }
1149 
1150     /**
1151      * Inits an unchangeable system property with the given value.
1152      *
1153      * This is called from native code when the environment needs to change under native
1154      * bridge emulation.
1155      *
1156      * @hide also visible for tests.
1157      */
setUnchangeableSystemProperty(String key, String value)1158     public static void setUnchangeableSystemProperty(String key, String value) {
1159         checkKey(key);
1160         unchangeableProps.put(key, value);
1161     }
1162 
addLegacyLocaleSystemProperties()1163     private static void addLegacyLocaleSystemProperties() {
1164         final String locale = getProperty("user.locale", "");
1165         if (!locale.isEmpty()) {
1166             Locale l = Locale.forLanguageTag(locale);
1167             setUnchangeableSystemProperty("user.language", l.getLanguage());
1168             setUnchangeableSystemProperty("user.region", l.getCountry());
1169             setUnchangeableSystemProperty("user.variant", l.getVariant());
1170         } else {
1171             // If "user.locale" isn't set we fall back to our old defaults of
1172             // language="en" and region="US" (if unset) and don't attempt to set it.
1173             // The Locale class will fall back to using user.language and
1174             // user.region if unset.
1175             final String language = getProperty("user.language", "");
1176             final String region = getProperty("user.region", "");
1177 
1178             if (language.isEmpty()) {
1179                 setUnchangeableSystemProperty("user.language", "en");
1180             }
1181 
1182             if (region.isEmpty()) {
1183                 setUnchangeableSystemProperty("user.region", "US");
1184             }
1185         }
1186     }
1187 
1188     /**
1189      * Determines the current system properties.
1190      *
1191      *
1192      * <p>The following properties are always provided by the Dalvik VM:</p>
1193      * <p><table BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
1194      * <tr BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
1195      *     <td><b>Name</b></td>        <td><b>Meaning</b></td>                    <td><b>Example</b></td></tr>
1196      * <tr><td>file.separator</td>     <td>{@link java.io.File#separator}</td>    <td>{@code /}</td></tr>
1197      *
1198      * <tr><td>java.class.path</td>    <td>System class path</td>                 <td>{@code .}</td></tr>
1199      * <tr><td>java.class.version</td> <td>(Not useful on Android)</td>           <td>{@code 50.0}</td></tr>
1200      * <tr><td>java.compiler</td>      <td>(Not useful on Android)</td>           <td>Empty</td></tr>
1201      * <tr><td>java.ext.dirs</td>      <td>(Not useful on Android)</td>           <td>Empty</td></tr>
1202      * <tr><td>java.home</td>          <td>Location of the VM on the file system</td> <td>{@code /apex/com.android.art/}</td></tr>
1203      * <tr><td>java.io.tmpdir</td>     <td>Location of a temporary directory.<br>The location varies by application.<br>See {@link java.io.File#createTempFile}</td> <td>{@code /data/user/0/com.android.app/cache}</td></tr>
1204      * <tr><td>java.library.path</td>  <td>Search path for JNI libraries</td>     <td>{@code /vendor/lib:/system/lib}</td></tr>
1205      * <tr><td>java.vendor</td>        <td>Human-readable VM vendor</td>          <td>{@code The Android Project}</td></tr>
1206      * <tr><td>java.vendor.url</td>    <td>URL for VM vendor's web site</td>      <td>{@code http://www.android.com/}</td></tr>
1207      * <tr><td>java.version</td>       <td>(Not useful on Android)</td>           <td>{@code 0}</td></tr>
1208      *
1209      * <tr><td>java.specification.version</td>    <td>VM libraries version</td>        <td>{@code 0.9}</td></tr>
1210      * <tr><td>java.specification.vendor</td>     <td>VM libraries vendor</td>         <td>{@code The Android Project}</td></tr>
1211      * <tr><td>java.specification.name</td>       <td>VM libraries name</td>           <td>{@code Dalvik Core Library}</td></tr>
1212      * <tr><td>java.vm.version</td>               <td>VM implementation version</td>   <td>{@code 1.2.0}</td></tr>
1213      * <tr><td>java.vm.vendor</td>                <td>VM implementation vendor</td>    <td>{@code The Android Project}</td></tr>
1214      * <tr><td>java.vm.name</td>                  <td>VM implementation name</td>      <td>{@code Dalvik}</td></tr>
1215      * <tr><td>java.vm.specification.version</td> <td>VM specification version</td>    <td>{@code 0.9}</td></tr>
1216      * <tr><td>java.vm.specification.vendor</td>  <td>VM specification vendor</td>     <td>{@code The Android Project}</td></tr>
1217      * <tr><td>java.vm.specification.name</td>    <td>VM specification name</td>       <td>{@code Dalvik Virtual Machine Specification}</td></tr>
1218      *
1219      * <tr><td>line.separator</td>     <td>The system line separator</td>         <td>{@code \n}</td></tr>
1220      *
1221      * <tr><td>os.arch</td>            <td>OS architecture</td>                   <td>{@code aarch64}</td></tr>
1222      * <tr><td>os.name</td>            <td>OS (kernel) name</td>                  <td>{@code Linux}</td></tr>
1223      * <tr><td>os.version</td>         <td>OS (kernel) version</td>               <td>{@code 5.10.98-g6ea688a79989}</td></tr>
1224      *
1225      * <tr><td>path.separator</td>     <td>See {@link java.io.File#pathSeparator}</td> <td>{@code :}</td></tr>
1226      *
1227      * <tr><td>user.dir</td>           <td>Base of non-absolute paths</td>        <td>{@code /}</td></tr>
1228      * <tr><td>user.home</td>          <td>(Not useful on Android)</td>           <td>Empty</td></tr>
1229      * <tr><td>user.name</td>          <td>(Not useful on Android)</td>           <td>Empty</td></tr>
1230      *
1231      * </table>
1232      * <p>
1233      * Multiple paths in a system property value are separated by the path
1234      * separator character of the platform.
1235      * <p>
1236      * Note that even if the security manager does not permit the
1237      * <code>getProperties</code> operation, it may choose to permit the
1238      * {@link #getProperty(String)} operation.
1239      *
1240      * @return     the system properties
1241      * @exception  SecurityException  if a security manager exists and its
1242      *             <code>checkPropertiesAccess</code> method doesn't allow access
1243      *              to the system properties.
1244      * @see        #setProperties
1245      * @see        java.lang.SecurityException
1246      * @see        java.lang.SecurityManager#checkPropertiesAccess()
1247      * @see        java.util.Properties
1248      */
getProperties()1249     public static Properties getProperties() {
1250         SecurityManager sm = getSecurityManager();
1251         if (sm != null) {
1252             sm.checkPropertiesAccess();
1253         }
1254 
1255         return props;
1256     }
1257 
1258     /**
1259      * Returns the system-dependent line separator string.  It always
1260      * returns the same value - the initial value of the {@linkplain
1261      * #getProperty(String) system property} {@code line.separator}.
1262      *
1263      * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
1264      * Windows systems it returns {@code "\r\n"}.
1265      *
1266      * @return the system-dependent line separator string
1267      * @since 1.7
1268      */
lineSeparator()1269     public static String lineSeparator() {
1270         return lineSeparator;
1271     }
1272 
1273     private static String lineSeparator;
1274 
1275 
1276     // Comment replaced with android one.
1277     /**
1278      * Attempts to set all system properties. Copies all properties from
1279      * {@code p} and discards system properties that are read only and cannot
1280      * be modified. See {@link #getProperty} for a list of such properties.
1281      */
setProperties(Properties props)1282     public static void setProperties(Properties props) {
1283         Properties baseProperties = new PropertiesWithNonOverrideableDefaults(unchangeableProps);
1284         if (props != null) {
1285             baseProperties.putAll(props);
1286         } else {
1287             setDefaultChangeableProperties(baseProperties);
1288         }
1289 
1290         System.props = baseProperties;
1291     }
1292 
1293     /**
1294      * Gets the system property indicated by the specified key.
1295      * <p>
1296      * First, if there is a security manager, its
1297      * <code>checkPropertyAccess</code> method is called with the key as
1298      * its argument. This may result in a SecurityException.
1299      * <p>
1300      * If there is no current set of system properties, a set of system
1301      * properties is first created and initialized in the same manner as
1302      * for the <code>getProperties</code> method.
1303      *
1304      * @param      key   the name of the system property.
1305      * @return     the string value of the system property,
1306      *             or <code>null</code> if there is no property with that key.
1307      *
1308      * @exception  SecurityException  if a security manager exists and its
1309      *             <code>checkPropertyAccess</code> method doesn't allow
1310      *              access to the specified system property.
1311      * @exception  NullPointerException if <code>key</code> is
1312      *             <code>null</code>.
1313      * @exception  IllegalArgumentException if <code>key</code> is empty.
1314      * @see        #setProperty
1315      * @see        java.lang.SecurityException
1316      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
1317      * @see        java.lang.System#getProperties()
1318      */
getProperty(String key)1319     public static String getProperty(String key) {
1320         checkKey(key);
1321         SecurityManager sm = getSecurityManager();
1322         if (sm != null) {
1323             sm.checkPropertyAccess(key);
1324         }
1325 
1326         return props.getProperty(key);
1327     }
1328 
1329     /**
1330      * Gets the system property indicated by the specified key.
1331      * <p>
1332      * First, if there is a security manager, its
1333      * <code>checkPropertyAccess</code> method is called with the
1334      * <code>key</code> as its argument.
1335      * <p>
1336      * If there is no current set of system properties, a set of system
1337      * properties is first created and initialized in the same manner as
1338      * for the <code>getProperties</code> method.
1339      *
1340      * @param      key   the name of the system property.
1341      * @param      def   a default value.
1342      * @return     the string value of the system property,
1343      *             or the default value if there is no property with that key.
1344      *
1345      * @exception  SecurityException  if a security manager exists and its
1346      *             <code>checkPropertyAccess</code> method doesn't allow
1347      *             access to the specified system property.
1348      * @exception  NullPointerException if <code>key</code> is
1349      *             <code>null</code>.
1350      * @exception  IllegalArgumentException if <code>key</code> is empty.
1351      * @see        #setProperty
1352      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
1353      * @see        java.lang.System#getProperties()
1354      */
getProperty(String key, String def)1355     public static String getProperty(String key, String def) {
1356         checkKey(key);
1357         SecurityManager sm = getSecurityManager();
1358         if (sm != null) {
1359             sm.checkPropertyAccess(key);
1360         }
1361 
1362         return props.getProperty(key, def);
1363     }
1364 
1365     /**
1366      * Sets the system property indicated by the specified key.
1367      * <p>
1368      * First, if a security manager exists, its
1369      * <code>SecurityManager.checkPermission</code> method
1370      * is called with a <code>PropertyPermission(key, "write")</code>
1371      * permission. This may result in a SecurityException being thrown.
1372      * If no exception is thrown, the specified property is set to the given
1373      * value.
1374      * <p>
1375      *
1376      * @param      key   the name of the system property.
1377      * @param      value the value of the system property.
1378      * @return     the previous value of the system property,
1379      *             or <code>null</code> if it did not have one.
1380      *
1381      * @exception  SecurityException  if a security manager exists and its
1382      *             <code>checkPermission</code> method doesn't allow
1383      *             setting of the specified property.
1384      * @exception  NullPointerException if <code>key</code> or
1385      *             <code>value</code> is <code>null</code>.
1386      * @exception  IllegalArgumentException if <code>key</code> is empty.
1387      * @see        #getProperty
1388      * @see        java.lang.System#getProperty(java.lang.String)
1389      * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
1390      * @see        java.util.PropertyPermission
1391      * @see        SecurityManager#checkPermission
1392      * @since      1.2
1393      */
setProperty(String key, String value)1394     public static String setProperty(String key, String value) {
1395         checkKey(key);
1396         SecurityManager sm = getSecurityManager();
1397         if (sm != null) {
1398             sm.checkPermission(new PropertyPermission(key,
1399                 SecurityConstants.PROPERTY_WRITE_ACTION));
1400         }
1401 
1402         return (String) props.setProperty(key, value);
1403     }
1404 
1405     /**
1406      * Removes the system property indicated by the specified key.
1407      * <p>
1408      * First, if a security manager exists, its
1409      * <code>SecurityManager.checkPermission</code> method
1410      * is called with a <code>PropertyPermission(key, "write")</code>
1411      * permission. This may result in a SecurityException being thrown.
1412      * If no exception is thrown, the specified property is removed.
1413      * <p>
1414      *
1415      * @param      key   the name of the system property to be removed.
1416      * @return     the previous string value of the system property,
1417      *             or <code>null</code> if there was no property with that key.
1418      *
1419      * @exception  SecurityException  if a security manager exists and its
1420      *             <code>checkPropertyAccess</code> method doesn't allow
1421      *              access to the specified system property.
1422      * @exception  NullPointerException if <code>key</code> is
1423      *             <code>null</code>.
1424      * @exception  IllegalArgumentException if <code>key</code> is empty.
1425      * @see        #getProperty
1426      * @see        #setProperty
1427      * @see        java.util.Properties
1428      * @see        java.lang.SecurityException
1429      * @see        java.lang.SecurityManager#checkPropertiesAccess()
1430      * @since 1.5
1431      */
clearProperty(String key)1432     public static String clearProperty(String key) {
1433         checkKey(key);
1434         SecurityManager sm = getSecurityManager();
1435         if (sm != null) {
1436             sm.checkPermission(new PropertyPermission(key, "write"));
1437         }
1438 
1439         return (String) props.remove(key);
1440     }
1441 
checkKey(String key)1442     private static void checkKey(String key) {
1443         if (key == null) {
1444             throw new NullPointerException("key can't be null");
1445         }
1446         if (key.equals("")) {
1447             throw new IllegalArgumentException("key can't be empty");
1448         }
1449     }
1450 
1451     /**
1452      * Gets the value of the specified environment variable. An
1453      * environment variable is a system-dependent external named
1454      * value.
1455      *
1456      * <p>If a security manager exists, its
1457      * {@link SecurityManager#checkPermission checkPermission}
1458      * method is called with a
1459      * <code>{@link RuntimePermission}("getenv."+name)</code>
1460      * permission.  This may result in a {@link SecurityException}
1461      * being thrown.  If no exception is thrown the value of the
1462      * variable <code>name</code> is returned.
1463      *
1464      * <p><a name="EnvironmentVSSystemProperties"><i>System
1465      * properties</i> and <i>environment variables</i></a> are both
1466      * conceptually mappings between names and values.  Both
1467      * mechanisms can be used to pass user-defined information to a
1468      * Java process.  Environment variables have a more global effect,
1469      * because they are visible to all descendants of the process
1470      * which defines them, not just the immediate Java subprocess.
1471      * They can have subtly different semantics, such as case
1472      * insensitivity, on different operating systems.  For these
1473      * reasons, environment variables are more likely to have
1474      * unintended side effects.  It is best to use system properties
1475      * where possible.  Environment variables should be used when a
1476      * global effect is desired, or when an external system interface
1477      * requires an environment variable (such as <code>PATH</code>).
1478      *
1479      * <p>On UNIX systems the alphabetic case of <code>name</code> is
1480      * typically significant, while on Microsoft Windows systems it is
1481      * typically not.  For example, the expression
1482      * <code>System.getenv("FOO").equals(System.getenv("foo"))</code>
1483      * is likely to be true on Microsoft Windows.
1484      *
1485      * @param  name the name of the environment variable
1486      * @return the string value of the variable, or <code>null</code>
1487      *         if the variable is not defined in the system environment
1488      * @throws NullPointerException if <code>name</code> is <code>null</code>
1489      * @throws SecurityException
1490      *         if a security manager exists and its
1491      *         {@link SecurityManager#checkPermission checkPermission}
1492      *         method doesn't allow access to the environment variable
1493      *         <code>name</code>
1494      * @see    #getenv()
1495      * @see    ProcessBuilder#environment()
1496      */
getenv(String name)1497     public static String getenv(String name) {
1498         if (name == null) {
1499             throw new NullPointerException("name == null");
1500         }
1501 
1502         return Libcore.os.getenv(name);
1503     }
1504 
1505 
1506     /**
1507      * Returns an unmodifiable string map view of the current system environment.
1508      * The environment is a system-dependent mapping from names to
1509      * values which is passed from parent to child processes.
1510      *
1511      * <p>If the system does not support environment variables, an
1512      * empty map is returned.
1513      *
1514      * <p>The returned map will never contain null keys or values.
1515      * Attempting to query the presence of a null key or value will
1516      * throw a {@link NullPointerException}.  Attempting to query
1517      * the presence of a key or value which is not of type
1518      * {@link String} will throw a {@link ClassCastException}.
1519      *
1520      * <p>The returned map and its collection views may not obey the
1521      * general contract of the {@link Object#equals} and
1522      * {@link Object#hashCode} methods.
1523      *
1524      * <p>The returned map is typically case-sensitive on all platforms.
1525      *
1526      * <p>If a security manager exists, its
1527      * {@link SecurityManager#checkPermission checkPermission}
1528      * method is called with a
1529      * <code>{@link RuntimePermission}("getenv.*")</code>
1530      * permission.  This may result in a {@link SecurityException} being
1531      * thrown.
1532      *
1533      * <p>When passing information to a Java subprocess,
1534      * <a href=#EnvironmentVSSystemProperties>system properties</a>
1535      * are generally preferred over environment variables.
1536      *
1537      * @return the environment as a map of variable names to values
1538      * @throws SecurityException
1539      *         if a security manager exists and its
1540      *         {@link SecurityManager#checkPermission checkPermission}
1541      *         method doesn't allow access to the process environment
1542      * @see    #getenv(String)
1543      * @see    ProcessBuilder#environment()
1544      * @since  1.5
1545      */
getenv()1546     public static java.util.Map<String,String> getenv() {
1547         SecurityManager sm = getSecurityManager();
1548         if (sm != null) {
1549             sm.checkPermission(new RuntimePermission("getenv.*"));
1550         }
1551 
1552         return ProcessEnvironment.getenv();
1553     }
1554 
1555     /**
1556      * Terminates the currently running Java Virtual Machine. The
1557      * argument serves as a status code; by convention, a nonzero status
1558      * code indicates abnormal termination.
1559      * <p>
1560      * This method calls the <code>exit</code> method in class
1561      * <code>Runtime</code>. This method never returns normally.
1562      * <p>
1563      * The call <code>System.exit(n)</code> is effectively equivalent to
1564      * the call:
1565      * <blockquote><pre>
1566      * Runtime.getRuntime().exit(n)
1567      * </pre></blockquote>
1568      *
1569      * @param      status   exit status.
1570      * @throws  SecurityException
1571      *        if a security manager exists and its <code>checkExit</code>
1572      *        method doesn't allow exit with the specified status.
1573      * @see        java.lang.Runtime#exit(int)
1574      */
exit(int status)1575     public static void exit(int status) {
1576         Runtime.getRuntime().exit(status);
1577     }
1578 
1579     /**
1580      * Runs the garbage collector.
1581      * <p>
1582      * Calling the <code>gc</code> method suggests that the Java Virtual
1583      * Machine expend effort toward recycling unused objects in order to
1584      * make the memory they currently occupy available for quick reuse.
1585      * When control returns from the method call, the Java Virtual
1586      * Machine has made a best effort to reclaim space from all discarded
1587      * objects.
1588      * <p>
1589      * The call <code>System.gc()</code> is effectively equivalent to the
1590      * call:
1591      * <blockquote><pre>
1592      * Runtime.getRuntime().gc()
1593      * </pre></blockquote>
1594      * At API level 34 and lower, this does nothing unless it is preceded or
1595      * followed by a runFinalization call.  Runtime.getRuntime().gc() always
1596      * attempts to reclaim space.
1597      * <p>
1598      * Calling this indiscriminately is likely to severely degrade performance.
1599      * Intended primarily for testing.
1600      *
1601      * @see     java.lang.Runtime#gc()
1602      */
gc()1603     public static void gc() {
1604         int targetSdkVersion = VMRuntime.getRuntime().getTargetSdkVersion();
1605         if (targetSdkVersion > 34) {
1606             Runtime.getRuntime().gc();
1607         } else {
1608             boolean shouldRunGC;
1609             synchronized (LOCK) {
1610                 shouldRunGC = targetSdkVersion <= 34 ? justRanFinalization : true;
1611                 if (shouldRunGC) {
1612                     justRanFinalization = false;
1613                 } else {
1614                     runGC = true;
1615                 }
1616             }
1617             if (shouldRunGC) {
1618                 Runtime.getRuntime().gc();
1619             }
1620         }
1621     }
1622 
1623     /**
1624      * Runs the finalization methods of any objects pending finalization.
1625      * <p>
1626      * Calling this method suggests that the Java Virtual Machine expend
1627      * effort toward running the <code>finalize</code> methods of objects
1628      * that have been found to be discarded but whose <code>finalize</code>
1629      * methods have not yet been run. When control returns from the
1630      * method call, the Java Virtual Machine has made a best effort to
1631      * complete all outstanding finalizations.
1632      * <p>
1633      * The call <code>System.runFinalization()</code> is effectively
1634      * equivalent to the call:
1635      * <blockquote><pre>
1636      * Runtime.getRuntime().runFinalization()
1637      * </pre></blockquote>
1638      *
1639      * @see     java.lang.Runtime#runFinalization()
1640      */
runFinalization()1641     public static void runFinalization() {
1642         int targetSdkVersion = VMRuntime.getRuntime().getTargetSdkVersion();
1643         if (targetSdkVersion <= 34) {
1644             boolean shouldRunGC;
1645             synchronized (LOCK) {
1646                 shouldRunGC = runGC;
1647                 runGC = false;
1648             }
1649             if (shouldRunGC) {
1650                 Runtime.getRuntime().gc();
1651             }
1652         }
1653         Runtime.getRuntime().runFinalization();
1654         if (targetSdkVersion <= 34) {
1655             synchronized (LOCK) {
1656                 justRanFinalization = true;
1657             }
1658         }
1659     }
1660 
1661     /**
1662      * Enable or disable finalization on exit; doing so specifies that the
1663      * finalizers of all objects that have finalizers that have not yet been
1664      * automatically invoked are to be run before the Java runtime exits.
1665      * By default, finalization on exit is disabled.
1666      *
1667      * <p>If there is a security manager,
1668      * its <code>checkExit</code> method is first called
1669      * with 0 as its argument to ensure the exit is allowed.
1670      * This could result in a SecurityException.
1671      *
1672      * @deprecated  This method is inherently unsafe.  It may result in
1673      *      finalizers being called on live objects while other threads are
1674      *      concurrently manipulating those objects, resulting in erratic
1675      *      behavior or deadlock.
1676      * @param value indicating enabling or disabling of finalization
1677      * @throws  SecurityException
1678      *        if a security manager exists and its <code>checkExit</code>
1679      *        method doesn't allow the exit.
1680      *
1681      * @see     java.lang.Runtime#exit(int)
1682      * @see     java.lang.Runtime#gc()
1683      * @see     java.lang.SecurityManager#checkExit(int)
1684      * @since   JDK1.1
1685      */
1686     @Deprecated
runFinalizersOnExit(boolean value)1687     public static void runFinalizersOnExit(boolean value) {
1688         Runtime.runFinalizersOnExit(value);
1689     }
1690 
1691     /**
1692      * Loads the native library specified by the filename argument.  The filename
1693      * argument must be an absolute path name.
1694      *
1695      * If the filename argument, when stripped of any platform-specific library
1696      * prefix, path, and file extension, indicates a library whose name is,
1697      * for example, L, and a native library called L is statically linked
1698      * with the VM, then the JNI_OnLoad_L function exported by the library
1699      * is invoked rather than attempting to load a dynamic library.
1700      * A filename matching the argument does not have to exist in the
1701      * file system.
1702      * See the JNI Specification for more details.
1703      *
1704      * Otherwise, the filename argument is mapped to a native library image in
1705      * an implementation-dependent manner.
1706      *
1707      * <p>
1708      * The call <code>System.load(name)</code> is effectively equivalent
1709      * to the call:
1710      * <blockquote><pre>
1711      * Runtime.getRuntime().load(name)
1712      * </pre></blockquote>
1713      *
1714      * @param      filename   the file to load.
1715      * @exception  SecurityException  if a security manager exists and its
1716      *             <code>checkLink</code> method doesn't allow
1717      *             loading of the specified dynamic library
1718      * @exception  UnsatisfiedLinkError  if either the filename is not an
1719      *             absolute path name, the native library is not statically
1720      *             linked with the VM, or the library cannot be mapped to
1721      *             a native library image by the host system.
1722      * @exception  NullPointerException if <code>filename</code> is
1723      *             <code>null</code>
1724      * @see        java.lang.Runtime#load(java.lang.String)
1725      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
1726      */
1727     @CallerSensitive
load(String filename)1728     public static void load(String filename) {
1729         Runtime.getRuntime().load0(Reflection.getCallerClass(), filename);
1730     }
1731 
1732     /**
1733      * Loads the native library specified by the <code>libname</code>
1734      * argument.  The <code>libname</code> argument must not contain any platform
1735      * specific prefix, file extension or path. If a native library
1736      * called <code>libname</code> is statically linked with the VM, then the
1737      * JNI_OnLoad_<code>libname</code> function exported by the library is invoked.
1738      * See the JNI Specification for more details.
1739      *
1740      * Otherwise, the libname argument is loaded from a system library
1741      * location and mapped to a native library image in an implementation-
1742      * dependent manner.
1743      * <p>
1744      * The call <code>System.loadLibrary(name)</code> is effectively
1745      * equivalent to the call
1746      * <blockquote><pre>
1747      * Runtime.getRuntime().loadLibrary(name)
1748      * </pre></blockquote>
1749      *
1750      * @param      libname   the name of the library.
1751      * @exception  SecurityException  if a security manager exists and its
1752      *             <code>checkLink</code> method doesn't allow
1753      *             loading of the specified dynamic library
1754      * @exception  UnsatisfiedLinkError if either the libname argument
1755      *             contains a file path, the native library is not statically
1756      *             linked with the VM,  or the library cannot be mapped to a
1757      *             native library image by the host system.
1758      * @exception  NullPointerException if <code>libname</code> is
1759      *             <code>null</code>
1760      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
1761      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
1762      */
1763     @CallerSensitive
loadLibrary(String libname)1764     public static void loadLibrary(String libname) {
1765         Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname);
1766     }
1767 
1768     /**
1769      * Maps a library name into a platform-specific string representing
1770      * a native library.
1771      *
1772      * @param      libname the name of the library.
1773      * @return     a platform-dependent native library name.
1774      * @exception  NullPointerException if <code>libname</code> is
1775      *             <code>null</code>
1776      * @see        java.lang.System#loadLibrary(java.lang.String)
1777      * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
1778      * @since      1.2
1779      */
mapLibraryName(String libname)1780     public static native String mapLibraryName(String libname);
1781 
1782     /**
1783      * Create PrintStream for stdout/err based on encoding.
1784      */
newPrintStream(FileOutputStream fos, String enc)1785     private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
1786        if (enc != null) {
1787             try {
1788                 return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
1789             } catch (UnsupportedEncodingException uee) {}
1790         }
1791         return new PrintStream(new BufferedOutputStream(fos, 128), true);
1792     }
1793 
1794 
1795     /**
1796      * Initialize the system class.  Called after thread initialization.
1797      */
1798     static {
1799         unchangeableProps = initUnchangeableSystemProperties();
1800         props = initProperties();
addLegacyLocaleSystemProperties()1801         addLegacyLocaleSystemProperties();
sun.misc.Version.initSystemProperties()1802         sun.misc.Version.initSystemProperties();
1803 
1804         // TODO: Confirm that this isn't something super important.
1805         // sun.misc.VM.saveAndRemoveProperties(props);
1806 
1807         lineSeparator = props.getProperty("line.separator");
1808 
1809         FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
1810         FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
1811         FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
1812         // BEGIN Android-changed: lower buffer size.
1813         // in = new BufferedInputStream(fdIn);
1814         in = new BufferedInputStream(fdIn, 128);
1815         // END Android-changed: lower buffer size.
1816         out = newPrintStream(fdOut, props.getProperty("sun.stdout.encoding"));
1817         err = newPrintStream(fdErr, props.getProperty("sun.stderr.encoding"));
1818 
1819         // Initialize any miscellenous operating system settings that need to be
1820         // set for the class libraries. Currently this is no-op everywhere except
1821         // for Windows where the process-wide error mode is set before the java.io
1822         // classes are used.
sun.misc.VM.initializeOSEnvironment()1823         sun.misc.VM.initializeOSEnvironment();
1824 
1825         // Subsystems that are invoked during initialization can invoke
1826         // sun.misc.VM.isBooted() in order to avoid doing things that should
1827         // wait until the application class loader has been set up.
1828         // IMPORTANT: Ensure that this remains the last initialization action!
sun.misc.VM.booted()1829         sun.misc.VM.booted();
jdk.internal.misc.VM.booted()1830         jdk.internal.misc.VM.booted();
1831     }
1832 
1833     /**
1834      * @hide internal use only
1835      */
logE(String message)1836     public static void logE(String message) {
1837         log('E', message, null);
1838     }
1839 
1840     /**
1841      * @hide internal use only
1842      */
logE(String message, Throwable th)1843     public static void logE(String message, Throwable th) {
1844         log('E', message, th);
1845     }
1846 
1847     /**
1848      * @hide internal use only
1849      */
logI(String message)1850     public static void logI(String message) {
1851         log('I', message, null);
1852     }
1853 
1854     /**
1855      * @hide internal use only
1856      */
logI(String message, Throwable th)1857     public static void logI(String message, Throwable th) {
1858         log('I', message, th);
1859     }
1860 
1861     /**
1862      * @hide internal use only
1863      */
logW(String message)1864     public static void logW(String message) {
1865         log('W', message, null);
1866     }
1867 
1868     /**
1869      * @hide internal use only
1870      */
logW(String message, Throwable th)1871     public static void logW(String message, Throwable th) {
1872         log('W', message, th);
1873     }
1874 
log(char type, String message, Throwable th)1875     private static native void log(char type, String message, Throwable th);
1876 }
1877