mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8263358: Update java.lang to use instanceof pattern variable
Reviewed-by: iris, chegar, mchung, dfuchs
This commit is contained in:
parent
ae9af57bf6
commit
329697b02e
18 changed files with 63 additions and 112 deletions
|
@ -302,8 +302,7 @@ class InvokerBytecodeGenerator {
|
|||
}
|
||||
|
||||
private static String debugString(Object arg) {
|
||||
if (arg instanceof MethodHandle) {
|
||||
MethodHandle mh = (MethodHandle) arg;
|
||||
if (arg instanceof MethodHandle mh) {
|
||||
MemberName member = mh.internalMemberName();
|
||||
if (member != null)
|
||||
return member.toString();
|
||||
|
@ -627,8 +626,7 @@ class InvokerBytecodeGenerator {
|
|||
|
||||
private void emitReferenceCast(Class<?> cls, Object arg) {
|
||||
Name writeBack = null; // local to write back result
|
||||
if (arg instanceof Name) {
|
||||
Name n = (Name) arg;
|
||||
if (arg instanceof Name n) {
|
||||
if (lambdaForm.useCount(n) > 1) {
|
||||
// This guy gets used more than once.
|
||||
writeBack = n;
|
||||
|
@ -1679,8 +1677,7 @@ class InvokerBytecodeGenerator {
|
|||
|
||||
private void emitPushArgument(Class<?> ptype, Object arg) {
|
||||
BasicType bptype = basicType(ptype);
|
||||
if (arg instanceof Name) {
|
||||
Name n = (Name) arg;
|
||||
if (arg instanceof Name n) {
|
||||
emitLoadInsn(n.type, n.index());
|
||||
emitImplicitConversion(n.type, ptype, n);
|
||||
} else if (arg == null && bptype == L_TYPE) {
|
||||
|
|
|
@ -568,8 +568,7 @@ class LambdaForm {
|
|||
Name n = names[i];
|
||||
assert(n.index() == i);
|
||||
for (Object arg : n.arguments) {
|
||||
if (arg instanceof Name) {
|
||||
Name n2 = (Name) arg;
|
||||
if (arg instanceof Name n2) {
|
||||
int i2 = n2.index;
|
||||
assert(0 <= i2 && i2 < names.length) : n.debugString() + ": 0 <= i2 && i2 < names.length: 0 <= " + i2 + " < " + names.length;
|
||||
assert(names[i2] == n2) : Arrays.asList("-1-", i, "-2-", n.debugString(), "-3-", i2, "-4-", n2.debugString(), "-5-", names[i2].debugString(), "-6-", this);
|
||||
|
@ -1133,9 +1132,9 @@ class LambdaForm {
|
|||
public boolean equals(Object other) {
|
||||
if (this == other) return true;
|
||||
if (other == null) return false;
|
||||
if (!(other instanceof NamedFunction)) return false;
|
||||
NamedFunction that = (NamedFunction) other;
|
||||
return this.member != null && this.member.equals(that.member);
|
||||
return (other instanceof NamedFunction that)
|
||||
&& this.member != null
|
||||
&& this.member.equals(that.member);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1407,8 +1406,7 @@ class LambdaForm {
|
|||
boolean replaced = false;
|
||||
eachArg:
|
||||
for (int j = 0; j < arguments.length; j++) {
|
||||
if (arguments[j] instanceof Name) {
|
||||
Name n = (Name) arguments[j];
|
||||
if (arguments[j] instanceof Name n) {
|
||||
int check = n.index;
|
||||
// harmless check to see if the thing is already in newNames:
|
||||
if (check >= 0 && check < newNames.length && n == newNames[check])
|
||||
|
@ -1435,8 +1433,7 @@ class LambdaForm {
|
|||
@SuppressWarnings("LocalVariableHidesMemberVariable")
|
||||
Object[] arguments = this.arguments;
|
||||
for (int j = 0; j < arguments.length; j++) {
|
||||
if (arguments[j] instanceof Name) {
|
||||
Name n = (Name) arguments[j];
|
||||
if (arguments[j] instanceof Name n) {
|
||||
if (n.isParam() && n.index < INTERNED_ARGUMENT_LIMIT)
|
||||
arguments[j] = internArgument(n);
|
||||
}
|
||||
|
|
|
@ -337,9 +337,8 @@ class LambdaFormEditor {
|
|||
k = m.get(key);
|
||||
} else if (c == null) {
|
||||
return null;
|
||||
} else if (c instanceof Transform) {
|
||||
} else if (c instanceof Transform t) {
|
||||
// one-element cache avoids overhead of an array
|
||||
Transform t = (Transform)c;
|
||||
if (t.equals(key)) k = t;
|
||||
} else {
|
||||
Transform[] ta = (Transform[])c;
|
||||
|
@ -389,8 +388,7 @@ class LambdaFormEditor {
|
|||
return form;
|
||||
}
|
||||
Transform[] ta;
|
||||
if (c instanceof Transform) {
|
||||
Transform k = (Transform)c;
|
||||
if (c instanceof Transform k) {
|
||||
if (k.equals(key)) {
|
||||
LambdaForm result = k.get();
|
||||
if (result == null) {
|
||||
|
|
|
@ -147,12 +147,10 @@ final class MemberName implements Member, Cloneable {
|
|||
|
||||
// type is not a MethodType yet. Convert it thread-safely.
|
||||
synchronized (this) {
|
||||
if (type instanceof String) {
|
||||
String sig = (String) type;
|
||||
if (type instanceof String sig) {
|
||||
MethodType res = MethodType.fromDescriptor(sig, getClassLoader());
|
||||
type = res;
|
||||
} else if (type instanceof Object[]) {
|
||||
Object[] typeInfo = (Object[]) type;
|
||||
} else if (type instanceof Object[] typeInfo) {
|
||||
Class<?>[] ptypes = (Class<?>[]) typeInfo[1];
|
||||
Class<?> rtype = (Class<?>) typeInfo[0];
|
||||
MethodType res = MethodType.makeImpl(rtype, ptypes, true);
|
||||
|
@ -235,8 +233,7 @@ final class MemberName implements Member, Cloneable {
|
|||
|
||||
// type is not a Class yet. Convert it thread-safely.
|
||||
synchronized (this) {
|
||||
if (type instanceof String) {
|
||||
String sig = (String) type;
|
||||
if (type instanceof String sig) {
|
||||
MethodType mtype = MethodType.fromDescriptor("()"+sig, getClassLoader());
|
||||
Class<?> res = mtype.returnType();
|
||||
type = res;
|
||||
|
@ -938,8 +935,7 @@ final class MemberName implements Member, Cloneable {
|
|||
} else {
|
||||
Module m;
|
||||
Class<?> plc;
|
||||
if (from instanceof MethodHandles.Lookup) {
|
||||
MethodHandles.Lookup lookup = (MethodHandles.Lookup)from;
|
||||
if (from instanceof MethodHandles.Lookup lookup) {
|
||||
from = lookup.lookupClass();
|
||||
m = lookup.lookupClass().getModule();
|
||||
plc = lookup.previousLookupClass();
|
||||
|
|
|
@ -2262,10 +2262,9 @@ public class MethodHandles {
|
|||
// workaround to read `this_class` using readConst and validate the value
|
||||
int thisClass = reader.readUnsignedShort(reader.header + 2);
|
||||
Object constant = reader.readConst(thisClass, new char[reader.getMaxStringLength()]);
|
||||
if (!(constant instanceof Type)) {
|
||||
if (!(constant instanceof Type type)) {
|
||||
throw new ClassFormatError("this_class item: #" + thisClass + " not a CONSTANT_Class_info");
|
||||
}
|
||||
Type type = ((Type) constant);
|
||||
if (!type.getDescriptor().startsWith("L")) {
|
||||
throw new ClassFormatError("this_class item: #" + thisClass + " not a CONSTANT_Class_info");
|
||||
}
|
||||
|
|
|
@ -605,8 +605,7 @@ final class VarHandles {
|
|||
}
|
||||
|
||||
private static void noCheckedExceptions(MethodHandle handle) {
|
||||
if (handle instanceof DirectMethodHandle) {
|
||||
DirectMethodHandle directHandle = (DirectMethodHandle)handle;
|
||||
if (handle instanceof DirectMethodHandle directHandle) {
|
||||
byte refKind = directHandle.member.getReferenceKind();
|
||||
MethodHandleInfo info = new InfoFromMemberName(
|
||||
MethodHandles.Lookup.IMPL_LOOKUP,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue