class gc

Jon Olson olson@mmsi.com
Fri Feb 26 16:36:00 GMT 1999


On Fri, 26 Feb 1999, Godmar Back wrote:
>Hi,
>
>I have a quick question about class gc in gcj's run-time.
>It appears that gcj puts java_lang_Class objects in the data segment.
>Class gc requires that objects keep their classes alive, but classes
>can also be kept alive through direct references from static or non-static
>variables.  In either case, the walk function of the containing object
>must mark the class objects to which it refers.
>
>This could be somewhat problematic for those walk functions that
>follow references to class objects that are stored in ordinary objects 
>or in arrays of type [Ljava/lang/Class.   Either you'll need to check
>on the collector side that you don't mark anything you haven't allocated
>(which seems expensive and act against the idea of precise walking/marking),
>or you'll have to check on the walk function side that you don't try to
>mark anything that wasn't allocated.  The latter seems error-prone and
>would require a lot of special-casing.
>
>What do you think?  Is this currently a problem in gcj at all (given that 
>maybe all class objects are in the data segment and hence there may be no need
>to mark them at all?)  It is definitely a problem in hybrid applications
>that allow both precompiled and loaded classes.
>
>	- Godmar

Typical collectors check an address for being within the heap before they
mark it.  All conservative collectors work this way since that's the criteria
they use to determine whether or not a given 32-bit word is a reference or
not.  Statically allocated classes will not be within the heap range and will
be ignored by existing conservative collectors.  So far, every JVM
implementation I've seen uses such a collector.

Now if you have a more precise collector which knows which words in
memory are really [Ljava/lang/Class objects and explicitly walks those
objects, you can handle it by either:

	1) Adding a flag to the java/lang/Class object to indicate
	    which classes are statically allocated.
	2) Checking the java/lang/Class pointer to make sure it's
	    inside of the allocated heap range.

Either way, I don't see it as much of a problem...

 --
Jon Olson, Modular Mining Systems
	   3289 E. Hemisphere Loop
	   Tucson, AZ 85706
INTERNET:  olson@mmsi.com
PHONE:     (520)746-9127
FAX:       (520)889-5790


More information about the Java mailing list