8267521: Post JEP 411 refactoring: maximum covering > 50K

Reviewed-by: dfuchs, prr
This commit is contained in:
Weijun Wang 2021-06-02 15:48:50 +00:00
parent 40d23a0c0b
commit 508cec7535
18 changed files with 205 additions and 104 deletions

View file

@ -152,10 +152,7 @@ import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
* @since 1.4
*/
@SuppressWarnings("removal")
public class LogManager {
// The global LogManager object
private static final LogManager manager;
// 'props' is assigned within a lock but accessed without it.
// Declaring it volatile makes sure that another thread will not
@ -220,39 +217,40 @@ public class LogManager {
private final Map<Object, Runnable> listeners =
Collections.synchronizedMap(new IdentityHashMap<>());
static {
manager = AccessController.doPrivileged(new PrivilegedAction<LogManager>() {
@Override
public LogManager run() {
LogManager mgr = null;
String cname = null;
try {
cname = System.getProperty("java.util.logging.manager");
if (cname != null) {
try {
@SuppressWarnings("deprecation")
Object tmp = ClassLoader.getSystemClassLoader()
.loadClass(cname).newInstance();
mgr = (LogManager) tmp;
} catch (ClassNotFoundException ex) {
@SuppressWarnings("deprecation")
Object tmp = Thread.currentThread()
.getContextClassLoader().loadClass(cname).newInstance();
mgr = (LogManager) tmp;
// The global LogManager object
@SuppressWarnings("removal")
private static final LogManager manager = AccessController.doPrivileged(
new PrivilegedAction<LogManager>() {
@Override
public LogManager run() {
LogManager mgr = null;
String cname = null;
try {
cname = System.getProperty("java.util.logging.manager");
if (cname != null) {
try {
@SuppressWarnings("deprecation")
Object tmp = ClassLoader.getSystemClassLoader()
.loadClass(cname).newInstance();
mgr = (LogManager) tmp;
} catch (ClassNotFoundException ex) {
@SuppressWarnings("deprecation")
Object tmp = Thread.currentThread()
.getContextClassLoader().loadClass(cname).newInstance();
mgr = (LogManager) tmp;
}
}
} catch (Exception ex) {
System.err.println("Could not load Logmanager \"" + cname + "\"");
ex.printStackTrace();
}
} catch (Exception ex) {
System.err.println("Could not load Logmanager \"" + cname + "\"");
ex.printStackTrace();
}
if (mgr == null) {
mgr = new LogManager();
}
return mgr;
if (mgr == null) {
mgr = new LogManager();
}
return mgr;
}
});
}
}
});
// This private class is used as a shutdown hook.
// It does a "reset" to close all open handlers.
@ -307,6 +305,7 @@ public class LogManager {
}
private static Void checkSubclassPermissions() {
@SuppressWarnings("removal")
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
// These permission will be checked in the LogManager constructor,
@ -338,6 +337,7 @@ public class LogManager {
*/
private boolean initializedCalled = false;
private volatile boolean initializationDone = false;
@SuppressWarnings("removal")
final void ensureLogManagerInitialized() {
final LogManager owner = this;
if (initializationDone || owner != manager) {
@ -462,6 +462,7 @@ public class LogManager {
private LoggerContext getUserContext() {
LoggerContext context = null;
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
if (sm != null && javaAwtAccess != null) {
@ -551,6 +552,7 @@ public class LogManager {
return demandSystemLogger(name, resourceBundleName, module);
}
@SuppressWarnings("removal")
Logger demandSystemLogger(String name, String resourceBundleName, Module module) {
// Add a system logger in the system context's namespace
final Logger sysLogger = getSystemContext()
@ -853,6 +855,7 @@ public class LogManager {
// If logger.getUseParentHandlers() returns 'true' and any of the logger's
// parents have levels or handlers defined, make sure they are instantiated.
@SuppressWarnings("removal")
private void processParentHandlers(final Logger logger, final String name,
Predicate<Logger> visited) {
final LogManager owner = getOwner();
@ -961,6 +964,7 @@ public class LogManager {
// We need to raise privilege here. All our decisions will
// be made based on the logging configuration, which can
// only be modified by trusted code.
@SuppressWarnings("removal")
private void loadLoggerHandlers(final Logger logger, final String name,
final String handlersPropertyName)
{
@ -1226,6 +1230,7 @@ public class LogManager {
// Private method to set a level on a logger.
// If necessary, we raise privilege before doing the call.
@SuppressWarnings("removal")
private static void doSetLevel(final Logger logger, final Level level) {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
@ -1245,6 +1250,7 @@ public class LogManager {
// Private method to set a parent on a logger.
// If necessary, we raise privilege before doing the setParent call.
@SuppressWarnings("removal")
private static void doSetParent(final Logger logger, final Logger parent) {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
@ -2428,6 +2434,7 @@ public class LogManager {
new LoggingPermission("control", null);
void checkPermission() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(controlPermission);
@ -2613,11 +2620,14 @@ public class LogManager {
public LogManager addConfigurationListener(Runnable listener) {
final Runnable r = Objects.requireNonNull(listener);
checkPermission();
@SuppressWarnings("removal")
final SecurityManager sm = System.getSecurityManager();
@SuppressWarnings("removal")
final AccessControlContext acc =
sm == null ? null : AccessController.getContext();
final PrivilegedAction<Void> pa =
acc == null ? null : () -> { r.run() ; return null; };
@SuppressWarnings("removal")
final Runnable pr =
acc == null ? r : () -> AccessController.doPrivileged(pa, acc);
// Will do nothing if already registered.
@ -2710,6 +2720,7 @@ public class LogManager {
}
Objects.requireNonNull(name);
Objects.requireNonNull(module);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(controlPermission);
@ -2732,6 +2743,11 @@ public class LogManager {
}
static {
initStatic();
}
@SuppressWarnings("removal")
private static void initStatic() {
AccessController.doPrivileged(LoggingProviderAccess.INSTANCE, null,
controlPermission);
}