Commit Graph

525 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
65141832d2 Open upvalues should be gray when entering gen. mode
Open upvalues are never black; so, when entering generational mode,
they must be colored gray, not black.
2020-08-07 14:53:38 -03:00
Roberto Ierusalimschy
68109afcdb Detail (in asserts)
Macro 'checkconsistency' replaced by the similar 'checkliveness".
2020-08-03 16:05:10 -03:00
Roberto Ierusalimschy
9cf3299faf Threads don't need to always go to 'grayagain'
In incremental mode, threads don't need to be visited again once
visited in the atomic phase. In generational mode (where all visits
are in the atomic phase), only old threads need to be kept in the
'grayagain' list for the next cycle.
2020-08-03 14:28:13 -03:00
Roberto Ierusalimschy
b9b554e0f6 Clearer handling of gray lists when entering generational mode
When entering generational mode, all objects are old. So, the only
objects that need to be in a gray list are threads, which can be
assigned without barriers. Changes in anything else (e.g., weak
tables) will trigger barriers that, if needed, will add the object
to a gray list.
2020-08-03 13:22:57 -03:00
Roberto Ierusalimschy
0dc5deca1c Optimization in 'markold'
OLD1 objects can be potentially anywhere in the 'allgc' list (up
to 'reallyold'), but frequently they are all after 'old1' (natural
evolution of survivals) or do not exist at all (when all objects die
young). So, instead of 'markold' starts looking for them always
from the start of 'allgc', the collector keeps an extra pointer,
'firstold1', that points to the first OLD1 object in the 'allgc' list,
or is NULL if there are no OLD1 objects in that list.
2020-07-29 17:05:47 -03:00
Roberto Ierusalimschy
b4c353434f Details
The fields 'old' and 'finobjold' were renamed 'old1' and 'finobjold1',
respectively, to make clearer the main ages of their elements.
2020-07-29 11:34:08 -03:00
Roberto Ierusalimschy
71f70df327 OLD1 ages advanced by 'markold'
Objects aged OLD1 have their ages advanced by 'markold', which has to
visit them anyway. So, the GC doesn't need to "sweep" the old1 list.
2020-07-29 09:58:25 -03:00
Roberto Ierusalimschy
663f83f647 Same changes around 'correctgraylist'
Instead of adding all tables and userdata back to the 'grayagain' list
to be checked by 'correctgraylist', the collector adds only the objects
that will remain in that list (objects aged TOUCHED1). This commit
also rewrites 'correctgraylist' with a clearer logic.
2020-07-28 15:51:07 -03:00
Roberto Ierusalimschy
d2c2e32e8a All objects are kept 'new' in incremental GC
Small changes to ensure that all objects are kept 'new' in incremental
GC (except for fixed strings, which are always old) and to make that
fact clearer.
2020-07-27 11:39:42 -03:00
Roberto Ierusalimschy
a6da1472c0 Fixed bug: barriers cannot be active during sweep
Barriers cannot be active during sweep, even in generational mode.
(Although gen. mode is not incremental, it can hit a barrier when
deleting a thread and closing its upvalues.)  The colors of objects are
being changed during sweep and, therefore, cannot be trusted.
2020-07-27 10:26:20 -03:00
Roberto Ierusalimschy
127e7a6c89 Fixed bug of old finalized objects in the GC
When an object aged OLD1 is finalized, it is moved from the list
'finobj' to the *beginning* of the list 'allgc'. So, this part of the
list (and not only the survival list) must be visited by 'markold'.
2020-07-10 14:13:50 -03:00
Roberto Ierusalimschy
9e0a8475cd Added 'simplesect' sections to the manual
'simplesect' encloses the introductory text of sections with
subsections, so that each section either is all text or is all
subsections. (This commit also corrects a small brace error in the
manual and extra spaces/tabs in some other files.)
2020-04-13 13:42:40 -03:00
Roberto Ierusalimschy
46c3587a6f Clearer distinction between types and tags
LUA_T* represents only types; tags (types + Variants) are represented
by LUA_V* constants.
2020-01-31 11:09:53 -03:00
Roberto Ierusalimschy
e592f94a64 Details (mostly comments) 2019-10-22 14:08:22 -03:00
Roberto Ierusalimschy
7bd1e53753 Fixed a warning and other minor issues
Fixed some minor issues from the feedback for 5.4-beta rc1.
2019-10-04 16:17:04 -03:00
Roberto Ierusalimschy
ca13be9af7 Supressed errors in '__close' generate warnings 2019-08-16 09:51:54 -03:00
Roberto Ierusalimschy
f64a1b175a Small optimization in 'convergeephemerons'
When converging marks on ephemeron tables, change the direction the
tables are traversed at each iteration, to try to avoid bad-case
scenarios with linked lists of entries in a table.
2019-08-12 15:32:44 -03:00
Roberto Ierusalimschy
9e6807c3c9 Do not collect open upvalues
Open upvalues are kept alive together with their corresponding
stack. This change makes a simpler and safer fix to the issue in
commit 440a5ee78c, about upvalues in the list of open upvalues
being collected while others are being created. (That previous fix
may not be correct.)
2019-07-22 09:41:10 -03:00
Roberto Ierusalimschy
dc07719b0d Tag LUA_TUPVALTBC replaced by a flag
It is simpler to signal a to-be-closed upvalue with a boolean flag,
instead of using a different tag.
2019-07-19 11:12:31 -03:00
Roberto Ierusalimschy
9cdf6b7082 Some details in 'lmem.c' and 'lgc.c'
- Several new comments in 'lmem.c'.
- Both 'luaM_growaux_' and 'luaM_shrinkvector_' use 'luaM_saferealloc_'
  to check for errors. Moreover, the use of 'luaM_saferealloc_' makes
  'luaM_shrinkvector_' try again if shrink fails (which can happen now).
