draft paper on Java support in Gnome

Jeff Sturm jsturm@sigma6.com
Mon Jul 10 21:10:00 GMT 2000


Per Bothner wrote:
> I wrote a little paper suggesting how Java support can be
> added to Gnome, with an emphasis on on using Gcj.

In this paper you describe a possible technique to combine Java objects
with gtk objects. It would be interesting to see if CNI could somehow
generalize this technique so that any classes compiled with gcj may
conveniently contain native instances or structs by value, not by
reference. Such classes should perform better than simple wrapper
classes:
- two memory allocations can be folded into one
- single allocation improves locality of reference
- one pointer variable can be elimnated, shrinking object footprint
slightly
- storage for the native object will be garbage collected by the java
runtime,
 perhaps eliminating the need for a finalizer method to cleanup the
wrapped object
Padding the Java object with dummy `int' members to accomodate the
native object seems like an awkward technique. It will require some
sort of pre- or post-processing on the Java classes, and the classes
will no longer be portable. Also the 32-bit alignment of `int' may not
be satisfactory on 64-bit machines.
An alternative is to manually allocate enough memory to store the native
object immediately following the Java object. Suppose the Java class
has a private empty constructor, and (in CNI) we can call the
undocumented _Jv_AllocObject function directly in place of the `new'
operator to create a combined instance of gnu.gtk.Button and GtkButton:
 gnu::gtk::Button *button = _Jv_AllocObject(buttonClass,
 sizeof(gnu::gtk::Button) + sizeof(GtkButton));
 GtkButton *peer = (GtkButton *)(button + 1);
For marking purposes the garbage collector should ignore any memory
beyond the original object. This seems to me a bit more straightforward
than Per's suggested technique. Thoughts?
--
Jeff Sturm
jeff.sturm@appnet.com


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /