docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY
/tmp/.X11-unix contains the unix domain socket file used by your running X11 application, but mounting it inside docker, the X11 app inside docker will happily access it.
31.95% iperf [kernel.kallsyms] [k] md5_transform 16.99% iperf [aesni_intel] [k] _aesni_enc1 3.14% iperf [kernel.kallsyms] [k] do_csum 2.50% iperf [kernel.kallsyms] [k] memcpy 2.16% iperf [kernel.kallsyms] [k] __ticket_spin_lock 1.78% iperf [aesni_intel] [k] _aesni_dec4 1.10% iperf [kernel.kallsyms] [k] nf_iterate 0.97% iperf [nf_conntrack] [k] ____nf_conntrack_find 0.91% iperf [kernel.kallsyms] [k] __slab_free 0.81% iperf [kernel.kallsyms] [k] skb_release_data 0.80% iperf [kernel.kallsyms] [k] fib_table_lookup 0.80% iperf [kernel.kallsyms] [k] memset 0.80% iperf [kernel.kallsyms] [k] __copy_user_nocache 0.77% iperf [cxgb4] [k] process_responses 0.77% iperf [ip_tables] [k] ipt_do_table 0.69% iperf [nf_conntrack] [k] __nf_conntrack_find_get 0.68% iperf [kernel.kallsyms] [k] md5_update 0.67% iperf [nf_conntrack] [k] nf_conntrack_in 0.56% iperf [nf_conntrack] [k] hash_conntrack_raw 0.52% iperf [kernel.kallsyms] [k] dst_release
add 10.0.0.216 10.0.0.11 ah 24500 -A hmac-md5 "1234567890123456"; add 10.0.0.216 10.0.0.11 esp 24501 -E 3des-cbc "123456789012123456789012"; spdadd 10.0.0.216 10.0.0.11 any -P out ipsec esp/transport//require ah/transport//require;
add 10.0.0.216 10.0.0.11 esp 24501 -E 3des-cbc "123456789012123456789012" -A hmac-md5 "1234567890123456"; spdadd 10.0.0.216 10.0.0.11 any -P out ipsec esp/transport//require ah/transport//require;
private static native void noopJni();
extern "C" JNIEXPORT void JNICALL
Java_com_foo_test_JniPerfTest_noopJni(
JNIEnv* env, jclass) {
}
private static native int sum(int[] src);
extern "C" JNIEXPORT jint JNICALL
Java_com_foo_test_JniPerfTest_sum(
JNIEnv* env, jclass, jintArray src) {
const jint size = env->GetArrayLength(src);
jint* data = env->GetIntArrayElements(src, 0);
jint sum = 0;
for (int i = 0; i < size; ++i) {
sum += data[i];
}
env->ReleaseIntArrayElements(src, data, 0);
return sum;
}
GetIntArrayElements to either pin the java array or make an copy from java array to native array. The reason that we have to call GetIntArrayElements is because another GC thread may move the data around during the native call. The Virtual Machine guarantees that the result of GetIntArrayElements points to a non-movable array of integers. The JVM will either "pin" down the array , or it will make a copy of the array into nonmovable memory. When the native code has finished using the array, it must call ReleaseIntArrayElements, which enables the JNI to copy back and free body if it is a copy of the original Java array, or "unpin" the Java array if it has been pinned in memory. Forgetting to do so will call memory leak.If the array size is large and the code only needs to access part of the array, it can call Get/Set<type>ArrayRegion functions, which will just make a copy of the given region instead of the whole array
GetPrimitiveArrayCritical, which is provided since Java 1.2. It will try to stop garbage collection on that array, and will provide direct access to the array pointer most of the time. The drawback of GetPrimitiveArrayCritical is that no blocking operation should be made between GetPrimitiveArrayCritical and ReleasePrimitiveArrayCritical, otherwise deadlock might happen. So code between the two calls should be treated as in critical section. Here is the code snippet:static native int sumCritical(int[] src);
extern "C" JNIEXPORT jint JNICALL
Java_com_foo_test_JniPerfTest_sumCritical(
JNIEnv* env, jclass, jintArray src) {
const jint size = env->GetArrayLength(src);
jint* data = (jint*) env->GetPrimitiveArrayCritical(src, 0);
jint sum = 0;
for (int i = 0; i < size; ++i) {
sum += data[i];
}
env->ReleasePrimitiveArrayCritical(src, data, 0);
return sum;
}
static int javaSum(int[] src) {
int result = 0;
for (int i = 0; i < src.length; ++i) {
result += src[i];
}
return result;
}
| Pure Java | JNI GetIntArrayElements | JNI GetPrimitiveArrayCritical |
| 493 ns | 1675 ns | 703 ns |
import _ "net/http/pprof"
go tool pprof http://localhost:6060/debug/pprof/heap
go tool pprof http://localhost:6060/debug/pprof/profile
go tool pprof http://localhost:6060/debug/pprof/