| 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 "code/nmethod.hpp" | 
|---|
| 26 | #include "gc/z/zBarrierSetNMethod.hpp" | 
|---|
| 27 | #include "gc/z/zGlobals.hpp" | 
|---|
| 28 | #include "gc/z/zLock.inline.hpp" | 
|---|
| 29 | #include "gc/z/zOopClosures.hpp" | 
|---|
| 30 | #include "gc/z/zNMethod.hpp" | 
|---|
| 31 | #include "gc/z/zThreadLocalData.hpp" | 
|---|
| 32 | #include "logging/log.hpp" | 
|---|
| 33 |  | 
|---|
| 34 | bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { | 
|---|
| 35 | ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm)); | 
|---|
| 36 | log_trace(nmethod, barrier)( "Entered critical zone for %p", nm); | 
|---|
| 37 |  | 
|---|
| 38 | if (!is_armed(nm)) { | 
|---|
| 39 | // Some other thread got here first and healed the oops | 
|---|
| 40 | // and disarmed the nmethod. | 
|---|
| 41 | return true; | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | if (nm->is_unloading()) { | 
|---|
| 45 | // We don't need to take the lock when unlinking nmethods from | 
|---|
| 46 | // the Method, because it is only concurrently unlinked by | 
|---|
| 47 | // the entry barrier, which acquires the per nmethod lock. | 
|---|
| 48 | nm->unlink_from_method(false /* acquire_lock */); | 
|---|
| 49 |  | 
|---|
| 50 | // We can end up calling nmethods that are unloading | 
|---|
| 51 | // since we clear compiled ICs lazily. Returning false | 
|---|
| 52 | // will re-resovle the call and update the compiled IC. | 
|---|
| 53 | return false; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | // Heal oops and disarm | 
|---|
| 57 | ZNMethodOopClosure cl; | 
|---|
| 58 | ZNMethod::nmethod_oops_do(nm, &cl); | 
|---|
| 59 | disarm(nm); | 
|---|
| 60 |  | 
|---|
| 61 | return true; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | int ZBarrierSetNMethod::disarmed_value() const { | 
|---|
| 65 | // We override the default BarrierSetNMethod::disarmed_value() since | 
|---|
| 66 | // this can be called by GC threads, which doesn't keep an up to date | 
|---|
| 67 | // address_bad_mask. | 
|---|
| 68 | const uintptr_t disarmed_addr = ((uintptr_t)&ZAddressBadMask) + ZNMethodDisarmedOffset; | 
|---|
| 69 | return *((int*)disarmed_addr); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | ByteSize ZBarrierSetNMethod::thread_disarmed_offset() const { | 
|---|
| 73 | return ZThreadLocalData::nmethod_disarmed_offset(); | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|