jdk/src/share/demo/jvmti/hprof/hprof_tracker.c
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 14342 8435a30053c1
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
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
/* Tracker class support functions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This file contains the native support calls for the Tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   class. These native methods are registered and not made extern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   Tracking is engaged by using JNI to assign to a static field in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   Tracker class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Just like JVMTI callbacks, it's best that we keep track of these so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   when the VM_DEATH happens we know to wait for them to complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * This file also contains the functions that will initialize the Tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   interface for BCI and identify the Tracker methods to make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   they are not included in any stack traces obtained from JVMTI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * RFE: The performance of the java injected code calling native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *        could be an issue here, cpu=times seems to be the worst where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *        a native call is made for entry and exit, even on the smallest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *        Java method. The alternative would be to cache the data on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *        the Java side, and either push it out to the native side, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *        use some kind of pull from the native side, or even using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *        shared memory or a socket.  However having said that, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *        current performance issues are more around sheer memory needed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *        and repeated calls to GetThreadCpuTime(), which is being investigated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/* Macros to surround tracker based callback code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   Also see BEGIN_CALLBACK and END_CALLBACK in hprof_init.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   If the VM_DEATH callback is active in the begining, then this callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   just blocks (it is assumed we don't want to return to the VM).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   If the VM_DEATH callback is active at the end, then this callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   will notify the VM_DEATH callback if it's the last one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *   WARNING: No not 'return' or 'goto' out of the BEGIN_TRACKER_CALLBACK/END_TRACKER_CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *            block, this will mess up the count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define BEGIN_TRACKER_CALLBACK()                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{ /* BEGIN OF TRACKER_CALLBACK */                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    jboolean bypass = JNI_TRUE;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    rawMonitorEnter(gdata->callbackLock); {                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if ( gdata->tracking_engaged != 0 ) {                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (!gdata->vm_death_callback_active) {                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                gdata->active_callbacks++;                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                bypass = JNI_FALSE;                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }                                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    } rawMonitorExit(gdata->callbackLock);                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    if ( !bypass ) {                                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        /* BODY OF TRACKER_CALLBACK CODE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#define END_TRACKER_CALLBACK() /* Part of bypass if body */             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        rawMonitorEnter(gdata->callbackLock); {                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            gdata->active_callbacks--;                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            if (gdata->active_callbacks < 0) {                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                HPROF_ERROR(JNI_TRUE, "Problems tracking callbacks");   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (gdata->vm_death_callback_active) {                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                if (gdata->active_callbacks == 0) {                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    rawMonitorNotifyAll(gdata->callbackLock);           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                }                                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } rawMonitorExit(gdata->callbackLock);                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
} /* END OF TRACKER_CALLBACK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * Class:     Tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * Method:    nativeNewArray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
Tracker_nativeNewArray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  (JNIEnv *env, jclass clazz, jobject thread, jobject obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    BEGIN_TRACKER_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        event_newarray(env, thread, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    } END_TRACKER_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * Class:     Tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * Method:    nativeObjectInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
Tracker_nativeObjectInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  (JNIEnv *env, jclass clazz, jobject thread, jobject obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    BEGIN_TRACKER_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        event_object_init(env, thread, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    } END_TRACKER_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Class:     Tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * Method:    nativeCallSite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * Signature: (Ljava/lang/Object;II)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
Tracker_nativeCallSite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  (JNIEnv *env, jclass clazz, jobject thread, jint cnum, jint mnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    BEGIN_TRACKER_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        event_call(env, thread, cnum, mnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    } END_TRACKER_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * Class:     Tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Method:    nativeReturnSite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * Signature: (Ljava/lang/Object;II)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
Tracker_nativeReturnSite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  (JNIEnv *env, jclass clazz, jobject thread, jint cnum, jint mnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    BEGIN_TRACKER_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        event_return(env, thread, cnum, mnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    } END_TRACKER_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
/* ------------------------------------------------------------------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
/* Set Java static field to turn on native code calls in Tracker. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
set_engaged(JNIEnv *env, jint engaged)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    LOG3("set_engaged()", "engaging tracking", engaged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    if ( ! gdata->bci ) {
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
    rawMonitorEnter(gdata->callbackLock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if ( gdata->tracking_engaged != engaged ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            jfieldID field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            jclass   tracker_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            tracker_class = class_get_class(env, gdata->tracker_cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            gdata->tracking_engaged = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            /* Activate or deactivate the injection code on the Java side */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            HPROF_ASSERT(tracker_class!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            exceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            field = getStaticFieldID(env, tracker_class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                    TRACKER_ENGAGED_NAME, TRACKER_ENGAGED_SIG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            setStaticIntField(env, tracker_class, field, engaged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            exceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            LOG3("set_engaged()", "tracking engaged", engaged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            gdata->tracking_engaged = engaged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    } rawMonitorExit(gdata->callbackLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
tracker_engage(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    set_engaged(env, 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
tracker_disengage(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    set_engaged(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
tracker_method(jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    int      i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    if ( ! gdata->bci ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    HPROF_ASSERT(method!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    HPROF_ASSERT(gdata->tracker_method_count > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    for ( i = 0 ; i < gdata->tracker_method_count ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        HPROF_ASSERT(gdata->tracker_methods[i].method!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if ( method == gdata->tracker_methods[i].method ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
static JNINativeMethod registry[4] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        { TRACKER_NEWARRAY_NATIVE_NAME,    TRACKER_NEWARRAY_NATIVE_SIG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                (void*)&Tracker_nativeNewArray },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        { TRACKER_OBJECT_INIT_NATIVE_NAME, TRACKER_OBJECT_INIT_NATIVE_SIG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                (void*)&Tracker_nativeObjectInit },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        { TRACKER_CALL_NATIVE_NAME,        TRACKER_CALL_NATIVE_SIG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                (void*)&Tracker_nativeCallSite },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        { TRACKER_RETURN_NATIVE_NAME,      TRACKER_RETURN_NATIVE_SIG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                (void*)&Tracker_nativeReturnSite }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
static struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    char *sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
} tracker_methods[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        { TRACKER_NEWARRAY_NAME,           TRACKER_NEWARRAY_SIG            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        { TRACKER_OBJECT_INIT_NAME,        TRACKER_OBJECT_INIT_SIG         },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        { TRACKER_CALL_NAME,               TRACKER_CALL_SIG                },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        { TRACKER_RETURN_NAME,             TRACKER_RETURN_SIG              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        { TRACKER_NEWARRAY_NATIVE_NAME,    TRACKER_NEWARRAY_NATIVE_SIG     },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        { TRACKER_OBJECT_INIT_NATIVE_NAME, TRACKER_OBJECT_INIT_NATIVE_SIG  },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        { TRACKER_CALL_NATIVE_NAME,        TRACKER_CALL_NATIVE_SIG         },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        { TRACKER_RETURN_NATIVE_NAME,      TRACKER_RETURN_NATIVE_SIG       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
tracker_setup_class(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    ClassIndex  cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    LoaderIndex loader_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    HPROF_ASSERT(gdata->tracker_cnum==0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    loader_index = loader_find_or_create(NULL,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    cnum = class_find_or_create(TRACKER_CLASS_SIG, loader_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    gdata->tracker_cnum = cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    HPROF_ASSERT(cnum!=0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    class_add_status(cnum, CLASS_SPECIAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
tracker_setup_methods(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    ClassIndex  cnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    LoaderIndex loader_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    int         i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    jclass      object_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    jclass      tracker_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    if ( ! gdata->bci ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    loader_index = loader_find_or_create(NULL,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    cnum = class_find_or_create(OBJECT_CLASS_SIG, loader_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    object_class = class_get_class(env, cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    tracker_class = class_get_class(env, gdata->tracker_cnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    CHECK_EXCEPTIONS(env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        registerNatives(env, tracker_class, registry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                (int)sizeof(registry)/(int)sizeof(registry[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    } END_CHECK_EXCEPTIONS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    HPROF_ASSERT(tracker_class!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    gdata->tracker_method_count =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        (int)sizeof(tracker_methods)/(int)sizeof(tracker_methods[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    HPROF_ASSERT(gdata->tracker_method_count <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      (int)(sizeof(gdata->tracker_methods)/sizeof(gdata->tracker_methods[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    CHECK_EXCEPTIONS(env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        gdata->object_init_method = getMethodID(env, object_class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                    OBJECT_INIT_NAME, OBJECT_INIT_SIG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        for ( i=0 ; i < gdata->tracker_method_count ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            gdata->tracker_methods[i].name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                        string_find_or_create(tracker_methods[i].name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            gdata->tracker_methods[i].sig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        string_find_or_create(tracker_methods[i].sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            gdata->tracker_methods[i].method =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                      getStaticMethodID(env, tracker_class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                            tracker_methods[i].name, tracker_methods[i].sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            HPROF_ASSERT(gdata->tracker_methods[i].method!=NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            LOG2("tracker_setup_methods(): Found", tracker_methods[i].name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    } END_CHECK_EXCEPTIONS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
}