jdk/src/share/demo/jvmti/hprof/hprof_check.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *   - Neither the name of Sun Microsystems nor the names of its
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/* Functionality for checking hprof format=b output. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/* ONLY used with logflags=4. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/* Verifies and write a verbose textual version of a format=b file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *   Textual output file is gdata->checkfilename, fd is gdata->check_fd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   Buffer is in gdata too, see gdata->check* variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   Could probably be isolated to a separate library or utility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
typedef TableIndex HprofId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "hprof_b_spec.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
static int type_size[ /*HprofType*/ ] =  HPROF_TYPE_SIZES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/* For map from HPROF_UTF8 to a string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
typedef struct UmapInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    char *str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
} UmapInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* Field information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
typedef struct Finfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    HprofId   id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    HprofType ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
} Finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/* Class information map from class ID (ClassIndex) to class information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
typedef struct CmapInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int      max_finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    int      n_finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    Finfo   *finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    int      inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    HprofId  sup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
} CmapInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/* Read raw bytes from the file image, update the pointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
read_raw(unsigned char **pp, unsigned char *buf, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    while ( len > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        *buf = **pp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        buf++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        (*pp)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        len--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
/* Read various sized elements, properly converted from big to right endian.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *    File will contain big endian format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
static unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
read_u1(unsigned char **pp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    unsigned char b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    read_raw(pp, &b, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
read_u2(unsigned char **pp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    unsigned short s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    read_raw(pp, (void*)&s, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    return md_htons(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
read_u4(unsigned char **pp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    unsigned int u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    read_raw(pp, (void*)&u, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    return md_htonl(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
static jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
read_u8(unsigned char **pp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    unsigned int high;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    unsigned int low;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    jlong        x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    high = read_u4(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    low  = read_u4(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    x = high;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    x = (x << 32) | low;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static HprofId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
read_id(unsigned char **pp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    return (HprofId)read_u4(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
/* System error routine */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
system_error(const char *system_call, int rc, int errnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    char buf[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    char details[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    details[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    if ( errnum != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        md_system_error(details, (int)sizeof(details));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    } else if ( rc >= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        (void)strcpy(details,"Only part of buffer processed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    if ( details[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        (void)strcpy(details,"Unknown system error condition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    (void)md_snprintf(buf, sizeof(buf), "System %s failed: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                            system_call, details);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    HPROF_ERROR(JNI_TRUE, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
/* Write to a fd */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
system_write(int fd, void *buf, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    int res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    HPROF_ASSERT(fd>=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    res = md_write(fd, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if (res < 0 || res!=len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        system_error("write", res, errno);
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
/* Flush check buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
check_flush(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    if ( gdata->check_fd < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if (gdata->check_buffer_index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        system_write(gdata->check_fd, gdata->check_buffer, gdata->check_buffer_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        gdata->check_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
/* Read out a given typed element */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
static jvalue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
read_val(unsigned char **pp, HprofType ty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    jvalue        val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    static jvalue empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    val = empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    switch ( ty ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        case HPROF_ARRAY_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        case HPROF_NORMAL_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            val.i = read_id(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        case HPROF_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        case HPROF_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            val.b = read_u1(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        case HPROF_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        case HPROF_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            val.s = read_u2(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        case HPROF_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        case HPROF_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            val.i = read_u4(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        case HPROF_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        case HPROF_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            val.j = read_u8(pp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            HPROF_ERROR(JNI_TRUE, "bad type number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
/* Move arbitrary byte stream into gdata->check_fd */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
check_raw(void *buf, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    if ( gdata->check_fd < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    if ( len <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    if (gdata->check_buffer_index + len > gdata->check_buffer_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        check_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (len > gdata->check_buffer_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            system_write(gdata->check_fd, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    (void)memcpy(gdata->check_buffer + gdata->check_buffer_index, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    gdata->check_buffer_index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
/* Printf for gdata->check_fd */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
check_printf(char *fmt, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    char    buf[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    va_list args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if ( gdata->check_fd < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    va_start(args, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    (void)md_vsnprintf(buf, sizeof(buf), fmt, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    buf[sizeof(buf)-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    check_raw(buf, (int)strlen(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    va_end(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
/* Printf of an element for gdata->check_fd */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
check_printf_val(HprofType ty, jvalue val, int long_form)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    jint low;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    jint high;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    switch ( ty ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        case HPROF_ARRAY_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            check_printf("0x%08x", val.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        case HPROF_NORMAL_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            check_printf("0x%08x", val.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        case HPROF_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            check_printf("0x%02x", val.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        case HPROF_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if ( long_form ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if ( val.s < 0 || val.s > 0x7f || !isprint(val.s) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    check_printf("0x%04x", val.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    check_printf("0x%04x(%c)", val.s, val.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                if ( val.s < 0 || val.s > 0x7f || !isprint(val.s) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    check_printf("\\u%04x", val.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    check_printf("%c", val.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        case HPROF_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            low  = jlong_low(val.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            check_printf("0x%08x(%f)", low, (double)val.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        case HPROF_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            high = jlong_high(val.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            low  = jlong_low(val.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            check_printf("0x%08x%08x(%f)", high, low, val.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        case HPROF_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            check_printf("0x%02x", val.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        case HPROF_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            check_printf("0x%04x", val.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        case HPROF_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            check_printf("0x%08x", val.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        case HPROF_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            high = jlong_high(val.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            low  = jlong_low(val.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            check_printf("0x%08x%08x", high, low);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
/* Printf of a string for gdata->check_fd */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
check_printf_str(char *str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    if ( str == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        check_printf("<null>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    check_printf("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    len = (int)strlen(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        unsigned char c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        c = str[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if ( isprint(c) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            check_printf("%c", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            check_printf("\\x%02x", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    check_printf("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
/* Printf of a utf8 id for gdata->check_fd */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
check_print_utf8(struct LookupTable *utab, char *prefix, HprofId id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    TableIndex uindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if ( id == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        check_printf("%s0x%x", prefix, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        uindex = table_find_entry(utab, &id, sizeof(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if ( uindex == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            check_printf("%s0x%x", prefix, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            UmapInfo *umap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            umap = (UmapInfo*)table_get_info(utab, uindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            HPROF_ASSERT(umap!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            HPROF_ASSERT(umap->str!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            check_printf("%s0x%x->", prefix, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            check_printf_str(umap->str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
/* Add a instance field information to this cmap. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
add_inst_field_to_cmap(CmapInfo *cmap, HprofId id, HprofType ty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
   int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
   HPROF_ASSERT(cmap!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
   i = cmap->n_finfo++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
   if ( i+1 >= cmap->max_finfo ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
       int    osize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
       Finfo *new_finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
       osize            = cmap->max_finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
       cmap->max_finfo += 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
       new_finfo = (Finfo*)HPROF_MALLOC(cmap->max_finfo*(int)sizeof(Finfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
       (void)memset(new_finfo,0,cmap->max_finfo*(int)sizeof(Finfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
       if ( i == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
           cmap->finfo = new_finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
       } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
           (void)memcpy(new_finfo,cmap->finfo,osize*(int)sizeof(Finfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
           HPROF_FREE(cmap->finfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
           cmap->finfo = new_finfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
   cmap->finfo[i].id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
   cmap->finfo[i].ty = ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
/* LookupTable callback for cmap entry cleanup */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
cmap_cleanup(TableIndex i, void *key_ptr, int key_len, void*info, void*data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    CmapInfo *cmap = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if ( cmap == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if ( cmap->finfo != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        HPROF_FREE(cmap->finfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        cmap->finfo = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
/* Case label for a switch on hprof heap dump elements */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
#define CASE_HEAP(name) case name: label = #name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
/* Given the heap dump data and the utf8 map, check/write the heap dump. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
check_heap_tags(struct LookupTable *utab, unsigned char *pstart, int nbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    int                 nrecords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    unsigned char      *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    unsigned char      *psave;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    struct LookupTable *ctab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    CmapInfo            cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    char               *label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    unsigned            tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    HprofType           ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    HprofId             id, id2, fr, sup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    int                 num_elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    int                 num_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    SerialNumber        trace_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    SerialNumber        thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    int                 npos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    int                 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    int                 inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    ctab     = table_initialize("temp ctab", 64, 64, 512, sizeof(CmapInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /* First pass over heap records just fills in the CmapInfo table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    nrecords = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    p        = pstart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    while ( p < (pstart+nbytes) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        nrecords++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        npos = (int)(p - pstart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        tag  = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        switch ( tag ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            CASE_HEAP(HPROF_GC_ROOT_UNKNOWN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            CASE_HEAP(HPROF_GC_ROOT_JNI_GLOBAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                id  = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                id2 = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            CASE_HEAP(HPROF_GC_ROOT_JNI_LOCAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                fr = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            CASE_HEAP(HPROF_GC_ROOT_JAVA_FRAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                fr = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            CASE_HEAP(HPROF_GC_ROOT_NATIVE_STACK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            CASE_HEAP(HPROF_GC_ROOT_STICKY_CLASS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            CASE_HEAP(HPROF_GC_ROOT_THREAD_BLOCK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            CASE_HEAP(HPROF_GC_ROOT_MONITOR_USED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            CASE_HEAP(HPROF_GC_ROOT_THREAD_OBJ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            CASE_HEAP(HPROF_GC_CLASS_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                (void)memset((void*)&cmap, 0, sizeof(cmap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    HprofId ld, si, pr, re1, re2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    sup      = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    ld       = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    si       = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    pr       = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    re1      = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    re2      = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    cmap.sup = sup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                inst_size = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                cmap.inst_size = inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                num_elements = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    (void)read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    (void)read_val(&p, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                num_elements = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    (void)read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    (void)read_val(&p, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                num_elements = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    HprofType ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    HprofId   id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    add_inst_field_to_cmap(&cmap, id, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                (void)table_create_entry(ctab, &id, sizeof(id), &cmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            CASE_HEAP(HPROF_GC_INSTANCE_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                id2 = read_id(&p); /* class id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                num_bytes = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                p += num_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            CASE_HEAP(HPROF_GC_OBJ_ARRAY_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                num_elements = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                id2 = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                p += num_elements*(int)sizeof(HprofId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            CASE_HEAP(HPROF_GC_PRIM_ARRAY_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                num_elements = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                p += type_size[ty]*num_elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                label = "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                check_printf("H#%d@%d %s: ERROR!\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                nrecords, npos, label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                HPROF_ERROR(JNI_TRUE, "unknown heap record type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    CHECK_FOR_ERROR(p==pstart+nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /* Scan again once we have our cmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    nrecords = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    p        = pstart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    while ( p < (pstart+nbytes) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        nrecords++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        npos = (int)(p - pstart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        tag  = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        switch ( tag ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            CASE_HEAP(HPROF_GC_ROOT_UNKNOWN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                check_printf("H#%d@%d %s: id=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                        nrecords, npos, label, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            CASE_HEAP(HPROF_GC_ROOT_JNI_GLOBAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                id2 = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                check_printf("H#%d@%d %s: id=0x%x, id2=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        nrecords, npos, label, id, id2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            CASE_HEAP(HPROF_GC_ROOT_JNI_LOCAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                fr = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u, fr=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                        nrecords, npos, label, id, thread_serial_num, fr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            CASE_HEAP(HPROF_GC_ROOT_JAVA_FRAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                fr = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u, fr=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                        nrecords, npos, label, id, thread_serial_num, fr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            CASE_HEAP(HPROF_GC_ROOT_NATIVE_STACK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                        nrecords, npos, label, id, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            CASE_HEAP(HPROF_GC_ROOT_STICKY_CLASS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                check_printf("H#%d@%d %s: id=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        nrecords, npos, label, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            CASE_HEAP(HPROF_GC_ROOT_THREAD_BLOCK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        nrecords, npos, label, id, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            CASE_HEAP(HPROF_GC_ROOT_MONITOR_USED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                check_printf("H#%d@%d %s: id=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                        nrecords, npos, label, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            CASE_HEAP(HPROF_GC_ROOT_THREAD_OBJ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                             " trace_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        nrecords, npos, label, id, thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            CASE_HEAP(HPROF_GC_CLASS_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                        nrecords, npos, label, id, trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    HprofId ld, si, pr, re1, re2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    sup = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    ld  = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    si  = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    pr  = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    re1 = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    re2 = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    check_printf("  su=0x%x, ld=0x%x, si=0x%x,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                 " pr=0x%x, re1=0x%x, re2=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        sup, ld, si, pr, re1, re2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                inst_size = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                check_printf("  instance_size=%d\n", inst_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                num_elements = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    HprofType ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    unsigned  cpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    jvalue    val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    cpi = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    ty  = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    val = read_val(&p, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    check_printf("  constant_pool %d: cpi=%d, ty=%d, val=",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                i, cpi, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    check_printf_val(ty, val, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    check_printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                num_elements = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                check_printf("  static_field_count=%d\n", num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    HprofType ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    HprofId   id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    jvalue    val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    id  = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    ty  = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    val = read_val(&p, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    check_printf("  static field %d: ", i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    check_print_utf8(utab, "id=", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    check_printf(", ty=%d, val=", ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    check_printf_val(ty, val, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                    check_printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                num_elements = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                check_printf("  instance_field_count=%d\n", num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    HprofType ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    HprofId   id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    check_printf("  instance_field %d: ", i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    check_print_utf8(utab, "id=", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    check_printf(", ty=%d\n", ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            CASE_HEAP(HPROF_GC_INSTANCE_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                id2 = read_id(&p); /* class id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                num_bytes = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                             " cid=0x%x, nbytes=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                            nrecords, npos, label, id, trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                            id2, num_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                /* This is a packed set of bytes for the instance fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                if ( num_bytes > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    TableIndex cindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    int        ifield;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    CmapInfo  *map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    cindex = table_find_entry(ctab, &id2, sizeof(id2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    HPROF_ASSERT(cindex!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    map = (CmapInfo*)table_get_info(ctab, cindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    HPROF_ASSERT(map!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    HPROF_ASSERT(num_bytes==map->inst_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    psave  = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    ifield = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        for(i=0;i<map->n_finfo;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                            HprofType ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                            HprofId   id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                            jvalue    val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                            ty = map->finfo[i].ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                            id = map->finfo[i].id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                            HPROF_ASSERT(ty!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                            HPROF_ASSERT(id!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                            val = read_val(&p, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                            check_printf("  field %d: ", ifield);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                            check_print_utf8(utab, "id=", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                            check_printf(", ty=%d, val=", ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                            check_printf_val(ty, val, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                            check_printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                            ifield++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                        id2    = map->sup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                        map    = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                        cindex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                        if ( id2 != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                            cindex = table_find_entry(ctab, &id2, sizeof(id2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                            HPROF_ASSERT(cindex!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                            map = (CmapInfo*)table_get_info(ctab, cindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                            HPROF_ASSERT(map!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    } while ( map != NULL );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    HPROF_ASSERT(num_bytes==(p-psave));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            CASE_HEAP(HPROF_GC_OBJ_ARRAY_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                num_elements = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                id2 = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u, nelems=%d, eid=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                nrecords, npos, label, id, trace_serial_num, num_elements, id2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                    HprofId id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    check_printf("  [%d]: id=0x%x\n", i, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            CASE_HEAP(HPROF_GC_PRIM_ARRAY_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                num_elements = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                psave = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                             "nelems=%d, ty=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                                nrecords, npos, label, id, trace_serial_num, num_elements, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                HPROF_ASSERT(HPROF_TYPE_IS_PRIMITIVE(ty));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                if ( num_elements > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    int   count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    int   long_form;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                    int   max_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    char *quote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    quote     = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    long_form = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    max_count = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    count     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    switch ( ty ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        case HPROF_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                            long_form = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                            max_count = 72;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                            quote     = "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                            /*FALLTHRU*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        case HPROF_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                        case HPROF_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                        case HPROF_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        case HPROF_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                        case HPROF_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                        case HPROF_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                        case HPROF_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                            check_printf("  val=%s", quote);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                            for(i=0; i<num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                                jvalue val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                                if ( i > 0 && count == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                                    check_printf("  %s", quote);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                                val = read_val(&p, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                check_printf_val(ty, val, long_form);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                                count += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                                if ( count >= max_count ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                                    check_printf("\"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                                    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                            if ( count != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                check_printf("%s\n", quote);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                HPROF_ASSERT(type_size[ty]*num_elements==(p-psave));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                label = "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                check_printf("H#%d@%d %s: ERROR!\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                                nrecords, npos, label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                HPROF_ERROR(JNI_TRUE, "unknown heap record type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    CHECK_FOR_ERROR(p==pstart+nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    table_cleanup(ctab, &cmap_cleanup, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    return nrecords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
/* LookupTable cleanup callback for utab */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
utab_cleanup(TableIndex i, void *key_ptr, int key_len, void*info, void*data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    UmapInfo *umap = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    if ( umap == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    if ( umap->str != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        HPROF_FREE(umap->str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        umap->str = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
/* Check all the heap tags in a heap dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
check_tags(unsigned char *pstart, int nbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    unsigned char      *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    int                 nrecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    struct LookupTable *utab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    UmapInfo            umap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    check_printf("\nCHECK TAGS: starting\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    utab    = table_initialize("temp utf8 map", 64, 64, 512, sizeof(UmapInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    /* Walk the tags, assumes UTF8 tags are defined before used */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    p       = pstart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    nrecord = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    while ( p < (pstart+nbytes) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        unsigned     tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        unsigned     size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        int          nheap_records;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        int          npos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        char        *label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        HprofId      id, nm, sg, so, gr, gn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        int          i, li, num_elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        HprofType    ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        SerialNumber trace_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        SerialNumber thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        SerialNumber class_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        unsigned     flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        unsigned     depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        float        cutoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        unsigned     temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        jint         nblive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        jint         nilive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        jlong        tbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        jlong        tinsts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        jint         total_samples;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        jint         trace_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        nrecord++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        npos = (int)(p - pstart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        tag = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        (void)read_u4(&p); /* microsecs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        size = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        #define CASE_TAG(name) case name: label = #name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        switch ( tag ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            CASE_TAG(HPROF_UTF8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                CHECK_FOR_ERROR(size>=(int)sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                check_printf("#%d@%d: %s, sz=%d, name_id=0x%x, \"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                nrecord, npos, label, size, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                num_elements = size-(int)sizeof(HprofId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                check_raw(p, num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                check_printf("\"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                /* Create entry in umap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                umap.str = HPROF_MALLOC(num_elements+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                (void)strncpy(umap.str, (char*)p, (size_t)num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                umap.str[num_elements] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                (void)table_create_entry(utab, &id, sizeof(id), &umap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                p += num_elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            CASE_TAG(HPROF_LOAD_CLASS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                CHECK_FOR_ERROR(size==2*4+2*(int)sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                class_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                nm = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                check_printf("#%d@%d: %s, sz=%d, class_serial_num=%u,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                             " id=0x%x, trace_serial_num=%u, name_id=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                nrecord, npos, label, size, class_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                                id, trace_serial_num, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            CASE_TAG(HPROF_UNLOAD_CLASS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                CHECK_FOR_ERROR(size==4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                class_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                check_printf("#%d@%d: %s, sz=%d, class_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                                nrecord, npos, label, size, class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            CASE_TAG(HPROF_FRAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                CHECK_FOR_ERROR(size==2*4+4*(int)sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                nm = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                sg = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                so = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                class_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                li = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                check_printf("#%d@%d: %s, sz=%d, ", nrecord, npos, label, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                check_print_utf8(utab, "id=", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                check_printf(" name_id=0x%x, sig_id=0x%x, source_id=0x%x,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                             " class_serial_num=%u, lineno=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                                nm, sg, so, class_serial_num, li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            CASE_TAG(HPROF_TRACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                CHECK_FOR_ERROR(size>=3*4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                thread_serial_num = read_u4(&p); /* Can be 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                num_elements = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                check_printf("#%d@%d: %s, sz=%d, trace_serial_num=%u,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                             " thread_serial_num=%u, nelems=%d [",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                nrecord, npos, label, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                                trace_serial_num, thread_serial_num, num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                for(i=0; i< num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    check_printf("0x%x,", read_id(&p));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                check_printf("]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            CASE_TAG(HPROF_ALLOC_SITES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                CHECK_FOR_ERROR(size>=2+4*4+2*8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                flags = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                temp  = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                cutoff = *((float*)&temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                nblive = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                nilive = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                tbytes = read_u8(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                tinsts = read_u8(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                num_elements     = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                check_printf("#%d@%d: %s, sz=%d, flags=0x%x, cutoff=%g,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                             " nblive=%d, nilive=%d, tbytes=(%d,%d),"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                             " tinsts=(%d,%d), num_elements=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                nrecord, npos, label, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                                flags, cutoff, nblive, nilive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                                jlong_high(tbytes), jlong_low(tbytes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                                jlong_high(tinsts), jlong_low(tinsts),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                                num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                for(i=0; i< num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    ty = read_u1(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    class_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    nblive = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    nilive = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    tbytes = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                    tinsts = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                    check_printf("\t %d: ty=%d, class_serial_num=%u,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                 " trace_serial_num=%u, nblive=%d, nilive=%d,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                                 " tbytes=%d, tinsts=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                                 i, ty, class_serial_num, trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                 nblive, nilive, (jint)tbytes, (jint)tinsts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            CASE_TAG(HPROF_HEAP_SUMMARY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                CHECK_FOR_ERROR(size==2*4+2*8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                nblive = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                nilive = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                tbytes = read_u8(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                tinsts = read_u8(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                check_printf("#%d@%d: %s, sz=%d,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                             " nblive=%d, nilive=%d, tbytes=(%d,%d),"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                             " tinsts=(%d,%d)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                                nrecord, npos, label, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                                nblive, nilive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                                jlong_high(tbytes), jlong_low(tbytes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                                jlong_high(tinsts), jlong_low(tinsts));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            CASE_TAG(HPROF_START_THREAD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                CHECK_FOR_ERROR(size==2*4+4*(int)sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                id = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                nm = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                gr = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                gn = read_id(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                check_printf("#%d@%d: %s, sz=%d, thread_serial_num=%u,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                             " id=0x%x, trace_serial_num=%u, ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                                nrecord, npos, label, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                                thread_serial_num, id, trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                check_print_utf8(utab, "nm=", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                check_printf(" trace_serial_num=%u, nm=0x%x,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                             " gr=0x%x, gn=0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                                trace_serial_num, nm, gr, gn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            CASE_TAG(HPROF_END_THREAD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                CHECK_FOR_ERROR(size==4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                thread_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                check_printf("#%d@%d: %s, sz=%d, thread_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                nrecord, npos, label, size, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            CASE_TAG(HPROF_HEAP_DUMP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                check_printf("#%d@%d: BEGIN: %s, sz=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                                nrecord, npos, label, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                nheap_records = check_heap_tags(utab, p, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                check_printf("#%d@%d: END: %s, sz=%d, nheap_recs=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                nrecord, npos, label, size, nheap_records);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                p += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            CASE_TAG(HPROF_HEAP_DUMP_SEGMENT) /* 1.0.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                check_printf("#%d@%d: BEGIN SEGMENT: %s, sz=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                                nrecord, npos, label, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                nheap_records = check_heap_tags(utab, p, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                check_printf("#%d@%d: END SEGMENT: %s, sz=%d, nheap_recs=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                                nrecord, npos, label, size, nheap_records);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                p += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            CASE_TAG(HPROF_HEAP_DUMP_END) /* 1.0.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                check_printf("#%d@%d: SEGMENT END: %s, sz=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                                nrecord, npos, label, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            CASE_TAG(HPROF_CPU_SAMPLES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                CHECK_FOR_ERROR(size>=2*4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                total_samples = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                trace_count = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                check_printf("#%d@%d: %s, sz=%d, total_samples=%d,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                             " trace_count=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                                nrecord, npos, label, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                total_samples, trace_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                for(i=0; i< trace_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    num_elements = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                    trace_serial_num = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                    check_printf("\t %d: samples=%d, trace_serial_num=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                 trace_serial_num, num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            CASE_TAG(HPROF_CONTROL_SETTINGS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                CHECK_FOR_ERROR(size==4+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                flags = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                depth = read_u2(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                check_printf("#%d@%d: %s, sz=%d, flags=0x%x, depth=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                                nrecord, npos, label, size, flags, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                label = "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                check_printf("#%d@%d: %s, sz=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                nrecord, npos, label, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                HPROF_ERROR(JNI_TRUE, "unknown record type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                p += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        CHECK_FOR_ERROR(p<=(pstart+nbytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    check_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    CHECK_FOR_ERROR(p==(pstart+nbytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    table_cleanup(utab, &utab_cleanup, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    return nrecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
/* Read the entire file into memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
static void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
get_binary_file_image(char *filename, int *pnbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    unsigned char *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    int            fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    jlong          nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    int            nread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    *pnbytes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    fd = md_open_binary(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    CHECK_FOR_ERROR(fd>=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    if ( (nbytes = md_seek(fd, (jlong)-1)) == (jlong)-1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        HPROF_ERROR(JNI_TRUE, "Cannot md_seek() to end of file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    CHECK_FOR_ERROR(((jint)nbytes)>512);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    if ( md_seek(fd, (jlong)0) != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        HPROF_ERROR(JNI_TRUE, "Cannot md_seek() to start of file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    image = HPROF_MALLOC(((jint)nbytes)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    CHECK_FOR_ERROR(image!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    /* Read the entire file image into memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    nread = md_read(fd, image, (jint)nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    if ( nread <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        HPROF_ERROR(JNI_TRUE, "System read failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    CHECK_FOR_ERROR(((jint)nbytes)==nread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    md_close(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    *pnbytes = (jint)nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
/* ------------------------------------------------------------------ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
check_binary_file(char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    unsigned char *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    unsigned char *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    unsigned       idsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    int            nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    int            nrecords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    image = get_binary_file_image(filename, &nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    if ( image == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        check_printf("No file image: %s\n", filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    p = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    CHECK_FOR_ERROR(strcmp((char*)p, gdata->header)==0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    check_printf("Filename=%s, nbytes=%d, header=\"%s\"\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                        filename, nbytes, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    p+=((int)strlen((char*)p)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    idsize = read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    CHECK_FOR_ERROR(idsize==sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    (void)read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    (void)read_u4(&p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /* LINTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    nrecords = check_tags(p, nbytes - (int)( p - image ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    check_printf("#%d total records found in %d bytes\n", nrecords, nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    HPROF_FREE(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
}