diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-13 15:43:02 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-13 15:43:02 -0300 |
commit | 2e297d6ab37c1bb255b6984b91dd92d9080e02c9 (patch) | |
tree | d9031b8d7fbd2670efb6f9a7d24a7a08f24de844 /testes | |
parent | fb18346dddcb0400d0396111c56a817a8d4bd8bd (diff) | |
download | lua-2e297d6ab37c1bb255b6984b91dd92d9080e02c9.tar.gz lua-2e297d6ab37c1bb255b6984b91dd92d9080e02c9.tar.bz2 lua-2e297d6ab37c1bb255b6984b91dd92d9080e02c9.zip |
Fixed bug in generational collection of userdata
During generational collection, a userdatum must become gray and
go to a gray list after being traversed (like tables), so that
'correctgraylist' can handle it to its next stage.
This commit also added minimum tests for the generational collector,
including one that would detect this bug.
Diffstat (limited to 'testes')
-rwxr-xr-x | testes/all.lua | 4 | ||||
-rw-r--r-- | testes/gc.lua | 4 | ||||
-rw-r--r-- | testes/gengc.lua | 83 |
3 files changed, 87 insertions, 4 deletions
diff --git a/testes/all.lua b/testes/all.lua index cfe21603..37796254 100755 --- a/testes/all.lua +++ b/testes/all.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | #!../lua | 1 | #!../lua |
2 | -- $Id: all.lua,v 1.100 2018/03/09 14:23:48 roberto Exp $ | 2 | -- $Id: all.lua $ |
3 | -- See Copyright Notice at the end of this file | 3 | -- See Copyright Notice at the end of this file |
4 | 4 | ||
5 | 5 | ||
@@ -162,7 +162,7 @@ olddofile('strings.lua') | |||
162 | olddofile('literals.lua') | 162 | olddofile('literals.lua') |
163 | dofile('tpack.lua') | 163 | dofile('tpack.lua') |
164 | assert(dofile('attrib.lua') == 27) | 164 | assert(dofile('attrib.lua') == 27) |
165 | 165 | dofile('gengc.lua') | |
166 | assert(dofile('locals.lua') == 5) | 166 | assert(dofile('locals.lua') == 5) |
167 | dofile('constructs.lua') | 167 | dofile('constructs.lua') |
168 | dofile('code.lua', true) | 168 | dofile('code.lua', true) |
diff --git a/testes/gc.lua b/testes/gc.lua index 9647cd54..05072efd 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -1,7 +1,7 @@ | |||
1 | -- $Id: gc.lua,v 1.82 2018/03/12 14:19:36 roberto Exp $ | 1 | -- $Id: gc.lua $ |
2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file all.lua |
3 | 3 | ||
4 | print('testing garbage collection') | 4 | print('testing incremental garbage collection') |
5 | 5 | ||
6 | local debug = require"debug" | 6 | local debug = require"debug" |
7 | 7 | ||
diff --git a/testes/gengc.lua b/testes/gengc.lua new file mode 100644 index 00000000..36aed806 --- /dev/null +++ b/testes/gengc.lua | |||
@@ -0,0 +1,83 @@ | |||
1 | -- $Id: gengc.lua $ | ||
2 | -- See Copyright Notice in file all.lua | ||
3 | |||
4 | print('testing generational garbage collection') | ||
5 | |||
6 | local debug = require"debug" | ||
7 | |||
8 | assert(collectgarbage("isrunning")) | ||
9 | |||
10 | collectgarbage() | ||
11 | |||
12 | local oldmode = collectgarbage("generational") | ||
13 | |||
14 | |||
15 | -- ensure that table barrier evolves correctly | ||
16 | do | ||
17 | local U = {} | ||
18 | -- full collection makes 'U' old | ||
19 | collectgarbage() | ||
20 | assert(not T or T.gcage(U) == "old") | ||
21 | |||
22 | -- U refers to a new table, so it becomes 'touched1' | ||
23 | U[1] = {x = {234}} | ||
24 | assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new")) | ||
25 | |||
26 | -- both U and the table survive one more collection | ||
27 | collectgarbage("step", 0) | ||
28 | assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival")) | ||
29 | |||
30 | -- both U and the table survive yet another collection | ||
31 | -- now everything is old | ||
32 | collectgarbage("step", 0) | ||
33 | assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1")) | ||
34 | |||
35 | -- data was not corrupted | ||
36 | assert(U[1].x[1] == 234) | ||
37 | end | ||
38 | |||
39 | |||
40 | if T == nil then | ||
41 | (Message or print)('\n >>> testC not active: \z | ||
42 | skipping some generational tests <<<\n') | ||
43 | print 'OK' | ||
44 | return | ||
45 | end | ||
46 | |||
47 | |||
48 | -- ensure that userdata barrier evolves correctly | ||
49 | do | ||
50 | local U = T.newuserdata(0, 1) | ||
51 | -- full collection makes 'U' old | ||
52 | collectgarbage() | ||
53 | assert(T.gcage(U) == "old") | ||
54 | |||
55 | -- U refers to a new table, so it becomes 'touched1' | ||
56 | debug.setuservalue(U, {x = {234}}) | ||
57 | assert(T.gcage(U) == "touched1" and | ||
58 | T.gcage(debug.getuservalue(U)) == "new") | ||
59 | |||
60 | -- both U and the table survive one more collection | ||
61 | collectgarbage("step", 0) | ||
62 | assert(T.gcage(U) == "touched2" and | ||
63 | T.gcage(debug.getuservalue(U)) == "survival") | ||
64 | |||
65 | -- both U and the table survive yet another collection | ||
66 | -- now everything is old | ||
67 | collectgarbage("step", 0) | ||
68 | assert(T.gcage(U) == "old" and | ||
69 | T.gcage(debug.getuservalue(U)) == "old1") | ||
70 | |||
71 | -- data was not corrupted | ||
72 | assert(debug.getuservalue(U).x[1] == 234) | ||
73 | end | ||
74 | |||
75 | |||
76 | |||
77 | -- just to make sure | ||
78 | assert(collectgarbage'isrunning') | ||
79 | |||
80 | collectgarbage(oldmode) | ||
81 | |||
82 | print('OK') | ||
83 | |||