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:37:21 UTC
svn commit: r1098476 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/ java/org/apache/commons/runtime/util/
native/os/bsdx/ native/os/darwin/ native/os/linux/ native/os/solaris/
native/os/win32/ native/shared/ test/org/apa...
Author: mturk
Date: Mon May 2 04:37:20 2011
New Revision: 1098476
URL: http://svn.apache.org/viewvc?rev=1098476&view=rev
Log:
Use Unsafe for accessing the String internal array
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Array.java
commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c
commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestArray.java
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.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=1098476&r1=1098475&r2=1098476&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:37:20 2011
@@ -102,4 +102,12 @@ public final class Unsafe
throw new IllegalArgumentException();
return getOffset1(field);
}
+
+ /**
+ * Get the {@code str} private character array.
+ */
+ public static native final char[] getStringChars(String str);
+
+
+
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java Mon May 2 04:37:20 2011
@@ -16,6 +16,7 @@
package org.apache.commons.runtime;
+import java.io.File;
/** Virtual Machine various info.
*
* @since Runtime 1.0
@@ -39,5 +40,18 @@ public final class Vm
*/
public static native int getParentPid();
- public static native String self();
+ public static final File exec;
+ public static native String exe0();
+
+ static {
+ exec = new File(exe0());
+ }
+
+ /**
+ * Returns full path to the current JVM executable.
+ */
+ public static final File executable()
+ {
+ return exec;
+ }
}
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=1098476&r1=1098475&r2=1098476&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 Mon May 2 04:37:20 2011
@@ -193,9 +193,5 @@ 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/os/bsdx/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c Mon May 2 04:37:20 2011
@@ -90,7 +90,7 @@ ACR_JNI_EXPORT(jstring, Os, getVersion)(
return CSTR_TO_JSTRING(_unknown);
}
-ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+ACR_JNI_EXPORT(jstring, Vm, exe0)(JNI_STDARGS)
{
char buf[PATH_MAX];
int mib[4];
Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c Mon May 2 04:37:20 2011
@@ -91,7 +91,7 @@ ACR_JNI_EXPORT(jstring, Os, getVersion)(
return CSTR_TO_JSTRING(_unknown);
}
-ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+ACR_JNI_EXPORT(jstring, Vm, exe0)(JNI_STDARGS)
{
char path[PATH_MAX];
Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c Mon May 2 04:37:20 2011
@@ -83,7 +83,7 @@ ACR_JNI_EXPORT(jstring, Os, getVersion)(
return CSTR_TO_JSTRING(_unknown);
}
-ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+ACR_JNI_EXPORT(jstring, Vm, exe0)(JNI_STDARGS)
{
char buf[PATH_MAX];
ssize_t sz;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c Mon May 2 04:37:20 2011
@@ -88,7 +88,7 @@ ACR_JNI_EXPORT(jstring, Os, getVersion)(
return CSTR_TO_JSTRING(buf);
}
-ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+ACR_JNI_EXPORT(jstring, Vm, exe0)(JNI_STDARGS)
{
char buf[PATH_MAX];
const char *en;
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=1098476&r1=1098475&r2=1098476&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 Mon May 2 04:37:20 2011
@@ -113,7 +113,7 @@ finally:
return ppid;
}
-ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+ACR_JNI_EXPORT(jstring, Vm, exe0)(JNI_STDARGS)
{
wchar_t ipath[PATH_MAX];
wchar_t lpath[ACR_PATH_MAX];
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=1098476&r1=1098475&r2=1098476&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:37:20 2011
@@ -16,6 +16,7 @@
#include "acr/string.h"
#include "acr/clazz.h"
+#include "acr/unsafe.h"
J_DECLARE_CLAZZ = {
INVALID_FIELD_BASE,
@@ -59,6 +60,7 @@ ACR_CLASS_CTOR(String)
J_LOAD_METHOD(0001);
J_LOAD_METHOD(0002);
J_LOAD_IFIELD(0000);
+ UNSAFE_IFIELD(0000);
_clazzn.u = 1;
return JNI_TRUE;
@@ -1229,13 +1231,19 @@ AcrGetJavaStringArrayW(JNI_STDENV, jobje
return ret;
}
-ACR_UTIL_EXPORT(jcharArray, Array, get)(JNI_STDARGS,
- jstring str)
+ACR_JNI_EXPORT(jcharArray, Unsafe, getStringChars)(JNI_STDARGS, jstring str)
{
- if (IS_JOBJECT_VALID(str))
- return GET_IFIELD_O(0000, str);
- else
- return 0;
+ if (IS_JOBJECT_VALID(str)) {
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)str;
+ if (oa != 0)
+ return (jobject)(oa + J4FLD_PTR(0000));
+ }
+ else if (CLAZZ_LOADED) {
+ return GET_IFIELD_O(0000, str);
+ }
+ }
+ return 0;
}
#if defined(ENABLE_TEST_PRIVATE)
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=1098476&r1=1098475&r2=1098476&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 Mon May 2 04:37:20 2011
@@ -40,16 +40,4 @@ public class TestArray extends Assert
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');
- }
-
}
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java Mon May 2 04:37:20 2011
@@ -100,7 +100,7 @@ public class TestExec extends Assert
Exec e = Exec.newInstance();
assertNotNull(e);
ArrayList<String> args = new ArrayList<String>();
- args.add(Vm.self());
+ args.add(Vm.executable().getPath());
args.add("-version");
e.redirectOutputStream(true);
int r = e.run(args);
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java?rev=1098476&r1=1098475&r2=1098476&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java Mon May 2 04:37:20 2011
@@ -57,4 +57,17 @@ public class TestString extends Assert
assertEquals(test2(c), 3);
}
+ @Test(groups = { "private" })
+ public void stringPrivate()
+ throws Exception
+ {
+ final char[] ca = Unsafe.getStringChars("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');
+ }
+
+
}