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