You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/05/02 06:04:24 UTC
svn commit: r1098468 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/ java/org/apache/commons/runtime/net/
native/ native/include/acr/ native/os/unix/ native/os/win32/ native/shared/
test/org/apache/commons/runtime/
Author: mturk
Date: Mon May 2 04:04:22 2011
New Revision: 1098468
URL: http://svn.apache.org/viewvc?rev=1098468&view=rev
Log:
Add java.net.Socket accessors
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java (with props)
commons/sandbox/runtime/trunk/src/main/native/include/acr/socks.h (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/dsockimpl.c (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/psock.c (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/psockimpl.c (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c (with props)
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h
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/os/unix/exec.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/procmutex.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/shmem.c
commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c
commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c
commons/sandbox/runtime/trunk/src/main/native/shared/native.c
commons/sandbox/runtime/trunk/src/main/native/shared/object.c
commons/sandbox/runtime/trunk/src/main/native/shared/observer.c
commons/sandbox/runtime/trunk/src/main/native/shared/ostream.c
commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/native/shared/system.c
commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java
Modified: 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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java Mon May 2 04:04:22 2011
@@ -37,13 +37,16 @@ public final class Unsafe
private static native int getOffset1(Field f);
private static native int getBase0(Field f);
- private static native int getSd0(long ptr);
- private static native long getSd1(long ptr);
- private static native short getSd2(long ptr);
- private static native double getSd3(long ptr);
- private static native String getSd4(long ptr);
- private static native String getSd5(long ptr);
- private static native char[] getSd6(long ptr);
+ private static native int peek0(long ptr);
+ private static native long peek1(long ptr);
+ private static native short peek2(long ptr);
+ private static native double peek3(long ptr);
+ private static native String peek4(long ptr);
+ private static native String peek5(long ptr);
+ private static native char[] peek6(long ptr);
+ private static native long peek7(long ptr);
+
+ private static native long addr0(byte[] b);
static {
unsafe = init0();
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java Mon May 2 04:04:22 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.net;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.DatagramSocketImpl;
+import java.net.SocketException;
+
+public final class DatagramSocketInstance
+{
+ private DatagramSocketInstance()
+ {
+ // No istance
+ }
+
+ private static native boolean init0();
+ static {
+ init0();
+ }
+
+ private static native FileDescriptor fd0(DatagramSocket s);
+ private static native int nd0(DatagramSocket s);
+
+ public static FileDescriptor getFileDescriptor(DatagramSocket s)
+ throws NullPointerException
+ {
+ if (s == null)
+ throw new NullPointerException();
+ return fd0(s);
+ }
+
+ public static int getNativeDescriptor(DatagramSocket s)
+ throws NullPointerException
+ {
+ if (s == null)
+ throw new NullPointerException();
+ return nd0(s);
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java Mon May 2 04:04:22 2011
@@ -0,0 +1,77 @@
+/*
+ * 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.net;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.SocketImpl;
+import java.net.ServerSocket;
+import java.net.SocketException;
+
+public final class SocketInstance
+{
+ private SocketInstance()
+ {
+ // No istance
+ }
+
+ private static native boolean init0();
+ static {
+ init0();
+ }
+
+ private static native FileDescriptor fd0(Socket s);
+ private static native FileDescriptor fd1(ServerSocket s);
+ private static native int nd0(Socket s);
+ private static native int nd1(ServerSocket s);
+
+ public static FileDescriptor getFileDescriptor(Socket s)
+ throws NullPointerException
+ {
+ if (s == null)
+ throw new NullPointerException();
+ return fd0(s);
+ }
+
+ public static FileDescriptor getFileDescriptor(ServerSocket s)
+ throws NullPointerException
+ {
+ if (s == null)
+ throw new NullPointerException();
+ return fd1(s);
+ }
+
+ public static int getNativeDescriptor(Socket s)
+ throws NullPointerException
+ {
+ if (s == null)
+ throw new NullPointerException();
+ return nd0(s);
+ }
+
+ public static int getNativeDescriptor(ServerSocket s)
+ throws NullPointerException
+ {
+ if (s == null)
+ throw new NullPointerException();
+ return nd1(s);
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon May 2 04:04:22 2011
@@ -108,17 +108,22 @@ LIBSOURCES=\
$(TOPDIR)\shared\constptr.c \
$(TOPDIR)\shared\debug.c \
$(TOPDIR)\shared\directbb.c \
+ $(TOPDIR)\shared\dsock.c \
+ $(TOPDIR)\shared\dsockimpl.c \
$(TOPDIR)\shared\error.c \
$(TOPDIR)\shared\iofd.c \
$(TOPDIR)\shared\memory.c \
$(TOPDIR)\shared\native.c \
$(TOPDIR)\shared\pointer.c \
+ $(TOPDIR)\shared\psock.c \
+ $(TOPDIR)\shared\psockimpl.c \
$(TOPDIR)\shared\object.c \
$(TOPDIR)\shared\observer.c \
$(TOPDIR)\shared\ostream.c \
$(TOPDIR)\shared\reflect.c \
$(TOPDIR)\shared\sbuf.c \
$(TOPDIR)\shared\sliceptr.c \
+ $(TOPDIR)\shared\ssock.c \
$(TOPDIR)\shared\string.c \
$(TOPDIR)\shared\system.c \
$(TOPDIR)\shared\unsafe.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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon May 2 04:04:22 2011
@@ -102,17 +102,22 @@ LIBSOURCES=\
$(TOPDIR)/shared/constptr.c \
$(TOPDIR)/shared/debug.c \
$(TOPDIR)/shared/directbb.c \
+ $(TOPDIR)/shared/dsock.c \
+ $(TOPDIR)/shared/dsockimpl.c \
$(TOPDIR)/shared/error.c \
$(TOPDIR)/shared/iofd.c \
$(TOPDIR)/shared/memory.c \
$(TOPDIR)/shared/native.c \
$(TOPDIR)/shared/pointer.c \
+ $(TOPDIR)/shared/psock.c \
+ $(TOPDIR)/shared/psockimpl.c \
$(TOPDIR)/shared/object.c \
$(TOPDIR)/shared/observer.c \
$(TOPDIR)/shared/ostream.c \
$(TOPDIR)/shared/reflect.c \
$(TOPDIR)/shared/sbuf.c \
$(TOPDIR)/shared/sliceptr.c \
+ $(TOPDIR)/shared/ssock.c \
$(TOPDIR)/shared/string.c \
$(TOPDIR)/shared/system.c \
$(TOPDIR)/shared/unsafe.c \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h Mon May 2 04:04:22 2011
@@ -52,10 +52,10 @@ extern "C" {
* @remark This function MUST be called before any classes using
* native methods are loaded by classloader.
*/
-int
+jboolean
AcrInitCoreClasses(JNI_STDENV);
-int
+jboolean
AcrLoadRuntimeClasses(JNI_STDENV);
void
@@ -84,7 +84,7 @@ AcrNewCoreObjectArray(JNI_STDENV, int cl
* @param init_array Initialize Class[][] support.
* @return ACR_SUCCESS on success.
*/
-int
+jboolean
AcrLoadClass(JNI_STDENV, JAVA_C_ID *clazz, int init_array);
/**
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=1098468&r1=1098467&r2=1098468&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 Mon May 2 04:04:22 2011
@@ -70,24 +70,25 @@
#define INVALID_FIELD_OFFSET (-1)
#define INVALID_FIELD_BASE (-1)
-#define ACR_CLASS_CTOR(CL) \
- int acr_class_##CL##_load(JNI_STDENV)
+#define ACR_CLASS_CTOR(CL) \
+ jboolean acr_class_##CL##_load(JNI_STDENV)
-#define ACR_CLASS_DTOR(CL) \
+#define ACR_CLASS_DTOR(CL) \
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_DECLARE(CL) \
+ extern jboolean acr_class_##CL##_load(JNIEnv *); \
+ extern jboolean acr_class_##CL##_unload(JNIEnv *)
+
+#define ACR_CLASS_LOAD(CL) \
+ if (acr_class_##CL##_load(env) == JNI_FALSE) \
+ return JNI_FALSE
-#define ACR_CLASS_LOAD(CL) \
- if (acr_class_##CL##_load(env)) return 1
-
-#define ACR_CLASS_LOPT(CL) \
- if (acr_class_##CL##_load(env)) \
+#define ACR_CLASS_LOPT(CL) \
+ if (acr_class_##CL##_load(env) == JNI_FALSE) \
(*env)->ExceptionClear(env)
-#define ACR_CLASS_UNLOAD(CL) \
+#define ACR_CLASS_UNLOAD(CL) \
acr_class_##CL##_unload(env)
#define J_DECLARE_CLAZZ static JAVA_C_ID _clazzn
@@ -95,6 +96,7 @@
#define J_DECLARE_M_ID(I) static JAVA_M_ID _m##I##n
#define J4MID(I) _m##I##n.i
#define J4FLD_OFF(I) _f##I##n.o
+#define J4FLD_PTR(I) (ptrdiff_t)_f##I##n.o
#define CLAZZ_LOADED (_clazzn.u != 0)
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=1098468&r1=1098467&r2=1098468&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 May 2 04:04:22 2011
@@ -41,7 +41,7 @@
_m##I##n.i = (*env)->GetMethodID(env, _clazzn.i, _m##I##n.n, \
_m##I##n.s); \
if (_m##I##n.i == 0) \
- return ACR_ESYMNOTFOUND; \
+ return JNI_FALSE; \
} else (void)(0)
#define R_LOAD_METHOD(I, E) \
@@ -65,7 +65,7 @@
_m##I##n.i = (*env)->GetStaticMethodID(env, _clazzn.i, _m##I##n.n, \
_m##I##n.s); \
if (_m##I##n.i == 0) \
- return ACR_ESYMNOTFOUND; \
+ return JNI_FALSE; \
} else (void)(0)
#define J_LOAD_IFIELD(I) \
@@ -73,7 +73,7 @@
_f##I##n.i = (*env)->GetFieldID(env, _clazzn.i, _f##I##n.n, \
_f##I##n.s); \
if (_f##I##n.i == 0) \
- return ACR_ESYMNOTFOUND; \
+ return JNI_FALSE; \
} else (void)(0)
#define J_LOAD_SFIELD(I) \
@@ -81,7 +81,7 @@
_f##I##n.i = (*env)->GetStaticFieldID(env, _clazzn.i, _f##I##n.n, \
_f##I##n.s); \
if (_f##I##n.i == 0) \
- return ACR_ESYMNOTFOUND; \
+ return JNI_FALSE; \
} else (void)(0)
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/socks.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/socks.h?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/socks.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/socks.h Mon May 2 04:04:22 2011
@@ -0,0 +1,53 @@
+/* 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_SOCKS_H
+#define _ACR_SOCKS_H
+
+#include "acr/jniapi.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file socks.h
+ * @brief
+ *
+ * ACR java.net.Socket* support.
+ *
+ */
+
+ACR_CLASS_CTOR(DatagramSocketImpl);
+ACR_CLASS_DTOR(DatagramSocketImpl);
+ACR_CLASS_CTOR(DatagramSocket);
+ACR_CLASS_DTOR(DatagramSocket);
+
+ACR_CLASS_CTOR(SocketImpl);
+ACR_CLASS_DTOR(SocketImpl);
+ACR_CLASS_CTOR(ServerSocket);
+ACR_CLASS_DTOR(ServerSocket);
+ACR_CLASS_CTOR(Socket);
+ACR_CLASS_DTOR(Socket);
+
+jobject AcrGetSocketImplFd(JNI_STDARGS);
+jobject AcrGetDatagramSocketImplFd(JNI_STDARGS);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_SOCKS_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/socks.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c Mon May 2 04:04:22 2011
@@ -580,7 +580,7 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c Mon May 2 04:04:22 2011
@@ -40,7 +40,7 @@ ACR_JNI_EXPORT(jobject, ExecutableMemory
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c Mon May 2 04:04:22 2011
@@ -94,7 +94,7 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
}
if ((env = AcrGetJNIEnv()) == 0)
return JNI_ERR;
- if (AcrInitCoreClasses(env) != 0)
+ if (AcrInitCoreClasses(env) == JNI_FALSE)
return JNI_ERR;
return JNI_VERSION_1_4;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c Mon May 2 04:04:22 2011
@@ -93,7 +93,7 @@ ACR_JNI_EXPORT(jobject, MutexImpl, init0
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000), (jint)_DEFAULT_MUTEX_TYPE);
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c Mon May 2 04:04:22 2011
@@ -47,7 +47,7 @@ ACR_JNI_EXPORT(jobject, SemaphoreImpl, i
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c Mon May 2 04:04:22 2011
@@ -60,7 +60,7 @@ ACR_JNI_EXPORT(jobject, ShmImpl, init0)(
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c Mon May 2 04:04:22 2011
@@ -524,7 +524,7 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
jstring shell;
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c Mon May 2 04:04:22 2011
@@ -38,7 +38,7 @@ ACR_JNI_EXPORT(jobject, ExecutableMemory
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c Mon May 2 04:04:22 2011
@@ -162,7 +162,7 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
return JNI_ERR;
if ((env = AcrGetJNIEnv()) == 0)
return JNI_ERR;
- if (AcrInitCoreClasses(env) != 0)
+ if (AcrInitCoreClasses(env) == JNI_FALSE)
return JNI_ERR;
return JNI_VERSION_1_4;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/procmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/procmutex.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/procmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/procmutex.c Mon May 2 04:04:22 2011
@@ -37,7 +37,7 @@ ACR_JNI_EXPORT(jobject, MutexImpl, init0
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c Mon May 2 04:04:22 2011
@@ -37,7 +37,7 @@ ACR_JNI_EXPORT(jobject, SemaphoreImpl, i
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/shmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/shmem.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/shmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/shmem.c Mon May 2 04:04:22 2011
@@ -44,7 +44,7 @@ ACR_JNI_EXPORT(jobject, ShmImpl, init0)(
{
if (_clazzn.u == 1)
return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
- if (AcrLoadClass(env, &_clazzn, 0) != 0)
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
return 0;
R_LOAD_METHOD(0000, 0);
_clazzn.u = 1;
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/callback.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/callback.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/callback.c Mon May 2 04:04:22 2011
@@ -39,14 +39,12 @@ J_DECLARE_M_ID(0000) = {
ACR_CLASS_CTOR(Callback)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(Callback)
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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Mon May 2 04:04:22 2011
@@ -25,6 +25,7 @@
#include "acr/callback.h"
#include "acr/observer.h"
#include "acr/iofd.h"
+#include "acr/socks.h"
#include "acr/pointer.h"
J_DECLARE_CLAZZ = {
@@ -155,10 +156,8 @@ static struct {
static
ACR_CLASS_CTOR(Class)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
J_LOAD_METHOD(0002);
@@ -176,7 +175,7 @@ ACR_CLASS_CTOR(Class)
J_LOAD_METHOD(0014);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
static
@@ -185,13 +184,13 @@ ACR_CLASS_DTOR(Class)
AcrUnloadClass(env, &_clazzn);
}
-int
+jboolean
AcrInitCoreClasses(JNI_STDENV)
{
int i = 0;
if (core_classes[0].clazz)
- return 0;
+ return JNI_TRUE;
while (core_classes[i].name) {
jobject o = (jobject)(*env)->FindClass(env, core_classes[i].name);
if (o != 0) {
@@ -199,12 +198,12 @@ AcrInitCoreClasses(JNI_STDENV)
(*env)->DeleteLocalRef(env, o);
if (core_classes[i].clazz == 0) {
/* Reference failed */
- return ACR_ENOMEM;
+ return JNI_FALSE;
}
}
else {
/* Not found */
- return ACR_ESYMNOTFOUND;
+ return JNI_FALSE;
}
i++;
}
@@ -215,10 +214,10 @@ AcrInitCoreClasses(JNI_STDENV)
ACR_CLASS_LOAD(System);
ACR_CLASS_LOAD(Observer);
ACR_CLASS_LOAD(OutputStream);
- return 0;
+ return JNI_TRUE;
}
-int
+jboolean
AcrLoadRuntimeClasses(JNI_STDENV)
{
ACR_CLASS_LOAD(Callback);
@@ -231,7 +230,7 @@ AcrLoadRuntimeClasses(JNI_STDENV)
#ifdef WIN32
#endif
- return 0;
+ return JNI_TRUE;
}
void
@@ -241,6 +240,11 @@ AcrUnloadRuntimeClasses(JNI_STDENV)
ACR_CLASS_UNLOAD(ConstPointer);
ACR_CLASS_UNLOAD(HeapPointer);
ACR_CLASS_UNLOAD(SlicePointer);
+ ACR_CLASS_UNLOAD(Socket);
+ ACR_CLASS_UNLOAD(SocketImpl);
+ ACR_CLASS_UNLOAD(ServerSocket);
+ ACR_CLASS_UNLOAD(DatagramSocket);
+ ACR_CLASS_UNLOAD(DatagramSocketImpl);
ACR_CLASS_UNLOAD(FileDescriptor);
ACR_CLASS_UNLOAD(Callback);
ACR_CLASS_UNLOAD(Unsafe);
@@ -275,14 +279,14 @@ AcrNewCoreObjectArray(JNI_STDENV, int cl
return 0;
}
-int
+jboolean
AcrLoadClass(JNI_STDENV, JAVA_C_ID *clazz, int init_array)
{
jobject c;
if (clazz->i != 0) {
/* Already inited */
- return 0;
+ return JNI_TRUE;
}
/* Init class */
c = (jobject)(*env)->FindClass(env, clazz->n);
@@ -324,14 +328,14 @@ AcrLoadClass(JNI_STDENV, JAVA_C_ID *claz
clazz->a = 0;
}
clazz->o = 0;
- return 0;
+ return JNI_TRUE;
failed:
if (clazz->i != 0) {
(*env)->DeleteGlobalRef(env, clazz->i);
clazz->i = 0;
}
- return ACR_NOTFOUND;
+ return JNI_FALSE;
}
void
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c Mon May 2 04:04:22 2011
@@ -40,13 +40,11 @@ J_DECLARE_M_ID(0000) = {
ACR_CLASS_CTOR(ConstPointer)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(ConstPointer)
Added: commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c Mon May 2 04:04:22 2011
@@ -0,0 +1,115 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/iofd.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+ INVALID_FIELD_OFFSET,
+ 0,
+ 0,
+ 0,
+ "java/net/DatagramSocket"
+};
+
+J_DECLARE_M_ID(0000) = {
+ 0,
+ "getImpl",
+ "()Ljava/net/DatagramSocketImpl;"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "impl",
+ "Ljava/net/DatagramSocketImpl;"
+};
+
+ACR_CLASS_CTOR(DatagramSocket)
+{
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
+ J_LOAD_IFIELD(0000);
+ J_LOAD_METHOD(0000);
+ UNSAFE_IFIELD(0000);
+ _clazzn.u = 1;
+ return JNI_TRUE;
+}
+
+ACR_CLASS_DTOR(DatagramSocket)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+ACR_NET_EXPORT(jboolean, DatagramSocketInstance, init0)(JNI_STDARGS)
+{
+ ACR_CLASS_LOAD(DatagramSocket);
+ ACR_CLASS_LOAD(DatagramSocketImpl);
+ return JNI_TRUE;
+}
+
+ACR_NET_EXPORT(jobject, DatagramSocketInstance, getImpl0)(JNI_STDARGS, jobject sock)
+{
+ return CALL_METHOD0(Object, 0000, sock);
+
+}
+
+ACR_NET_EXPORT(jobject, DatagramSocketInstance, fd0)(JNI_STDARGS, jobject sock)
+{
+ jobject impl = 0;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)sock;
+ if (oa != 0)
+ impl = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ impl = GET_IFIELD_O(0000, sock);
+ }
+ if (impl != 0)
+ return AcrGetDatagramSocketImplFd(env, impl);
+ else
+ return 0;
+}
+
+ACR_NET_EXPORT(jint, DatagramSocketInstance, nd0)(JNI_STDARGS, jobject sock)
+{
+ jobject impl = 0;
+ jobject fd;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)sock;
+ if (oa != 0)
+ impl = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ impl = GET_IFIELD_O(0000, sock);
+ }
+ if (impl != 0) {
+ fd = AcrGetDatagramSocketImplFd(env, impl);
+ if (fd != 0)
+ return AcrGetFileDescriptorFd(env, fd);
+ }
+ return -1;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/shared/dsockimpl.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dsockimpl.c?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dsockimpl.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dsockimpl.c Mon May 2 04:04:22 2011
@@ -0,0 +1,72 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/memory.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+ INVALID_FIELD_OFFSET,
+ 0,
+ 0,
+ 0,
+ "java/net/DatagramSocketImpl"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "fd",
+ "Ljava/io/FileDescriptor;"
+};
+
+ACR_CLASS_CTOR(DatagramSocketImpl)
+{
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
+ J_LOAD_IFIELD(0000);
+ UNSAFE_IFIELD(0000);
+
+ _clazzn.u = 1;
+ return JNI_TRUE;
+}
+
+ACR_CLASS_DTOR(DatagramSocketImpl)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+jobject AcrGetDatagramSocketImplFd(JNI_STDARGS)
+{
+ jobject o = 0;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)obj;
+ if (oa != 0)
+ o = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ o = GET_IFIELD_O(0000, obj);
+ }
+ return o;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/dsockimpl.c
------------------------------------------------------------------------------
svn:eol-style = native
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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c Mon May 2 04:04:22 2011
@@ -64,10 +64,8 @@ J_DECLARE_F_ID(0001) = {
ACR_CLASS_CTOR(FileDescriptor)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
J_LOAD_IFIELD(0000);
@@ -79,7 +77,7 @@ ACR_CLASS_CTOR(FileDescriptor)
UNSAFE_IFIELD(0001);
#endif
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(FileDescriptor)
@@ -95,7 +93,7 @@ AcrGetFileDescriptorFd(JNI_STDARGS)
if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
char *oa = *(char **)obj;
if (oa != 0) {
- char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0000));
+ char *fa = (oa + J4FLD_PTR(0000));
fd = *((int *)fa);
}
}
@@ -113,7 +111,7 @@ AcrSetFileDescriptorFd(JNI_STDARGS, int
if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
char *oa = *(char **)obj;
if (oa != 0) {
- char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0000));
+ char *fa = (oa + J4FLD_PTR(0000));
*((int *)fa) = fd;
rc = 0;
}
@@ -134,7 +132,7 @@ AcrGetFileDescriptorHandle(JNI_STDARGS)
if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
char *oa = *(char **)obj;
if (oa != 0) {
- char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0001));
+ char *fa = (oa + J4FLD_PTR(0001));
fh = J2P(*((jlong *)fa), HANDLE);
}
}
@@ -152,7 +150,7 @@ AcrSetFileDescriptorHandle(JNI_STDARGS,
if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
char *oa = *(char **)obj;
if (oa != 0) {
- char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0001));
+ char *fa = (oa + J4FLD_PTR(0001));
*((jlong *)fa) = P2J(fh);
rc = 0;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Mon May 2 04:04:22 2011
@@ -17,7 +17,6 @@
#include "acr/clazz.h"
#include "acr/misc.h"
-static jboolean _loaded = JNI_FALSE;
ACR_JNI_EXPORT(jboolean, Native, isdbg0)(JNI_STDARGS)
{
#if defined(DEBUG) || defined(_DEBUG)
@@ -29,17 +28,10 @@ ACR_JNI_EXPORT(jboolean, Native, isdbg0)
ACR_JNI_EXPORT(jboolean, Native, init0)(JNI_STDARGS)
{
- if (_loaded)
- return JNI_TRUE;
- if (AcrLoadRuntimeClasses(env) != 0)
- return JNI_FALSE;
- _loaded = JNI_TRUE;
- return _loaded;
+ return AcrLoadRuntimeClasses(env);
}
ACR_JNI_EXPORT(void, Native, fini0)(JNI_STDARGS)
{
- if (_loaded) {
- _loaded = JNI_FALSE;
- }
+ /* Noop currently */
}
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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Mon May 2 04:04:22 2011
@@ -76,10 +76,8 @@ J_DECLARE_M_ID(0007) = {
ACR_CLASS_CTOR(Object)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
J_LOAD_METHOD(0002);
@@ -90,7 +88,7 @@ ACR_CLASS_CTOR(Object)
J_LOAD_METHOD(0007);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(Object)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/observer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/observer.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/observer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/observer.c Mon May 2 04:04:22 2011
@@ -39,14 +39,12 @@ J_DECLARE_M_ID(0000) = {
ACR_CLASS_CTOR(Observer)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(Observer)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/ostream.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/ostream.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/ostream.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/ostream.c Mon May 2 04:04:22 2011
@@ -46,16 +46,15 @@ J_DECLARE_M_ID(0002) = {
ACR_CLASS_CTOR(OutputStream)
{
- int rv;
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
J_LOAD_METHOD(0002);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(OutputStream)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Mon May 2 04:04:22 2011
@@ -56,17 +56,15 @@ J_DECLARE_F_ID(0001) = {
ACR_CLASS_CTOR(HeapPointer)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
J_LOAD_IFIELD(0000);
J_LOAD_IFIELD(0001);
UNSAFE_IFIELD(0000);
UNSAFE_IFIELD(0001);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(HeapPointer)
Added: commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/psock.c?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/psock.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/psock.c Mon May 2 04:04:22 2011
@@ -0,0 +1,105 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/iofd.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+ INVALID_FIELD_OFFSET,
+ 0,
+ 0,
+ 0,
+ "java/net/Socket"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "impl",
+ "Ljava/net/SocketImpl;"
+};
+
+ACR_CLASS_CTOR(Socket)
+{
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
+ J_LOAD_IFIELD(0000);
+ UNSAFE_IFIELD(0000);
+ _clazzn.u = 1;
+ return JNI_TRUE;
+}
+
+
+ACR_CLASS_DTOR(Socket)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+ACR_NET_EXPORT(jboolean, SocketInstance, init0)(JNI_STDARGS)
+{
+ ACR_CLASS_LOAD(Socket);
+ ACR_CLASS_LOAD(SocketImpl);
+ ACR_CLASS_LOAD(ServerSocket);
+ return JNI_TRUE;
+}
+
+ACR_NET_EXPORT(jobject, SocketInstance, fd0)(JNI_STDARGS, jobject sock)
+{
+ jobject impl = 0;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)sock;
+ if (oa != 0)
+ impl = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ impl = GET_IFIELD_O(0000, sock);
+ }
+ if (impl != 0)
+ return AcrGetSocketImplFd(env, impl);
+ else
+ return 0;
+}
+
+ACR_NET_EXPORT(jint, SocketInstance, nd0)(JNI_STDARGS, jobject sock)
+{
+ jobject impl = 0;
+ jobject fd;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)sock;
+ if (oa != 0)
+ impl = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ impl = GET_IFIELD_O(0000, sock);
+ }
+ if (impl != 0) {
+ fd = AcrGetSocketImplFd(env, impl);
+ if (fd != 0)
+ return AcrGetFileDescriptorFd(env, fd);
+ }
+ return -1;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/shared/psockimpl.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/psockimpl.c?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/psockimpl.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/psockimpl.c Mon May 2 04:04:22 2011
@@ -0,0 +1,72 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/memory.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+ INVALID_FIELD_OFFSET,
+ 0,
+ 0,
+ 0,
+ "java/net/SocketImpl"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "fd",
+ "Ljava/io/FileDescriptor;"
+};
+
+ACR_CLASS_CTOR(SocketImpl)
+{
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
+ J_LOAD_IFIELD(0000);
+ UNSAFE_IFIELD(0000);
+
+ _clazzn.u = 1;
+ return JNI_TRUE;
+}
+
+ACR_CLASS_DTOR(SocketImpl)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+jobject AcrGetSocketImplFd(JNI_STDARGS)
+{
+ jobject o = 0;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)obj;
+ if (oa != 0)
+ o = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ o = GET_IFIELD_O(0000, obj);
+ }
+ return o;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/psockimpl.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c Mon May 2 04:04:22 2011
@@ -40,13 +40,11 @@ J_DECLARE_M_ID(0000) = {
ACR_CLASS_CTOR(SlicePointer)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(SlicePointer)
Added: commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c Mon May 2 04:04:22 2011
@@ -0,0 +1,95 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/iofd.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+ INVALID_FIELD_OFFSET,
+ 0,
+ 0,
+ 0,
+ "java/net/ServerSocket"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "impl",
+ "Ljava/net/SocketImpl;"
+};
+
+ACR_CLASS_CTOR(ServerSocket)
+{
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
+ J_LOAD_IFIELD(0000);
+ UNSAFE_IFIELD(0000);
+ _clazzn.u = 1;
+ return JNI_TRUE;
+}
+
+ACR_CLASS_DTOR(ServerSocket)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+ACR_NET_EXPORT(jobject, SocketInstance, fd1)(JNI_STDARGS, jobject sock)
+{
+ jobject impl = 0;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)sock;
+ if (oa != 0)
+ impl = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ impl = GET_IFIELD_O(0000, sock);
+ }
+ if (impl != 0)
+ return AcrGetSocketImplFd(env, impl);
+ else
+ return 0;
+}
+
+ACR_NET_EXPORT(jint, SocketInstance, nd1)(JNI_STDARGS, jobject sock)
+{
+ jobject impl = 0;
+ jobject fd;
+
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)sock;
+ if (oa != 0)
+ impl = (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ impl = GET_IFIELD_O(0000, sock);
+ }
+ if (impl != 0) {
+ fd = AcrGetSocketImplFd(env, impl);
+ if (fd != 0)
+ return AcrGetFileDescriptorFd(env, fd);
+ }
+ return -1;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/ssock.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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon May 2 04:04:22 2011
@@ -53,17 +53,15 @@ J_DECLARE_F_ID(0000) = {
ACR_CLASS_CTOR(String)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
J_LOAD_METHOD(0002);
J_LOAD_IFIELD(0000);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(String)
@@ -1120,7 +1118,7 @@ AcrNewJavaMszArrayW(JNI_STDENV, const wc
jchar *cc;
if ((cc = ACR_MALLOC(jchar, len))) {
int i;
- for (i = 0; i < l; i++) {
+ for (i = 0; i < len; i++) {
/* Simply assign utf32 to utf16 */
cc[i] = (jchar)s[i];
}
@@ -1264,6 +1262,7 @@ ACR_JNI_EXPORT(jint, TestString, test1)(
ACR_JNI_EXPORT(jint, TestString, test2)(JNI_STDARGS, jcharArray c)
{
+#if CC_SIZEOF_WCHAR_T == 2
int rv;
int len;
jchar *jca;
@@ -1273,6 +1272,9 @@ ACR_JNI_EXPORT(jint, TestString, test2)(
rv = wcszlen(jca, 0);
(*env)->ReleasePrimitiveArrayCritical(env, c, jca, 0);
return rv;
+#else
+ return -1;
+#endif
}
#endif
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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/system.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/system.c Mon May 2 04:04:22 2011
@@ -45,15 +45,13 @@ J_DECLARE_M_ID(0001) = {
ACR_CLASS_CTOR(System)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_MLOCAL(0000);
J_LOAD_MLOCAL(0001);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(System)
Modified: 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=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Mon May 2 04:04:22 2011
@@ -67,10 +67,8 @@ J_DECLARE_M_ID(0004) = {
ACR_CLASS_CTOR(Unsafe)
{
- int rv;
-
- if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
- return rv;
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return JNI_FALSE;
J_LOAD_SFIELD(0000);
J_LOAD_METHOD(0000);
@@ -80,7 +78,7 @@ ACR_CLASS_CTOR(Unsafe)
J_LOAD_METHOD(0004);
_clazzn.u = 1;
- return 0;
+ return JNI_TRUE;
}
ACR_CLASS_DTOR(Unsafe)
@@ -199,48 +197,70 @@ ACR_JNI_EXPORT(jint, Unsafe, getBase0)(J
return AcrUnsafeStaticFieldBase(env, field);
}
-ACR_JNI_EXPORT(jint, Unsafe, getSd0)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jint, Unsafe, peek0)(JNI_STDARGS, jlong ptr)
{
char *buf = J2P(ptr, char *);
return *((int *)buf);
}
-ACR_JNI_EXPORT(jlong, Unsafe, getSd1)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jlong, Unsafe, peek1)(JNI_STDARGS, jlong ptr)
{
char *buf = J2P(ptr, char *);
return *((jlong *)buf);
}
-ACR_JNI_EXPORT(jshort, Unsafe, getSd2)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jshort, Unsafe, peek2)(JNI_STDARGS, jlong ptr)
{
char *buf = J2P(ptr, char *);
return *((jshort *)buf);
}
-ACR_JNI_EXPORT(jdouble, Unsafe, getSd3)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jdouble, Unsafe, peek3)(JNI_STDARGS, jlong ptr)
{
char *buf = J2P(ptr, char *);
return *((double *)buf);
}
-ACR_JNI_EXPORT(jstring, Unsafe, getSd4)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jstring, Unsafe, peek4)(JNI_STDARGS, jlong ptr)
{
char *buf = J2P(ptr, char *);
return AcrNewJavaStringA(env, buf);
}
-ACR_JNI_EXPORT(jstring, Unsafe, getSd5)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jstring, Unsafe, peek5)(JNI_STDARGS, jlong ptr)
{
wchar_t *buf = J2P(ptr, wchar_t *);
return AcrNewJavaStringW(env, buf);
}
-ACR_JNI_EXPORT(jcharArray, Unsafe, getSd6)(JNI_STDARGS, jlong ptr)
+ACR_JNI_EXPORT(jcharArray, Unsafe, peek6)(JNI_STDARGS, jlong ptr)
{
wchar_t *buf = J2P(ptr, wchar_t *);
return AcrNewJavaMszArrayW(env, buf);
}
+ACR_JNI_EXPORT(jlong, Unsafe, peek7)(JNI_STDARGS, jlong ptr)
+{
+ char **buf = J2P(ptr, char **);
+ if (buf == 0)
+ return 0;
+ else
+ return P2J(*buf);
+}
+
+ACR_JNI_EXPORT(jlong, Unsafe, addr0)(JNI_STDARGS, jbyteArray ba)
+{
+ jlong adr;
+ void *ptr;
+
+ if (IS_JOBJECT_NULL(ba))
+ return 0;
+ ptr = (*env)->GetPrimitiveArrayCritical(env, ba, 0);
+ adr = P2J(ptr);
+ (*env)->ReleasePrimitiveArrayCritical(env, ba, ptr, 0);
+ return adr;
+}
+
#if defined(ENABLE_TEST_PRIVATE)
ACR_JNI_EXPORT(jint, TestUnsafe, test0)(JNI_STDARGS, jobject o, jint off)
{
@@ -253,4 +273,16 @@ ACR_JNI_EXPORT(jint, TestUnsafe, test0)(
}
return 0;
}
+
+ACR_JNI_EXPORT(jobject, TestUnsafe, test1)(JNI_STDARGS, jobject o, jint off)
+{
+ if (o != 0 && off > 0) {
+ char *oa = *(char **)o;
+ if (oa != 0) {
+ return (jobject)(oa + (ptrdiff_t)off);
+ }
+ }
+ return 0;
+}
+
#endif
Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java?rev=1098468&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java Mon May 2 04:04:22 2011
@@ -0,0 +1,131 @@
+/* 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.net;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.DatagramSocket;
+import java.net.DatagramSocketImpl;
+import java.net.Socket;
+import java.net.SocketImpl;
+import java.net.ServerSocket;
+import java.net.SocketException;
+import org.testng.annotations.*;
+import org.testng.Assert;
+
+public class TestNetworkImpl extends Assert
+{
+
+ @Test(groups = { "core" })
+ public void boundServerSocket()
+ throws IOException
+ {
+ // Create socket bound to the first free port
+ //
+ ServerSocket ss = new ServerSocket(0);
+ assertNotNull(SocketInstance.getFileDescriptor(ss));
+ assertFalse(SocketInstance.getNativeDescriptor(ss) == -1);
+ }
+
+ @Test(groups = { "core" })
+ public void bindServerSocket()
+ throws IOException
+ {
+ // Create unbound socket
+ // FileDescriptor is null until bind call
+ //
+ ServerSocket ss = new ServerSocket();
+ assertNull(SocketInstance.getFileDescriptor(ss));
+ assertTrue(SocketInstance.getNativeDescriptor(ss) == -1);
+ ss.bind(null);
+ assertNotNull(SocketInstance.getFileDescriptor(ss));
+ assertFalse(SocketInstance.getNativeDescriptor(ss) == -1);
+ }
+
+ @Test(groups = { "core" })
+ public void unboudSocket()
+ throws IOException
+ {
+ // Create unbound socket
+ // FileDescriptor is null until bind call
+ //
+ Socket s = new Socket();
+ assertNull(SocketInstance.getFileDescriptor(s));
+ }
+
+ class Worker extends Thread
+ {
+ ServerSocket ss;
+ public Worker(ServerSocket ss)
+ {
+ this.ss = ss;
+ }
+
+ public void run() {
+ try {
+ Socket s = ss.accept();
+ assertNotNull(SocketInstance.getFileDescriptor(s));
+ } catch (Exception x) {
+ fail("Accept failed " + x.toString());
+ }
+ }
+ }
+
+ @Test(groups = { "core" })
+ public void connectSocket()
+ throws IOException
+ {
+ ServerSocket ss = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
+ Worker w = new Worker(ss);
+ w.start();
+ try {
+
+ Thread.sleep(500);
+ } catch (InterruptedException x) {
+ // Ignore
+ }
+ // Create unbound socket
+ // FileDescriptor is null until bind call
+ //
+ Socket s = new Socket("127.0.0.1", ss.getLocalPort());
+ // Check various FileDescriptor instances for the Socket
+ FileDescriptor fd = SocketInstance.getFileDescriptor(s);
+ assertNotNull(fd);
+ FileOutputStream fs = (FileOutputStream)s.getOutputStream();
+ FileInputStream fi = (FileInputStream)s.getInputStream();
+ assertEquals(fd, fs.getFD());
+ assertEquals(fd, fi.getFD());
+ assertEquals(fs.getFD(), fi.getFD());
+ s.close();
+ }
+
+ @Test(groups = { "core" })
+ public void boundDatagramSocket()
+ throws IOException
+ {
+ // Create datagram socket bound to the first free port
+ //
+ DatagramSocket s = new DatagramSocket();
+ assertNotNull(DatagramSocketInstance.getFileDescriptor(s));
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java?rev=1098468&r1=1098467&r2=1098468&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java Mon May 2 04:04:22 2011
@@ -25,7 +25,10 @@ import org.apache.commons.runtime.io.Uti
public class TestUnsafe extends Assert
{
private int i = 12345;
- private static native int test0(Object o, int off);
+ private String s = "hello world";
+
+ private static native int test0(Object o, int off);
+ private static native Object test1(Object o, int off);
@Test(groups = { "core" })
public void isSupported()
@@ -45,6 +48,14 @@ public class TestUnsafe extends Assert
}
@Test(groups = { "private" })
+ public void getDirectObject()
+ throws Exception
+ {
+ int off = Unsafe.objectFieldOffset(TestUnsafe.class.getDeclaredField("s"));
+ assertEquals((String)test1(this, off), "hello world");
+ }
+
+ @Test(groups = { "private" })
public void nativeFileDescriptor()
throws Exception
{