JDK-4985576 : Multi-thread invocation of method sometimes returns null
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-01-29
  • Updated: 2004-02-05
  • Resolved: 2004-02-05
Related Reports
Duplicate :  
Description

Name: jl125535			Date: 01/29/2004


FULL PRODUCT VERSION :

Windows:

java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)



Linux:
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

Linux linux-int 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux



A DESCRIPTION OF THE PROBLEM :

This bug was submitted a month ago but reporter claims no response from Sun.    The "internal review ID" was 218838.

http://forum.java.sun.com/thread.jsp?thread=463092&forum=31
Bizzare non-deterministic run-time behavior.

I am re-submitting with smaller example and workarounds.

The enclosed small multi-threaded program sometimes prints out "retStr returned null?!?" when it never should do so.
Just let it run for several seconds on any typical modern Windows or Linux system and it will happen.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

Install J2SE SDK 1.4.2. Compile the included program with javac.  Run with default "java" command.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Nothing should print out.
ACTUAL -
"retStr returned null?!?" is printed out, clearly indicated the retStr method returned a vlaue to the string array element that was null.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
"retStr returned null?!?"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

class Tester {
 static String retStr() {
  for (int i = 0; i < 1; i++) { }
  return "1"; // This can be set to any string value.
 }
 public static void main(String[] args) {
  for (int i = 0; i < 2; i++) {
   new Thread() {
    public void run() {
     while (true) {
      String sa [] = new String[1];
      sa[0] = retStr();
      if (sa[0] == null) {
       System.out.println("retStr returned null?!?");
      }
     }
    }
   }.start();
  }
 }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :

Workaround is to disable HotSpot.

Also, you can disable it for retStr via

java -XX:+PrintCompilation Tester

see that retStr is compiled into 16 bytes and then

java -XX:MaxInlineSize=15 Tester
(Incident Review ID: 231471) 
======================================================================

Comments
EVALUATION We need to backport 4917709 in 1.4.2. ###@###.### 2004-02-05
05-02-2004