harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Li" <liyilei1...@gmail.com>
Subject [VM]How to trigue GC while free native memory is low.
Date Fri, 02 Feb 2007 07:08:32 GMT
Hi, all:
    After applying patch3073, I added the support for direct byte buffer in
nio module as spec requires. But now here exists a problem: The native
memory allocated to the byte buffer can be released when gc releases the
byte buffer object, however, if the native heap is full while java heap
still has space, gc will not be triggered.
    It seems that RI will start gc before native memory heap is depleted and
thus prevents out-of-memory error.

   Then our work focuses on:
   1. When gc is required.
   2. Trigger a gc.
   The first one requires that we get support from operating system, since
the memory allocated in the native code, for example by malloc, is out of
the control of java VM.( I have ever thought of counting the used memory in
hymemory_allocate, but the plan fails since hymemory_free will not report
how much space is released.)
   The second one needs the help from VM. System.gc() is not so reliable as
spec says, so it is necessary to have a internal channel to notify VM to
start gc.

    One solution, I think, is to let a monitor thread in VM to check whether
OS physical memory is low. For example, the QueryMemoryResourceNotification
of win32 API is a candidate. Although the interrupt model is more effective:
win32 SDK provides a CreateMemoryResourceNotification to get a handler on
which the monitor thread can wait, maybe on other platforms, OS does not
supply such a convenience. So the monitor thread in the VM might have to
check the OS resource once for a while and if necessary the monitor thread
will call a GC.

   My suggestion is first to add some function to monitor memory in portlib,
since it is highly related to platforms and in portlib there has been
some useful tools.(Thanks Mark to point out that.) On the other hand, we can
negotiate a channel to trigger gc in VM. Actually I am not an expert on VM
since I am not sure whether there has been some monitor thread and the load
on performance if such a monitor thread is added to the VM...


-- 
Leo Li
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message