Mercurial > hg > truffle
comparison src/share/vm/oops/instanceKlass.cpp @ 49:31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
Summary: (for Serguei) Clean up use of No_Safepoint_Verifier in JVM TI
Reviewed-by: dcubed
author | dcubed |
---|---|
date | Wed, 12 Mar 2008 18:09:34 -0700 |
parents | 2c106685d6d0 |
children | 75b0f3cb1943 |
comparison
equal
deleted
inserted
replaced
48:d8b3ef7ee3e5 | 49:31000d79ec71 |
---|---|
948 | 948 |
949 // Do all the safepointing things (allocations) before grabbing the lock. | 949 // Do all the safepointing things (allocations) before grabbing the lock. |
950 // These allocations will have to be freed if they are unused. | 950 // These allocations will have to be freed if they are unused. |
951 | 951 |
952 // Allocate a new array of methods. | 952 // Allocate a new array of methods. |
953 jmethodID* to_dealloc_jmeths = NULL; | |
954 jmethodID* new_jmeths = NULL; | 953 jmethodID* new_jmeths = NULL; |
955 if (length <= idnum) { | 954 if (length <= idnum) { |
956 // A new array will be needed (unless some other thread beats us to it) | 955 // A new array will be needed (unless some other thread beats us to it) |
957 size_t size = MAX2(idnum+1, (size_t)ik_h->idnum_allocated_count()); | 956 size_t size = MAX2(idnum+1, (size_t)ik_h->idnum_allocated_count()); |
958 new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1); | 957 new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1); |
959 memset(new_jmeths, 0, (size+1)*sizeof(jmethodID)); | 958 memset(new_jmeths, 0, (size+1)*sizeof(jmethodID)); |
960 new_jmeths[0] =(jmethodID)size; // array size held in the first element | 959 new_jmeths[0] =(jmethodID)size; // array size held in the first element |
961 } | 960 } |
962 | 961 |
963 // Allocate a new method ID. | 962 // Allocate a new method ID. |
964 jmethodID to_dealloc_id = NULL; | |
965 jmethodID new_id = NULL; | 963 jmethodID new_id = NULL; |
966 if (method_h->is_old() && !method_h->is_obsolete()) { | 964 if (method_h->is_old() && !method_h->is_obsolete()) { |
967 // The method passed in is old (but not obsolete), we need to use the current version | 965 // The method passed in is old (but not obsolete), we need to use the current version |
968 methodOop current_method = ik_h->method_with_idnum((int)idnum); | 966 methodOop current_method = ik_h->method_with_idnum((int)idnum); |
969 assert(current_method != NULL, "old and but not obsolete, so should exist"); | 967 assert(current_method != NULL, "old and but not obsolete, so should exist"); |
973 // It is the current version of the method or an obsolete method, | 971 // It is the current version of the method or an obsolete method, |
974 // use the version passed in | 972 // use the version passed in |
975 new_id = JNIHandles::make_jmethod_id(method_h); | 973 new_id = JNIHandles::make_jmethod_id(method_h); |
976 } | 974 } |
977 | 975 |
978 { | 976 if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) { |
977 // No need and unsafe to lock the JmethodIdCreation_lock at safepoint. | |
978 id = get_jmethod_id(ik_h, idnum, new_id, new_jmeths); | |
979 } else { | |
979 MutexLocker ml(JmethodIdCreation_lock); | 980 MutexLocker ml(JmethodIdCreation_lock); |
980 | 981 id = get_jmethod_id(ik_h, idnum, new_id, new_jmeths); |
981 // We must not go to a safepoint while holding this lock. | 982 } |
982 debug_only(No_Safepoint_Verifier nosafepoints;) | 983 } |
983 | 984 return id; |
984 // Retry lookup after we got the lock | 985 } |
985 jmeths = ik_h->methods_jmethod_ids_acquire(); | 986 |
986 if (jmeths == NULL || (length = (size_t)jmeths[0]) <= idnum) { | 987 |
987 if (jmeths != NULL) { | 988 jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, size_t idnum, |
988 // We have grown the array: copy the existing entries, and delete the old array | 989 jmethodID new_id, jmethodID* new_jmeths) { |
989 for (size_t index = 0; index < length; index++) { | 990 // Retry lookup after we got the lock or ensured we are at safepoint |
990 new_jmeths[index+1] = jmeths[index+1]; | 991 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
991 } | 992 jmethodID id = NULL; |
992 to_dealloc_jmeths = jmeths; // using the new jmeths, deallocate the old one | 993 jmethodID to_dealloc_id = NULL; |
993 } | 994 jmethodID* to_dealloc_jmeths = NULL; |
994 ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths); | 995 size_t length; |
995 } else { | 996 |
996 id = jmeths[idnum+1]; | 997 if (jmeths == NULL || (length = (size_t)jmeths[0]) <= idnum) { |
997 to_dealloc_jmeths = new_jmeths; // using the old jmeths, deallocate the new one | 998 if (jmeths != NULL) { |
998 } | 999 // We have grown the array: copy the existing entries, and delete the old array |
999 if (id == NULL) { | 1000 for (size_t index = 0; index < length; index++) { |
1000 id = new_id; | 1001 new_jmeths[index+1] = jmeths[index+1]; |
1001 jmeths[idnum+1] = id; // install the new method ID | 1002 } |
1002 } else { | 1003 to_dealloc_jmeths = jmeths; // using the new jmeths, deallocate the old one |
1003 to_dealloc_id = new_id; // the new id wasn't used, mark it for deallocation | 1004 } |
1004 } | 1005 ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths); |
1005 } | 1006 } else { |
1006 | 1007 id = jmeths[idnum+1]; |
1007 // Free up unneeded or no longer needed resources | 1008 to_dealloc_jmeths = new_jmeths; // using the old jmeths, deallocate the new one |
1008 FreeHeap(to_dealloc_jmeths); | 1009 } |
1009 if (to_dealloc_id != NULL) { | 1010 if (id == NULL) { |
1010 JNIHandles::destroy_jmethod_id(to_dealloc_id); | 1011 id = new_id; |
1011 } | 1012 jmeths[idnum+1] = id; // install the new method ID |
1013 } else { | |
1014 to_dealloc_id = new_id; // the new id wasn't used, mark it for deallocation | |
1015 } | |
1016 | |
1017 // Free up unneeded or no longer needed resources | |
1018 FreeHeap(to_dealloc_jmeths); | |
1019 if (to_dealloc_id != NULL) { | |
1020 JNIHandles::destroy_jmethod_id(to_dealloc_id); | |
1012 } | 1021 } |
1013 return id; | 1022 return id; |
1014 } | 1023 } |
1015 | 1024 |
1016 | 1025 |