- In 'checkSizes', save old debt only when needed.
2019-07-19 09:43:35 -03:00
Roberto Ierusalimschy
e888976bc6 Details (typos in comments) 2019-07-05 15:03:15 -03:00
Roberto Ierusalimschy
1d70708a78 Fixed bug [5.4 alpha] for errors in finalizers
Fixes the bug related in [1] (Lua can crash after raising an error
in a finalizer), following the lead in [2].

[1] http://lua-users.org/lists/lua-l/2019-06/msg00448.html
[2] http://lua-users.org/lists/lua-l/2019-06/msg00450.html
2019-06-21 09:34:49 -03:00
Roberto Ierusalimschy
2c68e66570 Details
Several small changes from feedback on 5.4 alhpa rc1 (warnings,
typos in the manual, and the like)
2019-06-03 11:36:42 -03:00
Roberto Ierusalimschy
38425e0692 Avoid moving the collector while in 'GCSenteratomic' state
The 'GCSenteratomic' is just an auxiliary state for transitioning
to 'GCSatomic'. All GC traversals should be done either on the
'GCSpropagate' state or the 'GCSatomic' state.
2019-04-01 14:22:07 -03:00
Roberto Ierusalimschy
8fa4f1380b Finalizers must be callable
Non-function __gc metamethods are not ignored; if present, the
metamethod will be called even if it is not a function.
2019-03-14 15:53:42 -03:00
Roberto Ierusalimschy
b56d4e570a Changes in the warning system
- The warning functions get an extra parameter that tells whether
message is to be continued (instead of using end-of-lines as a signal).

- The user data for the warning function is a regular value, instead
of a writable slot inside the Lua state.
2019-03-14 15:30:54 -03:00
Roberto Ierusalimschy
2c32bff609 After a "bad collections", avoid switching back back to generational
After a major bad collection (one that collects too few objects),
next collection will be major again. In that case, avoid switching
back to generational mode (as it will have to switch again to
incremental to do next major collection).
2019-01-30 11:44:42 -02:00
Roberto Ierusalimschy
c6f7181e91 No more LUA_ERRGCMM errors
Errors in finalizers (__gc metamethods) are never propagated.
Instead, they generate a warning.
2019-01-01 12:14:56 -02:00
Roberto Ierusalimschy
e8c779736f Removed internal cache for closures
The mechanism of "caching the last closure created for a prototype to
try to reuse it the next time a closure for that prototype is created"
was removed. There are several reasons:

- It is hard to find a natural example where this cache has a measurable
impact on performance.

- Programmers already perceive closure creation as something slow,
so they tend to avoid it inside hot paths. (Any case where the cache
could reuse a closure can be rewritten predefining the closure in some
variable and using that variable.)

