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/04/29 09:57:09 UTC
svn commit: r1097717 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/
java/org/apache/commons/runtime/platform/unix/
java/org/apache/commons/runtime/platform/windows/
java/org/apache/commons/runtime/util/ native/include/ac...
Author: mturk
Date: Fri Apr 29 07:57:08 2011
New Revision: 1097717
URL: http://svn.apache.org/viewvc?rev=1097717&view=rev
Log:
Get String private array getter
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SysVShm.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsShm.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Array.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.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/test/org/apache/commons/runtime/TestArray.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java Fri Apr 29 07:57:08 2011
@@ -73,7 +73,7 @@ public abstract class Shm implements Syn
* suitable (unused) address at which to attach the segment.
*/
public abstract Pointer attach(long address, boolean readOnly)
- throws IOException;
+ throws IOException, OutOfMemoryError;
/**
* Attaches the shared memory segment to the address
@@ -82,7 +82,7 @@ public abstract class Shm implements Syn
* suitable (unused) address at which to attach the segment.
*/
public Pointer attach(boolean readOnly)
- throws IOException
+ throws IOException, OutOfMemoryError
{
return attach(0L, readOnly);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java Fri Apr 29 07:57:08 2011
@@ -20,8 +20,8 @@ import org.apache.commons.runtime.Status
import org.apache.commons.runtime.AlreadyExistsException;
import org.apache.commons.runtime.NoSuchObjectException;
import org.apache.commons.runtime.SystemException;
-import org.apache.commons.runtime.io.RuntimeIOException;
import org.apache.commons.runtime.io.ClosedDescriptorException;
+import java.io.IOException;
/**
* Posix Api class.
@@ -113,5 +113,7 @@ final class Posix
public static final int HEAP_POINTER = 1;
public static final int SLICE_POINTER = 2;
public static final int CONST_POINTER = 3;
- public static native Pointer pointer(long addr, long length, int type);
+ public static native Pointer pointer(long addr, long length, int type)
+ throws OutOfMemoryError;
+
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java Fri Apr 29 07:57:08 2011
@@ -102,7 +102,7 @@ final class PosixShm extends Shm
@Override
public final Pointer attach(long addr, boolean readOnly)
- throws IOException
+ throws IOException, OutOfMemoryError
{
if (fd == -1)
throw new ClosedDescriptorException();
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SysVShm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SysVShm.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SysVShm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SysVShm.java Fri Apr 29 07:57:08 2011
@@ -90,7 +90,7 @@ final class SysVShm extends Shm
@Override
public final Pointer attach(long addr, boolean readOnly)
- throws IOException
+ throws IOException, OutOfMemoryError
{
if (fd == -1)
throw new ClosedDescriptorException();
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java Fri Apr 29 07:57:08 2011
@@ -22,9 +22,8 @@ import org.apache.commons.runtime.Alread
import org.apache.commons.runtime.NoSuchObjectException;
import org.apache.commons.runtime.SystemException;
import org.apache.commons.runtime.util.Utils;
-import org.apache.commons.runtime.io.RuntimeIOException;
import org.apache.commons.runtime.io.ClosedDescriptorException;
-
+import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
/**
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java Fri Apr 29 07:57:08 2011
@@ -21,8 +21,8 @@ import org.apache.commons.runtime.Status
import org.apache.commons.runtime.AlreadyExistsException;
import org.apache.commons.runtime.NoSuchObjectException;
import org.apache.commons.runtime.SystemException;
-import org.apache.commons.runtime.io.RuntimeIOException;
import org.apache.commons.runtime.io.ClosedDescriptorException;
+import java.io.IOException;
/**
* Win32 API class.
@@ -144,6 +144,7 @@ final class Win32
public static final int HEAP_POINTER = 1;
public static final int SLICE_POINTER = 2;
public static final int CONST_POINTER = 3;
- public static native Pointer pointer(long addr, long len, int type);
+ public static native Pointer pointer(long addr, long len, int type)
+ throws OutOfMemoryError;
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsShm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsShm.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsShm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsShm.java Fri Apr 29 07:57:08 2011
@@ -124,7 +124,7 @@ final class WindowsShm extends Shm
@Override
public final Pointer attach(long addr, boolean readOnly)
- throws IOException
+ throws IOException, OutOfMemoryError
{
if (handle == 0)
throw new InvalidHandleException();
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Array.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Array.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Array.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Array.java Fri Apr 29 07:57:08 2011
@@ -193,5 +193,9 @@ public final class Array
return memcmp0(src, srcPos, elemSize1, dst, dstPos, elemSize2, length);
}
+ /**
+ * Get the {@code str} private character array.
+ */
+ public static native final char[] get(String str);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Fri Apr 29 07:57:08 2011
@@ -36,6 +36,7 @@
/* Exception class enums */
enum {
+ ACR_EX_ENOINST, /* java/lang/InstatiationException */
ACR_EX_ERUNTIME, /* java/lang/RuntimeException */
ACR_EX_ENOMEM, /* java/lang/OutOfMemoryError */
ACR_EX_ENULL, /* java/lang/NullPointerException */
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=1097717&r1=1097716&r2=1097717&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 Fri Apr 29 07:57:08 2011
@@ -603,10 +603,22 @@ ACR_UNX_EXPORT(jlong, PosixExec, run0)(J
WITH_CSTR(executable) {
WITH_CSTR(cwd) {
char **argp;
- char **envs;
+ char **envs = 0;
argp = AcrGetJavaStringArrayA(env, args);
- envs = AcrGetJavaStringArrayA(env, envp);
+ if (argp == 0) {
+ rv = ACR_PARENT_ERROR;
+ rc = ACR_GET_OS_ERROR();
+ goto cleanup;
+ }
+ if (envp != 0) {
+ envs = AcrGetJavaStringArrayA(env, envp);
+ if (envs == 0) {
+ rv = ACR_PARENT_ERROR;
+ rc = ACR_GET_OS_ERROR();
+ goto cleanup;
+ }
+ }
if (inp != 0) {
ib = &bb[0];
ib->len = (*env)->GetArrayLength(env, inp);
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=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c Fri Apr 29 07:57:08 2011
@@ -57,15 +57,11 @@ ACR_CLASS_DTOR(ConstPointer)
jobject
AcrNewConstPointer(JNI_STDENV, void *ptr, size_t len)
{
- jobject po;
-
if (!CLAZZ_LOADED) {
+ ACR_THROW(ACR_EX_ENOINST, 0);
return 0;
}
- po = (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
- if (po == 0)
- ACR_SET_OS_ERROR(ACR_ENOMEM);
- return po;
+ return (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
}
ACR_JNI_EXPORT(jobject, Pointer, nullptr0)(JNI_STDARGS)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Apr 29 07:57:08 2011
@@ -30,7 +30,8 @@ static struct {
jclass clazz;
const char *name;
} _throw_classes[ACR_EX_LEN] = {
- { 0, "java/lang/RuntimeException" },
+ { 0, "java/lang/InstatiationException" }, /* ENOINIT */
+ { 0, "java/lang/RuntimeException" }, /* EGENERAL */
{ 0, "java/lang/OutOfMemoryError" }, /* ENOMEM */
{ 0, "java/lang/NullPointerException" }, /* EISNULL */
{ 0, "java/lang/UnsupportedOperationException" }, /* ENOSYS */
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=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Apr 29 07:57:08 2011
@@ -77,15 +77,11 @@ ACR_CLASS_DTOR(HeapPointer)
jobject
AcrNewHeapPointer(JNI_STDENV, void *ptr, size_t len)
{
- jobject po;
-
if (!CLAZZ_LOADED) {
+ ACR_THROW(ACR_EX_ENOINST, 0);
return 0;
}
- po = (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
- if (po == 0)
- ACR_SET_OS_ERROR(ACR_ENOMEM);
- return po;
+ return (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
}
ACR_JNI_EXPORT(void, HeapPointer, free0)(JNI_STDARGS, jlong ptr)
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=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c Fri Apr 29 07:57:08 2011
@@ -57,13 +57,9 @@ ACR_CLASS_DTOR(SlicePointer)
jobject
AcrNewSlicePointer(JNI_STDENV, void *ptr, size_t len)
{
- jobject po;
-
if (!CLAZZ_LOADED) {
+ ACR_THROW(ACR_EX_ENOINST, 0);
return 0;
}
- po = (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
- if (po == 0)
- ACR_SET_OS_ERROR(ACR_ENOMEM);
- return po;
+ return (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
}
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=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Fri Apr 29 07:57:08 2011
@@ -43,6 +43,14 @@ J_DECLARE_M_ID(0002) = {
"()[B"
};
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "value",
+ "[C"
+};
+
ACR_CLASS_CTOR(String)
{
int rv;
@@ -52,6 +60,7 @@ ACR_CLASS_CTOR(String)
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
J_LOAD_METHOD(0002);
+ J_LOAD_IFIELD(0000);
_clazzn.u = 1;
return 0;
@@ -1121,6 +1130,15 @@ AcrGetJavaStringArrayW(JNI_STDENV, jobje
return ret;
}
+ACR_UTIL_EXPORT(jcharArray, Array, get)(JNI_STDARGS,
+ jstring str)
+{
+ if (str != 0)
+ return GET_IFIELD_O(0000, str);
+ else
+ return 0;
+}
+
#if defined(ENABLE_TEST_PRIVATE)
ACR_JNI_EXPORT(jint, TestString, test0)(JNI_STDARGS, jstring s)
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestArray.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestArray.java?rev=1097717&r1=1097716&r2=1097717&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestArray.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestArray.java Fri Apr 29 07:57:08 2011
@@ -39,4 +39,17 @@ public class TestArray extends Assert
assertEquals((int)ba[4] & 0xff, 3);
assertEquals((int)ba[8] & 0xff, 4);
}
+
+ @Test(groups = { "core" })
+ public void stringPrivate()
+ throws Exception
+ {
+ final char[] ca = Array.get("string");
+ // bytes 0 .. 3 contains integer[1] (2)
+ // ### Assertion works on LSB machines only
+ assertEquals((int)ca[0], 's');
+ assertEquals((int)ca[1], 't');
+ assertEquals((int)ca[2], 'r');
+ }
+
}