< prev index next >

src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template

Print this page
rev 53074 : 8215648: remove equals and hashCode implementations from j.l.i.VarHandle


  47         FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
  48             this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM);
  49         }
  50 
  51         protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
  52                                         VarForm form) {
  53             super(form);
  54             this.fieldOffset = fieldOffset;
  55             this.receiverType = receiverType;
  56 #if[Object]
  57             this.fieldType = fieldType;
  58 #end[Object]
  59         }
  60 
  61         @Override
  62         final MethodType accessModeTypeUncached(AccessMode accessMode) {
  63             return accessMode.at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
  64         }
  65 
  66         @Override
  67         final boolean internalEquals(VarHandle vh) {
  68             FieldInstanceReadOnly that = (FieldInstanceReadOnly) vh;
  69             return fieldOffset == that.fieldOffset;
  70         }
  71 
  72         @Override
  73         final int internalHashCode() {
  74             return Long.hashCode(fieldOffset);
  75         }
  76 
  77         @Override
  78         public Optional<VarHandleDesc> describeConstable() {
  79             var receiverTypeRef = receiverType.describeConstable();
  80             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
  81             if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
  82                 return Optional.empty();
  83 
  84             // Reflect on this VarHandle to extract the field name
  85             String name = VarHandles.getFieldFromReceiverAndOffset(
  86                 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
  87             return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
  88         }
  89 
  90         @ForceInline
  91         static $type$ get(FieldInstanceReadOnly handle, Object holder) {
  92             return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
  93                                  handle.fieldOffset);
  94         }
  95 
  96         @ForceInline
  97         static $type$ getVolatile(FieldInstanceReadOnly handle, Object holder) {


 333         final long fieldOffset;
 334 #if[Object]
 335         final Class<?> fieldType;
 336 #end[Object]
 337 
 338         FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 339             this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM);
 340         }
 341 
 342         protected FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
 343                                       VarForm form) {
 344             super(form);
 345             this.base = base;
 346             this.fieldOffset = fieldOffset;
 347 #if[Object]
 348             this.fieldType = fieldType;
 349 #end[Object]
 350         }
 351 
 352         @Override
 353         final boolean internalEquals(VarHandle vh) {
 354             FieldStaticReadOnly that = (FieldStaticReadOnly) vh;
 355             return base == that.base && fieldOffset == that.fieldOffset;
 356         }
 357 
 358         @Override
 359         final int internalHashCode() {
 360             return 31 * Long.hashCode(fieldOffset) + base.hashCode();
 361         }
 362 
 363         @Override
 364         public Optional<VarHandleDesc> describeConstable() {
 365             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
 366             if (!fieldTypeRef.isPresent())
 367                 return Optional.empty();
 368 
 369             // Reflect on this VarHandle to extract the field name
 370             var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
 371                 base, fieldOffset, {#if[Object]?fieldType:$type$.class});
 372             var receiverTypeRef = staticField.getDeclaringClass().describeConstable();
 373             if (!receiverTypeRef.isPresent())
 374                 return Optional.empty();
 375             return Optional.of(VarHandleDesc.ofStaticField(receiverTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
 376         }
 377 
 378         @Override
 379         final MethodType accessModeTypeUncached(AccessMode accessMode) {
 380             return accessMode.at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
 381         }
 382 
 383         @ForceInline


 620         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
 621     }
 622 
 623 
 624     static final class Array extends VarHandle {
 625         final int abase;
 626         final int ashift;
 627 #if[Object]
 628         final Class<{#if[Object]??:$type$[]}> arrayType;
 629         final Class<?> componentType;
 630 #end[Object]
 631 
 632         Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
 633             super(Array.FORM);
 634             this.abase = abase;
 635             this.ashift = ashift;
 636 #if[Object]
 637             this.arrayType = {#if[Object]?arrayType:$type$[].class};
 638             this.componentType = arrayType.getComponentType();
 639 #end[Object]
 640         }
 641 
 642         @Override
 643         final boolean internalEquals(VarHandle vh) {
 644             // Equality of access mode types of AccessMode.GET is sufficient for
 645             // equality checks
 646             return true;
 647         }
 648 
 649         @Override
 650         final int internalHashCode() {
 651             // The hash code of the access mode types of AccessMode.GET is
 652             // sufficient for hash code generation
 653             return 0;
 654         }
 655 
 656         @Override
 657         public Optional<VarHandleDesc> describeConstable() {
 658             var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
 659             if (!arrayTypeRef.isPresent())
 660                 return Optional.empty();
 661 
 662             return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
 663         }
 664 
 665         @Override
 666         final MethodType accessModeTypeUncached(AccessMode accessMode) {
 667             return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
 668         }
 669 
 670 #if[Object]
 671         @ForceInline
 672         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
 673             if (handle.arrayType == oarray.getClass()) {




  47         FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
  48             this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM);
  49         }
  50 
  51         protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
  52                                         VarForm form) {
  53             super(form);
  54             this.fieldOffset = fieldOffset;
  55             this.receiverType = receiverType;
  56 #if[Object]
  57             this.fieldType = fieldType;
  58 #end[Object]
  59         }
  60 
  61         @Override
  62         final MethodType accessModeTypeUncached(AccessMode accessMode) {
  63             return accessMode.at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
  64         }
  65 
  66         @Override











  67         public Optional<VarHandleDesc> describeConstable() {
  68             var receiverTypeRef = receiverType.describeConstable();
  69             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
  70             if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
  71                 return Optional.empty();
  72 
  73             // Reflect on this VarHandle to extract the field name
  74             String name = VarHandles.getFieldFromReceiverAndOffset(
  75                 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
  76             return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
  77         }
  78 
  79         @ForceInline
  80         static $type$ get(FieldInstanceReadOnly handle, Object holder) {
  81             return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
  82                                  handle.fieldOffset);
  83         }
  84 
  85         @ForceInline
  86         static $type$ getVolatile(FieldInstanceReadOnly handle, Object holder) {


 322         final long fieldOffset;
 323 #if[Object]
 324         final Class<?> fieldType;
 325 #end[Object]
 326 
 327         FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 328             this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM);
 329         }
 330 
 331         protected FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
 332                                       VarForm form) {
 333             super(form);
 334             this.base = base;
 335             this.fieldOffset = fieldOffset;
 336 #if[Object]
 337             this.fieldType = fieldType;
 338 #end[Object]
 339         }
 340 
 341         @Override











 342         public Optional<VarHandleDesc> describeConstable() {
 343             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
 344             if (!fieldTypeRef.isPresent())
 345                 return Optional.empty();
 346 
 347             // Reflect on this VarHandle to extract the field name
 348             var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
 349                 base, fieldOffset, {#if[Object]?fieldType:$type$.class});
 350             var receiverTypeRef = staticField.getDeclaringClass().describeConstable();
 351             if (!receiverTypeRef.isPresent())
 352                 return Optional.empty();
 353             return Optional.of(VarHandleDesc.ofStaticField(receiverTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
 354         }
 355 
 356         @Override
 357         final MethodType accessModeTypeUncached(AccessMode accessMode) {
 358             return accessMode.at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
 359         }
 360 
 361         @ForceInline


 598         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
 599     }
 600 
 601 
 602     static final class Array extends VarHandle {
 603         final int abase;
 604         final int ashift;
 605 #if[Object]
 606         final Class<{#if[Object]??:$type$[]}> arrayType;
 607         final Class<?> componentType;
 608 #end[Object]
 609 
 610         Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
 611             super(Array.FORM);
 612             this.abase = abase;
 613             this.ashift = ashift;
 614 #if[Object]
 615             this.arrayType = {#if[Object]?arrayType:$type$[].class};
 616             this.componentType = arrayType.getComponentType();
 617 #end[Object]














 618         }
 619 
 620         @Override
 621         public Optional<VarHandleDesc> describeConstable() {
 622             var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
 623             if (!arrayTypeRef.isPresent())
 624                 return Optional.empty();
 625 
 626             return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
 627         }
 628 
 629         @Override
 630         final MethodType accessModeTypeUncached(AccessMode accessMode) {
 631             return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
 632         }
 633 
 634 #if[Object]
 635         @ForceInline
 636         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
 637             if (handle.arrayType == oarray.getClass()) {


< prev index next >