Skip to content

Commit 7905788

Browse files
author
Andrey Turbanov
committed
8289126: Cleanup unnecessary null comparison before instanceof check in jdk.hotspot.agent
Reviewed-by: ayang, cjplummer
1 parent 47fe9ef commit 7905788

File tree

18 files changed

+49
-62
lines changed

18 files changed

+49
-62
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ public void doit(Tokens t) {
581581
// dump replay data
582582

583583
CodeBlob cb = VM.getVM().getCodeCache().findBlob(a);
584-
if (cb != null && (cb instanceof NMethod)) {
585-
((NMethod)cb).dumpReplayData(out);
584+
if (cb instanceof NMethod nMethod) {
585+
nMethod.dumpReplayData(out);
586586
return;
587587
}
588588
// assume it is Metadata

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,11 +49,11 @@ class BsdThread implements ThreadProxy {
4949
}
5050

5151
public boolean equals(Object obj) {
52-
if ((obj == null) || !(obj instanceof BsdThread)) {
52+
if (!(obj instanceof BsdThread other)) {
5353
return false;
5454
}
5555

56-
return (((BsdThread) obj).unique_thread_id == unique_thread_id);
56+
return (other.unique_thread_id == unique_thread_id);
5757
}
5858

5959
public int hashCode() {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/cdbg/LoadObjectComparator.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,9 +38,6 @@ public int compare(LoadObject lo1, LoadObject lo2) {
3838
}
3939

4040
public boolean equals(Object o) {
41-
if (o == null || !(o instanceof LoadObjectComparator)) {
42-
return false;
43-
}
44-
return true;
41+
return o instanceof LoadObjectComparator;
4542
}
4643
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxThread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,11 +55,11 @@ class LinuxThread implements ThreadProxy {
5555
}
5656

5757
public boolean equals(Object obj) {
58-
if ((obj == null) || !(obj instanceof LinuxThread)) {
58+
if (!(obj instanceof LinuxThread other)) {
5959
return false;
6060
}
6161

62-
return (((LinuxThread) obj).lwp_id == lwp_id);
62+
return (other.lwp_id == lwp_id);
6363
}
6464

6565
public int hashCode() {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/posix/DSO.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
2525

2626
import sun.jvm.hotspot.debugger.*;
2727
import sun.jvm.hotspot.debugger.cdbg.*;
28-
import sun.jvm.hotspot.utilities.memo.*;
2928

3029
/** Provides a simple wrapper around the ELF library which handles
3130
relocation. */
@@ -69,10 +68,9 @@ public LineNumberInfo lineNumberForPC(Address pc) throws DebuggerException {
6968
}
7069

7170
public boolean equals(Object o) {
72-
if (o == null || !(o instanceof DSO)) {
71+
if (!(o instanceof DSO other)) {
7372
return false;
7473
}
75-
DSO other = (DSO)o;
7674
return getBase().equals(other.getBase());
7775
}
7876

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/proc/aarch64/ProcAARCH64Thread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2015, Red Hat Inc.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -74,11 +74,11 @@ public String toString() {
7474
}
7575

7676
public boolean equals(Object obj) {
77-
if ((obj == null) || !(obj instanceof ProcAARCH64Thread)) {
77+
if (!(obj instanceof ProcAARCH64Thread other)) {
7878
return false;
7979
}
8080

81-
return (((ProcAARCH64Thread) obj).id == id);
81+
return (other.id == id);
8282
}
8383

8484
public int hashCode() {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/proc/amd64/ProcAMD64Thread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,11 +73,11 @@ public String toString() {
7373
}
7474

7575
public boolean equals(Object obj) {
76-
if ((obj == null) || !(obj instanceof ProcAMD64Thread)) {
76+
if (!(obj instanceof ProcAMD64Thread other)) {
7777
return false;
7878
}
7979

80-
return (((ProcAMD64Thread) obj).id == id);
80+
return (other.id == id);
8181
}
8282

8383
public int hashCode() {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/proc/ppc64/ProcPPC64Thread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,11 +73,11 @@ public String toString() {
7373
}
7474

7575
public boolean equals(Object obj) {
76-
if ((obj == null) || !(obj instanceof ProcPPC64Thread)) {
76+
if (!(obj instanceof ProcPPC64Thread other)) {
7777
return false;
7878
}
7979

80-
return (((ProcPPC64Thread) obj).id == id);
80+
return (other.id == id);
8181
}
8282

8383
public int hashCode() {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/proc/riscv64/ProcRISCV64Thread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2015, Red Hat Inc.
44
* Copyright (c) 2021, Huawei Technologies Co., Ltd. All rights reserved.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -75,11 +75,11 @@ public String toString() {
7575
}
7676

7777
public boolean equals(Object obj) {
78-
if ((obj == null) || !(obj instanceof ProcRISCV64Thread)) {
78+
if (!(obj instanceof ProcRISCV64Thread other)) {
7979
return false;
8080
}
8181

82-
return (((ProcRISCV64Thread) obj).id == id);
82+
return (other.id == id);
8383
}
8484

8585
public int hashCode() {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/proc/x86/ProcX86Thread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -78,11 +78,11 @@ public String toString() {
7878
}
7979

8080
public boolean equals(Object obj) {
81-
if ((obj == null) || !(obj instanceof ProcX86Thread)) {
81+
if (!(obj instanceof ProcX86Thread other)) {
8282
return false;
8383
}
8484

85-
return (((ProcX86Thread) obj).id == id);
85+
return (other.id == id);
8686
}
8787

8888
public int hashCode() {

0 commit comments

Comments
 (0)