jdk/src/demo/share/jvmti/hprof/hprof_class.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23010 jdk/src/share/demo/jvmti/hprof/hprof_class.c@6dadb192ad81
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20823
diff changeset
     2
 * Copyright (c) 2003, 2013, 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
/* Table of class information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *   Each element in this table is identified with a ClassIndex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *   Each element is uniquely identified by it's signature and loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   Every class load has a unique class serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   While loaded, each element will have a cache of a global reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     to it's jclass object, plus jmethodID's as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   Method signatures and names are obtained via BCI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   Methods can be identified with a ClassIndex and MethodIndex pair,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     where the MethodIndex matches the index of the method name and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     signature arrays obtained from the BCI pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   Strings are stored in the string table and a StringIndex is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   Class Loaders are stored in the loader table and a LoaderIndex is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   Since the jclass object is an object, at some point an object table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      entry may be allocated for the jclass as an ObjectIndex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/* Effectively represents a jclass object. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/* These table elements are made unique by and sorted by signature name. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
typedef struct ClassKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    StringIndex    sig_string_index;    /* Signature of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    LoaderIndex    loader_index;        /* Index for class loader */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
} ClassKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/* Each class could contain method information, gotten from BCI callback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
typedef struct MethodInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    StringIndex  name_index;    /* Method name, index into string table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    StringIndex  sig_index;     /* Method signature, index into string table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    jmethodID    method_id;     /* Method ID, possibly NULL at first */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
} MethodInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/* The basic class information we save */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
typedef struct ClassInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    jclass         classref;            /* Global ref to jclass */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    MethodInfo    *method;              /* Array of method data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    int            method_count;        /* Count of methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    ObjectIndex    object_index;        /* Optional object index for jclass */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    SerialNumber   serial_num;          /* Unique to the actual class load */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    ClassStatus    status;              /* Current class status (bit mask) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    ClassIndex     super;               /* Super class in this table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    StringIndex    name;                /* Name of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    jint           inst_size;           /* #bytes needed for instance fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    jint           field_count;         /* Number of all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    FieldInfo     *field;               /* Pointer to all FieldInfo's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
} ClassInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
/* Private interfaces */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
static ClassKey*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
get_pkey(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    void *key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    int   key_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    table_get_key(gdata->class_table, index, (void*)&key_ptr, &key_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    HPROF_ASSERT(key_len==sizeof(ClassKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    return (ClassKey*)key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
fillin_pkey(const char *sig, LoaderIndex loader_index, ClassKey *pkey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static ClassKey empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    HPROF_ASSERT(loader_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    *pkey                  = empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    pkey->sig_string_index = string_find_or_create(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    pkey->loader_index     = loader_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
static ClassInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
get_info(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    info = (ClassInfo*)table_get_info(gdata->class_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
fill_info(TableIndex index, ClassKey *pkey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    char      *sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    info->serial_num = gdata->class_serial_number_counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    info->method_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    info->inst_size = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    info->field_count = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    info->field = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    sig = string_get(pkey->sig_string_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    if ( sig[0] != JVM_SIGNATURE_CLASS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        info->name = pkey->sig_string_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        int        len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        len = string_get_len(pkey->sig_string_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if ( len > 2  ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            char      *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            /* Class signature looks like "Lname;", we want "name" here. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            name = HPROF_MALLOC(len-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            (void)memcpy(name, sig+1, len-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            name[len-2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            info->name = string_find_or_create(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            HPROF_FREE(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            /* This would be strange, a class signature not in "Lname;" form? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            info->name = pkey->sig_string_index;
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
static ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
find_entry(ClassKey *pkey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    ClassIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    index = table_find_entry(gdata->class_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                (void*)pkey, (int)sizeof(ClassKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
static ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
create_entry(ClassKey *pkey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    ClassIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    index = table_create_entry(gdata->class_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                (void*)pkey, (int)sizeof(ClassKey), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    fill_info(index, pkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
static ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
find_or_create_entry(ClassKey *pkey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    ClassIndex      index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    HPROF_ASSERT(pkey!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    HPROF_ASSERT(pkey->loader_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    index = find_entry(pkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    if ( index == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        index = create_entry(pkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
delete_classref(JNIEnv *env, ClassInfo *info, jclass klass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    jclass ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    int    i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    HPROF_ASSERT(env!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    HPROF_ASSERT(info!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    for ( i = 0 ; i < info->method_count ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        info->method[i].method_id  = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    ref = info->classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    if ( klass != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        info->classref = newGlobalReference(env, klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        info->classref = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    if ( ref != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        deleteGlobalReference(env, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
cleanup_item(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /* Cleanup any information in this ClassInfo structure. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    HPROF_ASSERT(key_len==sizeof(ClassKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    info = (ClassInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if ( info->method_count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        HPROF_FREE((void*)info->method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        info->method_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        info->method       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    if ( info->field != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        HPROF_FREE((void*)info->field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        info->field_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        info->field      = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
delete_ref_item(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    delete_classref((JNIEnv*)arg, (ClassInfo*)info_ptr, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
list_item(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    ClassKey   key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    char      *sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    int        i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    HPROF_ASSERT(key_len==sizeof(ClassKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    key = *((ClassKey*)key_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    sig = string_get(key.sig_string_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    info = (ClassInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
             "0x%08x: Class %s, SN=%u, status=0x%08x, ref=%p,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
             " method_count=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
             index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
             (const char *)sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
             info->serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
             info->status,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
             (void*)info->classref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
             info->method_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    if ( info->method_count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        for ( i = 0 ; i < info->method_count ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                "    Method %d: \"%s\", sig=\"%s\", method=%p\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                string_get(info->method[i].name_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                string_get(info->method[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                (void*)info->method[i].method_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
all_status_remove(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    ClassInfo   *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    ClassStatus  status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    status = (ClassStatus)(long)(ptrdiff_t)arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    info = (ClassInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    info->status &= (~status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
unload_walker(TableIndex index, void *key_ptr, int key_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    ClassInfo        *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    info = (ClassInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    if ( ! ( info->status & CLASS_IN_LOAD_LIST ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if ( ! (info->status & (CLASS_SPECIAL|CLASS_SYSTEM|CLASS_UNLOADED)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            io_write_class_unload(info->serial_num, info->object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            info->status |= CLASS_UNLOADED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            delete_classref((JNIEnv*)arg, info, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
/* External interfaces */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
class_init(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    HPROF_ASSERT(gdata->class_table==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    gdata->class_table = table_initialize("Class", 512, 512, 511,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                    (int)sizeof(ClassInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
class_find_or_create(const char *sig, LoaderIndex loader_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    ClassKey key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    fillin_pkey(sig, loader_index, &key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    return find_or_create_entry(&key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
class_create(const char *sig, LoaderIndex loader_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    ClassKey key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    fillin_pkey(sig, loader_index, &key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    return create_entry(&key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
class_prime_system_classes(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /* Prime System classes? Anything before VM_START is System class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *   Or classes loaded before env arg is non-NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *   Or any of the classes listed below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    static const char * signatures[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            "Ljava/lang/Object;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            "Ljava/io/Serializable;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            "Ljava/lang/String;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            "Ljava/lang/Class;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            "Ljava/lang/ClassLoader;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            "Ljava/lang/System;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            "Ljava/lang/Thread;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            "Ljava/lang/ThreadGroup;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    int n_signatures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    LoaderIndex loader_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    n_signatures = (int)sizeof(signatures)/(int)sizeof(signatures[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    loader_index = loader_find_or_create(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    for ( i = 0 ; i < n_signatures ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        ClassInfo  *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        ClassIndex  index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        ClassKey    key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        fillin_pkey(signatures[i], loader_index, &key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        index = find_or_create_entry(&key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        info->status |= CLASS_SYSTEM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
class_add_status(ClassIndex index, ClassStatus status)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    info->status |= status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
ClassStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
class_get_status(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    return info->status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
StringIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
class_get_signature(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    ClassKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    return pkey->sig_string_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
SerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
class_get_serial_number(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    if ( index == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    return info->serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
class_all_status_remove(ClassStatus status)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    table_walk_items(gdata->class_table, &all_status_remove,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                (void*)(ptrdiff_t)(long)status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
class_do_unloads(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    table_walk_items(gdata->class_table, &unload_walker, (void*)env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
class_list(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        "--------------------- Class Table ------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    table_walk_items(gdata->class_table, &list_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        "----------------------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
class_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    table_cleanup(gdata->class_table, &cleanup_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    gdata->class_table = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
class_delete_global_references(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    table_walk_items(gdata->class_table, &delete_ref_item, (void*)env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
class_set_methods(ClassIndex index, const char **name, const char **sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        int count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    int        i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    info               = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    if ( info->method_count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        HPROF_FREE((void*)info->method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        info->method_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        info->method       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    info->method_count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    if ( count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        info->method = (MethodInfo *)HPROF_MALLOC(count*(int)sizeof(MethodInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        for ( i = 0 ; i < count ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            info->method[i].name_index = string_find_or_create(name[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            info->method[i].sig_index  = string_find_or_create(sig[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            info->method[i].method_id  = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
jclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
class_new_classref(JNIEnv *env, ClassIndex index, jclass classref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    HPROF_ASSERT(classref!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    if ( ! isSameObject(env, classref, info->classref) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        delete_classref(env, info, classref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    return info->classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
jclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
class_get_class(JNIEnv *env, ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    jclass     clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    info        = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    clazz       = info->classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    if ( env != NULL && clazz == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            jclass   new_clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            char    *class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            class_name = string_get(info->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            /* This really only makes sense for the bootclass classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
             *   since FindClass doesn't provide a way to load a class in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
             *   a specific class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            new_clazz = findClass(env, class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            if ( new_clazz == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                HPROF_ERROR(JNI_TRUE, "Cannot load class with findClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            HPROF_ASSERT(new_clazz!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            clazz = class_new_classref(env, index, new_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        } END_WITH_LOCAL_REFS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        HPROF_ASSERT(clazz!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
jmethodID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
class_get_methodID(JNIEnv *env, ClassIndex index, MethodIndex mnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    jmethodID  method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    info = get_info(index);
20823
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   530
    if (mnum >= info->method_count) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   531
        jclass newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   532
        (*env)->ThrowNew(env, newExcCls, "Illegal mnum");
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   533
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   534
        return NULL;
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   535
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    method = info->method[mnum].method_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    if ( method == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        char * name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        char * sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        name  = (char *)string_get(info->method[mnum].name_index);
20823
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   543
        if (name==NULL) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   544
            jclass newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   545
            (*env)->ThrowNew(env, newExcCls, "Name not found");
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   546
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   547
            return NULL;
ddd111318407 8014534: Better profiling support
sjiang
parents: 14342
diff changeset
   548
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        sig   = (char *)string_get(info->method[mnum].sig_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        HPROF_ASSERT(sig!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        clazz = class_get_class(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if ( clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            method = getMethodID(env, clazz, name, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            HPROF_ASSERT(method!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            info->method[mnum].method_id = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
class_set_inst_size(ClassIndex index, jint inst_size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    info->inst_size = inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
class_get_inst_size(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    return info->inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
class_set_object_index(ClassIndex index, ObjectIndex object_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    info->object_index = object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
ObjectIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
class_get_object_index(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    return info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
class_get_super(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    return info->super;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
class_set_super(ClassIndex index, ClassIndex super)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    ClassInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    info->super = super;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
LoaderIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
class_get_loader(ClassIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    ClassKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    HPROF_ASSERT(pkey->loader_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    return pkey->loader_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
/* Get ALL class fields (supers too), return 1 on error, 0 if ok */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
class_get_all_fields(JNIEnv *env, ClassIndex index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                jint *pfield_count, FieldInfo **pfield)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    ClassInfo  *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    FieldInfo  *finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    jint        count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    jint        ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    finfo = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    ret   = 1;       /* Default is to return an error condition */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    if ( info != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        if ( info->field_count >= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            /* Get cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            count = info->field_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            finfo = info->field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            ret   = 0;                 /* Return of cache data, no error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            jclass     klass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            klass = info->classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            if ( klass == NULL || isSameObject(env, klass, NULL) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                /* This is probably an error because this will cause the field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                 *    index values to be off, but I'm hesitant to generate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                 *    fatal error here, so I will issue something and continue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                 *    I should have been holding a global reference to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                 *    jclass, so I'm not sure how this could happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                 *    Issuing a FindClass() here is just asking for trouble
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                 *    because if the class went away, we aren't even sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                 *    what ClassLoader to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                HPROF_ERROR(JNI_FALSE, "Missing jclass when fields needed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                jint status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                status = getClassStatus(klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                if ( status &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    (JVMTI_CLASS_STATUS_PRIMITIVE|JVMTI_CLASS_STATUS_ARRAY) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    /* Set cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    info->field_count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    info->field       = finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    ret               = 0;      /* Primitive or array ok */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                } else if ( status & JVMTI_CLASS_STATUS_PREPARED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    /* Call JVMTI to get them */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    getAllClassFieldInfo(env, klass, &count, &finfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                    /* Set cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    info->field_count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    info->field       = finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    ret               = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    *pfield_count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    *pfield       = finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
}