Application-Level
  Virtual Memory for
Object-Oriented Systems
     Mariano Martinez Peck




                             1
Application-Level
  Virtual Memory for
Object-Oriented Systems
     Mariano Martinez Peck




                             2
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        3
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        3
Context




          4
Context




          4
Context




          4
Context




          4
Context




          4
Context




          4
We need to optimize
memory management


                      5
Context
• Object-oriented programming. Why?
     Most modern and widespread.
     Memory is usually automatically managed (GC).
• Dynamic languages. Why?
     Powerful.
     More and more used.

                                                     6
In this context of OOP,
is GC actually enough to
    optimize memory
      management?

                           7
% used objects ?     % used memory ?
% unused objects ?   % unused memory ?




                                    8
% used objects     % used memory
                                 % unused objects   % unused memory


        (web app + CMS)




 (standalone + lots of tools + large)
(174 pack. 1364 class. 121010 LOC)




            (mobile app)




         (infrastructure)
                                                                  8
% used objects     % used memory
                                 % unused objects   % unused memory
                                              19%            29%

        (web app + CMS)                 81%            71%


                                              18%            27%
 (standalone + lots of tools + large)
(174 pack. 1364 class. 121010 LOC)                     73%
                                        82%

                                              23%
                                                      54%    46%
                                        77%
            (mobile app)

                                          10%
                                                             37%
                                                       63%
         (infrastructure)                90%                       8
% used objects     % used memory
                                 % unused objects   % unused memory
                                              19%            29%

        (web app + CMS)                 81%            71%


                                              18%            27%
 (standalone + lots of tools + large)
(174 pack. 1364 class. 121010 LOC)                     73%
                                        82%

                                              23%
                                                      54%    46%
                                        77%
            (mobile app)

                                          10%
     In average, %80 of the                                  37%
     objects are unused.90%                            63%
        (infrastructure)
                                                                   8
% used objects           % used memory
                                 % unused objects         % unused memory
                                              19%                   29%

        (web app + CMS)                 81%                   71%


                                              18%                   27%
 (standalone + lots of tools + large)
(174 pack. 1364 class. 121010 LOC)                            73%
                                        82%

                                              23%
                                                             54%    46%
                                        77%
            (mobile app)

                                          10%
     In average, %80 of the                         In average, 77% 37%the
                                                                    of
     objects are unused.90%                          memory is63% unused.
        (infrastructure)
                                                                             8
Unused objects
   Referenced.
   GC cannot collect them!
   Waste primary memory.




                             9
Unused objects
   Referenced.
   GC cannot collect them!
   Waste primary memory.




    No, the GC is not enough
                               9
OS’ Virtual Memory is
   not the answer

• It only swaps pages.
• Developers cannot easily influence it.

                                          10
Thesis statement
A virtual memory for dynamic OOP languages
should be:
   Application-aware
   Efficient




                                             11
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        12
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        12
A model for efficient application-level virtual
  memory:
• Designed for dynamic OOP
• Based on the swapping of object graphs


                                                   13
Primary memory




                Swap out             Swap in
              unused object       needed object
                 graphs               graphs

Secondary memory


                                        cloud

        file            database
                                                  14
Primary memory




                Swap out             Swap in
              unused object       needed object
                 graphs               graphs

Secondary memory


                                        cloud

        file            database
                                                  14
Primary memory

                   Y       A
                       B       C

                       E       F


Secondary memory




                                   15
Primary memory

                   Y             A
                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory




                                                           15
Primary memory

                   Y             A
                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           15
Primary memory

                   Y             A
                                 Pa


                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           15
Primary memory

                   Y             Pa




              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           15
Primary memory

                   Y          Pa




Secondary memory




                       bytes (A,B,C,E,F)
                                           15
Primary memory

                   Y          Pa




Secondary memory




                       bytes (A,B,C,E,F)
                                           15
Primary memory

                   Y          Pa




                          Memory
                          Released


Secondary memory




                       bytes (A,B,C,E,F)
                                           15
Primary memory

                   Y          Pa




                          Memory
                          Released


Secondary memory

                               Swap in


                       bytes (A,B,C,E,F)
                                           15
Primary memory

                   Y       A
                       B       C

                       E       F


Secondary memory




                                   15
Primary memory

                   Y       A
                       B       C

                       E       F


Secondary memory




                                   16
Primary memory

                   Y       A       D

                       B       C

                       E       F


Secondary memory




                                       16
Primary memory

                   Y             A                D

                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory




                                                           16
Primary memory

                   Y             A                D

                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           16
Primary memory

                   Y             A
                                 Pa               D

                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           16
Primary memory

                   Y             Pa               D

                                       C

                             E
              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           16
Primary memory

                   Y           Pa          D

                                    C

                           E


Secondary memory




                       bytes (A,B,C,E,F)
                                               16
Primary memory

                   Y           Pa          D

                                    C

                           E


Secondary memory




                       bytes (A,B,C,E,F)
                                               16
Primary memory

                   Y           Pa          D

                                    C

                           E


Secondary memory

                                Swap in


                       bytes (A,B,C,E,F)
                                               16
Primary memory

                   Y           Pa          D

                                    C

                           E


Secondary memory

                                Swap in


                       bytes (A,B,C,E,F)
                                               16
Primary memory

                   Y           Pa          D

                                    C

                           E


Secondary memory

                                Swap in


                       bytes (A,B,C,E,F)
                                               16
Primary memory

                   Y         A       D

                        B    C   C

                       E E       F


Secondary memory




                                         16
Primary memory

                   Y         A       D

                        B    C   C

                       E E       F


Secondary memory




                                         16
Primary memory

                   Y         A       D

                        B    C   C

                       E E       F


Secondary memory




            INCORRECT!!!                 16
Objectives

Correctness: SwapIn(SwapOut(X))==X
Maximize memory released.
Minimize runtime overhead.




                                     17
subsystems

   Object
   Graph          Proxy
  Swapper        Toolbox


                 Object
Object Graph
                  Graph
 Serializer
                 Storage

                            18
Primary memory

                   Y       A       D

                       B       C

                       E       F


Secondary memory




                                       19
Primary memory

                   Y             A                D

                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory




                                                           19
Primary memory

                   Y             A                D

                            B          C

                             E        F
              Memory occupied by graph of unused objects

Secondary memory

                 Swap out


                        bytes (A,B,C,E,F)
                                                           19
Primary memory

                    Y              A                D

                              B          C
   facade objects
                               E        F
                Memory occupied by graph of unused objects

Secondary memory

                    Swap out


                          bytes (A,B,C,E,F)
                                                             19
Primary memory

                    Y              A
                                   Pa               D

                              B          C
                                         Pc

   facade objects
   proxy                       E        F
                Memory occupied by graph of unused objects

Secondary memory

                    Swap out


                          bytes (A,B,C,E,F)
                                                             19
Primary memory

                    Y              Pa               D
                                          Pc

   facade objects
   proxy
                Memory occupied by graph of unused objects

Secondary memory

                    Swap out


                          bytes (A,B,C,E,F)
                                                             19
Primary memory

                    Y          Pa           D
                                     Pc

   facade objects
   proxy


Secondary memory




                        bytes (A,B,C,E,F)
                                                19
Primary memory

                    Y          Pa           D
                                     Pc

   facade objects
   proxy


Secondary memory




                        bytes (A,B,C,E,F)
                                                19
Primary memory

                    Y          Pa           D
                                     Pc

   facade objects
   proxy


Secondary memory

                                Swap in


                        bytes (A,B,C,E,F)
                                                19
Primary memory

                    Y       A       D

                        B       C
   facade objects
   proxy                E       F


Secondary memory




                                        19
How to efficiently detect
 and manage facade objects?

• Back-pointers.
• Whole memory scan.   Y       A       D

                           B       C

                           E       F
                                       20
How to efficiently detect
 and manage facade objects?

• Back-pointers.
• Whole memory scan.   Y       A       D

                           B       C

 Marea provides an
                           E       F
 efficient solution.
                                       20
Primary memory     Swapping out
        A          D
                          GraphTable
    B       C



Secondary memory




                                       21
Primary memory     Swapping out
        A          D
                          GraphTable
    B       C



Secondary memory




                                       21
Primary memory         Swapping out
        Graph ID: 42

        A              D
                                     GraphTable
    B        C



Secondary memory           1) Assign graph ID




                                                  21
Primary memory          Swapping out
        Graph ID: 42

        A               D
                                        GraphTable
    B           C



Secondary memory             1) Assign graph ID
                            2) Serialize the object graph
         B’ A’ C’
            1   2   3


            42.swap
                                                            21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                   A Pa       GraphTable
     B           C                 B Pb
         Pb
         42 1                      C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’
             1   2      3


             42.swap
                                                                     21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                   A Pa       GraphTable
     B           C                 B Pb
         Pb
         42 1                      C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’
             1   2      3


             42.swap
                                                                     21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                   A Pa       GraphTable
     B           C                 B Pb
         Pb
         42 1                      C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’
             1   2      3


             42.swap
                                                                     21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                   A Pa       GraphTable
     B           C                 B Pb
         Pb
         42 1                      C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3


             42.swap
                                                                         21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                   A Pa       GraphTable
     B           C                 B Pb
         Pb
         42 1                      C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3


             42.swap
                                                                         21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                  Pa A        GraphTable
     B           C                B Pb
         Pb
         42 1                     C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3


             42.swap
                                                                         21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                  Pa A        GraphTable
     B           C                Pb B
         Pb
         42 1                     C Pc
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3


             42.swap
                                                                         21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc         D
  42 2   A       42 3
                                  Pa A        GraphTable
     B           C                Pb B
         Pb
         42 1                     Pc C
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3


             42.swap
                                                                         21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc                               42          Pa Pb Pc
         A                  D                                  (weak array)
  42 2           42 3
                                  Pa A        GraphTable
     B           C                Pb B
         Pb
         42 1                     Pc C
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3
                                   5) Update GraphTable

             42.swap
                                                                          21
Primary memory              Swapping out
         Graph ID: 42
  Pa             Pc                               42          Pa Pb Pc
         A                  D                                  (weak array)
  42 2           42 3
                                  Pa A        GraphTable
     B           C                Pb B
         Pb
         42 1                     Pc C
                                proxiesDict
