jdk/src/share/classes/java/lang/invoke/MethodHandleInfo.java
author darcy
Thu, 27 Jun 2013 19:02:02 -0700
changeset 18569 0e46c17766b7
parent 16030 265a0d86c9ff
child 19804 83170920c07b
permissions -rw-r--r--
8019357: Fix doclint warnings in java.lang.invoke Reviewed-by: jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     1
/*
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     4
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    10
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    15
 * accompanied this code).
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    16
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    20
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    23
 * questions.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    24
 */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    25
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    26
package java.lang.invoke;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    27
import java.lang.invoke.MethodHandleNatives.Constants;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    28
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    29
/**
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    30
 * Cracking (reflecting) method handles back into their constituent symbolic parts.
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    31
 *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    32
 */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    33
final class MethodHandleInfo {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    34
   public static final int
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    35
       REF_getField                = Constants.REF_getField,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    36
       REF_getStatic               = Constants.REF_getStatic,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    37
       REF_putField                = Constants.REF_putField,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    38
       REF_putStatic               = Constants.REF_putStatic,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    39
       REF_invokeVirtual           = Constants.REF_invokeVirtual,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    40
       REF_invokeStatic            = Constants.REF_invokeStatic,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    41
       REF_invokeSpecial           = Constants.REF_invokeSpecial,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    42
       REF_newInvokeSpecial        = Constants.REF_newInvokeSpecial,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    43
       REF_invokeInterface         = Constants.REF_invokeInterface;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    44
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    45
   private final Class<?> declaringClass;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    46
   private final String name;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    47
   private final MethodType methodType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    48
   private final int referenceKind;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    49
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    50
   public MethodHandleInfo(MethodHandle mh) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    51
       MemberName mn = mh.internalMemberName();
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    52
       if (mn == null)  throw new IllegalArgumentException("not a direct method handle");
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    53
       this.declaringClass = mn.getDeclaringClass();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    54
       this.name = mn.getName();
16030
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    55
       this.methodType = mn.getMethodOrFieldType();
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    56
       byte refKind = mn.getReferenceKind();
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    57
       if (refKind == REF_invokeSpecial && !mh.isInvokeSpecial())
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    58
           // Devirtualized method invocation is usually formally virtual.
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    59
           refKind = REF_invokeVirtual;
265a0d86c9ff 7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents: 16001
diff changeset
    60
       this.referenceKind = refKind;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    61
   }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    62
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    63
   public Class<?> getDeclaringClass() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    64
       return declaringClass;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    65
   }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    66
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    67
   public String getName() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    68
       return name;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    69
   }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    70
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    71
   public MethodType getMethodType() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    72
       return methodType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    73
   }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    74
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    75
   public int getModifiers() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    76
       return -1; //TODO
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    77
   }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    78
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    79
   public int getReferenceKind() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    80
       return referenceKind;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    81
   }
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    82
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    83
   static String getReferenceKindString(int referenceKind) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    84
        switch (referenceKind) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    85
            case REF_getField: return "getfield";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    86
            case REF_getStatic: return "getstatic";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    87
            case REF_putField: return "putfield";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    88
            case REF_putStatic: return "putstatic";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    89
            case REF_invokeVirtual: return "invokevirtual";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    90
            case REF_invokeStatic: return "invokestatic";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    91
            case REF_invokeSpecial: return "invokespecial";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    92
            case REF_newInvokeSpecial: return "newinvokespecial";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    93
            case REF_invokeInterface: return "invokeinterface";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    94
            default: return "UNKNOWN_REFENCE_KIND" + "[" + referenceKind + "]";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    95
        }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    96
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    97
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    98
    @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    99
    public String toString() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   100
        return String.format("%s %s.%s:%s", getReferenceKindString(referenceKind),
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   101
                             declaringClass.getName(), name, methodType);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   102
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   103
}