Slashdot Mirror


Java's New G1 Collector Not For-Pay After All

An anonymous reader writes "As a follow-up to our previous discussion, Sun appears to have quietly edited the Java 6u14 release notes language to say now: 'G1 is available as early access in this release, please try it and give us feedback. Usage in production settings without a Java SE for Business support contract is not recommended.' So does this mean it was all one huge typo? Or was Oracle/Sun tentatively testing the waters to see the community's reaction? In either case it's nice to see Java's back on the right path."

171 comments

  1. Right path? by DoofusOfDeath · · Score: 5, Funny

    In either case it's nice to see Java's back on the right path.

    Did kdawson even read the article before writing the summary? I don't see anything in the article about Java becoming more like Haskell!

    1. Re:Right path? by Anonymous Coward · · Score: 0, Insightful

      s/becoming more like Haskell/being scrapped/

    2. Re:Right path? by DoofusOfDeath · · Score: 1

      I want to mod that post "+1 funny because it's so -1 insane."

      When will Taco finally implement complex-number mods???

    3. Re:Right path? by moosesocks · · Score: 1

      In either case it's nice to see Java's back on the right path.

      Did kdawson even read the article before writing the summary?

      You must be new here.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    4. Re:Right path? by LizardKing · · Score: 1

      I don't see anything in the article about Java becoming more like Haskell!

      Shurely you meant Scala?

  2. But it could be! by BadAnalogyGuy · · Score: 5, Insightful

    Garbage collection is an amazingly boring field of computer science. It's all about tracking references and trying to keep memory from filling up while also trying to keep the overall impact on the running system down. But as boring as it may be, it's also absolutely critical in today's interpreted languages.

    Where Java really fails is in the inability to trust the finalize method. At least in C++, the destructor of an object is guaranteed to be called as soon as the object is deleted. Java has no such guarantee, so expecting an object to clean itself up once it goes out of scope is a fool's errand. It will get finalized eventually, but the lack of deterministic behavior in this critical part of the object lifecycle means that there is a very big chance that unacceptable delays may occur in practice.

    Give me deterministic behavior over faster GC any day.

    1. Re:But it could be! by yacc143 · · Score: 4, Informative

      Deterministic behaviour => use reference counting. E.g. Python has it.

      But the situation with C++ is not as rosy as you paint it.

      E.g. there are no guarantee that destructors on static object will be called.
      Nor are destructors called on longjmp.

    2. Re:But it could be! by codewarren · · Score: 1

      use reference counting != deterministic behavior

      reference counting + any indirect circular reference == memory leak

    3. Re:But it could be! by siloko · · Score: 4, Funny

      Where Java really fails is in the inability to trust the finalize method. At least in C++, the destructor of an object is guaranteed to be called as soon as the object is deleted.

      Destructor!? Finalize!? Deleted!? You talking like a crazy man, have you never heard of a system REBOOT?

    4. Re:But it could be! by DoofusOfDeath · · Score: 1

      use reference counting != deterministic behavior

      reference counting + any indirect circular reference == memory leak

      I disagree. The timing of when deletion occurs is still deterministic in such a case. It's just harder for programmers to notice. That causes its own problems, but nondeterminism isn't one of them.

    5. Re:But it could be! by ebolaZaireRules · · Score: 1

      Hmm... I thought that even then you had to pass a VM arg to ask the GC to call finalize... ugh.
      I got that far and seriously thought about switching to C++ for mini projects

      --
      The Bible: Historically verifiable fact from an observers point of view
    6. Re:But it could be! by tepples · · Score: 2, Informative

      use reference counting != deterministic behavior

      reference counting + any indirect circular reference == memory leak

      hybrid GC with both reference counting and mark and sweep for cycle detection == closer to deterministic than what Java offers in the good case (no circular references) while still correct in the bad case (circular reference becoming detached from main())

    7. Re:But it could be! by bluefoxlucid · · Score: 2, Insightful

      Reference counters have cycle detection. See Objective-C.

    8. Re:But it could be! by Anonymous Coward · · Score: 1, Funny

      windows user?

    9. Re:But it could be! by bluefoxlucid · · Score: 0

      Destructors on static objects don't make sense. Static objects are not dynamically allocated and cannot thus be freed.

    10. Re:But it could be! by tepples · · Score: 4, Informative

      Nor are destructors called on longjmp.

      That's one reason why setjmp was deprecated in favor of try/catch and longjmp in favor of throw.

    11. Re:But it could be! by Captain+Spam · · Score: 2, Insightful

      use reference counting != deterministic behavior

      reference counting + any indirect circular reference == memory leak

      That sounds pretty deterministic to me. Indirect circular reference == memory leak, all the time. You can count on that.

      --
      Demanding constant attention will only lead to attention.
    12. Re:But it could be! by Unoriginal_Nickname · · Score: 1

      Give me deterministic behavior over faster GC any day.

      The thing is, there really is no middle ground. You need to use a mark-and-sweep algorithm to avoid leaking cyclic references, which means you have no way of determining if an object should or should not be destroyed if it leaves scope. The good news is that a modern generational garbage collector is optimized toward collecting younger objects, so it's fairly likely that your resource objects will be collected fairly soon after you're done using them. .NET provides a modicum of determinism with a bunch of syntactic sugar for a particular interface (IDisposable). It's not RAII, but C++ doesn't have heap compaction which is far more inconvenient than having to type out a finally block every time you open a file.

    13. Re:But it could be! by Late+Adopter · · Score: 3, Insightful

      Nor are destructors called on longjmp.

      For the love of God, man, use exceptions! That's what they're for!

    14. Re:But it could be! by Anonymous Coward · · Score: 1, Informative

      Objective C (cocoa/openstep) reference counting does not have cycle detection.

    15. Re:But it could be! by Anonymous Coward · · Score: 0

      To call a finalize on every object you create will cause you to have to have a reference to said object. This is the part of Java that I find nice is the ability to use objects with no reference like this:

        String s = new Date().toString();

      There is no reference to the Date object -- all I really wanted was the String output -- it cleans up the code nicely.

    16. Re:But it could be! by 0xdeadbeef · · Score: 1

      Ref-counted Objective-C does not do automatic cycle detection. Garbage collected Objective-C is not based on reference counting.

    17. Re:But it could be! by TheRealMindChild · · Score: 0

      No they aren't. Exceptions are exceptional. I wouldn't say calling a deconstructor is "exceptional" by anyone's standards

      --

      "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
    18. Re:But it could be! by Ethanol-fueled · · Score: 5, Informative

      What you just said makes no sense. The whole point of Java is that you don't have to mess with memory management. You've just admitted that you want to invest more time and complexity in building "mini-projects" by switching to C++. Good for learning, but otherwise practically silly if you're a noob, and you've implied that you are.

      As far as Java goes, ignore the command line for now. You don't need it to quickly build decent-performing applications.

    19. Re:But it could be! by owlstead · · Score: 1

      Amazingly boring? Jeez, there is a lot of ways of doing garbage collection. You can mix GC types, have multiple levels of GC, heap sizes to tweak for these levels etc. Java has got an upper limit to the amount of memory the process uses, but I can think of other schemes that dont. Then you can do a lot of multithreading stuff, but you cannot break code anytime, because in that case the whole VM can die unexpectedly. Then you have to choose when and how long to garbage collect, if you only do so if CPU utilization is high or low. Weak references and such can also play a role etc.

      If it's really boring to people they aren't trying hard enough.

    20. Re:But it could be! by ThePhilips · · Score: 1

      I find on Google mentions that Python which uses ref counting detects cycles.

      I doubt Apple would bother including GC in Mac OS X 10.5 + Objective C 2.0 if it didn't work properly. More than that, documentation on developer.apple.com says that (manual) reference counting isn't compatible with auto GC, meaning that it's not really ref counting based GC. It is clearly states that ref counting and GC are mutually exclusive. Provided that Core Foundation already provides quite rich set of memory management facilities, I personally do not even think that GC is all that important to Cocoa applications. It is a mere utility, provided for convenience, as new generation of developers apparently fail at resource management. (Do not tell me: I know that GC makes life easier. But unfortunately I also have witnessed many occurrences when it can make life harder.)

      --
      All hope abandon ye who enter here.
    21. Re:But it could be! by SecondaryOak · · Score: 0

      I disagree about the "boring" part. I took a university course on garbage collection (and a bit more, but that was the main topic) and it was absolutely fascinating. It was filled with a lot of interesting challenges - like how to handle multithreaded systems, how to avoid dirtying the cache, how to write incremental garbage collectors to prevent pauses, etc.

    22. Re:But it could be! by Anonymous Coward · · Score: 0

      What's boring to one person is of great interest to another. There are piles of interesting problems being tackled in developing garbage collectors - it's one of the areas in computer science that's actively evolving, and it's receptive to new ideas or approaches.

      Also - much of the Java language/libraries were designed with the hope that desctructors would go out of style. I'm not saying desctructors don't have their uses - a number of core classes have finalizers, proving their use. You can always write your code so that they aren't required, though. I have yet to encounter a problem where I've needed one - when I've come close, it's worked out just fine to perform clean-up with a weak reference queue.

    23. Re:But it could be! by ThePhilips · · Score: 1

      Probably you should RTFM, e.g. man atexit and man exit. Then on Linux compile a small program with static objects and run it under ltrace to see the truth of how it really works.

      I did once had the unpleasant experience - debugging monstrous C++ applications, ridden with static objects, which depending on temperature outside of window and direction of wind was sometimes crashing during start-up. And quite reliably crashing during shutdown. (Redundant exception throwing (as modern OO programmer like it) and infamous "singleton" of the design patterns' hall of shame - and you have the sure recipe for a disaster.)

      That's actually I personally never use static objects. Very few objects in a program have no dependencies. As soon as any static object has any external dependency or internal state which has to be persistent - forget about clean shutdown.

      --
      All hope abandon ye who enter here.
    24. Re:But it could be! by Late+Adopter · · Score: 2, Insightful

      In the normal flow of execution your code goes out of scope and objects inside are destroyed. The purpose of EXCEPTIONS are so that when you have exceptional behavior, all aborted scopes are still properly cleaned up with object destruction. Longjmp doesn't do that. Hence my comment.

    25. Re:But it could be! by mpsmps · · Score: 4, Informative

      there are no guarantee that destructors on static object will be called.

      Actually, Section 3.6.3p1 of the C++ standard guarantees it. (Wonder why people who can't validate technical language claims feel qualified to mod posts that make them).

    26. Re:But it could be! by SecondaryOak · · Score: 0

      The thing is, there really is no middle ground. You need to use a mark-and-sweep algorithm to avoid leaking cyclic references, which means you have no way of determining if an object should or should not be destroyed if it leaves scope.

      There are cycle-detection algorithms that do not require a full mark-and-sweep; they run a limited, local scan which can be immediately performed any time a reference is decreased to 1.

    27. Re:But it could be! by Anonymous Coward · · Score: 0

      Not really sure if you really need destructor calls, the only area i can see where it would make sense even in garbage collected environments is ressource cleanup like file closing, but on the other hand relying on destructors for file closing is an antipattern in itself!
      In c++ it just makes sense because you dont have garbage collection so introducing object counters etc... via destructors is heavens sent in those surroundings!

    28. Re:But it could be! by ebolaZaireRules · · Score: 1

      Fine...
      The jMonkeyEngine uses ODE (Open Dynamics Engine) as its rigid body physics implementation.
      Whenever a new level is loaded, the old one allows all its threads to run off, and is left to rot till the garbage collector gets round to it.

      The problem with this is that the memory from the physics engine is never freed, because finalize is never actually called by default.

      I thought about going through it properley, but who wants to spend all day going through someone elses code with a debugger to home to spend all evening going through someone elses code with a debugger... and all for a proof of concept game.

      --
      The Bible: Historically verifiable fact from an observers point of view
    29. Re:But it could be! by hibiki_r · · Score: 2, Informative

      I write in Java every day, but if my code was running on anything other than an application server that takes care of most of my non-memory resources, I'd be wishing for the equivalent of a destructor every week.

      It's not really about memory management though, but about resource management. Initialize your resources at object construction and release them at destruction is a very simple and elegant solution that is common on many C++ projects. In Java, we can't really do anything like that. We can't really encapsulate the resources without jumping through hoops.

    30. Re:But it could be! by Anonymous Coward · · Score: 0

      'exit' is a system call that you shouldn't be using if you expect to cleanup resources. Return from main and your statics will be cleaned as expected. Since 'exit' is not part of the standard, you can't blame C++ when it doesn't clean up your statics.

    31. Re:But it could be! by Anonymous Coward · · Score: 0

      Destructors/finalizers/etc are nearly never used in the course of design in languages that are built upon a framework that use a GC. Best practices have long accepted this fact; you close connections, free resources in the course of your application logic, rather than is being a passive act. Managing the tedium of your own garbage collection for most applications is a proven waste of time, this is why we arrived at GC. Clearly there will always be exceptions :)

    32. Re:But it could be! by Anonymous Coward · · Score: 0

      The problem with this is that the memory from the physics engine is never freed, because finalize is never actually called by default.

      WTF?

      finalize IS called by default.

      Finalize is NOT called when the memory is not reclaimed.

      Finalize does not "free memory". It frees OTHER SYSTEM RESOURCES that should be handled (in Java) by a finally block (hopefully Java 7 will make this a little better with ARM).

      physics engine is never freed

      And you know this how?
      Likely it either is freed, but not handed back to the OS (this is why javas "new" is quicker than C++s(1)) so the memory is System Monitor is never reduced or YOU HAVE A REFERENCE TO IT.

      YOU as in THE DEVELOPER that could be you or the developer of the API.

      Not Java fucking it (its GC works fine, if it did not someone other than you would have noticed it).

      1) Unless you make C++ work the same way by overriding how new & delete work.

    33. Re:But it could be! by 0xdeadbeef · · Score: 1, Insightful

      We can't really encapsulate the resources without jumping through hoops.

      Those hoops are the same hoops you're jumping through with destructors on C++. It only looks more elegant because the complexity has all been pushed into ensuring that all objects are properly destroyed when they need to be. You're doing the exact same thing using the dispose pattern in a GC'ed language, only it feels difficult because you're normally reliant on the collector, but there is a distinction between "resources" and "objects".

    34. Re:But it could be! by multi+io · · Score: 1

      I doubt Apple would bother including GC in Mac OS X 10.5 + Objective C 2.0 if it didn't work properly.

      Parent was talking about ref counting, not GC. Apple bothered including GC in the ObjC runtime exactly because the reference counting they had before that had cycle detection issues (and it was harder to program to). In the commonly used terminology, GC and ref counting are different things.

    35. Re:But it could be! by petermgreen · · Score: 1

      In C++ the pattern is fairly simple, every object must be cleaned up. For objects on the stack that is done automatically. For objects on the heap the programmer can either do it manually, have a single reference responsible for the lifetime of the object (auto_ptr) or use reference counting (shared_ptr).

      In java the pattern is a mess, you have to check the docs for every object to see if it needs to be disposed or not and if so you have to manage that disposal manually and of course if you change an object that previously did not require diposal to require it you have to go through ALL code that uses the object and work out how to add disposal code to it.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    36. Re:But it could be! by ThePhilips · · Score: 2, Insightful

      'exit' is a system call ...

      That was about where I stopped reading the comment.

      The modern "high-level" programmers who do not understand (nor bother to try to) how their own programs actually work, fit with the system and how system is used to implement language features deserve no pity.

      Go back to your Java cave.

      --
      All hope abandon ye who enter here.
    37. Re:But it could be! by tkinnun0 · · Score: 1

      Exactly, and it's because that neat little abstraction called close() includes "tell them my regards and then bid them adieu" and "oh, you're still here?" and everything in between. How could one automatic clean-up abstraction deal with all that nuance without butchering something or other.

    38. Re:But it could be! by shutdown+-p+now · · Score: 1

      No they aren't. Exceptions are exceptional.

      You use longjmp in "normal" situations?

    39. Re:But it could be! by againjj · · Score: 1

      Garbage collection is an amazingly boring field of computer science.

      And so is , unless it isn't. Any time some one says, "X is boring," or, "X is interesting," that really means, "X is boring TO ME," or, "X is interesting TO ME." "Boring" or "interesting" is opinion. Personally, I find GC rather interesting, in particular the latest advances in real-time GC. I did compiler/programming languages work for my M.S., and I believe that most people would think that it is boring as well, but it is not to me.

      It's all about tracking references

      There is a lot more than that.

    40. Re:But it could be! by shutdown+-p+now · · Score: 1

      hybrid GC with both reference counting and mark and sweep for cycle detection == closer to deterministic than what Java offers in the good case (no circular references) while still correct in the bad case (circular reference becoming detached from main())

      It still doesn't make sense in practice, because all bets are off. So long as there is any external references to your object, direct or indirect, you do not know whether it is a part of a cycle or not, and therefore cannot know whether its destruction will be deterministic or not. So you can't rely on it being deterministic in general.

      So reference counting doesn't really buy you much there. However, it does introduce a significant performance hit (this may sound surprising, but mark & sweep GCs actually get better average performance than reference-counting ones).

    41. Re:But it could be! by shutdown+-p+now · · Score: 2, Informative

      I find on Google mentions that Python which uses ref counting detects cycles.

      It does, though, as I understand, the behavior is the way it is mostly for backwards-compatibility purposes.

      Guido once made a list of things that he considers "implementation details" for Python, and not guarantees of the language spec - meaning that alternative Python implementations could deviate on those points from CPython. Reference counting is on that list, and e.g. Jython and IronPython do not use it at all, relying strictly on tracing GCs provided by their respective VMs.

    42. Re:But it could be! by ebuck · · Score: 1

      It it has cycle detection, then it's not "just" a reference counter. Probably it's a hybrid reference count / mark and sweep algorithm. The reference count lets you discard some of the objects quickly, while the mark and sweep lets you discard the circular references a little more slowly.

      Even if Objective-C does not use a hybrid reference count / mark and sweep algorithm, it doesn't use a pure reference counting solution. If it did, then it would only have the number of times something was referenced, which cannot tell you the topology of the references, in the general case.

    43. Re:But it could be! by recharged95 · · Score: 1
      For every article, opinion and comment that starts with:

      "Where Java really fails..."

      I add to my 'what-evar!' list, consider the rant it in my app design and continue programming my [insert ANY app here] in Netbeans (likelt the app that pays my mortgage).

      .

      Thanks for the [usual academic] opinion.

      On the flip side, Java says, separate implementation representation (i.e. low-level, on the metal, specific to vendor, dependencies, etc...) from logical representation (move robot arm 10 degrees). That forces you to design 'the' solution, not hack it. The rest (all the business jargon of Java), can go into the trash heap as its just a sales pitch. Can we all just get along and say Java has its place: not at the flight controller level, but somewhere between flight controller and web app and stop the "my language is flat out better than yours"?.

    44. Re:But it could be! by shutdown+-p+now · · Score: 3, Interesting

      Those hoops are the same hoops you're jumping through with destructors on C++. It only looks more elegant because the complexity has all been pushed into ensuring that all objects are properly destroyed when they need to be.

      It not only "looks more elegant", it is more elegant and concise, because for any given resource type, you write the cleanup code once, and then it is called automatically. With Java, you still write the code once (preferably implementing Closeable), but then you also have to call it manually all the time, resulting in a mess of nested try-finally calls:

      InputStream in = new FileInputStream("foo");
      try {
        OutputStream out = new FileOutputStream("bar");
        try {
      ...
        } finally {
          out.close();
        }
      } finally {
        in.close();
      }

      At least C# had the decency to provide syntactic sugar for this in form of using:

      using (Stream input = File.Open("foo"))
      using (Stream output = File.Create("bar"))
      {
      ...
      }

      But even that only deals with resources local to a method, not instance fields. And it still isn't automatic.

      Even so, this feature alone would make Java so much easier to deal with. I can't believe they decided not to add it to Java 7, especially when there was a sane proposal already, and the implementation is trivial. It's probably the single most convenient feature C# has over Java (considering how often it's used).

    45. Re:But it could be! by BadAnalogyGuy · · Score: 1

      Can we all just get along and say Java has its place: not at the flight controller level, but somewhere between flight controller and web app and stop the "my language is flat out better than yours"?

      Clearly you have missed the point of posting on Slashdot.

    46. Re:But it could be! by ADRA · · Score: 1

      I think you're looking at deterministic in a different way than I. I know that when there are no longer any references to an Object, that object is completely out of scope from my application. I don't care how the system I'm on cleans it up, the same way that 99% of the time, you don't care about what a free/delete/close really does behind the scenes. What does matter is that:
            1. The process of cleaning up this memory doesn't negatively impact the application's runtime performance
            2. 'Native'/OS resources outside of the code are released in a timely manner (Sockets, shared memory, etc..)

      Point 1 is addressed in several different GC's in Java. Most happy cases where fine grained timing is not mandatory have very little issue with one's code unless you're creating/destroying a LOT of objects in which case, object reuse would be more meaningful. Although it may not be perfect, I think Java does a pretty good job of mitigating the GC's interruption of an application.

      Point 2 is where the real problem of non-finalization occurs. If one doesn't explicitly release these resources when a programmer is done with them, you'll start getting error for too many open files, or this or that. In this case, it should be up to the developer to specifically deallocate these pieces of code. In any Input/Output steam for instance, a user must explicitly call close() to free up those OS resources that have been allocated for them (This is done on finalization as well if you don't explicitly call it). I don't care about the memory being used, since the GC magically takes care of that for me. What I do care about is that the files are released.

      Java does allow one to free these resources when you tell it to, so even though I could say its a non-issue, this brings up an interesting dilemma as a Java developer. If I expect that the GC takes care of everything behind the scenes, I may be coaxed into forgetting about this behaviour when I'm developing my code. Generally, an issue like this is either caught right away which is fine, or its caught much later in the development when the programs are being tested excessively, or when performing load testing, etc.. This just re-enforces how important it is to profile your code with a good profiler to see what's staying in use and what gets freed up. Most Java 'memory leaks' I've seen fall into the annoying but not game-breaking category, but you'll eventually see degradation in performance the longer the issue is left undetected.

      --
      Bye!
    47. Re:But it could be! by bonch · · Score: 1

      I can only speak from experience with Mac development, but Apple's Objective-C garbage collector runs on a second thread so that there is no delay, and in theory, a garbage collected application has a small speed advantage because there are no retain and release messages in accessor methods. Arguably, you shouldn't be relying on a destructor to do huge cleanup operations regardless of what memory management scheme you're using.

      Garbage collection is one of those things that, someday, the majority of programmers will use--if they don't already--and people will wonder how we managed without it. It's just obvious at this point.

    48. Re:But it could be! by ebuck · · Score: 1

      Some people discover that you can request a garbage collection cycle from within the main program. Basically it flags the GC thread to do another collection and the GC honors the request whenever it will.

      Nearly 99.999% of the time, the person who put such a call together is a ex-C++ programmer who's under the impression that this will help the garbage collector in some way. They are just so used to garbage collection being deterministically halting their program, that they think the "lazy" thread of the garbage collector needs woken up to do it's work. Often then they will conclusively say (in error), "See since I called the garbage collector the class I just dereferenced will be collected by this line and it's destructor listener called." Of course, they are wrong. The GC will just get a request, and it will wait until it's safe to run a full sweep.

      I is just not safe to write stateful code that depends on destruction. C++ was a little too close to malloc() and free() for people to think of doing it another way, but there is no guarantee that anything will ever be destructed before the program exits. I prefer Java NOT having destructors for this very reason. Without them, I tend to write more robust code because I can't assume that I can clean up after myself later, so I clean up after myself right then.

    49. Re:But it could be! by tepples · · Score: 1

      So long as there is any external references to your object, direct or indirect, you do not know whether it is a part of a cycle or not

      Is this a matter of your code holding references to your object, or other libraries holding references to your object?

      So reference counting doesn't really buy you much there. However, it does introduce a significant performance hit

      Then what is the right way in Java to automatically write whatever finally blocks need to be written, in the manner of Python's with statement?

    50. Re:But it could be! by ebuck · · Score: 1

      I know that you're anonymous, but you're brilliant.

      This "feature" of the language extends even more deeply than you know. If I call
      int age = Users.getByName("Bob").getAge();
      I don't need to worry about the implementation of "getByName()" in Java, where in C++ I would need to know a lot to use the class. Java might be returning a modifiable "User" object which is referenced by the whole application, or it might be returning a copy of a "User" object where modification would only allow the block of code to be affected.

      In C++ I would have to know whether "getByName()" returned a copy or a reference to a system-wide object, because if I don't destroy a copy, it's a memory leak. That means I would either have to rely on the documentation of the "getByName()" method in the header file, have access to (and read) the source code, or experiment via trial and error.

    51. Re:But it could be! by shutdown+-p+now · · Score: 2, Informative

      Is this a matter of your code holding references to your object, or other libraries holding references to your object?

      Other libraries. You may not have a cycle between objects you control, but as soon as you expose any single one of them outside, that one can become a part of a cycle (an external object that is in a cycle holds a reference to yours), and, by extension, all objects it references. At this point, when it will die, it will die on a GC thread, when GC frees the cycle.

      Then what is the right way in Java to automatically write whatever finally blocks need to be written, in the manner of Python's with statement?

      Python's with statement has nothing to do with reference counting at all. It's a much simpler strategy where the programmer explicitly defines the boundary at which the resource is to be freed, irrespective of how many references there are to it. C# has a similar construct, using, which behaves much the same except for name of method that is called on block exit (__leave__ in Python, Dispose in C#), and it doesn't use reference counting at all, for any purposes.

      Java actually had a bunch of proposals for a very similar thing (e.g. here is one from Google). However, none of them were accepted for Java 7 (fools...).

    52. Re:But it could be! by Raul+Acevedo · · Score: 1

      At least in C++, the destructor of an object is guaranteed to be called as soon as the object is deleted. Java has no such guarantee, so expecting an object to clean itself up once it goes out of scope is a fool's errand.

      So? I switched from C/C++ to Java over 10 years ago, and have not once needed to even consider implementing finalize. The only thing this "lack of deterministic behavior" really means in practice is that you have to explicitly close input/output streams, rather than let objects go out of scope and close their own resources in the finalize method. In other words, instead of calling delete, you call close. Outside of that, there is very little consequence.

      I'll take Java's current behavior just fine, thanks. I don't know of a real example where Java's non-deterministic behavior is an issue.

      --
      In a real emergency, we would have all fled in terror, and you would not have been notified.
    53. Re:But it could be! by Anonymous Coward · · Score: 0

      Arguably, you shouldn't be relying on a destructor to do huge cleanup operations regardless of what memory management scheme you're using.

      Arguably, you should eat shit and die.

    54. Re:But it could be! by Hi_2k · · Score: 1

      Generally, that should be obvious based on what it's returning; If it's returning a copy, it should return a static User object, if it's returning a the original it will be a pointer to it. That's also what the documentation is for, in the event that it is returning a reference to a copy it needs to make clear that it's the caller's job to destroy the object. In Java, you refer to that as an "implementation detail"; In C++, you generally realize that /you are the implementer/ and need to pay attention to details.

      --
      When life gives you crap, Make Crapade.
      Sluggy Freelance.
    55. Re:But it could be! by Anonymous Coward · · Score: 0

      Best practices have long accepted this fact; you close connections, free resources in the course of your application logic, rather than is being a passive act.

      Managing the tedium of your own garbage collection for most applications is a proven waste of time, this is why we arrived at GC.

      These two statements say the opposite of each other.

    56. Re:But it could be! by david_thornley · · Score: 2, Insightful

      Of course you don't implement finalize in Java. Since it may or may not get called, it's almost completely useless. The reason the non-deterministic behavior is not an issue is that it is assiduously avoided. What is an issue is the lack of a useful analog to finalize.

      However:

      In other words, instead of calling delete, you call close.

      I don't call delete in C++ programs, in general. I let smart pointers take care of all of it. This means that all my resources, including memory, are automatically managed for me in a uniform manner.

      This means that resource management is easier in C++ than in Java. As a C++ guy, I never have to worry about calling close or delete or anything like that. I don't have to worry about closing something too soon or too late. I don't have to worry about resource leaks, unless I do some odd things with the pointers.

      You, on the other hand, have to make sure you close things. You may use the try...finally idiom, which enforces a non-cohesive chunk of code with very high coupling. In resources that get passed around and used in multiple places, you have to figure out when to call close.

      In short, C++ started with a general solution for resource management, and extended it to memory management. Java picked off the easy case of memory management, and left everything else to the developer, without the tools C++ gives to manage resources.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    57. Re:But it could be! by Anonymous Coward · · Score: 0

      Not quite true

      void do_something
      {
              static std::string x;
      }

      as a static within a function, x's destructor will get called without doubt; this makes leak detection much easier. Static objects outside of functions have no such guarantee.

    58. Re:But it could be! by SplashMyBandit · · Score: 1

      If more than one thread has a reference to an object then you are out of deterministic country - it is multi-threading support that makes things complicated.

    59. Re:But it could be! by Frnknstn · · Score: 1

      More than that; the GP is talking about a bug. If your program has a circular reference that you don't know about, it's a bug. That reduces his earlier statement to:

      use reference counting + buggy code != deterministic behavior

      and further to

      buggy code != deterministic behavior

      which is a lot less insightful that the GP hoped.

      --
      If it's in you sig, it's in your post.
    60. Re:But it could be! by Tacvek · · Score: 1

      indeed. _Exit(int) is a system call. exit() is part of the standard library. I quote from ISO/IEC 14882:2003:

      A return statement in main has the effect of leaving the main function (destroying any objects with automatic
      storage duration) and calling exit with the return value as the argument. If control reaches the end
      of main without encountering a return statement, the effect is that of executing
      return 0;

      Now, exit(int) does not clean up remaining automatics in the current scope (i.e. variables on the stack will not be cleaned up), but otherwise exit(int) and returning from main are identical.

      --
      Stylish sheet to fix many problems in Slashdot's D3: https://gist.github.com/801524
    61. Re:But it could be! by Raul+Acevedo · · Score: 1

      I'm not familiar with smart pointers; I can't tell (or remember) if they were always possible or if they were a language feature added since I last coded C++ in the mid-90s.

      They do seem cool and a better solution for this problem. But it seems you are still stuck with implementing them yourself, in which case you are in [almost] the same situation as in Java. I.e. in C++ you have to write custom code (e.g. smart pointers) to do the resource freeing automatically; but in Java you can do the same thing by writing a wrapper class that closes objects automatically after issuing whatever read/write-type operation you are performing. Either way you are writing custom code, which in either language isn't all that different.

      Conceptually smart pointers sound cleaner anyway. But then don't you have to worry about implementing all the semantics of smart pointers? It doesn't look trivial, and the elimination of all this pointer mess is one of the godsends of Java.

      --
      In a real emergency, we would have all fled in terror, and you would not have been notified.
    62. Re:But it could be! by david_thornley · · Score: 2, Informative

      Smart pointers, as something you can just use, were introduced in Boost several years ago, and are in the standard now via Technical Report 1. In the mid-90s, they were possible (given template support, which was not universally good at the time), but not widespread.

      Nor do I roll my own. I write the destructors, of course, and then I just use smart_ptr instead of * (okay, a bit more syntax difference than that). By now, it's not custom code.

      So, in about 2000 the Java approach was generally better. Smart pointers weren't really available then for C++, and Java programmers at least didn't have to worry about memory management. Nowadays, I consider the C++ solution to be superior, since it's more general.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    63. Re:But it could be! by countach · · Score: 1

      I don't find it boring, but then I am geeky.

    64. Re:But it could be! by countach · · Score: 1

      Smart pointers are an essentially reference counting solution, with all its pitfalls. I don't doubt it works in 90% of scenarios, but when things get really complicated, things can get hairy.

    65. Re:But it could be! by abdulla · · Score: 1

      There are also situations that force your hand. If you're using a C library, and you provide it callbacks, if the library wasn't compiled with exception handling support (very rare for C libraries to be on Linux), then you're out of luck. If you throw an exception your whole program fails, you have to longjmp() to a safe point inside your C++ code from where you can throw. I find I have this happen a lot with image libraries, e.g.: libpng and libjpeg.

      Best solution is to have all your objects set up before your setjmp(), then when you longjmp() back and throw, your objects should be cleanly deallocated.

    66. Re:But it could be! by maraist · · Score: 1

      Wow, I've done a lot of Java development and have never had a need for a finalizer. So while you may have a niche need in your C++/Java work, you certainly don't represent a majority of use-cases, and thus I can disregard your claim of Java's failure. There are many many other programming paradigms for resource cleanups. try-catch-finally (or better yet, pass a runnable to try-catch-finally processor to guarantee consistent resource-management). One particularly elegant form is Thread-Local Transactions (if your use-case can support them). The medium-weight spring-library provides a slew of these resource-safe 'executors', though they're really just simple convenience utilities where you could roll your own. Basically any resource that you want guarantees that you won't accidentally leave open, explicitly register with some framework that at some exit-point, items will be cleaned-up. (In a transaction model, this is the post-end-transaction phase - called after rollback or commit, and whether or not you are exiting with an exception).

      --
      -Michael
    67. Re:But it could be! by maraist · · Score: 1

      "The reference count lets you discard some of the objects quickly, while the mark and sweep lets you discard the circular references a little more slowly."

      'quickly' is debatable if you have a linked list. exiting a ref-count bounded function (or some other scope) could take 60+ seconds if you'd slowly accumulated millions of tree or linked-list nodes (I speak from experience in a perl world). In a copying collector GC, exiting a function is always instantaneous, and in fact, the vacuming of massive transient linked-lists/trees is exactly what copying collectors are good at (as they don't require any work at all). In both cases, allocating new memory might require some jiggering. In arena based ref-counted allocators (used in perl, again not familiar w/ Python's memory internals), if a free arena of a desired size doesn't exist, you search for larger arenas to segment into your desired arena size (thereby fragmenting memory). Over time your arenas get fragmented and thus you have to do some coallesing (either at allocation time or at freeing-time), and depending on tolerances/heuristics (if any) you could trigger wasteful thrashing (lots of memory book-keeping that's continuously never used). You could just use a buddy system allocator, but then you'd have a crap-load of wasted memory (unusable slack-space) in various use cases. Now in GC, you also have a lot of bookkeeping overhead (when doing an eventually necessary mark-and-sweep), but the copying-collector portion is pretty damn fast (especially with allocations, theoretically only requires 2 CPU instructions), and even when you don't have a lot of transient memory. The throughput is certainly better with copying collector + occasional mark+sweep, but your pause times may be unacceptible, and of course, you don't get time-guarantees on finalizers (as a mark+sweep may NEVER happen if you have too much transient memory - ironically the desired case).

      Now I'm not sure how python's hybrid works (I know that perl does a full reference traversal at perl-exit time to trigger all finalizers, obviously that's a radically different algorithm), but one thing it MIGHT do is not traverse reference chains on a ref-decriment == 0, and leave the rest up to the GC. That might give the best of both worlds. Large direct-referenced handles are freed immediately (even if dozens of such references exist), but those ref'd 2 or more indirections deep must wait for a mark+sweep.

      --
      -Michael
    68. Re:But it could be! by maraist · · Score: 1

      I think the more appropriate response is that a finalizer will eventually get called in any ref-counted system (even those that don't properly handle cycles), but the finalizer WANTED to be called at some scope-exit point, but due to the [possibly unforeseen] cycle, must instead wait for some secondary cleanup code which is non-determistically triggered. In a ref-count + mark+sweep hybrid it likely happens when an allocator says memory is too fragmented and thus does a mark+sweep prior to any sbrk calls, in perl it's just before exiting. And more importantly you may have code which relies on a finalizer BUT you can't guarantee that some external code won't INJECT a cycle into your critical region. This is VERY possible in such dynamic languages as perl/python, as your code can easily be mutated on the fly (and thus have undesirable external references to your critical regions).

      Thus NO code can have guaranteed deterministic finalizers that have such limitations.

      --
      -Michael
    69. Re:But it could be! by afsina · · Score: 1

      They will add automatic resource management in Java 7. Check project coin. http://openjdk.java.net/projects/coin/

    70. Re:But it could be! by shutdown+-p+now · · Score: 1

      Where does it say on the page that ARM is accepted (I've no doubt that it was submitted)? I don't see it on the tentative list of changes here, and it's not in top 3 in the poll.

      Last thing I heard on the subject was Mark Reinhold's update on the status of Java 7 dating back to December last year - and it doesn't list ARM. But I must admit that it may well be outdated (since the project you've linked to came later), so what's the current definite status, and where to keep track of it?

    71. Re:But it could be! by afsina · · Score: 1

      it has been vigorously discussed in project coin list. and it most likely to be included in the Java 7. Along with collection literals. there is a javaone presentation about language changes. http://blogs.sun.com/darcy/resource/JavaOne/J1_2009-TS-4060.pdf

    72. Re:But it could be! by afsina · · Score: 1

      i suggest reading the mailing lists of "project coin". it was very nice to read the proposals and how they have changed or rejected. http://mail.openjdk.java.net/pipermail/coin-dev/

    73. Re:But it could be! by shutdown+-p+now · · Score: 1

      Good stuff, thank you. I'm glad to see ARM blocks made it in - it really makes a lot of difference. Still a pity they decided not to do lambdas (I understand how major a change that is, but it is really worth it, IMO).

    74. Re:But it could be! by vikstar · · Score: 1

      but then you also have to call it manually all the time, resulting in a mess of nested try-finally calls

      Try (no pun indended) this.

      --
      The question of whether a computer can think is no more interesting than the question of whether a submarine can swim.
    75. Re:But it could be! by badkarmadayaccount · · Score: 1

      == is a comparison operator in most languages. Just = might be ambiguous, so to be clear that you are assigning, use Pascal's :=. But, please God, don't use comparison operators.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    76. Re:But it could be! by Anonymous Coward · · Score: 0

      Your Java Code doesnt work, close() throws IOException and must be in try, not in Finally

    77. Re:But it could be! by shutdown+-p+now · · Score: 1

      close() must be in finally because we want to close the stream no matter how control flow leaves the try-block - whether normally or via an exception. The fact that close() itself can throw an exception is irrelevant here (though the fact that it throws is a very silly design decision by itself, because cleanup operations shouldn't throw exceptions - see the no-exceptions-in-destructors rule in C++ - otherwise you cannot be guaranteed proper cleanup of anything).

  3. Well.... by samriel · · Score: 4, Insightful

    I think this means that, if you use the new GC in a production setting and it clobbers some mission-critical piece of data, they would really like you to have some support contract with them, rather than never using G1 or Java again. It is 'early release' after all.

    1. Re:Well.... by Anonymous Coward · · Score: 0, Funny

      Well, that missing "/" in the italics tab clobbered your post, Sam.

    2. Re:Well.... by Rosco+P.+Coltrane · · Score: 1

      Contracts for garbage collection eh? I knew Sun was in cahoots with the mafia. Just ask these guys if they don't wish they had stuck with the old Java...

      --
      "A door is what a dog is perpetually on the wrong side of" - Ogden Nash
    3. Re:Well.... by ebuck · · Score: 1

      Next thing you know, they'll be asking for memory protection money.

  4. Not quietly by RPoet · · Score: 5, Informative

    Sun didn't "quietly edit" the release notes; they announced it publicly and appologized for having been unclear (which seems like a bit dishonest, but not quiet).

    --
    "Oppression and harassment is a small price to pay to live in the land of the free." -- Montgomery Burns.
    1. Re:Not quietly by Joehonkie · · Score: 3, Insightful

      What you said here. People were so buy foaming at the mouth that they never bothered to read the actual article or the thousands of posts that spelled out pretty clearly how and why the slashdot story got it wrong.

    2. Re:Not quietly by causality · · Score: 4, Funny

      What you said here. People were so buy foaming at the mouth that they never bothered to read the actual article or the thousands of posts that spelled out pretty clearly how and why the slashdot story got it wrong.

      Never seen that before. No, not ever.

      It's funny when you can cut+paste your comment and drop it into multiple discussions without having to modify it. It is truly one-size-fits-all.

      "Stop. Look. Listen, learn, read, think .. SHUT THE FUCK UP!" - Bill Hicks

      --
      It is a miracle that curiosity survives formal education. - Einstein
    3. Re:Not quietly by harryandthehenderson · · Score: 1

      People were so buy foaming at the mouth that they never bothered to read the actual article

      But but but! Oracle is eviiiiiiiiiiiil! Who cares what the truth was? Did you know that Oracle was eviiiiiiiiiiiiiiiiiiiiiiiil!

    4. Re:Not quietly by Anonymous Coward · · Score: 0

      Ah, but they did read the article. The exact quote from the old release notes is:

      Although G1 is available for use in this release, note that production use of G1 is only permitted where a Java support contract has been purchased.

      Regardless of what the license says, that seems pretty clear to me: if you want to use G1 commercially, you gotta pay.

      Just because it wasn't true, doesn't mean that Sun didn't say that it was.

    5. Re:Not quietly by Anonymous Coward · · Score: 0

      Zealot! Slashdot is never wrong! Recant!

    6. Re:Not quietly by Anonymous Coward · · Score: 0

      Did the text go through Oracle first so they could throw some sticks into the mud?

    7. Re:Not quietly by BikeHelmet · · Score: 2, Insightful

      Sun didn't "quietly edit" the release notes; they announced it [sun.com] publicly and appologized for having been unclear (which seems like a bit dishonest, but not quiet).

      It was established in the prior slashdot post ranting about it that it was just headline mongering. Nobody commenting had trouble understanding the true meaning.

      But as usual, anything Java is SLOW, EVIL, BAD and out to steal your monies!

  5. Slashdot editors don't read slashdot? by argent · · Score: 5, Informative

    This is not a change, it was clear in the previous thread that the article was completely misinterpreted. The Slashdot summary made no sense at all once it was pointed out that G1 was GPL+Classpath.

    1. Re:Slashdot editors don't read slashdot? by harryandthehenderson · · Score: 1

      Well when did ScuttleMonkey ever actually read, or even comprehend, the articles he posts?

    2. Re:Slashdot editors don't read slashdot? by Anonymous Coward · · Score: 0

      Since when did ANYONE on Slashdot ever actually read, or even comprehend, the articles they posted?

    3. Re:Slashdot editors don't read slashdot? by harryandthehenderson · · Score: 1

      True. I seems like poor English grammar skills and reading comprehension are requirements for becoming a Slashdot editor.

    4. Re:Slashdot editors don't read slashdot? by Reality+Master+201 · · Score: 1

      Or a reader. I wonder how this correlation relates to causation.

    5. Re:Slashdot editors don't read slashdot? by nystire · · Score: 1

      One must be a reader before one becomes an editor...

    6. Re:Slashdot editors don't read slashdot? by slack_justyb · · Score: 1

      Ah yes, but Slashdot suspends all logic. Therefore, one must be an editor, before one becomes a reader, before one becomes an editor, before one becomes a reader... aka, randomly hit a submit button (no one cares just hit any submit button!)

      Great fun!

  6. Probablly just a misunderstanding by petermgreen · · Score: 4, Insightful

    I would guess a developer said something vauge like "don't use this in production without a support contract" and it got misunderstood by the person writing the release notes. If they really wanted to forbid it I'd expect them to be competant enough to do that in the license.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    1. Re:Probablly just a misunderstanding by ebuck · · Score: 1

      I tend to agree. If they really wanted a pay-to-use-this garbage collector, then they would have made the garbage collector a upgrade or add-on to the existing JVM and not distributed it in it's fully functional form for free.

      Fully functional software tends to get used, and Oracle is not such a newbie to think that a piece of paper (or an electronic equivalent of that) will block use of a revenue generating item all by itself. Nor are they interested in auditing and suing everyone who might have a production environment that uses Java. Those kinds of tactics are only reserved for companies that have no other viable business model.

  7. No Way! by Anonymous Coward · · Score: 5, Funny

    A kdawson article that totally blew something out of proportion? What a shock!

    1. Re:No Way! by harryandthehenderson · · Score: 3, Informative

      Actually the original article was posted by ScuttleMonkey, but both are masters at spreading misleading, FUD-filled articles.

    2. Re:No Way! by Anonymous Coward · · Score: 0

      An Anonymous Coward post that totally blamed the wrong incompetent Slashdot editor? What a shock!

  8. Was this ever an issue? by Lemming+Mark · · Score: 4, Insightful

    Argh, so I'm turning into the kind of person who comments without reading *either* article in question but ...

    Last time this came up, plenty of people pointed out that the G1 garbage collector was available to anyone, Open Source but that it was in development and you weren't recommended to use it in production without a support contract. A number of people even pointed out the settings that anybody could change to enable the experimental G1 garbage collector on their own system.

    Perhaps this is case of adjusting their wording to make it easier for Slashdot to not report incorrectly ;-)

  9. Stop spreading FUD by harryandthehenderson · · Score: 5, Insightful

    So does this mean it was all one huge typo? Or was Oracle/Sun tentatively testing the waters to see the community's reaction? In either case it's nice to see Java's back on the right path."

    No, it means that the original article was a misleading pile of FUD since the G1 garbage collector was released GPL + Classpath exception from the beginning. It's amusing that after being pointed out that the original submission was misleading and wrong that instead of this being a retraction that this article still tries to implicitly claim that Sun or Oracle did something wrong.

    1. Re:Stop spreading FUD by Anonymous Coward · · Score: 0

      please mod this up.

      which czar does our dear leader have running slashdot??

  10. Popular Java Myths by javacowboy · · Score: 4, Informative

    1) Java is slow
    2) Java is not yet open source (or only parts of it are or isn't "really" open source)
    3) Java is not available in any Linux distro's package manager
    4) Java does not meet the needs of the enterprise
    5) Nobody uses Java anymore
    6) "Java is a heavyweight ball and chain"
    7) Sun is charging people to use the new G1 garbage collector.

    Java has some weaknesses and disadvantages, but the above are not among them.

    --
    This space left intentionally blank.
    1. Re:Popular Java Myths by owlstead · · Score: 3, Insightful

      1) Java is slow.

      I'm generally a Java advocate, but you have to take into accounts when Java *is* slow. This is mostly where Java has to get down to the nitty gritty of the bare metal. Examples are cryptography (lots and lots of low level operations on bytes, 32 and 64 bit words) and processor based instructions. In those cases it makes sense to use a well defined C library (avoiding C++ if possible) and interface with that. These are also the places where it makes sense to really optimize the hell out of an application or library.

      But for general business logic this arguement is indeed long gone. I do believe that my Java applications are normally faster than their C++ counterparts for the simple reason that I've got more time to design my classes well. Even if it's slower then it's offset by the much lower maintainance cost. And it's way faster than most specialized languages. Then again, specialized languages can make sense if they are delivering lower maintainance cost. Lets just say that not choosing Java because is it slower *per se* is absolutely wrong.

    2. Re:Popular Java Myths by slack_justyb · · Score: 1

      You forgot

      8) Java for web pages = JavaScript (or vice versa)

      I'm sure there is more.

    3. Re:Popular Java Myths by petermgreen · · Score: 1

      1) Java is slow
      Semi-true, java is what you get when you take a language that is slow by design and optimise the hell out of it. Overall perforamnce is reasonable but not brilliant (shootout.alioth.debian.org places it at arround 1.5 to 2 times slower than C). Predictability of performance can be a problem though because instanciating a new class can mess with the inheritance tree and hence the performance of seemingly unrelated code.

      2) Java is not yet open source (or only parts of it are or isn't "really" open source)
      The truth or falseness of this depends on what you consider to be part of java. There is an open-source version and it can pass the platform compatibility tests but it's not entirely the same code as the binary releases and IIRC it lacks implementations of some optional parts of the platform. Also only a limited selection of CPU and OS ports were released. Also last I checked the source for the official java plugin was missing (there are third party ones though I dunno what thier compatibility is like currently).

      3) Java is not available in any Linux distro's package manager
      It is now but this is a fairly recent change. It only made it into debian lenny by the skin of it's teeth.

      6) "Java is a heavyweight ball and chain"
      Semi-true, java is a huge platform that makes it difficult to interact with code written in other languages though there is now a third party library (jna) to make it easier.

      7) Sun is charging people to use the new G1 garbage collector.
      Well that is what thier release notes originaly said though I don't think it was backed up by any statements in a license.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    4. Re:Popular Java Myths by againjj · · Score: 2, Insightful

      In other words, Java is not one-size-fits-all, and all languages have tradeoffs.

    5. Re:Popular Java Myths by shutdown+-p+now · · Score: 1

      I'm generally a Java advocate, but you have to take into accounts when Java *is* slow. This is mostly where Java has to get down to the nitty gritty of the bare metal. Examples are cryptography (lots and lots of low level operations on bytes, 32 and 64 bit words) and processor based instructions.

      It's surprising. Why would operations on bytes (or machine words) in Java be any slower than in C? After all, the JIT will compile them to the same stuff as a C compiler would do, and Java HotSpot is widely recognized as the most sophisticated JIT in production out there.

      So far as I know, most of Java slowness doesn't actually come from bit twiddling being slow. It's because of things like all calls being virtual by default, and all objects being allocated on heap and not stack by default (yes, I know Java heap allocation is much cheaper than C heap allocation; but you still can't beat allocating a single stack frame on entry; and you also get aliasing optimization problems with all the references).

    6. Re:Popular Java Myths by ADRA · · Score: 1

      Things like Cryptography and Compression which are process intensive are already implemented in native hooks in the base JVM. For instance, if you're using a GZIPOutputStream to GnuZip compress your data, the actually compression is done in a native block. Just because -a part- of your code requires high thoughtput, it doesn't mean that the entire piece of code needs to be developed in said language. Think of it like the distinction between C and ASM. You'd never write your entire code in assembly anymore, but there are some algorithms/loops that you'll do a better job of optimizing by using assembly instead of your general purpose C compiler.

      --
      Bye!
    7. Re:Popular Java Myths by fluffykitty1234 · · Score: 1

      As far as I can tell neither the compiler nor the JIT do even the most rudimentary of optimizations, like CSE elimination, dead code elmination, loop unrolling, inlining, etc.

      Just write 1 function that spins in a loop doing something like:

      for(i=0; i 100000; ++i) { a = 5; }

      The Java compiler is a joke, if they even made a little effort Java could be so much faster.

    8. Re:Popular Java Myths by fluffykitty1234 · · Score: 1

      That's wonderful _if_ the Java library provides exactly what I need. If I want to do something somewhat non-standard then writing my custom thing in Java is going to be slow. If I have to break out into C anyhow to be fast, I might as well just write in C to begin with.

    9. Re:Popular Java Myths by shutdown+-p+now · · Score: 1

      As far as I can tell neither the compiler nor the JIT do even the most rudimentary of optimizations, like CSE elimination, dead code elmination, loop unrolling, inlining, etc.

      Java compiler doesn't do it because JIT should do it. And how can you tell if JIT does it or not?

      Just write 1 function that spins in a loop doing something like:

      for(i=0; i 100000; ++i) { a = 5; }

      Yes, and then what? How did you test if it did any optimizations when JITting?

      I must admit I do not know the nitty gritty of Java JIT, but I've seen what .NET JIT can do, and it certainly does all optimizations you've listed - I observed dead code elimination, loop unrolling and inlining firsthand. With .NET it's easy because Visual Studio debugger lets you switch to disassembly mode even when debugging .NET apps, and then you see the actual native code that is running.

    10. Re:Popular Java Myths by fluffykitty1234 · · Score: 1

      I just run it and time it using the time command. Since this loop doesn't actually do anything, the optimizer should optimize it away, but it doesn't.

    11. Re:Popular Java Myths by shutdown+-p+now · · Score: 1

      If you time the execution of the whole "java Foo.class", then you're actually timing the startup time of JVM, class loading, and JITting. You'll need to raise the number of iterations much higher to see the difference. Or just use a long counter, and do Long.MAX_VALUE iterations - it'll hang if the loop is not optimized out, but won't if it is.

      Also, if you want to time how long the loop itself takes, you'll have to do the measurements from within the running Java program:

      long start = System.nanoTime();
      for(i=0; i 100000; ++i) { a = 5; }
      long end = System.nanoTime();
      long time = end - start;

    12. Re:Popular Java Myths by BikeHelmet · · Score: 1

      for(i=0; i 100000; ++i) { a = 5; }

      It handles that fine. (with the < added)

      I did it to a million, and stuck it in another loop to a million, inside another loop to a million.

      It finished in 0 milliseconds, according to the horrible precision timer.

      Maybe something is wrong with your configuration. I've found Java to be far smarter than C++ compilers when it comes to optimizations when the -server flag is enabled.

    13. Re:Popular Java Myths by countach · · Score: 1

      I would hardly call Java slow by design. TCL or Bourne shell would be slow by design. It seems like C programmers, and C-like language programmers think everything except C and its ilk to be "slow by design".

  11. One huge typo? by toby · · Score: 1

    Well, the keys are right next to each other...

    By the way, the research paper describing G1 is here.

    --
    you had me at #!
  12. Buddy heap by tepples · · Score: 1

    C++ doesn't have heap compaction

    There are ways around this, such as the buddy heap and the Windows XP low-fragmentation heap, which round sizes up to a power of 2 and keep similarly-sized allocations together.

    1. Re:Buddy heap by owlstead · · Score: 1

      With C++ there is always a way to get (around) a feature. The trick is to let these tricks play nice with the rest of your pogram including the used libraries and different runtime environments.

    2. Re:Buddy heap by tepples · · Score: 1

      The trick is to let these tricks play nice with the rest of your [program] including the used libraries and different runtime environments.

      That's an issue with any std::malloc replacement, but this page claims that Firefox manages to work around it.

  13. Java doesn't fail by beldraen · · Score: 4, Informative

    The reason why you are confused is because you're used to a compiled environment, where every call is an immediate action. A C/C++ program must be coded to (i.e. explicitly) deletes memory references. If you explicitly delete, you can also tie in other explicit behavior; therefore, it's common "duh this is how you do it" practice to tie "finalize" behavior to the object's deletion. But remember, it is your program's logic that has decided when to get rid of it. In a GC environment, deletion is no longer an explicit event--it is autonomous, automatic; therefore, it is illogical to tie anything to the deletion of the memory reference to anything other than deletion of the memory reference. There is no connection between when the object was dereferenced and when the GC chooses to clean up the reference. Generally, the only events that are tied to the finalize method are sanity checks to make sure non-Java code knows the reference is going away. Put differently: in Java, memory deallocation is not a part of the running logic of your program and so the program must create an explicit method of releasing resources in your program's logic. In other words, do what you were doing before, just don't call it finalize. That's a gripe of mine about Java: It confuses C++ users who are used to using the function finalize because Java gives finalize a specific purpose that cannot act the same way.

    --
    Bel, the mostly sane.. "Of course I can't see anything! I'm standing on the shoulders of idiots." -- Me
    1. Re:Java doesn't fail by hibiki_r · · Score: 1

      But in C++, many programs don't really deal with resource deallocation directly: That's what reference counting pointers are for. The resources get wiped the moment nothing references them anymore, and we can release both memory and connections at the exact moment they are not used anymore. In Java, just as you said, we end up doing it explicitly, doing a lot more work by hand, and risking destroying a resource that someone still has a reference to.

      Sure, the code can still work, but it's a lot harder to get that done than to just let the destructors do their job when the reference counter reaches 0.

    2. Re:Java doesn't fail by deepestblue · · Score: 2, Insightful

      If you're coding in lots of explicit memory reference deletes, what you're writing is not C++ but C. A C++ codebase would use RRID and automatic memory management to obviate the need for any explicit memory management. My last C++ project at work contained zero (yes, zero) calls to delete/free() out of around 20000 lines of code and a year of development/testing.

      You're making the same mistake you're accusing C++ developers of making - you're viewing C++ through Java lenses.

    3. Re:Java doesn't fail by skeeto · · Score: 1

      This means that a resource, other than memory, can't be tied completely to an object. Anything using the object has to handle the resource manually, like basic C++ memory management, breaking the abstraction.

      For example, I might want to tie, say, a database to an object. I create the object which opens/creates a database. I then use the object normally, and it makes transactions with the database as needed, but since finalize() is not reliable I have to explicitly call a close() method before I let the object fall out of scope if I want to keep the database synced up and tidy. And I can't call close() too soon or something else using the object will have a problem. If I have to do that I might as well be managing the memory too.

      This has specifically annoyed me in the past and now, as I continually run into this limitation. It is on my list of "Reasons I Despise Java".

    4. Re:Java doesn't fail by LUH+3418 · · Score: 1

      Wish I had mod points right now. This is very true. Simply using containers in C++ eliminates 95%+ of all memory management you would otherwise need to worry about. You can actually write complete, real-world C++ programs without ever calling new or delete.

      I personally don't use boost, but I've heard that it also offers manager pointers that delete objects for you (and do so better than auto_ptr). This can eliminate the need to keep track of allocation/deallocation completely in many programs.

      Myself, I'm programming a JIT compiler in C++ right now. I use Boehm's garbage collector to manage all language objects (the language is garbage collected). I use containers extensively for most of my other memory management needs.

    5. Re:Java doesn't fail by Alef · · Score: 1

      The problem is that you can't do what you were doing before, just by not calling it finalize. In C++ it is a common practice to rely on the stack for resource management (this is where it differs from C), and the reason that you can do this is because you have destructors. And yes, you can do this even when you allocate on the heap (see scoped_ptr). There is no equivalent way to track resources in Java.

      Now, you might say that this is not an issue, since the GC will reclaim all memory anyway. But what you have overlooked is that heap space is not the only resource you have to manage. There are various other types of resources (file handles, network connections, hardware interfaces, to name a few). So, ironically, the garbage collection approach in Java actually results in most types of resources becoming explicit in Java where they are, in essence, implicit C++.

      I'm not saying that this is a huge problem, but it is something I find lacking when I develop in Java and other GC based languages.

    6. Re:Java doesn't fail by Anonymous Coward · · Score: 0

      The reason why you are confused is because you're used to a compiled environment

      Compilation has nothing whatsoever to do with memory management. Java is a compiled environment, too. Java can even be compiled to native code, just like C++. Meanwhile, the gcc compiler, which is written in C and as compiled as you can get, uses GC.

      That's a gripe of mine about Java: It confuses C++ users who are used to using the function finalize

      What are you talking about? There is no function "finalize" in C++.

    7. Re:Java doesn't fail by Anonymous Coward · · Score: 1, Insightful

      Simply using containers in C++ eliminates 95%+ of all memory management you would otherwise need to worry about.

      Unfortunately, the standard C++ containers are deeply flawed: they can only hold objects by value. Which means they're useless for OO code, because you can't have a container of a base class and store instances of subclasses in it. No inheritance, no polymorphism.

      To get round that, you'd have to store pointers in your container... at which point it instantly stops managing the memory for you. The obvious answer is to use a smart pointer! And the standard smart pointer is std::auto_ptr, which ... oops, looks like using that in an STL container is a sure-fire recipe for horrible disasters.

      Now, boost does indeed solve this; it has a set of special pointer containers that can handle objects properly, as well as a set of smart pointers that don't actually suck. But boost is a large, complex third-party library, and that means that a heck of a lot of C++ coders simply can't use it. Sure, some of it's going to be in the next version of C++, but that's too little, too late.

    8. Re:Java doesn't fail by BikeHelmet · · Score: 1

      Yeah, I remember reading up on finalization before I even knew Java's syntax. I decided to create a method in every class - "deleteMe", which nulls everything out when called.

      I'm sure the garbage collector cleans it up soon after. Good enough. Has worked fine ever since.

    9. Re:Java doesn't fail by Anonymous Coward · · Score: 0

      the reason that you can do this is because you have destructors

      Let me rephrase that for you: the reason you have to to do that is that there's no other way to guarantee that anything will be called, specifically: if an exception is thrown.

      RAII is the poster child of making a virtue out of a necessity. The fact is that the only guarantee C++ makes WRT exceptions is that destructors will be called, meaning that the only way to reliably close() anything is to put it on the stack. I guess we should be glad that there a way to do it at least, but that doesn't hide that:

      a) you can't throw an exception from a destructor. Well, you can, but on real systems where your object is going to get wrapped into other RAII's object, you'll end up with a core dump. There's no such problems with close() methods because, one, you can always reliably catch exceptions in Java as opposed to C++, and two, you still the finalizer to clean up. Reference

      b) the siblings explaining how close() "break the abstraction" or destructors allow you to "release [...] at the exact moment they are not used anymore" make me laugh. At the exact moment is what close() does. To do the same in C++ you have to wrap the code in an "artificial" block so that the destructor gets called when you want to instead of when you return, 5 minutes later. Which incidentally breaks the whole "abstraction" business - as if pretending a disk, or worse, network, resource with an access time of the order of 10 ms was 5 orders of magnitude faster memory ever was a good idea - because now you have this block standing there for no obvious reason. At least try/catch/close makes is self describing.

    10. Re:Java doesn't fail by LizardKing · · Score: 1

      I decided to create a method in every class - "deleteMe", which nulls everything out when called.

      Well at least the consistent name means it will be easy to remove when a competent programmer gets hold of your code.

      I'm sure the garbage collector cleans it up soon after. Good enough. Has worked fine ever since.

      The classic sign of a lazy bodger. You could have actually checked, and then found out that your nulling exercise has zero influence on the garbage collectors activity.

    11. Re:Java doesn't fail by BikeHelmet · · Score: 1

      And how would you go about removing an Array containing a bunch of BufferedImage objects?

      I'm pretty sure the garbage collector isn't going to just wipe them out on the off chance they aren't used. When I don't need them anymore, I null them out, and hope it frees the memory soon after.

      If that makes me lazy, then... hurray?

    12. Re:Java doesn't fail by Alef · · Score: 1

      I understand perfectly well how exceptions work. RAII is a good practice in C++ regardless of whether you have exceptions enabled or not, because it enforces resource reclamation. It's just that exceptions in C++ won't let you get away with having bad habits.

      I don't understand what you mean when you are talking about objects being wrapped. Yes, you must never throw exceptions from destructors -- but if you follow that basic law, stack unwinding will work fine even when objects are wrapped in each other.

      Sure, you can argue that the compiler should forbid you from throwing exceptions in destructors, and I won't dispute you if you say that exceptions in C++ really is a rather complicated matter. But that completely misses the point. There is nothing inherent in scope based resource management that prevents reliable exception handling. C# has it with the "using" statement.

      The problem with only having close() or equivalent is that it adds one more way to break the logic of the program if you're not very careful all the time. And makes it impossible to implement "fool proof" interfaces around external resources. (And by the way, there is nothing that prevents you from having both a close() function and a destructor doing the same thing. On the contrary, this is usually the norm.)

      If your functions take 5 minutes to return and are cluttered with "artificial" blocks I'm guessing you're writing way to big functions. Try breaking them apart. I rarely find the need to add blocks to enclose RAII allocations, but when I do it usually makes the code a lot clearer. For instance if you lock a mutex to protect a number of statements inside a function.

  14. Little Early to Bring Up Oracle by Kagato · · Score: 1

    Until the deal closes Oracle has nothing to do with Sun's Day to Day operations. Once Oracle takes over take bets on what happens to MySql and Glassfish. Until then, they don't have squat to do with it.

    1. Re:Little Early to Bring Up Oracle by Zarf · · Score: 1

      The fact that Larry was on stage bidding farewell to the senior staff of Sun at JavaOne doesn't help the rumor mill one bit.

      --
      [signature]
  15. GC and the desctructor by testman123 · · Score: 1

    A destructor is useless with a GC.

    The finalize method was only introduced in some situation where you need to make memory cleaning easier & faster.

    If you are developing a regular program, you will never need to ever think on finalize. Using WeakReferences, Handles (look NIO for instance), you don't even need to know what is finalize() and what is the subilities it has. In the same way as the .wait() or .notify() !

    This is the problem with developper comming from C/C++, they have been so focussed on memory management problems that they can not understand it has been solved (with a CPU & memory cost) thru GC usage.

    Having automatic memory handling, does not mean you are freed from error. One famous problem is the loitering references, a reference you did not take notice to kept a bit longer than required in your code, but unfortunatly this reference has reference to lots of objects that have also reference...etc. The problem is getting worse if the place you are keeping tis reference is under a static zone or in a daemon thread.

    The known solution to this is :
      1- never keep a cache of objects that are external to your domain unless you know what you are doing or unless you are using a weak reference to point each object and performing the appropriate presence test on them.
      2- never store a reference to your domain in a foreign domain (worst example of this is swing client properties) unlessyou know what you are doing or unless you are using a weak reference to point each object and performing the appropriate presence test on them
      3- never use string interning (cf. .intern()) unless you truly understand it and can control the memory usage impact you will have on the VM on the long run.

    If you follow those simple advices, you will never have to think about .finalize() anymore :)

    Allright, here is my question : we know that GC are now well known techniques and have reached to a suitable level of maturity. Why is there no GC directly written in the microprocessor ? I mean, these are basic feature that a processor could control and perform better than anybody else. All languages could benefit this by replacing memory allocation techniques !

    This would be a huge step forward IMHO.

    1. Re:GC and the desctructor by afidel · · Score: 1

      In the enterprise destructors would be really nice. Depending on average object size the JVM's for our various applications can't use more than 1-1.5GB of ram because worst case GC times become bad enough to become noticeable at the display level. This leads to all sort of fun hacks for load balancing a bunch of JVM's. If GC were just used to catch the occasional leaked memory it could be scheduled for off hours where the performance impact would be minimal.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
  16. garbage collect itself? by Anonymous Coward · · Score: 0

    if the GC is working correctly, it should garbage collect the entire Java language, and flush it down the toilet.

    It's still too slow

    It's still not deterministic

    It's still lacking IEEE-754 floating point compliance

    It's still lacking STANDARD implementations of many COMMON functions

    It's still NOWHERE NEAR write once, run anywhere, it's more like write once, test against 3 difference versions of the JRE, and hope users have the right CLASSPATH set.

  17. I still worry... by tekiegreg · · Score: 1

    If Oracle is about to manage Java the way they manage their database product (basically letting Microsoft get ahead with SQL Server in many respects), I think Java's in trouble with .NET rumbling straight at 'em...

    --
    ...in bed
    1. Re:I still worry... by tthomas48 · · Score: 1

      Uh. Sure. This will be a problem when Microsoft makes .Net run well on Linux. Until then they'll just be that really obnoxious loud truck rumbling in the next lane over.

      I have no idea what you mean by SQL Server being ahead of Oracle, but SQL Server also only runs on Microsoft OSes and is thus only useful for people who run Microsoft OSes.

    2. Re:I still worry... by afidel · · Score: 1

      The only way that I see SQL server ahead in is pricing. When we implemented Oracle 10gR2 about 3 years ago we got such good pricing out of Oracle that MS refused to match for SQL Enterprise. Now that quad core is the norm and 8 core is on the horizon Oracles per core pricing model is insane.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    3. Re:I still worry... by El_Oscuro · · Score: 1

      basically letting Microsoft get ahead with SQL Server in many respects

      True. This only works in SQL Server, not Oracle.

      --
      "Be grateful for what you have. You may never know when you may lose it."
    4. Re:I still worry... by tekiegreg · · Score: 1

      Yeah Oracle's never had injection problems either right....

      --
      ...in bed
  18. So use real-time Java by shis-ka-bob · · Score: 3, Informative

    If you want to control garbage collection, you should use the real time version of Java. Go to youtube and view Java RTSJ on Wall Street pt1. Here are folks that greatly value deterministic behavior, and they are choosing Java over C++. Why? Because it is predictable and you get access to the tools, developers and tools of the Java World.

    --
    Think global, act loco
    1. Re:So use real-time Java by tkinnun0 · · Score: 1

      Ever heard of the terms undefined and unspecified behaviour? Well, I guess one could argue about the predictability of unpretictability...

    2. Re:So use real-time Java by LordKazan · · Score: 1

      all that "UB" means is that the standard doesn't care. and it always describes something that you're not supposed to do.

      No problem with predictability there.

      --
      If you cannot keep politics out of your moderation remove yourself from the Mod Lottery.. NOW!
  19. It's not because you aren't paranoid that java.... by flibuste · · Score: 1

    Or was Oracle/Sun tentatively testing the waters to see the community's reaction?

    It'd be great if my fellow slashdotters stop giving in the PROFIT conspiration theory, just one time.

  20. Just wondering is there a GPU like GC?. by Anonymous Coward · · Score: 0

    Is there anything like a hardware based GC?. Imagine all object life cycle and reference change events are fed in to GPU like dedicated hardware and the hardware determines which object can be dumped. Would it be worth?. If a GPU can process billions of whatever, why not GC. It should be there already somewhere, why it is not in wide use?.

  21. Not Oracle/Sun Yet by fm6 · · Score: 4, Informative

    Or was Oracle/Sun tentatively testing the waters to see the community's reaction?

    It's a little early to talk about Sun as a part of Oracle. It's probable that the acquisition will clear regulatory approval, but until it does, Oracle can't play anything resembling a decision-making role in something like this.

    I work at Sun, and right now our contacts with Oracle are actually more circumscribed than they'd normally be.

    1. Re:Not Oracle/Sun Yet by Red+Flayer · · Score: 1

      It's a little early to talk about Sun as a part of Oracle. It's probable that the acquisition will clear regulatory approval, but until it does, Oracle can't play anything resembling a decision-making role in something like this.

      That's a laugh. At the operational level, Oracle will not interfere much until the acquisition is approved.

      But at the strategic level? You can bet your bottom dollar that Sun isn't blowing its nose without checking with Oracle to see if it's OK first.

      --
      "Trolls they were, but filled with the evil will of their master: a fell race..." -- J.R.R. Tolkien on Olog-hai
    2. Re:Not Oracle/Sun Yet by fm6 · · Score: 1

      And you know this to be true because...

  22. How is Sun any different from Red Hat? by w3woody · · Score: 1

    I think the intent was simple.

    Until the code is stable, if you use the new, beta quality garbage collector in production, don't go crying to Sun for help unless you're willing to pay for a support contract.

    How is that any different from most open source companies such as Red Hat?

  23. ppc on linux by Joseph_Daniel_Zukige · · Score: 1

    Java is slow on PPC on Linux right now.

    I guess. Or maybe it's just Netbeans. But a 1.2GHz Mac Mini running Netbeans on Mac OS X is (subjectively) about half as fast as a 1.7 GHz Sempron running Netbeans on Linux. But Netbeans on the same 1.2GHz PPC processor running Linux is dead slow.

  24. Garbage Processor Unit? by Joseph_Daniel_Zukige · · Score: 1

    Hmm.

  25. C++ sucks. by Anonymous Coward · · Score: 0

    I love how anytime there is a Java related post, you get these C++ fanboys griping about how bad Java is. Usually comments include things about finalize(), the GC, unsigned primitives, the Date class being a pain in the ass (really?), etc.

    And then you tell people that there ARE very good ways to get around these issues, and they say, why don't you just use C++?

    Are you people freaking kidding me? I mean, I am not saying that Java doesn't have it's quirks, but compared to C++??? C++ has got to be the most inconsistent, most poorly designed language I have ever encountered.

    Pick up any C++ book, and 80% of the book describes what not to do just to avoid "undetermined behavior". This alone should raise red flags about the overall design of a language.

    Try to get any kind of static initializion right, or predictable across different OS's. Heck, just try to add an std:string as a key to a hash_map and watch the pages of compile errors you'll get depending on your target platform. Is hash_map even a subclass of map? No. You need to resort to templating to mimic polymorphic behavior, and then try to memorize all the ridiculous rules about where you can actually put your damn template function definitions, because these too are inconsistent. How about nice things like reflection? Forget about it. Heck, I even have to manually guard against a header file being included more than once. And I love how people tell me how "powerful" C++ macros are. They aren't... people get "complicated" and "powerful" confused. A powerful macro system would allow modifications to the AST at compile time, or even perhaps at runtime. C++ macros are nothing but poorly implemented, UNpowerful, text expansions. And C++0x is a joke, a hilarious one.

  26. Free, at first... for pay later, surely. by Anonymous Coward · · Score: 0

    They'll make it free for now... to get all of us to help them work out the bugs, then they'll start charging for it.

  27. Why would anyone pay to collect G1's anyway? by Teilo · · Score: 1

    I mean, they are rather bland looking, have poor 3G coverage, and limited memory.

    To each his own, I suppose, but Java better keep it's damn mitts off MY G1.

    --
    Mir tut es leid, Menschen daß Einfältigfehlersuchenbaumfolgendenaffen sind.