in modules/jpda/src/main/native/jdwp/common/agent/core/RequestManager.cpp [1091:1160]
void JNICALL RequestManager::HandleClassUnload(jvmtiEnv* jvmti, JNIEnv* jni,
jthread thread, jclass cls)
{
JDWP_TRACE_ENTRY("HandleClassUnload(" << jvmti << ',' << jni << ',' << thread << ',' << cls << ')');
try {
jvmtiError err;
EventInfo eInfo;
memset(&eInfo, 0, sizeof(eInfo));
eInfo.kind = JDWP_EVENT_CLASS_UNLOAD;
eInfo.thread = thread;
eInfo.cls = cls;
JVMTI_TRACE(err, GetJvmtiEnv()->GetClassSignature(eInfo.cls,
&eInfo.signature, 0));
JvmtiAutoFree jafSignature(eInfo.signature);
if (err != JVMTI_ERROR_NONE) {
throw AgentException(err);
}
#ifndef NDEBUG
if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
jvmtiThreadInfo info;
JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &info));
JDWP_TRACE_EVENT("CLASS_UNLOAD event:"
<< " class=" << JDWP_CHECK_NULL(eInfo.signature)
<< " thread=" << JDWP_CHECK_NULL(info.name));
}
#endif // NDEBUG
jint eventCount = 0;
RequestID *eventList = 0;
jdwpSuspendPolicy sp = JDWP_SUSPEND_NONE;
GetRequestManager().GenerateEvents(jni, eInfo, eventCount, eventList, sp);
AgentAutoFree aafEL(eventList JDWP_FILE_LINE);
bool isAgent = GetThreadManager().IsAgentThread(jni, thread);
if (isAgent) {
eInfo.thread = 0;
sp = JDWP_SUSPEND_NONE;
}
// post generated events
if (eventCount > 0) {
jdwpTypeTag typeTag = GetClassManager().GetJdwpTypeTag(cls);
jint status = 0;
JVMTI_TRACE(err, GetJvmtiEnv()->GetClassStatus(cls, &status));
if (err != JVMTI_ERROR_NONE) {
throw AgentException(err);
}
EventComposer *ec = new EventComposer(GetEventDispatcher().NewId(),
JDWP_COMMAND_SET_EVENT, JDWP_COMMAND_E_COMPOSITE, sp);
ec->event.WriteInt(eventCount);
for (jint i = 0; i < eventCount; i++) {
ec->event.WriteByte(JDWP_EVENT_CLASS_UNLOAD);
ec->event.WriteInt(eventList[i]);
ec->WriteThread(jni, thread);
ec->event.WriteByte(typeTag);
ec->event.WriteReferenceTypeID(jni, cls);
ec->event.WriteString(eInfo.signature);
ec->event.WriteInt(status);
}
JDWP_TRACE_EVENT("HandleClassUnload: post set of " << eventCount << " events");
GetEventDispatcher().PostEventSet(jni, ec, JDWP_EVENT_CLASS_UNLOAD);
}
} catch (AgentException& e) {
JDWP_INFO("JDWP error in CLASS_UNLOAD: " << e.what() << " [" << e.ErrCode() << "]");
}
}