JDK-8069389 : CompilerOracle prefix wildcarding is broken for long strings
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x,solaris
  • Submitted: 2015-01-20
  • Updated: 2024-04-10
  • Resolved: 2015-01-22
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 9 Other
9 b50Fixed openjdk8u422Fixed
Related Reports
Relates :  
Description
If you look at the command below, the printed version differs from the command line version at the last 7.

java -XX:CompileCommand=print,\*01234567890123456789012345678901234567890123456789,\*0123456789012345678901234567890123456789 -version
CompilerOracle: print *01234567890123456789012345678901234678901234567789.*0123456789012345678901234678901123456789
Java HotSpot(TM) 64-Bit Server VM warning: printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

The problem is that compilerOracle.cpp uses strcpy to copy within a string and that's specifically described as undefined behaviour for strcpy.  Apparently that semantic is somewhat contentious and most strcpy implementations handle the specific case of copying down properly.  But not the mac version.

The fix is to use memmove.

static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {
  int match = MethodMatcher::Exact;
  while (name[0] == '*') {
    match |= MethodMatcher::Suffix;
    // Copy remaining string plus NUL to the beginning
    memmove(name, name + 1, strlen(name + 1) + 1);
  }

Comments
[jdk8u-fix-request] Approval Request from Roman Marchenko Clean backport
16-02-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk8u-dev/pull/446 Date: 2024-02-16 18:33:02 +0000
16-02-2024

I'd like to backport this to [8u]. I've just found that the issue occurs even with short strings like "*123*", see the screenshot (https://bugs.openjdk.org/secure/attachment/108291/2024-02-15%2013_12_58.png). This can be reproduced currently with "slowdebug" build on my Ubuntu 22.04 + gcc-9.5.0, however I believe we cannot rely on it isn't reproduced with "release" now. Anyway, it wasn't good to use "strcpy" with overlapped buffers, because strcpy's docs says "The behavior is undefined if the strings overlap." So, I believe it should be fixed in jdk8 as well.
16-02-2024

URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/41e21dafddc9 User: lana Date: 2015-02-11 23:06:13 +0000
11-02-2015

URL: http://hg.openjdk.java.net/jdk9/hs-comp/hotspot/rev/41e21dafddc9 User: neliasso Date: 2015-01-22 14:45:22 +0000
22-01-2015

Created a regression test of your example and it fails on Solaris too.
21-01-2015

ILW=CompileCommand parsing broken on Mac, some usescases, none=MLH=P4
21-01-2015