1 /*
2  * Copyright (c) 2018, Oracle and/or its affiliates. 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 #include "precompiled.hpp"
25 #include "gc/z/zBarrierSet.hpp"
26 #include "gc/z/zBarrierSetAssembler.hpp"
27 #include "gc/z/zGlobals.hpp"
28 #include "gc/z/zHeap.inline.hpp"
29 #include "gc/z/zThreadLocalData.hpp"
30 #include "runtime/thread.hpp"
31 #ifdef COMPILER1
32 #include "gc/z/c1/zBarrierSetC1.hpp"
33 #endif
34 #ifdef COMPILER2
35 #include "gc/z/c2/zBarrierSetC2.hpp"
36 #endif
37 
38 class ZBarrierSetC1;
39 class ZBarrierSetC2;
40 
ZBarrierSet()41 ZBarrierSet::ZBarrierSet() :
42     BarrierSet(make_barrier_set_assembler<ZBarrierSetAssembler>(),
43                COMPILER1_PRESENT( make_barrier_set_c1<ZBarrierSetC1>() ) NOT_COMPILER1(NULL),
44                COMPILER2_PRESENT( make_barrier_set_c2<ZBarrierSetC2>() ) NOT_COMPILER2(NULL),
45                BarrierSet::FakeRtti(BarrierSet::ZBarrierSet)) {}
46 
assembler()47 ZBarrierSetAssembler* ZBarrierSet::assembler() {
48   BarrierSetAssembler* const bsa = BarrierSet::barrier_set()->barrier_set_assembler();
49   return reinterpret_cast<ZBarrierSetAssembler*>(bsa);
50 }
51 
barrier_needed(DecoratorSet decorators,BasicType type)52 bool ZBarrierSet::barrier_needed(DecoratorSet decorators, BasicType type) {
53   assert((decorators & AS_RAW) == 0, "Unexpected decorator");
54   assert((decorators & AS_NO_KEEPALIVE) == 0, "Unexpected decorator");
55   //assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Unexpected decorator");
56 
57   if (type == T_OBJECT || type == T_ARRAY) {
58     assert((decorators & (IN_HEAP | IN_NATIVE)) != 0, "Where is reference?");
59     // Barrier needed even when IN_NATIVE, to allow concurrent scanning.
60     return true;
61   }
62 
63   // Barrier not needed
64   return false;
65 }
66 
on_thread_create(Thread * thread)67 void ZBarrierSet::on_thread_create(Thread* thread) {
68   // Create thread local data
69   ZThreadLocalData::create(thread);
70 }
71 
on_thread_destroy(Thread * thread)72 void ZBarrierSet::on_thread_destroy(Thread* thread) {
73   // Destroy thread local data
74   ZThreadLocalData::destroy(thread);
75 }
76 
on_thread_attach(JavaThread * thread)77 void ZBarrierSet::on_thread_attach(JavaThread* thread) {
78   // Set thread local address bad mask
79   ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask);
80 }
81 
on_thread_detach(JavaThread * thread)82 void ZBarrierSet::on_thread_detach(JavaThread* thread) {
83   // Flush and free any remaining mark stacks
84   ZHeap::heap()->mark_flush_and_free(thread);
85 }
86