jvmti

determine Java class size from JNI jclass

。_饼干妹妹 提交于 2019-12-23 04:04:55
问题 I'm using JNI to analyze some program. I just wonder, after get jclass reference, how it is possible to find the size of the underlying class ? for example: class cls = env->FindClass("Lee/Boehm/Test"); from here how can i evaluate the size of the class Lee.Boehm.Test inside hotspot's heap ? Thank you Boehm 回答1: Here you go agent.c #include <stdlib.h> #include "jvmti.h" jvmtiEnv *globalJVMTIInterface; JNIEXPORT jlong JNICALL Java_util_Util_getObjectSize (JNIEnv *jni_env , jclass class ,

Failed to redefine class When I try to retransform class

筅森魡賤 提交于 2019-12-23 03:33:14
问题 I was trying to modify class dynamically, such as call sleep() before a line. I attached agent to a jvm during runtime using Attach method. Then I got target class from jvm, and modified it(Add a line to call sleep() ). And I got redine class error. I am using JDK1.6. I am using ASM core API to modify class. The Error: Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields) at sun.instrument.InstrumentationImpl

Instrument API介绍

时光怂恿深爱的人放手 提交于 2019-12-21 18:56:40
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. Instrumentation介绍   JVMTI (JVM Tool Interface)是 Java 虚拟机所提供的 native 编程接口,是 JVMPI(Java Virtual Machine Profiler Interface)和 JVMDI(Java Virtual Machine Debug Interface)的更新版本。JVMTI 提供了一套“代理”程序机制,可以支持第三方工具程序以代理的方式连接和访问 JVM,并利用 JVMTI 提供的丰富的编程接口,完成很多跟 JVM 相关的功能。  Agent 即 JVMTI 的客户端,它和执行 Java 程序的虚拟机运行在同一个进程上。他们通常由另一个独立的进程控制,充当这个独立进程和当前虚拟机之间的中介,通过调用 JVMTI 提供的接口和虚拟机交互,负责获取并返回当前虚拟机的状态或者转发控制命令。java.lang.instrument 包的实现,也是基于这种机制的。在 Instrumentation 的实现当中,存在一个 JVMTI 的代理程序,通过调用 JVMTI 当中于 Java 类相关的函数来完成Java 类的动态操作。  利用 java.lang.instrument 做动态 Instrumentation 是 Java SE 5

How to communicate with jvmti agent attached on a running JVM

六眼飞鱼酱① 提交于 2019-12-20 07:15:06
问题 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);

how to get running jvms in current machine

♀尐吖头ヾ 提交于 2019-12-20 06:24:43
问题 Imagine that: Two java projects are work on JDK1.5 and JDK1.6 Two are work on JDK 1.7. How to get the running jvm names, pids and projects name works on it. the result should LOOKS LIKE: pid 1234, projec_tname prj1, java_version JDK1.6 pid 4354, projec_tname prj2, java_version JDK1.5 pid 6234, projec_tname prj3, java_version JDK1.7 pid 9034, projec_tname prj4, java_version JDK1.7 Solution in Is there a Java library that searches for JVMs on the current machine? is find JDKs in current machine

how to get running jvms in current machine

允我心安 提交于 2019-12-20 06:24:16
问题 Imagine that: Two java projects are work on JDK1.5 and JDK1.6 Two are work on JDK 1.7. How to get the running jvm names, pids and projects name works on it. the result should LOOKS LIKE: pid 1234, projec_tname prj1, java_version JDK1.6 pid 4354, projec_tname prj2, java_version JDK1.5 pid 6234, projec_tname prj3, java_version JDK1.7 pid 9034, projec_tname prj4, java_version JDK1.7 Solution in Is there a Java library that searches for JVMs on the current machine? is find JDKs in current machine

Notification of any String object construction in Java 8 HotSpot VM

廉价感情. 提交于 2019-12-13 07:16:58
问题 Is there a way to get notified on all invocations to constructor of String class (either directly or using reflection) without weaving or instrumenting rt.jar? Further is it possible to filter these notifications only for calls within a specific package? Further is it possible to make these notifications async (like events) so that actual JVM invocations are not slowed down My use-case is to intercept all strings being created, make a pattern match on the content and raise alters based on

Invalid Slot Error When trying to access value of Exception and Thread Objects Using jvmti

我们两清 提交于 2019-12-12 02:13:34
问题 I have the following java Program using which i am trying to capture the state of the variables inside the method when an exception occurs using JVMTI, public class SimpleThread{ static MyThread t; String thisThread = "this Thread"; public static void main(String[] args) throws Exception { Thread thr = new Thread(new Runnable() { final Exception exec = new IllegalArgumentException("Titanic"); public void run() { // while(true) { String firstString = "string"; int firstInt = 1; for (int i =0 ;

Faster alternative to get tags for objects than JVMTI GetTag

被刻印的时光 ゝ 提交于 2019-12-11 19:07:06
问题 When profiling with async profiler and gperftools I noticed that jvmti->GetTag shows up quite a lot in the results for my agent. When I checked how it is implemented I found the following in the source of jvmitTagMap.cpp : jlong JvmtiTagMap::get_tag(jobject object) { MutexLocker ml(lock()); // resolve the object oop o = JNIHandles::resolve_non_null(object); // for Classes get the tag from the klassOop return tag_for(this, klassOop_if_java_lang_Class(o)); } Although my test only had one thread

What is the difference between JVMTI SuspendThread and Javas thread.suspend?

試著忘記壹切 提交于 2019-12-11 16:56:55
问题 Is there any difference in using SuspendThread from a JVMTI agent and using the plain Java thread.suspend()? 回答1: In HotSpot JVM both APIs have the same effect. I've added the links to the relevant parts of OpenJDK source code. Both functions are almost copy-paste of each other, both of them end up calling the same low-level routine JavaThread::java_suspend(). The native code for java.lang.Thread.suspend0() : JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread)) JVMWrapper("JVM