jvmti

How to communicate with jvmti agent attached on a running JVM

喜你入骨 提交于 2019-12-02 11:37:18
I wanted to know how would I communicate with the jvmti agent I attached on a running JVM using attach API. When I say communicate ,here's what I meant : I want to call native functions located on my jvmti agent , theses function will return me data (like field values) of the running JVM that I "infected" earlier with the agent. Here's the agent; I did not add the native functions yet: #include <jvmti.h> JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM* vm, char* options, void* reserved); jvmtiEnv* create_jvmti_env(JavaVM* vm); JNIEnv* create_jni_env(JavaVM* vm); void init_jvmti_capabilities

Got “UnsupportedOperationException” when try to retransformClasses

感情迁移 提交于 2019-12-02 09:36:47
JDK1.6, modify class loaded in jvm dynamically. When I comment the code: classReader.accept(classAdapter, ClassReader.SKIP_DEBUG); , the exception "UnsupportedOperationException" disapear. Actually, for testing my code, I didnt modify any field or method. But the program catch exception "UnsupportedOperationException" , after calling retransformClasses() . Anyone has similar exception? Can any give me some advices? thx Codes are as follow: public byte[] modifySleepMethod() throws Exception { System.out.println("Call modifySleepMethod"); ClassReader classReader = new ClassReader(classfileBuffer

Java JVMTI doesn't work alongside -Xdebug -Xrunjdwp

谁说我不能喝 提交于 2019-12-01 15:15:38
I spent the last 4 hours trying to set up Eclipse TPTP memory profiling on a Tomcat instance that must be run remotely (i.e. not in Eclipse). This should be possible according to the TPTP and Agent Controller docs. I installed the TPTP components (4.6.0) into my Eclipse (Galileo) workbench, along with the Agent Controller according to the instructions on the website. To enable the agent, I added the following options to the command line that starts the Tomcat instance: -agentlib:JPIBootLoader=JPIAgent:server=enabled;HeapProf:allocsites=true and added the following directories to the front of

JVMTI - how to get the value of a method parameter from callback

左心房为你撑大大i 提交于 2019-12-01 07:07:48
问题 I am recording all method entries from my Java app thanks to a JVMTI Agent. For now, I am able to get the name of each method, but I'd want to be able to get the value of the parameters that method received. This problem has already been discussed in an older topic (see How to get parameter values in a MethodEntry callback); it fits perfectly what I'm looking for, so I know I have to use GetLocalObject function, but I can't figure out how to (the example given in the topic is broken). Can

java的premain

我的梦境 提交于 2019-11-30 16:20:09
##特性 在类的字节码载入JVM前会调用ClassFileTransformer的transform方法,从而实现修改原类方法的功能。 ##原理 JVMTI(Java Virtual Machine Tool Interface)是一套本地编程接口集合,它提供了一套『代理』机制,可以支持第三方工具程序以代理的方式连接和访问 JVM,并利用 JVMTI 提供的丰富的编程接口,完成很多跟 JVM 相关的功能。 java.lang.instrument 包的实现,也就是基于这种机制的:在 Instrumentation 的实现当中,存在一个 JVMTI 的代理程序,通过调用 JVMTI 当中 Java 类相关的函数来完成 Java 类的动态操作。 Instrumentation 的最大作用就是类定义的动态改变和操作。在 Java SE 5 及其后续版本当中,开发者可以在一个普通 Java 程序(带有 main 函数的 Java 类)运行时,通过 – javaagent 参数指定一个特定的 jar 文件(包含 Instrumentation 代理)来启动 Instrumentation 的代理程序。 ##要素 ###Premain-Class 打成jar包,在jar包里面的 META-INF/MAINIFEST.MF 必须包含 Premain-Class这个属性。 如果 JVM

Java JVMTI和Instrumention机制介绍

自古美人都是妖i 提交于 2019-11-30 04:34:37
也可以看我的CSDN上的博客: https://blog.csdn.net/u013332124/article/details/88367630 1、JVMTI 介绍 JVMTI(JVM Tool Interface)是 Java 虚拟机所提供的 native 编程接口 ,是 JVMPI(Java Virtual Machine Profiler Interface)和 JVMDI(Java Virtual Machine Debug Interface)的替代版本。 JVMTI可以用来开发并监控虚拟机,可以查看JVM内部的状态,并控制JVM应用程序的执行。可实现的功能包括但不限于:调试、监控、线程分析、覆盖率分析工具等。 另外,需要注意的是,并非所有的JVM实现都支持JVMTI。 JVMTI只是一套接口, 我们要开发JVM工具就需要写一个Agent程序来使用这些接口 。Agent程序其实就是一个C/C++语言编写的动态链接库。这里不详细介绍如何开发一个JVMTI的agent程序。感兴趣的可以点击文章末尾的链接查看。 我们通过JVMTI开发好agent程序后,把程序编译成动态链接库,之后可以在jvm启动时指定加载运行该agent。 -agentlib:<agent-lib-name>=<options> 之后JVM启动后该agent程序就会开始工作。 1.1 Agent的工作形式

What are these threads which are spwaned when a Java application begins its execution?

情到浓时终转凉″ 提交于 2019-11-29 11:03:19
I have created a simple Java application which has a JFrame and few JButtons. When I tried to inspect the java application using JVMTI I found that though I did not create any explicit threads there were lot of them spawned. I could find the following threads: DestroyJavaVM AWT-EventQueue-0 AWT-Shutdown AWT-XAWT- Daemon Thread Java2D Disposer- Daemon Thread Thread-0- Daemon Thread [Created by the JVMTI Agent] Signal Dispatcher- Daemon Thread Finalize- Daemon Thread Reference Handler- Daemon Thread Most of them were in Runnable state. Can someone tell me the function of these threads? These

字节码和字节码增强

自作多情 提交于 2019-11-29 09:40:48
字节码 Java的一次编写到处运行就是靠的字节码技术,java通过javac命令编译源代码为字节码文件,流程如下: 通过字节码,可以进行各种AOP增强,比如ORM,热部署机制等。字节码有其规范,可以帮助其他JVM语言在JVM体系下运行,比如Scala,Groovy,Kotlin等。 字节码组成 魔数 所有.class文件的前四个字节都是魔数,魔数值是固定的 0xCAFEBABE (咖啡杯)。JVM根据关键字判断一个文件是否是一个.class文件,是的话才会继续进行操作。 版本号 版本号为魔数之后的四个字节,前两个表示次版本号,后两个表示主版本号。 常量池 在版本号之后的字节为常量池。常量池中存储两类常量:字面量和符号引用。 字面量表示代码中声明为final的常量值,符号引用如类和接口的全限名,字段名称和描述符,方法名称和描述符。 常量池分为两部分:常量池计数器和常量池数据区。 访问标志 常量池之后的两个字节描述Class是类还是接口,及是否被public,abstract,final等修饰。 当前类名 访问标志之后的两个字节,描述的是类的全限名,这两个字节保存的值为常量池中的索引值,根据索引值在常量池中找到这个类的全限名。 父类名称 当前类名后的两个字节,描述父类的全限名,同上,保存的是常量池中的索引值。 接口信息 父类名称之后的两个字节的接口计数器,描述了该类或父类实现的接口数量

Java字节码增强探秘

独自空忆成欢 提交于 2019-11-29 08:57:58
1.字节码 1.1 什么是字节码? Java之所以可以“一次编译,到处运行”,一是因为JVM针对各种操作系统、平台都进行了定制,二是因为无论在什么平台,都可以编译生成固定格式的字节码(.class文件)供JVM使用。因此,也可以看出字节码对于Java生态的重要性。之所以被称之为字节码,是因为字节码文件由十六进制值组成,而JVM以两个十六进制值为一组,即以字节为单位进行读取。在Java中一般是用javac命令编译源代码为字节码文件,一个.java文件从编译到运行的示例如图1所示。 对于开发人员,了解字节码可以更准确、直观地理解Java语言中更深层次的东西,比如通过字节码,可以很直观地看到Volatile关键字如何在字节码上生效。另外,字节码增强技术在Spring AOP、各种ORM框架、热部署中的应用屡见不鲜,深入理解其原理对于我们来说大有裨益。除此之外,由于JVM规范的存在,只要最终可以生成符合规范的字节码就可以在JVM上运行,因此这就给了各种运行在JVM上的语言(如Scala、Groovy、Kotlin)一种契机,可以扩展Java所没有的特性或者实现各种语法糖。理解字节码后再学习这些语言,可以“逆流而上”,从字节码视角看它的设计思路,学习起来也“易如反掌”。 本文重点着眼于字节码增强技术,从字节码开始逐层向上,由JVM字节码操作集合到Java中操作字节码的框架

Unloading a JVMTI agent at runtime?

纵饮孤独 提交于 2019-11-29 04:02:18
I'm using the attach API to load a JVMTI agent at runtime. I'd like to unload the JVMTI agent when my program is done without terminating the JVM the agent is loaded in. According to this documentation there is no way to do this from the attach API. Are there any other ways to force an agent to unload its self either through a Java API or from within the JVMTI agent? JVMTI spec says unloading (without JVM termination) is possible, but platform-dependent and out of specification's scope. You have to load JVMTI agent programatically : // attach to target VM VirtualMachine vm = VirtualMachine