jdk/src/jdk.hprof.agent/share/native/libhprof/hprof_loader.c
author sla
Tue, 26 Aug 2014 07:55:08 +0200
changeset 26201 40a873d21081
parent 25859 jdk/src/demo/share/jvmti/hprof/hprof_loader.c@3317bb8137f4
permissions -rw-r--r--
8043936: Drop HPROF as demo, keep as HPROF agent shipped with JDK Reviewed-by: erikj, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10292
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* The Class Loader table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The Class Loader objects show up so early in the VM process that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   separate table was designated for Class Loaders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The Class Loader is unique by way of it's jobject uniqueness, unfortunately
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   use of JNI too early for jobject comparisons is problematic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   It is assumed that the number of class loaders will be limited, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   a simple linear search will be performed for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   That logic is isolated here and can be changed to use the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   table hash table search once we know JNI can be called safely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * A weak global reference is created to keep tabs on loaders, and as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   each search for a loader happens, NULL weak global references will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   trigger the freedom of those entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    jobject         globalref;    /* Weak Global reference for object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    ObjectIndex     object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
} LoaderInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
static LoaderInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
get_info(LoaderIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    return (LoaderInfo*)table_get_info(gdata->loader_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
delete_globalref(JNIEnv *env, LoaderInfo *info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jobject     ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    HPROF_ASSERT(env!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    HPROF_ASSERT(info!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    ref = info->globalref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    info->globalref = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    if ( ref != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        deleteWeakGlobalReference(env, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    info->object_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
cleanup_item(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
delete_ref_item(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    delete_globalref((JNIEnv*)arg, (LoaderInfo*)info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
list_item(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    LoaderInfo     *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    info        = (LoaderInfo*)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    debug_message( "Loader 0x%08x: globalref=%p, object_index=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                index, (void*)info->globalref, info->object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
free_entry(JNIEnv *env, LoaderIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    LoaderInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    delete_globalref(env, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    table_free_entry(gdata->loader_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
typedef struct SearchData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jobject loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    LoaderIndex found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
} SearchData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
search_item(TableIndex index, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    LoaderInfo  *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    SearchData  *data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    HPROF_ASSERT(arg!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    info        = (LoaderInfo*)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    data        = (SearchData*)arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    if ( data->loader == info->globalref ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        /* Covers when looking for NULL too. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        HPROF_ASSERT(data->found==0); /* Did we find more than one? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        data->found = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    } else if ( data->env != NULL && data->loader != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                info->globalref != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        jobject lref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        lref = newLocalReference(data->env, info->globalref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if ( lref == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            /* Object went away, free reference and entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            free_entry(data->env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } else if ( isSameObject(data->env, data->loader, lref) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            HPROF_ASSERT(data->found==0); /* Did we find more than one? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            data->found = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if ( lref != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            deleteLocalReference(data->env, lref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
static LoaderIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
search(JNIEnv *env, jobject loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    SearchData  data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    data.env    = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    data.loader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    data.found  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    table_walk_items(gdata->loader_table, &search_item, (void*)&data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    return data.found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
LoaderIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
loader_find_or_create(JNIEnv *env, jobject loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    LoaderIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /* See if we remembered the system loader */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    if ( loader==NULL && gdata->system_loader != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return gdata->system_loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    if ( loader==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        env = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    index = search(env, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if ( index == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        static LoaderInfo  empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        LoaderInfo  info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        info = empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if ( loader != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            HPROF_ASSERT(env!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            info.globalref = newWeakGlobalReference(env, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            info.object_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        index = table_create_entry(gdata->loader_table, NULL, 0, (void*)&info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    HPROF_ASSERT(search(env,loader)==index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /* Remember the system loader */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    if ( loader==NULL && gdata->system_loader == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        gdata->system_loader = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
loader_init(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    gdata->loader_table = table_initialize("Loader",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                            16, 16, 0, (int)sizeof(LoaderInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
loader_list(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        "--------------------- Loader Table ------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    table_walk_items(gdata->loader_table, &list_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        "----------------------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
loader_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    table_cleanup(gdata->loader_table, &cleanup_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    gdata->loader_table = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
loader_delete_global_references(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    table_walk_items(gdata->loader_table, &delete_ref_item, (void*)env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
/* Get the object index for a class loader */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
ObjectIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
loader_object_index(JNIEnv *env, LoaderIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    LoaderInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    ObjectIndex object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    jobject     wref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /* Assume no object index at first (default class loader) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    object_index = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    wref = info->globalref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if ( wref != NULL && object_index == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        jobject lref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        object_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        lref = newLocalReference(env, wref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if ( lref != NULL && !isSameObject(env, lref, NULL) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            jlong tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            /* Get the tag on the object and extract the object_index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            tag = getTag(lref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            if ( tag != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                object_index = tag_extract(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if ( lref != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            deleteLocalReference(env, lref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        info->object_index = object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    return object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}