Author: mturk
Date: Fri Jul 3 09:30:54 2009
New Revision: 790835
URL:
http://svn.apache.org/viewvc?rev=790835&view=revLog:
Add ByReferencePointer
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer32.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer64.java (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/refptr.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NativePointer.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
commons/sandbox/runtime/trunk/src/main/native/os/linux/execmem.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java?rev=790835&view=auto==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java Fri Jul 3 09:30:54 2009
@@ -0,0 +1,33 @@
+/* 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;
+import java.lang.annotation.*;
+
+/**
+ * Annotation that represents the by reference {@code Pointer} parameter.
+ * <p>
+ * TODO: Describe ByReference usage
+ * </p>
+ * @since Runtime 1.0
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface ByReference
+{
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer.java?rev=790835&view=auto==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer.java Fri Jul 3 09:30:54 2009
@@ -0,0 +1,31 @@
+/* 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;
+
+import org.apache.commons.runtime.util.Utils;
+
+/**
+ * Represents the {@code Pointer} as buffer.
+ *
+ * @since Runtime 1.0
+ */
+@ByReference
+public interface ByReferencePointer extends Pointer
+{
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer32.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer32.java?rev=790835&view=auto==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer32.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer32.java Fri Jul 3 09:30:54 2009
@@ -0,0 +1,46 @@
+/* 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;
+
+import org.apache.commons.runtime.util.Utils;
+
+/** Represents the Operating System 32-bit by reference C/C++ pointer.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ * @since Runtime 1.0
+ */
+@ByReference
+class ByReferencePointer32 extends Pointer32 implements ByReferencePointer
+{
+
+ protected ByReferencePointer32()
+ {
+ }
+
+ /*
+ * Only created from JNI code.
+ */
+ private ByReferencePointer32(int ptr, int clr, int len)
+ {
+ POINTER = ptr;
+ CLEANUP = clr;
+ PLENGTH = len;
+ }
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer32.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer64.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer64.java?rev=790835&view=auto==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer64.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer64.java Fri Jul 3 09:30:54 2009
@@ -0,0 +1,46 @@
+/* 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;
+
+import org.apache.commons.runtime.util.Utils;
+
+/** Represents the Operating System 64-bit by reference C/C++ pointer.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ * @since Runtime 1.0
+ */
+@ByReference
+class ByReferencePointer64 extends Pointer64 implements ByReferencePointer
+{
+
+ protected ByReferencePointer64()
+ {
+ }
+
+ /*
+ * Only created from JNI code.
+ */
+ private ByReferencePointer64(long ptr, long clr, long len)
+ {
+ POINTER = ptr;
+ CLEANUP = clr;
+ PLENGTH = len;
+ }
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReferencePointer64.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NativePointer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NativePointer.java?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NativePointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NativePointer.java Fri Jul 3 09:30:54 2009
@@ -102,6 +102,17 @@
public abstract boolean IsNull();
/**
+ * Check if the pointer is to be used by reference
+ * @return true if the pointer has {@code ByReference} annotation.
+ * @see ByReference
+ */
+ public final boolean IsByReference()
+ {
+ return getClass().isAnnotationPresent(ByReference.class);
+ }
+
+
+ /**
* Compares this {@code Pointer} to the specified object.
*
* @param other a {@code Pointer}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Fri Jul 3 09:30:54 2009
@@ -60,6 +60,13 @@
public boolean IsNull();
/**
+ * Check if the pointer is to be used by reference
+ * @return true if the pointer has {@code ByReference} annotation.
+ * @see ByReference
+ */
+ public boolean IsByReference();
+
+ /**
* Compares this {@code Pointer} to the specified object.
*
* @param other a {@code Pointer}
@@ -71,7 +78,6 @@
@Override
public boolean equals(Object other);
-
/**
* Free the allocated resource by the Operating system.
* <p>
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java Fri Jul 3 09:30:54 2009
@@ -17,6 +17,7 @@
package org.apache.commons.runtime;
import org.apache.commons.runtime.util.Utils;
+import java.lang.annotation.Annotation;
/** Represents the Operating System 32-bit pointer C/C++ pointer.
* <p>
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Fri Jul 3 09:30:54 2009
@@ -85,6 +85,7 @@
$(SRCDIR)/shared/native.$(OBJ) \
$(SRCDIR)/shared/nbb.$(OBJ) \
$(SRCDIR)/shared/pointer.$(OBJ) \
+ $(SRCDIR)/shared/refptr.$(OBJ) \
$(SRCDIR)/shared/object.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
$(SRCDIR)/shared/tables.$(OBJ) \
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=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Jul 3 09:30:54 2009
@@ -79,6 +79,7 @@
$(SRCDIR)/shared/native.$(OBJ) \
$(SRCDIR)/shared/nbb.$(OBJ) \
$(SRCDIR)/shared/pointer.$(OBJ) \
+ $(SRCDIR)/shared/refptr.$(OBJ) \
$(SRCDIR)/shared/object.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
$(SRCDIR)/shared/tables.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h Fri Jul 3 09:30:54 2009
@@ -45,8 +45,8 @@
* @param len Length of the pointer.
* @param cb callback function to use on Pointer.finalize()
*/
-ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *env, void *p, size_t len,
- acr_pointer_cleanup_fn_t *cb);
+ACR_DECLARE(jobject) ACR_NewPointer(JNIEnv *env, void *p, size_t len,
+ acr_pointer_cleanup_fn_t *cb);
/**
* Create new Pointer array
@@ -100,8 +100,33 @@
* @param len Length of the pointer.
* @param cb callback function to use on Pointer.finalize()
*/
-ACR_DECLARE(jobject) ACR_DirectBufferCreate(JNIEnv *env, void *p, size_t len,
- acr_pointer_cleanup_fn_t *cb);
+ACR_DECLARE(jobject) ACR_NewDirectBuffer(JNIEnv *env, void *p, size_t len,
+ acr_pointer_cleanup_fn_t *cb);
+
+/**
+ * Create new DirectBuffer array
+ * @param env Current JNI environment
+ * @param len Size of the new DirectBuffer array
+ */
+ACR_DECLARE(jobjectArray) ACR_NewDirectBufferArray(JNIEnv *env, jsize len);
+
+/**
+ * Create new ByReferencePointer class instance
+ * @param env Current JNI environment
+ * @param p Native pointer to wrap into Pointer class
+ * @param len Length of the pointer.
+ * @param cb callback function to use on Pointer.finalize()
+ */
+ACR_DECLARE(jobject) ACR_NewByReferencePointer(JNIEnv *env, void *p, size_t len,
+ acr_pointer_cleanup_fn_t *cb);
+
+/**
+ * Create new ByReferencePointer array
+ * @param env Current JNI environment
+ * @param len Size of the new ByReferencePointer array
+ */
+ACR_DECLARE(jobjectArray) ACR_NewByReferencePointerArray(JNIEnv *env,
+ jsize len);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/execmem.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/execmem.c?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/execmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/execmem.c Fri Jul 3 09:30:54 2009
@@ -145,7 +145,7 @@
EXEC_PAGE_OFF(mmw, ass) = (ptrdiff_t)mmx;
/* Create the Pointer class with default cleanup.
*/
- ptr = ACR_PointerCreate(_E, mmw, ass, execmem_pointer_cleanup);
+ ptr = ACR_NewPointer(_E, mmw, ass, execmem_pointer_cleanup);
if (!ptr) {
munmap(mmw, ass);
if (mmx)
@@ -170,8 +170,9 @@
dp = (void *)(EXEC_PAGE_OFF(sp, sl));
if (dp)
- po = ACR_PointerCreate(_E, dp, sl, NULL);
+ po = ACR_NewPointer(_E, dp, sl, NULL);
else
- po = ACR_PointerCreate(_E, sp, sl, NULL);
+ po = ACR_NewPointer(_E, sp, sl, NULL);
return po;
}
+
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=790835&r1=790834&r2=790835&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 Fri Jul 3 09:30:54 2009
@@ -72,7 +72,7 @@
if (mem) {
/* Create the Pointer class with default cleanup.
*/
- ptr = ACR_PointerCreate(_E, mem, ass, execmem_pointer_cleanup);
+ ptr = ACR_NewPointer(_E, mem, ass, execmem_pointer_cleanup);
if (!ptr) {
#ifdef ACR_USE_MMAP
munmap(mem, ass);
@@ -91,5 +91,6 @@
void *sp = ACR_PointerGet(_E, src, &sl);
UNREFERENCED_O;
- return ACR_PointerCreate(_E, sp, sl, NULL);
+ return ACR_NewPointer(_E, sp, sl, NULL);
}
+
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=790835&r1=790834&r2=790835&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 Fri Jul 3 09:30:54 2009
@@ -51,7 +51,7 @@
if (mem) {
/* Create the Pointer class with default cleanup.
*/
- ptr = ACR_PointerCreate(_E, mem, ass, execmem_pointer_cleanup);
+ ptr = ACR_NewPointer(_E, mem, ass, execmem_pointer_cleanup);
if (!ptr) {
VirtualFree(mem, 0, MEM_RELEASE);
}
@@ -68,5 +68,6 @@
void *sp = ACR_PointerGet(_E, src, &sl);
UNREFERENCED_O;
- return ACR_PointerCreate(_E, sp, sl, NULL);
+ return ACR_NewPointer(_E, sp, sl, NULL);
}
+
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=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Fri Jul 3 09:30:54 2009
@@ -372,6 +372,7 @@
/* Forward class loading declarations */
ACR_CLASS_LDEC(Descriptor);
ACR_CLASS_LDEC(NativePointer);
+ACR_CLASS_LDEC(ByReferencePointer);
ACR_CLASS_LDEC(DirectBuffer);
ACR_CLASS_LDEC(MbString);
ACR_CLASS_LDEC(Group);
@@ -383,6 +384,7 @@
ACR_CLASS_LRUN(Descriptor);
ACR_CLASS_LRUN(NativePointer);
+ ACR_CLASS_LRUN(ByReferencePointer);
ACR_CLASS_LRUN(DirectBuffer);
ACR_CLASS_LRUN(MbString);
ACR_CLASS_LRUN(Group);
@@ -400,6 +402,7 @@
ACR_CLASS_URUN(Descriptor);
ACR_CLASS_URUN(NativePointer);
+ ACR_CLASS_URUN(ByReferencePointer);
ACR_CLASS_URUN(DirectBuffer);
ACR_CLASS_URUN(MbString);
ACR_CLASS_URUN(Group);
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c Fri Jul 3 09:30:54 2009
@@ -93,8 +93,8 @@
return NULL;
}
-ACR_DECLARE(jobject) ACR_DirectBufferCreate(JNIEnv *_E, void *p, size_t len,
- acr_pointer_cleanup_fn_t *cb)
+ACR_DECLARE(jobject) ACR_NewDirectBuffer(JNIEnv *_E, void *p, size_t len,
+ acr_pointer_cleanup_fn_t *cb)
{
if (_clazzn.i && J4MID(0000))
return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000),
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Jul 3 09:30:54 2009
@@ -251,7 +251,7 @@
ACR_JNI_EXPORT_DECLARE(jobject, Memory, nullp0)(ACR_JNISTDARGS)
{
UNREFERENCED_O;
- return ACR_PointerCreate(_E, 0, 0, memory_pointer_cleanup);
+ return ACR_NewByReferencePointer(_E, NULL, 0, memory_pointer_cleanup);
}
ACR_JNI_EXPORT_DECLARE(jobject, Memory, malloc)(ACR_JNISTDARGS, jlong siz)
@@ -269,7 +269,7 @@
if (mem) {
/* Create the Pointer class with default cleanup.
*/
- ptr = ACR_PointerCreate(_E, mem, (size_t)siz, memory_pointer_cleanup);
+ ptr = ACR_NewPointer(_E, mem, (size_t)siz, memory_pointer_cleanup);
if (!ptr)
free(mem);
}
@@ -291,7 +291,7 @@
if (mem) {
/* Create the Pointer class with default cleanup.
*/
- ptr = ACR_PointerCreate(_E, mem, (size_t)siz, memory_pointer_cleanup);
+ ptr = ACR_NewPointer(_E, mem, (size_t)siz, memory_pointer_cleanup);
if (!ptr)
free(mem);
}
@@ -345,7 +345,7 @@
/* Create the Pointer class without the cleanup.
* Original object will clean the entire allocated memory.
*/
- return ACR_PointerCreate(_E, sp + so, ss, NULL);
+ return ACR_NewPointer(_E, sp + so, ss, NULL);
}
ACR_JNI_EXPORT_DECLARE(jobject, Memory, dup0)(ACR_JNISTDARGS,
@@ -378,7 +378,7 @@
/* Copy the original content */
ACR_TRY {
memcpy(dp, sp + so, ss);
- po = ACR_PointerCreate(_E, dp, ss, memory_pointer_cleanup);
+ po = ACR_NewPointer(_E, dp, ss, memory_pointer_cleanup);
} ACR_CATCH() {
ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, ACR_EFAULT);
}
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=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Jul 3 09:30:54 2009
@@ -129,7 +129,7 @@
if (!_clazzn.i) {
initp0(_E);
}
- return ACR_PointerCreate(_E, 0, 0, NULL);
+ return ACR_NewPointer(_E, 0, 0, NULL);
}
ACR_JNI_EXPORT_DECLARE(void, NativePointer, cleanup0)(ACR_JNISTDARGS)
@@ -223,8 +223,8 @@
}
}
-ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *_E, void *p, size_t len,
- acr_pointer_cleanup_fn_t *cb)
+ACR_DECLARE(jobject) ACR_NewPointer(JNIEnv *_E, void *p, size_t len,
+ acr_pointer_cleanup_fn_t *cb)
{
if (_clazzn.i && J4MID(0000))
return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000),
Added: commons/sandbox/runtime/trunk/src/main/native/shared/refptr.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/refptr.c?rev=790835&view=auto==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/refptr.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/refptr.c Fri Jul 3 09:30:54 2009
@@ -0,0 +1,107 @@
+/* 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.h"
+#include "acr_private.h"
+#include "acr_clazz.h"
+#include "acr_memory.h"
+#include "acr_pointer.h"
+#include "acr_vm.h"
+
+#define ACR_WANT_MEMPROTECT
+#include "acr_error.h"
+
+/**
+ * ByReferencePointer utilities
+ */
+/**
+ * Pointer class utilities
+ */
+#if CC_SIZEOF_VOIDP == 8
+#define ACR_BRP_EXPORT_DECLARE(RT, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_ByReferencePointer64_##FN
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ ACR_CLASS_PATH "ByReferencePointer64"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "<init>",
+ "(JJJ)V"
+};
+
+#else
+#define ACR_BRP_EXPORT_DECLARE(RT, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_ByReferencePointer32_##FN
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ ACR_CLASS_PATH "ByReferencePointer32"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "<init>",
+ "(III)V"
+};
+
+#endif
+
+ACR_CLASS_LDEF(ByReferencePointer)
+{
+ int rv;
+
+ if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+ J_LOAD_METHOD(0000);
+
+ return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(ByReferencePointer)
+{
+ ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(jobjectArray) ACR_NewByReferencePointerArray(JNIEnv *_E, jsize len)
+{
+ if (_clazzn.i)
+ return (*_E)->NewObjectArray(_E, len, _clazzn.i, NULL);
+ else
+ return NULL;
+}
+
+ACR_DECLARE(jobject) ACR_NewByReferencePointer(JNIEnv *_E, void *p, size_t len,
+ acr_pointer_cleanup_fn_t *cb)
+{
+ if (_clazzn.i && J4MID(0000))
+ return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000),
+ P2N(p), P2N(cb), (acr_ptr_t)len);
+ else {
+ ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
+ return NULL;
+ }
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/refptr.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Fri Jul 3 09:30:54 2009
@@ -227,16 +227,29 @@
return 0;
}
+static int refcallback(void *p, size_t s)
+{
+ fprintf(stderr, "[native] ByReferencePointer callback called: %p - %d\n", p, s);
+ fflush(stderr);
+ return 0;
+}
+
ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test017)(ACR_JNISTDARGS, jint d)
{
- return ACR_PointerCreate(_E, I2P(d, void *), 0, callback);
+ return ACR_NewPointer(_E, I2P(d, void *), 0, callback);
}
ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test038)(ACR_JNISTDARGS, jint d)
{
- return ACR_DirectBufferCreate(_E, I2P(d, void *), 0, dbbcallback);
+ return ACR_NewDirectBuffer(_E, I2P(d, void *), 0, dbbcallback);
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test039)(ACR_JNISTDARGS, jint d)
+{
+
+ return ACR_NewByReferencePointer(_E, I2P(d, void *), 0, refcallback);
}
ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test018)(ACR_JNISTDARGS, jobject p)
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Fri Jul 3 09:30:54 2009
@@ -123,6 +123,14 @@
p.free();
}
+ public void testByReference()
+ throws Throwable
+ {
+ Pointer p = Memory.malloc();
+ assertNotNull("Pointer", p);
+ assertTrue("ByReference", p.IsByReference());
+ }
+
public void testExecutableMalloc()
throws Throwable
{
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=790835&r1=790834&r2=790835&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Fri Jul 3 09:30:54 2009
@@ -64,6 +64,7 @@
private static native int test016(int d);
private static native Pointer test017(int d);
private static native DirectBuffer test038(int d);
+ private static native Pointer test039(int d);
private static native int test018(Pointer p);
private static native int test019(Pointer p);
@@ -408,6 +409,25 @@
b.free();
}
+ public void testByrefNativePtrGet()
+ throws Throwable
+ {
+ Pointer b = test039(0xcafebabe);
+ assertNotNull("ByRefPointer", b);
+ int r = test019(b);
+ assertEquals("Result ", 1, r);
+ b.free();
+ int c = test019(b);
+ // Second call must return NULL
+ assertEquals("Result ", 0, c);
+
+ b = null;
+ System.gc();
+ // This should be enough for a gc
+ // from Pointer.finalize()
+ Thread.sleep(200);
+ }
+
public void testDescClassLoad()
throws Exception
{