提交 da8af369 编写于 作者: M mchung

7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo

Reviewed-by: alanb, sla, egahlin
上级 40192a8b
...@@ -27,7 +27,7 @@ package java.lang.management; ...@@ -27,7 +27,7 @@ package java.lang.management;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import java.util.concurrent.locks.*; import java.util.concurrent.locks.*;
import java.beans.ConstructorProperties; import sun.management.LockInfoCompositeData;
/** /**
* Information about a <em>lock</em>. A lock can be a built-in object monitor, * Information about a <em>lock</em>. A lock can be a built-in object monitor,
...@@ -44,8 +44,7 @@ import java.beans.ConstructorProperties; ...@@ -44,8 +44,7 @@ import java.beans.ConstructorProperties;
* *
* <h4><a name="MappedType">MXBean Mapping</a></h4> * <h4><a name="MappedType">MXBean Mapping</a></h4>
* <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData} * <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData}
* as specified in the <a href="../../../javax/management/MXBean.html#mapping-rules"> * as specified in the {@link #from from} method.
* type mapping rules</a> of {@linkplain javax.management.MXBean MXBeans}.
* *
* @see java.util.concurrent.locks.AbstractOwnableSynchronizer * @see java.util.concurrent.locks.AbstractOwnableSynchronizer
* @see java.util.concurrent.locks.Condition * @see java.util.concurrent.locks.Condition
...@@ -66,7 +65,6 @@ public class LockInfo { ...@@ -66,7 +65,6 @@ public class LockInfo {
* @param identityHashCode the {@link System#identityHashCode * @param identityHashCode the {@link System#identityHashCode
* identity hash code} of the lock object. * identity hash code} of the lock object.
*/ */
@ConstructorProperties({"className", "identityHashCode"})
public LockInfo(String className, int identityHashCode) { public LockInfo(String className, int identityHashCode) {
if (className == null) { if (className == null) {
throw new NullPointerException("Parameter className cannot be null"); throw new NullPointerException("Parameter className cannot be null");
...@@ -102,6 +100,50 @@ public class LockInfo { ...@@ -102,6 +100,50 @@ public class LockInfo {
return identityHashCode; return identityHashCode;
} }
/**
* Returns a {@code LockInfo} object represented by the
* given {@code CompositeData}.
* The given {@code CompositeData} must contain the following attributes:
* <blockquote>
* <table border>
* <tr>
* <th align=left>Attribute Name</th>
* <th align=left>Type</th>
* </tr>
* <tr>
* <td>className</td>
* <td><tt>java.lang.String</tt></td>
* </tr>
* <tr>
* <td>identityHashCode</td>
* <td><tt>java.lang.Integer</tt></td>
* </tr>
* </table>
* </blockquote>
*
* @param cd {@code CompositeData} representing a {@code LockInfo}
*
* @throws IllegalArgumentException if {@code cd} does not
* represent a {@code LockInfo} with the attributes described
* above.
* @return a {@code LockInfo} object represented
* by {@code cd} if {@code cd} is not {@code null};
* {@code null} otherwise.
*
* @since 1.8
*/
public static LockInfo from(CompositeData cd) {
if (cd == null) {
return null;
}
if (cd instanceof LockInfoCompositeData) {
return ((LockInfoCompositeData) cd).getLockInfo();
} else {
return LockInfoCompositeData.toLockInfo(cd);
}
}
/** /**
* Returns a string representation of a lock. The returned * Returns a string representation of a lock. The returned
* string representation consists of the name of the class of the * string representation consists of the name of the class of the
......
...@@ -696,9 +696,7 @@ public class ThreadInfo { ...@@ -696,9 +696,7 @@ public class ThreadInfo {
* <td>lockInfo</td> * <td>lockInfo</td>
* <td><tt>javax.management.openmbean.CompositeData</tt> * <td><tt>javax.management.openmbean.CompositeData</tt>
* - the mapped type for {@link LockInfo} as specified in the * - the mapped type for {@link LockInfo} as specified in the
* <a href="../../../javax/management/MXBean.html#mapping-rules"> * {@link LockInfo#from} method.
* type mapping rules</a> of
* {@linkplain javax.management.MXBean MXBeans}.
* <p> * <p>
* If <tt>cd</tt> does not contain this attribute, * If <tt>cd</tt> does not contain this attribute,
* the <tt>LockInfo</tt> object will be constructed from * the <tt>LockInfo</tt> object will be constructed from
...@@ -766,10 +764,7 @@ public class ThreadInfo { ...@@ -766,10 +764,7 @@ public class ThreadInfo {
* <td>lockedSynchronizers</td> * <td>lockedSynchronizers</td>
* <td><tt>javax.management.openmbean.CompositeData[]</tt> * <td><tt>javax.management.openmbean.CompositeData[]</tt>
* whose element type is the mapped type for * whose element type is the mapped type for
* {@link LockInfo} as specified in the * {@link LockInfo} as specified in the {@link LockInfo#from} method.
* <a href="../../../javax/management/MXBean.html#mapping-rules">
* type mapping rules</a> of
* {@linkplain javax.management.MXBean MXBeans}.
* <p> * <p>
* If <tt>cd</tt> does not contain this attribute, * If <tt>cd</tt> does not contain this attribute,
* this attribute will be set to an empty array. </td> * this attribute will be set to an empty array. </td>
...@@ -830,7 +825,6 @@ public class ThreadInfo { ...@@ -830,7 +825,6 @@ public class ThreadInfo {
* @since 1.6 * @since 1.6
*/ */
public LockInfo[] getLockedSynchronizers() { public LockInfo[] getLockedSynchronizers() {
// represents an <a href="LockInfo.html#OwnableSynchronizer">
return lockedSynchronizers; return lockedSynchronizers;
} }
......
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management;
import java.lang.management.LockInfo;
/**
* This interface is used for data conversion from LockInfo
* to CompositeData (its mapped type) or vice versa.
*/
public interface LockDataConverterMXBean {
public void setLockInfo(LockInfo l);
public LockInfo getLockInfo();
public void setLockedSynchronizers(LockInfo[] l);
public LockInfo[] getLockedSynchronizers();
}
/* /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,86 +26,93 @@ ...@@ -26,86 +26,93 @@
package sun.management; package sun.management;
import java.lang.management.LockInfo; import java.lang.management.LockInfo;
import java.lang.management.ThreadInfo; import javax.management.openmbean.CompositeType;
import javax.management.Attribute;
import javax.management.StandardMBean;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;
/** /**
* This MXBean is used for data conversion from LockInfo * A CompositeData for LockInfo for the local management support.
* to CompositeData (its mapped type) or vice versa. * This class avoids the performance penalty paid to the
* construction of a CompositeData use in the local case.
*/ */
class LockDataConverter extends StandardMBean public class LockInfoCompositeData extends LazyCompositeData {
implements LockDataConverterMXBean { private final LockInfo lock;
private LockInfo lockInfo;
private LockInfo[] lockedSyncs;
LockDataConverter() {
super(LockDataConverterMXBean.class, true);
this.lockInfo = null;
this.lockedSyncs = null;
}
LockDataConverter(ThreadInfo ti) {
super(LockDataConverterMXBean.class, true);
this.lockInfo = ti.getLockInfo();
this.lockedSyncs = ti.getLockedSynchronizers();
}
public void setLockInfo(LockInfo l) { private LockInfoCompositeData(LockInfo li) {
this.lockInfo = l; this.lock = li;
} }
public LockInfo getLockInfo() { public LockInfo getLockInfo() {
return this.lockInfo; return lock;
} }
public void setLockedSynchronizers(LockInfo[] l) { public static CompositeData toCompositeData(LockInfo li) {
this.lockedSyncs = l; if (li == null) {
} return null;
}
public LockInfo[] getLockedSynchronizers() { LockInfoCompositeData licd = new LockInfoCompositeData(li);
return this.lockedSyncs; return licd.getCompositeData();
} }
// helper methods protected CompositeData getCompositeData() {
CompositeData toLockInfoCompositeData() { // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
// lockInfoItemNames!
final Object[] lockInfoItemValues = {
new String(lock.getClassName()),
new Integer(lock.getIdentityHashCode()),
};
try { try {
return (CompositeData) getAttribute("LockInfo"); return new CompositeDataSupport(lockInfoCompositeType,
} catch (Exception e) { lockInfoItemNames,
throw new AssertionError(e); lockInfoItemValues);
} catch (OpenDataException e) {
// Should never reach here
throw Util.newException(e);
} }
} }
CompositeData[] toLockedSynchronizersCompositeData() { private static final CompositeType lockInfoCompositeType;
static {
try { try {
return (CompositeData[]) getAttribute("LockedSynchronizers"); lockInfoCompositeType = (CompositeType)
} catch (Exception e) { MappedMXBeanType.toOpenType(LockInfo.class);
throw new AssertionError(e); } catch (OpenDataException e) {
// Should never reach here
throw Util.newException(e);
} }
} }
LockInfo toLockInfo(CompositeData cd) { static CompositeType getLockInfoCompositeType() {
try { return lockInfoCompositeType;
setAttribute(new Attribute("LockInfo", cd));
} catch (Exception e) {
throw new AssertionError(e);
}
return getLockInfo();
} }
LockInfo[] toLockedSynchronizers(CompositeData[] cd) { private static final String CLASS_NAME = "className";
try { private static final String IDENTITY_HASH_CODE = "identityHashCode";
setAttribute(new Attribute("LockedSynchronizers", cd)); private static final String[] lockInfoItemNames = {
} catch (Exception e) { CLASS_NAME,
throw new AssertionError(e); IDENTITY_HASH_CODE,
};
/*
* Returns a LockInfo object mapped from the given CompositeData.
*/
public static LockInfo toLockInfo(CompositeData cd) {
if (cd == null) {
throw new NullPointerException("Null CompositeData");
} }
return getLockedSynchronizers();
}
static CompositeData toLockInfoCompositeData(LockInfo l) { if (!isTypeMatched(lockInfoCompositeType, cd.getCompositeType())) {
LockDataConverter ldc = new LockDataConverter(); throw new IllegalArgumentException(
ldc.setLockInfo(l); "Unexpected composite type for LockInfo");
return ldc.toLockInfoCompositeData(); }
String className = getString(cd, CLASS_NAME);
int identityHashCode = getInt(cd, IDENTITY_HASH_CODE);
return new LockInfo(className, identityHashCode);
} }
private static final long serialVersionUID = -6374759159749014052L;
} }
...@@ -703,7 +703,7 @@ public abstract class MappedMXBeanType { ...@@ -703,7 +703,7 @@ public abstract class MappedMXBeanType {
if (data instanceof java.lang.management.MonitorInfo) { if (data instanceof java.lang.management.MonitorInfo) {
return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data); return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data);
} }
return LockDataConverter.toLockInfoCompositeData((LockInfo) data); return LockInfoCompositeData.toCompositeData((LockInfo) data);
} }
if (data instanceof MemoryNotificationInfo) { if (data instanceof MemoryNotificationInfo) {
......
...@@ -59,7 +59,7 @@ public class MonitorInfoCompositeData extends LazyCompositeData { ...@@ -59,7 +59,7 @@ public class MonitorInfoCompositeData extends LazyCompositeData {
int len = monitorInfoItemNames.length; int len = monitorInfoItemNames.length;
Object[] values = new Object[len]; Object[] values = new Object[len];
CompositeData li = LockDataConverter.toLockInfoCompositeData(lock); CompositeData li = LockInfoCompositeData.toCompositeData(lock);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
String item = monitorInfoItemNames[i]; String item = monitorInfoItemNames[i];
......
...@@ -85,11 +85,18 @@ public class ThreadInfoCompositeData extends LazyCompositeData { ...@@ -85,11 +85,18 @@ public class ThreadInfoCompositeData extends LazyCompositeData {
} }
// Convert MonitorInfo[] and LockInfo[] to CompositeData[] // Convert MonitorInfo[] and LockInfo[] to CompositeData[]
LockDataConverter converter = new LockDataConverter(threadInfo); CompositeData lockInfoData =
CompositeData lockInfoData = converter.toLockInfoCompositeData(); LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
CompositeData[] lockedSyncsData = converter.toLockedSynchronizersCompositeData();
// Convert LockInfo[] and MonitorInfo[] to CompositeData[]
LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
CompositeData[] lockedSyncsData =
new CompositeData[lockedSyncs.length];
for (int i = 0; i < lockedSyncs.length; i++) {
LockInfo li = lockedSyncs[i];
lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
}
// Convert MonitorInfo[] to CompositeData[]
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
CompositeData[] lockedMonitorsData = CompositeData[] lockedMonitorsData =
new CompositeData[lockedMonitors.length]; new CompositeData[lockedMonitors.length];
...@@ -98,7 +105,6 @@ public class ThreadInfoCompositeData extends LazyCompositeData { ...@@ -98,7 +105,6 @@ public class ThreadInfoCompositeData extends LazyCompositeData {
lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi); lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
} }
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
// threadInfoItemNames! // threadInfoItemNames!
final Object[] threadInfoItemValues = { final Object[] threadInfoItemValues = {
...@@ -216,11 +222,11 @@ public class ThreadInfoCompositeData extends LazyCompositeData { ...@@ -216,11 +222,11 @@ public class ThreadInfoCompositeData extends LazyCompositeData {
// with it. So we can get the CompositeType representing LockInfo // with it. So we can get the CompositeType representing LockInfo
// from a mapped CompositeData for any LockInfo object. // from a mapped CompositeData for any LockInfo object.
// Thus we construct a random LockInfo object and pass it // Thus we construct a random LockInfo object and pass it
// to LockDataConverter to do the conversion. // to LockInfoCompositeData to do the conversion.
Object o = new Object(); Object o = new Object();
LockInfo li = new LockInfo(o.getClass().getName(), LockInfo li = new LockInfo(o.getClass().getName(),
System.identityHashCode(o)); System.identityHashCode(o));
CompositeData cd = LockDataConverter.toLockInfoCompositeData(li); CompositeData cd = LockInfoCompositeData.toCompositeData(li);
lockInfoCompositeType = cd.getCompositeType(); lockInfoCompositeType = cd.getCompositeType();
} }
...@@ -315,9 +321,8 @@ public class ThreadInfoCompositeData extends LazyCompositeData { ...@@ -315,9 +321,8 @@ public class ThreadInfoCompositeData extends LazyCompositeData {
// 6.0 new attributes // 6.0 new attributes
public LockInfo lockInfo() { public LockInfo lockInfo() {
LockDataConverter converter = new LockDataConverter();
CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO); CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO);
return converter.toLockInfo(lockInfoData); return LockInfo.from(lockInfoData);
} }
public MonitorInfo[] lockedMonitors() { public MonitorInfo[] lockedMonitors() {
...@@ -336,13 +341,17 @@ public class ThreadInfoCompositeData extends LazyCompositeData { ...@@ -336,13 +341,17 @@ public class ThreadInfoCompositeData extends LazyCompositeData {
} }
public LockInfo[] lockedSynchronizers() { public LockInfo[] lockedSynchronizers() {
LockDataConverter converter = new LockDataConverter();
CompositeData[] lockedSyncsData = CompositeData[] lockedSyncsData =
(CompositeData[]) cdata.get(LOCKED_SYNCS); (CompositeData[]) cdata.get(LOCKED_SYNCS);
// The LockedSynchronizers item cannot be null, but if it is we will // The LockedSynchronizers item cannot be null, but if it is we will
// get a NullPointerException when we ask for its length. // get a NullPointerException when we ask for its length.
return converter.toLockedSynchronizers(lockedSyncsData); LockInfo[] locks = new LockInfo[lockedSyncsData.length];
for (int i = 0; i < lockedSyncsData.length; i++) {
CompositeData cdi = lockedSyncsData[i];
locks[i] = LockInfo.from(cdi);
}
return locks;
} }
/** Validate if the input CompositeData has the expected /** Validate if the input CompositeData has the expected
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 5086470 6358247 * @bug 5086470 6358247 7193302
* @summary Test type conversion when invoking ThreadMXBean.dumpAllThreads * @summary Test type conversion when invoking ThreadMXBean.dumpAllThreads
* through proxy. * through proxy.
* *
...@@ -173,6 +173,10 @@ public class ThreadMXBeanProxy { ...@@ -173,6 +173,10 @@ public class ThreadMXBeanProxy {
throw new RuntimeException("LockInfo: " + syncs[0] + throw new RuntimeException("LockInfo: " + syncs[0] +
" IdentityHashCode not matched. Expected: " + hcode); " IdentityHashCode not matched. Expected: " + hcode);
} }
LockInfo li = info.getLockInfo();
if (li == null) {
throw new RuntimeException("Expected non-null LockInfo");
}
} }
} }
static class Mutex implements Lock, java.io.Serializable { static class Mutex implements Lock, java.io.Serializable {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册