Secondary memory                    1) Assign graph ID
                                   2) Serialize the object graph
                                   3) Create and associate proxies
            B’ A’ C’               4) Replace original objects with proxies
             1   2      3
                                   5) Update GraphTable
                                   6) GC runs
             42.swap
                                                                          21
Primary memory          Swapping out
  Pa         Pc                            42          Pa nil Pc
                        D                               (weak array)
  42 2       42 3
                            Pa A       GraphTable
                            Pb B
                            Pc C

Secondary memory             1) Assign graph ID
                            2) Serialize the object graph
                            3) Create and associate proxies
         B’ A’ C’           4) Replace original objects with proxies
         1   2      3
                            5) Update GraphTable
                            6) GC runs
         42.swap
                                                                   21
Primary memory          Swapping out
  Pa         Pc                            42          Pa nil Pc
                        D                               (weak array)
  42 2       42 3
                            Pa A       GraphTable
                            Pb B
                            Pc C

Secondary memory             1) Assign graph ID
                            2) Serialize the object graph
                            3) Create and associate proxies
         B’ A’ C’           4) Replace original objects with proxies
         1   2      3
                            5) Update GraphTable
                            6) GC runs
         42.swap            7) Compact (optional)
                                                                   21
Primary memory          Swapping out
  Pa         Pc                            42          Pa Pc
                        D                               (weak array)
  42 2       42 3
                            Pa A       GraphTable
                            Pb B
                            Pc C

Secondary memory             1) Assign graph ID
                            2) Serialize the object graph
                            3) Create and associate proxies
         B’ A’ C’           4) Replace original objects with proxies
         1   2      3
                            5) Update GraphTable
                            6) GC runs
         42.swap            7) Compact (optional)
                                                                   21
Primary memory
                        Swapping in
   Pa            Pc     D         42         Pa Pc
  42 2           42 3                        (weak array)

                                GraphTable




Secondary memory


         B’ A’ C’
         1   2      3


         42.swap
                                                       22
Primary memory
                        Swapping in
   Pa            Pc     D                      42           Pa Pc
  42 2           42 3                                      (weak array)

                                            GraphTable




Secondary memory            0) A proxy intercepts a message...


         B’ A’ C’
         1   2      3


         42.swap
                                                                     22
Primary memory
                        Swapping in
   Pa            Pc     D                      42           Pa Pc
  42 2           42 3                                      (weak array)

                                            GraphTable




Secondary memory            0) A proxy intercepts a message...


         B’ A’ C’
         1   2      3


         42.swap
                                                                     22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                                                       1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph

          B’ A’ C’
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable

                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable
                                 Pa A’
                                                      B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable
                                 Pa A’
                                 Pc C’                B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3


          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable
                                 Pa A’
                                 Pc C’                B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3       3) Replace proxies with original objects

          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable
                                 A’ Pa
                                 Pc C’                B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3       3) Replace proxies with original objects

          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable
                                 A’ Pa
                                 C’ Pc                B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3       3) Replace proxies with original objects

          42.swap
                                                                         22
Primary memory
                         Swapping in
   Pa             Pc     D                      42             Pa Pc
  42 2   A’       42 3                                         (weak array)

    B’        C’                             GraphTable
                                 A’ Pa
                                 C’ Pc                B’ A’ C’
                              proxiesDict              1   2      3
                                               materializedObjects
Secondary memory             0) A proxy intercepts a message...
                             1) Materialize the object graph
                             2) Associate proxies with
          B’ A’ C’           materialized objects
          1   2      3       3) Replace proxies with original objects
                             4) Clean
          42.swap
                                                                         22
Primary memory
                     Swapping in
   Pa          Pc    D
  42 2   A’   42 3

    B’        C’                         GraphTable

                             C’ Pc


Secondary memory         0) A proxy intercepts a message...
                         1) Materialize the object graph
                         2) Associate proxies with
                         materialized objects
                         3) Replace proxies with original objects
                         4) Clean

                                                                    22
Primary memory
                   Swapping in
         A’        D

    B’        C’                       GraphTable

                           C’ Pc


Secondary memory       0) A proxy intercepts a message...
                       1) Materialize the object graph
                       2) Associate proxies with
                       materialized objects
                       3) Replace proxies with original objects
                       4) Clean
                       5) GC runs
                                                                  22
Primary memory
                   Swapping in
         A’        D

    B’        C’                       GraphTable

                           C’ Pc


Secondary memory       0) A proxy intercepts a message...
                       1) Materialize the object graph
                       2) Associate proxies with
                       materialized objects
                       3) Replace proxies with original objects
                       4) Clean
                       5) GC runs
                       6) Forward message to object             22
Primary memory
                   Swapping in
         A’        D

    B’        C’                       GraphTable

                           C’ Pc


Secondary memory       0) A proxy intercepts a message...
                       1) Materialize the object graph
                       2) Associate proxies with
                       materialized objects
                       3) Replace proxies with original objects
                       4) Clean
                       5) GC runs
                       6) Forward message to object             22
Primary memory
                            Intersections...
                                                Pa Pc
      Pa         Pc     D            42         (weak array)
      42 2       42 3

                                   GraphTable




Secondary memory

 B’ A’ C’
  1      2   3

 42.swap

                                                        23
Primary memory
                            Intersections...
                                                Pa Pc
      Pa         Pc     D            42         (weak array)
      42 2       42 3

                                   GraphTable




Secondary memory

 B’ A’ C’
  1      2   3

 42.swap

                                                        23
Primary memory
                 Graph ID: 43
                                Intersections...
                                                                  Pa Pc
      Pa            Pc      D                          42         (weak array)
      42 2          42 3

                                                     GraphTable




Secondary memory                1) Assign graph ID

 B’ A’ C’
  1      2   3

 42.swap

                                                                          23
Primary memory
                 Graph ID: 43
                                Intersections...
                                                                 Pa Pc
      Pa            Pc      D                           42       (weak array)
      42 2          42 3

                                                    GraphTable




Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
 B’ A’ C’
  1      2   3

 42.swap

                                                                         23
Primary memory
                 Graph ID: 43
                                Intersections...
                                                                 Pa Pc
      Pa            Pc      D                           42       (weak array)
      42 2          42 3

                                                    GraphTable




Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
 B’ A’ C’
  1      2   3

 42.swap

                                                                         23
Primary memory
            Graph ID: 43
                           Intersections...
                                                            Pc
       A’              D

  B’          C’                               GraphTable




Secondary memory           1) Assign graph ID
                           2) Serialize the object graph




                                                             23
Primary memory
            Graph ID: 43
                             Intersections...
                                                              Pc
       A’                D

  B’          C’                                 GraphTable




Secondary memory             1) Assign graph ID
                             2) Serialize the object graph



                D’ C’
                1   2

               43.swap                                         23
Primary memory
            Graph ID: 43
                             Intersections...
                                                              Pc
       A’                D

  B’          C’                                 GraphTable




Secondary memory             1) Assign graph ID
                             2) Serialize the object graph
                             ...) as usually...

                D’ C’
                1   2

               43.swap                                         23
Primary memory
            Graph ID: 43
                           Intersections...
                                                            Pc
       A’              D

  B’          C’                               GraphTable




Secondary memory           1) Assign graph ID
                           2) Serialize the object graph
                           ...) as usually...


       We don’tC’
            D’ want to swap in a graph while
            1   2
            swapping out another one
           43.swap                                           23
Primary memory
                            Intersections...
                                                Pa Pc
      Pa         Pc     D            42         (weak array)
      42 2       42 3

                                   GraphTable




Secondary memory

 B’ A’ C’
  1      2   3

 42.swap

                                                        24
Primary memory
                            Intersections...
                                                Pa Pc
      Pa         Pc     D            42         (weak array)
      42 2       42 3

                                   GraphTable




Secondary memory

 B’ A’ C’
  1      2   3

 42.swap

                                                        24
Primary memory
                 Graph ID: 43
                                  Intersections...
                                                                  Pa Pc
      Pa            Pc      D                          42         (weak array)
      42 2          42 3

                                                     GraphTable




Secondary memory                1) Assign graph ID

 B’ A’ C’
  1      2   3

 42.swap

                                                                          24
Primary memory
                 Graph ID: 43
                                  Intersections...
                                                                         Pa Pc
      Pa               Pc   D                             42            (weak array)
      42 2          42 3

                                                       GraphTable




Secondary memory                1) Assign graph ID
                                2) Serialize the object graph (customize serializer)
 B’ A’ C’
  1      2   3

 42.swap          D’ Pc’
                   1    2

                 43.swap                                                        24
Primary memory
                 Graph ID: 43
                                       Intersections...
                                                                              Pa Pc
      Pa               Pc     D                                42            (weak array)
      42 2          42 3

                       Ppc    Pd                            GraphTable
                       43 2   43 1




Secondary memory                     1) Assign graph ID
                                     2) Serialize the object graph (customize serializer)
 B’ A’ C’                            3) Create and associate proxies
  1      2   3

 42.swap          D’ Pc’
                   1     2

                 43.swap                                                             24
Primary memory
                 Graph ID: 43
                                       Intersections...
                                                                              Pa Pc
      Pa               Pc     D                                42            (weak array)
      42 2          42 3

                       Ppc    Pd                            GraphTable
                       43 2   43 1




Secondary memory                     1) Assign graph ID
                                     2) Serialize the object graph (customize serializer)
 B’ A’ C’                            3) Create and associate proxies
  1      2   3                       4) Replace original objects with proxies
 42.swap          D’ Pc’
                   1     2

                 43.swap                                                             24
Primary memory
                 Graph ID: 43
                                       Intersections...
                                                                              Pa Pc
      Pa               Pc     D                                42            (weak array)
      42 2          42 3

                       Ppc    Pd                            GraphTable
                       43 2   43 1




Secondary memory                     1) Assign graph ID
                                     2) Serialize the object graph (customize serializer)
 B’ A’ C’                            3) Create and associate proxies
  1      2   3                       4) Replace original objects with proxies
 42.swap          D’ Pc’
                   1     2

                 43.swap                                                             24
