Immortal Memory in Simulator

I am having a trouble simulating SNI calls that copy data into immortal memory. For some reason, the application works fine on the hardware but the mock does not copy anything into the immortal space.

In my application I have:

import ej.bon.Immortals;

public class MySNI {

private static final byte[] readData;

static {
	byte[] immortalData = new byte[100];
	readData= (byte[]) Immortals.setImmortal(readData);
}

public static void test (void) {
	copyDataNative(readData);
	string temp = new String(readData, 0, 100);
	system.out.println(string);
}

private static native int copyDataNative(double readData[]);

}

And in my mock I have:

public class MySNI {

private static native int copyDataNative(double readData[]){
	String temp = "Success!";
	System.arraycopy(temp.getBytes(), 0, data, 0, temp.length());
	return temp.length();
}

}

When I step through the code the mock returns the expected value but the array is completely empty.

Update: It appears that the first call to this function does not populate the immortal memory but that subsequent calls do…

This is very strange and I do not want to have to call each SNI function that uses immortal memory twice if I can avoid it.

Hi @ssampson,

When using Immortal memory in your mocks, you need to explicitly flush and refresh the content.
For this you can use the functions

HIL.getInstance().refreshContent(array);
HIL.getInstance().flushContent(array);

This will make:

public class MySNI {

private static native int copyDataNative(double readData[]){
	String temp = "Success!";
	System.arraycopy(temp.getBytes(), 0, readData, 0, temp.length());
        HIL.getInstance().flushContent(readData);
	return temp.length();
}

}

For more informatuion, you can have look at the developer guide Chapter 20.3.4

Regards,

That’s great Pierre thank you! Unfortunately, it appears that we are now intermittently observing the issue on hardware as well. One of your colleagues mentioned it may be the Cortex M7 cache causing this so that is our next investigation. When the JVM makes a native C call that is to write to immortal memory I can see in the memory inspection window that it is in fact being set, but upon returning to Java the application appears to have the data from the last call.