This function finds a class of given name from the set
of already loaded classes. It is needed to implement some
VMClassLoader natives.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/classloader.h |    1 +
 vm/classloader.c         |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/include/vm/classloader.h b/include/vm/classloader.h
index fdf457c..b4289a3 100644
--- a/include/vm/classloader.h
+++ b/include/vm/classloader.h
@@ -12,5 +12,6 @@ int try_to_add_zip_to_classpath(const char *zip);
 
 struct vm_class *classloader_load(const char *class_name);
 struct vm_class *classloader_load_primitive(const char *class_name);
+struct vm_class *classloader_find_class(const char *name);
 
 #endif
diff --git a/vm/classloader.c b/vm/classloader.c
index 173dd78..18a1322 100644
--- a/vm/classloader.c
+++ b/vm/classloader.c
@@ -537,3 +537,40 @@ struct vm_class *classloader_load(const char *class_name)
        trace_pop();
        return vmc;
 }
+
+/**
+ * Returns class for a given name if it has already been loaded or
+ * NULL otherwise. It may block if class it being loaded.
+ */
+struct vm_class *classloader_find_class(const char *name)
+{
+       struct vm_class *vmc;
+       char *slash_class_name;
+       int class_index;
+
+       slash_class_name = dots_to_slash(name);
+       if (!slash_class_name) {
+               NOT_IMPLEMENTED;
+               return NULL;
+       }
+
+       vmc = NULL;
+
+       pthread_mutex_lock(&classloader_mutex);
+
+       class_index = lookup_class(slash_class_name);
+       if (class_index >= 0) {
+               /* If class is being loaded by another thread then wait
+                * until loading is completed. */
+               while (!classes[class_index].loaded)
+                       pthread_cond_wait(&classloader_cond,
+                                         &classloader_mutex);
+
+               vmc = classes[class_index].class;
+       }
+
+       free(slash_class_name);
+
+       pthread_mutex_unlock(&classloader_mutex);
+       return vmc;
+}
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to