mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-08 09:34:41 +08:00
a53785f90e
* java/io/ObjectInputStream.java (readObject): Added code to conditionally dump out the serialized data. Handle ENDBLOCKDATA case a bit more gracefully since the current behavior doesn't seem to work as expected. (readStreamHeader): Added code for serialized data dumper. (readNextBlock): Ditto. (readFields): Ditto. (dump): New private static field for turning on/off dumper. (setDump): New native method. (dumpElement): New native method. (dumpElementln): New native method. * java/io/natObjectInputStream.cc (setDump): New method. (dumpElement): New method. (dumpElementln): New method. Serialization dumper. Enable by configuring with --enable-libgcj-debug and calling java.io.ObjectInputStream.setDump(true) in your test program. The output will be generated as the object is deserialized (i.e. the readObject() method is executed). From-SVN: r37223
118 lines
2.5 KiB
C++
118 lines
2.5 KiB
C++
// natObjectInputStream.cc - Native part of ObjectInputStream class.
|
|
|
|
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
|
|
|
|
This ObjectInputStream is part of libgcj.
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
Libgcj License. Please consult the ObjectInputStream "LIBGCJ_LICENSE" for
|
|
details. */
|
|
|
|
#include <config.h>
|
|
|
|
#include <gcj/cni.h>
|
|
#include <jvm.h>
|
|
|
|
#include <java/io/ObjectInputStream$GetField.h>
|
|
#include <java/io/ObjectInputStream.h>
|
|
#include <java/io/IOException.h>
|
|
#include <java/lang/Class.h>
|
|
#include <java/lang/reflect/Modifier.h>
|
|
#include <java/lang/reflect/Method.h>
|
|
|
|
#ifdef DEBUG
|
|
#include <java/lang/System.h>
|
|
#include <java/io/PrintStream.h>
|
|
#endif
|
|
|
|
jobject
|
|
java::io::ObjectInputStream::allocateObject (jclass klass)
|
|
{
|
|
jobject obj = NULL;
|
|
using namespace java::lang::reflect;
|
|
|
|
try
|
|
{
|
|
JvAssert (klass && ! klass->isArray ());
|
|
if (klass->isInterface() || Modifier::isAbstract(klass->getModifiers()))
|
|
obj = NULL;
|
|
else
|
|
{
|
|
// FIXME: will this work for String?
|
|
obj = JvAllocObject (klass);
|
|
}
|
|
}
|
|
catch (jthrowable t)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
|
|
#define ObjectClass java::lang::Object::class$
|
|
#define ClassClass java::lang::Class::class$
|
|
|
|
void
|
|
java::io::ObjectInputStream::callConstructor (jclass klass, jobject obj)
|
|
{
|
|
jstring init_name = JvNewStringLatin1 ("<init>");
|
|
JArray<jclass> *arg_types
|
|
= (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
|
|
JArray<jobject> *args
|
|
= (JArray<jobject> *) JvNewObjectArray (0, &ObjectClass, NULL);
|
|
java::lang::reflect::Method *m = klass->getPrivateMethod (init_name, arg_types);
|
|
m->invoke (obj, args);
|
|
}
|
|
|
|
java::lang::reflect::Field *
|
|
java::io::ObjectInputStream::getField (jclass klass, jstring name)
|
|
{
|
|
return klass->getPrivateField (name);
|
|
}
|
|
|
|
java::lang::reflect::Method *
|
|
java::io::ObjectInputStream::getMethod (jclass klass, jstring name,
|
|
JArray<jclass> *arg_types)
|
|
{
|
|
return klass->getPrivateMethod (name, arg_types);
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
void
|
|
java::io::ObjectInputStream::setDump (jboolean dump)
|
|
{
|
|
java::io::ObjectInputStream::dump = dump;
|
|
}
|
|
|
|
void
|
|
java::io::ObjectInputStream::dumpElement (jstring msg)
|
|
{
|
|
if (dump)
|
|
java::lang::System::out->print (msg);
|
|
}
|
|
|
|
void
|
|
java::io::ObjectInputStream::dumpElementln (jstring msg)
|
|
{
|
|
if (dump)
|
|
java::lang::System::out->println (msg);
|
|
}
|
|
#else
|
|
void
|
|
java::io::ObjectInputStream::setDump (jboolean dump)
|
|
{
|
|
}
|
|
|
|
void
|
|
java::io::ObjectInputStream::dumpElement (jstring msg)
|
|
{
|
|
}
|
|
|
|
void
|
|
java::io::ObjectInputStream::dumpElementln (jstring msg)
|
|
{
|
|
}
|
|
#endif
|