< prev index next >

src/hotspot/share/prims/methodHandles.cpp


1046       if (rskip > 0) {                                                                                                               
1047         --rskip;                                                                                                                     
1048       } else if (rfill < rlimit) {                                                                                                   
1049         Handle result(thread, results->obj_at(rfill++));                                                                             
1050         if (!java_lang_invoke_MemberName::is_instance(result()))                                                                     
1051           return -99;  // caller bug!                                                                                                
1052         CallInfo info(m, NULL, CHECK_0);                                                                                             
1053         oop saved = MethodHandles::init_method_MemberName(result, info);                                                             
1054         if (!oopDesc::equals(saved, result()))                                                                                       
1055           results->obj_at_put(rfill-1, saved);  // show saved instance to user                                                       
1056       } else if (++overflow >= overflow_limit) {                                                                                     
1057         match_flags = 0; break; // got tired of looking at overflow                                                                  
1058       }                                                                                                                              
1059     }                                                                                                                                
1060   }                                                                                                                                  
1061 
1062   // return number of elements we at leasted wanted to initialize                                                                    
1063   return rfill + overflow;                                                                                                           
1064 }                                                                                                                                    
1065 
1066 // Is it safe to remove stale entries from a dependency list?                                                                        
1067 static bool safe_to_expunge() {                                                                                                      
1068   // Since parallel GC threads can concurrently iterate over a dependency                                                            
1069   // list during safepoint, it is safe to remove entries only when                                                                   
1070   // CodeCache lock is held.                                                                                                         
1071   return CodeCache_lock->owned_by_self();                                                                                            
1072 }                                                                                                                                    
1073                                                                                                                                      
1074 void MethodHandles::add_dependent_nmethod(oop call_site, nmethod* nm) {                                                              
1075   assert_locked_or_safepoint(CodeCache_lock);                                                                                        
1076 
1077   oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);                                                          
1078   DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);                            
1079   // Try to purge stale entries on updates.                                                                                          
1080   // Since GC doesn't clean dependency contexts rooted at CallSiteContext objects,                                                   
1081   // in order to avoid memory leak, stale entries are purged whenever a dependency list                                              
1082   // is changed (both on addition and removal). Though memory reclamation is delayed,                                                
1083   // it avoids indefinite memory usage growth.                                                                                       
1084   deps.add_dependent_nmethod(nm, /*expunge_stale_entries=*/safe_to_expunge());                                                       
1085 }                                                                                                                                    
1086 
1087 void MethodHandles::remove_dependent_nmethod(oop call_site, nmethod* nm) {                                                           
1088   assert_locked_or_safepoint(CodeCache_lock);                                                                                        
1089 
1090   oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);                                                          
1091   DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);                            
1092   deps.remove_dependent_nmethod(nm, /*expunge_stale_entries=*/safe_to_expunge());                                                    
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1093 }                                                                                                                                    
1094 
1095 void MethodHandles::flush_dependent_nmethods(Handle call_site, Handle target) {                                                      
1096   assert_lock_strong(Compile_lock);                                                                                                  
1097 
1098   int marked = 0;                                                                                                                    
1099   CallSiteDepChange changes(call_site, target);                                                                                      
1100   {                                                                                                                                  
1101     NoSafepointVerifier nsv;                                                                                                         
1102     MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);                                                              
1103 
1104     oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site());                                                      
1105     DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);                          
1106     marked = deps.mark_dependent_nmethods(changes);                                                                                  
1107   }                                                                                                                                  
1108   if (marked > 0) {                                                                                                                  
1109     // At least one nmethod has been marked for deoptimization.                                                                      
1110     VM_Deoptimize op;                                                                                                                
1111     VMThread::execute(&op);                                                                                                          

1046       if (rskip > 0) {
1047         --rskip;
1048       } else if (rfill < rlimit) {
1049         Handle result(thread, results->obj_at(rfill++));
1050         if (!java_lang_invoke_MemberName::is_instance(result()))
1051           return -99;  // caller bug!
1052         CallInfo info(m, NULL, CHECK_0);
1053         oop saved = MethodHandles::init_method_MemberName(result, info);
1054         if (!oopDesc::equals(saved, result()))
1055           results->obj_at_put(rfill-1, saved);  // show saved instance to user
1056       } else if (++overflow >= overflow_limit) {
1057         match_flags = 0; break; // got tired of looking at overflow
1058       }
1059     }
1060   }
1061 
1062   // return number of elements we at leasted wanted to initialize
1063   return rfill + overflow;
1064 }
1065 








