Jenkinsを使っているとJavaCrashがよく起きるので原因を探してみた話

エラーの内容

JenkinsでTrigger parameterized build on other projectsを使っていると、たまに起きるのがこのエラー(JavaCrash)

 

#

# A fatal error has been detected by the Java Runtime Environment:

#

#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000076ea48c8, pid=12356, tid=3960

#

# JRE version: 6.0_45-b06

# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.45-b01 mixed mode windows-amd64 compressed oops)

# Problematic frame:

# C  [ntdll.dll+0x548c8]

#

# An error report file with more information is saved as:

# E:\jenkins\hs_err_pid12356.log

#

# If you would like to submit a bug report, please visit:

#   http://java.sun.com/webapps/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 (0x000000000581d000):  JavaThread "Finalizer" daemon [_thread_in_native, id=9072, stack(0x0000000006460000,0x0000000006560000)]

 

siginfo: ExceptionCode=0xc0000005, reading address 0x0000000008d80074

 

(中略)

 

Stack: [0x0000000006460000,0x0000000006560000],  sp=0x000000000655f150,  free space=1020k

Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)

C  [ntdll.dll+0x53210]  RtlFreeHeap+0x10

j  com.sun.jna.Memory.finalize()V+4

v  ~StubRoutines::call_stub

V  [jvm.dll+0x1eac57]

 

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)

j  com.sun.jna.Memory.free(J)V+0

j  com.sun.jna.Memory.finalize()V+4

v  ~StubRoutines::call_stub

j  java.lang.ref.Finalizer.invokeFinalizeMethod(Ljava/lang/Object;)V+0

j  java.lang.ref.Finalizer.runFinalizer()V+45

j  java.lang.ref.Finalizer.access$100(Ljava/lang/ref/Finalizer;)V+1

j  java.lang.ref.Finalizer$FinalizerThread.run()V+24

v  ~StubRoutines::call_stub

(後略)

 

 

解決の第一歩

ここを見て、対策を考える

www.acroquest.co.jp

 

ふむふむ。

ということで、バグレポートを検索してみる

Bug Database

 

上記のJavaCrashのログより「"Finalizer" daemon Memory.finalize」で調べると、このバグレポートが出てくる

Bug ID: JDK-7071606 on end of application it crashes

JNAの問題だからJNAに聞けって書いてある。

 

JNAとの出会い

JNAのgithubを見てみる

github.com

 

「"Finalizer" daemon」で検索してみる

Search Results · GitHub

 

一番詳しく載ってるissuesはこれっぽい

JVM crash in unit test DirectTest · Issue #24 · twall/jna · GitHub

 

うーむ…。

それ以外のissuesでは、GoogleGroupに投げろって言ってる

 

GoogleGroupとの関わり

「"Finalizer" daemon」で検索してみる

https://groups.google.com/forum/#!searchin/jna-users/%22Finalizer%22$20daemon

 

うーん、あまり明確な答えが見つかってない…。

https://groups.google.com/forum/#!searchin/jna-users/%22Finalizer%22$20daemon/jna-users/7dAAYPGWAk0/VpTPlrv7rw0J

上記のページには、

This type of error (ntdll on windows during memory free) has shown up from time to time, but has not been definitively resolved.

意訳:このタイプのエラーは度々質問されるが解決されてない

なんて書かれてるし…。

 

一旦の回避策

とりあえず、

「-Djna.protected=true」にしてるか?

と言われたので、やってみたら、JavaCrashは回避できた。

ただ、Trigger parameterized build on other projects自体はエラーになる。

 

おそらく、

Trigger parameterized build on other projectsの中で、Memory.freeを実行しているせいで、
JNA本来のMemory.freeを行おうとしている時に、
そんな場所が無いから落ちるんだろうなと推測してる。