1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/classLoader.hpp" 27 #include "classfile/javaClasses.hpp" 28 #include "gc/shared/allocTracer.hpp" 29 #include "gc/shared/gcId.hpp" 30 #include "gc/shared/gcLocker.inline.hpp" 31 #include "gc/shared/genCollectedHeap.hpp" 32 #include "gc/shared/vmGCOperations.hpp" 33 #include "memory/oopFactory.hpp" 34 #include "logging/log.hpp" 35 #include "oops/instanceKlass.hpp" 36 #include "oops/instanceRefKlass.hpp" 37 #include "runtime/handles.inline.hpp" 38 #include "runtime/init.hpp" 39 #include "runtime/interfaceSupport.hpp" 40 #include "utilities/dtrace.hpp" 41 #include "utilities/macros.hpp" 42 #include "utilities/preserveException.hpp" 43 #if INCLUDE_ALL_GCS 44 #include "gc/g1/g1CollectedHeap.inline.hpp" 45 #endif // INCLUDE_ALL_GCS 46 47 VM_GC_Operation::~VM_GC_Operation() { 48 CollectedHeap* ch = Universe::heap(); 49 ch->collector_policy()->set_all_soft_refs_clear(false); 50 } 51 52 // The same dtrace probe can't be inserted in two different files, so we 53 // have to call it here, so it's only in one file. Can't create new probes 54 // for the other file anymore. The dtrace probes have to remain stable. 55 void VM_GC_Operation::notify_gc_begin(bool full) { 56 HOTSPOT_GC_BEGIN( 57 full); 58 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); 59 } 60 61 void VM_GC_Operation::notify_gc_end() { 62 HOTSPOT_GC_END(); 63 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); 64 } 65 66 void VM_GC_Operation::acquire_pending_list_lock() { 67 // we may enter this with pending exception set 68 InstanceRefKlass::acquire_pending_list_lock(&_pending_list_basic_lock); 69 } 70 71 72 void VM_GC_Operation::release_and_notify_pending_list_lock() { 73 74 InstanceRefKlass::release_and_notify_pending_list_lock(&_pending_list_basic_lock); 75 } 76 77 // Allocations may fail in several threads at about the same time, 78 // resulting in multiple gc requests. We only want to do one of them. 79 // In case a GC locker is active and the need for a GC is already signaled, 80 // we want to skip this GC attempt altogether, without doing a futile 81 // safepoint operation. 82 bool VM_GC_Operation::skip_operation() const { 83 bool skip = (_gc_count_before != Universe::heap()->total_collections()); 84 if (_full && skip) { 85 skip = (_full_gc_count_before != Universe::heap()->total_full_collections()); 86 } 87 if (!skip && GCLocker::is_active_and_needs_gc()) { 88 skip = Universe::heap()->is_maximal_no_gc(); 89 assert(!(skip && (_gc_cause == GCCause::_gc_locker)), 90 "GCLocker cannot be active when initiating GC"); 91 } 92 return skip; 93 } 94 | 1 /* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/classLoader.hpp" 27 #include "classfile/javaClasses.hpp" 28 #include "gc/shared/allocTracer.hpp" 29 #include "gc/shared/gcId.hpp" 30 #include "gc/shared/gcLocker.inline.hpp" 31 #include "gc/shared/genCollectedHeap.hpp" 32 #include "gc/shared/vmGCOperations.hpp" 33 #include "logging/log.hpp" 34 #include "memory/oopFactory.hpp" 35 #include "runtime/handles.inline.hpp" 36 #include "runtime/init.hpp" 37 #include "runtime/interfaceSupport.hpp" 38 #include "utilities/dtrace.hpp" 39 #include "utilities/macros.hpp" 40 #include "utilities/preserveException.hpp" 41 #if INCLUDE_ALL_GCS 42 #include "gc/g1/g1CollectedHeap.inline.hpp" 43 #endif // INCLUDE_ALL_GCS 44 45 VM_GC_Operation::~VM_GC_Operation() { 46 CollectedHeap* ch = Universe::heap(); 47 ch->collector_policy()->set_all_soft_refs_clear(false); 48 } 49 50 // The same dtrace probe can't be inserted in two different files, so we 51 // have to call it here, so it's only in one file. Can't create new probes 52 // for the other file anymore. The dtrace probes have to remain stable. 53 void VM_GC_Operation::notify_gc_begin(bool full) { 54 HOTSPOT_GC_BEGIN( 55 full); 56 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); 57 } 58 59 void VM_GC_Operation::notify_gc_end() { 60 HOTSPOT_GC_END(); 61 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); 62 } 63 64 void VM_GC_Operation::acquire_pending_list_lock() { 65 _pending_list_locker.lock(); 66 } 67 68 void VM_GC_Operation::release_and_notify_pending_list_lock() { 69 _pending_list_locker.unlock(); 70 } 71 72 // Allocations may fail in several threads at about the same time, 73 // resulting in multiple gc requests. We only want to do one of them. 74 // In case a GC locker is active and the need for a GC is already signaled, 75 // we want to skip this GC attempt altogether, without doing a futile 76 // safepoint operation. 77 bool VM_GC_Operation::skip_operation() const { 78 bool skip = (_gc_count_before != Universe::heap()->total_collections()); 79 if (_full && skip) { 80 skip = (_full_gc_count_before != Universe::heap()->total_full_collections()); 81 } 82 if (!skip && GCLocker::is_active_and_needs_gc()) { 83 skip = Universe::heap()->is_maximal_no_gc(); 84 assert(!(skip && (_gc_cause == GCCause::_gc_locker)), 85 "GCLocker cannot be active when initiating GC"); 86 } 87 return skip; 88 } 89 |