jdk/src/share/demo/jvmti/hprof/hprof_cpu.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
#include "hprof.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/* This file contains the cpu loop for the option cpu=samples */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/* The cpu_loop thread basically waits for gdata->sample_interval millisecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   then wakes up, and for each running thread it gets their stack trace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   and updates the traces with 'hits'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * No threads are suspended or resumed, and the thread sampling is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   file hprof_tls.c, which manages all active threads. The sampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   technique (what is sampled) is also in hprof_tls.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * No adjustments are made to the pause time or sample interval except
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   by the user via the interval=n option (default is 10ms).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This thread can cause havoc when started prematurely or not terminated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   properly, see cpu_sample_init() and cpu_term(), and their calls in hprof_init.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * The listener loop (hprof_listener.c) can dynamically turn on or off the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *  sampling of all or selected threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/* Private functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
cpu_loop_function(jvmtiEnv *jvmti, JNIEnv *env, void *p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    int         loop_trip_counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    jboolean    cpu_loop_running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    loop_trip_counter          = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        gdata->cpu_loop_running = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        cpu_loop_running = gdata->cpu_loop_running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        /* Notify cpu_sample_init() that we have started */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        rawMonitorNotifyAll(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    rawMonitorEnter(gdata->cpu_sample_lock); /* Only waits inside loop let go */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    while ( cpu_loop_running ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        ++loop_trip_counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        LOG3("cpu_loop()", "iteration", loop_trip_counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        /* If a dump is in progress, we pause sampling. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        rawMonitorEnter(gdata->dump_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            if (gdata->dump_in_process) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                gdata->pause_cpu_sampling = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } rawMonitorExit(gdata->dump_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        /* Check to see if we need to pause sampling (listener_loop command) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (gdata->pause_cpu_sampling) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
             * Pause sampling for now. Reset sample controls if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
             * sampling is resumed again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            rawMonitorWait(gdata->cpu_sample_lock, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                cpu_loop_running = gdata->cpu_loop_running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            /* Continue the while loop, which will terminate if done. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /* This is the normal short timed wait before getting a sample */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        rawMonitorWait(gdata->cpu_sample_lock,  (jlong)gdata->sample_interval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /* Make sure we really want to continue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            cpu_loop_running = gdata->cpu_loop_running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        /* Break out if we are done */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if ( !cpu_loop_running ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * If a dump request came in after we checked at the top of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * the while loop, then we catch that fact here. We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         * don't want to perturb the data that is being dumped so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         * we just ignore the data from this sampling loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        rawMonitorEnter(gdata->dump_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            if (gdata->dump_in_process) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                gdata->pause_cpu_sampling = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } rawMonitorExit(gdata->dump_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /* Sample all the threads and update trace costs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if ( !gdata->pause_cpu_sampling) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            tls_sample_all_threads(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        /* Check to see if we need to finish */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            cpu_loop_running = gdata->cpu_loop_running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    rawMonitorExit(gdata->cpu_sample_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        /* Notify cpu_sample_term() that we are done. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        rawMonitorNotifyAll(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    LOG2("cpu_loop()", "clean termination");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
/* External functions */
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
cpu_sample_init(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    gdata->cpu_sampling  = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /* Create the raw monitors needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    gdata->cpu_loop_lock = createRawMonitor("HPROF cpu loop lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    gdata->cpu_sample_lock = createRawMonitor("HPROF cpu sample lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        createAgentThread(env, "HPROF cpu sampling thread",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                            &cpu_loop_function);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /* Wait for cpu_loop_function() to notify us it has started. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        rawMonitorWait(gdata->cpu_loop_lock, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
cpu_sample_off(JNIEnv *env, ObjectIndex object_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (object_index != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        tls_set_sample_status(object_index, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        count = tls_sum_sample_status();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if ( count == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        gdata->pause_cpu_sampling = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        gdata->pause_cpu_sampling = JNI_FALSE;
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
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
cpu_sample_on(JNIEnv *env, ObjectIndex object_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    if ( gdata->cpu_loop_lock == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        cpu_sample_init(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    if (object_index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        gdata->cpu_sampling             = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        gdata->pause_cpu_sampling       = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        jint     count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        tls_set_sample_status(object_index, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        count = tls_sum_sample_status();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if ( count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            gdata->pause_cpu_sampling   = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /* Notify the CPU sampling thread that sampling is on */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    rawMonitorEnter(gdata->cpu_sample_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        rawMonitorNotifyAll(gdata->cpu_sample_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    } rawMonitorExit(gdata->cpu_sample_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
cpu_sample_term(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    gdata->pause_cpu_sampling   = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    rawMonitorEnter(gdata->cpu_sample_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        /* Notify the CPU sampling thread to get out of any sampling Wait */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        rawMonitorNotifyAll(gdata->cpu_sample_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    } rawMonitorExit(gdata->cpu_sample_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    rawMonitorEnter(gdata->cpu_loop_lock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if ( gdata->cpu_loop_running ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            gdata->cpu_loop_running = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            /* Wait for cpu_loop_function() thread to tell us it completed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            rawMonitorWait(gdata->cpu_loop_lock, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    } rawMonitorExit(gdata->cpu_loop_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}