Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making PMCs

20 views
Skip to first unread message

Nicholas Clark

unread,
Jun 13, 2004, 6:01:25 AM6/13/04
to perl6-i...@perl.org
I'm trying to work out how to make PMCs. I'm not finding much documentation,
and I'm not sure what I'm missing. Particularly I'm trying to work out where
I'm allowed to store data, and what flags I might have to set

A basic PMC appears to contain

flags
of which 8 are private so I could use
a data pointer
which I can use. I am always responsible for freeing anything there(?)
and to do this I need to set the active destroy flag(?)
This flag is not the same as the high priority DOD system(?)
Does the garbage collector ever consider this pointer?
Does it ever chase what it points to?
a pobj_t union
which I can use.
Given that the nature of a C union means that the floating point value
occupies the same space as the pointer, do I need to set flags
depending on whether the pointers point to anything?


The pobj_t union contains one of:

A buffers structure
I'm not sure how to use this, but I'm not sure if I need to.

A pair of pointers
What's the difference between the _struct_val pointer and the
_pmc_val pointer? Is the PMC pointer only allowed to point to other
PMCs, while the other pointer is allowed to point to anything
non-PMC. If not, why are there two pointers? Does on PMC need two?
Does the garbage collector consider both pointers? Does it inspect
whatever they point to?
Do I need to set any flags, or do I just assign pointers to these?
When I'm done, do I need to be careful to assign NULL pointers to
ensure that the GC doesn't think I'm still interested in whatever
object I used to point to?

A pointer to a parrot string

An integer

A floating point value

I think that's all my questioning for now :-)

Nicholas Clark

Matt Fowles

unread,
Jun 13, 2004, 1:53:09 PM6/13/04
to Nicholas Clark, perl6-i...@perl.org
Nicholas~

I will try to answer what I can, based on my current experience making
those array PMCs.


Nicholas Clark wrote:

>a data pointer
> which I can use. I am always responsible for freeing anything there(?)
> and to do this I need to set the active destroy flag(?)
> This flag is not the same as the high priority DOD system(?)
> Does the garbage collector ever consider this pointer?
> Does it ever chase what it points to?
>
>

You are responsible for freeing it by setting the active destroy flag.
If it contains pointers that need to be chased, you are responsible for
supplying a mark function and setting the custom mark flag.
Examples of both of these can be found in fixedstringarray.pmc and
fixedpmcarray.pmc, whereas fixedfloatarray.pmc has an active destroy and
no mark.
You access this through the PMC_data(...) macro, typically passing SELF.

>a pobj_t union
> which I can use.
> Given that the nature of a C union means that the floating point value
> occupies the same space as the pointer, do I need to set flags
> depending on whether the pointers point to anything?
>
>
>The pobj_t union contains one of:
>
>A buffers structure
> I'm not sure how to use this, but I'm not sure if I need to.
>
>A pair of pointers
> What's the difference between the _struct_val pointer and the
> _pmc_val pointer? Is the PMC pointer only allowed to point to other
> PMCs, while the other pointer is allowed to point to anything
> non-PMC. If not, why are there two pointers? Does on PMC need two?
> Does the garbage collector consider both pointers? Does it inspect
> whatever they point to?
> Do I need to set any flags, or do I just assign pointers to these?
> When I'm done, do I need to be careful to assign NULL pointers to
> ensure that the GC doesn't think I'm still interested in whatever
> object I used to point to?
>
>

Not sure, I never used any of this.

>A pointer to a parrot string
>
>An integer
>
>A floating point value
>
>

I know that you can access the integer via PMC_int_val(...) macro.

All of the array classes that I made just use the integer and the data
pointer, but that is because they are really quite simple.

>I think that's all my questioning for now :-)
>
>

Sorry I can't be more helpful.

>Nicholas Clark
>
>
Matt

Dan Sugalski

unread,
Jun 14, 2004, 8:53:10 AM6/14/04
to Matt Fowles, Nicholas Clark, perl6-i...@perl.org
At 12:53 PM -0500 6/13/04, Matt Fowles wrote:
>Nicholas~
>
>I will try to answer what I can, based on my current experience
>making those array PMCs.
>
>
>Nicholas Clark wrote:
>
>>a data pointer
>> which I can use. I am always responsible for freeing anything there(?)
>> and to do this I need to set the active destroy flag(?)
>> This flag is not the same as the high priority DOD system(?)
>> Does the garbage collector ever consider this pointer?
>> Does it ever chase what it points to?
>>
>You are responsible for freeing it by setting the active destroy flag.

Well... no. You're not. If the memory hanging off the data pointer
was allocated from one of parrot's managed pools (either free memory
or pmc/buffer header) then you don't have to free it.

You only need to have a destroy function if you've malloc'd memory or
need to actively tear down something, usually a filehandle or
connection to a third-party extension or something.
--
Dan

--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

Dan Sugalski

unread,
Jun 14, 2004, 9:29:38 AM6/14/04
to Nicholas Clark, perl6-i...@perl.org
At 11:01 AM +0100 6/13/04, Nicholas Clark wrote:
>I'm trying to work out how to make PMCs. I'm not finding much documentation,
>and I'm not sure what I'm missing. Particularly I'm trying to work out where
>I'm allowed to store data, and what flags I might have to set

