< prev index next >
src/java.base/share/classes/java/lang/invoke/ValueBootstrapMethods.java
Print this page
rev 55127 : 8223351: [lworld] Primary mirror and nullable mirror for inline type
Reviewed-by: tbd
*** 105,115 ****
static MethodHandle[] getters(Lookup lookup) {
return getters(lookup, null);
}
static MethodHandle[] getters(Lookup lookup, Comparator<MethodHandle> comparator) {
! Class<?> type = lookup.lookupClass().asValueType();
// filter static fields and synthetic fields
Stream<MethodHandle> s = Arrays.stream(type.getDeclaredFields())
.filter(f -> !Modifier.isStatic(f.getModifiers()) && !f.isSynthetic())
.map(f -> {
try {
--- 105,115 ----
static MethodHandle[] getters(Lookup lookup) {
return getters(lookup, null);
}
static MethodHandle[] getters(Lookup lookup, Comparator<MethodHandle> comparator) {
! Class<?> type = lookup.lookupClass().asPrimaryType();
// filter static fields and synthetic fields
Stream<MethodHandle> s = Arrays.stream(type.getDeclaredFields())
.filter(f -> !Modifier.isStatic(f.getModifiers()) && !f.isSynthetic())
.map(f -> {
try {
*** 171,182 ****
/*
* Produces a MethodHandle that returns boolean if two value instances
* of the given value class are substitutable.
*/
static MethodHandle valueEquals(Class<?> c) {
! assert c.isValue();
! Class<?> type = c.asValueType();
MethodType mt = methodType(boolean.class, type, type);
MethodHandles.Lookup lookup = new MethodHandles.Lookup(type);
MethodHandle[] getters = getters(lookup, TYPE_SORTER);
MethodHandle instanceFalse = dropArguments(FALSE, 0, type, Object.class).asType(mt);
MethodHandle accumulator = dropArguments(TRUE, 0, type, type);
--- 171,182 ----
/*
* Produces a MethodHandle that returns boolean if two value instances
* of the given value class are substitutable.
*/
static MethodHandle valueEquals(Class<?> c) {
! assert c.isInlineClass();
! Class<?> type = c.asPrimaryType();
MethodType mt = methodType(boolean.class, type, type);
MethodHandles.Lookup lookup = new MethodHandles.Lookup(type);
MethodHandle[] getters = getters(lookup, TYPE_SORTER);
MethodHandle instanceFalse = dropArguments(FALSE, 0, type, Object.class).asType(mt);
MethodHandle accumulator = dropArguments(TRUE, 0, type, type);
*** 215,225 ****
}
private static boolean isSameValueClass(Object a, Object b) {
if (a == null || b == null)
return false;
! return a.getClass().isValue() && a.getClass().asBoxType() == b.getClass().asBoxType();
}
private static boolean valueEq(Object a, Object b) {
assert isSameValueClass(a, b);
try {
--- 215,225 ----
}
private static boolean isSameValueClass(Object a, Object b) {
if (a == null || b == null)
return false;
! return a.getClass().isInlineClass() && a.getClass().asNullableType() == b.getClass().asNullableType();
}
private static boolean valueEq(Object a, Object b) {
assert isSameValueClass(a, b);
try {
*** 346,356 ****
/*
* Produces a method handle that computes the hashcode
*/
private static MethodHandle hashCodeInvoker(Lookup lookup, String name, MethodType mt) {
! Class<?> type = lookup.lookupClass().asValueType();
MethodHandle target = dropArguments(constant(int.class, SALT), 0, type);
MethodHandle cls = dropArguments(constant(Class.class, type),0, type);
MethodHandle classHashCode = filterReturnValue(cls, hashCodeForType(Class.class));
MethodHandle combiner = filterArguments(HASH_COMBINER, 0, target, classHashCode);
// int v = SALT * 31 + type.hashCode();
--- 346,356 ----
/*
* Produces a method handle that computes the hashcode
*/
private static MethodHandle hashCodeInvoker(Lookup lookup, String name, MethodType mt) {
! Class<?> type = lookup.lookupClass().asPrimaryType();
MethodHandle target = dropArguments(constant(int.class, SALT), 0, type);
MethodHandle cls = dropArguments(constant(Class.class, type),0, type);
MethodHandle classHashCode = filterReturnValue(cls, hashCodeForType(Class.class));
MethodHandle combiner = filterArguments(HASH_COMBINER, 0, target, classHashCode);
// int v = SALT * 31 + type.hashCode();
*** 374,394 ****
/*
* Produces a method handle that invokes the toString method of a value object.
*/
private static MethodHandle toStringInvoker(Lookup lookup, String name, MethodType mt) {
! Class<?> type = lookup.lookupClass().asValueType();
MethodHandle[] getters = MethodHandleBuilder.getters(lookup);
int length = getters.length;
StringBuilder format = new StringBuilder();
Class<?>[] parameterTypes = new Class<?>[length];
// append the value class name
format.append("[").append(type.getName());
String separator = " ";
for (int i = 0; i < length; i++) {
MethodHandle getter = getters[i];
MethodHandleInfo fieldInfo = lookup.revealDirect(getter);
Class<?> ftype = fieldInfo.getMethodType().returnType();
format.append(separator)
.append(fieldInfo.getName())
.append("=\1");
getters[i]= filterReturnValue(getter, MethodHandleBuilder.toString(ftype));
--- 374,400 ----
/*
* Produces a method handle that invokes the toString method of a value object.
*/
private static MethodHandle toStringInvoker(Lookup lookup, String name, MethodType mt) {
! Class<?> type = lookup.lookupClass().asPrimaryType();
MethodHandle[] getters = MethodHandleBuilder.getters(lookup);
+ if (VERBOSE) {
+ System.out.println("getter: " + Arrays.toString(getters));
+ }
int length = getters.length;
StringBuilder format = new StringBuilder();
Class<?>[] parameterTypes = new Class<?>[length];
// append the value class name
format.append("[").append(type.getName());
String separator = " ";
for (int i = 0; i < length; i++) {
MethodHandle getter = getters[i];
MethodHandleInfo fieldInfo = lookup.revealDirect(getter);
+ if (VERBOSE) {
+ System.out.println("getter: " + getter + " field info: " + fieldInfo);
+ }
Class<?> ftype = fieldInfo.getMethodType().returnType();
format.append(separator)
.append(fieldInfo.getName())
.append("=\1");
getters[i]= filterReturnValue(getter, MethodHandleBuilder.toString(ftype));
*** 410,420 ****
/*
* Produces a method handle that tests if two arguments are equals.
*/
private static MethodHandle equalsInvoker(Lookup lookup, String name, MethodType mt) {
! Class<?> type = lookup.lookupClass().asValueType();
// MethodHandle to compare all fields of two value objects
MethodHandle[] getters = MethodHandleBuilder.getters(lookup, TYPE_SORTER);
MethodHandle accumulator = dropArguments(TRUE, 0, type, type);
MethodHandle instanceFalse = dropArguments(FALSE, 0, type, Object.class)
.asType(methodType(boolean.class, type, type));
--- 416,426 ----
/*
* Produces a method handle that tests if two arguments are equals.
*/
private static MethodHandle equalsInvoker(Lookup lookup, String name, MethodType mt) {
! Class<?> type = lookup.lookupClass().asPrimaryType();
// MethodHandle to compare all fields of two value objects
MethodHandle[] getters = MethodHandleBuilder.getters(lookup, TYPE_SORTER);
MethodHandle accumulator = dropArguments(TRUE, 0, type, type);
MethodHandle instanceFalse = dropArguments(FALSE, 0, type, Object.class)
.asType(methodType(boolean.class, type, type));
*** 518,528 ****
if (a == b) return true;
if (a == null || b == null) return false;
if (a.getClass() != b.getClass()) return false;
try {
! Class<?> type = a.getClass().isValue() ? a.getClass().asValueType() : a.getClass();
return (boolean) substitutableInvoker(type).invoke(a, b);
} catch (Error|RuntimeException e) {
throw e;
} catch (Throwable e) {
if (VERBOSE) e.printStackTrace();
--- 524,534 ----
if (a == b) return true;
if (a == null || b == null) return false;
if (a.getClass() != b.getClass()) return false;
try {
! Class<?> type = a.getClass().isInlineClass() ? a.getClass().asPrimaryType() : a.getClass();
return (boolean) substitutableInvoker(type).invoke(a, b);
} catch (Error|RuntimeException e) {
throw e;
} catch (Throwable e) {
if (VERBOSE) e.printStackTrace();
*** 564,574 ****
return MethodHandleBuilder.primitiveEquals(type);
if (type.isInterface() || type == Object.class)
return MethodHandleBuilder.interfaceEquals(type);
! if (type.isValue())
return SUBST_TEST_METHOD_HANDLES.get(type);
return MethodHandleBuilder.referenceEquals(type);
}
--- 570,580 ----
return MethodHandleBuilder.primitiveEquals(type);
if (type.isInterface() || type == Object.class)
return MethodHandleBuilder.interfaceEquals(type);
! if (type.isInlineClass())
return SUBST_TEST_METHOD_HANDLES.get(type);
return MethodHandleBuilder.referenceEquals(type);
}
< prev index next >