- The implementation was somewhat complex, due to a bad interaction
with the generational collector. (Typically, new closures are new,
while prototypes are old. So, the cache breaks the invariant that
old objects should not point to new ones.)
2018-11-01 13:21:00 -03:00
Roberto Ierusalimschy
bd96330d03 First "complete" implementation of to-be-closed variables
Still missing:
- handling of memory errors when creating upvalue (must run closing
method all the same)
- interaction with coroutines
2018-10-17 10:44:42 -03:00
Roberto Ierusalimschy
4cd1f4aac0 Towards "to closed" local variables
Start of the implementation of "scoped variables" or "to be closed"
variables, local variables whose '__close' (or themselves) are called
when they go out of scope. This commit implements the syntax, the
opcode, and the creation of the corresponding upvalue, but it still
does not call the finalizations when the variable goes out of scope
(the most important part).

Currently, the syntax is 'local scoped name = exp', but that will
probably change.
2018-10-08 10:42:07 -03:00
Roberto Ierusalimschy
ccae0f5aad Comments about OLD0/OLD1 ages
Improved the comments in file 'lgc.c' explaining the roles of "ages"
OLD0 and OLD1 in the generacional collector.
2018-07-18 11:43:45 -03:00
Roberto Ierusalimschy
2e297d6ab3 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.
2018-07-13 15:43:02 -03:00
Roberto Ierusalimschy
626cf0581b Generational mode may wait longer after a major collection
When Lua is building large long-duration structures, frequent small
minor collections just waste time. Trying to avoid this, the
collector will do a larger pause after a major collection when it
does not collect enough garbage (which is a hint that memory is
being used for long-lasting objects).
2018-07-09 14:22:09 -03:00
Roberto Ierusalimschy
6e600695f8 field 'sizearray' in struct 'Table' changed to 'alimit', which can
be used as a hint for '#t'
2018-06-15 11:14:20 -03:00
Roberto Ierusalimschy
0c7738240e FALLTHROUGH comment must be last "statement"
(so it does not work when inside a block)
2018-03-16 11:22:09 -03:00
Roberto Ierusalimschy
2952bc5fc9 special compact representation for userdata with no user values
(a common case)
2018-02-26 10:35:03 -03:00
Roberto Ierusalimschy
4a7fe61806 in 'clearbykeys', clear keys of just-removed entries too 2018-02-23 10:21:27 -03:00
Roberto Ierusalimschy
9243c414d9 first version of empty entries in tables
(so that, in the future, tables can contain regular nil entries)
2018-02-23 10:16:18 -03:00
Roberto Ierusalimschy
477ca2fe8c some reorganization in 'lobject.h'
(just moving stuff around)
2018-02-22 14:28:10 -03:00
Roberto Ierusalimschy
ca6fe7449a userdata can have multiple user values 2018-02-20 13:52:50 -03:00
Roberto Ierusalimschy
1afd5a152d more generic way to handle 'gclist' 2018-02-19 17:06:56 -03:00
Roberto Ierusalimschy
daff7c3b4d small corrections in generational mode
(cannot call finalizers in emergency collections +
 should set everything before calling finalizers)
