Thursday, June 30, 2011

Get/Analyze the IBM JDK Heap DUMP

Was recently trying to do something that's suppose to be really simple but again was not... Looks like another case of set of engineers having strong "I did it my way.." syndrome. + The great IBM tools which are really strong but its easier to find your kid in a local fest than finding the help for IBM products. After looking through several web pages and sites (some of them even gave wrong/outdated information) I was able to do it. At one point I felt like I am getting clue from one page just to get redirected to another :), anyways enough of my frustration and required steps are given below:

1.     Get the DUMP for IBM JDK
Use the -Xdump argument on the command line or in the Eclipse run configuration. You can have multiple -Xdump stanzas on the command line and also multiple dump types driven by one or multiple events. Thus, -Xdump:heap+java:events=vmstart+vmstop would create a dump agent that would drive both heap and Java™ dump production when either a vmstart or vmstop event was encountered.

a)  Execute the program with the argument -Xdump:heap:events=vmstop
b)  Once the program starts stop/close  it. On Eclipse/Windows Console you will see something like this:

JVMDUMP006I Processing dump event "vmstop", detail "#00000000" - please wait.
JVMDUMP032I JVM requested Heap dump using 'C:\Program Files\MyProduct\heapdump.20110630.133125.776.0001.phd' in response to an event
JVMDUMP010I Heap dump written to C:\Program Files\MyProduct\heapdump.20110630.133125.776.0001.phd
JVMDUMP013I Processed dump event "vmstop", detail "#00000000".

2.     Install the Heap dump analysis tool
a)      If you don't already have the Support Assistant Workbench, download and install the IBM Support Assistant Workbench.
b)      From the Support Assistant Workbench, click Update > Find New... > Tools Add-ons.
c)       In the window that pops up, select the tools that you would like to install and follow the on-screen instructions to complete the installation. When the installation is completed, the Workbench will restart.
List of tools that you can install are given below, but I couldn’t find any so I installed the one which looked familiar. Important one that I think will do the job is HeapAnalyzer
§ IBM Monitoring and Diagnostic Tools for Java - Dump Analyzer
§ IBM Monitoring and Diagnostic Tools for Java - Garbage Collection and Memory Visualizer (GCMV)
§ IBM Monitoring and Diagnostic Tools for Java - Memory Analyzer
§ IBM Monitoring and Diagnostic Tools for Java - Health Center
§ IBM Thread and Monitor Dump Analyzer for Java (TMDA)
§ Multicore Software Development Kit for Java (MSDK)
§ HeapAnalyzer
§ IBM Pattern Modeling and Analysis Tool for Java Garbage Collector (PMAT)
§ Performance Analysis Tool for Java

3.     Starting Heap Analyzer
ISA Version 4:
  1. Select Analyze Problem from the Welcome tab on the home page.
  2. Open the Tools tab.
  3. Select HeapAnalyzer
  4. Once started Open the dump file created in first step
Another tool that’s mentioned on the site is Memory Dump Diagnostic for Java (MDD4J) but couldn’t find it

Sunday, June 19, 2011

more tools, less work

Recently read the article Are Java and .Net becoming legacy platforms?. Though don’t agree to the title of the article but I do agree with the discussion that the author brings up. With so many new languages sprawling up you kind of feel that Java is one of the older members.

Also with recent ‘Oracle Java mess’ I can understand why companies like Google are coming up with their own development platform.

But beside that, in terms of features does the world need so many dev tools. One of the discussion points in the article was the absence of closures in Java. But, come on; are these so important to make Java incomplete? And the security updates, which software does not have those. There can be reasons surrounding the politics but not the overall features. You can hate the process (aka JCP) but don’t hate the language and at-least not for the wrong reasons.

Java is fulfilling the purpose since so many years; I haven’t seen any practical situation where Java was a blocker in any software project I worked on. And how many new languages can you remember have actually made their mark in last 15 years - Ruby, even with a wild guess you will realize that hundreds of other attempts ate dust and god knows what happened to the product managers who started writing their code using those new tools.

