1040 * {@code (CT, T value)}
1041 * , statically represented using varargs.
1042 * @return the signature-polymorphic result that is the current value of
1043 * the variable
1044 * , statically represented using {@code Object}.
1045 * @throws UnsupportedOperationException if the access mode is unsupported
1046 * for this VarHandle.
1047 * @throws WrongMethodTypeException if the access mode type is not
1048 * compatible with the caller's symbolic type descriptor.
1049 * @throws ClassCastException if the access mode type is compatible with the
1050 * caller's symbolic type descriptor, but a reference cast fails.
1051 * @see #setVolatile(Object...)
1052 * @see #getVolatile(Object...)
1053 */
1054 public final native
1055 @MethodHandle.PolymorphicSignature
1056 @HotSpotIntrinsicCandidate
1057 Object addAndGet(Object... args);
1058
1059 enum AccessType {
1060 GET(Object.class) {
1061 @Override
1062 MethodType accessModeType(Class<?> receiver, Class<?> value,
1063 Class<?>... intermediate) {
1064 Class<?>[] ps = allocateParameters(0, receiver, intermediate);
1065 fillParameters(ps, receiver, intermediate);
1066 return MethodType.methodType(value, ps);
1067 }
1068 },
1069 SET(void.class) {
1070 @Override
1071 MethodType accessModeType(Class<?> receiver, Class<?> value,
1072 Class<?>... intermediate) {
1073 Class<?>[] ps = allocateParameters(1, receiver, intermediate);
1074 int i = fillParameters(ps, receiver, intermediate);
1075 ps[i] = value;
1076 return MethodType.methodType(void.class, ps);
1077 }
1078 },
1079 COMPARE_AND_SWAP(boolean.class) {
1080 @Override
1081 MethodType accessModeType(Class<?> receiver, Class<?> value,
1082 Class<?>... intermediate) {
1083 Class<?>[] ps = allocateParameters(2, receiver, intermediate);
1084 int i = fillParameters(ps, receiver, intermediate);
1085 ps[i++] = value;
1086 ps[i] = value;
1087 return MethodType.methodType(boolean.class, ps);
1088 }
1089 },
1090 COMPARE_AND_EXCHANGE(Object.class) {
1091 @Override
1092 MethodType accessModeType(Class<?> receiver, Class<?> value,
1093 Class<?>... intermediate) {
1094 Class<?>[] ps = allocateParameters(2, receiver, intermediate);
1095 int i = fillParameters(ps, receiver, intermediate);
1096 ps[i++] = value;
1097 ps[i] = value;
1098 return MethodType.methodType(value, ps);
1099 }
1100 },
1101 GET_AND_UPDATE(Object.class) {
1102 @Override
1103 MethodType accessModeType(Class<?> receiver, Class<?> value,
1104 Class<?>... intermediate) {
1105 Class<?>[] ps = allocateParameters(1, receiver, intermediate);
1106 int i = fillParameters(ps, receiver, intermediate);
1107 ps[i] = value;
1108 return MethodType.methodType(value, ps);
1109 }
1110 };
1111
1112 final Class<?> returnType;
1113 final boolean isMonomorphicInReturnType;
1114
1115 AccessType(Class<?> returnType) {
1116 this.returnType = returnType;
1117 isMonomorphicInReturnType = returnType != Object.class;
1118 }
1119
1120 abstract MethodType accessModeType(Class<?> receiver, Class<?> value,
1121 Class<?>... intermediate);
1122
1123 private static Class<?>[] allocateParameters(int values,
1124 Class<?> receiver, Class<?>... intermediate) {
1125 int size = ((receiver != null) ? 1 : 0) + intermediate.length + values;
1126 return new Class<?>[size];
1127 }
1128
1129 private static int fillParameters(Class<?>[] ps,
1130 Class<?> receiver, Class<?>... intermediate) {
1131 int i = 0;
1132 if (receiver != null)
1133 ps[i++] = receiver;
1134 for (int j = 0; j < intermediate.length; j++)
1135 ps[i++] = intermediate[j];
1136 return i;
1137 }
1138 }
1139
1140 /**
1141 * The set of access modes that specify how a variable, referenced by a
|
1040 * {@code (CT, T value)}
1041 * , statically represented using varargs.
1042 * @return the signature-polymorphic result that is the current value of
1043 * the variable
1044 * , statically represented using {@code Object}.
1045 * @throws UnsupportedOperationException if the access mode is unsupported
1046 * for this VarHandle.
1047 * @throws WrongMethodTypeException if the access mode type is not
1048 * compatible with the caller's symbolic type descriptor.
1049 * @throws ClassCastException if the access mode type is compatible with the
1050 * caller's symbolic type descriptor, but a reference cast fails.
1051 * @see #setVolatile(Object...)
1052 * @see #getVolatile(Object...)
1053 */
1054 public final native
1055 @MethodHandle.PolymorphicSignature
1056 @HotSpotIntrinsicCandidate
1057 Object addAndGet(Object... args);
1058
1059 enum AccessType {
1060 GET(Object.class),
1061 SET(void.class),
1062 COMPARE_AND_SWAP(boolean.class),
1063 COMPARE_AND_EXCHANGE(Object.class),
1064 GET_AND_UPDATE(Object.class);
1065
1066 final Class<?> returnType;
1067 final boolean isMonomorphicInReturnType;
1068
1069 AccessType(Class<?> returnType) {
1070 this.returnType = returnType;
1071 isMonomorphicInReturnType = returnType != Object.class;
1072 }
1073
1074 MethodType accessModeType(Class<?> receiver, Class<?> value,
1075 Class<?>... intermediate) {
1076 Class<?>[] ps;
1077 int i;
1078 switch (this) {
1079 case GET:
1080 ps = allocateParameters(0, receiver, intermediate);
1081 fillParameters(ps, receiver, intermediate);
1082 return MethodType.methodType(value, ps);
1083 case SET:
1084 ps = allocateParameters(1, receiver, intermediate);
1085 i = fillParameters(ps, receiver, intermediate);
1086 ps[i] = value;
1087 return MethodType.methodType(void.class, ps);
1088 case COMPARE_AND_SWAP:
1089 ps = allocateParameters(2, receiver, intermediate);
1090 i = fillParameters(ps, receiver, intermediate);
1091 ps[i++] = value;
1092 ps[i] = value;
1093 return MethodType.methodType(boolean.class, ps);
1094 case COMPARE_AND_EXCHANGE:
1095 ps = allocateParameters(2, receiver, intermediate);
1096 i = fillParameters(ps, receiver, intermediate);
1097 ps[i++] = value;
1098 ps[i] = value;
1099 return MethodType.methodType(value, ps);
1100 case GET_AND_UPDATE:
1101 ps = allocateParameters(1, receiver, intermediate);
1102 i = fillParameters(ps, receiver, intermediate);
1103 ps[i] = value;
1104 return MethodType.methodType(value, ps);
1105 default:
1106 throw new InternalError("Unknown AccessType");
1107 }
1108 }
1109
1110 private static Class<?>[] allocateParameters(int values,
1111 Class<?> receiver, Class<?>... intermediate) {
1112 int size = ((receiver != null) ? 1 : 0) + intermediate.length + values;
1113 return new Class<?>[size];
1114 }
1115
1116 private static int fillParameters(Class<?>[] ps,
1117 Class<?> receiver, Class<?>... intermediate) {
1118 int i = 0;
1119 if (receiver != null)
1120 ps[i++] = receiver;
1121 for (int j = 0; j < intermediate.length; j++)
1122 ps[i++] = intermediate[j];
1123 return i;
1124 }
1125 }
1126
1127 /**
1128 * The set of access modes that specify how a variable, referenced by a
|