collectedHeap.hpp revision 2597
3157N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 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 3233N/A// infrastructure common to all heaps. 3157N/A // Used for filler objects (static, but initialized in ctor). 3157N/A // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used 3157N/A // Reason for current garbage collection. Should be set to 3157N/A // a value reflecting no collection between collections. 3157N/A // Do common initializations that must follow instance construction, 3157N/A // for example, those needing virtual calls. 3157N/A // This code could perhaps be moved into initialize() but would 3157N/A // be slightly more awkward because we want the latter to be a 0N/A // Create a new tlab 3233N/A // Accumulate statistics on all tlabs. 3157N/A // Reinitialize tlabs before resuming mutators. 3157N/A // Allocate from the current thread's TLAB, with broken-out slow path. 3157N/A // Allocate an uninitialized block of the given size, or returns NULL if 3157N/A // Like allocate_init, but the block returned by a successful allocation 3157N/A // is guaranteed initialized to zeros. 3157N/A // Same as common_mem version, except memory is allocated in the permanent area 3157N/A // If there is no permanent area, revert to common_mem_allocate_noinit 3157N/A // Same as common_mem version, except memory is allocated in the permanent area 3157N/A // If there is no permanent area, revert to common_mem_allocate_init 3157N/A // Helper functions for (VM) allocation. 3157N/A // Clears an allocated object. 3157N/A // Filler object utilities. 3157N/A // Fill with a single array; caller must ensure filler_array_min_size() <= 3157N/A // words <= filler_array_max_size(). 3157N/A // Fill with a single object (either an int array or a java.lang.Object). 3157N/A * Returns JNI error code JNI_ENOMEM if memory could not be allocated, 3157N/A // In many heaps, there will be a need to perform some initialization activities 3157N/A // after the Universe is fully formed, but before general heap allocation is allowed. 3157N/A // This is the correct place to place such initialization methods. 3157N/A // Future cleanup here. The following functions should specify bytes or 3157N/A // heapwords as part of their signature. 3157N/A // Return "true" if the part of the heap that allocates Java 3157N/A // objects has reached the maximal committed limit that it can 3157N/A // reach, without a garbage collection. 3157N/A // Support for java.lang.Runtime.maxMemory(): return the maximum amount of 3157N/A // memory that the vm could make available for storing 'normal' java objects. 3157N/A // This is based on the reserved address space, but should not include space 3157N/A // that the vm uses internally for bookkeeping or temporary storage (e.g., 3157N/A // perm gen space or, in the case of the young gen, one of the survivor 3157N/A // Returns "TRUE" if "p" points into the reserved area of the heap. 3157N/A // Returns "TRUE" if "p" points to the head of an allocated object in the 3157N/A // heap. Since this method can be expensive in general, we restrict its 3157N/A // use to assertion checking only. 3157N/A // Let's define some terms: a "closed" subset of a heap is one that 3157N/A // 1) contains all currently-allocated objects, and 3157N/A // 2) is closed under reference: no object in the closed subset 3157N/A // references one outside the closed subset. 3157N/A // Membership in a heap's closed subset is useful for assertions. 3157N/A // Clearly, the entire heap is a closed subset, so the default 3157N/A // implementation is to use "is_in_reserved". But this may not be too 3157N/A // liberal to perform useful checking. Also, the "is_in" predicate 3157N/A // defines a closed subset, but may be too expensive, since "is_in" 3157N/A // verifies that its argument points to an object head. The 3157N/A // "closed_subset" method allows a heap to define an intermediate 3157N/A // predicate, allowing more precise checking than "is_in_reserved" at 3157N/A // lower cost than "is_in." 3157N/A // One important case is a heap composed of disjoint contiguous spaces, 3157N/A // such as the Garbage-First collector. Such heaps have a convenient 3157N/A // closed subset consisting of the allocated portions of those 3157N/A // Return "TRUE" iff the given pointer points into the heap's defined 3157N/A // closed subset (which defaults to the entire heap). 3157N/A // XXX is_permanent() and is_in_permanent() should be better named 3157N/A // to distinguish one from the other. 3157N/A // Returns "TRUE" if "p" is allocated as "permanent" data. 3157N/A // If the heap does not use "permanent" data, returns the same 3157N/A // value is_in_reserved() would return. 3157N/A // NOTE: this actually returns true if "p" is in reserved space 3157N/A // for the space not that it is actually allocated (i.e. in committed 3157N/A // space). If you need the more conservative answer use is_permanent(). 3157N/A // Returns true if "p" is in the part of the 3157N/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. // An object is scavengable if its location may move during a scavenge. // (A scavenge is a GC which is not a full GC.) // Returns "TRUE" if "p" is a method oop in the // current heap, with high probability. This predicate // is not stable, in general. // Number of threads currently working on GC tasks. // May be overridden to set additional parallelism. // Preload classes into the shared portion of the heap, and then dump // that data to a file so that it can be loaded directly by another // General obj/array allocation facilities. // Special obj/array allocation facilities. // Some heaps may want to manage "permanent" data uniquely. These default // to the general routines if the heap does not support such handling. // permanent_obj_allocate_no_klass_install() does not do the installation of // the klass pointer in the newly created object (as permanent_obj_allocate() // above does). This allows for a delay in the installation of the klass // pointer that is needed during the create of klassKlass's. The // method post_allocation_install_obj_klass() is used to install the // Raw memory allocation facilities // The obj and array allocate methods are covers for these methods. // The permanent allocation method should default to mem_allocate if // permanent memory isn't supported. // The boundary between a "large" and "small" array of primitives, in words. // Utilities for turning raw memory into filler objects. // min_fill_size() is the smallest region that can be filled. // fill_with_objects() can fill arbitrary-sized regions of the heap using // multiple objects. fill_with_object() is for regions known to be smaller // than the largest array of integers; it uses a single object to fill the // region and has slightly less overhead. // Some heaps may offer a contiguous region for shared non-blocking // allocation, via inlined code (by exporting the address of the top and // end fields defining the extent of the contiguous allocation region.) // This function returns "true" iff the heap supports this kind of // allocation. (Default is "no".) // These functions return the addresses of the fields that define the // boundaries of the contiguous allocation area. (These fields should be // physically near to one another.) guarantee(
false,
"inline contiguous allocation not supported");
guarantee(
false,
"inline contiguous allocation not supported");
// Some heaps may be in an unparseable state at certain times between // collections. This may be necessary for efficient implementation of // certain allocation-related activities. Calling this function before // attempting to parse a heap ensures that the heap is in a parsable // state (provided other concurrent activity does not introduce // unparsability). It is normally expected, therefore, that this // method is invoked with the world stopped. // NOTE: if you override this method, make sure you call // super::ensure_parsability so that the non-generational // part of the work gets done. See implementation of // CollectedHeap::ensure_parsability and, for instance, // that of GenCollectedHeap::ensure_parsability(). // The argument "retire_tlabs" controls whether existing TLABs // are merely filled or also retired, thus preventing further // allocation from them and necessitating allocation of new TLABs. // Return an estimate of the maximum allocation that could be performed // without triggering any collection or expansion activity. In a // generational collector, for example, this is probably the largest // allocation that could be supported (without expansion) in the youngest // generation. It is "unsafe" because no locks are taken; the result // should be treated as an approximation, not a guarantee, for use in // heuristic resizing decisions. // Section on thread-local allocation buffers (TLABs) // If the heap supports thread-local allocation buffers, it should override // the following methods: // Returns "true" iff the heap supports thread-local allocation buffers. // The amount of space available for thread-local allocation buffers. guarantee(
false,
"thread-local allocation buffers not supported");
// An estimate of the maximum allocation that could be performed // for thread-local allocation buffers without triggering any // collection or expansion activity. guarantee(
false,
"thread-local allocation buffers not supported");
// Can a compiler initialize a new object without store barriers? // This permission only extends from the creation of a new object // via a TLAB up to the first subsequent safepoint. If such permission // is granted for this heap type, the compiler promises to call // defer_store_barrier() below on any slow path allocation of // a new object for which such initializing store barriers will // If a compiler is eliding store barriers for TLAB-allocated objects, // there is probably a corresponding slow path which can produce // an object allocated anywhere. The compiler's runtime support // promises to call this function on such a slow-path-allocated // object before performing initializations that have elided // store barriers. Returns new_obj, or maybe a safer copy thereof. // Answers whether an initializing store to a new object currently // allocated at the given address doesn't need a store // barrier. Returns "true" if it doesn't need an initializing // store barrier; answers "false" if it does. // If a compiler is eliding store barriers for TLAB-allocated objects, // we will be informed of a slow-path allocation by a call // to new_store_pre_barrier() above. Such a call precedes the // initialization of the object itself, and no post-store-barriers will // be issued. Some heap types require that the barrier strictly follows // the initializing stores. (This is currently implemented by deferring the // barrier until the next slow-path allocation or gc-related safepoint.) // This interface answers whether a particular heap type needs the card // mark to be thus strictly sequenced after the stores. // If the CollectedHeap was asked to defer a store barrier above, // this informs it to flush such a deferred store barrier to the // Can a compiler elide a store barrier when it writes // a permanent oop into the heap? Applies when the compiler // is storing x to the heap, where x->is_perm() is true. // Does this heap support heap inspection (+PrintClassHistogram?) // Perform a collection of the heap; intended for use in implementing // "System.gc". This probably implies as full a collection as the // "CollectedHeap" supports. // This interface assumes that it's being called by the // vm thread. It collects the heap assuming that the // heap lock is already held and that we are executing in // the context of the vm thread. // Returns the barrier set for this heap // Returns "true" iff there is a stop-world GC in progress. (I assume // that it should answer "false" for the concurrent part of a concurrent // Total number of GC collections (started) // Increment total number of GC collections (started) // Should be protected but used by PSMarkSweep - cleanup for 1.4.2 // Return the AdaptiveSizePolicy for the heap. // Return the CollectorPolicy for the heap // Iterate over all the ref-containing fields of all objects, calling // "cl.do_oop" on each. This includes objects in permanent memory. // Iterate over all objects, calling "cl.do_object" on each. // This includes objects in permanent memory. // Similar to object_iterate() except iterates only // Behaves the same as oop_iterate, except only traverses // interior pointers contained in permanent memory. If there // is no permanent memory, does nothing. // Behaves the same as object_iterate, except only traverses // object contained in permanent memory. If there is no // permanent memory, does nothing. // NOTE! There is no requirement that a collector implement these // A CollectedHeap is divided into a dense sequence of "blocks"; that is, // each address in the (reserved) heap is a member of exactly // one block. The defining characteristic of a block is that it is // possible to find its size, and thus to progress forward to the next // block. (Blocks may be of different sizes.) Thus, blocks may // represent Java objects, or they might be free blocks in a // free-list-based heap (or subheap), as long as the two kinds are // distinguishable and the size of each is determinable. // Returns the address of the start of the "block" that contains the // address "addr". We say "blocks" instead of "object" since some heaps // may not pack objects densely; a chunk may either be an object or a // Requires "addr" to be the start of a chunk, and returns its size. // "addr + size" is required to be the start of a new chunk, or the end // of the active area of the heap. // Requires "addr" to be the start of a block, and returns "TRUE" iff // the block is an object. // Returns the longest time (in ms) that has elapsed since the last // time that any part of the heap was examined by a garbage collection. // Perform any cleanup actions necessary before allowing a verification. // Generate any dumps preceding or following a full gc virtual void print()
const = 0;
// Print all GC threads (other than the VM thread) // Iterator for all GC threads (other than VM thread) // Print any relevant tracing info that flags imply. // Default implementation does nothing. // Non product verification and debugging. // Support for PromotionFailureALot. Return true if it's time to cause a // promotion failure. The no-argument version uses // this->_promotion_failure_alot_count as the counter. // Reset the PromotionFailureALot counters. Should be called at the end of a // GC in which promotion failure ocurred. #
endif // #ifndef PRODUCT // This is a convenience method that is used in cases where // the actual number of GC worker threads is not pertinent but // only whether there more than 0. Use of this method helps // reduce the occurrence of ParallelGCThreads to uses where the // actual number may be germane. // Class to set and reset the GC cause for a CollectedHeap. "This method manipulates heap state without locking");
"This method manipulates heap state without locking");
#
endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP