1 /*
2  * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
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 "precompiled.hpp"
25 
26 #include "gc/shenandoah/shenandoahBarrierSetNMethod.hpp"
27 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
28 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
30 #include "gc/shenandoah/shenandoahLock.hpp"
31 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
32 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
33 #include "memory/iterator.hpp"
34 #include "memory/resourceArea.hpp"
35 
nmethod_entry_barrier(nmethod * nm)36 bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
37   ShenandoahReentrantLock* lock = ShenandoahNMethod::lock_for_nmethod(nm);
38   assert(lock != NULL, "Must be");
39   ShenandoahReentrantLocker locker(lock);
40 
41   if (!is_armed(nm)) {
42     // Some other thread got here first and healed the oops
43     // and disarmed the nmethod.
44     return true;
45   }
46 
47   if (nm->is_unloading()) {
48     // We don't need to take the lock when unlinking nmethods from
49     // the Method, because it is only concurrently unlinked by
50     // the entry barrier, which acquires the per nmethod lock.
51     nm->unlink_from_method();
52 
53     // We can end up calling nmethods that are unloading
54     // since we clear compiled ICs lazily. Returning false
55     // will re-resovle the call and update the compiled IC.
56     return false;
57   }
58 
59   // Heal oops and disarm
60   ShenandoahNMethod::heal_nmethod(nm);
61   ShenandoahNMethod::disarm_nmethod(nm);
62   return true;
63 }
64 
disarmed_value() const65 int ShenandoahBarrierSetNMethod::disarmed_value() const {
66   return ShenandoahCodeRoots::disarmed_value();
67 }
68 
thread_disarmed_offset() const69 ByteSize ShenandoahBarrierSetNMethod::thread_disarmed_offset() const {
70   return ShenandoahThreadLocalData::disarmed_value_offset();
71 }
72 
disarmed_value_address() const73 int* ShenandoahBarrierSetNMethod::disarmed_value_address() const {
74   return ShenandoahCodeRoots::disarmed_value_address();
75 }
76