diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-18 11:43:45 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-18 11:43:45 -0300 |
commit | ccae0f5aad11b448fa630a41b2c7c54e69d134d8 (patch) | |
tree | 472344c8b460746edf8d2bf78b46618e719eafbe | |
parent | 2e297d6ab37c1bb255b6984b91dd92d9080e02c9 (diff) | |
download | lua-ccae0f5aad11b448fa630a41b2c7c54e69d134d8.tar.gz lua-ccae0f5aad11b448fa630a41b2c7c54e69d134d8.tar.bz2 lua-ccae0f5aad11b448fa630a41b2c7c54e69d134d8.zip |
Comments about OLD0/OLD1 ages
Improved the comments in file 'lgc.c' explaining the roles of "ages"
OLD0 and OLD1 in the generacional collector.
-rw-r--r-- | lgc.c | 54 |
1 files changed, 30 insertions, 24 deletions
@@ -181,9 +181,13 @@ static int iscleared (global_State *g, const GCObject *o) { | |||
181 | 181 | ||
182 | /* | 182 | /* |
183 | ** barrier that moves collector forward, that is, mark the white object | 183 | ** barrier that moves collector forward, that is, mark the white object |
184 | ** being pointed by a black object. (If in sweep phase, clear the black | 184 | ** 'v' being pointed by the black object 'o'. (If in sweep phase, clear |
185 | ** object to white [sweep it] to avoid other barrier calls for this | 185 | ** the black object to white [sweep it] to avoid other barrier calls for |
186 | ** same object.) | 186 | ** this same object.) In the generational mode, 'v' must also become |
187 | ** old, if 'o' is old; however, it cannot be changed directly to OLD, | ||
188 | ** because it may still point to non-old objects. So, it is marked as | ||
189 | ** OLD0. In the next cycle it will become OLD1, and in the next it | ||
190 | ** will finally become OLD (regular old). | ||
187 | */ | 191 | */ |
188 | void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { | 192 | void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { |
189 | global_State *g = G(L); | 193 | global_State *g = G(L); |
@@ -218,13 +222,14 @@ void luaC_barrierback_ (lua_State *L, GCObject *o) { | |||
218 | 222 | ||
219 | 223 | ||
220 | /* | 224 | /* |
221 | ** Barrier for prototype's cache of closures. For an 'old1' | 225 | ** Barrier for prototype's cache of closures. It turns the prototype |
222 | ** object, making it gray stops it from being visited by 'markold', | 226 | ** back to gray (it was black). For an 'OLD1' prototype, making it |
223 | ** so it is linked in the 'grayagain' list to ensure it will be | 227 | ** gray stops it from being visited by 'markold', so it is linked in |
224 | ** visited. Otherwise, it goes to 'protogray', as only its 'cache' field | 228 | ** the 'grayagain' list to ensure it will be visited. For other ages, |
225 | ** needs to be revisited. (A prototype to be in this barrier must be | 229 | ** it goes to the 'protogray' list, as only its 'cache' field needs to |
226 | ** already finished, so its other fields cannot change and do not need | 230 | ** be revisited. (A prototype to be in this barrier must be already |
227 | ** to be revisited.) | 231 | ** finished, so its other fields cannot change and do not need to be |
232 | ** revisited.) | ||
228 | */ | 233 | */ |
229 | LUAI_FUNC void luaC_protobarrier_ (lua_State *L, Proto *p) { | 234 | LUAI_FUNC void luaC_protobarrier_ (lua_State *L, Proto *p) { |
230 | global_State *g = G(L); | 235 | global_State *g = G(L); |
@@ -233,7 +238,7 @@ LUAI_FUNC void luaC_protobarrier_ (lua_State *L, Proto *p) { | |||
233 | linkgclist(p, g->grayagain); /* link it in 'grayagain' */ | 238 | linkgclist(p, g->grayagain); /* link it in 'grayagain' */ |
234 | else | 239 | else |
235 | linkgclist(p, g->protogray); /* link it in 'protogray' */ | 240 | linkgclist(p, g->protogray); /* link it in 'protogray' */ |
236 | black2gray(p); /* make prototype gray (to avoid other barriers) */ | 241 | black2gray(p); /* make prototype gray */ |
237 | } | 242 | } |
238 | 243 | ||
239 | 244 | ||
@@ -533,9 +538,9 @@ static int traverseudata (global_State *g, Udata *u) { | |||
533 | ** cache is white, clear it. (A cache should not prevent the | 538 | ** cache is white, clear it. (A cache should not prevent the |
534 | ** collection of its reference.) Otherwise, if in generational | 539 | ** collection of its reference.) Otherwise, if in generational |
535 | ** mode, check the generational invariant. If the cache is old, | 540 | ** mode, check the generational invariant. If the cache is old, |
536 | ** everything is ok. If the prototype is 'old0', everything | 541 | ** everything is ok. If the prototype is 'OLD0', everything |
537 | ** is ok too. (It will naturally be visited again.) If the | 542 | ** is ok too. (It will naturally be visited again.) If the |
538 | ** prototype is older than 'old0', then its cache (which is new) | 543 | ** prototype is older than 'OLD0', then its cache (which is new) |
539 | ** must be visited again in the next collection, so the prototype | 544 | ** must be visited again in the next collection, so the prototype |
540 | ** goes to the 'protogray' list. (If the prototype has a cache, | 545 | ** goes to the 'protogray' list. (If the prototype has a cache, |
541 | ** it is already immutable and does not need other barriers; | 546 | ** it is already immutable and does not need other barriers; |
@@ -1085,9 +1090,9 @@ static void whitelist (global_State *g, GCObject *p) { | |||
1085 | 1090 | ||
1086 | 1091 | ||
1087 | /* | 1092 | /* |
1088 | ** Correct a list of gray objects. Because this correction is | 1093 | ** Correct a list of gray objects. |
1089 | ** done after sweeping, young objects can be white and still | 1094 | ** Because this correction is done after sweeping, young objects might |
1090 | ** be in the list. They are only removed. | 1095 | ** be turned white and still be in the list. They are only removed. |
1091 | ** For tables and userdata, advance 'touched1' to 'touched2'; 'touched2' | 1096 | ** For tables and userdata, advance 'touched1' to 'touched2'; 'touched2' |
1092 | ** objects become regular old and are removed from the list. | 1097 | ** objects become regular old and are removed from the list. |
1093 | ** For threads, just remove white ones from the list. | 1098 | ** For threads, just remove white ones from the list. |
@@ -1104,13 +1109,14 @@ static GCObject **correctgraylist (GCObject **p) { | |||
1104 | changeage(curr, G_TOUCHED1, G_TOUCHED2); | 1109 | changeage(curr, G_TOUCHED1, G_TOUCHED2); |
1105 | p = next; /* go to next element */ | 1110 | p = next; /* go to next element */ |
1106 | } | 1111 | } |
1107 | else { | 1112 | else { /* not touched in this cycle */ |
1108 | if (!iswhite(curr)) { | 1113 | if (!iswhite(curr)) { /* not white? */ |
1109 | lua_assert(isold(curr)); | 1114 | lua_assert(isold(curr)); |
1110 | if (getage(curr) == G_TOUCHED2) | 1115 | if (getage(curr) == G_TOUCHED2) /* advance from G_TOUCHED2... */ |
1111 | changeage(curr, G_TOUCHED2, G_OLD); | 1116 | changeage(curr, G_TOUCHED2, G_OLD); /* ... to G_OLD */ |
1112 | gray2black(curr); /* make it black */ | 1117 | gray2black(curr); /* make it black */ |
1113 | } | 1118 | } |
1119 | /* else, object is white: just remove it from this list */ | ||
1114 | *p = *next; /* remove 'curr' from gray list */ | 1120 | *p = *next; /* remove 'curr' from gray list */ |
1115 | } | 1121 | } |
1116 | break; | 1122 | break; |
@@ -1146,7 +1152,7 @@ static void correctgraylists (global_State *g) { | |||
1146 | 1152 | ||
1147 | 1153 | ||
1148 | /* | 1154 | /* |
1149 | ** Mark 'old1' objects when starting a new young collection. | 1155 | ** Mark 'OLD1' objects when starting a new young collection. |
1150 | ** Gray objects are already in some gray list, and so will be visited | 1156 | ** Gray objects are already in some gray list, and so will be visited |
1151 | ** in the atomic step. | 1157 | ** in the atomic step. |
1152 | */ | 1158 | */ |
@@ -1177,9 +1183,9 @@ static void finishgencycle (lua_State *L, global_State *g) { | |||
1177 | 1183 | ||
1178 | 1184 | ||
1179 | /* | 1185 | /* |
1180 | ** Does a young collection. First, mark 'old1' objects. (Only survival | 1186 | ** Does a young collection. First, mark 'OLD1' objects. (Only survival |
1181 | ** and "recent old" lists can contain 'old1' objects. New lists cannot | 1187 | ** and "recent old" lists can contain 'OLD1' objects. New lists cannot |
1182 | ** contain 'old1' objects, at most 'old0' objects that were already | 1188 | ** contain 'OLD1' objects, at most 'OLD0' objects that were already |
1183 | ** visited when marked old.) Then does the atomic step. Then, | 1189 | ** visited when marked old.) Then does the atomic step. Then, |
1184 | ** sweep all lists and advance pointers. Finally, finish the collection. | 1190 | ** sweep all lists and advance pointers. Finally, finish the collection. |
1185 | */ | 1191 | */ |