2018-02-05 15:14:54 -02:00
Roberto Ierusalimschy
e2b15aa21d janitor work on casts 2018-01-28 13:13:26 -02:00
Roberto Ierusalimschy
cf7eff45f3 keep control of stack top in Lua functions concentrated in 'luaV_execute' 2017-12-28 13:42:57 -02:00
Roberto Ierusalimschy
1d5b885437 when running Lua code, there is no need to keep 'L->top' "correct";
set it only when needed.
2017-12-20 12:58:05 -02:00
Roberto Ierusalimschy
e663a24ab0 more freedom in handling memory-allocation errors (not all allocations
automatically raise an error), which allows fixing a bug when resizing
a table.
2017-12-08 15:28:25 -02:00
Roberto Ierusalimschy
421e459684 'luaS_resize' can raise memory errors 2017-12-01 15:38:49 -02:00
Roberto Ierusalimschy
ac78b914b6 warnings from Visual Studio /W3 2017-11-30 13:37:16 -02:00
Roberto Ierusalimschy
599f1742c6 detail (typo in comments) 2017-11-23 17:29:04 -02:00
Roberto Ierusalimschy
ad0704e40c back to 'CallInfo' (no gains with its removal) 2017-11-07 11:25:26 -02:00
Roberto Ierusalimschy
54eb35a8aa more fields moved out of 'CallInfo' 2017-11-03 10:12:30 -02:00
Roberto Ierusalimschy
de9128d09d do not mess up the debt when the collector is not running 2017-10-31 13:29:28 -02:00
Roberto Ierusalimschy
1d8920dd7f some cleaning in GC parameters 2017-10-11 09:38:45 -03:00
Roberto Ierusalimschy
029d269f4d bug: dead keys with nil values can stay in weak tables 2017-08-31 13:14:41 -03:00
Roberto Ierusalimschy
f96497397a new type 'StackValue' for stack elements
(we may want to put extra info there in the future)
2017-06-29 12:06:44 -03:00
Roberto Ierusalimschy
73ec04fcf3 no more 'DEADKEY'. Table traversals do not need to consider dead keys;
if the key is dead, it cannot be given to 'next'. Instead, we now
use a 'table' tag without the collectable bit, which makes it
a unique tag good enough to reserve space.
2017-06-12 11:21:44 -03:00
Roberto Ierusalimschy
b6f87491af in hash nodes, keys are stored in separate pieces to avoid wasting
space with alignments
2017-06-09 13:48:44 -03:00
Roberto Ierusalimschy
4bc33d64de avoid overflows in computation of step size 2017-06-01 16:16:34 -03:00
Roberto Ierusalimschy
72d82a296c revamping the incremental collector
Some simplifications (not counting bytes, couting only slots visited;
no more 'gcfinnum'); more GC parameters; using vararg in 'lua_gc' to
set parameters in different GC modes
2017-05-26 16:14:29 -03:00
Roberto Ierusalimschy
2376eb6347 barrier for prototype's cache (with new gray list 'protogray' to keep
prototypes to have their caches visited again) + constant 'MAXMISS'
2017-05-04 10:32:01 -03:00
Roberto Ierusalimschy
8634b2a011 added 'cachemiss' field to prototype to avoid wasting time checking
hits that fail too often
2017-04-30 17:43:26 -03:00
Roberto Ierusalimschy
f399e6705f ensures that "collectgarbage'step'" in generational mode does a
minor collection
2017-04-24 14:52:18 -03:00
Roberto Ierusalimschy
69371c4b84 'KGC_NORMAL' -> 'KGC_INC' + emergency GC signalled by flag (instead
of mode)
2017-04-24 13:59:26 -03:00
Roberto Ierusalimschy
c354211744 small bug in generational control 2017-04-20 15:24:33 -03:00
Roberto Ierusalimschy
c7bdc0e0e8 first version of control for the generational collector 2017-04-19 14:02:50 -03:00
Roberto Ierusalimschy
16001acb15 small corrections + removal of debugging functions 'count' and
'printgray'.
2017-04-12 15:01:40 -03:00
Roberto Ierusalimschy
0c8a7e071b 'mainthread' lives in 'allgc' list, like everybody else 2017-04-11 16:00:27 -03:00
Roberto Ierusalimschy
a3d36fe283 Upvalues collected like everything else (with mark-sweep) instead
of reference count (simpler and better for generational mode)
2017-04-11 15:41:09 -03:00
Roberto Ierusalimschy
9569ad6b0d Comments for generational collector 2017-04-10 10:33:04 -03:00
Roberto Ierusalimschy
2331e1beec small changes in 'luaC_upvalbarrier' 2017-04-06 10:08:56 -03:00
Roberto Ierusalimschy
e4287da3a6 generational collector (still not complete) 2017-04-05 13:50:51 -03:00
Roberto Ierusalimschy
f5f3df3bd1 generational collection: new attempt (still incomplete) 2017-02-23 18:07:34 -03:00
Roberto Ierusalimschy
2a235312f0 detail (removing spaces at end of lines) 2016-12-22 11:08:50 -02:00
Roberto Ierusalimschy
7b1fba69b7 using 'lastfree == NULL' to signal that table is using the dummy
node for its hash part + new macro 'allocsizenode'
2016-11-07 10:38:35 -02:00
Roberto Ierusalimschy
138d00176c new flag in 'CallInfo.callstatus' to tell whether function is running
as a finalizer
2016-10-19 10:31:42 -02:00
Roberto Ierusalimschy
8d4feb504f do not try to ensure that 'sweepgc' points to a live object
when entering sweep phase ('entersweep'); that may be too
expensive to be done still inside the atomic step. Walking
one single object more often than not will work.
2016-03-31 16:02:03 -03:00
Roberto Ierusalimschy
03412af06e detail (removed fixed argument to function 'callallpendingfinalizers') 2015-12-10 16:12:30 -02:00
Roberto Ierusalimschy
7485512384 added comment and assert about dead keys 2015-11-03 16:10:44 -02:00
Roberto Ierusalimschy
ff1289a361 in 'luaD_call', use two functions instead of one with fixed boolean
argument
2015-11-02 16:48:07 -02:00
Roberto Ierusalimschy
cd73f3ccc5 now that we have a counter for CallInfos, use it for a more
accurate value for the memory used by a thread
2015-11-02 14:19:29 -02:00
Roberto Ierusalimschy
41964648ee long strings are created directly in final position when possible
(instead of using an auxiliar buffer to first create the string
and then allocate the final string and copy result there)
2015-09-08 12:41:05 -03:00
Roberto Ierusalimschy
2b61360d82 avoid overflows (detected with 'clang -ftrapv') 2015-07-13 10:30:03 -03:00
Roberto Ierusalimschy
b436ed58a3 'clearapihash' -> 'luaS_clearcache' and moved to 'lstring.c' (which
keeps all code related to this cache)
2015-03-25 10:42:19 -03:00
Roberto Ierusalimschy
2ae2e6408e avoid testing for NULL when marking objects that cannot be NULL 2015-03-04 10:51:55 -03:00
Roberto Ierusalimschy
a80cada914 new cache for interning strings 2015-03-04 10:31:21 -03:00
Roberto Ierusalimschy
7e2015a46d size of short strings stored in a single byte, to reduce the size
of struct 'TString'
2015-01-16 14:54:37 -02:00
Roberto Ierusalimschy
88ef06f4f3 comments were wrong (not updated about several changes) 2014-12-20 11:58:15 -02:00
Roberto Ierusalimschy
28fdbcf393 added include for 'lprefix.h', for stuff that must be added before
any other header file
2014-11-02 17:19:04 -02:00
Roberto Ierusalimschy
4542fb9f78 comments (a few extra quotes around identifiers) 2014-10-30 16:53:28 -02:00
Roberto Ierusalimschy
e9885efc7c added comment and assert about an (impossible) division by zero 2014-10-29 13:02:53 -02:00
Roberto Ierusalimschy
bdf566a8a3 `name' in comments changed to 'name' 2014-10-25 09:50:46 -02:00
Roberto Ierusalimschy
2f4d429071 details (comments) 2014-10-03 09:54:57 -03:00
Roberto Ierusalimschy
3a15c7ce43 size for array part of a table ('sizearray') changed from 'int' to
'unsigned int', which allows twice as many elements in the array part
2014-09-04 15:15:29 -03:00
Roberto Ierusalimschy
0a6b58c3aa weak tables that must be retraversed are kept in 'grayagain' list
until atomic phase (instead of going to their special lists) +
more comments
2014-09-03 13:54:41 -03:00
Roberto Ierusalimschy
df608f842a 'linktable' -> 'linkgclist' (and used for all links with 'gclist') 2014-09-01 14:37:11 -03:00
Roberto Ierusalimschy
07c7fdb9df simpler definition for 'setobj' (trust the compiler for the assignment) 2014-07-29 13:22:24 -03:00
Roberto Ierusalimschy
3c6d0aaa7d 'iswhite' and related macros now can work directly on any object
(no need to convert to 'GCObject')
2014-07-19 12:14:46 -03:00
Roberto Ierusalimschy
e43612aaf6 put the restriction that 'luaC_barrierback' works only on tables
in its prototype
2014-07-19 12:09:37 -03:00
Roberto Ierusalimschy
2898e2fd12 removed useless assertion (gcstate != GCSpause already implied by
other assertions) and wrong assertion (setmetatable uses this barrier
for tables too)
2014-07-19 11:44:19 -03:00