StokeBloke.com

Archive for March, 2009

Home and End key with rxvt

Tuesday, March 31st, 2009

I use cygwins rxvt at work and have had problems with the End and Home key not working.

I also had the same issue at home using rxvt-unicode on gentoo.

After lots of search last night I finally found the fix for urxvt.

Simply add this to your ~/.inputrc file

# home and end keys for rxvt
"\e[7~":beginning-of-line
"\e[8~":end-of-line

I then tried this at work this morning and found it works on cygwins rxvt too.

JVMTI IterateOverReachableObjects and very poor documentation.

Wednesday, March 25th, 2009

As part of my daily work I’ve been working with Steve to write a heap parser so that our tests can find any memory leaks without the need to attach a profiler and hunt though the results.

We created a jvmti agent which could tag an object on the heap then find out if the object was reachable via any GC roots.

This worked well and we had no problems for over a year but recently we started to get some strange array index out of bounds.

The cause was the very poor documentation of the jvmtiObjectReferenceCallback call where the field information was being calculated.

The documentation was wrong in 1.5 but even in 1.6 it simply does not provide enough information to write a heap walker which can print the field names.

I.e for the JVMTI_REFERENCE_FIELD reference kind it says the following:

Reference from an object to the value of one of its instance fields. For references of this kind the referrer_index parameter to the jvmtiObjectReferenceCallback is the index of the the instance field. The index is based on the order of all the object’s fields. This includes all fields of the directly declared static and instance fields in the class, and includes all fields (both public and private) fields declared in superclasses and superinterfaces. The index is thus calculated by summing the index of field in the directly declared class (see GetClassFields), with the total number of fields (both public and private) declared in all superclasses and superinterfaces. The index starts at zero.

This may seem ok but how do you parse the super classes and super interfaces?  The documentation states nothing about the order of the fields so do you scan all interfaces first or last, do you walk the super classes once for classes and once for interfaces?

Being very vague (even google didnt know much) it was difficult to get the output, when a leak was detected, to show the correct field.

It would randomly output fields which were the wrong type and many other issues.

After days of trial and error I was about to give up, then I found hprof_reference.c via google, and then found the rest of the hprof source as part of the JDK directory.

After looking though this code it was possible to figure out exactly how the class and interface heirachy should be processed.

How are we expected to use the JVMTI when its so poorly documented?

My emacs startup script for cygwin

Tuesday, March 24th, 2009

This is my emacs script for cygwin. It runs the Windows Emacs version and runs just 1 instance of emacs in most cases.

Typing emacs on its own simply starts a new version of emacs.

Type emacs and a file will try to open the document in a running version if its started else it will start emacs.

#!/bin/bash

if [ -z $1 ]
then
    d:/apps/emacs-22.2/bin/emacs.exe
else
    d:/apps/emacs-22.2/bin/emacsclient.exe -n \
    -a d:/apps/emacs-22.2/bin/emacs.exe $@ \
    >/dev/null 2>&1
fi

Hang in Java FileSystemView getFileSystemView() getSystemIcon()

Wednesday, March 18th, 2009

Recently I was working on a deadlock in our startup code.

It took some time to track it down as it never appeared as a deadlock (via CTRL-Break) it just stopped running with 0 CPU usage.

The cause was

 FileSystemView.getFileSystemView().getSystemIcon(file)

It appears that this call fails when called from multiple threads asking for the same system icon.

Below is an example on how to show the issue. Its was tested with Java 1.6.0_07

    public void testGetSystemIcon() throws IOException,
                                           InterruptedException {
        final FileImageThread t1 = new FileImageThread(".jpg");
        final FileImageThread t2 = new FileImageThread(".jpg");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }

    public class FileImageThread extends Thread {
        final File file;

        public FileImageThread(final String suffix) throws IOException {
            file = File.createTempFile("test", suffix);
        }

        @Override
        public void run() {
            FileSystemView.getFileSystemView().getSystemIcon(file);
        }
    }

It does not hang every time, but it happens enough to be an issue.

The hang call stack is

Thread  id=22 name=Thread-4 inState=WAITING deadlocked=false isNative=false
  sun.misc.Unsafe.park(Native Method)
  java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
  java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747)
  java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:905)
  java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1217)
  java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218)
  java.util.concurrent.FutureTask.get(FutureTask.java:83)
  sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Win32ShellFolderManager2.java:495)
  sun.awt.shell.Win32ShellFolder2.(Win32ShellFolder2.java:225)
  sun.awt.shell.Win32ShellFolderManager2.getDrives(Win32ShellFolderManager2.java:101)
  sun.awt.shell.Win32ShellFolderManager2.isFileSystemRoot(Win32ShellFolderManager2.java:323)
  sun.awt.shell.ShellFolder.isFileSystemRoot(ShellFolder.java:234)
  javax.swing.filechooser.FileSystemView.isFileSystemRoot(FileSystemView.java:310)
  com.osm.ui.FileImageUtilsTest$FileImageThread.run(FileImageUtilsTest.java:62)

Thread  id=21 name=Thread-3 inState=WAITING deadlocked=false isNative=false
  sun.misc.Unsafe.park(Native Method)
  java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
  java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747)
  java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:905)
  java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1217)
  java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218)
  java.util.concurrent.FutureTask.get(FutureTask.java:83)
  sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Win32ShellFolderManager2.java:495)
  sun.awt.shell.Win32ShellFolder2.(Win32ShellFolder2.java:225)
  sun.awt.shell.Win32ShellFolderManager2.getDrives(Win32ShellFolderManager2.java:101)
  sun.awt.shell.Win32ShellFolderManager2.isFileSystemRoot(Win32ShellFolderManager2.java:323)
  sun.awt.shell.ShellFolder.isFileSystemRoot(ShellFolder.java:234)
  javax.swing.filechooser.FileSystemView.isFileSystemRoot(FileSystemView.java:310)
  com.osm.ui.FileImageUtilsTest$FileImageThread.run(FileImageUtilsTest.java:62)

No one else seemed to see this issue, but I saw it lots of times on my PC.

New Lego Camper Van Blender Render

Friday, March 13th, 2009

I have been playing with Blender again and I spent a few days trying to render my Lego Camper Van.

I managed to create this.

Image of a Lego Camper Van rendered and created with blender download the grudge 2 movie

I’m still not 100% happy with it.