< prev index next >

src/hotspot/share/oops/weakHandle.cpp

Print this page
rev 50285 : 8195097: Make it possible to process StringTable outside safepoint
Reviewed-by:


   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 "classfile/systemDictionary.hpp"

  27 #include "gc/shared/oopStorage.hpp"
  28 #include "oops/access.inline.hpp"
  29 #include "oops/oop.hpp"
  30 #include "oops/weakHandle.inline.hpp"
  31 #include "utilities/debug.hpp"
  32 #include "utilities/ostream.hpp"
  33 
  34 template <> OopStorage* WeakHandle<vm_class_loader_data>::get_storage() {
  35   return SystemDictionary::vm_weak_oop_storage();
  36 }
  37 




  38 template <WeakHandleType T>
  39 WeakHandle<T> WeakHandle<T>::create(Handle obj) {
  40   assert(obj() != NULL, "no need to create weak null oop");
  41   oop* oop_addr = get_storage()->allocate();
  42   if (oop_addr == NULL) {
  43     vm_exit_out_of_memory(sizeof(oop*), OOM_MALLOC_ERROR, "Unable to create new weak oop handle in OopStorage");
  44   }
  45   // Create WeakHandle with address returned and store oop into it.
  46   RootAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_addr, obj());
  47   return WeakHandle(oop_addr);
  48 }
  49 
  50 template <WeakHandleType T>
  51 void WeakHandle<T>::release() const {
  52   // Only release if the pointer to the object has been created.
  53   if (_obj != NULL) {
  54     // Clear the WeakHandle.  For race in creating ClassLoaderData, we can release this
  55     // WeakHandle before it is cleared by GC.
  56     RootAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, (oop)NULL);
  57     get_storage()->release(_obj);
  58   }
  59 }
  60 
  61 template <WeakHandleType T>
  62 void WeakHandle<T>::print() const { print_on(tty); }
  63 
  64 template <WeakHandleType T>
  65 void WeakHandle<T>::print_on(outputStream* st) const {
  66   st->print("WeakHandle: " PTR_FORMAT, p2i(peek()));
  67 }
  68 
  69 // Provide instantiation.
  70 template class WeakHandle<vm_class_loader_data>;

  71 


   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 "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 "utilities/debug.hpp"
  33 #include "utilities/ostream.hpp"
  34 
  35 template <> OopStorage* WeakHandle<vm_class_loader_data>::get_storage() {
  36   return SystemDictionary::vm_weak_oop_storage();
  37 }
  38 
  39 template <> OopStorage* WeakHandle<vm_string_table_data>::get_storage() {
  40   return StringTable::weak_storage();
  41 }
  42 
  43 template <WeakHandleType T>
  44 WeakHandle<T> WeakHandle<T>::create(Handle obj) {
  45   assert(obj() != NULL, "no need to create weak null oop");
  46   oop* oop_addr = get_storage()->allocate();
  47   if (oop_addr == NULL) {
  48     vm_exit_out_of_memory(sizeof(oop*), OOM_MALLOC_ERROR, "Unable to create new weak oop handle in OopStorage");
  49   }
  50   // Create WeakHandle with address returned and store oop into it.
  51   RootAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_addr, obj());
  52   return WeakHandle(oop_addr);
  53 }
  54 
  55 template <WeakHandleType T>
  56 void WeakHandle<T>::release() const {
  57   // Only release if the pointer to the object has been created.
  58   if (_obj != NULL) {
  59     // Clear the WeakHandle.  For race in creating ClassLoaderData, we can release this
  60     // WeakHandle before it is cleared by GC.
  61     RootAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, (oop)NULL);
  62     get_storage()->release(_obj);
  63   }
  64 }
  65 
  66 template <WeakHandleType T>
  67 void WeakHandle<T>::print() const { print_on(tty); }
  68 
  69 template <WeakHandleType T>
  70 void WeakHandle<T>::print_on(outputStream* st) const {
  71   st->print("WeakHandle: " PTR_FORMAT, p2i(peek()));
  72 }
  73 
  74 // Provide instantiation.
  75 template class WeakHandle<vm_class_loader_data>;
  76 template class WeakHandle<vm_string_table_data>;
  77 
< prev index next >