1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
30
30
import sun .jvm .hotspot .oops .*;
31
31
32
32
public class ConcurrentLocksPrinter {
33
- private Map <JavaThread , List <Oop >> locksMap = new HashMap <>();
33
+ private final Map <JavaThread , List <Oop >> locksMap = new HashMap <>();
34
34
35
35
public ConcurrentLocksPrinter () {
36
36
fillLocks ();
@@ -42,8 +42,7 @@ public void print(JavaThread jthread, PrintStream tty) {
42
42
if (locks == null || locks .isEmpty ()) {
43
43
tty .println (" - None" );
44
44
} else {
45
- for (Iterator <Oop > itr = locks .iterator (); itr .hasNext ();) {
46
- Oop oop = itr .next ();
45
+ for (Oop oop : locks ) {
47
46
tty .println (" - <" + oop .getHandle () + ">, (a " +
48
47
oop .getKlass ().getName ().asString () + ")" );
49
48
}
@@ -71,12 +70,8 @@ private void fillLocks() {
71
70
public boolean doObj (Oop oop ) {
72
71
JavaThread thread = getOwnerThread (oop );
73
72
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 );
80
75
}
81
76
return false ;
82
77
}
1 commit comments
openjdk-notifier[bot] commentedon Mar 2, 2023
Review
Issues