1 /* |
1 /* |
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "classfile/javaClasses.hpp" |
26 #include "classfile/javaClasses.hpp" |
27 #include "classfile/systemDictionary.hpp" |
27 #include "classfile/systemDictionary.hpp" |
28 #include "gc/shared/collectedHeap.inline.hpp" |
|
29 #include "gc/shared/genCollectedHeap.hpp" |
|
30 #include "gc/shared/specialized_oop_closures.hpp" |
|
31 #include "oops/instanceRefKlass.inline.hpp" |
28 #include "oops/instanceRefKlass.inline.hpp" |
32 #include "oops/oop.inline.hpp" |
29 #include "oops/oop.inline.hpp" |
33 #include "utilities/macros.hpp" |
|
34 #include "utilities/preserveException.hpp" |
|
35 |
30 |
36 void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) { |
31 void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) { |
37 // Clear the nonstatic oop-map entries corresponding to referent |
32 // Clear the nonstatic oop-map entries corresponding to referent |
38 // and nextPending field. They are treated specially by the |
33 // and nextPending field. They are treated specially by the |
39 // garbage collector. |
34 // garbage collector. |
85 guarantee(next->is_oop(), "next field should be an oop"); |
80 guarantee(next->is_oop(), "next field should be an oop"); |
86 guarantee(next->is_instance(), "next field should be an instance"); |
81 guarantee(next->is_instance(), "next field should be an instance"); |
87 guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed"); |
82 guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed"); |
88 } |
83 } |
89 } |
84 } |
90 |
|
91 bool InstanceRefKlass::owns_pending_list_lock(JavaThread* thread) { |
|
92 if (java_lang_ref_Reference::pending_list_lock() == NULL) return false; |
|
93 Handle h_lock(thread, java_lang_ref_Reference::pending_list_lock()); |
|
94 return ObjectSynchronizer::current_thread_holds_lock(thread, h_lock); |
|
95 } |
|
96 |
|
97 void InstanceRefKlass::acquire_pending_list_lock(BasicLock *pending_list_basic_lock) { |
|
98 // we may enter this with pending exception set |
|
99 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument |
|
100 |
|
101 // Create a HandleMark in case we retry a GC multiple times. |
|
102 // Each time we attempt the GC, we allocate the handle below |
|
103 // to hold the pending list lock. We want to free this handle. |
|
104 HandleMark hm; |
|
105 |
|
106 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock()); |
|
107 ObjectSynchronizer::fast_enter(h_lock, pending_list_basic_lock, false, THREAD); |
|
108 assert(ObjectSynchronizer::current_thread_holds_lock( |
|
109 JavaThread::current(), h_lock), |
|
110 "Locking should have succeeded"); |
|
111 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION; |
|
112 } |
|
113 |
|
114 void InstanceRefKlass::release_and_notify_pending_list_lock( |
|
115 BasicLock *pending_list_basic_lock) { |
|
116 // we may enter this with pending exception set |
|
117 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument |
|
118 |
|
119 // Create a HandleMark in case we retry a GC multiple times. |
|
120 // Each time we attempt the GC, we allocate the handle below |
|
121 // to hold the pending list lock. We want to free this handle. |
|
122 HandleMark hm; |
|
123 |
|
124 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock()); |
|
125 assert(ObjectSynchronizer::current_thread_holds_lock( |
|
126 JavaThread::current(), h_lock), |
|
127 "Lock should be held"); |
|
128 // Notify waiters on pending lists lock if there is any reference. |
|
129 if (java_lang_ref_Reference::pending_list() != NULL) { |
|
130 ObjectSynchronizer::notifyall(h_lock, THREAD); |
|
131 } |
|
132 ObjectSynchronizer::fast_exit(h_lock(), pending_list_basic_lock, THREAD); |
|
133 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION; |
|
134 } |
|