JDK-4369484 : JDI: allThreads yields ThreadReference after ThreadDeath, .name() then crashes V
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 1.3.0,1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,solaris_7,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2000-09-08
  • Updated: 2001-11-05
  • Resolved: 2001-09-17
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
Name: tb29552			Date: 09/08/2000

java version "1.3.0beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta-b07)
Java HotSpot(TM) Client VM (build 1.3.0beta-b04, mixed mode)

1) javac Hello.java Debugger.java

2) java Debugger
   (lengthy output)

Hello.java:
-------------
import java.io.*;

class Hello {
    static void main (String[] args) {
        System.out.println("Hello world!");
    }
    
}
-------------
Debugger.java:
-------------
import java.io.*;
import java.util.*;

import com.sun.jdi.*;
import com.sun.jdi.connect.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;

class Debugger {
    
    static void main(String[] args) {
        // build virtual machine manager
        VirtualMachineManager vmm = new Bootstrap().virtualMachineManager();
        System.out.println ("JDI version " + vmm.majorInterfaceVersion()
                + "." + vmm.minorInterfaceVersion());
        
        // build launching connector
        LaunchingConnector lc = vmm.defaultConnector();
        System.out.println("Connector: " + lc.description());
        
        // add arguments
        Map lcArgs = lc.defaultArguments();
        
        Connector.Argument mainArg = (Connector.Argument) lcArgs.get("main");
        mainArg.setValue("Hello");
        
        Connector.Argument optionsArg = (Connector.Argument)
lcArgs.get("options");
        optionsArg.setValue("-classic");
                
        // show arguments
        for (Iterator i = lcArgs.values().iterator(); i.hasNext();) {
            System.out.println("   " + i.next());
        }
                
        // launch virtual machine
        VirtualMachine vm;
        try {
            vm = lc.launch(lcArgs);
        } catch (VMStartException e) {
            System.err.println ("Could not launch virtual machine");
            System.err.println (e);
            return;
        } catch (IOException e) {
            System.err.println ("Could not launch virtual machine");
            System.err.println (e);
            return;
        } catch (IllegalConnectorArgumentsException e) {
            System.err.println ("Could not launch virtual machine");
            System.err.println (e);
            return;
        }
        System.out.println(vm.description());

        // read standard and error output for not blocking the VM.
        Process vmp = vm.process();
        final BufferedReader bri = new BufferedReader(
                new InputStreamReader(vmp.getInputStream()));
        Thread thr = new Thread() {
            public void run() {
                System.out.println("started out-stream");
                try {
                    for (String str = ""; str != null; str = bri.readLine()) {
                        System.out.println(">" + str);
                    }
                } catch (IOException e) {
                    System.err.println("problem with VM input");
                }
                System.out.println("reached end of out-stream");
            }
        };
        thr.start();
        final BufferedReader bre = new BufferedReader(
                new InputStreamReader(vmp.getErrorStream()));
        thr = new Thread() {
            public void run() {
                System.out.println("started in-stream");
                try {
                    for (String str = ""; str != null; str = bre.readLine()) {
                        System.err.println(">>" + str);
                    }
                } catch (IOException e) {
                    System.err.println("problem with VM input");
                }
                System.out.println("reached end of err-stream");
            }
        };
        thr.start();

        // setting the event queue
        EventQueue eq = vm.eventQueue();
        int escnt = 0;

        EventRequestManager erm = vm.eventRequestManager();
        ThreadDeathRequest tdr = erm.createThreadDeathRequest();
        MethodExitRequest mer = erm.createMethodExitRequest();
        mer.enable();
        tdr.enable();
        while(true) {
            try {
                escnt ++;
                System.out.println("get event " + escnt);
                EventSet es = eq.remove(100);
                if (es == null) {
                    System.out.println("no Event");
                } else {
                    for (Iterator it = es.iterator(); it.hasNext(); ) {
                        Event ev = (Event) it.next();
                        if (ev instanceof MethodExitEvent) {
                            System.out.println("MethodExitEvent:");
                            System.out.println("   " +
((MethodExitEvent)ev).method().name());
                        } else {
                            System.out.println("Event:");
                            System.out.println("   " + ev + ": " +
ev.request());
                        }
                    }
                    switch (es.suspendPolicy()) {
                        case EventRequest.SUSPEND_ALL:
                            System.out.println("SUSPEND_ALL");
                            break;
                        case EventRequest.SUSPEND_NONE:
                            System.out.println("SUSPEND_NONE");
                            break;
                        case EventRequest.SUSPEND_EVENT_THREAD:
                            System.out.println("SUSPEND_EVENT_THREAD");
                            break;
                        default:
                            System.out.println("strange POLICY");
                            break;
                    }
                    dumpThreads(vm);
                    es.resume();
                }
            } catch (VMDisconnectedException e) {
                System.out.println("disconnected!");
                break;
            } catch (InterruptedException e)
            {
                System.out.println(e);
                break;
            }
        }
        System.out.println("reached end of main");
    }
    
