TweetFollow Us on Twitter

May 99 Factory Floor

Volume Number: 15 (1999)
Issue Number: 5
Column Tag: From The Factory Floor

Jens Alfke, AWT Engineer

by Jens Alfke and Dave Mark, ©1999 by Metrowerks, Inc., all rights reserved

This month's Factory Floor interview brings us back inside Apple for a visit with Jens Alfke, world famous creator of the Stickies desk accessory. Of particular interest this month is Jens' work reimplementing the AWT Jens' work re-implementing the AWT (Abstract Window Toolkit), the core Java user-interface framework, in the latest release of Apple's Java runtime, MRJ.

Jens Alfke, a Java Toolkit Engineer at Apple, led the effort to re-implement the AWT library in version 2.1 of Apple's Java runtime, MRJ. He has previously worked on OpenDoc and AppleScript, but is probably best known as the author of the popular Stickies desk accessory. After the demise of OpenDoc he spent a year working at a startup company and at the Java division of Sun, just to get a feel for how awkward using Windows NT on a daily basis really is. His main extracurricular technical interest is designing protocols and user interfaces for futuristic e-mail and discussion systems. In his spare time Jens plays Lego and Skwish with his two young children, saves the land of Hyrule from the evil Ganondorf with his Nintendo64, and DJs drum'n'bass and ambient music at friends' houses.

Dave: Given that Apple is a Sun Java licensee, how do you go about implementing your own version of the AWT?

Jens: There are two halves to any AWT implementation. One half, the one developers know about, consists of the public classes in the java.awt package. These define the API and much of the behavior, but they are of course incomplete because they're cross-platform and can't talk to the platform's GUI to really make anything happen onscreen.

The other half, then, is a set of platform-specific Java classes that implement the real behaviors such as creating windows, managing controls and handling events. The way the two halves connect is that some of the public classes (like Graphics) are abstract and have to be subclassed by the platform-specific AWT code, and other public classes use abstract "peer" interfaces to communicate with a set of corresponding private classes. Our AWT consists of both these concrete subclasses and implementations of the peer interfaces.

In most Java implementations the platform-specific side of the AWT is mostly written in native code - most of the private classes consists of native methods that are implemented in C or C++. But in our new AWT implementation in MRJ 2.1 we used Java wherever possible, using our JDirect feature to call the Toolbox directly and only resorting to C++ for some low level glue or for really heavily optimized graphics code. So for instance, all our code that manages controls consists of Java classes that directly call the Control Manager just as a normal Mac application would. Doing it in Java really simplified our development and resulted in cleaner code.

Dave: What was involved in rewriting the AWT?

Jens: The previous AWT implementation descended from code written at Javasoft for their old "MacJDK". It was pretty poor quality code and had to be fixed up a lot for MRJ 1.0; and it was then further hacked and extended in MRJ 1.5 and MRJ 2.0. It was clearly a codebase that needed to be thrown away and rewritten. It was also very inefficient in its graphics code, and it draw controls itself, which made it not theme-savvy.

So last May we took a deep breath and started writing a new codebase from scratch. Well, nearly from scratch - we copied over a few pieces of the old AWT (such as menu handling) and grabbed an experimental C++ library I'd written for OpenDoc that did hierarchical view management. But about 95% of the code is new.

By the time MRJ 2.1ea2 was released in August, we had an alpha-quality AWT that developers were pretty happy with. We actually kept the old AWT hidden inside ea2, with a secret switch to enable it, in case of emergency if developers ran into insurmountable problems trying to run their apps with the new AWT. But we never had to tell anyone how to enable it!

After that it was mostly a series of bug fixes and compatibility tweaks to make sure we matched every semi- or un-documented behavior of the JDK. There's no real specification for the detailed behavior of the AWT, so we had to rely on our own testing and lots of 3rd party bug reports to discover all the subtle JDK behaviors that people's code relies on, and implement them the same way in MRJ.

I started the task and did a lot of the core stuff, but the whole AWT team made it happen - Shehryar Lasi, Steve McGrath, Lee Ann Rucker, Pete Steinauer, Steve Zellers. Nick Kledzik and Nick Thompson helped out with specific features too.

Dave: These days, what are the pieces that make up the AWT?

Jens: At the lowest level there's a layer that plugs into the JManager library - that's how we receive events from the host application, and request things like windows and menus from it. Then the view system manages the hierarchy of components and containers and their clipping. There's a bunch of really complex event handling logic that maps the Mac event model into the Java event model.

Then there is our Toolkit class that acts as a factory for peers, and the component peer implementations themselves - these are where the public Java classes like Component and Button tell us what to do to make things happen onscreen. Many of these peers talk to the Control Manager, and our text peers talk to a new text editing library called Textension. Menu classes have peers too.

