jdk/src/demo/share/jvmti/hprof/hprof_site.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 14342 jdk/src/share/demo/jvmti/hprof/hprof_site.c@8435a30053c1
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10292
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* Allocation site table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Every object allocation will have a place where it was allocated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  this is the purpose of the SiteIndex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The allocation site or SiteIndex is unique via a (class,trace) pair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The allocation statistics are accumulated in the SiteInfo for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   site.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * This file also contains the heap iterate logic, which is closely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   associated with the site table, the object table, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   reference table. Each object has an element in the object table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   and as the heap is traversed, and information contained in each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   object is saved as a linked list of references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
typedef struct SiteKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    ClassIndex cnum;         /* Unique class number */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    TraceIndex trace_index;  /* Trace number */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
} SiteKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
typedef struct SiteInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    int         changed;               /* Objects at this site changed? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    unsigned    n_alloced_instances;   /* Total allocated instances */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    unsigned    n_alloced_bytes;       /* Total bytes allocated from here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    unsigned    n_live_instances;      /* Live instances for this site. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    unsigned    n_live_bytes;          /* Live byte count for this site. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
} SiteInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
typedef struct IterateInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    SiteIndex * site_nums;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    int         count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    int         changed_only;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
} IterateInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
/* Private internal functions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
static SiteKey*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
get_pkey(SiteIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    void *key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    int   key_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    table_get_key(gdata->site_table, index, &key_ptr, &key_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    HPROF_ASSERT(key_len==sizeof(SiteKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    return (SiteKey*)key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
site_get_class_index(SiteIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    SiteKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    return pkey->cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
TraceIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
site_get_trace_index(SiteIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    SiteKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    return pkey->trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
static SiteInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
get_info(SiteIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    SiteInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    info = (SiteInfo*)table_get_info(gdata->site_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
list_item(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    SiteKey         *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jlong            n_alloced_instances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    jlong            n_alloced_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    jlong            n_live_instances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    jlong            n_live_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    HPROF_ASSERT(key_len==sizeof(SiteKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    pkey = (SiteKey*)key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if ( info_ptr != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        SiteInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        info = (SiteInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        n_alloced_instances    = info->n_alloced_instances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        n_alloced_bytes        = info->n_alloced_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        n_live_instances       = info->n_live_instances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        n_live_bytes           = info->n_live_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        n_alloced_instances    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        n_alloced_bytes        = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        n_live_instances       = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        n_live_bytes           = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    debug_message( "Site 0x%08x: class=0x%08x, trace=0x%08x, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                          "Ninst=(%d,%d), Nbytes=(%d,%d), "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                          "Nlive=(%d,%d), NliveBytes=(%d,%d)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
             i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
             pkey->cnum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
             pkey->trace_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
             jlong_high(n_alloced_instances), jlong_low(n_alloced_instances),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
             jlong_high(n_alloced_bytes),     jlong_low(n_alloced_bytes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
             jlong_high(n_live_instances),    jlong_low(n_live_instances),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
             jlong_high(n_live_bytes),        jlong_low(n_live_bytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
collect_iterator(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    IterateInfo     *iterate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    HPROF_ASSERT(key_len==sizeof(SiteKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    HPROF_ASSERT(arg!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    iterate = (IterateInfo *)arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    if ( iterate->changed_only ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        SiteInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        info = (SiteInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if ( info==NULL || !info->changed ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    iterate->site_nums[iterate->count++] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
mark_unchanged_iterator(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    SiteInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    HPROF_ASSERT(key_len==sizeof(SiteKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    info = (SiteInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    if ( info != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        info->changed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
qsort_compare_allocated_bytes(const void *p_site1, const void *p_site2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    SiteIndex  site1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    SiteIndex  site2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    SiteInfo  *info1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    SiteInfo  *info2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    HPROF_ASSERT(p_site1!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    HPROF_ASSERT(p_site2!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    site1 = *(SiteIndex *)p_site1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    site2 = *(SiteIndex *)p_site2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    info1 = get_info(site1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    info2 = get_info(site2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    return info2->n_alloced_bytes - info1->n_alloced_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
qsort_compare_live_bytes(const void *p_site1, const void *p_site2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    SiteIndex  site1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    SiteIndex  site2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    SiteInfo  *info1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    SiteInfo  *info2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    HPROF_ASSERT(p_site1!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    HPROF_ASSERT(p_site2!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    site1 = *(SiteIndex *)p_site1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    site2 = *(SiteIndex *)p_site2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    info1 = get_info(site1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    info2 = get_info(site2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    return info2->n_live_bytes - info1->n_live_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
static ClassIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
find_cnum(jlong class_tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    ClassIndex  cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    ObjectIndex class_object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    SiteIndex   class_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    SiteKey    *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    class_object_index = tag_extract(class_tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    class_site_index = object_get_site(class_object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    pkey = get_pkey(class_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    cnum = pkey->cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    return cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
/* Create tag and object entry for an untagged object (should be rare) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
static jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
make_new_tag(jlong class_tag, jlong size, TraceIndex trace_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                  SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                  ObjectIndex *pindex, SiteIndex *psite)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    ObjectIndex object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    SiteIndex   object_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    object_site_index = site_find_or_create(find_cnum(class_tag), trace_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    object_index      = object_new(object_site_index, (jint)size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                   OBJECT_SYSTEM, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    if ( pindex != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        *pindex = object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    if ( psite != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        *psite = object_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    return tag_create(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
/* Setup tag on root object, if tagged return object index and site index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
setup_tag_on_root(jlong *tag_ptr, jlong class_tag, jlong size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                  SerialNumber thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                  ObjectIndex *pindex, SiteIndex *psite)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    if ( (*tag_ptr) != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if ( pindex != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            *pindex = tag_extract(*tag_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if ( psite != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            *psite = object_get_site(tag_extract(*tag_ptr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        /* Create and set the tag. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        *tag_ptr = make_new_tag(class_tag, size, gdata->system_trace_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                  thread_serial_num, pindex, psite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
/* External interfaces */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
SiteIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
site_find_or_create(ClassIndex cnum, TraceIndex trace_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    SiteIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    static SiteKey  empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    SiteKey   key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    key = empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    HPROF_ASSERT(cnum!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    HPROF_ASSERT(trace_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    key.cnum        = cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    key.trace_index = trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    index = table_find_or_create_entry(gdata->site_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                            &key, (int)sizeof(key), NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
site_init(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    HPROF_ASSERT(gdata->site_table==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    gdata->site_table = table_initialize("Site",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                            1024, 1024, 511, (int)sizeof(SiteInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
site_list(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        "--------------------- Site Table ------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    table_walk_items(gdata->site_table, &list_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        "----------------------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
site_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    table_cleanup(gdata->site_table, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    gdata->site_table = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
site_update_stats(SiteIndex index, jint size, jint hits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    SiteInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    table_lock_enter(gdata->site_table); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        info->n_live_instances          += hits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        info->n_live_bytes              += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        info->changed                   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        gdata->total_live_bytes         += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        gdata->total_live_instances     += hits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if ( size > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            info->n_alloced_instances   += hits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            info->n_alloced_bytes       += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            gdata->total_alloced_bytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                jlong_add(gdata->total_alloced_bytes, jint_to_jlong(size));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            gdata->total_alloced_instances =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                jlong_add(gdata->total_alloced_instances, jint_to_jlong(hits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    } table_lock_exit(gdata->site_table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
/* Output allocation sites, up to the given cut-off point, and according
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * to the given flags:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 *      SITE_DUMP_INCREMENTAL only dump what's changed since last dump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 *      SITE_SORT_BY_ALLOC    sort sites by total allocation rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 *                                  than live data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 *      SITE_FORCE_GC         force a GC before the site dump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
site_write(JNIEnv *env, int flags, double cutoff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    HPROF_ASSERT(gdata->site_table!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    LOG3("site_write", "flags", flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (flags & SITE_FORCE_GC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        runGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    HPROF_ASSERT(gdata->total_live_bytes!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    rawMonitorEnter(gdata->data_access_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        IterateInfo     iterate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        int             site_table_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        double          accum_percent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        void *          comment_str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        int             i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        int             cutoff_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        int             nbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        accum_percent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        site_table_size = table_element_count(gdata->site_table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        (void)memset(&iterate, 0, sizeof(iterate));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        nbytes            = site_table_size * (int)sizeof(SiteIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if ( nbytes > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            iterate.site_nums = HPROF_MALLOC(nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            (void)memset(iterate.site_nums, 0, nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        iterate.count   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        iterate.changed_only = flags & SITE_DUMP_INCREMENTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        table_walk_items(gdata->site_table, &collect_iterator, &iterate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        site_table_size = iterate.count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (flags & SITE_SORT_BY_ALLOC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            comment_str = "allocated bytes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            qsort(iterate.site_nums, site_table_size, sizeof(SiteIndex),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    &qsort_compare_allocated_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            comment_str = "live bytes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            qsort(iterate.site_nums, site_table_size, sizeof(SiteIndex),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    &qsort_compare_live_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        trace_output_unmarked(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        cutoff_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        for (i = 0; i < site_table_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            SiteInfo   *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            SiteIndex   index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            double      ratio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            index= iterate.site_nums[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            HPROF_ASSERT(index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            info        = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            ratio       = (double)info->n_live_bytes / (double)gdata->total_live_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (ratio < cutoff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            cutoff_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        io_write_sites_header(  comment_str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                cutoff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                gdata->total_live_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                                gdata->total_live_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                gdata->total_alloced_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                gdata->total_alloced_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                cutoff_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        for (i = 0; i < cutoff_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            SiteInfo     *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            SiteKey      *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            SiteIndex     index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            char         *class_signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            double        ratio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            index = iterate.site_nums[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            pkey         = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            info         = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            ratio       = (double)info->n_live_bytes / (double)gdata->total_live_bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            accum_percent += ratio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            class_signature  = string_get(class_get_signature(pkey->cnum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            io_write_sites_elem(i + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                ratio,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                accum_percent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                class_signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                class_get_serial_number(pkey->cnum),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                trace_get_serial_number(pkey->trace_index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                info->n_live_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                info->n_live_instances,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                info->n_alloced_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                info->n_alloced_instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        io_write_sites_footer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        table_walk_items(gdata->site_table, &mark_unchanged_iterator, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if ( iterate.site_nums != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            HPROF_FREE(iterate.site_nums);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    } rawMonitorExit(gdata->data_access_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
/* Primitive array data callback for FollowReferences */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
cbPrimArrayData(jlong class_tag, jlong size, jlong* tag_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         jint element_count, jvmtiPrimitiveType element_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         const void* elements, void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    ObjectIndex   object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    RefIndex      ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    RefIndex      prev_ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    HPROF_ASSERT(tag_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    HPROF_ASSERT((*tag_ptr)!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    if ( class_tag == (jlong)0 || (*tag_ptr) == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        /* We can't do anything with a class_tag==0, just skip it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /* Assume object has been tagged, get object index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    object_index = tag_extract((*tag_ptr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /* Save string data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    prev_ref_index = object_get_references(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    ref_index = reference_prim_array(prev_ref_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                  element_type, elements, element_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    object_set_references(object_index, ref_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
/* Primitive field data callback for FollowReferences */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
cbPrimFieldData(jvmtiHeapReferenceKind reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         const jvmtiHeapReferenceInfo* reference_info, jlong class_tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         jlong* tag_ptr, jvalue value, jvmtiPrimitiveType value_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    ObjectIndex   object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    jint          field_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    RefIndex      ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    RefIndex      prev_ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    HPROF_ASSERT(tag_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    HPROF_ASSERT((*tag_ptr)!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    if ( class_tag == (jlong)0 || (*tag_ptr) == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        /* We can't do anything with a class_tag==0, just skip it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /* If the field is 0, just skip it, we assume 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    if ( value.j == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /* Get field index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    field_index = reference_info->field.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /* We assume the object was tagged */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    object_index = tag_extract((*tag_ptr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /* Save primitive field data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    prev_ref_index = object_get_references(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    ref_index = reference_prim_field(prev_ref_index, reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                  value_type, value, field_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    object_set_references(object_index, ref_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
static SerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
checkThreadSerialNumber(SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    TlsIndex tls_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    if ( thread_serial_num == gdata->unknown_thread_serial_num ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        return thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    tls_index = tls_find(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    if ( tls_index != 0 && tls_get_in_heap_dump(tls_index) != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    return gdata->unknown_thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
/* Get the object index and thread serial number for this local object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
localReference(jlong *tag_ptr, jlong class_tag, jlong thread_tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     jlong size, ObjectIndex *pobject_index, SerialNumber *pthread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    ObjectIndex  object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    SerialNumber thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    HPROF_ASSERT(pobject_index!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    HPROF_ASSERT(pthread_serial_num!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    HPROF_ASSERT(tag_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    if ( (*tag_ptr) != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        object_index = tag_extract(*tag_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        thread_serial_num = object_get_thread_serial_number(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        thread_serial_num = checkThreadSerialNumber(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if ( thread_tag != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            ObjectIndex thread_object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            thread_object_index = tag_extract(thread_tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            thread_serial_num =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                   object_get_thread_serial_number(thread_object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            thread_serial_num = checkThreadSerialNumber(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            thread_serial_num = gdata->unknown_thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /* Create and set the tag. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        *tag_ptr = make_new_tag(class_tag, size, gdata->system_trace_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                  thread_serial_num, &object_index, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    HPROF_ASSERT(thread_serial_num!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    HPROF_ASSERT(object_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    *pobject_index      = object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    *pthread_serial_num = thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
/* Store away plain object reference information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
objectReference(jvmtiHeapReferenceKind reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                  const jvmtiHeapReferenceInfo* reference_info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                  jlong class_tag, jlong size, jlong* tag_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                  jlong* referrer_tag_ptr, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    ObjectIndex   object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    jint          reference_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    RefIndex      ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    RefIndex      prev_ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    ObjectIndex   referrer_object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    jlong         object_tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    HPROF_ASSERT(tag_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    HPROF_ASSERT(referrer_tag_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    HPROF_ASSERT((*referrer_tag_ptr)!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    if ( class_tag == (jlong)0 || (*referrer_tag_ptr) == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        /* We can't do anything with a class_tag==0, just skip it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    switch ( reference_kind ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        case JVMTI_HEAP_REFERENCE_CLASS_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        case JVMTI_HEAP_REFERENCE_INTERFACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            /* Currently we don't need these */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        case JVMTI_HEAP_REFERENCE_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        case JVMTI_HEAP_REFERENCE_STATIC_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            reference_index = reference_info->field.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            reference_index = reference_info->array.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        case JVMTI_HEAP_REFERENCE_CONSTANT_POOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            reference_index = reference_info->constant_pool.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        case JVMTI_HEAP_REFERENCE_SIGNERS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            reference_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /* We assume the referrer is tagged */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    referrer_object_index = tag_extract((*referrer_tag_ptr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /* Now check the referree */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    object_tag = *tag_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    if ( object_tag != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        object_index = tag_extract(object_tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        /* Create and set the tag. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        object_tag = make_new_tag(class_tag, size, gdata->system_trace_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                                  gdata->unknown_thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                  &object_index, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        *tag_ptr   = object_tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    HPROF_ASSERT(object_index!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /* Save reference information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    prev_ref_index = object_get_references(referrer_object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    ref_index = reference_obj(prev_ref_index, reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    object_index, reference_index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    object_set_references(referrer_object_index, ref_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
/* FollowReferences heap_reference_callback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
static jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
cbReference(jvmtiHeapReferenceKind reference_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                  const jvmtiHeapReferenceInfo* reference_info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                  jlong class_tag, jlong referrer_class_tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                  jlong size, jlong* tag_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                  jlong* referrer_tag_ptr, jint length, void* user_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    ObjectIndex   object_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
   /* Only calls to Allocate, Deallocate, RawMonitorEnter & RawMonitorExit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    *   are allowed here (see the JVMTI Spec).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    HPROF_ASSERT(tag_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    HPROF_ASSERT(class_tag!=(jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    if ( class_tag == (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        /* We can't do anything with a class_tag==0, just skip it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    switch ( reference_kind ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        case JVMTI_HEAP_REFERENCE_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        case JVMTI_HEAP_REFERENCE_CLASS_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        case JVMTI_HEAP_REFERENCE_SIGNERS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        case JVMTI_HEAP_REFERENCE_INTERFACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        case JVMTI_HEAP_REFERENCE_STATIC_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        case JVMTI_HEAP_REFERENCE_CONSTANT_POOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            return objectReference(reference_kind, reference_info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                   class_tag, size, tag_ptr, referrer_tag_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                SerialNumber trace_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                SerialNumber gref_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                TraceIndex   trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                SiteIndex    object_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                setup_tag_on_root(tag_ptr, class_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                                  gdata->unknown_thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                  &object_index, &object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                if ( object_site_index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    SiteKey     *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    pkey = get_pkey(object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    trace_index = pkey->trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    trace_index = gdata->system_trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                trace_serial_num = trace_get_serial_number(trace_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                gref_serial_num  = gdata->gref_serial_number_counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                io_heap_root_jni_global(object_index, gref_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                                        trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                char        *sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                SerialNumber class_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                SiteIndex    object_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                setup_tag_on_root(tag_ptr, class_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                  gdata->unknown_thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                  &object_index, &object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                sig = "Unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                class_serial_num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                if ( object_site_index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    SiteKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    pkey = get_pkey(object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    sig = string_get(class_get_signature(pkey->cnum));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    class_serial_num = class_get_serial_number(pkey->cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                io_heap_root_system_class(object_index, sig, class_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        case JVMTI_HEAP_REFERENCE_MONITOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            setup_tag_on_root(tag_ptr, class_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                              gdata->unknown_thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                              &object_index, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            io_heap_root_monitor(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        case JVMTI_HEAP_REFERENCE_STACK_LOCAL:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                SerialNumber thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                jlong        thread_tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                thread_tag = reference_info->stack_local.thread_tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                localReference(tag_ptr, class_tag, thread_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                             &object_index, &thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                io_heap_root_java_frame(object_index, thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                             reference_info->stack_local.depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        case JVMTI_HEAP_REFERENCE_JNI_LOCAL: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                SerialNumber thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                jlong        thread_tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                thread_tag = reference_info->jni_local.thread_tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                localReference(tag_ptr, class_tag, thread_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                             &object_index, &thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                io_heap_root_jni_local(object_index, thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                             reference_info->jni_local.depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        case JVMTI_HEAP_REFERENCE_THREAD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                SerialNumber thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                SerialNumber trace_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                TraceIndex   trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                SiteIndex    object_site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                TlsIndex     tls_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                /* It is assumed that tag_ptr is referring to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                 *      java.lang.Thread object here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                if ( (*tag_ptr) != (jlong)0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    setup_tag_on_root(tag_ptr, class_tag, size, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                      &object_index, &object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    trace_index       = site_get_trace_index(object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    /* Hopefully the ThreadStart event put this thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                     *   correct serial number on it's object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    thread_serial_num = object_get_thread_serial_number(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    /* Rare situation that a Thread object is not tagged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                     *   Create special unique thread serial number in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                     *   case, probably means we never saw a thread start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                     *   or thread end, or even an allocation of the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                     *   object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    thread_serial_num = gdata->thread_serial_number_counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    setup_tag_on_root(tag_ptr, class_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                                      thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                                      &object_index, &object_site_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    trace_index = gdata->system_trace_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                /* Get tls_index and set in_heap_dump, if we find it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                tls_index = tls_find(thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                if ( tls_index != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    tls_set_in_heap_dump(tls_index, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                trace_serial_num = trace_get_serial_number(trace_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                /* Issue thread object (must be before thread root) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                io_heap_root_thread_object(object_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                                 thread_serial_num, trace_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                /* Issue thread root */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                io_heap_root_thread(object_index, thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        case JVMTI_HEAP_REFERENCE_OTHER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            setup_tag_on_root(tag_ptr, class_tag, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                              gdata->unknown_thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                              &object_index, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            io_heap_root_unknown(object_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
       default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            /* Ignore anything else */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    return JVMTI_VISIT_OBJECTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
site_heapdump(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    rawMonitorEnter(gdata->data_access_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        jvmtiHeapCallbacks heapCallbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        /* Remove class dumped status, all classes must be dumped */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        class_all_status_remove(CLASS_DUMPED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        /* Clear in_heap_dump flag */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        tls_clear_in_heap_dump();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        /* Dump the last thread traces and get the lists back we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        tls_dump_traces(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        /* Write header for heap dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        io_heap_header(gdata->total_live_instances, gdata->total_live_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        /* Setup a clean reference table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        reference_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        /* Walk over all reachable objects and dump out roots */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        gdata->gref_serial_number_counter = gdata->gref_serial_number_start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        /* Issue thread object for fake non-existent unknown thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         *   just in case someone refers to it. Real threads are handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         *   during iterate over reachable objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        io_heap_root_thread_object(0, gdata->unknown_thread_serial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                        trace_get_serial_number(gdata->system_trace_index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        /* Iterate over heap and get the real stuff */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        (void)memset(&heapCallbacks, 0, sizeof(heapCallbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        /* Select callbacks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        heapCallbacks.heap_reference_callback       = &cbReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        if ( gdata->primfields == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            heapCallbacks.primitive_field_callback  = &cbPrimFieldData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        if ( gdata->primarrays == JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            heapCallbacks.array_primitive_value_callback  = &cbPrimArrayData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        followReferences(&heapCallbacks, (void*)NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        /* Process reference information. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        object_reference_dump(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        object_clear_references();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        reference_cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        /* Dump the last thread traces and get the lists back we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        tls_dump_traces(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        /* Write out footer for heap dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        io_heap_footer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    } rawMonitorExit(gdata->data_access_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
}