Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 21156 invoked from network); 23 Mar 2007 16:42:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Mar 2007 16:42:04 -0000 Received: (qmail 4459 invoked by uid 500); 23 Mar 2007 16:42:08 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 4427 invoked by uid 500); 23 Mar 2007 16:42:08 -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 4418 invoked by uid 99); 23 Mar 2007 16:42:08 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Mar 2007 09:42:08 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of ivan.g.popov@gmail.com designates 66.249.92.171 as permitted sender) Received: from [66.249.92.171] (HELO ug-out-1314.google.com) (66.249.92.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Mar 2007 09:41:58 -0700 Received: by ug-out-1314.google.com with SMTP id z36so999965uge for ; Fri, 23 Mar 2007 09:41:37 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=D5PZFc44wIzqM1Mau6Ua6CpHOWYEsoBfk+mCt1zReH6xS8SwCYW6qcuKwTOIPo8iD9pxzs/fn36NLVsDbLiDAuL6syyvbSSRZ/UFzZGJ9KfauVyjUzcfQUIsqClBd4ciIAT2i1Zf4v+SthzlxmBaBG+ZqrG1XzX9fb6su2muQEQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=mboq53ByHDUTPCqk5BPGPEmRQIdSmKn10kQ4ehGZRUQ9Bqocra2CxRVP64PXFyAuI6G41HBxA5a/UpqRoGCPW1T7tJD+D05fRXl1/UfLUlNcrjWvPwMCcOsUx6n30tcCkc0F//4R36j/73UZ8bOe6XBCJC3TThNeVAg3Uw+Ae8k= Received: by 10.114.153.18 with SMTP id a18mr1264571wae.1174668095908; Fri, 23 Mar 2007 09:41:35 -0700 (PDT) Received: by 10.114.137.5 with HTTP; Fri, 23 Mar 2007 09:41:35 -0700 (PDT) Message-ID: Date: Fri, 23 Mar 2007 22:41:35 +0600 From: "Ivan Popov" To: dev@harmony.apache.org Subject: Re: [drlvm][jni] NewGlobalRef() returns NULL for pending exception object In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org Gregory, Since ExceptionClear() zeroes reference to exception object, it may be collected before subsequent call to NewGlobalRef() can pin it. The only safe way to prevent exception from garbage collection and be able to report it to debugger is to call NewGlobalRef() before ExceptionClear(). I cannot find any other solution. Though this does not follow well JNI spec (which is quite vague in many points), it works with RI. And I'd like NewGlobalRef() to be fixed and don't return NULL in this case. Do you agree? Thanks. Ivan On 3/23/07, Gregory Shimansky wrote: > Ivan Popov wrote: > > Working on HARMONY-3304 [1] I noticed problem with JNI function > > NewGlobalRef() in DRLVM. If it is called for a pending exception > > object before ExceptionClear() is invoked, it returns NULL, which is > > interpreted as out of memory according to JNI spec [2]. This causes > > errors in debug support. In Sun/BEA VM non-NULL reference is returned > > in this case. > > Actually JNI specification [1] states that only 3 JNI functions may be > safely called in exception state. Looking at the code of NewGloabRef I > see that the check for exception was added at revision 489694 as a > result of committing HARMONY-2817. > > > Simple workaround is to call ExceptionClear() before NewGlobalRef(). > > However, I'm not sure if ExceptionClear() won't dispose exception > > ExceptionClear zeroes a reference to exception object in TLS which is > considered as no exception state. The object itself may be collected > later if there are no live references to it left. > > > object itself. To my mind it's better to fix NewGlobalRef() and make > > it compatible with RI. > > [1] http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp17626 > > -- > Gregory > >