jdk/src/share/back/invoker.c
author ohair
Fri, 22 Aug 2008 12:24:27 -0700
changeset 1090 c5805b1672a6
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6732421: Removed old javavm and Classic VM files from the jdk7 sources Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
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 "invoker.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 "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
static jrawMonitorID invokerLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
invoker_initialize(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    invokerLock = debugMonitorCreate("JDWP Invocation Lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
invoker_reset(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
void invoker_lock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    debugMonitorEnter(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
void invoker_unlock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    debugMonitorExit(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
returnTypeTag(char *signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    char *tagPtr = strchr(signature, SIGNATURE_END_ARGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    JDI_ASSERT(tagPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    tagPtr++;    /* 1st character after the end of args */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    return (jbyte)*tagPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
static jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
nextArgumentTypeTag(void **cursor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    char *tagPtr = *cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    jbyte argumentTag = (jbyte)*tagPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    if (*tagPtr != SIGNATURE_END_ARGS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        /* Skip any array modifiers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        while (*tagPtr == JDWP_TAG(ARRAY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            tagPtr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        /* Skip class name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (*tagPtr == JDWP_TAG(OBJECT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            tagPtr = strchr(tagPtr, SIGNATURE_END_CLASS) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            JDI_ASSERT(tagPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            /* Skip primitive sig */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            tagPtr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    *cursor = tagPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    return argumentTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
firstArgumentTypeTag(char *signature, void **cursor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    JDI_ASSERT(signature[0] == SIGNATURE_BEGIN_ARGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    *cursor = signature + 1; /* skip to the first arg */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    return nextArgumentTypeTag(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Note: argument refs may be destroyed on out-of-memory error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
createGlobalRefs(JNIEnv *env, InvokeRequest *request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    jclass clazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    jobject instance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    jint argIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    jbyte argumentTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    jvalue *argument;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    void *cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    jobject *argRefs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if ( request->argumentCount > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        argRefs = jvmtiAllocate((jint)(request->argumentCount*sizeof(jobject)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if ( argRefs==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            error = AGENT_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            (void)memset(argRefs, 0, request->argumentCount*sizeof(jobject));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        saveGlobalRef(env, request->clazz, &clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (clazz == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            error = AGENT_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if ( error == JVMTI_ERROR_NONE && request->instance != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        saveGlobalRef(env, request->instance, &instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (instance == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            error = AGENT_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    if ( error == JVMTI_ERROR_NONE && argRefs!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        argIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        argumentTag = firstArgumentTypeTag(request->methodSignature, &cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        argument = request->arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        while (argumentTag != SIGNATURE_END_ARGS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if ( argIndex > request->argumentCount ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if ((argumentTag == JDWP_TAG(OBJECT)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                (argumentTag == JDWP_TAG(ARRAY))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                /* Create a global ref for any non-null argument */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                if (argument->l != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    saveGlobalRef(env, argument->l, &argRefs[argIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    if (argRefs[argIndex] == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        error = AGENT_ERROR_OUT_OF_MEMORY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            argument++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            argIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            argumentTag = nextArgumentTypeTag(&cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#ifdef FIXUP /* Why isn't this an error? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /* Make sure the argument count matches */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    if ( error == JVMTI_ERROR_NONE && argIndex != request->argumentCount ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        error = AGENT_ERROR_INVALID_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /* Finally, put the global refs into the request if no errors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        request->clazz = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        request->instance = instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if ( argRefs!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            argIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            argumentTag = firstArgumentTypeTag(request->methodSignature, &cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            argument = request->arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            while ( argIndex < request->argumentCount ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if ((argumentTag == JDWP_TAG(OBJECT)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    (argumentTag == JDWP_TAG(ARRAY))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    argument->l = argRefs[argIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                argument++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                argIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                argumentTag = nextArgumentTypeTag(&cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            jvmtiDeallocate(argRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /* Delete global references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if ( clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            tossGlobalRef(env, &clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if ( instance != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            tossGlobalRef(env, &instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if ( argRefs!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            for ( argIndex=0; argIndex < request->argumentCount; argIndex++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if ( argRefs[argIndex] != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    tossGlobalRef(env, &argRefs[argIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            jvmtiDeallocate(argRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
fillInvokeRequest(JNIEnv *env, InvokeRequest *request,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                  jbyte invokeType, jbyte options, jint id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                  jthread thread, jclass clazz, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                  jobject instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                  jvalue *arguments, jint argumentCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    if (!request->available) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
         * Thread is not at a point where it can invoke.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return AGENT_ERROR_INVALID_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    if (request->pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         * Pending invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return AGENT_ERROR_ALREADY_INVOKING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    request->invokeType = invokeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    request->options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    request->detached = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    request->id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    request->clazz = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    request->method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    request->instance = instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    request->arguments = arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    request->arguments = arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    request->argumentCount = argumentCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    request->returnValue.j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    request->exception = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Squirrel away the method signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    error = methodSignature(method, NULL, &request->methodSignature,  NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * The given references for class and instance are not guaranteed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * to be around long enough for invocation, so create new ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    error = createGlobalRefs(env, request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        jvmtiDeallocate(request->methodSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    request->pending = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    request->available = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
invoker_enableInvokeRequests(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    InvokeRequest *request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    JDI_ASSERT(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    request = threadControl_getInvokeRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    if (request == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    request->available = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
invoker_requestInvoke(jbyte invokeType, jbyte options, jint id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                      jthread thread, jclass clazz, jmethodID method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                      jobject instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                      jvalue *arguments, jint argumentCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    InvokeRequest *request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    jvmtiError error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    debugMonitorEnter(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    request = threadControl_getInvokeRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    if (request != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        error = fillInvokeRequest(env, request, invokeType, options, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                  thread, clazz, method, instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                  arguments, argumentCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    debugMonitorExit(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (options & JDWP_INVOKE_OPTIONS(SINGLE_THREADED) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            /* true means it is okay to unblock the commandLoop thread */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            (void)threadControl_resumeThread(thread, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            (void)threadControl_resumeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
invokeConstructor(JNIEnv *env, InvokeRequest *request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    jobject object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    object = JNI_FUNC_PTR(env,NewObjectA)(env, request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                     request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                     request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    request->returnValue.l = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    if (object != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        saveGlobalRef(env, object, &(request->returnValue.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
invokeStatic(JNIEnv *env, InvokeRequest *request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    switch(returnTypeTag(request->methodSignature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        case JDWP_TAG(OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        case JDWP_TAG(ARRAY): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            jobject object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            object = JNI_FUNC_PTR(env,CallStaticObjectMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            request->returnValue.l = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (object != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                saveGlobalRef(env, object, &(request->returnValue.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            request->returnValue.b = JNI_FUNC_PTR(env,CallStaticByteMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            request->returnValue.c = JNI_FUNC_PTR(env,CallStaticCharMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            request->returnValue.f = JNI_FUNC_PTR(env,CallStaticFloatMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            request->returnValue.d = JNI_FUNC_PTR(env,CallStaticDoubleMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            request->returnValue.i = JNI_FUNC_PTR(env,CallStaticIntMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            request->returnValue.j = JNI_FUNC_PTR(env,CallStaticLongMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            request->returnValue.s = JNI_FUNC_PTR(env,CallStaticShortMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            request->returnValue.z = JNI_FUNC_PTR(env,CallStaticBooleanMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                                       request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                                       request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                                       request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        case JDWP_TAG(VOID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            JNI_FUNC_PTR(env,CallStaticVoidMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                          request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                          request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                          request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"Invalid method signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
invokeVirtual(JNIEnv *env, InvokeRequest *request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    switch(returnTypeTag(request->methodSignature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        case JDWP_TAG(OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        case JDWP_TAG(ARRAY): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            jobject object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            object = JNI_FUNC_PTR(env,CallObjectMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            request->returnValue.l = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (object != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                saveGlobalRef(env, object, &(request->returnValue.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            request->returnValue.b = JNI_FUNC_PTR(env,CallByteMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            request->returnValue.c = JNI_FUNC_PTR(env,CallCharMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            request->returnValue.f = JNI_FUNC_PTR(env,CallFloatMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            request->returnValue.d = JNI_FUNC_PTR(env,CallDoubleMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            request->returnValue.i = JNI_FUNC_PTR(env,CallIntMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            request->returnValue.j = JNI_FUNC_PTR(env,CallLongMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            request->returnValue.s = JNI_FUNC_PTR(env,CallShortMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            request->returnValue.z = JNI_FUNC_PTR(env,CallBooleanMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        case JDWP_TAG(VOID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            JNI_FUNC_PTR(env,CallVoidMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                    request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                    request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                    request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"Invalid method signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
invokeNonvirtual(JNIEnv *env, InvokeRequest *request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    switch(returnTypeTag(request->methodSignature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        case JDWP_TAG(OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        case JDWP_TAG(ARRAY): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            jobject object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            object = JNI_FUNC_PTR(env,CallNonvirtualObjectMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                           request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                           request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                           request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                           request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            request->returnValue.l = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (object != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                saveGlobalRef(env, object, &(request->returnValue.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            request->returnValue.b = JNI_FUNC_PTR(env,CallNonvirtualByteMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            request->returnValue.c = JNI_FUNC_PTR(env,CallNonvirtualCharMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            request->returnValue.f = JNI_FUNC_PTR(env,CallNonvirtualFloatMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            request->returnValue.d = JNI_FUNC_PTR(env,CallNonvirtualDoubleMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            request->returnValue.i = JNI_FUNC_PTR(env,CallNonvirtualIntMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            request->returnValue.j = JNI_FUNC_PTR(env,CallNonvirtualLongMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            request->returnValue.s = JNI_FUNC_PTR(env,CallNonvirtualShortMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            request->returnValue.z = JNI_FUNC_PTR(env,CallNonvirtualBooleanMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                                 request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                                 request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                                 request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                                 request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        case JDWP_TAG(VOID):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            JNI_FUNC_PTR(env,CallNonvirtualVoidMethodA)(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                    request->instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                    request->clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                    request->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                    request->arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            EXIT_ERROR(AGENT_ERROR_NULL_POINTER,"Invalid method signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
invoker_doInvoke(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    jboolean startNow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    InvokeRequest *request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    JDI_ASSERT(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    debugMonitorEnter(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    request = threadControl_getInvokeRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    if (request == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    request->available = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    startNow = request->pending && !request->started;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    if (startNow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        request->started = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    debugMonitorExit(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    if (!startNow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    WITH_LOCAL_REFS(env, 2) {  /* 1 for obj return values, 1 for exception */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        jobject exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        switch (request->invokeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            case INVOKE_CONSTRUCTOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                invokeConstructor(env, request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            case INVOKE_STATIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                invokeStatic(env, request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            case INVOKE_INSTANCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                if (request->options & JDWP_INVOKE_OPTIONS(NONVIRTUAL) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    invokeNonvirtual(env, request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    invokeVirtual(env, request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                JDI_ASSERT(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        request->exception = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        exception = JNI_FUNC_PTR(env,ExceptionOccurred)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        if (exception != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            saveGlobalRef(env, exception, &(request->exception));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
invoker_completeInvokeRequest(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    PacketOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    jbyte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    jobject exc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    jvalue returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    jint id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    InvokeRequest *request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    jboolean detached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    JDI_ASSERT(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /* Prevent gcc errors on uninitialized variables. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    tag = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    exc = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    id  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    eventHandler_lock(); /* for proper lock order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    debugMonitorEnter(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    request = threadControl_getInvokeRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    if (request == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    JDI_ASSERT(request->pending);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    JDI_ASSERT(request->started);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    request->pending = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    request->started = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    request->available = JNI_TRUE; /* For next time around */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    detached = request->detached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    if (!detached) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        if (request->options & JDWP_INVOKE_OPTIONS(SINGLE_THREADED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            (void)threadControl_suspendThread(thread, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            (void)threadControl_suspendAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if (request->invokeType == INVOKE_CONSTRUCTOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
             * Although constructors technically have a return type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
             * void, we return the object created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            tag = specificTypeKey(env, request->returnValue.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            tag = returnTypeTag(request->methodSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        id = request->id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        exc = request->exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        returnValue = request->returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Give up the lock before I/O operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    debugMonitorExit(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    eventHandler_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    if (!detached) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        outStream_initReply(&out, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        (void)outStream_writeValue(env, &out, tag, returnValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        (void)outStream_writeObjectTag(env, &out, exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        (void)outStream_writeObjectRef(env, &out, exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        outStream_sendReply(&out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
invoker_isPending(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    InvokeRequest *request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    JDI_ASSERT(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    request = threadControl_getInvokeRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    if (request == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    return request->pending;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
invoker_isEnabled(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    InvokeRequest *request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    JDI_ASSERT(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    request = threadControl_getInvokeRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    if (request == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    return request->available;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
invoker_detach(InvokeRequest *request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    JDI_ASSERT(request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    debugMonitorEnter(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    request->detached = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    debugMonitorExit(invokerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
}