1
1
/*
2
- * Copyright (c) 2015, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package jdk .internal .logger ;
27
27
28
- import java .security .AccessControlContext ;
29
- import java .security .AccessController ;
30
- import java .security .PrivilegedAction ;
31
28
import java .util .HashMap ;
32
29
import java .util .Iterator ;
33
30
import java .util .Map ;
@@ -131,15 +128,8 @@ private static ExecutorService getExecutor() {
131
128
@ Override
132
129
public Thread newThread (Runnable r ) {
133
130
ExecutorService owner = getExecutor ();
134
- @ SuppressWarnings ("removal" )
135
- Thread thread = AccessController .doPrivileged (new PrivilegedAction <Thread >() {
136
- @ Override
137
- public Thread run () {
138
- Thread t = InnocuousThread .newThread (new BootstrapMessageLoggerTask (owner , r ));
139
- t .setName ("BootstrapMessageLoggerTask-" +t .getName ());
140
- return t ;
141
- }
142
- }, null , new RuntimePermission ("enableContextClassLoaderOverride" ));
131
+ Thread thread = InnocuousThread .newThread (new BootstrapMessageLoggerTask (owner , r ));
132
+ thread .setName ("BootstrapMessageLoggerTask-" + thread .getName ());
143
133
thread .setDaemon (true );
144
134
return thread ;
145
135
}
@@ -269,8 +259,6 @@ static final class LogEvent {
269
259
// the parameters etc... we need to store the context of the
270
260
// caller who logged the message - so that we can reuse it when
271
261
// we finally log the message.
272
- @ SuppressWarnings ("removal" )
273
- final AccessControlContext acc ;
274
262
275
263
// The next event in the queue
276
264
LogEvent next ;
@@ -279,7 +267,6 @@ static final class LogEvent {
279
267
private LogEvent (BootstrapLogger bootstrap , Level level ,
280
268
ResourceBundle bundle , String msg ,
281
269
Throwable thrown , Object [] params ) {
282
- this .acc = AccessController .getContext ();
283
270
this .timeMillis = System .currentTimeMillis ();
284
271
this .nanoAdjustment = VM .getNanoTimeAdjustment (timeMillis );
285
272
this .level = level ;
@@ -298,7 +285,6 @@ private LogEvent(BootstrapLogger bootstrap, Level level,
298
285
private LogEvent (BootstrapLogger bootstrap , Level level ,
299
286
Supplier <String > msgSupplier ,
300
287
Throwable thrown , Object [] params ) {
301
- this .acc = AccessController .getContext ();
302
288
this .timeMillis = System .currentTimeMillis ();
303
289
this .nanoAdjustment = VM .getNanoTimeAdjustment (timeMillis );
304
290
this .level = level ;
@@ -319,7 +305,6 @@ private LogEvent(BootstrapLogger bootstrap,
319
305
String sourceClass , String sourceMethod ,
320
306
ResourceBundle bundle , String msg ,
321
307
Throwable thrown , Object [] params ) {
322
- this .acc = AccessController .getContext ();
323
308
this .timeMillis = System .currentTimeMillis ();
324
309
this .nanoAdjustment = VM .getNanoTimeAdjustment (timeMillis );
325
310
this .level = null ;
@@ -340,7 +325,6 @@ private LogEvent(BootstrapLogger bootstrap,
340
325
String sourceClass , String sourceMethod ,
341
326
Supplier <String > msgSupplier ,
342
327
Throwable thrown , Object [] params ) {
343
- this .acc = AccessController .getContext ();
344
328
this .timeMillis = System .currentTimeMillis ();
345
329
this .nanoAdjustment = VM .getNanoTimeAdjustment (timeMillis );
346
330
this .level = null ;
@@ -444,20 +428,12 @@ static LogEvent valueOf(BootstrapLogger bootstrap, Level level,
444
428
Objects .requireNonNull (level ),
445
429
Objects .requireNonNull (msgSupplier ), null , null );
446
430
}
447
- @ SuppressWarnings ( "removal" )
431
+
448
432
static void log (LogEvent log , Logger logger ) {
449
- final SecurityManager sm = System .getSecurityManager ();
450
433
// not sure we can actually use lambda here. We may need to create
451
434
// an anonymous class. Although if we reach here, then it means
452
435
// the VM is booted.
453
- if (sm == null || log .acc == null ) {
454
- BootstrapExecutors .submit (() -> log .log (logger ));
455
- } else {
456
- BootstrapExecutors .submit (() ->
457
- AccessController .doPrivileged ((PrivilegedAction <Void >) () -> {
458
- log .log (logger ); return null ;
459
- }, log .acc ));
460
- }
436
+ BootstrapExecutors .submit (() -> log .log (logger ));
461
437
}
462
438
463
439
// non default methods from PlatformLogger.Bridge interface
@@ -510,20 +486,9 @@ static LogEvent valueOf(BootstrapLogger bootstrap, PlatformLogger.Level level,
510
486
Objects .requireNonNull (level ), sourceClass ,
511
487
sourceMethod , msgSupplier , thrown , null );
512
488
}
513
- @ SuppressWarnings ( "removal" )
489
+
514
490
static void log (LogEvent log , PlatformLogger .Bridge logger ) {
515
- final SecurityManager sm = System .getSecurityManager ();
516
- if (sm == null || log .acc == null ) {
517
- BootstrapExecutors .submit (() -> log .log (logger ));
518
- } else {
519
- // not sure we can actually use lambda here. We may need to create
520
- // an anonymous class. Although if we reach here, then it means
521
- // the VM is booted.
522
- BootstrapExecutors .submit (() ->
523
- AccessController .doPrivileged ((PrivilegedAction <Void >) () -> {
524
- log .log (logger ); return null ;
525
- }, log .acc ));
526
- }
491
+ BootstrapExecutors .submit (() -> log .log (logger ));
527
492
}
528
493
529
494
static void log (LogEvent event ) {
@@ -897,37 +862,32 @@ private LoggingBackend(boolean useLoggerFinder) {
897
862
// We do not want this field to get initialized if VM.isBooted() is false.
898
863
@ SuppressWarnings ("removal" )
899
864
private static final class DetectBackend {
900
- static final LoggingBackend detectedBackend ;
901
- static {
902
- detectedBackend = AccessController .doPrivileged (new PrivilegedAction <LoggingBackend >() {
903
- @ Override
904
- public LoggingBackend run () {
905
- final Iterator <LoggerFinder > iterator =
906
- ServiceLoader .load (LoggerFinder .class , ClassLoader .getSystemClassLoader ())
865
+ static final LoggingBackend detectedBackend = detectBackend ();
866
+
867
+ static LoggingBackend detectBackend () {
868
+ final Iterator <LoggerFinder > iterator =
869
+ ServiceLoader .load (LoggerFinder .class , ClassLoader .getSystemClassLoader ())
907
870
.iterator ();
908
- if (iterator .hasNext ()) {
909
- return LoggingBackend .CUSTOM ; // Custom Logger Provider is registered
910
- }
911
- // No custom logger provider: we will be using the default
912
- // backend.
913
- final Iterator <DefaultLoggerFinder > iterator2 =
914
- ServiceLoader .loadInstalled (DefaultLoggerFinder .class )
871
+ if (iterator .hasNext ()) {
872
+ return LoggingBackend .CUSTOM ; // Custom Logger Provider is registered
873
+ }
874
+ // No custom logger provider: we will be using the default
875
+ // backend.
876
+ final Iterator <DefaultLoggerFinder > iterator2 =
877
+ ServiceLoader .loadInstalled (DefaultLoggerFinder .class )
915
878
.iterator ();
916
- if (iterator2 .hasNext ()) {
917
- // LoggingProviderImpl is registered. The default
918
- // implementation is java.util.logging
919
- String cname = System .getProperty ("java.util.logging.config.class" );
920
- String fname = System .getProperty ("java.util.logging.config.file" );
921
- return (cname != null || fname != null )
922
- ? LoggingBackend .JUL_WITH_CONFIG
923
- : LoggingBackend .JUL_DEFAULT ;
924
- } else {
925
- // SimpleConsoleLogger is used
926
- return LoggingBackend .NONE ;
927
- }
928
- }
929
- });
930
-
879
+ if (iterator2 .hasNext ()) {
880
+ // LoggingProviderImpl is registered. The default
881
+ // implementation is java.util.logging
882
+ String cname = System .getProperty ("java.util.logging.config.class" );
883
+ String fname = System .getProperty ("java.util.logging.config.file" );
884
+ return (cname != null || fname != null )
885
+ ? LoggingBackend .JUL_WITH_CONFIG
886
+ : LoggingBackend .JUL_DEFAULT ;
887
+ } else {
888
+ // SimpleConsoleLogger is used
889
+ return LoggingBackend .NONE ;
890
+ }
931
891
}
932
892
}
933
893
0 commit comments