< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahUnload.cpp

Print this page
rev 58162 : 8239926: Shenandoah: Shenandoah needs to mark nmethod's metadata
   1 /*
   2  * Copyright (c) 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  *


  28 #include "classfile/systemDictionary.hpp"
  29 #include "code/codeBehaviours.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/dependencyContext.hpp"
  32 #include "gc/shared/gcBehaviours.hpp"
  33 #include "gc/shared/suspendibleThreadSet.hpp"
  34 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  35 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
  36 #include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
  37 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
  38 #include "gc/shenandoah/shenandoahLock.hpp"
  39 #include "gc/shenandoah/shenandoahRootProcessor.hpp"
  40 #include "gc/shenandoah/shenandoahUnload.hpp"
  41 #include "gc/shenandoah/shenandoahVerifier.hpp"
  42 #include "memory/iterator.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "oops/access.inline.hpp"
  45 
  46 class ShenandoahIsUnloadingOopClosure : public OopClosure {
  47 private:
  48   ShenandoahMarkingContext*    _marking_context;
  49   bool                         _is_unloading;
  50 
  51 public:
  52   ShenandoahIsUnloadingOopClosure() :
  53     _marking_context(ShenandoahHeap::heap()->marking_context()),
  54     _is_unloading(false) {
  55   }
  56 
  57   virtual void do_oop(oop* p) {
  58     if (_is_unloading) {
  59       return;
  60     }
  61 
  62     const oop o = RawAccess<>::oop_load(p);
  63     if (!CompressedOops::is_null(o) &&
  64         _marking_context->is_complete() &&
  65         !_marking_context->is_marked(o)) {
  66       _is_unloading = true;
  67     }
  68   }
  69 
  70   virtual void do_oop(narrowOop* p) {
  71     ShouldNotReachHere();
  72   }
  73 
  74   bool is_unloading() const {
  75     return _is_unloading;
  76   }
  77 };
  78 
  79 class ShenandoahIsUnloadingBehaviour : public IsUnloadingBehaviour {
  80 public:
  81   virtual bool is_unloading(CompiledMethod* method) const {

  82     nmethod* const nm = method->as_nmethod();
  83     guarantee(ShenandoahHeap::heap()->is_concurrent_root_in_progress(), "Only this phase");





  84     ShenandoahNMethod* data = ShenandoahNMethod::gc_data(nm);
  85     ShenandoahReentrantLocker locker(data->lock());
  86     ShenandoahIsUnloadingOopClosure cl;
  87     data->oops_do(&cl);
  88     return  cl.is_unloading();
  89   }
  90 };
  91 
  92 class ShenandoahCompiledICProtectionBehaviour : public CompiledICProtectionBehaviour {
  93 public:
  94   virtual bool lock(CompiledMethod* method) {
  95     nmethod* const nm = method->as_nmethod();
  96     ShenandoahReentrantLock* const lock = ShenandoahNMethod::lock_for_nmethod(nm);
  97     assert(lock != NULL, "Not yet registered?");
  98     lock->lock();
  99     return true;
 100   }
 101 
 102   virtual void unlock(CompiledMethod* method) {
 103     nmethod* const nm = method->as_nmethod();


   1 /*
   2  * Copyright (c) 2019, 2020, 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  *


  28 #include "classfile/systemDictionary.hpp"
  29 #include "code/codeBehaviours.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/dependencyContext.hpp"
  32 #include "gc/shared/gcBehaviours.hpp"
  33 #include "gc/shared/suspendibleThreadSet.hpp"
  34 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  35 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
  36 #include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
  37 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
  38 #include "gc/shenandoah/shenandoahLock.hpp"
  39 #include "gc/shenandoah/shenandoahRootProcessor.hpp"
  40 #include "gc/shenandoah/shenandoahUnload.hpp"
  41 #include "gc/shenandoah/shenandoahVerifier.hpp"
  42 #include "memory/iterator.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "oops/access.inline.hpp"
  45 
  46 class ShenandoahIsUnloadingOopClosure : public OopClosure {
  47 private:
  48   ShenandoahMarkingContext* const _marking_context;
  49   bool                            _is_unloading;
  50 
  51 public:
  52   ShenandoahIsUnloadingOopClosure() :
  53     _marking_context(ShenandoahHeap::heap()->complete_marking_context()),
  54     _is_unloading(false) {
  55   }
  56 
  57   virtual void do_oop(oop* p) {
  58     if (_is_unloading) {
  59       return;
  60     }
  61 
  62     const oop o = RawAccess<>::oop_load(p);
  63     if (!CompressedOops::is_null(o) &&

  64         !_marking_context->is_marked(o)) {
  65       _is_unloading = true;
  66     }
  67   }
  68 
  69   virtual void do_oop(narrowOop* p) {
  70     ShouldNotReachHere();
  71   }
  72 
  73   bool is_unloading() const {
  74     return _is_unloading;
  75   }
  76 };
  77 
  78 class ShenandoahIsUnloadingBehaviour : public IsUnloadingBehaviour {
  79 public:
  80   virtual bool is_unloading(CompiledMethod* method) const {
  81     ShenandoahHeap* const heap = ShenandoahHeap::heap();
  82     nmethod* const nm = method->as_nmethod();
  83 
  84     if (heap->is_concurrent_mark_in_progress()) {
  85       ShenandoahNMethod::keep_metadata_alive(nm);
  86       return false;
  87     }
  88     assert(heap->is_concurrent_root_in_progress(), "What else?");
  89     ShenandoahNMethod* data = ShenandoahNMethod::gc_data(nm);
  90     ShenandoahReentrantLocker locker(data->lock());
  91     ShenandoahIsUnloadingOopClosure cl;
  92     data->oops_do(&cl);
  93     return  cl.is_unloading();
  94   }
  95 };
  96 
  97 class ShenandoahCompiledICProtectionBehaviour : public CompiledICProtectionBehaviour {
  98 public:
  99   virtual bool lock(CompiledMethod* method) {
 100     nmethod* const nm = method->as_nmethod();
 101     ShenandoahReentrantLock* const lock = ShenandoahNMethod::lock_for_nmethod(nm);
 102     assert(lock != NULL, "Not yet registered?");
 103     lock->lock();
 104     return true;
 105   }
 106 
 107   virtual void unlock(CompiledMethod* method) {
 108     nmethod* const nm = method->as_nmethod();


< prev index next >