Top Banner
Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg, department of Computer Sciences Garbage Collection in V8 1/1
48

Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Jul 04, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Welcome to our Presentation

Oliver Jessner, Andreas Scheicher

University of Salzburg, department of Computer Sciences

Garbage Collection in V8

1 / 1

Page 2: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What is V8 and what is a Garbage Collector?A Garbage Collector is a program that produces dangling pointers

V8 is the JavaScript Engine of Node.js, in all variants ofChromium and Opera.

V8 is developed by Google and the Open Source Community

A Garbage Collector is a program that provides automaticmemory management.

2 / 1

Page 3: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What is V8 and what is a Garbage Collector?A Garbage Collector is a program that produces dangling pointers

V8 is the JavaScript Engine of Node.js, in all variants ofChromium and Opera.

V8 is developed by Google and the Open Source Community

A Garbage Collector is a program that provides automaticmemory management.

2 / 1

Page 4: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What is V8 and what is a Garbage Collector?A Garbage Collector is a program that produces dangling pointers

V8 is the JavaScript Engine of Node.js, in all variants ofChromium and Opera.

V8 is developed by Google and the Open Source Community

A Garbage Collector is a program that provides automaticmemory management.

2 / 1

Page 5: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Modern Garbage Collectors

Cost of execution time circa 5%

Multithreading

Mixed Strategies

3 / 1

Page 6: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Modern Garbage Collectors

Cost of execution time circa 5%

Multithreading

Mixed Strategies

3 / 1

Page 7: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Modern Garbage Collectors

Cost of execution time circa 5%

Multithreading

Mixed Strategies

3 / 1

Page 8: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

How does a Object Graph look like?

root

obj1

obj2

obj3

obj4

obj5

4 / 1

Page 9: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Now a dereference takes place

root

obj1

obj2

obj3

obj4

obj5

X

5 / 1

Page 10: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

The Objects can not be reached from the root node

root

obj1

obj2

obj3

obj4

obj5

6 / 1

Page 11: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

How does a Simple Garbage Collector work?

1 var new = function(ref){

2 ref = allocate ();

34 if(ref === null){

5 mark();

6 sweep();

7 ref = allocate ();

8 }

910 if(ref === null)

11 throw new outOfMemoryException ();

12 }

7 / 1

Page 12: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Mark

1 var mark = function (){

2 var ref;

3 for(var obj : heap){

4 ref = obj.address;

56 if(ref && ref.Unmarked){

7 ref.mark();

8 recursiveMark(ref);

9 }

10 }

11 }

8 / 1

Page 13: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Sweep

1 var sweep = function (){

2 foreach(var obj : heap){

3 if(obj.isMarked)

4 obj.UnMark ();

5 else

6 free(obj);

7 }

8 }

9 / 1

Page 14: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What kind of Garbage Collector are existing?

Tracing Garbage Collection

1 Mark and Sweep2 Generational Garbage Collection

Reference counting

10 / 1

Page 15: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What kind of Garbage Collector are existing?

Tracing Garbage Collection

1 Mark and Sweep2 Generational Garbage Collection

Reference counting

10 / 1

Page 16: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What kind of Garbage Collector are existing?

Tracing Garbage Collection

1 Mark and Sweep2 Generational Garbage Collection

Reference counting

10 / 1

Page 17: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Which techniques are used in modern languages?

