public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* ByteBuffer.asReadOnlyBuffer() and direct byte buffers
@ 2009-09-28  2:34 Erik Larsson
  2009-10-03  4:30 ` Erik Larsson
  0 siblings, 1 reply; 4+ messages in thread
From: Erik Larsson @ 2009-09-28  2:34 UTC (permalink / raw)
  To: java

[-- Attachment #1: Type: text/plain, Size: 1668 bytes --]

Hi group,

In the process of trying to run my JNI-enabled library in gcj/gij I 
discovered what seems to be a bug in libgcj's direct ByteBuffer 
implementation.

When calling ByteBuffer.asReadOnlyBuffer() for a direct byte buffer, gij 
throws at me:
------
Exception in thread "main" java.nio.InvalidMarkException
    at java.nio.Buffer.reset(libgcj.so.10)
    at java.nio.DirectByteBufferImpl.duplicate(libgcj.so.10)
    at java.nio.DirectByteBufferImpl.asReadOnlyBuffer(libgcj.so.10)
    at Test.main(Test.java:18)
------

Test code is attached. The InvalidMarkException goes away if you call 
ByteBuffer.mark() before calling .asReadOnlyBuffer(), but 
.asReadOnlyBuffer() shouldn't require a defined mark (it doesn't for 
regular buffers).

gij version:
------
gij (GNU libgcj) version 4.4.1

Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
------

OS: Ubuntu 9.10 (prerelease), i386

I did a little research, and it seems this bug was reported against 
Classpath in 2005, along with a fix:
      http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22934

The GNU Classpath code contains what seems to be a fix in the current 
revision of DirectByteBufferImpl (duplicate() method):
     
http://cvs.savannah.gnu.org/viewvc/classpath/java/nio/DirectByteBufferImpl.java?revision=1.24&root=classpath&view=markup

...but gcc's libjava doesn't have that particular line ('if (this.mark 
!= -1)'):
     
http://gcc.gnu.org/viewcvs/trunk/libjava/java/nio/DirectByteBufferImpl.java?revision=141271&view=markup

Regards,

- Erik

[-- Attachment #2: Test.java --]
[-- Type: text/plain, Size: 379 bytes --]

import java.nio.ByteBuffer;

public class Test {
    public static void main(String[] args) {
	ByteBuffer bb = ByteBuffer.allocateDirect(1024);
	System.err.println("Created readwrite direct buffer: " + bb);
	//bb.mark(); // Uncomment this line to prevent exception.
	ByteBuffer bbro = bb.asReadOnlyBuffer();
	System.err.println("Created readonly direct buffer: " + bbro);
    }
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ByteBuffer.asReadOnlyBuffer() and direct byte buffers
  2009-09-28  2:34 ByteBuffer.asReadOnlyBuffer() and direct byte buffers Erik Larsson
@ 2009-10-03  4:30 ` Erik Larsson
  2009-10-03  6:19   ` Michael Koch
  0 siblings, 1 reply; 4+ messages in thread
From: Erik Larsson @ 2009-10-03  4:30 UTC (permalink / raw)
  To: java

Hi,

Should I report this somewhere else?

- Erik

Erik Larsson wrote:
> Hi group,
>
> In the process of trying to run my JNI-enabled library in gcj/gij I 
> discovered what seems to be a bug in libgcj's direct ByteBuffer 
> implementation.
>
> When calling ByteBuffer.asReadOnlyBuffer() for a direct byte buffer, 
> gij throws at me:
> ------
> Exception in thread "main" java.nio.InvalidMarkException
>    at java.nio.Buffer.reset(libgcj.so.10)
>    at java.nio.DirectByteBufferImpl.duplicate(libgcj.so.10)
>    at java.nio.DirectByteBufferImpl.asReadOnlyBuffer(libgcj.so.10)
>    at Test.main(Test.java:18)
> ------
>
> Test code is attached. The InvalidMarkException goes away if you call 
> ByteBuffer.mark() before calling .asReadOnlyBuffer(), but 
> .asReadOnlyBuffer() shouldn't require a defined mark (it doesn't for 
> regular buffers).
>
> gij version:
> ------
> gij (GNU libgcj) version 4.4.1
>
> Copyright (C) 2007 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There 
> is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
> PURPOSE.
> ------
>
> OS: Ubuntu 9.10 (prerelease), i386
>
> I did a little research, and it seems this bug was reported against 
> Classpath in 2005, along with a fix:
>      http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22934
>
> The GNU Classpath code contains what seems to be a fix in the current 
> revision of DirectByteBufferImpl (duplicate() method):
>     
> http://cvs.savannah.gnu.org/viewvc/classpath/java/nio/DirectByteBufferImpl.java?revision=1.24&root=classpath&view=markup 
>
>
> ...but gcc's libjava doesn't have that particular line ('if (this.mark 
> != -1)'):
>     
> http://gcc.gnu.org/viewcvs/trunk/libjava/java/nio/DirectByteBufferImpl.java?revision=141271&view=markup 
>
>
> Regards,
>
> - Erik

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ByteBuffer.asReadOnlyBuffer() and direct byte buffers
  2009-10-03  4:30 ` Erik Larsson
@ 2009-10-03  6:19   ` Michael Koch
  2009-10-03  8:17     ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Koch @ 2009-10-03  6:19 UTC (permalink / raw)
  To: Erik Larsson; +Cc: java

On Sat, Oct 03, 2009 at 06:30:18AM +0200, Erik Larsson wrote:
> Hi,
> 
> Should I report this somewhere else?

http://gcc.gnu.org/bugzilla/ would probably better so it don't get lost.
Bug reports in mailing list tend to get lost.


Cheers,
Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ByteBuffer.asReadOnlyBuffer() and direct byte buffers
  2009-10-03  6:19   ` Michael Koch
@ 2009-10-03  8:17     ` Andrew Haley
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2009-10-03  8:17 UTC (permalink / raw)
  To: Erik Larsson, java

Michael Koch wrote:
> On Sat, Oct 03, 2009 at 06:30:18AM +0200, Erik Larsson wrote:
>> Hi,
>>
>> Should I report this somewhere else?
> 
> http://gcc.gnu.org/bugzilla/ would probably better so it don't get lost.
> Bug reports in mailing list tend to get lost.

Never mind that, I'm trying to figure out how this is in Classpath but not
gcj.

Erik, if you submit a patch against gcj I'll check it in.

Thanks,
Andrew.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-03  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-28  2:34 ByteBuffer.asReadOnlyBuffer() and direct byte buffers Erik Larsson
2009-10-03  4:30 ` Erik Larsson
2009-10-03  6:19   ` Michael Koch
2009-10-03  8:17     ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).