    public static void dumpThreads(VirtualMachine vm) {
        System.out.println(" dump Threads");
        for (Iterator it = vm.allThreads().iterator(); it.hasNext(); ) {
            System.out.println(" get Thread");
            ThreadReference tr = (ThreadReference) it.next();
            System.out.println(" access Thread");
            switch (tr.status()) {
                case ThreadReference.THREAD_STATUS_NOT_STARTED:
                    System.out.println("   NOT_STARTED");
                    System.out.println("   susp=" + tr.suspendCount() + ", " +
tr);
                    break;
                case ThreadReference.THREAD_STATUS_RUNNING:
                    System.out.println("   RUNNING");
                    System.out.println("   susp=" + tr.suspendCount());
                    System.out.println("   name=" + tr.name());
                    break;
                case ThreadReference.THREAD_STATUS_UNKNOWN:
                    System.out.println("   UNKNOWN");
                    System.out.println("   susp=" + tr.suspendCount() + ", " +
tr);
                    break;
                case ThreadReference.THREAD_STATUS_SLEEPING:
                    System.out.println("   SLEEPING");
                    System.out.println("   susp=" + tr.suspendCount() + ", " +
tr);
                    break;
                case ThreadReference.THREAD_STATUS_WAIT:
                    System.out.println("   WAIT");
                    System.out.println("   susp=" + tr.suspendCount() + ", " +
tr);
                    break;
                case ThreadReference.THREAD_STATUS_ZOMBIE:
                    System.out.println("   ZOMBIE");
                    System.out.println("   susp=" + tr.suspendCount() + ", " +
tr);
                    break;
                case ThreadReference.THREAD_STATUS_MONITOR:
                    System.out.println("   MONITOR");
                    System.out.println("   susp=" + tr.suspendCount() + ", " +
tr);
                    break;
                default:
                    System.out.println("   STRANGE State" + tr.status());
                    break;
            }
        }
    }
}
----------------
error output:
>>
>>SIGSEGV   11*  segmentation violation
>>    si_signo [11]: SIGSEGV   11*  segmentation violation
>>    si_errno [0]: Success
>>    si_code [0]: SI_USER [pid: 0, uid: 0]
>>	stackpointer=0x44550c94
>>
>>Full thread dump Classic VM (1.3.0beta-b07, green threads):
>>    "JDWP Command Reader" (TID:0x40f9a0a0, sys_thread_t:0x8140088, state:CW)
prio=5
>>    "JDWP Event Helper Thread" (TID:0x40f99f08, sys_thread_t:0x813ca20,
  state:CW) prio=5
