OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | asm List | April 2011 Index

<--  Date Index  --> <--  Thread Index  -->

[asm] Plastic: An ASM wrapper for Tapestry 5.3


I'm not sure how many of you are aware of Tapestry
(http://tapestry.apache.org/) ... it's a sophisticated Java web
application framework.  At its core, it does some sophisticated
meta-programming on Java classes, transforming them at load time to
give them a number of new capabilities and such. This has built up in
Tapestry 5 over the last few years, using a wrapper around Javassist.

However, Javassist is poorly documented, supported and maintained.
It's also repeatedly caused problems with code compiled for JDK 1.6.
Several months ago, I decided to see if I could port my highest level
abstractions from Javassist to ASM (in fact, the move to higher
abstractions goes back a year or more).

The result is Plastic.  Plastic is a layer on top of ASM.  It entirely
hides the ASM APIs.

The JavaDoc is here (from Tapestry's continuous integration build):

https://builds.apache.org/hudson/job/tapestry-trunk-freestyle/ws/trunk/build/documentation/javadocs/org/apache/tapestry5/plastic/package-summary.html

(start with PlasticManager and PlasticClass)

Plastic is used in two ways:

1) To create new objects, typically proxy objects implementing one or
more interfaces

2) To instrument existing code, modifying its implementation
incrementally as classes are individually loaded

In most cases, you add behavior by introducing new interfaces and new
methods and by applying advice to existing methods.  For fields you
may inject values into the field, or outright replace access to the
field with delegation through a supplied FieldConduit.

You also get efficient access to methods, regardless of visibility,
via MethodHandle, as well as efficient access to fields (which are
required to be private) via FieldHandle.

Finally, there's a nice DSL, InstructionBuilder, used for providing
the implementation of a method directly.

Although Plastic is part of Tapestry, it is entirely usable outside of
Tapestry; it's a sub-project of Tapestry with no dependencies (it even
uses a repackaged copy of the ASM 3.3.1 source).  Tapestry 5.3,
including Plastic, is currently in an alpha state.

I'm generally quite pleased with how Plastic has come out, and I'd
like to share it with others with a similar interest.

Tapestry's inversion-of-control layer uses Plastic to generate various
kinds of proxies, to handle everything from just-in-time
initialization, to more advanced design patterns (such as
chain-of-command), to crazy stuff such as allowing method invocations
to return placeholder objects while computations execute on separate
thread.

In Tapestry's web layer, Plastic is used for additional types of
proxies, and for the property expression language (Tapestry compiles
template expressions such "user.name" directly to bytecode for optimal
execution).

In the next few weeks, I'll be converted the component class
transformation part from the Javassist layer to Plastic.

I'm very interested in comments and suggestions concerning Plastic.

-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.