You should be able to do this using JNI. Select an array of long sizes of your heap or a little smaller and call the JNI testing method.
package com.example.aslrtest; public class Test { private static native void test(long[] heapa); public void doTest() { long[] a=new long[size_of_available_heap/8]; for (long i=0; i!=a.length; i++) a[i]=i; test(a); System.out.println(a[0]); } }
Then with something like this JNI code, you can get the address of this array.
JNIEXPORT void JNICALL Java_com_example_aslrtest_Test_test(JNIEnv * env, jclass jc, jlongArray heapa) { jlong* heapp; jboolean jniNoCopy = JNI_FALSE; heapp = (*env)->GetLongArrayElements(env, heapa, &jniNoCopy); heapp[0] = (jlong)heapp; (*env)->ReleaseLongArrayElements(env,heapa,heapp,0); }
When this code is returned, the first element of the array must contain the address of the array.
Does it make sense is another question. Depends on what you do. I guess, probably not, but this is your call.
source share