Playing with Pivot reveals AWT dependence on Swing
Pivot is an open-source Java framework for building Web and desktop applications, originated as an R&D effort at VMware. Its recent introduction has ignited some discussions (see here or here.) Pivot builds on top of AWT and, as its authors Greg Brown and Todd Volkert say “takes a number of design cues from Swing”, but does not rely on Swing in any way.
This latter fact has made me eager to try optimizing and packaging a Pivot application with Excelsior JET to see to what extent its download size and disk footprint may be reduced using our Java Runtime Slim-Down model. I have compiled PivotDemo, but, to my big surprise, Swing was not marked as “safe to remove”. So I run PivotDemo on HotSpot in verbose mode:
E:\TEMP\pivot>java -verbose -cp pivot-core.jar;pivot-wtk.jar;pivot-wtkx.jar;pivot-tutorials.jar pivot.wtk.DesktopApplicationContext pivot.tutorials.Demo | grep swing
[Loaded javax.swing.TransferHandler$HasGetTransferHandler from C:\Program Files\Java\jre1.6.0_03\lib\rt.jar]
[Loaded javax.swing.JComponent from C:\Program Files\Java\jre1.6.0_03\lib\rt.jar]
[Loaded javax.swing.JPanel from C:\Program Files\Java\jre1.6.0_03\lib\rt.jar]
After some discussion with Greg that took place in comments to his blog post Introducing Pivot, he has kindly pointed out that there is a dependence on Swing in AWT code!
Dmitry,
A grep for ‘javax.swing’ in the source of java/awt/* yields that Sun has built a dependency on Swing within AWT:
EventDispatchThread#checkMouseEventForModalJInternalFrame(...):
> if (modalComp instanceof javax.swing.JInternalFrame) { ...
Container#startLWModal(...)
> Component predictedFocusOwner = (this instanceof javax.swing.JInternalFrame) ? ((javax.swing.JInternalFrame)(this)).getMostRecentFocusOwner() : null;
I have also run grep on AWT sources and found some more Swing dependencies. For instance, javax.swing.JFrame is used in the definition of the interface java.awt.im.spi.InputMethodContext, java.awt.dnd.DropTarget uses javax.swing.Timer, and so on.
Putting aside the discussion of whether these dependencies are evil, I was able to get the download size of PivotDemo down to 9.3MB, and the disk footprint to 34.6 MB even with some Swing classes compiled. The natively compiled demo also seems to use a bit less memory than when run on Sun JRE 1.6.0_03, which is, by the way, a 13.9 MB download and occupies 79 MB on the disk.
I invite you to download the natively compiled PivotDemo and see for yourself. Comments and questions are most welcome.
