harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: [classlib] OSResourceMonitor must go
Date Thu, 01 Oct 2009 10:00:18 GMT
On 01/Oct/2009 09:55, Tim Ellison wrote:
> I propose that the OSResourceMonitor abomination is removed.  It sits in
> front of our OSMemory.malloc() calls to check there is enough system memory.
> First, it is going to make all our regular mallocs (from Java) slow by
> making these extra JNI + system calls.  At least it should be written to
> kick-in when an OOM exception is thrown, not on every call!
> Second, it is there IIRC to attempt to solve the problem of NIO direct
> byte buffers.  I'm not convinced it will do a good job of that --
> invoking System.gc() in a loop is hopeful at best, and again taxing
> every call to malloc up from for this is unreasonable.
> The current situation is a hack to work around the lack of public API to
> free a direct byte buffer.  There is a far better hack available, and
> that is for apps to cast down and call free explicitly, i.e.
> ((DirectByteBuffer)myBuffer).free()

I should fix a typo here for the record... the cast is to a
_DirectBuffer_, like this:

import java.nio.ByteBuffer;
import org.apache.harmony.nio.internal.DirectBuffer;

public class FreeBuffer {

    public static void main(String[] args) {
        ByteBuffer myBuffer = ByteBuffer.allocateDirect(1024);
        // do stuff
        ((DirectBuffer) myBuffer).free();


View raw message