提交 094539c4 编写于 作者: D dcubed

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
上级 7b1df7e2
...@@ -950,7 +950,6 @@ jmethodID instanceKlass::jmethod_id_for_impl(instanceKlassHandle ik_h, methodHan ...@@ -950,7 +950,6 @@ jmethodID instanceKlass::jmethod_id_for_impl(instanceKlassHandle ik_h, methodHan
// These allocations will have to be freed if they are unused. // These allocations will have to be freed if they are unused.
// Allocate a new array of methods. // Allocate a new array of methods.
jmethodID* to_dealloc_jmeths = NULL;
jmethodID* new_jmeths = NULL; jmethodID* new_jmeths = NULL;
if (length <= idnum) { if (length <= idnum) {
// A new array will be needed (unless some other thread beats us to it) // A new array will be needed (unless some other thread beats us to it)
...@@ -961,7 +960,6 @@ jmethodID instanceKlass::jmethod_id_for_impl(instanceKlassHandle ik_h, methodHan ...@@ -961,7 +960,6 @@ jmethodID instanceKlass::jmethod_id_for_impl(instanceKlassHandle ik_h, methodHan
} }
// Allocate a new method ID. // Allocate a new method ID.
jmethodID to_dealloc_id = NULL;
jmethodID new_id = NULL; jmethodID new_id = NULL;
if (method_h->is_old() && !method_h->is_obsolete()) { if (method_h->is_old() && !method_h->is_obsolete()) {
// The method passed in is old (but not obsolete), we need to use the current version // The method passed in is old (but not obsolete), we need to use the current version
...@@ -975,40 +973,51 @@ jmethodID instanceKlass::jmethod_id_for_impl(instanceKlassHandle ik_h, methodHan ...@@ -975,40 +973,51 @@ jmethodID instanceKlass::jmethod_id_for_impl(instanceKlassHandle ik_h, methodHan
new_id = JNIHandles::make_jmethod_id(method_h); new_id = JNIHandles::make_jmethod_id(method_h);
} }
{ if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) {
// No need and unsafe to lock the JmethodIdCreation_lock at safepoint.
id = get_jmethod_id(ik_h, idnum, new_id, new_jmeths);
} else {
MutexLocker ml(JmethodIdCreation_lock); MutexLocker ml(JmethodIdCreation_lock);
id = get_jmethod_id(ik_h, idnum, new_id, new_jmeths);
}
}
return id;
}
// We must not go to a safepoint while holding this lock.
debug_only(No_Safepoint_Verifier nosafepoints;)
// Retry lookup after we got the lock jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, size_t idnum,
jmeths = ik_h->methods_jmethod_ids_acquire(); jmethodID new_id, jmethodID* new_jmeths) {
if (jmeths == NULL || (length = (size_t)jmeths[0]) <= idnum) { // Retry lookup after we got the lock or ensured we are at safepoint
if (jmeths != NULL) { jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
// We have grown the array: copy the existing entries, and delete the old array jmethodID id = NULL;
for (size_t index = 0; index < length; index++) { jmethodID to_dealloc_id = NULL;
new_jmeths[index+1] = jmeths[index+1]; jmethodID* to_dealloc_jmeths = NULL;
} size_t length;
to_dealloc_jmeths = jmeths; // using the new jmeths, deallocate the old one
} if (jmeths == NULL || (length = (size_t)jmeths[0]) <= idnum) {
ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths); if (jmeths != NULL) {
} else { // We have grown the array: copy the existing entries, and delete the old array
id = jmeths[idnum+1]; for (size_t index = 0; index < length; index++) {
to_dealloc_jmeths = new_jmeths; // using the old jmeths, deallocate the new one new_jmeths[index+1] = jmeths[index+1];
}
if (id == NULL) {
id = new_id;
jmeths[idnum+1] = id; // install the new method ID
} else {
to_dealloc_id = new_id; // the new id wasn't used, mark it for deallocation
} }
to_dealloc_jmeths = jmeths; // using the new jmeths, deallocate the old one
} }
ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths);
} else {
id = jmeths[idnum+1];
to_dealloc_jmeths = new_jmeths; // using the old jmeths, deallocate the new one
}
if (id == NULL) {
id = new_id;
jmeths[idnum+1] = id; // install the new method ID
} else {
to_dealloc_id = new_id; // the new id wasn't used, mark it for deallocation
}
// Free up unneeded or no longer needed resources // Free up unneeded or no longer needed resources
FreeHeap(to_dealloc_jmeths); FreeHeap(to_dealloc_jmeths);
if (to_dealloc_id != NULL) { if (to_dealloc_id != NULL) {
JNIHandles::destroy_jmethod_id(to_dealloc_id); JNIHandles::destroy_jmethod_id(to_dealloc_id);
}
} }
return id; return id;
} }
......
...@@ -432,6 +432,8 @@ class instanceKlass: public Klass { ...@@ -432,6 +432,8 @@ class instanceKlass: public Klass {
_enclosing_method_method_index = method_index; } _enclosing_method_method_index = method_index; }
// jmethodID support // jmethodID support
static jmethodID get_jmethod_id(instanceKlassHandle ik_h, size_t idnum,
jmethodID new_id, jmethodID* new_jmeths);
static jmethodID jmethod_id_for_impl(instanceKlassHandle ik_h, methodHandle method_h); static jmethodID jmethod_id_for_impl(instanceKlassHandle ik_h, methodHandle method_h);
jmethodID jmethod_id_or_null(methodOop method); jmethodID jmethod_id_or_null(methodOop method);
......
...@@ -1317,10 +1317,6 @@ JavaThread::~JavaThread() { ...@@ -1317,10 +1317,6 @@ JavaThread::~JavaThread() {
ThreadSafepointState::destroy(this); ThreadSafepointState::destroy(this);
if (_thread_profiler != NULL) delete _thread_profiler; if (_thread_profiler != NULL) delete _thread_profiler;
if (_thread_stat != NULL) delete _thread_stat; if (_thread_stat != NULL) delete _thread_stat;
if (jvmti_thread_state() != NULL) {
JvmtiExport::cleanup_thread(this);
}
} }
...@@ -1571,6 +1567,10 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) { ...@@ -1571,6 +1567,10 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
tlab().make_parsable(true); // retire TLAB tlab().make_parsable(true); // retire TLAB
} }
if (jvmti_thread_state() != NULL) {
JvmtiExport::cleanup_thread(this);
}
// Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
Threads::remove(this); Threads::remove(this);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册