diff options
Diffstat (limited to 'src/lj_obj.h')
-rw-r--r-- | src/lj_obj.h | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/lj_obj.h b/src/lj_obj.h index 6c974812..9d4bec08 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -13,7 +13,7 @@ | |||
13 | #include "lj_def.h" | 13 | #include "lj_def.h" |
14 | #include "lj_arch.h" | 14 | #include "lj_arch.h" |
15 | 15 | ||
16 | /* -- Memory references (32 bit address space) ---------------------------- */ | 16 | /* -- Memory references --------------------------------------------------- */ |
17 | 17 | ||
18 | /* Memory and GC object sizes. */ | 18 | /* Memory and GC object sizes. */ |
19 | typedef uint32_t MSize; | 19 | typedef uint32_t MSize; |
@@ -44,7 +44,7 @@ typedef struct MRef { | |||
44 | #define setmrefr(r, v) ((r).ptr32 = (v).ptr32) | 44 | #define setmrefr(r, v) ((r).ptr32 = (v).ptr32) |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | /* -- GC object references (32 bit address space) ------------------------- */ | 47 | /* -- GC object references ------------------------------------------------ */ |
48 | 48 | ||
49 | /* GCobj reference */ | 49 | /* GCobj reference */ |
50 | typedef struct GCRef { | 50 | typedef struct GCRef { |
@@ -287,12 +287,16 @@ typedef const TValue cTValue; | |||
287 | 287 | ||
288 | /* -- String object ------------------------------------------------------- */ | 288 | /* -- String object ------------------------------------------------------- */ |
289 | 289 | ||
290 | typedef uint32_t StrHash; /* String hash value. */ | ||
291 | typedef uint32_t StrID; /* String ID. */ | ||
292 | |||
290 | /* String object header. String payload follows. */ | 293 | /* String object header. String payload follows. */ |
291 | typedef struct GCstr { | 294 | typedef struct GCstr { |
292 | GCHeader; | 295 | GCHeader; |
293 | uint8_t reserved; /* Used by lexer for fast lookup of reserved words. */ | 296 | uint8_t reserved; /* Used by lexer for fast lookup of reserved words. */ |
294 | uint8_t unused; | 297 | uint8_t hashalg; /* Hash algorithm. */ |
295 | MSize hash; /* Hash of string. */ | 298 | StrID sid; /* Interned string ID. */ |
299 | StrHash hash; /* Hash of string. */ | ||
296 | MSize len; /* Size of string. */ | 300 | MSize len; /* Size of string. */ |
297 | } GCstr; | 301 | } GCstr; |
298 | 302 | ||
@@ -300,7 +304,6 @@ typedef struct GCstr { | |||
300 | #define strdata(s) ((const char *)((s)+1)) | 304 | #define strdata(s) ((const char *)((s)+1)) |
301 | #define strdatawr(s) ((char *)((s)+1)) | 305 | #define strdatawr(s) ((char *)((s)+1)) |
302 | #define strVdata(o) strdata(strV(o)) | 306 | #define strVdata(o) strdata(strV(o)) |
303 | #define sizestring(s) (sizeof(struct GCstr)+(s)->len+1) | ||
304 | 307 | ||
305 | /* -- Userdata object ----------------------------------------------------- */ | 308 | /* -- Userdata object ----------------------------------------------------- */ |
306 | 309 | ||
@@ -570,6 +573,7 @@ typedef enum { | |||
570 | #define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)]) | 573 | #define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)]) |
571 | #define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)])) | 574 | #define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)])) |
572 | 575 | ||
576 | /* Garbage collector state. */ | ||
573 | typedef struct GCState { | 577 | typedef struct GCState { |
574 | GCSize total; /* Memory currently allocated. */ | 578 | GCSize total; /* Memory currently allocated. */ |
575 | GCSize threshold; /* Memory threshold. */ | 579 | GCSize threshold; /* Memory threshold. */ |
@@ -590,25 +594,36 @@ typedef struct GCState { | |||
590 | MSize pause; /* Pause between successive GC cycles. */ | 594 | MSize pause; /* Pause between successive GC cycles. */ |
591 | } GCState; | 595 | } GCState; |
592 | 596 | ||
597 | /* String interning state. */ | ||
598 | typedef struct StrInternState { | ||
599 | GCRef *tab; /* String hash table anchors. */ | ||
600 | MSize mask; /* String hash mask (size of hash table - 1). */ | ||
601 | MSize num; /* Number of strings in hash table. */ | ||
602 | StrID id; /* Next string ID. */ | ||
603 | uint8_t idreseed; /* String ID reseed counter. */ | ||
604 | uint8_t second; /* String interning table uses secondary hashing. */ | ||
605 | uint8_t unused1; | ||
606 | uint8_t unused2; | ||
607 | LJ_ALIGN(8) uint64_t seed; /* Random string seed. */ | ||
608 | } StrInternState; | ||
609 | |||
593 | /* Global state, shared by all threads of a Lua universe. */ | 610 | /* Global state, shared by all threads of a Lua universe. */ |
594 | typedef struct global_State { | 611 | typedef struct global_State { |
595 | GCRef *strhash; /* String hash table (hash chain anchors). */ | ||
596 | MSize strmask; /* String hash mask (size of hash table - 1). */ | ||
597 | MSize strnum; /* Number of strings in hash table. */ | ||
598 | lua_Alloc allocf; /* Memory allocator. */ | 612 | lua_Alloc allocf; /* Memory allocator. */ |
599 | void *allocd; /* Memory allocator data. */ | 613 | void *allocd; /* Memory allocator data. */ |
600 | GCState gc; /* Garbage collector. */ | 614 | GCState gc; /* Garbage collector. */ |
601 | volatile int32_t vmstate; /* VM state or current JIT code trace number. */ | ||
602 | SBuf tmpbuf; /* Temporary string buffer. */ | ||
603 | GCstr strempty; /* Empty string. */ | 615 | GCstr strempty; /* Empty string. */ |
604 | uint8_t stremptyz; /* Zero terminator of empty string. */ | 616 | uint8_t stremptyz; /* Zero terminator of empty string. */ |
605 | uint8_t hookmask; /* Hook mask. */ | 617 | uint8_t hookmask; /* Hook mask. */ |
606 | uint8_t dispatchmode; /* Dispatch mode. */ | 618 | uint8_t dispatchmode; /* Dispatch mode. */ |
607 | uint8_t vmevmask; /* VM event mask. */ | 619 | uint8_t vmevmask; /* VM event mask. */ |
620 | StrInternState str; /* String interning. */ | ||
621 | volatile int32_t vmstate; /* VM state or current JIT code trace number. */ | ||
608 | GCRef mainthref; /* Link to main thread. */ | 622 | GCRef mainthref; /* Link to main thread. */ |
609 | TValue registrytv; /* Anchor for registry. */ | 623 | SBuf tmpbuf; /* Temporary string buffer. */ |
610 | TValue tmptv, tmptv2; /* Temporary TValues. */ | 624 | TValue tmptv, tmptv2; /* Temporary TValues. */ |
611 | Node nilnode; /* Fallback 1-element hash part (nil key and value). */ | 625 | Node nilnode; /* Fallback 1-element hash part (nil key and value). */ |
626 | TValue registrytv; /* Anchor for registry. */ | ||
612 | GCupval uvhead; /* Head of double-linked list of all open upvalues. */ | 627 | GCupval uvhead; /* Head of double-linked list of all open upvalues. */ |
613 | int32_t hookcount; /* Instruction hook countdown. */ | 628 | int32_t hookcount; /* Instruction hook countdown. */ |
614 | int32_t hookcstart; /* Start count for instruction hook counter. */ | 629 | int32_t hookcstart; /* Start count for instruction hook counter. */ |