Java Memory Model & Garbage collection

Posted by Infocampus HR on December 5th, 2018

The below clarification principally holds for JRE five.0+ - 7.0. JMM(Java memory model) is split into principally three components

  •          Young generation
  •          Old Generation
  •          Perm Gen

Young Generation is more divided into

  •          Eden space
  •          S0 (survivor space)
  •          S1 (survivor space)

Young Generation

Eden area may be a place wherever new objects square measure created. once the area is filled upto an explicit percentage, gc is performed. This event is named as Minor gc.

The living objects from Eden area square measure affected to survivor spaces(S0 & S1).

Minor gc checks the item in survivor areas and move to different survivor areas (S0->S1).

Objects living multiple minor gc square measure affected to previous generation.

Old Generation

Objects survived multiple minor rate square measure affected to previous generation. once associate previous generation is full, the Advanced Java Training In Bangalore Marathahalli main gc takes place to get rid of the unused objects. This event will cause a minor pause within the operating of application. Too several frequent major gc will trigger performance issue within the application. whereas coming up with associate application, one ought to be considerate  regarding it.

Perm Gen

Perm information contains the information of the categories.

  •          Methods of a category (including the bytecodes)
  •          Names of the categories (in the shape of associate object that points to a string conjointly within the permanent generation)
  •          Constant pool(e.g String pool) info (data scan from the category file, see chapter four of the JVM specification for all the details).
  •          Object arrays and sort arrays related to a category (e.g., associate object array containing references to methods).
  •          Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)

When will associate object becomes eligible for gc.

  •          When a object isn't referred by different objects or all its references square measure set to null.
  •          Object moves out of the scope.
  •          Weak reference objects, like Weak HashMap

What square measure completely different style of Garbage collector?

Serial gc (-XX:+UseSerialGC):Serial rate uses the straightforward mark-sweep-compact approach for Advanced Java Courses In Bangalore Marathahalli young and previous generations trash pickup i.e Minor and Major gc. Serial gc is helpful in client-machines like our straightforward stand alone applications and machines with smaller C.P.U.. it's sensible for smaller applications with low memory footprint.

Parallel rate (-XX:+UseParallelGC):Parallel gc is same as Serial gc except that's spawns N threads for young generation trash pickup wherever N is that the range of C.P.U. cores within the system. we will management the quantity of threads mistreatment -XX:ParallelGCThreads=n JVM possibility. Parallel employee is additionally known as outturn collector as a result of it uses multiple CPUs to hurry up the gc performance. Parallel rate uses single thread for previous Generation trash pickup.

Parallel previous gc (-XX:+UseParallelOldGC): this can be same as Parallel rate except that it uses multiple threads for each Young Generation and previous Generation trash pickup.

Concurrent Mark Sweep (CMS) Collector (-XX:+UseConcMarkSweepGC):CMS Collector is additionally referred as coinciding low pause collector. It will the rubbish assortment for previous generation. CMS collector tries to attenuate the pauses because of {garbage assortment| garbage pickup| trash collection| trash pickup |pickup} by doing most of the rubbish collection work at the same time with the applying threads. CMS collector on young generation uses a similar algorithmic program as that of the parallel collector. This employee is appropriate for responsive applications wherever we have a tendency to can’t afford longer pause times. we will limit the quantity of threads in CMS collector mistreatment -XX:ParallelCMSThreads=n JVM possibility.

G1 employee (-XX:+UseG1GC):the rubbish initial or G1 employee is offered from Java seven and it’s future goal is to exchange the CMS collector. The G1 collector may be a parallel, concurrent, and incrementally compacting low-pause employee. Garbage initial Collector does not work like different collectors and there's no conception of Young and previous generation area. It divides the heap area into multiple equal-sized heap regions. once a trash pickup is invoked, it initial collects the region with lesser live knowledge, therefore "Garbage First".

Like it? Share it!


Infocampus HR

About the Author

Infocampus HR
Joined: December 10th, 2016
Articles Posted: 792

More by this author