< prev index next >

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

Print this page
rev 55532 : 8223582: [lworld] WeakReference of an inline type should throw


 379      * Throws {@link CloneNotSupportedException}. A {@code Reference} cannot be
 380      * meaningfully cloned. Construct a new {@code Reference} instead.
 381      *
 382      * @return never returns normally
 383      * @throws  CloneNotSupportedException always
 384      *
 385      * @since 11
 386      */
 387     @Override
 388     protected Object clone() throws CloneNotSupportedException {
 389         throw new CloneNotSupportedException();
 390     }
 391 
 392     /* -- Constructors -- */
 393 
 394     Reference(T referent) {
 395         this(referent, null);
 396     }
 397 
 398     Reference(T referent, ReferenceQueue<? super T> queue) {




 399         this.referent = referent;
 400         this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
 401     }
 402 
 403     /**
 404      * Ensures that the object referenced by the given reference remains
 405      * <a href="package-summary.html#reachability"><em>strongly reachable</em></a>,
 406      * regardless of any prior actions of the program that might otherwise cause
 407      * the object to become unreachable; thus, the referenced object is not
 408      * reclaimable by garbage collection at least until after the invocation of
 409      * this method.  Invocation of this method does not itself initiate garbage
 410      * collection or finalization.
 411      *
 412      * <p> This method establishes an ordering for
 413      * <a href="package-summary.html#reachability"><em>strong reachability</em></a>
 414      * with respect to garbage collection.  It controls relations that are
 415      * otherwise only implicit in a program -- the reachability conditions
 416      * triggering garbage collection.  This method is designed for use in
 417      * uncommon situations of premature finalization where using
 418      * {@code synchronized} blocks or methods, or using other synchronization




 379      * Throws {@link CloneNotSupportedException}. A {@code Reference} cannot be
 380      * meaningfully cloned. Construct a new {@code Reference} instead.
 381      *
 382      * @return never returns normally
 383      * @throws  CloneNotSupportedException always
 384      *
 385      * @since 11
 386      */
 387     @Override
 388     protected Object clone() throws CloneNotSupportedException {
 389         throw new CloneNotSupportedException();
 390     }
 391 
 392     /* -- Constructors -- */
 393 
 394     Reference(T referent) {
 395         this(referent, null);
 396     }
 397 
 398     Reference(T referent, ReferenceQueue<? super T> queue) {
 399         if (referent != null && referent.getClass().isInlineClass()) {
 400             throw new IllegalArgumentException("cannot reference an inline value of type: " +
 401                     referent.getClass().getName());
 402         }
 403         this.referent = referent;
 404         this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
 405     }
 406 
 407     /**
 408      * Ensures that the object referenced by the given reference remains
 409      * <a href="package-summary.html#reachability"><em>strongly reachable</em></a>,
 410      * regardless of any prior actions of the program that might otherwise cause
 411      * the object to become unreachable; thus, the referenced object is not
 412      * reclaimable by garbage collection at least until after the invocation of
 413      * this method.  Invocation of this method does not itself initiate garbage
 414      * collection or finalization.
 415      *
 416      * <p> This method establishes an ordering for
 417      * <a href="package-summary.html#reachability"><em>strong reachability</em></a>
 418      * with respect to garbage collection.  It controls relations that are
 419      * otherwise only implicit in a program -- the reachability conditions
 420      * triggering garbage collection.  This method is designed for use in
 421      * uncommon situations of premature finalization where using
 422      * {@code synchronized} blocks or methods, or using other synchronization


< prev index next >