JDK-4802550 : java.util.WeakHashMap throws OutOfMemoryError on Linux
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2003-01-13
  • Updated: 2021-03-03
  • Resolved: 2003-01-14
Description

Name: nt126004			Date: 01/13/2003


FULL PRODUCT VERSION :
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
================================================================
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
================================================================
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

glibc:glibc-2.2.2-10
Linux develop 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686
unknown


EXTRA RELEVANT SYSTEM CONFIGURATION :
Pentium 4 1500Mhz/512M


A DESCRIPTION OF THE PROBLEM :
When I run the test below on windows/jdk1.3.1 ,nothing
happened.  Same on Solaris 2.8.  But when I run it on linux/jdk1.3.1/
1.4.0 /1.4.1, it crashed with OutOfMemoryError.

However, it seems that using the -Xincgc flag prevents the Error
from occuring.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the program on linux with any version of j2sdk for
about more than 10 minutes, then you might see
OutOfMemoryError. I am not quite sure if it is a bug or I
misunderstand the spec.

EXPECTED VERSUS ACTUAL BEHAVIOR :
OutOfMemoryError.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No stacktrace available.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;
public class WeakHashMapTest
{
  public static void main(String[]args)
  {
    Map hash=new WeakHashMap();
    long index=1;
    while(true)
    {
      hash.put(new Long(index),new Object());
      index++;
    }
  }
}

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

CUSTOMER WORKAROUND :
java WeakHashMapTest
(Review ID: 179442) 
======================================================================

Comments
EVALUATION It is not guaranteed that the garbage collector will always reclaim those objects before an OutOfMemoryError is thrown. ###@###.### 2003-01-14
14-01-2003