hotspot/src/share/vm/gc_implementation/shared/mutableSpace.hpp

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)mutableSpace.hpp     1.22 07/05/05 17:05:35 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2007 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 MutableSpace is a subtype of ImmutableSpace that supports the
  29 // concept of allocation. This includes the concepts that a space may
  30 // be only partially full, and the querry methods that go with such
  31 // an assumption.
  32 //
  33 // Invariant: (ImmutableSpace +) bottom() <= top() <= end() 
  34 // top() is inclusive and end() is exclusive.
  35 


  36 class MutableSpace: public ImmutableSpace {
  37   friend class VMStructs;




  38  protected:
  39   HeapWord* _top;
  40 


  41  public:
  42   virtual ~MutableSpace()                  {}
  43   MutableSpace()                           { _top = NULL;    }

  44   // Accessors
  45   HeapWord* top() const                    { return _top;    }
  46   virtual void set_top(HeapWord* value)    { _top = value;   }
  47 
  48   HeapWord** top_addr()                    { return &_top; }
  49   HeapWord** end_addr()                    { return &_end; }
  50 
  51   virtual void set_bottom(HeapWord* value) { _bottom = value; }
  52   virtual void set_end(HeapWord* value)    { _end = value; }
  53 
  54   // Returns a subregion containing all objects in this space.
  55   MemRegion used_region() { return MemRegion(bottom(), top()); }
  56 
  57   // Initialization
  58   virtual void initialize(MemRegion mr, bool clear_space);
  59   virtual void clear();






  60   virtual void update() { }
  61   virtual void accumulate_statistics() { }
  62 
  63   // Overwrites the unused portion of this space. Note that some collectors
  64   // may use this "scratch" space during collections.
  65   virtual void mangle_unused_area() {
  66     mangle_region(MemRegion(_top, _end));
  67   }





  68   virtual void ensure_parsability() { }
  69 
  70   void mangle_region(MemRegion mr) {
  71     debug_only(Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord));
  72   }
  73 
  74   // Boolean querries.
  75   bool is_empty() const              { return used_in_words() == 0; }
  76   bool not_empty() const             { return used_in_words() > 0; }
  77   bool contains(const void* p) const { return _bottom <= p && p < _end; }
  78 
  79   // Size computations.  Sizes are in bytes.
  80   size_t used_in_bytes() const                { return used_in_words() * HeapWordSize; }
  81   size_t free_in_bytes() const                { return free_in_words() * HeapWordSize; }
  82 
  83   // Size computations.  Sizes are in heapwords.
  84   virtual size_t used_in_words() const                    { return pointer_delta(top(), bottom()); }
  85   virtual size_t free_in_words() const                    { return pointer_delta(end(),    top()); }
  86   virtual size_t tlab_capacity(Thread* thr) const         { return capacity_in_bytes();            }
  87   virtual size_t unsafe_max_tlab_alloc(Thread* thr) const { return free_in_bytes();                }
  88 
  89   // Allocation (return NULL if full)
  90   virtual HeapWord* allocate(size_t word_size);
  91   virtual HeapWord* cas_allocate(size_t word_size);
  92   // Optional deallocation. Used in NUMA-allocator.
  93   bool cas_deallocate(HeapWord *obj, size_t size);
  94 
  95   // Iteration.
  96   void oop_iterate(OopClosure* cl);
  97   void object_iterate(ObjectClosure* cl);
  98 
  99   // Debugging
 100   virtual void print() const;
 101   virtual void print_on(outputStream* st) const;
 102   virtual void print_short() const;
 103   virtual void print_short_on(outputStream* st) const;
 104   virtual void verify(bool allow_dirty) const;
 105 };
   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)mutableSpace.hpp     1.22 07/05/05 17:05:35 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 MutableSpace is a subtype of ImmutableSpace that supports the
  29 // concept of allocation. This includes the concepts that a space may
  30 // be only partially full, and the querry methods that go with such
  31 // an assumption.
  32 //
  33 // Invariant: (ImmutableSpace +) bottom() <= top() <= end() 
  34 // top() is inclusive and end() is exclusive.
  35 
  36 class MutableSpaceMangler;
  37 
  38 class MutableSpace: public ImmutableSpace {
  39   friend class VMStructs;
  40 
  41   // Helper for mangling unused space in debug builds
  42   MutableSpaceMangler* _mangler;
  43 
  44  protected:
  45   HeapWord* _top;
  46 
  47   MutableSpaceMangler* mangler() { return _mangler; }
  48 
  49  public:
  50   virtual ~MutableSpace();
  51   MutableSpace();
  52 
  53   // Accessors
  54   HeapWord* top() const                    { return _top;    }
  55   virtual void set_top(HeapWord* value)    { _top = value;   }
  56 
  57   HeapWord** top_addr()                    { return &_top; }
  58   HeapWord** end_addr()                    { return &_end; }
  59 
  60   virtual void set_bottom(HeapWord* value) { _bottom = value; }
  61   virtual void set_end(HeapWord* value)    { _end = value; }
  62 
  63   // Returns a subregion containing all objects in this space.
  64   MemRegion used_region() { return MemRegion(bottom(), top()); }
  65 
  66   // Initialization
  67   virtual void initialize(MemRegion mr,
  68                           bool clear_space,
  69                           bool mangle_space);
  70   virtual void clear(bool mangle_space);
  71   // Does the usual initialization but optionally resets top to bottom.
  72 #if 0  // MANGLE_SPACE
  73   void initialize(MemRegion mr, bool clear_space, bool reset_top);
  74 #endif
  75   virtual void update() { }
  76   virtual void accumulate_statistics() { }
  77 
  78   // Methods used in mangling.  See descriptions under SpaceMangler.
  79   virtual void mangle_unused_area() PRODUCT_RETURN;
  80   virtual void mangle_unused_area_complete() PRODUCT_RETURN;
  81   virtual void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN;
  82   virtual void check_mangled_unused_area_complete() PRODUCT_RETURN;
  83   virtual void set_top_for_allocations(HeapWord* v) PRODUCT_RETURN;
  84 
  85   // Used to save the space's current top for later use during mangling.
  86   virtual void set_top_for_allocations() PRODUCT_RETURN;
  87 
  88   virtual void ensure_parsability() { }
  89 
  90   virtual void mangle_region(MemRegion mr) PRODUCT_RETURN;


  91 
  92   // Boolean querries.
  93   bool is_empty() const              { return used_in_words() == 0; }
  94   bool not_empty() const             { return used_in_words() > 0; }
  95   bool contains(const void* p) const { return _bottom <= p && p < _end; }
  96 
  97   // Size computations.  Sizes are in bytes.
  98   size_t used_in_bytes() const                { return used_in_words() * HeapWordSize; }
  99   size_t free_in_bytes() const                { return free_in_words() * HeapWordSize; }
 100 
 101   // Size computations.  Sizes are in heapwords.
 102   virtual size_t used_in_words() const                    { return pointer_delta(top(), bottom()); }
 103   virtual size_t free_in_words() const                    { return pointer_delta(end(),    top()); }
 104   virtual size_t tlab_capacity(Thread* thr) const         { return capacity_in_bytes();            }
 105   virtual size_t unsafe_max_tlab_alloc(Thread* thr) const { return free_in_bytes();                }
 106 
 107   // Allocation (return NULL if full)
 108   virtual HeapWord* allocate(size_t word_size);
 109   virtual HeapWord* cas_allocate(size_t word_size);
 110   // Optional deallocation. Used in NUMA-allocator.
 111   bool cas_deallocate(HeapWord *obj, size_t size);
 112 
 113   // Iteration.
 114   void oop_iterate(OopClosure* cl);
 115   void object_iterate(ObjectClosure* cl);
 116 
 117   // Debugging
 118   virtual void print() const;
 119   virtual void print_on(outputStream* st) const;
 120   virtual void print_short() const;
 121   virtual void print_short_on(outputStream* st) const;
 122   virtual void verify(bool allow_dirty);
 123 };