Object swapping issues and the imagesegment implementation

57
Object Swapping Issues and the ImageSegment implementation RMod 1 Ing. mariano martinez peck [email protected] Saturday, November 13, 2010

description

Presentation of the research paper entitled "Experiments with a Fast Object Swapper" in Smalltalks 2010, Concepción del Uruguay, Argentina.

Transcript of Object swapping issues and the imagesegment implementation

Page 1: Object swapping issues and the imagesegment implementation

Object Swapping Issues and the ImageSegment

implementation

RMod

1

I n g . m a r i a n o m a r t i n e z p e c km a r i a n o p e c k @ g m a i l . c o m

Saturday, November 13, 2010

Page 2: Object swapping issues and the imagesegment implementation

The context

2

Saturday, November 13, 2010

Page 3: Object swapping issues and the imagesegment implementation

The context

2

Saturday, November 13, 2010

Page 4: Object swapping issues and the imagesegment implementation

The context

2

Saturday, November 13, 2010

Page 5: Object swapping issues and the imagesegment implementation

The context

2

Saturday, November 13, 2010

Page 6: Object swapping issues and the imagesegment implementation

The context

2

Saturday, November 13, 2010

Page 7: Object swapping issues and the imagesegment implementation

Problem

Use more memory than needed.

Make OOP languages unsuitable for memory limited devices.

Existence of unused but referenced objects.

3

Saturday, November 13, 2010

Page 8: Object swapping issues and the imagesegment implementation

The contextIn OOP primary memory is represented by an object graph

A B C

D E F G H

Y

K

X

I LJ

Z

4

Saturday, November 13, 2010

Page 9: Object swapping issues and the imagesegment implementation

Garbage CollectorOnly collects objects that nobody else points to.

A B C

D E F G H

Y

K

X

I LJ

Z

5

Saturday, November 13, 2010

Page 10: Object swapping issues and the imagesegment implementation

Garbage CollectorOnly collects objects that nobody else points to.

A B C

D E F G H

Y

K

X

I LJ

Z

5

Saturday, November 13, 2010

Page 11: Object swapping issues and the imagesegment implementation

Garbage CollectorOnly collects objects that nobody else points to.

A B C

D E F G H

Y

K

X

I LJ

Z

5

Saturday, November 13, 2010

Page 12: Object swapping issues and the imagesegment implementation

Garbage CollectorOnly collects objects that nobody else points to.

A B C

D E F G H

Y

K

X

I LJ

Z

5

Saturday, November 13, 2010

Page 13: Object swapping issues and the imagesegment implementation

6

But...what happens with referenced yet unused objects?

A B C

D E F G H

Y

K

X

I LJ

Z

Saturday, November 13, 2010

Page 14: Object swapping issues and the imagesegment implementation

Idea

Swap out (not remove) unused objects to disk.

Automatically load them back when needed.

7

Saturday, November 13, 2010

Page 15: Object swapping issues and the imagesegment implementation

There are related works...but no one solves all the problems

8

Saturday, November 13, 2010

Page 16: Object swapping issues and the imagesegment implementation

Main challenges

Not to use more memory than the one released by swapping.

Low overhead penalty.

Group objects in an smart way.

9

Saturday, November 13, 2010

Page 17: Object swapping issues and the imagesegment implementation

Key aspects

Mark and trace unused/used objects at runtime.

The usage of proxies.

Group unused objects (subgraphs).

10

Saturday, November 13, 2010

Page 18: Object swapping issues and the imagesegment implementation

Why we need to group objects?

Because if we replace each object by a proxy, we release little memory.

We want to replace a whole group by one or a few proxies.

11

Saturday, November 13, 2010

Page 19: Object swapping issues and the imagesegment implementation

Why subgraphs?

Group of objects that are used (or not used) together.

We need few proxies (for the roots) for several objects.

12

Saturday, November 13, 2010

Page 20: Object swapping issues and the imagesegment implementation

Experiments done

Modify Smalltalk VM to mark and trace objects usage.

Visualize objects and memory usage.

Take statistics from different scenarios.

13

Saturday, November 13, 2010

Page 21: Object swapping issues and the imagesegment implementation

deployed web application example

14

Saturday, November 13, 2010

Page 22: Object swapping issues and the imagesegment implementation

deployed web application example

4%

96%

Amount of objects

Used Unused

14

Saturday, November 13, 2010

Page 23: Object swapping issues and the imagesegment implementation

deployed web application example

4%

96%

Amount of objects

Used Unused

15%

85%

Amount of memory

Used Unused

14

Saturday, November 13, 2010

Page 24: Object swapping issues and the imagesegment implementation

Swapping steps and challenges

1.Identify sets of objects and serialize them. Problems: cycles, speed, etc.

2.Write the serialized objects into a file. Problems: file format, encoding, speed, etc.

3. Load the objects from a file. Problems: class reshape, avoid duplicates, speed, etc.

15

Saturday, November 13, 2010