Primary memory
                 Graph ID: 43
                                       Intersections...
                                                                              Pa Pc
      Pa               Pc     D                                42            (weak array)
      42 2          42 3

                       Ppc    Pd                            GraphTable
                       43 2   43 1




Secondary memory                     1) Assign graph ID
                                     2) Serialize the object graph (customize serializer)
 B’ A’ C’                            3) Create and associate proxies
  1      2   3                       4) Replace original objects with proxies
 42.swap          D’ Pc’
                   1     2

                 43.swap                                                             24
Primary memory
                 Graph ID: 43
                                       Intersections...
                                                                              Pa Pc
      Pa               Pc     D                                42            (weak array)
      42 2          42 3
                                                               43             Pd Ppc
                       Ppc    Pd                            GraphTable
                              43 1                                           (weak array)
                       43 2




Secondary memory                     1) Assign graph ID
                                     2) Serialize the object graph (customize serializer)
 B’ A’ C’                            3) Create and associate proxies
  1      2   3                       4) Replace original objects with proxies
 42.swap                             5) Update GraphTable
                  D’ Pc’
                   1     2

                 43.swap                                                             24
Primary memory
                 Graph ID: 43
                                       Intersections...
                                                                              Pa Pc
      Pa               Pc     D                                42            (weak array)
      42 2          42 3
                                                               43             Pd Ppc
                       Ppc    Pd                            GraphTable
                              43 1                                           (weak array)
                       43 2




Secondary memory                     1) Assign graph ID
                                     2) Serialize the object graph (customize serializer)
 B’ A’ C’                            3) Create and associate proxies
  1      2   3                       4) Replace original objects with proxies
 42.swap                             5) Update GraphTable
                  D’ Pc’             6) GC runs
                   1     2

                 43.swap                                                             24
Primary memory
                                    Intersections...
                                                                           Pa nil
      Pa                                                    42            (weak array)
      42 2
                                                            43             Pd nil
                           Pd                            GraphTable
                           43 1                                           (weak array)




Secondary memory                  1) Assign graph ID
                                  2) Serialize the object graph (customize serializer)
 B’ A’ C’                         3) Create and associate proxies
  1      2   3                    4) Replace original objects with proxies
 42.swap                          5) Update GraphTable
                 D’ Pc’           6) GC runs
                  1   2

                 43.swap                                                          24
Primary memory
                                    Intersections...
                                                                           Pa nil
      Pa                                                    42            (weak array)
      42 2
                                                            43             Pd nil
                           Pd                            GraphTable
                           43 1                                           (weak array)




Secondary memory                  1) Assign graph ID
                                  2) Serialize the object graph (customize serializer)
 B’ A’ C’                         3) Create and associate proxies
  1      2   3                    4) Replace original objects with proxies
 42.swap                          5) Update GraphTable
                 D’ Pc’           6) GC runs
                  1   2           7) Swap in graph 42
                 43.swap                                                          24
Primary memory
                                Intersections...
                                                                            nil
                                                        43             Pd nil
        A’             Pd
                       43 1
                                                     GraphTable       (weak array)

   B’          C’


Secondary memory              1) Assign graph ID
                              2) Serialize the object graph (customize serializer)
                              3) Create and associate proxies
                              4) Replace original objects with proxies
                              5) Update GraphTable
             D’ Pc’           6) GC runs
              1   2           7) Swap in graph 42
             43.swap                                                          24
Primary memory
                                Intersections...
                                                                            nil
                                                        43             Pd nil
        A’             Pd
                       43 1
                                                     GraphTable       (weak array)

   B’          C’


Secondary memory              1) Assign graph ID
                              2) Serialize the object graph (customize serializer)
                              3) Create and associate proxies
                              4) Replace original objects with proxies
                              5) Update GraphTable
             D’ Pc’           6) GC runs
              1   2           7) Swap in graph 42
                              8) Swap in graph 43...
             43.swap                                                          24
Primary memory
                                Intersections...
                                                                            nil
                                                        43             Pd nil
        A’             Pd
                       43 1
                                                     GraphTable       (weak array)

   B’          C’


Secondary memory              1) Assign graph ID
                              2) Serialize the object graph (customize serializer)
                              3) Create and associate proxies
                              4) Replace original objects with proxies
                              5) Update GraphTable
             D’ Pc’           6) GC runs
              1   2           7) Swap in graph 42
                              8) Swap in graph 43...
             43.swap                                                          24
Primary memory
                           Intersections...
                    D’                                                 nil

        A’
                                                GraphTable
   B’        C’   Pc’
                  42 3



Secondary memory         1) Assign graph ID
                         2) Serialize the object graph (customize serializer)
                         3) Create and associate proxies
                         4) Replace original objects with proxies
                         5) Update GraphTable
                         6) GC runs
                         7) Swap in graph 42
                         8) Swap in graph 43...
                                                                        24
Primary memory
                           Intersections...
                    D’                                                 nil

        A’
                                                GraphTable
   B’        C’   Pc’
                  42 3



Secondary memory         1) Assign graph ID
                         2) Serialize the object graph (customize serializer)
                         3) Create and associate proxies
                         4) Replace original objects with proxies
                         5) Update GraphTable
                         6) GC runs
                         7) Swap in graph 42
                         8) Swap in graph 43...
                                                                        24
Primary memory
                           Intersections...
                    D’                                                 nil

        A’
                                                GraphTable
   B’        C’   Pc’
                  42 3



Secondary memory         1) Assign graph ID
                         2) Serialize the object graph (customize serializer)
                         3) Create and associate proxies
                         4) Replace original objects with proxies
                         5) Update GraphTable
                         6) GC runs
              INCORRECT!!!
                         7) Swap in graph 42
                         8) Swap in graph 43...
                                                                        24
Graph intersections
• Avoiding proxies for proxies (Ppc) does not solve
the problem either.
• Several scenarios for swapping in
swapped intersecting graphs.




                                                      25
Graph intersections
• Avoiding proxies for proxies (Ppc) does not solve
the problem either.
• Several scenarios for swapping in
swapped intersecting graphs.



               Marea solves all these
             scenarios and challenges.

                                                      25
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        26
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        26
Experiment
        (web app + CMS)                 1. We swapped out most classes
                                           with their instances.
 (standalone + lots of tools + large)   2. We navigated, used and tested
(174 pack. 1364 class. 121010 LOC)         each application
                                          1. Swapped in all needed
                                             graphs for typical uses.
            (mobile app)                  2. Tests also for correctness.
                                        3. We measured differences.
         (infrastructure)
                                                                           27
Original = 100%   With Marea           Measured minimun
              100


               75
% of memory




               50


               25


                0
                      DBXTalk   Moose        DrGeo         Pharo




                                                                   28
Original = 100%   With Marea           Measured minimun
              100


               75
% of memory




               50


               25


                0
                      DBXTalk   Moose        DrGeo         Pharo


Marea released between 25%
and 40% of the used memory.
                                                                   28
Original = 100%   With Marea           Measured minimun
              100


               75
% of memory




               50


               25


                0
                      DBXTalk   Moose        DrGeo         Pharo


Marea released between 25%                       There is still
and 40% of the used memory.                  room for improvement.
                                                                   28
Speed overhead
• For typical uses is 0%.
• For non covered uses:




                              29
Speed overhead
• For typical uses is 0%.                     Swap in         Swap out
• For non covered uses:            300

                                   225



                       Time (ms)
                                   150

                                   75

                                    0
                                         51     236     777    5758 21753
                                         Graph size (amount of objects)


                                                                         29
Speed overhead
• For typical uses is 0%.                       Swap in         Swap out
• For non covered uses:              300

                                     225



                         Time (ms)
                                     150

                                     75

                                      0
                                           51     236     777    5758 21753
                                           Graph size (amount of objects)

 Swapping in is faster
  than swapping out.                                                       29
Speed overhead
• For typical uses is 0%.                       Swap in         Swap out
• For non covered uses:              300

                                     225



                         Time (ms)
                                     150

                                      75

                                       0
                                           51     236     777    5758 21753
                                           Graph size (amount of objects)

 Swapping in is faster                 The graph size has a small
  than swapping out.                 impact in small/medium graphs.
                                                                  29
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        30
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        30
Comparison criteria
• Efficient object-based swapping unit.
• Uniformity.
• Reversibility.
• Automatic swapping in.
• Automatic swapping out.
• Transparency.
• Controllability at the application level.
• Portability.                                31
Language level and libraries

         Runtimes
OS related




                                        32
Language level and libraries

         Runtimes
OS related




                                        32
Language level and libraries

         Runtimes
OS related




                                        32
Language level and libraries

         Runtimes
OS related




                                        32
Language level and libraries

         Runtimes
OS related




                                        32
Language level and libraries

         Runtimes
OS related




                In progress


                                        32
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        33
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        33
in

   Object            Proxy
   Graph            Toolbox
  Swapper

Object Graph   Object
 Serializer     Graph
               Storage


                              34
• An extensible, uniform and fast serializer.
• General-purpose.
• Used in research and industry.
• Integrated in Pharo 2.0 and ported to Squeak,
  VisualWorks and Newspeak.
• ESUG Innovation Technology Awards 2011.

                                                  35
• An extensible, uniform and fast serializer.
• General-purpose.
• Used in research and industry.
• Integrated in Pharo 2.0 and ported to Squeak,
  VisualWorks and Newspeak.
• ESUG Innovation Technology Awards 2011.
                  Martin Dias, Mariano Martinez Peck, Stéphane Ducasse and
                    Gabriela Arévalo. Fuel: A Fast General Purpose Object
                   Graph Serializer. Software: Practice and Experience, 2012.
                                                                          35
• Proxify all kind of objects.
• Low memory footprint.
• Intercepting all messages.
• Clear division between proxies and handlers.
• General-purpose.

                                                 36
• Proxify all kind of objects.
• Low memory footprint.
• Intercepting all messages.
• Clear division between proxies and handlers.
• General-purpose.
           [Martinez Peck 2012a] Mariano Martinez Peck, Noury Bouraqadi,
          Stéphane Ducasse, Luc Fabresse and Marcus Denker. Ghost: A Uniform
             and Lightweight Proxy Implementation. Science of Computer
            Programming, 2012 (submitted + passed first review round).
                                                                          36
