< prev index next >

src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.org.objectweb.asm.ClassWriter;
  29 import jdk.internal.org.objectweb.asm.Label;
  30 import jdk.internal.org.objectweb.asm.MethodVisitor;
  31 import jdk.internal.org.objectweb.asm.Opcodes;
  32 import jdk.internal.vm.annotation.ForceInline;
  33 import jdk.internal.misc.Unsafe;
  34 
  35 import java.lang.invoke.MethodHandles.Lookup;
  36 import java.security.AccessController;
  37 import java.util.*;
  38 import java.util.concurrent.ConcurrentHashMap;
  39 import java.util.concurrent.ConcurrentMap;
  40 import java.util.function.Function;
  41 import sun.security.action.GetPropertyAction;
  42 
  43 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  44 
  45 /**
  46  * <p>Methods to facilitate the creation of String concatenation methods, that
  47  * can be used to efficiently concatenate a known number of arguments of known
  48  * types, possibly after type adaptation and partial evaluation of arguments.
  49  * These methods are typically used as <em>bootstrap methods</em> for {@code
  50  * invokedynamic} call sites, to support the <em>string concatenation</em>
  51  * feature of the Java Programming Language.
  52  *
  53  * <p>Indirect access to the behavior specified by the provided {@code
  54  * MethodHandle} proceeds in order through two phases:
  55  *
  56  * <ol>


 171     /**
 172      * Enables debugging: this may print debugging messages, perform additional (non-neutral for performance)
 173      * checks, etc.
 174      */
 175     private static final boolean DEBUG;
 176 
 177     /**
 178      * Enables caching of strategy stubs. This may improve the linkage time by reusing the generated
 179      * code, at the expense of contaminating the profiles.
 180      */
 181     private static final boolean CACHE_ENABLE;
 182 
 183     private static final ConcurrentMap<Key, MethodHandle> CACHE;
 184 
 185     /**
 186      * Dump generated classes to disk, for debugging purposes.
 187      */
 188     private static final ProxyClassesDumper DUMPER;
 189 
 190     static {
 191         final String strategy = AccessController.doPrivileged(
 192                 new GetPropertyAction("java.lang.invoke.stringConcat"));
 193         CACHE_ENABLE = Boolean.parseBoolean(AccessController.doPrivileged(
 194                 new GetPropertyAction("java.lang.invoke.stringConcat.cache")));
 195         DEBUG = Boolean.parseBoolean(AccessController.doPrivileged(
 196                 new GetPropertyAction("java.lang.invoke.stringConcat.debug")));
 197         final String dumpPath = AccessController.doPrivileged(
 198                 new GetPropertyAction("java.lang.invoke.stringConcat.dumpClasses"));

 199 
 200         STRATEGY = (strategy == null) ? DEFAULT_STRATEGY : Strategy.valueOf(strategy);
 201         CACHE = CACHE_ENABLE ? new ConcurrentHashMap<>() : null;
 202         DUMPER = (dumpPath == null) ? null : ProxyClassesDumper.getInstance(dumpPath);
 203     }
 204 
 205     /**
 206      * Cache key is a composite of:
 207      *   - class name, that lets to disambiguate stubs, to avoid excess sharing
 208      *   - method type, describing the dynamic arguments for concatenation
 209      *   - concat recipe, describing the constants and concat shape
 210      */
 211     private static final class Key {
 212         final String className;
 213         final MethodType mt;
 214         final Recipe recipe;
 215 
 216         public Key(String className, MethodType mt, Recipe recipe) {
 217             this.className = className;
 218             this.mt = mt;




  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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.org.objectweb.asm.ClassWriter;
  29 import jdk.internal.org.objectweb.asm.Label;
  30 import jdk.internal.org.objectweb.asm.MethodVisitor;
  31 import jdk.internal.org.objectweb.asm.Opcodes;
  32 import jdk.internal.vm.annotation.ForceInline;
  33 import jdk.internal.misc.Unsafe;
  34 
  35 import java.lang.invoke.MethodHandles.Lookup;

  36 import java.util.*;
  37 import java.util.concurrent.ConcurrentHashMap;
  38 import java.util.concurrent.ConcurrentMap;
  39 import java.util.function.Function;
  40 import sun.security.action.GetPropertyAction;
  41 
  42 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  43 
  44 /**
  45  * <p>Methods to facilitate the creation of String concatenation methods, that
  46  * can be used to efficiently concatenate a known number of arguments of known
  47  * types, possibly after type adaptation and partial evaluation of arguments.
  48  * These methods are typically used as <em>bootstrap methods</em> for {@code
  49  * invokedynamic} call sites, to support the <em>string concatenation</em>
  50  * feature of the Java Programming Language.
  51  *
  52  * <p>Indirect access to the behavior specified by the provided {@code
  53  * MethodHandle} proceeds in order through two phases:
  54  *
  55  * <ol>


 170     /**
 171      * Enables debugging: this may print debugging messages, perform additional (non-neutral for performance)
 172      * checks, etc.
 173      */
 174     private static final boolean DEBUG;
 175 
 176     /**
 177      * Enables caching of strategy stubs. This may improve the linkage time by reusing the generated
 178      * code, at the expense of contaminating the profiles.
 179      */
 180     private static final boolean CACHE_ENABLE;
 181 
 182     private static final ConcurrentMap<Key, MethodHandle> CACHE;
 183 
 184     /**
 185      * Dump generated classes to disk, for debugging purposes.
 186      */
 187     private static final ProxyClassesDumper DUMPER;
 188 
 189     static {
 190         Properties props = GetPropertyAction.getProperties();
 191         final String strategy =
 192                 props.getProperty("java.lang.invoke.stringConcat");
 193         CACHE_ENABLE = Boolean.parseBoolean(
 194                 props.getProperty("java.lang.invoke.stringConcat.cache"));
 195         DEBUG = Boolean.parseBoolean(
 196                 props.getProperty("java.lang.invoke.stringConcat.debug"));
 197         final String dumpPath =
 198                 props.getProperty("java.lang.invoke.stringConcat.dumpClasses");
 199 
 200         STRATEGY = (strategy == null) ? DEFAULT_STRATEGY : Strategy.valueOf(strategy);
 201         CACHE = CACHE_ENABLE ? new ConcurrentHashMap<>() : null;
 202         DUMPER = (dumpPath == null) ? null : ProxyClassesDumper.getInstance(dumpPath);
 203     }
 204 
 205     /**
 206      * Cache key is a composite of:
 207      *   - class name, that lets to disambiguate stubs, to avoid excess sharing
 208      *   - method type, describing the dynamic arguments for concatenation
 209      *   - concat recipe, describing the constants and concat shape
 210      */
 211     private static final class Key {
 212         final String className;
 213         final MethodType mt;
 214         final Recipe recipe;
 215 
 216         public Key(String className, MethodType mt, Recipe recipe) {
 217             this.className = className;
 218             this.mt = mt;


< prev index next >