jdk/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * eventHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * This module handles events as they come in directly from JVMTI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * and also maps them to JDI events.  JDI events are those requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * at the JDI or JDWP level and seen on those levels.  Mapping is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * one-to-many, a JVMTI event may map to several JDI events, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * to none.  Part of that mapping process is filteration, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * eventFilter sub-module handles.  A JDI EventRequest corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * to a HandlerNode and a JDI filter to the hidden HandlerNode data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * used by eventFilter.  For example, if at the JDI level the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * executed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   EventRequestManager erm = vm.eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   BreakpointRequest bp = erm.createBreakpointRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *   bp.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   ClassPrepareRequest req = erm.createClassPrepareRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *   req.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *   req = erm.createClassPrepareRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *   req.addClassFilter("Foo*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   req.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Three handlers would be created, the first with a LocationOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * filter and the last with a ClassMatch  filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * When a JVMTI class prepare event for "Foobar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * comes in, the second handler will create one JDI event, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * third handler will compare the class signature, and since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * it matchs create a second event.  There may also be internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * events as there are in this case, one created by the front-end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * and one by the back-end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Each event kind has a handler chain, which is a doublely linked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * list of handlers for that kind of event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#include "eventHandlerRestricted.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#include "eventFilter.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#include "eventFilterRestricted.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#include "standardHandlers.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#include "eventHelper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#include "classTrack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#include "commonRef.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#include "debugLoop.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
static HandlerID requestIdCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
static jbyte currentSessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/* Counter of active callbacks and flag for vm_death */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static int      active_callbacks   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
static jboolean vm_death_callback_active = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static jrawMonitorID callbackLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static jrawMonitorID callbackBlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/* Macros to surround callback code (non-VM_DEATH callbacks).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *   Note that this just keeps a count of the non-VM_DEATH callbacks that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   are currently active, it does not prevent these callbacks from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   operating in parallel. It's the VM_DEATH callback that will wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *   for all these callbacks to finish up, so that it can report the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   VM_DEATH in a clean state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *   If the VM_DEATH callback is active in the BEGIN macro then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *   callback just blocks until released by the VM_DEATH callback.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *   If the VM_DEATH callback is active in the END macro, then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   callback will notify the VM_DEATH callback if it's the last one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *   and then block until released by the VM_DEATH callback.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *   Why block? These threads are often the threads of the Java program,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *   not blocking might mean that a return would continue execution of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *   some java thread in the middle of VM_DEATH, this seems troubled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *   WARNING: No not 'return' or 'goto' out of the BEGIN_CALLBACK/END_CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *            block, this will mess up the count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#define BEGIN_CALLBACK()                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{ /* BEGIN OF CALLBACK */                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jboolean bypass = JNI_TRUE;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    debugMonitorEnter(callbackLock); {                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (vm_death_callback_active) {                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            /* allow VM_DEATH callback to finish */                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            debugMonitorExit(callbackLock);                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            /* Now block because VM is about to die */                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            debugMonitorEnter(callbackBlock);                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            debugMonitorExit(callbackBlock);                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } else {                                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            active_callbacks++;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            bypass = JNI_FALSE;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            debugMonitorExit(callbackLock);                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }                                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if ( !bypass ) {                                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        /* BODY OF CALLBACK CODE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#define END_CALLBACK() /* Part of bypass if body */                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        debugMonitorEnter(callbackLock); {                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            active_callbacks--;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (active_callbacks < 0) {                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                EXIT_ERROR(0, "Problems tracking active callbacks");    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (vm_death_callback_active) {                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                if (active_callbacks == 0) {                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    debugMonitorNotifyAll(callbackLock);                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                }                                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                /* allow VM_DEATH callback to finish */                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                debugMonitorExit(callbackLock);                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                /* Now block because VM is about to die */              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                debugMonitorEnter(callbackBlock);                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                debugMonitorExit(callbackBlock);                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            } else {                                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                debugMonitorExit(callbackLock);                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }                                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
} /* END OF CALLBACK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * We are starting with a very simple locking scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * for event handling.  All readers and writers of data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * the handlers[] chain must own this lock for the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * of its use. If contention becomes a problem, we can:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * 1) create a lock per event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * 2) move to a readers/writers approach where multiple threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * can access the chains simultaneously while reading (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * normal activity of an event callback).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
static jrawMonitorID handlerLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
typedef struct HandlerChain_ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    HandlerNode *first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /* add lock here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
} HandlerChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * This array maps event kinds to handler chains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * Protected by handlerLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
static HandlerChain __handlers[EI_max-EI_min+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
/* Given a HandlerNode, these access our private data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#define PRIVATE_DATA(node) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
       (&(((EventHandlerRestricted_HandlerNode*)(void*)(node))->private_ehpd))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#define NEXT(node) (PRIVATE_DATA(node)->private_next)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#define PREV(node) (PRIVATE_DATA(node)->private_prev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
#define CHAIN(node) (PRIVATE_DATA(node)->private_chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#define HANDLER_FUNCTION(node) (PRIVATE_DATA(node)->private_handlerFunction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
static jclass getObjectClass(jobject object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
static jvmtiError freeHandler(HandlerNode *node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
static jvmtiError freeHandlerChain(HandlerChain *chain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
static HandlerChain *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
getHandlerChain(EventIndex i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if ( i < EI_min || i > EI_max ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,"bad index for handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    return &(__handlers[i-EI_min]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
insert(HandlerChain *chain, HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    HandlerNode *oldHead = chain->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    NEXT(node) = oldHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    PREV(node) = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    CHAIN(node) = chain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    if (oldHead != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        PREV(oldHead) = node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    chain->first = node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
static HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
findInChain(HandlerChain *chain, HandlerID handlerID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    HandlerNode *node = chain->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (node->handlerID == handlerID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        node = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
static HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
find(EventIndex ei, HandlerID handlerID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    return findInChain(getHandlerChain(ei), handlerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * Deinsert.  Safe for non-inserted nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
deinsert(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    HandlerChain *chain = CHAIN(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    if (chain == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (chain->first == node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        chain->first = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    if (NEXT(node) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        PREV(NEXT(node)) = PREV(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (PREV(node) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        NEXT(PREV(node)) = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    CHAIN(node) = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
eventHandlerRestricted_iterator(EventIndex ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                              IteratorFunction func, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    HandlerChain *chain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    chain = getHandlerChain(ei);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    node = chain->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    if ( func == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        EXIT_ERROR(AGENT_ERROR_INTERNAL,"iterator function NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (((func)(env, node, arg))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        node = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
/* BREAKPOINT, METHOD_ENTRY and SINGLE_STEP events are covered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * the co-location of events policy. Of these three co-located
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * events, METHOD_ENTRY is  always reported first and BREAKPOINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * is always reported last. Here are the possible combinations and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * their order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * (p1) METHOD_ENTRY, BREAKPOINT (existing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * (p2) METHOD_ENTRY, BREAKPOINT (new)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * (p1) METHOD_ENTRY, SINGLE_STEP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * (p1) METHOD_ENTRY, SINGLE_STEP, BREAKPOINT (existing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * (p1/p2) METHOD_ENTRY, SINGLE_STEP, BREAKPOINT (new)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * (p1) SINGLE_STEP, BREAKPOINT (existing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * (p2) SINGLE_STEP, BREAKPOINT (new)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * BREAKPOINT (existing) indicates a BREAKPOINT that is set before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * the other co-located event is posted. BREAKPOINT (new) indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * a BREAKPOINT that is set after the other co-located event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * posted and before the thread has resumed execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * Co-location of events policy used to be implemented via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * temporary BREAKPOINTs along with deferring the reporting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * non-BREAKPOINT co-located events, but the temporary BREAKPOINTs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * caused performance problems on VMs where setting or clearing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * BREAKPOINTs is expensive, e.g., HotSpot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * The policy is now implemented in two phases. Phase 1: when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * METHOD_ENTRY or SINGLE_STEP event is received, if there is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * existing co-located BREAKPOINT, then the current event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * deferred. When the BREAKPOINT event is processed, the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * bag will contain the deferred METHOD_ENTRY and/or SINGLE_STEP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * events along with the BREAKPOINT event. For a METHOD_ENTRY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * event where there is not an existing co-located BREAKPOINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * if SINGLE_STEP events are also enabled for the thread, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * the METHOD_ENTRY event is deferred. When the SINGLE_STEP event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * is processed, the event bag will also contain the deferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * METHOD_ENTRY event. This covers each of the combinations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * marked with 'p1' above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * Phase 2: if there is no existing co-located BREAKPOINT, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 * location information for the METHOD_ENTRY or SINGLE_STEP event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 * is recorded in the ThreadNode. If the next event for the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * is a co-located BREAKPOINT, then the first BREAKPOINT event will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 * be skipped since it cannot be delivered in the same event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * This covers each of the combinations marked with 'p2' above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 * For the combination marked p1/p2, part of the case is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 * during phase 1 and the rest is handled during phase 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 * The recording of information in the ThreadNode is handled in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 * this routine. The special handling of the next event for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * thread is handled in skipEventReport().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
deferEventReport(JNIEnv *env, jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            EventIndex ei, jclass clazz, jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    jboolean deferring = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    switch (ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        case EI_METHOD_ENTRY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            if (!isMethodNative(method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                jlocation start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                jlocation end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                error = methodLocation(method, &start, &end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    deferring = isBreakpointSet(clazz, method, start) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                threadControl_getInstructionStepMode(thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                    == JVMTI_ENABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    if (!deferring) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        threadControl_saveCLEInfo(env, thread, ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                                  clazz, method, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        case EI_SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            deferring = isBreakpointSet(clazz, method, location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (!deferring) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                threadControl_saveCLEInfo(env, thread, ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                          clazz, method, location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /* TO DO: Once JVMTI supports a way to know if we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * at the end of a method, we should check here for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * break and step events which precede a method exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    return deferring;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
/* Handle phase 2 of the co-located events policy. See detailed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * comments in deferEventReport() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
skipEventReport(JNIEnv *env, jthread thread, EventIndex ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                        jclass clazz, jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    jboolean skipping = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    if (ei == EI_BREAKPOINT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (threadControl_cmpCLEInfo(env, thread, clazz, method, location)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            LOG_MISC(("Co-located breakpoint event found: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                "%s,thread=%p,clazz=%p,method=%p,location=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                eventText(ei), thread, clazz, method, location));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            skipping = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    threadControl_clearCLEInfo(env, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    return skipping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
reportEvents(JNIEnv *env, jbyte sessionID, jthread thread, EventIndex ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
             jclass clazz, jmethodID method, jlocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
             struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    jbyte suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    jboolean invoking;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    if (bagSize(eventBag) < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Never report events before initialization completes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    if (!debugInit_isInitComplete()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Check to see if we should skip reporting this event due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * co-location of events policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    if (thread != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
           skipEventReport(env, thread, ei, clazz, method, location)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        LOG_MISC(("event report being skipped: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            "ei=%s,thread=%p,clazz=%p,method=%p,location=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            eventText(ei), thread, clazz, method, location));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        bagDeleteAll(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /* We delay the reporting of some events so that they can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * properly grouped into event sets with upcoming events. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * the reporting is to be deferred, the event commands remain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * in the event bag until a subsequent event occurs.  Event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * NULL for synthetic events (e.g. unload).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    if (thread == NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         || !deferEventReport(env, thread, ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        clazz, method, location)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        struct bag *completedBag = bagDup(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        bagDeleteAll(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (completedBag == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
             * TO DO: Report, but don't terminate?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            suspendPolicy = eventHelper_reportEvents(sessionID, completedBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (thread != NULL && suspendPolicy != JDWP_SUSPEND_POLICY(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    /* The events have been reported and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                     * thread is about to continue, but it may
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   441
                     * have been started up just to perform a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                     * requested method invocation. If so, we do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                     * the invoke now and then stop again waiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                     * for another continue. By then another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                     * invoke request can be in place, so there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                     * a loop around this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    invoking = invoker_doInvoke(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    if (invoking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        eventHelper_reportInvokeDone(sessionID, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                } while (invoking);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            bagDestroyBag(completedBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
/* A bagEnumerateFunction.  Create a synthetic class unload event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
 * for every class no longer present.  Analogous to event_callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
 * combined with a handler in a unload specific (no event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
 * structure) kind of way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
synthesizeUnloadEvent(void *signatureVoid, void *envVoid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    JNIEnv *env = (JNIEnv *)envVoid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    char *signature = *(char **)signatureVoid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    char *classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    jbyte eventSessionID = currentSessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    struct bag *eventBag = eventHelper_createEventBag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    if (eventBag == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        /* TO DO: Report, but don't die
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        JDI_ASSERT(eventBag != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /* Signature needs to last, so convert extra copy to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    classname = jvmtiAllocate((int)strlen(signature)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    (void)strcpy(classname, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    convertSignatureToClassname(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    node = getHandlerChain(EI_GC_FINISH)->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        /* save next so handlers can remove themselves */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        HandlerNode *next = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        jboolean shouldDelete;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (eventFilterRestricted_passesUnloadFilter(env, classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                                     node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                                     &shouldDelete)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            /* There may be multiple handlers, the signature will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
             * be freed when the event helper thread has written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
             * it.  So each event needs a separate allocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            char *durableSignature = jvmtiAllocate((int)strlen(signature)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            (void)strcpy(durableSignature, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            eventHelper_recordClassUnload(node->handlerID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                          durableSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                                          eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (shouldDelete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            /* We can safely free the node now that we are done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
             * using it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            (void)freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        node = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    if (eventBag != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        reportEvents(env, eventSessionID, (jthread)NULL, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                            (jclass)NULL, (jmethodID)NULL, 0, eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * bag was created locally, destroy it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        bagDestroyBag(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    jvmtiDeallocate(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
/* Garbage Collection Happened */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
static unsigned int garbageCollected = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
/* The JVMTI generic event callback. Each event is passed to a sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
 * handlers in a chain until the chain ends or one handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
 * consumes the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
event_callback(JNIEnv *env, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    struct bag *eventBag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    jbyte eventSessionID = currentSessionID; /* session could change */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    jthrowable currentException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    LOG_MISC(("event_callback(): ei=%s", eventText(evinfo->ei)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    log_debugee_location("event_callback()", evinfo->thread, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /* We want to preserve any current exception that might get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * wiped out during event handling (e.g. JNI calls). We have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * to rely on space for the local reference on the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * frame because doing a PushLocalFrame here might itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * generate an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    currentException = JNI_FUNC_PTR(env,ExceptionOccurred)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /* See if a garbage collection finish event happened earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Note: The "if" is an optimization to avoid entering the lock on every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *       event; garbageCollected may be zapped before we enter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *       the lock but then this just becomes one big no-op.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    if ( garbageCollected > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        struct bag *unloadedSignatures = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        /* We want to compact the hash table of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         * objects sent to the front end by removing objects that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         * been collected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        commonRef_compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        /* We also need to simulate the class unload events. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        /* Clear garbage collection counter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        garbageCollected = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        /* Analyze which class unloads occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        unloadedSignatures = classTrack_processUnloads(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        /* Generate the synthetic class unload events and/or just cleanup.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if ( unloadedSignatures != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            (void)bagEnumerateOver(unloadedSignatures, synthesizeUnloadEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                             (void *)env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            bagDestroyBag(unloadedSignatures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    thread = evinfo->thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    if (thread != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         * Record the fact that we're entering an event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         * handler so that thread operations (status, interrupt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         * stop) can be done correctly and so that thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         * resources can be allocated.  This must be done before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         * grabbing any locks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        eventBag = threadControl_onEventHandlerEntry(eventSessionID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                                 evinfo->ei, thread, currentException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if ( eventBag == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            jboolean invoking;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                /* The event has been 'handled' and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                 * thread is about to continue, but it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                 * have been started up just to perform a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                 * requested method invocation. If so, we do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                 * the invoke now and then stop again waiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                 * for another continue. By then another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                 * invoke request can be in place, so there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                 * a loop around this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                invoking = invoker_doInvoke(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                if (invoking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    eventHelper_reportInvokeDone(eventSessionID, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            } while (invoking);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            return; /* Do nothing, event was consumed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        eventBag = eventHelper_createEventBag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (eventBag == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
             * TO DO: Report, but don't die
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            eventBag = NULL;  /* to shut up lint */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        char        *classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /* We must keep track of all classes prepared to know what's unloaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        if (evinfo->ei == EI_CLASS_PREPARE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            classTrack_addPreparedClass(env, evinfo->clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        node = getHandlerChain(evinfo->ei)->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        classname = getClassname(evinfo->clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            /* save next so handlers can remove themselves */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            HandlerNode *next = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            jboolean shouldDelete;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            if (eventFilterRestricted_passesFilter(env, classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                                                   evinfo, node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                                   &shouldDelete)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                HandlerFunction func;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                func = HANDLER_FUNCTION(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                if ( func == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    EXIT_ERROR(AGENT_ERROR_INTERNAL,"handler function NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                (*func)(env, evinfo, node, eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            if (shouldDelete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                /* We can safely free the node now that we are done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                 * using it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                (void)freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            node = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        jvmtiDeallocate(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    if (eventBag != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        reportEvents(env, eventSessionID, thread, evinfo->ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                evinfo->clazz, evinfo->method, evinfo->location, eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /* we are continuing after VMDeathEvent - now we are dead */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    if (evinfo->ei == EI_VM_DEATH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        gdata->vmDead = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * If the bag was created locally, destroy it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    if (thread == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        bagDestroyBag(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /* Always restore any exception that was set beforehand.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * there is a pending async exception, StopThread will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * called from threadControl_onEventHandlerExit immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * below.  Depending on VM implementation and state, the async
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * exception might immediately overwrite the currentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * or it might be delayed until later.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    if (currentException != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        JNI_FUNC_PTR(env,Throw)(env, currentException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Release thread resources and perform any delayed operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    if (thread != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        threadControl_onEventHandlerExit(evinfo->ei, thread, eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
/* Returns a local ref to the declaring class for an object. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
static jclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
getObjectClass(jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
/* Returns a local ref to the declaring class for a method, or NULL. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
jclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
getMethodClass(jvmtiEnv *jvmti_env, jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    jclass clazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    if ( method == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    error = methodClass(method, &clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        EXIT_ERROR(error,"Can't get jclass for a methodID, invalid?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
/* Event callback for JVMTI_EVENT_SINGLE_STEP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                        jthread thread, jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    LOG_CB(("cbSingleStep: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        info.ei         = EI_SINGLE_STEP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        info.clazz      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        info.method     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        info.location   = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    LOG_MISC(("END cbSingleStep"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
/* Event callback for JVMTI_EVENT_BREAKPOINT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                        jthread thread, jmethodID method, jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    LOG_CB(("cbBreakpoint: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        info.ei         = EI_BREAKPOINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        info.clazz      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        info.method     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        info.location   = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    LOG_MISC(("END cbBreakpoint"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
/* Event callback for JVMTI_EVENT_FRAME_POP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
cbFramePop(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                        jthread thread, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                        jboolean wasPoppedByException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /* JDWP does not return these events when popped due to an exception. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    if ( wasPoppedByException ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    LOG_CB(("cbFramePop: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        info.ei         = EI_FRAME_POP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        info.clazz      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        info.method     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    LOG_MISC(("END cbFramePop"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
/* Event callback for JVMTI_EVENT_EXCEPTION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
cbException(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                        jthread thread, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                        jlocation location, jobject exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                        jmethodID catch_method, jlocation catch_location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    LOG_CB(("cbException: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        info.ei                         = EI_EXCEPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        info.thread                     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        info.clazz                      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        info.method                     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        info.location                   = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        info.object                     = exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        info.u.exception.catch_clazz    = getMethodClass(jvmti_env, catch_method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        info.u.exception.catch_method   = catch_method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        info.u.exception.catch_location = catch_location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    LOG_MISC(("END cbException"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
/* Event callback for JVMTI_EVENT_THREAD_START */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
cbThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    LOG_CB(("cbThreadStart: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        info.ei         = EI_THREAD_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    LOG_MISC(("END cbThreadStart"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
/* Event callback for JVMTI_EVENT_THREAD_END */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
cbThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    LOG_CB(("cbThreadEnd: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        info.ei         = EI_THREAD_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    LOG_MISC(("END cbThreadEnd"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
/* Event callback for JVMTI_EVENT_CLASS_PREPARE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
cbClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                        jthread thread, jclass klass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    LOG_CB(("cbClassPrepare: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        info.ei         = EI_CLASS_PREPARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        info.clazz      = klass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    LOG_MISC(("END cbClassPrepare"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
/* Event callback for JVMTI_EVENT_GARBAGE_COLLECTION_FINISH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
cbGarbageCollectionFinish(jvmtiEnv *jvmti_env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    LOG_CB(("cbGarbageCollectionFinish"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    ++garbageCollected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    LOG_MISC(("END cbGarbageCollectionFinish"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
/* Event callback for JVMTI_EVENT_CLASS_LOAD */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
cbClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        jthread thread, jclass klass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    LOG_CB(("cbClassLoad: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        info.ei         = EI_CLASS_LOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        info.clazz      = klass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    LOG_MISC(("END cbClassLoad"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
/* Event callback for JVMTI_EVENT_FIELD_ACCESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                        jthread thread, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                        jlocation location, jclass field_klass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                        jobject object, jfieldID field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    LOG_CB(("cbFieldAccess: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        info.ei                         = EI_FIELD_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        info.thread                     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        info.clazz                      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        info.method                     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        info.location                   = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        info.u.field_access.field_clazz = field_klass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        info.object                     = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        info.u.field_access.field       = field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    LOG_MISC(("END cbFieldAccess"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
/* Event callback for JVMTI_EVENT_FIELD_MODIFICATION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        jthread thread, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        jlocation location, jclass field_klass, jobject object, jfieldID field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        char signature_type, jvalue new_value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    LOG_CB(("cbFieldModification: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        info.ei                                 = EI_FIELD_MODIFICATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        info.thread                             = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        info.clazz                              = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        info.method                             = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        info.location                           = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        info.u.field_modification.field         = field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        info.u.field_modification.field_clazz   = field_klass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        info.object                             = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        info.u.field_modification.signature_type= signature_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        info.u.field_modification.new_value     = new_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    LOG_MISC(("END cbFieldModification"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
/* Event callback for JVMTI_EVENT_EXCEPTION_CATCH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        jmethodID method, jlocation location, jobject exception)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    LOG_CB(("cbExceptionCatch: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        info.ei         = EI_EXCEPTION_CATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        info.clazz      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        info.method     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        info.location   = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        info.object     = exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    LOG_MISC(("END cbExceptionCatch"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
/* Event callback for JVMTI_EVENT_METHOD_ENTRY */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                        jthread thread, jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    LOG_CB(("cbMethodEntry: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        info.ei         = EI_METHOD_ENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        info.clazz      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        info.method     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    LOG_MISC(("END cbMethodEntry"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
/* Event callback for JVMTI_EVENT_METHOD_EXIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                        jthread thread, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                        jboolean wasPoppedByException, jvalue return_value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    /* JDWP does not return these events when popped due to an exception. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    if ( wasPoppedByException ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    LOG_CB(("cbMethodExit: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        info.ei         = EI_METHOD_EXIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        info.clazz      = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        info.method     = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        info.u.method_exit.return_value = return_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    LOG_MISC(("END cbMethodExit"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
/* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTER */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
cbMonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                        jthread thread, jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    jmethodID  method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    jlocation  location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    LOG_CB(("cbMonitorContendedEnter: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        info.ei         = EI_MONITOR_CONTENDED_ENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        info.object     = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        /* get current location of contended monitor enter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                (gdata->jvmti, thread, 0, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            info.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            info.method   = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            info.clazz    = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            info.location = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    LOG_MISC(("END cbMonitorContendedEnter"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
/* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTERED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                        jthread thread, jobject object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    jmethodID  method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    jlocation  location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    LOG_CB(("cbMonitorContendedEntered: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        info.ei         = EI_MONITOR_CONTENDED_ENTERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        info.object     = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        /* get current location of contended monitor enter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                (gdata->jvmti, thread, 0, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            info.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            info.method   = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            info.clazz    = getMethodClass(jvmti_env, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            info.location = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    LOG_MISC(("END cbMonitorContendedEntered"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
/* Event callback for JVMTI_EVENT_MONITOR_WAIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                        jthread thread, jobject object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                        jlong timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    jmethodID  method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    jlocation  location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    LOG_CB(("cbMonitorWait: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        info.ei         = EI_MONITOR_WAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        info.object     = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        /* The info.clazz is used for both class filtering and for location info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
         * For monitor wait event the class filtering is done for class of monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
         * object. So here info.clazz is set to class of monitor object here and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
         * is reset to class of method before writing location info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
         * See writeMonitorEvent in eventHelper.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        info.clazz      = getObjectClass(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        info.u.monitor.timeout = timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        /* get location of monitor wait() method. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                (gdata->jvmti, thread, 0, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            info.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            info.method   = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            info.location = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    LOG_MISC(("END cbMonitorWait"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
/* Event callback for JVMTI_EVENT_MONITOR_WAIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                        jthread thread, jobject object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                        jboolean timed_out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    jmethodID  method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    jlocation  location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    LOG_CB(("cbMonitorWaited: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        info.ei         = EI_MONITOR_WAITED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        info.object     = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        /* The info.clazz is used for both class filtering and for location info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
         * For monitor waited event the class filtering is done for class of monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
         * object. So here info.clazz is set to class of monitor object here and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
         * is reset to class of method before writing location info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
         * See writeMonitorEvent in eventHelper.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        info.clazz      = getObjectClass(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        info.u.monitor.timed_out = timed_out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        /* get location of monitor wait() method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                (gdata->jvmti, thread, 0, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            info.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            info.method   = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            info.location = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    LOG_MISC(("END cbMonitorWaited"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
/* Event callback for JVMTI_EVENT_VM_INIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
cbVMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    LOG_CB(("cbVMInit"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    BEGIN_CALLBACK() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        info.ei         = EI_VM_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        info.thread     = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    } END_CALLBACK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    LOG_MISC(("END cbVMInit"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
/* Event callback for JVMTI_EVENT_VM_DEATH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
cbVMDeath(jvmtiEnv *jvmti_env, JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    LOG_CB(("cbVMDeath"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    /* Clear out ALL callbacks at this time, we don't want any more. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    /*    This should prevent any new BEGIN_CALLBACK() calls. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        EXIT_ERROR(error,"Can't clear event callbacks on vm death");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    /* Now that no new callbacks will be made, we need to wait for the ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *   that are still active to complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     *   The BEGIN_CALLBACK/END_CALLBACK macros implement the VM_DEATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     *   callback protocol. Once the callback table is cleared (above),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *   we can have callback threads in different stages:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     *   1) after callback function entry and before BEGIN_CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     *      macro; we catch these threads with callbackBlock in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     *      BEGIN_CALLBACK macro
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     *   2) after BEGIN_CALLBACK macro and before END_CALLBACK macro; we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     *      catch these threads with callbackBlock in the END_CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     *      macro
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     *   3) after END_CALLBACK macro; these threads have made it past
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     *      callbackBlock and callbackLock and don't count as active
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     *   Since some of the callback threads could be blocked or suspended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     *   we will resume all threads suspended by the debugger for a short
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     *   time to flush out all callbacks. Note that the callback threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     *   will block from returning to the VM in both macros. Some threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     *   not associated with callbacks, but suspended by the debugger may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *   continue on, but not for long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *   Once the last callback finishes, it will notify this thread and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     *   we fall out of the loop below and actually process the VM_DEATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     *   event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    debugMonitorEnter(callbackBlock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        debugMonitorEnter(callbackLock); {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            vm_death_callback_active = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            (void)threadControl_resumeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            while (active_callbacks > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                /* wait for active CALLBACKs to check in (and block) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                debugMonitorWait(callbackLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        } debugMonitorExit(callbackLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        /* Only now should we actually process the VM death event */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        info.ei                 = EI_VM_DEATH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        event_callback(env, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        /* Here we unblock all the callbacks and let them return to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
         *   VM.  It's not clear this is necessary, but leaving threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
         *   blocked doesn't seem like a good idea. They don't have much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
         *   life left anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    } debugMonitorExit(callbackBlock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * The VM will die soon after the completion of this callback - we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * may need to do a final synchronization with the command loop to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * avoid the VM terminating with replying to the final (resume)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    debugLoop_sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    LOG_MISC(("END cbVMDeath"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
 * Delete this handler (do not delete permanent handlers):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
 * Deinsert handler from active list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
 * make it inactive, and free it's memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
 * Assumes handlerLock held.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
freeHandler(HandlerNode *node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    /* deinsert the handler node before disableEvents() to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * sure the event will be disabled when no other event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     * handlers are installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    if (node != NULL && (!node->permanent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        deinsert(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        error = eventFilterRestricted_deinstall(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        jvmtiDeallocate(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
 * Delete all the handlers on this chain (do not delete permanent handlers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
 * Assumes handlerLock held.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
freeHandlerChain(HandlerChain *chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    jvmtiError   error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    node  = chain->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    while ( node != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        HandlerNode *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        jvmtiError   singleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        next = NEXT(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        singleError = freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        if ( singleError != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            error = singleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        node = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
 * Deinsert and free all memory.  Safe for non-inserted nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
eventHandler_free(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    error = freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
 * Free all handlers of this kind created by the JDWP client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
 * that is, doesn't free handlers internally created by back-end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
eventHandler_freeAll(EventIndex ei)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    node = getHandlerChain(ei)->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        HandlerNode *next = NEXT(node);    /* allows node removal */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        if (node->handlerID != 0) {        /* don't free internal handlers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            error = freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        node = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
/***
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
 * Delete all breakpoints on "clazz".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
eventHandler_freeClassBreakpoints(jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    node = getHandlerChain(EI_BREAKPOINT)->first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    while (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        HandlerNode *next = NEXT(node); /* allows node removal */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        if (eventFilterRestricted_isBreakpointInClass(env, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                                                      node)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            (void)freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        node = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
eventHandler_freeByID(EventIndex ei, HandlerID handlerID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    node = find(ei, handlerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    if (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        error = freeHandler(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        /* already freed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
eventHandler_initialize(jbyte sessionID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    requestIdCounter = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    currentSessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    /* This is for BEGIN_CALLBACK/END_CALLBACK handling, make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     *   is done while none of these callbacks are active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    active_callbacks = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    vm_death_callback_active = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    callbackLock = debugMonitorCreate("JDWP Callback Lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    callbackBlock = debugMonitorCreate("JDWP Callback Block");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    handlerLock = debugMonitorCreate("JDWP Event Handler Lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    for (i = EI_min; i <= EI_max; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        getHandlerChain(i)->first = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * Permanently enabled some events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                                      EI_VM_INIT, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        EXIT_ERROR(error,"Can't enable vm init events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                                      EI_VM_DEATH, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        EXIT_ERROR(error,"Can't enable vm death events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                                      EI_THREAD_START, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        EXIT_ERROR(error,"Can't enable thread start events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                                       EI_THREAD_END, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        EXIT_ERROR(error,"Can't enable thread end events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                       EI_CLASS_PREPARE, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        EXIT_ERROR(error,"Can't enable class prepare events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    error = threadControl_setEventMode(JVMTI_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                                       EI_GC_FINISH, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        EXIT_ERROR(error,"Can't enable garbage collection finish events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    /* Event callback for JVMTI_EVENT_SINGLE_STEP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    gdata->callbacks.SingleStep                 = &cbSingleStep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    /* Event callback for JVMTI_EVENT_BREAKPOINT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    gdata->callbacks.Breakpoint                 = &cbBreakpoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    /* Event callback for JVMTI_EVENT_FRAME_POP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    gdata->callbacks.FramePop                   = &cbFramePop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    /* Event callback for JVMTI_EVENT_EXCEPTION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    gdata->callbacks.Exception                  = &cbException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    /* Event callback for JVMTI_EVENT_THREAD_START */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    gdata->callbacks.ThreadStart                = &cbThreadStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    /* Event callback for JVMTI_EVENT_THREAD_END */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    gdata->callbacks.ThreadEnd                  = &cbThreadEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    /* Event callback for JVMTI_EVENT_CLASS_PREPARE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    gdata->callbacks.ClassPrepare               = &cbClassPrepare;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    /* Event callback for JVMTI_EVENT_CLASS_LOAD */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    gdata->callbacks.ClassLoad                  = &cbClassLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    /* Event callback for JVMTI_EVENT_FIELD_ACCESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    gdata->callbacks.FieldAccess                = &cbFieldAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    /* Event callback for JVMTI_EVENT_FIELD_MODIFICATION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    gdata->callbacks.FieldModification          = &cbFieldModification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    /* Event callback for JVMTI_EVENT_EXCEPTION_CATCH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    gdata->callbacks.ExceptionCatch             = &cbExceptionCatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    /* Event callback for JVMTI_EVENT_METHOD_ENTRY */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    gdata->callbacks.MethodEntry                = &cbMethodEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    /* Event callback for JVMTI_EVENT_METHOD_EXIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    gdata->callbacks.MethodExit                 = &cbMethodExit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTER */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    gdata->callbacks.MonitorContendedEnter      = &cbMonitorContendedEnter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTERED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    gdata->callbacks.MonitorContendedEntered    = &cbMonitorContendedEntered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    /* Event callback for JVMTI_EVENT_MONITOR_WAIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    gdata->callbacks.MonitorWait                = &cbMonitorWait;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    /* Event callback for JVMTI_EVENT_MONITOR_WAITED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    gdata->callbacks.MonitorWaited              = &cbMonitorWaited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    /* Event callback for JVMTI_EVENT_VM_INIT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    gdata->callbacks.VMInit                     = &cbVMInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    /* Event callback for JVMTI_EVENT_VM_DEATH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    gdata->callbacks.VMDeath                    = &cbVMDeath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    /* Event callback for JVMTI_EVENT_GARBAGE_COLLECTION_FINISH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    gdata->callbacks.GarbageCollectionFinish    = &cbGarbageCollectionFinish;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        EXIT_ERROR(error,"Can't set event callbacks");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    /* Notify other modules that the event callbacks are in place */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    threadControl_onHook();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    /* Get the event helper thread initialized */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    eventHelper_initialize(sessionID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
eventHandler_reset(jbyte sessionID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    /* We must do this first so that if any invokes complete,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * there will be no attempt to send them to the front
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * end. Waiting for threadControl_reset leaves a window where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * the invoke completions can sneak through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    threadControl_detachInvokes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    /* Reset the event helper thread, purging all queued and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * in-process commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    eventHelper_reset(sessionID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    /* delete all handlers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    for (i = EI_min; i <= EI_max; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        (void)freeHandlerChain(getHandlerChain(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    requestIdCounter = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    currentSessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
eventHandler_lock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
eventHandler_unlock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
/***** handler creation *****/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
eventHandler_alloc(jint filterCount, EventIndex ei, jbyte suspendPolicy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    HandlerNode *node = eventFilterRestricted_alloc(filterCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    if (node != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        node->ei = ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        node->suspendPolicy = suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        node->permanent = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
HandlerID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
eventHandler_allocHandlerID(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    jint handlerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    handlerID = ++requestIdCounter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    return handlerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
installHandler(HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
              HandlerFunction func,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
              jboolean external)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    if ( func == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        return AGENT_ERROR_INVALID_EVENT_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    debugMonitorEnter(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    HANDLER_FUNCTION(node) = func;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    node->handlerID = external? ++requestIdCounter : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    error = eventFilterRestricted_install(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        insert(getHandlerChain(node->ei), node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    debugMonitorExit(handlerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
static HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
createInternal(EventIndex ei, HandlerFunction func,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
               jthread thread, jclass clazz, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
               jlocation location, jboolean permanent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    jint index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * Start with necessary allocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    node = eventHandler_alloc(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        ((thread == NULL)? 0 : 1) + ((clazz == NULL)? 0 : 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        ei, JDWP_SUSPEND_POLICY(NONE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    if (node == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    node->permanent = permanent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    if (thread != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        error = eventFilter_setThreadOnlyFilter(node, index++, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    if ((error == JVMTI_ERROR_NONE) && (clazz != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        error = eventFilter_setLocationOnlyFilter(node, index++, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                                                  method, location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * Create the new handler node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    error = installHandler(node, func, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        (void)eventHandler_free(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        node = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
eventHandler_createPermanentInternal(EventIndex ei, HandlerFunction func)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    return createInternal(ei, func, NULL,
23566
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
  1685
                          NULL, NULL, 0, JNI_TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
eventHandler_createInternalThreadOnly(EventIndex ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                                      HandlerFunction func,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                                      jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    return createInternal(ei, func, thread,
23566
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
  1694
                          NULL, NULL, 0, JNI_FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
HandlerNode *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
eventHandler_createInternalBreakpoint(HandlerFunction func,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                                      jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                                      jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                                      jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                                      jlocation location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    return createInternal(EI_BREAKPOINT, func, thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                          clazz, method, location, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
eventHandler_installExternal(HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    return installHandler(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                          standardHandlers_defaultHandler(node->ei),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                          JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
}