JNA:A fatal error has been detected by the Java Runtime environment

Source: Internet
Author: User
One of the common errors in using JNA to tune DLLs
The error message is as follows
#
# A Fatal error has been detected by the Java Runtime environment:
#
# exception_access_violation (0xc0000005) at pc=0x72ff2989, pid=1276, tid=4516
#-This line below indicates the JRE used, the JVM version
# JRE VERSION:6.0_37-B06
# Java Vm:java HotSpot (TM) Client VM (20.12-b01 mixed Mode windows-x86)
--The wrong location (from c)
# Problematic Frame:
# C [msvcp80.dll+0x2989]
#
# If You are would like to submit a bug and please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# problematic frame for where to the the bug.
#

A bunch of information underneath
---------------T H R E A D---------------

Current thread (0x021ea400): Javathread "Main" [_thread_in_native, id=4516, Stack (0x00390000,0x003e0000)]

siginfo:exceptioncode=0xc0000005, reading address 0x00000034

Registers:
eax=0x00000008, ebx=0x730c775d, ecx=0x0000001c, EDX=0XED646BFF
Esp=0x003deec8, Ebp=0x003deedc, esi=0x0000001c, Edi=0x004eaba8
eip=0x72ff2989, eflags=0x00010212
(...... Omit N rows)
Register to Memory Mapping:

Eax=0x00000008 is a unknown value
EBX=0X730C775D is a unknown value
ECX=0X0000001C is a unknown value
EDX=0XED646BFF is a unknown value
Esp=0x003deec8 is pointing to the stack for thread:0x021ea400
Ebp=0x003deedc is pointing to the stack for thread:0x021ea400
ESI=0X0000001C is a unknown value
Edi=0x004eaba8 is a unknown value

(...... And then omit N rows)
Stack: [0x00390000,0x003e0000], Sp=0x003deec8, free space=315k
Native Frames: (j=compiled Java Code, j=interpreted, VV=VM Code, c=native code)
C [msvcp80.dll+0x2989] std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_ inside+0x1

This information is probably to say that because the C side of the MSVCP80.dll a location cited illegal address and so on (c not familiar, quite guess)
Joint debugging is due to the number of string digits:
The C interface defines parameters such as Char *hkinstno, corresponding to JAVA, should be a byte[] type, and the end to add 0x00.
For example: C interface function: int GetInfo (char *id, Carh *CL);
JNA Interface Definition: public int GetInfo (byte[] ID, byte[] class);
JAVA call: Int res = GetInfo ("001". GetBytes (), "I" getBytes ()); The JVM exits, and the error message appears.
You must add a terminator to the string
========= separated from the ================
Wrote a method of terminating a character.
Public byte[] String2byte (String str) {byte[] src = str.getbytes ();                                byte[] Dest = new Byte[src.length + 1];                System.arraycopy (src, 0, dest, 0, src.length);     Dest[src.length] = 0x00;           This can not be, because new time has been initialized to 0 return dest; }
The above Java call is then changed to
int res = GetInfo (String2byte ("001"), String2byte ("101"));
Run through, can get the return value.
=================== a similar error ============================
The structure body defines the length of the byte[] and has been initialized
Public Static classORDERINFO extendsStructure { Public byte[] Ordercreator = New byte[32]; Order creation Person Public byte[] Outorderno = New byte[128]; External order Number 56 Public byte[] OrderType = New byte[5]; ... ............. PublicGoodsinfo. Byreference goods; Public Static classByreference extendsORDERINFO Implementsstructure.byreference{} Public Static classByvalue extendsORDERINFO Implementsstructure.byvalue{}}
ORDERINFO. Byreference orderinfo = new OrderInfo. Byreference ();
Orderinfo.ordercreator = Info.string2byte ("Zhouyy");
Orderinfo.outorderno = Info.string2byte ("0510030511355563");
Orderinfo.ordertype = Info.string2byte ("222S");
..................
Orderinfo.goods = Goodsinfo;

The public field is assigned a value in the business, the space pointed to by the public field has changed, so the length of the ordercreator is not 32 bit, but Zhouyy 6 bit
So this side should use data copy to copy data, Java has internal methods to copy the array: System.  Arraycopy (src, 0, dest, 0, Src. length);
ORDREINFO structure has a pointer goodsinfo, after copying the data to Goodsinfo to hold the goodsinfo memory, otherwise it will cause the DLL burst because of memory overflow, reaction to the JAV is the JVM exception exit, and throw similar error message 。
Goodsinfo.writer ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.