test/compiler/7190310/Test7190310.java

Thu, 29 Nov 2012 11:30:04 -0800

author
katleman
date
Thu, 29 Nov 2012 11:30:04 -0800
changeset 4283
2f6dc76eb8e5
parent 4002
09aad8452938
child 4449
bf623b2d5508
permissions
-rw-r--r--

Added tag jdk8-b66 for changeset 01684f7fee1b

kvn@4002 1 /*
kvn@4002 2 * Copyright (c) 2012, 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@4002 26 * Manual test
kvn@4002 27 */
kvn@4002 28
kvn@4002 29 import java.lang.ref.*;
kvn@4002 30
kvn@4002 31 public class Test7190310 {
kvn@4002 32 private static Object str = new Object() {
kvn@4002 33 public String toString() {
kvn@4002 34 return "The Object";
kvn@4002 35 }
kvn@4002 36
kvn@4002 37 protected void finalize() throws Throwable {
kvn@4002 38 System.out.println("The Object is being finalized");
kvn@4002 39 super.finalize();
kvn@4002 40 }
kvn@4002 41 };
kvn@4002 42 private final static ReferenceQueue<Object> rq =
kvn@4002 43 new ReferenceQueue<Object>();
kvn@4002 44 private final static WeakReference<Object> wr =
kvn@4002 45 new WeakReference<Object>(str, rq);
kvn@4002 46
kvn@4002 47 public static void main(String[] args)
kvn@4002 48 throws InterruptedException {
kvn@4002 49 Thread reader = new Thread() {
kvn@4002 50 public void run() {
kvn@4002 51 while (wr.get() != null) {
kvn@4002 52 }
kvn@4002 53 System.out.println("wr.get() returned null");
kvn@4002 54 }
kvn@4002 55 };
kvn@4002 56
kvn@4002 57 Thread queueReader = new Thread() {
kvn@4002 58 public void run() {
kvn@4002 59 try {
kvn@4002 60 Reference<? extends Object> ref = rq.remove();
kvn@4002 61 System.out.println(ref);
kvn@4002 62 System.out.println("queueReader returned, ref==wr is "
kvn@4002 63 + (ref == wr));
kvn@4002 64 } catch (InterruptedException e) {
kvn@4002 65 System.err.println("Sleep interrupted - exiting");
kvn@4002 66 }
kvn@4002 67 }
kvn@4002 68 };
kvn@4002 69
kvn@4002 70 reader.start();
kvn@4002 71 queueReader.start();
kvn@4002 72
kvn@4002 73 Thread.sleep(1000);
kvn@4002 74 str = null;
kvn@4002 75 System.gc();
kvn@4002 76 }
kvn@4002 77 }
kvn@4002 78

mercurial