5 comments

  • dist-epoch 27 minutes ago

    Since being created, the Java pitch was "don't worry about low-level stuff like value/reference classes, a Sufficiently Smart Compiler will automatically pick the best option given your code and runtime profiling".

    What changed, why suddenly they adopt C++ features they explicitly excluded?

    https://wiki.c2.com/?SufficientlySmartCompiler

      debugnik 2 minutes ago

      Even a smart compiler can't break the program semantics, and without a closed world assumption it simply can't assume that an entirely different part of the program doesn't expect to observe object identity for a type.

      Java is adding small, orthogonal features that amount to the same feature set as value types, but can be cherry-picked into existing code for partial advantages without significant changes.

      tancop 15 minutes ago

      Java is so dynamic that it's impossible to prove a class will only be used in "value friendly" ways. When objects have no identity the meaning of `==` is different, and the compiler would have to do some kind of whole program analysis to find out if there is any way an instance of the class could ever be checked for equality.

      That's hard when you have type erasure and polymorphism and runtime class loading. And even if they pulled it off it would blow up compile times and be programmer unfriendly because adding one line could deoptimize an important class defined in another package. So they decided to bite the bullet and add a way to statically opt in for faster but incompatible behavior.

      mcculley 13 minutes ago

      It was not at all “suddenly”. The discussions about explicitly defining value types because escape analysis is insufficient have been going on for at least a decade.

      pestatije 9 minutes ago

      I don't think that was ever the case...value(primitive) types were there from day 1 and the given reason that it is too much overhead to use objects