CSC 331 Object Oriented Programming Using Java

Slides:



Advertisements
Similar presentations
Paging: Design Issues. Readings r Silbershatz et al: ,
Advertisements

CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
Garbage Collection What is garbage and how can we deal with it?
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 6 Object Oriented Programming in Java Language Basics Objects.
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Memory Management Tom Roeder CS fa. Motivation Recall unmanaged code eg C: { double* A = malloc(sizeof(double)*M*N); for(int i = 0; i < M*N; i++)
CPSC 388 – Compiler Design and Construction
OOPSLA 2003 Mostly Concurrent Garbage Collection Revisited Katherine Barabash - IBM Haifa Research Lab. Israel Yoav Ossia - IBM Haifa Research Lab. Israel.
MOSTLY PARALLEL GARBAGE COLLECTION Authors : Hans J. Boehm Alan J. Demers Scott Shenker XEROX PARC Presented by:REVITAL SHABTAI.
UPortal Performance Optimization Faizan Ahmed Architect and Engineering Group Enterprise Systems & Services RUTGERS
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Age-Oriented Concurrent Garbage Collection Harel Paz, Erez Petrank – Technion, Israel Steve Blackburn – ANU, Australia April 05 Compiler Construction Scotland.
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
School of ComputingJanos Project Processes in KaffeOS: Isolation, Resource Management, and Sharing in Java Godmar Back Wilson HsiehJay Lepreau School of.
1 Garbage Collection Danny Angus. Introduction Student loans, amongst other things, run B2B applications implementing government policy in the UK. We.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
CLR: Garbage Collection Inside Out
File I/O Applied Component-Based Software Engineering File I/O CSE 668 / ECE 668 Prof. Roger Crawfis.
Lecture 10 : Introduction to Java Virtual Machine
Investigating the Effects of Using Different Nursery Sizing Policies on Performance Tony Guan, Witty Srisa-an, and Neo Jia Department of Computer Science.
Garbage Collection and Classloading Java Garbage Collectors  Eden Space  Surviver Space  Tenured Gen  Perm Gen  Garbage Collection Notes Classloading.
Runtime System CS 153: Compilers. Runtime System Runtime system: all the stuff that the language implicitly assumes and that is not described in the program.
Finalizers, this reference and static Sangeetha Parthasarathy 06/13/2001.
G ARBAGE C OLLECTION CSCE-531 Ankur Jain Neeraj Agrawal 1.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Introduction to Garbage Collection. Garbage Collection It automatically reclaims memory occupied by objects that are no longer in use It frees the programmer.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
® July 21, 2004GC Summer School1 Cycles to Recycle: Copy GC Without Stopping the World The Sapphire Collector Richard L. Hudson J. Eliot B. Moss Originally.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Lecture #20: Profiling NetBeans Profiler 6.0.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Lecture 6 The Rest of Scheduling Algorithms and The Beginning of Memory Management.
Multithreading The objectives of this chapter are:
Object Oriented Programming in
Garbage Collection What is garbage and how can we deal with it?
Core Java Garbage Collection LEVEL – PRACTITIONER.
Topic: Java Garbage Collection
Chapter 2 Memory and process management
Java 9: The Quest for Very Large Heaps
Unit-2 Objects and Classes
CS 153: Concepts of Compiler Design November 28 Class Meeting
Automatic Memory Management
Runtime Analysis of Hotspot Java Virtual Machine
Real-time Software Design
Chapter 9: Virtual-Memory Management
Smart Pointers.
Simulated Pointers.
Main Memory Background Swapping Contiguous Allocation Paging
Strategies for automatic memory management
Adaptive Code Unloading for Resource-Constrained JVMs
Closure Representations in Higher-Order Programming Languages
CSCI1600: Embedded and Real Time Software
There’s not always room for one more. Brian Bershad
Introduction to Object-Oriented Programming in Alice
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
Interpreting Java Program Runtimes
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
M S COLLEGE ART’S, COMM., SCI. & BMS
Multithreading The objectives of this chapter are:
Automating Memory Management
Continuously and Compacting By Lyndon Meadow
New GC collectors in Java 11
Program-level Adaptive Memory Management
CMPE 152: Compiler Design May 2 Class Meeting
Garbage Collection What is garbage and how can we deal with it?
Mooly Sagiv html:// Garbage Collection Mooly Sagiv html://
Presentation transcript:

CSC 331 Object Oriented Programming Using Java Garbage Collection CSC 331 Object Oriented Programming Using Java

Overview What, me worry? Garbage in Javaville. Different ways to collect garbage. Taking care of Java garbage. Tweaking Java garbage collection. Finalizing stuff. Credits.

What, me worry? What is garbage collection? C++ makes me use destructors . . . Java doesn’t. Automatic garbage collection. No need for destructors. No memory leaks? Can I cause garbage collection in Java? If not, why be concerned?

Starting garbage collection . . . System.gc() No guarantee that g.c. begins right away. JVM starts g.c. . . . Whenever JVM “wants” to . . . No garbage to collect unless all references to one or more objects have been invalidated.

Garbage in Javaville: a Metaphor “Imagine you live in a really small town (let's call it JavaVille). It has one main street, and, for fun, residents cruise the street, throwing candy wrappers and old computer parts out their car windows. This creates quite a mess, and the town has hired a full-time garbage collector to deal with the problem.”* .*Adapted from Holling, Greg, “J2SE 1.4.1 boosts garbage collection,” JavaWorld, March 2003

Javaville stinks . . . “Now, imagine you are the town garbage collector, or sanitation engineer. With your garbage truck, you pick up all the trash left on the street. However, your truck is so big that no other cars can travel on the main street while you're collecting garbage. This gives people something else to complain about—they can't do anything else while the garbage truck travels through town. You try to stay out of the way, but sometimes, certain vehicles must get through, like ambulances and fire trucks.”

Javaville attacks the problem “To alleviate the situation, the town council votes to add some new streets so people can go about their business even when the garbage truck is running. They also decide to buy more garbage trucks so garbage collection takes less time.”

Javaville garbage collection - constrained by number of trucks and streets. “This is a really useful metaphor for thinking about Java garbage collection, where multiple application threads (litterbugs) create garbage, and one thread (you) cleans it up. The application threads and the garbage collector share a single CPU (the main street), and all activity in the applications must stop while garbage collection is in progress (stop the world). You can make garbage collection less noticeable by adding more CPUs (streets) or more garbage collection (GC) threads (garbage trucks). Note that adding more GC threads (trucks) won't do you any good unless you have enough CPUs (streets) for them to work effectively in parallel.”

How to collect garbage, according to Sun. Sun JVM specs do not require garbage collection! Thus, a JVM may not have it. Example: JVM for a bare-bones smart card app. However, most JVMs do have it. The garbage collection algorithm is not defined. This means that the timing and manner of g.c. can’t be predicted unless you know the specific JVM being used-and maybe not then.

Different ways to collect garbage Mark and sweep: Original in JDK 1.0 Mark: Identify garbage objects. Sweep: Reclaim memory used by the objects. A “stop the world” technique All threads stop until g.c. is complete, or Until a higher-priority thread interrupts g.c.

Different ways to collect garbage Sun HotSpot VM approach Split heap into 3 sections. Permanent space – for JVM class and method objects. Old object space – for longer-lived objects. New object space – for newly created objects. Three different g.c. techniques P.s.: Incremental garbage collection. Old o.s.: Copy compaction New o.s.: Mark-compact. All 3 are “stop the world” techniques.

Taking care of Java garbage. Three new algorithms in J2SE 1.4.1: Parallel copying – optimized for multiple CPUs. Parallel scavenging – optimized for large amounts of memory Concurrent 6 phases 2 are “stop the world” 4 are parallel techniques

Tweaking Java garbage collection Command-line switches can select algorithms, affect heap allocation. How to select an algorithm: If it ain’t broke, don’t fix it. Some heuristics available. Careful forethought, testing required for proper selection.

Changes in garbage collection in J2SE 5.0: More tuning possible. On server-class machines default g.c. is a parallel collector. Can be overridden. Maximum heap size is the smaller of 1 GB or 1/4 the available memory. Formerly varied by platform. Can be overridden. Upper limit of percentage of total time spent on g.c. can be specified (default: 98%). Lower limit of space freed during g.c. as % of heap size can be set (default: 2%).

Finalization What is it? So? finalize() A method of Object. Java specs: Before reclaiming memory for an object that has a finalizer, finalize () will be invoked. So? Use finalizers to free non-memory finite resources, such as sockets. A backup; should be previously freed. If you override finalize(), be sure to call super.finalize() as the last action in your method.

Summary Explanation of why g.c. is important to understand. Used a metaphor to aid understanding of g.c. Introduced different ways to collect garbage. Described ways to tune g.c.. Introduced concept of finalization. Acknowledgements.

Credits java.sun.com/docs/books/tutorial/java/data/garbagecollection.html java.sun.com/docs/books/tutorial/java/javaOO/objectclass.html http://java.sun.com/j2se/1.5.0/docs/guide/vm/gc-ergonomics.html Eckel, Bruce, Thinking in Java, 3d. ed., Prentice-Hall, 2003, 183-191. Friesen, Jeff, “Trash Talk, Part I,” JavaWorld, December 2001. Holling, Greg, “J2SE 1.4.1 boosts garbage collection,” JavaWorld, March 2003. Jia, Xiaoping, Object-Oriented Software Development Using Java, 2d. ed., Addison-Wesley, 2003, 90-91. Venners, Bill, “Object finalization and cleanup,” JavaWorld, June 1998.