diff --git a/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp b/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp index c18be66a4a5eb05303633f4dccc3414d11820a7f..32f8269aed8338cb9122e246a0ab2d4e3d351fcd 100644 --- a/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp +++ b/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp @@ -38,7 +38,7 @@ VM_G1CollectForAllocation::VM_G1CollectForAllocation(uint gc_count_before, size_t word_size) : VM_G1OperationWithAllocRequest(gc_count_before, word_size, GCCause::_allocation_failure) { - guarantee(word_size > 0, "an allocation should always be requested"); + guarantee(word_size != 0, "An allocation should always be requested with this operation."); } void VM_G1CollectForAllocation::doit() { @@ -73,7 +73,7 @@ VM_G1IncCollectionPause::VM_G1IncCollectionPause(uint gc_count_before, } bool VM_G1IncCollectionPause::doit_prologue() { - bool res = VM_GC_Operation::doit_prologue(); + bool res = VM_G1OperationWithAllocRequest::doit_prologue(); if (!res) { if (_should_initiate_conc_mark) { // The prologue can fail for a couple of reasons. The first is that another GC @@ -167,7 +167,7 @@ void VM_G1IncCollectionPause::doit() { } void VM_G1IncCollectionPause::doit_epilogue() { - VM_GC_Operation::doit_epilogue(); + VM_G1OperationWithAllocRequest::doit_epilogue(); // If the pause was initiated by a System.gc() and // +ExplicitGCInvokesConcurrent, we have to wait here for the cycle diff --git a/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp b/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp index 9a22fe49accc17829e5789df52c47c63160a423c..265eb37d36f6e5320aa0bc790c00afc796d677f0 100644 --- a/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp +++ b/src/share/vm/gc_implementation/g1/vm_operations_g1.hpp @@ -36,10 +36,8 @@ // - VM_G1CollectForAllocation // - VM_G1IncCollectionPause -class VM_G1OperationWithAllocRequest: public VM_GC_Operation { +class VM_G1OperationWithAllocRequest : public VM_CollectForAllocation { protected: - size_t _word_size; - HeapWord* _result; bool _pause_succeeded; AllocationContext_t _allocation_context; @@ -47,9 +45,8 @@ public: VM_G1OperationWithAllocRequest(uint gc_count_before, size_t word_size, GCCause::Cause gc_cause) - : VM_GC_Operation(gc_count_before, gc_cause), - _word_size(word_size), _result(NULL), _pause_succeeded(false) { } - HeapWord* result() { return _result; } + : VM_CollectForAllocation(word_size, gc_count_before, gc_cause), + _pause_succeeded(false) {} bool pause_succeeded() { return _pause_succeeded; } void set_allocation_context(AllocationContext_t context) { _allocation_context = context; } AllocationContext_t allocation_context() { return _allocation_context; } diff --git a/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp b/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp index 10f8dceb57d43c1a35ccce313d54cd1cb85d1915..9148bb4ffc05b414e42aff62acef75eb16f753f2 100644 --- a/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp +++ b/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.cpp @@ -32,12 +32,10 @@ #include "utilities/dtrace.hpp" // The following methods are used by the parallel scavenge collector -VM_ParallelGCFailedAllocation::VM_ParallelGCFailedAllocation(size_t size, +VM_ParallelGCFailedAllocation::VM_ParallelGCFailedAllocation(size_t word_size, uint gc_count) : - VM_GC_Operation(gc_count, GCCause::_allocation_failure), - _size(size), - _result(NULL) -{ + VM_CollectForAllocation(word_size, gc_count, GCCause::_allocation_failure) { + assert(word_size != 0, "An allocation should always be requested with this operation."); } void VM_ParallelGCFailedAllocation::doit() { @@ -47,7 +45,7 @@ void VM_ParallelGCFailedAllocation::doit() { assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "must be a ParallelScavengeHeap"); GCCauseSetter gccs(heap, _gc_cause); - _result = heap->failed_mem_allocate(_size); + _result = heap->failed_mem_allocate(_word_size); if (_result == NULL && GC_locker::is_active_and_needs_gc()) { set_gc_locked(); diff --git a/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.hpp b/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.hpp index 20111e481ce7d905be00a8a119c7b8a4c1ac8e60..7ffe251618a7435f89d16cf9fdf38a8dc3f221d3 100644 --- a/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.hpp +++ b/src/share/vm/gc_implementation/parallelScavenge/vmPSOperations.hpp @@ -29,20 +29,14 @@ #include "gc_implementation/shared/vmGCOperations.hpp" #include "gc_interface/gcCause.hpp" -class VM_ParallelGCFailedAllocation: public VM_GC_Operation { - private: - size_t _size; - HeapWord* _result; - +class VM_ParallelGCFailedAllocation : public VM_CollectForAllocation { public: - VM_ParallelGCFailedAllocation(size_t size, uint gc_count); + VM_ParallelGCFailedAllocation(size_t word_size, uint gc_count); virtual VMOp_Type type() const { return VMOp_ParallelGCFailedAllocation; } virtual void doit(); - - HeapWord* result() const { return _result; } }; class VM_ParallelGCSystemGC: public VM_GC_Operation { diff --git a/src/share/vm/gc_implementation/shared/vmGCOperations.cpp b/src/share/vm/gc_implementation/shared/vmGCOperations.cpp index ea1760e5393ae9c2b1a363e5192d545d9bea32e4..80362c3174c7d4fc20437e46b13bd4e3ae1890c8 100644 --- a/src/share/vm/gc_implementation/shared/vmGCOperations.cpp +++ b/src/share/vm/gc_implementation/shared/vmGCOperations.cpp @@ -193,10 +193,10 @@ void VM_GenCollectForAllocation::doit() { GenCollectedHeap* gch = GenCollectedHeap::heap(); GCCauseSetter gccs(gch, _gc_cause); - _res = gch->satisfy_failed_allocation(_size, _tlab); - assert(gch->is_in_reserved_or_null(_res), "result not in heap"); + _result = gch->satisfy_failed_allocation(_word_size, _tlab); + assert(gch->is_in_reserved_or_null(_result), "result not in heap"); - if (_res == NULL && GC_locker::is_active_and_needs_gc()) { + if (_result == NULL && GC_locker::is_active_and_needs_gc()) { set_gc_locked(); } } diff --git a/src/share/vm/gc_implementation/shared/vmGCOperations.hpp b/src/share/vm/gc_implementation/shared/vmGCOperations.hpp index 06b109ac478121bbf95eea6cdc7009725d5d775f..0c2ca8018a88ee4a107541bf8282424a826d6d29 100644 --- a/src/share/vm/gc_implementation/shared/vmGCOperations.hpp +++ b/src/share/vm/gc_implementation/shared/vmGCOperations.hpp @@ -38,11 +38,12 @@ // VM_Operation // VM_GC_Operation // VM_GC_HeapInspection -// VM_GenCollectForAllocation // VM_GenCollectFull // VM_GenCollectFullConcurrent -// VM_ParallelGCFailedAllocation // VM_ParallelGCSystemGC +// VM_CollectForAllocation +// VM_GenCollectForAllocation +// VM_ParallelGCFailedAllocation // VM_GC_Operation // - implements methods common to all classes in the hierarchy: // prevents multiple gc requests and manages lock on heap; @@ -51,6 +52,7 @@ // - prints class histogram on SIGBREAK if PrintClassHistogram // is specified; and also the attach "inspectheap" operation // +// VM_CollectForAllocation // VM_GenCollectForAllocation // VM_ParallelGCFailedAllocation // - this operation is invoked when allocation is failed; @@ -160,25 +162,34 @@ class VM_GC_HeapInspection: public VM_GC_Operation { bool collect(); }; +class VM_CollectForAllocation : public VM_GC_Operation { + protected: + size_t _word_size; // Size of object to be allocated (in number of words) + HeapWord* _result; // Allocation result (NULL if allocation failed) + + public: + VM_CollectForAllocation(size_t word_size, uint gc_count_before, GCCause::Cause cause) + : VM_GC_Operation(gc_count_before, cause), _result(NULL), _word_size(word_size) {} + + HeapWord* result() const { + return _result; + } +}; -class VM_GenCollectForAllocation: public VM_GC_Operation { +class VM_GenCollectForAllocation : public VM_CollectForAllocation { private: - HeapWord* _res; - size_t _size; // size of object to be allocated. bool _tlab; // alloc is of a tlab. public: - VM_GenCollectForAllocation(size_t size, + VM_GenCollectForAllocation(size_t word_size, bool tlab, uint gc_count_before) - : VM_GC_Operation(gc_count_before, GCCause::_allocation_failure), - _size(size), + : VM_CollectForAllocation(word_size, gc_count_before, GCCause::_allocation_failure), _tlab(tlab) { - _res = NULL; + assert(word_size != 0, "An allocation should always be requested with this operation."); } ~VM_GenCollectForAllocation() {} virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; } virtual void doit(); - HeapWord* result() const { return _res; } }; // VM operation to invoke a collection of the heap as a