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

Ride into the zombie apocalypse in style...
Back in the good old days of Flash games, there were a few staples; Happy Wheels, Stick RPG, and of course the apocalyptic driver Earn to Die. Fans of the running over zombies simulator can rejoice, as the sequel to the legendary game, Earn to Die... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Netflix Games expands its catalogue with...
It is a good time to be a Netflix subscriber this month. I presume there's a good show or two, but we are, of course, talking about their gaming service that seems to be picking up steam lately. May is adding five new titles, and there are some... | Read more »
Pokemon Go takes a step closer to real P...
When Pokemon Go was first announced, one of the best concepts of the whole thing was having your favourite Pokemon follow you in the real world and be able to interact with them. To be frank, the AR Snapshot tool could have done a lot more to help... | Read more »
Seven Knights Idle Adventure drafts in a...
Seven Knights Idle Adventure is opening up more stages, passing the 15k mark, and players may find themselves in need of more help to clear these higher stages. Well, the cavalry has arrived with the introduction of the Legendary Hero Iris, as... | Read more »
AFK Arena celebrates five years of 100 m...
Lilith Games is quite the behemoth when it comes to mobile games, with Rise of Kingdom and Dislyte firmly planting them as a bit name. Also up there is AFK Arena, which is celebrating a double whammy of its 5th anniversary, as well as blazing past... | Read more »
Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »
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 »

Price Scanner via MacPrices.net

Retailers are clearing out 9th-generation iPa...
With the introduction of new iPad Air and iPad Pros, along with newly discounted 10th-generation iPads, several Apple retailers are clearing out their remaining stock of 9th-generation iPads. Prices... Read more
Apple Studio Display with Standard Glass on s...
Best Buy has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Their price is the lowest available for a Studio Display among Apple’s retailers. Shipping is free... Read more
AirPods Max headphones back on sale for $449,...
Amazon has Apple AirPods Max headphones in stock and on sale for $100 off MSRP, only $449. The sale price is valid for all colors at the time of this post. Shipping is free: – AirPods Max: $449.99 $... Read more
Deal Alert! 13-inch M2 MacBook Airs on record...
Amazon has 13″ MacBook Airs with M2 CPUs in stock and on sale this week for only $829 in Space Gray, Silver, Starlight, and Midnight colors. Their price is $170 off Apple’s MSRP, and it’s the lowest... Read more
Apple Watch Ultra 2 on sale for $50 off MSRP
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose free... Read more
Apple introduces the new M4-powered 11-inch a...
Today, Apple revealed the new 2024 M4 iPad Pro series, boasting a surprisingly thin and light design that pushes the boundaries of portability and performance. Offered in silver and space black... Read more
Apple introduces the new 2024 11-inch and 13-...
Apple has unveiled the revamped 11-inch and brand-new 13-inch iPad Air models, upgraded with the M2 chip. Marking the first time it’s offered in two sizes, the 11-inch iPad Air retains its super-... Read more
Apple discontinues 9th-gen iPad, drops prices...
With today’s introduction of the new 2024 iPad Airs and iPad Pros, Apple has (finally) discontinued the older 9th-generation iPad with a home button. In response, they also dropped prices on 10th-... Read more
Apple AirPods on sale for record-low prices t...
Best Buy has Apple AirPods on sale for record-low prices today starting at only $79. Buy online and choose free shipping or free local store pickup (if available). Sale price for online orders only,... Read more
13-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices, along with Amazon’s, are the lowest currently available for new 13″... Read more

Jobs Board

Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-367184 **Updated:** Wed May 08 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Rehabilitation Technician - *Apple* Hill (O...
Rehabilitation Technician - Apple Hill (Outpatient Clinic) - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Read more
LPN-Physician Office Nurse - Orthopedics- *Ap...
LPN-Physician Office Nurse - Orthopedics- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.