src/share/classes/java/lang/invoke/MethodHandle.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff src/share/classes/java/lang/invoke

src/share/classes/java/lang/invoke/MethodHandle.java

Print this page
rev 9490 : 8037210: Get rid of char-based descriptions 'J' of basic types
Reviewed-by: jrose, ?


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 
  29 import java.util.*;

  30 import sun.invoke.util.*;
  31 import sun.misc.Unsafe;
  32 
  33 import static java.lang.invoke.MethodHandleStatics.*;

  34 
  35 /**
  36  * A method handle is a typed, directly executable reference to an underlying method,
  37  * constructor, field, or similar low-level operation, with optional
  38  * transformations of arguments or return values.
  39  * These transformations are quite general, and include such patterns as
  40  * {@linkplain #asType conversion},
  41  * {@linkplain #bindTo insertion},
  42  * {@linkplain java.lang.invoke.MethodHandles#dropArguments deletion},
  43  * and {@linkplain java.lang.invoke.MethodHandles#filterArguments substitution}.
  44  *
  45  * <h1>Method handle contents</h1>
  46  * Method handles are dynamically and strongly typed according to their parameter and return types.
  47  * They are not distinguished by the name or the defining class of their underlying methods.
  48  * A method handle must be invoked using a symbolic type descriptor which matches
  49  * the method handle's own {@linkplain #type type descriptor}.
  50  * <p>
  51  * Every method handle reports its type descriptor via the {@link #type type} accessor.
  52  * This type descriptor is a {@link java.lang.invoke.MethodType MethodType} object,
  53  * whose structure is a series of classes, one of which is


1357     Object internalValues() {
1358         return null;
1359     }
1360 
1361     /*non-public*/
1362     Object internalProperties() {
1363         // Override to something like "/FOO=bar"
1364         return "";
1365     }
1366 
1367     //// Method handle implementation methods.
1368     //// Sub-classes can override these default implementations.
1369     //// All these methods assume arguments are already validated.
1370 
1371     /*non-public*/ MethodHandle convertArguments(MethodType newType) {
1372         // Override this if it can be improved.
1373         return MethodHandleImpl.makePairwiseConvert(this, newType, 1);
1374     }
1375 
1376     /*non-public*/
1377     MethodHandle bindArgument(int pos, char basicType, Object value) {
1378         // Override this if it can be improved.
1379         return rebind().bindArgument(pos, basicType, value);
1380     }
1381 
1382     /*non-public*/
1383     MethodHandle bindReceiver(Object receiver) {
1384         // Override this if it can be improved.
1385         return bindArgument(0, 'L', receiver);
1386     }
1387 
1388     /*non-public*/
1389     MethodHandle bindImmediate(int pos, char basicType, Object value) {
1390         // Bind an immediate value to a position in the arguments.
1391         // This means, elide the respective argument,
1392         // and replace all references to it in NamedFunction args with the specified value.
1393 
1394         // CURRENT RESTRICTIONS
1395         // * only for pos 0 and UNSAFE (position is adjusted in MHImpl to make API usable for others)
1396         assert pos == 0 && basicType == 'L' && value instanceof Unsafe;
1397         MethodType type2 = type.dropParameterTypes(pos, pos + 1); // adjustment: ignore receiver!
1398         LambdaForm form2 = form.bindImmediate(pos + 1, basicType, value); // adjust pos to form-relative pos
1399         return copyWith(type2, form2);
1400     }
1401 
1402     /*non-public*/
1403     MethodHandle copyWith(MethodType mt, LambdaForm lf) {
1404         throw new InternalError("copyWith: " + this.getClass());
1405     }
1406 
1407     /*non-public*/
1408     MethodHandle dropArguments(MethodType srcType, int pos, int drops) {
1409         // Override this if it can be improved.
1410         return rebind().dropArguments(srcType, pos, drops);
1411     }
1412 
1413     /*non-public*/
1414     MethodHandle permuteArguments(MethodType newType, int[] reorder) {
1415         // Override this if it can be improved.
1416         return rebind().permuteArguments(newType, reorder);




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 
  29 import java.util.*;
  30 import java.lang.invoke.LambdaForm.BasicType;
  31 import sun.invoke.util.*;
  32 import sun.misc.Unsafe;
  33 
  34 import static java.lang.invoke.MethodHandleStatics.*;
  35 import static java.lang.invoke.LambdaForm.BasicType.*;
  36 
  37 /**
  38  * A method handle is a typed, directly executable reference to an underlying method,
  39  * constructor, field, or similar low-level operation, with optional
  40  * transformations of arguments or return values.
  41  * These transformations are quite general, and include such patterns as
  42  * {@linkplain #asType conversion},
  43  * {@linkplain #bindTo insertion},
  44  * {@linkplain java.lang.invoke.MethodHandles#dropArguments deletion},
  45  * and {@linkplain java.lang.invoke.MethodHandles#filterArguments substitution}.
  46  *
  47  * <h1>Method handle contents</h1>
  48  * Method handles are dynamically and strongly typed according to their parameter and return types.
  49  * They are not distinguished by the name or the defining class of their underlying methods.
  50  * A method handle must be invoked using a symbolic type descriptor which matches
  51  * the method handle's own {@linkplain #type type descriptor}.
  52  * <p>
  53  * Every method handle reports its type descriptor via the {@link #type type} accessor.
  54  * This type descriptor is a {@link java.lang.invoke.MethodType MethodType} object,
  55  * whose structure is a series of classes, one of which is


1359     Object internalValues() {
1360         return null;
1361     }
1362 
1363     /*non-public*/
1364     Object internalProperties() {
1365         // Override to something like "/FOO=bar"
1366         return "";
1367     }
1368 
1369     //// Method handle implementation methods.
1370     //// Sub-classes can override these default implementations.
1371     //// All these methods assume arguments are already validated.
1372 
1373     /*non-public*/ MethodHandle convertArguments(MethodType newType) {
1374         // Override this if it can be improved.
1375         return MethodHandleImpl.makePairwiseConvert(this, newType, 1);
1376     }
1377 
1378     /*non-public*/
1379     MethodHandle bindArgument(int pos, BasicType basicType, Object value) {
1380         // Override this if it can be improved.
1381         return rebind().bindArgument(pos, basicType, value);
1382     }
1383 
1384     /*non-public*/
1385     MethodHandle bindReceiver(Object receiver) {
1386         // Override this if it can be improved.
1387         return bindArgument(0, L_TYPE, receiver);
1388     }
1389 
1390     /*non-public*/
1391     MethodHandle bindImmediate(int pos, BasicType basicType, Object value) {
1392         // Bind an immediate value to a position in the arguments.
1393         // This means, elide the respective argument,
1394         // and replace all references to it in NamedFunction args with the specified value.
1395 
1396         // CURRENT RESTRICTIONS
1397         // * only for pos 0 and UNSAFE (position is adjusted in MHImpl to make API usable for others)
1398         assert pos == 0 && basicType == L_TYPE && value instanceof Unsafe;
1399         MethodType type2 = type.dropParameterTypes(pos, pos + 1); // adjustment: ignore receiver!
1400         LambdaForm form2 = form.bindImmediate(pos + 1, basicType, value); // adjust pos to form-relative pos
1401         return copyWith(type2, form2);
1402     }
1403 
1404     /*non-public*/
1405     MethodHandle copyWith(MethodType mt, LambdaForm lf) {
1406         throw new InternalError("copyWith: " + this.getClass());
1407     }
1408 
1409     /*non-public*/
1410     MethodHandle dropArguments(MethodType srcType, int pos, int drops) {
1411         // Override this if it can be improved.
1412         return rebind().dropArguments(srcType, pos, drops);
1413     }
1414 
1415     /*non-public*/
1416     MethodHandle permuteArguments(MethodType newType, int[] reorder) {
1417         // Override this if it can be improved.
1418         return rebind().permuteArguments(newType, reorder);


src/share/classes/java/lang/invoke/MethodHandle.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File