Author: mturk
Date: Fri Mar 25 10:14:18 2011
New Revision: 1085306
URL: http://svn.apache.org/viewvc?rev=1085306&view=rev
Log:
Add basic Unsafe wrapper
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
(with props)
commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h (with
props)
commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h (with
props)
commons/sandbox/runtime/trunk/src/main/native/shared/object.c (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java?rev=1085306&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
Fri Mar 25 10:14:18 2011
@@ -0,0 +1,51 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ * Wrapper over sun.misc.Unsafe.
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class Unsafe
+{
+
+ private Unsafe()
+ {
+ // No instance.
+ }
+
+ private static final Object unsafe;
+ private static native Object get0();
+ static {
+ unsafe = get0();
+ }
+
+ /**
+ * Check if {@code sun.misc.Unsafe} is supported by this JVM.
+ */
+ public static boolean isSupported()
+ {
+ return unsafe != null;
+ }
+
+ public static Object getInstance()
+ {
+ return unsafe;
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1085306&r1=1085305&r2=1085306&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Fri Mar 25
10:14:18 2011
@@ -92,7 +92,9 @@ LIBSOURCES=\
$(TOPDIR)/shared/error.c \
$(TOPDIR)/shared/memory.c \
$(TOPDIR)/shared/native.c \
+ $(TOPDIR)/shared/object.c \
$(TOPDIR)/shared/string.c \
+ $(TOPDIR)/shared/unsafe.c \
$(TOPDIR)/shared/buildmark.c
SHROBJECTS=$(LIBSOURCES:.c=.$(SLO)) $(ASMSOURCES:.S=.$(SLO))
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1085306&r1=1085305&r2=1085306&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Fri Mar
25 10:14:18 2011
@@ -55,17 +55,21 @@
#define V2U(P) ((unsigned int)(acr_uintptr_t)(P))
#define ACR_CLASS_CTOR(CL) \
- int acr_class_##CL##_load(JNIEnv *_E)
+ int acr_class_##CL##_load(JNI_STDENV)
#define ACR_CLASS_DTOR(CL) \
- void acr_class_##CL##_unload(JNIEnv *_E)
+ void acr_class_##CL##_unload(JNI_STDENV)
#define ACR_CLASS_DECLARE(CL) \
extern int acr_class_##CL##_load(JNIEnv *); \
extern int acr_class_##CL##_unload(JNIEnv *)
#define ACR_CLASS_LOAD(CL) \
- if (acr_class_##CL##_load(_E)) return 1;
+ if (acr_class_##CL##_load(_E)) return 1
+
+#define ACR_CLASS_LOPT(CL) \
+ if (acr_class_##CL##_load(_E)) \
+ (*_E)->ExceptionClear(_E)
#define ACR_CLASS_UNLOAD(CL) \
acr_class_##CL##_unload(_E)
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=1085306&r1=1085305&r2=1085306&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 Fri
Mar 25 10:14:18 2011
@@ -25,43 +25,43 @@
#include "acr/stddefs.h"
#define IS_JOBJECT_NULL(E, O) \
- (!(O) || ((*(E))->IsSameObject((E), (O), NULL) == JNI_TRUE))
+ (!(O) || ((*(E))->IsSameObject((E), (O), 0) == JNI_TRUE))
#define IS_JOBJECT_VALID(E, O) \
- ((O) && !((*(E))->IsSameObject((E), (O), NULL) == JNI_TRUE))
+ ((O) && !((*(E))->IsSameObject((E), (O), 0) == JNI_TRUE))
#define J_LOAD_METHOD(I) \
- if (_m##I##n.i == NULL) { \
+ 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 == NULL) { \
+ if ((*_E)->ExceptionCheck(_E) || _m##I##n.i == 0) { \
return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
#define J_LOAD_MLOCAL(I) \
- if (_m##I##n.i == NULL) { \
+ if (_m##I##n.i == 0) { \
_m##I##n.i = (*_E)->GetStaticMethodID(_E, _clazzn.i, _m##I##n.n, \
_m##I##n.s); \
- if ((*_E)->ExceptionCheck(_E) || _m##I##n.i == NULL) { \
+ if ((*_E)->ExceptionCheck(_E) || _m##I##n.i == 0) { \
return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
#define J_LOAD_IFIELD(I) \
- if (_f##I##n.i == NULL) { \
+ if (_f##I##n.i == 0) { \
_f##I##n.i = (*_E)->GetFieldID(_E, _clazzn.i, _f##I##n.n, \
_f##I##n.s); \
- if ((*_E)->ExceptionCheck(_E) || _f##I##n.i == NULL) { \
+ if ((*_E)->ExceptionCheck(_E) || _f##I##n.i == 0) { \
return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
#define J_LOAD_SFIELD(I) \
- if (_f##I##n.i == NULL) { \
+ if (_f##I##n.i == 0) { \
_f##I##n.i = (*_E)->GetStaticFieldID(_E, _clazzn.i, _f##I##n.n, \
_f##I##n.s); \
- if ((*_E)->ExceptionCheck(_E) || _f##I##n.i == NULL) { \
+ if ((*_E)->ExceptionCheck(_E) || _f##I##n.i == 0) { \
return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
@@ -77,7 +77,10 @@
(_f##I##n.i && (O)) ? (*_E)->GetIntField(_E, (O), _f##I##n.i) : (D)
#define GET_IFIELD_O(I, O) \
- (_f##I##n.i && (O)) ? (*_E)->GetObjectField(_E, (O), _f##I##n.i) : NULL
+ (_f##I##n.i && (O)) ? (*_E)->GetObjectField(_E, (O), _f##I##n.i) : 0
+
+#define GET_SFIELD_O(I, C) \
+ (_f##I##n.i && (C)) ? (*_E)->GetStaticObjectField(_E, (C), _f##I##n.i) : 0
#define SET_IFIELD_J(I, O, V) \
if (_f##I##n.i && (O)) { \
Added: 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=1085306&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h Fri Mar
25 10:14:18 2011
@@ -0,0 +1,108 @@
+/* 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.
+ */
+
+#ifndef _ACR_OBJECT_H
+#define _ACR_OBJECT_H
+
+#include "acr/jnitypes.h"
+#include "acr/error.h"
+
+/**
+ * @file object.h
+ * @brief
+ *
+ * ACR Java Object class functions
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ACR_CLASS_CTOR(Object);
+ACR_CLASS_DTOR(Object);
+
+/**
+ * Native version of Java Object.notify() method.
+ * @param env Current JNI environment.
+ * @param o Object to use
+ * @return ACR_SUCCESS or ACR_BUSY on exception.
+ */
+int
+AcrObjectNotify(JNI_STDARGS);
+
+/**
+ * Native version of Java Object.notifyAll() method.
+ * @param env Current JNI environment.
+ * @param o Object to use
+ * @return ACR_SUCCESS or ACR_BUSY on exception.
+ */
+int
+AcrObjectNotifyAll(JNI_STDARGS);
+
+/**
+ * Native version of Java Object.wait() method.
+ * @param env Current JNI environment.
+ * @param o Object to use
+ * @return ACR_SUCCESS or ACR_TIMEUP on exception.
+ */
+int
+AcrObjectWait0(JNI_STDARGS);
+
+/**
+ * Native version of Java Object.wait(long) method.
+ * @param env Current JNI environment.
+ * @param o Object to use
+ * @param ms Number of miliseconds to wait
+ * @return ACR_SUCCESS or ACR_TIMEUP on exception.
+ */
+int
+AcrObjectWait1(JNI_STDARGS, jlong ms);
+
+/**
+ * Native version of Java Object.wait(long, int) method.
+ * @param env Current JNI environment.
+ * @param o Object to use
+ * @param ms Number of miliseconds to wait
+ * @param ns Number of nanoseconds to wait
+ * @return ACR_SUCCESS or ACR_TIMEUP on exception.
+ */
+int
+AcrObjectWait2(JNI_STDARGS, jlong ms, jint ns);
+
+/**
+ * Native version of Java Object.finalize() method.
+ * @param env Current JNI environment.
+ * @param o Object to use
+ */
+void
+AcrObjectFinalize(JNI_STDARGS);
+
+/**
+ * Get Object's method ID.
+ * @param env Current JNI environment.
+ * @param o Object to use..
+ * @param name Method name.
+ * @param sig JNI method signature.
+ */
+jmethodID
+AcrObjectGetMethod(JNI_STDARGS, const char *name, const char *sig);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_OBJECT_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/object.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h?rev=1085306&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h Fri Mar
25 10:14:18 2011
@@ -0,0 +1,45 @@
+/* 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.
+ */
+
+#ifndef _ACR_UNSAFE_H
+#define _ACR_UNSAFE_H
+
+#include "acr/jnitypes.h"
+#include "acr/error.h"
+
+/**
+ * @file unsafe.h
+ * @brief
+ *
+ * ACR Java Unsafe class functions
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ACR_CLASS_CTOR(Unsafe);
+ACR_CLASS_DTOR(Unsafe);
+
+jobject
+AcrUnsafeGetInstance(JNI_STDENV);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_UNSAFE_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1085306&r1=1085305&r2=1085306&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Fri Mar 25
10:14:18 2011
@@ -15,6 +15,8 @@
*/
#include "acr/clazz.h"
+#include "acr/object.h"
+#include "acr/unsafe.h"
#include "acr/string.h"
J_DECLARE_CLAZZ = {
@@ -120,7 +122,7 @@ static struct {
} core_classes[] = {
{ "java/lang/Object", NULL },
{ "java/lang/Class", NULL },
- { "java/lang/reflect/Filed", NULL },
+ { "java/lang/reflect/Field", NULL },
{ "java/lang/reflect/Method", NULL },
{ "java/lang/String", NULL },
{ "java/nio/ByteBuffer", NULL },
@@ -198,7 +200,9 @@ AcrInitCoreClasses(JNI_STDENV)
i++;
}
/* Init some core Objects and it's methods */
-
+ ACR_CLASS_LOAD(Object);
+ ACR_CLASS_LOAD(Class);
+ ACR_CLASS_LOPT(Unsafe);
return 0;
}
Added: 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=1085306&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Fri Mar 25
10:14:18 2011
@@ -0,0 +1,234 @@
+/* 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/object.h"
+#include "acr/string.h"
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ "java/lang/Object"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "<init>",
+ "()V"
+};
+
+J_DECLARE_M_ID(0001) = {
+ NULL,
+ "notify",
+ "()V"
+};
+
+J_DECLARE_M_ID(0002) = {
+ NULL,
+ "notifyAll",
+ "()V"
+};
+
+J_DECLARE_M_ID(0003) = {
+ NULL,
+ "wait",
+ "(J)V"
+};
+
+J_DECLARE_M_ID(0004) = {
+ NULL,
+ "wait",
+ "(JI)V"
+};
+
+J_DECLARE_M_ID(0005) = {
+ NULL,
+ "wait",
+ "()V"
+};
+
+J_DECLARE_M_ID(0006) = {
+ NULL,
+ "finalize",
+ "()V"
+};
+
+J_DECLARE_M_ID(0007) = {
+ NULL,
+ "getClass",
+ "()Ljava/lang/Class;"
+};
+
+ACR_CLASS_CTOR(Object)
+{
+ int rv;
+
+ if ((rv = AcrLoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+ J_LOAD_METHOD(0000);
+ J_LOAD_METHOD(0001);
+ J_LOAD_METHOD(0002);
+ J_LOAD_METHOD(0003);
+ J_LOAD_METHOD(0004);
+ J_LOAD_METHOD(0005);
+ J_LOAD_METHOD(0006);
+ J_LOAD_METHOD(0007);
+
+ return 0;
+}
+
+ACR_CLASS_DTOR(Object)
+{
+ AcrUnloadClass(_E, &_clazzn);
+}
+
+int
+AcrObjectNotify(JNI_STDARGS)
+{
+ int rc = ACR_ENOENT;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return ACR_EINVAL;
+ if (_clazzn.i && J4MID(0000)) {
+ CALL_VMETHOD0(0001, _O);
+ if ((*_E)->ExceptionCheck(_E)) {
+ (*_E)->ExceptionClear(_E);
+ rc = ACR_EBUSY;
+ }
+ else
+ rc = 0;
+ }
+ return rc;
+}
+
+int
+AcrObjectNotifyAll(JNI_STDARGS)
+{
+ int rc = ACR_ENOENT;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return ACR_EINVAL;
+ if (_clazzn.i && J4MID(0000)) {
+ CALL_VMETHOD0(0002, _O);
+ if ((*_E)->ExceptionCheck(_E)) {
+ (*_E)->ExceptionClear(_E);
+ rc = ACR_EBUSY;
+ }
+ else
+ rc = 0;
+ }
+ return rc;
+}
+
+int
+AcrObjectWait0(JNI_STDARGS)
+{
+ int rc = ACR_ENOENT;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return ACR_EINVAL;
+ if (_clazzn.i && J4MID(0000)) {
+ CALL_VMETHOD0(0005, _O);
+ if ((*_E)->ExceptionCheck(_E)) {
+ (*_E)->ExceptionClear(_E);
+ rc = ACR_TIMEUP;
+ }
+ else
+ rc = 0;
+ }
+ return rc;
+}
+
+int
+AcrObjectWait1(JNI_STDARGS, jlong ms)
+{
+ int rc = ACR_ENOENT;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return ACR_EINVAL;
+ if (_clazzn.i && J4MID(0000)) {
+ CALL_VMETHOD1(0003, _O, ms);
+ if ((*_E)->ExceptionCheck(_E)) {
+ (*_E)->ExceptionClear(_E);
+ rc = ACR_TIMEUP;
+ }
+ else
+ rc = 0;
+ }
+ return rc;
+}
+
+int
+AcrObjectWait2(JNI_STDARGS, jlong ms, jint ns)
+{
+ int rc = ACR_ENOENT;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return ACR_EINVAL;
+ if (_clazzn.i && J4MID(0000)) {
+ CALL_VMETHOD2(0004, _O, ms, ns);
+ if ((*_E)->ExceptionCheck(_E)) {
+ (*_E)->ExceptionClear(_E);
+ rc = ACR_TIMEUP;
+ }
+ else
+ rc = 0;
+ }
+ return rc;
+}
+
+void
+AcrObjectFinalize(JNI_STDARGS)
+{
+ if (IS_JOBJECT_NULL(_E, _O))
+ return;
+ if (_clazzn.i && J4MID(0000)) {
+ CALL_VMETHOD0(0006, _O);
+ }
+}
+
+jmethodID
+AcrObjectGetMethod(JNI_STDARGS, const char *name, const char *sig)
+{
+ jmethodID id;
+ jclass clazz;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return 0;
+ clazz = (*_E)->GetObjectClass(_E, _O);
+ if (!clazz)
+ return 0;
+
+ id = (*_E)->GetMethodID(_E, clazz, name, sig);
+ (*_E)->DeleteLocalRef(_E, clazz);
+
+ return id;
+}
+
+jobject
+AcrObjectGetClass(JNI_STDARGS)
+{
+ jobject c = 0;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return c;
+ if (_clazzn.i && J4MID(0000)) {
+ c = CALL_METHOD0(Object, 0007, _O);
+ }
+
+ return c;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c?rev=1085306&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Fri Mar 25
10:14:18 2011
@@ -0,0 +1,129 @@
+/* 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/unsafe.h"
+#include "acr/string.h"
+
+J_DECLARE_CLAZZ = {
+ 0,
+ 0,
+ "sun/misc/Unsafe"
+};
+
+J_DECLARE_F_ID(0000) = {
+ 0,
+ "theUnsafe",
+ "Lsun/misc/Unsafe;"
+};
+
+J_DECLARE_M_ID(0000) = {
+ 0,
+ "getObject",
+ "(Ljava/lang/Object;J)Ljava/lang/Object;"
+};
+
+J_DECLARE_M_ID(0001) = {
+ 0,
+ "putObject",
+ "(Ljava/lang/Object;JLjava/lang/Object;)V"
+};
+
+J_DECLARE_M_ID(0002) = {
+ 0,
+ "objectFieldOffset",
+ "(Ljava/lang/reflect/Field;)J"
+};
+
+J_DECLARE_M_ID(0003) = {
+ 0,
+ "staticFieldOffset",
+ "(Ljava/lang/reflect/Field;)J"
+};
+
+
+ACR_CLASS_CTOR(Unsafe)
+{
+ int rv;
+
+ if ((rv = AcrLoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+
+ J_LOAD_SFIELD(0000);
+ J_LOAD_METHOD(0000);
+ J_LOAD_METHOD(0001);
+ J_LOAD_METHOD(0002);
+ J_LOAD_METHOD(0003);
+
+ return 0;
+}
+
+ACR_CLASS_DTOR(Unsafe)
+{
+ AcrUnloadClass(_E, &_clazzn);
+}
+
+static jobject _unsafe_instance = 0;
+
+jobject
+AcrUnsafeGetInstance(JNI_STDENV)
+{
+ if (_unsafe_instance == 0 && _clazzn.i != 0) {
+ _unsafe_instance = GET_SFIELD_O(0000, _clazzn.i);
+ }
+ return _unsafe_instance;
+}
+
+jlong
+AcrUnsafeObjectFieldOffset(JNI_STDARGS)
+{
+ if (AcrUnsafeGetInstance(_E) == 0) {
+ return 0;
+ }
+ return CALL_METHOD1(Long, 0002, _unsafe_instance, _O);
+}
+
+jlong
+AcrUnsafeStaticFieldOffset(JNI_STDARGS)
+{
+ if (AcrUnsafeGetInstance(_E) == 0) {
+ return 0;
+ }
+ return CALL_METHOD1(Long, 0003, _unsafe_instance, _O);
+}
+
+ACR_JNI_EXPORT(jobject, Unsafe, get0)(JNI_STDARGS)
+{
+ return AcrUnsafeGetInstance(_E);
+}
+
+#if defined(ENABLE_TEST_PRIVATE)
+ACR_JNI_EXPORT(jint, TestUnsafe, get0)(JNI_STDARGS, jobject o, jlong off)
+{
+ if (o != 0) {
+ char *ob = (*(char **)o + (ptrdiff_t)off);
+ return *((jint *)ob);
+ }
+ else
+ return 0;
+}
+
+ACR_JNI_EXPORT(jlong, TestUnsafe, get1)(JNI_STDARGS, jobject o)
+{
+ return AcrUnsafeObjectFieldOffset(_E, o);
+}
+
+#endif
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
------------------------------------------------------------------------------
svn:eol-style = native