src/java.instrument/share/classes/java/lang/instrument/package-info.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 54080 75268d993deb
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     1
/*
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     4
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
54080
75268d993deb 8220474: Incorrect GPL header in src/java.instrument/share/classes/java/lang/instrument/package-info.java
gadams
parents: 54079
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    10
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    15
 * accompanied this code).
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    16
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    20
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    23
 * questions.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    24
 */
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    25
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    26
/*
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    27
 * Copyright 2003 Wily Technology, Inc.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    28
 */
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    29
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    30
/**
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    31
 * Provides services that allow Java programming language agents to instrument
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    32
 * programs running on the JVM. The mechanism for instrumentation is modification
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    33
 * of the byte-codes of methods.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    34
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    35
 * <p> An agent is deployed as a JAR file. An attribute in the JAR file manifest
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    36
 * specifies the agent class which will be loaded to start the agent. Agents can
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    37
 * be started in several ways:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    38
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    39
 * <ol>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    40
 *   <li><p> For implementations that support a command-line interface, an agent
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    41
 *   can be started by specifying an option on the command-line. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    42
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    43
 *   <li><p> An implementation may support a mechanism to start agents some time
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    44
 *   after the VM has started. For example, an implementation may provide a
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    45
 *   mechanism that allows a tool to <i>attach</i> to a running application, and
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    46
 *   initiate the loading of the tool's agent into the running application. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    47
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    48
 *   <li><p> An agent may be packaged with an application in an executable JAR
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    49
 *   file.</p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    50
 * </ol>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    51
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    52
 * <p> Each of these ways to start an agent is described below.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    53
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    54
 *
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
    55
 * <h2>Starting an Agent from the Command-Line Interface</h2>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    56
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    57
 * <p> Where an implementation provides a means to start agents from the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    58
 * command-line interface, an agent is started by adding the following option
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    59
 * to the command-line:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    60
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    61
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    62
 *     -javaagent:<jarpath>[=<options>]
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    63
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    64
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    65
 * where <i>{@code <jarpath>}</i> is the path to the agent JAR file and
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    66
 * <i>{@code <options>}</i> is the agent options.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    67
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    68
 * <p> The manifest of the agent JAR file must contain the attribute {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    69
 * Premain-Class} in its main manifest. The value of this attribute is the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    70
 * name of the <i>agent class</i>. The agent class must implement a public
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    71
 * static {@code premain} method similar in principle to the {@code main}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    72
 * application entry point. After the Java Virtual Machine (JVM) has
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    73
 * initialized, the {@code premain} method will be called, then the real
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    74
 * application {@code main} method. The {@code premain} method must return
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    75
 * in order for the startup to proceed.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    76
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    77
 * <p> The {@code premain} method has one of two possible signatures. The
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    78
 * JVM first attempts to invoke the following method on the agent class:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    79
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    80
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    81
 *     public static void premain(String agentArgs, Instrumentation inst)
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    82
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    83
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    84
 * <p> If the agent class does not implement this method then the JVM will
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    85
 * attempt to invoke:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    86
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    87
 *     public static void premain(String agentArgs)
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    88
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    89
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    90
 * <p> The agent class may also have an {@code agentmain} method for use when
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    91
 * the agent is started after VM startup (see below). When the agent is started
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    92
 * using a command-line option, the {@code agentmain} method is not invoked.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    93
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    94
 * <p> Each agent is passed its agent options via the {@code agentArgs} parameter.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    95
 * The agent options are passed as a single string, any additional parsing
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    96
 * should be performed by the agent itself.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    97
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    98
 * <p> If the agent cannot be started (for example, because the agent class
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
    99
 * cannot be loaded, or because the agent class does not have an appropriate
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   100
 * {@code premain} method), the JVM will abort. If a {@code premain} method
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   101
 * throws an uncaught exception, the JVM will abort.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   102
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   103
 * <p> An implementation is not required to provide a way to start agents
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   104
 * from the command-line interface. When it does, then it supports the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   105
 * {@code -javaagent} option as specified above. The {@code -javaagent} option
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   106
 * may be used multiple times on the same command-line, thus starting multiple
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   107
 * agents. The {@code premain} methods will be called in the order that the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   108
 * agents are specified on the command line. More than one agent may use the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   109
 * same <i>{@code <jarpath>}</i>.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   110
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   111
 * <p> There are no modeling restrictions on what the agent {@code premain}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   112
 * method may do. Anything application {@code main} can do, including creating
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   113
 * threads, is legal from {@code premain}.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   114
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   115
 *
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   116
 * <h2>Starting an Agent After VM Startup</h2>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   117
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   118
 * <p> An implementation may provide a mechanism to start agents sometime after
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   119
 * the the VM has started. The details as to how this is initiated are
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   120
 * implementation specific but typically the application has already started and
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   121
 * its {@code main} method has already been invoked. In cases where an
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   122
 * implementation supports the starting of agents after the VM has started the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   123
 * following applies:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   124
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   125
 * <ol>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   126
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   127
 *   <li><p> The manifest of the agent JAR must contain the attribute {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   128
 *   Agent-Class} in its main manfiest. The value of this attribute is the name
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   129
 *   of the <i>agent class</i>. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   130
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   131
 *   <li><p> The agent class must implement a public static {@code agentmain}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   132
 *   method. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   133
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   134
 * </ol>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   135
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   136
 * <p> The {@code agentmain} method has one of two possible signatures. The JVM
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   137
 * first attempts to invoke the following method on the agent class:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   138
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   139
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   140
 *     public static void agentmain(String agentArgs, Instrumentation inst)
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   141
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   142
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   143
 * <p> If the agent class does not implement this method then the JVM will
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   144
 * attempt to invoke:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   145
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   146
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   147
 *     public static void agentmain(String agentArgs)
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   148
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   149
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   150
 * <p> The agent class may also have a {@code premain} method for use when the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   151
 * agent is started using a command-line option. When the agent is started after
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   152
 * VM startup the {@code premain} method is not invoked.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   153
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   154
 * <p> The agent is passed its agent options via the {@code agentArgs}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   155
 * parameter. The agent options are passed as a single string, any additional
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   156
 * parsing should be performed by the agent itself.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   157
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   158
 * <p> The {@code agentmain} method should do any necessary initialization
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   159
 * required to start the agent. When startup is complete the method should
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   160
 * return. If the agent cannot be started (for example, because the agent class
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   161
 * cannot be loaded, or because the agent class does not have a conformant
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   162
 * {@code agentmain} method), the JVM will not abort. If the {@code agentmain}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   163
 * method throws an uncaught exception it will be ignored (but may be logged
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   164
 * by the JVM for troubleshooting purposes).
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   165
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   166
 *
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   167
 * <h2>Including an Agent in an Executable JAR file</h2>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   168
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   169
 * <p> The JAR File Specification defines manifest attributes for standalone
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   170
 * applications that are packaged as <em>executable JAR files</em>. If an
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   171
 * implementation supports a mechanism to start an application as an executable
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   172
 * JAR then the main manifest may include the {@code Launcher-Agent-Class}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   173
 * attribute to specify the class name of an agent to start before the application
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   174
 * {@code main} method is invoked. The Java virtual machine attempts to
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   175
 * invoke the following method on the agent class:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   176
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   177
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   178
 *     public static void agentmain(String agentArgs, Instrumentation inst)
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   179
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   180
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   181
 * <p> If the agent class does not implement this method then the JVM will
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   182
 * attempt to invoke:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   183
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   184
 * <blockquote>{@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   185
 *     public static void agentmain(String agentArgs)
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   186
 * }</blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   187
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   188
 * <p> The value of the {@code agentArgs} parameter is always the empty string.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   189
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   190
 * <p> The {@code agentmain} method should do any necessary initialization
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   191
 * required to start the agent and return. If the agent cannot be started, for
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   192
 * example the agent class cannot be loaded, the agent class does not define a
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   193
 * conformant {@code agentmain} method, or the {@code agentmain} method throws
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   194
 * an uncaught exception or error, the JVM will abort.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   195
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   196
 *
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   197
 * <h2> Loading agent classes and the modules/classes available to the agent
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   198
 * class </h2>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   199
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   200
 * <p> Classes loaded from the agent JAR file are loaded by the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   201
 * {@linkplain ClassLoader#getSystemClassLoader() system class loader} and are
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   202
 * members of the system class loader's {@linkplain ClassLoader#getUnnamedModule()
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   203
 * unnamed module}. The system class loader typically defines the class containing
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   204
 * the application {@code main} method too.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   205
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   206
 * <p> The classes visible to the agent class are the classes visible to the system
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   207
 * class loader and minimally include:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   208
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   209
 * <ul>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   210
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   211
 *   <li><p> The classes in packages exported by the modules in the {@linkplain
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   212
 *   ModuleLayer#boot() boot layer}. Whether the boot layer contains all platform
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   213
 *   modules or not will depend on the initial module or how the application was
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   214
 *   started. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   215
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   216
 *   <li><p> The classes that can be defined by the system class loader (typically
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   217
 *   the class path) to be members of its unnamed module. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   218
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   219
 *   <li><p> Any classes that the agent arranges to be defined by the bootstrap
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   220
 *   class loader to be members of its unnamed module. </p></li>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   221
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   222
 * </ul>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   223
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   224
 * <p> If agent classes need to link to classes in platform (or other) modules
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   225
 * that are not in the boot layer then the application may need to be started in
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   226
 * a way that ensures that these modules are in the boot layer. In the JDK
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   227
 * implementation for example, the {@code --add-modules} command line option can
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   228
 * be used to add modules to the set of root modules to resolve at startup. </p>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   229
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   230
 * <p> Supporting classes that the agent arranges to be loaded by the bootstrap
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   231
 * class loader (by means of {@link Instrumentation#appendToBootstrapClassLoaderSearch
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   232
 * appendToBootstrapClassLoaderSearch} or the {@code Boot-Class-Path} attribute
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   233
 * specified below), must link only to classes defined to the bootstrap class loader.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   234
 * There is no guarantee that all platform classes can be defined by the boot
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   235
 * class loader.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   236
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   237
 * <p> If a custom system class loader is configured (by means of the system property
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   238
 * {@code java.system.class.loader} as specified in the {@link
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   239
 * ClassLoader#getSystemClassLoader() getSystemClassLoader} method) then it must
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   240
 * define the {@code appendToClassPathForInstrumentation} method as specified in
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   241
 * {@link Instrumentation#appendToSystemClassLoaderSearch appendToSystemClassLoaderSearch}.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   242
 * In other words, a custom system class loader must support the mechanism to
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   243
 * add an agent JAR file to the system class loader search.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   244
 *
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   245
 * <h2>Manifest Attributes</h2>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   246
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   247
 * <p> The following manifest attributes are defined for an agent JAR file:
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   248
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   249
 * <blockquote><dl>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   250
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   251
 * <dt>{@code Premain-Class}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   252
 * <dd> When an agent is specified at JVM launch time this attribute specifies
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   253
 * the agent class. That is, the class containing the {@code premain} method.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   254
 * When an agent is specified at JVM launch time this attribute is required. If
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   255
 * the attribute is not present the JVM will abort. Note: this is a class name,
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   256
 * not a file name or path. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   257
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   258
 * <dt>{@code Agent-Class}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   259
 * <dd> If an implementation supports a mechanism to start agents sometime after
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   260
 * the VM has started then this attribute specifies the agent class. That is,
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   261
 * the class containing the {@code agentmain} method. This attribute is required
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   262
 * if it is not present the agent will not be started. Note: this is a class name,
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   263
 * not a file name or path. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   264
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   265
 * <dt>{@code Launcher-Agent-Class}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   266
 * <dd> If an implementation supports a mechanism to start an application as an
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   267
 * executable JAR then the main manifest may include this attribute to specify
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   268
 * the class name of an agent to start before the application {@code main}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   269
 * method is invoked. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   270
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   271
 * <dt>{@code Boot-Class-Path}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   272
 * <dd> A list of paths to be searched by the bootstrap class loader. Paths
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   273
 * represent directories or libraries (commonly referred to as JAR or zip
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   274
 * libraries on many platforms). These paths are searched by the bootstrap class
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   275
 * loader after the platform specific mechanisms of locating a class have failed.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   276
 * Paths are searched in the order listed. Paths in the list are separated by one
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   277
 * or more spaces. A path takes the syntax of the path component of a hierarchical
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   278
 * URI. The path is absolute if it begins with a slash character ('/'), otherwise
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   279
 * it is relative. A relative path is resolved against the absolute path of the
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   280
 * agent JAR file. Malformed and non-existent paths are ignored. When an agent is
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   281
 * started sometime after the VM has started then paths that do not represent a
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   282
 * JAR file are ignored. This attribute is optional. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   283
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   284
 * <dt>{@code Can-Redefine-Classes}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   285
 * <dd> Boolean ({@code true} or {@code false}, case irrelevant). Is the ability
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   286
 * to redefine classes needed by this agent. Values other than {@code true} are
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   287
 * considered {@code false}. This attribute is optional, the default is {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   288
 * false}. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   289
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   290
 * <dt>{@code Can-Retransform-Classes}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   291
 * <dd> Boolean ({@code true} or {@code false}, case irrelevant). Is the ability
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   292
 * to retransform classes needed by this agent. Values other than {@code true}
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   293
 * are considered {@code false}. This attribute is optional, the default is
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   294
 * {@code false}. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   295
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   296
 * <dt>{@code Can-Set-Native-Method-Prefix}</dt>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   297
 * <dd> Boolean ({@code true} or {@code false}, case irrelevant). Is the ability
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   298
 * to set native method prefix needed by this agent. Values other than {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   299
 * true} are considered {@code false}. This attribute is optional, the default
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   300
 * is {@code false}. </dd>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   301
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   302
 * </dl></blockquote>
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   303
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   304
 * <p> An agent JAR file may have both the {@code Premain-Class} and {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   305
 * Agent-Class} attributes present in the manifest. When the agent is started
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   306
 * on the command-line using the {@code -javaagent} option then the {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   307
 * Premain-Class} attribute specifies the name of the agent class and the {@code
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   308
 * Agent-Class} attribute is ignored. Similarly, if the agent is started sometime
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   309
 * after the VM has started, then the {@code Agent-Class} attribute specifies
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   310
 * the name of the agent class (the value of {@code Premain-Class} attribute is
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   311
 * ignored).
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   312
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   313
 *
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   314
 * <h2>Instrumenting code in modules</h2>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   315
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   316
 * <p> As an aid to agents that deploy supporting classes on the search path of
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   317
 * the bootstrap class loader, or the search path of the class loader that loads
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   318
 * the main agent class, the Java virtual machine arranges for the module of
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   319
 * transformed classes to read the unnamed module of both class loaders.
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   320
 *
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   321
 * @since 1.5
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   322
 * @revised 1.6
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   323
 * @revised 9
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   324
 */
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents:
diff changeset
   325
54079
018217e30f5c 8220257: fix headings in java.instrument
gadams
parents: 47216
diff changeset
   326
package java.lang.instrument;