< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

G1BarrierSet_merge

16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                                     
17  *                                                                                                                                   
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                           
19  * or visit www.oracle.com if you need additional information or have any                                                            
20  * questions.                                                                                                                        
21  *                                                                                                                                   
22  */                                                                                                                                  
23 
24 #include "precompiled.hpp"                                                                                                           
25 #include "gc/shared/oopStorage.inline.hpp"                                                                                           
26 #include "logging/log.hpp"                                                                                                           
27 #include "memory/iterator.hpp"                                                                                                       
28 #include "oops/oop.inline.hpp"                                                                                                       
29 #include "runtime/jniHandles.hpp"                                                                                                    
30 #include "runtime/mutexLocker.hpp"                                                                                                   
31 #include "runtime/thread.inline.hpp"                                                                                                 
32 #include "trace/traceMacros.hpp"                                                                                                     
33 #include "utilities/align.hpp"                                                                                                       
34 #include "utilities/debug.hpp"                                                                                                       
35 #if INCLUDE_ALL_GCS                                                                                                                  
36 #include "gc/g1/g1SATBCardTableModRefBS.hpp"                                                                                         
37 #endif                                                                                                                               
38 
39 OopStorage* JNIHandles::_global_handles = NULL;                                                                                      
40 OopStorage* JNIHandles::_weak_global_handles = NULL;                                                                                 
41 
42 
43 jobject JNIHandles::make_local(oop obj) {                                                                                            
44   if (obj == NULL) {                                                                                                                 
45     return NULL;                // ignore null handles                                                                               
46   } else {                                                                                                                           
47     Thread* thread = Thread::current();                                                                                              
48     assert(oopDesc::is_oop(obj), "not an oop");                                                                                      
49     assert(!current_thread_in_native(), "must not be in native");                                                                    
50     return thread->active_handles()->allocate_handle(obj);                                                                           
51   }                                                                                                                                  
52 }                                                                                                                                    
53 
54 
55 // optimized versions                                                                                                                

16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #include "precompiled.hpp"
25 #include "gc/shared/oopStorage.inline.hpp"
26 #include "logging/log.hpp"
27 #include "memory/iterator.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/jniHandles.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/thread.inline.hpp"
32 #include "trace/traceMacros.hpp"
33 #include "utilities/align.hpp"
34 #include "utilities/debug.hpp"
35 #if INCLUDE_ALL_GCS
36 #include "gc/g1/g1BarrierSet.hpp"
37 #endif
38 
39 OopStorage* JNIHandles::_global_handles = NULL;
40 OopStorage* JNIHandles::_weak_global_handles = NULL;
41 
42 
43 jobject JNIHandles::make_local(oop obj) {
44   if (obj == NULL) {
45     return NULL;                // ignore null handles
46   } else {
47     Thread* thread = Thread::current();
48     assert(oopDesc::is_oop(obj), "not an oop");
49     assert(!current_thread_in_native(), "must not be in native");
50     return thread->active_handles()->allocate_handle(obj);
51   }
52 }
53 
54 
55 // optimized versions

123     // Return NULL on allocation failure.                                                                                            
124     if (ptr != NULL) {                                                                                                               
125       *ptr = obj();                                                                                                                  
126       char* tptr = reinterpret_cast<char*>(ptr) + weak_tag_value;                                                                    
127       res = reinterpret_cast<jobject>(tptr);                                                                                         
128     } else {                                                                                                                         
129       report_handle_allocation_failure(alloc_failmode, "weak global");                                                               
130     }                                                                                                                                
131   } else {                                                                                                                           
132     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());                                                            
133   }                                                                                                                                  
134   return res;                                                                                                                        
135 }                                                                                                                                    
136 
137 oop JNIHandles::resolve_jweak(jweak handle) {                                                                                        
138   assert(handle != NULL, "precondition");                                                                                            
139   assert(is_jweak(handle), "precondition");                                                                                          
140   oop result = jweak_ref(handle);                                                                                                    
141 #if INCLUDE_ALL_GCS                                                                                                                  
142   if (result != NULL && UseG1GC) {                                                                                                   
143     G1SATBCardTableModRefBS::enqueue(result);                                                                                        
144   }                                                                                                                                  
145 #endif // INCLUDE_ALL_GCS                                                                                                            
146   return result;                                                                                                                     
147 }                                                                                                                                    
148 
149 bool JNIHandles::is_global_weak_cleared(jweak handle) {                                                                              
150   assert(handle != NULL, "precondition");                                                                                            
151   assert(is_jweak(handle), "not a weak handle");                                                                                     
152   return jweak_ref(handle) == NULL;                                                                                                  
153 }                                                                                                                                    
154 
155 void JNIHandles::destroy_global(jobject handle) {                                                                                    
156   if (handle != NULL) {                                                                                                              
157     assert(!is_jweak(handle), "wrong method for detroying jweak");                                                                   
158     jobject_ref(handle) = NULL;                                                                                                      
159     _global_handles->release(&jobject_ref(handle));                                                                                  
160   }                                                                                                                                  
161 }                                                                                                                                    
162 

123     // Return NULL on allocation failure.
124     if (ptr != NULL) {
125       *ptr = obj();
126       char* tptr = reinterpret_cast<char*>(ptr) + weak_tag_value;
127       res = reinterpret_cast<jobject>(tptr);
128     } else {
129       report_handle_allocation_failure(alloc_failmode, "weak global");
130     }
131   } else {
132     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
133   }
134   return res;
135 }
136 
137 oop JNIHandles::resolve_jweak(jweak handle) {
138   assert(handle != NULL, "precondition");
139   assert(is_jweak(handle), "precondition");
140   oop result = jweak_ref(handle);
141 #if INCLUDE_ALL_GCS
142   if (result != NULL && UseG1GC) {
143     G1BarrierSet::enqueue(result);
144   }
145 #endif // INCLUDE_ALL_GCS
146   return result;
147 }
148 
149 bool JNIHandles::is_global_weak_cleared(jweak handle) {
150   assert(handle != NULL, "precondition");
151   assert(is_jweak(handle), "not a weak handle");
152   return jweak_ref(handle) == NULL;
153 }
154 
155 void JNIHandles::destroy_global(jobject handle) {
156   if (handle != NULL) {
157     assert(!is_jweak(handle), "wrong method for detroying jweak");
158     jobject_ref(handle) = NULL;
159     _global_handles->release(&jobject_ref(handle));
160   }
161 }
162 
< prev index next >