View
1
Download
0
Category
Preview:
Citation preview
Proceedings of the 11th
INDIACom; INDIACom-2017; IEEE Conference ID: 40353
2017 4th
International Conference on “Computing for Sustainable Global Development”, 01st
- 03rd
March, 2017
Bharati Vidyapeeth's Institute of Computer Applications and Management (BVICAM), New Delhi (INDIA)
Optimisation of Garbage Collection in Java
Aabhas Arya, Amity University,
Uttar Pradesh,
Sector125,Noida India
Email id: aabhas.arya01@gmail.com
Diksha Kaul Amity University,
Uttar Pradesh,
Sector125,Noida India
Email id: kau l.diksha7@gmail.com
Ankur Saxena Amity University,
Uttar Pradesh,
Sector125,Noida India
Email id: asaxena1@amity.edu
Abstract — Java is an efficient language designed to allow
developers to develop applications that are platform independent.
This platform independence is central to the Java Virtual
Machine (JVM), which converts all code to machine level language. Although the JVM is a very useful feature of the Java
language as Whole, its working is still flawed. This paper mainly
focuses on the background processes that JVM performs in order
to run the applications more efficiently. The main focus is on the
key feature of JAVA that is GARBAGE COLLECTION which is usually an automatic process that occurs in the background.
Usually, developers are not concerned with such background
processes but in developing certain complex applications, it
becomes necessary to have a degree of control over garbage
collection, undergo, the working of the JVM also to a slight extent. In our paper, we discuss how garbage collection (GC) can
be tuned or optimized to overcome issues like long GC pauses,
lagging and out-of- memory exceptions.
Keywords — JVM; GC; GC Events; young,old and permanent
generation; eden space; survivor space; latency
I. INTRODUCTION
In this paper we will be describing the back side working
of the varied Garbage collectors present in Java. We will be showing the contrast in the varied Garbage Collectors that
work on the backdrop accomplishing the operation according
to the application.
Java Virtual Machine is the linchpin of Java Platfo rm. JVM
has the authority for platform independence minute size of the code and shield it’s users from destructive programs [1]
[2][25].
JVM accomplishes the following:
Loading of the code
Verify ing of the code
Executing the code
Bestows run time environment
JVM interprets for:
Area of the memory
File format of the class
Fig. 1. Runtime system of java
Class Loader is a fragment of JVM manoeuvre
loading of class files
Area of class holds per class structures
Heap is a run time data region from which all objects
and arrays are issued
Stack stows frames. It holds locally declared variables
and partial results. It also plays a role in method
invocation and result
Program Counter(PC) Register is enough to hold
return address [3][24]
Application native methods are contained in method
native stack
Engine Execution holds virtual processor,intrepretor
and JIT compiler
Copy Right © INDIACom-2017; ISSN 0973-7529; ISBN 978-93-80544-24-3 1987
Proceedings of the 11th
INDIACom; INDIACom-2017; IEEE Conference ID: 40353
2017 4th
International Conference on “Computing for Sustainable Global Development”, 01st
- 03rd
March, 2017
JIT or Just in Time Compiler compiles the java bytecodes
into machine language. When the JVM calls a method, it uses the called method as specified method region of the loaded
class object. For GC to happen, a program must reach its safe point. For this, introduces yield points at various interim in the
native code. [4][5][23]
The objects are resided in a region called as heap
[6][22].Heap space for instances are retrieved by an automatic
storage management system. This referred to as Garbage Collector. The heap is not permanent. This size may vary
according to its use[7][26].
Java has four distinct Garbage Collectors given below[8][9]:
Serial GC
Parallel GC
CMS GC
G1 GC
Serial GC works by gripping all application threads. It
functions on single thread environments [10][11].
Command to Turn on: -XX:+UseSerialGC JVM
Parallel GC is the default GC for JVM.This functions upon multip le threads. This also freezes all application threads while
working[12][13].
CMS GC makes use of multiple heap memory to mark objects for deletion and then sweeps them. If more memory
units can be allocated to optimise collector performance, CMS garbage collector emerges as the preferred option[14].
Command to Turn on: XX:+USeParNewGC JVM[15][20]
G1 garbage collectors are applied to large heap memory
areas, segregating and performing parallel garbage collection.
Command to Turn on : –XX:+UseG1GC JVM [16][21].
II. . REVIEW
Simon Marlow and Simon Peter Jones, in their paper
Multicore Garbage Collection with Local Heaps say that “in a garbage collected environment, multithreaded programs can
run into an allocation wall in which performance is limited by the rate at which newly allocated data can be written to main
memory, and adding more cores does not improve
performance once the limit is reached”[2][17]. Performance is affected by the fact that latency in a single core can halt the
entire system especially if the system prioritizes some other process running in the same core over the execution of our
program. Considerable work has been done to try and overcome the inherent synchronization in garbage collection
by, for example, designing collectors where each processor has
a private heap which can be collected independently without having to synchronize with the other processors. The building
of advanced embedded systems demands co-designing the hardware and software components. However, as discussed in
the paper, a software developer views execution as one that is purely sequential or with only some parallelis m using threads
or passing messages[2][18]. A hardware developer, on the
other hand, prefers working with a more physically oriented
model of the applications. Execution, in terms of hardware, is extremely paralleled, as is demonstrated by mult iple parallel
processes functioning simultaneously.
Simon Marlow and Simon Peyton Jones in their paper
discuss heap structures that allow recruiting pointers from the global heap to local heaps created for each process, mainly to
avoid the premature transfer of mutable objects to the global
heap. As opposed to this, Phillippe Faes et al. employ a dynamic approach where hardware components are made to
create and hold references to dynamically allocated objects. Since the second approach enabled hardware components to
hold objects, it necessitated the Java garbage collector to register the existence of these objects so as to find all objects
in use. Moreover, the garbage collector must be enabled to also keep updating the references for the objects residing in the
hardware memory components. Faes et al. have validated their
techniques to achieve this on four different garbage collector types, and focus mainly on the ones that stall the complete
Java application while performing garbage collection (“stop-the-world” garbage collection), in their paper.
The following schematic showing the mapping of address
spaces for the garbage collector has been taken off the original
paper by Faes et al.
Fig. 2.
The consequences of garbage collection using hardware and
that in a pure software environment were compared using what
they called a “micro benchmark”, where hardware instances,
each with a capacity to hold 256 references to Java objects,
were created along with n x 256 objects. Their references were
passed to the hardware in a continuous loop in which garbage
collection was forcefully invoked [3][19]. The execution time
for a few such loops was measured as well as ones where the
references were held in object arrays.
The following results were obtained:
Copy Right © INDIACom-2017; ISSN 0973-7529; ISBN 978-93-80544-24-3 1988
Optimisation of Garbage Collection in Java
In our paper, we aim to d iscuss how memory is better managed
using garbage collection and how that process can be
optimised for various processes, environments, and platforms.
III. METHODOLOGY
Java Memory Management lets developers create objects
without having to worry about exhausting memory resources.
Memory is automatically freed for reassignment as the garbage collector removes objects that have completed their lifecycle.
As beneficial as this may seem, Java garbage collection often generates a number of serious performance issues like
longer pauses, decreased throughput, increased latency, and even causes certain applications to lag.
Garbage collection is an automated process that runs in background so that the programmers do not have to worry
about the background processes.
But sometimes the automatic process does not work too well for the application developers as they sometimes face the
issues like slow working of their application, so the tuning of the GC plays a very important role in enhancing the output and
the performance of their applicat ion.
A. WORKING OF THE GARBAGE COLLECTION
The general belief is that garbage collect ion involves the
collection and removal of dead objects, whereas, in reality
garbage collection in Java functions in quite the opposite manner. Objects that are still in use are tracked in real t ime and
everything else is categorized as garbage.
The heap, which is the term used to describe the memory
allocated dynamically, is primarily recruited to be handled by
the JVM even while a program runs. This puts into play a few
important implicat ions:
Object creat ion speeds up since the heap need not be
synchronized with OS.Memory is divided , instead,
into array.
As soon as an object ceases to be of use, the garbage
collector frees the memory associated with that object
so that it may be allocated to a different object in the
future.
Every object assigned to the heap is managed automatically by the JVM. These include class objects, static variables, and
even parts of the original code. As long as an object is being
referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the
application code, the garbage collector removes it and reclaims the unused memory.
The heap memory is further divided into two generations Young generation and the Old generation.
Young generation: - It is main ly the place where the object
lives for short period and divided into two spaces:
Eden Space: - The object which is created using new
keyword memory allocated in this space.
Survivor Space: This is the space which is acceptable
for objects which have sustained after Java garbage
collection from Eden space.
Old Generation: This space basically contains
tenured and virtual (reserved) space and will be
holding those objects which survived after garbage
collection from Young Generat ion.
Tenured Space: This memory space contains objects
which survived after multiple garbage collection
cycles means object which survived after garbage
collection from Survivor space.
There are a third types of memory in JVM which is
independent and not the part of heap memory known as PERMANENT GENERATION. Also termed as non-heap
generation Further divided into read-only and read-write areas.
This is the separate space for the class definition and the other
related data.
Commands for tuning heap:
-Xms<size> set init ial java heap size
-Xmx<s ize> set maximum java heap size
-Xss<size> set java thread stack size
B. TYPES OF GARBAGE COLLECTORS:-
1. Serial Garbage Collector
This collector is the most effort less one which is primarily
intended for the single thread situations or for the small heaps.
This collector works by holding all the application threads
mechanis m. It is most appropriate for command line type
program.
Copy Right © INDIACom-2017; ISSN 0973-7529; ISBN 978-93-80544-24-3 1989
Proceedings of the 11th
INDIACom; INDIACom-2017; IEEE Conference ID: 40353
2017 4th
International Conference on “Computing for Sustainable Global Development”, 01st
- 03rd
March, 2017
Turn on the -XX:+UseSerialGC JVM.
2. Parallel Garbage Collector
This is default collector of the JVM in JAVA9 . Unlike serial
garbage collector, this uses multiple threads for garbage
collection. Similar to serial garbage collector this also has a
downside that is it also fix all the application type of threads
while performing garbage collection either a minor or a full
GC collection.
3. CMS Garbage Collector
CMS garbage collector holds all the application threads in the
given below two situations as it were,
1. While denoting the referenced objects in the
generation space.
2. If there is an adjustment in heap memory in parallel
while doing the garbage collection
In contrast with parallel garbage collector, CMS collector
utilizes more CPU to guarantee better application throughput.
On the off chance that we can dispense more CPU for better
execution then CMS type garbage collector is the favored
decision over the parallel collector of JVM .Turn on
the XX:+USeParNewGC JVM.
1. G1 Garbage Collector (proposed java 9 default
collector)
The proposed new JAVA 9 collector was first usable for the
java programs when JAVA 7 update 4 was released.
Generally the G1 collector was designed to support the heap
larger than 4GB which in return causes less frequent GC
pauses but at the same time when the GC pause occurs while
the G1 collector is enabled they are very long. G1collector
splits the processing of the old generation into multiple phases
but not all of them are stop-the-world. Because of this the
pauses are generally shorter as compared to other collectors.
Turn on the –XX:+UseG1GC JVM.
IV. RESULT AND DISCUSSION
PERMORFANCE OF 4 TYPES OF GARBAGE
COLLECTORS :-
Fig. 3. Performace of serial GC
Fig. 4. Performace of paralel GC
Copy Right © INDIACom-2017; ISSN 0973-7529; ISBN 978-93-80544-24-3 1990
Optimisation of Garbage Collection in Java
Fig. 5. Performace of concurrent GC
Fig. 6. Performace of G1 GC
V. CONCLUSION AND FUTURE WORK
Through this paper, we have tried to exp lain the workings of garbage collectors in Java and highlighted how a seemingly
helpful feature could in fact cause a range of problems and decrease the execution efficiency. It is our belief, and
something that shows a lot of potential, that elements of garbage collection like the JIT can be optimized to combat the
downsides of conventional garbage collection. As we have
explained in detail, there are various ways by which garbage collectors work in Java which themselves are categorized on
that basis. The trick, we believe, lies in picking the suitable type for a particular set of code. We hope we have been able to
describe our take on how to do that, whils t also describing how memory management can be controlled by the user to a certain
degree. Memory is absolutely integral to the functioning of a
computer system and proper prioritization of available memory resources is key to obtaining optimum output.
Through our work, we have seen that in certain cases default garbage collectors are not as proficient as they would
normally be. Furthermore, they may cause lags and the system
to crash. The G1 garbage collector is a suitable option in both
these cases. Similarly, we might want to consider test-running java programs through various garbage collectors. Also,
concentrating our efforts towards fine-tuning or modifying code to suit the Just-in-time compiler (a part of the Java
Virtual Machine) ensures a smoother execution of programs written in Java, and also improves compilat ion and execution
time.
REFERENCES
[1] “The Complete Reference” Java J2SE 5 edition, Herbert Schildt, Eighth reprint 2006, Pg 9-12
[2] ”The Java Virtual Machine Specification” Java SE 8 Edition, T im Lindolm, Frank Yellin, Gilad Bracha, Alex Buckley, 2015, Pg 1-3, 12-14
[3] www.javatpoint.com/internal-details-of-jvm
[4] http://stackoverflow.com/questions/95635/what-does-a-just-in-time-jit-compiler-do artiomg.blogspot.in/2011/10/just-in-time-compiler-jit-in-hotspot.html?m=1
[5] docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/garbage_collect.html
[6] www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html
[7] https://plumbr.eu/blog/garbage-collection/g1-garbage-collector-in-action
[8] https://plumbr.eu/blog/garbage-collection/what-is-garbage-collection
[9] http://javapapers.com/java/java-garbage-collection-introduction/
[10] http://javapapers.com/java/how-java-garbage-collection-works/
[11] http://javapapers.com/java/types-of-java-garbage-collectors/
[12] http://javapapers.com/java/java-garbage-collection-monitoring-and-analysis/
[13] P. Faes, M. Christiaens, D. Buytaert, D. Stroobandt,”FPGA-aware garbage collection in java”, IEEE Xplore Conference: Field Programmable Logic and Applications, 2005
[14] S. Marlow, S.P. Jones,”Multicore garbage collections with local heaps”, ISMM '11: Proceedings of the 10th International Symposium on Memory Management,2011
[15] ”Core Java: An Integrated Approach”, 2016 Edition, Dr.R. Nageswara Rao
[16] N.Goyal,V.Laxmi,A.Saxena,”Handling multithreding approach using java”,International Journa of Computer Science trends and Technology(IJCST) - Volume 3 issue 2,2015
[17] J.M.Lambert,J.F.Power,”Platform independent t iming of java virtual machine bytecode instructions”, Proceedings of the Sixth Workshop on Quantitative Aspects of Programming Languages,2008
[18] S.Gupta,N.Gupta,R.Gupta,”Objects and method calling in java virtual machine”, International Journal of Computer Applications 86(11):34-36,2014
[19] A Saxena,R Jakhmola “Securing Confidential Data using Java/J2EE” International Journal of Science technology & Management Vol. 2 Issue 3, July 2011 (54-59).
[20] J Kumari, S Singh, A Saxena” An Exception Monitoring Using Java” International Journal of Computer Science Trends and Technology (IJCST), Vol 3,Issue 2 2015,12-18
[21] D D Sarkar, A Jaiswal, A Saxena “Understanding Architecture and Framework of J2EE using Weƅ Application” International Journal of Computer Science and Information Technologies, Vol. 6 (2) , 2015, 1253-1257.
[22] A Saxena, A Chaurasia “ Key and Value Paired Data using Java Hash Taƅle” International Journal of Engineering and Management Research Volume-4, Issue-1, Feƅruary-2014,81-89.
[23] A Saxena”Web Based Custom Validation Using Framework in Java” International Journal of Computer Science Trends and Technology (IJCST), Vol 3,Issue 1 2015,90-96
Copy Right © INDIACom-2017; ISSN 0973-7529; ISBN 978-93-80544-24-3 1991
Proceedings of the 11th
INDIACom; INDIACom-2017; IEEE Conference ID: 40353
2017 4th
International Conference on “Computing for Sustainable Global Development”, 01st
- 03rd
March, 2017
[24] A Saxena “HANDLING OF SYNCHRONIZED DATA USING JAVA/J2EE” International Journal of Management, IT and Engineering,Volume 1, Issue 7,182-194.
[25] A Saxena, N Kaushik, N Kaushik ,A Chaurssia”Securing Password of website using Blowfish Encryption and Decryption Techniques with Struts2 Framework” International Journal of control theory and application volume 9, issue 23 pp 201-209 September 2016.
Copy Right © INDIACom-2017; ISSN 0973-7529; ISBN 978-93-80544-24-3 1992
Recommended