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 "memory/allocation.inline.hpp"
27 #include "oops/constantPool.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/atomic.hpp"
30 #include "runtime/handles.inline.hpp"
31 #include "runtime/thread.inline.hpp"
32
33 #ifdef ASSERT
34 oop* HandleArea::allocate_handle(oop obj) {
35 assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark");
36 assert(_no_handle_mark_nesting == 0, "allocating handle inside NoHandleMark");
37 assert(obj->is_oop(), "not an oop: " INTPTR_FORMAT, p2i(obj));
38 return real_allocate_handle(obj);
39 }
40 #endif
41
42 // Copy constructors and destructors for metadata handles
43 // These do too much to inline.
44 #define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \
45 name##Handle::name##Handle(const name##Handle &h) { \
46 _value = h._value; \
47 if (_value != NULL) { \
48 assert(_value->is_valid(), "obj is valid"); \
49 if (h._thread != NULL) { \
50 assert(h._thread == Thread::current(), "thread must be current");\
51 _thread = h._thread; \
52 } else { \
53 _thread = Thread::current(); \
54 } \
55 assert (_thread->is_in_stack((address)this), "not on stack?"); \
56 _thread->metadata_handles()->push((Metadata*)_value); \
57 } else { \
82 assert(i!=-1, "not in metadata_handles list"); \
83 _thread->metadata_handles()->remove_at(i); \
84 } \
85 } \
86 name##Handle::~name##Handle () { remove(); } \
87
88 DEF_METADATA_HANDLE_FN_NOINLINE(method, Method)
89 DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool)
90
91
92 static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
93 oop* bottom = (oop*) chunk->bottom();
94 oop* top = (oop*) chunk_top;
95 uintx handles_visited = top - bottom;
96 assert(top >= bottom && top <= (oop*) chunk->top(), "just checking");
97 // during GC phase 3, a handle may be a forward pointer that
98 // is not yet valid, so loosen the assertion
99 while (bottom < top) {
100 // This test can be moved up but for now check every oop.
101
102 assert((*bottom)->is_oop(), "handle should point to oop");
103
104 f->do_oop(bottom++);
105 }
106 return handles_visited;
107 }
108
109 // Used for debugging handle allocation.
110 NOT_PRODUCT(jint _nof_handlemarks = 0;)
111
112 void HandleArea::oops_do(OopClosure* f) {
113 uintx handles_visited = 0;
114 // First handle the current chunk. It is filled to the high water mark.
115 handles_visited += chunk_oops_do(f, _chunk, _hwm);
116 // Then handle all previous chunks. They are completely filled.
117 Chunk* k = _first;
118 while(k != _chunk) {
119 handles_visited += chunk_oops_do(f, k, k->top());
120 k = k->next();
121 }
122
|
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 "memory/allocation.inline.hpp"
27 #include "oops/constantPool.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/atomic.hpp"
30 #include "runtime/handles.inline.hpp"
31 #include "runtime/thread.inline.hpp"
32
33 #ifdef ASSERT
34 oop* HandleArea::allocate_handle(oop obj) {
35 assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark");
36 assert(_no_handle_mark_nesting == 0, "allocating handle inside NoHandleMark");
37 assert(oopDesc::is_oop(obj), "not an oop: " INTPTR_FORMAT, p2i(obj));
38 return real_allocate_handle(obj);
39 }
40 #endif
41
42 // Copy constructors and destructors for metadata handles
43 // These do too much to inline.
44 #define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \
45 name##Handle::name##Handle(const name##Handle &h) { \
46 _value = h._value; \
47 if (_value != NULL) { \
48 assert(_value->is_valid(), "obj is valid"); \
49 if (h._thread != NULL) { \
50 assert(h._thread == Thread::current(), "thread must be current");\
51 _thread = h._thread; \
52 } else { \
53 _thread = Thread::current(); \
54 } \
55 assert (_thread->is_in_stack((address)this), "not on stack?"); \
56 _thread->metadata_handles()->push((Metadata*)_value); \
57 } else { \
82 assert(i!=-1, "not in metadata_handles list"); \
83 _thread->metadata_handles()->remove_at(i); \
84 } \
85 } \
86 name##Handle::~name##Handle () { remove(); } \
87
88 DEF_METADATA_HANDLE_FN_NOINLINE(method, Method)
89 DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool)
90
91
92 static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
93 oop* bottom = (oop*) chunk->bottom();
94 oop* top = (oop*) chunk_top;
95 uintx handles_visited = top - bottom;
96 assert(top >= bottom && top <= (oop*) chunk->top(), "just checking");
97 // during GC phase 3, a handle may be a forward pointer that
98 // is not yet valid, so loosen the assertion
99 while (bottom < top) {
100 // This test can be moved up but for now check every oop.
101
102 assert(oopDesc::is_oop(*bottom), "handle should point to oop");
103
104 f->do_oop(bottom++);
105 }
106 return handles_visited;
107 }
108
109 // Used for debugging handle allocation.
110 NOT_PRODUCT(jint _nof_handlemarks = 0;)
111
112 void HandleArea::oops_do(OopClosure* f) {
113 uintx handles_visited = 0;
114 // First handle the current chunk. It is filled to the high water mark.
115 handles_visited += chunk_oops_do(f, _chunk, _hwm);
116 // Then handle all previous chunks. They are completely filled.
117 Chunk* k = _first;
118 while(k != _chunk) {
119 handles_visited += chunk_oops_do(f, k, k->top());
120 k = k->next();
121 }
122
|