hotspot/test/compiler/7190310/Test7190310.java
author jjg
Fri, 07 Nov 2014 14:51:35 -0800
changeset 27547 d07b3dcbc707
parent 15212 bbda5353d846
permissions -rw-r--r--
8063145: ToolBox should support extracting classes from a JavaFileManager/Location Reviewed-by: ksrini
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
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    25
/*
15212
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    26
 * @test
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    27
 * @bug 7190310
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    28
 * @summary Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
bbda5353d846 8006204: please JTREGify test/compiler/7190310/Test7190310.java
kvn
parents: 13486
diff changeset
    29
 * @run main/othervm/timeout=600 -Xbatch Test7190310
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
 */
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    37
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    38
import java.lang.ref.*;
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    39
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    40
public class Test7190310 {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    41
  private static Object str = new Object() {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    42
    public String toString() {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    43
      return "The Object";
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    44
    }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    45
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    46
    protected void finalize() throws Throwable {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    47
      System.out.println("The Object is being finalized");
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    48
      super.finalize();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    49
    }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    50
  };
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    51
  private final static ReferenceQueue<Object> rq =
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    52
      new ReferenceQueue<Object>();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    53
  private final static WeakReference<Object> wr =
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    54
      new WeakReference<Object>(str, rq);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    55
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    56
  public static void main(String[] args)
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    57
      throws InterruptedException {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    58
    Thread reader = new Thread() {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    59
      public void run() {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    60
        while (wr.get() != null) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    61
        }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    62
        System.out.println("wr.get() returned null");
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    63
      }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    64
    };
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    65
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    66
    Thread queueReader = new Thread() {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    67
      public void run() {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    68
        try {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    69
          Reference<? extends Object> ref = rq.remove();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    70
          System.out.println(ref);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    71
          System.out.println("queueReader returned, ref==wr is "
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    72
              + (ref == wr));
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    73
        } catch (InterruptedException e) {
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    74
          System.err.println("Sleep interrupted - exiting");
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    75
        }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    76
      }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    77
    };
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    78
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    79
    reader.start();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    80
    queueReader.start();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    81
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    82
    Thread.sleep(1000);
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    83
    str = null;
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    84
    System.gc();
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    85
  }
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    86
}
4f0635e148c1 7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff changeset
    87