jdk/src/share/back/outStream.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 "stream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "transport.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "commonRef.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "bag.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "FrameID.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define INITIAL_ID_ALLOC  50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define SMALLEST(a, b) ((a) < (b)) ? (a) : (b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
commonInit(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    stream->current = &stream->initialSegment[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    stream->left = sizeof(stream->initialSegment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    stream->segment = &stream->firstSegment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    stream->segment->length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    stream->segment->data = &stream->initialSegment[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    stream->segment->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    stream->error = JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    stream->sent = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    stream->ids = bagCreateBag(sizeof(jlong), INITIAL_ID_ALLOC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    if (stream->ids == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        stream->error = JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
outStream_initCommand(PacketOutputStream *stream, jint id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                      jbyte flags, jbyte commandSet, jbyte command)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    commonInit(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Command-specific initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    stream->packet.type.cmd.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    stream->packet.type.cmd.cmdSet = commandSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    stream->packet.type.cmd.cmd = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    stream->packet.type.cmd.flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
outStream_initReply(PacketOutputStream *stream, jint id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    commonInit(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Reply-specific initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    stream->packet.type.reply.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    stream->packet.type.reply.errorCode = 0x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    stream->packet.type.cmd.flags = (jbyte)JDWPTRANSPORT_FLAGS_REPLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
outStream_id(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    return stream->packet.type.cmd.id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
jbyte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
outStream_command(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /* Only makes sense for commands */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    JDI_ASSERT(!(stream->packet.type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    return stream->packet.type.cmd.cmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
writeBytes(PacketOutputStream *stream, void *source, int size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jbyte *bytes = (jbyte *)source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    if (stream->error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    while (size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (stream->left == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            jint segSize = SMALLEST(2 * stream->segment->length, MAX_SEGMENT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            jbyte *newSeg = jvmtiAllocate(segSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            struct PacketData *newHeader = jvmtiAllocate(sizeof(*newHeader));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if ((newSeg == NULL) || (newHeader == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                jvmtiDeallocate(newSeg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                jvmtiDeallocate(newHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                stream->error = JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            newHeader->length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            newHeader->data = newSeg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            newHeader->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            stream->segment->next = newHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            stream->segment = newHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            stream->current = newHeader->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            stream->left = segSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        count = SMALLEST(size, stream->left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        (void)memcpy(stream->current, bytes, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        stream->current += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        stream->left -= count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        stream->segment->length += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        size -= count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        bytes += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
outStream_writeBoolean(PacketOutputStream *stream, jboolean val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    jbyte byte = (val != 0) ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return writeBytes(stream, &byte, sizeof(byte));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
outStream_writeByte(PacketOutputStream *stream, jbyte val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
outStream_writeChar(PacketOutputStream *stream, jchar val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    val = HOST_TO_JAVA_CHAR(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
outStream_writeShort(PacketOutputStream *stream, jshort val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    val = HOST_TO_JAVA_SHORT(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
outStream_writeInt(PacketOutputStream *stream, jint val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    val = HOST_TO_JAVA_INT(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
outStream_writeLong(PacketOutputStream *stream, jlong val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    val = HOST_TO_JAVA_LONG(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
outStream_writeFloat(PacketOutputStream *stream, jfloat val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    val = HOST_TO_JAVA_FLOAT(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
outStream_writeDouble(PacketOutputStream *stream, jdouble val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    val = HOST_TO_JAVA_DOUBLE(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    return writeBytes(stream, &val, sizeof(val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
outStream_writeObjectTag(JNIEnv *env, PacketOutputStream *stream, jobject val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    return outStream_writeByte(stream, specificTypeKey(env, val));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
outStream_writeObjectRef(JNIEnv *env, PacketOutputStream *stream, jobject val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    jlong id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    jlong *idPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    if (stream->error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (val == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        id = NULL_OBJECT_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        /* Convert the object to an object id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        id = commonRef_refToID(env, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (id == NULL_OBJECT_ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            stream->error = JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        /* Track the common ref in case we need to release it on a future error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        idPtr = bagAdd(stream->ids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (idPtr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            commonRef_release(env, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            stream->error = JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            *idPtr = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        /* Add the encoded object id to the stream */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        id = HOST_TO_JAVA_LONG(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    return writeBytes(stream, &id, sizeof(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
outStream_writeFrameID(PacketOutputStream *stream, FrameID val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Not good - we're writing a pointer as a jint.  Need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * to write as a jlong if sizeof(FrameID) == 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (sizeof(FrameID) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return outStream_writeLong(stream, (jlong)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return outStream_writeInt(stream, (jint)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
outStream_writeMethodID(PacketOutputStream *stream, jmethodID val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Not good - we're writing a pointer as a jint.  Need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * to write as a jlong if sizeof(jmethodID) == 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if (sizeof(jmethodID) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return outStream_writeLong(stream, (jlong)(intptr_t)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return outStream_writeInt(stream, (jint)(intptr_t)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
outStream_writeFieldID(PacketOutputStream *stream, jfieldID val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Not good - we're writing a pointer as a jint.  Need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * to write as a jlong if sizeof(jfieldID) == 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    if (sizeof(jfieldID) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return outStream_writeLong(stream, (jlong)(intptr_t)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return outStream_writeInt(stream, (jint)(intptr_t)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
outStream_writeLocation(PacketOutputStream *stream, jlocation val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    return outStream_writeLong(stream, (jlong)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
outStream_writeByteArray(PacketOutputStream*stream, jint length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                         jbyte *bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    (void)outStream_writeInt(stream, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    return writeBytes(stream, bytes, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
outStream_writeString(PacketOutputStream *stream, char *string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    jdwpError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    jint      length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /* Options utf8=y/n controls if we want Standard UTF-8 or Modified */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if ( gdata->modifiedUtf8 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        length = (int)strlen(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        (void)outStream_writeInt(stream, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        error = writeBytes(stream, (jbyte *)string, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        jint      new_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        length = (int)strlen(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        new_length = (gdata->npt->utf8mToUtf8sLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            (gdata->npt->utf, (jbyte*)string, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if ( new_length == length ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            (void)outStream_writeInt(stream, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            error = writeBytes(stream, (jbyte *)string, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            char *new_string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            new_string = jvmtiAllocate(new_length+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            (gdata->npt->utf8mToUtf8s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            (gdata->npt->utf, (jbyte*)string, length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                             (jbyte*)new_string, new_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            (void)outStream_writeInt(stream, new_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            error = writeBytes(stream, (jbyte *)new_string, new_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            jvmtiDeallocate(new_string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
outStream_writeValue(JNIEnv *env, PacketOutputStream *out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                     jbyte typeKey, jvalue value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    if (typeKey == JDWP_TAG(OBJECT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        (void)outStream_writeByte(out, specificTypeKey(env, value.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        (void)outStream_writeByte(out, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if (isObjectTag(typeKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        (void)outStream_writeObjectRef(env, out, value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                return outStream_writeByte(out, value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                return outStream_writeChar(out, value.c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                return outStream_writeFloat(out, value.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                return outStream_writeDouble(out, value.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                return outStream_writeInt(out, value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                return outStream_writeLong(out, value.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                return outStream_writeShort(out, value.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                return outStream_writeBoolean(out, value.z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            case JDWP_TAG(VOID):  /* happens with function return values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                /* write nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                EXIT_ERROR(AGENT_ERROR_INVALID_OBJECT,"Invalid type key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
outStream_skipBytes(PacketOutputStream *stream, jint count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        (void)outStream_writeByte(stream, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
outStream_error(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    return stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
outStream_setError(PacketOutputStream *stream, jdwpError error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    if (stream->error == JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        stream->error = error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        LOG_MISC(("outStream_setError error=%s(%d)", jdwpErrorText(error), error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
outStream_send(PacketOutputStream *stream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    jint rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    jint len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    PacketData *segment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    jbyte *data, *posP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * If there's only 1 segment then we just send the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * packet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    if (stream->firstSegment.next == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        stream->packet.type.cmd.len = 11 + stream->firstSegment.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        stream->packet.type.cmd.data = stream->firstSegment.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        rc = transport_sendPacket(&stream->packet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Multiple segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    segment = (PacketData *)&(stream->firstSegment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        len += segment->length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        segment = segment->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    } while (segment != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    data = jvmtiAllocate(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    if (data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    posP = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    segment = (PacketData *)&(stream->firstSegment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    while (segment != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        (void)memcpy(posP, segment->data, segment->length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        posP += segment->length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        segment = segment->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    stream->packet.type.cmd.len = 11 + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    stream->packet.type.cmd.data = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    rc = transport_sendPacket(&stream->packet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    stream->packet.type.cmd.data = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    jvmtiDeallocate(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
outStream_sendReply(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    jint rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    if (stream->error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
         * Don't send any collected stream data on an error reply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        stream->packet.type.reply.len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        stream->packet.type.reply.errorCode = (jshort)stream->error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    rc = outStream_send(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    if (rc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        stream->sent = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
outStream_sendCommand(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    jint rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    if (!stream->error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        rc = outStream_send(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (rc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            stream->sent = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
releaseID(void *elementPtr, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    jlong *idPtr = elementPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    commonRef_release(getEnv(), *idPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
outStream_destroy(PacketOutputStream *stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    struct PacketData *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    if (stream->error || !stream->sent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        (void)bagEnumerateOver(stream->ids, releaseID, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    next = stream->firstSegment.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    while (next != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        struct PacketData *p = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        next = p->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        jvmtiDeallocate(p->data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        jvmtiDeallocate(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    bagDestroyBag(stream->ids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
}