Page 25: Object swapping issues and the imagesegment implementation

Subgraphs

16

A (Root)

B (Root)

C (Root)

D E F G H

Y

K

X

I LJ

Subgraph to process

Z

Roots Inner Shared External

Saturday, November 13, 2010

Page 26: Object swapping issues and the imagesegment implementation

More problems

Should shared objects be included or not?

GC moves objects.

Pointers update.

Class changes.

Recreate and reinitialize objects.

Code executed after loading.

Special objects.17

A (Root)

B (Root)

C (Root)

D E F G H

Y

K

X

I LJ

Subgraph to process

Z

Roots Inner Shared External

Saturday, November 13, 2010

Page 27: Object swapping issues and the imagesegment implementation

ImageSegment

Saturday, November 13, 2010

Page 28: Object swapping issues and the imagesegment implementation

ImageSegment basis Only write/swap roots and inner objects.

Shared objects are NOT swapped.

Keep an array in memory for the shared objects.

Update object pointers to point to a relative address inside the arrays (offset).

Roots are replaced by proxies.

Uses GC facilities to detect shared objects.

Saturday, November 13, 2010

Page 29: Object swapping issues and the imagesegment implementation

The goal

Input -- Output

A CB

D E F G H

I J K L

Saturday, November 13, 2010

Page 30: Object swapping issues and the imagesegment implementation

The goal

Input -- OutputD F G

J K

P1 P3P2

Saturday, November 13, 2010

Page 31: Object swapping issues and the imagesegment implementation

The goal

Input -- OutputD F G

J K

P1 P3P2

aMessage

Saturday, November 13, 2010

Page 32: Object swapping issues and the imagesegment implementation

The goal

Input -- Output

A CB

D E F G H

I J K L

Saturday, November 13, 2010

Page 33: Object swapping issues and the imagesegment implementation

Simple example

Saturday, November 13, 2010

Page 34: Object swapping issues and the imagesegment implementation

Subgraph traverse

Saturday, November 13, 2010

Page 35: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 36: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 37: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 38: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 39: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 40: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’D

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 41: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’D

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 42: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’D

offsetSerialized objects WordArray

Shared objects Array

anImageSegment

Saturday, November 13, 2010

Page 43: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’ E’D

offsetSerialized objects WordArray

Shared objects Array

anImageSegment

Saturday, November 13, 2010

Page 44: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’ E’D

offset

offset

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 45: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’ E’D

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 46: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’ E’D

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 47: Object swapping issues and the imagesegment implementation

Subgraph traverse

A CB

D E F G H

I J K L

A’ B’ C’ E’F GD J

I’ H’ L’

Serialized objects WordArrayShared objects Array

anImageSegment

Saturday, November 13, 2010

Page 48: Object swapping issues and the imagesegment implementation

A CB

D E F G H

I J K L

A’ B’ C’ E’F GD J

I’ H’ L’

Serialized objects WordArrayShared objects Array

Offset Memory address

Saturday, November 13, 2010

Page 49: Object swapping issues and the imagesegment implementation

Roots replace

Saturday, November 13, 2010

Page 50: Object swapping issues and the imagesegment implementation

A CB

D E F G H

I J K L

A’ B’ C’ E’ F GD JI’ H’ L’

Serialized objects WordArray Shared objects Array

anImageSegment

Saturday, November 13, 2010

Page 51: Object swapping issues and the imagesegment implementation

D E F G H

I J K L

A’ B’ C’ E’ F GD JI’ H’ L’

Serialized objects WordArray Shared objects Array

anImageSegment

P1 P3P2

Saturday, November 13, 2010

Page 52: Object swapping issues and the imagesegment implementation

D F G

J K

A’ B’ C’ E’ F GD JI’ H’ L’

Serialized objects WordArray Shared objects Array

anImageSegment

P1 P3P2

Saturday, November 13, 2010

Page 53: Object swapping issues and the imagesegment implementation

Write to file

Saturday, November 13, 2010

Page 54: Object swapping issues and the imagesegment implementation

CB

D F G

J K

A’ B’ C’ E’ I’ H’ L’

Serialized objects WordArray

F GD J

Shared objects Array

anImageSegment

P1 P3P2Binary file

Saturday, November 13, 2010

Page 55: Object swapping issues and the imagesegment implementation

CB

D F G

J K

F GD J

Shared objects Array

anImageSegment

P1 P3P2Binary file

A’ B’ C’ E’ I’ H’ L’

NIL

Saturday, November 13, 2010

Page 56: Object swapping issues and the imagesegment implementation

ImageSegment conclusions

Good speed.

Graph traverse is done in VM side.

Good use of GC facilities.

You have to be aware of shared objects.

Bad granularity level.

Implicit needed information in object graphs.

Saturday, November 13, 2010

Page 57: Object swapping issues and the imagesegment implementation

Thanks!

Mariano Martinez [email protected]

RMod

Saturday, November 13, 2010