Cross Reference: inStream.c
xref
: /
openjdk7
/
jdk
/
src
/
share
/
back
/
inStream.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
0
N/A
/*
2362
N/A
* Copyright (c) 1998, 2008, Oracle
and
/
or
its affiliates. All rights reserved.
0
N/A
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0
N/A
*
0
N/A
* This code is free software; you can redistribute it
and
/
or
modify it
0
N/A
* under the terms of the GNU General Public License version 2 only, as
2362
N/A
* published by the Free Software Foundation. Oracle designates this
0
N/A
* particular file as subject to the "Classpath" exception as provided
2362
N/A
* by Oracle in the LICENSE file that accompanied this code.
0
N/A
*
0
N/A
* This code is distributed in the hope that it will be useful, but WITHOUT
0
N/A
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0
N/A
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0
N/A
* version 2 for more details (a copy is included in the LICENSE file that
0
N/A
* accompanied this code).
0
N/A
*
0
N/A
* You should have received a copy of the GNU General Public License version
0
N/A
* 2 along with this work; if not, write to the Free Software Foundation,
0
N/A
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0
N/A
*
2362
N/A
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362
N/A
* or visit
www.oracle.c
om if you need additional information or have any
2362
N/A
* questions.
0
N/A
*/
0
N/A
0
N/A
#
include
"
util.h
"
0
N/A
#
include
"
stream.h
"
0
N/A
#
include
"
inStream.h
"
0
N/A
#
include
"
transport.h
"
0
N/A
#
include
"
bag.h
"
0
N/A
#
include
"
commonRef.h
"
0
N/A
#
include
"
FrameID.h
"
0
N/A
0
N/A
#
define
INITIAL_REF_ALLOC
50
0
N/A
#
define
SMALLEST
(a, b) ((a) < (b)) ? (a) : (b)
0
N/A
0
N/A
/*
0
N/A
* TO DO: Support processing of replies through command input streams.
0
N/A
*/
0
N/A
void
0
N/A
inStream_init
(
PacketInputStream
*
stream
,
jdwpPacket
packet
)
0
N/A
{
0
N/A
stream
->
packet
=
packet
;
0
N/A
stream
->
error
=
JDWP_ERROR
(
NONE
);
0
N/A
stream
->
left
=
packet
.
type
.
cmd
.
len
;
0
N/A
stream
->
current
=
packet
.
type
.
cmd
.
data
;
0
N/A
stream
->
refs
=
bagCreateBag
(
sizeof
(
jobject
),
INITIAL_REF_ALLOC
);
0
N/A
if
(
stream
->
refs
==
NULL
) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
OUT_OF_MEMORY
);
0
N/A
}
0
N/A
}
0
N/A
0
N/A
jint
0
N/A
inStream_id
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
return
stream
->
packet
.
type
.
cmd
.
id
;
0
N/A
}
0
N/A
0
N/A
jbyte
0
N/A
inStream_command
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
return
stream
->
packet
.
type
.
cmd
.
cmd
;
0
N/A
}
0
N/A
0
N/A
static
jdwpError
0
N/A
readBytes
(
PacketInputStream
*
stream
,
void
*
dest
,
int
size
)
0
N/A
{
0
N/A
if
(
stream
->
error
) {
0
N/A
return
stream
->
error
;
0
N/A
}
0
N/A
0
N/A
if
(
size
>
stream
->
left
) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INTERNAL
);
0
N/A
return
stream
->
error
;
0
N/A
}
0
N/A
0
N/A
if
(
dest
) {
0
N/A
(
void
)
memcpy
(
dest
,
stream
->
current
,
size
);
0
N/A
}
0
N/A
stream
->
current
+=
size
;
0
N/A
stream
->
left
-=
size
;
0
N/A
0
N/A
return
stream
->
error
;
0
N/A
}
0
N/A
0
N/A
jdwpError
0
N/A
inStream_skipBytes
(
PacketInputStream
*
stream
,
jint
size
) {
0
N/A
return
readBytes
(
stream
,
NULL
,
size
);
0
N/A
}
0
N/A
0
N/A
jboolean
0
N/A
inStream_readBoolean
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jbyte
flag
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
flag
,
sizeof
(
flag
));
0
N/A
if
(
stream
->
error
) {
0
N/A
return
0;
0
N/A
}
else
{
0
N/A
return
flag
?
JNI_TRUE
:
JNI_FALSE
;
0
N/A
}
0
N/A
}
0
N/A
0
N/A
jbyte
0
N/A
inStream_readByte
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jbyte
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
val
;
0
N/A
}
0
N/A
0
N/A
jbyte
*
0
N/A
inStream_readBytes
(
PacketInputStream
*
stream
,
int
length
,
jbyte
*
buf
)
0
N/A
{
0
N/A
(
void
)
readBytes
(
stream
,
buf
,
length
);
0
N/A
return
buf
;
0
N/A
}
0
N/A
0
N/A
jchar
0
N/A
inStream_readChar
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jchar
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
JAVA_TO_HOST_CHAR
(
val
);
0
N/A
}
0
N/A
0
N/A
jshort
0
N/A
inStream_readShort
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jshort
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
JAVA_TO_HOST_SHORT
(
val
);
0
N/A
}
0
N/A
0
N/A
jint
0
N/A
inStream_readInt
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jint
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
JAVA_TO_HOST_INT
(
val
);
0
N/A
}
0
N/A
0
N/A
jlong
0
N/A
inStream_readLong
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jlong
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
JAVA_TO_HOST_LONG
(
val
);
0
N/A
}
0
N/A
0
N/A
jfloat
0
N/A
inStream_readFloat
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jfloat
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
JAVA_TO_HOST_FLOAT
(
val
);
0
N/A
}
0
N/A
0
N/A
jdouble
0
N/A
inStream_readDouble
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jdouble
val
= 0;
0
N/A
(
void
)
readBytes
(
stream
, &
val
,
sizeof
(
val
));
0
N/A
return
JAVA_TO_HOST_DOUBLE
(
val
);
0
N/A
}
0
N/A
0
N/A
/*
0
N/A
* Read an object from the stream. The ID used in the wire protocol
0
N/A
* is converted to a reference which is returned. The reference is
0
N/A
* global and strong, but it should *not* be deleted by the caller
0
N/A
* since it is freed when this stream is destroyed.
0
N/A
*/
0
N/A
jobject
0
N/A
inStream_readObjectRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
ref
;
0
N/A
jobject
*
refPtr
;
0
N/A
jlong
id
=
inStream_readLong
(
stream
);
0
N/A
if
(
stream
->
error
) {
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(
id
==
NULL_OBJECT_ID
) {
0
N/A
return
NULL
;
0
N/A
}
0
N/A
0
N/A
ref
=
commonRef_idToRef
(
env
,
id
);
0
N/A
if
(
ref
==
NULL
) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_OBJECT
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
0
N/A
refPtr
=
bagAdd
(
stream
->
refs
);
0
N/A
if
(
refPtr
==
NULL
) {
0
N/A
commonRef_idToRef_delete
(
env
,
ref
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
0
N/A
*
refPtr
=
ref
;
0
N/A
return
ref
;
0
N/A
}
0
N/A
0
N/A
/*
0
N/A
* Read a raw object id from the stream. This should be used rarely.
0
N/A
* Normally, inStream_readObjectRef is preferred since it takes care
0
N/A
* of reference conversion and tracking. Only code that needs to
0
N/A
* perform maintence of the commonRef hash table uses this function.
0
N/A
*/
0
N/A
jlong
0
N/A
inStream_readObjectID
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
return
inStream_readLong
(
stream
);
0
N/A
}
0
N/A
0
N/A
jclass
0
N/A
inStream_readClassRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
object
=
inStream_readObjectRef
(
env
,
stream
);
0
N/A
if
(
object
==
NULL
) {
0
N/A
/*
0
N/A
* Could be error or just the null reference. In either case,
0
N/A
* stop now.
0
N/A
*/
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(!
isClass
(
object
)) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_CLASS
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
return
object
;
0
N/A
}
0
N/A
0
N/A
jthread
0
N/A
inStream_readThreadRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
object
=
inStream_readObjectRef
(
env
,
stream
);
0
N/A
if
(
object
==
NULL
) {
0
N/A
/*
0
N/A
* Could be error or just the null reference. In either case,
0
N/A
* stop now.
0
N/A
*/
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(!
isThread
(
object
)) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_THREAD
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
return
object
;
0
N/A
}
0
N/A
0
N/A
jthreadGroup
0
N/A
inStream_readThreadGroupRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
object
=
inStream_readObjectRef
(
env
,
stream
);
0
N/A
if
(
object
==
NULL
) {
0
N/A
/*
0
N/A
* Could be error or just the null reference. In either case,
0
N/A
* stop now.
0
N/A
*/
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(!
isThreadGroup
(
object
)) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_THREAD_GROUP
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
return
object
;
0
N/A
}
0
N/A
0
N/A
jstring
0
N/A
inStream_readStringRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
object
=
inStream_readObjectRef
(
env
,
stream
);
0
N/A
if
(
object
==
NULL
) {
0
N/A
/*
0
N/A
* Could be error or just the null reference. In either case,
0
N/A
* stop now.
0
N/A
*/
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(!
isString
(
object
)) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_STRING
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
return
object
;
0
N/A
}
0
N/A
0
N/A
jclass
0
N/A
inStream_readClassLoaderRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
object
=
inStream_readObjectRef
(
env
,
stream
);
0
N/A
if
(
object
==
NULL
) {
0
N/A
/*
0
N/A
* Could be error or just the null reference. In either case,
0
N/A
* stop now.
0
N/A
*/
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(!
isClassLoader
(
object
)) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_CLASS_LOADER
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
return
object
;
0
N/A
}
0
N/A
0
N/A
jarray
0
N/A
inStream_readArrayRef
(
JNIEnv
*
env
,
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
jobject
object
=
inStream_readObjectRef
(
env
,
stream
);
0
N/A
if
(
object
==
NULL
) {
0
N/A
/*
0
N/A
* Could be error or just the null reference. In either case,
0
N/A
* stop now.
0
N/A
*/
0
N/A
return
NULL
;
0
N/A
}
0
N/A
if
(!
isArray
(
object
)) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_ARRAY
);
0
N/A
return
NULL
;
0
N/A
}
0
N/A
return
object
;
0
N/A
}
0
N/A
0
N/A
/*
0
N/A
* Next 3 functions read an Int and convert to a Pointer!?
0
N/A
* If sizeof(jxxxID) == 8 we must read these values as Longs.
0
N/A
*/
0
N/A
FrameID
0
N/A
inStream_readFrameID
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
if
(
sizeof
(
FrameID
) ==
8
) {
0
N/A
/*LINTED*/
0
N/A
return
(
FrameID
)
inStream_readLong
(
stream
);
0
N/A
}
else
{
0
N/A
/*LINTED*/
0
N/A
return
(
FrameID
)
inStream_readInt
(
stream
);
0
N/A
}
0
N/A
}
0
N/A
0
N/A
jmethodID
0
N/A
inStream_readMethodID
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
if
(
sizeof
(
jmethodID
) ==
8
) {
0
N/A
/*LINTED*/
0
N/A
return
(
jmethodID
)(
intptr_t
)
inStream_readLong
(
stream
);
0
N/A
}
else
{
0
N/A
/*LINTED*/
0
N/A
return
(
jmethodID
)(
intptr_t
)
inStream_readInt
(
stream
);
0
N/A
}
0
N/A
}
0
N/A
0
N/A
jfieldID
0
N/A
inStream_readFieldID
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
if
(
sizeof
(
jfieldID
) ==
8
) {
0
N/A
/*LINTED*/
0
N/A
return
(
jfieldID
)(
intptr_t
)
inStream_readLong
(
stream
);
0
N/A
}
else
{
0
N/A
/*LINTED*/
0
N/A
return
(
jfieldID
)(
intptr_t
)
inStream_readInt
(
stream
);
0
N/A
}
0
N/A
}
0
N/A
0
N/A
jlocation
0
N/A
inStream_readLocation
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
return
(
jlocation
)
inStream_readLong
(
stream
);
0
N/A
}
0
N/A
0
N/A
char
*
0
N/A
inStream_readString
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
int
length
;
0
N/A
char
*
string
;
0
N/A
0
N/A
length
=
inStream_readInt
(
stream
);
0
N/A
string
=
jvmtiAllocate
(
length
+
1
);
0
N/A
if
(
string
!=
NULL
) {
0
N/A
int
new_length
;
0
N/A
0
N/A
(
void
)
readBytes
(
stream
,
string
,
length
);
0
N/A
string
[
length
] =
'\0'
;
0
N/A
0
N/A
/* This is Standard UTF-8, convert to Modified UTF-8 if necessary */
0
N/A
new_length
= (
gdata
->
npt
->
utf8sToUtf8mLength
)
0
N/A
(
gdata
->
npt
->
utf
, (
jbyte
*)
string
,
length
);
0
N/A
if
(
new_length
!=
length
) {
0
N/A
char
*
new_string
;
0
N/A
0
N/A
new_string
=
jvmtiAllocate
(
new_length
+
1
);
0
N/A
(
gdata
->
npt
->
utf8sToUtf8m
)
0
N/A
(
gdata
->
npt
->
utf
, (
jbyte
*)
string
,
length
,
0
N/A
(
jbyte
*)
new_string
,
new_length
);
0
N/A
jvmtiDeallocate
(
string
);
0
N/A
return
new_string
;
0
N/A
}
0
N/A
}
0
N/A
return
string
;
0
N/A
}
0
N/A
0
N/A
jboolean
0
N/A
inStream_endOfInput
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
return
(
stream
->
left
> 0);
0
N/A
}
0
N/A
0
N/A
jdwpError
0
N/A
inStream_error
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
return
stream
->
error
;
0
N/A
}
0
N/A
0
N/A
void
0
N/A
inStream_clearError
(
PacketInputStream
*
stream
) {
0
N/A
stream
->
error
=
JDWP_ERROR
(
NONE
);
0
N/A
}
0
N/A
0
N/A
jvalue
0
N/A
inStream_readValue
(
PacketInputStream
*
stream
,
jbyte
*
typeKeyPtr
)
0
N/A
{
0
N/A
jvalue
value
;
0
N/A
jbyte
typeKey
=
inStream_readByte
(
stream
);
0
N/A
if
(
stream
->
error
) {
0
N/A
value
.j = 0L;
0
N/A
return
value
;
0
N/A
}
0
N/A
0
N/A
if
(
isObjectTag
(
typeKey
)) {
0
N/A
value
.l =
inStream_readObjectRef
(
getEnv
(),
stream
);
0
N/A
}
else
{
0
N/A
switch
(
typeKey
) {
0
N/A
case
JDWP_TAG
(
BYTE
):
0
N/A
value
.b =
inStream_readByte
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
CHAR
):
0
N/A
value
.c =
inStream_readChar
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
FLOAT
):
0
N/A
value
.f =
inStream_readFloat
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
DOUBLE
):
0
N/A
value
.d =
inStream_readDouble
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
INT
):
0
N/A
value
.i =
inStream_readInt
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
LONG
):
0
N/A
value
.j =
inStream_readLong
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
SHORT
):
0
N/A
value
.s =
inStream_readShort
(
stream
);
0
N/A
break
;
0
N/A
0
N/A
case
JDWP_TAG
(
BOOLEAN
):
0
N/A
value
.z =
inStream_readBoolean
(
stream
);
0
N/A
break
;
0
N/A
default
:
0
N/A
stream
->
error
=
JDWP_ERROR
(
INVALID_TAG
);
0
N/A
break
;
0
N/A
}
0
N/A
}
0
N/A
if
(
typeKeyPtr
) {
0
N/A
*
typeKeyPtr
=
typeKey
;
0
N/A
}
0
N/A
return
value
;
0
N/A
}
0
N/A
0
N/A
static
jboolean
0
N/A
deleteRef
(
void
*
elementPtr
,
void
*
arg
)
0
N/A
{
0
N/A
JNIEnv
*
env
=
arg
;
0
N/A
jobject
*
refPtr
=
elementPtr
;
0
N/A
commonRef_idToRef_delete
(
env
, *
refPtr
);
0
N/A
return
JNI_TRUE
;
0
N/A
}
0
N/A
0
N/A
void
0
N/A
inStream_destroy
(
PacketInputStream
*
stream
)
0
N/A
{
0
N/A
if
(
stream
->
packet
.
type
.
cmd
.
data
!=
NULL
) {
0
N/A
jvmtiDeallocate
(
stream
->
packet
.
type
.
cmd
.
data
);
0
N/A
}
0
N/A
0
N/A
(
void
)
bagEnumerateOver
(
stream
->
refs
,
deleteRef
, (
void
*)
getEnv
());
0
N/A
bagDestroyBag
(
stream
->
refs
);
0
N/A
}