8344187: Remove SecurityManager and related calls from java.instrument
Reviewed-by: alanb, amenkov
This commit is contained in:
parent
922b12f30c
commit
70eb95f848
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package java.lang.instrument;
|
package java.lang.instrument;
|
||||||
|
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -36,7 +36,6 @@ import java.io.PrintStream;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.InvalidPathException;
|
import java.nio.file.InvalidPathException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
@ -68,9 +67,7 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
private static final String TRACE_USAGE_PROP_NAME = "jdk.instrument.traceUsage";
|
private static final String TRACE_USAGE_PROP_NAME = "jdk.instrument.traceUsage";
|
||||||
private static final boolean TRACE_USAGE;
|
private static final boolean TRACE_USAGE;
|
||||||
static {
|
static {
|
||||||
PrivilegedAction<String> pa = () -> System.getProperty(TRACE_USAGE_PROP_NAME);
|
String s = System.getProperty(TRACE_USAGE_PROP_NAME);
|
||||||
@SuppressWarnings("removal")
|
|
||||||
String s = AccessController.doPrivileged(pa);
|
|
||||||
TRACE_USAGE = (s != null) && (s.isEmpty() || Boolean.parseBoolean(s));
|
TRACE_USAGE = (s != null) && (s.isEmpty() || Boolean.parseBoolean(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +97,7 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
String source = jarFile(nativeAgent);
|
String source = jarFile(nativeAgent);
|
||||||
try {
|
try {
|
||||||
Path path = Path.of(source);
|
Path path = Path.of(source);
|
||||||
PrivilegedAction<Path> pa = path::toAbsolutePath;
|
Path absolutePath = path.toAbsolutePath();
|
||||||
@SuppressWarnings("removal")
|
|
||||||
Path absolutePath = AccessController.doPrivileged(pa);
|
|
||||||
source = absolutePath.toString();
|
source = absolutePath.toString();
|
||||||
} catch (InvalidPathException e) {
|
} catch (InvalidPathException e) {
|
||||||
// use original path
|
// use original path
|
||||||
@ -482,18 +477,6 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
* Internals
|
* Internals
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Enable or disable Java programming language access checks on a
|
|
||||||
// reflected object (for example, a method)
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private static void setAccessible(final AccessibleObject ao, final boolean accessible) {
|
|
||||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
|
||||||
public Object run() {
|
|
||||||
ao.setAccessible(accessible);
|
|
||||||
return null;
|
|
||||||
}});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to load and start an agent
|
// Attempt to load and start an agent
|
||||||
private void
|
private void
|
||||||
loadClassAndStartAgent( String classname,
|
loadClassAndStartAgent( String classname,
|
||||||
@ -553,7 +536,7 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
!javaAgentClass.getModule().isNamed()) {
|
!javaAgentClass.getModule().isNamed()) {
|
||||||
// If the java agent class is in an unnamed module, the java agent class can be non-public.
|
// If the java agent class is in an unnamed module, the java agent class can be non-public.
|
||||||
// Suppress access check upon the invocation of the premain/agentmain method.
|
// Suppress access check upon the invocation of the premain/agentmain method.
|
||||||
setAccessible(m, true);
|
m.setAccessible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke the 1 or 2-arg method
|
// invoke the 1 or 2-arg method
|
||||||
@ -665,9 +648,7 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
* Returns the possibly-bnull code source of the given class.
|
* Returns the possibly-bnull code source of the given class.
|
||||||
*/
|
*/
|
||||||
private static URL codeSource(Class<?> clazz) {
|
private static URL codeSource(Class<?> clazz) {
|
||||||
PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain;
|
CodeSource cs = clazz.getProtectionDomain().getCodeSource();
|
||||||
@SuppressWarnings("removal")
|
|
||||||
CodeSource cs = AccessController.doPrivileged(pa).getCodeSource();
|
|
||||||
return (cs != null) ? cs.getLocation() : null;
|
return (cs != null) ? cs.getLocation() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,13 +656,6 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
* Holder for StackWalker object.
|
* Holder for StackWalker object.
|
||||||
*/
|
*/
|
||||||
private static class HolderStackWalker {
|
private static class HolderStackWalker {
|
||||||
static final StackWalker walker;
|
static final StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
||||||
static {
|
|
||||||
PrivilegedAction<StackWalker> pa = () ->
|
|
||||||
StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
StackWalker w = AccessController.doPrivileged(pa);
|
|
||||||
walker = w;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user