1066 void MethodHandles::add_dependent_nmethod(oop call_site, nmethod* nm) {
1067   assert_locked_or_safepoint(CodeCache_lock);
1068 
1069   oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
1070   DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1071   // Try to purge stale entries on updates.
1072   // Since GC doesn't clean dependency contexts rooted at CallSiteContext objects,
1073   // in order to avoid memory leak, stale entries are purged whenever a dependency list
1074   // is changed (both on addition and removal). Though memory reclamation is delayed,
1075   // it avoids indefinite memory usage growth.
1076   deps.add_dependent_nmethod(nm);
1077 }
1078 
1079 void MethodHandles::remove_dependent_nmethod(oop call_site, nmethod* nm) {
1080   assert_locked_or_safepoint(CodeCache_lock);
1081 
1082   oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
1083   DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1084   deps.remove_dependent_nmethod(nm);
1085 }
1086 
1087 void MethodHandles::clean_dependency_context(oop call_site) {
1088   assert_locked_or_safepoint(CodeCache_lock);
1089 
1090   oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
1091   DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1092   deps.clean_unloading_dependents();
1093 }
1094 
1095 void MethodHandles::flush_dependent_nmethods(Handle call_site, Handle target) {
1096   assert_lock_strong(Compile_lock);
1097 
1098   int marked = 0;
1099   CallSiteDepChange changes(call_site, target);
1100   {
1101     NoSafepointVerifier nsv;
1102     MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1103 
1104     oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site());
1105     DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1106     marked = deps.mark_dependent_nmethods(changes);
1107   }
1108   if (marked > 0) {
1109     // At least one nmethod has been marked for deoptimization.
1110     VM_Deoptimize op;
1111     VMThread::execute(&op);

1482   Handle ifna(THREAD, JNIHandles::resolve(ifna_jh));                                                                                 
1483   caller->constants()->                                                                                                              
1484     copy_bootstrap_arguments_at(bss_index_in_pool,                                                                                   
1485                                 start, end, buf, pos,                                                                                
1486                                 (resolve == JNI_TRUE), ifna, CHECK);                                                                 
1487 }                                                                                                                                    
1488 JVM_END                                                                                                                              
1489 
1490 // It is called by a Cleaner object which ensures that dropped CallSites properly                                                    
1491 // deallocate their dependency information.                                                                                          
1492 JVM_ENTRY(void, MHN_clearCallSiteContext(JNIEnv* env, jobject igcls, jobject context_jh)) {                                          
1493   Handle context(THREAD, JNIHandles::resolve_non_null(context_jh));                                                                  
1494   {                                                                                                                                  
1495     // Walk all nmethods depending on this call site.                                                                                
1496     MutexLocker mu1(Compile_lock, thread);                                                                                           
1497 
1498     int marked = 0;                                                                                                                  
1499     {                                                                                                                                
1500       NoSafepointVerifier nsv;                                                                                                       
1501       MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);                                                            
1502       assert(safe_to_expunge(), "removal is not safe");                                                                              
1503       DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());                      
1504       marked = deps.remove_all_dependents();                                                                                         
1505     }                                                                                                                                
1506     if (marked > 0) {                                                                                                                
1507       // At least one nmethod has been marked for deoptimization                                                                     
1508       VM_Deoptimize op;                                                                                                              
1509       VMThread::execute(&op);                                                                                                        
1510     }                                                                                                                                
1511   }                                                                                                                                  
1512 }                                                                                                                                    
1513 JVM_END                                                                                                                              
1514 
1515 /**                                                                                                                                  
1516  * Throws a java/lang/UnsupportedOperationException unconditionally.                                                                 
1517  * This is required by the specification of MethodHandle.invoke if                                                                   
1518  * invoked directly.                                                                                                                 
1519  */                                                                                                                                  
1520 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {                                                      
1521   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");        

1482   Handle ifna(THREAD, JNIHandles::resolve(ifna_jh));
1483   caller->constants()->
1484     copy_bootstrap_arguments_at(bss_index_in_pool,
1485                                 start, end, buf, pos,
1486                                 (resolve == JNI_TRUE), ifna, CHECK);
1487 }
1488 JVM_END
1489 
1490 // It is called by a Cleaner object which ensures that dropped CallSites properly
1491 // deallocate their dependency information.
1492 JVM_ENTRY(void, MHN_clearCallSiteContext(JNIEnv* env, jobject igcls, jobject context_jh)) {
1493   Handle context(THREAD, JNIHandles::resolve_non_null(context_jh));
1494   {
1495     // Walk all nmethods depending on this call site.
1496     MutexLocker mu1(Compile_lock, thread);
1497 
1498     int marked = 0;
1499     {
1500       NoSafepointVerifier nsv;
1501       MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);

1502       DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());
1503       marked = deps.remove_all_dependents();
1504     }
1505     if (marked > 0) {
1506       // At least one nmethod has been marked for deoptimization
1507       VM_Deoptimize op;
1508       VMThread::execute(&op);
1509     }
1510   }
1511 }
1512 JVM_END
1513 
1514 /**
1515  * Throws a java/lang/UnsupportedOperationException unconditionally.
1516  * This is required by the specification of MethodHandle.invoke if
1517  * invoked directly.
1518  */
1519 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1520   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");
< prev index next >