comparison test/compiler/7190310/Test7190310.java @ 6615:09aad8452938

7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops Summary: In C2 add software membar after load from Reference.referent field to prevent commoning of loads across safepoint since GC can change its value. In C1 always generate Reference.get() intrinsic. Reviewed-by: roland, twisti, dholmes, johnc
author kvn
date Mon, 20 Aug 2012 09:58:58 -0700
parents
children bf623b2d5508
comparison
equal deleted inserted replaced
6614:006050192a5a 6615:09aad8452938
1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /*
26 * Manual test
27 */
28
29 import java.lang.ref.*;
30
31 public class Test7190310 {
32 private static Object str = new Object() {
33 public String toString() {
34 return "The Object";
35 }
36
37 protected void finalize() throws Throwable {
38 System.out.println("The Object is being finalized");
39 super.finalize();
40 }
41 };
42 private final static ReferenceQueue<Object> rq =
43 new ReferenceQueue<Object>();
44 private final static WeakReference<Object> wr =
45 new WeakReference<Object>(str, rq);
46
47 public static void main(String[] args)
48 throws InterruptedException {
49 Thread reader = new Thread() {
50 public void run() {
51 while (wr.get() != null) {
52 }
53 System.out.println("wr.get() returned null");
54 }
55 };
56
57 Thread queueReader = new Thread() {
58 public void run() {
59 try {
60 Reference<? extends Object> ref = rq.remove();
61 System.out.println(ref);
62 System.out.println("queueReader returned, ref==wr is "
63 + (ref == wr));
64 } catch (InterruptedException e) {
65 System.err.println("Sleep interrupted - exiting");
66 }
67 }
68 };
69
70 reader.start();
71 queueReader.start();
72
73 Thread.sleep(1000);
74 str = null;
75 System.gc();
76 }
77 }
78