hotspot/src/share/vm/runtime/handles.inline.hpp
changeset 13728 882756847a04
parent 13195 be27e1b6a4b9
child 14120 7d298141c258
--- a/hotspot/src/share/vm/runtime/handles.inline.hpp	Fri Aug 31 16:39:35 2012 -0700
+++ b/hotspot/src/share/vm/runtime/handles.inline.hpp	Sat Sep 01 13:25:18 2012 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,63 @@
 }
 #endif // ASSERT
 
+// Constructors for metadata handles
+#define DEF_METADATA_HANDLE_FN(name, type) \
+inline name##Handle::name##Handle(type* obj) : _value(obj), _thread(NULL) {       \
+  if (obj != NULL) {                                                   \
+    assert(((Metadata*)obj)->is_valid(), "obj is valid");              \
+    _thread = Thread::current();                                       \
+    assert (_thread->is_in_stack((address)this), "not on stack?");     \
+    _thread->metadata_handles()->push((Metadata*)obj);                 \
+  }                                                                    \
+}                                                                      \
+inline name##Handle::name##Handle(Thread* thread, type* obj) : _value(obj), _thread(thread) { \
+  if (obj != NULL) {                                                   \
+    assert(((Metadata*)obj)->is_valid(), "obj is valid");              \
+    assert(_thread == Thread::current(), "thread must be current");    \
+    assert (_thread->is_in_stack((address)this), "not on stack?");     \
+    _thread->metadata_handles()->push((Metadata*)obj);                 \
+  }                                                                    \
+}                                                                      \
+inline 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();                                     \
+    }                                                                  \
+    _thread->metadata_handles()->push((Metadata*)_value);              \
+  }                                                                    \
+}                                                                      \
+inline 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();                                     \
+    }                                                                  \
+    _thread->metadata_handles()->push((Metadata*)_value);              \
+  }                                                                    \
+  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);                         \
+  }                                                                    \
+}                                                                      \
+inline name##Handle::~name##Handle () { remove(); }                    \
+
+DEF_METADATA_HANDLE_FN(method, Method)
+DEF_METADATA_HANDLE_FN(constantPool, ConstantPool)
 
 inline HandleMark::HandleMark() {
   initialize(Thread::current());