< prev index next >
jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Print this page
*** 23,33 ****
* questions.
*/
package java.lang.invoke;
- import jdk.experimental.value.ValueType;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.IllegalAccessLogger;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
--- 23,32 ----
*** 36,45 ****
--- 35,45 ----
import sun.invoke.util.VerifyAccess;
import sun.invoke.util.Wrapper;
import sun.reflect.misc.ReflectUtil;
import sun.security.util.SecurityConstants;
import valhalla.shady.MinimalValueTypes_1_0;
+ import valhalla.shady.ValueTypeHolder;
import java.lang.invoke.LambdaForm.BasicType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
*** 54,64 ****
import java.util.Arrays;
import java.util.BitSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
- import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.invoke.MethodHandleImpl.Intrinsic;
--- 54,63 ----
*** 1425,1435 ****
* @throws NullPointerException if any argument is null
* @see #findVarHandle(Class, String, Class)
*/
public MethodHandle findGetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException {
if (MinimalValueTypes_1_0.isValueType(refc)) {
! return ValueType.forClass(MinimalValueTypes_1_0.getValueCapableClass(refc)).findGetter(this, name, type);
} else {
MemberName field = resolveOrFail(REF_getField, refc, name, type);
return getDirectField(REF_getField, refc, field);
}
}
--- 1424,1434 ----
* @throws NullPointerException if any argument is null
* @see #findVarHandle(Class, String, Class)
*/
public MethodHandle findGetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException {
if (MinimalValueTypes_1_0.isValueType(refc)) {
! return MinimalValueTypes_1_0.findValueType(refc).findGetter(this, name, type);
} else {
MemberName field = resolveOrFail(REF_getField, refc, name, type);
return getDirectField(REF_getField, refc, field);
}
}
*** 2537,2547 ****
* @see java.lang.reflect.Array#newInstance(Class, int)
* @since 9
*/
public static
MethodHandle arrayConstructor(Class<?> arrayClass) throws IllegalArgumentException {
! ValueType<?> compValue = valueComponent(arrayClass);
if (compValue != null) {
return compValue.newArray();
} else {
MethodHandle ani = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_Array_newInstance).
bindTo(arrayClass.getComponentType());
--- 2536,2546 ----
* @see java.lang.reflect.Array#newInstance(Class, int)
* @since 9
*/
public static
MethodHandle arrayConstructor(Class<?> arrayClass) throws IllegalArgumentException {
! ValueTypeHolder<?> compValue = valueComponent(arrayClass);
if (compValue != null) {
return compValue.newArray();
} else {
MethodHandle ani = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_Array_newInstance).
bindTo(arrayClass.getComponentType());
*** 2559,2569 ****
* @throws IllegalArgumentException if arrayClass is not an array type
* @since 9
*/
public static
MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {
! ValueType<?> compValue = valueComponent(arrayClass);
return (compValue != null) ?
compValue.arrayLength() :
MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.LENGTH);
}
--- 2558,2568 ----
* @throws IllegalArgumentException if arrayClass is not an array type
* @since 9
*/
public static
MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {
! ValueTypeHolder<?> compValue = valueComponent(arrayClass);
return (compValue != null) ?
compValue.arrayLength() :
MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.LENGTH);
}
*** 2577,2587 ****
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
*/
public static
MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
! ValueType<?> compValue = valueComponent(arrayClass);
return (compValue != null) ?
compValue.arrayGetter() :
MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
}
--- 2576,2586 ----
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
*/
public static
MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
! ValueTypeHolder<?> compValue = valueComponent(arrayClass);
return (compValue != null) ?
compValue.arrayGetter() :
MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
}
*** 2595,2619 ****
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
*/
public static
MethodHandle arrayElementSetter(Class<?> arrayClass) throws IllegalArgumentException {
! ValueType<?> compValue = valueComponent(arrayClass);
return (compValue != null) ?
compValue.arraySetter() :
MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.SET);
}
@SuppressWarnings("unchecked")
! private static <Z> ValueType<Z> valueComponent(Class<Z> arrayClass) {
if (!arrayClass.isArray()) {
throw newIllegalArgumentException("not an array class: " + arrayClass.getName());
}
Class<?> comp = arrayClass.getComponentType();
if (MinimalValueTypes_1_0.isValueType(comp)) {
! return (ValueType<Z>)ValueType.forClass(MinimalValueTypes_1_0.getValueCapableClass(comp));
} else {
return null;
}
}
--- 2594,2618 ----
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
*/
public static
MethodHandle arrayElementSetter(Class<?> arrayClass) throws IllegalArgumentException {
! ValueTypeHolder<?> compValue = valueComponent(arrayClass);
return (compValue != null) ?
compValue.arraySetter() :
MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.SET);
}
@SuppressWarnings("unchecked")
! private static <Z> ValueTypeHolder<Z> valueComponent(Class<Z> arrayClass) {
if (!arrayClass.isArray()) {
throw newIllegalArgumentException("not an array class: " + arrayClass.getName());
}
Class<?> comp = arrayClass.getComponentType();
if (MinimalValueTypes_1_0.isValueType(comp)) {
! return (ValueTypeHolder<Z>) MinimalValueTypes_1_0.findValueType(comp);
} else {
return null;
}
}
*** 3381,3391 ****
public static MethodHandle zero(Class<?> type) {
Objects.requireNonNull(type);
if (type.isPrimitive()) {
return zero(Wrapper.forPrimitiveType(type), type);
} else if (MinimalValueTypes_1_0.isValueType(type)) {
! return ValueType.forClass(MinimalValueTypes_1_0.getValueCapableClass(type)).defaultValueConstant();
} else {
return zero(Wrapper.OBJECT, type);
}
}
--- 3380,3390 ----
public static MethodHandle zero(Class<?> type) {
Objects.requireNonNull(type);
if (type.isPrimitive()) {
return zero(Wrapper.forPrimitiveType(type), type);
} else if (MinimalValueTypes_1_0.isValueType(type)) {
! return MinimalValueTypes_1_0.findValueType(type).defaultValueConstant();
} else {
return zero(Wrapper.OBJECT, type);
}
}
*** 3419,3429 ****
if (!MinimalValueTypes_1_0.isValueType(ptype)) {
MethodType mtype = MethodType.methodType(ptype, ptype);
LambdaForm lform = LambdaForm.identityForm(BasicType.basicType(ptype));
return MethodHandleImpl.makeIntrinsic(mtype, lform, Intrinsic.IDENTITY);
} else {
! return ValueType.forClass(MinimalValueTypes_1_0.getValueCapableClass(ptype)).identity();
}
}
private static MethodHandle zero(Wrapper btw, Class<?> rtype) {
int pos = btw.ordinal();
--- 3418,3428 ----
if (!MinimalValueTypes_1_0.isValueType(ptype)) {
MethodType mtype = MethodType.methodType(ptype, ptype);
LambdaForm lform = LambdaForm.identityForm(BasicType.basicType(ptype));
return MethodHandleImpl.makeIntrinsic(mtype, lform, Intrinsic.IDENTITY);
} else {
! return MinimalValueTypes_1_0.findValueType(ptype).identity();
}
}
private static MethodHandle zero(Wrapper btw, Class<?> rtype) {
int pos = btw.ordinal();
*** 3496,3506 ****
result = insertArgumentPrimitive(result, pos, ptype, value);
} else if (MinimalValueTypes_1_0.isValueType(ptype)) {
Class<?> vcc = MinimalValueTypes_1_0.getValueCapableClass(ptype);
Objects.requireNonNull(value); // throw NPE if needed
value = vcc.cast(value); // throw CCE if needed
! MethodHandle unbox = ValueType.forClass(vcc).unbox();
result = result.bindArgumentQ(pos, value, unbox);
} else {
value = ptype.cast(value); // throw CCE if needed
result = result.bindArgumentL(pos, value);
}
--- 3495,3505 ----
result = insertArgumentPrimitive(result, pos, ptype, value);
} else if (MinimalValueTypes_1_0.isValueType(ptype)) {
Class<?> vcc = MinimalValueTypes_1_0.getValueCapableClass(ptype);
Objects.requireNonNull(value); // throw NPE if needed
value = vcc.cast(value); // throw CCE if needed
! MethodHandle unbox = MinimalValueTypes_1_0.findValueType(ptype).unbox();
result = result.bindArgumentQ(pos, value, unbox);
} else {
value = ptype.cast(value); // throw CCE if needed
result = result.bindArgumentL(pos, value);
}
< prev index next >