hotspot/src/share/vm/runtime/handles.cpp
changeset 35194 7151995ee79e
parent 33611 9abd65805e19
child 36583 71f4f42b0fcd
--- a/hotspot/src/share/vm/runtime/handles.cpp	Fri Dec 18 13:38:49 2015 +0000
+++ b/hotspot/src/share/vm/runtime/handles.cpp	Fri Dec 18 15:50:33 2015 -0500
@@ -46,8 +46,57 @@
     _handle = thread->handle_area()->allocate_handle(obj);
   }
 }
+#endif
 
-#endif
+// Copy constructors and destructors for metadata handles
+// These do too much to inline.
+#define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \
+name##Handle::name##Handle(const name##Handle &h) {                    \
+  _value = h._value;                                                   \
+  if (_value != NULL) {                                                \
+    assert(_value->is_valid(), "obj is valid");                        \
+    if (h._thread != NULL) {                                           \
+      assert(h._thread == Thread::current(), "thread must be current");\
+      _thread = h._thread;                                             \
+    } else {                                                           \
+      _thread = Thread::current();                                     \
+    }                                                                  \
+    assert (_thread->is_in_stack((address)this), "not on stack?");     \
+    _thread->metadata_handles()->push((Metadata*)_value);              \
+  } else {                                                             \
+    _thread = NULL;                                                    \
+  }                                                                    \
+}                                                                      \
+name##Handle& name##Handle::operator=(const name##Handle &s) {         \
+  remove();                                                            \
+  _value = s._value;                                                   \
+  if (_value != NULL) {                                                \
+    assert(_value->is_valid(), "obj is valid");                        \
+    if (s._thread != NULL) {                                           \
+      assert(s._thread == Thread::current(), "thread must be current");\
+      _thread = s._thread;                                             \
+    } else {                                                           \
+      _thread = Thread::current();                                     \
+    }                                                                  \
+    assert (_thread->is_in_stack((address)this), "not on stack?");     \
+    _thread->metadata_handles()->push((Metadata*)_value);              \
+  } else {                                                             \
+    _thread = NULL;                                                    \
+  }                                                                    \
+  return *this;                                                        \
+}                                                                      \
+inline void name##Handle::remove() {                                   \
+  if (_value != NULL) {                                                \
+    int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \
+    assert(i!=-1, "not in metadata_handles list");                     \
+    _thread->metadata_handles()->remove_at(i);                         \
+  }                                                                    \
+}                                                                      \
+name##Handle::~name##Handle () { remove(); }                           \
+
+DEF_METADATA_HANDLE_FN_NOINLINE(method, Method)
+DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool)
+
 
 static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
   oop* bottom = (oop*) chunk->bottom();