test/compiler/7190310/Test7190310.java

Thu, 17 Apr 2014 16:09:08 -0700

author
amurillo
date
Thu, 17 Apr 2014 16:09:08 -0700
changeset 6635
49b5160951dd
parent 4449
bf623b2d5508
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag hs25.20-b11 for changeset b6a2ba7d3ea7

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

mercurial