< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java

Print this page




 184      * invokedynamic instructions.
 185      * @param lookup MethodHandle lookup. Ignored as Nashorn only uses public lookup.
 186      * @param opDesc Dynalink dynamic operation descriptor.
 187      * @param type   Method type.
 188      * @param flags  flags for call type, trace/profile etc.
 189      * @return CallSite with MethodHandle to appropriate method or null if not found.
 190      */
 191     public static CallSite bootstrap(final Lookup lookup, final String opDesc, final MethodType type, final int flags) {
 192         return Context.getDynamicLinker(lookup.lookupClass()).link(LinkerCallSite.newLinkerCallSite(lookup, opDesc, type, flags));
 193     }
 194 
 195     /**
 196      * Boostrapper for math calls that may overflow
 197      * @param lookup         lookup
 198      * @param name           name of operation
 199      * @param type           method type
 200      * @param programPoint   program point to bind to callsite
 201      *
 202      * @return callsite for a math intrinsic node
 203      */
 204     public static CallSite mathBootstrap(final MethodHandles.Lookup lookup, final String name, final MethodType type, final int programPoint) {
 205         final MethodHandle mh;
 206         switch (name) {
 207         case "iadd":
 208             mh = JSType.ADD_EXACT.methodHandle();
 209             break;
 210         case "isub":
 211             mh = JSType.SUB_EXACT.methodHandle();
 212             break;
 213         case "imul":
 214             mh = JSType.MUL_EXACT.methodHandle();
 215             break;
 216         case "idiv":
 217             mh = JSType.DIV_EXACT.methodHandle();
 218             break;
 219         case "irem":
 220             mh = JSType.REM_EXACT.methodHandle();
 221             break;
 222         case "ineg":
 223             mh = JSType.NEGATE_EXACT.methodHandle();
 224             break;
 225         case "ladd":
 226             mh = JSType.ADD_EXACT_LONG.methodHandle();
 227             break;
 228         case "lsub":
 229             mh = JSType.SUB_EXACT_LONG.methodHandle();
 230             break;
 231         case "lmul":
 232             mh = JSType.MUL_EXACT_LONG.methodHandle();
 233             break;
 234         case "ldiv":
 235             mh = JSType.DIV_EXACT_LONG.methodHandle();
 236             break;
 237         case "lrem":
 238             mh = JSType.REM_EXACT_LONG.methodHandle();
 239             break;
 240         case "lneg":
 241             mh = JSType.NEGATE_EXACT_LONG.methodHandle();
 242             break;
 243         default:
 244             throw new AssertionError("unsupported math intrinsic");
 245         }
 246         return new ConstantCallSite(MH.insertArguments(mh, mh.type().parameterCount() - 1, programPoint));
 247     }
 248 
 249     /**
 250      * Returns a dynamic invoker for a specified dynamic operation using the
 251      * public lookup. You can use this method to create a method handle that
 252      * when invoked acts completely as if it were a Nashorn-linked call site.
 253      * Note that the available operations are encoded in the flags, see
 254      * {@link NashornCallSiteDescriptor} operation constants. If the operation
 255      * takes a name, it should be set otherwise empty name (not null) should be
 256      * used. All names (including the empty one) should be encoded using
 257      * {@link NameCodec#encode(String)}. Few examples:
 258      * <ul>
 259      *   <li>Get a named property with fixed name:
 260      *     <pre>
 261      * MethodHandle getColor = Boostrap.createDynamicInvoker(




 184      * invokedynamic instructions.
 185      * @param lookup MethodHandle lookup. Ignored as Nashorn only uses public lookup.
 186      * @param opDesc Dynalink dynamic operation descriptor.
 187      * @param type   Method type.
 188      * @param flags  flags for call type, trace/profile etc.
 189      * @return CallSite with MethodHandle to appropriate method or null if not found.
 190      */
 191     public static CallSite bootstrap(final Lookup lookup, final String opDesc, final MethodType type, final int flags) {
 192         return Context.getDynamicLinker(lookup.lookupClass()).link(LinkerCallSite.newLinkerCallSite(lookup, opDesc, type, flags));
 193     }
 194 
 195     /**
 196      * Boostrapper for math calls that may overflow
 197      * @param lookup         lookup
 198      * @param name           name of operation
 199      * @param type           method type
 200      * @param programPoint   program point to bind to callsite
 201      *
 202      * @return callsite for a math intrinsic node
 203      */
 204     public static CallSite mathBootstrap(final Lookup lookup, final String name, final MethodType type, final int programPoint) {
 205         final MethodHandle mh;
 206         switch (name) {
 207         case "iadd":
 208             mh = JSType.ADD_EXACT.methodHandle();
 209             break;
 210         case "isub":
 211             mh = JSType.SUB_EXACT.methodHandle();
 212             break;
 213         case "imul":
 214             mh = JSType.MUL_EXACT.methodHandle();
 215             break;
 216         case "idiv":
 217             mh = JSType.DIV_EXACT.methodHandle();
 218             break;
 219         case "irem":
 220             mh = JSType.REM_EXACT.methodHandle();
 221             break;
 222         case "ineg":
 223             mh = JSType.NEGATE_EXACT.methodHandle();


















 224             break;
 225         default:
 226             throw new AssertionError("unsupported math intrinsic");
 227         }
 228         return new ConstantCallSite(MH.insertArguments(mh, mh.type().parameterCount() - 1, programPoint));
 229     }
 230 
 231     /**
 232      * Returns a dynamic invoker for a specified dynamic operation using the
 233      * public lookup. You can use this method to create a method handle that
 234      * when invoked acts completely as if it were a Nashorn-linked call site.
 235      * Note that the available operations are encoded in the flags, see
 236      * {@link NashornCallSiteDescriptor} operation constants. If the operation
 237      * takes a name, it should be set otherwise empty name (not null) should be
 238      * used. All names (including the empty one) should be encoded using
 239      * {@link NameCodec#encode(String)}. Few examples:
 240      * <ul>
 241      *   <li>Get a named property with fixed name:
 242      *     <pre>
 243      * MethodHandle getColor = Boostrap.createDynamicInvoker(


< prev index next >