< prev index next >

src/java.base/share/classes/java/lang/ref/Reference.java

Print this page


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


 218         ThreadGroup tg = Thread.currentThread().getThreadGroup();
 219         for (ThreadGroup tgn = tg;
 220              tgn != null;
 221              tg = tgn, tgn = tg.getParent());
 222         Thread handler = new ReferenceHandler(tg, "Reference Handler");
 223         /* If there were a special system-only priority greater than
 224          * MAX_PRIORITY, it would be used here
 225          */
 226         handler.setPriority(Thread.MAX_PRIORITY);
 227         handler.setDaemon(true);
 228         handler.start();
 229 
 230         // provide access in SharedSecrets
 231         SharedSecrets.setJavaLangRefAccess(new JavaLangRefAccess() {
 232             @Override
 233             public boolean waitForReferenceProcessing()
 234                 throws InterruptedException
 235             {
 236                 return Reference.waitForReferenceProcessing();
 237             }





 238         });
 239     }
 240 
 241     /* -- Referent accessor and setters -- */
 242 
 243     /**
 244      * Returns this reference object's referent.  If this reference object has
 245      * been cleared, either by the program or by the garbage collector, then
 246      * this method returns <code>null</code>.
 247      *
 248      * @return   The object to which this reference refers, or
 249      *           <code>null</code> if this reference object has been cleared
 250      */
 251     @HotSpotIntrinsicCandidate
 252     public T get() {
 253         return this.referent;
 254     }
 255 
 256     /**
 257      * Clears this reference object.  Invoking this method will not cause this


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


 218         ThreadGroup tg = Thread.currentThread().getThreadGroup();
 219         for (ThreadGroup tgn = tg;
 220              tgn != null;
 221              tg = tgn, tgn = tg.getParent());
 222         Thread handler = new ReferenceHandler(tg, "Reference Handler");
 223         /* If there were a special system-only priority greater than
 224          * MAX_PRIORITY, it would be used here
 225          */
 226         handler.setPriority(Thread.MAX_PRIORITY);
 227         handler.setDaemon(true);
 228         handler.start();
 229 
 230         // provide access in SharedSecrets
 231         SharedSecrets.setJavaLangRefAccess(new JavaLangRefAccess() {
 232             @Override
 233             public boolean waitForReferenceProcessing()
 234                 throws InterruptedException
 235             {
 236                 return Reference.waitForReferenceProcessing();
 237             }
 238 
 239             @Override
 240             public void runFinalization() {
 241                 Finalizer.runFinalization();
 242             }
 243         });
 244     }
 245 
 246     /* -- Referent accessor and setters -- */
 247 
 248     /**
 249      * Returns this reference object's referent.  If this reference object has
 250      * been cleared, either by the program or by the garbage collector, then
 251      * this method returns <code>null</code>.
 252      *
 253      * @return   The object to which this reference refers, or
 254      *           <code>null</code> if this reference object has been cleared
 255      */
 256     @HotSpotIntrinsicCandidate
 257     public T get() {
 258         return this.referent;
 259     }
 260 
 261     /**
 262      * Clears this reference object.  Invoking this method will not cause this


< prev index next >