InfoQ

News

Understanding the ActionScript Virtual Machine for Java Developers

Posted by Jon Rose on Nov 13, 2007

Community
Architecture,
Ruby,
Java
Topics
Programming ,
Open Source ,
Object Oriented Design ,
Rich Client / Desktop ,
Rich Internet Apps
Tags
Flex ,
Adobe ,
Flash ,
Closures ,
Apollo ,
Adobe Integrated Runtime
The ActionScript Virtual Machine 2 (AVM2) executes ActionScript 3.0 (AS3) bytecode in the Flash Player 9 runtime. ActionScript 3 is an Object Oriented programming language, used by developers to build Flash based applications in Adobe Flex and AIR. AS3 is fully compliant with the Third Edition of the ECMAScript standard.

For the Java developer, the concept of a virtual machine is nothing new, but there are a number of AVM2 features worth reviewing. Per Olesen published a blog last week discussing a number of the AVM2 notable features, including: Strong Typing, Method Closures, Just-in-Time (JIT) Compiler, and Garbage Collection.

Type Information
AS3 supports strong typing, discussed by Olesen:
Prior to AS3, all type information was stripped out of the code when compiled. At runtime, everything was just dynamically typed atoms. Starting with AS3, we can get the type information all the way down to the runtime.

… Using explicitly typed variables can improve performance and reduce memory consumption.
Method Closures
AS3 supports Method Closures, described by Olesen:
In AS3, we got method closures, which also mean we can create variables that are functions, and pass them around, while the function still retains the environment, it was created within ("this" is still what "this" was, when defined).
In Gary Grossman's and Emmy Huang's article, ‘Action Script 3.0 Overview,’ they describe a key usage of Method Closures:
Event handling is simplified in ActionScript 3.0 thanks to method closures, which provide built-in event delegation.

myButton.addEventListener("click", someMethod);
Just-in-Time (JIT) Compiler
JIT compilation is a technique where bytecode is converted into native machine code to improve performance. Adobe’s article ActionScript Virtual Machine 2 (AVM2) Overview details the impact on development:
In practice, the AVM2 may transform the code at run-time by means of a JIT, but this does not affect the semantics of execution, only its performance.
Olesen does note one impact developers should consider:
There is one thing to take notice of with JIT in AVM2. Constructors are not JIT'ed, so if you have performance intensive code in a class, take it out of the constructor.
Garbage Collection
Olesen provides a high level view of the Garbage Collection in AVM2:
The memory management and garbage collector is to be found in the separate MMgc project. This is a Deferred Reference Counting (DRC) mechanism combined with an incremental, conservative mark/sweep collector. Of course, the garbage collector implementation has been tuned for best client performance, with small (30ms) time slices.
For those looking for additional resources, , Farata Systems has a detailed blog entry comparing the language syntax between Java 5 and ActionScript 3. Also, more information can be found on AVM2 by reviewing the Mozilla Tamarin Project. Tamarin is the AVM2 implementation used in the Flash Player 9 and AIR platform. In addition, Adobe has a community Flex site dedicated to Java Developers at, http://flex.org/java/.

For Java developers, there are clearly a number of similarities in the ActionScript syntax and virtual machine architecture that should ease the learning process.

No comments

Watch Thread Reply

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.