Path: blob/master/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java
41159 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang.instrument;2627import java.security.ProtectionDomain;28import java.util.List;29import java.util.Map;30import java.util.Set;31import java.util.jar.JarFile;3233/*34* Copyright 2003 Wily Technology, Inc.35*/3637/**38* This class provides services needed to instrument Java39* programming language code.40* Instrumentation is the addition of byte-codes to methods for the41* purpose of gathering data to be utilized by tools.42* Since the changes are purely additive, these tools do not modify43* application state or behavior.44* Examples of such benign tools include monitoring agents, profilers,45* coverage analyzers, and event loggers.46*47* <P>48* There are two ways to obtain an instance of the49* <code>Instrumentation</code> interface:50*51* <ol>52* <li><p> When a JVM is launched in a way that indicates an agent53* class. In that case an <code>Instrumentation</code> instance54* is passed to the <code>premain</code> method of the agent class.55* </p></li>56* <li><p> When a JVM provides a mechanism to start agents sometime57* after the JVM is launched. In that case an <code>Instrumentation</code>58* instance is passed to the <code>agentmain</code> method of the59* agent code. </p> </li>60* </ol>61* <p>62* These mechanisms are described in the63* {@linkplain java.lang.instrument package specification}.64* <p>65* Once an agent acquires an <code>Instrumentation</code> instance,66* the agent may call methods on the instance at any time.67*68* @apiNote This interface is not intended to be implemented outside of69* the java.instrument module.70*71* @since 1.572*/73public interface Instrumentation {74/**75* Registers the supplied transformer. All future class definitions76* will be seen by the transformer, except definitions of classes upon which any77* registered transformer is dependent.78* The transformer is called when classes are loaded, when they are79* {@linkplain #redefineClasses redefined}. and if <code>canRetransform</code> is true,80* when they are {@linkplain #retransformClasses retransformed}.81* {@link ClassFileTransformer} defines the order of transform calls.82*83* If a transformer throws84* an exception during execution, the JVM will still call the other registered85* transformers in order. The same transformer may be added more than once,86* but it is strongly discouraged -- avoid this by creating a new instance of87* transformer class.88* <P>89* This method is intended for use in instrumentation, as described in the90* {@linkplain Instrumentation class specification}.91*92* @param transformer the transformer to register93* @param canRetransform can this transformer's transformations be retransformed94* @throws java.lang.NullPointerException if passed a <code>null</code> transformer95* @throws java.lang.UnsupportedOperationException if <code>canRetransform</code>96* is true and the current configuration of the JVM does not allow97* retransformation ({@link #isRetransformClassesSupported} is false)98* @since 1.699*/100void101addTransformer(ClassFileTransformer transformer, boolean canRetransform);102103/**104* Registers the supplied transformer.105* <P>106* Same as <code>addTransformer(transformer, false)</code>.107*108* @param transformer the transformer to register109* @throws java.lang.NullPointerException if passed a <code>null</code> transformer110* @see #addTransformer(ClassFileTransformer,boolean)111*/112void113addTransformer(ClassFileTransformer transformer);114115/**116* Unregisters the supplied transformer. Future class definitions will117* not be shown to the transformer. Removes the most-recently-added matching118* instance of the transformer. Due to the multi-threaded nature of119* class loading, it is possible for a transformer to receive calls120* after it has been removed. Transformers should be written defensively121* to expect this situation.122*123* @param transformer the transformer to unregister124* @return true if the transformer was found and removed, false if the125* transformer was not found126* @throws java.lang.NullPointerException if passed a <code>null</code> transformer127*/128boolean129removeTransformer(ClassFileTransformer transformer);130131/**132* Returns whether or not the current JVM configuration supports retransformation133* of classes.134* The ability to retransform an already loaded class is an optional capability135* of a JVM.136* Retransformation will only be supported if the137* <code>Can-Retransform-Classes</code> manifest attribute is set to138* <code>true</code> in the agent JAR file (as described in the139* {@linkplain java.lang.instrument package specification}) and the JVM supports140* this capability.141* During a single instantiation of a single JVM, multiple calls to this142* method will always return the same answer.143* @return true if the current JVM configuration supports retransformation of144* classes, false if not.145* @see #retransformClasses146* @since 1.6147*/148boolean149isRetransformClassesSupported();150151/**152* Retransform the supplied set of classes.153*154* <P>155* This function facilitates the instrumentation156* of already loaded classes.157* When classes are initially loaded or when they are158* {@linkplain #redefineClasses redefined},159* the initial class file bytes can be transformed with the160* {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer}.161* This function reruns the transformation process162* (whether or not a transformation has previously occurred).163* This retransformation follows these steps:164* <ul>165* <li>starting from the initial class file bytes166* </li>167* <li>for each transformer that was added with <code>canRetransform</code>168* false, the bytes returned by169* {@link ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[])170* transform} during the last class load or redefine are171* reused as the output of the transformation; note that this is172* equivalent to reapplying the previous transformation, unaltered;173* except that {@code transform} method is not called.174* </li>175* <li>for each transformer that was added with <code>canRetransform</code>176* true, the177* {@link ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[])178* transform} method is called in these transformers179* </li>180* <li>the transformed class file bytes are installed as the new181* definition of the class182* </li>183* </ul>184* <P>185*186* The order of transformation is described in {@link ClassFileTransformer}.187* This same order is used in the automatic reapplication of188* retransformation incapable transforms.189* <P>190*191* The initial class file bytes represent the bytes passed to192* {@link java.lang.ClassLoader#defineClass ClassLoader.defineClass} or193* {@link #redefineClasses redefineClasses}194* (before any transformations195* were applied), however they might not exactly match them.196* The constant pool might not have the same layout or contents.197* The constant pool may have more or fewer entries.198* Constant pool entries may be in a different order; however,199* constant pool indices in the bytecodes of methods will correspond.200* Some attributes may not be present.201* Where order is not meaningful, for example the order of methods,202* order might not be preserved.203*204* <P>205* This method operates on206* a set in order to allow interdependent changes to more than one class at the same time207* (a retransformation of class A can require a retransformation of class B).208*209* <P>210* If a retransformed method has active stack frames, those active frames continue to211* run the bytecodes of the original method.212* The retransformed method will be used on new invokes.213*214* <P>215* This method does not cause any initialization except that which would occur216* under the customary JVM semantics. In other words, redefining a class217* does not cause its initializers to be run. The values of static variables218* will remain as they were prior to the call.219*220* <P>221* Instances of the retransformed class are not affected.222*223* <P>224* The supported class file changes are described in225* <a href="{@docRoot}/../specs/jvmti.html#RetransformClasses">JVM TI RetransformClasses</a>.226* The class file bytes are not checked, verified and installed227* until after the transformations have been applied, if the resultant bytes are in228* error this method will throw an exception.229*230* <P>231* If this method throws an exception, no classes have been retransformed.232* <P>233* This method is intended for use in instrumentation, as described in the234* {@linkplain Instrumentation class specification}.235*236* @param classes array of classes to retransform;237* a zero-length array is allowed, in this case, this method does nothing238* @throws java.lang.instrument.UnmodifiableClassException if a specified class cannot be modified239* ({@link #isModifiableClass} would return <code>false</code>)240* @throws java.lang.UnsupportedOperationException if the current configuration of the JVM does not allow241* retransformation ({@link #isRetransformClassesSupported} is false) or the retransformation attempted242* to make unsupported changes243* @throws java.lang.ClassFormatError if the data did not contain a valid class244* @throws java.lang.NoClassDefFoundError if the name in the class file is not equal to the name of the class245* @throws java.lang.UnsupportedClassVersionError if the class file version numbers are not supported246* @throws java.lang.ClassCircularityError if the new classes contain a circularity247* @throws java.lang.LinkageError if a linkage error occurs248* @throws java.lang.NullPointerException if the supplied classes array or any of its components249* is <code>null</code>.250*251* @see #isRetransformClassesSupported252* @see #addTransformer253* @see java.lang.instrument.ClassFileTransformer254* @since 1.6255*/256void257retransformClasses(Class<?>... classes) throws UnmodifiableClassException;258259/**260* Returns whether or not the current JVM configuration supports redefinition261* of classes.262* The ability to redefine an already loaded class is an optional capability263* of a JVM.264* Redefinition will only be supported if the265* <code>Can-Redefine-Classes</code> manifest attribute is set to266* <code>true</code> in the agent JAR file (as described in the267* {@linkplain java.lang.instrument package specification}) and the JVM supports268* this capability.269* During a single instantiation of a single JVM, multiple calls to this270* method will always return the same answer.271* @return true if the current JVM configuration supports redefinition of classes,272* false if not.273* @see #redefineClasses274*/275boolean276isRedefineClassesSupported();277278/**279* Redefine the supplied set of classes using the supplied class files.280*281* <P>282* This method is used to replace the definition of a class without reference283* to the existing class file bytes, as one might do when recompiling from source284* for fix-and-continue debugging.285* Where the existing class file bytes are to be transformed (for286* example in bytecode instrumentation)287* {@link #retransformClasses retransformClasses}288* should be used.289*290* <P>291* This method operates on292* a set in order to allow interdependent changes to more than one class at the same time293* (a redefinition of class A can require a redefinition of class B).294*295* <P>296* If a redefined method has active stack frames, those active frames continue to297* run the bytecodes of the original method.298* The redefined method will be used on new invokes.299*300* <P>301* This method does not cause any initialization except that which would occur302* under the customary JVM semantics. In other words, redefining a class303* does not cause its initializers to be run. The values of static variables304* will remain as they were prior to the call.305*306* <P>307* Instances of the redefined class are not affected.308*309* <P>310* The supported class file changes are described in311* <a href="{@docRoot}/../specs/jvmti.html#RedefineClasses">JVM TI RedefineClasses</a>.312* The class file bytes are not checked, verified and installed313* until after the transformations have been applied, if the resultant bytes are in314* error this method will throw an exception.315*316* <P>317* If this method throws an exception, no classes have been redefined.318* <P>319* This method is intended for use in instrumentation, as described in the320* {@linkplain Instrumentation class specification}.321*322* @param definitions array of classes to redefine with corresponding definitions;323* a zero-length array is allowed, in this case, this method does nothing324* @throws java.lang.instrument.UnmodifiableClassException if a specified class cannot be modified325* ({@link #isModifiableClass} would return <code>false</code>)326* @throws java.lang.UnsupportedOperationException if the current configuration of the JVM does not allow327* redefinition ({@link #isRedefineClassesSupported} is false) or the redefinition attempted328* to make unsupported changes329* @throws java.lang.ClassFormatError if the data did not contain a valid class330* @throws java.lang.NoClassDefFoundError if the name in the class file is not equal to the name of the class331* @throws java.lang.UnsupportedClassVersionError if the class file version numbers are not supported332* @throws java.lang.ClassCircularityError if the new classes contain a circularity333* @throws java.lang.LinkageError if a linkage error occurs334* @throws java.lang.NullPointerException if the supplied definitions array or any of its components335* is <code>null</code>336* @throws java.lang.ClassNotFoundException Can never be thrown (present for compatibility reasons only)337*338* @see #isRedefineClassesSupported339* @see #addTransformer340* @see java.lang.instrument.ClassFileTransformer341*/342void343redefineClasses(ClassDefinition... definitions)344throws ClassNotFoundException, UnmodifiableClassException;345346347/**348* Tests whether a class is modifiable by349* {@linkplain #retransformClasses retransformation}350* or {@linkplain #redefineClasses redefinition}.351* If a class is modifiable then this method returns <code>true</code>.352* If a class is not modifiable then this method returns <code>false</code>.353* <P>354* For a class to be retransformed, {@link #isRetransformClassesSupported} must also be true.355* But the value of <code>isRetransformClassesSupported()</code> does not influence the value356* returned by this function.357* For a class to be redefined, {@link #isRedefineClassesSupported} must also be true.358* But the value of <code>isRedefineClassesSupported()</code> does not influence the value359* returned by this function.360* <P>361* Primitive classes (for example, <code>java.lang.Integer.TYPE</code>)362* and array classes are never modifiable.363*364* @param theClass the class to check for being modifiable365* @return whether or not the argument class is modifiable366* @throws java.lang.NullPointerException if the specified class is <code>null</code>.367*368* @see #retransformClasses369* @see #isRetransformClassesSupported370* @see #redefineClasses371* @see #isRedefineClassesSupported372* @since 1.6373*/374boolean375isModifiableClass(Class<?> theClass);376377/**378* Returns an array of all classes currently loaded by the JVM.379* The returned array includes all classes and interfaces, including380* {@linkplain Class#isHidden hidden classes or interfaces}, and array classes381* of all types.382*383* @return an array containing all the classes loaded by the JVM, zero-length if there are none384*/385@SuppressWarnings("rawtypes")386Class[]387getAllLoadedClasses();388389/**390* Returns an array of all classes which {@code loader} can find by name391* via {@link ClassLoader#loadClass(String, boolean) ClassLoader::loadClass},392* {@link Class#forName(String) Class::forName} and bytecode linkage.393* That is, all classes for which {@code loader} has been recorded as394* an initiating loader. If the supplied {@code loader} is {@code null},395* classes that the bootstrap class loader can find by name are returned.396* <p>397* The returned array does not include {@linkplain Class#isHidden()398* hidden classes or interfaces} or array classes whose399* {@linkplain Class#componentType() element type} is a400* {@linkplain Class#isHidden() hidden class or interface}.401* as they cannot be discovered by any class loader.402*403* @param loader the loader whose initiated class list will be returned404* @return an array containing all classes which {@code loader} can find by name;405* zero-length if there are none406*/407@SuppressWarnings("rawtypes")408Class[]409getInitiatedClasses(ClassLoader loader);410411/**412* Returns an implementation-specific approximation of the amount of storage consumed by413* the specified object. The result may include some or all of the object's overhead,414* and thus is useful for comparison within an implementation but not between implementations.415*416* The estimate may change during a single invocation of the JVM.417*418* @param objectToSize the object to size419* @return an implementation-specific approximation of the amount of storage consumed by the specified object420* @throws java.lang.NullPointerException if the supplied Object is <code>null</code>.421*/422long423getObjectSize(Object objectToSize);424425426/**427* Specifies a JAR file with instrumentation classes to be defined by the428* bootstrap class loader.429*430* <p> When the virtual machine's built-in class loader, known as the "bootstrap431* class loader", unsuccessfully searches for a class, the entries in the {@link432* java.util.jar.JarFile JAR file} will be searched as well.433*434* <p> This method may be used multiple times to add multiple JAR files to be435* searched in the order that this method was invoked.436*437* <p> The agent should take care to ensure that the JAR does not contain any438* classes or resources other than those to be defined by the bootstrap439* class loader for the purpose of instrumentation.440* Failure to observe this warning could result in unexpected441* behavior that is difficult to diagnose. For example, suppose there is a442* loader L, and L's parent for delegation is the bootstrap class loader.443* Furthermore, a method in class C, a class defined by L, makes reference to444* a non-public accessor class C$1. If the JAR file contains a class C$1 then445* the delegation to the bootstrap class loader will cause C$1 to be defined446* by the bootstrap class loader. In this example an <code>IllegalAccessError</code>447* will be thrown that may cause the application to fail. One approach to448* avoiding these types of issues, is to use a unique package name for the449* instrumentation classes.450*451* <p>452* <cite>The Java Virtual Machine Specification</cite>453* specifies that a subsequent attempt to resolve a symbolic454* reference that the Java virtual machine has previously unsuccessfully attempted455* to resolve always fails with the same error that was thrown as a result of the456* initial resolution attempt. Consequently, if the JAR file contains an entry457* that corresponds to a class for which the Java virtual machine has458* unsuccessfully attempted to resolve a reference, then subsequent attempts to459* resolve that reference will fail with the same error as the initial attempt.460*461* @param jarfile462* The JAR file to be searched when the bootstrap class loader463* unsuccessfully searches for a class.464*465* @throws NullPointerException466* If <code>jarfile</code> is <code>null</code>.467*468* @see #appendToSystemClassLoaderSearch469* @see java.lang.ClassLoader470* @see java.util.jar.JarFile471*472* @since 1.6473*/474void475appendToBootstrapClassLoaderSearch(JarFile jarfile);476477/**478* Specifies a JAR file with instrumentation classes to be defined by the479* system class loader.480*481* When the system class loader for delegation (see482* {@link java.lang.ClassLoader#getSystemClassLoader getSystemClassLoader()})483* unsuccessfully searches for a class, the entries in the {@link484* java.util.jar.JarFile JarFile} will be searched as well.485*486* <p> This method may be used multiple times to add multiple JAR files to be487* searched in the order that this method was invoked.488*489* <p> The agent should take care to ensure that the JAR does not contain any490* classes or resources other than those to be defined by the system class491* loader for the purpose of instrumentation.492* Failure to observe this warning could result in unexpected493* behavior that is difficult to diagnose (see494* {@link #appendToBootstrapClassLoaderSearch495* appendToBootstrapClassLoaderSearch}).496*497* <p> The system class loader supports adding a JAR file to be searched if498* it implements a method named <code>appendToClassPathForInstrumentation</code>499* which takes a single parameter of type <code>java.lang.String</code>. The500* method is not required to have <code>public</code> access. The name of501* the JAR file is obtained by invoking the {@link java.util.zip.ZipFile#getName502* getName()} method on the <code>jarfile</code> and this is provided as the503* parameter to the <code>appendToClassPathForInstrumentation</code> method.504*505* <p>506* <cite>The Java Virtual Machine Specification</cite>507* specifies that a subsequent attempt to resolve a symbolic508* reference that the Java virtual machine has previously unsuccessfully attempted509* to resolve always fails with the same error that was thrown as a result of the510* initial resolution attempt. Consequently, if the JAR file contains an entry511* that corresponds to a class for which the Java virtual machine has512* unsuccessfully attempted to resolve a reference, then subsequent attempts to513* resolve that reference will fail with the same error as the initial attempt.514*515* <p> This method does not change the value of <code>java.class.path</code>516* {@link java.lang.System#getProperties system property}.517*518* @param jarfile519* The JAR file to be searched when the system class loader520* unsuccessfully searches for a class.521*522* @throws UnsupportedOperationException523* If the system class loader does not support appending a524* a JAR file to be searched.525*526* @throws NullPointerException527* If <code>jarfile</code> is <code>null</code>.528*529* @see #appendToBootstrapClassLoaderSearch530* @see java.lang.ClassLoader#getSystemClassLoader531* @see java.util.jar.JarFile532* @since 1.6533*/534void535appendToSystemClassLoaderSearch(JarFile jarfile);536537/**538* Returns whether the current JVM configuration supports539* {@linkplain #setNativeMethodPrefix(ClassFileTransformer,String)540* setting a native method prefix}.541* The ability to set a native method prefix is an optional542* capability of a JVM.543* Setting a native method prefix will only be supported if the544* <code>Can-Set-Native-Method-Prefix</code> manifest attribute is set to545* <code>true</code> in the agent JAR file (as described in the546* {@linkplain java.lang.instrument package specification}) and the JVM supports547* this capability.548* During a single instantiation of a single JVM, multiple549* calls to this method will always return the same answer.550* @return true if the current JVM configuration supports551* setting a native method prefix, false if not.552* @see #setNativeMethodPrefix553* @since 1.6554*/555boolean556isNativeMethodPrefixSupported();557558/**559* This method modifies the failure handling of560* native method resolution by allowing retry561* with a prefix applied to the name.562* When used with the563* {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer},564* it enables native methods to be565* instrumented.566* <p>567* Since native methods cannot be directly instrumented568* (they have no bytecodes), they must be wrapped with569* a non-native method which can be instrumented.570* For example, if we had:571* <pre>572* native boolean foo(int x);</pre>573* <p>574* We could transform the class file (with the575* ClassFileTransformer during the initial definition576* of the class) so that this becomes:577* <pre>578* boolean foo(int x) {579* <i>... record entry to foo ...</i>580* return wrapped_foo(x);581* }582*583* native boolean wrapped_foo(int x);</pre>584* <p>585* Where <code>foo</code> becomes a wrapper for the actual native586* method with the appended prefix "wrapped_". Note that587* "wrapped_" would be a poor choice of prefix since it588* might conceivably form the name of an existing method589* thus something like "$$$MyAgentWrapped$$$_" would be590* better but would make these examples less readable.591* <p>592* The wrapper will allow data to be collected on the native593* method call, but now the problem becomes linking up the594* wrapped method with the native implementation.595* That is, the method <code>wrapped_foo</code> needs to be596* resolved to the native implementation of <code>foo</code>,597* which might be:598* <pre>599* Java_somePackage_someClass_foo(JNIEnv* env, jint x)</pre>600* <p>601* This function allows the prefix to be specified and the602* proper resolution to occur.603* Specifically, when the standard resolution fails, the604* resolution is retried taking the prefix into consideration.605* There are two ways that resolution occurs, explicit606* resolution with the JNI function <code>RegisterNatives</code>607* and the normal automatic resolution. For608* <code>RegisterNatives</code>, the JVM will attempt this609* association:610* <pre>{@code611* method(foo) -> nativeImplementation(foo)612* }</pre>613* <p>614* When this fails, the resolution will be retried with615* the specified prefix prepended to the method name,616* yielding the correct resolution:617* <pre>{@code618* method(wrapped_foo) -> nativeImplementation(foo)619* }</pre>620* <p>621* For automatic resolution, the JVM will attempt:622* <pre>{@code623* method(wrapped_foo) -> nativeImplementation(wrapped_foo)624* }</pre>625* <p>626* When this fails, the resolution will be retried with627* the specified prefix deleted from the implementation name,628* yielding the correct resolution:629* <pre>{@code630* method(wrapped_foo) -> nativeImplementation(foo)631* }</pre>632* <p>633* Note that since the prefix is only used when standard634* resolution fails, native methods can be wrapped selectively.635* <p>636* Since each <code>ClassFileTransformer</code>637* can do its own transformation of the bytecodes, more638* than one layer of wrappers may be applied. Thus each639* transformer needs its own prefix. Since transformations640* are applied in order, the prefixes, if applied, will641* be applied in the same order642* (see {@link #addTransformer(ClassFileTransformer,boolean) addTransformer}).643* Thus if three transformers applied644* wrappers, <code>foo</code> might become645* <code>$trans3_$trans2_$trans1_foo</code>. But if, say,646* the second transformer did not apply a wrapper to647* <code>foo</code> it would be just648* <code>$trans3_$trans1_foo</code>. To be able to649* efficiently determine the sequence of prefixes,650* an intermediate prefix is only applied if its non-native651* wrapper exists. Thus, in the last example, even though652* <code>$trans1_foo</code> is not a native method, the653* <code>$trans1_</code> prefix is applied since654* <code>$trans1_foo</code> exists.655*656* @param transformer657* The ClassFileTransformer which wraps using this prefix.658* @param prefix659* The prefix to apply to wrapped native methods when660* retrying a failed native method resolution. If prefix661* is either <code>null</code> or the empty string, then662* failed native method resolutions are not retried for663* this transformer.664* @throws java.lang.NullPointerException if passed a <code>null</code> transformer.665* @throws java.lang.UnsupportedOperationException if the current configuration of666* the JVM does not allow setting a native method prefix667* ({@link #isNativeMethodPrefixSupported} is false).668* @throws java.lang.IllegalArgumentException if the transformer is not registered669* (see {@link #addTransformer(ClassFileTransformer,boolean) addTransformer}).670*671* @since 1.6672*/673void674setNativeMethodPrefix(ClassFileTransformer transformer, String prefix);675676/**677* Redefine a module to expand the set of modules that it reads, the set of678* packages that it exports or opens, or the services that it uses or679* provides. This method facilitates the instrumentation of code in named680* modules where that instrumentation requires changes to the set of modules681* that are read, the packages that are exported or open, or the services682* that are used or provided.683*684* <p> This method cannot reduce the set of modules that a module reads, nor685* reduce the set of packages that it exports or opens, nor reduce the set686* of services that it uses or provides. This method is a no-op when invoked687* to redefine an unnamed module. </p>688*689* <p> When expanding the services that a module uses or provides then the690* onus is on the agent to ensure that the service type will be accessible at691* each instrumentation site where the service type is used. This method692* does not check if the service type is a member of the module or in a693* package exported to the module by another module that it reads. </p>694*695* <p> The {@code extraExports} parameter is the map of additional packages696* to export. The {@code extraOpens} parameter is the map of additional697* packages to open. In both cases, the map key is the fully-qualified name698* of the package as defined in section 6.5.3 of699* <cite>The Java Language Specification </cite>, for example, {@code700* "java.lang"}. The map value is the non-empty set of modules that the701* package should be exported or opened to. </p>702*703* <p> The {@code extraProvides} parameter is the additional service providers704* for the module to provide. The map key is the service type. The map value705* is the non-empty list of implementation types, each of which is a member706* of the module and an implementation of the service. </p>707*708* <p> This method is safe for concurrent use and so allows multiple agents709* to instrument and update the same module at around the same time. </p>710*711* @param module the module to redefine712* @param extraReads the possibly-empty set of additional modules to read713* @param extraExports the possibly-empty map of additional packages to export714* @param extraOpens the possibly-empty map of additional packages to open715* @param extraUses the possibly-empty set of additional services to use716* @param extraProvides the possibly-empty map of additional services to provide717*718* @throws IllegalArgumentException719* If {@code extraExports} or {@code extraOpens} contains a key720* that is not a package in the module; if {@code extraExports} or721* {@code extraOpens} maps a key to an empty set; if a value in the722* {@code extraProvides} map contains a service provider type that723* is not a member of the module or an implementation of the service;724* or {@code extraProvides} maps a key to an empty list725* @throws UnmodifiableModuleException if the module cannot be modified726* @throws NullPointerException if any of the arguments are {@code null} or727* any of the Sets or Maps contains a {@code null} key or value728*729* @see #isModifiableModule(Module)730* @since 9731*/732void redefineModule(Module module,733Set<Module> extraReads,734Map<String, Set<Module>> extraExports,735Map<String, Set<Module>> extraOpens,736Set<Class<?>> extraUses,737Map<Class<?>, List<Class<?>>> extraProvides);738739/**740* Tests whether a module can be modified with {@link #redefineModule741* redefineModule}. If a module is modifiable then this method returns742* {@code true}. If a module is not modifiable then this method returns743* {@code false}. This method always returns {@code true} when the module744* is an unnamed module (as redefining an unnamed module is a no-op).745*746* @param module the module to test if it can be modified747* @return {@code true} if the module is modifiable, otherwise {@code false}748* @throws NullPointerException if the module is {@code null}749*750* @since 9751*/752boolean isModifiableModule(Module module);753}754755756