jdk/src/share/classes/java/lang/invoke/MethodHandleInfo.java
author rfield
Sat, 16 Feb 2013 12:36:54 -0800
changeset 16001 fd4c8d3becf8
parent 13423 17843fff200d
child 16030 265a0d86c9ff
permissions -rw-r--r--
8004970: Implement serialization in the lambda metafactory Reviewed-by: forax
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
/*
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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_NONE                    = Constants.REF_NONE,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    36
       REF_getField                = Constants.REF_getField,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    37
       REF_getStatic               = Constants.REF_getStatic,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    38
       REF_putField                = Constants.REF_putField,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    39
       REF_putStatic               = Constants.REF_putStatic,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    40
       REF_invokeVirtual           = Constants.REF_invokeVirtual,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    41
       REF_invokeStatic            = Constants.REF_invokeStatic,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    42
       REF_invokeSpecial           = Constants.REF_invokeSpecial,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    43
       REF_newInvokeSpecial        = Constants.REF_newInvokeSpecial,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    44
       REF_invokeInterface         = Constants.REF_invokeInterface;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    45
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    46
   private final Class<?> declaringClass;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    47
   private final String name;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    48
   private final MethodType methodType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    49
   private final int referenceKind;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    50
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    51
   public MethodHandleInfo(MethodHandle mh) throws ReflectiveOperationException {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    52
       MemberName mn = mh.internalMemberName();
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();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    55
       this.methodType = mn.getMethodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    56
       this.referenceKind = mn.getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    57
   }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    58
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    59
   public Class<?> getDeclaringClass() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    60
       return declaringClass;
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 String getName() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    64
       return name;
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 MethodType getMethodType() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    68
       return methodType;
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
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    71
   public int getModifiers() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    72
       return -1; //TODO
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    73
   }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    74
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    75
   public int getReferenceKind() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    76
       return referenceKind;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    77
   }
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    78
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    79
   static String getReferenceKindString(int referenceKind) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    80
        switch (referenceKind) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    81
            case REF_NONE: return "REF_NONE";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    82
            case REF_getField: return "getfield";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    83
            case REF_getStatic: return "getstatic";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    84
            case REF_putField: return "putfield";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    85
            case REF_putStatic: return "putstatic";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    86
            case REF_invokeVirtual: return "invokevirtual";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    87
            case REF_invokeStatic: return "invokestatic";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    88
            case REF_invokeSpecial: return "invokespecial";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    89
            case REF_newInvokeSpecial: return "newinvokespecial";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    90
            case REF_invokeInterface: return "invokeinterface";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    91
            default: return "UNKNOWN_REFENCE_KIND" + "[" + referenceKind + "]";
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    92
        }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    93
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    94
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    95
    @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    96
    public String toString() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    97
        return String.format("%s %s.%s:%s", getReferenceKindString(referenceKind),
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    98
                             declaringClass.getName(), name, methodType);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    99
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   100
}