1 /* 2 * Copyright (c) 2015, 2020, 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_ZMARK_HPP 25 #define SHARE_GC_Z_ZMARK_HPP 26 27 #include "gc/z/zMarkStack.hpp" 28 #include "gc/z/zMarkStackAllocator.hpp" 29 #include "gc/z/zMarkStackEntry.hpp" 30 #include "gc/z/zMarkTerminate.hpp" 31 #include "oops/oopsHierarchy.hpp" 32 #include "utilities/globalDefinitions.hpp" 33 34 class Thread; 35 class ZMarkCache; 36 class ZPageTable; 37 class ZWorkers; 38 39 class ZMark { 40 friend class ZMarkTask; 41 42 private: 43 ZWorkers* const _workers; 44 ZPageTable* const _page_table; 45 ZMarkStackAllocator _allocator; 46 ZMarkStripeSet _stripes; 47 ZMarkTerminate _terminate; 48 volatile bool _work_terminateflush; 49 volatile size_t _work_nproactiveflush; 50 volatile size_t _work_nterminateflush; 51 size_t _nproactiveflush; 52 size_t _nterminateflush; 53 size_t _ntrycomplete; 54 size_t _ncontinue; 55 uint _nworkers; 56 57 size_t calculate_nstripes(uint nworkers) const; 58 59 bool is_array(uintptr_t addr) const; 60 void push_partial_array(uintptr_t addr, size_t size, bool finalizable); 61 void follow_small_array(uintptr_t addr, size_t size, bool finalizable); 62 void follow_large_array(uintptr_t addr, size_t size, bool finalizable); 63 void follow_array(uintptr_t addr, size_t size, bool finalizable); 64 void follow_partial_array(ZMarkStackEntry entry, bool finalizable); 65 void follow_array_object(objArrayOop obj, bool finalizable); 66 void follow_object(oop obj, bool finalizable); 67 bool try_mark_object(ZMarkCache* cache, uintptr_t addr, bool finalizable); 68 void mark_and_follow(ZMarkCache* cache, ZMarkStackEntry entry); 69 70 template <typename T> bool drain(ZMarkStripe* stripe, 71 ZMarkThreadLocalStacks* stacks, 72 ZMarkCache* cache, 73 T* timeout); 74 template <typename T> bool drain_and_flush(ZMarkStripe* stripe, 75 ZMarkThreadLocalStacks* stacks, 76 ZMarkCache* cache, 77 T* timeout); 78 bool try_steal(ZMarkStripe* stripe, ZMarkThreadLocalStacks* stacks); 79 void idle() const; 80 bool flush(bool at_safepoint); 81 bool try_proactive_flush(); 82 bool try_flush(volatile size_t* nflush); 83 bool try_terminate(); 84 bool try_complete(); 85 bool try_end(); 86 87 void prepare_work(); 88 void finish_work(); 89 90 void work_without_timeout(ZMarkCache* cache, 91 ZMarkStripe* stripe, 92 ZMarkThreadLocalStacks* stacks); 93 void work_with_timeout(ZMarkCache* cache, 94 ZMarkStripe* stripe, 95 ZMarkThreadLocalStacks* stacks, 96 uint64_t timeout_in_micros); 97 void work(uint64_t timeout_in_micros); 98 99 void verify_all_stacks_empty() const; 100 101 public: 102 ZMark(ZWorkers* workers, ZPageTable* page_table); 103 104 bool is_initialized() const; 105 106 template <bool follow, bool finalizable, bool publish> void mark_object(uintptr_t addr); 107 108 void start(); 109 void mark(bool initial); 110 bool end(); 111 112 void flush_and_free(); 113 bool flush_and_free(Thread* thread); 114 }; 115 116 #endif // SHARE_GC_Z_ZMARK_HPP 117