src/share/classes/sun/reflect/generics/scope/AbstractScope.java

Print this page
rev 7735 : 8064846: Lazy-init thread safety problems in core reflection


  25 
  26 package sun.reflect.generics.scope;
  27 
  28 import java.lang.reflect.GenericDeclaration;
  29 import java.lang.reflect.TypeVariable;
  30 
  31 
  32 
  33 /**
  34  * Abstract superclass for lazy scope objects, used when building
  35  * factories for generic information repositories.
  36  * The type parameter <tt>D</tt> represents the type of reflective
  37  * object whose scope this class is representing.
  38  * <p> To subclass this, all one needs to do is implement
  39  * <tt>computeEnclosingScope</tt> and the subclass' constructor.
  40  */
  41 public abstract class AbstractScope<D extends GenericDeclaration>
  42     implements Scope {
  43 
  44     private final D recvr; // the declaration whose scope this instance represents
  45     private volatile Scope enclosingScope; // the enclosing scope of this scope


  46 
  47     /**
  48      * Constructor. Takes a reflective object whose scope the newly
  49      * constructed instance will represent.
  50      * @param D - A generic declaration whose scope the newly
  51      * constructed instance will represent
  52      */
  53     protected AbstractScope(D decl){ recvr = decl;}
  54 
  55     /**
  56      * Accessor for the receiver - the object whose scope this <tt>Scope</tt>
  57      * object represents.
  58      * @return The object whose scope this <tt>Scope</tt> object represents
  59      */
  60     protected D getRecvr() {return recvr;}
  61 
  62     /** This method must be implemented by any concrete subclass.
  63      * It must return the enclosing scope of this scope. If this scope
  64      * is a top-level scope, an instance of  DummyScope must be returned.
  65      * @return The enclosing scope of this scope




  25 
  26 package sun.reflect.generics.scope;
  27 
  28 import java.lang.reflect.GenericDeclaration;
  29 import java.lang.reflect.TypeVariable;
  30 
  31 
  32 
  33 /**
  34  * Abstract superclass for lazy scope objects, used when building
  35  * factories for generic information repositories.
  36  * The type parameter <tt>D</tt> represents the type of reflective
  37  * object whose scope this class is representing.
  38  * <p> To subclass this, all one needs to do is implement
  39  * <tt>computeEnclosingScope</tt> and the subclass' constructor.
  40  */
  41 public abstract class AbstractScope<D extends GenericDeclaration>
  42     implements Scope {
  43 
  44     private final D recvr; // the declaration whose scope this instance represents
  45 
  46     /** The enclosing scope of this scope.  Lazily initialized. */
  47     private volatile Scope enclosingScope;
  48 
  49     /**
  50      * Constructor. Takes a reflective object whose scope the newly
  51      * constructed instance will represent.
  52      * @param D - A generic declaration whose scope the newly
  53      * constructed instance will represent
  54      */
  55     protected AbstractScope(D decl){ recvr = decl;}
  56 
  57     /**
  58      * Accessor for the receiver - the object whose scope this <tt>Scope</tt>
  59      * object represents.
  60      * @return The object whose scope this <tt>Scope</tt> object represents
  61      */
  62     protected D getRecvr() {return recvr;}
  63 
  64     /** This method must be implemented by any concrete subclass.
  65      * It must return the enclosing scope of this scope. If this scope
  66      * is a top-level scope, an instance of  DummyScope must be returned.
  67      * @return The enclosing scope of this scope