duke@435: /* mlarsson@7686: * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP stefank@2314: mlarsson@7688: #include "gc_implementation/shared/gcId.hpp" stefank@2314: #include "memory/heapInspection.hpp" stefank@2314: #include "runtime/handles.hpp" stefank@2314: #include "runtime/jniHandles.hpp" stefank@2314: #include "runtime/synchronizer.hpp" stefank@2314: #include "runtime/vm_operations.hpp" kamg@2445: #include "prims/jvmtiExport.hpp" stefank@2314: duke@435: // The following class hierarchy represents duke@435: // a set of operations (VM_Operation) related to GC. duke@435: // duke@435: // VM_Operation duke@435: // VM_GC_Operation duke@435: // VM_GC_HeapInspection duke@435: // VM_GenCollectFull duke@435: // VM_GenCollectFullConcurrent duke@435: // VM_ParallelGCSystemGC mlarsson@7687: // VM_CollectForAllocation mlarsson@7687: // VM_GenCollectForAllocation mlarsson@7687: // VM_ParallelGCFailedAllocation duke@435: // VM_GC_Operation duke@435: // - implements methods common to all classes in the hierarchy: duke@435: // prevents multiple gc requests and manages lock on heap; duke@435: // duke@435: // VM_GC_HeapInspection duke@435: // - prints class histogram on SIGBREAK if PrintClassHistogram duke@435: // is specified; and also the attach "inspectheap" operation duke@435: // mlarsson@7687: // VM_CollectForAllocation duke@435: // VM_GenCollectForAllocation duke@435: // VM_ParallelGCFailedAllocation duke@435: // - this operation is invoked when allocation is failed; duke@435: // operation performs garbage collection and tries to duke@435: // allocate afterwards; duke@435: // duke@435: // VM_GenCollectFull duke@435: // VM_GenCollectFullConcurrent duke@435: // VM_ParallelGCSystemGC duke@435: // - these operations preform full collection of heaps of duke@435: // different kind duke@435: // duke@435: duke@435: class VM_GC_Operation: public VM_Operation { duke@435: protected: mlarsson@7686: BasicLock _pending_list_basic_lock; // for refs pending list notification (PLL) mlarsson@7686: uint _gc_count_before; // gc count before acquiring PLL mlarsson@7686: uint _full_gc_count_before; // full gc count before acquiring PLL mlarsson@7686: bool _full; // whether a "full" collection mlarsson@7686: bool _prologue_succeeded; // whether doit_prologue succeeded duke@435: GCCause::Cause _gc_cause; // the putative cause for this gc op mlarsson@7686: bool _gc_locked; // will be set if gc was locked duke@435: duke@435: virtual bool skip_operation() const; duke@435: duke@435: // java.lang.ref.Reference support duke@435: void acquire_pending_list_lock(); duke@435: void release_and_notify_pending_list_lock(); duke@435: duke@435: public: mlarsson@7686: VM_GC_Operation(uint gc_count_before, brutisso@2532: GCCause::Cause _cause, mlarsson@7686: uint full_gc_count_before = 0, duke@435: bool full = false) { duke@435: _full = full; duke@435: _prologue_succeeded = false; duke@435: _gc_count_before = gc_count_before; duke@435: duke@435: // A subclass constructor will likely overwrite the following brutisso@2532: _gc_cause = _cause; duke@435: duke@435: _gc_locked = false; duke@435: tonyp@2011: _full_gc_count_before = full_gc_count_before; jmasa@1822: // In ParallelScavengeHeap::mem_allocate() collections can be jmasa@1822: // executed within a loop and _all_soft_refs_clear can be set jmasa@1822: // true after they have been cleared by a collection and another jmasa@1822: // collection started so that _all_soft_refs_clear can be true jmasa@1822: // when this collection is started. Don't assert that jmasa@1822: // _all_soft_refs_clear have to be false here even though jmasa@1822: // mutators have run. Soft refs will be cleared again in this jmasa@1822: // collection. duke@435: } jmasa@1822: ~VM_GC_Operation() { jmasa@1822: CollectedHeap* ch = Universe::heap(); jmasa@1822: ch->collector_policy()->set_all_soft_refs_clear(false); jmasa@1822: } duke@435: duke@435: // Acquire the reference synchronization lock duke@435: virtual bool doit_prologue(); duke@435: // Do notifyAll (if needed) and release held lock duke@435: virtual void doit_epilogue(); duke@435: duke@435: virtual bool allow_nested_vm_operations() const { return true; } duke@435: bool prologue_succeeded() const { return _prologue_succeeded; } duke@435: duke@435: void set_gc_locked() { _gc_locked = true; } duke@435: bool gc_locked() const { return _gc_locked; } duke@435: duke@435: static void notify_gc_begin(bool full = false); duke@435: static void notify_gc_end(); duke@435: }; duke@435: duke@435: duke@435: class VM_GC_HeapInspection: public VM_GC_Operation { duke@435: private: duke@435: outputStream* _out; duke@435: bool _full_gc; acorn@4497: bool _csv_format; // "comma separated values" format for spreadsheet. acorn@4497: bool _print_help; acorn@4497: bool _print_class_stats; acorn@4497: const char* _columns; duke@435: public: sla@5237: VM_GC_HeapInspection(outputStream* out, bool request_full_gc) : duke@435: VM_GC_Operation(0 /* total collections, dummy, ignored */, brutisso@2532: GCCause::_heap_inspection /* GC Cause */, duke@435: 0 /* total full collections, dummy, ignored */, duke@435: request_full_gc) { duke@435: _out = out; duke@435: _full_gc = request_full_gc; acorn@4497: _csv_format = false; acorn@4497: _print_help = false; acorn@4497: _print_class_stats = false; acorn@4497: _columns = NULL; duke@435: } duke@435: duke@435: ~VM_GC_HeapInspection() {} duke@435: virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; } duke@435: virtual bool skip_operation() const; duke@435: virtual bool doit_prologue(); duke@435: virtual void doit(); acorn@4497: void set_csv_format(bool value) {_csv_format = value;} acorn@4497: void set_print_help(bool value) {_print_help = value;} acorn@4497: void set_print_class_stats(bool value) {_print_class_stats = value;} acorn@4497: void set_columns(const char* value) {_columns = value;} sla@5237: protected: sla@5237: bool collect(); duke@435: }; duke@435: mlarsson@7687: class VM_CollectForAllocation : public VM_GC_Operation { mlarsson@7687: protected: mlarsson@7687: size_t _word_size; // Size of object to be allocated (in number of words) mlarsson@7687: HeapWord* _result; // Allocation result (NULL if allocation failed) duke@435: mlarsson@7687: public: mlarsson@7688: VM_CollectForAllocation(size_t word_size, uint gc_count_before, GCCause::Cause cause); mlarsson@7687: mlarsson@7687: HeapWord* result() const { mlarsson@7687: return _result; mlarsson@7687: } mlarsson@7687: }; mlarsson@7687: mlarsson@7687: class VM_GenCollectForAllocation : public VM_CollectForAllocation { duke@435: private: duke@435: bool _tlab; // alloc is of a tlab. duke@435: public: mlarsson@7687: VM_GenCollectForAllocation(size_t word_size, duke@435: bool tlab, mlarsson@7686: uint gc_count_before) mlarsson@7687: : VM_CollectForAllocation(word_size, gc_count_before, GCCause::_allocation_failure), duke@435: _tlab(tlab) { mlarsson@7687: assert(word_size != 0, "An allocation should always be requested with this operation."); duke@435: } duke@435: ~VM_GenCollectForAllocation() {} duke@435: virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; } duke@435: virtual void doit(); duke@435: }; duke@435: duke@435: // VM operation to invoke a collection of the heap as a duke@435: // GenCollectedHeap heap. duke@435: class VM_GenCollectFull: public VM_GC_Operation { duke@435: private: duke@435: int _max_level; duke@435: public: mlarsson@7686: VM_GenCollectFull(uint gc_count_before, mlarsson@7686: uint full_gc_count_before, duke@435: GCCause::Cause gc_cause, kbarrett@9787: int max_level); duke@435: ~VM_GenCollectFull() {} duke@435: virtual VMOp_Type type() const { return VMOp_GenCollectFull; } duke@435: virtual void doit(); duke@435: }; apetrusenko@574: coleenp@4037: class VM_CollectForMetadataAllocation: public VM_GC_Operation { apetrusenko@574: private: coleenp@4037: MetaWord* _result; jmasa@4196: size_t _size; // size of object to be allocated coleenp@4037: Metaspace::MetadataType _mdtype; coleenp@4037: ClassLoaderData* _loader_data; apetrusenko@574: public: coleenp@4037: VM_CollectForMetadataAllocation(ClassLoaderData* loader_data, coleenp@4037: size_t size, Metaspace::MetadataType mdtype, mlarsson@7686: uint gc_count_before, mlarsson@7686: uint full_gc_count_before, mlarsson@7688: GCCause::Cause gc_cause); coleenp@4037: virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; } apetrusenko@574: virtual void doit(); coleenp@4037: MetaWord* result() const { return _result; } stefank@6992: stefank@6992: bool initiate_concurrent_GC(); apetrusenko@574: }; stefank@2314: kamg@2445: class SvcGCMarker : public StackObj { kamg@2445: private: kamg@2445: JvmtiGCMarker _jgcm; kamg@2445: public: kamg@2445: typedef enum { MINOR, FULL, OTHER } reason_type; kamg@2445: kamg@2445: SvcGCMarker(reason_type reason ) { kamg@2445: VM_GC_Operation::notify_gc_begin(reason == FULL); tonyp@2381: } tonyp@2381: kamg@2445: ~SvcGCMarker() { tonyp@2381: VM_GC_Operation::notify_gc_end(); tonyp@2381: } tonyp@2381: }; tonyp@2381: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP