74
75 // Verification
76
77 void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
78 InstanceKlass::oop_verify_on(obj, st);
79 // Verify referent field
80 oop referent = java_lang_ref_Reference::referent(obj);
81 if (referent != NULL) {
82 guarantee(referent->is_oop(), "referent field heap failed");
83 }
84 // Verify next field
85 oop next = java_lang_ref_Reference::next(obj);
86 if (next != NULL) {
87 guarantee(next->is_oop(), "next field verify failed");
88 guarantee(next->is_instanceRef(), "next field verify failed");
89 }
90 }
91
92 bool InstanceRefKlass::owns_pending_list_lock(JavaThread* thread) {
93 if (java_lang_ref_Reference::pending_list_lock() == NULL) return false;
94 Handle h_lock(thread, java_lang_ref_Reference::pending_list_lock());
95 return ObjectSynchronizer::current_thread_holds_lock(thread, h_lock);
96 }
97
98 void InstanceRefKlass::acquire_pending_list_lock(BasicLock *pending_list_basic_lock) {
99 // we may enter this with pending exception set
100 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
101
102 // Create a HandleMark in case we retry a GC multiple times.
103 // Each time we attempt the GC, we allocate the handle below
104 // to hold the pending list lock. We want to free this handle.
105 HandleMark hm;
106
107 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock());
108 ObjectSynchronizer::fast_enter(h_lock, pending_list_basic_lock, false, THREAD);
109 assert(ObjectSynchronizer::current_thread_holds_lock(
110 JavaThread::current(), h_lock),
111 "Locking should have succeeded");
112 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
113 }
114
115 void InstanceRefKlass::release_and_notify_pending_list_lock(
116 BasicLock *pending_list_basic_lock) {
117 // we may enter this with pending exception set
118 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
119
120 // Create a HandleMark in case we retry a GC multiple times.
121 // Each time we attempt the GC, we allocate the handle below
122 // to hold the pending list lock. We want to free this handle.
123 HandleMark hm;
124
125 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock());
126 assert(ObjectSynchronizer::current_thread_holds_lock(
127 JavaThread::current(), h_lock),
128 "Lock should be held");
129 // Notify waiters on pending lists lock if there is any reference.
130 if (java_lang_ref_Reference::pending_list() != NULL) {
131 ObjectSynchronizer::notifyall(h_lock, THREAD);
132 }
133 ObjectSynchronizer::fast_exit(h_lock(), pending_list_basic_lock, THREAD);
134 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
135 }
|
74
75 // Verification
76
77 void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
78 InstanceKlass::oop_verify_on(obj, st);
79 // Verify referent field
80 oop referent = java_lang_ref_Reference::referent(obj);
81 if (referent != NULL) {
82 guarantee(referent->is_oop(), "referent field heap failed");
83 }
84 // Verify next field
85 oop next = java_lang_ref_Reference::next(obj);
86 if (next != NULL) {
87 guarantee(next->is_oop(), "next field verify failed");
88 guarantee(next->is_instanceRef(), "next field verify failed");
89 }
90 }
91
92 bool InstanceRefKlass::owns_pending_list_lock(JavaThread* thread) {
93 if (java_lang_ref_Reference::pending_list_lock() == NULL) return false;
94 Handle h_lock(thread, oopDesc::bs()->resolve_and_maybe_copy_oop(java_lang_ref_Reference::pending_list_lock()));
95 return ObjectSynchronizer::current_thread_holds_lock(thread, h_lock);
96 }
97
98 void InstanceRefKlass::acquire_pending_list_lock(BasicLock *pending_list_basic_lock) {
99 // we may enter this with pending exception set
100 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
101
102 // Create a HandleMark in case we retry a GC multiple times.
103 // Each time we attempt the GC, we allocate the handle below
104 // to hold the pending list lock. We want to free this handle.
105 HandleMark hm;
106
107 Handle h_lock(THREAD, oopDesc::bs()->resolve_and_maybe_copy_oop(java_lang_ref_Reference::pending_list_lock()));
108 ObjectSynchronizer::fast_enter(h_lock, pending_list_basic_lock, false, THREAD);
109 assert(ObjectSynchronizer::current_thread_holds_lock(
110 JavaThread::current(), h_lock),
111 "Locking should have succeeded");
112 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
113 }
114
115 void InstanceRefKlass::release_and_notify_pending_list_lock(
116 BasicLock *pending_list_basic_lock) {
117 // we may enter this with pending exception set
118 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
119
120 // Create a HandleMark in case we retry a GC multiple times.
121 // Each time we attempt the GC, we allocate the handle below
122 // to hold the pending list lock. We want to free this handle.
123 HandleMark hm;
124
125 Handle h_lock(THREAD, oopDesc::bs()->resolve_and_maybe_copy_oop(java_lang_ref_Reference::pending_list_lock()));
126 assert(ObjectSynchronizer::current_thread_holds_lock(
127 JavaThread::current(), h_lock),
128 "Lock should be held");
129 // Notify waiters on pending lists lock if there is any reference.
130 if (java_lang_ref_Reference::pending_list() != NULL) {
131 ObjectSynchronizer::notifyall(h_lock, THREAD);
132 }
133 ObjectSynchronizer::fast_exit(h_lock(), pending_list_basic_lock, THREAD);
134 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
135 }
|