Monday Jul 13, 2009

javafxdoc-style docs for Java code

You may have browsed JavaFX API docs generated by javafxdoc tool. javafxdoc tool is implemented as a doclet. It is possible to use javafxdoc's doclet to generate API docs for Java code.

Note: The XMLDoclet implemented as part of javafxdoc tool is an implementation detail and not part of official JavaFX/tool API and so please do not depend on this. This is more for fun/learning/personal use!)

I generated javadoc for BTrace source using the following command:

javadoc -docletpath $JAVAFX_HOME/lib/shared/javafxdoc.jar  -doclet -sourcepath .  -subpackages com.sun.btrace

where JAVAFX_HOME is the directory where JavaFX SDK lives.

A screenshot from generated docs:

Monday Jul 06, 2009

BTrace project moved to

We have recently moved BTrace project to If you are interested in BTrace, please continue to use it and help develop it from

Thursday Feb 26, 2009

Prizes for having fun! Hurry....

Do you live in India? What do you want? Sony Ericsson phone or Canon Camera or iPod? If so, have fun writing JavaFX code and win any of these prizes!

Monday Feb 23, 2009

JavaFX interactive shell

JavaFX compiler has a built-in script shell - Per Bothner has implemented a read-eval-print loop facility for JavaFX. The script shell class is Note:This is in the openjfx-compiler repository and not in the JavaFX 1.0 binary.

A sample JavaFX session is as follows:

$ java -cp dist/lib/shared/javafxc.jar 
/\*fx1\*/ "hello"
/\*fx2\*/ 2 + 4
/\*fx3\*/ function greet (name) { println("Hello, {name}") }
/\*fx4\*/ greet("Sundar")
Hello, Sundar
/\*fx5\*/ var s = [ "Sunday", "Monday", "Tuesday" ]
[ Sunday, Monday, Tuesday ]
/\*fx6\*/ for (i in s) println(i) 
/\*fx7\*/ class Person { public var name: String; }               
/\*fx8\*/ var p = Person { name: "Sundar" }
/\*fx10\*/ import javax.swing.\*;
/\*fx11\*/ var f = new JFrame("hello");
fx11:1: cannot find symbol
symbol  : class JFrame
location: class fx11
/\*fx13\*/ var f = new javax.swing.JFrame("hello")
/\*fx14\*/ f.setSize(300, 300)
/\*fx15\*/ f.setVisible(true)

While there is a generic shell called "jrunscript" for languages that implement jsr-223, it does not work very well for statically typed languages (which can be said about jsr-223 itself). But, the above mentioned JavaFX script shell is independent of jsr-223 interface.

Besides, jrunscript crashes for JavaFX!