We have a subclass of Graphics and two subclasses of Image that implement all the abstract methods of drawing and image management. And there's a lot of miscellany for dealing with cursors, fonts and so on.

Dave: Anyone who runs the CaffeineMark benchmark knows that MRJ has made some giant strides recently. What has been done to the AWT to contribute to this?

Jens: The new AWT gives most Java components their own GrafPorts, and ensures that we never draw into the host app's window's GrafPorts. This means we don't have to spend as much time setting up and tearing down GrafPort state like clipRgns and colors, since there aren't as many different things trying to use the same GrafPorts. The new code is very lazy (in a good way!) about setting up state only when it's necessary and preserving state as long as possible.

On top of that is the graphics pipeline, which speeds up primitive drawing operations such as lines and text. These calls are written into a big array in opcode/operand style. When the array fills up, or when a split second has gone by, we make a single call to a native function that parses the opcodes and does all the QuickDraw calls. This gets around the "mixed-mode" overhead of frequent transitions between Java and native code and lets us further optimize the way we set up GrafPorts. Our raw drawing performance is now within a few percentage points of the limit of what QuickDraw can achieve.

And of course I have to give thanks to the Symantec JIT (Just-In-Time compiler) and kelly jacklin's work in integrating it - I don't think that implementing the AWT mostly in Java would have worked nearly as well without the pure speed of the new JIT.

Dave: What else changed from AWT 2.0 to 2.1?

Jens: We now use native controls - that is, we use the Control Manager for things like buttons and checkboxes. We used to draw our controls by hand; they looked awful in MRJ 1.X, looked more like real controls in MRJ 2.0, but they still weren't theme-savvy. Now with MRJ 2.1, if you change your system's appearance by installing Appearance Manager themes or Kaleidoscope schemes, the controls in Java apps will fit in. With OS 8.5 installed we also support proportional scrollbar thumbs, live scrolling and UI sound effects - in all themes.

We now use some very fast QuickTime blitters to display images.

We use a new text editing library called Textension, which will be part of the upcoming ATSUI (Apple Type Solution For Unicode Imaging.) It's a very powerful text editor, but the Java text component APIs are pretty limited, so the major benefit we get out of it is that we're no longer limited to 32k of text.

Our FileDialog implementation now uses Navigation Services if it's available.

And in general, our stability has improved, and we're a lot better at conformance with other Java implementations, so a lot of real live Java apps that were developed and tested on other platforms now run much better in MRJ.

Dave: : Tell me about Java support for Mac OS X?

Jens: OS X Server, which recently shipped, includes its own Java, which is unrelated to MRJ. The virtual machine is a straightforward port of Sun's Solaris JDK, since OS X is BSD Unix compatible. The AWT is implemented using the "Yellow Box" or OpenStep framework.

It works well, but it doesn't include the Symantec JIT, and the AWT isn't as highly tuned as the one in MRJ 2.1, so it's not as fast as MRJ 2.1 in general. It may be faster for server type applications, though, since OS X has better I/O throughput than Mac OS 8.

For the final OS X, scheduled for late this year, we'll take a hybrid approach. The virtual machine itself will be based on the current one in OS X Server. This is great, since as I said it's a straightforward port of Sun's code and therefore there will be very few compatibility issues to worry about. We'll integrate the Symantec JIT.

The AWT will be based on the one in MRJ 2.1. Actually, we're "Carbonizing" our AWT, just as a developer would Carbonize their native app, so it will run on either OS X or OS 8. That way we can keep the same codebase for both operating systems and have the same functionality on both. The Carbon strategy makes just as much sense for us as it does for, say, Adobe!

We think this will be a really great product. The Unix-based virtual machine will get us around the limitations of the current OS's threading, memory management and I/O, while the Carbon-based AWT will continue to provide very Mac-like appearance and functionality.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »

Price Scanner via MacPrices.net

Save $300 at Apple on 14-inch M3 MacBook Pros...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Apple continues to offer 14-inch M3 MacBook P...
Apple has 14″ M3 MacBook Pros, Certified Refurbished, available starting at only $1359 and ranging up to $270 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year... Read more
Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more
Every version of Apple Pencil is on sale toda...
Best Buy has all Apple Pencils on sale today for $79, ranging up to 39% off MSRP for some models. Sale prices for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more

Jobs Board

*Apple* App Developer - Datrose (United Stat...
…year experiencein programming and have computer knowledge with SWIFT. Job Responsibilites: Apple App Developer is expected to support essential tasks for the RxASL Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
*Apple* Software Engineer - HP Inc. (United...
…Mobile, Windows and Mac applications. We are seeking a high energy Senior Apple mobile engineer who can lead and drive application development while also enabling Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.