1 /*
2  * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #include "precompiled.hpp"
26 #include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
27 #include "gc/shenandoah/shenandoahBarrierSetClone.inline.hpp"
28 #include "gc/shenandoah/shenandoahRuntime.hpp"
29 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
30 #include "runtime/interfaceSupport.inline.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "utilities/copy.hpp"
33 
arraycopy_barrier_oop_entry(oop * src,oop * dst,size_t length)34 void ShenandoahRuntime::arraycopy_barrier_oop_entry(oop* src, oop* dst, size_t length) {
35   ShenandoahBarrierSet *bs = ShenandoahBarrierSet::barrier_set();
36   bs->arraycopy_barrier(src, dst, length);
37 }
38 
arraycopy_barrier_narrow_oop_entry(narrowOop * src,narrowOop * dst,size_t length)39 void ShenandoahRuntime::arraycopy_barrier_narrow_oop_entry(narrowOop* src, narrowOop* dst, size_t length) {
40   ShenandoahBarrierSet *bs = ShenandoahBarrierSet::barrier_set();
41   bs->arraycopy_barrier(src, dst, length);
42 }
43 
44 // Shenandoah pre write barrier slowpath
45 JRT_LEAF(void, ShenandoahRuntime::write_ref_field_pre_entry(oopDesc* orig, JavaThread *thread))
46   assert(orig != NULL, "should be optimized out");
47   shenandoah_assert_correct(NULL, orig);
48   // store the original value that was in the field reference
49   assert(ShenandoahThreadLocalData::satb_mark_queue(thread).is_active(), "Shouldn't be here otherwise");
50   ShenandoahThreadLocalData::satb_mark_queue(thread).enqueue_known_active(orig);
51 JRT_END
52 
53 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_strong(oopDesc* src, oop* load_addr))
54   return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_mutator(src, load_addr);
55 JRT_END
56 
57 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_strong_narrow(oopDesc* src, narrowOop* load_addr))
58   return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_mutator(src, load_addr);
59 JRT_END
60 
61 // Shenandoah clone barrier: makes sure that references point to to-space
62 // in cloned objects.
63 JRT_LEAF(void, ShenandoahRuntime::shenandoah_clone_barrier(oopDesc* src))
64   oop s = oop(src);
65   shenandoah_assert_correct(NULL, s);
66   ShenandoahBarrierSet::barrier_set()->clone_barrier(s);
67 JRT_END
68 
69 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak(oopDesc * src, oop* load_addr))
70   return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier<ON_WEAK_OOP_REF, oop>(oop(src), load_addr);
71 JRT_END
72 
73 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak_narrow(oopDesc * src, narrowOop* load_addr))
74   return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier<ON_WEAK_OOP_REF, narrowOop>(oop(src), load_addr);
75 JRT_END
76 
77 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_phantom(oopDesc * src, oop* load_addr))
78   return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier<ON_PHANTOM_OOP_REF, oop>(oop(src), load_addr);
79 JRT_END
80 
81 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_phantom_narrow(oopDesc * src, narrowOop* load_addr))
82   return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier<ON_PHANTOM_OOP_REF, narrowOop>(oop(src), load_addr);
83 JRT_END
84