|
|
07b2a4 |
# HG changeset patch
|
|
|
07b2a4 |
# User rkennke
|
|
|
07b2a4 |
# Date 1579704902 -3600
|
|
|
07b2a4 |
# Wed Jan 22 15:55:02 2020 +0100
|
|
|
07b2a4 |
# Node ID 63a288f3f25a5785460fa25756bd7d1e532cd874
|
|
|
07b2a4 |
# Parent ca116bb90caf334f8a78c6c763321f7c76452540
|
|
|
07b2a4 |
8227269: Slow class loading when running with JDWP
|
|
|
07b2a4 |
Reviewed-by: sspitsyn, cjplummer
|
|
|
07b2a4 |
|
|
|
07b2a4 |
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c b/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
|
|
|
07b2a4 |
--- a/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
|
|
|
07b2a4 |
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
|
|
|
07b2a4 |
@@ -22,273 +22,204 @@
|
|
|
07b2a4 |
* or visit www.oracle.com if you need additional information or have any
|
|
|
07b2a4 |
* questions.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
* This module tracks classes that have been prepared, so as to
|
|
|
07b2a4 |
- * be able to compute which have been unloaded. On VM start-up
|
|
|
07b2a4 |
- * all prepared classes are put in a table. As class prepare
|
|
|
07b2a4 |
- * events come in they are added to the table. After an unload
|
|
|
07b2a4 |
- * event or series of them, the VM can be asked for the list
|
|
|
07b2a4 |
- * of classes; this list is compared against the table keep by
|
|
|
07b2a4 |
- * this module, any classes no longer present are known to
|
|
|
07b2a4 |
- * have been unloaded.
|
|
|
07b2a4 |
- *
|
|
|
07b2a4 |
- * For efficient access, classes are keep in a hash table.
|
|
|
07b2a4 |
- * Each slot in the hash table has a linked list of KlassNode.
|
|
|
07b2a4 |
- *
|
|
|
07b2a4 |
- * Comparing current set of classes is compared with previous
|
|
|
07b2a4 |
- * set by transferring all classes in the current set into
|
|
|
07b2a4 |
- * a new table, any that remain in the old table have been
|
|
|
07b2a4 |
- * unloaded.
|
|
|
07b2a4 |
+ * be able to report which have been unloaded. On VM start-up
|
|
|
07b2a4 |
+ * and whenever new classes are loaded, all prepared classes'
|
|
|
07b2a4 |
+ * signatures are attached as JVMTI tag to the class object.
|
|
|
07b2a4 |
+ * Class unloading is tracked by registering
|
|
|
07b2a4 |
+ * ObjectFree callback on class objects. When this happens, we find
|
|
|
07b2a4 |
+ * the signature of the unloaded class(es) and report them back
|
|
|
07b2a4 |
+ * to the event handler to synthesize class-unload-events.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
|
|
|
07b2a4 |
#include "util.h"
|
|
|
07b2a4 |
#include "bag.h"
|
|
|
07b2a4 |
#include "classTrack.h"
|
|
|
07b2a4 |
|
|
|
07b2a4 |
-/* ClassTrack hash table slot count */
|
|
|
07b2a4 |
-#define CT_HASH_SLOT_COUNT 263 /* Prime which eauals 4k+3 for some k */
|
|
|
07b2a4 |
+#define NOT_TAGGED 0
|
|
|
07b2a4 |
|
|
|
07b2a4 |
-typedef struct KlassNode {
|
|
|
07b2a4 |
- jclass klass; /* weak global reference */
|
|
|
07b2a4 |
- char *signature; /* class signature */
|
|
|
07b2a4 |
- struct KlassNode *next; /* next node in this slot */
|
|
|
07b2a4 |
-} KlassNode;
|
|
|
07b2a4 |
+/*
|
|
|
07b2a4 |
+ * The JVMTI tracking env to keep track of klass tags for class-unloads
|
|
|
07b2a4 |
+ */
|
|
|
07b2a4 |
+static jvmtiEnv* trackingEnv;
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+/*
|
|
|
07b2a4 |
+ * A bag containing all the deleted classes' signatures. Must be accessed under
|
|
|
07b2a4 |
+ * classTrackLock.
|
|
|
07b2a4 |
+ */
|
|
|
07b2a4 |
+struct bag* deletedSignatures;
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
- * Hash table of prepared classes. Each entry is a pointer
|
|
|
07b2a4 |
- * to a linked list of KlassNode.
|
|
|
07b2a4 |
+ * Lock to keep integrity of deletedSignatures.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
-static KlassNode **table;
|
|
|
07b2a4 |
+static jrawMonitorID classTrackLock;
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
- * Return slot in hash table to use for this class.
|
|
|
07b2a4 |
+ * Invoke the callback when classes are freed, find and record the signature
|
|
|
07b2a4 |
+ * in deletedSignatures. Those are only used in addPreparedClass() by the
|
|
|
07b2a4 |
+ * same thread.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
-static jint
|
|
|
07b2a4 |
-hashKlass(jclass klass)
|
|
|
07b2a4 |
+static void JNICALL
|
|
|
07b2a4 |
+cbTrackingObjectFree(jvmtiEnv* jvmti_env, jlong tag)
|
|
|
07b2a4 |
{
|
|
|
07b2a4 |
- jint hashCode = objectHashCode(klass);
|
|
|
07b2a4 |
- return abs(hashCode) % CT_HASH_SLOT_COUNT;
|
|
|
07b2a4 |
+ debugMonitorEnter(classTrackLock);
|
|
|
07b2a4 |
+ if (deletedSignatures == NULL) {
|
|
|
07b2a4 |
+ debugMonitorExit(classTrackLock);
|
|
|
07b2a4 |
+ return;
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
+ *(char**)bagAdd(deletedSignatures) = (char*)tag;
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+ debugMonitorExit(classTrackLock);
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
- * Transfer a node (which represents klass) from the current
|
|
|
07b2a4 |
- * table to the new table.
|
|
|
07b2a4 |
- */
|
|
|
07b2a4 |
-static void
|
|
|
07b2a4 |
-transferClass(JNIEnv *env, jclass klass, KlassNode **newTable) {
|
|
|
07b2a4 |
- jint slot = hashKlass(klass);
|
|
|
07b2a4 |
- KlassNode **head = &table[slot];
|
|
|
07b2a4 |
- KlassNode **newHead = &newTable[slot];
|
|
|
07b2a4 |
- KlassNode **nodePtr;
|
|
|
07b2a4 |
- KlassNode *node;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* Search the node list of the current table for klass */
|
|
|
07b2a4 |
- for (nodePtr = head; node = *nodePtr, node != NULL; nodePtr = &(node->next)) {
|
|
|
07b2a4 |
- if (isSameObject(env, klass, node->klass)) {
|
|
|
07b2a4 |
- /* Match found transfer node */
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* unlink from old list */
|
|
|
07b2a4 |
- *nodePtr = node->next;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* insert in new list */
|
|
|
07b2a4 |
- node->next = *newHead;
|
|
|
07b2a4 |
- *newHead = node;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- return;
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* we haven't found the class, only unloads should have happenned,
|
|
|
07b2a4 |
- * so the only reason a class should not have been found is
|
|
|
07b2a4 |
- * that it is not prepared yet, in which case we don't want it.
|
|
|
07b2a4 |
- * Asset that the above is true.
|
|
|
07b2a4 |
- */
|
|
|
07b2a4 |
-/**** the HotSpot VM doesn't create prepare events for some internal classes ***
|
|
|
07b2a4 |
- JDI_ASSERT_MSG((classStatus(klass) &
|
|
|
07b2a4 |
- (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY))==0,
|
|
|
07b2a4 |
- classSignature(klass));
|
|
|
07b2a4 |
-***/
|
|
|
07b2a4 |
-}
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
-/*
|
|
|
07b2a4 |
- * Delete a hash table of classes.
|
|
|
07b2a4 |
- * The signatures of classes in the table are returned.
|
|
|
07b2a4 |
- */
|
|
|
07b2a4 |
-static struct bag *
|
|
|
07b2a4 |
-deleteTable(JNIEnv *env, KlassNode *oldTable[])
|
|
|
07b2a4 |
-{
|
|
|
07b2a4 |
- struct bag *signatures = bagCreateBag(sizeof(char*), 10);
|
|
|
07b2a4 |
- jint slot;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- if (signatures == NULL) {
|
|
|
07b2a4 |
- EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"signatures");
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- for (slot = 0; slot < CT_HASH_SLOT_COUNT; slot++) {
|
|
|
07b2a4 |
- KlassNode *node = oldTable[slot];
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- while (node != NULL) {
|
|
|
07b2a4 |
- KlassNode *next;
|
|
|
07b2a4 |
- char **sigSpot;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* Add signature to the signature bag */
|
|
|
07b2a4 |
- sigSpot = bagAdd(signatures);
|
|
|
07b2a4 |
- if (sigSpot == NULL) {
|
|
|
07b2a4 |
- EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"signature bag");
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- *sigSpot = node->signature;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* Free weak ref and the node itself */
|
|
|
07b2a4 |
- JNI_FUNC_PTR(env,DeleteWeakGlobalRef)(env, node->klass);
|
|
|
07b2a4 |
- next = node->next;
|
|
|
07b2a4 |
- jvmtiDeallocate(node);
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- node = next;
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- jvmtiDeallocate(oldTable);
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- return signatures;
|
|
|
07b2a4 |
-}
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
-/*
|
|
|
07b2a4 |
- * Called after class unloads have occurred. Creates a new hash table
|
|
|
07b2a4 |
- * of currently loaded prepared classes.
|
|
|
07b2a4 |
- * The signatures of classes which were unloaded (not present in the
|
|
|
07b2a4 |
- * new table) are returned.
|
|
|
07b2a4 |
+ * Called after class unloads have occurred.
|
|
|
07b2a4 |
+ * The signatures of classes which were unloaded are returned.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
struct bag *
|
|
|
07b2a4 |
classTrack_processUnloads(JNIEnv *env)
|
|
|
07b2a4 |
{
|
|
|
07b2a4 |
- KlassNode **newTable;
|
|
|
07b2a4 |
- struct bag *unloadedSignatures;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- unloadedSignatures = NULL;
|
|
|
07b2a4 |
- newTable = jvmtiAllocate(CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
|
|
|
07b2a4 |
- if (newTable == NULL) {
|
|
|
07b2a4 |
- EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY, "classTrack table");
|
|
|
07b2a4 |
- } else {
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- (void)memset(newTable, 0, CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- WITH_LOCAL_REFS(env, 1) {
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- jint classCount;
|
|
|
07b2a4 |
- jclass *classes;
|
|
|
07b2a4 |
- jvmtiError error;
|
|
|
07b2a4 |
- int i;
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- error = allLoadedClasses(&classes, &classCount);
|
|
|
07b2a4 |
- if ( error != JVMTI_ERROR_NONE ) {
|
|
|
07b2a4 |
- jvmtiDeallocate(newTable);
|
|
|
07b2a4 |
- EXIT_ERROR(error,"loaded classes");
|
|
|
07b2a4 |
- } else {
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* Transfer each current class into the new table */
|
|
|
07b2a4 |
- for (i=0; i
|
|
|
07b2a4 |
- jclass klass = classes[i];
|
|
|
07b2a4 |
- transferClass(env, klass, newTable);
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- jvmtiDeallocate(classes);
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- /* Delete old table, install new one */
|
|
|
07b2a4 |
- unloadedSignatures = deleteTable(env, table);
|
|
|
07b2a4 |
- table = newTable;
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- } END_WITH_LOCAL_REFS(env)
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
+ debugMonitorEnter(classTrackLock);
|
|
|
07b2a4 |
+ if (deletedSignatures == NULL) {
|
|
|
07b2a4 |
+ // Class tracking not initialized, nobody's interested.
|
|
|
07b2a4 |
+ debugMonitorExit(classTrackLock);
|
|
|
07b2a4 |
+ return NULL;
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- return unloadedSignatures;
|
|
|
07b2a4 |
+ struct bag* deleted = deletedSignatures;
|
|
|
07b2a4 |
+ deletedSignatures = bagCreateBag(sizeof(char*), 10);
|
|
|
07b2a4 |
+ debugMonitorExit(classTrackLock);
|
|
|
07b2a4 |
+ return deleted;
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
- * Add a class to the prepared class hash table.
|
|
|
07b2a4 |
- * Assumes no duplicates.
|
|
|
07b2a4 |
+ * Add a class to the prepared class table.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
void
|
|
|
07b2a4 |
-classTrack_addPreparedClass(JNIEnv *env, jclass klass)
|
|
|
07b2a4 |
+classTrack_addPreparedClass(JNIEnv *env_unused, jclass klass)
|
|
|
07b2a4 |
{
|
|
|
07b2a4 |
- jint slot = hashKlass(klass);
|
|
|
07b2a4 |
- KlassNode **head = &table[slot];
|
|
|
07b2a4 |
- KlassNode *node;
|
|
|
07b2a4 |
jvmtiError error;
|
|
|
07b2a4 |
+ jvmtiEnv* env = trackingEnv;
|
|
|
07b2a4 |
|
|
|
07b2a4 |
- if (gdata->assertOn) {
|
|
|
07b2a4 |
- /* Check this is not a duplicate */
|
|
|
07b2a4 |
- for (node = *head; node != NULL; node = node->next) {
|
|
|
07b2a4 |
- if (isSameObject(env, klass, node->klass)) {
|
|
|
07b2a4 |
- JDI_ASSERT_FAILED("Attempting to insert duplicate class");
|
|
|
07b2a4 |
- break;
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
+ if (gdata && gdata->assertOn) {
|
|
|
07b2a4 |
+ // Check this is not already tagged.
|
|
|
07b2a4 |
+ jlong tag;
|
|
|
07b2a4 |
+ error = JVMTI_FUNC_PTR(trackingEnv, GetTag)(env, klass, &tag;;
|
|
|
07b2a4 |
+ if (error != JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
+ EXIT_ERROR(error, "Unable to GetTag with class trackingEnv");
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
+ JDI_ASSERT(tag == NOT_TAGGED);
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
- node = jvmtiAllocate(sizeof(KlassNode));
|
|
|
07b2a4 |
- if (node == NULL) {
|
|
|
07b2a4 |
- EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"KlassNode");
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- error = classSignature(klass, &(node->signature), NULL);
|
|
|
07b2a4 |
+ char* signature;
|
|
|
07b2a4 |
+ error = classSignature(klass, &signature, NULL);
|
|
|
07b2a4 |
if (error != JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
- jvmtiDeallocate(node);
|
|
|
07b2a4 |
EXIT_ERROR(error,"signature");
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
- if ((node->klass = JNI_FUNC_PTR(env,NewWeakGlobalRef)(env, klass)) == NULL) {
|
|
|
07b2a4 |
- jvmtiDeallocate(node->signature);
|
|
|
07b2a4 |
- jvmtiDeallocate(node);
|
|
|
07b2a4 |
- EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"NewWeakGlobalRef");
|
|
|
07b2a4 |
+ error = JVMTI_FUNC_PTR(trackingEnv, SetTag)(env, klass, (jlong)signature);
|
|
|
07b2a4 |
+ if (error != JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
+ jvmtiDeallocate(signature);
|
|
|
07b2a4 |
+ EXIT_ERROR(error,"SetTag");
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
+}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
- /* Insert the new node */
|
|
|
07b2a4 |
- node->next = *head;
|
|
|
07b2a4 |
- *head = node;
|
|
|
07b2a4 |
+static jboolean
|
|
|
07b2a4 |
+setupEvents()
|
|
|
07b2a4 |
+{
|
|
|
07b2a4 |
+ jvmtiCapabilities caps;
|
|
|
07b2a4 |
+ memset(&caps, 0, sizeof(caps));
|
|
|
07b2a4 |
+ caps.can_generate_object_free_events = 1;
|
|
|
07b2a4 |
+ jvmtiError error = JVMTI_FUNC_PTR(trackingEnv, AddCapabilities)(trackingEnv, &caps);
|
|
|
07b2a4 |
+ if (error != JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
+ return JNI_FALSE;
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
+ jvmtiEventCallbacks cb;
|
|
|
07b2a4 |
+ memset(&cb, 0, sizeof(cb));
|
|
|
07b2a4 |
+ cb.ObjectFree = cbTrackingObjectFree;
|
|
|
07b2a4 |
+ error = JVMTI_FUNC_PTR(trackingEnv, SetEventCallbacks)(trackingEnv, &cb, sizeof(cb));
|
|
|
07b2a4 |
+ if (error != JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
+ return JNI_FALSE;
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
+ error = JVMTI_FUNC_PTR(trackingEnv, SetEventNotificationMode)(trackingEnv, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL);
|
|
|
07b2a4 |
+ if (error != JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
+ return JNI_FALSE;
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
+ return JNI_TRUE;
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
- * Called once to build the initial prepared class hash table.
|
|
|
07b2a4 |
+ * Called once to initialize class-tracking.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
void
|
|
|
07b2a4 |
classTrack_initialize(JNIEnv *env)
|
|
|
07b2a4 |
{
|
|
|
07b2a4 |
- WITH_LOCAL_REFS(env, 1) {
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- jint classCount;
|
|
|
07b2a4 |
- jclass *classes;
|
|
|
07b2a4 |
- jvmtiError error;
|
|
|
07b2a4 |
- jint i;
|
|
|
07b2a4 |
+ deletedSignatures = NULL;
|
|
|
07b2a4 |
+ classTrackLock = debugMonitorCreate("Deleted class tag lock");
|
|
|
07b2a4 |
+ trackingEnv = getSpecialJvmti();
|
|
|
07b2a4 |
+ if (trackingEnv == NULL) {
|
|
|
07b2a4 |
+ EXIT_ERROR(AGENT_ERROR_INTERNAL, "Failed to allocate tag-tracking jvmtiEnv");
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
|
|
|
07b2a4 |
- error = allLoadedClasses(&classes, &classCount);
|
|
|
07b2a4 |
- if ( error == JVMTI_ERROR_NONE ) {
|
|
|
07b2a4 |
- table = jvmtiAllocate(CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
|
|
|
07b2a4 |
- if (table != NULL) {
|
|
|
07b2a4 |
- (void)memset(table, 0, CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
|
|
|
07b2a4 |
- for (i=0; i
|
|
|
07b2a4 |
- jclass klass = classes[i];
|
|
|
07b2a4 |
- jint status;
|
|
|
07b2a4 |
- jint wanted =
|
|
|
07b2a4 |
- (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY);
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+ if (!setupEvents()) {
|
|
|
07b2a4 |
+ EXIT_ERROR(AGENT_ERROR_INTERNAL, "Unable to setup ObjectFree tracking");
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
|
|
|
07b2a4 |
- /* We only want prepared classes and arrays */
|
|
|
07b2a4 |
- status = classStatus(klass);
|
|
|
07b2a4 |
- if ( (status & wanted) != 0 ) {
|
|
|
07b2a4 |
- classTrack_addPreparedClass(env, klass);
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- }
|
|
|
07b2a4 |
- } else {
|
|
|
07b2a4 |
- jvmtiDeallocate(classes);
|
|
|
07b2a4 |
- EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"KlassNode");
|
|
|
07b2a4 |
+ jint classCount;
|
|
|
07b2a4 |
+ jclass *classes;
|
|
|
07b2a4 |
+ jvmtiError error;
|
|
|
07b2a4 |
+ jint i;
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+ error = allLoadedClasses(&classes, &classCount);
|
|
|
07b2a4 |
+ if ( error == JVMTI_ERROR_NONE ) {
|
|
|
07b2a4 |
+ for (i = 0; i < classCount; i++) {
|
|
|
07b2a4 |
+ jclass klass = classes[i];
|
|
|
07b2a4 |
+ jint status;
|
|
|
07b2a4 |
+ jint wanted = JVMTI_CLASS_STATUS_PREPARED | JVMTI_CLASS_STATUS_ARRAY;
|
|
|
07b2a4 |
+ status = classStatus(klass);
|
|
|
07b2a4 |
+ if ((status & wanted) != 0) {
|
|
|
07b2a4 |
+ classTrack_addPreparedClass(env, klass);
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
- jvmtiDeallocate(classes);
|
|
|
07b2a4 |
- } else {
|
|
|
07b2a4 |
- EXIT_ERROR(error,"loaded classes array");
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
- } END_WITH_LOCAL_REFS(env)
|
|
|
07b2a4 |
-
|
|
|
07b2a4 |
+ jvmtiDeallocate(classes);
|
|
|
07b2a4 |
+ } else {
|
|
|
07b2a4 |
+ EXIT_ERROR(error,"loaded classes array");
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
+/*
|
|
|
07b2a4 |
+ * Called to activate class-tracking when a listener registers for EI_GC_FINISH.
|
|
|
07b2a4 |
+ */
|
|
|
07b2a4 |
+void
|
|
|
07b2a4 |
+classTrack_activate(JNIEnv *env)
|
|
|
07b2a4 |
+{
|
|
|
07b2a4 |
+ debugMonitorEnter(classTrackLock);
|
|
|
07b2a4 |
+ deletedSignatures = bagCreateBag(sizeof(char*), 1000);
|
|
|
07b2a4 |
+ debugMonitorExit(classTrackLock);
|
|
|
07b2a4 |
+}
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+static jboolean
|
|
|
07b2a4 |
+cleanDeleted(void *signatureVoid, void *arg)
|
|
|
07b2a4 |
+{
|
|
|
07b2a4 |
+ char* sig = *(char**)signatureVoid;
|
|
|
07b2a4 |
+ jvmtiDeallocate(sig);
|
|
|
07b2a4 |
+ return JNI_TRUE;
|
|
|
07b2a4 |
+}
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+/*
|
|
|
07b2a4 |
+ * Called when agent detaches.
|
|
|
07b2a4 |
+ */
|
|
|
07b2a4 |
void
|
|
|
07b2a4 |
classTrack_reset(void)
|
|
|
07b2a4 |
{
|
|
|
07b2a4 |
+ debugMonitorEnter(classTrackLock);
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+ if (deletedSignatures != NULL) {
|
|
|
07b2a4 |
+ bagEnumerateOver(deletedSignatures, cleanDeleted, NULL);
|
|
|
07b2a4 |
+ bagDestroyBag(deletedSignatures);
|
|
|
07b2a4 |
+ deletedSignatures = NULL;
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+ debugMonitorExit(classTrackLock);
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.h b/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.h
|
|
|
07b2a4 |
--- a/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.h
|
|
|
07b2a4 |
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.h
|
|
|
07b2a4 |
@@ -46,6 +46,12 @@
|
|
|
07b2a4 |
classTrack_initialize(JNIEnv *env);
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/*
|
|
|
07b2a4 |
+ * Activates class tracking.
|
|
|
07b2a4 |
+ */
|
|
|
07b2a4 |
+void
|
|
|
07b2a4 |
+classTrack_activate(JNIEnv *env);
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
+/*
|
|
|
07b2a4 |
* Reset class tracking.
|
|
|
07b2a4 |
*/
|
|
|
07b2a4 |
void
|
|
|
07b2a4 |
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c b/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
|
|
|
07b2a4 |
--- a/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
|
|
|
07b2a4 |
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
|
|
|
07b2a4 |
@@ -1625,6 +1625,9 @@
|
|
|
07b2a4 |
|
|
|
07b2a4 |
node->handlerID = external? ++requestIdCounter : 0;
|
|
|
07b2a4 |
error = eventFilterRestricted_install(node);
|
|
|
07b2a4 |
+ if (node->ei == EI_GC_FINISH) {
|
|
|
07b2a4 |
+ classTrack_activate(getEnv());
|
|
|
07b2a4 |
+ }
|
|
|
07b2a4 |
if (error == JVMTI_ERROR_NONE) {
|
|
|
07b2a4 |
insert(getHandlerChain(node->ei), node);
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/util.c b/src/jdk.jdwp.agent/share/native/libjdwp/util.c
|
|
|
07b2a4 |
--- a/src/jdk.jdwp.agent/share/native/libjdwp/util.c
|
|
|
07b2a4 |
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/util.c
|
|
|
07b2a4 |
@@ -1742,7 +1742,7 @@
|
|
|
07b2a4 |
}
|
|
|
07b2a4 |
|
|
|
07b2a4 |
/* Get the jvmti environment to be used with tags */
|
|
|
07b2a4 |
-static jvmtiEnv *
|
|
|
07b2a4 |
+jvmtiEnv *
|
|
|
07b2a4 |
getSpecialJvmti(void)
|
|
|
07b2a4 |
{
|
|
|
07b2a4 |
jvmtiEnv *jvmti;
|
|
|
07b2a4 |
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/util.h b/src/jdk.jdwp.agent/share/native/libjdwp/util.h
|
|
|
07b2a4 |
--- a/src/jdk.jdwp.agent/share/native/libjdwp/util.h
|
|
|
07b2a4 |
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/util.h
|
|
|
07b2a4 |
@@ -414,4 +414,6 @@
|
|
|
07b2a4 |
void saveGlobalRef(JNIEnv *env, jobject obj, jobject *pobj);
|
|
|
07b2a4 |
void tossGlobalRef(JNIEnv *env, jobject *pobj);
|
|
|
07b2a4 |
|
|
|
07b2a4 |
+jvmtiEnv* getSpecialJvmti(void);
|
|
|
07b2a4 |
+
|
|
|
07b2a4 |
#endif
|