48
Welcome to our Presentation Oliver Jessner, Andreas Scheicher University of Salzburg, department of Computer Sciences Garbage Collection in V8 1/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,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Welcome to our Presentation

Oliver Jessner, Andreas Scheicher

University of Salzburg, department of Computer Sciences

Garbage Collection in V8

1 / 1

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

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

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

Modern Garbage Collectors

Cost of execution time circa 5%

Multithreading

Mixed Strategies

3 / 1

Modern Garbage Collectors

Cost of execution time circa 5%

Multithreading

Mixed Strategies

3 / 1

Modern Garbage Collectors

Cost of execution time circa 5%

Multithreading

Mixed Strategies

3 / 1

How does a Object Graph look like?

root

obj1

obj2

obj3

obj4

obj5

4 / 1

Now a dereference takes place

root

obj1

obj2

obj3

obj4

obj5

X

5 / 1

The Objects can not be reached from the root node

root

obj1

obj2

obj3

obj4

obj5

6 / 1

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

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

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

What kind of Garbage Collector are existing?

Tracing Garbage Collection

1 Mark and Sweep2 Generational Garbage Collection

Reference counting

10 / 1

What kind of Garbage Collector are existing?

Tracing Garbage Collection

1 Mark and Sweep2 Generational Garbage Collection

Reference counting

10 / 1

What kind of Garbage Collector are existing?

Tracing Garbage Collection

1 Mark and Sweep2 Generational Garbage Collection

Reference counting

10 / 1

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

Which Garbage Collector is used in V8?

State of the art GenerationalGarbage Collection

12 / 1

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

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

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

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

More generations less Stop-the-World interrupts

80% die young

Young Generation

20% survive

Old Generation

14 / 1

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

Young Generation

Fast collection

Frequent collection

Needs more space

15 / 1

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

Young Generation

Fast collection

Frequent collection

Needs more space

15 / 1

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

Young Generation

Fast collection

Frequent collection

Needs more space

15 / 1

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

To Space

From Space

a b c d e

16 / 1

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

To Space

From Space

a

b c d e

16 / 1

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

To Space

From Space

a b

c d e

16 / 1

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

To Space

From Space

a b c

d e

16 / 1

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

To Space

From Space

a b c d

e

16 / 1

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

To Space

From Space

a b c d e

16 / 1

Now the mark phase startsKeyword, Mark and Copy

To Space

From Space

a b c d

a c

17 / 1

Now the mark phase startsKeyword, Mark and Copy

To Space

From Space

a b c d

a c

17 / 1

Delete toSpaceKeyword, Mark and Copy

To Space

From Space

a c

a c

18 / 1

Delete toSpaceKeyword, Mark and Copy

To Space

From Space

a c

a c

18 / 1

Delete fromSpaceKeyword, Mark and Copy

To Space

From Space

a c

e

19 / 1

Delete fromSpaceKeyword, Mark and Copy

To Space

From Space

a c e

19 / 1

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

Old Generation

Slower collection

Infrequent collection

Needs less space

20 / 1

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

Old Generation

Slower collection

Infrequent collection

Needs less space

20 / 1

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

Old Generation

Slower collection

Infrequent collection

Needs less space

20 / 1

Keyword Mark and Compact

free live

21 / 1

Keyword Mark and Compact

free live

22 / 1

Keyword Mark and Compact

free live

23 / 1

There is one big flaw with GenerationsIntergenerational References

yObj

Young Generation

array[..., yObj]

Old Generation

24 / 1

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

null

Young Generation

array[..., yObj]

Old Generation

25 / 1

There is one big flaw with GenerationsIntergenerational References

null

Young Generation

array [..., yObj ], yObj

Old Generation

26 / 1

Thank you for your attention

Any further questions?

27 / 1