hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.hpp

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)freeBlockDictionary.hpp      1.32 07/05/05 17:05:47 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2005 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 //
  29 // Free block maintenance for Concurrent Mark Sweep Generation
  30 //
  31 // The main data structure for free blocks are
  32 // . an indexed array of small free blocks, and
  33 // . a dictionary of large free blocks
  34 //
  35 
  36 // No virtuals in FreeChunk (don't want any vtables).
  37 
  38 // A FreeChunk is merely a chunk that can be in a doubly linked list
  39 // and has a size field. NOTE: FreeChunks are distinguished from allocated
  40 // objects in two ways (by the sweeper). The second word (prev) has the
  41 // LSB set to indicate a free chunk; allocated objects' klass() pointers
  42 // don't have their LSB set. The corresponding bit in the CMSBitMap is
  43 // set when the chunk is allocated. There are also blocks that "look free"
  44 // but are not part of the free list and should not be coalesced into larger
  45 // free blocks. These free blocks have their two LSB's set.
  46 
  47 class FreeChunk VALUE_OBJ_CLASS_SPEC {
  48   friend class VMStructs;
  49   FreeChunk* _next;
  50   FreeChunk* _prev;
  51   size_t     _size;
  52 
  53  public:
  54   NOT_PRODUCT(static const size_t header_size();)
  55   // Returns "true" if the "wrd", which is required to be the second word
  56   // of a block, indicates that the block represents a free chunk.
  57   static bool secondWordIndicatesFreeChunk(intptr_t wrd) {
  58     return (wrd & 0x1) == 0x1;
  59   }
  60   bool isFree()       const {
  61     return secondWordIndicatesFreeChunk((intptr_t)_prev);
  62   }
  63   bool cantCoalesce() const { return (((intptr_t)_prev) & 0x3) == 0x3; }
  64   FreeChunk* next()   const { return _next; }
  65   FreeChunk* prev()   const { return (FreeChunk*)(((intptr_t)_prev) & ~(0x3)); }
  66   debug_only(void* prev_addr() const { return (void*)&_prev; })
  67 
  68   void linkAfter(FreeChunk* ptr) {
  69     linkNext(ptr);
  70     if (ptr != NULL) ptr->linkPrev(this);
  71   }
  72   void linkAfterNonNull(FreeChunk* ptr) {
  73     assert(ptr != NULL, "precondition violation");
  74     linkNext(ptr);
  75     ptr->linkPrev(this);
  76   }
  77   void linkNext(FreeChunk* ptr) { _next = ptr; }
  78   void linkPrev(FreeChunk* ptr) { _prev = (FreeChunk*)((intptr_t)ptr | 0x1); }
  79   void clearPrev()              { _prev = NULL; }
  80   void clearNext()              { _next = NULL; }
  81   void dontCoalesce()      {
  82     // the block should be free
  83     assert(isFree(), "Should look like a free block");
  84     _prev = (FreeChunk*)(((intptr_t)_prev) | 0x2);
  85   }
  86   void markFree()    { _prev = (FreeChunk*)((intptr_t)_prev | 0x1);    }
  87   void markNotFree() { _prev = NULL; }
  88 
  89   size_t size()           const { return _size; }
  90   void setSize(size_t size)     { _size = size; }
  91 
  92   // For volatile reads:
  93   size_t* size_addr()           { return &_size; }
  94 
  95   // Return the address past the end of this chunk
  96   HeapWord* end() const { return ((HeapWord*) this) + _size; }
  97 
  98   // debugging
  99   void verify()             const PRODUCT_RETURN;
 100   void verifyList()         const PRODUCT_RETURN;
 101   void mangleAllocated(size_t size) PRODUCT_RETURN;
 102   void mangleFreed(size_t size)     PRODUCT_RETURN; 
 103 };
 104 
 105 // Alignment helpers etc.
 106 #define numQuanta(x,y) ((x+y-1)/y)
 107 enum AlignmentConstants {
 108   MinChunkSize = numQuanta(sizeof(FreeChunk), MinObjAlignmentInBytes) * MinObjAlignment
 109 };
 110 
 111 // A FreeBlockDictionary is an abstract superclass that will allow
 112 // a number of alternative implementations in the future.
 113 class FreeBlockDictionary: public CHeapObj {
 114  public:
 115   enum Dither {
 116     atLeast,
 117     exactly,
 118     roughly
 119   };
 120   enum DictionaryChoice {
 121     dictionaryBinaryTree = 0,
 122     dictionarySplayTree  = 1,
 123     dictionarySkipList   = 2
 124   };
 125 
 126  private:
 127   NOT_PRODUCT(Mutex* _lock;)
 128 
 129  public:
 130   virtual void       removeChunk(FreeChunk* fc) = 0;


   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)freeBlockDictionary.hpp      1.32 07/05/05 17:05:47 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 



















































































  28 // A FreeBlockDictionary is an abstract superclass that will allow
  29 // a number of alternative implementations in the future.
  30 class FreeBlockDictionary: public CHeapObj {
  31  public:
  32   enum Dither {
  33     atLeast,
  34     exactly,
  35     roughly
  36   };
  37   enum DictionaryChoice {
  38     dictionaryBinaryTree = 0,
  39     dictionarySplayTree  = 1,
  40     dictionarySkipList   = 2
  41   };
  42 
  43  private:
  44   NOT_PRODUCT(Mutex* _lock;)
  45 
  46  public:
  47   virtual void       removeChunk(FreeChunk* fc) = 0;