From 70eb95f8488aa39c22ee404c1a4756ecf5db7af6 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 18 Nov 2024 19:18:22 +0000 Subject: [PATCH] 8344187: Remove SecurityManager and related calls from java.instrument Reviewed-by: alanb, amenkov --- .../lang/instrument/ClassFileTransformer.java | 2 - .../sun/instrument/InstrumentationImpl.java | 38 +++---------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java b/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java index ee2037fac5b..7091847a599 100644 --- a/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java +++ b/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java @@ -25,8 +25,6 @@ package java.lang.instrument; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.security.ProtectionDomain; /* diff --git a/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java b/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java index 3aeddd1c90d..bd54b89aee6 100644 --- a/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java +++ b/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java @@ -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. * * 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.InvalidPathException; import java.net.URL; -import java.security.AccessController; import java.security.CodeSource; import java.security.PrivilegedAction; 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 boolean TRACE_USAGE; static { - PrivilegedAction pa = () -> System.getProperty(TRACE_USAGE_PROP_NAME); - @SuppressWarnings("removal") - String s = AccessController.doPrivileged(pa); + String s = System.getProperty(TRACE_USAGE_PROP_NAME); TRACE_USAGE = (s != null) && (s.isEmpty() || Boolean.parseBoolean(s)); } @@ -100,9 +97,7 @@ public class InstrumentationImpl implements Instrumentation { String source = jarFile(nativeAgent); try { Path path = Path.of(source); - PrivilegedAction pa = path::toAbsolutePath; - @SuppressWarnings("removal") - Path absolutePath = AccessController.doPrivileged(pa); + Path absolutePath = path.toAbsolutePath(); source = absolutePath.toString(); } catch (InvalidPathException e) { // use original path @@ -482,18 +477,6 @@ public class InstrumentationImpl implements Instrumentation { * 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() { - public Object run() { - ao.setAccessible(accessible); - return null; - }}); - } - // Attempt to load and start an agent private void loadClassAndStartAgent( String classname, @@ -553,7 +536,7 @@ public class InstrumentationImpl implements Instrumentation { !javaAgentClass.getModule().isNamed()) { // 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. - setAccessible(m, true); + m.setAccessible(true); } // 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. */ private static URL codeSource(Class clazz) { - PrivilegedAction pa = clazz::getProtectionDomain; - @SuppressWarnings("removal") - CodeSource cs = AccessController.doPrivileged(pa).getCodeSource(); + CodeSource cs = clazz.getProtectionDomain().getCodeSource(); return (cs != null) ? cs.getLocation() : null; } @@ -675,13 +656,6 @@ public class InstrumentationImpl implements Instrumentation { * Holder for StackWalker object. */ private static class HolderStackWalker { - static final StackWalker walker; - static { - PrivilegedAction pa = () -> - StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); - @SuppressWarnings("removal") - StackWalker w = AccessController.doPrivileged(pa); - walker = w; - } + static final StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); } }