2362N/A * Copyright (c) 2000, 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 2362N/A * published by the Free Software Foundation. 2362N/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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// A "SharedHeap" 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. 2037N/A// Note on use of FlexibleWorkGang's for GC. 2037N/A// There are three places where task completion is determined. 1870N/A// 1) ParallelTaskTerminator::offer_termination() where _n_threads 1870N/A// must be set to the correct value so that count of workers that 1870N/A// have offered termination will exactly match the number 1870N/A// working on the task. Tasks such as those derived from GCTask 1870N/A// use ParallelTaskTerminator's. Tasks that want load balancing 0N/A// by work stealing use this method to gauge completion. 0N/A// 2) SubTasksDone has a variable _n_threads that is used in 0N/A// all_tasks_completed() to determine completion. all_tasks_complete() 0N/A// counts the number of tasks that have been done and then reset 0N/A// the SubTasksDone so that it can be used again. When the number of 0N/A// tasks is set to the number of GC workers, then _n_threads must 0N/A// be set to the number of active GC workers. G1CollectedHeap, 0N/A// HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone. 0N/A// This seems too many. 0N/A// 3) SequentialSubTasksDone has an _n_threads that is used in 0N/A// a way similar to SubTasksDone and has the same dependency on the 0N/A// number of active GC workers. CompactibleFreeListSpace and Space 0N/A// have SequentialSubTasksDone's. 0N/A// Example of using SubTasksDone and SequentialSubTasksDone 0N/A// G1CollectedHeap::g1_process_strong_roots() calls 0N/A// process_strong_roots(false, // no scoping; this is parallel code 0N/A// collecting_perm_gen, so, 0N/A// &buf_scan_non_heap_roots, 0N/A// &eager_scan_code_roots, 0N/A// which delegates to SharedHeap::process_strong_roots() and uses 0N/A// SubTasksDone* _process_strong_tasks to claim tasks. 1870N/A// process_strong_roots() calls 1870N/A// rem_set()->younger_refs_iterate(perm_gen(), perm_blk); 0N/A// to scan the card table and which eventually calls down into 0N/A// CardTableModRefBS::par_non_clean_card_iterate_work(). This method 0N/A// uses SequentialSubTasksDone* _pst to claim tasks. 0N/A// Both SubTasksDone and SequentialSubTasksDone call their method 0N/A// all_tasks_completed() to count the number of GC workers that have 0N/A// finished their work. That logic is "when all the workers are 1870N/A// finished the tasks are finished". 1870N/A// The pattern that appears in the code is to set _n_threads 0N/A// to a value > 1 before a task that you would like executed in parallel 0N/A// and then to set it to 0 after that task has completed. A value of 0N/A// 0 is a "special" value in set_n_threads() which translates to 0N/A// setting _n_threads to 1. 0N/A// Some code uses _n_terminiation to decide if work should be done in 0N/A// is an example of such code. Look for variable "is_par" for other 0N/A// The active_workers is not reset to 0 after a parallel phase. It's 0N/A// value may be used in later phases and in one instance at least 1870N/A// (the parallel remark) it has to be used (the parallel remark depends 1870N/A// on the partitioning done in the previous parallel scavenge). 0N/A // For claiming strong_roots tasks. 0N/A // There should be only a single instance of "SharedHeap" in a program. 0N/A // This is enforced with the protected constructor below, which will also 0N/A // set the static pointer "_sh" to that instance. 0N/A // All heaps contain a "permanent generation." This is some ways 0N/A // similar to a generation in a generational system, in other ways not. 0N/A // See the "PermGen" class. 0N/A // and the Gen Remembered Set, at least one good enough to scan the perm 0N/A // A gc policy, controls global gc resource issues 0N/A // See the discussion below, in the specification of the reader function 0N/A // for this variable. 0N/A // If we're doing parallel GC, use this gang of threads. 1870N/A // Full initialization is done in a concrete subtype's "initialize" 0N/A // Returns true if the calling thread holds the heap lock, 1870N/A // or the calling thread is a par gc thread and the heap_lock is held 1870N/A // by the vm thread doing a gc operation. 0N/A // True if the heap_lock is held by the a non-gc thread invoking a gc 0N/A // Does operations required after initialization has been done. 0N/A // Initialization of ("weak") reference processing support 0N/A // This function returns the "GenRemSet" object that allows us to scan 0N/A // generations; at least the perm gen, possibly more in a fully 0N/A // generational heap. 0N/A // These function return the "permanent" generation, in which 0N/A // reflective objects are allocated and stored. Two versions, the second 0N/A // of which returns the view of the perm gen as a generation. 0N/A // Iteration functions. 0N/A // Same as above, restricted to a memory region. 0N/A // Iterate over all objects allocated since the last collection, calling 0N/A // "cl->do_object" on each. The heap must have been initialized properly 0N/A // to support this function, or else this call will fail. 2037N/A // Iterate over all spaces in use in the heap, in an undefined order. 2037N/A // A SharedHeap will contain some number of spaces. This finds the 2037N/A // space whose reserved area contains the given address, or else returns 0N/A // Some collectors will perform "process_strong_roots" in parallel. 0N/A // Such a call will involve claiming some fine-grained tasks, such as 0N/A // scanning of threads. To make this process simpler, we provide the 0N/A // "strong_roots_parity()" method. Collectors that start parallel tasks 0N/A // whose threads invoke "process_strong_roots" must 0N/A // call "change_strong_roots_parity" in sequential code starting such a 0N/A // task. (This also means that a parallel thread may only call 0N/A // process_strong_roots once.) 0N/A // For calls to process_strong_roots by sequential code, the parity is 0N/A // updated automatically. 0N/A // The idea is that objects representing fine-grained tasks, such as 0N/A // threads, will contain a "parity" field. A task will is claimed in the 0N/A // current "process_strong_roots" call only if its parity field is the 0N/A // same as the "strong_roots_parity"; task claiming is accomplished by 0N/A // updating the parity field to the strong_roots_parity with a CAS. 0N/A // If the client meats this spec, then strong_roots_parity() will have 0N/A // the following properties: 0N/A // a) to return a different value than was returned before the last 0N/A // call to change_strong_roots_parity, and 0N/A // c) to never return a distinguished value (zero) with which such 0N/A // task-claiming variables may be initialized, to indicate "never 0N/A // Call these in sequential code around process_strong_roots. 0N/A // strong_roots_prologue calls change_strong_roots_parity, if 0N/A // parallel tasks are enabled. 0N/A // Invoke the "do_oop" method the closure "roots" on all root locations. 0N/A // If "collecting_perm_gen" is false, then roots that may only contain 1870N/A // references to permGen objects are not scanned; instead, in that case, 1870N/A // the "perm_blk" closure is applied to all outgoing refs in the 0N/A // permanent generation. The "so" argument determines which of roots 0N/A // the closure is applied to: 0N/A // "SO_None" does none; 0N/A // "SO_AllClasses" applies the closure to all entries in the SystemDictionary; 0N/A // "SO_SystemClasses" to all the "system" classes and loaders; 1870N/A // "SO_Strings" applies the closure to all entries in StringTable; 1870N/A // "SO_CodeCache" applies the closure to all elements of the CodeCache. 0N/A // Apply "blk" to all the weak roots of the system. These include 0N/A // JNI weak roots, the code cache, system dictionary, symbol table, 0N/A // The functions below are helper functions that a subclass of 0N/A // "SharedHeap" can use in the implementation of its virtual 0N/A // Do anything common to GC's. 0N/A // Sets the number of parallel threads that will be doing tasks 0N/A // (such as process strong roots) subsequently. 0N/A // New methods from CollectedHeap 0N/A // Different from is_in_permanent in that is_in_permanent 0N/A // only checks if p is in the reserved area of the heap 0N/A // and this checks to see if it in the commited area. 0N/A // This is typically used by things like the forte stackwalker 0N/A // during verification of suspicious frame values. 1870N/A#
endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP