* src/native/vm/openjdk/jvm.cpp (JVM_CurrentClassLoader): Implemented.
[cacao.git] / src / vm / javaobjects.cpp
index cc82bdc6e9a79f7659f784438b60bc216f64b8e1..901756534cd4441f25d5f03a5e2b7e706f402e52 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/javaobjects.cpp - functions to create and access Java objects
 
-   Copyright (C) 2008 Theobroma Systems Ltd.
+   Copyright (C) 2008, 2009 Theobroma Systems Ltd.
 
    This file is part of CACAO.
 
 
 #include "native/vm/reflection.hpp"
 
-#include "vm/access.h"
+#include "vm/access.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/global.h"
 #include "vm/globals.hpp"
-#include "vm/initialize.h"
+#include "vm/initialize.hpp"
 #include "vm/javaobjects.hpp"
 
 
 #if defined(ENABLE_JAVASE)
 
+/**
+ * Invokes the static Java method getSystemClassLoader().
+ *
+ * @return Return value of the invocation or NULL in
+ * case of an exception.
+ */
+java_handle_t* java_lang_ClassLoader::invoke_getSystemClassLoader()
+{
+       methodinfo    *m;
+       java_handle_t *clo;
+       classloader_t *cl;
+
+       assert(class_java_lang_Object);
+       assert(class_java_lang_ClassLoader);
+       assert(class_java_lang_ClassLoader->state & CLASS_LINKED);
+
+       m = class_resolveclassmethod(class_java_lang_ClassLoader,
+                                                                utf_getSystemClassLoader,
+                                                                utf_void__java_lang_ClassLoader,
+                                                                class_java_lang_Object,
+                                                                false);
+
+       if (m == NULL)
+               return NULL;
+
+       clo = vm_call_method(m, NULL);
+
+       if (clo == NULL)
+               return NULL;
+
+       cl = loader_hashtable_classloader_add(clo);
+
+       return cl;
+}
+
+
 /**
  * Constructs a Java object with the given
  * java.lang.reflect.Constructor.
@@ -67,7 +103,7 @@ java_handle_t* java_lang_reflect_Constructor::new_instance(java_handle_objectarr
 
        if (h == NULL)
                return NULL;
-        
+
        // Call initializer.
        (void) Reflection::invoke(m, h, args);
 
@@ -120,15 +156,6 @@ java_handle_t* java_lang_reflect_Method::invoke(java_handle_t* o, java_handle_ob
        return result;
 }
 
-
-// Legacy C interface.
-
-extern "C" {
-       java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m) { return java_lang_reflect_Constructor(m).get_handle(); }
-       java_handle_t* java_lang_reflect_Field_create(fieldinfo* f) { return java_lang_reflect_Field(f).get_handle(); }
-       java_handle_t* java_lang_reflect_Method_create(methodinfo* m) { return java_lang_reflect_Method(m).get_handle(); }
-}
-
 #endif // ENABLE_JAVASE