This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC Garbage Collection


Mike Stump wrote:

On Nov 12, 2006, at 10:47 PM, Brendon Costa wrote:

I think i am having trouble with the garbage collector deleting the memory for tree nodes that i am still using.


You must have a reference to that data from gc managed memory. If you don't use use gc to allocate the data structures, it just won't work. In addition, the roots of all such data structures have to be findable from the gc roots. The compiler is littered with examples of how to do this, as an example:

static GTY(()) tree block_clear_fn;

is findable by the gc system. All data findable from this tree, will be findable by the GC system.

If you _must_ have references outside gc, you can do this, if there is at least 1 reference within the gc system. For example, if you do:

static GTY(()) tree my_refereces;

void note_reference(tree decl) {
  my_references = tree_cons (NULL_TREE, decl, my_references);
}

and call note_reference (decl) for every single bit you save a reference to, it'll work. Actually, no, it won't work, precompiled headers will fail to work because you'd need to modify the PCH writer to write your data, because you didn't mark your data structures with GTY and didn't use gc to allocate them. See the preprocessor for an example of code that doesn't use GTY and yet writes the data out for PCH files.



Thanks for the help.


I used the idea you showed above and it seems to work (I dont understand enough to know why you say it wont work and thus this email). I did this by adding the note_reference() function to except.c as a quick hack so I did not have to modify the build files at all.

Eventually I plan on trying to update my code to perform all calculation at the time it finds a given node. This will reduce memory usage as the nodes will not have to remain around after this. For now as a hack I might keep this code in my patched except.c file.

I dont think I understand the relationship between the PCH files and the garbage collector. I thought that the PCH files were the gt-*.h files which are generated, though I have no idea what is placed in them except. I think it somehow does some black magic to let the garbage collector know what does and does not need to be cleaned up, but in reality I have no idea.

None of my data structures are being managed by the garbage collector, i manually malloc and free them so I figured that I did not need to worry about modifying a PCH writer to cater for them? The only thing being used with the garbage collector are existing tree nodes which from what I understand should already have all infrustructure to achieve this...

So now when i create a instance of TypeInfo

struct TypeInfoStruct
{
   tree node;
   ....
};
typedef TypeInfoStruct TypeInfo;

I also now call note_reference() with the node that I store in the type info struct which ensures that the garbage collector knows there is at least 1 reference to this tree node and so does not destroy it.

Thanks again for the help. Sorry that I dont understand how this works. I am still trying to learn more about GCC hacking.

Brendon.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]