natVMObjectInputStream.cc 1.94 KB
Newer Older
1
// natVMObjectInputStream.cc - Native part of VMObjectInputStream class.
Tom Tromey committed
2

3 4
/* Copyright (C) 1998, 1999, 2000, 2001, 2005, 2006, 2007
   Free Software Foundation
Tom Tromey committed
5

6
   This file is part of libgcj.
Tom Tromey committed
7 8 9 10 11 12 13 14 15

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>
Bryce McKinlay committed
16
#include <gcj/method.h>
Tom Tromey committed
17

18
#include <java/io/VMObjectInputStream.h>
Tom Tromey committed
19 20 21 22
#include <java/io/IOException.h>
#include <java/lang/Class.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/reflect/Method.h>
23 24
#include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/SecurityManager.h>
Bryce McKinlay committed
25 26
#include <java/lang/reflect/Constructor.h>
#include <java/lang/reflect/Method.h>
27
#include <java-stack.h>
Tom Tromey committed
28

29
#ifdef __GCJ_DEBUG
30 31 32 33
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#endif

Tom Tromey committed
34
jobject
35
java::io::VMObjectInputStream::allocateObject (jclass klass, jclass,
Bryce McKinlay committed
36
  ::java::lang::reflect::Constructor *ctr)
Tom Tromey committed
37 38 39 40 41 42 43 44 45 46 47
{
  jobject obj = NULL;
  using namespace java::lang::reflect;

  try
    {
      JvAssert (klass && ! klass->isArray ());
      if (klass->isInterface() || Modifier::isAbstract(klass->getModifiers()))
	obj = NULL;	
      else
	{
48
	  obj = _Jv_AllocObject (klass);
Bryce McKinlay committed
49
	}	
Tom Tromey committed
50 51 52 53 54 55
    }
  catch (jthrowable t)
    {
      return NULL;
    }

Bryce McKinlay committed
56
  jmethodID meth = _Jv_FromReflectedConstructor (ctr);
Tom Tromey committed
57

Tom Tromey committed
58 59 60 61
  // This is a bit inefficient, and a bit of a hack, since we don't
  // actually use the Method and since what is returned isn't
  // technically a Method.  We can't use Method.invoke as it looks up
  // the declared method.
Tom Tromey committed
62
  JArray<jclass> *arg_types
Tom Tromey committed
63 64
    = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
					   NULL);
Bryce McKinlay committed
65

Tom Tromey committed
66 67 68
  // We lie about this being a constructor.  If we put `true' here
  // then _Jv_CallAnyMethodA would try to allocate the object for us.
  _Jv_CallAnyMethodA (obj, JvPrimClass (void), meth, false, arg_types, NULL);
69

Bryce McKinlay committed
70
  return obj;
71
}