Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / io / natObjectInputStream.cc
blob0e0d5a719cc7d4409b90cf18163bb2cfc94d9c86
1 // natObjectInputStream.cc - Native part of ObjectInputStream class.
3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
5 This ObjectInputStream is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the ObjectInputStream "LIBGCJ_LICENSE" for
9 details. */
11 #include <config.h>
13 #include <gcj/cni.h>
14 #include <jvm.h>
15 #include <gcj/method.h>
17 #include <java/io/ObjectInputStream$GetField.h>
18 #include <java/io/ObjectInputStream.h>
19 #include <java/io/IOException.h>
20 #include <java/lang/Class.h>
21 #include <java/lang/reflect/Modifier.h>
22 #include <java/lang/reflect/Method.h>
23 #include <java/lang/ArrayIndexOutOfBoundsException.h>
24 #include <java/lang/SecurityManager.h>
25 #include <java/lang/reflect/Constructor.h>
26 #include <java/lang/reflect/Method.h>
28 #ifdef DEBUG
29 #include <java/lang/System.h>
30 #include <java/io/PrintStream.h>
31 #endif
33 jobject
34 java::io::ObjectInputStream::allocateObject (jclass klass, jclass,
35 ::java::lang::reflect::Constructor *ctr)
37 jobject obj = NULL;
38 using namespace java::lang::reflect;
40 try
42 JvAssert (klass && ! klass->isArray ());
43 if (klass->isInterface() || Modifier::isAbstract(klass->getModifiers()))
44 obj = NULL;
45 else
47 obj = _Jv_AllocObject (klass);
50 catch (jthrowable t)
52 return NULL;
55 jmethodID meth = _Jv_FromReflectedConstructor (ctr);
57 // This is a bit inefficient, and a bit of a hack, since we don't
58 // actually use the Method and since what is returned isn't
59 // technically a Method. We can't use Method.invoke as it looks up
60 // the declared method.
61 JArray<jclass> *arg_types
62 = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
63 NULL);
65 // We lie about this being a constructor. If we put `true' here
66 // then _Jv_CallAnyMethodA would try to allocate the object for us.
67 _Jv_CallAnyMethodA (obj, JvPrimClass (void), meth, false, arg_types, NULL);
69 return obj;
72 java::lang::ClassLoader*
73 java::io::ObjectInputStream::currentClassLoader (::java::lang::SecurityManager *sm)
75 return sm->currentClassLoader ();