Monday, January 14, 2008

CICE/ARM prototype

As I mentioned a few days ago, I've been hacking around in javac recently in an attempt to get it to implement some of the ideas in the CICE and ARM proposals. The idea being that having a prototype available may help to highlight which aspects of the proposals really work in practice, and which do not.

I've put an initial cut here, which is based on the JRL licensed JDK codebase from 04-Dec-2007 (JDK 7 build 24). It hasn't had a great deal of testing, so don't expect it to be wonderfully stable at this stage. I'll attempt to fix any bugs that crop up however.

It's important to note that this initial prototype has been put together without consulting the authors of the two proposals, so I may well have misunderstood some of the ideas - apologies if so. I've also had to make a call on which aspects of the proposals to include, and which to exclude for now. I've opted for a pretty minimalist implementation to start with, and that pans out as follows:

CICE

CICE expressions, public local variables and implicitly final local variables should all be working. I've left out transient public locals and type inference.

At this stage, I also haven't provided any of the library additions or changes mentioned in section IV of the proposal.

Basically all of the examples in the CICE document should work (apart from those involving AbstractThreadLocal).

ARM blocks

ARM blocks can take one of two forms, both based on the do keyword only for now. The first allows you to declare the resources' variables as part of the ARM block itself:

do (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest)) {
// ...
}

The second form is where the resources are provided as a list of expressions:

InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);

do (in, out) {
// ...
}

Currently, all resources must implement java.io.Closeable. As the ARM proposal points out, Closeable is probably not a good choice in the long run, but it's a starting point.

An ARM block will attempt to call close() on all the resources, in the reverse order that they were listed. In the first form of the block the variables are not final so it is possible to reassign in and out to some other Input/OutputStream within the ARM block - the block will attempt to close whatever Closeables the variables refer to at the time the block ends. In the second form of the block, reassigning in and out has no effect.

In the first example, if in or out are set to null this effectively cancels the automatic closing of the variable in question, and does not cause a NullPointerException or any other runtime error. I don't know whether this is useful or not, as yet.

In the first form, it's possible to mark the variables as final. It's also possible to mark them as public, which is only really useful if reassignment should be allowed.

If exceptions are raised, whether by evaluating the variable initializers (in the first form), by executing the body of the block, or by the calls to close() at the end of the block, it should only ever be the first such exception which is ultimately thrown by the block, after it has attempted to close all the resources.

The proposal doesn't mention whether it should be possible to use 'break' statements within an ARM block so I haven't implemented that. I think it may be useful though - thoughts welcome.

Bug reports and the like can be sent to me directly at markmahieu at gmail dot com.

12 comments:

Stephen Colebourne said...

I've been trying to code up a prototype of FCM at Kijaro - http://kijaro.dev.java.net.

I'd love to see your CICE/ARM prototypes hosted at Kijaro as well, but there may be a license problem. Kijaro uses the GPL JDK build, whereas you seem to have chosen JRL. Having the proposals in the same place would be a big win IMO. Would you consider a change of license?

Stephen Colebourne

PS. If you want to help finish me code up FCM closures that would be great too ;-)

Mark Mahieu said...

Hi Stephen,

I have no problem moving the code to Kijaro - it's only JRL at the moment because those were the sources I had to hand at the time. I'll look into what's involved when I get a chance.

Regarding FCM (and JCA), I'm conscious of the fact that I still need to read through the proposal in detail, which I'll try to do over the next couple of days. It does look like there are bits of the CICE prototype which may be reusable for FCM (more from Neal's prototype, mind), although you may have already implemented those areas... time for me to check out Kijaro (again) !

Anonymous said...

Nice blog you got here. I'd like to read something more about this matter.
By the way check the design I've made myself Young escorts

Green Parks said...

Hello.. Firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Green Parks Costa Rica in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.

Comprare Cialis Generico said...

Nice post! Thanks for sharing!

Frank said...

Hey,
Loving your blog, awesome tips on blog you have here. I
would just like to ask you some questions privately, mind real player 11,IDM Free Download,function venues geelong,la Fitness,Nokia Mobile Prices in Pakistan

Poker said...

Well written
"CICE/ARM prototype" blog article, well researched and useful for me in the future. I am so happy you took the time to make incredible Mark Mahieu's blog here. See you around
--------------------------
My site: Poker Money No Deposit Bonuses.

Poker said...

I really enjoy reading this one. Your have great insight about
"CICE/ARM prototype" of your post. Your online Mark Mahieu's blog is really excellent.
--------------------------
Free Sign up Bonus and Shark Poker and Latest poker bonuses.

Poker said...

I just leave a comment here coz I have read a lots of goodies that makes me feel interesting when the time comes I visit here great
"CICE/ARM prototype" post guys.
--------------------------
Visit me: Bonus sans depot & Poker sans depot 50

London Oriental Escorts said...

London Asian Escorts is an Asian and Oriental escort agency operating in Central London. The agency provides escort service for a true gentlemen. Our escort models are carefully selected and are genuine.

love supra said...

They are all beautiful and fashionable i have to say, and my friends told me they are of good quality as well. I have not see post good enough like yours here.
More tags:
wow gold | cheap wow gold | buy cheap wow gold | buy wow gold

china tours said...

Wow, wondeгful blog layout! It's really a nice and useful piece of info.You can learn more: China tour packages | China travel packages | China Travel Agency