Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ final Class<?> loadClass(Module module, String name) {
protected Object getClassLoadingLock(String className) {
Object lock = this;
if (parallelLockMap != null) {
Object newLock = new Object();
Object newLock = new String(className);
lock = parallelLockMap.putIfAbsent(className, newLock);
if (lock == null) {
lock = newLock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public class LockInfo {

private String className;
private int identityHashCode;
private String stringValue;

/**
* Constructs a {@code LockInfo} object.
*
* @param className the fully qualified name of the class of the lock object.
* @param identityHashCode the {@link System#identityHashCode
* identity hash code} of the lock object.
* @param stringValue the string value of the lock object.
*/
public LockInfo(String className, int identityHashCode, String stringValue) {
if (className == null) {
throw new NullPointerException("Parameter className cannot be null");
}
this.className = className;
this.identityHashCode = identityHashCode;
this.stringValue = stringValue;
}

/**
* Constructs a {@code LockInfo} object.
Expand All @@ -77,6 +95,7 @@ public LockInfo(String className, int identityHashCode) {
* package-private constructors
*/
LockInfo(Object lock) {
this.stringValue = String.valueOf(lock);
this.className = lock.getClass().getName();
this.identityHashCode = System.identityHashCode(lock);
}
Expand All @@ -90,6 +109,15 @@ public String getClassName() {
return className;
}

/**
* Returns the string value of lock object.
*
* @return the string value of lock object.
*/
public String getStringValue() {
return stringValue;
}

/**
* Returns the identity hash code of the lock object
* returned from the {@link System#identityHashCode} method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,39 @@ public MonitorInfo(String className,
this.stackFrame = stackFrame;
}

/**
* Construct a {@code MonitorInfo} object.
*
* @param className the fully qualified name of the class of the lock object.
* @param identityHashCode the {@link System#identityHashCode
* identity hash code} of the lock object.
* @param stringValue the string value of the lock object.
* @param stackDepth the depth in the stack trace where the object monitor
* was locked.
* @param stackFrame the stack frame that locked the object monitor.
* @throws IllegalArgumentException if
* {@code stackDepth} &ge; 0 but {@code stackFrame} is {@code null},
* or {@code stackDepth} &lt; 0 but {@code stackFrame} is not
* {@code null}.
*/
public MonitorInfo(String className,
int identityHashCode,
String stringValue,
int stackDepth,
StackTraceElement stackFrame) {
super(className, identityHashCode, stringValue);
if (stackDepth >= 0 && stackFrame == null) {
throw new IllegalArgumentException("Parameter stackDepth is " +
stackDepth + " but stackFrame is null");
}
if (stackDepth < 0 && stackFrame != null) {
throw new IllegalArgumentException("Parameter stackDepth is " +
stackDepth + " but stackFrame is not null");
}
this.stackDepth = stackDepth;
this.stackFrame = stackFrame;
}

/**
* Returns the depth in the stack trace where the object monitor
* was locked. The depth is the index to the {@code StackTraceElement}
Expand Down Expand Up @@ -149,10 +182,12 @@ public static MonitorInfo from(CompositeData cd) {
MonitorInfoCompositeData.validateCompositeData(cd);
String className = MonitorInfoCompositeData.getClassName(cd);
int identityHashCode = MonitorInfoCompositeData.getIdentityHashCode(cd);
String stringValue = MonitorInfoCompositeData.getStringValue(cd);
int stackDepth = MonitorInfoCompositeData.getLockedStackDepth(cd);
StackTraceElement stackFrame = MonitorInfoCompositeData.getLockedStackFrame(cd);
return new MonitorInfo(className,
identityHashCode,
stringValue,
stackDepth,
stackFrame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
Object lock = monitors[i];
String className = lock.getClass().getName();
int identityHashCode = System.identityHashCode(lock);
String stringValue = String.valueOf(lock);
int depth = stackDepths[i];
StackTraceElement ste = (depth >= 0 ? stackTrace[depth]
: null);
lockedMonitors[i] = new MonitorInfo(className,
identityHashCode,
stringValue,
depth,
ste);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected CompositeData getCompositeData() {
: null;
// values may be null; can't use Map.of
Map<String,Object> items = new HashMap<>();
items.put(STRING_VALUE, lock.getStringValue());
items.put(CLASS_NAME, lock.getClassName());
items.put(IDENTITY_HASH_CODE, lock.getIdentityHashCode());
items.put(LOCKED_STACK_FRAME, steCData);
Expand All @@ -75,12 +76,14 @@ protected CompositeData getCompositeData() {
}
}

private static final String STRING_VALUE = "stringValue";
private static final String CLASS_NAME = "className";
private static final String IDENTITY_HASH_CODE = "identityHashCode";
private static final String LOCKED_STACK_FRAME = "lockedStackFrame";
private static final String LOCKED_STACK_DEPTH = "lockedStackDepth";

private static final String[] MONITOR_INFO_ATTRIBUTES = {
STRING_VALUE,
CLASS_NAME,
IDENTITY_HASH_CODE,
LOCKED_STACK_FRAME,
Expand Down Expand Up @@ -116,6 +119,10 @@ static CompositeType v6CompositeType() {
return V6_COMPOSITE_TYPE;
}

public static String getStringValue(CompositeData cd) {
return getString(cd, STRING_VALUE);
}

public static String getClassName(CompositeData cd) {
return getString(cd, CLASS_NAME);
}
Expand Down