From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20940 invoked by alias); 28 Sep 2009 02:34:03 -0000 Received: (qmail 20931 invoked by uid 22791); 28 Sep 2009 02:34:02 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from ey-out-1920.google.com (HELO ey-out-1920.google.com) (74.125.78.144) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Sep 2009 02:33:58 +0000 Received: by ey-out-1920.google.com with SMTP id 13so742025eye.46 for ; Sun, 27 Sep 2009 19:33:56 -0700 (PDT) Received: by 10.211.145.8 with SMTP id x8mr2439947ebn.67.1254105236164; Sun, 27 Sep 2009 19:33:56 -0700 (PDT) Received: from onirica.local (c-6106e055.1135-1-64736c21.cust.bredbandsbolaget.se [85.224.6.97]) by mx.google.com with ESMTPS id 5sm981804eyh.35.2009.09.27.19.33.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 27 Sep 2009 19:33:55 -0700 (PDT) Message-ID: <4AC0208F.2040109@gmail.com> Date: Mon, 28 Sep 2009 02:34:00 -0000 From: Erik Larsson User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; sv-SE; rv:1.9.1.4pre) Gecko/20090915 Thunderbird/3.0b4 MIME-Version: 1.0 To: java@gcc.gnu.org Subject: ByteBuffer.asReadOnlyBuffer() and direct byte buffers Content-Type: multipart/mixed; boundary="------------050000050302030303060702" X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-09/txt/msg00031.txt.bz2 This is a multi-part message in MIME format. --------------050000050302030303060702 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1668 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 --------------050000050302030303060702 Content-Type: text/plain; name="Test.java" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Test.java" Content-length: 517 aW1wb3J0IGphdmEubmlvLkJ5dGVCdWZmZXI7CgpwdWJsaWMgY2xhc3MgVGVz dCB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdz KSB7CglCeXRlQnVmZmVyIGJiID0gQnl0ZUJ1ZmZlci5hbGxvY2F0ZURpcmVj dCgxMDI0KTsKCVN5c3RlbS5lcnIucHJpbnRsbigiQ3JlYXRlZCByZWFkd3Jp dGUgZGlyZWN0IGJ1ZmZlcjogIiArIGJiKTsKCS8vYmIubWFyaygpOyAvLyBV bmNvbW1lbnQgdGhpcyBsaW5lIHRvIHByZXZlbnQgZXhjZXB0aW9uLgoJQnl0 ZUJ1ZmZlciBiYnJvID0gYmIuYXNSZWFkT25seUJ1ZmZlcigpOwoJU3lzdGVt LmVyci5wcmludGxuKCJDcmVhdGVkIHJlYWRvbmx5IGRpcmVjdCBidWZmZXI6 ICIgKyBiYnJvKTsKICAgIH0KfQ== --------------050000050302030303060702--