Tracing Garbage Collection (JavaScript, Python, Ruby, Rust,C#)

1 Mark and Sweep2 Generational Garbage Collection

Reference counting (C++, PHP, Perl, Vala)

11 / 1

Page 18: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Which Garbage Collector is used in V8?

State of the art GenerationalGarbage Collection

12 / 1

Page 19: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Generational Garbage CollectionWhat is the difference?

Divides the heap into more heaps (V8 uses two generations)

More generations lead to less interruption times

Mark and Copy/Semi Space

Mark and Compact

13 / 1

Page 20: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Generational Garbage CollectionWhat is the difference?

Divides the heap into more heaps (V8 uses two generations)

More generations lead to less interruption times

Mark and Copy/Semi Space

Mark and Compact

13 / 1

Page 21: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Generational Garbage CollectionWhat is the difference?

Divides the heap into more heaps (V8 uses two generations)

More generations lead to less interruption times

Mark and Copy/Semi Space

Mark and Compact

13 / 1

Page 22: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Generational Garbage CollectionWhat is the difference?

Divides the heap into more heaps (V8 uses two generations)

More generations lead to less interruption times

Mark and Copy/Semi Space

Mark and Compact

13 / 1

Page 23: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

More generations less Stop-the-World interrupts

80% die young

Young Generation

20% survive

Old Generation

14 / 1

Page 24: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What are the differences between the Old- and Young-generation?

Young Generation

Fast collection

Frequent collection

Needs more space

15 / 1

Page 25: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What are the differences between the Old- and Young-generation?

Young Generation

Fast collection

Frequent collection

Needs more space

15 / 1

Page 26: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What are the differences between the Old- and Young-generation?

Young Generation

Fast collection

Frequent collection

Needs more space

15 / 1

Page 27: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Why is the collection of the Young Generation faster?Keyword, Mark and Copy

To Space

From Space

a b c d e

16 / 1

Page 28: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Why is the collection of the Young Generation faster?Keyword, Mark and Copy

To Space

From Space

a

b c d e

16 / 1

Page 29: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Why is the collection of the Young Generation faster?Keyword, Mark and Copy

To Space

From Space

a b

c d e

16 / 1

Page 30: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Why is the collection of the Young Generation faster?Keyword, Mark and Copy

To Space

From Space

a b c

d e

16 / 1

Page 31: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Why is the collection of the Young Generation faster?Keyword, Mark and Copy

To Space

From Space

a b c d

e

16 / 1

Page 32: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Why is the collection of the Young Generation faster?Keyword, Mark and Copy

To Space

From Space

a b c d e

16 / 1

Page 33: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Now the mark phase startsKeyword, Mark and Copy

To Space

From Space

a b c d

a c

17 / 1

Page 34: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Now the mark phase startsKeyword, Mark and Copy

To Space

From Space

a b c d

a c

17 / 1

Page 35: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Delete toSpaceKeyword, Mark and Copy

To Space

From Space

a c

a c

18 / 1

Page 36: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Delete toSpaceKeyword, Mark and Copy

To Space

From Space

a c

a c

18 / 1

Page 37: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Delete fromSpaceKeyword, Mark and Copy

To Space

From Space

a c

e

19 / 1

Page 38: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Delete fromSpaceKeyword, Mark and Copy

To Space

From Space

a c e

19 / 1

Page 39: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What are the differences between the Old- and Young-generation?

Old Generation

Slower collection

Infrequent collection

Needs less space

20 / 1

Page 40: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What are the differences between the Old- and Young-generation?

Old Generation

Slower collection

Infrequent collection

Needs less space

20 / 1

Page 41: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

What are the differences between the Old- and Young-generation?

Old Generation

Slower collection

Infrequent collection

Needs less space

20 / 1

Page 42: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Keyword Mark and Compact

free live

21 / 1

Page 43: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Keyword Mark and Compact

free live

22 / 1

Page 44: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Keyword Mark and Compact

free live

23 / 1

Page 45: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

There is one big flaw with GenerationsIntergenerational References

yObj

Young Generation

array[..., yObj]

Old Generation

24 / 1

Page 46: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Now the Young Generation gets collectedWe have a null reference in the Old Generation

null

Young Generation

array[..., yObj]

Old Generation

25 / 1

Page 47: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

There is one big flaw with GenerationsIntergenerational References

null

Young Generation

array [..., yObj ], yObj

Old Generation

26 / 1

Page 48: Welcome to our Presentation - Uni Salzburgheld/teaching/wiss_arbeiten/slides_14-15/v8.pdf · Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg,

Thank you for your attention

Any further questions?

27 / 1