Eclipse JDT Templates

January 29, 2008

Eclipse Java development tool provides default Java templates such as for, syserr, sysout etc … When typing these templates in the Java editor and then pressing ctrl + space JDT insert automatically for you a for loop, a System.err.println(”") or a System.out.println(”"). Nice !!!

These shortcuts are really cool but what about creating our own shortcuts ??

For example as SWT developer we often need to write Display.getCurrent.getSystemColor(SWT.COLOR_XXXX);

Here is (from the JDT online help ) the way to follow to add this template :

To create your own templates, go to the Java > Editor > Templates preference page and press the New button to create a template. For our example, the template would look like this: Display.getCurrent().getSystemColor(SWT.COLOR_${cursor})

Using this feature, you can create all the templates you need !!! The previous sample adds a basic template but you can create complex templates depending on a lot of parameters of the current edited text. There is a lot of default templates provided within the JDT showing how to create complex templates.

More informations are available here.


Profile your Eclipse Plugins with SAP Memory Analyzer part 2

January 16, 2008

An other way to dump the JVM memory heap is to use javax.management and com.sun.management APIs . You can find here the way to do this.

Using this solution I wrote a simple Eclipse plugin just adding a tool bar button allowing me to dump the memory of the current running Eclipse’s JVM in a choosen file.

I can now profile my Eclipse’s plugins without living my favorite open extensible IDE for anything and nothing in particular.



Profile your eclipse plugins with SAP Memory Analyzer part 1

January 16, 2008

After quite a long time browsing the web i finally found a way to profile my Eclipse plugins using SAP Memory Analyzer. In fact i had troubles to generate an on demand memory dump to the JVM running Eclipse. It was easy to generate a memory dump on OutOfMemoryErrors using a simple jvm parameter but not so easy to have this dump at any time. Using jconsole 1.6 you can have this dump when you want

Here is the procedure i am using to analyze the JVM memory content of a running Eclipse :

0- You need : SAP Memory Analyzer (free registration required) and a JDK 6.

1- Set your Java environment (jconsole.exe + java.exe) to a JDK 1.6 (new jconsole tool and new com.sun.management mbean are required)

2- Edit your eclipse.ini file and add the following bold lines :

-vm /home/selvam/Softs/Java/jdk1.6.0_04/bin/java (path to a java.exe 1.6 to force Eclipse to create a new java.exe process)
-vmargs
-Dcom.sun.management.jmxremote (To start Eclipse with the management agent for local monitoring, MUST be added after -vmargs)
-Xms40m
-Xmx512m

3- Launch Eclipse

4- Launch jconsole.exe

5- You should see the process corresponding to the previously launched Eclipse (if not be sure to have correctly perform steps 1,2 and 3). Connect to this process.

jconsole Connection Screen

6- Go to the Mbeans tab and to com.sun.management / HotSpotDiagnostic / Operations (No com.sun.management entry displayed means that the underlying JVM is older than 1.6)

7- Enter the full path of the memory dump file to generate in the first argument slot and then click dumpHeap button. Warning - The file name must have .hprof extension in order to be opened with SAP Memory Analyzer. After few seconds (depending on the size of your JVM memory heap) you should receive a confirmation message.

8- Finally, you just have to open the generated file with SAP Memory analyzer and have fun !!!!