Esempio n. 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);
     }
   }
 }
Esempio n. 2
0
 boolean resolveInPlace(MemberName m, boolean searchSupers, Class<?> lookupClass) {
   if (m.name == null || m.type == null) { // find unique non-overloaded name
     Class<?> defc = m.getDeclaringClass();
     List<MemberName> choices = null;
     if (m.isMethod())
       choices = getMethods(defc, searchSupers, m.name, (MethodType) m.type, lookupClass);
     else if (m.isConstructor()) choices = getConstructors(defc, lookupClass);
     else if (m.isField())
       choices = getFields(defc, searchSupers, m.name, (Class<?>) m.type, lookupClass);
     // System.out.println("resolving "+m+" to "+choices);
     if (choices == null || choices.size() != 1) return false;
     if (m.name == null) m.name = choices.get(0).name;
     if (m.type == null) m.type = choices.get(0).type;
   }
   MethodHandleNatives.resolve(m, lookupClass);
   if (m.isResolved()) return true;
   int matchFlags = m.flags | (searchSupers ? SEARCH_ALL_SUPERS : 0);
   String matchSig = m.getSignature();
   MemberName[] buf = {m};
   int n =
       MethodHandleNatives.getMembers(
           m.getDeclaringClass(), m.getName(), matchSig, matchFlags, lookupClass, 0, buf);
   if (n != 1) return false;
   return m.isResolved();
 }
Esempio n. 3
0
 private void ensureInitialized() {
   if (checkInitialized(member)) {
     // The coast is clear.  Delete the <clinit> barrier.
     if (member.isField()) updateForm(preparedFieldLambdaForm(member));
     else updateForm(preparedLambdaForm(member));
   }
 }