예제 #1
0
Bool MPMCheck(void)
{
    CHECKL(sizeof(Word) * CHAR_BIT == MPS_WORD_WIDTH);
    CHECKL((Word)1 << MPS_WORD_SHIFT == MPS_WORD_WIDTH);
    CHECKL(AlignCheck(MPS_PF_ALIGN));
    /* Check that trace ids will fit in the TraceId type. */
    CHECKL(TraceLIMIT <= UINT_MAX);
    /* Check that there are enough bits in */
    /* a TraceSet to store all possible trace ids. */
    CHECKL(sizeof(TraceSet) * CHAR_BIT >= TraceLIMIT);

    CHECKL((SizeAlignUp(0, 2048) == 0));
    CHECKL(!SizeIsAligned(64, (unsigned) -1));
    CHECKL(SizeIsAligned(0, 32));
    CHECKL((SizeAlignUp(1024, 16) == 1024));
    /* .prime: 31051 is prime */
    CHECKL(SizeIsAligned(SizeAlignUp(31051, 256), 256));
    CHECKL(SizeIsAligned(SizeAlignUp(31051, 512), 512));
    CHECKL(!SizeIsAligned(31051, 1024));
    CHECKL(!SizeIsP2(0));
    CHECKL(SizeIsP2(128));
    CHECKL(SizeLog2((Size)1) == 0);
    CHECKL(SizeLog2((Size)256) == 8);
    CHECKL(SizeLog2((Size)65536) == 16);
    CHECKL(SizeLog2((Size)131072) == 17);

    /* .check.writef: We check that various types will fit in a Word; */
    /* See .writef.check.  Don't need to check WriteFS or WriteFF as they */
    /* should not be cast to Word. */
    CHECKL(sizeof(WriteFA) <= sizeof(Word));
    CHECKL(sizeof(WriteFP) <= sizeof(Word));
    CHECKL(sizeof(WriteFW) <= sizeof(Word)); /* Should be trivial*/
    CHECKL(sizeof(WriteFU) <= sizeof(Word));
    CHECKL(sizeof(WriteFB) <= sizeof(Word));
    CHECKL(sizeof(WriteFC) <= sizeof(Word));
    /* .check.write.double: See .write.double.check */
    {
        int e, DBL_EXP_DIG = 1;
        for (e = DBL_MAX_10_EXP; e > 0; e /= 10)
            DBL_EXP_DIG++;
        CHECKL(DBL_EXP_DIG < DBL_DIG);
        CHECKL(-(DBL_MIN_10_EXP) <= DBL_MAX_10_EXP);
    }

    return TRUE;
}
예제 #2
0
Bool FormatCheck(Format format)
{
  CHECKS(Format, format);
  CHECKU(Arena, format->arena);
  CHECKL(format->serial < format->arena->formatSerial);
  CHECKD_NOSIG(Ring, &format->arenaRing);
  CHECKL(AlignCheck(format->alignment));
  /* TODO: Define the concept of the maximum alignment it is possible to
     request from the MPS, document and provide an interface to it, and then
     check that this alignment is not greater than that, as well as all other
     alignments. */
  CHECKL(FUNCHECK(format->scan));
  CHECKL(FUNCHECK(format->skip));
  CHECKL(FUNCHECK(format->move));
  CHECKL(FUNCHECK(format->isMoved));
  CHECKL(FUNCHECK(format->pad));
  CHECKL(FUNCHECK(format->class));

  return TRUE;
}
예제 #3
0
파일: pool.c 프로젝트: bhanug/mps
Bool PoolCheck(Pool pool)
{
  PoolClass klass;
  /* Checks ordered as per struct decl in <code/mpmst.h#pool> */
  CHECKS(Pool, pool);
  CHECKC(AbstractPool, pool);
  /* Break modularity for checking efficiency */
  CHECKL(pool->serial < ArenaGlobals(pool->arena)->poolSerial);
  klass = ClassOfPoly(Pool, pool);
  CHECKD(PoolClass, klass);
  CHECKU(Arena, pool->arena);
  CHECKD_NOSIG(Ring, &pool->arenaRing);
  CHECKD_NOSIG(Ring, &pool->bufferRing);
  /* Cannot check pool->bufferSerial */
  CHECKD_NOSIG(Ring, &pool->segRing);
  CHECKL(AlignCheck(pool->alignment));
  /* Normally pool->format iff PoolHasAttr(pool, AttrFMT), but during
     pool initialization the class may not yet be set. */
  CHECKL(!PoolHasAttr(pool, AttrFMT) || pool->format != NULL);
  return TRUE;
}
예제 #4
0
Addr (AddrAlignDown)(Addr addr, Align alignment)
{
    AVER(AlignCheck(alignment));
    return AddrAlignDown(addr, alignment);
}
예제 #5
0
Word (WordAlignDown)(Word word, Align alignment)
{
    AVER(AlignCheck(alignment));
    return WordAlignDown(word, alignment);
}
예제 #6
0
Word (WordAlignUp)(Word word, Align align)
{
    AVER(AlignCheck(align));
    return WordAlignUp(word, align);
}
예제 #7
0
Bool (WordIsAligned)(Word word, Align align)
{
    AVER(AlignCheck(align));
    return WordIsAligned(word, align);
}
예제 #8
0
Bool ArgCheckAlign(Arg arg) {
  CHECKL(AlignCheck(arg->val.align));
  return TRUE;
}
예제 #9
0
파일: buffer.c 프로젝트: Ravenbrook/mps
Bool BufferCheck(Buffer buffer)
{
  CHECKS(Buffer, buffer);
  CHECKC(Buffer, buffer);
  CHECKL(buffer->serial < buffer->pool->bufferSerial); /* .trans.mod */
  CHECKU(Arena, buffer->arena);
  CHECKU(Pool, buffer->pool);
  CHECKL(buffer->arena == buffer->pool->arena);
  CHECKD_NOSIG(Ring, &buffer->poolRing);
  CHECKL(BoolCheck(buffer->isMutator));
  CHECKL(buffer->fillSize >= 0.0);
  CHECKL(buffer->emptySize >= 0.0);
  CHECKL(buffer->emptySize <= buffer->fillSize);
  CHECKL(buffer->alignment == buffer->pool->alignment);
  CHECKL(AlignCheck(buffer->alignment));

  /* If any of the buffer's fields indicate that it is reset, make */
  /* sure it is really reset.  Otherwise, check various properties */
  /* of the non-reset fields. */
  if (buffer->mode & BufferModeTRANSITION) {
    /* nothing to check */
  } else if ((buffer->mode & BufferModeATTACHED) == 0
             || buffer->base == (Addr)0
             || buffer->ap_s.init == (Addr)0
             || buffer->ap_s.alloc == (Addr)0
             || buffer->poolLimit == (Addr)0) {
    CHECKL((buffer->mode & BufferModeATTACHED) == 0);
    CHECKL(buffer->base == (Addr)0);
    CHECKL(buffer->initAtFlip == (Addr)0);
    CHECKL(buffer->ap_s.init == (Addr)0);
    CHECKL(buffer->ap_s.alloc == (Addr)0);
    CHECKL(buffer->ap_s.limit == (Addr)0);
    /* Nothing reliable to check for lightweight frame state */
    CHECKL(buffer->poolLimit == (Addr)0);
  } else {
    /* The buffer is attached to a region of memory.   */
    /* Check consistency. */
    CHECKL(buffer->mode & BufferModeATTACHED);

    /* These fields should obey the ordering */
    /* base <= init <= alloc <= poolLimit */
    CHECKL((mps_addr_t)buffer->base <= buffer->ap_s.init);
    CHECKL(buffer->ap_s.init <= buffer->ap_s.alloc);
    CHECKL(buffer->ap_s.alloc <= (mps_addr_t)buffer->poolLimit);

    /* Check that the fields are aligned to the buffer alignment. */
    CHECKL(AddrIsAligned(buffer->base, buffer->alignment));
    CHECKL(AddrIsAligned(buffer->initAtFlip, buffer->alignment));
    CHECKL(AddrIsAligned(buffer->ap_s.init, buffer->alignment));
    CHECKL(AddrIsAligned(buffer->ap_s.alloc, buffer->alignment));
    CHECKL(AddrIsAligned(buffer->ap_s.limit, buffer->alignment));
    CHECKL(AddrIsAligned(buffer->poolLimit, buffer->alignment));

    /* If the buffer isn't trapped then "limit" should be the limit */
    /* set by the owning pool.  Otherwise, "init" is either at the */
    /* same place it was at flip (.commit.before) or has been set */
    /* to "alloc" (.commit.after).  Also, when the buffer is */
    /* flipped, initAtFlip should hold the init at flip, which is */
    /* between the base and current init.  Otherwise, initAtFlip */
    /* is kept at zero to avoid misuse (see */
    /* request.dylan.170429.sol.zero_). */
    /* .. _request.dylan.170429.sol.zero: https://info.ravenbrook.com/project/mps/import/2001-11-05/mmprevol/request/dylan/170429 */

    if (BufferIsTrapped(buffer)) {
      /* .check.use-trapped: This checking function uses BufferIsTrapped, */
      /* So BufferIsTrapped can't do checking as that would cause an */
      /* infinite loop. */
      if (buffer->mode & BufferModeFLIPPED) {
        CHECKL(buffer->ap_s.init == buffer->initAtFlip
               || buffer->ap_s.init == buffer->ap_s.alloc);
        CHECKL(buffer->base <= buffer->initAtFlip);
        CHECKL(buffer->initAtFlip <= (Addr)buffer->ap_s.init);
      }
      /* Nothing special to check in the logged mode. */
    } else {
      CHECKL(buffer->initAtFlip == (Addr)0);
    }
  }

  return TRUE;
}