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/20 15:58:39 UTC
svn commit: r1095413 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/
java/org/apache/commons/runtime/platform/unix/ native/os/unix/
native/os/win32/ test/org/apache/commons/runtime/
Author: mturk
Date: Wed Apr 20 13:58:39 2011
New Revision: 1095413
URL: http://svn.apache.org/viewvc?rev=1095413&view=rev
Log:
Compress init into a single native call
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java
commons/sandbox/runtime/trunk/src/main/native/os/unix/platform.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java?rev=1095413&r1=1095412&r2=1095413&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java Wed Apr 20 13:58:39 2011
@@ -45,9 +45,7 @@ final class Platform
/*
* Get Platform integer property value.
*/
- private static native void init0(int cp);
- private static native void init1(int[] p);
- private static native void init2(long[] p);
+ private static native void init0(int cp, long[] p);
private static final int getDefaultCharset()
{
int cs;
@@ -73,26 +71,22 @@ final class Platform
}
static {
- int [] i = new int[16];
- long [] s = new long[8];
+ long [] s = new long[16];
+ init0(getDefaultCharset(), s);
- init0(getDefaultCharset());
- init1(i);
- init2(s);
-
- SIZEOF_INT = i[0];
- SIZEOF_LONG = i[1];
- SIZEOF_SIZE_T = i[2];
- SIZEOF_POINTER = i[3];
- SIZEOF_WCHAR_T = i[4];
- DATA_MODEL = i[5];
- MAX_PATH_ELEMENT = i[6];
- MAX_PATH = i[7];
- PAGESIZE = i[8];
- ALLOCTION_GRANULARITY = i[9];
- SIZE_T_MAX = s[0];
- SHMMIN = s[1];
- SHMMAX = s[2];
+ SIZEOF_INT = (int)s[0];
+ SIZEOF_LONG = (int)s[1];
+ SIZEOF_SIZE_T = (int)s[2];
+ SIZEOF_POINTER = (int)s[3];
+ SIZEOF_WCHAR_T = (int)s[4];
+ DATA_MODEL = (int)s[5];
+ MAX_PATH_ELEMENT = (int)s[6];
+ MAX_PATH = (int)s[7];
+ PAGESIZE = (int)s[8];
+ ALLOCTION_GRANULARITY = (int)s[9];
+ SIZE_T_MAX = s[10];
+ SHMMIN = s[11];
+ SHMMAX = s[12];
}
/**
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java?rev=1095413&r1=1095412&r2=1095413&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java Wed Apr 20 13:58:39 2011
@@ -15,6 +15,7 @@
*/
package org.apache.commons.runtime.platform.unix;
+import org.apache.commons.runtime.Limits;
import org.apache.commons.runtime.Shm;
import org.apache.commons.runtime.ShmImpl;
import org.apache.commons.runtime.AlreadyExistsException;
@@ -42,6 +43,8 @@ final class PosixShmImpl extends ShmImpl
AlreadyExistsException,
SystemException
{
+ if (size < Limits.SHMMIN || size > Limits.SHMMAX)
+ throw new IllegalArgumentException("Shared memory size is outside the limits.");
return new PosixShm(name, size);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/platform.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/platform.c?rev=1095413&r1=1095412&r2=1095413&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/platform.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/platform.c Wed Apr 20 13:58:39 2011
@@ -22,8 +22,9 @@
extern int acr_native_codepage;
-ACR_JNI_EXPORT(void, Platform, init0)(JNI_STDARGS, jint cp)
+ACR_JNI_EXPORT(void, Platform, init0)(JNI_STDARGS, jint cp, jlongArray p)
{
+ jlong sa[16];
UNREFERENCED_STDARGS;
acr_native_codepage = cp;
@@ -32,50 +33,32 @@ ACR_JNI_EXPORT(void, Platform, init0)(JN
acr_native_codepage = AcrGetNativeCodePage(nl_langinfo(CODESET));
setlocale(LC_ALL, sls);
}
-}
-
-ACR_JNI_EXPORT(void, Platform, init1)(JNI_STDARGS, jintArray p)
-{
- jint ia[16];
-
- UNREFERENCED_OBJECT;
-
- ia[0] = ISIZEOF(int);
- ia[1] = ISIZEOF(long);
- ia[2] = ISIZEOF(size_t);
- ia[3] = ISIZEOF(void *);
- ia[4] = ISIZEOF(wchar_t);
+ sa[0] = sizeof(int);
+ sa[1] = sizeof(long);
+ sa[2] = sizeof(size_t);
+ sa[3] = sizeof(void *);
+ sa[4] = sizeof(wchar_t);
#if CC_SIZEOF_VOIDP == 8
- ia[5] = 64;
+ sa[5] = 64;
#else
- ia[5] = 32;
+ sa[5] = 32;
#endif
- ia[6] = PATH_MAX - 2;
- ia[7] = PATH_MAX;
- ia[8] = (jint)getpagesize();
- ia[9] = ia[8];
-
- (*env)->SetIntArrayRegion(env, p, 0, 16, ia);
-}
-
-ACR_JNI_EXPORT(void, Platform, init2)(JNI_STDARGS, jlongArray p)
-{
- jlong sa[8];
-
- UNREFERENCED_OBJECT;
-
- sa[0] = SIZE_T_MAX;
-#if defined(SHMMIN)
- sa[1] = SHMMIN;
+ sa[6] = PATH_MAX - 2;
+ sa[7] = PATH_MAX;
+ sa[8] = getpagesize();
+ sa[9] = sa[8];
+ sa[10] = SIZE_T_MAX;
+#if defined(SHMMIN)
+ sa[11] = SHMMIN;
#else
- sa[1] = getpagesize();
+ sa[11] = sa[8];
#endif
#if defined(SHMMAX)
- sa[2] = SHMMAX;
+ sa[12] = SHMMAX;
#else
- sa[2] = SIZE_T_MAX;
+ sa[12] = SIZE_T_MAX;
#endif
- (*env)->SetLongArrayRegion(env, p, 0, 8, sa);
+ (*env)->SetLongArrayRegion(env, p, 0, 16, sa);
}
ACR_JNI_EXPORT(jboolean, Platform, supported0)(JNI_STDARGS)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c?rev=1095413&r1=1095412&r2=1095413&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c Wed Apr 20 13:58:39 2011
@@ -23,52 +23,36 @@
extern int acr_native_codepage;
extern LPOSVERSIONINFOEXA acr_osver;
+extern LPSYSTEM_INFO acr_osinf;
-ACR_JNI_EXPORT(void, Platform, init0)(JNI_STDARGS, jint cp)
+ACR_JNI_EXPORT(void, Platform, init0)(JNI_STDARGS, jint cp, jlongArray p)
{
+ jlong sa[16];
UNREFERENCED_STDARGS;
acr_native_codepage = cp;
if (acr_native_codepage == -1) {
acr_native_codepage = ACR_CP_DEFAULT;
}
-}
-
-ACR_JNI_EXPORT(void, Platform, init1)(JNI_STDARGS, jintArray p)
-{
- jint ia[16];
-
- UNREFERENCED_OBJECT;
- (*env)->GetIntArrayRegion(env, p, 0, 16, ia);
-
- ia[0] = ISIZEOF(int);
- ia[1] = ISIZEOF(long);
- ia[2] = ISIZEOF(size_t);
- ia[3] = ISIZEOF(void *);
- ia[4] = ISIZEOF(wchar_t);
+ sa[0] = sizeof(int);
+ sa[1] = sizeof(long);
+ sa[2] = sizeof(size_t);
+ sa[3] = sizeof(void *);
+ sa[4] = sizeof(wchar_t);
#if CC_SIZEOF_VOIDP == 8
- ia[5] = 64;
+ sa[5] = 64;
#else
- ia[5] = 32;
+ sa[5] = 32;
#endif
- ia[6] = PATH_MAX - 2;
- ia[7] = PATH_MAX;
- ia[8] = (jint)getpagesize();
- ia[9] = ia[8];
-
- (*env)->SetIntArrayRegion(env, p, 0, 16, ia);
-}
-
-ACR_JNI_EXPORT(void, Platform, init2)(JNI_STDARGS, jlongArray p)
-{
- jlong sa[8];
-
- UNREFERENCED_OBJECT;
+ sa[6] = MAX_PATH - 12;
+ sa[7] = MAX_PATH;
+ sa[8] = acr_osinf->dwPageSize;
+ sa[9] = acr_osinf->dwAllocationGranularity;
+ sa[10] = SIZE_T_MAX;
+ sa[11] = sa[8];
+ sa[12] = SIZE_T_MAX;
- sa[0] = SIZE_T_MAX;
- sa[1] = getpagesize();
- sa[2] = SIZE_T_MAX;
- (*env)->SetLongArrayRegion(env, p, 0, 8, sa);
+ (*env)->SetLongArrayRegion(env, p, 0, 16, sa);
}
ACR_JNI_EXPORT(jboolean, Platform, supported0)(JNI_STDARGS)
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java?rev=1095413&r1=1095412&r2=1095413&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java Wed Apr 20 13:58:39 2011
@@ -37,6 +37,8 @@ public class TestShm extends Assert
} catch (Exception x) {
// Ignore
}
+ System.out.println("[parent] Creating shared memory [" + Limits.SHMMIN + ".." + Limits.SHMMAX + "]" );
+ System.out.flush();
Semaphore s = Semaphore.create(semname, 0);
assertNotNull(s);
Shm m = Shm.create(shmname, shmsize);