JNA 调用Libuv的UDP报错误

walker_grq 2017-06-08 02:56:58
错误:运行测试时,udp接受自动停止或包下面的错误

# A fatal error has been detected by the Java Runtime Environment:
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffa97f52bb0, pid=11864, tid=0x0000000000001fc8
# JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [ntdll.dll+0x42bb0]
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
# 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.

--------------- T H R E A D ---------------
Current thread (0x000000001be4a800): JavaThread "Finalizer" daemon [_thread_in_native, id=8136, stack(0x000000001d0c0000,0x000000001d1c0000)]

siginfo: ExceptionCode=0xc0000005, reading address 0xffffffffffffffff

Registers:
RAX=0x00000000000016e9, RBX=0x20656d6f68206f67, RCX=0x00000000000039b8, RDX=0x00000000008772b0
RSP=0x000000001d1be820, RBP=0x0000000000000001, RSI=0x0000000000870150, RDI=0x0000000000870000
R8 =0x0000000043602130, R9 =0x00000000000003ff, R10=0x00000000000050a1, R11=0x000000001d1be898
R12=0x00000000000003ff, R13=0x00000000ffffffff, R14=0x00000000000050a1, R15=0x000000000000037f
RIP=0x00007ffa97f52bb0, EFLAGS=0x0000000000010202

Top of Stack: (sp=0x000000001d1be820)
0x000000001d1be820: 0000000002869b80 00000000574d99a9

Instructions: (pc=0x00007ffa97f52bb0)
0x00007ffa97f52b90: 0f 85 78 c0 07 00 48 8b 5b 30 4a 8b 1c fb 48 3b
0x00007ffa97f52ba0: f3 0f 84 84 01 00 00 40 84 ed 0f 84 8a 01 00 00

Register to memory mapping:

RAX=0x00000000000016e9 is an unknown value
RBX=0x20656d6f68206f67 is an unknown value

Stack: [0x000000001d0c0000,0x000000001d1c0000], sp=0x000000001d1be820, free space=1018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ntdll.dll+0x42bb0]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 670 C1 java.lang.ref.Finalizer.runFinalizer(Lsun/misc/JavaLangAccess;)V (62 bytes) @ 0x0000000002bdff14 [0x0000000002bdf980+0x594]
J 669 C1 java.lang.ref.Finalizer.access$100(Ljava/lang/ref/Finalizer;Lsun/misc/JavaLangAccess;)V (6 bytes) @ 0x0000000002bdf61c [0x0000000002bdf5c0+0x5c]
j java.lang.ref.Finalizer$FinalizerThread.run()V+45
v ~StubRoutines::call_stub

--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x000000001d298800 JavaThread "Service Thread" daemon [_thread_blocked, id=11348, stack(0x000000001db20000,0x000000001dc20000)]
0x0000000002770800 JavaThread "main" [_thread_in_vm, id=8488, stack(0x00000000022d0000,0x00000000023d0000)]

Other Threads:
0x000000001be28800 VMThread [stack: 0x000000001cec0000,0x000000001cfc0000] [id=7060]
0x000000001d2a0000 WatcherThread [stack: 0x000000001dc20000,0x000000001dd20000] [id=7208]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap:
PSYoungGen total 75776K, used 8400K [0x000000076b580000, 0x0000000770a00000, 0x00000007c0000000)
eden space 65024K, 4% used [0x000000076b580000,0x000000076b8a9950,0x000000076f500000)
from space 10752K, 48% used [0x000000076f500000,0x000000076fa0a950,0x000000076ff80000)
to space 10752K, 0% used [0x000000076ff80000,0x000000076ff80000,0x0000000770a00000)
ParOldGen total 173568K, used 8K [0x00000006c2000000, 0x00000006cc980000, 0x000000076b580000)
object space 173568K, 0% used [0x00000006c2000000,0x00000006c2002000,0x00000006cc980000)
Metaspace used 5228K, capacity 5302K, committed 5504K, reserved 1056768K
class space used 564K, capacity 595K, committed 640K, reserved 1048576K

Card table byte_map: [0x0000000011c30000,0x0000000012430000] byte_map_base: 0x000000000e620000

Marking Bits: (ParMarkBitMap*) 0x0000000057adb6d0
Begin Bits: [0x0000000012d80000, 0x0000000016d00000)
End Bits: [0x0000000016d00000, 0x000000001ac80000)

Polling page: 0x00000000023d0000

CodeCache: size=245760Kb used=3535Kb max_used=3535Kb free=242224Kb
bounds [0x0000000002870000, 0x0000000002bf0000, 0x0000000011870000]
total_blobs=967 nmethods=675 adapters=205
compilation: enabled

Compilation events (10 events):
Event: 7.717 Thread 0x000000001d27a800 683 1 java.lang.ref.Finalizer::access$000 (4 bytes)
Event: 7.717 Thread 0x000000001d27a800 nmethod 683 0x0000000002be2cd0 code [0x0000000002be2e20, 0x0000000002be2f10]

