< prev index next >

src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


  92                 return new StaticAccessor(mtype, lform, member, base, offset);
  93             } else {
  94                 long offset = MethodHandleNatives.objectFieldOffset(member);
  95                 assert(offset == (int)offset);
  96                 return new Accessor(mtype, lform, member, (int)offset);
  97             }
  98         }
  99     }
 100     static DirectMethodHandle make(Class<?> receiver, MemberName member) {
 101         byte refKind = member.getReferenceKind();
 102         if (refKind == REF_invokeSpecial)
 103             refKind =  REF_invokeVirtual;
 104         return make(refKind, receiver, member);
 105     }
 106     static DirectMethodHandle make(MemberName member) {
 107         if (member.isConstructor())
 108             return makeAllocator(member);
 109         return make(member.getDeclaringClass(), member);
 110     }
 111     static DirectMethodHandle make(Method method) {
 112         return make(method.getDeclaringClass(), new MemberName(method));
 113     }
 114     static DirectMethodHandle make(Field field) {
 115         return make(field.getDeclaringClass(), new MemberName(field));
 116     }
 117     private static DirectMethodHandle makeAllocator(MemberName ctor) {
 118         assert(ctor.isConstructor() && ctor.getName().equals("<init>"));
 119         Class<?> instanceClass = ctor.getDeclaringClass();
 120         ctor = ctor.asConstructor();
 121         assert(ctor.isConstructor() && ctor.getReferenceKind() == REF_newInvokeSpecial) : ctor;
 122         MethodType mtype = ctor.getMethodType().changeReturnType(instanceClass);
 123         LambdaForm lform = preparedLambdaForm(ctor);
 124         MemberName init = ctor.asSpecial();
 125         assert(init.getMethodType().returnType() == void.class);
 126         return new Constructor(mtype, lform, ctor, init, instanceClass);
 127     }
 128 
 129     @Override
 130     BoundMethodHandle rebind() {
 131         return BoundMethodHandle.makeReinvoker(this);
 132     }
 133 
 134     @Override
 135     MethodHandle copyWith(MethodType mt, LambdaForm lf) {


   1 /*
   2  * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


  92                 return new StaticAccessor(mtype, lform, member, base, offset);
  93             } else {
  94                 long offset = MethodHandleNatives.objectFieldOffset(member);
  95                 assert(offset == (int)offset);
  96                 return new Accessor(mtype, lform, member, (int)offset);
  97             }
  98         }
  99     }
 100     static DirectMethodHandle make(Class<?> receiver, MemberName member) {
 101         byte refKind = member.getReferenceKind();
 102         if (refKind == REF_invokeSpecial)
 103             refKind =  REF_invokeVirtual;
 104         return make(refKind, receiver, member);
 105     }
 106     static DirectMethodHandle make(MemberName member) {
 107         if (member.isConstructor())
 108             return makeAllocator(member);
 109         return make(member.getDeclaringClass(), member);
 110     }
 111     static DirectMethodHandle make(Method method) {
 112         return make(method.getDeclaringClass(), MemberName.make(method));
 113     }
 114     static DirectMethodHandle make(Field field) {
 115         return make(field.getDeclaringClass(), MemberName.make(field));
 116     }
 117     private static DirectMethodHandle makeAllocator(MemberName ctor) {
 118         assert(ctor.isConstructor() && ctor.getName().equals("<init>"));
 119         Class<?> instanceClass = ctor.getDeclaringClass();
 120         ctor = ctor.asConstructor();
 121         assert(ctor.isConstructor() && ctor.getReferenceKind() == REF_newInvokeSpecial) : ctor;
 122         MethodType mtype = ctor.getMethodType().changeReturnType(instanceClass);
 123         LambdaForm lform = preparedLambdaForm(ctor);
 124         MemberName init = ctor.asSpecial();
 125         assert(init.getMethodType().returnType() == void.class);
 126         return new Constructor(mtype, lform, ctor, init, instanceClass);
 127     }
 128 
 129     @Override
 130     BoundMethodHandle rebind() {
 131         return BoundMethodHandle.makeReinvoker(this);
 132     }
 133 
 134     @Override
 135     MethodHandle copyWith(MethodType mt, LambdaForm lf) {


< prev index next >