Misplaced memset?

Angelo Corsaro corsaro@ece.uci.edu
Mon Nov 25 13:16:00 GMT 2002


Hi all,

   I've seen that there were some changes in the  _Jv_AllocPtrFreeObj 
function, between 3.0/1 and 3.2.x I could not see any entry in the
ChangeLog. I think that the memset following in the following code
should be moved to _Jv_AllocPtrFreeObj. I think it is better to
assume as precondition that all the allocators give back zeroed
memory. Otherwise there is the danger that we have in the GCJ runtime
code that is there only to deal with specific characteristics of the 
Boehm GC. I detected this change since it was affecting the performances
of my allocators.   

jobject
_Jv_NewPrimArray (jclass eltype, jint count)
{

// [snipped code] 

# ifdef JV_HASH_SYNCHRONIZATION
  // Since the vtable is always statically allocated,
  // these are completely pointerfree!  Make sure the GC doesn't touch
them.
  __JArray *arr =
    (__JArray*) _Jv_AllocPtrFreeObj (size + elsize * count, klass); 
     memset((char *)arr + size, 0, elsize * count);
# else
  __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count,
klass);
  // Note that we assume we are given zeroed memory by the allocator.
# endif

// [snipped code] 
}


IMHO the memset should be moved to _Jv_AllocPtrFreeObj, and the 
resulting code should be:

inline void *
_Jv_AllocPtrFreeObj (jsize size, jclass klass)
{
#ifdef JV_HASH_SYNCHRONIZATION
# ifdef THREAD_LOCAL_ALLOC
    void * obj = GC_local_malloc_atomic(size);
# else
    void * obj = GC_malloc_atomic(size);
# endif
  memset((char *)obj, 0, size);
  *((_Jv_VTable **) obj) = klass->vtable;
#else
# ifdef THREAD_LOCAL_ALLOC
    void * obj = GC_local_gcj_malloc(size, klass->vtable);
# else
    void * obj = GC_gcj_malloc(size, klass->vtable);
# endif
#endif
  return obj;
}


Cheers,
   Angelo

-- 
Angelo Corsaro
Web - http://www.ece.uci.edu/~corsaro
Tel. - (949) 824-7548
University of California, Irvine
355 Engineering Tower
Irvine, CA 92697-2625 



More information about the Java mailing list