Program: 149728
Project: 149728
Buggy source:
/** 
 * Allocate <code>pages</code> pages from this resource.<p> If the request can be satisfied, then ensure the pages are mmpapped and zeroed before returning the address of the start of the region.  If the request cannot be satisfied, return zero.
 * @param pages The number of pages to be allocated.
 * @return The start of the first page if successful, zero onfailure.
 */
@Inline protected Address allocPages(int pages){
  if (VM.VERIFY_ASSERTIONS)   VM.assertions._assert(metaDataPagesPerRegion == 0 || pages <= PAGES_IN_CHUNK - metaDataPagesPerRegion);
  lock();
  boolean newChunk=false;
  int pageOffset=freeList.alloc(pages);
  if (pageOffset == GenericFreeList.FAILURE && !contiguous) {
    pageOffset=allocateContiguousChunks(pages);
    newChunk=true;
  }
  if (pageOffset == -1) {
    unlock();
    return Address.zero();
  }
 else {
    pagesCurrentlyOnFreeList-=pages;
    if (pageOffset > highWaterMark) {
      if ((pageOffset ^ highWaterMark) > EmbeddedMetaData.PAGES_IN_REGION) {
        int regions=1 + ((pageOffset - highWaterMark) >> EmbeddedMetaData.LOG_PAGES_IN_REGION);
        int metapages=regions * metaDataPagesPerRegion;
        reserved+=metapages;
        committed+=metapages;
        newChunk=true;
      }
      highWaterMark=pageOffset;
    }
    Address rtn=start.plus(Conversions.pagesToBytes(pageOffset));
    Extent bytes=Conversions.pagesToBytes(pages);
    commitPages(pages,pages);
    space.growSpace(rtn,bytes,newChunk);
    unlock();
    Mmapper.ensureMapped(rtn,pages);
    VM.memory.zero(rtn,bytes);
    VM.events.tracePageAcquired(space,rtn,pages);
    return rtn;
  }
}

Fixed version (ground truth):
/** 
 * Allocate <code>pages</code> pages from this resource.<p> If the request can be satisfied, then ensure the pages are mmpapped and zeroed before returning the address of the start of the region.  If the request cannot be satisfied, return zero.
 * @param pages The number of pages to be allocated.
 * @return The start of the first page if successful, zero onfailure.
 */
@Inline protected Address allocPages(int pages){
  if (VM.VERIFY_ASSERTIONS)   VM.assertions._assert(metaDataPagesPerRegion == 0 || pages <= PAGES_IN_CHUNK - metaDataPagesPerRegion);
  lock();
  boolean newChunk=false;
  int pageOffset=freeList.alloc(pages);
  if (pageOffset == GenericFreeList.FAILURE && !contiguous) {
    pageOffset=allocateContiguousChunks(pages);
    newChunk=true;
  }
  if (pageOffset == -1) {
    unlock();
    return Address.zero();
  }
 else {
    pagesCurrentlyOnFreeList-=pages;
    if (pageOffset > highWaterMark) {
      if (highWaterMark == 0 || (pageOffset ^ highWaterMark) > EmbeddedMetaData.PAGES_IN_REGION) {
        int regions=1 + ((pageOffset - highWaterMark) >> EmbeddedMetaData.LOG_PAGES_IN_REGION);
        int metapages=regions * metaDataPagesPerRegion;
        reserved+=metapages;
        committed+=metapages;
        newChunk=true;
      }
      highWaterMark=pageOffset;
    }
    Address rtn=start.plus(Conversions.pagesToBytes(pageOffset));
    Extent bytes=Conversions.pagesToBytes(pages);
    commitPages(pages,pages);
    space.growSpace(rtn,bytes,newChunk);
    unlock();
    Mmapper.ensureMapped(rtn,pages);
    VM.memory.zero(rtn,bytes);
    VM.events.tracePageAcquired(space,rtn,pages);
    return rtn;
  }
}