From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24912 invoked by alias); 15 Nov 2005 16:41:18 -0000 Received: (qmail 24827 invoked by uid 22791); 15 Nov 2005 16:41:11 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 15 Nov 2005 16:41:11 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id jAFGf8d5011005; Tue, 15 Nov 2005 11:41:08 -0500 Received: from opsy.redhat.com (vpn50-71.rdu.redhat.com [172.16.50.71]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id jAFGf3V17129; Tue, 15 Nov 2005 11:41:03 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 1C27B2DC10F; Tue, 15 Nov 2005 10:35:04 -0700 (MST) To: David Daney Cc: Gabriel Dos Reis , gcc@gcc.gnu.org, java@gcc.gnu.org Subject: Re: Null pointer check elimination References: <200511122101.jACL17FV008454@earth.phy.uc.edu> <20051114173736.GB15434@synopsys.com> <4378DADA.1080508@mnmoran.org> <4378FA7C.6000904@mnmoran.org> <43790043.1080204@mnmoran.org> <43790EA1.3060004@mnmoran.org> <437944B1.1010109@mnmoran.org> <43799001.5070103@avtrex.com> From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Tue, 15 Nov 2005 16:41:00 -0000 In-Reply-To: <43799001.5070103@avtrex.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2005-11/txt/msg00652.txt.bz2 >>>>> "David" == David Daney writes: David> The Java Language Specification requires that NullPointerExceptions David> are thrown when calling a method via a null 'this'. But since a David> method call does not usually involve dereferencing 'this', an explicit David> check for null must be made when it cannot be proven that 'this' is David> not null. Note that on ports where we rely on SEGV generation on a null pointer dereference, we actually only emit these explicit checks for calls to final methods (and methods in final classes). That's because plain old virtual calls do require a dereference. (This is all detailed at length in the PR for this issue..) David> Which leads me to the (unrelated) thought that inserting an David> instruction that dereferences the pointer may be more efficient (from David> a code size point of view) than an explicit check for null and then David> branching around the code that creates and throws the exception. I remember writing a patch that did this, a long time ago. But I don't recall why we didn't do it. Note that the branch in this question should always be marked 'unlikely' by GCC, as it is a branch to an exception handler. And, we ordinarily must load the value anyway since we're going to pass it as 'this' to the method call... so perhaps the cost is low. On MMU-less ports the situation is different. There, we emit a lot of null pointer checks. Tom