test/hotspot/jtreg/compiler/c2/Test7190310.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 47216 71c04702a3d5
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     1
/*
15212
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     4
 *
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     8
 *
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    13
 * accompanied this code).
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    14
 *
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    18
 *
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    21
 * questions.
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    22
 */
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    23
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    24
/*
15212
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    25
 * @test
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    26
 * @bug 7190310
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    27
 * @summary Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    29
 * @run main/othervm/timeout=600 -Xbatch compiler.c2.Test7190310
15212
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    30
 */
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    31
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    32
/*
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    33
 * Note bug exhibits as infinite loop, timeout is helpful.
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    34
 * It should normally finish pretty quickly, but on some especially slow machines
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    35
 * it may not.  The companion _unsafe test lacks a timeout, but that is okay.
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    36
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    37
package compiler.c2;
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    38
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    39
import java.lang.ref.Reference;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    40
import java.lang.ref.ReferenceQueue;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    41
import java.lang.ref.WeakReference;
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    42
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    43
public class Test7190310 {
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    44
    private static Object str = new Object() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    45
        public String toString() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    46
            return "The Object";
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    47
        }
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    48
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    49
        protected void finalize() throws Throwable {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    50
            System.out.println("The Object is being finalized");
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    51
            super.finalize();
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    52
        }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    53
    };
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    54
    private final static ReferenceQueue<Object> rq =
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    55
            new ReferenceQueue<Object>();
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    56
    private final static WeakReference<Object> wr =
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    57
            new WeakReference<Object>(str, rq);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    58
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    59
    public static void main(String[] args)
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    60
            throws InterruptedException {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    61
        Thread reader = new Thread() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    62
            public void run() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    63
                while (wr.get() != null) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    64
                }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    65
                System.out.println("wr.get() returned null");
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    66
            }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    67
        };
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    68
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    69
        Thread queueReader = new Thread() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    70
            public void run() {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    71
                try {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    72
                    Reference<? extends Object> ref = rq.remove();
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    73
                    System.out.println(ref);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    74
                    System.out.println("queueReader returned, ref==wr is "
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    75
                            + (ref == wr));
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    76
                } catch (InterruptedException e) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    77
                    System.err.println("Sleep interrupted - exiting");
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    78
                }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    79
            }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    80
        };
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    81
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    82
        reader.start();
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    83
        queueReader.start();
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    84
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    85
        Thread.sleep(1000);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    86
        str = null;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    87
        System.gc();
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    88
    }
13486
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    89
}
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    90