< prev index next >

src/hotspot/share/oops/weakHandle.cpp

Print this page




  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 "classfile/systemDictionary.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "gc/shared/oopStorage.hpp"
  29 #include "oops/access.inline.hpp"
  30 #include "oops/oop.hpp"
  31 #include "oops/weakHandle.inline.hpp"
  32 #include "prims/resolvedMethodTable.hpp"

  33 #include "utilities/debug.hpp"
  34 #include "utilities/ostream.hpp"
  35 
  36 template <> OopStorage* WeakHandle<vm_class_loader_data>::get_storage() {
  37   return SystemDictionary::vm_weak_oop_storage();
  38 }
  39 
  40 template <> OopStorage* WeakHandle<vm_string_table_data>::get_storage() {
  41   return StringTable::weak_storage();
  42 }
  43 
  44 template <> OopStorage* WeakHandle<vm_resolved_method_table_data>::get_storage() {
  45   return ResolvedMethodTable::weak_storage();
  46 }
  47 




  48 template <WeakHandleType T>
  49 WeakHandle<T> WeakHandle<T>::create(Handle obj) {
  50   assert(obj() != NULL, "no need to create weak null oop");
  51   oop* oop_addr = get_storage()->allocate();
  52   if (oop_addr == NULL) {
  53     vm_exit_out_of_memory(sizeof(oop*), OOM_MALLOC_ERROR, "Unable to create new weak oop handle in OopStorage");
  54   }
  55   // Create WeakHandle with address returned and store oop into it.
  56   NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_addr, obj());
  57   return WeakHandle(oop_addr);
  58 }
  59 
  60 template <WeakHandleType T>






  61 void WeakHandle<T>::release() const {
  62   // Only release if the pointer to the object has been created.
  63   if (_obj != NULL) {
  64     // Clear the WeakHandle.  For race in creating ClassLoaderData, we can release this
  65     // WeakHandle before it is cleared by GC.
  66     NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, (oop)NULL);
  67     get_storage()->release(_obj);
  68   }
  69 }
  70 
  71 template <WeakHandleType T>
  72 void WeakHandle<T>::print() const { print_on(tty); }
  73 
  74 template <WeakHandleType T>
  75 void WeakHandle<T>::print_on(outputStream* st) const {
  76   st->print("WeakHandle: " PTR_FORMAT, p2i(peek()));
  77 }
  78 
  79 // Provide instantiation.
  80 template class WeakHandle<vm_class_loader_data>;
  81 template class WeakHandle<vm_string_table_data>;
  82 template class WeakHandle<vm_resolved_method_table_data>;



  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 "classfile/systemDictionary.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "gc/shared/oopStorage.hpp"
  29 #include "oops/access.inline.hpp"
  30 #include "oops/oop.hpp"
  31 #include "oops/weakHandle.inline.hpp"
  32 #include "prims/resolvedMethodTable.hpp"
  33 #include "runtime/continuation.hpp"
  34 #include "utilities/debug.hpp"
  35 #include "utilities/ostream.hpp"
  36 
  37 template <> OopStorage* WeakHandle<vm_class_loader_data>::get_storage() {
  38   return SystemDictionary::vm_weak_oop_storage();
  39 }
  40 
  41 template <> OopStorage* WeakHandle<vm_string_table_data>::get_storage() {
  42   return StringTable::weak_storage();
  43 }
  44 
  45 template <> OopStorage* WeakHandle<vm_resolved_method_table_data>::get_storage() {
  46   return ResolvedMethodTable::weak_storage();
  47 }
  48 
  49 template <> OopStorage* WeakHandle<vm_nmethod_keepalive_data>::get_storage() {
  50   return Continuation::weak_storage();
  51 }
  52 
  53 template <WeakHandleType T>
  54 WeakHandle<T> WeakHandle<T>::create(Handle obj) {
  55   assert(obj() != NULL, "no need to create weak null oop");
  56   oop* oop_addr = get_storage()->allocate();
  57   if (oop_addr == NULL) {
  58     vm_exit_out_of_memory(sizeof(oop*), OOM_MALLOC_ERROR, "Unable to create new weak oop handle in OopStorage");
  59   }
  60   // Create WeakHandle with address returned and store oop into it.
  61   NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_addr, obj());
  62   return WeakHandle(oop_addr);
  63 }
  64 
  65 template <WeakHandleType T>
  66 WeakHandle<T> WeakHandle<T>::from_raw(oop* raw) {
  67   assert(raw != NULL, "can't create from raw with NULL value");
  68   return WeakHandle(raw);
  69 }
  70 
  71 template <WeakHandleType T>
  72 void WeakHandle<T>::release() const {
  73   // Only release if the pointer to the object has been created.
  74   if (_obj != NULL) {
  75     // Clear the WeakHandle.  For race in creating ClassLoaderData, we can release this
  76     // WeakHandle before it is cleared by GC.
  77     NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, (oop)NULL);
  78     get_storage()->release(_obj);
  79   }
  80 }
  81 
  82 template <WeakHandleType T>
  83 void WeakHandle<T>::print() const { print_on(tty); }
  84 
  85 template <WeakHandleType T>
  86 void WeakHandle<T>::print_on(outputStream* st) const {
  87   st->print("WeakHandle: " PTR_FORMAT, p2i(peek()));
  88 }
  89 
  90 // Provide instantiation.
  91 template class WeakHandle<vm_class_loader_data>;
  92 template class WeakHandle<vm_string_table_data>;
  93 template class WeakHandle<vm_resolved_method_table_data>;
  94 template class WeakHandle<vm_nmethod_keepalive_data>;
< prev index next >