--- /dev/null 2015-10-06 23:29:51.451421828 +0200 +++ new/src/share/vm/gc/shenandoah/shenandoahBarrierSet.hpp 2015-10-14 13:54:46.861100155 +0200 @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2013, 2015, 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. + * + */ + +#ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP +#define SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP + +#include "gc/shenandoah/shenandoahHeap.hpp" +#include "gc/shared/barrierSet.hpp" + +class ShenandoahBarrierSet: public BarrierSet { +private: + + static inline oop get_shenandoah_forwardee_helper(oop p) { + assert(UseShenandoahGC, "must only be called when Shenandoah is used."); + assert(Universe::heap()->is_in(p), "We shouldn't be calling this on objects not in the heap"); + oop forwardee; +#ifdef ASSERT + if (ShenandoahVerifyReadsToFromSpace) { + ShenandoahHeap* heap = (ShenandoahHeap *) Universe::heap(); + ShenandoahHeapRegion* region = heap->heap_region_containing(p); + { + region->memProtectionOff(); + forwardee = oop( *((HeapWord**) ((HeapWord*) p) - 1)); + region->memProtectionOn(); + } + } else { + forwardee = oop( *((HeapWord**) ((HeapWord*) p) - 1)); + } +#else + forwardee = oop( *((HeapWord**) ((HeapWord*) p) - 1)); +#endif + return forwardee; + } + +public: + + ShenandoahBarrierSet(); + + void print_on(outputStream* st) const; + + bool is_a(BarrierSet::Name bsn); + + bool has_read_prim_array_opt(); + bool has_read_prim_barrier(); + bool has_read_ref_array_opt(); + bool has_read_ref_barrier(); + bool has_read_region_opt(); + bool has_write_prim_array_opt(); + bool has_write_prim_barrier(); + bool has_write_ref_array_opt(); + bool has_write_ref_barrier(); + bool has_write_ref_pre_barrier(); + bool has_write_region_opt(); + bool is_aligned(HeapWord* hw); + void read_prim_array(MemRegion mr); + void read_prim_field(HeapWord* hw, size_t s); + bool read_prim_needs_barrier(HeapWord* hw, size_t s); + void read_ref_array(MemRegion mr); + + void read_ref_field(void* v); + + bool read_ref_needs_barrier(void* v); + void read_region(MemRegion mr); + void resize_covered_region(MemRegion mr); + void write_prim_array(MemRegion mr); + void write_prim_field(HeapWord* hw, size_t s , juint x, juint y); + bool write_prim_needs_barrier(HeapWord* hw, size_t s, juint x, juint y); + void write_ref_array_work(MemRegion mr); + + template void + write_ref_array_pre_work(T* dst, int count); + + void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized); + + void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized); + + + template static void write_ref_field_pre_static(T* field, oop newVal); + + // We export this to make it available in cases where the static + // type of the barrier set is known. Note that it is non-virtual. + template inline void inline_write_ref_field_pre(T* field, oop newVal); + + // These are the more general virtual versions. + void write_ref_field_pre_work(oop* field, oop new_val); + void write_ref_field_pre_work(narrowOop* field, oop new_val); + void write_ref_field_pre_work(void* field, oop new_val); + + void write_ref_field_work(void* v, oop o, bool release = false); + void write_region_work(MemRegion mr); + + virtual oop read_barrier(oop src); + + virtual oop resolve_and_update_oop(oop* p, oop obj) { + return resolve_and_update_oop_static(p, obj); + } + virtual oop resolve_and_update_oop(narrowOop* p, oop obj) { + Unimplemented(); + return NULL; + } + + template + static inline oop resolve_and_update_oop_static(T p, oop obj) { + oop forw = ShenandoahBarrierSet::resolve_oop_static_not_null(obj); + if (forw != obj) { + obj = forw; + oopDesc::encode_store_heap_oop_not_null(p, obj); + } + return obj; + } + + static inline oop resolve_oop_static_not_null(oop p) { + assert(p != NULL, "Must be NULL checked"); + + oop result = get_shenandoah_forwardee_helper(p); + + if (result != NULL) { +#ifdef ASSERT + if (result != p) { + oop second_forwarding = get_shenandoah_forwardee_helper(result); + + // We should never be forwarded more than once. + if (result != second_forwarding) { + ShenandoahHeap* sh = (ShenandoahHeap*) Universe::heap(); + tty->print("first reference "PTR_FORMAT" is in heap region:\n", p2i((HeapWord*) p)); + sh->heap_region_containing(p)->print(); + tty->print("first_forwarding "PTR_FORMAT" is in heap region:\n", p2i((HeapWord*) result)); + sh->heap_region_containing(result)->print(); + tty->print("final reference "PTR_FORMAT" is in heap region:\n", p2i((HeapWord*) second_forwarding)); + sh->heap_region_containing(second_forwarding)->print(); + assert(get_shenandoah_forwardee_helper(result) == result, "Only one fowarding per customer"); + } + } +#endif + if (! ShenandoahVerifyReadsToFromSpace) { + // is_oop() would trigger a SEGFAULT when we're checking from-space-access. + assert(ShenandoahHeap::heap()->is_in(result) && result->is_oop(), "resolved oop must be a valid oop in the heap"); + } + } + return result; + } + + static inline oop resolve_oop_static(oop p) { + if (((HeapWord*) p) != NULL) { + return resolve_oop_static_not_null(p); + } else { + return p; + } + } + + static inline oop resolve_oop_static_no_check(oop p) { + if (((HeapWord*) p) != NULL) { + return get_shenandoah_forwardee_helper(p); + } else { + return p; + } + } + + + oop resolve_and_maybe_copy_oopHelper(oop src); + oop resolve_and_maybe_copy_oop_work(oop src); + oop resolve_and_maybe_copy_oop_work2(oop src); + virtual oop write_barrier(oop src); + + static oopDesc* write_barrier_c2(oopDesc* src); + static oopDesc* write_barrier_interp(oopDesc* src); + static oopDesc* write_barrier_c1(JavaThread* thread, oopDesc* src); + +private: + bool need_update_refs_barrier(); + +#ifndef CC_INTERP +public: + virtual void interpreter_read_barrier(MacroAssembler* masm, Register dst); + virtual void interpreter_read_barrier_not_null(MacroAssembler* masm, Register dst); + void interpreter_write_barrier(MacroAssembler* masm, Register dst); + +private: + void compile_resolve_oop_runtime(MacroAssembler* masm, Register dst); + +#endif +}; + +#endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP