jdk/src/share/classes/java/lang/invoke/DirectMethodHandle.java
changeset 16030 265a0d86c9ff
parent 14342 8435a30053c1
child 16123 82033940e774
--- a/jdk/src/share/classes/java/lang/invoke/DirectMethodHandle.java	Thu Feb 21 20:01:22 2013 +0000
+++ b/jdk/src/share/classes/java/lang/invoke/DirectMethodHandle.java	Tue Feb 26 11:05:26 2013 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,8 +55,7 @@
     }
 
     // Factory methods:
-
-    static DirectMethodHandle make(Class<?> receiver, MemberName member) {
+    static DirectMethodHandle make(byte refKind, Class<?> receiver, MemberName member) {
         MethodType mtype = member.getMethodOrFieldType();
         if (!member.isStatic()) {
             if (!member.getDeclaringClass().isAssignableFrom(receiver) || member.isConstructor())
@@ -64,8 +63,14 @@
             mtype = mtype.insertParameterTypes(0, receiver);
         }
         if (!member.isField()) {
-            LambdaForm lform = preparedLambdaForm(member);
-            return new DirectMethodHandle(mtype, lform, member);
+            if (refKind == REF_invokeSpecial) {
+                member = member.asSpecial();
+                LambdaForm lform = preparedLambdaForm(member);
+                return new Special(mtype, lform, member);
+            } else {
+                LambdaForm lform = preparedLambdaForm(member);
+                return new DirectMethodHandle(mtype, lform, member);
+            }
         } else {
             LambdaForm lform = preparedFieldLambdaForm(member);
             if (member.isStatic()) {
@@ -79,6 +84,12 @@
             }
         }
     }
+    static DirectMethodHandle make(Class<?> receiver, MemberName member) {
+        byte refKind = member.getReferenceKind();
+        if (refKind == REF_invokeSpecial)
+            refKind =  REF_invokeVirtual;
+        return make(refKind, receiver, member);
+    }
     static DirectMethodHandle make(MemberName member) {
         if (member.isConstructor())
             return makeAllocator(member);
@@ -114,6 +125,10 @@
 
     //// Implementation methods.
     @Override
+    MethodHandle viewAsType(MethodType newType) {
+        return new DirectMethodHandle(newType, form, member);
+    }
+    @Override
     @ForceInline
     MemberName internalMemberName() {
         return member;
@@ -357,6 +372,21 @@
         ((DirectMethodHandle)mh).ensureInitialized();
     }
 
+    /** This subclass represents invokespecial instructions. */
+    static class Special extends DirectMethodHandle {
+        private Special(MethodType mtype, LambdaForm form, MemberName member) {
+            super(mtype, form, member);
+        }
+        @Override
+        boolean isInvokeSpecial() {
+            return true;
+        }
+        @Override
+        MethodHandle viewAsType(MethodType newType) {
+            return new Special(newType, form, member);
+        }
+    }
+
     /** This subclass handles constructor references. */
     static class Constructor extends DirectMethodHandle {
         final MemberName initMethod;
@@ -369,6 +399,10 @@
             this.instanceClass = instanceClass;
             assert(initMethod.isResolved());
         }
+        @Override
+        MethodHandle viewAsType(MethodType newType) {
+            return new Constructor(newType, form, member, initMethod, instanceClass);
+        }
     }
 
     /*non-public*/ static Object constructorMethod(Object mh) {
@@ -395,6 +429,10 @@
         @Override Object checkCast(Object obj) {
             return fieldType.cast(obj);
         }
+        @Override
+        MethodHandle viewAsType(MethodType newType) {
+            return new Accessor(newType, form, member, fieldOffset);
+        }
     }
 
     @ForceInline
@@ -434,6 +472,10 @@
         @Override Object checkCast(Object obj) {
             return fieldType.cast(obj);
         }
+        @Override
+        MethodHandle viewAsType(MethodType newType) {
+            return new StaticAccessor(newType, form, member, staticBase, staticOffset);
+        }
     }
 
     @ForceInline