jdk/src/share/back/ThreadReferenceImpl.c
author xdono
Thu, 02 Oct 2008 19:58:32 -0700
changeset 1247 b4c26443dee5
parent 896 5c02031316bf
child 5506 202f599c92aa
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1247
b4c26443dee5 6754988: Update copyright year
xdono
parents: 896
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 "ThreadReferenceImpl.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 "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "FrameID.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
name(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        jvmtiThreadInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        (void)memset(&info, 0, sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                (gdata->jvmti, thread, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            (void)outStream_writeString(out, info.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if ( info.name != NULL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            jvmtiDeallocate(info.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
suspend(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    error = threadControl_suspendThread(thread, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
resume(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /* true means it is okay to unblock the commandLoop thread */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    error = threadControl_resumeThread(thread, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
status(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    jdwpThreadStatus threadStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jint statusFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    error = threadControl_applicationThreadStatus(thread, &threadStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                                          &statusFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    (void)outStream_writeInt(out, threadStatus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    (void)outStream_writeInt(out, statusFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
threadGroup(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        jvmtiThreadInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        (void)memset(&info, 0, sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                (gdata->jvmti, thread, &info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            (void)outStream_writeObjectRef(env, out, info.thread_group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if ( info.name!=NULL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            jvmtiDeallocate(info.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
validateSuspendedThread(PacketOutputStream *out, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    error = threadControl_suspendCount(thread, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        outStream_setError(out, JDWP_ERROR(THREAD_NOT_SUSPENDED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
frames(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    FrameNumber fnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    jint startIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jint length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    startIndex = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    length = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    if (!validateSuspendedThread(out, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        (gdata->jvmti, thread, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if (length == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        length = count - startIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    if (length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        (void)outStream_writeInt(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    if ((startIndex < 0) || (startIndex > count - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        outStream_setError(out, JDWP_ERROR(INVALID_INDEX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    if ((length < 0) || (length + startIndex > count)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        outStream_setError(out, JDWP_ERROR(INVALID_LENGTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    (void)outStream_writeInt(out, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    for(fnum = startIndex ; fnum < startIndex+length ; fnum++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            /* Get location info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                (gdata->jvmti, thread, fnum, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (error == JVMTI_ERROR_OPAQUE_FRAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                clazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                location = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            } else if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                error = methodClass(method, &clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    FrameID frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    frame = createFrameID(thread, fnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    (void)outStream_writeFrameID(out, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    writeCodeLocation(out, clazz, method, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (error != JVMTI_ERROR_NONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
getFrameCount(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    if (!validateSuspendedThread(out, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        (gdata->jvmti, thread, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    (void)outStream_writeInt(out, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    return JNI_TRUE;
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 jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
ownedMonitors(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    if (!validateSuspendedThread(out, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        jint count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        jobject *monitors = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                (gdata->jvmti, thread, &count, &monitors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            (void)outStream_writeInt(out, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                jobject monitor = monitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                (void)outStream_writeByte(out, specificTypeKey(env, monitor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                (void)outStream_writeObjectRef(env, out, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (monitors != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            jvmtiDeallocate(monitors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
currentContendedMonitor(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    if (thread == NULL || threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    if (!validateSuspendedThread(out, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        jobject monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetCurrentContendedMonitor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                (gdata->jvmti, thread, &monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            (void)outStream_writeByte(out, specificTypeKey(env, monitor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            (void)outStream_writeObjectRef(env, out, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
stop(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    jobject throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    throwable = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    error = threadControl_stop(thread, throwable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
interrupt(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    error = threadControl_interrupt(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
suspendCount(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    error = threadControl_suspendCount(thread, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    (void)outStream_writeInt(out, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
ownedMonitorsWithStackDepth(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    if (thread == NULL || threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    if (!validateSuspendedThread(out, thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        jint count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        jvmtiMonitorStackDepthInfo *monitors=NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorStackDepthInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                (gdata->jvmti, thread, &count, &monitors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            (void)outStream_writeInt(out, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                jobject monitor = monitors[i].monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                (void)outStream_writeByte(out, specificTypeKey(env, monitor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                (void)outStream_writeObjectRef(getEnv(), out, monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                (void)outStream_writeInt(out,monitors[i].stack_depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (monitors != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            jvmtiDeallocate(monitors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
forceEarlyReturn(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    jvalue value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    jbyte typeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    typeKey = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    if (isObjectTag(typeKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        value.l = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        (gdata->jvmti, thread, value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            case JDWP_TAG(VOID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnVoid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                                (gdata->jvmti, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                value.b = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                (gdata->jvmti, thread, value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                value.c = inStream_readChar(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                                (gdata->jvmti, thread, value.c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                value.f = inStream_readFloat(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnFloat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                (gdata->jvmti, thread, value.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                value.d = inStream_readDouble(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnDouble)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                (gdata->jvmti, thread, value.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                value.i = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                (gdata->jvmti, thread, value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                value.j = inStream_readLong(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnLong)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                (gdata->jvmti, thread, value.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                value.s = inStream_readShort(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                (gdata->jvmti, thread, value.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                value.z = inStream_readBoolean(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                                (gdata->jvmti, thread, value.z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                error =  AGENT_ERROR_INVALID_TAG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
      jdwpError serror = map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
      if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
void *ThreadReference_Cmds[] = { (void *)14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    (void *)name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    (void *)suspend,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    (void *)resume,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    (void *)status,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    (void *)threadGroup,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    (void *)frames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    (void *)getFrameCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    (void *)ownedMonitors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    (void *)currentContendedMonitor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    (void *)stop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    (void *)interrupt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    (void *)suspendCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    (void *)ownedMonitorsWithStackDepth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    (void *)forceEarlyReturn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    };