< prev index next >

src/java.desktop/share/classes/sun/java2d/Disposer.java

Print this page
rev 55657 : 8227587: Add internal privileged System.loadLibrary
Reviewed-by: rriggs
   1 /*
   2  * Copyright (c) 2002, 2015, 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


  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
  49  * of the associated DisposerRecord object will be called.
  50  *
  51  * @see DisposerRecord
  52  */
  53 public class Disposer implements Runnable {
  54     private static final ReferenceQueue<Object> queue = new ReferenceQueue<>();
  55     private static final Hashtable<java.lang.ref.Reference<Object>, DisposerRecord> records =
  56         new Hashtable<>();
  57 
  58     private static Disposer disposerInstance;
  59     public static final int WEAK = 0;
  60     public static final int PHANTOM = 1;
  61     public static int refType = PHANTOM;
  62 
  63     static {
  64         java.security.AccessController.doPrivileged(
  65             new java.security.PrivilegedAction<Void>() {
  66                 public Void run() {
  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);


   1 /*
   2  * Copyright (c) 2002, 2019, 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


  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
  49  * of the associated DisposerRecord object will be called.
  50  *
  51  * @see DisposerRecord
  52  */
  53 public class Disposer implements Runnable {
  54     private static final ReferenceQueue<Object> queue = new ReferenceQueue<>();
  55     private static final Hashtable<java.lang.ref.Reference<Object>, DisposerRecord> records =
  56         new Hashtable<>();
  57 
  58     private static Disposer disposerInstance;
  59     public static final int WEAK = 0;
  60     public static final int PHANTOM = 1;
  61     public static int refType = PHANTOM;
  62 
  63     static {
  64         jdk.internal.access.SharedSecrets.getJavaLangAccess().loadLibrary("awt");






  65         initIDs();
  66         String type = java.security.AccessController.doPrivileged(
  67                 new sun.security.action.GetPropertyAction("sun.java2d.reftype"));
  68         if (type != null) {
  69             if (type.equals("weak")) {
  70                 refType = WEAK;
  71                 System.err.println("Using WEAK refs");
  72             } else {
  73                 refType = PHANTOM;
  74                 System.err.println("Using PHANTOM refs");
  75             }
  76         }
  77         disposerInstance = new Disposer();
  78         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
  79             String name = "Java2D Disposer";
  80             ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
  81             Thread t = new Thread(rootTG, disposerInstance, name, 0, false);
  82             t.setContextClassLoader(null);
  83             t.setDaemon(true);
  84             t.setPriority(Thread.MAX_PRIORITY);


< prev index next >