`
netcome
  • 浏览: 475617 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Debugging the JNI

    博客分类:
  • JAVA
阅读更多

If you think you have a JNI problem, there are checks you can run to help you diagnose the JNI transitions.

Errors in JNI code can occur in several ways:
  • The program crashes during execution of a native method (most common).
  • The program crashes some time after returning from the native method, often during GC (not so common).
  • Bad JNI code causes deadlocks shortly after returning from a native method (occasional).

If you think that you have a problem with the interaction between user-written native code and the JVM (that is, a JNI problem), you can run checks that help you diagnose the JNI transitions. To run these checks, specify the -Xcheck:jni option when you start the JVM.

The -Xcheck:jni option activates a set of wrapper functions around the JNI functions. The wrapper functions perform checks on the incoming parameters. These checks include:
  • Whether the call and the call that initialized JNI are on the same thread.
  • Whether the object parameters are valid objects.
  • Whether local or global references refer to valid objects.
  • Whether the type of a field matches the Get<Type>Field or Set<Type>Field call.
  • Whether static and nonstatic field IDs are valid.
  • Whether strings are valid and non-null.
  • Whether array elements are non-null.
  • The types on array elements.

Output from -Xcheck:jni is displayed on the standard error stream, and looks like:

JVMJNCK059W: JNI warning in FindClass: argument #2 is a malformed identifier ("invalid.name")
JVMJNCK090W: Warning detected in com/ibm/examples/JNIExample.nativeMethod() [Ljava/lang/String];
The first line indicates:
  • The error level (error, warning, or advice).
  • The JNI API in which the error was detected.
  • An explanation of the problem.
The last line indicates the native method that was being executed when the error was detected.

You can specify additional suboptions by using -Xcheck:jni:<suboption>[,<...>]. Useful suboptions are:

all
Check application and system classes.
verbose
Trace certain JNI functions and activities.
trace
Trace all JNI functions.
nobounds
Do not perform bounds checking on strings and arrays.
nonfatal
Do not exit when errors are detected.
nowarn
Do not display warnings.
noadvice
Do not display advice.
novalist
Do not check for va_list reuse (see the note at the bottom of this section).
pedantic
Perform more thorough, but slower checks.
valist
Check for va_list reuse (see the note at the bottom of the section).
help
Print help information.

The -Xcheck:jni option might reduce performance because it is thorough when it validates the supplied parameters.

Note:

On some platforms, reusing a va_list in a second JNI call (for example, when calling CallStaticVoidMethod() twice with the same arguments) causes the va_list to be corrupted and the second call to fail. To ensure that the va_list is not corrupted, use the standard C macro va_copy() in the first call. By default, -Xcheck:jniensures that va_lists are not being reused. Use the novalist suboption to disable this check only if your platform allows reusing va_list without va_copyz/OS® platforms allow va_list reuse, and by default -Xcheck:jni:novalist is used. To enable va_list reuse checking, use the -Xcheck:jni:valist option.

分享到:
评论

相关推荐

    《Debugging the Development Process》+《Write Clean Code》

    《Debugging the Development Process》 - 无论是写代码的还是不写代码的人都应该读读。 《Write Clean Code》- 作者在微软开发了n年(n &gt; 2)程序后的经验总结,比较适合软件开发设计人员。

    Debugging the development process

    ### Debugging the Development Process #### 书籍概述 《Debugging the Development Process》是Stephen A. Maguire撰写的一本关于软件开发过程中的调试与优化的重要著作。该书由Microsoft Press出版,首次出版于...

    Debugging the Development Process

    ### Debugging the Development Process 《Debugging the Development Process》是由微软的经典著作《Writing Solid Code》的作者Stephen A. Maguire撰写的一本书。该书于1994年出版,主要探讨了软件开发过程中遇到...

    Debugging the Development Process微软研发:致胜策略

    英文原书名:Debugging the Development Process 作者:史蒂夫·马魁尔 译者:苏斐然 作者详细描述了他在美国领导项目的各种实际的策略方法,教您如何开发高质量的软件,而且绝不延误。本书中,作者以直率、真诚的...

    the art of debugging

    the art of debugging

    Advanced.Apple.Debugging.&.Reverse.Engineering.v2.0 Code Part2

    Advanced Apple Debugging & Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple’s software debugger, LLDB, that can get more information out of any program than you ever ...

    JNI 使用文档

    最后,“Debugging JNI Programs”章节介绍了如何调试JNI程序。由于JNI程序涉及到两种语言和不同的运行时环境,调试会比纯Java程序更加复杂。文档会提供一些技巧和工具,帮助开发者有效定位和解决问题。 需要注意的...

    Debugging With GDB中文版

    This is the Tenth Edition, of Debugging with GDB: the GNU Source-Level Debugger for GDB (GDB) Version 8.1.90.20180814-git. Copyright © 1988-2018 Free Software Foundation, Inc. Permission is granted...

    Advanced Apple Debugging & Reverse Engineering Code part1

    Advanced Apple Debugging & Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple’s software debugger, LLDB, that can get more information out of any program than you ever ...

    Springer.The.Developer’s.Guide.to.Debugging.2008.pdf

    2.3.8 Match the Tool to the Bug . . . . . . . . . 12 2.3.9 One Change at a Time . . . . . . . . . 12 2.3.10 Keep an Audit Trail . . . . . . . . 12 2.3.11 Get a Fresh View . . . . . . . . . . . 13 ...

    Debugging - The 9 Indispensable Rules for Finding Even the Most Elusive Problems.pdf

    《调试——发现最难以捉摸的软件和硬件问题的9个不可或缺的规则》是一本深入探讨调试技术的书籍。本书的核心在于提供一套行之有效的规则,帮助开发者和IT专业人士解决那些看似无解的问题。以下是对书中部分内容的...

    Advanced Apple Debugging & Reverse Engineering

    Advanced Apple Debugging & Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple's software debugger, LLDB, that can get more information out of any program than you ever ...

    Debugging Malloc Lab: Detecting Memory-Related Errors

    This is the same as the error(), except there are two sets of filenames and line numbers, one for the statement in which the block was malloc'd, and the other for the statement in which the block was ...

    DebuggingTools

    Debugging Tools for Windows 是一套强大的开发和调试工具,主要用于对Windows操作系统进行深入的故障排查和性能分析。这个工具集包含了多种实用程序,如WinDbg、KD、CDB、NTSD等,它们都是针对不同场景的专业调试器...

    Advanced Apple Debugging & Reverse Engineering v0.9.5

    When LLDB comes up against a stripped executable (an executable devoid of DWARF debugging information), LLDB won’t have the symbol information to give you the stack trace. Instead, LLDB will generate...

    jni调试 c层在eclipse中输出信息

    __android_log_print(ANDROID_LOG_DEBUG, "JniDebugTest", "Debugging from C!"); } ``` 4. **配置构建过程** - 配置`Android.mk`或`CMakeLists.txt`文件,指定编译规则和依赖库。 - 对于`Android.mk`,可能的...

    【放大招】Advanced Apple Debugging & Reverse Engineering v2.0

    Advanced Apple Debugging & Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple’s software debugger, LLDB, that can get more information out of any program than you ever ...

    Debugging Tools for Windows.zip

    【标题】:Debugging Tools for Windows.zip 【描述】:这个压缩包文件“Debugging Tools for Windows.zip”包含了用于Windows环境下的调试工具,特别针对Qt Creator的调试器配置问题。通常,当Qt Creator的调试器...

Global site tag (gtag.js) - Google Analytics