|
|
||
Mark Lam's BlogAsync Thread Dumps on CVMPosted by mlam on June 22, 2007 at 01:45 AM | Comments (4)There are times in the course of your development effort when your application just seems to hang forever. At those times, you wish you had some way of knowing where the hang is occurring. If you're running on JavaSE, chances are you'll have a lot of advanced tools that makes life easy for you. But if you're running on an embedded device, suddenly, your options are now severely limited. For the phoneME Advanced VM (CVM), there's a way to get help on this even when there is not advance debugging support on your device. What I'll be showing here is an old trick to get an asynchronous dump of the stacks of all the threads that are currently alive in the VM. First of all, you need to know that this is a hack i.e. it's not good and clean code. That's why I haven't already committed it to the source repository, and won't be doing so. The reason it is a hack will be explained below later under Why this is a Hack!!!. But even though it is a hack, it is useful when you need it. Many of my colleagues as well as customers have often asked me for the code patch for this hack to help with debugging the hangs in their applications. I figure you might find it helpful too. So, here it is ... the Code Patch
Step 2: In linuxSyncInit(), add:
If you'll look in src/linux/javavm/runtime/sync_md.c, you'll note that this code is set up to use the same SIGQUIT signal that JVMPI is also using. So, you need to make sure that there is no conflict i.e. either you aren't using JVMPI at the same time, or that the threadDumpHandler function needs to be called from the JVMPI signal handler function instead. In this case, "using JVMPI at the same time" means that you had built CVM with the CVM_JVMPI=true option. How Does it Work? Note that the trigger mechanism used here is a signal on Linux. You should be able to use this for other OSes as well provided that you can set up an asynchronous request handler whereby CVM can receive a request from the user. That request handler should call threadDumpHandler. Disclaimer: Some finessing may be necessary if you try to use this for other OSes. I've only tested this code on Linux. How to Use it Then, issue a "kill -QUIT <pid>" where <pid> is the process ID of the CVM instance you want a thread dump from. This will send a SIGQUIT signal to CVM and trigger the thread dump. You can request this dump as many times as you like and at different times to see if there are changes in the stack traces. Bear in mind that there is a chance that the request may crash the VM because this is a hack (and not a clean solution). If you don't want to use SIGQUIT as the trigger signal, you can choose a different signal in the code, and issue a different kill command from the terminal. Why this is a HACK!!! Here are all the reasons why this trick is a hack:
WARNING! Again, I caution you: DO NOT put this code in the production VM that you deploy in your products. It can crash your VM. That's why I don't want to commit it into the source repository (for fear that someone will enable it without knowing what the consequences are). Using the Thread Stack Dump Info To actually determine if you have a deadlock or not will require some additional info regarding the state of the monitors that a thread is blocked on. You will also need to know who owns those monitors. That is a topic for another day. The thread dumps may be enough to suggest the existence of a deadlock as the source of your application's hang, and thereby justify further investigation in that direction. Alternatively, it can show that you don't have a deadlock either. Final Words Have a nice day. =) Personal Update While I often feel guilty about not updating the blog regularly, I also don't want to just write entries that wouldn't provide you with something useful. I doubt you'll really want to hear about what I have for lunch each week (or some such mundane details). So instead, if you have a question or a request for a discussion on any specific subject that interests you, please ask me about it by entering a comment in my blog. That will inspire me to write as I do prefer to talk about things that are relevant to you, the Java developer. Till next time then. Tags: CDC CVM Java J2ME JavaME JIT phoneME phoneME Advanced embedded systems Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| ||
|
|