www.delorie.com/gnu/docs/gcc/gcj_31.html   search  
Buy the book!

Guide to GNU gcj

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.5.2 Object fields

Each object contains an object header, followed by the instance fields of the class, in order. The object header consists of a single pointer to a dispatch or virtual function table. (There may be extra fields in front of the object, for example for memory management, but this is invisible to the application, and the reference to the object points to the dispatch table pointer.)

The fields are laid out in the same order, alignment, and size as in C++. Specifically, 8-bite and 16-bit native types (byte, short, char, and boolean) are not widened to 32 bits. Note that the Java VM does extend 8-bit and 16-bit types to 32 bits when on the VM stack or temporary registers.

If you include the gcjh-generated header for a class, you can access fields of Java classes in the natural way. For example, given the following Java class:

public class Int
  public int i;
  public Integer (int i) { this.i = i; }
  public static zero = new Integer(0);

you can write:

#include <gcj/cni.h>;
#include <Int>;

mult (Int *p, jint k)
  if (k == 0)
    return Int::zero;  // Static member access.
  return new Int(p->i * k);

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003