src/jdk.jdwp.agent/share/native/libjdwp/eventHelper.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47525 e05aff6beada
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
46841
76a15bd1de0a 8134103: JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2017, 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
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "invoker.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
    32
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
    33
#define COMMAND_LOOP_THREAD_NAME "JDWP Event Helper Thread"
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Event helper thread command commandKinds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define COMMAND_REPORT_EVENT_COMPOSITE          1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define COMMAND_REPORT_INVOKE_DONE              2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define COMMAND_REPORT_VM_INIT                  3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#define COMMAND_SUSPEND_THREAD                  4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Event helper thread command singleKinds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define COMMAND_SINGLE_EVENT                    11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define COMMAND_SINGLE_UNLOAD                   12
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define COMMAND_SINGLE_FRAME_EVENT              13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
typedef struct EventCommandSingle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    jbyte suspendPolicy; /* NOTE: Must be the first field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    jint id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
} EventCommandSingle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
typedef struct UnloadCommandSingle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    char *classSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    jint id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
} UnloadCommandSingle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
typedef struct FrameEventCommandSingle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jbyte suspendPolicy; /* NOTE: Must be the first field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    jint id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    EventIndex ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    char typeKey;         /* Not used for method entry events */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                          /* If typeKey is 0, then no return value is needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    jvalue returnValue;   /* Not used for method entry events */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
} FrameEventCommandSingle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
typedef struct CommandSingle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    jint singleKind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        EventCommandSingle eventCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        UnloadCommandSingle unloadCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        FrameEventCommandSingle frameEventCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    } u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
} CommandSingle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
typedef struct ReportInvokeDoneCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
} ReportInvokeDoneCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
typedef struct ReportVMInitCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    jbyte suspendPolicy; /* NOTE: Must be the first field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
} ReportVMInitCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
typedef struct SuspendThreadCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
} SuspendThreadCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
typedef struct ReportEventCompositeCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    jbyte suspendPolicy; /* NOTE: Must be the first field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    jint eventCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    CommandSingle singleCommand[1]; /* variable length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
} ReportEventCompositeCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
typedef struct HelperCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    jint commandKind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    jboolean done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    jboolean waiting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    jbyte sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    struct HelperCommand *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        /* NOTE: Each of the structs below must have the same first field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        ReportEventCompositeCommand reportEventComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ReportInvokeDoneCommand     reportInvokeDone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        ReportVMInitCommand         reportVMInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        SuspendThreadCommand        suspendThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    } u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /* composite array expand out, put nothing after */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
} HelperCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    HelperCommand *head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    HelperCommand *tail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
} CommandQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
static CommandQueue commandQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
static jrawMonitorID commandQueueLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
static jrawMonitorID commandCompleteLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
static jrawMonitorID blockCommandLoopLock;
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   127
static jrawMonitorID vmDeathLock;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   128
static volatile jboolean commandLoopEnteredVmDeathLock = JNI_FALSE;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   129
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
static jint maxQueueSize = 50 * 1024; /* TO DO: Make this configurable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
static jboolean holdEvents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
static jint currentQueueSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
static jint currentSessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
static void saveEventInfoRefs(JNIEnv *env, EventInfo *evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
static void tossEventInfoRefs(JNIEnv *env, EventInfo *evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
commandSize(HelperCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    jint size = sizeof(HelperCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    if (command->commandKind == COMMAND_REPORT_EVENT_COMPOSITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * One event is accounted for in the Helper Command. If there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * more, add to size here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        size += ((int)sizeof(CommandSingle) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                     (command->u.reportEventComposite.eventCount - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
freeCommand(HelperCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if ( command == NULL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    jvmtiDeallocate(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
enqueueCommand(HelperCommand *command,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
               jboolean wait, jboolean reportingVMDeath)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    static jboolean vmDeathReported = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    CommandQueue *queue = &commandQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    jint size = commandSize(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    command->done = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    command->waiting = wait;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    command->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    debugMonitorEnter(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    while (size + currentQueueSize > maxQueueSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        debugMonitorWait(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    log_debugee_location("enqueueCommand(): HelperCommand being processed", NULL, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    if (vmDeathReported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /* send no more events after VMDeath and don't wait */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        wait = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        currentQueueSize += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (queue->head == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            queue->head = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            queue->tail->next = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        queue->tail = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (reportingVMDeath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            vmDeathReported = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    debugMonitorNotifyAll(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    debugMonitorExit(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    if (wait) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        debugMonitorEnter(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        while (!command->done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            log_debugee_location("enqueueCommand(): HelperCommand wait", NULL, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            debugMonitorWait(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        freeCommand(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        debugMonitorExit(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
completeCommand(HelperCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    if (command->waiting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        debugMonitorEnter(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        command->done = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        log_debugee_location("completeCommand(): HelperCommand done waiting", NULL, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        debugMonitorNotifyAll(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        debugMonitorExit(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        freeCommand(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
static HelperCommand *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
dequeueCommand(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    HelperCommand *command = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    CommandQueue *queue = &commandQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    debugMonitorEnter(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    while (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        while (holdEvents || (queue->head == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            debugMonitorWait(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        JDI_ASSERT(queue->head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        command = queue->head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        queue->head = command->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (queue->tail == command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            queue->tail = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        log_debugee_location("dequeueCommand(): command being dequeued", NULL, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        size = commandSize(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        /*
46841
76a15bd1de0a 8134103: JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 25859
diff changeset
   249
         * Immediately close out any commands enqueued from
76a15bd1de0a 8134103: JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 25859
diff changeset
   250
         * a dead VM or a previously attached debugger.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         */
46841
76a15bd1de0a 8134103: JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 25859
diff changeset
   252
        if (gdata->vmDead || command->sessionID != currentSessionID) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            log_debugee_location("dequeueCommand(): command session removal", NULL, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            completeCommand(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            command = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * There's room in the queue for more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        currentQueueSize -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        debugMonitorNotifyAll(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    debugMonitorExit(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    return command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
void eventHelper_holdEvents(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    debugMonitorEnter(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    holdEvents = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    debugMonitorNotifyAll(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    debugMonitorExit(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
void eventHelper_releaseEvents(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    debugMonitorEnter(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    holdEvents = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    debugMonitorNotifyAll(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    debugMonitorExit(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
writeSingleStepEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
writeBreakpointEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
writeFieldAccessEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    jbyte fieldClassTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    fieldClassTag = referenceTypeTag(evinfo->u.field_access.field_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    (void)outStream_writeByte(out, fieldClassTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    (void)outStream_writeObjectRef(env, out, evinfo->u.field_access.field_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    (void)outStream_writeFieldID(out, evinfo->u.field_access.field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    (void)outStream_writeObjectTag(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    (void)outStream_writeObjectRef(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
writeFieldModificationEvent(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    jbyte fieldClassTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    fieldClassTag = referenceTypeTag(evinfo->u.field_modification.field_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    (void)outStream_writeByte(out, fieldClassTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    (void)outStream_writeObjectRef(env, out, evinfo->u.field_modification.field_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    (void)outStream_writeFieldID(out, evinfo->u.field_modification.field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    (void)outStream_writeObjectTag(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    (void)outStream_writeObjectRef(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    (void)outStream_writeValue(env, out, (jbyte)evinfo->u.field_modification.signature_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                         evinfo->u.field_modification.new_value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
writeExceptionEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    (void)outStream_writeObjectTag(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    (void)outStream_writeObjectRef(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    writeCodeLocation(out, evinfo->u.exception.catch_clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                      evinfo->u.exception.catch_method, evinfo->u.exception.catch_location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
writeThreadEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
writeMonitorEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    jclass klass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    (void)outStream_writeObjectTag(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    (void)outStream_writeObjectRef(env, out, evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (evinfo->ei == EI_MONITOR_WAIT || evinfo->ei == EI_MONITOR_WAITED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        /* clazz of evinfo was set to class of monitor object for monitor wait event class filtering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * So get the method class to write location info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * See cbMonitorWait() and cbMonitorWaited() function in eventHandler.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        klass=getMethodClass(gdata->jvmti, evinfo->method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        writeCodeLocation(out, klass, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (evinfo->ei == EI_MONITOR_WAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            (void)outStream_writeLong(out, evinfo->u.monitor.timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } else  if (evinfo->ei == EI_MONITOR_WAITED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            (void)outStream_writeBoolean(out, evinfo->u.monitor.timed_out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        /* This runs in a command loop and this thread may not return to java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         * So we need to delete the local ref created by jvmti GetMethodDeclaringClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        JNI_FUNC_PTR(env,DeleteLocalRef)(env, klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
writeClassEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    jbyte classTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    jint status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    classTag = referenceTypeTag(evinfo->clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    error = classSignature(evinfo->clazz, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        EXIT_ERROR(error,"signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    status = classStatus(evinfo->clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    (void)outStream_writeObjectRef(env, out, evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    (void)outStream_writeByte(out, classTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    (void)outStream_writeObjectRef(env, out, evinfo->clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    (void)outStream_writeString(out, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    (void)outStream_writeInt(out, map2jdwpClassStatus(status));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
writeVMDeathEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
handleEventCommandSingle(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                           EventCommandSingle *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    EventInfo *evinfo = &command->info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    (void)outStream_writeByte(out, eventIndex2jdwp(evinfo->ei));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    (void)outStream_writeInt(out, command->id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    switch (evinfo->ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        case EI_SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            writeSingleStepEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        case EI_BREAKPOINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            writeBreakpointEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        case EI_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            writeFieldAccessEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        case EI_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            writeFieldModificationEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        case EI_EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            writeExceptionEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        case EI_THREAD_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        case EI_THREAD_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            writeThreadEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        case EI_CLASS_LOAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        case EI_CLASS_PREPARE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            writeClassEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        case EI_MONITOR_CONTENDED_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        case EI_MONITOR_CONTENDED_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        case EI_MONITOR_WAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        case EI_MONITOR_WAITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            writeMonitorEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        case EI_VM_DEATH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            writeVMDeathEvent(env, out, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,"unknown event index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    tossEventInfoRefs(env, evinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
handleUnloadCommandSingle(JNIEnv* env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                           UnloadCommandSingle *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    (void)outStream_writeByte(out, JDWP_EVENT(CLASS_UNLOAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    (void)outStream_writeInt(out, command->id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    (void)outStream_writeString(out, command->classSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    jvmtiDeallocate(command->classSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    command->classSignature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
handleFrameEventCommandSingle(JNIEnv* env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                              FrameEventCommandSingle *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    if (command->typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        (void)outStream_writeByte(out, JDWP_EVENT(METHOD_EXIT_WITH_RETURN_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        (void)outStream_writeByte(out, eventIndex2jdwp(command->ei));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    (void)outStream_writeInt(out, command->id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    (void)outStream_writeObjectRef(env, out, command->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    writeCodeLocation(out, command->clazz, command->method, command->location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    if (command->typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        (void)outStream_writeValue(env, out, command->typeKey, command->returnValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (isObjectTag(command->typeKey) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            command->returnValue.l != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            tossGlobalRef(env, &(command->returnValue.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    tossGlobalRef(env, &(command->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    tossGlobalRef(env, &(command->clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
suspendWithInvokeEnabled(jbyte policy, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    invoker_enableInvokeRequests(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    if (policy == JDWP_SUSPEND_POLICY(ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        (void)threadControl_suspendAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        (void)threadControl_suspendThread(thread, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
handleReportEventCompositeCommand(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                  ReportEventCompositeCommand *recc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    PacketOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    jint count = recc->eventCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    if (recc->suspendPolicy != JDWP_SUSPEND_POLICY(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        /* must determine thread to interrupt before writing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        /* since writing destroys it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        jthread thread = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            CommandSingle *single = &(recc->singleCommand[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            switch (single->singleKind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                case COMMAND_SINGLE_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    thread = single->u.eventCommand.info.thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                case COMMAND_SINGLE_FRAME_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    thread = single->u.frameEventCommand.thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (thread != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (thread == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            (void)threadControl_suspendAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            suspendWithInvokeEnabled(recc->suspendPolicy, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    outStream_initCommand(&out, uniqueID(), 0x0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                          JDWP_COMMAND_SET(Event),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                          JDWP_COMMAND(Event, Composite));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    (void)outStream_writeByte(&out, recc->suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    (void)outStream_writeInt(&out, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        CommandSingle *single = &(recc->singleCommand[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        switch (single->singleKind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            case COMMAND_SINGLE_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                handleEventCommandSingle(env, &out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                         &single->u.eventCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            case COMMAND_SINGLE_UNLOAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                handleUnloadCommandSingle(env, &out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                          &single->u.unloadCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            case COMMAND_SINGLE_FRAME_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                handleFrameEventCommandSingle(env, &out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                              &single->u.frameEventCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    outStream_sendCommand(&out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    outStream_destroy(&out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
handleReportInvokeDoneCommand(JNIEnv* env, ReportInvokeDoneCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    invoker_completeInvokeRequest(command->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    tossGlobalRef(env, &(command->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
handleReportVMInitCommand(JNIEnv* env, ReportVMInitCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    PacketOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    if (command->suspendPolicy == JDWP_SUSPEND_POLICY(ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        (void)threadControl_suspendAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    } else if (command->suspendPolicy == JDWP_SUSPEND_POLICY(EVENT_THREAD)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        (void)threadControl_suspendThread(command->thread, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    outStream_initCommand(&out, uniqueID(), 0x0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                          JDWP_COMMAND_SET(Event),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                          JDWP_COMMAND(Event, Composite));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    (void)outStream_writeByte(&out, command->suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    (void)outStream_writeInt(&out, 1);   /* Always one component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    (void)outStream_writeByte(&out, JDWP_EVENT(VM_INIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    (void)outStream_writeInt(&out, 0);    /* Not in response to an event req. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    (void)outStream_writeObjectRef(env, &out, command->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    outStream_sendCommand(&out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    outStream_destroy(&out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /* Why aren't we tossing this: tossGlobalRef(env, &(command->thread)); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
handleSuspendThreadCommand(JNIEnv* env, SuspendThreadCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * For the moment, there's  nothing that can be done with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * return code, so we don't check it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    (void)threadControl_suspendThread(command->thread, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    tossGlobalRef(env, &(command->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
handleCommand(JNIEnv *env, HelperCommand *command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    switch (command->commandKind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        case COMMAND_REPORT_EVENT_COMPOSITE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            handleReportEventCompositeCommand(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                        &command->u.reportEventComposite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        case COMMAND_REPORT_INVOKE_DONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            handleReportInvokeDoneCommand(env, &command->u.reportInvokeDone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        case COMMAND_REPORT_VM_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            handleReportVMInitCommand(env, &command->u.reportVMInit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        case COMMAND_SUSPEND_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            handleSuspendThreadCommand(env, &command->u.suspendThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,"Event Helper Command");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
 * There was an assumption that only one event with a suspend-all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
 * policy could be processed by commandLoop() at one time. It was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
 * assumed that native thread suspension from the first suspend-all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
 * event would prevent the second suspend-all event from making it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 * into the command queue. For the Classic VM, this was a reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 * assumption. However, in HotSpot all thread suspension requires a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * VM operation and VM operations take time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 * The solution is to add a mechanism to prevent commandLoop() from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
 * processing more than one event with a suspend-all policy. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
 * accomplished by forcing commandLoop() to wait for either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
 * ThreadReferenceImpl.c: resume() or VirtualMachineImpl.c: resume()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
 * when an event with a suspend-all policy has been completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
static jboolean blockCommandLoop = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
 * We wait for either ThreadReferenceImpl.c: resume() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
 * VirtualMachineImpl.c: resume() to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
doBlockCommandLoop(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    debugMonitorEnter(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    while (blockCommandLoop == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        debugMonitorWait(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    debugMonitorExit(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
 * If the command that we are about to execute has a suspend-all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
 * policy, then prepare for either ThreadReferenceImpl.c: resume()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
 * or VirtualMachineImpl.c: resume() to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
needBlockCommandLoop(HelperCommand *cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    if (cmd->commandKind == COMMAND_REPORT_EVENT_COMPOSITE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    && cmd->u.reportEventComposite.suspendPolicy == JDWP_SUSPEND_POLICY(ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        debugMonitorEnter(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        blockCommandLoop = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        debugMonitorExit(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
 * Used by either ThreadReferenceImpl.c: resume() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
 * VirtualMachineImpl.c: resume() to resume commandLoop().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
unblockCommandLoop(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    debugMonitorEnter(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    blockCommandLoop = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    debugMonitorNotifyAll(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    debugMonitorExit(blockCommandLoopLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
 * The event helper thread. Dequeues commands and processes them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
commandLoop(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    LOG_MISC(("Begin command loop thread"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    while (JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        HelperCommand *command = dequeueCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (command != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
             * Setup for a potential doBlockCommand() call before calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
             * handleCommand() to prevent any races.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            jboolean doBlock = needBlockCommandLoop(command);
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   709
            debugMonitorEnter(vmDeathLock);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   710
            commandLoopEnteredVmDeathLock = JNI_TRUE;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   711
            if (!gdata->vmDead) {
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   712
                log_debugee_location("commandLoop(): command being handled", NULL, NULL, 0);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   713
                handleCommand(jni_env, command);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   714
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            completeCommand(command);
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   716
            debugMonitorExit(vmDeathLock);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   717
            commandLoopEnteredVmDeathLock = JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            /* if we just finished a suspend-all cmd, then we block here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            if (doBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                doBlockCommandLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /* This loop never ends, even as connections come and go with server=y */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
eventHelper_initialize(jbyte sessionID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    jvmtiStartFunction func;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    currentSessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    holdEvents = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    commandQueue.head = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    commandQueue.tail = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    commandQueueLock = debugMonitorCreate("JDWP Event Helper Queue Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    commandCompleteLock = debugMonitorCreate("JDWP Event Helper Completion Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    blockCommandLoopLock = debugMonitorCreate("JDWP Event Block CommandLoop Monitor");
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   740
    vmDeathLock = debugMonitorCreate("JDWP VM_DEATH CommandLoop Monitor");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /* Start the event handler thread */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    func = &commandLoop;
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   744
    (void)spawnNewThread(func, NULL, COMMAND_LOOP_THREAD_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
eventHelper_reset(jbyte newSessionID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    debugMonitorEnter(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    currentSessionID = newSessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    holdEvents = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    debugMonitorNotifyAll(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    debugMonitorExit(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 * Provide a means for threadControl to ensure that crucial locks are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
 * held by suspended threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
eventHelper_lock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    debugMonitorEnter(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    debugMonitorEnter(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
eventHelper_unlock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    debugMonitorExit(commandCompleteLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    debugMonitorExit(commandQueueLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47525
diff changeset
   775
void commandLoop_exitVmDeathLockOnError(void)
47525
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   776
{
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   777
    const char* MSG_BASE = "exitVmDeathLockOnError: error in JVMTI %s: %d\n";
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   778
    jthread cur_thread = NULL;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   779
    jvmtiThreadInfo thread_info;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   780
    jvmtiError err = JVMTI_ERROR_NONE;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   781
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   782
    err = JVMTI_FUNC_PTR(gdata->jvmti, GetCurrentThread)
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   783
              (gdata->jvmti, &cur_thread);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   784
    if (err != JVMTI_ERROR_NONE) {
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   785
        LOG_ERROR((MSG_BASE, "GetCurrentThread", err));
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   786
        return;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   787
    }
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   788
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   789
    err = JVMTI_FUNC_PTR(gdata->jvmti, GetThreadInfo)
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   790
              (gdata->jvmti, cur_thread, &thread_info);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   791
    if (err != JVMTI_ERROR_NONE) {
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   792
        LOG_ERROR((MSG_BASE, "GetThreadInfo", err));
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   793
        return;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   794
    }
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   795
    if (strcmp(thread_info.name, COMMAND_LOOP_THREAD_NAME) != 0) {
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   796
        return;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   797
    }
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   798
    if (commandLoopEnteredVmDeathLock == JNI_TRUE) {
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   799
        debugMonitorExit(vmDeathLock);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   800
        commandLoopEnteredVmDeathLock = JNI_FALSE;
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   801
    }
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   802
}
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   803
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   804
void
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   805
commandLoop_sync(void)
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   806
{
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   807
    debugMonitorEnter(vmDeathLock);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   808
    debugMonitorExit(vmDeathLock);
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   809
}
e05aff6beada 8177901: JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface
sspitsyn
parents: 47216
diff changeset
   810
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
/* Change all references to global in the EventInfo struct */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
saveEventInfoRefs(JNIEnv *env, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    jthread *pthread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    jclass *pclazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    jobject *pobject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    jobject object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    char sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    if ( evinfo->thread != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        pthread = &(evinfo->thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        thread = *pthread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        *pthread = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        saveGlobalRef(env, thread, pthread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    if ( evinfo->clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        pclazz = &(evinfo->clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        clazz = *pclazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        saveGlobalRef(env, clazz, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    if ( evinfo->object != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        pobject = &(evinfo->object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        object = *pobject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        *pobject = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        saveGlobalRef(env, object, pobject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    switch (evinfo->ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        case EI_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            if ( evinfo->u.field_modification.field_clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                pclazz = &(evinfo->u.field_modification.field_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                clazz = *pclazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                saveGlobalRef(env, clazz, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            sig = evinfo->u.field_modification.signature_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            if ((sig == JDWP_TAG(ARRAY)) || (sig == JDWP_TAG(OBJECT))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                if ( evinfo->u.field_modification.new_value.l != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                    pobject = &(evinfo->u.field_modification.new_value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    object = *pobject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    *pobject = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    saveGlobalRef(env, object, pobject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        case EI_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            if ( evinfo->u.field_access.field_clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                pclazz = &(evinfo->u.field_access.field_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                clazz = *pclazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                saveGlobalRef(env, clazz, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        case EI_EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            if ( evinfo->u.exception.catch_clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                pclazz = &(evinfo->u.exception.catch_clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                clazz = *pclazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                saveGlobalRef(env, clazz, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,"ExceptionOccurred");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
tossEventInfoRefs(JNIEnv *env, EventInfo *evinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    char sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    if ( evinfo->thread != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        tossGlobalRef(env, &(evinfo->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    if ( evinfo->clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        tossGlobalRef(env, &(evinfo->clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    if ( evinfo->object != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        tossGlobalRef(env, &(evinfo->object));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    switch (evinfo->ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        case EI_FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            if ( evinfo->u.field_modification.field_clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                tossGlobalRef(env, &(evinfo->u.field_modification.field_clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            sig = evinfo->u.field_modification.signature_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            if ((sig == JDWP_TAG(ARRAY)) || (sig == JDWP_TAG(OBJECT))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                if ( evinfo->u.field_modification.new_value.l != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    tossGlobalRef(env, &(evinfo->u.field_modification.new_value.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        case EI_FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            if ( evinfo->u.field_access.field_clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                tossGlobalRef(env, &(evinfo->u.field_access.field_clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        case EI_EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            if ( evinfo->u.exception.catch_clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                tossGlobalRef(env, &(evinfo->u.exception.catch_clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
struct bag *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
eventHelper_createEventBag(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    return bagCreateBag(sizeof(CommandSingle), 5 /* events */ );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
/* Return the combined suspend policy for the event set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
enumForCombinedSuspendPolicy(void *cv, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    CommandSingle *command = cv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    jbyte thisPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    jbyte *policy = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    switch(command->singleKind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        case COMMAND_SINGLE_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            thisPolicy = command->u.eventCommand.suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        case COMMAND_SINGLE_FRAME_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            thisPolicy = command->u.frameEventCommand.suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            thisPolicy = JDWP_SUSPEND_POLICY(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    /* Expand running policy value if this policy demands it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    if (*policy == JDWP_SUSPEND_POLICY(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        *policy = thisPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    } else if (*policy == JDWP_SUSPEND_POLICY(EVENT_THREAD)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        *policy = (thisPolicy == JDWP_SUSPEND_POLICY(ALL))?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                        thisPolicy : *policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /* Short circuit if we reached maximal suspend policy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    if (*policy == JDWP_SUSPEND_POLICY(ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
/* Determine whether we are reporting VM death
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
enumForVMDeath(void *cv, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    CommandSingle *command = cv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    jboolean *reportingVMDeath = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    if (command->singleKind == COMMAND_SINGLE_EVENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (command->u.eventCommand.info.ei == EI_VM_DEATH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            *reportingVMDeath = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
struct singleTracker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    ReportEventCompositeCommand *recc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
enumForCopyingSingles(void *command, void *tv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    struct singleTracker *tracker = (struct singleTracker *)tv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    (void)memcpy(&tracker->recc->singleCommand[tracker->index++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
           command,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
           sizeof(CommandSingle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
eventHelper_reportEvents(jbyte sessionID, struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    int size = bagSize(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    jbyte suspendPolicy = JDWP_SUSPEND_POLICY(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    jboolean reportingVMDeath = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    jboolean wait;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    int command_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    HelperCommand *command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    ReportEventCompositeCommand *recc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    struct singleTracker tracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    if (size == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        return suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    (void)bagEnumerateOver(eventBag, enumForCombinedSuspendPolicy, &suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    (void)bagEnumerateOver(eventBag, enumForVMDeath, &reportingVMDeath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    command_size = (int)(sizeof(HelperCommand) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                         sizeof(CommandSingle)*(size-1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    command = jvmtiAllocate(command_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    (void)memset(command, 0, command_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    command->commandKind = COMMAND_REPORT_EVENT_COMPOSITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    command->sessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    recc = &command->u.reportEventComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    recc->suspendPolicy = suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    recc->eventCount = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    tracker.recc = recc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    tracker.index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    (void)bagEnumerateOver(eventBag, enumForCopyingSingles, &tracker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * We must wait if this thread (the event thread) is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * suspended or if the VM is about to die. (Waiting in the latter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * case ensures that we get the event out before the process dies.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    wait = (jboolean)((suspendPolicy != JDWP_SUSPEND_POLICY(NONE)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                      reportingVMDeath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    enqueueCommand(command, wait, reportingVMDeath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    return suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
eventHelper_recordEvent(EventInfo *evinfo, jint id, jbyte suspendPolicy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                         struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    CommandSingle *command = bagAdd(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    if (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"badAdd(eventBag)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    command->singleKind = COMMAND_SINGLE_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    command->u.eventCommand.suspendPolicy = suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    command->u.eventCommand.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * Copy the event into the command so that it can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * asynchronously by the event helper thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    (void)memcpy(&command->u.eventCommand.info, evinfo, sizeof(*evinfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    saveEventInfoRefs(env, &command->u.eventCommand.info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
eventHelper_recordClassUnload(jint id, char *signature, struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    CommandSingle *command = bagAdd(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    if (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"bagAdd(eventBag)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    command->singleKind = COMMAND_SINGLE_UNLOAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    command->u.unloadCommand.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    command->u.unloadCommand.classSignature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
eventHelper_recordFrameEvent(jint id, jbyte suspendPolicy, EventIndex ei,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                             jthread thread, jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                             jmethodID method, jlocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                             int needReturnValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                             jvalue returnValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                             struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    FrameEventCommandSingle *frameCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    CommandSingle *command = bagAdd(eventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    jvmtiError err = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    if (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"bagAdd(eventBag)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    command->singleKind = COMMAND_SINGLE_FRAME_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    frameCommand = &command->u.frameEventCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    frameCommand->suspendPolicy = suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    frameCommand->id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    frameCommand->ei = ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    saveGlobalRef(env, thread, &(frameCommand->thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    saveGlobalRef(env, clazz, &(frameCommand->clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    frameCommand->method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    frameCommand->location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    if (needReturnValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        err = methodReturnType(method, &frameCommand->typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        JDI_ASSERT(err == JVMTI_ERROR_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
         * V or B C D F I J S Z L <classname> ;    [ ComponentType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        if (isObjectTag(frameCommand->typeKey) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            returnValue.l != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            saveGlobalRef(env, returnValue.l, &(frameCommand->returnValue.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            frameCommand->returnValue = returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
      /* This is not a JDWP METHOD_EXIT_WITH_RETURN_VALUE request,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
       * so signal this by setting typeKey = 0 which is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
       * a legal typekey.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
       frameCommand->typeKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
eventHelper_reportInvokeDone(jbyte sessionID, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    HelperCommand *command = jvmtiAllocate(sizeof(*command));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    if (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"HelperCommand");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    (void)memset(command, 0, sizeof(*command));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    command->commandKind = COMMAND_REPORT_INVOKE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    command->sessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    saveGlobalRef(env, thread, &(command->u.reportInvokeDone.thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    enqueueCommand(command, JNI_TRUE, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
 * This, currently, cannot go through the normal event handling code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
 * because the JVMTI event does not contain a thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
eventHelper_reportVMInit(JNIEnv *env, jbyte sessionID, jthread thread, jbyte suspendPolicy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    HelperCommand *command = jvmtiAllocate(sizeof(*command));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    if (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"HelperCommmand");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    (void)memset(command, 0, sizeof(*command));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    command->commandKind = COMMAND_REPORT_VM_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    command->sessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    saveGlobalRef(env, thread, &(command->u.reportVMInit.thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    command->u.reportVMInit.suspendPolicy = suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    enqueueCommand(command, JNI_TRUE, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
eventHelper_suspendThread(jbyte sessionID, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    HelperCommand *command = jvmtiAllocate(sizeof(*command));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    if (command == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"HelperCommmand");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    (void)memset(command, 0, sizeof(*command));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    command->commandKind = COMMAND_SUSPEND_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    command->sessionID = sessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    saveGlobalRef(env, thread, &(command->u.suspendThread.thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    enqueueCommand(command, JNI_TRUE, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
}