OSDN Git Service

2011-07-12 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / natClass.cc
index 79fa599..ec4a18f 100644 (file)
@@ -1,7 +1,7 @@
 // natClass.cc - Implementation of java.lang.Class native methods.
 
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
-   Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2010 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -29,6 +29,7 @@ details.  */
 #include <java/lang/reflect/Member.h>
 #include <java/lang/reflect/Method.h>
 #include <java/lang/reflect/Field.h>
+#include <java/lang/reflect/Proxy.h>
 #include <java/lang/reflect/Constructor.h>
 #include <java/lang/AbstractMethodError.h>
 #include <java/lang/ArrayStoreException.h>
@@ -667,9 +668,12 @@ java::lang::Class::newInstance (void)
 void
 java::lang::Class::finalize (void)
 {
-  engine->unregister(this);
+  // Array classes don't have an engine, and don't need to be finalized.
+   if (engine)
+     engine->unregister(this);
 }
 
+#ifdef INTERPRETER
 void
 _Jv_ClosureList::releaseClosures (_Jv_ClosureList **closures)
 {
@@ -687,10 +691,14 @@ void
 _Jv_ClosureList::registerClosure (jclass klass, void *ptr)
 {
   _Jv_ClosureList **closures = klass->engine->get_closure_list (klass);
-  this->ptr = ptr;
-  this->next = *closures;
-  *closures = this;
+  if (closures)
+    {
+      this->ptr = ptr;
+      this->next = *closures;
+      *closures = this;
+    }
 }
+#endif
 
 // This implements the initialization process for a class.  From Spec
 // section 12.4.2.
@@ -1040,7 +1048,8 @@ java::lang::Class::getEnclosingClass()
   _Jv_word indexes;
   indexes.i = getEnclosingMethodData();
   if (indexes.i == 0)
-    return NULL;
+    // No enclosing method, but perhaps a member or anonymous class
+    return getDeclaringClass();
   _Jv_ushort class_index, method_index;
   _Jv_loadIndexes (&indexes, class_index, method_index);
   return _Jv_Linker::resolve_pool_entry (this, class_index).clazz;
@@ -2064,3 +2073,17 @@ _Jv_GetClassState (jclass klass)
   return klass->state;
 }
 
+#ifdef INTERPRETER
+jstring
+_Jv_GetInterpClassSourceFile (jclass klass)
+{
+  if (_Jv_IsInterpretedClass (klass))
+    {
+      _Jv_InterpClass *iclass =
+       reinterpret_cast<_Jv_InterpClass *> (klass->aux_info);
+      return iclass->source_file_name;
+    }
+
+  return NULL;
+}
+#endif