>>    "JDWP Transport Listener: dt_socket" (TID:0x40f99f28,
sys_thread_t:0x813b490, state:R) prio=5
>>    "Finalizer" (TID:0x40f94528, sys_thread_t:0x80c80c8, state:S) prio=8
>>    "Finalizer" (TID:0x40f94528, sys_thread_t:0x80c80c8, state:S) prio=8
>>	at java.lang.Object.wait(Native Method)
>>	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:108)
>>	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:123)
>>	at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:162)
>>    "Reference Handler" (TID:0x40f94300, sys_thread_t:0x80c3008, state:S)
prio=10
>>	at java.lang.Object.wait(Native Method)
>>	at java.lang.Object.wait(Object.java:420)
>>	at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:110)
>>    "Signal dispatcher" (TID:0x40f94330, sys_thread_t:0x80bfb30, state:S)
prio=5
>>    NULL (TID:0x40f9cb70, sys_thread_t:0x804dab8, state:S) prio=5
>>	at java.lang.Object.<init>(Object.java:23)
>>	at java.lang.Thread.<init>(Thread.java:362)
>>Monitor Cache Dump:
>>    java.lang.ref.Reference$Lock@40F94310/40FCA2B0: <unowned>
>>	Waiting to be notified:
>>	    "Reference Handler" (0x80c3008)
>>    java.lang.ref.ReferenceQueue$Lock@40F94540/40FCA7A8: <unowned>
>>	Waiting to be notified:
>>	    "Finalizer" (0x80c80c8)
>>Registered Monitor Dump:
>>    JDWP Command Queue Lock: <unowned>
>>    JDWP Event Helper Completion Monitor: <unowned>
>>    JDWP Event Helper Queue Monitor: <unowned>
>>	Waiting to be notified:
>>	    "JDWP Event Helper Thread" (0x813ca20)
>>    JDWP Event Handler Lock: <unowned>
>>    JDWP Transport Send Monitor: <unowned>
>>    JDWP Transport Listener Monitor: <unowned>
>>    JDWP Initialization Monitor: <unowned>
>>    JDWP Invocation Lock: <unowned>
>>    JDWP Step Handler Lock: <unowned>
>>    JDWP Thread Lock: <unowned>
>>    JDWP Reference Table Monitor: <unowned>
>>    JDWP Alloc Lock: <unowned>
>>    utf8 hash table: <unowned>
>>    JNI pinning lock: <unowned>
>>    JNI global reference lock: <unowned>
>>    BinClass lock: <unowned>
>>    Class linking lock: <unowned>
>>    System class loader lock: <unowned>
>>    Code rewrite lock: <unowned>
>>    Heap lock: <unowned>
>>    Monitor cache lock: owner "JDWP Transport Listener: dt_socket" (0x813b490)
1 entry
>>    Dynamic loading lock: <unowned>
>>    Monitor IO lock: <unowned>
>>    User signal monitor: <unowned>
>>	Waiting to be notified:
>>	    "Signal dispatcher" (0x80bfb30)
>>    Child death monitor: <unowned>
>>    I/O monitor: <unowned>
>>    Alarm monitor: <unowned>
>>	Waiting to be notified:
>>	    <unknown thread> (0x8057f18)
>>    Thread queue lock: owner "JDWP Transport Listener: dt_socket" (0x813b490)
1 entry
>>    Monitor registry: owner "JDWP Transport Listener: dt_socket" (0x813b490) 1
entry
>>
(Review ID: 109120) 
======================================================================
****************
NOTE:   The regression test java/text/BreakIterator/BreakIteratorTest.jtr is failing on all HARDWARE and OS.
        The Bug# 4396286 is filed for the same failure but it is closed as a duplicate of this bug. So, Iam adding the description of the failure on merlin beta build#58.

Test results on sol8-64 bit:
---------------------------
#-----testresult-----
description=file:///net/sqesvr/export/st1/regression/merlin/jdk1.4Tests/tests/b58/java/text/BreakIterator/BreakIteratorTest.java
end=Mon Apr 02 18:43:02 PDT 2001
environment=regtest
execStatus=Failed. Execution failed
javatestOS=SunOS 5.8 (sparc)
javatestVersion=JT_2.1.3i
script=com.sun.javatest.regtest.RegressionScript 
sections=script_messages build compile main
start=Mon Apr 02 18:42:47 PDT 2001
status=Failed. Execution failed
test=java/text/BreakIterator/BreakIteratorTest.java
work=/export0/results/regression/merlin/b58/conway5.8-jth13-jdk14b58.04-02.12.15-ALL/java/text/BreakIterator

#section:script_messages
----------messages:(1/100)----------
JDK under test: java full version "1.4.0-beta-b58" (/net/sqesvr/export/st1/jdk14-beta/b58/solsparc)

