| 1 | /* |
| 2 | * Copyright (c) 2015, 2019, 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 | #ifndef SHARE_GC_Z_ZREFERENCEPROCESSOR_HPP |
| 25 | #define SHARE_GC_Z_ZREFERENCEPROCESSOR_HPP |
| 26 | |
| 27 | #include "gc/shared/referenceDiscoverer.hpp" |
| 28 | #include "gc/z/zValue.hpp" |
| 29 | |
| 30 | class ReferencePolicy; |
| 31 | class ZWorkers; |
| 32 | |
| 33 | class ZReferenceProcessor : public ReferenceDiscoverer { |
| 34 | friend class ZReferenceProcessorTask; |
| 35 | |
| 36 | private: |
| 37 | static const size_t reference_type_count = REF_PHANTOM + 1; |
| 38 | typedef size_t Counters[reference_type_count]; |
| 39 | |
| 40 | ZWorkers* const _workers; |
| 41 | ReferencePolicy* _soft_reference_policy; |
| 42 | ZPerWorker<Counters> _encountered_count; |
| 43 | ZPerWorker<Counters> _discovered_count; |
| 44 | ZPerWorker<Counters> _enqueued_count; |
| 45 | ZPerWorker<oop> _discovered_list; |
| 46 | ZContended<oop> _pending_list; |
| 47 | oop* _pending_list_tail; |
| 48 | |
| 49 | bool is_inactive(oop reference, oop referent, ReferenceType type) const; |
| 50 | bool is_strongly_live(oop referent) const; |
| 51 | bool is_softly_live(oop reference, ReferenceType type) const; |
| 52 | |
| 53 | bool should_discover(oop reference, ReferenceType type) const; |
| 54 | bool should_drop(oop reference, ReferenceType type) const; |
| 55 | void keep_alive(oop reference, ReferenceType type) const; |
| 56 | void make_inactive(oop reference, ReferenceType type) const; |
| 57 | |
| 58 | void discover(oop reference, ReferenceType type); |
| 59 | |
| 60 | oop drop(oop reference, ReferenceType type); |
| 61 | oop* keep(oop reference, ReferenceType type); |
| 62 | |
| 63 | bool is_empty() const; |
| 64 | |
| 65 | void work(); |
| 66 | void collect_statistics(); |
| 67 | |
| 68 | public: |
| 69 | ZReferenceProcessor(ZWorkers* workers); |
| 70 | |
| 71 | void set_soft_reference_policy(bool clear); |
| 72 | void reset_statistics(); |
| 73 | |
| 74 | virtual bool discover_reference(oop reference, ReferenceType type); |
| 75 | void process_references(); |
| 76 | void enqueue_references(); |
| 77 | }; |
| 78 | |
| 79 | #endif // SHARE_GC_Z_ZREFERENCEPROCESSOR_HPP |
| 80 | |