src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/WildcardTypeImpl.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 38,57 **** * Implementation of WildcardType interface for core reflection. */ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator implements WildcardType { // upper bounds - evaluated lazily ! private Type[] upperBounds; // lower bounds - evaluated lazily ! private Type[] lowerBounds; // The ASTs for the bounds. We are required to evaluate the bounds ! // lazily, so we store these at least until we are first asked // for the bounds. This also neatly solves the // problem with F-bounds - you can't reify them before the formal // is defined. ! private FieldTypeSignature[] upperBoundASTs; ! private FieldTypeSignature[] lowerBoundASTs; // constructor is private to enforce access through static factory private WildcardTypeImpl(FieldTypeSignature[] ubs, FieldTypeSignature[] lbs, GenericsFactory f) { --- 38,57 ---- * Implementation of WildcardType interface for core reflection. */ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator implements WildcardType { // upper bounds - evaluated lazily ! private volatile Type[] upperBounds; // lower bounds - evaluated lazily ! private volatile Type[] lowerBounds; // The ASTs for the bounds. We are required to evaluate the bounds ! // lazily, so we store these until we are first asked // for the bounds. This also neatly solves the // problem with F-bounds - you can't reify them before the formal // is defined. ! private volatile FieldTypeSignature[] upperBoundASTs; ! private volatile FieldTypeSignature[] lowerBoundASTs; // constructor is private to enforce access through static factory private WildcardTypeImpl(FieldTypeSignature[] ubs, FieldTypeSignature[] lbs, GenericsFactory f) {
*** 74,102 **** FieldTypeSignature[] lbs, GenericsFactory f) { return new WildcardTypeImpl(ubs, lbs, f); } - // Accessors - - // accessor for ASTs for upper bounds. Must not be called after upper - // bounds have been evaluated, because we might throw the ASTs - // away (but that is not thread-safe, is it?) - private FieldTypeSignature[] getUpperBoundASTs() { - // check that upper bounds were not evaluated yet - assert(upperBounds == null); - return upperBoundASTs; - } - // accessor for ASTs for lower bounds. Must not be called after lower - // bounds have been evaluated, because we might throw the ASTs - // away (but that is not thread-safe, is it?) - private FieldTypeSignature[] getLowerBoundASTs() { - // check that lower bounds were not evaluated yet - assert(lowerBounds == null); - return lowerBoundASTs; - } - /** * Returns an array of <tt>Type</tt> objects representing the upper * bound(s) of this type variable. Note that if no upper bound is * explicitly declared, the upper bound is <tt>Object</tt>. * --- 74,83 ----
*** 116,142 **** * bounds refer to a parameterized type that cannot be instantiated * for any reason */ public Type[] getUpperBounds() { // lazily initialize bounds if necessary ! if (upperBounds == null) { ! FieldTypeSignature[] fts = getUpperBoundASTs(); // get AST ! // allocate result array; note that // keeping ts and bounds separate helps with threads ! Type[] ts = new Type[fts.length]; // iterate over bound trees, reifying each in turn for ( int j = 0; j < fts.length; j++) { Reifier r = getReifier(); fts[j].accept(r); ts[j] = r.getResult(); } // cache result upperBounds = ts; ! // could throw away upper bound ASTs here; thread safety? } ! return upperBounds.clone(); // return cached bounds } /** * Returns an array of <tt>Type</tt> objects representing the * lower bound(s) of this type variable. Note that if no lower bound is --- 97,130 ---- * bounds refer to a parameterized type that cannot be instantiated * for any reason */ public Type[] getUpperBounds() { // lazily initialize bounds if necessary ! Type[] ts = upperBounds; ! if (ts == null) { ! FieldTypeSignature[] fts = upperBoundASTs; // get AST ! if (fts == null) { ! // race with concurrent initialization ! ts = upperBounds; ! assert ts != null; ! } else { // allocate result array; note that // keeping ts and bounds separate helps with threads ! ts = new Type[fts.length]; // iterate over bound trees, reifying each in turn for ( int j = 0; j < fts.length; j++) { Reifier r = getReifier(); fts[j].accept(r); ts[j] = r.getResult(); } // cache result upperBounds = ts; ! // throw away upper bound ASTs ! upperBoundASTs = null; ! } } ! return ts.clone(); // return cached bounds } /** * Returns an array of <tt>Type</tt> objects representing the * lower bound(s) of this type variable. Note that if no lower bound is
*** 159,184 **** * bounds refer to a parameterized type that cannot be instantiated * for any reason */ public Type[] getLowerBounds() { // lazily initialize bounds if necessary ! if (lowerBounds == null) { ! FieldTypeSignature[] fts = getLowerBoundASTs(); // get AST // allocate result array; note that // keeping ts and bounds separate helps with threads ! Type[] ts = new Type[fts.length]; // iterate over bound trees, reifying each in turn for ( int j = 0; j < fts.length; j++) { Reifier r = getReifier(); fts[j].accept(r); ts[j] = r.getResult(); } // cache result lowerBounds = ts; ! // could throw away lower bound ASTs here; thread safety? } ! return lowerBounds.clone(); // return cached bounds } public String toString() { Type[] lowerBounds = getLowerBounds(); Type[] bounds = lowerBounds; --- 147,180 ---- * bounds refer to a parameterized type that cannot be instantiated * for any reason */ public Type[] getLowerBounds() { // lazily initialize bounds if necessary ! Type[] ts = lowerBounds; ! if (ts == null) { ! FieldTypeSignature[] fts = lowerBoundASTs; // get AST ! if (fts == null) { ! // race with concurrent initialization ! ts = lowerBounds; ! assert ts != null; ! } else { // allocate result array; note that // keeping ts and bounds separate helps with threads ! ts = new Type[fts.length]; // iterate over bound trees, reifying each in turn for ( int j = 0; j < fts.length; j++) { Reifier r = getReifier(); fts[j].accept(r); ts[j] = r.getResult(); } // cache result lowerBounds = ts; ! // throw away lower bound ASTs ! lowerBoundASTs = null; ! } } ! return ts.clone(); // return cached bounds } public String toString() { Type[] lowerBounds = getLowerBounds(); Type[] bounds = lowerBounds;