DOC PREVIEW
U of I CS 421 - Run-time systems and garbage collection

This preview shows page 1-2-3-26-27-28 out of 28 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 421 Lecture 13: Run-time systems and garbage collection Lecture outline Execution of dynamic languages Sun HotSpot run-time system for Java Tags, JIT compilation, reflection Memory managementMemory layout; definition of “garbage”Memory layout; definition of “garbage” Reference-counting Garbage collection Non-compacting (mark-and-sweep) Compacting6/29/20091Dynamic languages Automatic memory management Tagged values For GC, run-time type-checking, reflection Sometimes: Dynamic type-checking Reflection Usually: Execute virtual machine code Will use Sun HotSpot Java virtual machine as example6/29/20092Java HotSpot run-time system Developed around 1999 – replaced existing widely-used Java VM Described in several places, e.g.: http://java.sun.com/products/hotspot/whitepaper.html HotSpot is VM used in java program, and embedded in many browsersmany browsers(Note re: above document – word “compiler” used to refer to translator from Java bytecode to native machine code, not translator from source code.)6/29/20093Java HotSpot run-time system Garbage collection Two-word object headers Executes .class files (Java VM code) “Just-in-time” compilationMeta-objects represented as objectsMeta-objects represented as objects6/29/20094Meta-objects represented as objects Class and Method are classes Each class corresponds to a Class object Methods of class Class include getDeclaredMethods(), getFields(), … Each method corresponds to a Method objectMethods of class Method include getParameterTypes, Methods of class Method include getParameterTypes, getReturnType, … Can invoke methods that are detected dynamically –e.g., search all objects reachable from one object – and invoke method print on any object whose class contains a print method.6/29/20095Two-word headers Every object in heap is preceded by two words First word is pointer to Class object of this method’s class (which gives layout of object) Second word contains GC info Arrays contain third word giving length6/29/20096Just-in-time compilation Methods obtained in bytecode form (.class files) translated to native machine code on the fly Numerous optimizations employed Very important optimization: inlining Level of optimization determined by monitoring execution Heavily used methods are optimized, and possibly reoptimized more aggressively Because this is the most innovative aspect of HotSpot, it is the main topic of many HotSpot papers.6/29/20097Automatic memory management Memory in heap consists of objects containing pointers to other objects. Objects in heap are accessed in program by using pointers stored in local variables, which are on stack. Therefore, only heap objects that matter are reachableeither directly from stack, or from fields of other either directly from stack, or from fields of other reachable heap objects Objects that are not reachable are called garbage. Automatic memory management attempts to make garbage cells available for allocation.6/29/20098Creation of garbage Example:let f n y = let x = numbers 1 n (* list [1;2;…;n] *)in x@yCreates n“cons cells” of garbage, because x@y makes a Creates n“cons cells” of garbage, because x@y makes a copy of x.6/29/20099Representing free memory Alternatives: free list or free area Free list: Free memory is placed on a linked list. Request for memory iterates over list looking for big enough memory area. Free area: Unused area of memory reserved for allocation. Memory allocated from bottom of this area.Will discuss free list representation firstWill discuss free list representation first6/29/200910History of heap object, using “free list” system Heap contains: Data that have been allocated Data on free listin usefree6/29/200911(Pointers from stack, and between reachable cells are not shown.)free list pointerHistory of heap object, using “free list” system Program executes: x = new C(); or x = malloc(); or x = a::b(x a local variable of function f)6/29/200912free list pointerHistory of heap object, using “free list” system Return from f. Assume no other objects point to the new object. New object no longer reachablefrom stacklonger reachable (but not allocatable either)6/29/200913free list pointerstackHistory of heap object, using “free list” systemEventually, object is returned to free list6/29/200914free list pointerThree types of memory cellsAllocatable – i.e., on free list Initially contains all cellsReachable Obtained by request for heap memory Still reachable from stack (possibly via other heap objects)NeitherNeither Once reachable, now not –e.g., was reachable from a local variable of function f, but have returned from f Was not returned to free list “Neither” category is most interesting – memory could be made allocatable.6/29/200915Reference counting Use free list Track number of pointers to every object Adjust count each time a pointer is copied/assigned“p = q”: Increment refcnt(*q)Decrement refcnt(*p)Decrement refcnt(*p)if refcnt(*p)=0 then return *p to free listand decrement refcnt of allobjects that *p points toAll objects go to free list as soon as they are non-reachable – no “neither” category6/29/200916Reference counting (cont.) Advantages Cost spread out over computation Disadvantages Cannot easily handle cycles among objects (which occur a lot)216/29/2009172111remove pointerGarbage collection Two methods Non-copying (mark-and-sweep) Uses free list representation Copying Uses free area representationUnlike reference-counting:Unlike reference-counting: Cells go into “neither” category temporarily Are recovered all at once Costs vary according to method, but happen all at once – “GC pause” – and are not amortized6/29/200918Non-copying garbage collection Use free list Reserve one bit in each object header, called the “reachable” bit Start with reachable bit zero in every headerTraverse reachable data, setting reachable bitTraverse reachable data, setting reachable bit Iterate over entire heap. If reachable bit is 1, reset it; if it is zero, place that memory chunk on free listObservations Reachable data is not moved Reachable data remains spread across memory


View Full Document

U of I CS 421 - Run-time systems and garbage collection

Documents in this Course
Lecture 2

Lecture 2

12 pages

Exams

Exams

20 pages

Lecture

Lecture

32 pages

Lecture

Lecture

21 pages

Lecture

Lecture

15 pages

Lecture

Lecture

4 pages

Lecture

Lecture

68 pages

Lecture

Lecture

68 pages

Lecture

Lecture

84 pages

s

s

32 pages

Parsing

Parsing

52 pages

Lecture 2

Lecture 2

45 pages

Midterm

Midterm

13 pages

LECTURE

LECTURE

10 pages

Lecture

Lecture

5 pages

Lecture

Lecture

39 pages

Load more
Download Run-time systems and garbage collection
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Run-time systems and garbage collection and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Run-time systems and garbage collection 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?