Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1560)

Side by Side Diff: Modules/gcmodule.c

Issue 22043: Use a monotonic clock to compute timeouts
Patch Set: Created 3 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Modules/_threadmodule.c ('k') | Modules/socketmodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 2
3 Reference Cycle Garbage Collection 3 Reference Cycle Garbage Collection
4 ================================== 4 ==================================
5 5
6 Neil Schemenauer <nas@arctrix.com> 6 Neil Schemenauer <nas@arctrix.com>
7 7
8 Based on a post on the python-dev list. Ideas from Guido van Rossum, 8 Based on a post on the python-dev list. Ideas from Guido van Rossum,
9 Eric Tiedemann, and various others. 9 Eric Tiedemann, and various others.
10 10
11 http://www.arctrix.com/nas/python/gc/ 11 http://www.arctrix.com/nas/python/gc/
12 12
13 The following mailing list threads provide a historical perspective on 13 The following mailing list threads provide a historical perspective on
14 the design of this module. Note that a fair amount of refinement has 14 the design of this module. Note that a fair amount of refinement has
15 occurred since those discussions. 15 occurred since those discussions.
16 16
17 http://mail.python.org/pipermail/python-dev/2000-March/002385.html 17 http://mail.python.org/pipermail/python-dev/2000-March/002385.html
18 http://mail.python.org/pipermail/python-dev/2000-March/002434.html 18 http://mail.python.org/pipermail/python-dev/2000-March/002434.html
19 http://mail.python.org/pipermail/python-dev/2000-March/002497.html 19 http://mail.python.org/pipermail/python-dev/2000-March/002497.html
20 20
21 For a highlevel view of the collection process, read the collect 21 For a highlevel view of the collection process, read the collect
22 function. 22 function.
23 23
24 */ 24 */
25 25
26 #include "Python.h" 26 #include "Python.h"
27 #include "frameobject.h" /* for PyFrame_ClearFreeList */ 27 #include "frameobject.h" /* for PyFrame_ClearFreeList */
28 #include "pytime.h" /* for _PyTime_gettimeofday, _PyTime_INTERVAL */ 28 #include "pytime.h" /* for _PyTime_monotonic, _PyTime_INTERVAL */
29 29
30 /* Get an object's GC head */ 30 /* Get an object's GC head */
31 #define AS_GC(o) ((PyGC_Head *)(o)-1) 31 #define AS_GC(o) ((PyGC_Head *)(o)-1)
32 32
33 /* Get the object given the GC head */ 33 /* Get the object given the GC head */
34 #define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1)) 34 #define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
35 35
36 /*** Global GC state ***/ 36 /*** Global GC state ***/
37 37
38 struct gc_generation { 38 struct gc_generation {
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 912
913 struct gc_generation_stats *stats = &generation_stats[generation]; 913 struct gc_generation_stats *stats = &generation_stats[generation];
914 914
915 if (debug & DEBUG_STATS) { 915 if (debug & DEBUG_STATS) {
916 PySys_WriteStderr("gc: collecting generation %d...\n", 916 PySys_WriteStderr("gc: collecting generation %d...\n",
917 generation); 917 generation);
918 PySys_WriteStderr("gc: objects in each generation:"); 918 PySys_WriteStderr("gc: objects in each generation:");
919 for (i = 0; i < NUM_GENERATIONS; i++) 919 for (i = 0; i < NUM_GENERATIONS; i++)
920 PySys_FormatStderr(" %zd", 920 PySys_FormatStderr(" %zd",
921 gc_list_size(GEN_HEAD(i))); 921 gc_list_size(GEN_HEAD(i)));
922 _PyTime_gettimeofday(&t1); 922 _PyTime_monotonic(&t1);
923 923
924 PySys_WriteStderr("\n"); 924 PySys_WriteStderr("\n");
925 } 925 }
926 926
927 /* update collection and allocation counters */ 927 /* update collection and allocation counters */
928 if (generation+1 < NUM_GENERATIONS) 928 if (generation+1 < NUM_GENERATIONS)
929 generations[generation+1].count += 1; 929 generations[generation+1].count += 1;
930 for (i = 0; i <= generation; i++) 930 for (i = 0; i <= generation; i++)
931 generations[i].count = 0; 931 generations[i].count = 0;
932 932
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 * debugging information. */ 1018 * debugging information. */
1019 for (gc = finalizers.gc.gc_next; 1019 for (gc = finalizers.gc.gc_next;
1020 gc != &finalizers; 1020 gc != &finalizers;
1021 gc = gc->gc.gc_next) { 1021 gc = gc->gc.gc_next) {
1022 n++; 1022 n++;
1023 if (debug & DEBUG_UNCOLLECTABLE) 1023 if (debug & DEBUG_UNCOLLECTABLE)
1024 debug_cycle("uncollectable", FROM_GC(gc)); 1024 debug_cycle("uncollectable", FROM_GC(gc));
1025 } 1025 }
1026 if (debug & DEBUG_STATS) { 1026 if (debug & DEBUG_STATS) {
1027 _PyTime_timeval t2; 1027 _PyTime_timeval t2;
1028 _PyTime_gettimeofday(&t2); 1028 _PyTime_monotonic(&t2);
1029 1029
1030 if (m == 0 && n == 0) 1030 if (m == 0 && n == 0)
1031 PySys_WriteStderr("gc: done"); 1031 PySys_WriteStderr("gc: done");
1032 else 1032 else
1033 PySys_FormatStderr( 1033 PySys_FormatStderr(
1034 "gc: done, %zd unreachable, %zd uncollectable", 1034 "gc: done, %zd unreachable, %zd uncollectable",
1035 n+m, n); 1035 n+m, n);
1036 PySys_WriteStderr(", %.4fs elapsed\n", _PyTime_INTERVAL(t1, t2)); 1036 PySys_WriteStderr(", %.4fs elapsed\n", _PyTime_INTERVAL(t1, t2));
1037 } 1037 }
1038 1038
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 PyObject_GC_Del(void *op) 1769 PyObject_GC_Del(void *op)
1770 { 1770 {
1771 PyGC_Head *g = AS_GC(op); 1771 PyGC_Head *g = AS_GC(op);
1772 if (IS_TRACKED(op)) 1772 if (IS_TRACKED(op))
1773 gc_list_remove(g); 1773 gc_list_remove(g);
1774 if (generations[0].count > 0) { 1774 if (generations[0].count > 0) {
1775 generations[0].count--; 1775 generations[0].count--;
1776 } 1776 }
1777 PyObject_FREE(g); 1777 PyObject_FREE(g);
1778 } 1778 }
OLDNEW
« no previous file with comments | « Modules/_threadmodule.c ('k') | Modules/socketmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7