On Fri, 16 Apr 2021 20:30:15 GMT, Rafael Winterhalter 
<winterhal...@openjdk.org> wrote:

>> To allow agents the definition of auxiliary classes, an API is needed to 
>> allow this. Currently, this is often achieved by using `sun.misc.Unsafe` or 
>> `jdk.internal.misc.Unsafe` ever since the `defineClass` method was removed 
>> from `sun.misc.Unsafe`.
>
> Rafael Winterhalter 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.

Sorry to be late to this party. I've been wanting to read this thread for a 
while but have bene too busy up to now. I have just a few comments

I too was party to the discussions about agent capabilities and recall well the 
decision to gradually impose restrictions, the first one being to control 
dynamic agent loading. I was happy to accept that general decision and the 
specific one to limit the opportunity for an agent self-hoisting into the 
current JVM. However, a key part of the plan to move forward on restrictions 
was to provide an override switch. I'd very much like to see that retained as 
an option. I know that in some uses self-hoisting is much preferable to having 
to install the agent on the command line and I'd expect he same to be true for 
any other capabilities for which restrictions were adopted.

Although it is true -- as Ron said - -that configuring -javaagent on the 
command line is always /possible/ there are actually many scenarios for agent 
use where deployment of an agent after startup is pragmatically much more 
desirable. An obvious use is trouble shooting, where you only want an agent in 
place when something goes wrong. That turns out to be critical to solving some 
seriously difficult support cases. The interesting use cases also fall under 
testing where self-hoisting of a test agent by a test framework can result in 
an enormous simplification of test configuration. Usage of Byteman for testing 
went through the roof with this capability in place. Never underestimate the 
degree to which even the most minimal configuration complexity puts off 
Enterprise java developers when it is multiplied by the test suite size of a 
large project.

So, likewise with other restrictions on behaviour, I'm very happy to see them 
put in place for dynamically hoisted agents so long as there is still a command 
line override along the lines of the agent attach property that allows a 
dynamic agent to do all that a command line agent can.

One other thing I'd like to correct is a point made in the discussion about 
agent code residing in the system loader. It is true that the main agent class 
gets loaded by the system loader.  However, it is perfectly possible to ensure 
that all the rest of the agent code is loaded by the bootstrap loader. A Main 
class can add the agent jar to the bootstrap path and then load and use 
reflection to invoke an effective main routine on a bootstrap loaded SubMain 
class.

Byteman uses this trick on request in order to allow it to instrument bootstrap 
classes. Because all the Byteman classes except for the original Main shell 
class are loaded by the bootstrap loader Byteman can safely inject references 
to the Byteman rule engine and Byteman exception classes into bootstrap code.

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

PR: https://git.openjdk.java.net/jdk/pull/3546

Reply via email to