From df7fe4181966d91f20f1f35b5ee6ac8de25ec29a Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 16 Jun 2011 09:52:05 +0000 Subject: [PATCH] code to do mark bits... --- Robust/src/Runtime/bamboo/markbit.c | 30 ++++++++ Robust/src/Runtime/bamboo/markbit.h | 114 ++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 Robust/src/Runtime/bamboo/markbit.c create mode 100644 Robust/src/Runtime/bamboo/markbit.h diff --git a/Robust/src/Runtime/bamboo/markbit.c b/Robust/src/Runtime/bamboo/markbit.c new file mode 100644 index 00000000..c6ca5566 --- /dev/null +++ b/Robust/src/Runtime/bamboo/markbit.c @@ -0,0 +1,30 @@ +#include "markbit.h" + +unsigned int markmappingarray[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15}; + + +unsigned int bitmarkmappingarray[]={2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 4, 4, 4, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, + 30}; + +unsigned int revmarkmappingarray[]={0x0, 0x40000000, 0x80000000, 0x90000000, 0x94000000, 0x98000000, 0x9c000000, 0xa0000000, 0xa4000000, 0xa8000000, 0xac000000, 0xb0000000, 0xb4000000, 0xb8000000, 0xbc000000, 0xc0000000}; + + +/*int main(int argv, char **argc) { + void *ptr=1024; + unsigned int i; + gcmarktbl[0]=0xf000ffff; + gcmarktbl[1]=0xffffffff; + for(i=0;i<36;i++) { + setLength(ptr, i); + printf("%d\n",getMarkedLength(ptr)); + printf("%x %x %x\n", gcmarktbl[0], gcmarktbl[1], gcmarktbl[2]); + clearMark(ptr); + printf("%x %x %x\n", gcmarktbl[0], gcmarktbl[1], gcmarktbl[2]); + } + }*/ + diff --git a/Robust/src/Runtime/bamboo/markbit.h b/Robust/src/Runtime/bamboo/markbit.h new file mode 100644 index 00000000..740403e5 --- /dev/null +++ b/Robust/src/Runtime/bamboo/markbit.h @@ -0,0 +1,114 @@ +#ifndef MARKBIT_H +#define MARKBIT_H + +extern unsigned int markmappingarray[]; +extern unsigned int bitmarkmappingarray[]; +extern unsigned int revmarkmappingarray[]; + +#define NOTMARKED 0 +#define ALIGNOBJSIZE(x) (x)>>5 + +#define OBJMASK 0x40000000 //set towhatever smallest object mark is +#define MARKMASK 0xc0000000 //set towhatever smallest object mark is + + + +/* Return length in units of ALIGNSIZE */ + +static inline unsigned int getMarkedLength(void *ptr) { + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR hibits=alignsize>>4; + unsigned INTPTR lobits=(alignsize&15)<<1; + unsigned INTPTR val; + if (lobits==0) + val=gcmarktbl[hibits]; + else { + unsigned INTPTR revlobits=32-lobits; + unsigned INTPTR val=(gcmarktbl[hibits]<>(revlobits)); + } + unsigned int index=val>>26; + if (index>48) + return (val-0xc4000000)+16; + else + return markmappingarray[index]; +} + +/* Return non-zero value if the object is marked */ + +static inline unsigned int checkMark(void *ptr) { + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR hibits=alignsize>>4; + unsigned INTPTR lobits=(alignsize&15)<<1; + + return (gcmarktbl[hibits]<>4; + unsigned INTPTR lobits=(alignsize&15)<<1; + unsigned int ormask=(length>=16)?0xc4000000+(length-16):revmarkmappingarray[length]; + if (lobits==0) { + gcmarktbl[hibits]|=ormask; + } else { + gcmarktbl[hibits]|=ormask>>lobits; + gcmarktbl[hibits+1]|=ormask<<(32-lobits); + } +} + +/* Set length for premarked object */ + +static inline void setLengthMarked(void *ptr, unsigned int length) { + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR hibits=alignsize>>4; + unsigned INTPTR lobits=(alignsize&15)<<1; + unsigned int ormask=(length>=16)?0xc4000000+(length-16):revmarkmappingarray[length]; + if (lobits==0) { + gcmarktbl[hibits]=(gcmarktbl[hibits]^(OBJMASK))|ormask; + } else { + gcmarktbl[hibits]=(gcmarktbl[hibits]^(OBJMASK>>lobits))|(ormask>>lobits); + gcmarktbl[hibits+1]|=ormask<<(32-lobits); + } +} +/* Set length in units of ALIGNSIZE */ + +static inline void setMark(void *ptr) { + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR hibits=alignsize>>4; + unsigned INTPTR lobits=(alignsize&15)<<1; + gcmarktbl[hibits]|=OBJMASK>>lobits; +} + +static inline void clearMark(void *ptr) { + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR hibits=alignsize>>4; + unsigned INTPTR lobits=(alignsize&15)<<1; + + if (lobits==0) { + unsigned int hipart=gcmarktbl[hibits]; + unsigned int index=hipart>>26; + unsigned int bits=(index>48)?32:bitmarkmappingarray[index]; + unsigned int bitstotoss=32-bits; + gcmarktbl[hibits]^=((hipart>>(bitstotoss))<<(bitstotoss)); + + } else { + unsigned int orighi=gcmarktbl[hibits]; + unsigned int hipart=orighi<>revlobits; + unsigned INTPTR val=hipart|lowpart; + + unsigned int index=val>>26; + unsigned int bits=(index>48)?32:bitmarkmappingarray[index]; + + unsigned int bitstotoss=32-bits; + unsigned int bitstotosspluslobits=bitstotoss-lobits; + gcmarktbl[hibits]^=((orighi>>(bitstotosspluslobits))<>bitstotoss)<<(bitstotoss+revlobits); + } +} + +#endif -- 2.34.1