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
23 * questions.
24 */
25
26 package sun.java2d;
27
28 import sun.awt.util.ThreadGroupUtils;
29 import sun.misc.ManagedLocalsThread;
30
31 import java.lang.ref.Reference;
32 import java.lang.ref.ReferenceQueue;
33 import java.lang.ref.PhantomReference;
34 import java.lang.ref.WeakReference;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import java.util.ArrayList;
38 import java.util.Hashtable;
39
40 /**
41 * This class is used for registering and disposing the native
42 * data associated with java objects.
43 *
44 * The object can register itself by calling one of the addRecord
45 * methods and providing either the pointer to the native disposal
46 * method or a descendant of the DisposerRecord class with overridden
47 * dispose() method.
48 *
49 * When the object becomes unreachable, the dispose() method
68 System.loadLibrary("awt");
69 return null;
70 }
71 });
72 initIDs();
73 String type = java.security.AccessController.doPrivileged(
74 new sun.security.action.GetPropertyAction("sun.java2d.reftype"));
75 if (type != null) {
76 if (type.equals("weak")) {
77 refType = WEAK;
78 System.err.println("Using WEAK refs");
79 } else {
80 refType = PHANTOM;
81 System.err.println("Using PHANTOM refs");
82 }
83 }
84 disposerInstance = new Disposer();
85 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
86 String name = "Java2D Disposer";
87 ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
88 Thread t = new ManagedLocalsThread(rootTG, disposerInstance, name);
89 t.setContextClassLoader(null);
90 t.setDaemon(true);
91 t.setPriority(Thread.MAX_PRIORITY);
92 t.start();
93 return null;
94 });
95 }
96
97 /**
98 * Registers the object and the native data for later disposal.
99 * @param target Object to be registered
100 * @param disposeMethod pointer to the native disposal method
101 * @param pData pointer to the data to be passed to the
102 * native disposal method
103 */
104 public static void addRecord(Object target,
105 long disposeMethod, long pData)
106 {
107 disposerInstance.add(target,
108 new DefaultDisposerRecord(disposeMethod, pData));
|
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
23 * questions.
24 */
25
26 package sun.java2d;
27
28 import sun.awt.util.ThreadGroupUtils;
29
30 import java.lang.ref.Reference;
31 import java.lang.ref.ReferenceQueue;
32 import java.lang.ref.PhantomReference;
33 import java.lang.ref.WeakReference;
34 import java.security.AccessController;
35 import java.security.PrivilegedAction;
36 import java.util.ArrayList;
37 import java.util.Hashtable;
38
39 /**
40 * This class is used for registering and disposing the native
41 * data associated with java objects.
42 *
43 * The object can register itself by calling one of the addRecord
44 * methods and providing either the pointer to the native disposal
45 * method or a descendant of the DisposerRecord class with overridden
46 * dispose() method.
47 *
48 * When the object becomes unreachable, the dispose() method
67 System.loadLibrary("awt");
68 return null;
69 }
70 });
71 initIDs();
72 String type = java.security.AccessController.doPrivileged(
73 new sun.security.action.GetPropertyAction("sun.java2d.reftype"));
74 if (type != null) {
75 if (type.equals("weak")) {
76 refType = WEAK;
77 System.err.println("Using WEAK refs");
78 } else {
79 refType = PHANTOM;
80 System.err.println("Using PHANTOM refs");
81 }
82 }
83 disposerInstance = new Disposer();
84 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
85 String name = "Java2D Disposer";
86 ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
87 Thread t = new Thread(rootTG, disposerInstance, name, 0, false);
88 t.setContextClassLoader(null);
89 t.setDaemon(true);
90 t.setPriority(Thread.MAX_PRIORITY);
91 t.start();
92 return null;
93 });
94 }
95
96 /**
97 * Registers the object and the native data for later disposal.
98 * @param target Object to be registered
99 * @param disposeMethod pointer to the native disposal method
100 * @param pData pointer to the data to be passed to the
101 * native disposal method
102 */
103 public static void addRecord(Object target,
104 long disposeMethod, long pData)
105 {
106 disposerInstance.add(target,
107 new DefaultDisposerRecord(disposeMethod, pData));
|