jdk/src/jdk.hprof.agent/share/native/libhprof/hprof_reference.c
author sla
Tue, 26 Aug 2014 07:55:08 +0200
changeset 26201 40a873d21081
parent 25859 jdk/src/demo/share/jvmti/hprof/hprof_reference.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
/* Object references table (used in hprof_object.c). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This table is used by the object table to store object reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   and primitive data information obtained from iterations over the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   heap (see hprof_site.c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Most of these table entries have no Key, but the key is used to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   the primitive array and primitive field jvalue. None of these entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   are ever looked up, there will be no hash table, use of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   LookupTable was just an easy way to handle a unbounded table of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   entries. The object table (see hprof_object.c) will completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   free this reference table after each heap dump or after processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   references and primitive data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The hprof format required this accumulation of all heap iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   references and primitive data from objects in order to compose an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   hprof records for it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * This file contains detailed understandings of how an hprof CLASS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   and INSTANCE dump is constructed, most of this is derived from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   original hprof code, but some has been derived by reading the HAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   code that accepts this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/* The flavor of data being saved in the RefInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    INFO_OBJECT_REF_DATA    = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    INFO_PRIM_FIELD_DATA    = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    INFO_PRIM_ARRAY_DATA    = 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/* Reference information, object reference or primitive data information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
typedef struct RefInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    ObjectIndex object_index; /* If an object reference, the referree index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    jint        index;        /* If array or field, array or field index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    jint        length;       /* If array the element count, if not -1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    RefIndex    next;         /* The next table element */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    unsigned    flavor   : 8; /* INFO_*, flavor of RefInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    unsigned    refKind  : 8; /* The kind of reference */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    unsigned    primType : 8; /* If primitive data involved, it's type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
} RefInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/* Private internal functions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/* Get the RefInfo structure from an entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
static RefInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
get_info(RefIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    RefInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    info = (RefInfo*)table_get_info(gdata->reference_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
/* Get a jvalue that was stored as the key. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
static jvalue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
get_key_value(RefIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    void  *key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    int    len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    jvalue value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    static jvalue empty_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    key = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    table_get_key(gdata->reference_table, index, &key, &len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    HPROF_ASSERT(key!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    HPROF_ASSERT(len==(int)sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    if ( key != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        (void)memcpy(&value, key, (int)sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        value = empty_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/* Get size of a primitive type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
get_prim_size(jvmtiPrimitiveType primType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    switch ( primType ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        case JVMTI_PRIMITIVE_TYPE_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            size = (jint)sizeof(jboolean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        case JVMTI_PRIMITIVE_TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            size = (jint)sizeof(jbyte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        case JVMTI_PRIMITIVE_TYPE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            size = (jint)sizeof(jchar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        case JVMTI_PRIMITIVE_TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            size = (jint)sizeof(jshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        case JVMTI_PRIMITIVE_TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            size = (jint)sizeof(jint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        case JVMTI_PRIMITIVE_TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            size = (jint)sizeof(jfloat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        case JVMTI_PRIMITIVE_TYPE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            size = (jint)sizeof(jlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        case JVMTI_PRIMITIVE_TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            size = (jint)sizeof(jdouble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            size = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
/* Get a void* elements array that was stored as the key. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
static void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
get_key_elements(RefIndex index, jvmtiPrimitiveType primType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                 jint *nelements, jint *nbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    void  *key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    jint   byteLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    HPROF_ASSERT(nelements!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    HPROF_ASSERT(nbytes!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    table_get_key(gdata->reference_table, index, &key, &byteLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    HPROF_ASSERT(byteLen>=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    HPROF_ASSERT(byteLen!=0?key!=NULL:key==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    *nbytes      = byteLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    *nelements   = byteLen / get_prim_size(primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
/* Dump a RefInfo* structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
dump_ref_info(RefInfo *info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    debug_message("[%d]: flavor=%d"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                          ", refKind=%d"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                          ", primType=%d"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                          ", object_index=0x%x"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                          ", length=%d"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                          ", next=0x%x"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                          "\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            info->index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            info->flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            info->refKind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            info->primType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            info->object_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            info->length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            info->next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
/* Dump a RefIndex list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
dump_ref_list(RefIndex list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    RefInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    RefIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    debug_message("\nFOLLOW REFERENCES RETURNED:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    index = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    while ( index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        dump_ref_info(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        index = info->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
/* Dump information about a field and what ref data we had on it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
dump_field(FieldInfo *fields, jvalue *fvalues, int n_fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                jint index, jvalue value, jvmtiPrimitiveType primType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    ClassIndex  cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    StringIndex name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    StringIndex sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    cnum = fields[index].cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    name = fields[index].name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    sig  = fields[index].sig_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    debug_message("[%d] %s \"%s\" \"%s\"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
          index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
          cnum!=0?string_get(class_get_signature(cnum)):"?",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
          name!=0?string_get(name):"?",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
          sig!=0?string_get(sig):"?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if ( fields[index].primType!=0 || fields[index].primType!=primType ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        debug_message(" (primType=%d(%c)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
          fields[index].primType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
          primTypeToSigChar(fields[index].primType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if ( primType != fields[index].primType ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            debug_message(", got %d(%c)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
              primType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
              primTypeToSigChar(primType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        debug_message(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        debug_message("(ty=OBJ)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    if ( value.j != (jlong)0 || fvalues[index].j != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        debug_message(" val=[0x%08x,0x%08x] or [0x%08x,0x%08x]",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            jlong_high(value.j), jlong_low(value.j),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            jlong_high(fvalues[index].j), jlong_low(fvalues[index].j));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    debug_message("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
/* Dump all the fields of interest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
dump_fields(RefIndex list, FieldInfo *fields, jvalue *fvalues, int n_fields)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    debug_message("\nHPROF LIST OF ALL FIELDS:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    for ( i = 0 ; i < n_fields ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if ( fields[i].name_index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            dump_field(fields, fvalues, n_fields, i, fvalues[i], fields[i].primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    dump_ref_list(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
/* Verify field data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
verify_field(RefIndex list, FieldInfo *fields, jvalue *fvalues, int n_fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                jint index, jvalue value, jvmtiPrimitiveType primType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    HPROF_ASSERT(fvalues != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    HPROF_ASSERT(n_fields > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    HPROF_ASSERT(index < n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    HPROF_ASSERT(index >= 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    if ( primType!=fields[index].primType ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        dump_fields(list, fields, fvalues, n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        debug_message("\nPROBLEM WITH:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        dump_field(fields, fvalues, n_fields, index, value, primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        debug_message("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        HPROF_ERROR(JNI_FALSE, "Trouble with fields and heap data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    if ( primType == JVMTI_PRIMITIVE_TYPE_BOOLEAN &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         ( value.b != 1 && value.b != 0 ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        dump_fields(list, fields, fvalues, n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        debug_message("\nPROBLEM WITH:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        dump_field(fields, fvalues, n_fields, index, value, primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        debug_message("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        HPROF_ERROR(JNI_FALSE, "Trouble with fields and heap data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
/* Fill in a field value, making sure the index is safe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
fill_in_field_value(RefIndex list, FieldInfo *fields, jvalue *fvalues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    int n_fields, jint index, jvalue value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    jvmtiPrimitiveType primType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    HPROF_ASSERT(fvalues != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    HPROF_ASSERT(n_fields > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    HPROF_ASSERT(index < n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    HPROF_ASSERT(index >= 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    HPROF_ASSERT(fvalues[index].j==(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    verify_field(list, fields, fvalues, n_fields, index, value, primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    if (index >= 0 && index < n_fields) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        fvalues[index] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
/* Walk all references for an ObjectIndex and construct the hprof CLASS dump. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
dump_class_and_supers(JNIEnv *env, ObjectIndex object_index, RefIndex list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    SiteIndex    site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    SerialNumber trace_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    RefIndex     index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    ClassIndex   super_cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    ObjectIndex  super_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    LoaderIndex  loader_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    ObjectIndex  signers_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    ObjectIndex  domain_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    FieldInfo   *fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    jvalue      *fvalues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    jint         n_fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    jboolean     skip_fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    jint         n_fields_set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    jlong        size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    ClassIndex   cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    char        *sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    ObjectKind   kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    TraceIndex   trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    Stack       *cpool_values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    ConstantPoolValue *cpool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    jint         cpool_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    HPROF_ASSERT(object_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    kind        = object_get_kind(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    if ( kind != OBJECT_CLASS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    site_index         = object_get_site(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    HPROF_ASSERT(site_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    cnum        = site_get_class_index(site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    HPROF_ASSERT(cnum!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if ( class_get_status(cnum) & CLASS_DUMPED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    class_add_status(cnum, CLASS_DUMPED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    size        = (jlong)object_get_size(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    super_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    super_cnum  = class_get_super(cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    if ( super_cnum != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        super_index  = class_get_object_index(super_cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if ( super_index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            dump_class_and_supers(env, super_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        object_get_references(super_index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    trace_index      = site_get_trace_index(site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    HPROF_ASSERT(trace_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    trace_serial_num = trace_get_serial_number(trace_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    sig              = string_get(class_get_signature(cnum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    loader_index     = class_get_loader(cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    signers_index    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    domain_index     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /* Get field information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    n_fields     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    skip_fields  = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    n_fields_set = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    fields       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    fvalues      = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        /* Problems getting all the fields, can't trust field index values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        skip_fields = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        /* Class with no references at all? (ok to be unprepared if list==0?) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if ( list != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            /* It is assumed that the reason why we didn't get the fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
             *     was because the class is not prepared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                dump_ref_list(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                debug_message("Unprepared class with references: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                               sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            HPROF_ERROR(JNI_FALSE, "Trouble with unprepared classes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        /* Why would an unprepared class contain references? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    if ( n_fields > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        fvalues      = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /* We use a Stack just because it will automatically expand as needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    cpool_values = stack_init(16, 16, sizeof(ConstantPoolValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    cpool = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    cpool_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    index      = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    while ( index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        RefInfo    *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        jvalue      ovalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        static jvalue empty_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        switch ( info->flavor ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            case INFO_OBJECT_REF_DATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                switch ( info->refKind ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    case JVMTI_HEAP_REFERENCE_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        /* Should never be seen on a class dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    case JVMTI_HEAP_REFERENCE_STATIC_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        if ( skip_fields == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        ovalue   = empty_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        ovalue.i = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                        fill_in_field_value(list, fields, fvalues, n_fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                        info->index, ovalue, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        n_fields_set++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        HPROF_ASSERT(n_fields_set <= n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        ConstantPoolValue cpv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                        ObjectIndex       cp_object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        SiteIndex         cp_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        ClassIndex        cp_cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        cp_object_index = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        HPROF_ASSERT(cp_object_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        cp_site_index = object_get_site(cp_object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        HPROF_ASSERT(cp_site_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        cp_cnum = site_get_class_index(cp_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        cpv.constant_pool_index = info->index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        cpv.sig_index = class_get_signature(cp_cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        cpv.value.i = cp_object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        stack_push(cpool_values, (void*)&cpv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        cpool_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    case JVMTI_HEAP_REFERENCE_SIGNERS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        signers_index = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        domain_index = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    case JVMTI_HEAP_REFERENCE_CLASS_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    case JVMTI_HEAP_REFERENCE_INTERFACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        /* Ignore, not needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            case INFO_PRIM_FIELD_DATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                if ( skip_fields == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                HPROF_ASSERT(info->primType!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                HPROF_ASSERT(info->length==-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_STATIC_FIELD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                ovalue = get_key_value(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                fill_in_field_value(list, fields, fvalues, n_fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                    info->index, ovalue, info->primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                n_fields_set++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                HPROF_ASSERT(n_fields_set <= n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            case INFO_PRIM_ARRAY_DATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                /* Should never see these */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        index = info->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /* Get constant pool data if we have any */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    HPROF_ASSERT(cpool_count==stack_depth(cpool_values));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    if ( cpool_count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        cpool = (ConstantPoolValue*)stack_element(cpool_values, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    io_heap_class_dump(cnum, sig, object_index, trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            super_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            loader_object_index(env, loader_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            signers_index, domain_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            (jint)size, cpool_count, cpool, n_fields, fields, fvalues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    stack_term(cpool_values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    if ( fvalues != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        HPROF_FREE(fvalues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
/* Walk all references for an ObjectIndex and construct the hprof INST dump. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
dump_instance(JNIEnv *env, ObjectIndex object_index, RefIndex list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    jvmtiPrimitiveType primType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    SiteIndex    site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    SerialNumber trace_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    RefIndex     index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    ObjectIndex  class_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    jlong        size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    ClassIndex   cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    char        *sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    void        *elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    jint         num_elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    jint         num_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    ObjectIndex *values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    FieldInfo   *fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    jvalue      *fvalues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    jint         n_fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    jboolean     skip_fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    jint         n_fields_set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    ObjectKind   kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    TraceIndex   trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    jboolean     is_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    jboolean     is_prim_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    HPROF_ASSERT(object_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    kind        = object_get_kind(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    if ( kind == OBJECT_CLASS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    site_index       = object_get_site(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    HPROF_ASSERT(site_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    cnum             = site_get_class_index(site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    HPROF_ASSERT(cnum!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    size             = (jlong)object_get_size(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    trace_index      = site_get_trace_index(site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    HPROF_ASSERT(trace_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    trace_serial_num = trace_get_serial_number(trace_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    sig              = string_get(class_get_signature(cnum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    class_index      = class_get_object_index(cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    values       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    elements     = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    num_elements = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    num_bytes    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    n_fields     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    skip_fields  = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    n_fields_set = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    fields       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    fvalues      = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    index      = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    is_array      = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    is_prim_array = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    if ( sig[0] != JVM_SIGNATURE_ARRAY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            /* Trouble getting all the fields, can't trust field index values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            skip_fields = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            /* It is assumed that the reason why we didn't get the fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
             *     was because the class is not prepared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                if ( list != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    dump_ref_list(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    debug_message("Instance of unprepared class with refs: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                   sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    debug_message("Instance of unprepared class without refs: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                   sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                HPROF_ERROR(JNI_FALSE, "Big Trouble with unprepared class instances");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if ( n_fields > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        is_array = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if ( sig[0] != 0 && sigToPrimSize(sig+1) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            is_prim_array = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    while ( index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        RefInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        jvalue   ovalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        static jvalue empty_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /* Process reference objects, many not used right now. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        switch ( info->flavor ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            case INFO_OBJECT_REF_DATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                switch ( info->refKind ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    case JVMTI_HEAP_REFERENCE_SIGNERS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    case JVMTI_HEAP_REFERENCE_CLASS_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    case JVMTI_HEAP_REFERENCE_INTERFACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    case JVMTI_HEAP_REFERENCE_STATIC_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    case JVMTI_HEAP_REFERENCE_CONSTANT_POOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        /* Should never be seen on an instance dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                        HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    case JVMTI_HEAP_REFERENCE_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        if ( skip_fields == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        HPROF_ASSERT(is_array!=JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                        ovalue   = empty_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                        ovalue.i = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                        fill_in_field_value(list, fields, fvalues, n_fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                                        info->index, ovalue, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                        n_fields_set++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                        HPROF_ASSERT(n_fields_set <= n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        /* We get each object element one at a time.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        HPROF_ASSERT(is_array==JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        HPROF_ASSERT(is_prim_array!=JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                        if ( num_elements <= info->index ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                            int nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                            if ( values == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                num_elements = info->index + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                nbytes = num_elements*(int)sizeof(ObjectIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                values = (ObjectIndex*)HPROF_MALLOC(nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                (void)memset(values, 0, nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                void *new_values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                int   new_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                int   obytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                obytes = num_elements*(int)sizeof(ObjectIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                new_size = info->index + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                                nbytes = new_size*(int)sizeof(ObjectIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                new_values = (void*)HPROF_MALLOC(nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                (void)memcpy(new_values, values, obytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                (void)memset(((char*)new_values)+obytes, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                                        nbytes-obytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                HPROF_FREE(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                                num_elements = new_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                values =  new_values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                        HPROF_ASSERT(values[info->index]==0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                        values[info->index] = info->object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        /* Ignore, not needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            case INFO_PRIM_FIELD_DATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                if ( skip_fields == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                HPROF_ASSERT(info->primType!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                HPROF_ASSERT(info->length==-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_FIELD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                HPROF_ASSERT(is_array!=JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                ovalue = get_key_value(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                fill_in_field_value(list, fields, fvalues, n_fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                                    info->index, ovalue, info->primType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                n_fields_set++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                HPROF_ASSERT(n_fields_set <= n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            case INFO_PRIM_ARRAY_DATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                /* Should only be one, and it's handled below */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                HPROF_ASSERT(info->refKind==0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                /* We assert that nothing else was saved with this array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                HPROF_ASSERT(index==list&&info->next==0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                HPROF_ASSERT(is_array==JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                HPROF_ASSERT(is_prim_array==JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                primType = info->primType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                elements = get_key_elements(index, primType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                            &num_elements, &num_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                HPROF_ASSERT(info->length==num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                size = num_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        index = info->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    if ( is_array == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if ( is_prim_array == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            HPROF_ASSERT(values==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            io_heap_prim_array(object_index, trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    (jint)size, num_elements, sig, elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            HPROF_ASSERT(elements==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            io_heap_object_array(object_index, trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    (jint)size, num_elements, sig, values, class_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        io_heap_instance_dump(cnum, object_index, trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    class_index, (jint)size, sig, fields, fvalues, n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    if ( values != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        HPROF_FREE(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    if ( fvalues != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        HPROF_FREE(fvalues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    if ( elements != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        /* Do NOT free elements, it's a key in the table, leave it be */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
/* External interfaces. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
reference_init(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    HPROF_ASSERT(gdata->reference_table==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    gdata->reference_table = table_initialize("Ref", 2048, 4096, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                            (int)sizeof(RefInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
/* Save away a reference to an object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
RefIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
reference_obj(RefIndex next, jvmtiHeapReferenceKind refKind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
              ObjectIndex object_index, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    static RefInfo  empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    RefIndex        entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    RefInfo         info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    info                = empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    info.flavor         = INFO_OBJECT_REF_DATA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    info.refKind        = refKind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    info.object_index   = object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    info.index          = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    info.length         = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    info.next           = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    entry = table_create_entry(gdata->reference_table, NULL, 0, (void*)&info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
/* Save away some primitive field data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
RefIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
reference_prim_field(RefIndex next, jvmtiHeapReferenceKind refKind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
              jvmtiPrimitiveType primType, jvalue field_value, jint field_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    static RefInfo  empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    RefIndex        entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    RefInfo         info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    HPROF_ASSERT(primType==JVMTI_PRIMITIVE_TYPE_BOOLEAN?(field_value.b==1||field_value.b==0):1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    info                = empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    info.flavor         = INFO_PRIM_FIELD_DATA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    info.refKind        = refKind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    info.primType       = primType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    info.index          = field_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    info.length         = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    info.next           = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    entry = table_create_entry(gdata->reference_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                (void*)&field_value, (int)sizeof(jvalue), (void*)&info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
/* Save away some primitive array data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
RefIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
reference_prim_array(RefIndex next, jvmtiPrimitiveType primType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
              const void *elements, jint elementCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    static RefInfo  empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    RefIndex        entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    RefInfo         info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    HPROF_ASSERT(next == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    HPROF_ASSERT(elementCount >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    HPROF_ASSERT(elements != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    info                = empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    info.flavor         = INFO_PRIM_ARRAY_DATA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    info.refKind        = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    info.primType       = primType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    info.index          = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    info.length         = elementCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    info.next           = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    entry = table_create_entry(gdata->reference_table, (void*)elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                         elementCount * get_prim_size(primType), (void*)&info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
reference_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    if ( gdata->reference_table == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    table_cleanup(gdata->reference_table, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    gdata->reference_table = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
reference_dump_instance(JNIEnv *env, ObjectIndex object_index, RefIndex list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    dump_instance(env, object_index, list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
reference_dump_class(JNIEnv *env, ObjectIndex object_index, RefIndex list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    dump_class_and_supers(env, object_index, list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
}