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 virtual HeapWord* allocate_work(size_t size); 63 64 // TLAB allocations 65 virtual bool supports_tlab_allocation() const { return true; } 66 virtual size_t tlab_capacity(Thread *thr) const { return capacity(); } 67 virtual size_t tlab_used(Thread *thr) const { return used(); } // TODO: Should probably record the TLAB? 68 virtual size_t unsafe_max_tlab_alloc(Thread *thr) const { 69 // TODO: hook up in TLAB policy better. pointer_delta(_current, _end); 70 return HeapWordSize * 128 * K; 71 } 72 73 virtual bool can_elide_tlab_store_barriers() const { 74 return true; // TODO: Really? 75 } 76 77 virtual bool can_elide_initializing_store_barrier(oop new_obj) { 78 return true; // TODO: Really? 79 } 80 81 virtual bool card_mark_must_follow_store() const { 82 return true; // TODO: Really? 83 } 84 85 virtual void collect(GCCause::Cause cause); 86 virtual void do_full_collection(bool clear_all_soft_refs); 87 88 virtual AdaptiveSizePolicy *size_policy() { 89 // No such thing for Epsilon 90 return NULL; 91 } 92 93 virtual CollectorPolicy *collector_policy() const { 94 return _policy; 95 } 96 97 virtual void object_iterate(ObjectClosure *cl) { 98 safe_object_iterate(cl); 99 } 100 101 virtual void safe_object_iterate(ObjectClosure *cl); 102 103 virtual HeapWord *block_start(const void *addr) const { 104 Unimplemented(); 105 return NULL; 106 } 107 108 virtual size_t block_size(const HeapWord *addr) const { 109 Unimplemented(); 110 return 0; 111 } 112 113 virtual bool block_is_obj(const HeapWord *addr) const { 114 Unimplemented(); 115 return false; 116 } 117 118 virtual jlong millis_since_last_gc() { 119 return os::elapsed_counter() / NANOSECS_PER_MILLISEC; // since the VM start 120 } 121 122 virtual void prepare_for_verify() { 123 // No heap verification. 124 } 125 126 virtual void print_on(outputStream *st) const { 127 // Print nothing. 128 } 129 130 virtual void print_gc_threads_on(outputStream *st) const { 131 // No GC threads. 132 } 133 134 virtual void gc_threads_do(ThreadClosure *tc) const { 135 // No GC threads. 136 } 137 138 virtual void print_tracing_info() const { 139 Log(gc) log; 140 size_t allocated_kb = pointer_delta((HeapWord*)_current, _start) * HeapWordSize / K; 141 log.info("Total allocated: " SIZE_FORMAT " KB.", 142 allocated_kb); 143 log.info("Average allocation rate: " SIZE_FORMAT " KB/sec", 144 allocated_kb * NANOSECS_PER_SEC / os::elapsed_counter()); 145 } 146 147 virtual void verify(VerifyOption option) { 148 // No heap verification for Epsilon. 149 } 150 151 };