|
37 | 37 | #include "util.h" |
38 | 38 | #include "bag.h" |
39 | 39 | #include "classTrack.h" |
| 40 | +#include "eventHandler.h" |
40 | 41 |
|
41 | 42 | #define NOT_TAGGED 0 |
42 | 43 |
|
|
46 | 47 | static jvmtiEnv* trackingEnv; |
47 | 48 |
|
48 | 49 | /* |
49 | | - * A bag containing all the deleted classes' signatures. Must be accessed under |
50 | | - * classTrackLock. |
| 50 | + * Invoke the callback when classes are freed. |
51 | 51 | */ |
52 | | -struct bag* deletedSignatures; |
53 | | - |
54 | | -/* |
55 | | - * Lock to keep integrity of deletedSignatures. |
56 | | - */ |
57 | | -static jrawMonitorID classTrackLock; |
58 | | - |
59 | | -/* |
60 | | - * Invoke the callback when classes are freed, find and record the signature |
61 | | - * in deletedSignatures. Those are only used in addPreparedClass() by the |
62 | | - * same thread. |
63 | | - */ |
64 | | -static void JNICALL |
| 52 | +void JNICALL |
65 | 53 | cbTrackingObjectFree(jvmtiEnv* jvmti_env, jlong tag) |
66 | 54 | { |
67 | | - debugMonitorEnter(classTrackLock); |
68 | | - if (deletedSignatures == NULL) { |
69 | | - debugMonitorExit(classTrackLock); |
70 | | - return; |
71 | | - } |
72 | | - *(char**)bagAdd(deletedSignatures) = (char*)jlong_to_ptr(tag); |
73 | | - |
74 | | - debugMonitorExit(classTrackLock); |
75 | | -} |
76 | | - |
77 | | -/* |
78 | | - * Called after class unloads have occurred. |
79 | | - * The signatures of classes which were unloaded are returned. |
80 | | - */ |
81 | | -struct bag * |
82 | | -classTrack_processUnloads(JNIEnv *env) |
83 | | -{ |
84 | | - if (deletedSignatures == NULL) { |
85 | | - return NULL; |
86 | | - } |
87 | | - |
88 | | - /* Allocate new bag outside classTrackLock lock to avoid deadlock. |
89 | | - * |
90 | | - * Note: jvmtiAllocate/jvmtiDeallocate() may be blocked by ongoing safepoints. |
91 | | - * It is dangerous to call them (via bagCreateBag/bagDestroyBag()) while holding monitor(s), |
92 | | - * because jvmti may post events, e.g. JVMTI_EVENT_OBJECT_FREE at safepoints and event processing |
93 | | - * code may acquire the same monitor(s), e.g. classTrackLock in cbTrackingObjectFree(), |
94 | | - * which can lead to deadlock. |
95 | | - */ |
96 | | - struct bag* new_bag = bagCreateBag(sizeof(char*), 10); |
97 | | - debugMonitorEnter(classTrackLock); |
98 | | - struct bag* deleted = deletedSignatures; |
99 | | - deletedSignatures = new_bag; |
100 | | - debugMonitorExit(classTrackLock); |
101 | | - return deleted; |
| 55 | + eventHandler_synthesizeUnloadEvent((char*)jlong_to_ptr(tag), getEnv()); |
102 | 56 | } |
103 | 57 |
|
104 | | -/* |
105 | | - * Add a class to the prepared class table. |
106 | | - */ |
107 | 58 | void |
108 | 59 | classTrack_addPreparedClass(JNIEnv *env_unused, jclass klass) |
109 | 60 | { |
@@ -162,8 +113,6 @@ setupEvents() |
162 | 113 | void |
163 | 114 | classTrack_initialize(JNIEnv *env) |
164 | 115 | { |
165 | | - deletedSignatures = NULL; |
166 | | - classTrackLock = debugMonitorCreate("Deleted class tag lock"); |
167 | 116 | trackingEnv = getSpecialJvmti(); |
168 | 117 | if (trackingEnv == NULL) { |
169 | 118 | EXIT_ERROR(AGENT_ERROR_INTERNAL, "Failed to allocate tag-tracking jvmtiEnv"); |
@@ -195,44 +144,3 @@ classTrack_initialize(JNIEnv *env) |
195 | 144 | EXIT_ERROR(error,"loaded classes array"); |
196 | 145 | } |
197 | 146 | } |
198 | | - |
199 | | -/* |
200 | | - * Called to activate class-tracking when a listener registers for EI_GC_FINISH. |
201 | | - */ |
202 | | -void |
203 | | -classTrack_activate(JNIEnv *env) |
204 | | -{ |
205 | | - // Allocate bag outside classTrackLock lock to avoid deadlock. |
206 | | - // See comments in classTrack_processUnloads() for details. |
207 | | - struct bag* new_bag = bagCreateBag(sizeof(char*), 1000); |
208 | | - debugMonitorEnter(classTrackLock); |
209 | | - deletedSignatures = new_bag; |
210 | | - debugMonitorExit(classTrackLock); |
211 | | -} |
212 | | - |
213 | | -static jboolean |
214 | | -cleanDeleted(void *signatureVoid, void *arg) |
215 | | -{ |
216 | | - char* sig = *(char**)signatureVoid; |
217 | | - jvmtiDeallocate(sig); |
218 | | - return JNI_TRUE; |
219 | | -} |
220 | | - |
221 | | -/* |
222 | | - * Called when agent detaches. |
223 | | - */ |
224 | | -void |
225 | | -classTrack_reset(void) |
226 | | -{ |
227 | | - debugMonitorEnter(classTrackLock); |
228 | | - struct bag* to_delete = deletedSignatures; |
229 | | - deletedSignatures = NULL; |
230 | | - debugMonitorExit(classTrackLock); |
231 | | - |
232 | | - // Deallocate bag outside classTrackLock to avoid deadlock. |
233 | | - // See comments in classTrack_processUnloads() for details. |
234 | | - if (to_delete != NULL) { |
235 | | - bagEnumerateOver(to_delete, cleanDeleted, NULL); |
236 | | - bagDestroyBag(to_delete); |
237 | | - } |
238 | | -} |
0 commit comments