RFR: 6964: [Agent] Automatically open base module for accessing Unsafe on JDK 11+ [v3]
Marcus Hirt
hirt at openjdk.java.net
Wed Nov 25 15:53:58 UTC 2020
On Sat, 21 Nov 2020 19:52:09 GMT, Gunnar Morling <github.com+28612+gunnarmorling at openjdk.org> wrote:
>> So here's a fresh take on the `Unsafe` / `add-opens` issue for JMC Agent. This still is using `Unsafe`, but I'm using the instrumentation API for opening up the base module within the agent itself, instead of requiring the user to do so. Ideally, we'd still get away from `Unsafe`, but this make the agent easier to use. This is still a draft, would do some more polishing if you all think it's the right approach. Feedback welcome!
>
> Gunnar Morling has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains two commits:
>
> - 6964: Refactor - Unifying handling of Java version
> - 6964: Automatically open base module for accessing Unsafe on JDK 11+
Changes requested by hirt (Lead).
agent/src/main/java/org/openjdk/jmc/agent/util/ModuleUtils.java line 3:
> 1: /*
> 2: * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
> 3: * Copyright (c) 2020 Red Hat Inc. All rights reserved.
Comma after year.
agent/src/main/java/org/openjdk/jmc/agent/util/ModuleUtils.java line 56:
> 54: if (featureVersion >= 11) {
> 55:
> 56: Method redefineModule = getRedefineModuleMethod();
I am not great with the access controller and running with a security manager, but are these reflective checks and module openings something that would benefit from doPrivileged?
Even the (JDK) implementation of the Instrumentation interface is using doPrivileged to do reflective stuff (getting access to premain and agentmain).
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java#L416
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java#L509
-------------
PR: https://git.openjdk.java.net/jmc/pull/152
More information about the jmc-dev
mailing list