JDK-8214773 : Replace use of thread unsafe strtok
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 10,11,12
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-12-04
  • Updated: 2019-11-04
  • Resolved: 2018-12-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12
11.0.6-oracleFixed 12 b24Fixed
Description
Quoted from hotspot-compiler-dev@openjdk.java.net:

"Hello,

I���m posting this to the group since I can���t open a bug report against OpenJDK ��� I only have browsing privileges.

compilerDirectives.cpp is using the MT-Unsafe strtok function.  This is causing some JVM crashes with our application under linux-x86_64 since some of our native code run via JNI is also using strtok.  Fixing either our code or HotSpot to use strtok_r resolves the issue.  We started seeing this problem after upgrading to OpenJDK 11 from Oracle JDK 8, which didn���t trigger any crashes.

Problematic lines:

https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/hotspot/share/compiler/compilerDirectives.cpp#l402

https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/hotspot/share/compiler/compilerDirectives.cpp#l407

Fixing this would make the compiler immune from other JNI code (or other JVM code) that could be using strtok.

The following details a survey of HotSpot that was done a long time ago to identify all occurrences of MT-unsafe functions:

https://bugs.openjdk.java.net/browse/JDK-4647546

I understand the latter goes beyond the scope of the compiler group.

Thanks,

Andre <Andre.Gillet@nuance.com>




Comments
Fix Request I am requesting a backport of this issue to 11u as it enhances runtime stability in multithreaded environments. The original patch applies (with fuzz, but without changes) to the 11u codebase, but I have also included a slightly modified patch that applies with no fuzz. webrev: http://cr.openjdk.java.net/~stooke/webrevs/jdk-8214773-jdk11u/00/00/
24-10-2019

ILW = possible JVM crashes due to uses of thread unsafe strtok function in hotspot; rare, some cases in which applications also use strtok though jni; using strtok_r in apllication code = HLL = P4
04-12-2018

http://cr.openjdk.java.net/~neliasso/8214773/webrev.01/
04-12-2018

There is a total of four uses of strtok in hotspot. All uses except compilerDirectives is used during startup, and is probably safe. I choose to replace them anyway for consistency. strtok is replaced by strtok_r on all platforms but windows, where either strtok or strtok_s can be used. Since the platforms differ I added the function to the OS files.
04-12-2018