/* * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "gc/shared/collectedHeap.hpp" #include "gc/epsilon/epsilonCollectorPolicy.hpp" #include "gc/epsilon/epsilonBarrierSet.hpp" #include "gc/epsilon/epsilon_globals.hpp" class EpsilonCollectedHeap : public CollectedHeap { private: EpsilonCollectorPolicy* _policy; HeapWord* _start; HeapWord* _end; volatile HeapWord* _current; public: EpsilonCollectedHeap(EpsilonCollectorPolicy* p) : _policy(p) {}; virtual Name kind() const { return CollectedHeap::EpsilonCollectedHeap; } virtual const char *name() const { return "Epsilon GC"; } virtual jint initialize(); virtual void post_initialize() {} virtual size_t capacity() const { return pointer_delta(_end, _start); } virtual size_t used() const { return pointer_delta((HeapWord*)_current, _start); } virtual size_t max_capacity() const { return capacity(); } virtual bool is_maximal_no_gc() const { return used() == capacity(); } // TODO: Really? virtual bool is_in(const void *p) const { return (_start <= p) && (p < _end); } virtual bool is_scavengable(const void *p) { return true; } // TODO: Why? virtual HeapWord* mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded); virtual HeapWord* allocate_new_tlab(size_t size); virtual HeapWord* allocate_work(size_t size); // TLAB allocations virtual bool supports_tlab_allocation() const { return UseTLAB; } virtual size_t tlab_capacity(Thread *thr) const { return capacity(); } virtual size_t tlab_used(Thread *thr) const { return used(); } // TODO: Should probably record the TLAB? virtual size_t unsafe_max_tlab_alloc(Thread *thr) const { // TODO: hook up in TLAB policy better. return EpsilonTLABSize; } virtual bool can_elide_tlab_store_barriers() const { return true; // TODO: Really? } virtual bool can_elide_initializing_store_barrier(oop new_obj) { return true; // TODO: Really? } virtual bool card_mark_must_follow_store() const { return false; // TODO: Really? } virtual void collect(GCCause::Cause cause); virtual void do_full_collection(bool clear_all_soft_refs); virtual AdaptiveSizePolicy *size_policy() { // No such thing for Epsilon return NULL; } virtual CollectorPolicy *collector_policy() const { return _policy; } virtual void object_iterate(ObjectClosure *cl) { safe_object_iterate(cl); } virtual void safe_object_iterate(ObjectClosure *cl); virtual HeapWord *block_start(const void *addr) const { Unimplemented(); return NULL; } virtual size_t block_size(const HeapWord *addr) const { Unimplemented(); return 0; } virtual bool block_is_obj(const HeapWord *addr) const { Unimplemented(); return false; } virtual jlong millis_since_last_gc() { return os::elapsed_counter() / NANOSECS_PER_MILLISEC; // since the VM start } virtual void prepare_for_verify() { // No heap verification. } virtual void print_on(outputStream *st) const { // Print nothing. } virtual void print_gc_threads_on(outputStream *st) const { // No GC threads. } virtual void gc_threads_do(ThreadClosure *tc) const { // No GC threads. } virtual void print_tracing_info() const { Log(gc) log; size_t allocated_kb = pointer_delta((HeapWord*)_current, _start) * HeapWordSize / K; log.info("Total allocated: " SIZE_FORMAT " KB.", allocated_kb); log.info("Average allocation rate: " SIZE_FORMAT " KB/sec", allocated_kb * NANOSECS_PER_SEC / os::elapsed_counter()); } virtual void verify(VerifyOption option) { // No heap verification for Epsilon. } };