RFR: 6964: [Agent] Automatically open base module for accessing Unsafe on JDK 11+ [v3]

Gunnar Morling github.com+28612+gunnarmorling at openjdk.java.net
Wed Nov 25 16:06:00 UTC 2020


On Wed, 25 Nov 2020 15:48:47 GMT, Marcus Hirt <hirt at openjdk.org> wrote:

>> 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+
>
> 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

Is anyone using the security manager still these days ;)

If we wanted to support it, maybe let's tackle that via a separate issue? I think this will need more holistic consideration, there's other places too where a privileged action would be needed (e.g. when obtaining the `Unsafe`). 

Personally, I don't think it's worth the effort and would wait for user feedback/requirement for it. As one data point, we added SM support for Hibernate Validator and never heard anything about it (well, perhaps it just worked). But we didn't do it for Hibernate ORM, and we didn't hear anything there either. Testing for SM is a rather painful experience, too, as you have JUnit and things like that on the callstack and need to accomodate for that.

> 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.

Will add.

-------------

PR: https://git.openjdk.java.net/jmc/pull/152


More information about the jmc-dev mailing list