collectedHeap.hpp revision 113
0N/A * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A// A "CollectedHeap" is an implementation of a java heap for HotSpot. This 0N/A// is an abstract class: there may be many different kinds of heaps. This 0N/A// class defines the functions that a heap must implement, and contains 0N/A// infrastructure common to all heaps. 0N/A// ParallelScavengeHeap 0N/A // Reason for current garbage collection. Should be set to 0N/A // a value reflecting no collection between collections. 0N/A // Create a new tlab 0N/A // Fix up tlabs to make the heap well-formed again, 0N/A // optionally retiring the tlabs. 0N/A // Accumulate statistics on all tlabs. 0N/A // Reinitialize tlabs before resuming mutators. 0N/A // Allocate from the current thread's TLAB, with broken-out slow path. 0N/A // Allocate an uninitialized block of the given size, or returns NULL if 0N/A // this is impossible. 0N/A // Like allocate_init, but the block returned by a successful allocation 0N/A // is guaranteed initialized to zeros. 0N/A // Same as common_mem version, except memory is allocated in the permanent area 0N/A // If there is no permanent area, revert to common_mem_allocate_noinit 0N/A // Same as common_mem version, except memory is allocated in the permanent area 0N/A // If there is no permanent area, revert to common_mem_allocate_init 0N/A // Helper functions for (VM) allocation. 0N/A // Clears an allocated object. 0N/A // Verification functions 0N/A * Returns JNI error code JNI_ENOMEM if memory could not be allocated, 0N/A * and JNI_OK on success. 0N/A // In many heaps, there will be a need to perform some initialization activities 0N/A // after the Universe is fully formed, but before general heap allocation is allowed. 0N/A // This is the correct place to place such initialization methods. 0N/A // Future cleanup here. The following functions should specify bytes or 0N/A // heapwords as part of their signature. 0N/A // Return "true" if the part of the heap that allocates Java 0N/A // objects has reached the maximal committed limit that it can 0N/A // reach, without a garbage collection. 0N/A // Support for java.lang.Runtime.maxMemory(): return the maximum amount of 0N/A // memory that the vm could make available for storing 'normal' java objects. 0N/A // This is based on the reserved address space, but should not include space 0N/A // that the vm uses internally for bookkeeping or temporary storage (e.g., 0N/A // perm gen space or, in the case of the young gen, one of the survivor 0N/A // Returns "TRUE" if "p" points into the reserved area of the heap. 0N/A // Returns "TRUE" if "p" points to the head of an allocated object in the 0N/A // heap. Since this method can be expensive in general, we restrict its 0N/A // use to assertion checking only. 0N/A virtual bool is_in(
const void* p)
const = 0;
0N/A // Let's define some terms: a "closed" subset of a heap is one that 0N/A // 1) contains all currently-allocated objects, and 0N/A // 2) is closed under reference: no object in the closed subset 0N/A // references one outside the closed subset. 0N/A // Membership in a heap's closed subset is useful for assertions. 0N/A // Clearly, the entire heap is a closed subset, so the default 0N/A // implementation is to use "is_in_reserved". But this may not be too 0N/A // liberal to perform useful checking. Also, the "is_in" predicate 0N/A // defines a closed subset, but may be too expensive, since "is_in" 0N/A // verifies that its argument points to an object head. The 0N/A // "closed_subset" method allows a heap to define an intermediate 0N/A // predicate, allowing more precise checking than "is_in_reserved" at 0N/A // lower cost than "is_in." 0N/A // One important case is a heap composed of disjoint contiguous spaces, 0N/A // such as the Garbage-First collector. Such heaps have a convenient 0N/A // closed subset consisting of the allocated portions of those 0N/A // contiguous spaces. 0N/A // Return "TRUE" iff the given pointer points into the heap's defined 0N/A // closed subset (which defaults to the entire heap). 0N/A // Returns "TRUE" if "p" is allocated as "permanent" data. 0N/A // If the heap does not use "permanent" data, returns the same 0N/A // value is_in_reserved() would return. 0N/A // NOTE: this actually returns true if "p" is in reserved space 0N/A // for the space not that it is actually allocated (i.e. in committed 0N/A // space). If you need the more conservative answer use is_permanent(). 0N/A // Returns "TRUE" if "p" is in the committed area of "permanent" data. 0N/A // If the heap does not use "permanent" data, returns the same 0N/A // value is_in() would return. 0N/A // Returns "TRUE" if "p" is a method oop in the 0N/A // current heap, with high probability. This predicate 0N/A // is not stable, in general. 0N/A // Preload classes into the shared portion of the heap, and then dump 0N/A // that data to a file so that it can be loaded directly by another 0N/A // VM (then terminate). 0N/A // Some heaps may want to manage "permanent" data uniquely. These default 0N/A // to the general routines if the heap does not support such handling. 0N/A // permanent_obj_allocate_no_klass_install() does not do the installation of 0N/A // the klass pointer in the newly created object (as permanent_obj_allocate() 0N/A // above does). This allows for a delay in the installation of the klass 0N/A // pointer that is needed during the create of klassKlass's. The 0N/A // method post_allocation_install_obj_klass() is used to install the 0N/A // Raw memory allocation facilities 0N/A // The obj and array allocate methods are covers for these methods. 0N/A // The permanent allocation method should default to mem_allocate if 0N/A // permanent memory isn't supported. 0N/A // The boundary between a "large" and "small" array of primitives, in words. 0N/A // Some heaps may offer a contiguous region for shared non-blocking 0N/A // allocation, via inlined code (by exporting the address of the top and 0N/A // end fields defining the extent of the contiguous allocation region.) 0N/A // This function returns "true" iff the heap supports this kind of 0N/A // allocation. (Default is "no".) 0N/A // These functions return the addresses of the fields that define the 0N/A // boundaries of the contiguous allocation area. (These fields should be 0N/A // physically near to one another.) 0N/A guarantee(
false,
"inline contiguous allocation not supported");
0N/A guarantee(
false,
"inline contiguous allocation not supported");
0N/A // Some heaps may be in an unparseable state at certain times between 0N/A // collections. This may be necessary for efficient implementation of 0N/A // certain allocation-related activities. Calling this function before 0N/A // attempting to parse a heap ensures that the heap is in a parsable 0N/A // state (provided other concurrent activity does not introduce 0N/A // unparsability). It is normally expected, therefore, that this 0N/A // method is invoked with the world stopped. 0N/A // NOTE: if you override this method, make sure you call 0N/A // super::ensure_parsability so that the non-generational 0N/A // part of the work gets done. See implementation of 0N/A // CollectedHeap::ensure_parsability and, for instance, 0N/A // that of GenCollectedHeap::ensure_parsability(). 0N/A // The argument "retire_tlabs" controls whether existing TLABs 0N/A // are merely filled or also retired, thus preventing further 0N/A // allocation from them and necessitating allocation of new TLABs. 0N/A // Return an estimate of the maximum allocation that could be performed 0N/A // without triggering any collection or expansion activity. In a 0N/A // generational collector, for example, this is probably the largest 0N/A // allocation that could be supported (without expansion) in the youngest 0N/A // generation. It is "unsafe" because no locks are taken; the result 0N/A // should be treated as an approximation, not a guarantee, for use in 0N/A // heuristic resizing decisions. 0N/A // Section on thread-local allocation buffers (TLABs) 0N/A // If the heap supports thread-local allocation buffers, it should override 0N/A // the following methods: 0N/A // Returns "true" iff the heap supports thread-local allocation buffers. 0N/A // The default is "no". 0N/A // The amount of space available for thread-local allocation buffers. 0N/A guarantee(
false,
"thread-local allocation buffers not supported");
0N/A // An estimate of the maximum allocation that could be performed 0N/A // for thread-local allocation buffers without triggering any 0N/A // collection or expansion activity. 0N/A guarantee(
false,
"thread-local allocation buffers not supported");
0N/A // Can a compiler initialize a new object without store barriers? 0N/A // This permission only extends from the creation of a new object 0N/A // via a TLAB up to the first subsequent safepoint. 0N/A // If a compiler is eliding store barriers for TLAB-allocated objects, 0N/A // there is probably a corresponding slow path which can produce 0N/A // an object allocated anywhere. The compiler's runtime support 0N/A // promises to call this function on such a slow-path-allocated 0N/A // object before performing initializations that have elided 0N/A // store barriers. Returns new_obj, or maybe a safer copy thereof. 0N/A // Can a compiler elide a store barrier when it writes 0N/A // a permanent oop into the heap? Applies when the compiler 0N/A // is storing x to the heap, where x->is_perm() is true. 0N/A // Does this heap support heap inspection (+PrintClassHistogram?) 0N/A return false;
// Until RFE 5023697 is implemented 0N/A // Perform a collection of the heap; intended for use in implementing 0N/A // "System.gc". This probably implies as full a collection as the 0N/A // "CollectedHeap" supports. 0N/A // This interface assumes that it's being called by the 0N/A // vm thread. It collects the heap assuming that the 0N/A // heap lock is already held and that we are executing in 0N/A // the context of the vm thread. 0N/A // Returns the barrier set for this heap 0N/A // Returns "true" iff there is a stop-world GC in progress. (I assume 0N/A // that it should answer "false" for the concurrent part of a concurrent 0N/A // collector -- dld). 0N/A // Total number of GC collections (started) 0N/A // Increment total number of GC collections (started) 0N/A // Should be protected but used by PSMarkSweep - cleanup for 1.4.2 0N/A // Return the AdaptiveSizePolicy for the heap. 0N/A // Iterate over all the ref-containing fields of all objects, calling 0N/A // "cl.do_oop" on each. This includes objects in permanent memory. 0N/A // Iterate over all objects, calling "cl.do_object" on each. 0N/A // This includes objects in permanent memory. 0N/A // Behaves the same as oop_iterate, except only traverses 0N/A // interior pointers contained in permanent memory. If there 0N/A // is no permanent memory, does nothing. 0N/A // Behaves the same as object_iterate, except only traverses 0N/A // object contained in permanent memory. If there is no 0N/A // permanent memory, does nothing. 0N/A // NOTE! There is no requirement that a collector implement these 0N/A // A CollectedHeap is divided into a dense sequence of "blocks"; that is, 0N/A // each address in the (reserved) heap is a member of exactly 0N/A // one block. The defining characteristic of a block is that it is 0N/A // possible to find its size, and thus to progress forward to the next 0N/A // block. (Blocks may be of different sizes.) Thus, blocks may 0N/A // represent Java objects, or they might be free blocks in a 0N/A // free-list-based heap (or subheap), as long as the two kinds are 0N/A // distinguishable and the size of each is determinable. 0N/A // Returns the address of the start of the "block" that contains the 0N/A // address "addr". We say "blocks" instead of "object" since some heaps 0N/A // may not pack objects densely; a chunk may either be an object or a 0N/A // Requires "addr" to be the start of a chunk, and returns its size. 0N/A // "addr + size" is required to be the start of a new chunk, or the end 0N/A // of the active area of the heap. 0N/A // Requires "addr" to be the start of a block, and returns "TRUE" iff 0N/A // the block is an object. 0N/A // Returns the longest time (in ms) that has elapsed since the last 0N/A // time that any part of the heap was examined by a garbage collection. 0N/A // Perform any cleanup actions necessary before allowing a verification. 0N/A // Print all GC threads (other than the VM thread) 0N/A // used by this heap. 0N/A // Iterator for all GC threads (other than VM thread) 0N/A // Print any relevant tracing info that flags imply. 0N/A // Default implementation does nothing. 0N/A // Heap verification 0N/A // Non product verification and debugging. 0N/A // Support for PromotionFailureALot. Return true if it's time to cause a 0N/A // promotion failure. The no-argument version uses 0N/A // this->_promotion_failure_alot_count as the counter. 0N/A // Reset the PromotionFailureALot counters. Should be called at the end of a 0N/A // GC in which promotion failure ocurred. 0N/A#
endif // #ifndef PRODUCT 0N/A// Class to set and reset the GC cause for a CollectedHeap. 0N/A "This method manipulates heap state without locking");
0N/A "This method manipulates heap state without locking");