serkan-ozal / jillegal

Java Off Heap Object Pool and On the Fly Instrumentation Tool
http://serkan-ozal.github.com/jillegal/
111 stars 13 forks source link

Offheap object with offheap array within #5

Open glebreutov opened 7 years ago

glebreutov commented 7 years ago

It's not an issue, rather a question: I,m trying to make offheap object, that contains offheap array

@JillegalAware
public class HashVO extends DefaultVO {
    private HashVONode[] voarray;
    public void init(){
        OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

        arrayPool = offHeapService.createOffHeapPool(
                new ArrayOffHeapPoolCreateParameterBuilder<HashVONode>().
                        type(HashVONode.class).
                        length(10000).
                        initializeElements(false).
                        build());

        //this.voarray = arrayPool.getArray();
        setVoarray(arrayPool.getArray());

    }

    public void setVoarray(HashVONode[] voarray){
        this.voarray = voarray;
    }}

When I allocate it on heap - everything works fine, but when I trying to get it as offheap object

        EagerReferencedObjectOffHeapPool<HashVO> map_pool =
                offHeapService.createOffHeapPool(
                        new ObjectOffHeapPoolCreateParameterBuilder<HashVO>().
                                type(HashVO.class).
                                objectCount(10).
                                referenceType(ObjectPoolReferenceType.EAGER_REFERENCED).
                                build());
        HashVO hv = map_pool.get();

I'm getting JVM crash

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGBUS (0xa) at pc=0x00000001030e79a9, pid=3718, tid=5891
#
# JRE version: Java(TM) SE Runtime Environment (8.0_20-b05) (build 1.8.0_20-ea-b05)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.20-b05 mixed mode bsd-amd64 )
# Problematic frame:
# j  impl.jilligal.HashVO.setVoarray([Limpl/jilligal/HashVONode;)V+2
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again```

I think that I'm doing something wrong, but can't figure out what.

Thanks in advance
PS Is there some doc available? 
glebreutov commented 7 years ago

Seems I found solution: just access array through array pool methods

serkan-ozal commented 7 years ago

Hi @glebreutov I think, array field assignments are not intercepted (I should do) and JVM crashes while trying to update card marking table (so fields assignment must be handled by Jillegal by bypassing JVM). Can you update setVoarray method with this and try again?

public void setVoarray(HashVONode[] voarray) {
    DirectMemoryServiceFactory.getDirectMemoryService().setObjectField(this, "voarray", voarray);
}
glebreutov commented 7 years ago

Yep, It' works. Thanks!