Object replacement
• Provided by regular VM (#become:)
    Specific to Smalltalk.
• Different implementations
    Full memory scan in Pharo VM.
    Object header swapping in VisualWorks VM.
    Object tables’ entries swapping in Gemstone VM.

                                                      37
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        38
Outline
1. Context, problem and introduction.
2. My proposal.
3. Validation.
4. Related work.
5. Implementation.
6. Conclusion and future work

                                        38
Conclusion
For an improved automatic memory
       management we need:
                GC
                 +
An application-level virtual memory


         We propose



                                      39
Results

  Correct
• Facade objects.
• Graph intersection.
• Serializer and proxies for all type of objects.
• Proxies intercept all messages.
• Support proxies in primitives.


                                                    40
Results
  Maximizes memory released
• Small proxies.
• Object graphs as swapping unit.
• Proxies only for facade objects.
  Minimizes speed overhead
• Fast serialization.
• Fast detection of facade objects.
• Avoid unnecessary swap in.

                                      41
Future Work

• Automatic graphs detection.



                                42
Visualizing Objects Usage




                            43
Cus
Visualizing Objects Usage
                  trac tom
                       eo  ized
                         bjec VM
                              t us to
                                  age




                                   43
Cus
Visualizing Objects Usage
                  trac tom
                       eo  ized
                         bjec VM
                              t us to
                                  age




                                   43
Future Work

• Automatic graphs detection.
• Study possible integration with GC.
• Partial swap in.

                                        44
List of publications
Conferences
   [Dias 2011] Martin Dias, Mariano Martinez Peck, Stéphane Ducasse and Gabriela
 Arévalo. Clustered Serialization with Fuel. In Proceedings of ESUG International Workshop
 on Smalltalk Technologies (IWST 2011), Edinburgh, Scotland, 2011.

    [Martinez Peck 2010a] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker,
 Stéphane Ducasse and Luc Fabresse. Experiments with a Fast Object Swapper. In
 Smalltalks 2010, Concepción del Uruguay, Argentina, 2010.

    [Martinez Peck 2010b] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker,
 Stéphane Ducasse and Luc Fabresse. Visualizing Objects and Memory Usage. In Smalltalks
 2010, Concepción del Uruguay, Argentina, 2010.

    [Martinez Peck 2011a] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker,
 Stéphane Ducasse and Luc Fabresse. Efficient Proxies in Smalltalk. In Proceedings of ESUG
 International Workshop on Smalltalk Technologies (IWST 2011), Edinburgh, Scotland, 2011.

    [Martinez Peck 2011b] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker,
 Stéphane Ducasse and Luc Fabresse. Problems and Challenges when Building a
 Manager for Unused Objects. In Proceedings of Smalltalks 2011 International Workshop,
 Bernal, Buenos Aires, Argentina, 2011.
                                                                                            45
List of publications
  Journals
   [Martinez Peck 2011c] Mariano Martinez Peck, Noury Bouraqadi, Stéphane Ducasse
and Luc Fabresse. Object Swapping Challenges: an Evaluation of ImageSegment.
Journal of Computer Languages, Systems and Structures, vol. 38, no. 1, pages 1–15, nov 2011.

  [Dias 2012] Martin Dias, Mariano Martinez Peck, Stéphane Ducasse and Gabriela
Arévalo. Fuel: A Fast General Purpose Object Graph Serializer. Software: Practice and
Experience, 2012.

  [Martinez Peck 2012a] Mariano Martinez Peck, Noury Bouraqadi, Stéphane Ducasse,
Luc Fabresse and Marcus Denker. Ghost: A Uniform and Lightweight Proxy
Implementation. Science of Computer Programming, 2012 (submitted + passed first
review round).

   [Martinez Peck 2012b] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker,
Stéphane Ducasse and Luc Fabresse. Object-Based Virtual Memory Brought To The
Application Level. Journal of Object Technology, 2012 (submitted).



                                                                                               46
In summary...
 • We implemented a novel and efficient
   application-level virtual memory for object-
   oriented systems.
 • Almost no need from the VM and fully
   implemented in the language side.
 • Users can decide and influence what and when
   to swap.
                 Thanks!
                Mariano Martinez Peck



                                                  47
Fuel Features
• It is a fast, well-designed, concrete, general-
    purpose and flexible binary serializer.
• Can serialize/materialize not only plain objects
    but also classes, traits, methods, closures,
    contexts, packages, etc.
•   Support for global references.
•    Large number of hooks: ignore certain instance
    variables, substitute objects by others, post and
    pre serialization and materialization actions.
• Supports class rename and class reshape.
Key Characteristics
•   Pickle format.
•   Objects grouped in clusters.
•   Analysis phase before writing.
•   Stack over recursion.
•   Two phases for writing instances and
    references.
• Iterative graph recreation.
Success stories
•   Export and import of Moose models.
•   Pier CMS persistency (and export/import)
•   Backend of SandstoneDB, SimplePersistence and NoSQL databases.
•   BioSmalltalk: serialize big DNA or proteins.
•   PharoKernel regeneration and bootstrap (Hazelnut).
•   Presenty UI and Gaucho frameworks.
•   Revive test failures from Jenkins and materialize debuggers in
    another image.
•   Serialization for remote programming (Seamless).
•   Tanker (export/import packages of code).
•   Several commercial applications.
Traditional proxies
Usage of a minimal object together with an implementation of a
                custom #doesNotUnderstand

         ProtoObject
     identityHash
     pointersTo
     nextObject
     ...



           Proxy
   target
   doesNotUnderstand:
   executeBeforeHandling
   executeAfterHandling
Problems
 #doesNotUnderstand: cannot be trapped like a
regular message.

Mix of handling procedure and proxy interception.

 Only methods that are not understood are
intercepted.

No separation between proxies and handlers

                This approach is not stratified
Ghost features

• It is stratified, it intercept all messages and
  there are proxies and handlers.
• Uniform: it can proxy classes, methods, etc.
• Low memory footprint.
• Easy debugging.
Traditional                     Ghost
#doesNotUnderstand:        #cannotInterpret: is
cannot be trapped like a   trapped like a regular
regular message.           message.
Mix of handling            No mix of handling
procedure and proxy        procedure and proxy
interception.              interception.
Only methods that are
                           “All” methods are
not understood are
                           intercepted.
intercepted.
No separation between      Clear separation between
proxies and handlers.      proxies and handlers.
Classes with no
          MethodDictionary
       References                                              Object
        instance of
        message send
        lookup
        subclass                                               Proxy
                                                    cannotInterpret: aMessage


    aProxy username              4: #cannotInterpret: lookup

     1: #username send
                                                          ProxyTrap
                                                         methodDict := nil
               aProxy

                                   2: #aProxy lookup



       3: Since the method dictionary was nil,
          the VM sends #cannotInterpret to
the receiver but starting the lookup in the superclass
Object
                                                                           Interception
                             InterceptionDelegator                       message
        MethodLookup         cannotInterpret:                            proxy
    InterceptionDelegator                                                receiver
                                            <<methodDict := nil>>
    cannotInterpret:
                                      ProxyTrap


               superclass
                                     AbstractProxy
                                  proxyHandler

                                                                                         AbstractProxyHandler
                  AbstractClassProxy
                                                                                 handleInterception: anInterception
                 superclass
                                                                                 handleInterceptionToInstance: anObject
                 methodDict
                                                                                 handleMethodExecution: anInterception
                 proxyInitialize

Framework
Application                                          handler
                                                                                        SimpleForwarderHandler
     TargetBasedClassProxy                   TargetBasedProxy                    handleInterception: anInterception
 handler                              handler                                    handleInterceptionToInstance: anObject
 target                               target                                     handleMethodExecution: anInterception
                                                                       handler
 proxyHandler                         proxyHandler
 proxyTarget                          proxyTarget
 createProxyFor:handler:              createProxyFor:handler:
 createProxyAndReplace:handler:       createProxyAndReplace:handler:
Conclusion
With a little bit of special support from the
VM (#cannotInterpret hook), we can have an
image-side proxy solution much better than
the classic #doesNotUnderstand:




       [Martinez Peck 2012a] Mariano Martinez Peck, Noury Bouraqadi,
     Stéphane Ducasse, Luc Fabresse and Marcus Denker. Ghost: A Uniform
        and Lightweight Proxy Implementation. Science of Computer
    Programming, 2012 (in submission, accepted with major revision).
ObjectTracer VM

   • A Pharo Smalltalk virtual machine that
     traces object usage.
   • Let us query which objects has been used
     and which ones have not.



http://ss3.gemstone.com/ss/ObjectUsageTracer.html
Results
ImageSegment
   (an object swapper for Squeak Smalltalk)
Good swapping unit: graphs.
It does not swap shared objects.
It cannot swap classes and methods.
It scans the whole memory twice for each graph.
Implemented in the VM side.
No support for graph intersection.
             Mariano Martinez Peck, Noury Bouraqadi,Stéphane Ducasse
                  and Luc Fabresse. Object Swapping Challenges: an
             Evaluation of ImageSegment. Journal of Computer Languages,
                Systems and Structures, vol. 38, no. 1, pages 1–15, nov 2011.
Forwarding pointers


• To maintain correctness when we cannot
  proxify certain objects.
Speed analysis
Primary memory
                            Intersections...
                                                                      Pa Pc
                                                          42          (weak array)
      Pa         Pc     D
      42 2       42 3
                                                         GraphTable




                                      SharedProxiesTable
                            (key: proxyID / value: object or proxy)

Secondary memory

 B’ A’ C’
  1      2   3

 42.swap
Primary memory
                            Intersections...
                                                                      Pa Pc
                                                          42          (weak array)
      Pa         Pc     D
      42 2       42 3
                                                         GraphTable




                                      SharedProxiesTable
                            (key: proxyID / value: object or proxy)

Secondary memory

 B’ A’ C’
  1      2   3

 42.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                            Pa Pc
                                                                42          (weak array)
      Pa            Pc      D
      42 2          42 3
                                                               GraphTable




                                            SharedProxiesTable
                                  (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID

 B’ A’ C’
  1      2   3

 42.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3
                                                                GraphTable




                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
 B’ A’ C’
  1      2   3

 42.swap          D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3
                                                                GraphTable
                            Pd
                            43 1



                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’
  1      2   3

 42.swap          D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3
                                                                GraphTable
                            Pd
                            43 1



                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’                       4) Replace original objects with proxies
  1      2   3

 42.swap          D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3
                                                                GraphTable
                            Pd
                            43 1



                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’                       4) Replace original objects with proxies
  1      2   3

 42.swap          D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3
                                                                GraphTable
                            Pd
                            43 1



                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’                       4) Replace original objects with proxies
  1      2   3
                                5) Store shared proxy
 42.swap          D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3
                                                                GraphTable
                            Pd
                            43 1


                                              49194 Pc
                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’                       4) Replace original objects with proxies
  1      2   3
                                5) Store shared proxy
 42.swap          D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3                                         43          Pd Pc
                                                                GraphTable
                            Pd                                               (weak array)
                            43 1


                                              49194 Pc
                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’                       4) Replace original objects with proxies
  1      2   3
                                5) Store shared proxy
 42.swap                        6) Update GraphTable
                  D’ Pc’
                   1    2

                 43.swap
