src/share/vm/memory/sharedHeap.hpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 435
a61af66fc99e
child 777
37f87013dfd8
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // A "SharedHeap" is an implementation of a java heap for HotSpot.  This
    26 // is an abstract class: there may be many different kinds of heaps.  This
    27 // class defines the functions that a heap must implement, and contains
    28 // infrastructure common to all heaps.
    30 class PermGen;
    31 class Generation;
    32 class BarrierSet;
    33 class GenRemSet;
    34 class Space;
    35 class SpaceClosure;
    36 class OopClosure;
    37 class OopsInGenClosure;
    38 class ObjectClosure;
    39 class SubTasksDone;
    40 class WorkGang;
    41 class CollectorPolicy;
    42 class KlassHandle;
    44 class SharedHeap : public CollectedHeap {
    45   friend class VMStructs;
    47 private:
    48   // For claiming strong_roots tasks.
    49   SubTasksDone* _process_strong_tasks;
    51 protected:
    52   // There should be only a single instance of "SharedHeap" in a program.
    53   // This is enforced with the protected constructor below, which will also
    54   // set the static pointer "_sh" to that instance.
    55   static SharedHeap* _sh;
    57   // All heaps contain a "permanent generation."  This is some ways
    58   // similar to a generation in a generational system, in other ways not.
    59   // See the "PermGen" class.
    60   PermGen* _perm_gen;
    62   // and the Gen Remembered Set, at least one good enough to scan the perm
    63   // gen.
    64   GenRemSet* _rem_set;
    66   // A gc policy, controls global gc resource issues
    67   CollectorPolicy *_collector_policy;
    69   // See the discussion below, in the specification of the reader function
    70   // for this variable.
    71   int _strong_roots_parity;
    73   // If we're doing parallel GC, use this gang of threads.
    74   WorkGang* _workers;
    76   // Number of parallel threads currently working on GC tasks.
    77   // O indicates use sequential code; 1 means use parallel code even with
    78   // only one thread, for performance testing purposes.
    79   int _n_par_threads;
    81   // Full initialization is done in a concrete subtype's "initialize"
    82   // function.
    83   SharedHeap(CollectorPolicy* policy_);
    85 public:
    86   static SharedHeap* heap() { return _sh; }
    88   CollectorPolicy *collector_policy() const { return _collector_policy; }
    90   void set_barrier_set(BarrierSet* bs);
    92   // Does operations required after initialization has been done.
    93   virtual void post_initialize();
    95   // Initialization of ("weak") reference processing support
    96   virtual void ref_processing_init();
    98   void set_perm(PermGen* perm_gen) { _perm_gen = perm_gen; }
   100   // A helper function that fills an allocated-but-not-yet-initialized
   101   // region with a garbage object.
   102   static void fill_region_with_object(MemRegion mr);
   104   // Minimum garbage fill object size
   105   static size_t min_fill_size()          { return (size_t)align_object_size(oopDesc::header_size()); }
   106   static size_t min_fill_size_in_bytes() { return min_fill_size() * HeapWordSize; }
   108   // This function returns the "GenRemSet" object that allows us to scan
   109   // generations; at least the perm gen, possibly more in a fully
   110   // generational heap.
   111   GenRemSet* rem_set() { return _rem_set; }
   113   // These function return the "permanent" generation, in which
   114   // reflective objects are allocated and stored.  Two versions, the second
   115   // of which returns the view of the perm gen as a generation.
   116   PermGen* perm() const { return _perm_gen; }
   117   Generation* perm_gen() const { return _perm_gen->as_gen(); }
   119   // Iteration functions.
   120   void oop_iterate(OopClosure* cl) = 0;
   122   // Same as above, restricted to a memory region.
   123   virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0;
   125   // Iterate over all objects allocated since the last collection, calling
   126   // "cl->do_object" on each.  The heap must have been initialized properly
   127   // to support this function, or else this call will fail.
   128   virtual void object_iterate_since_last_GC(ObjectClosure* cl) = 0;
   130   // Iterate over all spaces in use in the heap, in an undefined order.
   131   virtual void space_iterate(SpaceClosure* cl) = 0;
   133   // A SharedHeap will contain some number of spaces.  This finds the
   134   // space whose reserved area contains the given address, or else returns
   135   // NULL.
   136   virtual Space* space_containing(const void* addr) const = 0;
   138   bool no_gc_in_progress() { return !is_gc_active(); }
   140   // Some collectors will perform "process_strong_roots" in parallel.
   141   // Such a call will involve claiming some fine-grained tasks, such as
   142   // scanning of threads.  To make this process simpler, we provide the
   143   // "strong_roots_parity()" method.  Collectors that start parallel tasks
   144   // whose threads invoke "process_strong_roots" must
   145   // call "change_strong_roots_parity" in sequential code starting such a
   146   // task.  (This also means that a parallel thread may only call
   147   // process_strong_roots once.)
   148   //
   149   // For calls to process_strong_roots by sequential code, the parity is
   150   // updated automatically.
   151   //
   152   // The idea is that objects representing fine-grained tasks, such as
   153   // threads, will contain a "parity" field.  A task will is claimed in the
   154   // current "process_strong_roots" call only if its parity field is the
   155   // same as the "strong_roots_parity"; task claiming is accomplished by
   156   // updating the parity field to the strong_roots_parity with a CAS.
   157   //
   158   // If the client meats this spec, then strong_roots_parity() will have
   159   // the following properties:
   160   //   a) to return a different value than was returned before the last
   161   //      call to change_strong_roots_parity, and
   162   //   c) to never return a distinguished value (zero) with which such
   163   //      task-claiming variables may be initialized, to indicate "never
   164   //      claimed".
   165   void change_strong_roots_parity();
   166   int strong_roots_parity() { return _strong_roots_parity; }
   168   enum ScanningOption {
   169     SO_None                = 0x0,
   170     SO_AllClasses          = 0x1,
   171     SO_SystemClasses       = 0x2,
   172     SO_Symbols             = 0x4,
   173     SO_Strings             = 0x8,
   174     SO_CodeCache           = 0x10
   175   };
   177   WorkGang* workers() const { return _workers; }
   179   // Sets the number of parallel threads that will be doing tasks
   180   // (such as process strong roots) subsequently.
   181   virtual void set_par_threads(int t);
   183   // Number of threads currently working on GC tasks.
   184   int n_par_threads() { return _n_par_threads; }
   186   // Invoke the "do_oop" method the closure "roots" on all root locations.
   187   // If "collecting_perm_gen" is false, then roots that may only contain
   188   // references to permGen objects are not scanned.  If true, the
   189   // "perm_gen" closure is applied to all older-to-younger refs in the
   190   // permanent generation.  The "so" argument determines which of roots
   191   // the closure is applied to:
   192   // "SO_None" does none;
   193   // "SO_AllClasses" applies the closure to all entries in the SystemDictionary;
   194   // "SO_SystemClasses" to all the "system" classes and loaders;
   195   // "SO_Symbols" applies the closure to all entries in SymbolsTable;
   196   // "SO_Strings" applies the closure to all entries in StringTable;
   197   // "SO_CodeCache" applies the closure to all elements of the CodeCache.
   198   void process_strong_roots(bool collecting_perm_gen,
   199                             ScanningOption so,
   200                             OopClosure* roots,
   201                             OopsInGenClosure* perm_blk);
   203   // Apply "blk" to all the weak roots of the system.  These include
   204   // JNI weak roots, the code cache, system dictionary, symbol table,
   205   // string table.
   206   void process_weak_roots(OopClosure* root_closure,
   207                           OopClosure* non_root_closure);
   210   // Like CollectedHeap::collect, but assume that the caller holds the Heap_lock.
   211   virtual void collect_locked(GCCause::Cause cause) = 0;
   213   // The functions below are helper functions that a subclass of
   214   // "SharedHeap" can use in the implementation of its virtual
   215   // functions.
   217 protected:
   219   // Do anything common to GC's.
   220   virtual void gc_prologue(bool full) = 0;
   221   virtual void gc_epilogue(bool full) = 0;
   223 public:
   224   //
   225   // New methods from CollectedHeap
   226   //
   228   size_t permanent_capacity() const {
   229     assert(perm_gen(), "NULL perm gen");
   230     return perm_gen()->capacity();
   231   }
   233   size_t permanent_used() const {
   234     assert(perm_gen(), "NULL perm gen");
   235     return perm_gen()->used();
   236   }
   238   bool is_in_permanent(const void *p) const {
   239     assert(perm_gen(), "NULL perm gen");
   240     return perm_gen()->is_in_reserved(p);
   241   }
   243   // Different from is_in_permanent in that is_in_permanent
   244   // only checks if p is in the reserved area of the heap
   245   // and this checks to see if it in the commited area.
   246   // This is typically used by things like the forte stackwalker
   247   // during verification of suspicious frame values.
   248   bool is_permanent(const void *p) const {
   249     assert(perm_gen(), "NULL perm gen");
   250     return perm_gen()->is_in(p);
   251   }
   253   HeapWord* permanent_mem_allocate(size_t size) {
   254     assert(perm_gen(), "NULL perm gen");
   255     return _perm_gen->mem_allocate(size);
   256   }
   258   void permanent_oop_iterate(OopClosure* cl) {
   259     assert(perm_gen(), "NULL perm gen");
   260     _perm_gen->oop_iterate(cl);
   261   }
   263   void permanent_object_iterate(ObjectClosure* cl) {
   264     assert(perm_gen(), "NULL perm gen");
   265     _perm_gen->object_iterate(cl);
   266   }
   268   // Some utilities.
   269   void print_size_transition(size_t bytes_before,
   270                              size_t bytes_after,
   271                              size_t capacity);
   272 };

mercurial