Advertisement
avisrivastava254084

Untitled

Nov 24th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. ```
  2. class MyClass(object):
  3. pass
  4.  
  5. a = MyClass()
  6. a.obj = a
  7. del a
  8. ```
  9.  
  10. 4: mutator allots a block from free memory for a with epoch. a = 2
  11. 5: a.obj = a. This makes mutator to have a = 3, and marker brings a from root set to be set to 3(from the prev cycle).
  12. However, a refers to a with epoch = 3. So, it is a cycle. both a.obj and a are in the root set.
  13. 6: del a. This does not delete a from root set, it just deletes a from the context of current stack in code. a.obj refers to a and both of them are at epoch 3.
  14.  
  15. So, in the current stack of this module, even as the code proceeds, the sweeper would never be able to free the
  16. a's memory blocks as they will be in the root set with epoch's color because marker would keep bringing the reachable data from root set "up to date".
  17. Reference from the paper:
  18. >The sweeper thread is parameterized by COLOR(epoch-2),
  19. >called the sweeper color (line g in Figure 1). It examines every block of storage in the system. If block b has
  20. >sweeper color it may be deallocated and returned to the
  21. >free list; reclamation of b is safe because neither the mutator nor marker can reach it. If b has COLOR(epoch) or
  22. >COLOR(epoch-1), it is skipped because it is still potentially
  23. >in use. (Blocks with marker color (COLOR(epoch-1)) will
  24. >either be marked with COLOR(epoch) during this epoch if
  25. >reachable from the root set or their color remains unchanged,
  26. >indicating that they have become garbage. Garbage thus
  27. >identi ed will be detected by the sweeper in the next epoch.)
  28. >It is simple matter for an implementation to make reclaimed
  29. >free lists available for mutator allocation without explicit
  30. >synchronization (x4).
  31.  
  32. So, the condition mentioned above states that the object's block will be freed if its color is epoch-2 and unreachable from the marker and mutator.
  33. In this case, it will always be epoch, updated by marker. Hence, never freed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement