Skip to content

Commit 6ed285b

Browse files
committed
intellij inspection inspired cleanups
1 parent feec6c4 commit 6ed285b

File tree

3 files changed

+82
-144
lines changed

3 files changed

+82
-144
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/type/IntegerStamp.java

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ static IntegerStamp createEmptyStamp(int bits) {
481481

482482
@Override
483483
public Stamp constant(Constant c, MetaAccessProvider meta) {
484-
if (c instanceof PrimitiveConstant) {
485-
PrimitiveConstant primitiveConstant = (PrimitiveConstant) c;
484+
if (c instanceof PrimitiveConstant primitiveConstant) {
486485
long value = primitiveConstant.asLong();
487486
if (primitiveConstant.getJavaKind() == JavaKind.Boolean && value == 1) {
488487
// Need to special case booleans as integer stamps are always signed values.
@@ -497,20 +496,15 @@ public Stamp constant(Constant c, MetaAccessProvider meta) {
497496

498497
@Override
499498
public SerializableConstant deserialize(ByteBuffer buffer) {
500-
switch (getBits()) {
501-
case 1:
502-
return JavaConstant.forBoolean(buffer.get() != 0);
503-
case 8:
504-
return JavaConstant.forByte(buffer.get());
505-
case 16:
506-
return JavaConstant.forShort(buffer.getShort());
507-
case 32:
508-
return JavaConstant.forInt(buffer.getInt());
509-
case 64:
510-
return JavaConstant.forLong(buffer.getLong());
511-
default:
499+
return switch (getBits()) {
500+
case 1 -> JavaConstant.forBoolean(buffer.get() != 0);
501+
case 8 -> JavaConstant.forByte(buffer.get());
502+
case 16 -> JavaConstant.forShort(buffer.getShort());
503+
case 32 -> JavaConstant.forInt(buffer.getInt());
504+
case 64 -> JavaConstant.forLong(buffer.getLong());
505+
default ->
512506
throw GraalError.shouldNotReachHereUnexpectedValue(getBits()); // ExcludeFromJacocoGeneratedReport
513-
}
507+
};
514508
}
515509

516510
@Override
@@ -534,20 +528,15 @@ public LIRKind getLIRKind(LIRKindTool tool) {
534528

535529
@Override
536530
public ResolvedJavaType javaType(MetaAccessProvider metaAccess) {
537-
switch (getBits()) {
538-
case 1:
539-
return metaAccess.lookupJavaType(Boolean.TYPE);
540-
case 8:
541-
return metaAccess.lookupJavaType(Byte.TYPE);
542-
case 16:
543-
return metaAccess.lookupJavaType(Short.TYPE);
544-
case 32:
545-
return metaAccess.lookupJavaType(Integer.TYPE);
546-
case 64:
547-
return metaAccess.lookupJavaType(Long.TYPE);
548-
default:
531+
return switch (getBits()) {
532+
case 1 -> metaAccess.lookupJavaType(Boolean.TYPE);
533+
case 8 -> metaAccess.lookupJavaType(Byte.TYPE);
534+
case 16 -> metaAccess.lookupJavaType(Short.TYPE);
535+
case 32 -> metaAccess.lookupJavaType(Integer.TYPE);
536+
case 64 -> metaAccess.lookupJavaType(Long.TYPE);
537+
default ->
549538
throw GraalError.shouldNotReachHereUnexpectedValue(getBits()); // ExcludeFromJacocoGeneratedReport
550-
}
539+
};
551540
}
552541

553542
@Override
@@ -753,17 +742,15 @@ public boolean isCompatible(Stamp stamp) {
753742
if (this == stamp) {
754743
return true;
755744
}
756-
if (stamp instanceof IntegerStamp) {
757-
IntegerStamp other = (IntegerStamp) stamp;
745+
if (stamp instanceof IntegerStamp other) {
758746
return getBits() == other.getBits();
759747
}
760748
return false;
761749
}
762750

763751
@Override
764752
public boolean isCompatible(Constant constant) {
765-
if (constant instanceof PrimitiveConstant) {
766-
PrimitiveConstant prim = (PrimitiveConstant) constant;
753+
if (constant instanceof PrimitiveConstant prim) {
767754
JavaKind kind = prim.getJavaKind();
768755
return kind.isNumericInteger() && kind.getBitCount() == getBits();
769756
}
@@ -793,10 +780,10 @@ public int hashCode() {
793780
final int prime = 31;
794781
int result = 1;
795782
result = prime * result + super.hashCode();
796-
result = prime * result + (int) (lowerBound ^ (lowerBound >>> 32));
797-
result = prime * result + (int) (upperBound ^ (upperBound >>> 32));
798-
result = prime * result + (int) (mustBeSet ^ (mustBeSet >>> 32));
799-
result = prime * result + (int) (mayBeSet ^ (mayBeSet >>> 32));
783+
result = prime * result + Long.hashCode(lowerBound);
784+
result = prime * result + Long.hashCode(upperBound);
785+
result = prime * result + Long.hashCode(mustBeSet);
786+
result = prime * result + Long.hashCode(mayBeSet);
800787
result = prime * result + Boolean.hashCode(canBeZero);
801788
return result;
802789
}
@@ -907,9 +894,9 @@ public static boolean multiplicationOverflows(long a, long b, int bits) {
907894
if (bits == 64) {
908895
if (a > 0 && b > 0) {
909896
return a > 0x7FFFFFFF_FFFFFFFFL / b;
910-
} else if (a > 0 && b <= 0) {
897+
} else if (a > 0) {
911898
return b < 0x80000000_00000000L / a;
912-
} else if (a <= 0 && b > 0) {
899+
} else if (b > 0) {
913900
return a < 0x80000000_00000000L / b;
914901
} else {
915902
// a<=0 && b <=0
@@ -1315,7 +1302,7 @@ protected Stamp foldStampImpl(Stamp stamp1, Stamp stamp2) {
13151302
}
13161303
}
13171304

1318-
assert newLowerBound <= newUpperBound : Assertions.errorMessageContext("newLowerBound", newLowerBound, "newUpperBonud", newUpperBound, "stamp1", stamp1, "stamp2",
1305+
assert newLowerBound <= newUpperBound : Assertions.errorMessageContext("newLowerBound", newLowerBound, "newUpperBound", newUpperBound, "stamp1", stamp1, "stamp2",
13191306
stamp2);
13201307
return StampFactory.forIntegerWithMask(bits, newLowerBound, newUpperBound, 0, newMayBeSet);
13211308
}
@@ -1835,18 +1822,16 @@ public Stamp foldStampImpl(Stamp stamp, Stamp amount) {
18351822
return value;
18361823
}
18371824
if (shiftAmount >= bits) {
1838-
IntegerStamp result = IntegerStamp.create(bits, 0, 0, 0, 0);
1839-
return result;
1825+
return IntegerStamp.create(bits, 0, 0, 0, 0);
18401826
}
18411827
// the mask of bits that will be lost or shifted into the sign bit
18421828
if (testNoSignChangeAfterShifting(bits, value.lowerBound(), shiftAmount) && testNoSignChangeAfterShifting(bits, value.upperBound(), shiftAmount)) {
18431829
/*
18441830
* use a better stamp if neither lower nor upper bound can lose
18451831
* bits
18461832
*/
1847-
IntegerStamp result = IntegerStamp.create(bits, value.lowerBound() << shiftAmount, value.upperBound() << shiftAmount,
1833+
return IntegerStamp.create(bits, value.lowerBound() << shiftAmount, value.upperBound() << shiftAmount,
18481834
(value.mustBeSet() << shiftAmount) & CodeUtil.mask(bits), (value.mayBeSet() << shiftAmount) & CodeUtil.mask(bits));
1849-
return result;
18501835
}
18511836
}
18521837
if ((shift.lowerBound() >>> shiftBits) == (shift.upperBound() >>> shiftBits)) {
@@ -2189,11 +2174,11 @@ public Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp) {
21892174
* @formatter:on
21902175
*/
21912176
if (zeroInExtension) {
2192-
long msbZeroMask = ~(1 << (inputBits - 1));
2177+
long msbZeroMask = ~(1L << (inputBits - 1));
21932178
inputMustBeSet &= msbZeroMask;
21942179
inputMayBeSet &= msbZeroMask;
21952180
} else if (oneInExtension) {
2196-
long msbOneMask = 1 << (inputBits - 1);
2181+
long msbOneMask = 1L << (inputBits - 1);
21972182
inputMustBeSet |= msbOneMask;
21982183
inputMayBeSet |= msbOneMask;
21992184
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/BoxingSnippets.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ public Templates(OptionValues options, SnippetCounter.Group.Factory factory, Pro
239239
}
240240

241241
static Class<?> getCacheClass(JavaKind kind) {
242-
Class<?>[] innerClasses = null;
243-
innerClasses = kind.toBoxedJavaClass().getDeclaredClasses();
242+
Class<?>[] innerClasses = kind.toBoxedJavaClass().getDeclaredClasses();
244243
for (Class<?> innerClass : innerClasses) {
245244
if (innerClass.getSimpleName().equals(kind.toBoxedJavaClass().getSimpleName() + "Cache")) {
246245
return innerClass;

0 commit comments

Comments
 (0)