diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_obj.h | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/lj_obj.h b/src/lj_obj.h index 9d4bec08..9a783a5c 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -232,7 +232,7 @@ typedef const TValue cTValue; | |||
232 | ** ---MSW---.---LSW--- | 232 | ** ---MSW---.---LSW--- |
233 | ** primitive types | itype | | | 233 | ** primitive types | itype | | |
234 | ** lightuserdata | itype | void * | (32 bit platforms) | 234 | ** lightuserdata | itype | void * | (32 bit platforms) |
235 | ** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers) | 235 | ** lightuserdata |ffff|seg| ofs | (64 bit platforms) |
236 | ** GC objects | itype | GCRef | | 236 | ** GC objects | itype | GCRef | |
237 | ** int (LJ_DUALNUM)| itype | int | | 237 | ** int (LJ_DUALNUM)| itype | int | |
238 | ** number -------double------ | 238 | ** number -------double------ |
@@ -245,7 +245,8 @@ typedef const TValue cTValue; | |||
245 | ** | 245 | ** |
246 | ** ------MSW------.------LSW------ | 246 | ** ------MSW------.------LSW------ |
247 | ** primitive types |1..1|itype|1..................1| | 247 | ** primitive types |1..1|itype|1..................1| |
248 | ** GC objects/lightud |1..1|itype|-------GCRef--------| | 248 | ** GC objects |1..1|itype|-------GCRef--------| |
249 | ** lightuserdata |1..1|itype|seg|------ofs-------| | ||
249 | ** int (LJ_DUALNUM) |1..1|itype|0..0|-----int-------| | 250 | ** int (LJ_DUALNUM) |1..1|itype|0..0|-----int-------| |
250 | ** number ------------double------------- | 251 | ** number ------------double------------- |
251 | ** | 252 | ** |
@@ -285,6 +286,12 @@ typedef const TValue cTValue; | |||
285 | #define LJ_GCVMASK (((uint64_t)1 << 47) - 1) | 286 | #define LJ_GCVMASK (((uint64_t)1 << 47) - 1) |
286 | #endif | 287 | #endif |
287 | 288 | ||
289 | #if LJ_64 | ||
290 | /* To stay within 47 bits, lightuserdata is segmented. */ | ||
291 | #define LJ_LIGHTUD_BITS_SEG 8 | ||
292 | #define LJ_LIGHTUD_BITS_LO (47 - LJ_LIGHTUD_BITS_SEG) | ||
293 | #endif | ||
294 | |||
288 | /* -- String object ------------------------------------------------------- */ | 295 | /* -- String object ------------------------------------------------------- */ |
289 | 296 | ||
290 | typedef uint32_t StrHash; /* String hash value. */ | 297 | typedef uint32_t StrHash; /* String hash value. */ |
@@ -580,7 +587,11 @@ typedef struct GCState { | |||
580 | uint8_t currentwhite; /* Current white color. */ | 587 | uint8_t currentwhite; /* Current white color. */ |
581 | uint8_t state; /* GC state. */ | 588 | uint8_t state; /* GC state. */ |
582 | uint8_t nocdatafin; /* No cdata finalizer called. */ | 589 | uint8_t nocdatafin; /* No cdata finalizer called. */ |
583 | uint8_t unused2; | 590 | #if LJ_64 |
591 | uint8_t lightudnum; /* Number of lightuserdata segments - 1. */ | ||
592 | #else | ||
593 | uint8_t unused1; | ||
594 | #endif | ||
584 | MSize sweepstr; /* Sweep position in string table. */ | 595 | MSize sweepstr; /* Sweep position in string table. */ |
585 | GCRef root; /* List of all collectable objects. */ | 596 | GCRef root; /* List of all collectable objects. */ |
586 | MRef sweep; /* Sweep position in root list. */ | 597 | MRef sweep; /* Sweep position in root list. */ |
@@ -592,6 +603,9 @@ typedef struct GCState { | |||
592 | GCSize estimate; /* Estimate of memory actually in use. */ | 603 | GCSize estimate; /* Estimate of memory actually in use. */ |
593 | MSize stepmul; /* Incremental GC step granularity. */ | 604 | MSize stepmul; /* Incremental GC step granularity. */ |
594 | MSize pause; /* Pause between successive GC cycles. */ | 605 | MSize pause; /* Pause between successive GC cycles. */ |
606 | #if LJ_64 | ||
607 | MRef lightudseg; /* Upper bits of lightuserdata segments. */ | ||
608 | #endif | ||
595 | } GCState; | 609 | } GCState; |
596 | 610 | ||
597 | /* String interning state. */ | 611 | /* String interning state. */ |
@@ -813,10 +827,23 @@ typedef union GCobj { | |||
813 | #endif | 827 | #endif |
814 | #define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - itype(o))) | 828 | #define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - itype(o))) |
815 | #if LJ_64 | 829 | #if LJ_64 |
816 | #define lightudV(o) \ | 830 | #define lightudseg(u) \ |
817 | check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff))) | 831 | (((u) >> LJ_LIGHTUD_BITS_LO) & ((1 << LJ_LIGHTUD_BITS_SEG)-1)) |
832 | #define lightudlo(u) \ | ||
833 | ((u) & (((uint64_t)1 << LJ_LIGHTUD_BITS_LO) - 1)) | ||
834 | #define lightudup(p) \ | ||
835 | ((uint32_t)(((p) >> LJ_LIGHTUD_BITS_LO) << (LJ_LIGHTUD_BITS_LO-32))) | ||
836 | static LJ_AINLINE void *lightudV(global_State *g, cTValue *o) | ||
837 | { | ||
838 | uint64_t u = o->u64; | ||
839 | uint64_t seg = lightudseg(u); | ||
840 | uint32_t *segmap = mref(g->gc.lightudseg, uint32_t); | ||
841 | lj_assertG(tvislightud(o), "lightuserdata expected"); | ||
842 | lj_assertG(seg <= g->gc.lightudnum, "bad lightuserdata segment %d", seg); | ||
843 | return (void *)(((uint64_t)segmap[seg] << 32) | lightudlo(u)); | ||
844 | } | ||
818 | #else | 845 | #else |
819 | #define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void)) | 846 | #define lightudV(g, o) check_exp(tvislightud(o), gcrefp((o)->gcr, void)) |
820 | #endif | 847 | #endif |
821 | #define gcV(o) check_exp(tvisgcv(o), gcval(o)) | 848 | #define gcV(o) check_exp(tvisgcv(o), gcval(o)) |
822 | #define strV(o) check_exp(tvisstr(o), &gcval(o)->str) | 849 | #define strV(o) check_exp(tvisstr(o), &gcval(o)->str) |
@@ -842,7 +869,7 @@ typedef union GCobj { | |||
842 | #define setpriV(o, i) (setitype((o), (i))) | 869 | #define setpriV(o, i) (setitype((o), (i))) |
843 | #endif | 870 | #endif |
844 | 871 | ||
845 | static LJ_AINLINE void setlightudV(TValue *o, void *p) | 872 | static LJ_AINLINE void setrawlightudV(TValue *o, void *p) |
846 | { | 873 | { |
847 | #if LJ_GC64 | 874 | #if LJ_GC64 |
848 | o->u64 = (uint64_t)p | (((uint64_t)LJ_TLIGHTUD) << 47); | 875 | o->u64 = (uint64_t)p | (((uint64_t)LJ_TLIGHTUD) << 47); |
@@ -853,24 +880,14 @@ static LJ_AINLINE void setlightudV(TValue *o, void *p) | |||
853 | #endif | 880 | #endif |
854 | } | 881 | } |
855 | 882 | ||
856 | #if LJ_64 | 883 | #if LJ_FR2 || LJ_32 |
857 | #define checklightudptr(L, p) \ | ||
858 | (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p)) | ||
859 | #else | ||
860 | #define checklightudptr(L, p) (p) | ||
861 | #endif | ||
862 | |||
863 | #if LJ_FR2 | ||
864 | #define contptr(f) ((void *)(f)) | 884 | #define contptr(f) ((void *)(f)) |
865 | #define setcont(o, f) ((o)->u64 = (uint64_t)(uintptr_t)contptr(f)) | 885 | #define setcont(o, f) ((o)->u64 = (uint64_t)(uintptr_t)contptr(f)) |
866 | #elif LJ_64 | 886 | #else |
867 | #define contptr(f) \ | 887 | #define contptr(f) \ |
868 | ((void *)(uintptr_t)(uint32_t)((intptr_t)(f) - (intptr_t)lj_vm_asm_begin)) | 888 | ((void *)(uintptr_t)(uint32_t)((intptr_t)(f) - (intptr_t)lj_vm_asm_begin)) |
869 | #define setcont(o, f) \ | 889 | #define setcont(o, f) \ |
870 | ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) | 890 | ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) |
871 | #else | ||
872 | #define contptr(f) ((void *)(f)) | ||
873 | #define setcont(o, f) setlightudV((o), contptr(f)) | ||
874 | #endif | 891 | #endif |
875 | 892 | ||
876 | static LJ_AINLINE void checklivetv(lua_State *L, TValue *o, const char *msg) | 893 | static LJ_AINLINE void checklivetv(lua_State *L, TValue *o, const char *msg) |
@@ -1016,6 +1033,6 @@ LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1]; | |||
1016 | 1033 | ||
1017 | /* Compare two objects without calling metamethods. */ | 1034 | /* Compare two objects without calling metamethods. */ |
1018 | LJ_FUNC int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2); | 1035 | LJ_FUNC int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2); |
1019 | LJ_FUNC const void * LJ_FASTCALL lj_obj_ptr(cTValue *o); | 1036 | LJ_FUNC const void * LJ_FASTCALL lj_obj_ptr(global_State *g, cTValue *o); |
1020 | 1037 | ||
1021 | #endif | 1038 | #endif |