News for hackers. Stuff that matters.
Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by mehrdadn on Monday December 18, 2017 @06:05PM (#15956292)
>> I heard so many times that JVM is much better than CLR, especially in the JIT area (Hotspot?).

> I wouldn't disagree with this

I would wholeheartedly disagree with this though. There's not even any way to write, say, a generic class (even one as simple as ArrayList<T>) and then let the user instantiate it with a primitive type like <int> in Java. To use generics in Java is to pay the speed penalty of an indirection for every single primitive type on top of the extra per-object bytes of space overhead. There's just no way Java is going to fix these problems without massive breaking changes in the type system or an extremely in-depth & expensive form of static analysis unlike anything I've seen in any real-world compiler.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by chrisseaton on Monday December 18, 2017 @06:18PM (#15956344)
You're not disagreeing with me, because we're talking about different things!

You're talking about Java, the language, I'm talking about the JVM, really HotSpot, really C2 actually, the implementation and the techniques it uses, whatever the language is, compared to the techniques that the .NET CLR uses.

The points you bring up are interesting though, because some of these complexities (which HotSpot isn't responsible for or in a position to change!) are as someone else has said, probably partly what has motivated the extra work in C2 compared to the .NET CLR JIT.

> To use generics in Java is to pay the speed penalty of an indirection for every single element on top of the extra per-object bytes of space overhead.

And this is just false - the extra indirection only applies for elements that are boxed primitives, not 'every single element'. There is no extra indirection for things that are references anyway.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by mehrdadn on Monday December 18, 2017 @06:56PM (#15956613)
> You're not disagreeing with me, because we're talking about different things! You're talking about Java, the language, I'm talking about the JVM, really HotSpot, really C2 actually, the implementation and the techniques it uses, whatever the language is, compared to the techniques that the .NET CLR uses.

No, we are disagreeing. I'm talking about how repercussions of decisions in the language affect the implementation. My comment was not at all limited to just the language itself. If you read my comment, you notice I mentioned fixing these issues would require changes in either the type system or an "expensive form of static analysis unlike anything I've seen in any real-world compiler". Because when the language dictates that there must be an indirection, the implementation can only remove it when it can prove that doing so would be transparent to the code, which is impossible to do in general and extremely difficult in practice. This is neither just about the language nor just about the implementation; it's about the consequences of language decisions in the implementation.

> the extra indirection only applies for elements that are boxed primitives

Yes, I just assumed since I had already mentioned primitives it was clear that I'm talking about the use of primitives in generics. But I'll edit it in to repeat myself.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by chrisseaton on Monday December 18, 2017 @07:07PM (#15956675)
> I'm talking talking about the repercussions of decisions in the language that affect the implementation

Well fine I welcome and respect your opinions on this topic, and you're not even wrong, but that's it's not remotely what anyone else is talking about in this thread!

We're talking about what the two main JIT compilers on the two teams have decided to implement, given the constraints they have from their input. We're not talking about how generics were implemented, or language design changes, because we're talking about how the JIT compilers work.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by mehrdadn on Monday December 18, 2017 @07:22PM (#15956740)
In that case, it seems we have a different metric for a JIT compiler being "better"? I was going by the quality of the final output, but you seem to be going by the complexity of the intermediate optimizations it goes through? Which I admit also makes sense, but it's not what I expected: when someone says "is X better than Y", the obvious implication is they should choose X over Y since it would yield a better result, and yet that generally wouldn't be the case here?
Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by chrisseaton on Monday December 18, 2017 @07:32PM (#15956792)
Think about it like this:

Two chefs.

Chef A gets really easy to use ingredients and produces a good dish with them.

Chef B gets rubbish ingredients but spends time doing amazing techniques with them anyway and produces a good dish as well, maybe even a bit better!

If this is all we know about the chefs, I'd say it looks like Chef B is the 'better' chef. It's not their fault they got worse ingredients, and they managed to do a great job with them.

You didn't need Chef B to handle Chef A's ingredients, because they were simple. Perhaps we should thank the supplier for that! But Chef B is still the 'better' chef.

It still might be nice if Chef A could do some of the amazing techniques that Chef B did, even though their ingredients mean they aren't required all of the time. They may help in some cases.

The .NET CLR JIT is Chef A, the JVM's HotSpot C2 JIT is Chef B.

I mean if we judge a JIT just by the quality of the output and don't consider the input, then reducing to absurdity an identity JIT for already-optimised machine code to the same machine code is the best JIT in the world. Clearly it isn't.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by mehrdadn on Monday December 18, 2017 @07:50PM (#15956884)
What you say would make sense in a hypothetical world where every JITter could work with every language, but that's not the world we live in. You can just hand chef B better-quality ingredients and have him do his thing, but you can't just hand HotSpot MSIL code and have it do its thing. Half of this is due to differences in the representations. The other half is because MSIL has features that (as far as I know; please correct me if I'm wrong) the JVM doesn't have, such as by-ref variables, which it would still need to support, but which might make optimizations such as escape analysis harder.

This is why people judge chefs independently from the ingredients they are given, but don't judge languages and implementations independently from each other. In the first case they are actually (mostly) independent in the real world, whereas in the second case they are frequently dependent on each other, and it is not possible to mix-and-match languages with compilers. (But I certainly do hope we get to a point where the latter would be possible, too.)

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by chrisseaton on Monday December 18, 2017 @07:59PM (#15956933)
Your points do make sense.

I would argue that it just isn't the case in practice that MSIL includes anything that would make optimisations that the JVM does significantly harder, but I only have my academic and professional experience working on both systems, nothing that I can cite or prove to you.

Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by macca321 on Tuesday December 19, 2017 @04:59AM (#15959074)
Is it not that Chef B doesn't have a frying pan (i.e. decent generics) so has to do a lot of tricks?
Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by matthewwarren on Tuesday December 19, 2017 @05:22AM (#15959170)
Thanks for this analogy, I love it!!
Re:A Look at the Internals of 'Tiered JIT Compilation' in .N... by srean on Tuesday December 19, 2017 @10:10AM (#15960707)
> If you read my comment,

That was not necessary.