RFR: 6964: [Agent] Automatically open base module for accessing Unsafe on JDK 11+ [v2]
Marcus Hirt
hirt at openjdk.java.net
Tue Nov 10 23:16:55 UTC 2020
On Tue, 3 Nov 2020 08:32:05 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 refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
>
> 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/VersionUtils.java line 70:
> 68:
> 69: } catch (Exception e) {
> 70: System.out.println("Could not identify Java version. The agent will not work"); //$NON-NLS-1$
A system exit from a method named determineFeatureVersion seems slightly evil. ;)
agent/src/main/java/org/openjdk/jmc/agent/Agent.java line 97:
> 95: );
> 96: } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
> 97: System.out.println(
Perhaps moving the openUnsafePackage method out of the Agent class might be nice to keep the agent class clean. Also, since you use the same pattern in the VersionUtils, perhaps some static printAndExit(Exception e, int errorCode, String message) too. And perhaps use different exit codes for failing to open up the package vs not being able to determine the version.
Perhaps you could have an AgentStartupUtils under the agent.impl package and move the VersionUtils methods there too? These are only used when starting the agent.
-------------
PR: https://git.openjdk.java.net/jmc/pull/152
More information about the jmc-dev
mailing list