1 /* 2 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #ifndef SHARE_GC_EPSILON_EPSILONHEAP_HPP 25 #define SHARE_GC_EPSILON_EPSILONHEAP_HPP 26 27 #include "gc/shared/collectedHeap.hpp" 28 #include "gc/shared/softRefPolicy.hpp" 29 #include "gc/shared/space.hpp" 30 #include "services/memoryManager.hpp" 31 #include "gc/epsilon/epsilonCollectorPolicy.hpp" 32 #include "gc/epsilon/epsilonMonitoringSupport.hpp" 33 #include "gc/epsilon/epsilonBarrierSet.hpp" 34 #include "gc/epsilon/epsilon_globals.hpp" 35 36 class EpsilonHeap : public CollectedHeap { 37 friend class VMStructs; 38 private: 39 EpsilonCollectorPolicy* _policy; 40 SoftRefPolicy _soft_ref_policy; 41 EpsilonMonitoringSupport* _monitoring_support; 42 MemoryPool* _pool; 43 GCMemoryManager _memory_manager; 44 ContiguousSpace* _space; 45 VirtualSpace _virtual_space; 46 size_t _max_tlab_size; 47 size_t _step_counter_update; 48 size_t _step_heap_print; 49 int64_t _decay_time_ns; 50 volatile size_t _last_counter_update; 51 volatile size_t _last_heap_print; 52 53 public: 54 static EpsilonHeap* heap(); 55 56 EpsilonHeap(EpsilonCollectorPolicy* p) : 57 _policy(p), 58 _memory_manager("Epsilon Heap", "") {}; 59 60 virtual Name kind() const { 61 return CollectedHeap::Epsilon; 62 } 63 64 virtual const char* name() const { 65 return "Epsilon"; 66 } 67 68 virtual CollectorPolicy* collector_policy() const { 69 return _policy; 70 } 71 72 virtual SoftRefPolicy* soft_ref_policy() { 73 return &_soft_ref_policy; 74 } 75 76 virtual jint initialize(); 77 virtual void post_initialize(); 78 virtual void initialize_serviceability(); 79 80 virtual GrowableArray<GCMemoryManager*> memory_managers(); 81 virtual GrowableArray<MemoryPool*> memory_pools(); 82 83 virtual size_t max_capacity() const { return _virtual_space.reserved_size(); } 84 virtual size_t capacity() const { return _virtual_space.committed_size(); } 85 virtual size_t used() const { return _space->used(); } 86 87 virtual bool is_in(const void* p) const { 88 return _space->is_in(p); 89 } 90 91 virtual bool is_scavengable(oop obj) { 92 // No GC is going to happen, therefore no objects ever move. 93 return false; 94 } 95 96 virtual bool is_maximal_no_gc() const { 97 // No GC is going to happen. Return "we are at max", when we are about to fail. 98 return used() == capacity(); 99 } 100 101 // Allocation 102 HeapWord* allocate_work(size_t size); 103 virtual HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded); 104 virtual HeapWord* allocate_new_tlab(size_t min_size, 105 size_t requested_size, 106 size_t* actual_size); 107 108 // TLAB allocation 109 virtual bool supports_tlab_allocation() const { return true; } 110 virtual size_t tlab_capacity(Thread* thr) const { return capacity(); } 111 virtual size_t tlab_used(Thread* thr) const { return used(); } 112 virtual size_t max_tlab_size() const { return _max_tlab_size; } 113 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const; 114 115 virtual void collect(GCCause::Cause cause); 116 virtual void do_full_collection(bool clear_all_soft_refs); 117 118 // Heap walking support 119 virtual void safe_object_iterate(ObjectClosure* cl); 120 virtual void object_iterate(ObjectClosure* cl) { 121 safe_object_iterate(cl); 122 } 123 124 // Object pinning support: every object is implicitly pinned 125 virtual bool supports_object_pinning() const { return true; } 126 virtual oop pin_object(JavaThread* thread, oop obj) { return obj; } 127 virtual void unpin_object(JavaThread* thread, oop obj) { } 128 129 // No support for block parsing. 130 virtual HeapWord* block_start(const void* addr) const { return NULL; } 131 virtual size_t block_size(const HeapWord* addr) const { return 0; } 132 virtual bool block_is_obj(const HeapWord* addr) const { return false; } 133 134 // No GC threads 135 virtual void print_gc_threads_on(outputStream* st) const {} 136 virtual void gc_threads_do(ThreadClosure* tc) const {} 137 138 // No heap verification 139 virtual void prepare_for_verify() {} 140 virtual void verify(VerifyOption option) {} 141 142 virtual jlong millis_since_last_gc() { 143 // Report time since the VM start 144 return os::elapsed_counter() / NANOSECS_PER_MILLISEC; 145 } 146 147 virtual void print_on(outputStream* st) const; 148 virtual void print_tracing_info() const; 149 150 private: 151 void print_heap_info(size_t used) const; 152 void print_metaspace_info() const; 153 154 }; 155 156 #endif // SHARE_GC_EPSILON_EPSILONHEAP_HPP