comparison src/share/vm/prims/jvmtiEnv.cpp @ 8989:e33aa14a0d8b

8211909: JDWP Transport Listener: dt_socket thread crash Reviewed-by: dholmes, jcbeyler
author fmatte
date Mon, 22 Oct 2018 02:50:45 -0400
parents 96a7391e620a
children 32bc598624bd
comparison
equal deleted inserted replaced
33:0beac833abe7 34:5e9ea6039d57
1 /* 1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2003, 2018, 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.
725 } 725 }
726 726
727 thread_objs = NEW_RESOURCE_ARRAY(Handle, nthreads); 727 thread_objs = NEW_RESOURCE_ARRAY(Handle, nthreads);
728 NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY); 728 NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY);
729 729
730 for (int i=0; i < nthreads; i++) { 730 for (int i = 0; i < nthreads; i++) {
731 thread_objs[i] = Handle(tle.get_threadObj(i)); 731 thread_objs[i] = Handle(tle.get_threadObj(i));
732 } 732 }
733 733
734 // have to make global handles outside of Threads_lock 734 // have to make global handles outside of Threads_lock
735 jthread *jthreads = new_jthreadArray(nthreads, thread_objs); 735 jthread *jthreads = new_jthreadArray(nthreads, thread_objs);
950 ThreadPriority priority; 950 ThreadPriority priority;
951 Handle thread_group; 951 Handle thread_group;
952 Handle context_class_loader; 952 Handle context_class_loader;
953 bool is_daemon; 953 bool is_daemon;
954 954
955 { MutexLocker mu(Threads_lock); 955 name = Handle(current_thread, java_lang_Thread::name(thread_obj()));
956 956 priority = java_lang_Thread::priority(thread_obj());
957 name = Handle(current_thread, java_lang_Thread::name(thread_obj())); 957 thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj()));
958 priority = java_lang_Thread::priority(thread_obj()); 958 is_daemon = java_lang_Thread::is_daemon(thread_obj());
959 thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj())); 959
960 is_daemon = java_lang_Thread::is_daemon(thread_obj()); 960 oop loader = java_lang_Thread::context_class_loader(thread_obj());
961 961 context_class_loader = Handle(current_thread, loader);
962 oop loader = java_lang_Thread::context_class_loader(thread_obj()); 962
963 context_class_loader = Handle(current_thread, loader);
964 }
965 { const char *n; 963 { const char *n;
966 964
967 if (name() != NULL) { 965 if (name() != NULL) {
968 n = java_lang_String::as_utf8_string(name()); 966 n = java_lang_String::as_utf8_string(name());
969 } else { 967 } else {
1191 typeArrayHandle name; 1189 typeArrayHandle name;
1192 Handle parent_group; 1190 Handle parent_group;
1193 bool is_daemon; 1191 bool is_daemon;
1194 ThreadPriority max_priority; 1192 ThreadPriority max_priority;
1195 1193
1196 { MutexLocker mu(Threads_lock); 1194 name = typeArrayHandle(current_thread,
1197 1195 java_lang_ThreadGroup::name(group_obj()));
1198 name = typeArrayHandle(current_thread, 1196 parent_group = Handle(current_thread, java_lang_ThreadGroup::parent(group_obj()));
1199 java_lang_ThreadGroup::name(group_obj())); 1197 is_daemon = java_lang_ThreadGroup::is_daemon(group_obj());
1200 parent_group = Handle(current_thread, java_lang_ThreadGroup::parent(group_obj())); 1198 max_priority = java_lang_ThreadGroup::maxPriority(group_obj());
1201 is_daemon = java_lang_ThreadGroup::is_daemon(group_obj());
1202 max_priority = java_lang_ThreadGroup::maxPriority(group_obj());
1203 }
1204 1199
1205 info_ptr->is_daemon = is_daemon; 1200 info_ptr->is_daemon = is_daemon;
1206 info_ptr->max_priority = max_priority; 1201 info_ptr->max_priority = max_priority;
1207 info_ptr->parent = jni_reference(parent_group); 1202 info_ptr->parent = jni_reference(parent_group);
1208 1203
1238 ResourceMark rm; 1233 ResourceMark rm;
1239 HandleMark hm; 1234 HandleMark hm;
1240 1235
1241 Handle group_hdl(current_thread, group_obj); 1236 Handle group_hdl(current_thread, group_obj);
1242 1237
1243 { MutexLocker mu(Threads_lock); 1238 {
1244 1239 ObjectLocker ol(group_hdl, current_thread);
1245 nthreads = java_lang_ThreadGroup::nthreads(group_hdl()); 1240 nthreads = java_lang_ThreadGroup::nthreads(group_hdl());
1246 ngroups = java_lang_ThreadGroup::ngroups(group_hdl()); 1241 ngroups = java_lang_ThreadGroup::ngroups(group_hdl());
1247 1242
1248 if (nthreads > 0) { 1243 if (nthreads > 0) {
1249 objArrayOop threads = java_lang_ThreadGroup::threads(group_hdl()); 1244 objArrayOop threads = java_lang_ThreadGroup::threads(group_hdl());
1250 assert(nthreads <= threads->length(), "too many threads"); 1245 assert(nthreads <= threads->length(), "too many threads");
1251 thread_objs = NEW_RESOURCE_ARRAY(Handle,nthreads); 1246 thread_objs = NEW_RESOURCE_ARRAY(Handle,nthreads);
1252 for (int i=0, j=0; i<nthreads; i++) { 1247 for (int i = 0, j = 0; i < nthreads; i++) {
1253 oop thread_obj = threads->obj_at(i); 1248 oop thread_obj = threads->obj_at(i);
1254 assert(thread_obj != NULL, "thread_obj is NULL"); 1249 assert(thread_obj != NULL, "thread_obj is NULL");
1255 JavaThread *javathread = java_lang_Thread::thread(thread_obj); 1250 JavaThread *javathread = java_lang_Thread::thread(thread_obj);
1256 // Filter out hidden java threads. 1251 // Filter out hidden java threads.
1257 if (javathread != NULL && javathread->is_hidden_from_external_view()) { 1252 if (javathread != NULL && javathread->is_hidden_from_external_view()) {
1264 } 1259 }
1265 if (ngroups > 0) { 1260 if (ngroups > 0) {
1266 objArrayOop groups = java_lang_ThreadGroup::groups(group_hdl()); 1261 objArrayOop groups = java_lang_ThreadGroup::groups(group_hdl());
1267 assert(ngroups <= groups->length(), "too many threads"); 1262 assert(ngroups <= groups->length(), "too many threads");
1268 group_objs = NEW_RESOURCE_ARRAY(Handle,ngroups); 1263 group_objs = NEW_RESOURCE_ARRAY(Handle,ngroups);
1269 for (int i=0; i<ngroups; i++) { 1264 for (int i = 0; i < ngroups; i++) {
1270 oop group_obj = groups->obj_at(i); 1265 oop group_obj = groups->obj_at(i);
1271 assert(group_obj != NULL, "group_obj != NULL"); 1266 assert(group_obj != NULL, "group_obj != NULL");
1272 group_objs[i] = Handle(current_thread, group_obj); 1267 group_objs[i] = Handle(current_thread, group_obj);
1273 } 1268 }
1274 } 1269 }
1275 } 1270 } // ThreadGroup unlocked here
1276 1271
1277 // have to make global handles outside of Threads_lock
1278 *group_count_ptr = ngroups; 1272 *group_count_ptr = ngroups;
1279 *thread_count_ptr = nthreads; 1273 *thread_count_ptr = nthreads;
1280 *threads_ptr = new_jthreadArray(nthreads, thread_objs); 1274 *threads_ptr = new_jthreadArray(nthreads, thread_objs);
1281 *groups_ptr = new_jthreadGroupArray(ngroups, group_objs); 1275 *groups_ptr = new_jthreadGroupArray(ngroups, group_objs);
1282 if ((nthreads > 0) && (*threads_ptr == NULL)) { 1276 if ((nthreads > 0) && (*threads_ptr == NULL)) {
2977 // "delete monitor" call below can work without an assertion 2971 // "delete monitor" call below can work without an assertion
2978 // failure on systems that don't like destroying synchronization 2972 // failure on systems that don't like destroying synchronization
2979 // objects that are locked. 2973 // objects that are locked.
2980 int r; 2974 int r;
2981 intptr_t recursion = rmonitor->recursions(); 2975 intptr_t recursion = rmonitor->recursions();
2982 for (intptr_t i=0; i <= recursion; i++) { 2976 for (intptr_t i = 0; i <= recursion; i++) {
2983 r = rmonitor->raw_exit(thread); 2977 r = rmonitor->raw_exit(thread);
2984 assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked"); 2978 assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked");
2985 if (r != ObjectMonitor::OM_OK) { // robustness 2979 if (r != ObjectMonitor::OM_OK) { // robustness
2986 return JVMTI_ERROR_INTERNAL; 2980 return JVMTI_ERROR_INTERNAL;
2987 } 2981 }
3393 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value); 3387 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value);
3394 if (err == JVMTI_ERROR_NONE) { 3388 if (err == JVMTI_ERROR_NONE) {
3395 strcpy(*tmp_value, key); 3389 strcpy(*tmp_value, key);
3396 } else { 3390 } else {
3397 // clean up previously allocated memory. 3391 // clean up previously allocated memory.
3398 for (int j=0; j<i; j++) { 3392 for (int j = 0; j < i; j++) {
3399 Deallocate((unsigned char*)*property_ptr+j); 3393 Deallocate((unsigned char*)*property_ptr+j);
3400 } 3394 }
3401 Deallocate((unsigned char*)property_ptr); 3395 Deallocate((unsigned char*)property_ptr);
3402 break; 3396 break;
3403 } 3397 }