Package jadex.bytecode.vmhacks
Class VmHacks.Unsafe
java.lang.Object
jadex.bytecode.vmhacks.VmHacks.Unsafe
- Enclosing class:
VmHacks
Access to unsafe operations.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendToBootstrapClassLoaderSearch
(String classname, byte[] classcontent) Appends a new class to the bootstrap classloader.void
appendToBootstrapClassLoaderSearch
(String classname, InputStream classcontent) Appends a new class to the bootstrap classloader.Class
<?> defineClass
(String name, byte[] b, int off, int len, ClassLoader loader, ProtectionDomain pd) Access to sun.misc.Unsafe or equivalent.jadex.nativetools.NativeHelper
Returns functionality unlocked through native interface.boolean
hasAsm()
Tests if ASM is available.boolean
Checks if redefineClassIndirect() is available.boolean
Checks if instrumentation is available.boolean
Tests if native access is available.protected void
init()
Initialization step after constructor to allow bootstrapping.void
redefineClass
(Class<?> clazz, byte[] bytecode) Redefine class byte code.Class
<?> redefineClassIndirect
(Class<?> clazz, byte[] bytecode) Redefine class byte code.protected void
Run an instrumentation commandtoString()
Debug message.boolean
tryChangeUser
(String username) Attempts to change the user of the process to the given name.
-
Field Details
-
TEMP_JAR_DIR
Directory for temporary jar files.
-
-
Method Details
-
hasAsm
public boolean hasAsm()Tests if ASM is available.- Returns:
- True, if ASM is available.
-
hasNative
public boolean hasNative()Tests if native access is available.- Returns:
- True, if native access is available.
-
getNativeHelper
public jadex.nativetools.NativeHelper getNativeHelper()Returns functionality unlocked through native interface.- Returns:
- The native helper, may return null if unavailable.
-
hasInstrumentation
public boolean hasInstrumentation()Checks if instrumentation is available.- Returns:
- True, if instrumentation is available.
-
hasIndirectRedefinition
public boolean hasIndirectRedefinition()Checks if redefineClassIndirect() is available.- Returns:
- True, if indirect redefinition is available.
-
tryChangeUser
Attempts to change the user of the process to the given name. If set to null, a list of default user accounts is tried.- Parameters:
username
- The target user name, set to null for a list of default user account.- Returns:
- True, if successful, false if the attempt probably failed.
-
defineClass
public Class<?> defineClass(String name, byte[] b, int off, int len, ClassLoader loader, ProtectionDomain pd) Access to sun.misc.Unsafe or equivalent. -
redefineClassIndirect
Redefine class byte code. Check HAS_INSTRUMENTATION before use. Uses indirect route via classloader enhancement, more likely to work.- Parameters:
clazz
- Class to be redefined.bytecode
- The new byte code.- Returns:
- Redefined class.
-
redefineClass
Redefine class byte code. Check HAS_INSTRUMENTATION before use.- Parameters:
clazz
- Class to be redefined.bytecode
- The new byte code.
-
appendToBootstrapClassLoaderSearch
Appends a new class to the bootstrap classloader.- Parameters:
classname
- The class name.classcontent
- The bytecode.
-
appendToBootstrapClassLoaderSearch
Appends a new class to the bootstrap classloader.- Parameters:
classname
- The class name.classcontent
- The bytecode.
-
toString
Debug message. -
init
protected void init()Initialization step after constructor to allow bootstrapping. -
runInstrumentationCommand
Run an instrumentation command
-