Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 94919 invoked from network); 16 Aug 2010 10:54:09 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Aug 2010 10:54:09 -0000 Received: (qmail 53573 invoked by uid 500); 16 Aug 2010 10:54:09 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 53215 invoked by uid 500); 16 Aug 2010 10:54:06 -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 53206 invoked by uid 99); 16 Aug 2010 10:54:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Aug 2010 10:54:05 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of oliver.deakin@googlemail.com designates 209.85.215.49 as permitted sender) Received: from [209.85.215.49] (HELO mail-ew0-f49.google.com) (209.85.215.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Aug 2010 10:53:59 +0000 Received: by ewy9 with SMTP id 9so2550387ewy.36 for ; Mon, 16 Aug 2010 03:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=SFtxscPTLFTLYyygQp8fHdu89lXrpuBFSIwSrbPL+Is=; b=P9nitD08CAbkut5d9MWWLJCH+ZTVO+mtwEq3dZYrs/Qo1LRy3DhDWMO7/XURqPw467 yFvipapP8UDhX5GnZzxT00YdQQs/i3se5myhRjzL4KSgq4VJIyTYF8F/5YLb/HXa96ue VFOwOgBWJhJ7HOkkDwGhycdC5wEdWiNH+aM1s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=fxM2jc1Ur/WXrbmu8u9yHKr2iXKQygGOqaKo6demxCKVjKTx42SeWW5aYx5QOvdeTa X86i4tGxRtAZJavk7fovdO56b5Pp9tlDMi1IkDkp7eE5BZwAZFHs4QnZBY5noGmkHUsU q7cMKG6y9P4g1Ip4oH1r9O5+oaQl1sPr88ctg= Received: by 10.213.33.73 with SMTP id g9mr2582400ebd.41.1281956018395; Mon, 16 Aug 2010 03:53:38 -0700 (PDT) Received: from [9.20.183.161] (gbibp9ph1--blueice3n1.emea.ibm.com [195.212.29.83]) by mx.google.com with ESMTPS id a48sm9787235eei.7.2010.08.16.03.53.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 16 Aug 2010 03:53:37 -0700 (PDT) Message-ID: <4C6918B1.8060301@googlemail.com> Date: Mon, 16 Aug 2010 11:53:37 +0100 From: Oliver Deakin User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 To: dev@harmony.apache.org Subject: Re: [drlvm] Should the referent of a PhantomReference be cleared before it is enqueued? References: <4C62DB1D.1060803@googlemail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Agreed. I tried some simple tests commenting out the line in the DRLVM code that nulls the referent (looks to be line 400, finalizer_weakref.cpp). This fixes the difference for one GC cycle, but we then crash in the next GC cycle. I have a feeling that this is because the referent is actually freed in the first cycle, but because we are no longer nulling the reference from the PhantomReference the next GC cycle tries to free it again and crashes. I'm not sure whether just removing the code above this line that GCs the referent (so it only gets GC'ed when it is completely unreachable rather than phantomly reachable) will fix the crash - I'll take a bit more of a look at it when I get time. If anyone has some knowledge of this code or how to fix this issue it'd be a great help! Regards, Oliver On 14/08/2010 11:39, Deven You wrote: > I agree with you. > > From my point, the spec means phantom references only be cleared by Java > code, GC won't clear them automatically. And GC only adds them into the > corresponding reference queue so that Java program can know the change and > decides whether or not clear these phantom references to make their > referents can be garbage collected. > > 2010/8/12 Oliver Deakin > >> I have discovered that DRLVM appears to clear the referent field of a >> PhantomReference before calling its enqueue() method (this can be shown >> quite easily by printing the referent field in Reference.enqueue()). This >> behaviour appears to differ from the RI, on which a non-null referent can be >> got hold of via reflection [1]. The spec for PhantomReference says: >> >> "Unlike soft and weak references, phantom references are not automatically >> cleared by the garbage collector as they are enqueued. An object that is >> reachable via phantom references will remain so until all such references >> are cleared or themselves become unreachable." >> >> This reads to me that soft and weak references clear their referent field >> before being enqueued, but phantom references should only make the referent >> eligible for gc once the referent is no longer phantomly reachable (or >> reachable at all). If this is the case, it would seem that DRLVM's current >> behaviour does not match the spec. >> >> Any comments/thoughts? >> >> Regards, >> Oliver >> >> [1] An example of this kind of use/abuse of PhantomReference can be found >> at: >> http://www.roseindia.net/javatutorials/references.shtml >> >> -- >> Oliver Deakin >> Unless stated otherwise above: >> IBM United Kingdom Limited - Registered in England and Wales with number >> 741598. >> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU >> >> -- Oliver Deakin Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU