< 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,11 +105,11 @@
static MethodHandle[] getters(Lookup lookup) {
return getters(lookup, null);
}
static MethodHandle[] getters(Lookup lookup, Comparator<MethodHandle> comparator) {
- Class<?> type = lookup.lookupClass().asValueType();
+ 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,12 +171,12 @@
/*
* 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();
+ 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,11 +215,11 @@
}
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();
+ return a.getClass().isInlineClass() && a.getClass().asNullableType() == b.getClass().asNullableType();
}
private static boolean valueEq(Object a, Object b) {
assert isSameValueClass(a, b);
try {
@@ -346,11 +346,11 @@
/*
* Produces a method handle that computes the hashcode
*/
private static MethodHandle hashCodeInvoker(Lookup lookup, String name, MethodType mt) {
- Class<?> type = lookup.lookupClass().asValueType();
+ 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,21 +374,27 @@
/*
* 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();
+ 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,11 +416,11 @@
/*
* 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();
+ 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,11 +524,11 @@
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();
+ 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,11 +570,11 @@
return MethodHandleBuilder.primitiveEquals(type);
if (type.isInterface() || type == Object.class)
return MethodHandleBuilder.interfaceEquals(type);
- if (type.isValue())
+ if (type.isInlineClass())
return SUBST_TEST_METHOD_HANDLES.get(type);
return MethodHandleBuilder.referenceEquals(type);
}
< prev index next >