Monday Jun 16, 2008

BTrace in the real world

In the last few weeks, I came to know about two cases of real world use of BTrace.
  1. Glencross, Christian M (his blog?) wrote about attempting to write a script to track SQL statements executed by a Java application (private email). Thanks to him for permitting me to blog about his BTrace script. I've made few formatting changes to fit his code in this blog and added few explanatory comments (staring with "VERBOSE:").
    import static com.sun.btrace.BTraceUtils.\*;
    import java.sql.Statement;
    import java.util.Map;
    import java.util.concurrent.atomic.AtomicLong;
    import com.sun.btrace.\*;
    import com.sun.btrace.annotations.\*;
     \* BTrace script to print timings for all executed JDBC statements on an event.
     \* <p>
     \* @author Chris Glencross
    public class JdbcQueries {
        private static Map preparedStatementDescriptions = newWeakMap();
        private static Map statementDurations = newHashMap();
        // VERBOSE: @TLS makes the field "thread local" -- sort of like using java.lang.ThreadLocal
        private static String preparingStatement;
        private static long timeStampNanos;
        private static String executingStatement;
         \* If "--stack" is passed on command line, print the Java stack trace of the JDBC statement.
         \* VERBOSE: Command line arguments to BTrace are accessed as $(N) where N is the command line arg position.
         \* Otherwise we print the SQL.
        private static boolean useStackTrace = $(2) != null && strcmp("--stack", $(2)) == 0;
        // The first couple of probes capture whenever prepared statement and callable statements are
        // instantiated, in order to let us track what SQL they contain.
         \* Capture SQL used to create prepared statements.
         \* VERBOSE: +foo in clazz means foo and it's subtypes. Note the use of regular expression
         \* for method names. With that BTrace matches all methods starting with "prepare". The
         \* type "AnyType" matches any Java type.
         \* @param args - the list of method parameters. args[1] is the SQL.
        @OnMethod(clazz = "+java.sql.Connection", method = "/prepare.\*/")
        public static void onPrepare(AnyType[] args) {
            preparingStatement = useStackTrace ? jstackStr() : str(args[1]);
         \* Cache SQL associated with a prepared statement.
         \* VERBOSE: By default, @OnMethod matches method entry points. Modifying with @Location 
         \* annotation to match the method return points.
         \* @param arg - the return value from the prepareXxx() method.
        @OnMethod(clazz = "+java.sql.Connection", method = "/prepare.\*/", location = @Location(Kind.RETURN))
        public static void onPrepareReturn(AnyType arg) {
            if (preparingStatement != null) {
                print("P"); // Debug Prepared
                Statement preparedStatement = (Statement) arg;
                put(preparedStatementDescriptions, preparedStatement, preparingStatement);
                preparingStatement = null;
        // The next couple of probes intercept the execution of a statement. If it execute with no-args,
        // then it must be a prepared statement or callable statement. Get the SQL from the probes up above.
        // Otherwise the SQL is in the first argument.
        @OnMethod(clazz = "+java.sql.Statement", method = "/execute.\*/")
        public static void onExecute(AnyType[] args) {
            timeStampNanos = timeNanos();
            if (args.length == 1) {
                // No SQL argument; lookup the SQL from the prepared statement
                Statement currentStatement = (Statement) args[0]; // this
                executingStatement = get(preparedStatementDescriptions, currentStatement);
            } else {
                // Direct SQL in the first argument
                executingStatement = useStackTrace ? jstackStr() : str(args[1]);
        @OnMethod(clazz = "+java.sql.Statement", method = "/execute.\*/", location = @Location(Kind.RETURN))
        public static void onExecuteReturn() {
            if (executingStatement == null) {
            print("X"); // Debug Executed
            long durationMicros = (timeNanos() - timeStampNanos) / 1000;
            AtomicLong ai = get(statementDurations, executingStatement);
            if (ai == null) {
                ai = newAtomicLong(durationMicros);
                put(statementDurations, executingStatement, ai);
            } else {
                addAndGet(ai, durationMicros);
            executingStatement = null;
        // VERBOSE: @OnEvent probe fires whenever BTrace client sends "event" command.
        // The command line BTrace client sends BTrace events when user pressed Ctrl-C 
        // (more precisely, on receiving SIGINT signal)
        public static void onEvent() {
            printNumberMap("JDBC statement executions / microseconds:", statementDurations);

    And he has expressed few wish lists for BTrace based on his experience with DTrace. We plan to investigate those items in near future.

  2. Binod P.G exchanged private e-mails about BTrace usage to track down a memory leak. Subsequently, he has blogged about the same.

Wednesday May 28, 2008

BTrace JavaOne2008 BOF slides..

I received emails asking for BTrace BOF (JavaOne-2008) slides. Better late than never... I've uploaded PDF of the slides. The BOF was mostly around demos -- slides do not contain much. But, slides have few pointers that may be useful.

Friday May 09, 2008

Thursday May 8, JavaOne

Here are the few highlights from the talks that I attended today:

TS-5428 Java Technology Meets the Real World: Intelligence Everywhere.

This talk is about pervasive computing (a.k.a ubiquitous computing) with products from Sentilla. There was an interesting demo about humidity sensor detecting changes and sending a message to a host. The "motes" run CLDC 1.1 VM (+ proprietary profile for motes). These motes have ports for sensors and actuators and some built-in sensor. There were many interesting suggestions for embedded programming for such small devices (don't allocate in inner loops and there by leading to to GC kick-in, avoid too many static fields, avoid threads whenever possible and so on).

TS-7575 Using Java Technology-Based Class Loaders to design and implementing a Java platform, Micro Edition

The basic idea is to run JavaME applications (developed for different configurations/profiles/subsets of optional packages) on top of JavaSE. The extended JavaSE classes and packages not available in specific profile or optional package set [implemented by a specific phone] should not be made available to JavaME apps targeted. i.e., only the classes available to a specific phone model should be available. If the JavaME app tries to access any other class, it should receive ClassNotFoundException. The speakers explained how to achieve such "containers" by class loader based isolation. The problem is that they seem to solve only the class access. What about extended methods and fields? For example, platform core classes on JavaSE have superset of methods [more methods on the same class available on JavaME - eg. java.util.Hashtable has more methods on JavaSE). The application classes have to bytecode analyzed and instrumented to take care of field/method accces. It seems that their current product that does not address this yet.

PAN-5542 Developing Semantic Web Applications on the Java Platform.

The discussion started with some nice demos. There was a demo with AllegroGraph RDF store, Twine, a demo with using GRDDL and getting RDF triples by a proxy server. i.e., a proxy serves does the GRDDL transformations to get RDF triples from sites [which could be stored/analyzed with RDF stores subsequently] and a demo with FOAF files. Interesting take aways from the discussion include:

  • We don't have to wait for SEMANTIC WEB with full fledged reasoners and so on. Instead, add little semantic bits to existing web (say using RDFa, GRDDL etc.) in your current web projects/pages.
  • There are many Java tools. There is need to standard Java APIs for triple store access etc. Right now, we have to write for Jena, Sesame etc. It was also felt that APIs will need to wait for more usage scenarios.
  • There are tools to expose your existing databases as virtual RDF stores -- for example: D2RQ. Probably, most of the RDF triples could come from existing data.
  • Privacy, security of the information is very important. Work needs to be done in this area.
  • Natural language processing and getting triples out of it is very hard. You may want to refer to systems like DBpedia.

Thursday May 08, 2008

Wednesday May 7, JavaOne

Today Bill, Chihiro, Jaya and I talked on Blu-ray. The talk was centered around the open source project @ - a library and a set of tools to build Blu-ray discs. If you haven't checked out code/docs, you may want to checkout and play with the code. All you need is a laptop with blu-ray drive and a BD-RE disc. Optionally, for added fun you may want to have a hardware bluray player such as PS3 -- so that you can see the output on your TV rather than on a laptop. Other than the session, we also had a very informal BOF on blu-ray, OCAP etc. during the evening. It is good to meet experts in respective technologies in one place!

Other than the the blu-ray stuff, I did attend other talks/BOF. Just after Blu-ray session, I attended "TS-6000 Improving Application Performance with Monitoring and Profiling Tools" talk. This talk was about OS specific tools, JDK tools and third-party tools for profiling and monitoring. Gregg Sporar and Jaroslav Bachorik (NetBeans Profiler team) presented very well. There were many interesting questions/discussions as well. If you haven't done so already, you may want to download VisualVM. If you want bit more fun doing monitoring/profiling, you may want to check out the sources from and build it yourself. You can build BTrace VisualVM plugin using the command:

    c:\\visualvm\\plugins>ant build

assuming you have checked out VisualVM sources under "c:\\visualvm". If you have already checked out BTrace sources under some other directory, say "c:\\btrace", you can use

    c:\\visualvm\\plugins>ant -Dbtrace.home=c:\\btrace build

To run VisualVM with all the plugins that you built, you can use the following command:

    c:\\visualvm\\plugins>ant -Dbtrace.home=c:\\btrace run

Please let us know what features you'd like to see with BTrace and/or BTrace VisualVM plugin.

I attended and liked the "Class Loader Rearchitected (BOF-6180)" BOF. If you have ever written class loaders, chances are that you have faced mysterious deadlocks or ClassCastException that said "ClassCastException: Foo cannot be cast to Foo" or having to decide between overriding loadClass and findclass, you probably should have attended this talk and gave your opinions/suggestions/ideas :-) If I understood properly, I think there was a suggestion to add class loader info. to the ClassCastException (something like class-loader-class-name@identity-HashCode style string?) so that one can quickly see it is a class loader issue. Also, there were many questions on loading classes from jar files. Looks like there will be changes to class loader API and class loading in VM for JDK 7.

Wednesday May 07, 2008

Tuesday May 6, JavaOne

In today's sessions that I attended I liked the following:

JRuby: Why, What, How... Do It Now

This talk is a good introduction to (J)Ruby the language and important applications of (J)Ruby. And many pointers to related (J)Ruby sessions. Nice summary!

JavaScript programming language: The Language Everybody Loves to Hate

great talk by Roberto Chinnici. Nice summary of functional and prototype-based object orientation aspects of JavaScript. You can easily impress your friends will some neat snippets of JavaScript :-) You may want to continue the fun by reading Doug Crockford's pages, if you have not do already!

At 7.30 PM, we (I and Kannan) talked about BTrace. There were many interesting questions/discussions -- both during and after the BOF! Today (Wed May 7) will be a Blu-ray day -- it starts with TS-5449 Java Technology for Blu-ray and TV: Creating your own Blu-ray Java Discs session. It is about the open source project @ Meet you all there!

Wednesday Apr 30, 2008

JVM Languages @ JavaOne 2008

In JavaOne 2008, there are many intesting sessions on "other" JVM languages covering both dynamically typed languages (JavaScript, Groovy, JRuby) and statically typed languages (JavaFX, Scala). As usual, there are many sessions covering application aspects -- like using scripting on Glassfish, Grials (Groovy), Rails (JRuby) and so on. But, my interest is mostly on the programming language aspects and JVM implementation issues. Here is a table of sessions covering those:

Session ID

Session Title

Session Type

Speakers and Company

Speakers and Company

Venue - Room


Overview of the JavaFX™ Script Programming Language

Technical Session

Christopher Oliver, Sun Microsystems, Inc.

May 06
10:50 - 11:50

Moscone Center -
Gateway 104


JRuby: Why, What, How...Do It Now

Technical Session

Thomas Enebo, Sun Microsystems, Inc. ; Charles Nutter, Sun Microsystems, Inc.

May 06
10:50 - 11:50

Moscone Center -
Esplanade 307-310


A JavaFX™ Script Programming Language Tutorial

Technical Session

James Weaver, LAT

May 06
12:10 - 13:10

Moscone Center -
Esplanade 305


JavaScript™ Programming Language: The Language Everybody Loves to Hate

Technical Session

Roberto Chinnici, Sun Microsystems, Inc.

May 06
15:20 - 16:20

Moscone Center -
Esplanade 307-310


The Script Bowl: A Rapid-Fire Comparison of Scripting Languages

Panel Session

Guillaume Laforge, G2One, Inc.; Charles Nutter, Sun Microsystems, Inc. ; Jorge Ortiz, Stanford; Raghavan Srinivas, Sun Microsystems, Inc.; Frank Wierzbicki, Sun Microsystems

May 07
09:30 - 10:30

Moscone Center -
Gateway 104


Groovy, the Red Pill: Metaprogramming--How to Blow the Mind of Developers on the Java™ Platform

Technical Session

Scott Davis, Davisworld Consulting, Inc.

May 07
09:30 - 10:30

Moscone Center -
North Mtg-121/122/124/125


Programming with Functional Objects in Scala

Technical Session

Martin Odersky, EPFL

May 08
13:30 - 14:30

Moscone Center -
Gateway 104


Writing Your Own JSR-Compliant, Domain-Specific Scripting Language

Technical Session

John Colosi, VeriSign, Inc.; David Smith, VeriSign Inc.

May 08
13:30 - 14:30

Moscone Center -
Esplanade 301


Comparing JRuby and Groovy

Technical Session

Neal Ford, ThoughtWorks Inc.

May 09
13:30 - 14:30

Moscone Center -
Esplanade 303


Jython - Implementing Dynamic Language Features for the Java™ Platform Ecosystem

Technical Session

Jim Baker, Zyasoft; Tobias Ivarsson, Neo Technology

May 09
14:50 - 15:50

Moscone Center -
Esplanade 305

Tuesday Apr 29, 2008

BTrace BOF @ JavaOne 2008

We have a BOF on BTrace in this year's JavaOne. But, you will not find the name "BTrace" in session title -- that is because talk was submitted before BTrace was open sourced with that name :-) The details of the BOF is as below. Please visit and let us discuss on dynamic tracing for Java.

BOF-5552 Java™ Platform Observability by Bytecode Instrumentation Kannan Balasubramainan, A. Sundararajan Tuesday May 06 19:30 - 20:20 Moscone Center - Esplanade 300

Other related talks/BOFs on dynamic tracing/observability include:

Moscone Center - Hall E 133
TS-5716 D-I-Y (Diagnose-It-Yourself): Adaptive Monitoring for Sun Java™ Real-Time System Technical Session Carlos Lucasius, Frederic Parain Tuesday May 06 18:00 - 19:00
TS-6000 Improving Application Performance with Monitoring and Profiling Tools Technical Session Jaroslav Bachorik, Gregg Sporar Wednesday May 07 10:50 - 11:50 Moscone Center - Gateway 104
LAB-9400 Exposing the Depth of Your JDK™ Release 7.0 Applications with Dynamic Tracing (DTrace) Hands-On Lab Angelo Rajadurai, Raghavan Srinivas, Wednesday May 07 18:30 - 20:30 Moscone Center - Hall E 130/131 (LAB)
TS-6145 Using DTrace with Java™ Technology-Based Applications: Bridging the Observability Gap Technical Session Jonathan Haslam, Simon Ritter Thursday May 08 13:30 - 14:30 Moscone Center - North Mtg-121/122/124/125
BOF-4994 End-to-End Tracing of Ajax/Java™ Technology-Based Applications, Using Dynamic Tracing (dTrace) Birds-of-a-Feather Session (BOF) Amit Hurvitz Thursday May 08 18:30 - 19:20 Moscone Center - Gateway 104
BOF-5223 VisualVM: Integrated and Extensible Troubleshooting Tool for the Java™ Platform Birds-of-a-Feather Session (BOF) Luis-Miguel Alventosa, Tomas Hurka Thursday May 08 19:30 - 20:20 Moscone Center - Gateway 104
TS-6145 Using DTrace with Java™ Technology-Based Applications: Bridging the Observability Gap Technical Session Jonathan Haslam, Simon Ritter Friday May 09 14:50 - 15:50 Moscone Center - North Mtg-121/122/124/125
TS-6000 Improving Application Performance with Monitoring and Profiling Tools Technical Session Jaroslav Bachorik, Gregg Sporar Friday May 09 16:10 - 17:10 Moscone Center - Hall E 133

Groovy jsr-223 engine updated..

Groovy jsr-223 script engine @ has been updated to use Groovy version 1.5.6.

Monday Apr 28, 2008

Bluray @ JavaOne 2008

If you want to learn more about Blu-ray disc and what Java has to do with it, you may want to attend the following talks/BOFs @ JavaOne 2008!

Date/Time Session ID Session Name
Wednesday, May 07 9:30 AM - 10:30 AM TS-5449 Java™ Technology for Blu-ray™ and TV: Creating your own Blu-ray Java Discs
Wednesday, May 07 9:30 AM - 1:30 PM - 2:30 PM TS-6464 Blu-ray Disc Security
Wednesday, May 07 9:30 AM - 6:30 PM - 7:20 PM BOF-5451 Blu-ray and Java™ Technology Roundtable
Thursday May 08 1:30 PM - 2:30 PM TS-5638 Writing Connected Device Configuration Applications for Resource-Constrained Devices
Thursday May 08 1:30 PM - 2:30 PM TS-5888 Driving Innovation in Packaged Media (Blu-ray) User Experience

From our group talk (TS-5449), we will be focusing on the open source project @ Meet you soon @ JavaOne !!

Friday Mar 07, 2008

BTrace - a dynamic tracing tool for Java

Are you interested in a byte code instrumentation (BCI) based dynamic tracing solution for the Java platform? If so, please visit BTrace is a safe, dynamic tracing solution for Java. You can express tracing code in Java and run it against a running Java application. Your Java application should be running on JDK 6 or above for BTrace to work. You may be using VisualVM, the all-in-one Java troubleshooting tool. VisualVM supports plugin model to extend it's capabilities. BTrace plugin for VisualVM will be available soon. When BTrace plugin is available, you can trace your application from VisualVM tool. In the meanwhile, you can use BTrace command line tools. You may want to check out the user guide for the command line access.

Tuesday Mar 04, 2008

Latest on scripting for the Java platform...

Updates on the world of Scripting for the Java platform:

Friday Feb 15, 2008

VM on a VM on a ...

My recent fun with virtualization continues. In the last JavaOne, I missed the talk titled "Everything Java": JPC, a Fast x86 PC Emulator. But, I downloaded the source and binary of JPC just to check it out. I ran the classic game "Prince". Nostalgia :-)

Thursday Feb 14, 2008

A tale of many OSes without reboot/partitioning

In my previous post, I talked about having to use more than OS for education/entertainment purpose. The problem is that I've quite a few ISO images and LiveCDs with those images. Two problems:

  • I need to keep searching right LiveCD I want or I need to install more than one OSes on the same/different boxes.
  • Need to re-start the machine if I've use a single machine with many OSes.

For kids, all they want is the best stuff available across all operating systems. They don't wait for the machine to reboot from another partition or from a LiveCD. Besides, while they can switch between applications easily, restarting a different OS is bit much to ask :-) [although I won't be surprised if they do that!]. Kids want to switch between interesting applications/games/edutainment stuff rather quickly. Also, we don't seem to get all the good stuff on the same OS! For example, I need to Scratch on Windows or Mac -- no official Linux binary yet :-( While it is possible to hack to run Scratch on Linux by taking the Squeak image, there are issues with MIDI etc. There are many good stuff in Edubuntu and OLPC too. The point is that you want to run the best set of applications/games across operating systems -- without having to reboot.

This is where Virtualization helps! As Tim Marland said, you don't have to be a hypervisor/virtualization expert to use it. I downloaded VirtualBox for Windows XP [just run .msi file to install] and edubuntu [this later was very easy -- I just to use Add/Remove programs menu and look for "VirtualBox". VirtualBox is very easy to configure -- mostly point-n-click stuff. Now, I can run OLPC, Edubuntu and Belenix on my Windows XP latop without having to partition my hard-disk or rebooting. Kids can switch between their favorite applications across Operating Systems easily. If you are curious how it looks, here are some screen-shots:

Monday Feb 11, 2008

A tale of two operating systems for kids..

When I introduced computers to my kids, as like many other kids they started with games on the net. Mostly playing simple games like tom-and-jerry chase, bob the builder etc. My mother tongue is Tamil and so I came across the kids section of the Tamil Virtual University site.

Then, I started experimenting with Squeak and EToys. Later on, I moved to use Scratch. After some time, I learned about GCompris, Tux Math, Alice, Robomind etc. During that period, I still used the non-open-source OS that came with my laptop. GCompris version on that OS does not include all the activities -- to encourage the usage of open source operating systems! So, I looked for operating systems for kids. I've started using the following operating systems.

  1. Edubuntu. Venkateswara TV of Solaris sustaining team suggested this to me when I asked him about a Linux distro with GCompris. Wow! Edubuntu is very nice. In addition to what edubuntu comes with (lot of good stuff!), I installed more programs like Childsplay etc.
  2. LiveCD for OLPC (One-Laptop-Per-Child). The user interface definitely appeals to kids. Kids seem to enjoy the text editing, painting, Turtle (LOGO) and EToys...!!

Recently, I came to know about OpenSolaris in Tamil -- one of these days, I'll try a LiveCD. Need to check if there is a Tamil version of Belenix out there...

Monday Jan 07, 2008

No evidence, but still guilty?

Harbhajan banned for three-matches for alleged "racial abuse". Umpires haven't heard or seen anything. Mike Procter himself came on camera and said that the umpires told him they have not heard or seen anything. Did he see anything from the TV footage? It does not seem so. If there is any evidence, we have the right to know it. Aussie players claim something. Indian players claim otherwise. Two parties are not agreeing on what really happened. Under the circumstances, you expect the ICC referee to dismiss the charge on the lack of evidence. Instead, he punished Harbhajan. Did he go by just the word from Aussie players alone?

Now, by this process anyone can be punished. Any team can gang against the better players of the opponent team and claim racial abuse or anything that can get a ban! If a Muttiah Muralidaran bowls well, previously they claimed chucking, shouted "no ball", wrote "expert" columns about his bowling action and so on. Now, it seems that there is even a new trick - claim "racial abuse", get a ban for 2/3 matches and then you can bag the series!!

If BCCI believes injustice has been done, then they should just pull out and send a strong message to ICC. It is ICC that needs India and it's large cricket crazy population. Not the other way around. It is economically viable to have our own tournaments, entertain public, have fun and make money. BCCI has to learn from the ICL example and start something within India and expand.




« November 2015

No bookmarks in folder


No bookmarks in folder


No bookmarks in folder