src/share/classes/java/lang/invoke/MemberName.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff src/share/classes/java/lang/invoke

src/share/classes/java/lang/invoke/MemberName.java

Print this page
rev 10274 : 8050052: Small cleanups in java.lang.invoke code
Reviewed-by: ?


 310         assert(vminfo instanceof Object[]);
 311         long vmindex = (Long) ((Object[])vminfo)[0];
 312         Object vmtarget = ((Object[])vminfo)[1];
 313         if (MethodHandleNatives.refKindIsField(refKind)) {
 314             assert(vmindex >= 0) : vmindex + ":" + this;
 315             assert(vmtarget instanceof Class);
 316         } else {
 317             if (MethodHandleNatives.refKindDoesDispatch(refKind))
 318                 assert(vmindex >= 0) : vmindex + ":" + this;
 319             else
 320                 assert(vmindex < 0) : vmindex;
 321             assert(vmtarget instanceof MemberName) : vmtarget + " in " + this;
 322         }
 323         return true;
 324     }
 325 
 326     private MemberName changeReferenceKind(byte refKind, byte oldKind) {
 327         assert(getReferenceKind() == oldKind);
 328         assert(MethodHandleNatives.refKindIsValid(refKind));
 329         flags += (((int)refKind - oldKind) << MN_REFERENCE_KIND_SHIFT);
 330 //        if (isConstructor() && refKind != REF_newInvokeSpecial)
 331 //            flags += (IS_METHOD - IS_CONSTRUCTOR);
 332 //        else if (refKind == REF_newInvokeSpecial && isMethod())
 333 //            flags += (IS_CONSTRUCTOR - IS_METHOD);
 334         return this;
 335     }
 336 
 337     private boolean testFlags(int mask, int value) {
 338         return (flags & mask) == value;
 339     }
 340     private boolean testAllFlags(int mask) {
 341         return testFlags(mask, mask);
 342     }
 343     private boolean testAnyFlags(int mask) {
 344         return !testFlags(mask, 0);
 345     }
 346 
 347     /** Utility method to query if this member is a method handle invocation (invoke or invokeExact). */


 348     public boolean isMethodHandleInvoke() {
 349         final int bits = MH_INVOKE_MODS;
 350         final int negs = Modifier.STATIC;
 351         if (testFlags(bits | negs, bits) &&
 352             clazz == MethodHandle.class) {
 353             return isMethodHandleInvokeName(name);
 354         }
 355         return false;
 356     }
 357     public static boolean isMethodHandleInvokeName(String name) {
 358         return name.equals("invoke") || name.equals("invokeExact");







 359     }
 360     private static final int MH_INVOKE_MODS = Modifier.NATIVE | Modifier.FINAL | Modifier.PUBLIC;
 361 
 362     /** Utility method to query the modifier flags of this member. */
 363     public boolean isStatic() {
 364         return Modifier.isStatic(flags);
 365     }
 366     /** Utility method to query the modifier flags of this member. */
 367     public boolean isPublic() {
 368         return Modifier.isPublic(flags);
 369     }
 370     /** Utility method to query the modifier flags of this member. */
 371     public boolean isPrivate() {
 372         return Modifier.isPrivate(flags);
 373     }
 374     /** Utility method to query the modifier flags of this member. */
 375     public boolean isProtected() {
 376         return Modifier.isProtected(flags);
 377     }
 378     /** Utility method to query the modifier flags of this member. */


 703      */
 704     public boolean equals(MemberName that) {
 705         if (this == that)  return true;
 706         if (that == null)  return false;
 707         return this.clazz == that.clazz
 708                 && this.getReferenceKind() == that.getReferenceKind()
 709                 && Objects.equals(this.name, that.name)
 710                 && Objects.equals(this.getType(), that.getType());
 711     }
 712 
 713     // Construction from symbolic parts, for queries:
 714     /** Create a field or type name from the given components:
 715      *  Declaring class, name, type, reference kind.
 716      *  The declaring class may be supplied as null if this is to be a bare name and type.
 717      *  The resulting name will in an unresolved state.
 718      */
 719     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 720         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 721         initResolved(false);
 722     }
 723     /** Create a field or type name from the given components:  Declaring class, name, type.
 724      *  The declaring class may be supplied as null if this is to be a bare name and type.
 725      *  The modifier flags default to zero.
 726      *  The resulting name will in an unresolved state.
 727      */
 728     public MemberName(Class<?> defClass, String name, Class<?> type, Void unused) {
 729         this(defClass, name, type, REF_NONE);
 730         initResolved(false);
 731     }
 732     /** Create a method or constructor name from the given components:  Declaring class, name, type, modifiers.
 733      *  It will be a constructor if and only if the name is {@code "&lt;init&gt;"}.
 734      *  The declaring class may be supplied as null if this is to be a bare name and type.
 735      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 736      *  The resulting name will in an unresolved state.
 737      */
 738     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 739         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
 740         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 741         initResolved(false);
 742     }
 743     /** Create a method, constructor, or field name from the given components:
 744      *  Reference kind, declaring class, name, type.
 745      */
 746     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 747         int kindFlags;
 748         if (MethodHandleNatives.refKindIsField(refKind)) {
 749             kindFlags = IS_FIELD;
 750             if (!(type instanceof Class))
 751                 throw newIllegalArgumentException("not a field type");
 752         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {




 310         assert(vminfo instanceof Object[]);
 311         long vmindex = (Long) ((Object[])vminfo)[0];
 312         Object vmtarget = ((Object[])vminfo)[1];
 313         if (MethodHandleNatives.refKindIsField(refKind)) {
 314             assert(vmindex >= 0) : vmindex + ":" + this;
 315             assert(vmtarget instanceof Class);
 316         } else {
 317             if (MethodHandleNatives.refKindDoesDispatch(refKind))
 318                 assert(vmindex >= 0) : vmindex + ":" + this;
 319             else
 320                 assert(vmindex < 0) : vmindex;
 321             assert(vmtarget instanceof MemberName) : vmtarget + " in " + this;
 322         }
 323         return true;
 324     }
 325 
 326     private MemberName changeReferenceKind(byte refKind, byte oldKind) {
 327         assert(getReferenceKind() == oldKind);
 328         assert(MethodHandleNatives.refKindIsValid(refKind));
 329         flags += (((int)refKind - oldKind) << MN_REFERENCE_KIND_SHIFT);




 330         return this;
 331     }
 332 
 333     private boolean testFlags(int mask, int value) {
 334         return (flags & mask) == value;
 335     }
 336     private boolean testAllFlags(int mask) {
 337         return testFlags(mask, mask);
 338     }
 339     private boolean testAnyFlags(int mask) {
 340         return !testFlags(mask, 0);
 341     }
 342 
 343     /** Utility method to query if this member is a method handle invocation (invoke or invokeExact).
 344      *  Also returns true for the non-public MH.invokeBasic.
 345      */
 346     public boolean isMethodHandleInvoke() {
 347         final int bits = MH_INVOKE_MODS &~ Modifier.PUBLIC;
 348         final int negs = Modifier.STATIC;
 349         if (testFlags(bits | negs, bits) &&
 350             clazz == MethodHandle.class) {
 351             return isMethodHandleInvokeName(name);
 352         }
 353         return false;
 354     }
 355     public static boolean isMethodHandleInvokeName(String name) {
 356         switch (name) {
 357         case "invoke":
 358         case "invokeExact":
 359         case "invokeBasic":  // internal sig-poly method
 360             return true;
 361         default:
 362             return false;
 363         }
 364     }
 365     private static final int MH_INVOKE_MODS = Modifier.NATIVE | Modifier.FINAL | Modifier.PUBLIC;
 366 
 367     /** Utility method to query the modifier flags of this member. */
 368     public boolean isStatic() {
 369         return Modifier.isStatic(flags);
 370     }
 371     /** Utility method to query the modifier flags of this member. */
 372     public boolean isPublic() {
 373         return Modifier.isPublic(flags);
 374     }
 375     /** Utility method to query the modifier flags of this member. */
 376     public boolean isPrivate() {
 377         return Modifier.isPrivate(flags);
 378     }
 379     /** Utility method to query the modifier flags of this member. */
 380     public boolean isProtected() {
 381         return Modifier.isProtected(flags);
 382     }
 383     /** Utility method to query the modifier flags of this member. */


 708      */
 709     public boolean equals(MemberName that) {
 710         if (this == that)  return true;
 711         if (that == null)  return false;
 712         return this.clazz == that.clazz
 713                 && this.getReferenceKind() == that.getReferenceKind()
 714                 && Objects.equals(this.name, that.name)
 715                 && Objects.equals(this.getType(), that.getType());
 716     }
 717 
 718     // Construction from symbolic parts, for queries:
 719     /** Create a field or type name from the given components:
 720      *  Declaring class, name, type, reference kind.
 721      *  The declaring class may be supplied as null if this is to be a bare name and type.
 722      *  The resulting name will in an unresolved state.
 723      */
 724     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 725         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 726         initResolved(false);
 727     }
 728     /** Create a method or constructor name from the given components:
 729      *  Declaring class, name, type, reference kind.








 730      *  It will be a constructor if and only if the name is {@code "&lt;init&gt;"}.
 731      *  The declaring class may be supplied as null if this is to be a bare name and type.
 732      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 733      *  The resulting name will in an unresolved state.
 734      */
 735     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 736         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
 737         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 738         initResolved(false);
 739     }
 740     /** Create a method, constructor, or field name from the given components:
 741      *  Reference kind, declaring class, name, type.
 742      */
 743     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 744         int kindFlags;
 745         if (MethodHandleNatives.refKindIsField(refKind)) {
 746             kindFlags = IS_FIELD;
 747             if (!(type instanceof Class))
 748                 throw newIllegalArgumentException("not a field type");
 749         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {


src/share/classes/java/lang/invoke/MemberName.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File