src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
author rkennke
Fri, 12 Oct 2018 16:25:24 +0200
changeset 52107 0c1e44da019c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8212053: A few more missing object equals barriers Reviewed-by: shade, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * This module tracks classes that have been prepared, so as to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * be able to compute which have been unloaded.  On VM start-up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * all prepared classes are put in a table.  As class prepare
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * events come in they are added to the table.  After an unload
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * event or series of them, the VM can be asked for the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * of classes; this list is compared against the table keep by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * this module, any classes no longer present are known to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * have been unloaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * For efficient access, classes are keep in a hash table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Each slot in the hash table has a linked list of KlassNode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Comparing current set of classes is compared with previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * set by transferring all classes in the current set into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * a new table, any that remain in the old table have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * unloaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "bag.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "classTrack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/* ClassTrack hash table slot count */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define CT_HASH_SLOT_COUNT 263    /* Prime which eauals 4k+3 for some k */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
typedef struct KlassNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    jclass klass;            /* weak global reference */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    char *signature;         /* class signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    struct KlassNode *next;  /* next node in this slot */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
} KlassNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Hash table of prepared classes.  Each entry is a pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * to a linked list of KlassNode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static KlassNode **table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Return slot in hash table to use for this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
hashKlass(jclass klass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    jint hashCode = objectHashCode(klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    return abs(hashCode) % CT_HASH_SLOT_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Transfer a node (which represents klass) from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * table to the new table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
transferClass(JNIEnv *env, jclass klass, KlassNode **newTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    jint slot = hashKlass(klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    KlassNode **head = &table[slot];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    KlassNode **newHead = &newTable[slot];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    KlassNode **nodePtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    KlassNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /* Search the node list of the current table for klass */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    for (nodePtr = head; node = *nodePtr, node != NULL; nodePtr = &(node->next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (isSameObject(env, klass, node->klass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            /* Match found transfer node */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            /* unlink from old list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            *nodePtr = node->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            /* insert in new list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            node->next = *newHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            *newHead = node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /* we haven't found the class, only unloads should have happenned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * so the only reason a class should not have been found is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * that it is not prepared yet, in which case we don't want it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Asset that the above is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
/**** the HotSpot VM doesn't create prepare events for some internal classes ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    JDI_ASSERT_MSG((classStatus(klass) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY))==0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
               classSignature(klass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Delete a hash table of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * The signatures of classes in the table are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
static struct bag *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
deleteTable(JNIEnv *env, KlassNode *oldTable[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    struct bag *signatures = bagCreateBag(sizeof(char*), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    jint slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    if (signatures == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"signatures");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    for (slot = 0; slot < CT_HASH_SLOT_COUNT; slot++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        KlassNode *node = oldTable[slot];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            KlassNode *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            char **sigSpot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            /* Add signature to the signature bag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            sigSpot = bagAdd(signatures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            if (sigSpot == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"signature bag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            *sigSpot = node->signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            /* Free weak ref and the node itself */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            JNI_FUNC_PTR(env,DeleteWeakGlobalRef)(env, node->klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            next = node->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            jvmtiDeallocate(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            node = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    jvmtiDeallocate(oldTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return signatures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Called after class unloads have occurred.  Creates a new hash table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * of currently loaded prepared classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * The signatures of classes which were unloaded (not present in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * new table) are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
struct bag *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
classTrack_processUnloads(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    KlassNode **newTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    struct bag *unloadedSignatures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    unloadedSignatures = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    newTable = jvmtiAllocate(CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    if (newTable == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY, "classTrack table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        (void)memset(newTable, 0, CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            jint classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            jclass *classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            error = allLoadedClasses(&classes, &classCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                jvmtiDeallocate(newTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                EXIT_ERROR(error,"loaded classes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                /* Transfer each current class into the new table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                for (i=0; i<classCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    jclass klass = classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    transferClass(env, klass, newTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                jvmtiDeallocate(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                /* Delete old table, install new one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                unloadedSignatures = deleteTable(env, table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                table = newTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } END_WITH_LOCAL_REFS(env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    return unloadedSignatures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * Add a class to the prepared class hash table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * Assumes no duplicates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
classTrack_addPreparedClass(JNIEnv *env, jclass klass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    jint slot = hashKlass(klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    KlassNode **head = &table[slot];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    KlassNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    if (gdata->assertOn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        /* Check this is not a duplicate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        for (node = *head; node != NULL; node = node->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (isSameObject(env, klass, node->klass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                JDI_ASSERT_FAILED("Attempting to insert duplicate class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    node = jvmtiAllocate(sizeof(KlassNode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    if (node == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"KlassNode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    error = classSignature(klass, &(node->signature), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        jvmtiDeallocate(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        EXIT_ERROR(error,"signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    if ((node->klass = JNI_FUNC_PTR(env,NewWeakGlobalRef)(env, klass)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        jvmtiDeallocate(node->signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        jvmtiDeallocate(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"NewWeakGlobalRef");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /* Insert the new node */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    node->next = *head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    *head = node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * Called once to build the initial prepared class hash table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
classTrack_initialize(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        jint classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        jclass *classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        error = allLoadedClasses(&classes, &classCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            table = jvmtiAllocate(CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (table != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                (void)memset(table, 0, CT_HASH_SLOT_COUNT * sizeof(KlassNode *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                for (i=0; i<classCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    jclass klass = classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    jint status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    jint wanted =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    /* We only want prepared classes and arrays */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    status = classStatus(klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    if ( (status & wanted) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        classTrack_addPreparedClass(env, klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                jvmtiDeallocate(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"KlassNode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            jvmtiDeallocate(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            EXIT_ERROR(error,"loaded classes array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    } END_WITH_LOCAL_REFS(env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
classTrack_reset(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}