Issue1633

classification
Title: SIGSEGV when adding a java.util.HashSet to itself twice
Type: Severity: normal
Components: Core Versions: 2.5.1
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: somejan, zyasoft
Priority: Keywords:

Created on 2010-07-12.23:39:47 by somejan, last changed 2010-07-13.03:40:57 by zyasoft.

Files
File name Uploaded Description Edit Remove
hs_err_pid16846.log somejan, 2010-07-12.23:39:45 The logfile produced by jython/java
Messages
msg5889 (view) Author: somejan (somejan) Date: 2010-07-12.23:39:45
Doing the following results in a SIGSEGV on Ubuntu Linux 9.10 with OpenJDK 6: 

-----
from java.util import HashSet
s = HashSet()
s.add(s)
s.add(s)
-----

The error message: 

-----
$> jython
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54) 
[OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_0
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.util import HashSet
>>> s = HashSet()
>>> s.add(s)
True
>>> s.add(s)
An irrecoverable stack overflow has occurred.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fc1044fafdd, pid=16846, tid=140467075377424
#
# JRE version: 6.0-b16
# Java VM: OpenJDK 64-Bit Server VM (14.0-b16 mixed mode linux-amd64 )
# Distribution: Ubuntu 9.10, package 6b16-1.6.1-3ubuntu3
# Problematic frame:
# j  java.util.HashMap$HashIterator.<init>(Ljava/util/HashMap;)V+0
#
# An error report file with more information is saved as:
# /home/***/hs_err_pid16846.log
#
# If you would like to submit a bug report, please include
# instructions how to reproduce the bug and visit:
#   https://bugs.launchpad.net/ubuntu/+source/openjdk-6/
#
/home/***/bin/jython: line 271: 16846 Aborted                 "${JAVA_CMD[@]}" $JAVA_OPTS "${java_args[@]}" -Dpython.home="$JYTHON_HOME" -Dpython.executable="$PRG" org.python.util.jython $JYTHON_OPTS "$@"
-----


I'm reporting this crash here because it doesn't happen in Java, just in Jython. Doing the same thing in Java causes a StackOverflowError, but no segmentation fault.
msg5890 (view) Author: Jim Baker (zyasoft) Date: 2010-07-13.03:40:56
This is what I would expect, from

Jython 2.5.2b1 (trunk:7076M, Jul 12 2010, 17:46:19) 
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_20

>>> from java.util import HashSet
>>> s = HashSet()    
>>> s.add(s)
True
>>> s.add(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded

Python's sets work better here, simply refusing to do this (even for reasons not related to building inadvertent self recursive structures):

>>> s = set()
>>> s.add(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: set objects are unhashable

Note that our sets are backed by a ConcurrentHashMap, but it works out the same:

>>> from java.util.concurrent import ConcurrentHashMap as CHM
>>> s = CHM()
>>> s[s] = True
>>> s[s] = True
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded

I don't believe there's really anything to do here except report this to the OpenJDK team. Seg faults in cases like this are really a fault of the JVM. Jython simply catches the StackOverflowError and converts it to the equivalent Python exception (RuntimeError: maximum recursion depth exceeded).
History
Date User Action Args
2010-07-13 03:40:57zyasoftsetstatus: open -> closed
resolution: wont fix
messages: + msg5890
nosy: + zyasoft
2010-07-12 23:39:47somejancreate