/* src/native/llni.h - low level native interfarce (LLNI)
- Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
#ifndef _LLNI_H
#define _LLNI_H
-#include "config.h"
-
-#include "native/localref.h"
-
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#else
-# include "threads/none/threads.h"
+#ifdef __cplusplus
+extern "C" {
#endif
+#include "config.h"
-/* LLNI macros *****************************************************************
-
- The following macros should be used whenever a Java Object is
- accessed in native code without the use of an JNI function.
-
- LLNI_field_set_val, LLNI_field_get_val:
- Deal with primitive values like integer and float values. Do
- not use these macros to access pointers or references!
+/* forward defines ************************************************************/
- LLNI_field_set_ref, LLNI_field_get_ref:
- Deal with references to other objects.
+/* LLNI wrapping / unwrapping macros *******************************************
- LLNI_field_set_cls, LLNI_field_get_cls:
- Deal with references to Java Classes which are internally
- represented by classinfo or java_lang_Class.
+ ATTENTION: Only use these macros inside a LLNI critical section!
+ Once the ciritical section ends, all pointers onto the GC heap
+ retrieved through these macros are void!
*******************************************************************************/
-#define LLNI_field_set_val(obj, field, value) \
- LLNI_field_direct(obj, field) = (value)
-
-#define LLNI_field_set_ref(obj, field, reference) \
- LLNI_field_direct(obj, field) = LLNI_UNWRAP(reference)
+#if defined(ENABLE_HANDLES)
+# define LLNI_WRAP(obj) ((obj) == NULL ? NULL : localref_add(obj))
+# define LLNI_UNWRAP(hdl) ((hdl) == NULL ? NULL : (hdl)->heap_object)
+# define LLNI_QUICKWRAP(obj) ((obj) == NULL ? NULL : &(obj))
+# define LLNI_DIRECT(hdl) ((hdl)->heap_object)
+#else
+# define LLNI_WRAP(obj) (obj)
+# define LLNI_UNWRAP(hdl) (hdl)
+# define LLNI_QUICKWRAP(obj) (obj)
+# define LLNI_DIRECT(hdl) (hdl)
+#endif
-#define LLNI_field_set_cls(obj, field, value) \
- LLNI_field_direct(obj, field) = (java_lang_Class *) (value)
-#define LLNI_field_get_val(obj, field, variable) \
- (variable) = LLNI_field_direct(obj, field)
+#include "native/localref.h"
-#define LLNI_field_get_ref(obj, field, variable) \
- (variable) = LLNI_WRAP(LLNI_field_direct(obj, field))
+#include "threads/thread.hpp"
-#define LLNI_field_get_cls(obj, field, variable) \
- (variable) = (classinfo *) LLNI_field_direct(obj, field)
#define LLNI_class_get(obj, variable) \
- (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->class)
+ (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->clazz)
/* LLNI_equals ****************************************************************
*******************************************************************************/
#define LLNI_classinfo_wrap(classinfo) \
- ((java_lang_Class *) LLNI_WRAP(classinfo))
+ ((java_handle_t*) LLNI_WRAP(classinfo))
#define LLNI_classinfo_unwrap(clazz) \
((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz)))
#define LLNI_array_size(arr) (LLNI_DIRECT((java_handle_objectarray_t *) (arr))->header.size)
-/* LLNI wrapping / unwrapping macros *******************************************
-
- ATTENTION: Only use these macros inside a LLNI critical section!
- Once the ciritical section ends, all pointers onto the GC heap
- retrieved through these macros are void!
-
-*******************************************************************************/
-
-#if defined(ENABLE_HANDLES)
-# define LLNI_WRAP(obj) ((obj) == NULL ? NULL : localref_add(obj))
-# define LLNI_UNWRAP(hdl) ((hdl) == NULL ? NULL : (hdl)->heap_object)
-# define LLNI_QUICKWRAP(obj) ((obj) == NULL ? NULL : &(obj))
-# define LLNI_DIRECT(hdl) ((hdl)->heap_object)
-#else
-# define LLNI_WRAP(obj) (obj)
-# define LLNI_UNWRAP(hdl) (hdl)
-# define LLNI_QUICKWRAP(obj) (obj)
-# define LLNI_DIRECT(hdl) (hdl)
-#endif
-
-
/* LLNI critical sections ******************************************************
These macros handle the LLNI critical sections. While a critical
void llni_critical_start_thread(threadobject *t);
void llni_critical_end_thread(threadobject *t);
+#ifdef __cplusplus
+}
+#endif
#endif /* _LLNI_H */