Blog O' Matty


Generating byte code from a Java class file

This article was posted by Matty on 2007-12-16 18:31:00 -0400 -0400

I have been reading through the Java virtual machine specification, which covers all the details needed to implement a JVM. Once thing the specification talks about in detail is Java bytecode, which is the machine independent code that is executed by the virtual machine implementation. At various places in the specification I wondered what the byte code would look like for a chunk of Java code. Fortunately for me, the Java SDK comes with the javap utility, which can be run with the “-c” option to translate a class file into byte code:

$ javap -c -s -verbose MyEnv

{
MyEnv();
Signature: ()V
Code:
Stack=1, Locals=1, Args_size=1
0: aload_0
1: invokespecial #1; //Method java/lang/Object."":()V
4: return
LineNumberTable:
line 3: 0

public static void main(java.lang.String[]);
Signature: ([Ljava/lang/String;)V
Code:
Stack=2, Locals=2, Args_size=1
0: new #2; //class MyEnv
3: dup
4: invokespecial #3; //Method "":()V
7: astore_1
8: aload_1
9: invokespecial #4; //Method allocateObjects:()V
12: return
LineNumberTable:
line 7: 0
line 8: 8
line 9: 12
}

In the output above, you can see the methods and constants the MyEnv class utilizes, and the byte code that makes up the main method in the MyEnv class. Javap is amazingly cool, and I am starting to realize that understanding byte code can a super useful tool for debugging problems.

Printing a set of lines after a pattern match

This article was posted by Matty on 2007-12-03 20:52:00 -0400 -0400

I had to do some pattern matching last week, and needed a way to print the two lines that occurred after each line that matched a specific string. Since awk provides robust pattern matching, I came up with the following awk command line to grab the information I needed:

$ cat test

foo
1
2
3
foo
1
2
3

$ awk 'BEGIN { i=0 } /foo/ { while (i < 2 ) { getline; print 0; i++ } i=0}' test

1
2
1
2

I digs me some awk!

Is ZFS ready for primetime?

This article was posted by Matty on 2007-11-28 22:05:00 -0400 -0400

Over the course of the past four months, I have encountered a couple of ZFS bugs that led to corrupt pools. One of the bugs hit this weekend, and resulted in us having to recover the pool from a snapshot on our storage array (this experience has made me truly appreciate the 3par’s snapshot capability). These bugs have led me to question whether or not ZFS is ready for prime time, and if companies should be deploying it in production. If you have bumped into any ZFS bugs that led to data corruption, please leave me a comment.

Getting patches to install on Solaris 10 systems

This article was posted by Matty on 2007-11-27 03:13:00 -0400 -0400

There have been a number of threads in zones-discuss relating to Solaris 10 patching. Most of the feedback came from folks who ran into issues related to delayed activation patching, or patching zones that run on ZFS file system. Running zones on ZFS file systems is not currently supported by Sun, but it appears installing the latest version of 119254 or 119255 will help address a number of issues related to running zones on ZFS file systems. I am posting this here for future reference, and in an effort to help others who may be stumbling into issues applying patches to their Solaris 10 hosts.

Monitoring system utilization on Linux hosts

This article was posted by Matty on 2007-11-26 00:20:00 -0400 -0400

I am always on the look out for tools to analyze system performance. One nifty tool I recently came across is atop, which is an advanced system performance monitor for Linux. When atop is run, it displays overall system utilization in the header, and per-process CPU, memory, network or disk utilization information in the body (you need to patch your kernel to get disk and network utilization). Here is a sample atop session that shows just how awesome this utility is:

Atop Screenshot

I really dig the headers, as well as the network and disk utilization menus. Atop rocks!