Skip to content

Commit d4dcba0

Browse files
author
Andrey Turbanov
committedMar 2, 2023
8303267: Prefer ArrayList to LinkedList in ConcurrentLocksPrinter
Reviewed-by: cjplummer, sspitsyn
1 parent 2c7d2c0 commit d4dcba0

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed
 

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ConcurrentLocksPrinter.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, 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
@@ -30,7 +30,7 @@
3030
import sun.jvm.hotspot.oops.*;
3131

3232
public class ConcurrentLocksPrinter {
33-
private Map<JavaThread, List<Oop>> locksMap = new HashMap<>();
33+
private final Map<JavaThread, List<Oop>> locksMap = new HashMap<>();
3434

3535
public ConcurrentLocksPrinter() {
3636
fillLocks();
@@ -42,8 +42,7 @@ public void print(JavaThread jthread, PrintStream tty) {
4242
if (locks == null || locks.isEmpty()) {
4343
tty.println(" - None");
4444
} else {
45-
for (Iterator<Oop> itr = locks.iterator(); itr.hasNext();) {
46-
Oop oop = itr.next();
45+
for (Oop oop : locks) {
4746
tty.println(" - <" + oop.getHandle() + ">, (a " +
4847
oop.getKlass().getName().asString() + ")");
4948
}
@@ -71,12 +70,8 @@ private void fillLocks() {
7170
public boolean doObj(Oop oop) {
7271
JavaThread thread = getOwnerThread(oop);
7372
if (thread != null) {
74-
List<Oop> locks = locksMap.get(thread);
75-
if (locks == null) {
76-
locks = new LinkedList<>();
77-
locksMap.put(thread, locks);
78-
}
79-
locks.add(oop);
73+
locksMap.computeIfAbsent(thread, t -> new ArrayList<>())
74+
.add(oop);
8075
}
8176
return false;
8277
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Mar 2, 2023

@openjdk-notifier[bot]
Please sign in to comment.