I'll write up something more detailed later on today, but for now:

>A basic PMC appears to contain
>
>flags
> of which 8 are private so I could use

Yes.

>a data pointer
> which I can use. I am always responsible for freeing anything there(?)

No. Only if you need to take some sort of extraordinary measures.

> and to do this I need to set the active destroy flag(?)

Again, only with extraordinary measures.

> This flag is not the same as the high priority DOD system(?)

Nope.

> Does the garbage collector ever consider this pointer?

Yes, if the right flags are set.

is_PMC_ptr is set if this pointer points to a PMC.
is_buffer_ptr is set if this pointer points to a buffer-like
structure. (Such as a string)

Set them both if the pointer points to a buffer of PMCs.

> Does it ever chase what it points to?

If the right flags are set (namely the two above) yes.

>a pobj_t union
> which I can use.
> Given that the nature of a C union means that the floating point value
> occupies the same space as the pointer, do I need to set flags
> depending on whether the pointers point to anything?

If they point to something parrot needs to track (a buffer, string or
PMC) and you want parrot to do it automatically, yes. I'm going to
have to go dig for that, though, as things have changed a bit since I
last looked.

Nicholas Clark

unread,
Jun 14, 2004, 9:33:58 AM6/14/04
to perl6-i...@perl.org
On Mon, Jun 14, 2004 at 08:53:10AM -0400, Dan Sugalski wrote:
> At 12:53 PM -0500 6/13/04, Matt Fowles wrote:
> >Nicholas~
> >
> >I will try to answer what I can, based on my current experience
> >making those array PMCs.
> >
> >
> >Nicholas Clark wrote:
> >
> >>a data pointer
> >> which I can use. I am always responsible for freeing anything
> >> there(?)
> >> and to do this I need to set the active destroy flag(?)
> >> This flag is not the same as the high priority DOD system(?)
> >> Does the garbage collector ever consider this pointer?
> >> Does it ever chase what it points to?
> >>
> >You are responsible for freeing it by setting the active destroy flag.
>
> Well... no. You're not. If the memory hanging off the data pointer
> was allocated from one of parrot's managed pools (either free memory
> or pmc/buffer header) then you don't have to free it.

There's a memory internals document, but I can't spot any document given
an API overview on how to allocate memory this way.

The implication of what you're saying is that the data pointer is checked by
the DOD, and any PMC it points directly to isn't dead.

Nicholas Clark

Dan Sugalski

unread,
Jun 14, 2004, 9:41:41 AM6/14/04
to Nicholas Clark, perl6-i...@perl.org
At 2:33 PM +0100 6/14/04, Nicholas Clark wrote:
>On Mon, Jun 14, 2004 at 08:53:10AM -0400, Dan Sugalski wrote:
>> At 12:53 PM -0500 6/13/04, Matt Fowles wrote:
>> >Nicholas~
>> >
>> >I will try to answer what I can, based on my current experience
>> >making those array PMCs.
>> >
>> >
>> >Nicholas Clark wrote:
>> >
>> >>a data pointer
>> >> which I can use. I am always responsible for freeing anything
>> >> there(?)
>> >> and to do this I need to set the active destroy flag(?)
>> >> This flag is not the same as the high priority DOD system(?)
>> >> Does the garbage collector ever consider this pointer?
>> >> Does it ever chase what it points to?
>> >>
>> >You are responsible for freeing it by setting the active destroy flag.
>>
>> Well... no. You're not. If the memory hanging off the data pointer
>> was allocated from one of parrot's managed pools (either free memory
>> or pmc/buffer header) then you don't have to free it.
>
>There's a memory internals document, but I can't spot any document given
>an API overview on how to allocate memory this way.

Yeah, it's all kinda ad-hoc. Needs fixing.

>The implication of what you're saying is that the data pointer is checked by
>the DOD, and any PMC it points directly to isn't dead.

Well... sort of. Checking and cleaning up are two very separate
things here. Parrot may not automatically check (leaving that to your
PMC's custom mark routine) but will automatically clean up. (If
you've not marked in your custom mark routine)

Basically, if the right flags are set, the DOD trace will treat the
pointer as pointing to something it should consider, and
automatically trace into it. If the right flags aren't set it won't,
and your needs to mark it explicitly.

Regardless of anything else, the DOD sweep will reclaim the
PMC/String/Buffer/PObj structures if they aren't marked in the mark
phase, either automatically or by a PMC mark routine, and memory not
pointed to by a live buffer-ish thing will get reclaimed, so if your
PMC with custom stuff hanging off the data pointer dies parrot will
still reclaim its memory and whatnot for you.

Leopold Toetsch

unread,
Jun 14, 2004, 9:49:37 AM6/14/04
to Nicholas Clark, perl6-i...@perl.org
Nicholas Clark <ni...@ccl4.org> wrote:
> I'm trying to work out how to make PMCs. I'm not finding much documentation,

I'll create a POD, which hopefully will answer all these questons.

leo

Leopold Toetsch

unread,
Jun 15, 2004, 3:37:14 AM6/15/04
to Nicholas Clark, perl6-i...@perl.org
Nicholas Clark <ni...@ccl4.org> wrote:
> I'm trying to work out how to make PMCs. I'm not finding much documentation,

A first draft of F<docs/pmc.pod> is in.

leo

0 new messages