• Post Reply Bookmark Topic Watch Topic
  • New Topic

Concurrent Garbage Collection  RSS feed

 
Seetharaman Venkatesan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to this forum. And I am here to get answers for a few questions abt the Concurrent Garbage Collection.

(1) Enabling the Concurrent Garbage Collector:
By adding the concurrent garbage collector switch -J-XX:+UseConcMarkSweepGC to the netbeans.conf file.
But how am I supposed to add the switch in the netbeans.conf file? is it using command prompt or is it via some option in netbeans?

(2) Advantages and disadvantages of enabling the Concurrent Garbage Collector?

(3) Scenarios where the
(a) GC is faster compared to new/delete
(b) new/delete is faster than GC

I have partial answers for 2 and 3 but I would be grateful if some helps me by explaining them in detail.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatesan wrote:I have partial answers for 2 and 3 but I would be grateful if some helps me by explaining them in detail.


If you haven't read it already, this is worth reading.
Note that this only applies to version 6. If you are using a different version, just google something like 'Java X garbage collector tuning' to get a similar document for version X.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

I am afraid we like to keep this forum for easy questions, so I shall have to move you to where more difficult questions are usually asked.
 
Seetharaman Venkatesan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Joanne
I am going though the link.

@Campbell
Go ahead and move it to the appropriate forum.

I am looking forward, for some detailed explanation on my query.

Thanks
 
Seetharaman Venkatesan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Joanne
The link was really informative.

@All
I am still unable to find scenarios where GC is faster than new/delete
My 2 cents:
I have been a C++ guy for quite some time (read new to Java) , and new/delete give more control to the programmer/application to allocate and de-allocate memory. And by the end of de-allocation you know, memory has been released and is available for sure (Predictable).

But that is not the case with GC. Even if you envoke System.gc(), you are not assured immediate results. And GC's behavior is unpredictable. There are possibilities of 'pausing', which could affect the performance of the application.

So I always feel that new/delete is faster than GC.

But what about scenarios where GC being faster than new/delete?
Looking forwards for some answers...


-------------------------------------------------------------------------------------------------------------------------------------
Misc:
For people who want to understand the concept of GC:
http://www.youtube.com/watch?v=rp8PvFvSO_c [the whole video]
http://www.youtube.com/watch?v=zksIj9O8_jc&feature=SeriesPlayList&p=4BBB74C7D2A1049C [first 15 mins]




 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by GC being faster than new/delete? New/delete in C++? In Java there is no other option to create an object than using new (okay, there is serialization, Class.newInstance(), reflective constructor calls etc. but let's not mess things up), which in no way can be influenced by GC. I think that explicit object removal using delete could be faster, because you would directly point at the object to be deleted - the GC has to go through all the objects and mark the unused ones. On the other hand, GC runs in a background thread, so it can use the processor when it is idle (stopping your program only for a short while), while explicit deletion is called in the main thread(s) of your program.

I'm not sure if I got you right and what you want to achieve - could you please explain more of your concerns? Also, you can have a look at the new G1 (Garbage First) GC, introduced in JDK 6u14. It's experimental as for now, but you can give it a try ;)
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Michalik wrote:I think that explicit object removal using delete could be faster, because you would directly point at the object to be deleted


I think it is opposite. Java heap can use very different data structures and algorithms then malloc/free because it does not need to support freeing of objects on demand and can do deallocation of more objects at once. GC can also move objects in memory to reduce fragmentation and make continuous chunk of free memory for very fast allocations.

Disadvantages or GC are (relatively) long pauses, unpredictability and higher memory usage.
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this discussion would require some serious benchmarking to give us some arguments. I agree that JVM memory management is very smart and GCs do a hell of a good job. So maybe they are as fast or relatively faster than de/allocation by hand... Anyway I read somewhere that memory management is one of the fastest things that Java has ;)

Here are some interesting links, too:
IBM - Brian Goetz - Allocation is faster than you think, and getting faster
IBM - Brian Goetz - Java theory and practice: Garbage collection and performance
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have been a C++ guy for quite some time (read new to Java) , and new/delete give more control to the programmer/application to allocate and de-allocate memory. And by the end of de-allocation you know, memory has been released and is available for sure (Predictable).

But that is not the case with GC. Even if you envoke System.gc(), you are not assured immediate results. And GC's behavior is unpredictable. There are possibilities of 'pausing', which could affect the performance of the application.

So I always feel that new/delete is faster than GC.

But what about scenarios where GC being faster than new/delete?
Looking forwards for some answers..


Comparing C++ and Java is kinda silly... comparing it by the GC is really really silly. It is really like comparing apples and oranges.

The Java programmer don't worry about delete -- and as such, don't think twice about doing "dangerous maneuvers", such as returning an iterator from a method. In C++, I need to keep track of the number of references to my data, as an external iterator may still be using it -- or more likely, I have to give the iterator its own copy (which requires that I change the spec, as it is no longer directly backed to the data).

You can't really compare which is faster, because the Java programmer uses the GC in a fashion that would incredibly annoy the C++ programmer. In fact, I get really annoyed with this myself all the time, when I want to do something in C++ that I know can be done with one line in Java, but needs a bunch of reference counting code in C++.

Of course, with C++, I don't worry too much about closing resources, because I know that my destructors are run, then the variables goes out of scope, instead of when the GC runs (which is a good thing, but not enough to make up for the previous).

Now you can argue which is better, but that is opinion, and considering that you are someone who use one for "quite some time" and "new" to the other, we probably know where you stand.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!