Author: mturk
Date: Mon Mar 28 14:57:44 2011
New Revision: 1086263
URL: http://svn.apache.org/viewvc?rev=1086263&view=rev
Log:
Add low level Reflection support
Added:
commons/sandbox/runtime/trunk/src/main/native/shared/reflect.c (with
props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h
commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c
commons/sandbox/runtime/trunk/src/main/native/shared/object.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/native/shared/system.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon Mar 28
14:57:44 2011
@@ -97,6 +97,7 @@ LIBSOURCES=\
$(TOPDIR)/shared/native.c \
$(TOPDIR)/shared/object.c \
$(TOPDIR)/shared/observer.c \
+ $(TOPDIR)/shared/reflect.c \
$(TOPDIR)/shared/string.c \
$(TOPDIR)/shared/system.c \
$(TOPDIR)/shared/unsafe.c \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h Mon Mar 28
14:57:44 2011
@@ -35,14 +35,14 @@ ACR_CLASS_CTOR(FileDescriptor);
ACR_CLASS_DTOR(FileDescriptor);
int
-AcrFileDescriptorGetFd(JNI_STDARGS);
+AcrGetFileDescriptorFd(JNI_STDARGS);
int
-AcrFileDescriptorSetFd(JNI_STDARGS, int fd);
+AcrSetFileDescriptorFd(JNI_STDARGS, int fd);
#if defined (WINDOWS)
HANDLE
-AcrFileDescriptorGetHandle(JNI_STDARGS);
+AcrGetFileDescriptorHandle(JNI_STDARGS);
int
-AcrFileDescriptorSetHandle(JNI_STDARGS, HANDLE fh);
+AcrSetFileDescriptorHandle(JNI_STDARGS, HANDLE fh);
#endif
jobject
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h Mon
Mar 28 14:57:44 2011
@@ -39,6 +39,16 @@
} \
} else (void)(0)
+#define J_LOPT_METHOD(I) \
+ if (_m##I##n.i == 0) { \
+ _m##I##n.i = (*_E)->GetMethodID(_E, _clazzn.i, _m##I##n.n, \
+ _m##I##n.s); \
+ if ((*_E)->ExceptionCheck(_E) || _m##I##n.i == 0) { \
+ (*_E)->ExceptionClear(_E); \
+ _m##I##n.i = 0; \
+ } \
+ } else (void)(0)
+
#define J_LOAD_MLOCAL(I) \
if (_m##I##n.i == 0) { \
_m##I##n.i = (*_E)->GetStaticMethodID(_E, _clazzn.i, _m##I##n.n, \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h Mon Mar
28 14:57:44 2011
@@ -99,7 +99,15 @@ AcrObjectFinalize(JNI_STDARGS);
* @param sig JNI method signature.
*/
jmethodID
-AcrObjectGetMethod(JNI_STDARGS, const char *name, const char *sig);
+AcrGetObjectMethod(JNI_STDARGS, const char *name, const char *sig);
+
+/**
+ * Get Object's java.lang.Class object.
+ * @param env Current JNI environment.
+ * @param o Object to use..
+ */
+jobject
+AcrGetObjectClass(JNI_STDARGS);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h Mon Mar
28 14:57:44 2011
@@ -18,6 +18,7 @@
#define _ACR_STRING_H
#include "acr/jnitypes.h"
+#include "acr/memory.h"
#define ACR_CP_DEFAULT 0
#define ACR_CP_ISO8859_1 1
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h Mon Mar
28 14:57:44 2011
@@ -52,9 +52,9 @@ AcrSystemExit(JNI_STDENV, jint status);
* string is no longer needed.
*/
char *
-AcrSystemGetPropertyA(JNI_STDENV, const char *key);
+AcrGetSystemPropertyA(JNI_STDENV, const char *key);
wchar_t *
-AcrSystemGetPropertyW(JNI_STDENV, const wchar_t *key);
+AcrGetSystemPropertyW(JNI_STDENV, const wchar_t *key);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c Mon Mar 28
14:57:44 2011
@@ -88,7 +88,7 @@ ACR_CLASS_DTOR(FileDescriptor)
}
int
-AcrFileDescriptorGetFd(JNI_STDARGS)
+AcrGetFileDescriptorFd(JNI_STDARGS)
{
int fd = -1;
@@ -108,7 +108,7 @@ AcrFileDescriptorGetFd(JNI_STDARGS)
}
int
-AcrFileDescriptorSetFd(JNI_STDARGS, int fd)
+AcrSetFileDescriptorFd(JNI_STDARGS, int fd)
{
int rc = ACR_EBADF;
@@ -131,7 +131,7 @@ AcrFileDescriptorSetFd(JNI_STDARGS, int
#if defined (WINDOWS)
HANDLE
-AcrFileDescriptorGetHandle(JNI_STDARGS)
+AcrGetFileDescriptorHandle(JNI_STDARGS)
{
HANDLE fh = INVALID_HANDLE_VALUE;
@@ -151,7 +151,7 @@ AcrFileDescriptorGetHandle(JNI_STDARGS)
}
int
-AcrFileDescriptorSetHandle(JNI_STDARGS, HANDLE fh)
+AcrSetFileDescriptorHandle(JNI_STDARGS, HANDLE fh)
{
int rc = ACR_EBADF;
@@ -177,6 +177,7 @@ jobject
AcrNewFileDescriptor(JNI_STDENV, int fd, acr_osd_t fh)
{
jobject fo;
+
if (!CLAZZ_LOADED) {
ACR_SET_OS_ERROR(ACR_EINIT);
return 0;
@@ -190,5 +191,7 @@ AcrNewFileDescriptor(JNI_STDENV, int fd,
}
}
#endif
+ if (fo == 0)
+ ACR_SET_OS_ERROR(ACR_ENOMEM);
return fo;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/object.c?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Mon Mar 28
14:57:44 2011
@@ -204,7 +204,7 @@ AcrObjectFinalize(JNI_STDARGS)
}
jmethodID
-AcrObjectGetMethod(JNI_STDARGS, const char *name, const char *sig)
+AcrGetObjectMethod(JNI_STDARGS, const char *name, const char *sig)
{
jmethodID id;
jclass clazz;
@@ -222,7 +222,7 @@ AcrObjectGetMethod(JNI_STDARGS, const ch
}
jobject
-AcrObjectGetClass(JNI_STDARGS)
+AcrGetObjectClass(JNI_STDARGS)
{
jobject c = 0;
Added: commons/sandbox/runtime/trunk/src/main/native/shared/reflect.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/reflect.c?rev=1086263&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/reflect.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/reflect.c Mon Mar 28
14:57:44 2011
@@ -0,0 +1,100 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/clazz.h"
+#include "acr/string.h"
+
+ACR_INLINE(void) _jni_classname(char *name)
+{
+ char *p;
+ for (p = name; *p != '\0'; p++) {
+ if (*p == '.')
+ *p = '/';
+ }
+}
+
+ACR_JNI_EXPORT(jobject, Reflect, get0)(JNI_STDARGS, jstring name)
+{
+ jobject c = 0;
+ WITH_CSTR(name) {
+ _jni_classname(J2S(name));
+ c = (jobject)(*_E)->FindClass(_E, J2S(name));
+ if (c != 0) {
+ /* Can throw OutOfMemoryError */
+ c = (*_E)->NewWeakGlobalRef(_E, c);
+ }
+ }
+ DONE_WITH_STR(name);
+ return c;
+}
+
+ACR_JNI_EXPORT(jlong, Reflect, get1)(JNI_STDARGS,
+ jclass clazz,
+ jstring name,
+ jstring sig,
+ jboolean isStatic)
+{
+ jlong id = 0;
+
+ WITH_CSTR(name) {
+ WITH_CSTR(sig) {
+ jmethodID mid;
+ if (isStatic)
+ mid = (*_E)->GetStaticMethodID(_E, clazz, J2S(name), J2S(sig));
+ else
+ mid = (*_E)->GetMethodID(_E, clazz, J2S(name), J2S(sig));
+ id = P2J(mid);
+ } DONE_WITH_STR(sig);
+ } DONE_WITH_STR(name);
+ return id;
+}
+
+ACR_JNI_EXPORT(jlong, Reflect, get2)(JNI_STDARGS,
+ jclass clazz,
+ jstring name,
+ jstring sig,
+ jboolean isStatic)
+{
+ jlong id = 0;
+
+ WITH_CSTR(name) {
+ WITH_CSTR(sig) {
+ jfieldID fid;
+ if (isStatic)
+ fid = (*_E)->GetStaticFieldID(_E, clazz, J2S(name), J2S(sig));
+ else
+ fid = (*_E)->GetFieldID(_E, clazz, J2S(name), J2S(sig));
+ id = P2J(fid);
+ } DONE_WITH_STR(sig);
+ } DONE_WITH_STR(name);
+ return id;
+}
+
+ACR_JNI_EXPORT(jobject, Reflect, get3)(JNI_STDARGS,
+ jclass clazz,
+ jlong methodId,
+ jboolean isStatic)
+{
+ return (*_E)->ToReflectedMethod(_E, clazz, J2P(methodId, jmethodID),
isStatic);
+}
+
+ACR_JNI_EXPORT(jobject, Reflect, get4)(JNI_STDARGS,
+ jclass clazz,
+ jlong fieldId,
+ jboolean isStatic)
+{
+ return (*_E)->ToReflectedField(_E, clazz, J2P(fieldId, jfieldID),
isStatic);
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/reflect.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Mar 28
14:57:44 2011
@@ -15,7 +15,6 @@
*/
#include "acr/string.h"
-#include "acr/memory.h"
#include "acr/clazz.h"
J_DECLARE_CLAZZ = {
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/system.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/system.c?rev=1086263&r1=1086262&r2=1086263&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/system.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/system.c Mon Mar 28
14:57:44 2011
@@ -79,7 +79,7 @@ AcrSystemExit(JNI_STDENV, jint status)
}
char *
-AcrSystemGetPropertyA(JNI_STDENV, const char *key)
+AcrGetSystemPropertyA(JNI_STDENV, const char *key)
{
char *val = NULL;
jstring skey;
@@ -104,7 +104,7 @@ AcrSystemGetPropertyA(JNI_STDENV, const
}
wchar_t *
-AcrSystemGetPropertyW(JNI_STDENV, const wchar_t *key)
+AcrGetSystemPropertyW(JNI_STDENV, const wchar_t *key)
{
wchar_t *val = NULL;
jstring skey;