jvmti

JVM CPU Profiler技术原理及源码深度解析

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-28 07:34:44
研发人员在遇到线上报警或需要优化系统性能时,常常需要分析程序运行行为和性能瓶颈。Profiling技术是一种在应用运行时收集程序相关信息的动态分析手段,常用的JVM Profiler可以从多个方面对程序进行动态分析,如CPU、Memory、Thread、Classes、GC等,其中CPU Profiling的应用最为广泛。CPU Profiling经常被用于分析代码的执行热点,如“哪个方法占用CPU的执行时间最长”、“每个方法占用CPU的比例是多少”等等,通过CPU Profiling得到上述相关信息后,研发人员就可以轻松针对热点瓶颈进行分析和性能优化,进而突破性能瓶颈,大幅提升系统的吞吐量。 本文介绍了JVM平台上CPU Profiler的实现原理,希望能帮助读者在使用类似工具的同时也能清楚其内部的技术实现。 CPU Profiler简介 社区实现的JVM Profiler很多,比如已经商用且功能强大的 JProfiler ,也有免费开源的产品,如 JVM-Profiler ,功能各有所长。我们日常使用的Intellij IDEA最新版内部也集成了一个简单好用的Profiler,详细的介绍参见 官方Blog 。 在用IDEA打开需要诊断的Java项目后,在“Preferences -> Build, Execution, Deployment -> Java Profiler

Starting JVM Tool Interface agents in the VM during live phase

主宰稳场 提交于 2020-01-15 03:40:07
问题 The JVM Tool Interface(JVMTI) specification says that the JVMTI agents can be started in the VM during live phase but they havent mentioned how it can be done. Has anyone tried this before or got any hints on how to do it? 回答1: You can use method * @param agent * Path to the JAR file containing the agent. * * @param options * The options to provide to the agent's <code>agentmain</code> * method (can be <code>null</code>). com.sun.tools.attach.VirtualMachine.loadAgent(String agent, String

How to Get the values of method local variables and class variables using jvmti

本秂侑毒 提交于 2020-01-04 13:48:40
问题 I am trying to capture the variable values using JVMTI, when an exception event is generated, i went through the jvmti documentation and found that there are no functions which let me retrieve the values of the fields(variables), how can this be achieved ? Below is the Agent code: #include<jni.h> #include<jvmti.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> typedef struct { jvmtiEnv *jvmti; jrawMonitorID lock; } GlobalAgentData; static GlobalAgentData *gdata; static bool check

jvmti agent deadlock

半腔热情 提交于 2020-01-04 02:42:41
问题 When I run my jvmti agent with a java program, it seems that jvm encounters a deadlock. In my jvmti agent, I create a single raw monitor in Agent_OnLoad() and enter that lock at the beginning of every callback function and exit that lock at the end of every callback functions. I don't know the reason of this deadlock. Is there any other possibilities of deadlocks in jvmti agents? thanks. 回答1: Yes, there is a possibility of deadlocks in JVMTI Agent. The JVMTI Reference states: The same thread

Java JVMTI doesn't work alongside -Xdebug -Xrunjdwp

隐身守侯 提交于 2019-12-30 17:19:55
问题 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

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

不打扰是莪最后的温柔 提交于 2019-12-29 07:49:41
问题 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

JVM crashing EXCEPTION_ACCESS_VIOLATION (0xc0000005) :problematic frame in jvmti agent

空扰寡人 提交于 2019-12-24 09:35:41
问题 I wrote a JVMTI agent and upon running an application with the particular jvmti agent, the jvm crashes and exits with EXCEPTION_ACCESS_VIOLATION (0xc0000005). Problematic frame lies in the jvmti agent that I wrote. The stacktrace showed some jni calls to getstaticbyte and getstaticint functions . When i run it under debugger the crash/exception_access_violation is not reproduced. And the run is perfectly normal. What could be the cause of the crash when running outside of debugger? hs_err_pid

Perplexed by jvmti object allocation callback behavior

∥☆過路亽.° 提交于 2019-12-24 08:24:25
问题 Can anybody explain to me why can I get a callback when jvm allocates some java objects, but not others? Here is what I am doing: static jvmtiCapabilities capa; static jvmtiEnv* jvmti = NULL; static const char* fileName = "C:\\temp\\ObjectInitCallbackDump.txt"; static ofstream outFileStream; void JNICALL callbackObjectAllocation ( jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, jobject object, jclass object_klass, jlong size ) { char* generic_ptr_class; char* class_name; jvmtiError

Dynamic Bytecode Instrumentation fails without any error

北慕城南 提交于 2019-12-24 01:07:17
问题 Objective I'm doing dynamic bytecode instrumentation using a JVMTI agent. I have to instrument those methods which are "hot", that is, the methods which invoke JIT compiler. To do so I listen to a CompiledLoadEvent and inside its call back function, call RetransformClasses . This in turn invokes ClassFileLoadHook on the class containing "hot" function and actual instrumentation begins. Problem Premises Currently I'm instrumenting my class to spawn some threads. I also listen to thread starts

How to monitor exceptions or errors generated by other Java applications?

爱⌒轻易说出口 提交于 2019-12-23 04:24:13
问题 I want to find or develop an application that can run as a daemon, notify the administrator by email or sms when the Java applications running on a host get any exceptions or errors. I know JVMTI can achieve part of my goal, but it will impact performance of the monitored applications(I don't know how much will it be, it will be acceptable if it's slight), besides it seems to be a troublesom job to develop a JVMTI agent and I'm not sure what would happen if several applications running at the