United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6895383 JCK test throws NPE for method compiled with Escape Analysis
6895383 : JCK test throws NPE for method compiled with Escape Analysis

Details
Type:
Bug
Submit Date:
2009-10-26
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
solaris
Sub-Component:
compiler
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
hs17
Fixed Versions:
hs17

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

Description
It seems that the following JCK test:
api/java_util/concurrent/CopyOnWriteArrayList/index.html#CopyOnWriteArrayList[testAddAll1_IndexOutOfBoundsException]
also fails due to the issue.

The minimized test throws NPE at line marked (*) with -Xcomp specified since JDK b72:
-----------------------------------------------------------
import java.util.*;
import java.util.concurrent.*;

public class CopyOnWriteArrayListTest {
    public static void main(String argv[]) {
        CopyOnWriteArrayListTest test = new CopyOnWriteArrayListTest();
        test.testRemove1_IndexOutOfBounds();
        test.testAddAll1_IndexOutOfBoundsException();
    }

    public void testRemove1_IndexOutOfBounds() {
        CopyOnWriteArrayList c = new CopyOnWriteArrayList();
    }

    public void testAddAll1_IndexOutOfBoundsException() {
        try {
            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
            c.addAll(-1, new LinkedList()); // (*)
        } catch (IndexOutOfBoundsException e) {
        }
    }
}
-----------------------------------------------------------
*** (#3 of 3): 2009-10-26 10:12:14 PDT ###@###.###

                                    

Comments
WORK AROUND

-XX:-DoEscapeAnalysis
                                     
2009-12-11
PUBLIC COMMENTS

Problem:
EA misses checks for MemBar nodes when looking for following
MergeMem nodes. As result it did not add memory slice for
the volatile store (followed by several MemBar nodes)
in MergeMem of uncommon trap.
So when the method deoptimized and eliminated object reallocated
the NULL is stored to the corresponding field.

Solution:
Collect all MergeMem nodes at the beginning of EA when it walks
through Ideal graph instead of searching MergeMem nodes by going
down trough memory during memory splitting for non escaping objects.
Also check for general MemBar nodes instead of only Initialize nodes
during memory splitting.

I also did next optimizations/fixes:

1. Check for SafePointScalarObject nodes to avoid printing empty lines
in PrintOptoAssembly output since they don't have corresponding mach nodes.

2. Eliminate volatile MemBars nodes for stores into a scalar replaced objects.
I noticed that we still generate membars even if the object is eliminated.
For that I added the Precedent edge to corresponding Store node.

3. The check for ClearArray node is missing when searching for
a better memory edge during EA, memory optimization and an object
scalar replacement. We can't bypass it since it is the part of object
initialization (zeroing).

4. Add missing checks for string intrinsic nodes to adjust the escape state
(non scalar replaceable) of char[] arrays they use.

5. Move code for searching objects which are not scalar replaceable to separate
method verify_escape_state() since the code became too large. Add a simple
control flow check to find initializing store for oop fields.

6. Added asserts to check cases which don't have to be handled.

7. I also changed instance type setting for sequential CheckCastPP nodes
to change following CheckCastPP node type to allocation type
if it is subtype.

8. And I found that G1 barriers CallLeaf node case is missing
in process_call_arguments() (as result referenced allocations
were marked as global escape instead of thread local).
                                     
2009-12-11
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/f96a1a986f7b
                                     
2009-12-10
SUGGESTED FIX

-XX:-DoEscapeAnalysis
                                     
2009-11-19
EVALUATION

It is different from 6894807. It is caused by EA lost the array allocation for CopyOnWriteArrayList (the "array" field should not be NULL):

027     CALL,static  wrapper for: uncommon_trap(reason='unloaded' action='reinterpret' index='8')
        # CopyOnWriteArrayListTest::testAddAll1_IndexOutOfBoundsException @ bci:10  L[0]=_ L[1]=_ STK[0]=#ScObj0 STK[1]=#-1
        # ScObj0 java/util/concurrent/CopyOnWriteArrayList={ [lock :0]=#ScObj1, [array :1]=#NULL }
        # ScObj1 java/util/concurrent/locks/ReentrantLock={ [sync :0]=#ScObj2 }
        # ScObj2 java/util/concurrent/locks/ReentrantLock$NonfairSync={ [exclusiveOwnerThread :0]=#NULL, [state :1]=#0, [head :2]=#NULL, [tail :3]=#NULL }
        # OopMap{off=44}
                                     
2009-10-26



Hardware and Software, Engineered to Work Together