From dev-return-23824-apmail-harmony-dev-archive=harmony.apache.org@harmony.apache.org Fri Feb 02 07:09:25 2007 Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 5501 invoked from network); 2 Feb 2007 07:09:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Feb 2007 07:09:23 -0000 Received: (qmail 17935 invoked by uid 500); 2 Feb 2007 07:09:29 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 17319 invoked by uid 500); 2 Feb 2007 07:09:25 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 17304 invoked by uid 99); 2 Feb 2007 07:09:25 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Feb 2007 23:09:25 -0800 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_10_20,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of liyilei1979@gmail.com designates 66.249.82.226 as permitted sender) Received: from [66.249.82.226] (HELO wx-out-0506.google.com) (66.249.82.226) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Feb 2007 23:08:53 -0800 Received: by wx-out-0506.google.com with SMTP id i26so790570wxd for ; Thu, 01 Feb 2007 23:08:32 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=K+LakKzTG1kebSj0wqz8/cTcqUobVW3OvI2lJCU7/6HXjLMgZ6MIYxSjkTVmp+STuSlHd2c3m+NA1DoyILoCBkFF+gu4kxalPQkc1WeciKpiMxro1HihSGIRn1zB9joEWtC4KAixjfPEsxG519NebVwM/EmZLzQGVl3ENNHB224= Received: by 10.90.31.19 with SMTP id e19mr4398197age.1170400112369; Thu, 01 Feb 2007 23:08:32 -0800 (PST) Received: by 10.90.28.2 with HTTP; Thu, 1 Feb 2007 23:08:32 -0800 (PST) Message-ID: Date: Fri, 2 Feb 2007 15:08:32 +0800 From: "Leo Li" To: dev@harmony.apache.org Subject: [VM]How to trigue GC while free native memory is low. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_21299_32965430.1170400112218" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_21299_32965430.1170400112218 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ------=_Part_21299_32965430.1170400112218--