src/jdk/nashorn/internal/runtime/linker/Bootstrap.java

Print this page




  44 import jdk.nashorn.internal.codegen.RuntimeCallSite;
  45 import jdk.nashorn.internal.runtime.JSType;
  46 import jdk.nashorn.internal.runtime.ScriptFunction;
  47 import jdk.nashorn.internal.runtime.ScriptRuntime;
  48 import jdk.nashorn.internal.runtime.options.Options;
  49 
  50 /**
  51  * This class houses bootstrap method for invokedynamic instructions generated by compiler.
  52  */
  53 public final class Bootstrap {
  54     /** Reference to the seed boostrap function */
  55     public static final Call BOOTSTRAP = staticCallNoLookup(Bootstrap.class, "bootstrap", CallSite.class, Lookup.class, String.class, MethodType.class, int.class);
  56 
  57     // do not create me!!
  58     private Bootstrap() {
  59     }
  60 
  61     private static final DynamicLinker dynamicLinker;
  62     static {
  63         final DynamicLinkerFactory factory = new DynamicLinkerFactory();


  64         factory.setPrioritizedLinkers(new NashornLinker(), new NashornPrimitiveLinker(), new NashornStaticClassLinker(),
  65                 new BoundDynamicMethodLinker(), new JavaSuperAdapterLinker(), new JSObjectLinker(), new ReflectionCheckLinker());
  66         factory.setFallbackLinkers(new NashornBeansLinker(), new NashornBottomLinker());
  67         factory.setSyncOnRelink(true);
  68         final int relinkThreshold = Options.getIntProperty("nashorn.unstable.relink.threshold", -1);
  69         if (relinkThreshold > -1) {
  70             factory.setUnstableRelinkThreshold(relinkThreshold);
  71         }
  72 
  73         // Linkers for any additional language runtimes deployed alongside Nashorn will be picked up by the factory.
  74         factory.setClassLoader(Bootstrap.class.getClassLoader());
  75 
  76         dynamicLinker = factory.createLinker();
  77     }
  78 
  79     /**
  80      * Returns if the given object is a "callable"
  81      * @param obj object to be checked for callability
  82      * @return true if the obj is callable
  83      */
  84     public static boolean isCallable(final Object obj) {
  85         if (obj == ScriptRuntime.UNDEFINED || obj == null) {
  86             return false;




  44 import jdk.nashorn.internal.codegen.RuntimeCallSite;
  45 import jdk.nashorn.internal.runtime.JSType;
  46 import jdk.nashorn.internal.runtime.ScriptFunction;
  47 import jdk.nashorn.internal.runtime.ScriptRuntime;
  48 import jdk.nashorn.internal.runtime.options.Options;
  49 
  50 /**
  51  * This class houses bootstrap method for invokedynamic instructions generated by compiler.
  52  */
  53 public final class Bootstrap {
  54     /** Reference to the seed boostrap function */
  55     public static final Call BOOTSTRAP = staticCallNoLookup(Bootstrap.class, "bootstrap", CallSite.class, Lookup.class, String.class, MethodType.class, int.class);
  56 
  57     // do not create me!!
  58     private Bootstrap() {
  59     }
  60 
  61     private static final DynamicLinker dynamicLinker;
  62     static {
  63         final DynamicLinkerFactory factory = new DynamicLinkerFactory();
  64         final NashornBeansLinker nashornBeansLinker = new NashornBeansLinker();
  65         final JSObjectLinker jsObjectLinker = new JSObjectLinker(nashornBeansLinker);
  66         factory.setPrioritizedLinkers(new NashornLinker(), new NashornPrimitiveLinker(), new NashornStaticClassLinker(),
  67                 new BoundDynamicMethodLinker(), new JavaSuperAdapterLinker(), jsObjectLinker, new ReflectionCheckLinker());
  68         factory.setFallbackLinkers(nashornBeansLinker, new NashornBottomLinker());
  69         factory.setSyncOnRelink(true);
  70         final int relinkThreshold = Options.getIntProperty("nashorn.unstable.relink.threshold", -1);
  71         if (relinkThreshold > -1) {
  72             factory.setUnstableRelinkThreshold(relinkThreshold);
  73         }
  74 
  75         // Linkers for any additional language runtimes deployed alongside Nashorn will be picked up by the factory.
  76         factory.setClassLoader(Bootstrap.class.getClassLoader());
  77 
  78         dynamicLinker = factory.createLinker();
  79     }
  80 
  81     /**
  82      * Returns if the given object is a "callable"
  83      * @param obj object to be checked for callability
  84      * @return true if the obj is callable
  85      */
  86     public static boolean isCallable(final Object obj) {
  87         if (obj == ScriptRuntime.UNDEFINED || obj == null) {
  88             return false;