Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,35 @@
*/
static jvmtiEnv* trackingEnv;

static void addPreparedClass(JNIEnv *env, jclass klass);

/*
* Invoke the callback when classes are freed.
*/
void JNICALL
cbTrackingObjectFree(jvmtiEnv* jvmti_env, jlong tag)
{
JDI_ASSERT(jvmti_env == trackingEnv);
eventHandler_synthesizeUnloadEvent((char*)jlong_to_ptr(tag), getEnv());
}

void
classTrack_addPreparedClass(JNIEnv *env_unused, jclass klass)
/*
* Invoke the callback when classes are prepared.
*/
void JNICALL
cbTrackingClassPrepare(jvmtiEnv* jvmti_env, JNIEnv *env, jthread thread, jclass klass)
{
JDI_ASSERT(jvmti_env == trackingEnv);
addPreparedClass(env, klass);
}

/*
* Add a class to the prepared class hash table.
*/
static void
addPreparedClass(JNIEnv *env, jclass klass)
{
jvmtiError error;
jvmtiEnv* env = trackingEnv;

char* signature;
error = classSignature(klass, &signature, NULL);
Expand All @@ -70,7 +85,7 @@ classTrack_addPreparedClass(JNIEnv *env_unused, jclass klass)
if (gdata && gdata->assertOn) {
// Check if already tagged.
jlong tag;
error = JVMTI_FUNC_PTR(trackingEnv, GetTag)(env, klass, &tag);
error = JVMTI_FUNC_PTR(trackingEnv, GetTag)(trackingEnv, klass, &tag);
if (error != JVMTI_ERROR_NONE) {
EXIT_ERROR(error, "Unable to GetTag with class trackingEnv");
}
Expand All @@ -83,7 +98,7 @@ classTrack_addPreparedClass(JNIEnv *env_unused, jclass klass)
}
}

error = JVMTI_FUNC_PTR(trackingEnv, SetTag)(env, klass, ptr_to_jlong(signature));
error = JVMTI_FUNC_PTR(trackingEnv, SetTag)(trackingEnv, klass, ptr_to_jlong(signature));
if (error != JVMTI_ERROR_NONE) {
jvmtiDeallocate(signature);
EXIT_ERROR(error,"SetTag");
Expand All @@ -102,15 +117,27 @@ setupEvents()
}
jvmtiEventCallbacks cb;
memset(&cb, 0, sizeof(cb));

// Setup JVMTI callbacks
cb.ObjectFree = cbTrackingObjectFree;
cb.ClassPrepare = cbTrackingClassPrepare;
error = JVMTI_FUNC_PTR(trackingEnv, SetEventCallbacks)(trackingEnv, &cb, sizeof(cb));
if (error != JVMTI_ERROR_NONE) {
return JNI_FALSE;
}

// Enable OBJECT_FREE events
error = JVMTI_FUNC_PTR(trackingEnv, SetEventNotificationMode)(trackingEnv, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL);
if (error != JVMTI_ERROR_NONE) {
return JNI_FALSE;
}

// Enable CLASS_PREPARE events
error = JVMTI_FUNC_PTR(trackingEnv, SetEventNotificationMode)(trackingEnv, JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, NULL);
if (error != JVMTI_ERROR_NONE) {
return JNI_FALSE;
}

return JNI_TRUE;
}

Expand Down Expand Up @@ -143,7 +170,7 @@ classTrack_initialize(JNIEnv *env)
jint wanted = JVMTI_CLASS_STATUS_PREPARED | JVMTI_CLASS_STATUS_ARRAY;
status = classStatus(klass);
if ((status & wanted) != 0) {
classTrack_addPreparedClass(env, klass);
addPreparedClass(env, klass);
}
}
jvmtiDeallocate(classes);
Expand Down
6 changes: 0 additions & 6 deletions src/jdk.jdwp.agent/share/native/libjdwp/classTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
struct bag *
classTrack_processUnloads(JNIEnv *env);

/*
* Add a class to the prepared class hash table.
*/
void
classTrack_addPreparedClass(JNIEnv *env, jclass klass);

/*
* Initialize class tracking.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/jdk.jdwp.agent/share/native/libjdwp/eventFilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,6 @@ enableEvents(HandlerNode *node)
case EI_THREAD_END:
case EI_VM_INIT:
case EI_VM_DEATH:
case EI_CLASS_PREPARE:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CLASS_PREPARE is no longer globally and permanently enabled, we remove it from this list so the code below can enable it as needed based on whether or not the debugger as requested CLASS_PREPARE events.

case EI_GC_FINISH:
case EI_VIRTUAL_THREAD_START:
case EI_VIRTUAL_THREAD_END:
Expand Down Expand Up @@ -1326,7 +1325,6 @@ disableEvents(HandlerNode *node)
case EI_THREAD_END:
case EI_VM_INIT:
case EI_VM_DEATH:
case EI_CLASS_PREPARE:
case EI_GC_FINISH:
case EI_VIRTUAL_THREAD_START:
case EI_VIRTUAL_THREAD_END:
Expand Down
10 changes: 0 additions & 10 deletions src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,6 @@ filterAndHandleEvent(JNIEnv *env, EventInfo *evinfo, EventIndex ei,
HandlerNode *node;
char *classname;

/* We must keep track of all classes prepared to know what's unloaded */
if (evinfo->ei == EI_CLASS_PREPARE) {
classTrack_addPreparedClass(env, evinfo->clazz);
}

Comment on lines -549 to -553
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need this hack here since the class tracking code now installs its own CLASS_PREPARE event handler.

node = getHandlerChain(ei)->first;
classname = getClassname(evinfo->clazz);

Expand Down Expand Up @@ -1509,11 +1504,6 @@ eventHandler_initialize(jbyte sessionID)
if (error != JVMTI_ERROR_NONE) {
EXIT_ERROR(error,"Can't enable thread end events");
}
error = threadControl_setEventMode(JVMTI_ENABLE,
EI_CLASS_PREPARE, NULL);
if (error != JVMTI_ERROR_NONE) {
EXIT_ERROR(error,"Can't enable class prepare events");
}
Comment on lines -1512 to -1516
Copy link
Contributor Author

@plummercj plummercj Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer permanently enable CLASS_PREPARE events here. It's now done in classTrack.c, and only impacts the JVMTIEnv that is used for class tracking.

error = threadControl_setEventMode(JVMTI_ENABLE,
EI_GC_FINISH, NULL);
if (error != JVMTI_ERROR_NONE) {
Expand Down