1 /* 2 * Copyright (c) 2015, 2017, 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/zMarkTerminate.hpp" 29 #include "oops/oopsHierarchy.hpp" 30 #include "utilities/globalDefinitions.hpp" 31 32 class Thread; 33 class ZMarkCache; 34 class ZPageTable; 35 class ZWorkers; 36 37 class ZMark { 38 friend class ZMarkRootsTask; 39 friend class ZMarkTask; 40 friend class ZMarkTryCompleteTask; 41 42 private: 43 ZWorkers* const _workers; 44 ZPageTable* const _pagetable; 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 void prepare_mark(); 59 60 bool is_array(uintptr_t addr) const; 61 void push_partial_array(uintptr_t addr, size_t size, bool finalizable); 62 void follow_small_array(uintptr_t addr, size_t size, bool finalizable); 63 void follow_large_array(uintptr_t addr, size_t size, bool finalizable); 64 void follow_array(uintptr_t addr, size_t size, bool finalizable); 65 void follow_partial_array(ZMarkStackEntry entry, bool finalizable); 66 void follow_array_object(objArrayOop obj, bool finalizable); 67 void follow_object(oop obj, bool finalizable); 68 bool try_mark_object(ZMarkCache* cache, uintptr_t addr, bool finalizable); 69 void mark_and_follow(ZMarkCache* cache, ZMarkStackEntry entry); 70 71 template <typename T> bool drain(ZMarkStripe* stripe, 72 ZMarkThreadLocalStacks* stacks, 73 ZMarkCache* cache, 74 T* timeout); 75 template <typename T> bool drain_and_flush(ZMarkStripe* stripe, 76 ZMarkThreadLocalStacks* stacks, 77 ZMarkCache* cache, 78 T* timeout); 79 bool try_steal(ZMarkStripe* stripe, ZMarkThreadLocalStacks* stacks); 80 void idle() const; 81 bool flush(bool at_safepoint); 82 bool try_proactive_flush(); 83 bool try_flush(volatile size_t* nflush); 84 bool try_terminate(); 85 bool try_complete(); 86 bool try_end(); 87 88 void prepare_work(); 89 void finish_work(); 90 91 void work_without_timeout(ZMarkCache* cache, 92 ZMarkStripe* stripe, 93 ZMarkThreadLocalStacks* stacks); 94 void work_with_timeout(ZMarkCache* cache, 95 ZMarkStripe* stripe, 96 ZMarkThreadLocalStacks* stacks, 97 uint64_t timeout_in_millis); 98 void work(uint64_t timeout_in_millis); 99 100 void verify_all_stacks_empty() const; 101 102 public: 103 ZMark(ZWorkers* workers, ZPageTable* pagetable); 104 105 template <bool finalizable, bool publish> void mark_object(uintptr_t addr); 106 107 void start(); 108 void mark(); 109 bool end(); 110 111 void flush_and_free(); 112 bool flush_and_free(Thread* thread); 113 }; 114 115 #endif // SHARE_GC_Z_ZMARK_HPP