#section:build
----------messages:(3/104)----------
command: build BreakIteratorTest 
reason: Named class compiled on demand
elapsed time (seconds): 10.174
result: Passed. Compilation successful

#section:compile
----------messages:(3/209)----------
command: compile /net/sqesvr/export/st1/regression/merlin/jdk1.4Tests/tests/b58/java/text/BreakIterator/BreakIteratorTest.java 
reason: .class file out of date or does not exist
elapsed time (seconds): 10.147
----------System.out:(0/0)----------
----------System.err:(0/0)----------
result: Passed. Compilation successful

#section:main
----------messages:(3/133)----------
command: main BreakIteratorTest
reason: Assumed action based on file name: run main BreakIteratorTest 
elapsed time (seconds): 4.726
----------System.out:(9/290)----------
BreakIteratorTest {
  TestEmptyString Passed
  TestSentenceInvariants Passed
  TestBug4152416 Passed
  TestBug4153072 Passed
  TestCharacterBreak Passed
  TestBug4214367 {
    Discrepancy between expected result and actual result
    Uncaught exception thrown in test method TestBug4214367
----------System.err:(18/848)----------
java.lang.RuntimeException: Uncaught exception thrown in test method TestBug4214367

        at BITestFmwk.err(BITestFmwk.java:173)
        at BITestFmwk.errln(BITestFmwk.java:182)
        at BITestFmwk.run(BITestFmwk.java:126)
        at BreakIteratorTest.main(BreakIteratorTest.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:30)
        at sun.reflect.InflatableMethodAccessorImpl.invoke(InflatableMethodAccessorImpl.java:47)
        at java.lang.reflect.Method.invoke(Method.java:306)
        at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:94)
        at java.lang.Thread.run(Thread.java:579)

JavaTest Message: Test threw exception: java.lang.RuntimeException: Uncaught exception thrown in test method TestBug4214367

JavaTest Message: shutting down test

STATUS:Failed.
result: Failed. Execution failed


test result: Failed. Execution failed


Comments
WORK AROUND Name: tb29552 Date: 09/08/2000 Follow ThreadDeath events and check threads from allThreads(), whether they have been reported dead. ======================================================================
11-06-2004

PUBLIC COMMENTS .
10-06-2004

EVALUATION Yes. Note that this test case is launching the debugee using classic VM. When the test is modified to run the debugee using the HotSpot runtime, the test ran for four minutes before failing on an 8-way SPARC/Solaris system: [....copious output deleted...] get event 11642 MethodExitEvent: <init> SUSPEND_ALL dump Threads get Thread access Thread RUNNING susp=1 ># ># HotSpot Virtual Machine Error, Unexpected Signal 11 ># Please report this error at ># http://java.sun.com/cgi-bin/bugreport.cgi ># ># Error ID: 4F533F534F4C415249530E435050079A 01 ># ># Problematic Thread: prio=5 tid=0x990b8 nid=0x8 runnable ># reached end of out-stream reached end of err-stream disconnected! reached end of main It appears that the ThreadReference returned by Iterator it = vm.allThreads().iterator(); ThreadReference tr = (ThreadReference) it.next(); is non-null, but attempting to fetch information from it, EG: String tn = tr.name(); String sc = Integer.toString(tr.suspendCount()); causes the error above. tim.bell@Eng 2000-10-01 ###@###.### 2001-08-27 This test case fails in "1.4.0-beta2-b77" and earlier J2SE releases. It works very well in the latest promoted build ( This bug was solved on Aug 23 2001 by the fix for: 4345208 ArcTest applet with JVM/DI agent crashes VM (category: hotspot/jvmdi) If my testing on other platforms is successful, I will be closing this bug as a DUP of 4345208. ###@###.### 2001-08-27 The test case now works very well in: % java -version java version "1.4.0-beta3" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b79) Java HotSpot(TM) Client VM (build 1.4.0-beta3-b79, mixed mode) Results of five test runs each on: Solaris/SPARC : all PASS Solaris/x86 : all PASS Windows NT/x86 : all PASS Linux/x86 : all PASS I am closing this bug as a DUP of 4345208. ###@###.### 2001-09-17
17-09-2001