jdk/src/jdk.hprof.agent/share/native/libhprof/hprof_io.c
author tschatzl
Wed, 19 Aug 2015 13:59:39 +0200
changeset 32379 aa14adafaf0f
parent 26201 40a873d21081
permissions -rw-r--r--
8073013: Add detailed information about PLAB memory usage Summary: Track and provide information about direct allocation, region end waste and failure waste for G1. Reviewed-by: jmasa, david, ehelin, mgerdin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10292
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* All I/O functionality for hprof. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The hprof agent has many forms of output:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   format=b   gdata->output_format=='b'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      Binary format. Defined below. This is used by HAT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      This is NOT the same format as emitted by JVMPI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   format=a   gdata->output_format=='a'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      Ascii format. Not exactly an ascii representation of the binary format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * And many forms of dumps:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *    heap=dump
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *        A large dump that in this implementation is written to a separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *        file first before being placed in the output file. Several reasons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *        the binary form needs a byte count of the length in the header, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *        references in this dump to other items need to be emitted first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *        So it's two pass, or use a temp file and copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *    heap=sites
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *        Dumps the sites in the order of most allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *    cpu=samples
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *        Dumps the traces in order of most hits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *    cpu=times
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *        Dumps the traces in the order of most time spent there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *    cpu=old   (format=a only)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *        Dumps out an older form of cpu output (old -prof format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *    monitor=y (format=a only)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *        Dumps out a list of monitors in order of most contended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * This file also includes a binary format check function that will read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   back in the hprof binary format and verify the syntax looks correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * WARNING: Besides the comments below, there is little format spec on this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *          however see:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *           http://java.sun.com/j2se/1.4.2/docs/guide/jvmpi/jvmpi.html#hprof
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
typedef TableIndex HprofId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#include "hprof_ioname.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#include "hprof_b_spec.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
static int type_size[ /*HprofType*/ ] =  HPROF_TYPE_SIZES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static void dump_heap_segment_and_reset(jlong segment_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
not_implemented(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
static IoNameIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
get_name_index(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    if (name != NULL && gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return ioname_find_or_create(name, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
signature_to_name(char *sig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    char *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    char *basename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    int name_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if ( sig != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        switch ( sig[0] ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            case JVM_SIGNATURE_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                ptr = strchr(sig+1, JVM_SIGNATURE_ENDCLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                if ( ptr == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    basename = "Unknown_class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                name_len = (jint)(ptr - (sig+1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                name = HPROF_MALLOC(name_len+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                (void)memcpy(name, sig+1, name_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                name[name_len] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                for ( i = 0 ; i < name_len ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    if ( name[i] == '/' ) name[i] = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            case JVM_SIGNATURE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                basename = signature_to_name(sig+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                len = (int)strlen(basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                name_len = len+2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                name = HPROF_MALLOC(name_len+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                (void)memcpy(name, basename, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                (void)memcpy(name+len, "[]", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                name[name_len] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                HPROF_FREE(basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            case JVM_SIGNATURE_FUNC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                ptr = strchr(sig+1, JVM_SIGNATURE_ENDFUNC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                if ( ptr == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    basename = "Unknown_method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                basename = "()"; /* Someday deal with method signatures */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            case JVM_SIGNATURE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                basename = "byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            case JVM_SIGNATURE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                basename = "char";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            case JVM_SIGNATURE_ENUM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                basename = "enum";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            case JVM_SIGNATURE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                basename = "float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            case JVM_SIGNATURE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                basename = "double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            case JVM_SIGNATURE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                basename = "int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            case JVM_SIGNATURE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                basename = "long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            case JVM_SIGNATURE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                basename = "short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            case JVM_SIGNATURE_VOID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                basename = "void";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            case JVM_SIGNATURE_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                basename = "boolean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                basename = "Unknown_class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        basename = "Unknown_class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /* Simple basename */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    name_len = (int)strlen(basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    name = HPROF_MALLOC(name_len+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    (void)strcpy(name, basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
size_from_field_info(int size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    if ( size == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        size = (int)sizeof(HprofId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
type_from_signature(const char *sig, HprofType *kind, jint *size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    *kind = HPROF_NORMAL_OBJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    *size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    switch ( sig[0] ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        case JVM_SIGNATURE_ENUM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        case JVM_SIGNATURE_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        case JVM_SIGNATURE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            *kind = HPROF_NORMAL_OBJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        case JVM_SIGNATURE_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            *kind = HPROF_BOOLEAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        case JVM_SIGNATURE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            *kind = HPROF_CHAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        case JVM_SIGNATURE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            *kind = HPROF_FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        case JVM_SIGNATURE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            *kind = HPROF_DOUBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        case JVM_SIGNATURE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            *kind = HPROF_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        case JVM_SIGNATURE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            *kind = HPROF_SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        case JVM_SIGNATURE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            *kind = HPROF_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        case JVM_SIGNATURE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            *kind = HPROF_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    *size = type_size[*kind];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
type_array(const char *sig, HprofType *kind, jint *elem_size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    *kind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    *elem_size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    switch ( sig[0] ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        case JVM_SIGNATURE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            type_from_signature(sig+1, kind, elem_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
system_error(const char *system_call, int rc, int errnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    char buf[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    char details[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    details[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    if ( errnum != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        md_system_error(details, (int)sizeof(details));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    } else if ( rc >= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        (void)strcpy(details,"Only part of buffer processed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    if ( details[0] == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        (void)strcpy(details,"Unknown system error condition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    (void)md_snprintf(buf, sizeof(buf), "System %s failed: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            system_call, details);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    HPROF_ERROR(JNI_TRUE, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
system_write(int fd, void *buf, int len, jboolean socket)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    int res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    HPROF_ASSERT(fd>=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    if (socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        res = md_send(fd, buf, len, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (res < 0 || res!=len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            system_error("send", res, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        res = md_write(fd, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (res < 0 || res!=len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            system_error("write", res, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
write_flush(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    HPROF_ASSERT(gdata->fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (gdata->write_buffer_index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        system_write(gdata->fd, gdata->write_buffer, gdata->write_buffer_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                gdata->socket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        gdata->write_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
heap_flush(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    HPROF_ASSERT(gdata->heap_fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    if (gdata->heap_buffer_index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        gdata->heap_write_count += (jlong)gdata->heap_buffer_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        system_write(gdata->heap_fd, gdata->heap_buffer, gdata->heap_buffer_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        gdata->heap_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
write_raw(void *buf, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    HPROF_ASSERT(gdata->fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    if (gdata->write_buffer_index + len > gdata->write_buffer_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        write_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (len > gdata->write_buffer_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            system_write(gdata->fd, buf, len, gdata->socket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    (void)memcpy(gdata->write_buffer + gdata->write_buffer_index, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    gdata->write_buffer_index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
write_u4(unsigned i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    i = md_htonl(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    write_raw(&i, (jint)sizeof(unsigned));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
write_u8(jlong t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    write_u4((jint)jlong_high(t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    write_u4((jint)jlong_low(t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
write_u2(unsigned short i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    i = md_htons(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    write_raw(&i, (jint)sizeof(unsigned short));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
write_u1(unsigned char i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    write_raw(&i, (jint)sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
write_id(HprofId i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    write_u4(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
write_current_ticks(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    write_u4((jint)(md_get_microsecs() - gdata->micro_sec_ticks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
write_header(unsigned char type, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    write_u1(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    write_current_ticks();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    write_u4(length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
write_index_id(HprofId index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    write_id(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
static IoNameIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
write_name_first(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    if ( name == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        IoNameIndex name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        jboolean    new_one;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        new_one = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        name_index = ioname_find_or_create(name, &new_one);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if ( new_one ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            int      len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            len = (int)strlen(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            write_header(HPROF_UTF8, len + (jint)sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            write_index_id(name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            write_raw(name, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
write_printf(char *fmt, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    char buf[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    va_list args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    va_start(args, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    (void)md_vsnprintf(buf, sizeof(buf), fmt, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    buf[sizeof(buf)-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    write_raw(buf, (int)strlen(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    va_end(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
write_thread_serial_number(SerialNumber thread_serial_num, int with_comma)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    if ( thread_serial_num != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if ( with_comma ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            write_printf(" thread %d,", thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            write_printf(" thread %d", thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if ( with_comma ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            write_printf(" <unknown thread>,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            write_printf(" <unknown thread>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
heap_raw(void *buf, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    HPROF_ASSERT(gdata->heap_fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    if (gdata->heap_buffer_index + len > gdata->heap_buffer_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        heap_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (len > gdata->heap_buffer_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            gdata->heap_write_count += (jlong)len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            system_write(gdata->heap_fd, buf, len, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    (void)memcpy(gdata->heap_buffer + gdata->heap_buffer_index, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    gdata->heap_buffer_index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
heap_u4(unsigned i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    i = md_htonl(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    heap_raw(&i, (jint)sizeof(unsigned));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
heap_u8(jlong i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    heap_u4((jint)jlong_high(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    heap_u4((jint)jlong_low(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
heap_u2(unsigned short i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    i = md_htons(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    heap_raw(&i, (jint)sizeof(unsigned short));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
heap_u1(unsigned char i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    heap_raw(&i, (jint)sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
/* Write out the first byte of a heap tag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
heap_tag(unsigned char tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    jlong pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /* Current position in virtual heap dump file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    pos = gdata->heap_write_count + (jlong)gdata->heap_buffer_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    if ( gdata->segmented == JNI_TRUE ) { /* 1.0.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if ( pos >= gdata->maxHeapSegment ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            /* Flush all bytes to the heap dump file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            heap_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            /* Send out segment (up to last tag written out) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            dump_heap_segment_and_reset(gdata->heap_last_tag_position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            /* Get new current position */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            pos = gdata->heap_write_count + (jlong)gdata->heap_buffer_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /* Save position of this tag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    gdata->heap_last_tag_position = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /* Write out this tag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    heap_u1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
heap_id(HprofId i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    heap_u4(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
heap_index_id(HprofId index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    heap_id(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
heap_name(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    heap_index_id(get_name_index(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
heap_printf(char *fmt, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    char buf[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    va_list args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    va_start(args, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    (void)md_vsnprintf(buf, sizeof(buf), fmt, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    buf[sizeof(buf)-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    heap_raw(buf, (int)strlen(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    va_end(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
heap_element(HprofType kind, jint size, jvalue value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    if ( !HPROF_TYPE_IS_PRIMITIVE(kind) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        HPROF_ASSERT(size==4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        heap_id((HprofId)value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        switch ( size ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                HPROF_ASSERT(size==8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                HPROF_ASSERT(kind==HPROF_LONG || kind==HPROF_DOUBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                heap_u8(value.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                HPROF_ASSERT(size==4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                HPROF_ASSERT(kind==HPROF_INT || kind==HPROF_FLOAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                heap_u4(value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                HPROF_ASSERT(size==2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                HPROF_ASSERT(kind==HPROF_SHORT || kind==HPROF_CHAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                heap_u2(value.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                HPROF_ASSERT(size==1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                HPROF_ASSERT(kind==HPROF_BOOLEAN || kind==HPROF_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                HPROF_ASSERT(kind==HPROF_BOOLEAN?(value.b==0 || value.b==1):1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                heap_u1(value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                HPROF_ASSERT(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
/* Dump out all elements of an array, objects in jvalues, prims packed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
heap_elements(HprofType kind, jint num_elements, jint elem_size, void *elements)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    int     i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    jvalue  val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    static jvalue empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    if ( num_elements == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    switch ( kind ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        case HPROF_ARRAY_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        case HPROF_NORMAL_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            for (i = 0; i < num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                val   = empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                val.i = ((ObjectIndex*)elements)[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                heap_element(kind, elem_size, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        case HPROF_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        case HPROF_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            HPROF_ASSERT(elem_size==1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            for (i = 0; i < num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                val   = empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                val.b = ((jboolean*)elements)[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                heap_element(kind, elem_size, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        case HPROF_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        case HPROF_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            HPROF_ASSERT(elem_size==2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            for (i = 0; i < num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                val   = empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                val.s = ((jshort*)elements)[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                heap_element(kind, elem_size, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        case HPROF_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        case HPROF_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            HPROF_ASSERT(elem_size==4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            for (i = 0; i < num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                val   = empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                val.i = ((jint*)elements)[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                heap_element(kind, elem_size, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        case HPROF_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        case HPROF_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            HPROF_ASSERT(elem_size==8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            for (i = 0; i < num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                val   = empty_val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                val.j = ((jlong*)elements)[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                heap_element(kind, elem_size, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
/* ------------------------------------------------------------------ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
io_flush(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    HPROF_ASSERT(gdata->header!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    write_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
io_setup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    gdata->write_buffer_size = FILE_IO_BUFFER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    gdata->write_buffer = HPROF_MALLOC(gdata->write_buffer_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    gdata->write_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    gdata->heap_write_count = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    gdata->heap_last_tag_position = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    gdata->heap_buffer_size = FILE_IO_BUFFER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    gdata->heap_buffer = HPROF_MALLOC(gdata->heap_buffer_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    gdata->heap_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    if ( gdata->logflags & LOG_CHECK_BINARY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        gdata->check_buffer_size = FILE_IO_BUFFER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        gdata->check_buffer = HPROF_MALLOC(gdata->check_buffer_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        gdata->check_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    ioname_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
io_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    if ( gdata->write_buffer != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        HPROF_FREE(gdata->write_buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    gdata->write_buffer_size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    gdata->write_buffer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    gdata->write_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    if ( gdata->heap_buffer != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        HPROF_FREE(gdata->heap_buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    gdata->heap_write_count = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    gdata->heap_last_tag_position = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    gdata->heap_buffer_size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    gdata->heap_buffer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    gdata->heap_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    if ( gdata->logflags & LOG_CHECK_BINARY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if ( gdata->check_buffer != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            HPROF_FREE(gdata->check_buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        gdata->check_buffer_size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        gdata->check_buffer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        gdata->check_buffer_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    ioname_cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
io_write_file_header(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    HPROF_ASSERT(gdata->header!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        jint settings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        jlong t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        settings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (gdata->heap_dump || gdata->alloc_sites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            settings |= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if (gdata->cpu_sampling) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            settings |= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        t = md_get_timemillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        write_raw(gdata->header, (int)strlen(gdata->header) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        write_u4((jint)sizeof(HprofId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        write_u8(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        write_header(HPROF_CONTROL_SETTINGS, 4 + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        write_u4(settings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        write_u2((unsigned short)gdata->max_trace_depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    } else if ((!gdata->cpu_timing) || (!gdata->old_timing_format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        /* We don't want the prelude file for the old prof output format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        time_t t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        char prelude_file[FILENAME_MAX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        int prelude_fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        int nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        t = time(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        md_get_prelude_path(prelude_file, sizeof(prelude_file), PRELUDE_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        prelude_fd = md_open(prelude_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (prelude_fd < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            char buf[FILENAME_MAX+80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            (void)md_snprintf(buf, sizeof(buf), "Can't open %s", prelude_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            buf[sizeof(buf)-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            HPROF_ERROR(JNI_TRUE, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        write_printf("%s, created %s\n", gdata->header, ctime(&t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            char buf[1024]; /* File is small, small buffer ok here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            nbytes = md_read(prelude_fd, buf, sizeof(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            if ( nbytes < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                system_error("read", nbytes, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (nbytes == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            write_raw(buf, nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        } while ( nbytes > 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        md_close(prelude_fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        write_printf("\n--------\n\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        write_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
io_write_file_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    HPROF_ASSERT(gdata->header!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
io_write_class_load(SerialNumber class_serial_num, ObjectIndex index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    SerialNumber trace_serial_num, char *sig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        IoNameIndex name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        char *class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        class_name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        name_index = write_name_first(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        write_header(HPROF_LOAD_CLASS, (2 * (jint)sizeof(HprofId)) + (4 * 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        write_u4(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        write_index_id(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        write_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        write_index_id(name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
io_write_class_unload(SerialNumber class_serial_num, ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        write_header(HPROF_UNLOAD_CLASS, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        write_u4(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
io_write_sites_header(const char * comment_str, jint flags, double cutoff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    jint total_live_bytes, jint total_live_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    jlong total_alloced_bytes, jlong total_alloced_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    jint count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    if ( gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        write_header(HPROF_ALLOC_SITES, 2 + (8 * 4) + (count * (4 * 6 + 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        write_u2((unsigned short)flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        write_u4(*(int *)(&cutoff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        write_u4(total_live_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        write_u4(total_live_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        write_u8(total_alloced_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        write_u8(total_alloced_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        write_u4(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        time_t t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        t = time(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        write_printf("SITES BEGIN (ordered by %s) %s", comment_str, ctime(&t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        write_printf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            "          percent          live          alloc'ed  stack class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        write_printf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            " rank   self  accum     bytes objs     bytes  objs trace name\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
io_write_sites_elem(jint index, double ratio, double accum_percent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                char *sig, SerialNumber class_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                SerialNumber trace_serial_num, jint n_live_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                jint n_live_instances, jint n_alloced_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                jint n_alloced_instances)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    if ( gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        type_array(sig, &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        write_u1(kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        write_u4(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        write_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        write_u4(n_live_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        write_u4(n_live_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        write_u4(n_alloced_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        write_u4(n_alloced_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        char *class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        class_name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        write_printf("%5u %5.2f%% %5.2f%% %9u %4u %9u %5u %5u %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                     index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                     ratio * 100.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                     accum_percent * 100.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                     n_live_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                     n_live_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                     n_alloced_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                     n_alloced_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                     trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                     class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
io_write_sites_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        write_printf("SITES END\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
io_write_thread_start(SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                        ObjectIndex thread_obj_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                        SerialNumber trace_serial_num, char *thread_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                        char *thread_group_name, char *thread_parent_name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        IoNameIndex tname_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        IoNameIndex gname_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        IoNameIndex pname_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        tname_index = write_name_first(thread_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        gname_index = write_name_first(thread_group_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        pname_index = write_name_first(thread_parent_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        write_header(HPROF_START_THREAD, ((jint)sizeof(HprofId) * 4) + (4 * 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        write_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        write_index_id(thread_obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        write_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        write_index_id(tname_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        write_index_id(gname_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        write_index_id(pname_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    } else if ( (!gdata->cpu_timing) || (!gdata->old_timing_format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        /* We don't want thread info for the old prof output format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        write_printf("THREAD START "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                     "(obj=%x, id = %d, name=\"%s\", group=\"%s\")\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                     thread_obj_id, thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                     (thread_name==NULL?"":thread_name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                     (thread_group_name==NULL?"":thread_group_name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
io_write_thread_end(SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        write_header(HPROF_END_THREAD, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        write_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    } else if ( (!gdata->cpu_timing) || (!gdata->old_timing_format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        /* we don't want thread info for the old prof output format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        write_printf("THREAD END (id = %d)\n", thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
io_write_frame(FrameIndex index, SerialNumber frame_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
               char *mname, char *msig, char *sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
               SerialNumber class_serial_num, jint lineno)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    CHECK_CLASS_SERIAL_NO(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        IoNameIndex mname_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        IoNameIndex msig_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        IoNameIndex sname_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        mname_index = write_name_first(mname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        msig_index  = write_name_first(msig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        sname_index = write_name_first(sname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        write_header(HPROF_FRAME, ((jint)sizeof(HprofId) * 4) + (4 * 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        write_index_id(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        write_index_id(mname_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        write_index_id(msig_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        write_index_id(sname_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        write_u4(class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        write_u4(lineno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
io_write_trace_header(SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                SerialNumber thread_serial_num, jint n_frames, char *phase_str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        write_header(HPROF_TRACE, ((jint)sizeof(HprofId) * n_frames) + (4 * 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        write_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        write_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        write_u4(n_frames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        write_printf("TRACE %u:", trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        if (thread_serial_num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            write_printf(" (thread=%d)", thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        if ( phase_str != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            write_printf(" (from %s phase of JVM)", phase_str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        write_printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (n_frames == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            write_printf("\t<empty>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
io_write_trace_elem(SerialNumber trace_serial_num, FrameIndex frame_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    SerialNumber frame_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                    char *csig, char *mname, char *sname, jint lineno)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        write_index_id(frame_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        char *class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        char linebuf[32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        if (lineno == -2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            (void)md_snprintf(linebuf, sizeof(linebuf), "Compiled method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        } else if (lineno == -3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            (void)md_snprintf(linebuf, sizeof(linebuf), "Native method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        } else if (lineno == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            (void)md_snprintf(linebuf, sizeof(linebuf), "Unknown line");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            (void)md_snprintf(linebuf, sizeof(linebuf), "%d", lineno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        linebuf[sizeof(linebuf)-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        class_name = signature_to_name(csig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if ( mname == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            mname = "<Unknown Method>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        if ( sname == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            sname = "<Unknown Source>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        write_printf("\t%s.%s(%s:%s)\n", class_name, mname, sname, linebuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
io_write_trace_footer(SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                SerialNumber thread_serial_num, jint n_frames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
#define CPU_SAMPLES_RECORD_NAME ("CPU SAMPLES")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
#define CPU_TIMES_RECORD_NAME ("CPU TIME (ms)")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
io_write_cpu_samples_header(jlong total_cost, jint n_items)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        write_header(HPROF_CPU_SAMPLES, (n_items * (4 * 2)) + (4 * 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        write_u4((jint)total_cost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        write_u4(n_items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        time_t t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        char *record_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if ( gdata->cpu_sampling ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            record_name = CPU_SAMPLES_RECORD_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            record_name = CPU_TIMES_RECORD_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        t = time(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        write_printf("%s BEGIN (total = %d) %s", record_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                     /*jlong*/(int)total_cost, ctime(&t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        if ( n_items > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            write_printf("rank   self  accum   count trace method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
io_write_cpu_samples_elem(jint index, double percent, double accum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                jint num_hits, jlong cost, SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                jint n_frames, char *csig, char *mname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        write_u4((jint)cost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        write_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        write_printf("%4u %5.2f%% %5.2f%% %7u %5u",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                     index, percent, accum, num_hits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                     trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        if (n_frames > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            char * class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            class_name = signature_to_name(csig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            write_printf(" %s.%s\n", class_name, mname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            write_printf(" <empty trace>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
io_write_cpu_samples_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        char *record_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        if ( gdata->cpu_sampling ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            record_name = CPU_SAMPLES_RECORD_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            record_name = CPU_TIMES_RECORD_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        write_printf("%s END\n", record_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
io_write_heap_summary(jlong total_live_bytes, jlong total_live_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                jlong total_alloced_bytes, jlong total_alloced_instances)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        write_header(HPROF_HEAP_SUMMARY, 4 * 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        write_u4((jint)total_live_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        write_u4((jint)total_live_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        write_u8(total_alloced_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        write_u8(total_alloced_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
io_write_oldprof_header(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    if ( gdata->old_timing_format ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        write_printf("count callee caller time\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
io_write_oldprof_elem(jint num_hits, jint num_frames, char *csig_callee,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            char *mname_callee, char *msig_callee, char *csig_caller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            char *mname_caller, char *msig_caller, jlong cost)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    if ( gdata->old_timing_format ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        char * class_name_callee;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        char * class_name_caller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        class_name_callee = signature_to_name(csig_callee);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        class_name_caller = signature_to_name(csig_caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        write_printf("%d ", num_hits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        if (num_frames >= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            write_printf("%s.%s%s ", class_name_callee,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                 mname_callee,  msig_callee);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            write_printf("%s ", "<unknown callee>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        if (num_frames > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            write_printf("%s.%s%s ", class_name_caller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                 mname_caller,  msig_caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            write_printf("%s ", "<unknown caller>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        write_printf("%d\n", (int)cost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        HPROF_FREE(class_name_callee);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        HPROF_FREE(class_name_caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
io_write_oldprof_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
io_write_monitor_header(jlong total_time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        time_t t = time(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        t = time(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        write_printf("MONITOR TIME BEGIN (total = %u ms) %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                                (int)total_time, ctime(&t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        if (total_time > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            write_printf("rank   self  accum   count trace monitor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
io_write_monitor_elem(jint index, double percent, double accum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            jint num_hits, SerialNumber trace_serial_num, char *sig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        char *class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        class_name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        write_printf("%4u %5.2f%% %5.2f%% %7u %5u %s (Java)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                     index, percent, accum, num_hits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                     trace_serial_num, class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
io_write_monitor_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        write_printf("MONITOR TIME END\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
io_write_monitor_sleep(jlong timeout, SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        if ( thread_serial_num == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            write_printf("SLEEP: timeout=%d, <unknown thread>\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                        (int)timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            write_printf("SLEEP: timeout=%d, thread %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                        (int)timeout, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
io_write_monitor_wait(char *sig, jlong timeout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        if ( thread_serial_num == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            write_printf("WAIT: MONITOR %s, timeout=%d, <unknown thread>\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                        sig, (int)timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            write_printf("WAIT: MONITOR %s, timeout=%d, thread %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                        sig, (int)timeout, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
io_write_monitor_waited(char *sig, jlong time_waited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        if ( thread_serial_num == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            write_printf("WAITED: MONITOR %s, time_waited=%d, <unknown thread>\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                        sig, (int)time_waited);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            write_printf("WAITED: MONITOR %s, time_waited=%d, thread %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                        sig, (int)time_waited, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
io_write_monitor_exit(char *sig, SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        if ( thread_serial_num == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            write_printf("EXIT: MONITOR %s, <unknown thread>\n", sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            write_printf("EXIT: MONITOR %s, thread %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                        sig, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
io_write_monitor_dump_header(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        write_printf("MONITOR DUMP BEGIN\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
io_write_monitor_dump_thread_state(SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                      SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                      jint threadState)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        char tstate[20];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        tstate[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        if (threadState & JVMTI_THREAD_STATE_SUSPENDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            (void)strcat(tstate,"S|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        if (threadState & JVMTI_THREAD_STATE_INTERRUPTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            (void)strcat(tstate,"intr|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        if (threadState & JVMTI_THREAD_STATE_IN_NATIVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            (void)strcat(tstate,"native|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        if ( ! ( threadState & JVMTI_THREAD_STATE_ALIVE ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            if ( threadState & JVMTI_THREAD_STATE_TERMINATED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                (void)strcat(tstate,"ZO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                (void)strcat(tstate,"NS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            if ( threadState & JVMTI_THREAD_STATE_SLEEPING ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                (void)strcat(tstate,"SL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            } else if ( threadState & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                (void)strcat(tstate,"MW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            } else if ( threadState & JVMTI_THREAD_STATE_WAITING ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                (void)strcat(tstate,"CW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            } else if ( threadState & JVMTI_THREAD_STATE_RUNNABLE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                (void)strcat(tstate,"R");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                (void)strcat(tstate,"UN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        write_printf("    THREAD %d, trace %d, status: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                     thread_serial_num, trace_serial_num, tstate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
io_write_monitor_dump_state(char *sig, SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                    jint entry_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                    SerialNumber *waiters, jint waiter_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                    SerialNumber *notify_waiters, jint notify_waiter_count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        if ( thread_serial_num != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            write_printf("    MONITOR %s\n", sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            write_printf("\towner: thread %d, entry count: %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                thread_serial_num, entry_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            write_printf("    MONITOR %s unowned\n", sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        write_printf("\twaiting to enter:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        for (i = 0; i < waiter_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            write_thread_serial_number(waiters[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                                (i != (waiter_count-1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        write_printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        write_printf("\twaiting to be notified:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        for (i = 0; i < notify_waiter_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            write_thread_serial_number(notify_waiters[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                                (i != (notify_waiter_count-1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        write_printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
io_write_monitor_dump_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        not_implemented();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        write_printf("MONITOR DUMP END\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
/* ----------------------------------------------------------------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
/* These functions write to a separate file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
io_heap_header(jlong total_live_instances, jlong total_live_bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    if (gdata->output_format != 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        time_t t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        t = time(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        heap_printf("HEAP DUMP BEGIN (%u objects, %u bytes) %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                        /*jlong*/(int)total_live_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                        /*jlong*/(int)total_live_bytes, ctime(&t));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
io_heap_root_thread_object(ObjectIndex thread_obj_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                SerialNumber thread_serial_num, SerialNumber trace_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
         heap_tag(HPROF_GC_ROOT_THREAD_OBJ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
         heap_id(thread_obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
         heap_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
         heap_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        heap_printf("ROOT %x (kind=<thread>, id=%u, trace=%u)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                     thread_obj_id, thread_serial_num, trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
io_heap_root_unknown(ObjectIndex obj_id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        heap_tag(HPROF_GC_ROOT_UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        heap_printf("ROOT %x (kind=<unknown>)\n", obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
io_heap_root_jni_global(ObjectIndex obj_id, SerialNumber gref_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                         SerialNumber trace_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        heap_tag(HPROF_GC_ROOT_JNI_GLOBAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        heap_id(gref_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        heap_printf("ROOT %x (kind=<JNI global ref>, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                     "id=%x, trace=%u)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                     obj_id, gref_serial_num, trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
io_heap_root_jni_local(ObjectIndex obj_id, SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        jint frame_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        heap_tag(HPROF_GC_ROOT_JNI_LOCAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        heap_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        heap_u4(frame_depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        heap_printf("ROOT %x (kind=<JNI local ref>, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                     "thread=%u, frame=%d)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                     obj_id, thread_serial_num, frame_depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
io_heap_root_system_class(ObjectIndex obj_id, char *sig, SerialNumber class_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        heap_tag(HPROF_GC_ROOT_STICKY_CLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        char *class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        class_name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        heap_printf("ROOT %x (kind=<system class>, name=%s)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                     obj_id, class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
io_heap_root_monitor(ObjectIndex obj_id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        heap_tag(HPROF_GC_ROOT_MONITOR_USED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        heap_printf("ROOT %x (kind=<busy monitor>)\n", obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
io_heap_root_thread(ObjectIndex obj_id, SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        heap_tag(HPROF_GC_ROOT_THREAD_BLOCK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        heap_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        heap_printf("ROOT %x (kind=<thread block>, thread=%u)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                     obj_id, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
io_heap_root_java_frame(ObjectIndex obj_id, SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        jint frame_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        heap_tag(HPROF_GC_ROOT_JAVA_FRAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        heap_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        heap_u4(frame_depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        heap_printf("ROOT %x (kind=<Java stack>, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                     "thread=%u, frame=%d)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                     obj_id, thread_serial_num, frame_depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
io_heap_root_native_stack(ObjectIndex obj_id, SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    CHECK_THREAD_SERIAL_NO(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        heap_tag(HPROF_GC_ROOT_NATIVE_STACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        heap_u4(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        heap_printf("ROOT %x (kind=<native stack>, thread=%u)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                     obj_id, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
is_static_field(jint modifiers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    if ( modifiers & JVM_ACC_STATIC ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
is_inst_field(jint modifiers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    if ( modifiers & JVM_ACC_STATIC ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
io_heap_class_dump(ClassIndex cnum, char *sig, ObjectIndex class_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                ObjectIndex super_id, ObjectIndex loader_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                ObjectIndex signers_id, ObjectIndex domain_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                jint size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                jint n_cpool, ConstantPoolValue *cpool,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                jint n_fields, FieldInfo *fields, jvalue *fvalues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        int  i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        jint n_static_fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        jint n_inst_fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        jint inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        jint saved_inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        n_static_fields = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        n_inst_fields = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        inst_size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        /* These do NOT go into the heap output */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        for ( i = 0 ; i < n_fields ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            if ( fields[i].cnum == cnum &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                 is_static_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                char *field_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                field_name = string_get(fields[i].name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                (void)write_name_first(field_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                n_static_fields++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            if ( is_inst_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                inst_size += size_from_field_info(fields[i].primSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                if ( fields[i].cnum == cnum ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                    char *field_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                    field_name = string_get(fields[i].name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    (void)write_name_first(field_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                    n_inst_fields++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        /* Verify that the instance size we have calculated as we went
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
         *   through the fields, matches what is saved away with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
         *   class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        if ( size >= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            saved_inst_size = class_get_inst_size(cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            if ( saved_inst_size == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                class_set_inst_size(cnum, inst_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            } else if ( saved_inst_size != inst_size ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                HPROF_ERROR(JNI_TRUE, "Mis-match on instance size in class dump");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        heap_tag(HPROF_GC_CLASS_DUMP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        heap_id(class_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        heap_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        heap_id(super_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        heap_id(loader_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        heap_id(signers_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        heap_id(domain_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        heap_id(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        heap_id(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        heap_u4(inst_size); /* Must match inst_size in instance dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        heap_u2((unsigned short)n_cpool);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        for ( i = 0 ; i < n_cpool ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
            jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            type_from_signature(string_get(cpool[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                            &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            heap_u2((unsigned short)(cpool[i].constant_pool_index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            heap_u1(kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            HPROF_ASSERT(!HPROF_TYPE_IS_PRIMITIVE(kind));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            heap_element(kind, size, cpool[i].value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        heap_u2((unsigned short)n_static_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        for ( i = 0 ; i < n_fields ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            if ( fields[i].cnum == cnum &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                 is_static_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                char *field_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                type_from_signature(string_get(fields[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                                &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                field_name = string_get(fields[i].name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                heap_name(field_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                heap_u1(kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                heap_element(kind, size, fvalues[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        heap_u2((unsigned short)n_inst_fields); /* Does not include super class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        for ( i = 0 ; i < n_fields ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            if ( fields[i].cnum == cnum &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                 is_inst_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                char *field_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                field_name = string_get(fields[i].name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                type_from_signature(string_get(fields[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                            &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                heap_name(field_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                heap_u1(kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        char * class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        class_name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        heap_printf("CLS %x (name=%s, trace=%u)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                     class_id, class_name, trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        if (super_id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            heap_printf("\tsuper\t\t%x\n", super_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        if (loader_id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            heap_printf("\tloader\t\t%x\n", loader_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        if (signers_id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            heap_printf("\tsigners\t\t%x\n", signers_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        if (domain_id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            heap_printf("\tdomain\t\t%x\n", domain_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        for ( i = 0 ; i < n_fields ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            if ( fields[i].cnum == cnum &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                 is_static_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                type_from_signature(string_get(fields[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                                &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                if ( !HPROF_TYPE_IS_PRIMITIVE(kind) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                    if (fvalues[i].i != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                        char *field_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                        field_name = string_get(fields[i].name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                        heap_printf("\tstatic %s\t%x\n", field_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                            fvalues[i].i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        for ( i = 0 ; i < n_cpool ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            type_from_signature(string_get(cpool[i].sig_index), &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            if ( !HPROF_TYPE_IS_PRIMITIVE(kind) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                if (cpool[i].value.i != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                    heap_printf("\tconstant pool entry %d\t%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                            cpool[i].constant_pool_index, cpool[i].value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
/* Dump the instance fields in the right order. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
dump_instance_fields(ClassIndex cnum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                     FieldInfo *fields, jvalue *fvalues, jint n_fields)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    ClassIndex super_cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    int        i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    int        nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
    HPROF_ASSERT(cnum!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    nbytes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    for (i = 0; i < n_fields; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        if ( fields[i].cnum == cnum &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
             is_inst_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            type_from_signature(string_get(fields[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                            &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            heap_element(kind, size, fvalues[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            nbytes += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    super_cnum = class_get_super(cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    if ( super_cnum != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        nbytes += dump_instance_fields(super_cnum, fields, fvalues, n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    return nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
io_heap_instance_dump(ClassIndex cnum, ObjectIndex obj_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                ObjectIndex class_id, jint size, char *sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                FieldInfo *fields, jvalue *fvalues, jint n_fields)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        jint inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        jint saved_inst_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        int  i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        int  nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        inst_size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        for (i = 0; i < n_fields; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            if ( is_inst_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                inst_size += size_from_field_info(fields[i].primSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        /* Verify that the instance size we have calculated as we went
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
         *   through the fields, matches what is saved away with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
         *   class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        saved_inst_size = class_get_inst_size(cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        if ( saved_inst_size == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            class_set_inst_size(cnum, inst_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        } else if ( saved_inst_size != inst_size ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            HPROF_ERROR(JNI_TRUE, "Mis-match on instance size in instance dump");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        heap_tag(HPROF_GC_INSTANCE_DUMP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        heap_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        heap_id(class_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        heap_u4(inst_size); /* Must match inst_size in class dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        /* Order must be class, super, super's super, ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        nbytes = dump_instance_fields(cnum, fields, fvalues, n_fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        HPROF_ASSERT(nbytes==inst_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        char * class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        class_name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        heap_printf("OBJ %x (sz=%u, trace=%u, class=%s@%x)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                     obj_id, size, trace_serial_num, class_name, class_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        HPROF_FREE(class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        for (i = 0; i < n_fields; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            if ( is_inst_field(fields[i].modifiers) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                type_from_signature(string_get(fields[i].sig_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                            &kind, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                if ( !HPROF_TYPE_IS_PRIMITIVE(kind) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    if (fvalues[i].i != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                        char *sep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                        ObjectIndex val_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                        char *field_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                        field_name = string_get(fields[i].name_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                        val_id =  (ObjectIndex)(fvalues[i].i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                        sep = (int)strlen(field_name) < 8 ? "\t" : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                        heap_printf("\t%s\t%s%x\n", field_name, sep, val_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
io_heap_object_array(ObjectIndex obj_id, SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                jint size, jint num_elements, char *sig, ObjectIndex *values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                ObjectIndex class_id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        heap_tag(HPROF_GC_OBJ_ARRAY_DUMP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        heap_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        heap_u4(num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        heap_id(class_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        heap_elements(HPROF_NORMAL_OBJECT, num_elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                (jint)sizeof(HprofId), (void*)values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        heap_printf("ARR %x (sz=%u, trace=%u, nelems=%u, elem type=%s@%x)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                     obj_id, size, trace_serial_num, num_elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                     name, class_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        for (i = 0; i < num_elements; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            ObjectIndex id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            id = values[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                heap_printf("\t[%u]\t\t%x\n", i, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        HPROF_FREE(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
io_heap_prim_array(ObjectIndex obj_id, SerialNumber trace_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
              jint size, jint num_elements, char *sig, void *elements)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
    CHECK_TRACE_SERIAL_NO(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        HprofType kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        jint  esize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        type_array(sig, &kind, &esize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        HPROF_ASSERT(HPROF_TYPE_IS_PRIMITIVE(kind));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        heap_tag(HPROF_GC_PRIM_ARRAY_DUMP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        heap_id(obj_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        heap_u4(trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        heap_u4(num_elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        heap_u1(kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        heap_elements(kind, num_elements, esize, elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        name = signature_to_name(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
        heap_printf("ARR %x (sz=%u, trace=%u, nelems=%u, elem type=%s)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                     obj_id, size, trace_serial_num, num_elements, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
        HPROF_FREE(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
/* Move file bytes into supplied raw interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
write_raw_from_file(int fd, jlong byteCount, void (*raw_interface)(void *,int))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    char *buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    int   buf_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
    int   left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
    int   nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    HPROF_ASSERT(fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    /* Move contents of this file into output file. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
    buf_len = FILE_IO_BUFFER_SIZE*2; /* Twice as big! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    buf = HPROF_MALLOC(buf_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
    HPROF_ASSERT(buf!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    /* Keep track of how many we have left */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    left = (int)byteCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        count = buf_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
        if ( count > left ) count = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        nbytes = md_read(fd, buf, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
        if (nbytes < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            system_error("read", nbytes, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        if (nbytes == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        if ( nbytes > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            (*raw_interface)(buf, nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            left -= nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
    } while ( left > 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    if (left > 0 && nbytes == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        HPROF_ERROR(JNI_TRUE, "File size is smaller than bytes written");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
    HPROF_FREE(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
/* Write out a heap segment, and copy remainder to top of file. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
dump_heap_segment_and_reset(jlong segment_size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
    int   fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    jlong last_chunk_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
    HPROF_ASSERT(gdata->heap_fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    /* Flush all bytes to the heap dump file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    heap_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    /* Last segment? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
    last_chunk_len = gdata->heap_write_count - segment_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    HPROF_ASSERT(last_chunk_len>=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    /* Re-open in proper way, binary vs. ascii is important */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    if (gdata->output_format == 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        int   tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        if ( gdata->segmented == JNI_TRUE ) { /* 1.0.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            tag = HPROF_HEAP_DUMP_SEGMENT; /* 1.0.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            tag = HPROF_HEAP_DUMP; /* Just one segment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            HPROF_ASSERT(last_chunk_len==0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        /* Write header for binary heap dump (don't know size until now) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        write_header(tag, (jint)segment_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        fd = md_open_binary(gdata->heapfilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        fd = md_open(gdata->heapfilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
    /* Move file bytes into hprof dump file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
    write_raw_from_file(fd, segment_size, &write_raw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
    /* Clear the byte count and reset the heap file. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    if ( md_seek(gdata->heap_fd, (jlong)0) != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        HPROF_ERROR(JNI_TRUE, "Cannot seek to beginning of heap info file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    gdata->heap_write_count = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    gdata->heap_last_tag_position = (jlong)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    /* Move trailing bytes from heap dump file to beginning of file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
    if ( last_chunk_len > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
        write_raw_from_file(fd, last_chunk_len, &heap_raw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    /* Close the temp file handle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    md_close(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
io_heap_footer(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
    HPROF_ASSERT(gdata->heap_fd >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    /* Flush all bytes to the heap dump file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    heap_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    /* Send out the last (or maybe only) segment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
    dump_heap_segment_and_reset(gdata->heap_write_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    /* Write out the last tag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    if (gdata->output_format != 'b') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        write_printf("HEAP DUMP END\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        if ( gdata->segmented == JNI_TRUE ) { /* 1.0.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            write_header(HPROF_HEAP_DUMP_END, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
}