|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2003, 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
|
|
36 | 36 | import java.nio.file.Path;
|
37 | 37 | import java.nio.file.InvalidPathException;
|
38 | 38 | import java.net.URL;
|
39 |
| -import java.security.AccessController; |
40 | 39 | import java.security.CodeSource;
|
41 | 40 | import java.security.PrivilegedAction;
|
42 | 41 | import java.security.ProtectionDomain;
|
@@ -68,9 +67,7 @@ public class InstrumentationImpl implements Instrumentation {
|
68 | 67 | private static final String TRACE_USAGE_PROP_NAME = "jdk.instrument.traceUsage";
|
69 | 68 | private static final boolean TRACE_USAGE;
|
70 | 69 | static {
|
71 |
| - PrivilegedAction<String> pa = () -> System.getProperty(TRACE_USAGE_PROP_NAME); |
72 |
| - @SuppressWarnings("removal") |
73 |
| - String s = AccessController.doPrivileged(pa); |
| 70 | + String s = System.getProperty(TRACE_USAGE_PROP_NAME); |
74 | 71 | TRACE_USAGE = (s != null) && (s.isEmpty() || Boolean.parseBoolean(s));
|
75 | 72 | }
|
76 | 73 |
|
@@ -100,9 +97,7 @@ public class InstrumentationImpl implements Instrumentation {
|
100 | 97 | String source = jarFile(nativeAgent);
|
101 | 98 | try {
|
102 | 99 | Path path = Path.of(source);
|
103 |
| - PrivilegedAction<Path> pa = path::toAbsolutePath; |
104 |
| - @SuppressWarnings("removal") |
105 |
| - Path absolutePath = AccessController.doPrivileged(pa); |
| 100 | + Path absolutePath = path.toAbsolutePath(); |
106 | 101 | source = absolutePath.toString();
|
107 | 102 | } catch (InvalidPathException e) {
|
108 | 103 | // use original path
|
@@ -482,18 +477,6 @@ private TransformerManager findTransformerManager(ClassFileTransformer transform
|
482 | 477 | * Internals
|
483 | 478 | */
|
484 | 479 |
|
485 |
| - |
486 |
| - // Enable or disable Java programming language access checks on a |
487 |
| - // reflected object (for example, a method) |
488 |
| - @SuppressWarnings("removal") |
489 |
| - private static void setAccessible(final AccessibleObject ao, final boolean accessible) { |
490 |
| - AccessController.doPrivileged(new PrivilegedAction<Object>() { |
491 |
| - public Object run() { |
492 |
| - ao.setAccessible(accessible); |
493 |
| - return null; |
494 |
| - }}); |
495 |
| - } |
496 |
| - |
497 | 480 | // Attempt to load and start an agent
|
498 | 481 | private void
|
499 | 482 | loadClassAndStartAgent( String classname,
|
@@ -553,7 +536,7 @@ public Object run() {
|
553 | 536 | !javaAgentClass.getModule().isNamed()) {
|
554 | 537 | // If the java agent class is in an unnamed module, the java agent class can be non-public.
|
555 | 538 | // Suppress access check upon the invocation of the premain/agentmain method.
|
556 |
| - setAccessible(m, true); |
| 539 | + m.setAccessible(true); |
557 | 540 | }
|
558 | 541 |
|
559 | 542 | // invoke the 1 or 2-arg method
|
@@ -665,23 +648,14 @@ private void trace(String methodName) {
|
665 | 648 | * Returns the possibly-bnull code source of the given class.
|
666 | 649 | */
|
667 | 650 | private static URL codeSource(Class<?> clazz) {
|
668 |
| - PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain; |
669 |
| - @SuppressWarnings("removal") |
670 |
| - CodeSource cs = AccessController.doPrivileged(pa).getCodeSource(); |
| 651 | + CodeSource cs = clazz.getProtectionDomain().getCodeSource(); |
671 | 652 | return (cs != null) ? cs.getLocation() : null;
|
672 | 653 | }
|
673 | 654 |
|
674 | 655 | /**
|
675 | 656 | * Holder for StackWalker object.
|
676 | 657 | */
|
677 | 658 | private static class HolderStackWalker {
|
678 |
| - static final StackWalker walker; |
679 |
| - static { |
680 |
| - PrivilegedAction<StackWalker> pa = () -> |
681 |
| - StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); |
682 |
| - @SuppressWarnings("removal") |
683 |
| - StackWalker w = AccessController.doPrivileged(pa); |
684 |
| - walker = w; |
685 |
| - } |
| 659 | + static final StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); |
686 | 660 | }
|
687 | 661 | }
|
0 commit comments