GC Heap History (2 events):
Event: 7.697 GC heap before
{Heap before GC invocations=1 (full 0):
PSYoungGen total 75776K, used 65024K [0x000000076b580000, 0x0000000770a00000, 0x00000007c0000000)
eden space 65024K, 100% used [0x000000076b580000,0x000000076f500000,0x000000076f500000)
from space 10752K, 0% used [0x000000076ff80000,0x000000076ff80000,0x0000000770a00000)
to space 10752K, 0% used [0x000000076f500000,0x000000076f500000,0x000000076ff80000)
ParOldGen total 173568K, used 0K [0x00000006c2000000, 0x00000006cc980000, 0x000000076b580000)
object space 173568K, 0% used [0x00000006c2000000,0x00000006c2000000,0x00000006cc980000)
Metaspace used 5217K, capacity 5294K, committed 5504K, reserved 1056768K
class space used 564K, capacity 595K, committed 640K, reserved 1048576K
Event: 7.710 GC heap after
Heap after GC invocations=1 (full 0):
PSYoungGen total 75776K, used 5162K [0x000000076b580000, 0x0000000770a00000, 0x00000007c0000000)
eden space 65024K, 0% used [0x000000076b580000,0x000000076b580000,0x000000076f500000)
from space 10752K, 48% used [0x000000076f500000,0x000000076fa0a950,0x000000076ff80000)
to space 10752K, 0% used [0x000000076ff80000,0x000000076ff80000,0x0000000770a00000)
ParOldGen total 173568K, used 8K [0x00000006c2000000, 0x00000006cc980000, 0x000000076b580000)
object space 173568K, 0% used [0x00000006c2000000,0x00000006c2002000,0x00000006cc980000)
Metaspace used 5217K, capacity 5294K, committed 5504K, reserved 1056768K
class space used 564K, capacity 595K, committed 640K, reserved 1048576K
}

Deoptimization events (10 events):
Event: 6.770 Thread 0x0000000002770800 Uncommon trap: reason=null_check action=make_not_entrant pc=0x0000000002b03a68 method=com.sun.jna.Native.getNativeSize(Ljava/lang/Class;)I @ 4

Internal exceptions (8 events):
Event: 0.022 Thread 0x0000000002770800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class; name or signature does not match> (0x000000076b587ca8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u121\8372\hotspot\

Events (10 events):
Event: 7.335 Thread 0x0000000002770800 DEOPT PACKING pc=0x0000000002baeb34 sp=0x00000000023cdbf0
Event: 7.335 Thread 0x0000000002770800 DEOPT UNPACKING pc=0x00000000028b582a sp=0x00000000023cda20 mode 2

Dynamic libraries:
0x00007ff692ab0000 - 0x00007ff692ae7000 C:\Program Files\Java\jdk1.8.0_121\bin\javaw.exe
0x00007ffa892a0000 - 0x00007ffa8951a000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.14393.953_none_42151e83c686086b\COMCTL32.dll


代码:
String pathname = "C:\\Users\\worker\\Desktop\\test.txt";
File f = new File(pathname);
file = new FileWriter(f);

uv_loop_t loop = new uv_loop_t();
int loop_init = Libuv.uv_loop_init(loop);

uv_udp_t server = new uv_udp_t();
int init = Libuv.uv_udp_init(loop, server);

Pointer recv_addr = new Memory(16);
int ip4 = Libuv.uv_ip4_addr("127.0.0.1", 8080, recv_addr );

int bind = Libuv.uv_udp_bind(server, recv_addr ,0);

int start = Libuv.uv_udp_recv_start(server, new uv_alloc_cb() {

public void invoke(Pointer handle, int suggested_size, uv_buf_t buf) {
buf.base = new Memory(suggested_size);
buf.len = suggested_size;
}
}, new uv_udp_recv_cb() {
public void invoke(Pointer handle, int nread, uv_buf_t buf, Pointer addr, int flags) {
System.out.println("nread: "+nread);
if(nread > 0){
System.out.println(new String(buf.base.getByteArray(0, nread))+"---"+i);

try {
file.write(new String(buf.base.getByteArray(0, nread))+"---"+i+"\r\n");
} catch (IOException e) {
e.printStackTrace();
}
i++;
Native.free(Pointer.nativeValue(buf.base));
Pointer.nativeValue(buf.base, 0)
}

}
});

System.out.println(loop_init+init+ip4+bind+start);
int run = Libuv.uv_run(loop, uv_run_mode.UV_RUN_DEFAULT);
System.out.println("run: "+run);
}

uv_buf_t的定义:
public class uv_buf_t extends Structure{
public long len ;

public Pointer base ;
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] {"len","base"});
}
public static class ByReference extends uv_buf_t implements Structure.ByReference { }
public static class ByValue extends uv_buf_t implements Structure.ByValue{ }

}
...全文
213 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