3 ms·
> NO. Static typing doesn't help when speaking about inline caches for virtual calls (most method calls in a typical Java app) ... it only helps on the initial
by KirinDave 16y ago
> NO. Static typing doesn't help when speaking about inline caches for virtual calls (most method calls in a typical Java app) ... it only helps on the initial method lookup because you're dealing with a vtable instead of a hash (that's because at least you know the interface at compile-time).
Are you sure? I thought in certain conditions Java could dispense with the vtable lookup even in interpreted land. Not that it matters nearly so much there.
> But to do code-inlining and other such optimizations, the Hotspot JVM only compiles bytecode that has been profiled. That's because jitting itself is an expensive operation and you can't just redo it after you've inferred the conditions of a potential call-site cache, being more efficient to just first interpret that code until you have enough data.
So you're saying the Dalvik JIT does not do this? The reason I said "static typed compilation + JIT" was because, in my reading of the literature anyways, at jit time it could dispense with the vtable lookup if it's seen a stable type signature.
> I still think Java was a poor language choice for Dalvik precisely because methods in Java are implicitly virtual and because you can't have custom stack-allocated values. A language like C# would've been more suitable ... but since its their VM, maybe they'll provide an efficient alternative.
Please no. C# has, unsurprisingly, evolved into an absolute soup of a language. It's a crud-infested nightmare. The only thing saving me from absolute insanity these days is the slow migration to F#.
But really, since our comparison is to Objective C, where all calls are method dispatch which is a slightly more expensive than java calls, I don't think we're losing much. At best, Java is slightly faster. At worst, Java uses the same technique (or is interpreted, but again it doesn't seem to be losing that badly in this mode).
- bad_user 16y ago> thought in certain conditions Java could dispense with the vtable lookup even in interpreted land Not for calls to virtual methods, especially those call done through an interface ... you can't infer the right method to call at compile time when you don't know the object's real type. And in Java you can also load new classes that implement a certain interface at runtime ... and this also makes optimizations more difficult. Now of course ... for calls to static functions or for calls on methods marked as "final" Java can and does dispense of the vtable lookup. Unfortunately in Java methods are implicitly virtual, as you have to explicitly mark them as being final (for performance, although as far as language design for the stuff I do, I like it). > Please no. C# has, unsurprisingly, evolved into an absolute soup of a language I meant ... just as high level as Java, but with lower level capabilities here and there (where it matters). I don't think having your custom stack-allocated values or having pointers in "unsafe" portions of code (which really is a lot safer than doing JNI) is that big of a deal, and can help a lot in constrained environments.
- KirinDave 16y ago> Not for calls to virtual methods, especially those call done through an interface ... you can't infer the right method to call at compile time when you don't know the object's real type. Yes. I think we've actually been arguing the same point and just stating it differently. My original argument was that the Java way is actually always as fast and potentially faster than the ObjC way. Everything that works for ObjC works for Java, but java has semantics that allow for further optimization without breaking the required behavior of message passing. > I don't think having your custom stack-allocated values or having pointers in "unsafe" portions of code (which really is a lot safer than doing JNI) is that big of a deal, and can help a lot in constrained environments. I wonder. Most GCs are doing allocation that is only an instruction or three (I don't know what it'd look like on ARM) more overhead than incrementing the stack pointer. The CLR is somewhat famous for this. It is a bit of a bummer that you lose prescriptive-layout for structure types in java, though.
- bad_user 16y agoYeah, allocating / deallocating short-lived objects in Java has an almost zero cost (read about it in some article, can't remember which one). But that's not the point ... stack-allocated values help with mathematics, like boolean comparisons, matrix multiplication or just plain arithmetic, because otherwise you have to box/unbox those values. Software that relies on that (graphics / animations come to my mind, but not only) ... can take a big performance hit. And even if the GC is very efficient, you can still strangle it with many small objects, and sometimes those objects aren't deallocated fast enough. Stack allocation/deallocation is much more predictable for lots of small objects. But I think you already addressed this point.