News for hackers. Stuff that matters.
Re:An Opinionated Guide to Modern Java Development, Part 1 by mncolinlee on Thursday May 01, 2014 @01:53PM (#7681472)
Dalvik is being slowly replaced by ART (Android RunTime). Also, you can pretty easily hack Java 7 or even Java 8 into Android to use lambdas. Official, default support is coming soon.

http://tools.android.com/tech-docs/new-build-system/user-gui...

http://zserge.com/blog/android-lambda.html

Re:An Opinionated Guide to Modern Java Development, Part 1 by pjmlp on Thursday May 01, 2014 @02:03PM (#7681548)
Except those lambdas are not as efficient as the standard compliants VMs, as they make use of invokedynamic to generate better code, even inline calls for small lambdas.
Re:An Opinionated Guide to Modern Java Development, Part 1 by georgewfraser on Thursday May 01, 2014 @04:17PM (#7682471)
Are you sure about that? I've looked at the way invokedynamic generates lambdas, and it's just generating anonymous classes at runtime using ASM. Inlining is from the JIT and applies to anonymous classes as well. I'm pretty sure you can get the exact same results without invokedynamic, you just have a lot more .class files to distribute.
Re:An Opinionated Guide to Modern Java Development, Part 1 by sixbrx on Thursday May 01, 2014 @07:36PM (#7683320)
I think you got it right. According to Grzegorz Kossakowski's comment (which is more accurate than the misleading article) : http://www.takipiblog.com/2014/01/16/compiling-lambda-expres... , Java 8's lambda's aren't particularly efficient. They do create an anonymous class instance at runtime, as you say. Scala closures are implemented in a similar way, without invokedynamic, and as he says, and currently there is no performance win from invokedynamic's use in Java 8 vs the Scala impl. But it does hold promise of future optimizations, as he says:

"However, the key thing about invokedynamic is that it's essentially a JVM-level macro that defers lambda translation strategy to LambdaMetaFactory which is a library class. If Java 9 or 10 gets more direct (and performant) support for lambdas that won't require classes and object allocations then it can swap implementation of LambdaMetaFactory and all _existing_ code written for Java 8 will get performance boost. That is the brilliance of using invokedynamic in context of translating lambdas. We'll have to wait for future versions of Java to experience those benefits, though."

Re:An Opinionated Guide to Modern Java Development, Part 1 by spullara on Thursday May 01, 2014 @11:52PM (#7684047)
I don't think that person understands how it works at all.
Re:An Opinionated Guide to Modern Java Development, Part 1 by llemiengre on Friday May 02, 2014 @03:48AM (#7684539)
He knows what he is talking about & his description matches the explanation by Brian Goetz.

So unless I'm missing something, please be specific.

Re:An Opinionated Guide to Modern Java Development, Part 1 by spullara on Friday May 02, 2014 @11:44AM (#7686361)
Well, for one, Lambdas are desugared into methods, not anonymous classes. Early on they used anonymous classes because it was convenient but that wasn't the final translation strategy.

http://cr.openjdk.java.net/~briangoetz/lambda/lambda-transla...

Re:An Opinionated Guide to Modern Java Development, Part 1 by georgewfraser on Friday May 02, 2014 @12:53PM (#7686782)
My impression from the openjdk code is that each lambda generates:

1. A method in its parent class. 2. An invokedynamic instruction at the call site.

The invokedynamic instruction calls LambdaMetafactory, which compiles an anonymous class at runtime that calls method #1. So the only benefit of using invokedynamic is fewer class files, by deferring generating them until runtime.

Re:An Opinionated Guide to Modern Java Development, Part 1 by pron on Friday May 02, 2014 @01:41PM (#7687040)
Non-capturing lambdas also don't instantiate a new object at each call site. But this is also doable without invokedynamic.
Re:An Opinionated Guide to Modern Java Development, Part 1 by frowaway001 on Friday May 02, 2014 @12:46PM (#7686735)
Yes, and these methods create an anonymous class at runtime. What's so hard to understand about this?
Re:An Opinionated Guide to Modern Java Development, Part 1 by spullara on Friday May 02, 2014 @07:39PM (#7688805)
It was a misunderstanding on my part about where they were claiming the anonymous class was generated. Early versions of Lambda were nothing more than sugar on top of anonymous inner classes and the claim above sounded very similar to that. However, I see that inside the LambdaMetaFactory anonymous classes are generated based on the call site. Probably the biggest difference is that Java 8 can avoid an object allocation when the lambda doesn't capture. Not sure if Scala supports this but I'm sure that it could do it.
Re:An Opinionated Guide to Modern Java Development, Part 1 by pjmlp on Friday May 02, 2014 @02:49AM (#7684400)
Since I cannot edit my reply.

Have you checked this talk at Java ONE?

http://parleys.com/play/5251c164e4b0a43ac1212459/about

Some older slides also available

http://www.slideshare.net/jaxlondon2012/lambda-a-peek-under-...

Re:An Opinionated Guide to Modern Java Development, Part 1 by pjmlp on Thursday May 01, 2014 @07:04PM (#7683195)
I am basing my comment on the Java One talk about Java 8 lambdas implementation on the Oracle JVM.

I assume other certified JVMs would follow similar design approaches.

Re:An Opinionated Guide to Modern Java Development, Part 1 by nl on Thursday May 01, 2014 @07:25PM (#7683273)
But it allows people to move forward using the syntax itself.

The implementation can be optimised at any point.

Re:An Opinionated Guide to Modern Java Development, Part 1 by Groxx on Thursday May 01, 2014 @03:58PM (#7682357)
Which might be fixable with ART as it's an on-device ahead-of-time compiler (I think it optimizes too? can't find references...). I have no idea if it actually does work for this in practice or not, though.
Re:An Opinionated Guide to Modern Java Development, Part 1 by pjmlp on Thursday May 01, 2014 @04:09PM (#7682428)
True, but it won't help users with KitKat and lower devices. We all know that they won't see any vendor updates.
Re:An Opinionated Guide to Modern Java Development, Part 1 by Groxx on Thursday May 01, 2014 @06:39PM (#7683097)
Well sure. But people don't update their Java installs either, neither do all businesses. They're likely not going to be able to take advantage of v8 stuff. And can dumbphones on a Java platform (Symbian? Nokia? Others?) run the new Java flashiness? Every platform has problems like this.
Re:An Opinionated Guide to Modern Java Development, Part 1 by clumsysmurf on Friday May 02, 2014 @05:58AM (#7684818)
>> Official, default support is coming soon.

Default support of ART or Java 8?

If Java 8, how do you know this? Citation needed ;)

Re:An Opinionated Guide to Modern Java Development, Part 1 by mncolinlee on Friday May 02, 2014 @12:42PM (#7686706)
Java 8.

Arguing whether Java 8 will be completely supported or not ignores the nature of the Android API. Android doesn't even support 100% of Java 6 because it is not a desktop JDK and does not intend to replicate everything.

However, the Android team has actively been adding default support of Java 7 features piece by piece in recent months. They intend to handle Java 8 in the same manner. It's not clear which features will be supported in what version of Android, but lambdas are clearly a priority and can already be used today by early adopters using retrolambda.

http://stackoverflow.com/a/22303654/1412973