home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / Jikes / Source / src / segment.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-24  |  4.0 KB  |  199 lines

  1. // $Id: segment.h,v 1.5 2001/01/05 09:13:21 mdejong Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1999, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef segment_INCLUDED
  11. #define segment_INCLUDED
  12.  
  13. #include "platform.h"
  14. #include "tuple.h"
  15.  
  16. #ifdef    HAVE_JIKES_NAMESPACE
  17. namespace Jikes {    // Open namespace Jikes block
  18. #endif
  19.  
  20. class SegmentPool;
  21.  
  22.  
  23. class PairSegment
  24. {
  25. public:
  26.  
  27.     enum
  28.     {
  29.         LIST_LIMIT = 5,
  30.         LOG_BLKSIZE = 8,
  31.         BLKSIZE = 1 << LOG_BLKSIZE,
  32.         MASK = 0xFFFFFFFF << LOG_BLKSIZE
  33.     };
  34.  
  35. private:
  36.  
  37.     class TargetValuePair
  38.     {
  39.     public:
  40.         u2 target;
  41.         u2 value;
  42.     };
  43.  
  44.     TargetValuePair list[LIST_LIMIT];
  45.     int top;
  46.     u2 *array;
  47.  
  48. public:
  49.  
  50.     PairSegment() : top(0),
  51.                     array(NULL)
  52.     {}
  53.  
  54.     ~PairSegment()
  55.     {
  56.         if (array)
  57.         {
  58.             unsigned offset = ((unsigned) list[0].target) & MASK;
  59.             delete [] (array + offset);
  60.         }
  61.     }
  62.  
  63.     u2 &Image(u2);
  64. };
  65.  
  66.  
  67. class Pair
  68. {
  69. public:
  70.  
  71.     Pair(SegmentPool &segment_pool_, int estimate = 0) : segment_pool(segment_pool_)
  72.     {
  73.         //
  74.         // DO NOT PERFORM THESE INITIALIZATION IN THE METHOD DECLARATOR !!!
  75.         // There appears to be a bug in the xlC compiler that causes base to
  76.         // not be initialized properly !!!
  77.         //
  78.         base_size = (estimate > 0 ? (estimate >> PairSegment::LOG_BLKSIZE) + 1 : 0);
  79.         base = (PairSegment **) (estimate > 0 ? memset(new PairSegment*[base_size], 0, base_size * sizeof(PairSegment *)) : NULL);
  80.     }
  81.  
  82.     ~Pair()
  83.     {
  84.         delete [] base;
  85.     }
  86.  
  87.     u2 &operator[](const u2);
  88.  
  89. private:
  90.  
  91.     SegmentPool &segment_pool;
  92.  
  93.     PairSegment **base;
  94.     int base_size;
  95. };
  96.  
  97.  
  98. class TripletSegment
  99. {
  100. public:
  101.  
  102.     enum
  103.     {
  104.         LIST_LIMIT = 5,
  105.         LOG_BLKSIZE = 8,
  106.         BLKSIZE = 1 << LOG_BLKSIZE,
  107.         MASK = 0xFFFFFFFF << LOG_BLKSIZE
  108.     };
  109.  
  110. private:
  111.  
  112.     class TargetValuePair
  113.     {
  114.     public:
  115.         u2 target;
  116.         Pair *value;
  117.     };
  118.  
  119.     SegmentPool &segment_pool;
  120.  
  121.     TargetValuePair list[LIST_LIMIT];
  122.     int top;
  123.     Pair **array;
  124.  
  125. public:
  126.  
  127.     TripletSegment(SegmentPool &segment_pool_) : segment_pool(segment_pool_),
  128.                                                  top(0),
  129.                                                  array(NULL)
  130.     {}
  131.  
  132.     ~TripletSegment()
  133.     {
  134.         if (array)
  135.         {
  136.             unsigned offset = ((unsigned) list[0].target) & MASK;
  137.             delete [] (array + offset);
  138.         }
  139.     }
  140.  
  141.     Pair &Image(u2);
  142. };
  143.  
  144.  
  145. class Triplet
  146. {
  147. public:
  148.  
  149.     Triplet(SegmentPool &segment_pool_, int estimate = 0) : segment_pool(segment_pool_)
  150.     {
  151.         //
  152.         // DO NOT PERFORM THESE INITIALIZATION IN THE METHOD DECLARATOR !!!
  153.         // There appears to be a bug in the xlC compiler that causes base to
  154.         // not be initialized properly !!!
  155.         //
  156.         base_size = (estimate > 0 ? (estimate >> TripletSegment::LOG_BLKSIZE) + 1 : 0);
  157.         base = (TripletSegment **)
  158.                (estimate > 0 ? memset(new TripletSegment*[base_size], 0, base_size * sizeof(TripletSegment *)) : NULL);
  159.     }
  160.  
  161.     ~Triplet()
  162.     {
  163.         delete [] base;
  164.     }
  165.  
  166.     u2 &Image(const u2, const u2);
  167.  
  168. private:
  169.  
  170.     SegmentPool &segment_pool;
  171.  
  172.     TripletSegment **base;
  173.     int base_size;
  174. };
  175.  
  176.  
  177. class SegmentPool
  178. {
  179.     Tuple<TripletSegment *> triplet_segment_pool;
  180.     Tuple<PairSegment *> pair_segment_pool;
  181.     Tuple<Pair *> pair_pool;
  182.  
  183. public:
  184.     SegmentPool();
  185.  
  186.     ~SegmentPool();
  187.  
  188.     Pair *AllocatePair(int estimate = 0) { return pair_pool.Next() = new Pair(*this, estimate); }
  189.     PairSegment *AllocatePairSegment() { return pair_segment_pool.Next() = new PairSegment(); }
  190.     TripletSegment *AllocateTripletSegment() { return triplet_segment_pool.Next() = new TripletSegment(*this); }
  191. };
  192.  
  193. #ifdef    HAVE_JIKES_NAMESPACE
  194. }            // Close namespace Jikes block
  195. #endif
  196.  
  197. #endif
  198.  
  199.