Primary memory
                 Graph ID: 43
                                   Intersections...
                                                                             Pa Pc
                                                                 42          (weak array)
      Pa               Pc   D
      42 2          42 3                                         43          Pd Pc
                                                                GraphTable
                            Pd                                               (weak array)
                            43 1


                                              49194 Pc
                                             SharedProxiesTable
                                   (key: proxyID / value: object or proxy)

Secondary memory                1) Assign graph ID
                                2) Serialize the object graph
                                3) Create and associate proxies (not for proxies)
 B’ A’ C’                       4) Replace original objects with proxies
  1      2   3
                                5) Store shared proxy
 42.swap                        6) Update GraphTable
                  D’ Pc’        7) GC runs
                   1    2

                 43.swap
Primary memory
                                  Intersections...
                                                                            Pa Pc
                                                                42          (weak array)
      Pa              Pc
      42 2         42 3                                         43          Pd Pc
                                                               GraphTable
                           Pd                                               (weak array)
                           43 1


                                             49194 Pc
                                            SharedProxiesTable
                                  (key: proxyID / value: object or proxy)

Secondary memory              1) Assign graph ID
                              2) Serialize the object graph
                              3) Create and associate proxies (not for proxies)
 B’ A’ C’                     4) Replace original objects with proxies
  1      2   3
                              5) Store shared proxy
 42.swap                      6) Update GraphTable
                 D’ Pc’       7) GC runs
                  1    2

                 43.swap
Primary memory
                                  Intersections...
                                                                            Pa Pc
                                                                42          (weak array)
      Pa              Pc
      42 2         42 3                                         43          Pd Pc
                                                               GraphTable
                           Pd                                               (weak array)
                           43 1


                                             49194 Pc
                                            SharedProxiesTable
                                  (key: proxyID / value: object or proxy)

Secondary memory              1) Assign graph ID
                              2) Serialize the object graph
                              3) Create and associate proxies (not for proxies)
 B’ A’ C’                     4) Replace original objects with proxies
  1      2   3
                              5) Store shared proxy
 42.swap                      6) Update GraphTable
                 D’ Pc’       7) GC runs
                  1    2
                              8) Swap in graph 42
                 43.swap
Primary memory
                                      Intersections...
                                                                                Pa C’
                                                                    42          (weak array)
                         Pc
                      42 3                                          43          Pd C’
               A’              Pd
                                                                   GraphTable   (weak array)
                               43 1
      B’              C’
                                                 49194 C’
                                                SharedProxiesTable
                                      (key: proxyID / value: object or proxy)

Secondary memory                  1) Assign graph ID
                                  2) Serialize the object graph
                                  3) Create and associate proxies (not for proxies)
 B’ A’ C’                         4) Replace original objects with proxies
  1    2   3
                                  5) Store shared proxy
 42.swap                          6) Update GraphTable
                    D’ Pc’        7) GC runs
                     1     2
                                  8) Swap in graph 42
                    43.swap
Primary memory
                                      Intersections...
                                                                                      C’
                         Pc
                      42 3                                          43          Pd C’
               A’              Pd
                                                                   GraphTable   (weak array)
                               43 1
      B’              C’
                                                 49194 C’
                                                SharedProxiesTable
                                      (key: proxyID / value: object or proxy)

Secondary memory                  1) Assign graph ID
                                  2) Serialize the object graph
                                  3) Create and associate proxies (not for proxies)
 B’ A’ C’                         4) Replace original objects with proxies
  1    2   3
                                  5) Store shared proxy
 42.swap                          6) Update GraphTable
                    D’ Pc’        7) GC runs
                     1     2
                                  8) Swap in graph 42
                    43.swap
Primary memory
                               Intersections...
                                                                               C’
                  Pc
               42 3                                          43          Pd C’
        A’              Pd
                                                            GraphTable   (weak array)
                        43 1
   B’          C’
                                          49194 C’
                                         SharedProxiesTable
                               (key: proxyID / value: object or proxy)

Secondary memory           1) Assign graph ID
                           2) Serialize the object graph
                           3) Create and associate proxies (not for proxies)
                           4) Replace original objects with proxies
                           5) Store shared proxy
                           6) Update GraphTable
             D’ Pc’        7) GC runs
              1     2
                           8) Swap in graph 42
             43.swap
Primary memory
                               Intersections...
                                                                               C’
                  Pc
               42 3                                          43          Pd C’
        A’              Pd
                                                            GraphTable   (weak array)
                        43 1
   B’          C’
                                          49194 C’
                                         SharedProxiesTable
                               (key: proxyID / value: object or proxy)

Secondary memory           1) Assign graph ID
                           2) Serialize the object graph
                           3) Create and associate proxies (not for proxies)
                           4) Replace original objects with proxies
                           5) Store shared proxy
                           6) Update GraphTable
             D’ Pc’        7) GC runs
              1     2
                           8) Swap in graph 42
             43.swap       9) Swap in graph 43
Primary memory
                               Intersections...
                                                                               C’
                  Pc
               42 3                                          43          Pd C’
        A’              Pd
                                                            GraphTable   (weak array)
                        43 1
   B’          C’
                                          49194 C’
                                         SharedProxiesTable
                               (key: proxyID / value: object or proxy)

Secondary memory           1) Assign graph ID
                           2) Serialize the object graph
                           3) Create and associate proxies (not for proxies)
                           4) Replace original objects with proxies
                           5) Store shared proxy
                           6) Update GraphTable
             D’ Pc’        7) GC runs
              1     2
                           8) Swap in graph 42
             43.swap       9) Swap in graph 43
Primary memory
                               Intersections...
                                                                               C’
                  Pc
               42 3                                          43          Pd C’
        A’              Pd
                                                            GraphTable   (weak array)
                        43 1
   B’          C’
                                          49194 C’
                                         SharedProxiesTable
                               (key: proxyID / value: object or proxy)

Secondary memory           1) Assign graph ID
                           2) Serialize the object graph
                           3) Create and associate proxies (not for proxies)
                           4) Replace original objects with proxies
                           5) Store shared proxy
                           6) Update GraphTable
             D’ Pc’        7) GC runs
              1     2
                           8) Swap in graph 42
             43.swap       9) Swap in graph 43
Primary memory
                            Intersections...
                                                                            C’
                  Pc    D
               42 3                                       43          Pd C’
        A’                                               GraphTable   (weak array)


   B’          C’
                                       49194 C’
                                      SharedProxiesTable
                            (key: proxyID / value: object or proxy)

Secondary memory        1) Assign graph ID
                        2) Serialize the object graph
                        3) Create and associate proxies (not for proxies)
                        4) Replace original objects with proxies
                        5) Store shared proxy
                        6) Update GraphTable
             D’ Pc’     7) GC runs
              1     2
                        8) Swap in graph 42
             43.swap    9) Swap in graph 43
5000
                              Overhead
                                           Without Marea
                                           After Marea
            3750
Time (ms)




            2500




            1250




               0
                   start   home   /tools   /Doc   /Download   /Support   /news

                                       Action / Page                             66
Overhead
                  100
                                                      Without Marea
                                                      After Marea
                   75
Value Time (ms)




                   50




                   25




                    0
                        /tools   /Documentation /Download   /Support   /news

                                            Action / Page                      67

