jdk/src/jdk.hprof.agent/share/native/libhprof/hprof_object.c
author sla
Tue, 26 Aug 2014 07:55:08 +0200
changeset 26201 40a873d21081
parent 25859 jdk/src/demo/share/jvmti/hprof/hprof_object.c@3317bb8137f4
permissions -rw-r--r--
8043936: Drop HPROF as demo, keep as HPROF agent shipped with JDK Reviewed-by: erikj, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10292
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* Object 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
 * An Object is unique by it's allocation site (SiteIndex), it's size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   it's kind, and it's serial number. Normally only the serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   would have been necessary for heap=dump, and these other items
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   could have been moved to the ObjectInfo. An optimization left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   to the reader. Lookups are not normally done on ObjectIndex's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   anyway because we typically know when to create them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   Objects that have been tagged, are tagged with an ObjectIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   Objects that are not tagged need a ObjectIndex, a lookup when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     heap=sites, and a new one when heap=dump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   Objects that are freed, need the tag converted to an ObjectIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     so they can be freed, but only when heap=dump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   The thread serial number is for the thread associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     object. If the object is a Thread object, it should be the serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *     number for that thread. The ThreadStart event is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *     for making sure the thread serial number is correct, but between the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     initial allocation of a Thread object and it's ThreadStart event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     the thread serial number could be for the thread that allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *     the Thread object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * This will likely be the largest table when using heap=dump, when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   there is one table entry per object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * ObjectIndex entries differ between heap=dump and heap=sites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   With heap=sites, each ObjectIndex represents a unique site, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   and kind of object, so many jobject's will map to a single ObjectIndex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   With heap=dump, every ObjectIndex maps to a unique jobject.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * During processing of a heap dump, the references for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   this ObjectIndex represents is assigned to the references field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   of the ObjectInfo as a linked list. (see hprof_references.c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   Once all the refernces are attached, they are processed into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   appropriate hprof dump information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * The references field is set and cleared as many times as the heap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   is dumped, as is the reference table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
typedef struct ObjectKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    SiteIndex    site_index;    /* Site of allocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    jint         size;          /* Size of object as reported by VM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    ObjectKind   kind;          /* Kind of object, most are OBJECT_NORMAL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    SerialNumber serial_num;    /* For heap=dump, a unique number. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
} ObjectKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
typedef struct ObjectInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    RefIndex     references;        /* Linked list of refs in this object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    SerialNumber thread_serial_num; /* Thread serial number for allocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
} ObjectInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
/* Private internal functions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static ObjectKey*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
get_pkey(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    void *key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int   key_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    table_get_key(gdata->object_table, index, (void*)&key_ptr, &key_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    HPROF_ASSERT(key_len==(int)sizeof(ObjectKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    return (ObjectKey*)key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
static ObjectInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
get_info(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    info = (ObjectInfo*)table_get_info(gdata->object_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
list_item(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    ObjectKey  *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    HPROF_ASSERT(key_len!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    info = (ObjectInfo*)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    pkey = (ObjectKey*)key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    debug_message( "Object 0x%08x: site=0x%08x, SN=%u, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                          " size=%d, kind=%d, refs=0x%x, threadSN=%u\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         i, pkey->site_index, pkey->serial_num, pkey->size, pkey->kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         info->references, info->thread_serial_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
clear_references(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    info = (ObjectInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    info->references = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
dump_class_references(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    info = (ObjectInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    reference_dump_class((JNIEnv*)arg, i, info->references);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
dump_instance_references(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    info = (ObjectInfo *)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    reference_dump_instance((JNIEnv*)arg, i, info->references);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
/* External interfaces. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
ObjectIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
object_new(SiteIndex site_index, jint size, ObjectKind kind, SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    ObjectIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    ObjectKey   key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    static ObjectKey empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    key            = empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    key.site_index = site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    key.size       = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    key.kind       = kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    if ( gdata->heap_dump ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        static ObjectInfo empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        ObjectInfo i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        i = empty_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        i.thread_serial_num = thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        key.serial_num = gdata->object_serial_number_counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        index = table_create_entry(gdata->object_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            &key, (int)sizeof(ObjectKey), &i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        key.serial_num =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             class_get_serial_number(site_get_class_index(site_index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        index = table_find_or_create_entry(gdata->object_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                            &key, (int)sizeof(ObjectKey), NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    site_update_stats(site_index, size, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
object_init(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    jint bucket_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    bucket_count = 511;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    if ( gdata->heap_dump ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        bucket_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    HPROF_ASSERT(gdata->object_table==NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    gdata->object_table = table_initialize("Object", 4096,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        4096, bucket_count, (int)sizeof(ObjectInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
SiteIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
object_get_site(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    ObjectKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    return pkey->site_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
object_get_size(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    ObjectKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    return pkey->size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
ObjectKind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
object_get_kind(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    ObjectKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    return pkey->kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
ObjectKind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
object_free(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    ObjectKey *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    ObjectKind kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    pkey = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    kind = pkey->kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /* Decrement allocations at this site. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    site_update_stats(pkey->site_index, -(pkey->size), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if ( gdata->heap_dump ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        table_free_entry(gdata->object_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    return kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
object_list(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        "--------------------- Object Table ------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    table_walk_items(gdata->object_table, &list_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        "----------------------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
object_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    table_cleanup(gdata->object_table, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    gdata->object_table = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
object_set_thread_serial_number(ObjectIndex index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                SerialNumber thread_serial_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    info->thread_serial_num = thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
SerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
object_get_thread_serial_number(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    return info->thread_serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
RefIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
object_get_references(ObjectIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    return info->references;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
object_set_references(ObjectIndex index, RefIndex ref_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    ObjectInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    info->references = ref_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
object_clear_references(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    table_walk_items(gdata->object_table, &clear_references, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
object_reference_dump(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    table_walk_items(gdata->object_table, &dump_instance_references, (void*)env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    table_walk_items(gdata->object_table, &dump_class_references, (void*)env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
}