author | darcy |
Thu, 16 Feb 2017 19:08:17 -0800 | |
changeset 43891 | 59f9fbf2b7f0 |
parent 43221 | eef9383d25cb |
child 43894 | c316ff1ea2c7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
2 |
* Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
package java.lang; |
|
26 |
||
36511 | 27 |
import java.io.BufferedInputStream; |
28 |
import java.io.BufferedOutputStream; |
|
29 |
import java.io.Console; |
|
30 |
import java.io.FileDescriptor; |
|
31 |
import java.io.FileInputStream; |
|
32 |
import java.io.FileOutputStream; |
|
33 |
import java.io.IOException; |
|
34 |
import java.io.InputStream; |
|
35 |
import java.io.PrintStream; |
|
36 |
import java.io.UnsupportedEncodingException; |
|
37 |
import java.lang.annotation.Annotation; |
|
38 |
import java.lang.reflect.Constructor; |
|
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
39 |
import java.lang.reflect.Executable; |
36511 | 40 |
import java.lang.reflect.Layer; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
41 |
import java.lang.reflect.Method; |
36511 | 42 |
import java.lang.reflect.Modifier; |
43 |
import java.lang.reflect.Module; |
|
44 |
import java.net.URL; |
|
20805 | 45 |
import java.security.AccessControlContext; |
2 | 46 |
import java.util.Properties; |
47 |
import java.util.PropertyPermission; |
|
21358
d41ff832d4f6
8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents:
20831
diff
changeset
|
48 |
import java.util.Map; |
34370 | 49 |
import java.security.AccessController; |
50 |
import java.security.PrivilegedAction; |
|
2 | 51 |
import java.nio.channels.Channel; |
52 |
import java.nio.channels.spi.SelectorProvider; |
|
36972
27147cde3256
8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents:
36511
diff
changeset
|
53 |
import java.util.concurrent.ConcurrentHashMap; |
36511 | 54 |
import java.util.stream.Stream; |
55 |
||
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
56 |
import java.util.Objects; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
57 |
import java.util.ResourceBundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
58 |
import java.util.function.Supplier; |
2 | 59 |
import sun.nio.ch.Interruptible; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36972
diff
changeset
|
60 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36972
diff
changeset
|
61 |
import jdk.internal.reflect.Reflection; |
2 | 62 |
import sun.security.util.SecurityConstants; |
63 |
import sun.reflect.annotation.AnnotationType; |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29986
diff
changeset
|
64 |
import jdk.internal.HotSpotIntrinsicCandidate; |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
32649
diff
changeset
|
65 |
import jdk.internal.misc.JavaLangAccess;; |
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
32649
diff
changeset
|
66 |
import jdk.internal.misc.SharedSecrets;; |
34882 | 67 |
import jdk.internal.misc.VM; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
68 |
import jdk.internal.logger.LoggerFinderLoader; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
69 |
import jdk.internal.logger.LazyLoggers; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
70 |
import jdk.internal.logger.LocalizedLoggerWrapper; |
2 | 71 |
|
36511 | 72 |
import jdk.internal.module.ModuleBootstrap; |
73 |
||
2 | 74 |
/** |
75 |
* The <code>System</code> class contains several useful class fields |
|
76 |
* and methods. It cannot be instantiated. |
|
77 |
* |
|
78 |
* <p>Among the facilities provided by the <code>System</code> class |
|
79 |
* are standard input, standard output, and error output streams; |
|
80 |
* access to externally defined properties and environment |
|
81 |
* variables; a means of loading files and libraries; and a utility |
|
82 |
* method for quickly copying a portion of an array. |
|
83 |
* |
|
84 |
* @author unascribed |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
85 |
* @since 1.0 |
2 | 86 |
*/ |
87 |
public final class System { |
|
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
88 |
/* register the natives via the static initializer. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
89 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
90 |
* VM will invoke the initializeSystemClass method to complete |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
91 |
* the initialization for this class separated from clinit. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
92 |
* Note that to use properties set by the VM, see the constraints |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
93 |
* described in the initializeSystemClass method. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
94 |
*/ |
2 | 95 |
private static native void registerNatives(); |
96 |
static { |
|
97 |
registerNatives(); |
|
98 |
} |
|
99 |
||
100 |
/** Don't let anyone instantiate this class */ |
|
101 |
private System() { |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* The "standard" input stream. This stream is already |
|
106 |
* open and ready to supply input data. Typically this stream |
|
107 |
* corresponds to keyboard input or another input source specified by |
|
108 |
* the host environment or user. |
|
109 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32033
diff
changeset
|
110 |
public static final InputStream in = null; |
2 | 111 |
|
112 |
/** |
|
113 |
* The "standard" output stream. This stream is already |
|
114 |
* open and ready to accept output data. Typically this stream |
|
115 |
* corresponds to display output or another output destination |
|
116 |
* specified by the host environment or user. |
|
117 |
* <p> |
|
118 |
* For simple stand-alone Java applications, a typical way to write |
|
119 |
* a line of output data is: |
|
120 |
* <blockquote><pre> |
|
121 |
* System.out.println(data) |
|
122 |
* </pre></blockquote> |
|
123 |
* <p> |
|
124 |
* See the <code>println</code> methods in class <code>PrintStream</code>. |
|
125 |
* |
|
126 |
* @see java.io.PrintStream#println() |
|
127 |
* @see java.io.PrintStream#println(boolean) |
|
128 |
* @see java.io.PrintStream#println(char) |
|
129 |
* @see java.io.PrintStream#println(char[]) |
|
130 |
* @see java.io.PrintStream#println(double) |
|
131 |
* @see java.io.PrintStream#println(float) |
|
132 |
* @see java.io.PrintStream#println(int) |
|
133 |
* @see java.io.PrintStream#println(long) |
|
134 |
* @see java.io.PrintStream#println(java.lang.Object) |
|
135 |
* @see java.io.PrintStream#println(java.lang.String) |
|
136 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32033
diff
changeset
|
137 |
public static final PrintStream out = null; |
2 | 138 |
|
139 |
/** |
|
140 |
* The "standard" error output stream. This stream is already |
|
141 |
* open and ready to accept output data. |
|
142 |
* <p> |
|
143 |
* Typically this stream corresponds to display output or another |
|
144 |
* output destination specified by the host environment or user. By |
|
145 |
* convention, this output stream is used to display error messages |
|
146 |
* or other information that should come to the immediate attention |
|
147 |
* of a user even if the principal output stream, the value of the |
|
148 |
* variable <code>out</code>, has been redirected to a file or other |
|
149 |
* destination that is typically not continuously monitored. |
|
150 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32033
diff
changeset
|
151 |
public static final PrintStream err = null; |
2 | 152 |
|
153 |
/* The security manager for the system. |
|
154 |
*/ |
|
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
34372
diff
changeset
|
155 |
private static volatile SecurityManager security; |
2 | 156 |
|
157 |
/** |
|
158 |
* Reassigns the "standard" input stream. |
|
159 |
* |
|
160 |
* <p>First, if there is a security manager, its <code>checkPermission</code> |
|
161 |
* method is called with a <code>RuntimePermission("setIO")</code> permission |
|
162 |
* to see if it's ok to reassign the "standard" input stream. |
|
163 |
* |
|
164 |
* @param in the new standard input stream. |
|
165 |
* |
|
166 |
* @throws SecurityException |
|
167 |
* if a security manager exists and its |
|
168 |
* <code>checkPermission</code> method doesn't allow |
|
169 |
* reassigning of the standard input stream. |
|
170 |
* |
|
171 |
* @see SecurityManager#checkPermission |
|
172 |
* @see java.lang.RuntimePermission |
|
173 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
174 |
* @since 1.1 |
2 | 175 |
*/ |
176 |
public static void setIn(InputStream in) { |
|
177 |
checkIO(); |
|
178 |
setIn0(in); |
|
179 |
} |
|
180 |
||
181 |
/** |
|
182 |
* Reassigns the "standard" output stream. |
|
183 |
* |
|
184 |
* <p>First, if there is a security manager, its <code>checkPermission</code> |
|
185 |
* method is called with a <code>RuntimePermission("setIO")</code> permission |
|
186 |
* to see if it's ok to reassign the "standard" output stream. |
|
187 |
* |
|
188 |
* @param out the new standard output stream |
|
189 |
* |
|
190 |
* @throws SecurityException |
|
191 |
* if a security manager exists and its |
|
192 |
* <code>checkPermission</code> method doesn't allow |
|
193 |
* reassigning of the standard output stream. |
|
194 |
* |
|
195 |
* @see SecurityManager#checkPermission |
|
196 |
* @see java.lang.RuntimePermission |
|
197 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
198 |
* @since 1.1 |
2 | 199 |
*/ |
200 |
public static void setOut(PrintStream out) { |
|
201 |
checkIO(); |
|
202 |
setOut0(out); |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Reassigns the "standard" error output stream. |
|
207 |
* |
|
208 |
* <p>First, if there is a security manager, its <code>checkPermission</code> |
|
209 |
* method is called with a <code>RuntimePermission("setIO")</code> permission |
|
210 |
* to see if it's ok to reassign the "standard" error output stream. |
|
211 |
* |
|
212 |
* @param err the new standard error output stream. |
|
213 |
* |
|
214 |
* @throws SecurityException |
|
215 |
* if a security manager exists and its |
|
216 |
* <code>checkPermission</code> method doesn't allow |
|
217 |
* reassigning of the standard error output stream. |
|
218 |
* |
|
219 |
* @see SecurityManager#checkPermission |
|
220 |
* @see java.lang.RuntimePermission |
|
221 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
222 |
* @since 1.1 |
2 | 223 |
*/ |
224 |
public static void setErr(PrintStream err) { |
|
225 |
checkIO(); |
|
226 |
setErr0(err); |
|
227 |
} |
|
228 |
||
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
34372
diff
changeset
|
229 |
private static volatile Console cons; |
2 | 230 |
/** |
231 |
* Returns the unique {@link java.io.Console Console} object associated |
|
232 |
* with the current Java virtual machine, if any. |
|
233 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
31671
diff
changeset
|
234 |
* @return The system console, if any, otherwise {@code null}. |
2 | 235 |
* |
236 |
* @since 1.6 |
|
237 |
*/ |
|
238 |
public static Console console() { |
|
39826
5dba95a26226
8162563: Fix double checked locking in System.console()
martin
parents:
38861
diff
changeset
|
239 |
Console c; |
5dba95a26226
8162563: Fix double checked locking in System.console()
martin
parents:
38861
diff
changeset
|
240 |
if ((c = cons) == null) { |
2 | 241 |
synchronized (System.class) { |
39826
5dba95a26226
8162563: Fix double checked locking in System.console()
martin
parents:
38861
diff
changeset
|
242 |
if ((c = cons) == null) { |
5dba95a26226
8162563: Fix double checked locking in System.console()
martin
parents:
38861
diff
changeset
|
243 |
cons = c = SharedSecrets.getJavaIOAccess().console(); |
5dba95a26226
8162563: Fix double checked locking in System.console()
martin
parents:
38861
diff
changeset
|
244 |
} |
2 | 245 |
} |
246 |
} |
|
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
34372
diff
changeset
|
247 |
return c; |
2 | 248 |
} |
249 |
||
250 |
/** |
|
251 |
* Returns the channel inherited from the entity that created this |
|
252 |
* Java virtual machine. |
|
253 |
* |
|
254 |
* <p> This method returns the channel obtained by invoking the |
|
255 |
* {@link java.nio.channels.spi.SelectorProvider#inheritedChannel |
|
256 |
* inheritedChannel} method of the system-wide default |
|
257 |
* {@link java.nio.channels.spi.SelectorProvider} object. </p> |
|
258 |
* |
|
259 |
* <p> In addition to the network-oriented channels described in |
|
260 |
* {@link java.nio.channels.spi.SelectorProvider#inheritedChannel |
|
261 |
* inheritedChannel}, this method may return other kinds of |
|
262 |
* channels in the future. |
|
263 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
31671
diff
changeset
|
264 |
* @return The inherited channel, if any, otherwise {@code null}. |
2 | 265 |
* |
266 |
* @throws IOException |
|
267 |
* If an I/O error occurs |
|
268 |
* |
|
269 |
* @throws SecurityException |
|
270 |
* If a security manager is present and it does not |
|
271 |
* permit access to the channel. |
|
272 |
* |
|
273 |
* @since 1.5 |
|
274 |
*/ |
|
275 |
public static Channel inheritedChannel() throws IOException { |
|
276 |
return SelectorProvider.provider().inheritedChannel(); |
|
277 |
} |
|
278 |
||
279 |
private static void checkIO() { |
|
280 |
SecurityManager sm = getSecurityManager(); |
|
281 |
if (sm != null) { |
|
282 |
sm.checkPermission(new RuntimePermission("setIO")); |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
private static native void setIn0(InputStream in); |
|
287 |
private static native void setOut0(PrintStream out); |
|
288 |
private static native void setErr0(PrintStream err); |
|
289 |
||
290 |
/** |
|
291 |
* Sets the System security. |
|
292 |
* |
|
293 |
* <p> If there is a security manager already installed, this method first |
|
294 |
* calls the security manager's <code>checkPermission</code> method |
|
295 |
* with a <code>RuntimePermission("setSecurityManager")</code> |
|
296 |
* permission to ensure it's ok to replace the existing |
|
297 |
* security manager. |
|
298 |
* This may result in throwing a <code>SecurityException</code>. |
|
299 |
* |
|
300 |
* <p> Otherwise, the argument is established as the current |
|
301 |
* security manager. If the argument is <code>null</code> and no |
|
302 |
* security manager has been established, then no action is taken and |
|
303 |
* the method simply returns. |
|
304 |
* |
|
305 |
* @param s the security manager. |
|
306 |
* @exception SecurityException if the security manager has already |
|
307 |
* been set and its <code>checkPermission</code> method |
|
308 |
* doesn't allow it to be replaced. |
|
309 |
* @see #getSecurityManager |
|
310 |
* @see SecurityManager#checkPermission |
|
311 |
* @see java.lang.RuntimePermission |
|
312 |
*/ |
|
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
313 |
public static void setSecurityManager(final SecurityManager s) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
314 |
if (s != null) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
315 |
try { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
316 |
s.checkPackageAccess("java.lang"); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
317 |
} catch (Exception e) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
318 |
// no-op |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
42338
diff
changeset
|
319 |
} |
2 | 320 |
} |
321 |
setSecurityManager0(s); |
|
322 |
} |
|
323 |
||
324 |
private static synchronized |
|
325 |
void setSecurityManager0(final SecurityManager s) { |
|
326 |
SecurityManager sm = getSecurityManager(); |
|
327 |
if (sm != null) { |
|
328 |
// ask the currently installed security manager if we |
|
329 |
// can replace it. |
|
330 |
sm.checkPermission(new RuntimePermission |
|
331 |
("setSecurityManager")); |
|
332 |
} |
|
333 |
||
334 |
if ((s != null) && (s.getClass().getClassLoader() != null)) { |
|
335 |
// New security manager class is not on bootstrap classpath. |
|
336 |
// Cause policy to get initialized before we install the new |
|
337 |
// security manager, in order to prevent infinite loops when |
|
338 |
// trying to initialize the policy (which usually involves |
|
339 |
// accessing some security and/or system properties, which in turn |
|
340 |
// calls the installed security manager's checkPermission method |
|
341 |
// which will loop infinitely if there is a non-system class |
|
342 |
// (in this case: the new security manager class) on the stack). |
|
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
28668
diff
changeset
|
343 |
AccessController.doPrivileged(new PrivilegedAction<>() { |
2 | 344 |
public Object run() { |
345 |
s.getClass().getProtectionDomain().implies |
|
346 |
(SecurityConstants.ALL_PERMISSION); |
|
347 |
return null; |
|
348 |
} |
|
349 |
}); |
|
350 |
} |
|
351 |
||
352 |
security = s; |
|
353 |
} |
|
354 |
||
355 |
/** |
|
356 |
* Gets the system security interface. |
|
357 |
* |
|
358 |
* @return if a security manager has already been established for the |
|
359 |
* current application, then that security manager is returned; |
|
360 |
* otherwise, <code>null</code> is returned. |
|
361 |
* @see #setSecurityManager |
|
362 |
*/ |
|
363 |
public static SecurityManager getSecurityManager() { |
|
364 |
return security; |
|
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Returns the current time in milliseconds. Note that |
|
369 |
* while the unit of time of the return value is a millisecond, |
|
370 |
* the granularity of the value depends on the underlying |
|
371 |
* operating system and may be larger. For example, many |
|
372 |
* operating systems measure time in units of tens of |
|
373 |
* milliseconds. |
|
374 |
* |
|
375 |
* <p> See the description of the class <code>Date</code> for |
|
376 |
* a discussion of slight discrepancies that may arise between |
|
377 |
* "computer time" and coordinated universal time (UTC). |
|
378 |
* |
|
379 |
* @return the difference, measured in milliseconds, between |
|
380 |
* the current time and midnight, January 1, 1970 UTC. |
|
381 |
* @see java.util.Date |
|
382 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29986
diff
changeset
|
383 |
@HotSpotIntrinsicCandidate |
2 | 384 |
public static native long currentTimeMillis(); |
385 |
||
386 |
/** |
|
387 |
* Returns the current value of the running Java Virtual Machine's |
|
388 |
* high-resolution time source, in nanoseconds. |
|
389 |
* |
|
390 |
* <p>This method can only be used to measure elapsed time and is |
|
391 |
* not related to any other notion of system or wall-clock time. |
|
392 |
* The value returned represents nanoseconds since some fixed but |
|
393 |
* arbitrary <i>origin</i> time (perhaps in the future, so values |
|
394 |
* may be negative). The same origin is used by all invocations of |
|
395 |
* this method in an instance of a Java virtual machine; other |
|
396 |
* virtual machine instances are likely to use a different origin. |
|
397 |
* |
|
398 |
* <p>This method provides nanosecond precision, but not necessarily |
|
399 |
* nanosecond resolution (that is, how frequently the value changes) |
|
400 |
* - no guarantees are made except that the resolution is at least as |
|
401 |
* good as that of {@link #currentTimeMillis()}. |
|
402 |
* |
|
403 |
* <p>Differences in successive calls that span greater than |
|
404 |
* approximately 292 years (2<sup>63</sup> nanoseconds) will not |
|
405 |
* correctly compute elapsed time due to numerical overflow. |
|
406 |
* |
|
407 |
* <p>The values returned by this method become meaningful only when |
|
408 |
* the difference between two such values, obtained within the same |
|
409 |
* instance of a Java virtual machine, is computed. |
|
410 |
* |
|
28668 | 411 |
* <p>For example, to measure how long some code takes to execute: |
412 |
* <pre> {@code |
|
2 | 413 |
* long startTime = System.nanoTime(); |
414 |
* // ... the code being measured ... |
|
28668 | 415 |
* long elapsedNanos = System.nanoTime() - startTime;}</pre> |
2 | 416 |
* |
28668 | 417 |
* <p>To compare elapsed time against a timeout, use <pre> {@code |
418 |
* if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre> |
|
419 |
* instead of <pre> {@code |
|
420 |
* if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre> |
|
2 | 421 |
* because of the possibility of numerical overflow. |
422 |
* |
|
423 |
* @return the current value of the running Java Virtual Machine's |
|
424 |
* high-resolution time source, in nanoseconds |
|
425 |
* @since 1.5 |
|
426 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29986
diff
changeset
|
427 |
@HotSpotIntrinsicCandidate |
2 | 428 |
public static native long nanoTime(); |
429 |
||
430 |
/** |
|
431 |
* Copies an array from the specified source array, beginning at the |
|
432 |
* specified position, to the specified position of the destination array. |
|
433 |
* A subsequence of array components are copied from the source |
|
434 |
* array referenced by <code>src</code> to the destination array |
|
435 |
* referenced by <code>dest</code>. The number of components copied is |
|
436 |
* equal to the <code>length</code> argument. The components at |
|
437 |
* positions <code>srcPos</code> through |
|
438 |
* <code>srcPos+length-1</code> in the source array are copied into |
|
439 |
* positions <code>destPos</code> through |
|
440 |
* <code>destPos+length-1</code>, respectively, of the destination |
|
441 |
* array. |
|
442 |
* <p> |
|
443 |
* If the <code>src</code> and <code>dest</code> arguments refer to the |
|
444 |
* same array object, then the copying is performed as if the |
|
445 |
* components at positions <code>srcPos</code> through |
|
446 |
* <code>srcPos+length-1</code> were first copied to a temporary |
|
447 |
* array with <code>length</code> components and then the contents of |
|
448 |
* the temporary array were copied into positions |
|
449 |
* <code>destPos</code> through <code>destPos+length-1</code> of the |
|
450 |
* destination array. |
|
451 |
* <p> |
|
452 |
* If <code>dest</code> is <code>null</code>, then a |
|
453 |
* <code>NullPointerException</code> is thrown. |
|
454 |
* <p> |
|
455 |
* If <code>src</code> is <code>null</code>, then a |
|
456 |
* <code>NullPointerException</code> is thrown and the destination |
|
457 |
* array is not modified. |
|
458 |
* <p> |
|
459 |
* Otherwise, if any of the following is true, an |
|
460 |
* <code>ArrayStoreException</code> is thrown and the destination is |
|
461 |
* not modified: |
|
462 |
* <ul> |
|
463 |
* <li>The <code>src</code> argument refers to an object that is not an |
|
464 |
* array. |
|
465 |
* <li>The <code>dest</code> argument refers to an object that is not an |
|
466 |
* array. |
|
467 |
* <li>The <code>src</code> argument and <code>dest</code> argument refer |
|
468 |
* to arrays whose component types are different primitive types. |
|
469 |
* <li>The <code>src</code> argument refers to an array with a primitive |
|
470 |
* component type and the <code>dest</code> argument refers to an array |
|
471 |
* with a reference component type. |
|
472 |
* <li>The <code>src</code> argument refers to an array with a reference |
|
473 |
* component type and the <code>dest</code> argument refers to an array |
|
474 |
* with a primitive component type. |
|
475 |
* </ul> |
|
476 |
* <p> |
|
477 |
* Otherwise, if any of the following is true, an |
|
478 |
* <code>IndexOutOfBoundsException</code> is |
|
479 |
* thrown and the destination is not modified: |
|
480 |
* <ul> |
|
481 |
* <li>The <code>srcPos</code> argument is negative. |
|
482 |
* <li>The <code>destPos</code> argument is negative. |
|
483 |
* <li>The <code>length</code> argument is negative. |
|
484 |
* <li><code>srcPos+length</code> is greater than |
|
485 |
* <code>src.length</code>, the length of the source array. |
|
486 |
* <li><code>destPos+length</code> is greater than |
|
487 |
* <code>dest.length</code>, the length of the destination array. |
|
488 |
* </ul> |
|
489 |
* <p> |
|
490 |
* Otherwise, if any actual component of the source array from |
|
491 |
* position <code>srcPos</code> through |
|
492 |
* <code>srcPos+length-1</code> cannot be converted to the component |
|
493 |
* type of the destination array by assignment conversion, an |
|
494 |
* <code>ArrayStoreException</code> is thrown. In this case, let |
|
495 |
* <b><i>k</i></b> be the smallest nonnegative integer less than |
|
496 |
* length such that <code>src[srcPos+</code><i>k</i><code>]</code> |
|
497 |
* cannot be converted to the component type of the destination |
|
498 |
* array; when the exception is thrown, source array components from |
|
499 |
* positions <code>srcPos</code> through |
|
500 |
* <code>srcPos+</code><i>k</i><code>-1</code> |
|
501 |
* will already have been copied to destination array positions |
|
502 |
* <code>destPos</code> through |
|
503 |
* <code>destPos+</code><i>k</I><code>-1</code> and no other |
|
504 |
* positions of the destination array will have been modified. |
|
505 |
* (Because of the restrictions already itemized, this |
|
506 |
* paragraph effectively applies only to the situation where both |
|
507 |
* arrays have component types that are reference types.) |
|
508 |
* |
|
509 |
* @param src the source array. |
|
510 |
* @param srcPos starting position in the source array. |
|
511 |
* @param dest the destination array. |
|
512 |
* @param destPos starting position in the destination data. |
|
513 |
* @param length the number of array elements to be copied. |
|
514 |
* @exception IndexOutOfBoundsException if copying would cause |
|
515 |
* access of data outside array bounds. |
|
516 |
* @exception ArrayStoreException if an element in the <code>src</code> |
|
517 |
* array could not be stored into the <code>dest</code> array |
|
518 |
* because of a type mismatch. |
|
519 |
* @exception NullPointerException if either <code>src</code> or |
|
520 |
* <code>dest</code> is <code>null</code>. |
|
521 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29986
diff
changeset
|
522 |
@HotSpotIntrinsicCandidate |
2 | 523 |
public static native void arraycopy(Object src, int srcPos, |
524 |
Object dest, int destPos, |
|
525 |
int length); |
|
526 |
||
527 |
/** |
|
528 |
* Returns the same hash code for the given object as |
|
529 |
* would be returned by the default method hashCode(), |
|
530 |
* whether or not the given object's class overrides |
|
531 |
* hashCode(). |
|
532 |
* The hash code for the null reference is zero. |
|
533 |
* |
|
534 |
* @param x object for which the hashCode is to be calculated |
|
535 |
* @return the hashCode |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
536 |
* @since 1.1 |
43891
59f9fbf2b7f0
8172928: Add doc link from System.identityHashCode to Object.hashCode
darcy
parents:
43221
diff
changeset
|
537 |
* @see Object#hashCode |
59f9fbf2b7f0
8172928: Add doc link from System.identityHashCode to Object.hashCode
darcy
parents:
43221
diff
changeset
|
538 |
* @see java.util.Objects#hashCode(Object) |
2 | 539 |
*/ |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29986
diff
changeset
|
540 |
@HotSpotIntrinsicCandidate |
2 | 541 |
public static native int identityHashCode(Object x); |
542 |
||
543 |
/** |
|
544 |
* System properties. The following properties are guaranteed to be defined: |
|
545 |
* <dl> |
|
546 |
* <dt>java.version <dd>Java version number |
|
547 |
* <dt>java.vendor <dd>Java vendor specific string |
|
548 |
* <dt>java.vendor.url <dd>Java vendor URL |
|
549 |
* <dt>java.home <dd>Java installation directory |
|
550 |
* <dt>java.class.version <dd>Java class version number |
|
551 |
* <dt>java.class.path <dd>Java classpath |
|
552 |
* <dt>os.name <dd>Operating System Name |
|
553 |
* <dt>os.arch <dd>Operating System Architecture |
|
554 |
* <dt>os.version <dd>Operating System Version |
|
555 |
* <dt>file.separator <dd>File separator ("/" on Unix) |
|
556 |
* <dt>path.separator <dd>Path separator (":" on Unix) |
|
557 |
* <dt>line.separator <dd>Line separator ("\n" on Unix) |
|
558 |
* <dt>user.name <dd>User account name |
|
559 |
* <dt>user.home <dd>User home directory |
|
560 |
* <dt>user.dir <dd>User's current working directory |
|
561 |
* </dl> |
|
562 |
*/ |
|
563 |
||
564 |
private static Properties props; |
|
565 |
private static native Properties initProperties(Properties props); |
|
566 |
||
567 |
/** |
|
568 |
* Determines the current system properties. |
|
569 |
* <p> |
|
570 |
* First, if there is a security manager, its |
|
571 |
* <code>checkPropertiesAccess</code> method is called with no |
|
572 |
* arguments. This may result in a security exception. |
|
573 |
* <p> |
|
574 |
* The current set of system properties for use by the |
|
575 |
* {@link #getProperty(String)} method is returned as a |
|
576 |
* <code>Properties</code> object. If there is no current set of |
|
577 |
* system properties, a set of system properties is first created and |
|
578 |
* initialized. This set of system properties always includes values |
|
579 |
* for the following keys: |
|
580 |
* <table summary="Shows property keys and associated values"> |
|
581 |
* <tr><th>Key</th> |
|
582 |
* <th>Description of Associated Value</th></tr> |
|
583 |
* <tr><td><code>java.version</code></td> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
584 |
* <td>Java Runtime Environment version which may be interpreted |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
585 |
* as a {@link Runtime.Version}</td></tr> |
2 | 586 |
* <tr><td><code>java.vendor</code></td> |
14014 | 587 |
* <td>Java Runtime Environment vendor</td></tr> |
2 | 588 |
* <tr><td><code>java.vendor.url</code></td> |
589 |
* <td>Java vendor URL</td></tr> |
|
590 |
* <tr><td><code>java.home</code></td> |
|
591 |
* <td>Java installation directory</td></tr> |
|
592 |
* <tr><td><code>java.vm.specification.version</code></td> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
593 |
* <td>Java Virtual Machine specification version which may be |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
594 |
* interpreted as a {@link Runtime.Version}</td></tr> |
2 | 595 |
* <tr><td><code>java.vm.specification.vendor</code></td> |
596 |
* <td>Java Virtual Machine specification vendor</td></tr> |
|
597 |
* <tr><td><code>java.vm.specification.name</code></td> |
|
598 |
* <td>Java Virtual Machine specification name</td></tr> |
|
599 |
* <tr><td><code>java.vm.version</code></td> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
600 |
* <td>Java Virtual Machine implementation version which may be |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
601 |
* interpreted as a {@link Runtime.Version}</td></tr> |
2 | 602 |
* <tr><td><code>java.vm.vendor</code></td> |
603 |
* <td>Java Virtual Machine implementation vendor</td></tr> |
|
604 |
* <tr><td><code>java.vm.name</code></td> |
|
605 |
* <td>Java Virtual Machine implementation name</td></tr> |
|
606 |
* <tr><td><code>java.specification.version</code></td> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
607 |
* <td>Java Runtime Environment specification version which may be |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37780
diff
changeset
|
608 |
* interpreted as a {@link Runtime.Version}</td></tr> |
2 | 609 |
* <tr><td><code>java.specification.vendor</code></td> |
610 |
* <td>Java Runtime Environment specification vendor</td></tr> |
|
611 |
* <tr><td><code>java.specification.name</code></td> |
|
612 |
* <td>Java Runtime Environment specification name</td></tr> |
|
613 |
* <tr><td><code>java.class.version</code></td> |
|
614 |
* <td>Java class format version number</td></tr> |
|
615 |
* <tr><td><code>java.class.path</code></td> |
|
616 |
* <td>Java class path</td></tr> |
|
617 |
* <tr><td><code>java.library.path</code></td> |
|
618 |
* <td>List of paths to search when loading libraries</td></tr> |
|
619 |
* <tr><td><code>java.io.tmpdir</code></td> |
|
620 |
* <td>Default temp file path</td></tr> |
|
621 |
* <tr><td><code>java.compiler</code></td> |
|
622 |
* <td>Name of JIT compiler to use</td></tr> |
|
623 |
* <tr><td><code>os.name</code></td> |
|
624 |
* <td>Operating system name</td></tr> |
|
625 |
* <tr><td><code>os.arch</code></td> |
|
626 |
* <td>Operating system architecture</td></tr> |
|
627 |
* <tr><td><code>os.version</code></td> |
|
628 |
* <td>Operating system version</td></tr> |
|
629 |
* <tr><td><code>file.separator</code></td> |
|
630 |
* <td>File separator ("/" on UNIX)</td></tr> |
|
631 |
* <tr><td><code>path.separator</code></td> |
|
632 |
* <td>Path separator (":" on UNIX)</td></tr> |
|
633 |
* <tr><td><code>line.separator</code></td> |
|
634 |
* <td>Line separator ("\n" on UNIX)</td></tr> |
|
635 |
* <tr><td><code>user.name</code></td> |
|
636 |
* <td>User's account name</td></tr> |
|
637 |
* <tr><td><code>user.home</code></td> |
|
638 |
* <td>User's home directory</td></tr> |
|
639 |
* <tr><td><code>user.dir</code></td> |
|
640 |
* <td>User's current working directory</td></tr> |
|
641 |
* </table> |
|
642 |
* <p> |
|
643 |
* Multiple paths in a system property value are separated by the path |
|
644 |
* separator character of the platform. |
|
645 |
* <p> |
|
646 |
* Note that even if the security manager does not permit the |
|
647 |
* <code>getProperties</code> operation, it may choose to permit the |
|
648 |
* {@link #getProperty(String)} operation. |
|
649 |
* |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39826
diff
changeset
|
650 |
* @implNote In addition to the standard system properties, the system |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39826
diff
changeset
|
651 |
* properties may include the following keys: |
36511 | 652 |
* <table summary="Shows property keys and associated values"> |
653 |
* <tr><th>Key</th> |
|
654 |
* <th>Description of Associated Value</th></tr> |
|
655 |
* <tr><td>{@code jdk.module.path}</td> |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39826
diff
changeset
|
656 |
* <td>The application module path</td></tr> |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39826
diff
changeset
|
657 |
* <tr><td>{@code jdk.module.upgrade.path}</td> |
36511 | 658 |
* <td>The upgrade module path</td></tr> |
659 |
* <tr><td>{@code jdk.module.main}</td> |
|
660 |
* <td>The module name of the initial/main module</td></tr> |
|
661 |
* <tr><td>{@code jdk.module.main.class}</td> |
|
662 |
* <td>The main class name of the initial module</td></tr> |
|
663 |
* </table> |
|
664 |
* |
|
2 | 665 |
* @return the system properties |
666 |
* @exception SecurityException if a security manager exists and its |
|
667 |
* <code>checkPropertiesAccess</code> method doesn't allow access |
|
668 |
* to the system properties. |
|
669 |
* @see #setProperties |
|
670 |
* @see java.lang.SecurityException |
|
671 |
* @see java.lang.SecurityManager#checkPropertiesAccess() |
|
672 |
* @see java.util.Properties |
|
673 |
*/ |
|
674 |
public static Properties getProperties() { |
|
675 |
SecurityManager sm = getSecurityManager(); |
|
676 |
if (sm != null) { |
|
677 |
sm.checkPropertiesAccess(); |
|
678 |
} |
|
679 |
||
680 |
return props; |
|
681 |
} |
|
682 |
||
683 |
/** |
|
4355
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
684 |
* Returns the system-dependent line separator string. It always |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
685 |
* returns the same value - the initial value of the {@linkplain |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
686 |
* #getProperty(String) system property} {@code line.separator}. |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
687 |
* |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
688 |
* <p>On UNIX systems, it returns {@code "\n"}; on Microsoft |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
689 |
* Windows systems it returns {@code "\r\n"}. |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17426
diff
changeset
|
690 |
* |
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
17426
diff
changeset
|
691 |
* @return the system-dependent line separator string |
10360 | 692 |
* @since 1.7 |
4355
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
693 |
*/ |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
694 |
public static String lineSeparator() { |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
695 |
return lineSeparator; |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
696 |
} |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
697 |
|
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
698 |
private static String lineSeparator; |
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
699 |
|
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
700 |
/** |
2 | 701 |
* Sets the system properties to the <code>Properties</code> |
702 |
* argument. |
|
703 |
* <p> |
|
704 |
* First, if there is a security manager, its |
|
705 |
* <code>checkPropertiesAccess</code> method is called with no |
|
706 |
* arguments. This may result in a security exception. |
|
707 |
* <p> |
|
708 |
* The argument becomes the current set of system properties for use |
|
709 |
* by the {@link #getProperty(String)} method. If the argument is |
|
710 |
* <code>null</code>, then the current set of system properties is |
|
711 |
* forgotten. |
|
712 |
* |
|
713 |
* @param props the new system properties. |
|
714 |
* @exception SecurityException if a security manager exists and its |
|
715 |
* <code>checkPropertiesAccess</code> method doesn't allow access |
|
716 |
* to the system properties. |
|
717 |
* @see #getProperties |
|
718 |
* @see java.util.Properties |
|
719 |
* @see java.lang.SecurityException |
|
720 |
* @see java.lang.SecurityManager#checkPropertiesAccess() |
|
721 |
*/ |
|
722 |
public static void setProperties(Properties props) { |
|
723 |
SecurityManager sm = getSecurityManager(); |
|
724 |
if (sm != null) { |
|
725 |
sm.checkPropertiesAccess(); |
|
726 |
} |
|
727 |
if (props == null) { |
|
728 |
props = new Properties(); |
|
729 |
initProperties(props); |
|
730 |
} |
|
731 |
System.props = props; |
|
732 |
} |
|
733 |
||
734 |
/** |
|
735 |
* Gets the system property indicated by the specified key. |
|
736 |
* <p> |
|
737 |
* First, if there is a security manager, its |
|
738 |
* <code>checkPropertyAccess</code> method is called with the key as |
|
739 |
* its argument. This may result in a SecurityException. |
|
740 |
* <p> |
|
741 |
* If there is no current set of system properties, a set of system |
|
742 |
* properties is first created and initialized in the same manner as |
|
743 |
* for the <code>getProperties</code> method. |
|
744 |
* |
|
745 |
* @param key the name of the system property. |
|
746 |
* @return the string value of the system property, |
|
747 |
* or <code>null</code> if there is no property with that key. |
|
748 |
* |
|
749 |
* @exception SecurityException if a security manager exists and its |
|
750 |
* <code>checkPropertyAccess</code> method doesn't allow |
|
751 |
* access to the specified system property. |
|
752 |
* @exception NullPointerException if <code>key</code> is |
|
753 |
* <code>null</code>. |
|
754 |
* @exception IllegalArgumentException if <code>key</code> is empty. |
|
755 |
* @see #setProperty |
|
756 |
* @see java.lang.SecurityException |
|
757 |
* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) |
|
758 |
* @see java.lang.System#getProperties() |
|
759 |
*/ |
|
760 |
public static String getProperty(String key) { |
|
761 |
checkKey(key); |
|
762 |
SecurityManager sm = getSecurityManager(); |
|
763 |
if (sm != null) { |
|
764 |
sm.checkPropertyAccess(key); |
|
765 |
} |
|
766 |
||
767 |
return props.getProperty(key); |
|
768 |
} |
|
769 |
||
770 |
/** |
|
771 |
* Gets the system property indicated by the specified key. |
|
772 |
* <p> |
|
773 |
* First, if there is a security manager, its |
|
774 |
* <code>checkPropertyAccess</code> method is called with the |
|
775 |
* <code>key</code> as its argument. |
|
776 |
* <p> |
|
777 |
* If there is no current set of system properties, a set of system |
|
778 |
* properties is first created and initialized in the same manner as |
|
779 |
* for the <code>getProperties</code> method. |
|
780 |
* |
|
781 |
* @param key the name of the system property. |
|
782 |
* @param def a default value. |
|
783 |
* @return the string value of the system property, |
|
784 |
* or the default value if there is no property with that key. |
|
785 |
* |
|
786 |
* @exception SecurityException if a security manager exists and its |
|
787 |
* <code>checkPropertyAccess</code> method doesn't allow |
|
788 |
* access to the specified system property. |
|
789 |
* @exception NullPointerException if <code>key</code> is |
|
790 |
* <code>null</code>. |
|
791 |
* @exception IllegalArgumentException if <code>key</code> is empty. |
|
792 |
* @see #setProperty |
|
793 |
* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) |
|
794 |
* @see java.lang.System#getProperties() |
|
795 |
*/ |
|
796 |
public static String getProperty(String key, String def) { |
|
797 |
checkKey(key); |
|
798 |
SecurityManager sm = getSecurityManager(); |
|
799 |
if (sm != null) { |
|
800 |
sm.checkPropertyAccess(key); |
|
801 |
} |
|
802 |
||
803 |
return props.getProperty(key, def); |
|
804 |
} |
|
805 |
||
806 |
/** |
|
807 |
* Sets the system property indicated by the specified key. |
|
808 |
* <p> |
|
809 |
* First, if a security manager exists, its |
|
810 |
* <code>SecurityManager.checkPermission</code> method |
|
811 |
* is called with a <code>PropertyPermission(key, "write")</code> |
|
812 |
* permission. This may result in a SecurityException being thrown. |
|
813 |
* If no exception is thrown, the specified property is set to the given |
|
814 |
* value. |
|
815 |
* |
|
816 |
* @param key the name of the system property. |
|
817 |
* @param value the value of the system property. |
|
818 |
* @return the previous value of the system property, |
|
819 |
* or <code>null</code> if it did not have one. |
|
820 |
* |
|
821 |
* @exception SecurityException if a security manager exists and its |
|
822 |
* <code>checkPermission</code> method doesn't allow |
|
823 |
* setting of the specified property. |
|
824 |
* @exception NullPointerException if <code>key</code> or |
|
825 |
* <code>value</code> is <code>null</code>. |
|
826 |
* @exception IllegalArgumentException if <code>key</code> is empty. |
|
827 |
* @see #getProperty |
|
828 |
* @see java.lang.System#getProperty(java.lang.String) |
|
829 |
* @see java.lang.System#getProperty(java.lang.String, java.lang.String) |
|
830 |
* @see java.util.PropertyPermission |
|
831 |
* @see SecurityManager#checkPermission |
|
832 |
* @since 1.2 |
|
833 |
*/ |
|
834 |
public static String setProperty(String key, String value) { |
|
835 |
checkKey(key); |
|
836 |
SecurityManager sm = getSecurityManager(); |
|
837 |
if (sm != null) { |
|
838 |
sm.checkPermission(new PropertyPermission(key, |
|
839 |
SecurityConstants.PROPERTY_WRITE_ACTION)); |
|
840 |
} |
|
841 |
||
842 |
return (String) props.setProperty(key, value); |
|
843 |
} |
|
844 |
||
845 |
/** |
|
846 |
* Removes the system property indicated by the specified key. |
|
847 |
* <p> |
|
848 |
* First, if a security manager exists, its |
|
849 |
* <code>SecurityManager.checkPermission</code> method |
|
850 |
* is called with a <code>PropertyPermission(key, "write")</code> |
|
851 |
* permission. This may result in a SecurityException being thrown. |
|
852 |
* If no exception is thrown, the specified property is removed. |
|
853 |
* |
|
854 |
* @param key the name of the system property to be removed. |
|
855 |
* @return the previous string value of the system property, |
|
856 |
* or <code>null</code> if there was no property with that key. |
|
857 |
* |
|
858 |
* @exception SecurityException if a security manager exists and its |
|
859 |
* <code>checkPropertyAccess</code> method doesn't allow |
|
860 |
* access to the specified system property. |
|
861 |
* @exception NullPointerException if <code>key</code> is |
|
862 |
* <code>null</code>. |
|
863 |
* @exception IllegalArgumentException if <code>key</code> is empty. |
|
864 |
* @see #getProperty |
|
865 |
* @see #setProperty |
|
866 |
* @see java.util.Properties |
|
867 |
* @see java.lang.SecurityException |
|
868 |
* @see java.lang.SecurityManager#checkPropertiesAccess() |
|
869 |
* @since 1.5 |
|
870 |
*/ |
|
871 |
public static String clearProperty(String key) { |
|
872 |
checkKey(key); |
|
873 |
SecurityManager sm = getSecurityManager(); |
|
874 |
if (sm != null) { |
|
875 |
sm.checkPermission(new PropertyPermission(key, "write")); |
|
876 |
} |
|
877 |
||
878 |
return (String) props.remove(key); |
|
879 |
} |
|
880 |
||
881 |
private static void checkKey(String key) { |
|
882 |
if (key == null) { |
|
883 |
throw new NullPointerException("key can't be null"); |
|
884 |
} |
|
885 |
if (key.equals("")) { |
|
886 |
throw new IllegalArgumentException("key can't be empty"); |
|
887 |
} |
|
888 |
} |
|
889 |
||
890 |
/** |
|
891 |
* Gets the value of the specified environment variable. An |
|
892 |
* environment variable is a system-dependent external named |
|
893 |
* value. |
|
894 |
* |
|
895 |
* <p>If a security manager exists, its |
|
896 |
* {@link SecurityManager#checkPermission checkPermission} |
|
897 |
* method is called with a |
|
898 |
* <code>{@link RuntimePermission}("getenv."+name)</code> |
|
899 |
* permission. This may result in a {@link SecurityException} |
|
900 |
* being thrown. If no exception is thrown the value of the |
|
901 |
* variable <code>name</code> is returned. |
|
902 |
* |
|
903 |
* <p><a name="EnvironmentVSSystemProperties"><i>System |
|
904 |
* properties</i> and <i>environment variables</i></a> are both |
|
905 |
* conceptually mappings between names and values. Both |
|
906 |
* mechanisms can be used to pass user-defined information to a |
|
907 |
* Java process. Environment variables have a more global effect, |
|
908 |
* because they are visible to all descendants of the process |
|
909 |
* which defines them, not just the immediate Java subprocess. |
|
910 |
* They can have subtly different semantics, such as case |
|
911 |
* insensitivity, on different operating systems. For these |
|
912 |
* reasons, environment variables are more likely to have |
|
913 |
* unintended side effects. It is best to use system properties |
|
914 |
* where possible. Environment variables should be used when a |
|
915 |
* global effect is desired, or when an external system interface |
|
916 |
* requires an environment variable (such as <code>PATH</code>). |
|
917 |
* |
|
918 |
* <p>On UNIX systems the alphabetic case of <code>name</code> is |
|
919 |
* typically significant, while on Microsoft Windows systems it is |
|
920 |
* typically not. For example, the expression |
|
921 |
* <code>System.getenv("FOO").equals(System.getenv("foo"))</code> |
|
922 |
* is likely to be true on Microsoft Windows. |
|
923 |
* |
|
924 |
* @param name the name of the environment variable |
|
925 |
* @return the string value of the variable, or <code>null</code> |
|
926 |
* if the variable is not defined in the system environment |
|
927 |
* @throws NullPointerException if <code>name</code> is <code>null</code> |
|
928 |
* @throws SecurityException |
|
929 |
* if a security manager exists and its |
|
930 |
* {@link SecurityManager#checkPermission checkPermission} |
|
931 |
* method doesn't allow access to the environment variable |
|
932 |
* <code>name</code> |
|
933 |
* @see #getenv() |
|
934 |
* @see ProcessBuilder#environment() |
|
935 |
*/ |
|
936 |
public static String getenv(String name) { |
|
937 |
SecurityManager sm = getSecurityManager(); |
|
938 |
if (sm != null) { |
|
939 |
sm.checkPermission(new RuntimePermission("getenv."+name)); |
|
940 |
} |
|
941 |
||
942 |
return ProcessEnvironment.getenv(name); |
|
943 |
} |
|
944 |
||
945 |
||
946 |
/** |
|
947 |
* Returns an unmodifiable string map view of the current system environment. |
|
948 |
* The environment is a system-dependent mapping from names to |
|
949 |
* values which is passed from parent to child processes. |
|
950 |
* |
|
951 |
* <p>If the system does not support environment variables, an |
|
952 |
* empty map is returned. |
|
953 |
* |
|
954 |
* <p>The returned map will never contain null keys or values. |
|
955 |
* Attempting to query the presence of a null key or value will |
|
956 |
* throw a {@link NullPointerException}. Attempting to query |
|
957 |
* the presence of a key or value which is not of type |
|
958 |
* {@link String} will throw a {@link ClassCastException}. |
|
959 |
* |
|
960 |
* <p>The returned map and its collection views may not obey the |
|
961 |
* general contract of the {@link Object#equals} and |
|
962 |
* {@link Object#hashCode} methods. |
|
963 |
* |
|
964 |
* <p>The returned map is typically case-sensitive on all platforms. |
|
965 |
* |
|
966 |
* <p>If a security manager exists, its |
|
967 |
* {@link SecurityManager#checkPermission checkPermission} |
|
968 |
* method is called with a |
|
969 |
* <code>{@link RuntimePermission}("getenv.*")</code> |
|
970 |
* permission. This may result in a {@link SecurityException} being |
|
971 |
* thrown. |
|
972 |
* |
|
973 |
* <p>When passing information to a Java subprocess, |
|
974 |
* <a href=#EnvironmentVSSystemProperties>system properties</a> |
|
975 |
* are generally preferred over environment variables. |
|
976 |
* |
|
977 |
* @return the environment as a map of variable names to values |
|
978 |
* @throws SecurityException |
|
979 |
* if a security manager exists and its |
|
980 |
* {@link SecurityManager#checkPermission checkPermission} |
|
981 |
* method doesn't allow access to the process environment |
|
982 |
* @see #getenv(String) |
|
983 |
* @see ProcessBuilder#environment() |
|
984 |
* @since 1.5 |
|
985 |
*/ |
|
986 |
public static java.util.Map<String,String> getenv() { |
|
987 |
SecurityManager sm = getSecurityManager(); |
|
988 |
if (sm != null) { |
|
989 |
sm.checkPermission(new RuntimePermission("getenv.*")); |
|
990 |
} |
|
991 |
||
992 |
return ProcessEnvironment.getenv(); |
|
993 |
} |
|
994 |
||
995 |
/** |
|
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
996 |
* {@code System.Logger} instances log messages that will be |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
997 |
* routed to the underlying logging framework the {@link System.LoggerFinder |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
998 |
* LoggerFinder} uses. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
999 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1000 |
* {@code System.Logger} instances are typically obtained from |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1001 |
* the {@link java.lang.System System} class, by calling |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1002 |
* {@link java.lang.System#getLogger(java.lang.String) System.getLogger(loggerName)} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1003 |
* or {@link java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1004 |
* System.getLogger(loggerName, bundle)}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1005 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1006 |
* @see java.lang.System#getLogger(java.lang.String) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1007 |
* @see java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1008 |
* @see java.lang.System.LoggerFinder |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1009 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1010 |
* @since 9 |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1011 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1012 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1013 |
public interface Logger { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1014 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1015 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1016 |
* System {@linkplain Logger loggers} levels. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1017 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1018 |
* A level has a {@linkplain #getName() name} and {@linkplain |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1019 |
* #getSeverity() severity}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1020 |
* Level values are {@link #ALL}, {@link #TRACE}, {@link #DEBUG}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1021 |
* {@link #INFO}, {@link #WARNING}, {@link #ERROR}, {@link #OFF}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1022 |
* by order of increasing severity. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1023 |
* <br> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1024 |
* {@link #ALL} and {@link #OFF} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1025 |
* are simple markers with severities mapped respectively to |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1026 |
* {@link java.lang.Integer#MIN_VALUE Integer.MIN_VALUE} and |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1027 |
* {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1028 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1029 |
* <b>Severity values and Mapping to {@code java.util.logging.Level}.</b> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1030 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1031 |
* {@linkplain System.Logger.Level System logger levels} are mapped to |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1032 |
* {@linkplain java.util.logging.Level java.util.logging levels} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1033 |
* of corresponding severity. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1034 |
* <br>The mapping is as follows: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1035 |
* <br><br> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1036 |
* <table border="1"> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1037 |
* <caption>System.Logger Severity Level Mapping</caption> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1038 |
* <tr><td><b>System.Logger Levels</b></td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1039 |
* <td>{@link Logger.Level#ALL ALL}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1040 |
* <td>{@link Logger.Level#TRACE TRACE}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1041 |
* <td>{@link Logger.Level#DEBUG DEBUG}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1042 |
* <td>{@link Logger.Level#INFO INFO}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1043 |
* <td>{@link Logger.Level#WARNING WARNING}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1044 |
* <td>{@link Logger.Level#ERROR ERROR}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1045 |
* <td>{@link Logger.Level#OFF OFF}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1046 |
* </tr> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1047 |
* <tr><td><b>java.util.logging Levels</b></td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1048 |
* <td>{@link java.util.logging.Level#ALL ALL}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1049 |
* <td>{@link java.util.logging.Level#FINER FINER}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1050 |
* <td>{@link java.util.logging.Level#FINE FINE}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1051 |
* <td>{@link java.util.logging.Level#INFO INFO}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1052 |
* <td>{@link java.util.logging.Level#WARNING WARNING}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1053 |
* <td>{@link java.util.logging.Level#SEVERE SEVERE}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1054 |
* <td>{@link java.util.logging.Level#OFF OFF}</td> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1055 |
* </tr> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1056 |
* </table> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1057 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1058 |
* @since 9 |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1059 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1060 |
* @see java.lang.System.LoggerFinder |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1061 |
* @see java.lang.System.Logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1062 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1063 |
public enum Level { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1064 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1065 |
// for convenience, we're reusing java.util.logging.Level int values |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1066 |
// the mapping logic in sun.util.logging.PlatformLogger depends |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1067 |
// on this. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1068 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1069 |
* A marker to indicate that all levels are enabled. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1070 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1071 |
* {@link Integer#MIN_VALUE}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1072 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1073 |
ALL(Integer.MIN_VALUE), // typically mapped to/from j.u.l.Level.ALL |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1074 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1075 |
* {@code TRACE} level: usually used to log diagnostic information. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1076 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1077 |
* {@code 400}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1078 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1079 |
TRACE(400), // typically mapped to/from j.u.l.Level.FINER |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1080 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1081 |
* {@code DEBUG} level: usually used to log debug information traces. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1082 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1083 |
* {@code 500}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1084 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1085 |
DEBUG(500), // typically mapped to/from j.u.l.Level.FINEST/FINE/CONFIG |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1086 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1087 |
* {@code INFO} level: usually used to log information messages. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1088 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1089 |
* {@code 800}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1090 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1091 |
INFO(800), // typically mapped to/from j.u.l.Level.INFO |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1092 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1093 |
* {@code WARNING} level: usually used to log warning messages. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1094 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1095 |
* {@code 900}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1096 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1097 |
WARNING(900), // typically mapped to/from j.u.l.Level.WARNING |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1098 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1099 |
* {@code ERROR} level: usually used to log error messages. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1100 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1101 |
* {@code 1000}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1102 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1103 |
ERROR(1000), // typically mapped to/from j.u.l.Level.SEVERE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1104 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1105 |
* A marker to indicate that all levels are disabled. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1106 |
* This level {@linkplain #getSeverity() severity} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1107 |
* {@link Integer#MAX_VALUE}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1108 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1109 |
OFF(Integer.MAX_VALUE); // typically mapped to/from j.u.l.Level.OFF |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1110 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1111 |
private final int severity; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1112 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1113 |
private Level(int severity) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1114 |
this.severity = severity; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1115 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1116 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1117 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1118 |
* Returns the name of this level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1119 |
* @return this level {@linkplain #name()}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1120 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1121 |
public final String getName() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1122 |
return name(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1123 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1124 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1125 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1126 |
* Returns the severity of this level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1127 |
* A higher severity means a more severe condition. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1128 |
* @return this level severity. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1129 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1130 |
public final int getSeverity() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1131 |
return severity; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1132 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1133 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1134 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1135 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1136 |
* Returns the name of this logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1137 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1138 |
* @return the logger name. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1139 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1140 |
public String getName(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1141 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1142 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1143 |
* Checks if a message of the given level would be logged by |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1144 |
* this logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1145 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1146 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1147 |
* @return {@code true} if the given log message level is currently |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1148 |
* being logged. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1149 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1150 |
* @throws NullPointerException if {@code level} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1151 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1152 |
public boolean isLoggable(Level level); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1153 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1154 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1155 |
* Logs a message. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1156 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1157 |
* @implSpec The default implementation for this method calls |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1158 |
* {@code this.log(level, (ResourceBundle)null, msg, (Object[])null);} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1159 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1160 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1161 |
* @param msg the string message (or a key in the message catalog, if |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1162 |
* this logger is a {@link |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1163 |
* LoggerFinder#getLocalizedLogger(java.lang.String, |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1164 |
* java.util.ResourceBundle, java.lang.reflect.Module) localized logger}); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1165 |
* can be {@code null}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1166 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1167 |
* @throws NullPointerException if {@code level} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1168 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1169 |
public default void log(Level level, String msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1170 |
log(level, (ResourceBundle) null, msg, (Object[]) null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1171 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1172 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1173 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1174 |
* Logs a lazily supplied message. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1175 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1176 |
* If the logger is currently enabled for the given log message level |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1177 |
* then a message is logged that is the result produced by the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1178 |
* given supplier function. Otherwise, the supplier is not operated on. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1179 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1180 |
* @implSpec When logging is enabled for the given level, the default |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1181 |
* implementation for this method calls |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1182 |
* {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), (Object[])null);} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1183 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1184 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1185 |
* @param msgSupplier a supplier function that produces a message. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1186 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1187 |
* @throws NullPointerException if {@code level} is {@code null}, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1188 |
* or {@code msgSupplier} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1189 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1190 |
public default void log(Level level, Supplier<String> msgSupplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1191 |
Objects.requireNonNull(msgSupplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1192 |
if (isLoggable(Objects.requireNonNull(level))) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1193 |
log(level, (ResourceBundle) null, msgSupplier.get(), (Object[]) null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1194 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1195 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1196 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1197 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1198 |
* Logs a message produced from the given object. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1199 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1200 |
* If the logger is currently enabled for the given log message level then |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1201 |
* a message is logged that, by default, is the result produced from |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1202 |
* calling toString on the given object. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1203 |
* Otherwise, the object is not operated on. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1204 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1205 |
* @implSpec When logging is enabled for the given level, the default |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1206 |
* implementation for this method calls |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1207 |
* {@code this.log(level, (ResourceBundle)null, obj.toString(), (Object[])null);} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1208 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1209 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1210 |
* @param obj the object to log. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1211 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1212 |
* @throws NullPointerException if {@code level} is {@code null}, or |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1213 |
* {@code obj} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1214 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1215 |
public default void log(Level level, Object obj) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1216 |
Objects.requireNonNull(obj); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1217 |
if (isLoggable(Objects.requireNonNull(level))) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1218 |
this.log(level, (ResourceBundle) null, obj.toString(), (Object[]) null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1219 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1220 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1221 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1222 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1223 |
* Logs a message associated with a given throwable. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1224 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1225 |
* @implSpec The default implementation for this method calls |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1226 |
* {@code this.log(level, (ResourceBundle)null, msg, thrown);} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1227 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1228 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1229 |
* @param msg the string message (or a key in the message catalog, if |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1230 |
* this logger is a {@link |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1231 |
* LoggerFinder#getLocalizedLogger(java.lang.String, |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1232 |
* java.util.ResourceBundle, java.lang.reflect.Module) localized logger}); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1233 |
* can be {@code null}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1234 |
* @param thrown a {@code Throwable} associated with the log message; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1235 |
* can be {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1236 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1237 |
* @throws NullPointerException if {@code level} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1238 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1239 |
public default void log(Level level, String msg, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1240 |
this.log(level, null, msg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1241 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1242 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1243 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1244 |
* Logs a lazily supplied message associated with a given throwable. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1245 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1246 |
* If the logger is currently enabled for the given log message level |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1247 |
* then a message is logged that is the result produced by the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1248 |
* given supplier function. Otherwise, the supplier is not operated on. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1249 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1250 |
* @implSpec When logging is enabled for the given level, the default |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1251 |
* implementation for this method calls |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1252 |
* {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), thrown);} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1253 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1254 |
* @param level one of the log message level identifiers. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1255 |
* @param msgSupplier a supplier function that produces a message. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1256 |
* @param thrown a {@code Throwable} associated with log message; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1257 |
* can be {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1258 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1259 |
* @throws NullPointerException if {@code level} is {@code null}, or |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1260 |
* {@code msgSupplier} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1261 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1262 |
public default void log(Level level, Supplier<String> msgSupplier, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1263 |
Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1264 |
Objects.requireNonNull(msgSupplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1265 |
if (isLoggable(Objects.requireNonNull(level))) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1266 |
this.log(level, null, msgSupplier.get(), thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1267 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1268 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1269 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1270 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1271 |
* Logs a message with an optional list of parameters. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1272 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1273 |
* @implSpec The default implementation for this method calls |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1274 |
* {@code this.log(level, (ResourceBundle)null, format, params);} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1275 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1276 |
* @param level one of the log message level identifiers. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1277 |
* @param format the string message format in {@link |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1278 |
* java.text.MessageFormat} format, (or a key in the message |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1279 |
* catalog, if this logger is a {@link |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1280 |
* LoggerFinder#getLocalizedLogger(java.lang.String, |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1281 |
* java.util.ResourceBundle, java.lang.reflect.Module) localized logger}); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1282 |
* can be {@code null}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1283 |
* @param params an optional list of parameters to the message (may be |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1284 |
* none). |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1285 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1286 |
* @throws NullPointerException if {@code level} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1287 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1288 |
public default void log(Level level, String format, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1289 |
this.log(level, null, format, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1290 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1291 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1292 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1293 |
* Logs a localized message associated with a given throwable. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1294 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1295 |
* If the given resource bundle is non-{@code null}, the {@code msg} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1296 |
* string is localized using the given resource bundle. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1297 |
* Otherwise the {@code msg} string is not localized. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1298 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1299 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1300 |
* @param bundle a resource bundle to localize {@code msg}; can be |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1301 |
* {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1302 |
* @param msg the string message (or a key in the message catalog, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1303 |
* if {@code bundle} is not {@code null}); can be {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1304 |
* @param thrown a {@code Throwable} associated with the log message; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1305 |
* can be {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1306 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1307 |
* @throws NullPointerException if {@code level} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1308 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1309 |
public void log(Level level, ResourceBundle bundle, String msg, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1310 |
Throwable thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1311 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1312 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1313 |
* Logs a message with resource bundle and an optional list of |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1314 |
* parameters. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1315 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1316 |
* If the given resource bundle is non-{@code null}, the {@code format} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1317 |
* string is localized using the given resource bundle. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1318 |
* Otherwise the {@code format} string is not localized. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1319 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1320 |
* @param level the log message level. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1321 |
* @param bundle a resource bundle to localize {@code format}; can be |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1322 |
* {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1323 |
* @param format the string message format in {@link |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1324 |
* java.text.MessageFormat} format, (or a key in the message |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1325 |
* catalog if {@code bundle} is not {@code null}); can be {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1326 |
* @param params an optional list of parameters to the message (may be |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1327 |
* none). |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1328 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1329 |
* @throws NullPointerException if {@code level} is {@code null}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1330 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1331 |
public void log(Level level, ResourceBundle bundle, String format, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1332 |
Object... params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1333 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1334 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1335 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1336 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1337 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1338 |
* The {@code LoggerFinder} service is responsible for creating, managing, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1339 |
* and configuring loggers to the underlying framework it uses. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1340 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1341 |
* A logger finder is a concrete implementation of this class that has a |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1342 |
* zero-argument constructor and implements the abstract methods defined |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1343 |
* by this class. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1344 |
* The loggers returned from a logger finder are capable of routing log |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1345 |
* messages to the logging backend this provider supports. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1346 |
* A given invocation of the Java Runtime maintains a single |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1347 |
* system-wide LoggerFinder instance that is loaded as follows: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1348 |
* <ul> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1349 |
* <li>First it finds any custom {@code LoggerFinder} provider |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1350 |
* using the {@link java.util.ServiceLoader} facility with the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1351 |
* {@linkplain ClassLoader#getSystemClassLoader() system class |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1352 |
* loader}.</li> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1353 |
* <li>If no {@code LoggerFinder} provider is found, the system default |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1354 |
* {@code LoggerFinder} implementation will be used.</li> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1355 |
* </ul> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1356 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1357 |
* An application can replace the logging backend |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1358 |
* <i>even when the java.logging module is present</i>, by simply providing |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1359 |
* and declaring an implementation of the {@link LoggerFinder} service. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1360 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1361 |
* <b>Default Implementation</b> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1362 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1363 |
* The system default {@code LoggerFinder} implementation uses |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1364 |
* {@code java.util.logging} as the backend framework when the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1365 |
* {@code java.logging} module is present. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1366 |
* It returns a {@linkplain System.Logger logger} instance |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1367 |
* that will route log messages to a {@link java.util.logging.Logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1368 |
* java.util.logging.Logger}. Otherwise, if {@code java.logging} is not |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1369 |
* present, the default implementation will return a simple logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1370 |
* instance that will route log messages of {@code INFO} level and above to |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1371 |
* the console ({@code System.err}). |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1372 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1373 |
* <b>Logging Configuration</b> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1374 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1375 |
* {@linkplain Logger Logger} instances obtained from the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1376 |
* {@code LoggerFinder} factory methods are not directly configurable by |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1377 |
* the application. Configuration is the responsibility of the underlying |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1378 |
* logging backend, and usually requires using APIs specific to that backend. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1379 |
* <p>For the default {@code LoggerFinder} implementation |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1380 |
* using {@code java.util.logging} as its backend, refer to |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1381 |
* {@link java.util.logging java.util.logging} for logging configuration. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1382 |
* For the default {@code LoggerFinder} implementation returning simple loggers |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1383 |
* when the {@code java.logging} module is absent, the configuration |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1384 |
* is implementation dependent. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1385 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1386 |
* Usually an application that uses a logging framework will log messages |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1387 |
* through a logger facade defined (or supported) by that framework. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1388 |
* Applications that wish to use an external framework should log |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1389 |
* through the facade associated with that framework. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1390 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1391 |
* A system class that needs to log messages will typically obtain |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1392 |
* a {@link System.Logger} instance to route messages to the logging |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1393 |
* framework selected by the application. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1394 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1395 |
* Libraries and classes that only need loggers to produce log messages |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1396 |
* should not attempt to configure loggers by themselves, as that |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1397 |
* would make them dependent from a specific implementation of the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1398 |
* {@code LoggerFinder} service. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1399 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1400 |
* In addition, when a security manager is present, loggers provided to |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1401 |
* system classes should not be directly configurable through the logging |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1402 |
* backend without requiring permissions. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1403 |
* <br> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1404 |
* It is the responsibility of the provider of |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1405 |
* the concrete {@code LoggerFinder} implementation to ensure that |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1406 |
* these loggers are not configured by untrusted code without proper |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1407 |
* permission checks, as configuration performed on such loggers usually |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1408 |
* affects all applications in the same Java Runtime. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1409 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1410 |
* <b>Message Levels and Mapping to backend levels</b> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1411 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1412 |
* A logger finder is responsible for mapping from a {@code |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1413 |
* System.Logger.Level} to a level supported by the logging backend it uses. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1414 |
* <br>The default LoggerFinder using {@code java.util.logging} as the backend |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1415 |
* maps {@code System.Logger} levels to |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1416 |
* {@linkplain java.util.logging.Level java.util.logging} levels |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1417 |
* of corresponding severity - as described in {@link Logger.Level |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1418 |
* Logger.Level}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1419 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1420 |
* @see java.lang.System |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1421 |
* @see java.lang.System.Logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1422 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1423 |
* @since 9 |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1424 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1425 |
public static abstract class LoggerFinder { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1426 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1427 |
* The {@code RuntimePermission("loggerFinder")} is |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1428 |
* necessary to subclass and instantiate the {@code LoggerFinder} class, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1429 |
* as well as to obtain loggers from an instance of that class. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1430 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1431 |
static final RuntimePermission LOGGERFINDER_PERMISSION = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1432 |
new RuntimePermission("loggerFinder"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1433 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1434 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1435 |
* Creates a new instance of {@code LoggerFinder}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1436 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1437 |
* @implNote It is recommended that a {@code LoggerFinder} service |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1438 |
* implementation does not perform any heavy initialization in its |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1439 |
* constructor, in order to avoid possible risks of deadlock or class |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1440 |
* loading cycles during the instantiation of the service provider. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1441 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1442 |
* @throws SecurityException if a security manager is present and its |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1443 |
* {@code checkPermission} method doesn't allow the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1444 |
* {@code RuntimePermission("loggerFinder")}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1445 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1446 |
protected LoggerFinder() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1447 |
this(checkPermission()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1448 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1449 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1450 |
private LoggerFinder(Void unused) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1451 |
// nothing to do. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1452 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1453 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1454 |
private static Void checkPermission() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1455 |
final SecurityManager sm = System.getSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1456 |
if (sm != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1457 |
sm.checkPermission(LOGGERFINDER_PERMISSION); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1458 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1459 |
return null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1460 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1461 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1462 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1463 |
* Returns an instance of {@link Logger Logger} |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1464 |
* for the given {@code module}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1465 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1466 |
* @param name the name of the logger. |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1467 |
* @param module the module for which the logger is being requested. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1468 |
* |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1469 |
* @return a {@link Logger logger} suitable for use within the given |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1470 |
* module. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1471 |
* @throws NullPointerException if {@code name} is {@code null} or |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1472 |
* {@code module} is {@code null}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1473 |
* @throws SecurityException if a security manager is present and its |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1474 |
* {@code checkPermission} method doesn't allow the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1475 |
* {@code RuntimePermission("loggerFinder")}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1476 |
*/ |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1477 |
public abstract Logger getLogger(String name, Module module); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1478 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1479 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1480 |
* Returns a localizable instance of {@link Logger Logger} |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1481 |
* for the given {@code module}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1482 |
* The returned logger will use the provided resource bundle for |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1483 |
* message localization. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1484 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1485 |
* @implSpec By default, this method calls {@link |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1486 |
* #getLogger(java.lang.String, java.lang.reflect.Module) |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1487 |
* this.getLogger(name, module)} to obtain a logger, then wraps that |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1488 |
* logger in a {@link Logger} instance where all methods that do not |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1489 |
* take a {@link ResourceBundle} as parameter are redirected to one |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1490 |
* which does - passing the given {@code bundle} for |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1491 |
* localization. So for instance, a call to {@link |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1492 |
* Logger#log(Level, String) Logger.log(Level.INFO, msg)} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1493 |
* will end up as a call to {@link |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1494 |
* Logger#log(Level, ResourceBundle, String, Object...) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1495 |
* Logger.log(Level.INFO, bundle, msg, (Object[])null)} on the wrapped |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1496 |
* logger instance. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1497 |
* Note however that by default, string messages returned by {@link |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1498 |
* java.util.function.Supplier Supplier<String>} will not be |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1499 |
* localized, as it is assumed that such strings are messages which are |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1500 |
* already constructed, rather than keys in a resource bundle. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1501 |
* <p> |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1502 |
* An implementation of {@code LoggerFinder} may override this method, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1503 |
* for example, when the underlying logging backend provides its own |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1504 |
* mechanism for localizing log messages, then such a |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1505 |
* {@code LoggerFinder} would be free to return a logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1506 |
* that makes direct use of the mechanism provided by the backend. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1507 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1508 |
* @param name the name of the logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1509 |
* @param bundle a resource bundle; can be {@code null}. |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1510 |
* @param module the module for which the logger is being requested. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1511 |
* @return an instance of {@link Logger Logger} which will use the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1512 |
* provided resource bundle for message localization. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1513 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1514 |
* @throws NullPointerException if {@code name} is {@code null} or |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1515 |
* {@code module} is {@code null}. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1516 |
* @throws SecurityException if a security manager is present and its |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1517 |
* {@code checkPermission} method doesn't allow the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1518 |
* {@code RuntimePermission("loggerFinder")}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1519 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1520 |
public Logger getLocalizedLogger(String name, ResourceBundle bundle, |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1521 |
Module module) { |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1522 |
return new LocalizedLoggerWrapper<>(getLogger(name, module), bundle); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1523 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1524 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1525 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1526 |
* Returns the {@code LoggerFinder} instance. There is one |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1527 |
* single system-wide {@code LoggerFinder} instance in |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1528 |
* the Java Runtime. See the class specification of how the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1529 |
* {@link LoggerFinder LoggerFinder} implementation is located and |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1530 |
* loaded. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1531 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1532 |
* @return the {@link LoggerFinder LoggerFinder} instance. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1533 |
* @throws SecurityException if a security manager is present and its |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1534 |
* {@code checkPermission} method doesn't allow the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1535 |
* {@code RuntimePermission("loggerFinder")}. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1536 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1537 |
public static LoggerFinder getLoggerFinder() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1538 |
final SecurityManager sm = System.getSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1539 |
if (sm != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1540 |
sm.checkPermission(LOGGERFINDER_PERMISSION); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1541 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1542 |
return accessProvider(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1543 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1544 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1545 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1546 |
private static volatile LoggerFinder service; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1547 |
static LoggerFinder accessProvider() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1548 |
// We do not need to synchronize: LoggerFinderLoader will |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1549 |
// always return the same instance, so if we don't have it, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1550 |
// just fetch it again. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1551 |
if (service == null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1552 |
PrivilegedAction<LoggerFinder> pa = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1553 |
() -> LoggerFinderLoader.getLoggerFinder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1554 |
service = AccessController.doPrivileged(pa, null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1555 |
LOGGERFINDER_PERMISSION); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1556 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1557 |
return service; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1558 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1559 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1560 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1561 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1562 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1563 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1564 |
* Returns an instance of {@link Logger Logger} for the caller's |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1565 |
* use. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1566 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1567 |
* @implSpec |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1568 |
* Instances returned by this method route messages to loggers |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1569 |
* obtained by calling {@link LoggerFinder#getLogger(java.lang.String, |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1570 |
* java.lang.reflect.Module) LoggerFinder.getLogger(name, module)}, where |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1571 |
* {@code module} is the caller's module. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1572 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1573 |
* @apiNote |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1574 |
* This method may defer calling the {@link |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1575 |
* LoggerFinder#getLogger(java.lang.String, java.lang.reflect.Module) |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1576 |
* LoggerFinder.getLogger} method to create an actual logger supplied by |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1577 |
* the logging backend, for instance, to allow loggers to be obtained during |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1578 |
* the system initialization time. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1579 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1580 |
* @param name the name of the logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1581 |
* @return an instance of {@link Logger} that can be used by the calling |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1582 |
* class. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1583 |
* @throws NullPointerException if {@code name} is {@code null}. |
34933
09a3dab8e1f9
8146691: @since 9 tag missing for System.getLogger
dfuchs
parents:
34882
diff
changeset
|
1584 |
* |
09a3dab8e1f9
8146691: @since 9 tag missing for System.getLogger
dfuchs
parents:
34882
diff
changeset
|
1585 |
* @since 9 |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1586 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1587 |
@CallerSensitive |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1588 |
public static Logger getLogger(String name) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1589 |
Objects.requireNonNull(name); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1590 |
final Class<?> caller = Reflection.getCallerClass(); |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1591 |
return LazyLoggers.getLogger(name, caller.getModule()); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1592 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1593 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1594 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1595 |
* Returns a localizable instance of {@link Logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1596 |
* Logger} for the caller's use. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1597 |
* The returned logger will use the provided resource bundle for message |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1598 |
* localization. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1599 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1600 |
* @implSpec |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1601 |
* The returned logger will perform message localization as specified |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1602 |
* by {@link LoggerFinder#getLocalizedLogger(java.lang.String, |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1603 |
* java.util.ResourceBundle, java.lang.reflect.Module) |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1604 |
* LoggerFinder.getLocalizedLogger(name, bundle, module}, where |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1605 |
* {@code module} is the caller's module. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1606 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1607 |
* @apiNote |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1608 |
* This method is intended to be used after the system is fully initialized. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1609 |
* This method may trigger the immediate loading and initialization |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1610 |
* of the {@link LoggerFinder} service, which may cause issues if the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1611 |
* Java Runtime is not ready to initialize the concrete service |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1612 |
* implementation yet. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1613 |
* System classes which may be loaded early in the boot sequence and |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1614 |
* need to log localized messages should create a logger using |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1615 |
* {@link #getLogger(java.lang.String)} and then use the log methods that |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1616 |
* take a resource bundle as parameter. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1617 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1618 |
* @param name the name of the logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1619 |
* @param bundle a resource bundle. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1620 |
* @return an instance of {@link Logger} which will use the provided |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1621 |
* resource bundle for message localization. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1622 |
* @throws NullPointerException if {@code name} is {@code null} or |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1623 |
* {@code bundle} is {@code null}. |
34933
09a3dab8e1f9
8146691: @since 9 tag missing for System.getLogger
dfuchs
parents:
34882
diff
changeset
|
1624 |
* |
09a3dab8e1f9
8146691: @since 9 tag missing for System.getLogger
dfuchs
parents:
34882
diff
changeset
|
1625 |
* @since 9 |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1626 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1627 |
@CallerSensitive |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1628 |
public static Logger getLogger(String name, ResourceBundle bundle) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1629 |
final ResourceBundle rb = Objects.requireNonNull(bundle); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1630 |
Objects.requireNonNull(name); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1631 |
final Class<?> caller = Reflection.getCallerClass(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1632 |
final SecurityManager sm = System.getSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1633 |
// We don't use LazyLoggers if a resource bundle is specified. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1634 |
// Bootstrap sensitive classes in the JDK do not use resource bundles |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1635 |
// when logging. This could be revisited later, if it needs to. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1636 |
if (sm != null) { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1637 |
final PrivilegedAction<Logger> pa = |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1638 |
() -> LoggerFinder.accessProvider() |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1639 |
.getLocalizedLogger(name, rb, caller.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1640 |
return AccessController.doPrivileged(pa, null, |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1641 |
LoggerFinder.LOGGERFINDER_PERMISSION); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1642 |
} |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1643 |
return LoggerFinder.accessProvider() |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
37521
diff
changeset
|
1644 |
.getLocalizedLogger(name, rb, caller.getModule()); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1645 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1646 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
32834
diff
changeset
|
1647 |
/** |
2 | 1648 |
* Terminates the currently running Java Virtual Machine. The |
1649 |
* argument serves as a status code; by convention, a nonzero status |
|
1650 |
* code indicates abnormal termination. |
|
1651 |
* <p> |
|
1652 |
* This method calls the <code>exit</code> method in class |
|
1653 |
* <code>Runtime</code>. This method never returns normally. |
|
1654 |
* <p> |
|
1655 |
* The call <code>System.exit(n)</code> is effectively equivalent to |
|
1656 |
* the call: |
|
1657 |
* <blockquote><pre> |
|
1658 |
* Runtime.getRuntime().exit(n) |
|
1659 |
* </pre></blockquote> |
|
1660 |
* |
|
1661 |
* @param status exit status. |
|
1662 |
* @throws SecurityException |
|
1663 |
* if a security manager exists and its <code>checkExit</code> |
|
1664 |
* method doesn't allow exit with the specified status. |
|
1665 |
* @see java.lang.Runtime#exit(int) |
|
1666 |
*/ |
|
1667 |
public static void exit(int status) { |
|
1668 |
Runtime.getRuntime().exit(status); |
|
1669 |
} |
|
1670 |
||
1671 |
/** |
|
1672 |
* Runs the garbage collector. |
|
1673 |
* <p> |
|
1674 |
* Calling the <code>gc</code> method suggests that the Java Virtual |
|
1675 |
* Machine expend effort toward recycling unused objects in order to |
|
1676 |
* make the memory they currently occupy available for quick reuse. |
|
1677 |
* When control returns from the method call, the Java Virtual |
|
1678 |
* Machine has made a best effort to reclaim space from all discarded |
|
1679 |
* objects. |
|
1680 |
* <p> |
|
1681 |
* The call <code>System.gc()</code> is effectively equivalent to the |
|
1682 |
* call: |
|
1683 |
* <blockquote><pre> |
|
1684 |
* Runtime.getRuntime().gc() |
|
1685 |
* </pre></blockquote> |
|
1686 |
* |
|
1687 |
* @see java.lang.Runtime#gc() |
|
1688 |
*/ |
|
1689 |
public static void gc() { |
|
1690 |
Runtime.getRuntime().gc(); |
|
1691 |
} |
|
1692 |
||
1693 |
/** |
|
1694 |
* Runs the finalization methods of any objects pending finalization. |
|
1695 |
* <p> |
|
1696 |
* Calling this method suggests that the Java Virtual Machine expend |
|
1697 |
* effort toward running the <code>finalize</code> methods of objects |
|
1698 |
* that have been found to be discarded but whose <code>finalize</code> |
|
1699 |
* methods have not yet been run. When control returns from the |
|
1700 |
* method call, the Java Virtual Machine has made a best effort to |
|
1701 |
* complete all outstanding finalizations. |
|
1702 |
* <p> |
|
1703 |
* The call <code>System.runFinalization()</code> is effectively |
|
1704 |
* equivalent to the call: |
|
1705 |
* <blockquote><pre> |
|
1706 |
* Runtime.getRuntime().runFinalization() |
|
1707 |
* </pre></blockquote> |
|
1708 |
* |
|
1709 |
* @see java.lang.Runtime#runFinalization() |
|
1710 |
*/ |
|
1711 |
public static void runFinalization() { |
|
1712 |
Runtime.getRuntime().runFinalization(); |
|
1713 |
} |
|
1714 |
||
1715 |
/** |
|
1716 |
* Enable or disable finalization on exit; doing so specifies that the |
|
1717 |
* finalizers of all objects that have finalizers that have not yet been |
|
1718 |
* automatically invoked are to be run before the Java runtime exits. |
|
1719 |
* By default, finalization on exit is disabled. |
|
1720 |
* |
|
1721 |
* <p>If there is a security manager, |
|
1722 |
* its <code>checkExit</code> method is first called |
|
1723 |
* with 0 as its argument to ensure the exit is allowed. |
|
1724 |
* This could result in a SecurityException. |
|
1725 |
* |
|
1726 |
* @deprecated This method is inherently unsafe. It may result in |
|
1727 |
* finalizers being called on live objects while other threads are |
|
1728 |
* concurrently manipulating those objects, resulting in erratic |
|
1729 |
* behavior or deadlock. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
1730 |
* This method is subject to removal in a future version of Java SE. |
2 | 1731 |
* @param value indicating enabling or disabling of finalization |
1732 |
* @throws SecurityException |
|
1733 |
* if a security manager exists and its <code>checkExit</code> |
|
1734 |
* method doesn't allow the exit. |
|
1735 |
* |
|
1736 |
* @see java.lang.Runtime#exit(int) |
|
1737 |
* @see java.lang.Runtime#gc() |
|
1738 |
* @see java.lang.SecurityManager#checkExit(int) |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
1739 |
* @since 1.1 |
2 | 1740 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
1741 |
@Deprecated(since="1.2", forRemoval=true) |
2 | 1742 |
public static void runFinalizersOnExit(boolean value) { |
11275 | 1743 |
Runtime.runFinalizersOnExit(value); |
2 | 1744 |
} |
1745 |
||
1746 |
/** |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1747 |
* Loads the native library specified by the filename argument. The filename |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1748 |
* argument must be an absolute path name. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1749 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1750 |
* If the filename argument, when stripped of any platform-specific library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1751 |
* prefix, path, and file extension, indicates a library whose name is, |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1752 |
* for example, L, and a native library called L is statically linked |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1753 |
* with the VM, then the JNI_OnLoad_L function exported by the library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1754 |
* is invoked rather than attempting to load a dynamic library. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1755 |
* A filename matching the argument does not have to exist in the |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1756 |
* file system. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1757 |
* See the JNI Specification for more details. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1758 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1759 |
* Otherwise, the filename argument is mapped to a native library image in |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1760 |
* an implementation-dependent manner. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1761 |
* |
2 | 1762 |
* <p> |
1763 |
* The call <code>System.load(name)</code> is effectively equivalent |
|
1764 |
* to the call: |
|
1765 |
* <blockquote><pre> |
|
1766 |
* Runtime.getRuntime().load(name) |
|
1767 |
* </pre></blockquote> |
|
1768 |
* |
|
1769 |
* @param filename the file to load. |
|
1770 |
* @exception SecurityException if a security manager exists and its |
|
1771 |
* <code>checkLink</code> method doesn't allow |
|
1772 |
* loading of the specified dynamic library |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1773 |
* @exception UnsatisfiedLinkError if either the filename is not an |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1774 |
* absolute path name, the native library is not statically |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1775 |
* linked with the VM, or the library cannot be mapped to |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1776 |
* a native library image by the host system. |
2 | 1777 |
* @exception NullPointerException if <code>filename</code> is |
1778 |
* <code>null</code> |
|
1779 |
* @see java.lang.Runtime#load(java.lang.String) |
|
1780 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
1781 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
1782 |
@CallerSensitive |
2 | 1783 |
public static void load(String filename) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
1784 |
Runtime.getRuntime().load0(Reflection.getCallerClass(), filename); |
2 | 1785 |
} |
1786 |
||
1787 |
/** |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1788 |
* Loads the native library specified by the <code>libname</code> |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1789 |
* argument. The <code>libname</code> argument must not contain any platform |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1790 |
* specific prefix, file extension or path. If a native library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1791 |
* called <code>libname</code> is statically linked with the VM, then the |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1792 |
* JNI_OnLoad_<code>libname</code> function exported by the library is invoked. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1793 |
* See the JNI Specification for more details. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1794 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1795 |
* Otherwise, the libname argument is loaded from a system library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1796 |
* location and mapped to a native library image in an implementation- |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1797 |
* dependent manner. |
2 | 1798 |
* <p> |
1799 |
* The call <code>System.loadLibrary(name)</code> is effectively |
|
1800 |
* equivalent to the call |
|
1801 |
* <blockquote><pre> |
|
1802 |
* Runtime.getRuntime().loadLibrary(name) |
|
1803 |
* </pre></blockquote> |
|
1804 |
* |
|
1805 |
* @param libname the name of the library. |
|
1806 |
* @exception SecurityException if a security manager exists and its |
|
1807 |
* <code>checkLink</code> method doesn't allow |
|
1808 |
* loading of the specified dynamic library |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1809 |
* @exception UnsatisfiedLinkError if either the libname argument |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1810 |
* contains a file path, the native library is not statically |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1811 |
* linked with the VM, or the library cannot be mapped to a |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
15511
diff
changeset
|
1812 |
* native library image by the host system. |
2 | 1813 |
* @exception NullPointerException if <code>libname</code> is |
1814 |
* <code>null</code> |
|
1815 |
* @see java.lang.Runtime#loadLibrary(java.lang.String) |
|
1816 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
1817 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
1818 |
@CallerSensitive |
2 | 1819 |
public static void loadLibrary(String libname) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
1820 |
Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname); |
2 | 1821 |
} |
1822 |
||
1823 |
/** |
|
1824 |
* Maps a library name into a platform-specific string representing |
|
1825 |
* a native library. |
|
1826 |
* |
|
1827 |
* @param libname the name of the library. |
|
1828 |
* @return a platform-dependent native library name. |
|
1829 |
* @exception NullPointerException if <code>libname</code> is |
|
1830 |
* <code>null</code> |
|
1831 |
* @see java.lang.System#loadLibrary(java.lang.String) |
|
1832 |
* @see java.lang.ClassLoader#findLibrary(java.lang.String) |
|
1833 |
* @since 1.2 |
|
1834 |
*/ |
|
1835 |
public static native String mapLibraryName(String libname); |
|
1836 |
||
1837 |
/** |
|
11906
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1838 |
* Create PrintStream for stdout/err based on encoding. |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1839 |
*/ |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1840 |
private static PrintStream newPrintStream(FileOutputStream fos, String enc) { |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1841 |
if (enc != null) { |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1842 |
try { |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1843 |
return new PrintStream(new BufferedOutputStream(fos, 128), true, enc); |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1844 |
} catch (UnsupportedEncodingException uee) {} |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1845 |
} |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1846 |
return new PrintStream(new BufferedOutputStream(fos, 128), true); |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1847 |
} |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1848 |
|
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1849 |
/** |
2 | 1850 |
* Initialize the system class. Called after thread initialization. |
1851 |
*/ |
|
36511 | 1852 |
private static void initPhase1() { |
8399
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1853 |
|
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1854 |
// VM might invoke JNU_NewStringPlatform() to set those encoding |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1855 |
// sensitive properties (user.home, user.name, boot.class.path, etc.) |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1856 |
// during "props" initialization, in which it may need access, via |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1857 |
// System.getProperty(), to the related system encoding property that |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1858 |
// have been initialized (put into "props") at early stage of the |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1859 |
// initialization. So make sure the "props" is available at the |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1860 |
// very beginning of the initialization and all system properties to |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1861 |
// be put into it directly. |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1862 |
props = new Properties(); |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1863 |
initProperties(props); // initialized by the VM |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1864 |
|
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1865 |
// There are certain system configurations that may be controlled by |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1866 |
// VM options such as the maximum amount of direct memory and |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1867 |
// Integer cache size used to support the object identity semantics |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1868 |
// of autoboxing. Typically, the library will obtain these values |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1869 |
// from the properties set by the VM. If the properties are for |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1870 |
// internal implementation use only, these properties should be |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1871 |
// removed from the system properties. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1872 |
// |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
6668
diff
changeset
|
1873 |
// See java.lang.Integer.IntegerCache and the |
34882 | 1874 |
// VM.saveAndRemoveProperties method for example. |
8399
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1875 |
// |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1876 |
// Save a private copy of the system properties object that |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1877 |
// can only be accessed by the internal implementation. Remove |
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1878 |
// certain system properties that are not intended for public access. |
34882 | 1879 |
VM.saveAndRemoveProperties(props); |
8399
0a7dab5d5922
6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents:
7668
diff
changeset
|
1880 |
|
4355
12d58d6de82f
6900043: Add method to return line.separator property
martin
parents:
3288
diff
changeset
|
1881 |
lineSeparator = props.getProperty("line.separator"); |
36225
6ae0eebc46e9
8150162: Move sun.misc.Version to a truly internal package
chegar
parents:
36215
diff
changeset
|
1882 |
VersionProps.init(); |
2425
99a19a90813e
6807702: Integer.valueOf cache should be configurable
alanb
parents:
2288
diff
changeset
|
1883 |
|
2 | 1884 |
FileInputStream fdIn = new FileInputStream(FileDescriptor.in); |
1885 |
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out); |
|
1886 |
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err); |
|
1887 |
setIn0(new BufferedInputStream(fdIn)); |
|
11906
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1888 |
setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding"))); |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1889 |
setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding"))); |
dc984e35d8a6
4153167: separate between ANSI and OEM code pages on Windows
sherman
parents:
11275
diff
changeset
|
1890 |
|
6668 | 1891 |
// Load the zip library now in order to keep java.util.zip.ZipFile |
1892 |
// from trying to use itself to load this library later. |
|
1893 |
loadLibrary("zip"); |
|
1894 |
||
2 | 1895 |
// Setup Java signal handlers for HUP, TERM, and INT (where available). |
1896 |
Terminator.setup(); |
|
1897 |
||
25979 | 1898 |
// Initialize any miscellaneous operating system settings that need to be |
2 | 1899 |
// set for the class libraries. Currently this is no-op everywhere except |
1900 |
// for Windows where the process-wide error mode is set before the java.io |
|
1901 |
// classes are used. |
|
34882 | 1902 |
VM.initializeOSEnvironment(); |
2 | 1903 |
|
1904 |
// The main thread is not added to its thread group in the same |
|
1905 |
// way as other threads; we must do it ourselves here. |
|
1906 |
Thread current = Thread.currentThread(); |
|
1907 |
current.getThreadGroup().add(current); |
|
6668 | 1908 |
|
1909 |
// register shared secrets |
|
1910 |
setJavaLangAccess(); |
|
12038
ba8cfc6c5118
7149320: Move sun.misc.VM.booted() to the end of System.initializeSystemClass()
mduigou
parents:
11906
diff
changeset
|
1911 |
|
ba8cfc6c5118
7149320: Move sun.misc.VM.booted() to the end of System.initializeSystemClass()
mduigou
parents:
11906
diff
changeset
|
1912 |
// Subsystems that are invoked during initialization can invoke |
34882 | 1913 |
// VM.isBooted() in order to avoid doing things that should |
36511 | 1914 |
// wait until the VM is fully initialized. The initialization level |
1915 |
// is incremented from 0 to 1 here to indicate the first phase of |
|
1916 |
// initialization has completed. |
|
12038
ba8cfc6c5118
7149320: Move sun.misc.VM.booted() to the end of System.initializeSystemClass()
mduigou
parents:
11906
diff
changeset
|
1917 |
// IMPORTANT: Ensure that this remains the last initialization action! |
36511 | 1918 |
VM.initLevel(1); |
1919 |
} |
|
1920 |
||
1921 |
// @see #initPhase2() |
|
1922 |
private static Layer bootLayer; |
|
1923 |
||
1924 |
/* |
|
1925 |
* Invoked by VM. Phase 2 module system initialization. |
|
1926 |
* Only classes in java.base can be loaded in this phase. |
|
1927 |
*/ |
|
1928 |
private static void initPhase2() { |
|
1929 |
// initialize the module system |
|
1930 |
System.bootLayer = ModuleBootstrap.boot(); |
|
1931 |
||
1932 |
// module system initialized |
|
1933 |
VM.initLevel(2); |
|
1934 |
} |
|
1935 |
||
1936 |
/* |
|
1937 |
* Invoked by VM. Phase 3 is the final system initialization: |
|
1938 |
* 1. set security manager |
|
1939 |
* 2. set system class loader |
|
1940 |
* 3. set TCCL |
|
1941 |
* |
|
1942 |
* This method must be called after the module system initialization. |
|
1943 |
* The security manager and system class loader may be custom class from |
|
1944 |
* the application classpath or modulepath. |
|
1945 |
*/ |
|
1946 |
private static void initPhase3() { |
|
38861
e567cc17866d
8158851: MH.publicLookup() init circularity, triggered by custom SecurityManager with String concat and -limitmods java.base
shade
parents:
38432
diff
changeset
|
1947 |
// Initialize publicLookup early, to avoid bootstrapping circularities |
e567cc17866d
8158851: MH.publicLookup() init circularity, triggered by custom SecurityManager with String concat and -limitmods java.base
shade
parents:
38432
diff
changeset
|
1948 |
// with security manager using java.lang.invoke infrastructure. |
e567cc17866d
8158851: MH.publicLookup() init circularity, triggered by custom SecurityManager with String concat and -limitmods java.base
shade
parents:
38432
diff
changeset
|
1949 |
java.lang.invoke.MethodHandles.publicLookup(); |
e567cc17866d
8158851: MH.publicLookup() init circularity, triggered by custom SecurityManager with String concat and -limitmods java.base
shade
parents:
38432
diff
changeset
|
1950 |
|
36511 | 1951 |
// set security manager |
1952 |
String cn = System.getProperty("java.security.manager"); |
|
1953 |
if (cn != null) { |
|
1954 |
if (cn.isEmpty() || "default".equals(cn)) { |
|
1955 |
System.setSecurityManager(new SecurityManager()); |
|
1956 |
} else { |
|
1957 |
try { |
|
1958 |
Class<?> c = Class.forName(cn, false, ClassLoader.getBuiltinAppClassLoader()); |
|
1959 |
Constructor<?> ctor = c.getConstructor(); |
|
1960 |
// Must be a public subclass of SecurityManager with |
|
1961 |
// a public no-arg constructor |
|
1962 |
if (!SecurityManager.class.isAssignableFrom(c) || |
|
1963 |
!Modifier.isPublic(c.getModifiers()) || |
|
1964 |
!Modifier.isPublic(ctor.getModifiers())) { |
|
1965 |
throw new Error("Could not create SecurityManager: " + ctor.toString()); |
|
1966 |
} |
|
1967 |
// custom security manager implementation may be in unnamed module |
|
1968 |
// or a named module but non-exported package |
|
1969 |
ctor.setAccessible(true); |
|
1970 |
SecurityManager sm = (SecurityManager) ctor.newInstance(); |
|
1971 |
System.setSecurityManager(sm); |
|
1972 |
} catch (Exception e) { |
|
1973 |
throw new Error("Could not create SecurityManager", e); |
|
1974 |
} |
|
1975 |
} |
|
1976 |
} |
|
1977 |
||
1978 |
// initializing the system class loader |
|
1979 |
VM.initLevel(3); |
|
1980 |
||
1981 |
// system class loader initialized |
|
1982 |
ClassLoader scl = ClassLoader.initSystemClassLoader(); |
|
1983 |
||
1984 |
// set TCCL |
|
1985 |
Thread.currentThread().setContextClassLoader(scl); |
|
1986 |
||
1987 |
// system is fully initialized |
|
1988 |
VM.initLevel(4); |
|
3111
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2703
diff
changeset
|
1989 |
} |
2 | 1990 |
|
3111
fefdeafb7ab9
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
2703
diff
changeset
|
1991 |
private static void setJavaLangAccess() { |
2 | 1992 |
// Allow privileged classes outside of java.lang |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1993 |
SharedSecrets.setJavaLangAccess(new JavaLangAccess() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1994 |
public Method getMethodOrNull(Class<?> klass, String name, Class<?>... parameterTypes) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1995 |
return klass.getMethodOrNull(name, parameterTypes); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1996 |
} |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36972
diff
changeset
|
1997 |
public jdk.internal.reflect.ConstantPool getConstantPool(Class<?> klass) { |
2 | 1998 |
return klass.getConstantPool(); |
1999 |
} |
|
18827
ecbd9c8bef12
7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents:
18546
diff
changeset
|
2000 |
public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) { |
ecbd9c8bef12
7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents:
18546
diff
changeset
|
2001 |
return klass.casAnnotationType(oldType, newType); |
2 | 2002 |
} |
11117
b6e68b1344d4
7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents:
10360
diff
changeset
|
2003 |
public AnnotationType getAnnotationType(Class<?> klass) { |
2 | 2004 |
return klass.getAnnotationType(); |
2005 |
} |
|
21358
d41ff832d4f6
8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents:
20831
diff
changeset
|
2006 |
public Map<Class<? extends Annotation>, Annotation> getDeclaredAnnotationMap(Class<?> klass) { |
d41ff832d4f6
8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents:
20831
diff
changeset
|
2007 |
return klass.getDeclaredAnnotationMap(); |
d41ff832d4f6
8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents:
20831
diff
changeset
|
2008 |
} |
18827
ecbd9c8bef12
7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents:
18546
diff
changeset
|
2009 |
public byte[] getRawClassAnnotations(Class<?> klass) { |
ecbd9c8bef12
7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents:
18546
diff
changeset
|
2010 |
return klass.getRawAnnotations(); |
ecbd9c8bef12
7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents:
18546
diff
changeset
|
2011 |
} |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
2012 |
public byte[] getRawClassTypeAnnotations(Class<?> klass) { |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
2013 |
return klass.getRawTypeAnnotations(); |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
2014 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
2015 |
public byte[] getRawExecutableTypeAnnotations(Executable executable) { |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
2016 |
return Class.getExecutableTypeAnnotationBytes(executable); |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14676
diff
changeset
|
2017 |
} |
2 | 2018 |
public <E extends Enum<E>> |
2019 |
E[] getEnumConstantsShared(Class<E> klass) { |
|
2020 |
return klass.getEnumConstantsShared(); |
|
2021 |
} |
|
2022 |
public void blockedOn(Thread t, Interruptible b) { |
|
2023 |
t.blockedOn(b); |
|
2024 |
} |
|
2703
acd4d6a53e3e
6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents:
2425
diff
changeset
|
2025 |
public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) { |
acd4d6a53e3e
6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents:
2425
diff
changeset
|
2026 |
Shutdown.add(slot, registerShutdownInProgress, hook); |
2277
445a331b4a8b
6810254: Lazily instantiate the shared secret access objects
mchung
parents:
2
diff
changeset
|
2027 |
} |
17426
45db19517346
8013528: Provide SharedSecrets access to String(char[], boolean) constructor
mduigou
parents:
16906
diff
changeset
|
2028 |
public String newStringUnsafe(char[] chars) { |
45db19517346
8013528: Provide SharedSecrets access to String(char[], boolean) constructor
mduigou
parents:
16906
diff
changeset
|
2029 |
return new String(chars, true); |
45db19517346
8013528: Provide SharedSecrets access to String(char[], boolean) constructor
mduigou
parents:
16906
diff
changeset
|
2030 |
} |
20805 | 2031 |
public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) { |
2032 |
return new Thread(target, acc); |
|
2033 |
} |
|
21628
50fd58446d64
8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents:
21358
diff
changeset
|
2034 |
public void invokeFinalize(Object o) throws Throwable { |
50fd58446d64
8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents:
21358
diff
changeset
|
2035 |
o.finalize(); |
50fd58446d64
8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents:
21358
diff
changeset
|
2036 |
} |
36511 | 2037 |
public Layer getBootLayer() { |
2038 |
return bootLayer; |
|
2039 |
} |
|
36972
27147cde3256
8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents:
36511
diff
changeset
|
2040 |
public ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap(ClassLoader cl) { |
27147cde3256
8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents:
36511
diff
changeset
|
2041 |
return cl.createOrGetClassLoaderValueMap(); |
27147cde3256
8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents:
36511
diff
changeset
|
2042 |
} |
36511 | 2043 |
public Class<?> findBootstrapClassOrNull(ClassLoader cl, String name) { |
2044 |
return cl.findBootstrapClassOrNull(name); |
|
2045 |
} |
|
2046 |
public URL findResource(ClassLoader cl, String mn, String name) throws IOException { |
|
2047 |
return cl.findResource(mn, name); |
|
2048 |
} |
|
2049 |
public Stream<Package> packages(ClassLoader cl) { |
|
2050 |
return cl.packages(); |
|
2051 |
} |
|
2052 |
public Package definePackage(ClassLoader cl, String name, Module module) { |
|
2053 |
return cl.definePackage(name, module); |
|
2054 |
} |
|
35707 | 2055 |
public String fastUUID(long lsb, long msb) { |
2056 |
return Long.fastUUID(lsb, msb); |
|
25660
01fa3ccedf50
8050114: Expose Integer/Long formatUnsigned methods internally
redestad
parents:
24865
diff
changeset
|
2057 |
} |
2 | 2058 |
}); |
2059 |
} |
|
2060 |
} |