Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6587756
Votes 0
Synopsis RFE: Optimize addMetaName method in "zip_util.c" to reduce the cache miss
Category java:classes_util_jarzip
Reported Against
Release Fixed 7(b20)
State 10-Fix Delivered, request for enhancement
Priority: 3-Medium
Related Bugs
Submit Date 01-AUG-2007
Description
There is a benchmark called "compiler.compiler" in SPECjvm2007 (download from /net/javaperf/export/amurillo/SPECjvm2007/SPECjvm2007.kitv0.65.zip). I ran this benchmark on Solaris-sparc and run it inside Sun studio collect tool and found that addMetaName is on the top of the time consumed. 

Looking into the current implementation and the disaseembly, I found that the following code is problematic in terms of the performance.

static int
addMetaName(jzfile *zip, const char *name, int length)
{
    jint i;
    if (zip->metanames == NULL) {
	zip->metacount = 2;
	zip->metanames = calloc(zip->metacount, sizeof(zip->metanames[0]));
	if (zip->metanames == NULL) return -1;
    }
    for (i = 0; i < zip->metacount; i++) {
---->	if (zip->metanames[i] == NULL) {
	    zip->metanames[i] = (char *) malloc(length+1);
	    if (zip->metanames[i] == NULL) return -1;
	    memcpy(zip->metanames[i], name, length);
	    zip->metanames[i][length] = '\0';
	    return 0;
	}
    }

The collect shows that loading "zip->metanames[i]" takes a great deal of time. This is most likely caused by L2 cache miss.

In fact, we don't need to look into each element of the array to find out which one to fill next. We could use a date member in jzfile to record the current meta slot. The following rewrite improved the score of the benchmark by 13 - 14% on Solaris sparc & x86.

static int
addMetaName(jzfile *zip, const char *name, int length)
{
    jint i;
    if (zip->metanames == NULL) {
      zip->curMetaSlotCount = INITIAL_META_COUNT;
      zip->metanames = calloc(zip->curMetaSlotCount, sizeof(zip->metanames[0]));
      if (zip->metanames == NULL) return -1;
      zip->curMetaSlot = 0;
    }

    i = zip->curMetaSlot;

    if (i >= zip->curMetaSlotCount) {
      /* No free entries in zip->metanames? */
      if (growMetaNames(zip) != 0) return -1;  
      return addMetaName(zip, name, length);
    }
    
    zip->metanames[i] = (char *) malloc(length+1);
    if (zip->metanames[i] == NULL) return -1;
    memcpy(zip->metanames[i], name, length);
    zip->metanames[i][length] = '\0';
    zip->curMetaSlot++;
    return 0;
}
Posted Date : 2007-08-01 07:08:25.0
Work Around
N/A
Evaluation
Add a field to record the next meta array slot will likely reduce the need to look into every element of that array in order to find the empty slot. I tested the fix and it seems improved the score of the benchmark by 13- 14%.
Posted Date : 2007-08-01 07:10:31.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang