One embodiment of the present invention facilitates skewing a
bi-directional object layout to provide good cache behavior. During
operation, the system receives a request to access an object. This
request includes an object identifier and an object offset that specifies
the offset of a target field within the object, wherein the object has a
bi-directional layout that locates scalar fields at positive offsets and
reference fields at negative offsets, so that a reference field can be
immediately identified from its object offset. Next, the system
determines a skew value for a cache line containing the object, wherein
data within the cache line is shifted based upon the skew value, so that
reference fields with small negative offsets are likely to be located in
the same cache line as scalar fields with small positive offsets. Next,
the system uses the skew value in accessing the object.