jdk/src/share/demo/jvmti/hprof/hprof_frame.c
author goetz
Thu, 21 Nov 2013 18:29:34 -0800
changeset 22852 1063026e8cee
parent 14342 8435a30053c1
permissions -rw-r--r--
8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization. Summary: Fixed Implicit NULL check optimization for AIX, where the page at address '0' is only write-protected. Reviewed-by: kvn
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
/* This file contains support for handling frames, or (method,location) pairs. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  Frames map 1-to-1 to (methodID,location) pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *  When no line number is known, -1 should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *  Frames are mostly used in traces (see hprof_trace.c) and will be marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *    with their status flag as they are written out to the hprof output file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
enum LinenoState {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    LINENUM_UNINITIALIZED = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    LINENUM_AVAILABLE     = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    LINENUM_UNAVAILABLE   = 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
typedef struct FrameKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    jmethodID   method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jlocation   location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
} FrameKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
typedef struct FrameInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    unsigned short      lineno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    unsigned char       lineno_state; /* LinenoState */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    unsigned char       status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    SerialNumber serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
} FrameInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
static FrameKey*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
get_pkey(FrameIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    void *key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    int   key_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    table_get_key(gdata->frame_table, index, &key_ptr, &key_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    HPROF_ASSERT(key_len==sizeof(FrameKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    return (FrameKey*)key_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
static FrameInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
get_info(FrameIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    FrameInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    info = (FrameInfo*)table_get_info(gdata->frame_table, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
list_item(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    FrameKey   key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    FrameInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    HPROF_ASSERT(key_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    HPROF_ASSERT(key_len==sizeof(FrameKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    HPROF_ASSERT(info_ptr!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    key = *((FrameKey*)key_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    info = (FrameInfo*)info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "Frame 0x%08x: method=%p, location=%d, lineno=%d(%d), status=%d \n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                i, (void*)key.method, (jint)key.location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                info->lineno, info->lineno_state, info->status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
frame_init(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    gdata->frame_table = table_initialize("Frame",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                            1024, 1024, 1023, (int)sizeof(FrameInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
FrameIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
frame_find_or_create(jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    FrameIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    static FrameKey empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    FrameKey key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    jboolean new_one;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    key          = empty_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    key.method   = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    key.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    new_one      = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    index        = table_find_or_create_entry(gdata->frame_table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        &key, (int)sizeof(key), &new_one, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    if ( new_one ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        FrameInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        info->lineno_state = LINENUM_UNINITIALIZED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if ( location < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            info->lineno_state = LINENUM_UNAVAILABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        info->serial_num = gdata->frame_serial_number_counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
frame_list(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        "--------------------- Frame Table ------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    table_walk_items(gdata->frame_table, &list_item, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    debug_message(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        "----------------------------------------------------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
frame_cleanup(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    table_cleanup(gdata->frame_table, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    gdata->frame_table = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
frame_set_status(FrameIndex index, jint status)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    FrameInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    info->status = (unsigned char)status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
frame_get_location(FrameIndex index, SerialNumber *pserial_num,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                   jmethodID *pmethod, jlocation *plocation, jint *plineno)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    FrameKey  *pkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    FrameInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    jint       lineno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    pkey       = get_pkey(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    *pmethod   = pkey->method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    *plocation = pkey->location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    info       = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    lineno     = (jint)info->lineno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    if ( info->lineno_state == LINENUM_UNINITIALIZED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        info->lineno_state = LINENUM_UNAVAILABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if ( gdata->lineno_in_traces ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if ( pkey->location >= 0 && !isMethodNative(pkey->method) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                lineno = getLineNumber(pkey->method, pkey->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if ( lineno >= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    info->lineno = (unsigned short)lineno; /* save it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    info->lineno_state = LINENUM_AVAILABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    if ( info->lineno_state == LINENUM_UNAVAILABLE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        lineno = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    *plineno     = lineno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    *pserial_num = info->serial_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
frame_get_status(FrameIndex index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    FrameInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    info = get_info(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    return (jint)info->status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}