I think the problem with so many new upcoming languages is more to do with “I want to do it my way”. This is very simmilar to ‘teenage mindset’ where you just want to show off your new language skills just like a new Apple gadget. And this mindset is somehow encroaching into the head of some senior developers. Learning new things is not bad but when you are working on Enterprise software, it’s all about developing new features and develop fast. You can’t simply put that limited time in trying out new things especially when the existing ones are working fine. And why not simply use that extra time in making existing things better. Say, checking out the existing code for anomalies creeping into your product since 10+ year.  Refer my previous blog:  Mumbai Vs Software architecture ...

In nut shell, at the end of the day I will like to see 95 products in 5 languages rather than 5 products in 95 languages.


Saturday, February 12, 2011

Please Sir, don’t apply that Design pattern here…

Not sure how to start on this, but since many years I have seen a disturbing trend in Software industry - Being obsessed with technology, being obsessed with new things and having those inner fetish towards the tools rather than the work itself.
What I mean is sometimes developers/architects use certain technologies not because there is a need in the current architecture but because either it’s an ‘in thing’ everyone is using or it’s something new they recently learned or may be got a free book on it.
For instance, I worked with some highly techie guys who created a very robust multi-tier system which use to communicate with many third party data stores (including mainframes). And for each system the folks used different set of middle wares. Somewhere they were using MSMQ, somewhere IBM MQ and what else. You name the middleware and they had used it.   
I talked to one of the guy to understand why it was done, and he clarified “we were bunch of young guys mad about new things with lot of zeal to try them”.  End result, when the whole big application was transferred to a new team, they had no clue what was going on, and even the previous guys were not having the complete information to give a good KT (quite obviously there was no documentation what so ever)
Being a techy guy I myself get interested in new tools, but that’s my leisure time work and not when I am doing official project. Software folks need to understand that learning is a good thing but should be tried on a personal level, may be a PoC. Just because you have learned new things doesn’t mean you should simply apply it everywhere.
(just to list few of the other over used things - Design patterns, XMLs, and now every manager is talking about Cloud :). In a recent meeting, few managers kept using Cloud and SaaS interchangeably, and even after lot of argument I was not able to convince them that both the things are different)

Edit: Recently came across two articles on the same lines, good read:-
The Duct Tape Programmer
The 7 deadly sins of software development

Wednesday, February 9, 2011

Eclipse plugin editor > Extension tab Issues

While adding / updating any extension in Eclipse Plug-in Editor, many times you may have seen that you add an extension point and right click on it > New > Shows only “Generic”.
For example, in tutorials available on web you will see something like this: 
But in your IDE you will only get the Generic option. Also many other extension options are missing.
Solution: Get the source for the corresponding plugins. One way is to download the eclipse with source included. But that can be too length process. Another quick fix is using Eclipse 'Install new Software' wizard:
  1. Go to Help - Install new Software
  2. Select the helios (corresponding) site
  3. In the filter box type: Eclipse RCP Plug-in Developer Resources 
  4. Select the filtered option displayed and install. 
  5. Restart Eclipse and you should get the proper options while working with Extensions

Friday, February 4, 2011

Equinox: Reading External File

I was looking for a way to read a file from the current directory. The business scenario is: We are opening a socket connection from an equinox bundle.
Currently the port for the socket communication is hard coded. In a rare scenario it’s possible that the port will be already in use. We should be able to provide the port from outside the execution environment. 

One way is to pass it through the launch arguments. But sometimes getting hold of config.ini or starting the application from console may not be possible. (In case of custom launchers)

Second option is to read the port from an external file. We can use following to pick the file:

this.getClass().getProtectionDomain().getCodeSource().getLocation() - Gets the current location of the bundle.

If we have kept the file with port at the same location then read the file using:
URL url = new URL(this.getClass().getProtectionDomain().getCodeSource().getLocation()
+ "/../messages.properties");
InputStream inputStream = url.openStream();
Properties properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace(); 
}
socketport=properties.getProperty("SocketPort"));

Not sure if that's the best way. But surprisingly I didn't find any other way to read a file from the current path kept outside the bundle; and even this is specific to Equinox and not available in other OSGi implementations. If anyone is aware of any other way then do let me know