< prev index next >

src/share/vm/oops/instanceRefKlass.inline.hpp

Print this page
rev 12851 : 8138737: Remove oop_ms_adjust_pointers and use oop_iterate instead
Reviewed-by:
rev 12852 : [mq]: 8138737-remove-oop-ms-adjust-kbarrett-rev1
   1 /*
   2  * Copyright (c) 2015, 2016, 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  *


  61 }
  62 
  63 template <typename T, class OopClosureType>
  64 bool InstanceRefKlass::try_discover(oop obj, ReferenceType type, OopClosureType* closure) {
  65   ReferenceProcessor* rp = closure->ref_processor();
  66   if (rp != NULL) {
  67     T referent_oop = oopDesc::load_heap_oop((T*)java_lang_ref_Reference::referent_addr(obj));
  68     if (!oopDesc::is_null(referent_oop)) {
  69       oop referent = oopDesc::decode_heap_oop_not_null(referent_oop);
  70       if (!referent->is_gc_marked()) {
  71         // Only try to discover if not yet marked.
  72         return rp->discover_reference(obj, type);
  73       }
  74     }
  75   }
  76   return false;
  77 }
  78 
  79 template <bool nv, typename T, class OopClosureType, class Contains>
  80 void InstanceRefKlass::oop_oop_iterate_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains) {
  81   log_develop_trace(gc, ref)("Process reference default " PTR_FORMAT, p2i(obj));
  82 
  83   // Special case for some closures.
  84   if (closure->apply_to_weak_ref_discovered_field()) {
  85     do_discovered<nv, T>(obj, closure, contains);
  86   }
  87 
  88   // Try to discover reference and return if it succeeds.
  89   if (try_discover<T>(obj, type, closure)) {
  90     return;
  91   }
  92 
  93   // Treat referent as normal oop.
  94   do_referent<nv, T>(obj, closure, contains);
  95 
  96   // Treat discovered as normal oop, if ref is not "active" (next non-NULL).
  97   T next_oop  = oopDesc::load_heap_oop((T*)java_lang_ref_Reference::next_addr(obj));
  98   if (!oopDesc::is_null(next_oop)) {
  99     do_discovered<nv, T>(obj, closure, contains);
 100   }
 101 
 102   // Treat next as normal oop.
 103   do_next<nv, T>(obj, closure, contains);
 104 }
 105 
 106 template <bool nv, typename T, class OopClosureType, class Contains>
 107 void InstanceRefKlass::oop_oop_iterate_fields(oop obj, OopClosureType* closure, Contains& contains) {
 108   do_referent<nv, T>(obj, closure, contains);
 109   do_discovered<nv, T>(obj, closure, contains);
 110   do_next<nv, T>(obj, closure, contains);
 111   debug_only(trace_reference_gc("InstanceRefKlass::oop_oop_iterate_fields()",
 112                                 obj,
 113                                 (T*)java_lang_ref_Reference::referent_addr(obj),
 114                                 (T*)java_lang_ref_Reference::next_addr(obj),
 115                                 (T*)java_lang_ref_Reference::discovered_addr(obj));)
 116 }
 117 
 118 template <bool nv, typename T, class OopClosureType, class Contains>
 119 void InstanceRefKlass::oop_oop_iterate_ref_processing_specialized(oop obj, OopClosureType* closure, Contains& contains) {
 120   switch (closure->reference_iteration_mode()) {
 121     case ExtendedOopClosure::DO_DISCOVERY:
 122       oop_oop_iterate_discovery<nv, T>(obj, reference_type(), closure, contains);
 123       break;
 124     case ExtendedOopClosure::DO_FIELDS:
 125       oop_oop_iterate_fields<nv, T>(obj, closure, contains);
 126       break;
 127     default:
 128       ShouldNotReachHere();
 129   }
 130 }
 131 
 132 class AlwaysContains {
 133  public:
 134   template <typename T> bool operator()(T* p) const { return true; }
 135 };


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


  61 }
  62 
  63 template <typename T, class OopClosureType>
  64 bool InstanceRefKlass::try_discover(oop obj, ReferenceType type, OopClosureType* closure) {
  65   ReferenceProcessor* rp = closure->ref_processor();
  66   if (rp != NULL) {
  67     T referent_oop = oopDesc::load_heap_oop((T*)java_lang_ref_Reference::referent_addr(obj));
  68     if (!oopDesc::is_null(referent_oop)) {
  69       oop referent = oopDesc::decode_heap_oop_not_null(referent_oop);
  70       if (!referent->is_gc_marked()) {
  71         // Only try to discover if not yet marked.
  72         return rp->discover_reference(obj, type);
  73       }
  74     }
  75   }
  76   return false;
  77 }
  78 
  79 template <bool nv, typename T, class OopClosureType, class Contains>
  80 void InstanceRefKlass::oop_oop_iterate_discovery(oop obj, ReferenceType type, OopClosureType* closure, Contains& contains) {
  81   log_develop_trace(gc, ref)("Process reference with discovery " PTR_FORMAT, p2i(obj));
  82 
  83   // Special case for some closures.
  84   if (closure->apply_to_weak_ref_discovered_field()) {
  85     do_discovered<nv, T>(obj, closure, contains);
  86   }
  87 
  88   // Try to discover reference and return if it succeeds.
  89   if (try_discover<T>(obj, type, closure)) {
  90     return;
  91   }
  92 
  93   // Treat referent as normal oop.
  94   do_referent<nv, T>(obj, closure, contains);
  95 
  96   // Treat discovered as normal oop, if ref is not "active" (next non-NULL).
  97   T next_oop  = oopDesc::load_heap_oop((T*)java_lang_ref_Reference::next_addr(obj));
  98   if (!oopDesc::is_null(next_oop)) {
  99     do_discovered<nv, T>(obj, closure, contains);
 100   }
 101 
 102   // Treat next as normal oop.
 103   do_next<nv, T>(obj, closure, contains);
 104 }
 105 
 106 template <bool nv, typename T, class OopClosureType, class Contains>
 107 void InstanceRefKlass::oop_oop_iterate_fields(oop obj, OopClosureType* closure, Contains& contains) {
 108   do_referent<nv, T>(obj, closure, contains);
 109   do_discovered<nv, T>(obj, closure, contains);
 110   do_next<nv, T>(obj, closure, contains);
 111   trace_reference_gc("InstanceRefKlass::oop_oop_iterate_fields()",
 112                      obj,
 113                      (T*)java_lang_ref_Reference::referent_addr(obj),
 114                      (T*)java_lang_ref_Reference::next_addr(obj),
 115                      (T*)java_lang_ref_Reference::discovered_addr(obj));
 116 }
 117 
 118 template <bool nv, typename T, class OopClosureType, class Contains>
 119 void InstanceRefKlass::oop_oop_iterate_ref_processing_specialized(oop obj, OopClosureType* closure, Contains& contains) {
 120   switch (closure->reference_iteration_mode()) {
 121     case ExtendedOopClosure::DO_DISCOVERY:
 122       oop_oop_iterate_discovery<nv, T>(obj, reference_type(), closure, contains);
 123       break;
 124     case ExtendedOopClosure::DO_FIELDS:
 125       oop_oop_iterate_fields<nv, T>(obj, closure, contains);
 126       break;
 127     default:
 128       ShouldNotReachHere();
 129   }
 130 }
 131 
 132 class AlwaysContains {
 133  public:
 134   template <typename T> bool operator()(T* p) const { return true; }
 135 };


< prev index next >