Discussion:
[Gc] BDWGC and tagged pointers
(too old to reply)
John Mastro
2016-03-15 18:39:48 UTC
Permalink
Raw Message
Hello,

I suspect this question is quite basic, but I haven't been able to
figure it out on my own.

I'm implementing a small programming language and would like to use
BDWGC for garbage collection. I'm using tagged pointers, where the 3
least-significant bits can carry a type tag. The tagged value may be
either an immediate (e.g. an integer) or a pointer. In other words, I
have something like this:

typedef intptr_t object;

#define TAG_BITS 3
#define VAL_MASK -(1 << TAG_BITS)

enum obj_tag { TAG_INT = 1, TAG_LIST };

typedef struct {
object head, tail;
} obj_list;

#define make_integer(i) (((i) << TAG_BITS) + TAG_INT)
#define extract_integer(o) ((o) >> TAG_BITS)

object make_list(object head, object tail)
{
obj_list *list = /* allocate it */;
list->head = head;
list->tail = tail;
return ((intptr_t)list) + TAG_LIST;
}

#define extract_list(o) ((void *)((o) & VAL_MASK))

... which I think is pretty standard/boring. However, I believe I need
to teach BDWGC about this tagging, so it knows these `object` values may
(or may not) represent pointers, and I'm not sure how to do that.

Are there any documents, examples, or other help on how to accomplish
this?

Thanks,

John Mastro
Brian Beuning
2016-03-15 19:03:27 UTC
Permalink
Raw Message
Maybe configuring INTERIOR_POINTERS would help.


Brian Beuning
CoreCard
Work: 770 564 5616
E-mail: ***@corecard.com
Web: www.corecard.com

----- Original Message -----
From: "John Mastro" <***@gmail.com>
To: ***@lists.opendylan.org
Sent: Tuesday, March 15, 2016 2:39:48 PM
Subject: [Gc] BDWGC and tagged pointers

Hello,

I suspect this question is quite basic, but I haven't been able to
figure it out on my own.

I'm implementing a small programming language and would like to use
BDWGC for garbage collection. I'm using tagged pointers, where the 3
least-significant bits can carry a type tag. The tagged value may be
either an immediate (e.g. an integer) or a pointer. In other words, I
have something like this:

typedef intptr_t object;

#define TAG_BITS 3
#define VAL_MASK -(1 << TAG_BITS)

enum obj_tag { TAG_INT = 1, TAG_LIST };

typedef struct {
object head, tail;
} obj_list;

#define make_integer(i) (((i) << TAG_BITS) + TAG_INT)
#define extract_integer(o) ((o) >> TAG_BITS)

object make_list(object head, object tail)
{
obj_list *list = /* allocate it */;
list->head = head;
list->tail = tail;
return ((intptr_t)list) + TAG_LIST;
}

#define extract_list(o) ((void *)((o) & VAL_MASK))

... which I think is pretty standard/boring. However, I believe I need
to teach BDWGC about this tagging, so it knows these `object` values may
(or may not) represent pointers, and I'm not sure how to do that.

Are there any documents, examples, or other help on how to accomplish
this?

Thanks,

John Mastro
Basile Starynkevitch
2016-03-15 19:06:30 UTC
Permalink
Raw Message
Post by John Mastro
... which I think is pretty standard/boring. However, I believe I need
to teach BDWGC about this tagging, so it knows these `object` values may
(or may not) represent pointers, and I'm not sure how to do that.
Are there any documents, examples, or other help on how to accomplish
this?
As an example, look into the source code of Bigloo or HOP runtime
http://www-sop.inria.fr/mimosa/fp/Bigloo/
http://hop.inria.fr/home/index.html

Regards
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***
Loading...