< prev index next >

src/hotspot/cpu/aarch64/gc/shared/barrierSetNMethod_aarch64.cpp

Print this page
rev 58823 : [mq]: aarch64-jdk-nmethod-barriers-3.patch
   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 
  25 #include "precompiled.hpp"


  26 #include "gc/shared/barrierSetNMethod.hpp"





  27 #include "utilities/debug.hpp"

  28 




























































  29 void BarrierSetNMethod::deoptimize(nmethod* nm, address* return_address_ptr) {
  30   ShouldNotReachHere();














































  31 }
  32 
  33 void BarrierSetNMethod::disarm(nmethod* nm) {
  34   ShouldNotReachHere();








  35 }
  36 
  37 bool BarrierSetNMethod::is_armed(nmethod* nm) {
  38   ShouldNotReachHere();
  39   return false;




  40 }
   1 /*
   2  * Copyright (c) 2018, 2020, 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 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "code/nativeInst.hpp"
  28 #include "gc/shared/barrierSetNMethod.hpp"
  29 #include "logging/log.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "runtime/sharedRuntime.hpp"
  32 #include "runtime/thread.hpp"
  33 #include "utilities/align.hpp"
  34 #include "utilities/debug.hpp"
  35 #include "icache_aarch64.hpp"
  36 
  37 class NativeNMethodBarrier: public NativeInstruction {
  38   address instruction_address() const { return addr_at(0); }
  39 
  40   int *guard_addr() {
  41     return reinterpret_cast<int*>(instruction_address() + 10 * 4);
  42   }
  43 
  44 public:
  45   int get_value() {
  46     return Atomic::load_acquire(guard_addr());
  47   }
  48 
  49   void set_value(int value) {
  50     Atomic::release_store(guard_addr(), value);
  51   }
  52 
  53   void verify() const;
  54 };
  55 
  56 // Store the instruction bitmask, bits and name for checking the barrier.
  57 struct CheckInsn {
  58   uint32_t mask;
  59   uint32_t bits;
  60   const char *name;
  61 };
  62 
  63 static const struct CheckInsn barrierInsn[] = {
  64   { 0xff000000, 0x18000000, "ldr (literal)" },
  65   { 0xfffff0ff, 0xd50330bf, "dmb" },
  66   { 0xffc00000, 0xb9400000, "ldr"},
  67   { 0x7f20001f, 0x6b00001f, "cmp"},
  68   { 0xff00001f, 0x54000000, "b.eq"},
  69   { 0xff800000, 0xd2800000, "mov"},
  70   { 0xff800000, 0xf2800000, "movk"},
  71   { 0xff800000, 0xf2800000, "movk"},
  72   { 0xfffffc1f, 0xd63f0000, "blr"},
  73   { 0xfc000000, 0x14000000, "b"}
  74 };
  75 
  76 // The encodings must match the instructions emitted by
  77 // BarrierSetAssembler::nmethod_entry_barrier. The matching ignores the specific
  78 // register numbers and immediate values in the encoding.
  79 void NativeNMethodBarrier::verify() const {
  80   intptr_t addr = (intptr_t) instruction_address();
  81   for(unsigned int i = 0; i < sizeof(barrierInsn)/sizeof(struct CheckInsn); i++ ) {
  82     uint32_t inst = *((uint32_t*) addr);
  83     if ((inst & barrierInsn[i].mask) != barrierInsn[i].bits) {
  84       tty->print_cr("Addr: " INTPTR_FORMAT " Code: 0x%x", addr, inst);
  85       fatal("not an %s instruction.", barrierInsn[i].name);
  86     }
  87     addr +=4;
  88   }
  89 }
  90 
  91 
  92 /* We're called from an nmethod when we need to deoptimize it. We do
  93    this by throwing away the nmethod's frame and jumping to the
  94    ic_miss stub. This looks like there has been an IC miss at the
  95    entry of the nmethod, so we resolve the call, which will fall back
  96    to the interpreter if the nmethod has been unloaded. */
  97 void BarrierSetNMethod::deoptimize(nmethod* nm, address* return_address_ptr) {
  98 
  99   typedef struct {
 100     intptr_t *sp; intptr_t *fp; address lr; address pc;
 101   } frame_pointers_t;
 102 
 103   frame_pointers_t *new_frame = (frame_pointers_t *)(return_address_ptr - 5);
 104 
 105   JavaThread *thread = (JavaThread*)Thread::current();
 106   RegisterMap reg_map(thread, false);
 107   frame frame = thread->last_frame();
 108 
 109   assert(frame.is_compiled_frame() || frame.is_native_frame(), "must be");
 110   assert(frame.cb() == nm, "must be");
 111   frame = frame.sender(&reg_map);
 112 
 113   LogTarget(Trace, nmethod, barrier) out;
 114   if (out.is_enabled()) {
 115     Thread* thread = Thread::current();
 116     assert(thread->is_Java_thread(), "must be JavaThread");
 117     JavaThread* jth = (JavaThread*) thread;
 118     ResourceMark mark;
 119     log_trace(nmethod, barrier)("deoptimize(nmethod: %s(%p), return_addr: %p, osr: %d, thread: %p(%s), making rsp: %p) -> %p",
 120                                 nm->method()->name_and_sig_as_C_string(),
 121                                 nm, *(address *) return_address_ptr, nm->is_osr_method(), jth,
 122                                 jth->get_thread_name(), frame.sp(), nm->verified_entry_point());
 123   }
 124 
 125   new_frame->sp = frame.sp();
 126   new_frame->fp = frame.fp();
 127   new_frame->lr = frame.pc();
 128   new_frame->pc = SharedRuntime::get_handle_wrong_method_stub();
 129 }
 130 
 131 // This is the offset of the entry barrier from where the frame is completed.
 132 // If any code changes between the end of the verified entry where the entry
 133 // barrier resides, and the completion of the frame, then
 134 // NativeNMethodCmpBarrier::verify() will immediately complain when it does
 135 // not find the expected native instruction at this offset, which needs updating.
 136 // Note that this offset is invariant of PreserveFramePointer.
 137 
 138 static const int entry_barrier_offset = -4 * 11;
 139 
 140 static NativeNMethodBarrier* native_nmethod_barrier(nmethod* nm) {
 141   address barrier_address = nm->code_begin() + nm->frame_complete_offset() + entry_barrier_offset;
 142   NativeNMethodBarrier* barrier = reinterpret_cast<NativeNMethodBarrier*>(barrier_address);
 143   debug_only(barrier->verify());
 144   return barrier;
 145 }
 146 
 147 void BarrierSetNMethod::disarm(nmethod* nm) {
 148   if (!supports_entry_barrier(nm)) {
 149     return;
 150   }
 151 
 152   // Disarms the nmethod guard emitted by BarrierSetAssembler::nmethod_entry_barrier.
 153   // Symmetric "LDR; DMB ISHLD" is in the nmethod barrier.
 154   NativeNMethodBarrier* barrier = native_nmethod_barrier(nm);
 155 
 156   barrier->set_value(disarmed_value());
 157 }
 158 
 159 bool BarrierSetNMethod::is_armed(nmethod* nm) {
 160   if (!supports_entry_barrier(nm)) {
 161     return false;
 162   }
 163 
 164   NativeNMethodBarrier* barrier = native_nmethod_barrier(nm);
 165   return barrier->get_value() != disarmed_value();
 166 }
< prev index next >