$ jrunscript -cp dist/lib/shared/javafxc.jar -l javafx
fx> "hello"
Exception in thread "main" java.lang.NoSuchMethodError:$OptionHelper;)[Lcom/sun/tools/javac/main/JavacOption$Option;
	at javax.script.AbstractScriptEngine.eval(

This is because JavaFX compiler code depends on modified javac classes. The code for jrunscript lives in tools.jar along with the unmodified javac classes! These unmodified javac classes are loaded which results in exception from javafxc code! We have to use the bootstrap path workaround as shown below:

$ jrunscript -J-Xbootclasspath/p:./dist/lib/shared/javafxc.jar -l javafx
fx> 233 + 334
fx> for (i in [0..4]) println(i)

But, now we have a much better ScriptShell for JavaFX :-) We don't need to resort to this hack...

Friday Feb 20, 2009

A JavaFX compiler debug trick

There is an unsupported (read - can be removed in future without notice!) command line option with JavaFX compiler. If you run javafxc as

    javafxc -XDdumpjava Test.fx

the compiler generates intermediate Java code for your JavaFX program in "./dumpjava" directory (compiler expects you to create ./dumpjava directory before invoking javafxc). This is meant to be a debugging option for JavaFX compiler developers. But, you can look at generated Java code to see what happens behind the scenes - much like C++ programmers used to look at intermediate C code and/or preprocessed code.

JavaFX for Java, JavaScript programmers

I missed attending and speaking at Sun Tech Days at Hyderabad due to a personal reason :-( In fact, I prepared slides for a talk titled "JavaFX for Java, JavaScript programmers". This is much like my earlier language comparison blog entries such as Java, JavaScript and Jython, Java, Groovy and JRuby etc. The idea is to learn a language by language comparison - and not to conclude "better"/"worse" language and so on. So, no politics please :-) Although I could not attend Sun Tech Days, I am posting the slides here : slides in a .pdf file

Tuesday Dec 23, 2008

Installed Ubuntu 8.10 on my PS3

Ubuntu on PS3

I wanted to install Ubuntu on my PlayStation 3.

My Setup

  • PS3 is NTSC 60 GB hard disk version - updated with firmware version 2.42.
  • PS3 is connected to 32 inch 720p Sony LCD TV via HDMI.
  • PS3 is connected to wireless network.

Stuff needed in addition to the above

  1. USB keyboard.
  2. USB mouse.
  3. CD burned with Ubuntu powerpc iso (ubuntu-8.10-alternate-powerpc+ps3.iso).

Preparing PS3

  1. Backup your PS3 hard disk using [Settings] -> [System Settings] -> [Backup Utility] menu. I didn't bother to backup the hard disk.
  2. Go to [Settings] -> [System Settings] > [Format Utility] menu.
  3. Select [Format Hard Disk] and click [Yes].
  4. Choose [Custom] and [Allot 10GB to the Other OS].
  5. Select [Quick Format] and confirm with [Yes].

Installing Ubuntu

  1. Connect USB keyboard and mouse to PS3.
  2. Insert the disk with Ubuntu iso image into PS3.
  3. Go to [Settings] -> [System Settings] > [Install Other OS]. PS3 will detect the install CD and copy files and instruct you to ..
  4. Select [Settings] -> [System Settings] -> [Default System] -> [Other OS]. This will boot PS3 with other OS. From then onwards, follow the Ubuntu installation instructions.

Small hiccup

The installation was smooth except for one small issue - the installation seemed to hang in "Select and install software" step. After 6% the progress bar did not increase at all! Fortunately, this seems to be a known issue with text mode installer. Please refer to Ubuntu 8.10 release notes and bug 290234. I pressed Alt-F4 and Alt-F1 to toggle between logging console and main screen to check the progress. Eventually, the installation completed! While installing I configured network as well -- i.e., giving WEP password etc. -- not sure if this is mandatory, but in my case I have wireless connectivity and so I supplied the configuration values for the same.

Switching between Operating Systems

  • From Ubuntu to Game OS, use the command
        sudo boot-game-os
  • From Game OS to Ubuntu, use the menu
       [Settings] -> [System Settings] -> [Default System] -> [Other OS]

Few Screenshots

Wednesday Dec 17, 2008

Debugging option for javac and javafxc

I work on JavaFX compiler these days. The command line (debugging) option that I often use is -doe ("dump on error"). This option prints stack trace of the compiler when error message is printed. NOTE: This is an internal option and can be removed any time without notice! But, it is useful for debugging. This option works for javac as well as javafxc. When I misspelled "class" as "clas" and run compiler with -doe option, I got the stack trace below:

$ javac -doe class, interface, or enum expected
clas t {}
1 error

Wednesday Dec 10, 2008

Yet another reason for using VirtualBox

I bought a laptop from ELCOT for my sons. It came with SUSE Linux Enterprise Desktop 10 SP2. Kids wanted to see how it is like playing games in the "old" days. Nothing better than seeing and really playing! And so VirtualBox :-)

Also, having access to more than one OS without having to partition does not hurt -- even for a kid's laptop! We can run OLPC, OpenSolaris, Puppy Linux, or anything else!

Thursday Dec 04, 2008

