jdk/src/share/back/VirtualMachineImpl.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 24125 b85eeaae56c7
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "VirtualMachineImpl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "commonRef.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "eventHelper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "SDE.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "FrameID.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
static char *versionName = "Java Debug Wire Protocol (Reference Implementation)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static int majorVersion = 1;  /* JDWP major version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
static int minorVersion = 6;  /* JDWP minor version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
version(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    char buf[500];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    char *vmName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    char *vmVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    char *vmInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    vmVersion = gdata->property_java_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    if (vmVersion == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        vmVersion = "<unknown>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    vmName = gdata->property_java_vm_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    if (vmName == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        vmName = "<unknown>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    vmInfo = gdata->property_java_vm_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if (vmInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        vmInfo = "<unknown>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Write the descriptive version information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    (void)snprintf(buf, sizeof(buf),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                "%s version %d.%d\nJVM Debug Interface version %d.%d\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                 "JVM version %s (%s, %s)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                  versionName, majorVersion, minorVersion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                  jvmtiMajorVersion(), jvmtiMinorVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                  vmVersion, vmName, vmInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    (void)outStream_writeString(out, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Write the JDWP version numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    (void)outStream_writeInt(out, majorVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    (void)outStream_writeInt(out, minorVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Write the VM version and name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    (void)outStream_writeString(out, vmVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    (void)outStream_writeString(out, vmName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
classesForSignature(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    char *signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    signature = inStream_readString(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    if (signature == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        jint classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        jclass *theClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        error = allLoadedClasses(&theClasses, &classCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            /* Count classes in theClasses which match signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            int matchCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            /* Count classes written to the JDWP connection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            int writtenCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            for (i=0; i<classCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                jclass clazz = theClasses[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                jint status = classStatus(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                char *candidate_signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                jint wanted =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                     JVMTI_CLASS_STATUS_PRIMITIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                /* We want prepared classes, primitives, and arrays only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                if ((status & wanted) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                error = classSignature(clazz, &candidate_signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                if (strcmp(candidate_signature, signature) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    /* Float interesting classes (those that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                     * are matching and are prepared) to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                     * beginning of the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    theClasses[i] = theClasses[matchCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    theClasses[matchCount++] = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                jvmtiDeallocate(candidate_signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            /* At this point matching prepared classes occupy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
             * indicies 0 thru matchCount-1 of theClasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if ( error ==  JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                (void)outStream_writeInt(out, matchCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                for (; writtenCount < matchCount; writtenCount++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    jclass clazz = theClasses[writtenCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    jint status = classStatus(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    jbyte tag = referenceTypeTag(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    (void)outStream_writeByte(out, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    (void)outStream_writeObjectRef(env, out, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    (void)outStream_writeInt(out, map2jdwpClassStatus(status));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    /* No point in continuing if there's an error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    if (outStream_error(out)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            jvmtiDeallocate(theClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
allClasses1(PacketInputStream *in, PacketOutputStream *out, int outputGenerics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        jint classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        jclass *theClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        error = allLoadedClasses(&theClasses, &classCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            /* Count classes in theClasses which are prepared */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            int prepCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            /* Count classes written to the JDWP connection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            int writtenCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            for (i=0; i<classCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                jclass clazz = theClasses[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                jint status = classStatus(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                jint wanted =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                /* We want prepared classes and arrays only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                if ((status & wanted) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    /* Float interesting classes (those that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                     * are prepared) to the beginning of the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    theClasses[i] = theClasses[prepCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    theClasses[prepCount++] = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            /* At this point prepared classes occupy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
             * indicies 0 thru prepCount-1 of theClasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            (void)outStream_writeInt(out, prepCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            for (; writtenCount < prepCount; writtenCount++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                char *genericSignature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                jclass clazz = theClasses[writtenCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                jint status = classStatus(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                jbyte tag = referenceTypeTag(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                error = classSignature(clazz, &signature, &genericSignature);
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
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                (void)outStream_writeByte(out, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                (void)outStream_writeObjectRef(env, out, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                (void)outStream_writeString(out, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                if (outputGenerics == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    writeGenericSignature(out, genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                (void)outStream_writeInt(out, map2jdwpClassStatus(status));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                if (genericSignature != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                  jvmtiDeallocate(genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                /* No point in continuing if there's an error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                if (outStream_error(out)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            jvmtiDeallocate(theClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
allClasses(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    return allClasses1(in, out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
allClassesWithGeneric(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    return allClasses1(in, out, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
  /***********************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
instanceCounts(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    jint classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    jclass *classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    int ii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    classCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    if (classCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        (void)outStream_writeInt(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    if (classCount < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        outStream_setError(out, JDWP_ERROR(ILLEGAL_ARGUMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    classes = jvmtiAllocate(classCount * (int)sizeof(jclass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    for (ii = 0; ii < classCount; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        jdwpError errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        classes[ii] = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        errorCode = inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (errorCode != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
             * A class could have been unloaded/gc'd so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
             * if we get an error, just ignore it and keep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
             * going.  An instanceCount of 0 will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (errorCode == JDWP_ERROR(INVALID_OBJECT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                errorCode == JDWP_ERROR(INVALID_CLASS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                inStream_clearError(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                classes[ii] = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            jvmtiDeallocate(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        jlong      *counts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        counts = jvmtiAllocate(classCount * (int)sizeof(jlong));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        /* Iterate over heap getting info on these classes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        error = classInstanceCounts(classCount, classes, counts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            (void)outStream_writeInt(out, classCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            for (ii = 0; ii < classCount; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                (void)outStream_writeLong(out, counts[ii]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        jvmtiDeallocate(counts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    jvmtiDeallocate(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
redefineClasses(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    jvmtiClassDefinition *classDefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    jboolean ok = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    jint classCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        /* quietly ignore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    classCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    if ( classCount == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    classDefs = jvmtiAllocate(classCount*(int)sizeof(jvmtiClassDefinition));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    if (classDefs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    (void)memset(classDefs, 0, classCount*sizeof(jvmtiClassDefinition));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    for (i = 0; i < classCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        int byteCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        unsigned char * bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            ok = JNI_FALSE;
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
        byteCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            ok = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if ( byteCount <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            outStream_setError(out, JDWP_ERROR(INVALID_CLASS_FORMAT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            ok = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        bytes = (unsigned char *)jvmtiAllocate(byteCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (bytes == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            ok = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        (void)inStream_readBytes(in, byteCount, (jbyte *)bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            ok = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        classDefs[i].klass = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        classDefs[i].class_byte_count = byteCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        classDefs[i].class_bytes = bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    if (ok == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        error = JVMTI_FUNC_PTR(gdata->jvmti,RedefineClasses)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        (gdata->jvmti, classCount, classDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            /* zap our BP info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            for ( i = 0 ; i < classCount; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                eventHandler_freeClassBreakpoints(classDefs[i].klass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /* free up allocated memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    for ( i = 0 ; i < classCount; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if ( classDefs[i].class_bytes != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            jvmtiDeallocate((void*)classDefs[i].class_bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    jvmtiDeallocate(classDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
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
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
setDefaultStratum(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    char *stratumId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        /* quietly ignore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    stratumId = inStream_readString(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    } else if (strcmp(stratumId, "") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        stratumId = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    setGlobalStratumId(stratumId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
getAllThreads(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        jint threadCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        jthread *theThreads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        theThreads = allThreads(&threadCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (theThreads == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            /* Squish out all of the debugger-spawned threads */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            threadCount = filterDebugThreads(theThreads, threadCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            (void)outStream_writeInt(out, threadCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            for (i = 0; i <threadCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                (void)outStream_writeObjectRef(env, out, theThreads[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            jvmtiDeallocate(theThreads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
topLevelThreadGroups(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        jint groupCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        jthreadGroup *groups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        groups = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetTopThreadGroups)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    (gdata->jvmti, &groupCount, &groups);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            (void)outStream_writeInt(out, groupCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            for (i = 0; i < groupCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                (void)outStream_writeObjectRef(env, out, groups[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            jvmtiDeallocate(groups);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
dispose(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
idSizes(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    (void)outStream_writeInt(out, sizeof(jfieldID));    /* fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    (void)outStream_writeInt(out, sizeof(jmethodID));   /* methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    (void)outStream_writeInt(out, sizeof(jlong));       /* objects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    (void)outStream_writeInt(out, sizeof(jlong));       /* referent types */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    (void)outStream_writeInt(out, sizeof(FrameID));    /* frames */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
suspend(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    error = threadControl_suspendAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
resume(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    error = threadControl_resumeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
doExit(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    jint exitCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    exitCode = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        /* quietly ignore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /* We send the reply from here because we are about to exit. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        outStream_setError(out, inStream_error(in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    outStream_sendReply(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    forceExit(exitCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /* Shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    JDI_ASSERT(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /* Shut up the compiler */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
createString(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    char *cstring;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    cstring = inStream_readString(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    if (cstring == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        jstring string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        string = JNI_FUNC_PTR(env,NewStringUTF)(env, cstring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            (void)outStream_writeObjectRef(env, out, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    jvmtiDeallocate(cstring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
capabilities(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    jvmtiCapabilities caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    error = jvmtiGetCapabilities(&caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_modification_events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_access_events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_bytecodes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_synthetic_attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_owned_monitor_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_current_contended_monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_monitor_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
capabilitiesNew(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    jvmtiCapabilities caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        outStream_setError(out, JDWP_ERROR(VM_DEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    error = jvmtiGetCapabilities(&caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_modification_events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_access_events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_bytecodes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_synthetic_attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_owned_monitor_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_current_contended_monitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_monitor_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /* new since JDWP version 1.4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    (void)outStream_writeBoolean(out, (jboolean)caps.can_redefine_classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE /* can_add_method */ );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE /* can_unrestrictedly_redefine_classes */ );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    /* 11: canPopFrames */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    (void)outStream_writeBoolean(out, (jboolean)caps.can_pop_frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /* 12: canUseInstanceFilters */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    (void)outStream_writeBoolean(out, (jboolean)JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /* 13: canGetSourceDebugExtension */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_source_debug_extension);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /* 14: canRequestVMDeathEvent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    (void)outStream_writeBoolean(out, (jboolean)JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /* 15: canSetDefaultStratum */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    (void)outStream_writeBoolean(out, (jboolean)JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /* 16: canGetInstanceInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    (void)outStream_writeBoolean(out, (jboolean)caps.can_tag_objects);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    /* 17: canRequestMonitorEvents */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_monitor_events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /* 18: canGetMonitorFrameInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_owned_monitor_stack_depth_info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /* remaining reserved */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 19 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /* 20 Can get constant pool information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    (void)outStream_writeBoolean(out, (jboolean)caps.can_get_constant_pool);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /* 21 Can force early return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    (void)outStream_writeBoolean(out, (jboolean)caps.can_force_early_return);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 22 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 23 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 24 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 25 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 26 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 27 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 28 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 29 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 30 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 31 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 32 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
countPaths(char *string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    int cnt = 1; /* always have one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    char *pos = string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    char *ps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    ps = gdata->property_path_separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    if ( ps == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        ps = ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    while ((pos = strchr(pos, ps[0])) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        ++cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        ++pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    return cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
writePaths(PacketOutputStream *out, char *string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    char *pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    char *ps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    char *buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    int   npaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    int   i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    buf = jvmtiAllocate((int)strlen(string)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    npaths = countPaths(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    (void)outStream_writeInt(out, npaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    ps = gdata->property_path_separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    if ( ps == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        ps = ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    pos = string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    for ( i = 0 ; i < npaths ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        char *psPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        int   plen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        psPos = strchr(pos, ps[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if ( psPos == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            plen = (int)strlen(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            plen = (int)(psPos-pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            psPos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        (void)memcpy(buf, pos, plen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        buf[plen] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        (void)outStream_writeString(out, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        pos = psPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    jvmtiDeallocate(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
classPaths(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    char *ud;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    char *bp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    char *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    ud = gdata->property_user_dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    if ( ud == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        ud = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    cp = gdata->property_java_class_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    if ( cp == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        cp = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    bp = gdata->property_sun_boot_class_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    if ( bp == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        bp = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    (void)outStream_writeString(out, ud);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    writePaths(out, cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    writePaths(out, bp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
disposeObjects(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    int refCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    jlong id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    int requestCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    if (gdata->vmDead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        /* quietly ignore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    requestCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    for (i = 0; i < requestCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        id = inStream_readObjectID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        refCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        commonRef_releaseMultiple(env, id, refCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
holdEvents(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    eventHelper_holdEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
releaseEvents(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    eventHelper_releaseEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
void *VirtualMachine_Cmds[] = { (void *)21
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    ,(void *)version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    ,(void *)classesForSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    ,(void *)allClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    ,(void *)getAllThreads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    ,(void *)topLevelThreadGroups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    ,(void *)dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    ,(void *)idSizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    ,(void *)suspend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    ,(void *)resume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    ,(void *)doExit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    ,(void *)createString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    ,(void *)capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    ,(void *)classPaths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    ,(void *)disposeObjects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    ,(void *)holdEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    ,(void *)releaseEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    ,(void *)capabilitiesNew
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    ,(void *)redefineClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    ,(void *)setDefaultStratum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    ,(void *)allClassesWithGeneric
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    ,(void *)instanceCounts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
};