PhD Thesis Defense Presentation

  • 1.
    Application-Level VirtualMemory for Object-Oriented Systems Mariano Martinez Peck 1
  • 2.
    Application-Level VirtualMemory for Object-Oriented Systems Mariano Martinez Peck 2
  • 3.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 3
  • 4.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 3
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
    We need tooptimize memory management 5
  • 12.
    Context • Object-oriented programming.Why? Most modern and widespread. Memory is usually automatically managed (GC). • Dynamic languages. Why? Powerful. More and more used. 6
  • 13.
    In this contextof OOP, is GC actually enough to optimize memory management? 7
  • 14.
    % used objects? % used memory ? % unused objects ? % unused memory ? 8
  • 15.
    % used objects % used memory % unused objects % unused memory (web app + CMS) (standalone + lots of tools + large) (174 pack. 1364 class. 121010 LOC) (mobile app) (infrastructure) 8
  • 16.
    % used objects % used memory % unused objects % unused memory 19% 29% (web app + CMS) 81% 71% 18% 27% (standalone + lots of tools + large) (174 pack. 1364 class. 121010 LOC) 73% 82% 23% 54% 46% 77% (mobile app) 10% 37% 63% (infrastructure) 90% 8
  • 17.
    % used objects % used memory % unused objects % unused memory 19% 29% (web app + CMS) 81% 71% 18% 27% (standalone + lots of tools + large) (174 pack. 1364 class. 121010 LOC) 73% 82% 23% 54% 46% 77% (mobile app) 10% In average, %80 of the 37% objects are unused.90% 63% (infrastructure) 8
  • 18.
    % used objects % used memory % unused objects % unused memory 19% 29% (web app + CMS) 81% 71% 18% 27% (standalone + lots of tools + large) (174 pack. 1364 class. 121010 LOC) 73% 82% 23% 54% 46% 77% (mobile app) 10% In average, %80 of the In average, 77% 37%the of objects are unused.90% memory is63% unused. (infrastructure) 8
  • 19.
    Unused objects Referenced. GC cannot collect them! Waste primary memory. 9
  • 20.
    Unused objects Referenced. GC cannot collect them! Waste primary memory. No, the GC is not enough 9
  • 21.
    OS’ Virtual Memoryis not the answer • It only swaps pages. • Developers cannot easily influence it. 10
  • 22.
    Thesis statement A virtualmemory for dynamic OOP languages should be: Application-aware Efficient 11
  • 23.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 12
  • 24.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 12
  • 25.
    A model forefficient application-level virtual memory: • Designed for dynamic OOP • Based on the swapping of object graphs 13
  • 26.
    Primary memory Swap out Swap in unused object needed object graphs graphs Secondary memory cloud file database 14
  • 27.
    Primary memory Swap out Swap in unused object needed object graphs graphs Secondary memory cloud file database 14
  • 28.
    Primary memory Y A B C E F Secondary memory 15
  • 29.
    Primary memory Y A B C E F Memory occupied by graph of unused objects Secondary memory 15
  • 30.
    Primary memory Y A B C E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 15
  • 31.
    Primary memory Y A Pa B C E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 15
  • 32.
    Primary memory Y Pa Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 15
  • 33.
    Primary memory Y Pa Secondary memory bytes (A,B,C,E,F) 15
  • 34.
    Primary memory Y Pa Secondary memory bytes (A,B,C,E,F) 15
  • 35.
    Primary memory Y Pa Memory Released Secondary memory bytes (A,B,C,E,F) 15
  • 36.
    Primary memory Y Pa Memory Released Secondary memory Swap in bytes (A,B,C,E,F) 15
  • 37.
    Primary memory Y A B C E F Secondary memory 15
  • 38.
    Primary memory Y A B C E F Secondary memory 16
  • 39.
    Primary memory Y A D B C E F Secondary memory 16
  • 40.
    Primary memory Y A D B C E F Memory occupied by graph of unused objects Secondary memory 16
  • 41.
    Primary memory Y A D B C E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 16
  • 42.
    Primary memory Y A Pa D B C E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 16
  • 43.
    Primary memory Y Pa D C E Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 16
  • 44.
    Primary memory Y Pa D C E Secondary memory bytes (A,B,C,E,F) 16
  • 45.
    Primary memory Y Pa D C E Secondary memory bytes (A,B,C,E,F) 16
  • 46.
    Primary memory Y Pa D C E Secondary memory Swap in bytes (A,B,C,E,F) 16
  • 47.
    Primary memory Y Pa D C E Secondary memory Swap in bytes (A,B,C,E,F) 16
  • 48.
    Primary memory Y Pa D C E Secondary memory Swap in bytes (A,B,C,E,F) 16
  • 49.
    Primary memory Y A D B C C E E F Secondary memory 16
  • 50.
    Primary memory Y A D B C C E E F Secondary memory 16
  • 51.
    Primary memory Y A D B C C E E F Secondary memory INCORRECT!!! 16
  • 52.
  • 53.
    subsystems Object Graph Proxy Swapper Toolbox Object Object Graph Graph Serializer Storage 18
  • 54.
    Primary memory Y A D B C E F Secondary memory 19
  • 55.
    Primary memory Y A D B C E F Memory occupied by graph of unused objects Secondary memory 19
  • 56.
    Primary memory Y A D B C E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 19
  • 57.
    Primary memory Y A D B C facade objects E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 19
  • 58.
    Primary memory Y A Pa D B C Pc facade objects proxy E F Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 19
  • 59.
    Primary memory Y Pa D Pc facade objects proxy Memory occupied by graph of unused objects Secondary memory Swap out bytes (A,B,C,E,F) 19
  • 60.
    Primary memory Y Pa D Pc facade objects proxy Secondary memory bytes (A,B,C,E,F) 19
  • 61.
    Primary memory Y Pa D Pc facade objects proxy Secondary memory bytes (A,B,C,E,F) 19
  • 62.
    Primary memory Y Pa D Pc facade objects proxy Secondary memory Swap in bytes (A,B,C,E,F) 19
  • 63.
    Primary memory Y A D B C facade objects proxy E F Secondary memory 19
  • 64.
    How to efficientlydetect and manage facade objects? • Back-pointers. • Whole memory scan. Y A D B C E F 20
  • 65.
    How to efficientlydetect and manage facade objects? • Back-pointers. • Whole memory scan. Y A D B C Marea provides an E F efficient solution. 20
  • 66.
    Primary memory Swapping out A D GraphTable B C Secondary memory 21
  • 67.
    Primary memory Swapping out A D GraphTable B C Secondary memory 21
  • 68.
    Primary memory Swapping out Graph ID: 42 A D GraphTable B C Secondary memory 1) Assign graph ID 21
  • 69.
    Primary memory Swapping out Graph ID: 42 A D GraphTable B C Secondary memory 1) Assign graph ID 2) Serialize the object graph B’ A’ C’ 1 2 3 42.swap 21
  • 70.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 A Pa GraphTable B C B Pb Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 1 2 3 42.swap 21
  • 71.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 A Pa GraphTable B C B Pb Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 1 2 3 42.swap 21
  • 72.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 A Pa GraphTable B C B Pb Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 1 2 3 42.swap 21
  • 73.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 A Pa GraphTable B C B Pb Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap 21
  • 74.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 A Pa GraphTable B C B Pb Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap 21
  • 75.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 Pa A GraphTable B C B Pb Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap 21
  • 76.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 Pa A GraphTable B C Pb B Pb 42 1 C Pc proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap 21
  • 77.
    Primary memory Swapping out Graph ID: 42 Pa Pc D 42 2 A 42 3 Pa A GraphTable B C Pb B Pb 42 1 Pc C proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap 21
  • 78.
    Primary memory Swapping out Graph ID: 42 Pa Pc 42 Pa Pb Pc A D (weak array) 42 2 42 3 Pa A GraphTable B C Pb B Pb 42 1 Pc C proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Update GraphTable 42.swap 21
  • 79.
    Primary memory Swapping out Graph ID: 42 Pa Pc 42 Pa Pb Pc A D (weak array) 42 2 42 3 Pa A GraphTable B C Pb B Pb 42 1 Pc C proxiesDict Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Update GraphTable 6) GC runs 42.swap 21
  • 80.
    Primary memory Swapping out Pa Pc 42 Pa nil Pc D (weak array) 42 2 42 3 Pa A GraphTable Pb B Pc C Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Update GraphTable 6) GC runs 42.swap 21
  • 81.
    Primary memory Swapping out Pa Pc 42 Pa nil Pc D (weak array) 42 2 42 3 Pa A GraphTable Pb B Pc C Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Update GraphTable 6) GC runs 42.swap 7) Compact (optional) 21
  • 82.
    Primary memory Swapping out Pa Pc 42 Pa Pc D (weak array) 42 2 42 3 Pa A GraphTable Pb B Pc C Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Update GraphTable 6) GC runs 42.swap 7) Compact (optional) 21
  • 83.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 42 3 (weak array) GraphTable Secondary memory B’ A’ C’ 1 2 3 42.swap 22
  • 84.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 42 3 (weak array) GraphTable Secondary memory 0) A proxy intercepts a message... B’ A’ C’ 1 2 3 42.swap 22
  • 85.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 42 3 (weak array) GraphTable Secondary memory 0) A proxy intercepts a message... B’ A’ C’ 1 2 3 42.swap 22
  • 86.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph B’ A’ C’ 1 2 3 42.swap 22
  • 87.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 88.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 89.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 90.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 91.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 92.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 93.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable Pa A’ B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 94.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable Pa A’ Pc C’ B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 42.swap 22
  • 95.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable Pa A’ Pc C’ B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 3) Replace proxies with original objects 42.swap 22
  • 96.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable A’ Pa Pc C’ B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 3) Replace proxies with original objects 42.swap 22
  • 97.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable A’ Pa C’ Pc B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 3) Replace proxies with original objects 42.swap 22
  • 98.
    Primary memory Swapping in Pa Pc D 42 Pa Pc 42 2 A’ 42 3 (weak array) B’ C’ GraphTable A’ Pa C’ Pc B’ A’ C’ proxiesDict 1 2 3 materializedObjects Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with B’ A’ C’ materialized objects 1 2 3 3) Replace proxies with original objects 4) Clean 42.swap 22
  • 99.
    Primary memory Swapping in Pa Pc D 42 2 A’ 42 3 B’ C’ GraphTable C’ Pc Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with materialized objects 3) Replace proxies with original objects 4) Clean 22
  • 100.
    Primary memory Swapping in A’ D B’ C’ GraphTable C’ Pc Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with materialized objects 3) Replace proxies with original objects 4) Clean 5) GC runs 22
  • 101.
    Primary memory Swapping in A’ D B’ C’ GraphTable C’ Pc Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with materialized objects 3) Replace proxies with original objects 4) Clean 5) GC runs 6) Forward message to object 22
  • 102.
    Primary memory Swapping in A’ D B’ C’ GraphTable C’ Pc Secondary memory 0) A proxy intercepts a message... 1) Materialize the object graph 2) Associate proxies with materialized objects 3) Replace proxies with original objects 4) Clean 5) GC runs 6) Forward message to object 22
  • 103.
    Primary memory Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory B’ A’ C’ 1 2 3 42.swap 23
  • 104.
    Primary memory Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory B’ A’ C’ 1 2 3 42.swap 23
  • 105.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory 1) Assign graph ID B’ A’ C’ 1 2 3 42.swap 23
  • 106.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph B’ A’ C’ 1 2 3 42.swap 23
  • 107.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph B’ A’ C’ 1 2 3 42.swap 23
  • 108.
    Primary memory Graph ID: 43 Intersections... Pc A’ D B’ C’ GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph 23
  • 109.
    Primary memory Graph ID: 43 Intersections... Pc A’ D B’ C’ GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph D’ C’ 1 2 43.swap 23
  • 110.
    Primary memory Graph ID: 43 Intersections... Pc A’ D B’ C’ GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph ...) as usually... D’ C’ 1 2 43.swap 23
  • 111.
    Primary memory Graph ID: 43 Intersections... Pc A’ D B’ C’ GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph ...) as usually... We don’tC’ D’ want to swap in a graph while 1 2 swapping out another one 43.swap 23
  • 112.
    Primary memory Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory B’ A’ C’ 1 2 3 42.swap 24
  • 113.
    Primary memory Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory B’ A’ C’ 1 2 3 42.swap 24
  • 114.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory 1) Assign graph ID B’ A’ C’ 1 2 3 42.swap 24
  • 115.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 GraphTable Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 1 2 3 42.swap D’ Pc’ 1 2 43.swap 24
  • 116.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 Ppc Pd GraphTable 43 2 43 1 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 42.swap D’ Pc’ 1 2 43.swap 24
  • 117.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 Ppc Pd GraphTable 43 2 43 1 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap D’ Pc’ 1 2 43.swap 24
  • 118.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 Ppc Pd GraphTable 43 2 43 1 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap D’ Pc’ 1 2 43.swap 24
  • 119.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 Ppc Pd GraphTable 43 2 43 1 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap D’ Pc’ 1 2 43.swap 24
  • 120.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 43 Pd Ppc Ppc Pd GraphTable 43 1 (weak array) 43 2 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap 5) Update GraphTable D’ Pc’ 1 2 43.swap 24
  • 121.
    Primary memory Graph ID: 43 Intersections... Pa Pc Pa Pc D 42 (weak array) 42 2 42 3 43 Pd Ppc Ppc Pd GraphTable 43 1 (weak array) 43 2 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap 5) Update GraphTable D’ Pc’ 6) GC runs 1 2 43.swap 24
  • 122.
    Primary memory Intersections... Pa nil Pa 42 (weak array) 42 2 43 Pd nil Pd GraphTable 43 1 (weak array) Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap 5) Update GraphTable D’ Pc’ 6) GC runs 1 2 43.swap 24
  • 123.
    Primary memory Intersections... Pa nil Pa 42 (weak array) 42 2 43 Pd nil Pd GraphTable 43 1 (weak array) Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) B’ A’ C’ 3) Create and associate proxies 1 2 3 4) Replace original objects with proxies 42.swap 5) Update GraphTable D’ Pc’ 6) GC runs 1 2 7) Swap in graph 42 43.swap 24
  • 124.
    Primary memory Intersections... nil 43 Pd nil A’ Pd 43 1 GraphTable (weak array) B’ C’ Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) 3) Create and associate proxies 4) Replace original objects with proxies 5) Update GraphTable D’ Pc’ 6) GC runs 1 2 7) Swap in graph 42 43.swap 24
  • 125.
    Primary memory Intersections... nil 43 Pd nil A’ Pd 43 1 GraphTable (weak array) B’ C’ Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) 3) Create and associate proxies 4) Replace original objects with proxies 5) Update GraphTable D’ Pc’ 6) GC runs 1 2 7) Swap in graph 42 8) Swap in graph 43... 43.swap 24
  • 126.
    Primary memory Intersections... nil 43 Pd nil A’ Pd 43 1 GraphTable (weak array) B’ C’ Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) 3) Create and associate proxies 4) Replace original objects with proxies 5) Update GraphTable D’ Pc’ 6) GC runs 1 2 7) Swap in graph 42 8) Swap in graph 43... 43.swap 24
  • 127.
    Primary memory Intersections... D’ nil A’ GraphTable B’ C’ Pc’ 42 3 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) 3) Create and associate proxies 4) Replace original objects with proxies 5) Update GraphTable 6) GC runs 7) Swap in graph 42 8) Swap in graph 43... 24
  • 128.
    Primary memory Intersections... D’ nil A’ GraphTable B’ C’ Pc’ 42 3 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) 3) Create and associate proxies 4) Replace original objects with proxies 5) Update GraphTable 6) GC runs 7) Swap in graph 42 8) Swap in graph 43... 24
  • 129.
    Primary memory Intersections... D’ nil A’ GraphTable B’ C’ Pc’ 42 3 Secondary memory 1) Assign graph ID 2) Serialize the object graph (customize serializer) 3) Create and associate proxies 4) Replace original objects with proxies 5) Update GraphTable 6) GC runs INCORRECT!!! 7) Swap in graph 42 8) Swap in graph 43... 24
  • 130.
    Graph intersections • Avoidingproxies for proxies (Ppc) does not solve the problem either. • Several scenarios for swapping in swapped intersecting graphs. 25
  • 131.
    Graph intersections • Avoidingproxies for proxies (Ppc) does not solve the problem either. • Several scenarios for swapping in swapped intersecting graphs. Marea solves all these scenarios and challenges. 25
  • 132.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 26
  • 133.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 26
  • 134.
    Experiment (web app + CMS) 1. We swapped out most classes with their instances. (standalone + lots of tools + large) 2. We navigated, used and tested (174 pack. 1364 class. 121010 LOC) each application 1. Swapped in all needed graphs for typical uses. (mobile app) 2. Tests also for correctness. 3. We measured differences. (infrastructure) 27
  • 135.
    Original = 100% With Marea Measured minimun 100 75 % of memory 50 25 0 DBXTalk Moose DrGeo Pharo 28
  • 136.
    Original = 100% With Marea Measured minimun 100 75 % of memory 50 25 0 DBXTalk Moose DrGeo Pharo Marea released between 25% and 40% of the used memory. 28
  • 137.
    Original = 100% With Marea Measured minimun 100 75 % of memory 50 25 0 DBXTalk Moose DrGeo Pharo Marea released between 25% There is still and 40% of the used memory. room for improvement. 28
  • 138.
    Speed overhead • Fortypical uses is 0%. • For non covered uses: 29
  • 139.
    Speed overhead • Fortypical uses is 0%. Swap in Swap out • For non covered uses: 300 225 Time (ms) 150 75 0 51 236 777 5758 21753 Graph size (amount of objects) 29
  • 140.
    Speed overhead • Fortypical uses is 0%. Swap in Swap out • For non covered uses: 300 225 Time (ms) 150 75 0 51 236 777 5758 21753 Graph size (amount of objects) Swapping in is faster than swapping out. 29
  • 141.
    Speed overhead • Fortypical uses is 0%. Swap in Swap out • For non covered uses: 300 225 Time (ms) 150 75 0 51 236 777 5758 21753 Graph size (amount of objects) Swapping in is faster The graph size has a small than swapping out. impact in small/medium graphs. 29
  • 142.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 30
  • 143.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 30
  • 144.
    Comparison criteria • Efficientobject-based swapping unit. • Uniformity. • Reversibility. • Automatic swapping in. • Automatic swapping out. • Transparency. • Controllability at the application level. • Portability. 31
  • 145.
    Language level andlibraries Runtimes OS related 32
  • 146.
    Language level andlibraries Runtimes OS related 32
  • 147.
    Language level andlibraries Runtimes OS related 32
  • 148.
    Language level andlibraries Runtimes OS related 32
  • 149.
    Language level andlibraries Runtimes OS related 32
  • 150.
    Language level andlibraries Runtimes OS related In progress 32
  • 151.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 33
  • 152.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 33
  • 153.
    in Object Proxy Graph Toolbox Swapper Object Graph Object Serializer Graph Storage 34
  • 154.
    • An extensible,uniform and fast serializer. • General-purpose. • Used in research and industry. • Integrated in Pharo 2.0 and ported to Squeak, VisualWorks and Newspeak. • ESUG Innovation Technology Awards 2011. 35
  • 155.
    • An extensible,uniform and fast serializer. • General-purpose. • Used in research and industry. • Integrated in Pharo 2.0 and ported to Squeak, VisualWorks and Newspeak. • ESUG Innovation Technology Awards 2011. Martin Dias, Mariano Martinez Peck, Stéphane Ducasse and Gabriela Arévalo. Fuel: A Fast General Purpose Object Graph Serializer. Software: Practice and Experience, 2012. 35
  • 156.
    • Proxify allkind of objects. • Low memory footprint. • Intercepting all messages. • Clear division between proxies and handlers. • General-purpose. 36
  • 157.
    • Proxify allkind of objects. • Low memory footprint. • Intercepting all messages. • Clear division between proxies and handlers. • General-purpose. [Martinez Peck 2012a] Mariano Martinez Peck, Noury Bouraqadi, Stéphane Ducasse, Luc Fabresse and Marcus Denker. Ghost: A Uniform and Lightweight Proxy Implementation. Science of Computer Programming, 2012 (submitted + passed first review round). 36
  • 158.
    Object replacement • Providedby regular VM (#become:) Specific to Smalltalk. • Different implementations Full memory scan in Pharo VM. Object header swapping in VisualWorks VM. Object tables’ entries swapping in Gemstone VM. 37
  • 159.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 38
  • 160.
    Outline 1. Context, problemand introduction. 2. My proposal. 3. Validation. 4. Related work. 5. Implementation. 6. Conclusion and future work 38
  • 161.
    Conclusion For an improvedautomatic memory management we need: GC + An application-level virtual memory We propose 39
  • 162.
    Results Correct •Facade objects. • Graph intersection. • Serializer and proxies for all type of objects. • Proxies intercept all messages. • Support proxies in primitives. 40
  • 163.
    Results Maximizesmemory released • Small proxies. • Object graphs as swapping unit. • Proxies only for facade objects. Minimizes speed overhead • Fast serialization. • Fast detection of facade objects. • Avoid unnecessary swap in. 41
  • 164.
    Future Work • Automaticgraphs detection. 42
  • 165.
  • 166.
    Cus Visualizing Objects Usage trac tom eo ized bjec VM t us to age 43
  • 167.
    Cus Visualizing Objects Usage trac tom eo ized bjec VM t us to age 43
  • 168.
    Future Work • Automaticgraphs detection. • Study possible integration with GC. • Partial swap in. 44
  • 169.
    List of publications Conferences [Dias 2011] Martin Dias, Mariano Martinez Peck, Stéphane Ducasse and Gabriela Arévalo. Clustered Serialization with Fuel. In Proceedings of ESUG International Workshop on Smalltalk Technologies (IWST 2011), Edinburgh, Scotland, 2011. [Martinez Peck 2010a] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker, Stéphane Ducasse and Luc Fabresse. Experiments with a Fast Object Swapper. In Smalltalks 2010, Concepción del Uruguay, Argentina, 2010. [Martinez Peck 2010b] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker, Stéphane Ducasse and Luc Fabresse. Visualizing Objects and Memory Usage. In Smalltalks 2010, Concepción del Uruguay, Argentina, 2010. [Martinez Peck 2011a] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker, Stéphane Ducasse and Luc Fabresse. Efficient Proxies in Smalltalk. In Proceedings of ESUG International Workshop on Smalltalk Technologies (IWST 2011), Edinburgh, Scotland, 2011. [Martinez Peck 2011b] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker, Stéphane Ducasse and Luc Fabresse. Problems and Challenges when Building a Manager for Unused Objects. In Proceedings of Smalltalks 2011 International Workshop, Bernal, Buenos Aires, Argentina, 2011. 45
  • 170.
    List of publications Journals [Martinez Peck 2011c] Mariano Martinez Peck, Noury Bouraqadi, Stéphane Ducasse and Luc Fabresse. Object Swapping Challenges: an Evaluation of ImageSegment. Journal of Computer Languages, Systems and Structures, vol. 38, no. 1, pages 1–15, nov 2011. [Dias 2012] Martin Dias, Mariano Martinez Peck, Stéphane Ducasse and Gabriela Arévalo. Fuel: A Fast General Purpose Object Graph Serializer. Software: Practice and Experience, 2012. [Martinez Peck 2012a] Mariano Martinez Peck, Noury Bouraqadi, Stéphane Ducasse, Luc Fabresse and Marcus Denker. Ghost: A Uniform and Lightweight Proxy Implementation. Science of Computer Programming, 2012 (submitted + passed first review round). [Martinez Peck 2012b] Mariano Martinez Peck, Noury Bouraqadi, Marcus Denker, Stéphane Ducasse and Luc Fabresse. Object-Based Virtual Memory Brought To The Application Level. Journal of Object Technology, 2012 (submitted). 46
  • 171.
    In summary... •We implemented a novel and efficient application-level virtual memory for object- oriented systems. • Almost no need from the VM and fully implemented in the language side. • Users can decide and influence what and when to swap. Thanks! Mariano Martinez Peck 47
  • 174.
    Fuel Features • Itis a fast, well-designed, concrete, general- purpose and flexible binary serializer. • Can serialize/materialize not only plain objects but also classes, traits, methods, closures, contexts, packages, etc. • Support for global references. • Large number of hooks: ignore certain instance variables, substitute objects by others, post and pre serialization and materialization actions. • Supports class rename and class reshape.
  • 175.
    Key Characteristics • Pickle format. • Objects grouped in clusters. • Analysis phase before writing. • Stack over recursion. • Two phases for writing instances and references. • Iterative graph recreation.
  • 176.
    Success stories • Export and import of Moose models. • Pier CMS persistency (and export/import) • Backend of SandstoneDB, SimplePersistence and NoSQL databases. • BioSmalltalk: serialize big DNA or proteins. • PharoKernel regeneration and bootstrap (Hazelnut). • Presenty UI and Gaucho frameworks. • Revive test failures from Jenkins and materialize debuggers in another image. • Serialization for remote programming (Seamless). • Tanker (export/import packages of code). • Several commercial applications.
  • 177.
    Traditional proxies Usage ofa minimal object together with an implementation of a custom #doesNotUnderstand ProtoObject identityHash pointersTo nextObject ... Proxy target doesNotUnderstand: executeBeforeHandling executeAfterHandling
  • 178.
    Problems #doesNotUnderstand: cannotbe trapped like a regular message. Mix of handling procedure and proxy interception. Only methods that are not understood are intercepted. No separation between proxies and handlers This approach is not stratified
  • 179.
    Ghost features • Itis stratified, it intercept all messages and there are proxies and handlers. • Uniform: it can proxy classes, methods, etc. • Low memory footprint. • Easy debugging.
  • 180.
    Traditional Ghost #doesNotUnderstand: #cannotInterpret: is cannot be trapped like a trapped like a regular regular message. message. Mix of handling No mix of handling procedure and proxy procedure and proxy interception. interception. Only methods that are “All” methods are not understood are intercepted. intercepted. No separation between Clear separation between proxies and handlers. proxies and handlers.
  • 181.
    Classes with no MethodDictionary References Object instance of message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass
  • 182.
    Object Interception InterceptionDelegator message MethodLookup cannotInterpret: proxy InterceptionDelegator receiver <<methodDict := nil>> cannotInterpret: ProxyTrap superclass AbstractProxy proxyHandler AbstractProxyHandler AbstractClassProxy handleInterception: anInterception superclass handleInterceptionToInstance: anObject methodDict handleMethodExecution: anInterception proxyInitialize Framework Application handler SimpleForwarderHandler TargetBasedClassProxy TargetBasedProxy handleInterception: anInterception handler handler handleInterceptionToInstance: anObject target target handleMethodExecution: anInterception handler proxyHandler proxyHandler proxyTarget proxyTarget createProxyFor:handler: createProxyFor:handler: createProxyAndReplace:handler: createProxyAndReplace:handler:
  • 183.
    Conclusion With a littlebit of special support from the VM (#cannotInterpret hook), we can have an image-side proxy solution much better than the classic #doesNotUnderstand: [Martinez Peck 2012a] Mariano Martinez Peck, Noury Bouraqadi, Stéphane Ducasse, Luc Fabresse and Marcus Denker. Ghost: A Uniform and Lightweight Proxy Implementation. Science of Computer Programming, 2012 (in submission, accepted with major revision).
  • 184.
    ObjectTracer VM • A Pharo Smalltalk virtual machine that traces object usage. • Let us query which objects has been used and which ones have not. http://ss3.gemstone.com/ss/ObjectUsageTracer.html
  • 185.
  • 186.
    ImageSegment (an object swapper for Squeak Smalltalk) Good swapping unit: graphs. It does not swap shared objects. It cannot swap classes and methods. It scans the whole memory twice for each graph. Implemented in the VM side. No support for graph intersection. Mariano Martinez Peck, Noury Bouraqadi,Stéphane Ducasse and Luc Fabresse. Object Swapping Challenges: an Evaluation of ImageSegment. Journal of Computer Languages, Systems and Structures, vol. 38, no. 1, pages 1–15, nov 2011.
  • 187.
    Forwarding pointers • Tomaintain correctness when we cannot proxify certain objects.
  • 188.
  • 189.
    Primary memory Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory B’ A’ C’ 1 2 3 42.swap
  • 190.
    Primary memory Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory B’ A’ C’ 1 2 3 42.swap
  • 191.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID B’ A’ C’ 1 2 3 42.swap
  • 192.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph B’ A’ C’ 1 2 3 42.swap D’ Pc’ 1 2 43.swap
  • 193.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable Pd 43 1 SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 1 2 3 42.swap D’ Pc’ 1 2 43.swap
  • 194.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable Pd 43 1 SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap D’ Pc’ 1 2 43.swap
  • 195.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable Pd 43 1 SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 42.swap D’ Pc’ 1 2 43.swap
  • 196.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable Pd 43 1 SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap D’ Pc’ 1 2 43.swap
  • 197.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 GraphTable Pd 43 1 49194 Pc SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap D’ Pc’ 1 2 43.swap
  • 198.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 43 Pd Pc GraphTable Pd (weak array) 43 1 49194 Pc SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap 6) Update GraphTable D’ Pc’ 1 2 43.swap
  • 199.
    Primary memory Graph ID: 43 Intersections... Pa Pc 42 (weak array) Pa Pc D 42 2 42 3 43 Pd Pc GraphTable Pd (weak array) 43 1 49194 Pc SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 43.swap
  • 200.
    Primary memory Intersections... Pa Pc 42 (weak array) Pa Pc 42 2 42 3 43 Pd Pc GraphTable Pd (weak array) 43 1 49194 Pc SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 43.swap
  • 201.
    Primary memory Intersections... Pa Pc 42 (weak array) Pa Pc 42 2 42 3 43 Pd Pc GraphTable Pd (weak array) 43 1 49194 Pc SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap
  • 202.
    Primary memory Intersections... Pa C’ 42 (weak array) Pc 42 3 43 Pd C’ A’ Pd GraphTable (weak array) 43 1 B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap
  • 203.
    Primary memory Intersections... C’ Pc 42 3 43 Pd C’ A’ Pd GraphTable (weak array) 43 1 B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) B’ A’ C’ 4) Replace original objects with proxies 1 2 3 5) Store shared proxy 42.swap 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap
  • 204.
    Primary memory Intersections... C’ Pc 42 3 43 Pd C’ A’ Pd GraphTable (weak array) 43 1 B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) 4) Replace original objects with proxies 5) Store shared proxy 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap
  • 205.
    Primary memory Intersections... C’ Pc 42 3 43 Pd C’ A’ Pd GraphTable (weak array) 43 1 B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) 4) Replace original objects with proxies 5) Store shared proxy 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap 9) Swap in graph 43
  • 206.
    Primary memory Intersections... C’ Pc 42 3 43 Pd C’ A’ Pd GraphTable (weak array) 43 1 B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) 4) Replace original objects with proxies 5) Store shared proxy 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap 9) Swap in graph 43
  • 207.
    Primary memory Intersections... C’ Pc 42 3 43 Pd C’ A’ Pd GraphTable (weak array) 43 1 B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) 4) Replace original objects with proxies 5) Store shared proxy 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap 9) Swap in graph 43
  • 208.
    Primary memory Intersections... C’ Pc D 42 3 43 Pd C’ A’ GraphTable (weak array) B’ C’ 49194 C’ SharedProxiesTable (key: proxyID / value: object or proxy) Secondary memory 1) Assign graph ID 2) Serialize the object graph 3) Create and associate proxies (not for proxies) 4) Replace original objects with proxies 5) Store shared proxy 6) Update GraphTable D’ Pc’ 7) GC runs 1 2 8) Swap in graph 42 43.swap 9) Swap in graph 43
  • 209.
    5000 Overhead Without Marea After Marea 3750 Time (ms) 2500 1250 0 start home /tools /Doc /Download /Support /news Action / Page 66
  • 210.
    Overhead 100 Without Marea After Marea 75 Value Time (ms) 50 25 0 /tools /Documentation /Download /Support /news Action / Page 67