Playing with Alice and PhET

These days, my son is playing with these (apart from usual game sites):
Alice is a 3D programming environment. He likes it as much as he likes Scratch.
Interactive simulation tool for physical phenomena from University of Colorado. He kept trying to soft land "on the moon" :-) I guess Chandrayaan I has impressed him a lot!

What is the common between Alice and PhET apart from being great education tools? It is Java! With the advent of JavaFX, we can expect that such fantastic rich GUI applications will be written in JavaFX.

Friday Aug 08, 2008

Scriptifying BTrace?

One of the issues reported with BTrace is that the trace authors have to write "verbose" code [some people say Java is "verbose"!]. In BTrace, we have to repeat the same set of imports, annotations in every btrace file and all methods have to be "public static void" and so on. Instead of inventing a new scripting language, I've added a simple C preprocessor like step in BTrace compilation. This preprocessor is based on the one in the GlueGen project. Thanks to Ken Russell for this code and for reviewing my changes specific to BTrace project. The preprocessor solution does not rule out a scripting solution in future :-) If you have nice ideas or would like contribute in this area, you are always welcome! But, I think preprocessor solution is simple and will be useful to some.

Simple Example:


To run this sample, the following command can be used:

   btrace -I . <pid-of-the-traced-process>

Without the -I option in command line, BTrace skips the preprocessor step.

Friday Jul 25, 2008

Playing with JSqueak

Squeak is a open source implementation of Smalltalk. What is JSqueak? JSqueak is a Squeak interpreter written in Java. You can download JSqueak source code and play with it. I did the following:
  • Expanded the downloaded under a directory, say c:\\JSqueak.
  • cd c:\\JSqueak
  • javac -d . \*.java
  • copy mini.image.gz JSqueak
  • java JSqueak.Main
Even if you are not going to learn Smalltalk (why?), you can have the fun of reading Smalltalk VM implemented in Java. If you are lazy and don't want to compile, you can run directly by JNLP link from Inside the Squeak environment, I wrote the legendary "Hello World" :-) This is how it looks...

Friday Jul 18, 2008

BTrace and JMX

You can dyanamically attach BTrace to a Java process to inject trace code into it. BTrace client classescollect the trace output via a socket -- these client classes are used by BTrace command line client as well as VisualVM plugin for BTrace. How about attaching a JMX client to collect BTrace's trace data? Yes, it is possible to access a BTrace class's static fields as attributes of a MBean with this RFE.

There are two MBean samples in the BTrace repository. I attached both BTrace samples to a "Java2D demo" process. And then I attached VisualVM to view the Mbean registered by these BTrace samples:

  1. - this sample instruments java.lang.Thread.start() method to update a counter field. This counter field is accessible by JMX clients.

  2. - this sample collects histogram of java.awt.Component objects created by an application and exposes the histogram (map) as MBean attribute.

Friday Jun 27, 2008

Working from an office -- for a change!

I work from home in Chennai, India. There is maintenance power shutdown in my part of the city today [from 9.00 AM to 5.00 PM). I'm writing this blog from a Sun office in Apeejay Business Centre, Chennai. It is nice to be in an office after quite some time - at least as a change! But, I think I'd rather prefer to avoid travel, preparation to go office etc. every day :-)

Thursday Jun 26, 2008

BTrace aggregations - contribution from community

If you have used DTrace, chances are that you have used aggregations. For performance issues, aggregated data is often more useful than individual data points. With BTrace, aggregating data is bit painful (you have to manage using Maps explicitly). It would be nice to have DTrace-style aggregation functions such as sum, max, min and so on. Glencross, Christian M (cited in my previous entry) has contributed code changes, doc and a sample for easy-to-use aggregation facility for BTrace. Please refer to the sample code ( that demonstrates aggregations.

Now something unrelated to aggregations, but related to BTrace : I came to know about another use-case of BTrace. See also




« November 2015

No bookmarks in folder


No bookmarks in folder


No bookmarks in folder