1 /* 2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 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 #include "gc/shared/collectedHeap.hpp" 25 #include "gc/epsilon/epsilonCollectorPolicy.hpp" 26 #include "gc/epsilon/epsilonBarrierSet.hpp" 27 #include "gc/epsilon/epsilon_globals.hpp" 28 29 class EpsilonCollectedHeap : public CollectedHeap { 30 private: 31 EpsilonCollectorPolicy* _policy; 32 HeapWord* _start; 33 HeapWord* _end; 34 volatile HeapWord* _current; 35 public: 36 EpsilonCollectedHeap(EpsilonCollectorPolicy* p) : _policy(p) {}; 37 38 virtual Name kind() const { 39 return CollectedHeap::EpsilonCollectedHeap; 40 } 41 42 virtual const char *name() const { 43 return "Epsilon GC"; 44 } 45 46 virtual jint initialize(); 47 48 virtual void post_initialize() {} 49 50 virtual size_t capacity() const { return pointer_delta(_end, _start); } 51 virtual size_t used() const { return pointer_delta((HeapWord*)_current, _start); } 52 virtual size_t max_capacity() const { return capacity(); } 53 54 virtual bool is_maximal_no_gc() const { return used() == capacity(); } // TODO: Really? 55 56 virtual bool is_in(const void *p) const { return (_start <= p) && (p < _end); } 57 58 virtual bool is_scavengable(const void *p) { return true; } // TODO: Why? 59 60 virtual HeapWord* mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded); 61 virtual HeapWord* allocate_new_tlab(size_t size); 62 63 virtual HeapWord* allocate_work(size_t size); 64 65 // TLAB allocations 66 virtual bool supports_tlab_allocation() const { return UseTLAB; } 67 virtual size_t tlab_capacity(Thread *thr) const { return capacity(); } 68 virtual size_t tlab_used(Thread *thr) const { return used(); } // TODO: Should probably record the TLAB? 69 virtual size_t unsafe_max_tlab_alloc(Thread *thr) const { 70 // TODO: hook up in TLAB policy better. 71 return EpsilonTLABSize; 72 } 73 74 virtual bool can_elide_tlab_store_barriers() const { 75 return true; // TODO: Really? 76 } 77 78 virtual bool can_elide_initializing_store_barrier(oop new_obj) { 79 return true; // TODO: Really? 80 } 81 82 virtual bool card_mark_must_follow_store() const { 83 return false; // TODO: Really? 84 } 85 86 virtual void collect(GCCause::Cause cause); 87 virtual void do_full_collection(bool clear_all_soft_refs); 88 89 virtual AdaptiveSizePolicy *size_policy() { 90 // No such thing for Epsilon 91 return NULL; 92 } 93 94 virtual CollectorPolicy *collector_policy() const { 95 return _policy; 96 } 97 98 virtual void object_iterate(ObjectClosure *cl) { 99 safe_object_iterate(cl); 100 } 101 102 virtual void safe_object_iterate(ObjectClosure *cl); 103 104 virtual HeapWord *block_start(const void *addr) const { 105 Unimplemented(); 106 return NULL; 107 } 108 109 virtual size_t block_size(const HeapWord *addr) const { 110 Unimplemented(); 111 return 0; 112 } 113 114 virtual bool block_is_obj(const HeapWord *addr) const { 115 Unimplemented(); 116 return false; 117 } 118 119 virtual jlong millis_since_last_gc() { 120 return os::elapsed_counter() / NANOSECS_PER_MILLISEC; // since the VM start 121 } 122 123 virtual void prepare_for_verify() { 124 // No heap verification. 125 } 126 127 virtual void print_on(outputStream *st) const { 128 // Print nothing. 129 } 130 131 virtual void print_gc_threads_on(outputStream *st) const { 132 // No GC threads. 133 } 134 135 virtual void gc_threads_do(ThreadClosure *tc) const { 136 // No GC threads. 137 } 138 139 virtual void print_tracing_info() const { 140 Log(gc) log; 141 size_t allocated_kb = pointer_delta((HeapWord*)_current, _start) * HeapWordSize / K; 142 log.info("Total allocated: " SIZE_FORMAT " KB.", 143 allocated_kb); 144 log.info("Average allocation rate: " SIZE_FORMAT " KB/sec", 145 allocated_kb * NANOSECS_PER_SEC / os::elapsed_counter()); 146 } 147 148 virtual void verify(VerifyOption option) { 149 // No heap verification for Epsilon. 150 } 151 152 };