RFR: 8307478: Implementation of Prepare to Restrict The Dynamic Loading of Agents [v4]
Chris Plummer
cjplummer at openjdk.org
Mon May 22 23:35:58 UTC 2023
On Fri, 19 May 2023 17:11:36 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> This is the implementation for JEP 451. There are two parts to this:
>>
>> 1. A multi-line warning is printed when a JVM TI or Java agent is loaded into a running VM. For JVM TI, the message is printed to stderr from JvmtiAgent::load. For Java agents, it is printed to System.err (as that may be redirected) in the JPLIS (j.l.instrumentation) implementation. This part includes an update to the JVM TI spec and API docs to require the warning.
>>
>> 2. If running with -Djdk.instrument.traceUsage or -Djdk.instrument.traceUsage=true, the calls to the Instrumentation API print a trace message and stack trace.
>
> Alan Bateman has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 10 additional commits since the last revision:
>
> - Merge
> - Refresh package description
> - Merge
> - Tweak docs
> - Merge
> - Draft docs changes
> - Merge
> - Rename/cleanup
> - Merge
> - Initial commit
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 61:
> 59: * manifest attributes for standalone applications that are packaged as <em>executable
> 60: * JAR files</em>. If an implementation supports a mechanism to start an application as
> 61: * an executable JAR then the main manifest of the JAR file can include the
Suggestion:
* JAR files</em>. If an implementation supports a mechanism to start an application as
* an executable JAR, then the main manifest of the JAR file can include the
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 65:
> 63: * class that is packaged with the application. If the attribute is present then the
> 64: * JVM starts the agent, by loading the agent class and invoking its {@code agentmain}
> 65: * method, before the application {@code main} method is invoked.
Suggestion:
* class that is packaged with the application. If the attribute is present, then the
* JVM starts the agent by loading the agent class and invoking its {@code agentmain}
* method before the application {@code main} method is invoked.
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 73:
> 71: * }</blockquote>
> 72: *
> 73: * <p> If the agent class does not define this method then the JVM will attempt
Suggestion:
* <p> If the agent class does not define this method, then the JVM will attempt
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 106:
> 104: * Premain-Class}. The value of this attribute is the binary name of the agent class
> 105: * in the JAR file. The JVM starts the agent, by loading the agent class and invoking
> 106: * its {@code premain} method, before the application {@code main} method is invoked.
Suggestion:
* in the JAR file. The JVM starts the agent by loading the agent class and invoking
* its {@code premain} method before the application {@code main} method is invoked.
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 146:
> 144: * <p> An implementation may provide a mechanism to start agents in a running VM (meaning
> 145: * after JVM startup). The details as to how this is initiated are implementation specific
> 146: * but typically the application has already started and its {@code main} method has
Suggestion:
* after JVM startup). The details as to how this is initiated are implementation specific,
* but typically the application has already started and its {@code main} method has
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 194:
> 192: * <p> The agent class may also have a {@code premain} method for use when the agent
> 193: * is started using a command-line option. When the agent is started in a running JVM
> 194: * the {@code premain} method is not invoked.
Suggestion:
* is started using a command-line option. When the agent is started in a running JVM,
* the {@code premain} method is not invoked.
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 253:
> 251: * <dt>{@code Launcher-Agent-Class}</dt>
> 252: * <dd> If an implementation supports a mechanism to start an application in an
> 253: * executable JAR file then this attribute, if present, specifies the binary name
Suggestion:
* <dd> If an implementation supports a mechanism to start an application in an
* executable JAR file, then this attribute, if present, specifies the binary name
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 256:
> 254: * of the agent class that is packaged with the application.
> 255: * The agent is started, by invoking the agent class {@code agentmain} method,
> 256: * before the application {@code main} method is invoked. </dd>
Suggestion:
* The agent is started by invoking the agent class {@code agentmain} method
* before the application {@code main} method is invoked. </dd>
src/java.instrument/share/classes/java/lang/instrument/package-info.java line 262:
> 260: * the binary name of the agent class in the JAR file.
> 261: * The agent is started, by invoking the agent class {@code premain} method,
> 262: * before the application {@code main} method is invoked.
Suggestion:
* The agent is started by invoking the agent class {@code premain} method
* before the application {@code main} method is invoked.
src/java.instrument/share/native/libinstrument/InvocationAdapter.c line 161:
> 159: }
> 160:
> 161: initerror = createNewJPLISAgent(vm, &agent, jarfile, JNI_FALSE);
No warning is ever printed in this case since this is an agent being loaded due to -javaagent on the command line. Correct?
src/java.instrument/share/native/libinstrument/InvocationAdapter.c line 501:
> 499:
> 500: // create JPLISAgent with JVMTI environment
> 501: if (createNewJPLISAgent(vm, &agent, jarfile, JNI_FALSE) != JPLIS_INIT_ERROR_NONE) {
No warning is ever printed in this case since this is an agent being loaded from an executable JAR. Correct?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201264543
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201266407
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201266670
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201267997
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201269344
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201270901
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201271453
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201271684
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201272099
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201293583
PR Review Comment: https://git.openjdk.org/jdk/pull/13899#discussion_r1201292355
More information about the serviceability-dev
mailing list