From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27215 invoked by alias); 18 Jun 2009 16:30:21 -0000 Received: (qmail 27198 invoked by uid 22791); 18 Jun 2009 16:30:17 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_44 X-Spam-Check-By: sourceware.org Received: from g1t0029.austin.hp.com (HELO g1t0029.austin.hp.com) (15.216.28.36) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Jun 2009 16:30:05 +0000 Received: from g5t0012.atlanta.hp.com (g5t0012.atlanta.hp.com [15.192.0.49]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by g1t0029.austin.hp.com (Postfix) with ESMTPS id D314D38384; Thu, 18 Jun 2009 16:30:03 +0000 (UTC) Received: from FS (m208-135.dsl.rawbw.com [198.144.208.135]) by g5t0012.atlanta.hp.com (Postfix) with ESMTPSA id 8650F1000D; Thu, 18 Jun 2009 16:30:02 +0000 (UTC) Date: Thu, 18 Jun 2009 16:30:00 -0000 From: Hans Boehm To: abhishek desai cc: "java@gcc.gnu.org" Subject: Re: problem when mapping malloc to GC_malloc. In-Reply-To: <898285d30906180800q3b5bd3b2h1d4a11d6a8245e34@mail.gmail.com> Message-ID: References: <898285d30906180800q3b5bd3b2h1d4a11d6a8245e34@mail.gmail.com> User-Agent: Alpine 1.10 (LNX 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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-06/txt/msg00041.txt.bz2 On Thu, 18 Jun 2009, abhishek desai wrote: > Hi, > > My JNI code includes redefinitions to the malloc, free and realloc > functions (shown below). These functions call GC_malloc, GC_free and > GC_realloc respectively. This is done so that any calls to the malloc > get allocated through the garbage collector. However this is failing > with segfault. Any clues why this does not work ? > I am using this code along with the libgcj library linked dynamically > with my application. > > void *malloc(size_t size) > { > return GC_malloc(size); > } > > void *realloc(void *ptr, size_t size) > { > return GC_realloc(ptr, size); > } > > void free(void *ptr) > { > GC_free(ptr); > } > > > regards > abhishek > The collector itself supports a REDIRECT_MALLOC option that might get you closer. In general, this is very hard. There are other functions (calloc, memalign, etc.) that you would also have to replace, so that their clients don't end up using the original malloc with GC_free. This is the easy part. The hard part is that if you replace malloc, low level parts of the system will also end up using GC_malloc, and sometimes squirrel away pointers to the results in places the GC doesn't really know about. Recent versions of the GC (7.1+) contains some hacks to try to handle this on Linux. But the multithreaded versions still are sometimes not 100% robust. Gcj's version is unlikely to work in this mode, except possibly in single-threaded mode. A real fix here would probably require some new hooks in glibc and the startup and libpthread code. Hans