1 /*
2 * Copyright (c) 2002, 2010, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
47 * @see DisposerRecord
48 */
49 public class Disposer implements Runnable {
50 private static final ReferenceQueue queue = new ReferenceQueue();
51 private static final Hashtable records = new Hashtable();
52
53 private static Disposer disposerInstance;
54 public static final int WEAK = 0;
55 public static final int PHANTOM = 1;
56 public static int refType = PHANTOM;
57
58 static {
59 java.security.AccessController.doPrivileged(
60 new java.security.PrivilegedAction<Void>() {
61 public Void run() {
62 System.loadLibrary("awt");
63 return null;
64 }
65 });
66 initIDs();
67 String type = (String) java.security.AccessController.doPrivileged(
68 new sun.security.action.GetPropertyAction("sun.java2d.reftype"));
69 if (type != null) {
70 if (type.equals("weak")) {
71 refType = WEAK;
72 System.err.println("Using WEAK refs");
73 } else {
74 refType = PHANTOM;
75 System.err.println("Using PHANTOM refs");
76 }
77 }
78 disposerInstance = new Disposer();
79 java.security.AccessController.doPrivileged(
80 new java.security.PrivilegedAction() {
81 public Object run() {
82 /* The thread must be a member of a thread group
83 * which will not get GCed before VM exit.
84 * Make its parent the top-level thread group.
85 */
86 ThreadGroup tg = Thread.currentThread().getThreadGroup();
87 for (ThreadGroup tgn = tg;
|
1 /*
2 * Copyright (c) 2002, 2014, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
47 * @see DisposerRecord
48 */
49 public class Disposer implements Runnable {
50 private static final ReferenceQueue queue = new ReferenceQueue();
51 private static final Hashtable records = new Hashtable();
52
53 private static Disposer disposerInstance;
54 public static final int WEAK = 0;
55 public static final int PHANTOM = 1;
56 public static int refType = PHANTOM;
57
58 static {
59 java.security.AccessController.doPrivileged(
60 new java.security.PrivilegedAction<Void>() {
61 public Void run() {
62 System.loadLibrary("awt");
63 return null;
64 }
65 });
66 initIDs();
67 String type = java.security.AccessController.doPrivileged(
68 new sun.security.action.GetPropertyAction("sun.java2d.reftype"));
69 if (type != null) {
70 if (type.equals("weak")) {
71 refType = WEAK;
72 System.err.println("Using WEAK refs");
73 } else {
74 refType = PHANTOM;
75 System.err.println("Using PHANTOM refs");
76 }
77 }
78 disposerInstance = new Disposer();
79 java.security.AccessController.doPrivileged(
80 new java.security.PrivilegedAction() {
81 public Object run() {
82 /* The thread must be a member of a thread group
83 * which will not get GCed before VM exit.
84 * Make its parent the top-level thread group.
85 */
86 ThreadGroup tg = Thread.currentThread().getThreadGroup();
87 for (ThreadGroup tgn = tg;
|