1 /*
2 * Copyright (c) 2001, 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 *
768 // It's good to check this to make sure that the two methods are in sync.
769 assert(verify_ready_for_par_iteration(), "post-condition");
770 }
771
772 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs,
773 BitMap* region_bm, BitMap* card_bm) {
774 _other_regions.scrub(ctbs, region_bm, card_bm);
775 }
776
777 // Code roots support
778 //
779 // The code root set is protected by two separate locking schemes
780 // When at safepoint the per-hrrs lock must be held during modifications
781 // except when doing a full gc.
782 // When not at safepoint the CodeCache_lock must be held during modifications.
783 // When concurrent readers access the contains() function
784 // (during the evacuation phase) no removals are allowed.
785
786 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {
787 assert(nm != NULL, "sanity");
788 // Optimistic unlocked contains-check
789 if (!_code_roots.contains(nm)) {
790 MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag);
791 add_strong_code_root_locked(nm);
792 }
793 }
794
795 void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) {
796 assert(nm != NULL, "sanity");
797 _code_roots.add(nm);
798 }
799
800 void HeapRegionRemSet::remove_strong_code_root(nmethod* nm) {
801 assert(nm != NULL, "sanity");
802 assert_locked_or_safepoint(CodeCache_lock);
803
804 MutexLockerEx ml(CodeCache_lock->owned_by_self() ? NULL : &_m, Mutex::_no_safepoint_check_flag);
805 _code_roots.remove(nm);
806
807 // Check that there were no duplicates
808 guarantee(!_code_roots.contains(nm), "duplicate entry found");
809 }
810
811 void HeapRegionRemSet::strong_code_roots_do(CodeBlobClosure* blk) const {
812 _code_roots.nmethods_do(blk);
813 }
814
815 void HeapRegionRemSet::clean_strong_code_roots(HeapRegion* hr) {
816 _code_roots.clean(hr);
|
1 /*
2 * Copyright (c) 2001, 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 *
768 // It's good to check this to make sure that the two methods are in sync.
769 assert(verify_ready_for_par_iteration(), "post-condition");
770 }
771
772 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs,
773 BitMap* region_bm, BitMap* card_bm) {
774 _other_regions.scrub(ctbs, region_bm, card_bm);
775 }
776
777 // Code roots support
778 //
779 // The code root set is protected by two separate locking schemes
780 // When at safepoint the per-hrrs lock must be held during modifications
781 // except when doing a full gc.
782 // When not at safepoint the CodeCache_lock must be held during modifications.
783 // When concurrent readers access the contains() function
784 // (during the evacuation phase) no removals are allowed.
785
786 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {
787 assert(nm != NULL, "sanity");
788 assert((!CodeCache_lock->owned_by_self() || SafepointSynchronize::is_at_safepoint()),
789 "should call add_strong_code_root_locked instead");
790 // Optimistic unlocked contains-check
791 if (!_code_roots.contains(nm)) {
792 MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag);
793 add_strong_code_root_locked(nm);
794 }
795 }
796
797 void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) {
798 assert(nm != NULL, "sanity");
799 assert((CodeCache_lock->owned_by_self() ||
800 (SafepointSynchronize::is_at_safepoint() &&
801 (_m.owned_by_self() || Thread::current()->is_VM_thread()))),
802 "not safely locked");
803 _code_roots.add(nm);
804 }
805
806 void HeapRegionRemSet::remove_strong_code_root(nmethod* nm) {
807 assert(nm != NULL, "sanity");
808 assert_locked_or_safepoint(CodeCache_lock);
809
810 MutexLockerEx ml(CodeCache_lock->owned_by_self() ? NULL : &_m, Mutex::_no_safepoint_check_flag);
811 _code_roots.remove(nm);
812
813 // Check that there were no duplicates
814 guarantee(!_code_roots.contains(nm), "duplicate entry found");
815 }
816
817 void HeapRegionRemSet::strong_code_roots_do(CodeBlobClosure* blk) const {
818 _code_roots.nmethods_do(blk);
819 }
820
821 void HeapRegionRemSet::clean_strong_code_roots(HeapRegion* hr) {
822 _code_roots.clean(hr);
|