jdk/src/share/back/ArrayReferenceImpl.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-2005 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 "ArrayReferenceImpl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
length(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    jsize arrayLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    jarray  array = inStream_readArrayRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    arrayLength = JNI_FUNC_PTR(env,GetArrayLength)(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    (void)outStream_writeInt(out, arrayLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
static void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
newComponents(PacketOutputStream *out, jint length, size_t nbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    void *ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    if ( length > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        ptr = jvmtiAllocate(length*((jint)nbytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        if ( ptr == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            (void)memset(ptr, 0, length*nbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    return ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
deleteComponents(void *ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    jvmtiDeallocate(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
writeBooleanComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    jboolean *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    components = newComponents(out, length, sizeof(jboolean));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        JNI_FUNC_PTR(env,GetBooleanArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            (void)outStream_writeBoolean(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
writeByteComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    jbyte *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    components = newComponents(out, length, sizeof(jbyte));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        JNI_FUNC_PTR(env,GetByteArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            (void)outStream_writeByte(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
writeCharComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    jchar *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    components = newComponents(out, length, sizeof(jchar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        JNI_FUNC_PTR(env,GetCharArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            (void)outStream_writeChar(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
writeShortComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    jshort *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    components = newComponents(out, length, sizeof(jshort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        JNI_FUNC_PTR(env,GetShortArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            (void)outStream_writeShort(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
writeIntComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    jint *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    components = newComponents(out, length, sizeof(jint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        JNI_FUNC_PTR(env,GetIntArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            (void)outStream_writeInt(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
writeLongComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    jlong *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    components = newComponents(out, length, sizeof(jlong));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        JNI_FUNC_PTR(env,GetLongArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            (void)outStream_writeLong(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
writeFloatComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    jfloat *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    components = newComponents(out, length, sizeof(jfloat));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        JNI_FUNC_PTR(env,GetFloatArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            (void)outStream_writeFloat(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
writeDoubleComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    jdouble *components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    components = newComponents(out, length, sizeof(jdouble));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    if (components != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        JNI_FUNC_PTR(env,GetDoubleArrayRegion)(env, array, index, length, components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            (void)outStream_writeDouble(out, components[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        deleteComponents(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
writeObjectComponents(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    jarray array, jint index, jint length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    WITH_LOCAL_REFS(env, length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        jobject component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            component = JNI_FUNC_PTR(env,GetObjectArrayElement)(env, array, index + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                /* cleared by caller */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            (void)outStream_writeByte(out, specificTypeKey(env, component));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            (void)outStream_writeObjectRef(env, out, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
getValues(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    jint arrayLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    jarray array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    jint index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    jint length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    array = inStream_readArrayRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    index = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    length = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    arrayLength = JNI_FUNC_PTR(env,GetArrayLength)(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    if (length == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        length = arrayLength - index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    if ((index < 0) || (index > arrayLength - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        outStream_setError(out, JDWP_ERROR(INVALID_INDEX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if ((length < 0) || (length + index > arrayLength)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        outStream_setError(out, JDWP_ERROR(INVALID_LENGTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        jclass arrayClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        char *componentSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        jbyte typeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        arrayClass = JNI_FUNC_PTR(env,GetObjectClass)(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        error = classSignature(arrayClass, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        componentSignature = &signature[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        typeKey = componentSignature[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        (void)outStream_writeByte(out, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        (void)outStream_writeInt(out, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (isObjectTag(typeKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            writeObjectComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    writeByteComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    writeCharComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    writeFloatComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    writeDoubleComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    writeIntComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    writeLongComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    writeShortComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    writeBooleanComponents(env, out, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    outStream_setError(out, JDWP_ERROR(INVALID_TAG));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    err:;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        outStream_setError(out, JDWP_ERROR(INTERNAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
readBooleanComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    jboolean component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        component = inStream_readBoolean(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        JNI_FUNC_PTR(env,SetBooleanArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
readByteComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    jbyte component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        component = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        JNI_FUNC_PTR(env,SetByteArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
readCharComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    jchar component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        component = inStream_readChar(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        JNI_FUNC_PTR(env,SetCharArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
readShortComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    jshort component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        component = inStream_readShort(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        JNI_FUNC_PTR(env,SetShortArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
readIntComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    jint component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        component = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        JNI_FUNC_PTR(env,SetIntArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
readLongComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    jlong component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        component = inStream_readLong(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        JNI_FUNC_PTR(env,SetLongArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
readFloatComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    jfloat component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        component = inStream_readFloat(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        JNI_FUNC_PTR(env,SetFloatArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
readDoubleComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    jdouble component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    for (i = 0; (i < length) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        component = inStream_readDouble(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        JNI_FUNC_PTR(env,SetDoubleArrayRegion)(env, array, index + i, 1, &component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    return inStream_error(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
readObjectComponents(JNIEnv *env, PacketInputStream *in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                   jarray array, int index, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                   /* char *componentSignature) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        jobject object = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        JNI_FUNC_PTR(env,SetObjectArrayElement)(env, array, index + i, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            /* caller will clear */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
setValues(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    JNIEnv *env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    jdwpError serror = JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    int arrayLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    jarray array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    jint index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    jint length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    array = inStream_readArrayRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    index = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    length = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    arrayLength = JNI_FUNC_PTR(env,GetArrayLength)(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    if ((index < 0) || (index > arrayLength - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        outStream_setError(out, JDWP_ERROR(INVALID_INDEX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    if ((length < 0) || (length + index > arrayLength)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        outStream_setError(out, JDWP_ERROR(INVALID_LENGTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    WITH_LOCAL_REFS(env, 1)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        jclass arrayClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        char *componentSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        arrayClass = JNI_FUNC_PTR(env,GetObjectClass)(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        error = classSignature(arrayClass, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        componentSignature = &signature[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        switch (componentSignature[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            case JDWP_TAG(OBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            case JDWP_TAG(ARRAY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                serror = readObjectComponents(env, in, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                serror = readByteComponents(env, in, array, index, length);
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
                serror = readCharComponents(env, in, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                serror = readFloatComponents(env, in, array, index, length);
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(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                serror = readDoubleComponents(env, in, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                serror = readIntComponents(env, in, array, index, length);
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(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                serror = readLongComponents(env, in, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                serror = readShortComponents(env, in, array, index, length);
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(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                serror = readBooleanComponents(env, in, array, index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    ERROR_MESSAGE(("Invalid array component signature: %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                        componentSignature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    EXIT_ERROR(AGENT_ERROR_INVALID_OBJECT,NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    err:;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * TO DO: Check exception type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        serror = JDWP_ERROR(TYPE_MISMATCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
void *ArrayReference_Cmds[] = { (void *)0x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    ,(void *)length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    ,(void *)getValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    ,(void *)setValues};