Ich portiere einen Code von Linux zu Windows und da es keine Unterstützung für Linux Shared Memory-Segmente in Java gibt. Daher verwenden wir die Java Native Interface (JNI) für den Zugriff auf Shared Memory. Es funktioniert gut auf Linux-Plattform.JNI stürzt das Java in Windows 7
-Code für shmget:
JNIEXPORT jint JNICALL Java_emulatorinterface_communication_shm_SharedMem_shmget
(JNIEnv * env, jobject jobj, jint COUNT,jint MaxNumJavaThreads,jint EmuThreadsPerJavaThread,
jlong coremap, jint pid) {
uint64_t mask = coremap;
int size;//=sizeof(packet)*(COUNT+5)*MaxNumJavaThreads*EmuThreadsPerJavaThread;
char str[50];
int ptr;
#ifdef _WIN32
HANDLE hMapFile;
#endif
printf("hello");
size=sizeof(packet)*(COUNT+5)*MaxNumJavaThreads*EmuThreadsPerJavaThread;
/*if (sched_setaffinity(0, sizeof(mask), (cpu_set_t *)&mask) <0) {
perror("sched_setaffinity");
}*/
//set the global variables
gCOUNT = COUNT;
gMaxNumJavaThreads = MaxNumJavaThreads;
gEmuThreadsPerJavaThread = EmuThreadsPerJavaThread;
//size1 is the number of packets needed in the segment.
#ifdef _WIN32
_itoa(pid,str,10);
hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,
NULL, PAGE_READWRITE,
0,32, str);
if (hMapFile == NULL)
{
exit(1);
}
CloseHandle(hMapFile);
hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,
NULL, PAGE_READWRITE,
0,size, str);
if (hMapFile == NULL)
{
printf("Unable to create a shared mem file.");
exit(1);
}
if (hMapFile < 0)
{
return (-1);
}
/*
if((hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,
NULL, PAGE_READWRITE,
0,size, str))<0)
{
printf("error window %d\n",size);
return (-1);
}
*/
ptr=*((int*)(hMapFile));
return ptr; ///////////////error in return type
#else
Wenn ich eine andere Funktion in JNI zu verwenden Ich versuche, meine Java-Abstürze.
Fehler
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007feedf911be, pid=4696, tid=4216
#
# JRE version: Java(TM) SE Runtime Environment (8.0_77-b03) (build 1.8.0_77-b03)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.77-b03 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [JNIShm.dll+0x11be]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\workspace\tejasMinor\hs_err_pid4696.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Kann jemand zeigen, wo ist das Problem?
Sie meine Antwort geholfen hat? – manuell