예제 #1
0
 // Factory methods:
 static DirectMethodHandle make(byte refKind, Class<?> receiver, MemberName member) {
   MethodType mtype = member.getMethodOrFieldType();
   if (!member.isStatic()) {
     if (!member.getDeclaringClass().isAssignableFrom(receiver) || member.isConstructor())
       throw new InternalError(member.toString());
     mtype = mtype.insertParameterTypes(0, receiver);
   }
   if (!member.isField()) {
     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()) {
       long offset = MethodHandleNatives.staticFieldOffset(member);
       Object base = MethodHandleNatives.staticFieldBase(member);
       return new StaticAccessor(mtype, lform, member, base, offset);
     } else {
       long offset = MethodHandleNatives.objectFieldOffset(member);
       assert (offset == (int) offset);
       return new Accessor(mtype, lform, member, (int) offset);
     }
   }
 }
예제 #2
0
 private static DirectMethodHandle makeAllocator(MemberName ctor) {
   assert (ctor.isConstructor() && ctor.getName().equals("<init>"));
   Class<?> instanceClass = ctor.getDeclaringClass();
   ctor = ctor.asConstructor();
   assert (ctor.isConstructor() && ctor.getReferenceKind() == REF_newInvokeSpecial) : ctor;
   MethodType mtype = ctor.getMethodType().changeReturnType(instanceClass);
   LambdaForm lform = preparedLambdaForm(ctor);
   MemberName init = ctor.asSpecial();
   assert (init.getMethodType().returnType() == void.class);
   return new Constructor(mtype, lform, ctor, init, instanceClass);
 }