2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A *
2N/A * ident "%Z%%M% %I% %E% SMI"
2N/A */
2N/Apackage org.opensolaris.os.dtrace;
2N/A
2N/Aimport java.io.*;
2N/Aimport java.beans.*;
2N/A
2N/A/**
2N/A * Triplet of attributes consisting of two stability levels and a
2N/A * dependency class. Attributes may vary independently. They use
2N/A * labels described in the {@code attributes(5)} man page to help set
2N/A * expectations for what kinds of changes might occur in different kinds
2N/A * of future releases. The D compiler includes features to dynamically
2N/A * compute the stability levels of D programs you create. For more
2N/A * information, refer to the <a
2N/A * href=http://docs.sun.com/app/docs/doc/817-6223/6mlkidlnp?a=view>
2N/A * <b>Stability</b></a> chapter of the <i>Solaris Dynamic Tracing
2N/A * Guide</i>.
2N/A * <p>
2N/A * Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
2N/A *
2N/A * @see Consumer#getProgramInfo(Program program)
2N/A * @see Consumer#enable(Program program)
2N/A * @see Consumer#listProbes(ProbeDescription filter)
2N/A * @see Consumer#listProgramProbes(Program program)
2N/A *
2N/A * @author Tom Erickson
2N/A */
2N/Apublic final class InterfaceAttributes implements Serializable {
2N/A static final long serialVersionUID = -2814012588381562694L;
2N/A
2N/A static {
2N/A try {
2N/A BeanInfo info = Introspector.getBeanInfo(InterfaceAttributes.class);
2N/A PersistenceDelegate persistenceDelegate =
2N/A new DefaultPersistenceDelegate(
2N/A new String[] {"nameStability", "dataStability",
2N/A "dependencyClass" })
2N/A {
2N/A /*
2N/A * Need to prevent DefaultPersistenceDelegate from using
2N/A * overridden equals() method, resulting in a
2N/A * StackOverFlowError. Revert to PersistenceDelegate
2N/A * implementation. See
2N/A * http://forum.java.sun.com/thread.jspa?threadID=
2N/A * 477019&tstart=135
2N/A */
2N/A protected boolean
2N/A mutatesTo(Object oldInstance, Object newInstance)
2N/A {
2N/A return (newInstance != null && oldInstance != null &&
2N/A oldInstance.getClass() == newInstance.getClass());
2N/A }
2N/A
2N/A protected Expression
2N/A instantiate(Object oldInstance, Encoder out)
2N/A {
2N/A InterfaceAttributes attr = (InterfaceAttributes)
2N/A oldInstance;
2N/A return new Expression(oldInstance, oldInstance.getClass(),
2N/A "new", new Object[] {
2N/A attr.getNameStability().name(),
2N/A attr.getDataStability().name(),
2N/A attr.getDependencyClass().name() });
2N/A }
2N/A };
2N/A BeanDescriptor d = info.getBeanDescriptor();
2N/A d.setValue("persistenceDelegate", persistenceDelegate);
2N/A } catch (IntrospectionException e) {
2N/A e.printStackTrace();
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Interface stability level. Assists developers in making risk
2N/A * assessments when developing scripts and tools based on DTrace by
2N/A * indicating how likely an interface or DTrace entity is to change
2N/A * in a future release or patch.
2N/A */
2N/A public enum Stability {
2N/A /**
2N/A * The interface is private to DTrace itself and represents an
2N/A * implementation detail of DTrace. Internal interfaces might
2N/A * change in minor or micro releases.
2N/A */
2N/A INTERNAL("Internal"),
2N/A /**
2N/A * The interface is private to Sun and represents an interface
2N/A * developed for use by other Sun products that is not yet
2N/A * publicly documented for use by customers and ISVs. Private
2N/A * interfaces might change in minor or micro releases.
2N/A */
2N/A PRIVATE("Private"),
2N/A /**
2N/A * The interface is supported in the current release but is
2N/A * scheduled to be removed, most likely in a future minor
2N/A * release. When support of an interface is to be discontinued,
2N/A * Sun will attempt to provide notification before discontinuing
2N/A * the interface. The D compiler might produce warning messages
2N/A * if you attempt to use an Obsolete interface.
2N/A */
2N/A OBSOLETE("Obsolete"),
2N/A /**
2N/A * The interface is controlled by an entity other than Sun. At
2N/A * Sun's discretion, Sun can deliver updated and possibly
2N/A * incompatible versions as part of any release, subject to
2N/A * their availability from the controlling entity. Sun makes no
2N/A * claims regarding either the source or binary compatibility
2N/A * for External interfaces between two releases. Applications
2N/A * based on these interfaces might not work in future releases,
2N/A * including patches that contain External interfaces.
2N/A */
2N/A EXTERNAL("External"),
2N/A /**
2N/A * The interface is provided to give developers early access to
2N/A * new or rapidly changing technology or to an implementation
2N/A * artifact that is essential for observing or debugging system
2N/A * behavior for which a more stable solution is anticipated in
2N/A * the future. Sun makes no claims about either source of
2N/A * binary compatibility for Unstable interfaces from one minor
2N/A * release to another.
2N/A */
2N/A UNSTABLE("Unstable"),
2N/A /**
2N/A * The interface might eventually become Standard or Stable but
2N/A * is still in transition. Sun will make reasonable efforts to
2N/A * ensure compatibility with previous releases as it eveolves.
2N/A * When non-upward compatible changes become necessary, they
2N/A * will occur in minor and major releases. These changes will
2N/A * be avoided in micro releases whenever possible. If such a
2N/A * change is necessary, it will be documented in the release
2N/A * notes for the affected release, and when feasible, Sun will
2N/A * provide migration aids for binary compatibility and continued
2N/A * D program development.
2N/A */
2N/A EVOLVING("Evolving"),
2N/A /**
2N/A * The interface is a mature interface under Sun's control. Sun
2N/A * will try to avoid non-upward-compatible changes to these
2N/A * interfaces, especially in minor or micro releases. If
2N/A * support of a Stable interface must be discontinued, Sun will
2N/A * attempt to provide notification and the stability level
2N/A * changes to Obsolete.
2N/A */
2N/A STABLE("Stable"),
2N/A /**
2N/A * The interface complies with an industry standard. The
2N/A * corresponding documentation for the interface will describe
2N/A * the standard to which the interface conforms. Standards are
2N/A * typically controlled by a standards development organization,
2N/A * and changes can be made to the interface in accordance with
2N/A * approved changes to the standard. This stability level can
2N/A * also apply to interfaces that have been adopted (without a
2N/A * formal standard) by an industry convention. Support is
2N/A * provided for only the specified versions of a standard;
2N/A * support for later versions is not guaranteed. If the
2N/A * standards development organization approves a
2N/A * non-upward-compatible change to a Standard interface that Sun
2N/A * decides to support, Sun will announce a compatibility and
2N/A * migration strategy.
2N/A */
2N/A STANDARD("Standard");
2N/A
2N/A private String s;
2N/A
2N/A private
2N/A Stability(String displayName)
2N/A {
2N/A s = displayName;
2N/A }
2N/A
2N/A /**
2N/A * Overridden to get the default display value. To
2N/A * internationalize the display value, use {@link
2N/A * java.lang.Enum#name()} instead as a lookup key.
2N/A */
2N/A @Override
2N/A public String
2N/A toString()
2N/A {
2N/A return s;
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Architectural dependency class. Tells whether an interface is
2N/A * common to all Solaris platforms and processors, or whether the
2N/A * interface is associated with a particular architecture such as
2N/A * SPARC processors only.
2N/A */
2N/A public enum DependencyClass {
2N/A // Note that the compareTo() method depends on the order in
2N/A // which the instances are instantiated
2N/A
2N/A /**
2N/A * The interface has an unknown set of architectural dependencies.
2N/A * DTrace does not necessarily know the architectural dependencies of
2N/A * all entities, such as data types defined in the operating system
2N/A * implementation. The Unknown label is typically applied to interfaces
2N/A * of very low stability for which dependencies cannot be computed. The
2N/A * interface might not be available when using DTrace on <i>any</i>
2N/A * architecture other than the one you are currently using.
2N/A */
2N/A UNKNOWN("Unknown"),
2N/A /**
2N/A * The interface is specific to the CPU model of the current
2N/A * system. You can use the {@code psrinfo(1M)} utility's {@code
2N/A * -v} option to display the current CPU model and
2N/A * implementation names. Interfaces with CPU model dependencies
2N/A * might not be available on other CPU implementations, even if
2N/A * those CPUs export the same instruction set architecture
2N/A * (ISA). For example, a CPU-dependent interface on an
2N/A * UltraSPARC-III+ microprocessor might not be available on an
2N/A * UltraSPARC-II microprocessor, even though both processors
2N/A * support the SPARC instruction set.
2N/A */
2N/A CPU("CPU"),
2N/A /**
2N/A * The interface is specific to the hardware platform of the current
2N/A * system. A platform typically associates a set of system components
2N/A * and architectural characteristics such as a set of supported CPU
2N/A * models with a system name such as <code>SUNW,
2N/A * Ultra-Enterprise-10000</code>. You can display the current
2N/A * platform name using the {@code uname(1)} {@code -i} option.
2N/A * The interface might not be available on other hardware
2N/A * platforms.
2N/A */
2N/A PLATFORM("Platform"),
2N/A /**
2N/A * The interface is specific to the hardware platform group of the
2N/A * current system. A platform group typically associates a set of
2N/A * platforms with related characteristics together under a single name,
2N/A * such as {@code sun4u}. You can display the current platform
2N/A * group name using the {@code uname(1)} {@code -m} option. The
2N/A * interface is available on other platforms in the platform
2N/A * group, but might not be available on hardware platforms that
2N/A * are not members of the group.
2N/A */
2N/A GROUP("Group"),
2N/A /**
2N/A * The interface is specific to the instruction set architecture (ISA)
2N/A * supported by the microprocessor on this system. The ISA describes a
2N/A * specification for software that can be executed on the
2N/A * microprocessor, including details such as assembly language
2N/A * instructions and registers. You can display the native
2N/A * instruction sets supported by the system using the {@code
2N/A * isainfo(1)} utility. The interface might not be supported on
2N/A * systems that do not export any of of the same instruction
2N/A * sets. For example, an ISA-dependent interface on a Solaris
2N/A * SPARC system might not be supported on a Solaris x86 system.
2N/A */
2N/A ISA("ISA"),
2N/A /**
2N/A * The interface is common to all Solaris systems regardless of the
2N/A * underlying hardware. DTrace programs and layered applications that
2N/A * depend only on Common interfaces can be executed and deployed on
2N/A * other Solaris systems with the same Solaris and DTrace revisions.
2N/A * The majority of DTrace interfaces are Common, so you can use them
2N/A * wherever you use Solaris.
2N/A */
2N/A COMMON("Common");
2N/A
2N/A private String s;
2N/A
2N/A private
2N/A DependencyClass(String displayString)
2N/A {
2N/A s = displayString;
2N/A }
2N/A
2N/A /**
2N/A * Overridden to get the default display value. To
2N/A * internationalize the display value, use {@link
2N/A * java.lang.Enum#name()} instead as a lookup key.
2N/A */
2N/A @Override
2N/A public String
2N/A toString()
2N/A {
2N/A return s;
2N/A }
2N/A }
2N/A
2N/A /** @serial */
2N/A private Stability nameStability;
2N/A /** @serial */
2N/A private Stability dataStability;
2N/A /** @serial */
2N/A private DependencyClass dependencyClass;
2N/A
2N/A /**
2N/A * Called by native code.
2N/A */
2N/A private
2N/A InterfaceAttributes()
2N/A {
2N/A }
2N/A
2N/A /**
2N/A * Creates an interface attribute triplet from the given attributes.
2N/A *
2N/A * @param nameStabilityAttribute the stability level of the
2N/A * interface associated with its name in a D program
2N/A * @param dataStabilityAttribute stability of the data format used
2N/A * by the interface and any associated data semantics
2N/A * @param dependencyClassAttribute describes whether the interface
2N/A * is specific to the current operating platform or microprocessor
2N/A * @throws NullPointerException if any parameter is {@code null}
2N/A */
2N/A public
2N/A InterfaceAttributes(Stability nameStabilityAttribute,
2N/A Stability dataStabilityAttribute,
2N/A DependencyClass dependencyClassAttribute)
2N/A {
2N/A nameStability = nameStabilityAttribute;
2N/A dataStability = dataStabilityAttribute;
2N/A dependencyClass = dependencyClassAttribute;
2N/A validate();
2N/A }
2N/A
2N/A /**
2N/A * Creates an interface attribute triplet from the given attribute
2N/A * names. Supports XML persistence.
2N/A *
2N/A * @throws NullPointerException if any parameter is {@code null}
2N/A * @throws IllegalArgumentException if any parameter fails to match
2N/A * an enumerated stability value
2N/A */
2N/A public
2N/A InterfaceAttributes(String nameStabilityAttributeName,
2N/A String dataStabilityAttributeName,
2N/A String dependencyClassAttributeName)
2N/A {
2N/A this(Enum.valueOf(Stability.class, nameStabilityAttributeName),
2N/A Enum.valueOf(Stability.class, dataStabilityAttributeName),
2N/A Enum.valueOf(DependencyClass.class,
2N/A dependencyClassAttributeName));
2N/A // validate() unnecessary because Enum.valueOf() has already
2N/A // thrown the exception
2N/A }
2N/A
2N/A private final void
2N/A validate()
2N/A {
2N/A if (nameStability == null) {
2N/A throw new NullPointerException("nameStability is null");
2N/A }
2N/A if (dataStability == null) {
2N/A throw new NullPointerException("dataStability is null");
2N/A }
2N/A if (dependencyClass == null) {
2N/A throw new NullPointerException("dependencyClass is null");
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Gets the stabiltiy level of an interface associated with its name
2N/A * as it appears in a D program. For example, the {@code execname}
2N/A * D variable is a {@link Stability#STABLE STABLE} name: Sun
2N/A * guarantees this identifier will continue to be supported in D
2N/A * programs according to the rules described for Stable interfaces.
2N/A *
2N/A * @return the stability level of an interface associated with its
2N/A * name as it appears in a D program
2N/A */
2N/A public Stability
2N/A getNameStability()
2N/A {
2N/A return nameStability;
2N/A }
2N/A
2N/A /**
2N/A * Called by native code.
2N/A */
2N/A private void
2N/A setNameStability(String s)
2N/A {
2N/A nameStability = Enum.valueOf(Stability.class, s);
2N/A }
2N/A
2N/A /**
2N/A * Gets the stability level of the data format used by an interface
2N/A * and any associated data semantics. For example, the {@code pid}
2N/A * D variable is a {@link Stability#STABLE STABLE} interface:
2N/A * process IDs are a stable concept in Solaris, and Sun guarantees
2N/A * that the {@code pid} variable will be of type {@code pid_t} with
2N/A * the semantic that it is set to the process ID corresponding to
2N/A * the thread that fired a given probe in accordance with the rules
2N/A * described for Stable interfaces.
2N/A *
2N/A * @return the stability level of the data format used by an
2N/A * interface and any associated data semantics.
2N/A */
2N/A public Stability
2N/A getDataStability()
2N/A {
2N/A return dataStability;
2N/A }
2N/A
2N/A /**
2N/A * Called by native code.
2N/A */
2N/A private void
2N/A setDataStability(String s)
2N/A {
2N/A dataStability = Enum.valueOf(Stability.class, s);
2N/A }
2N/A
2N/A /**
2N/A * Gets the interface dependency class.
2N/A *
2N/A * @return the dependency class describing whether the interface is
2N/A * specific to the current operating platform or microprocessor
2N/A */
2N/A public DependencyClass
2N/A getDependencyClass()
2N/A {
2N/A return dependencyClass;
2N/A }
2N/A
2N/A /**
2N/A * Called by native code.
2N/A */
2N/A private void
2N/A setDependencyClass(String s)
2N/A {
2N/A dependencyClass = Enum.valueOf(DependencyClass.class, s);
2N/A }
2N/A
2N/A /**
2N/A * Compares the specified object with this attribute triplet for
2N/A * equality. Defines equality as having the same attributes.
2N/A *
2N/A * @return {@code true} if and only if the specified object is also
2N/A * an {@code InterfaceAttributes} instance and has all the same
2N/A * attributes as this instance.
2N/A */
2N/A @Override
2N/A public boolean
2N/A equals(Object o)
2N/A {
2N/A if (o == this) {
2N/A return true;
2N/A }
2N/A if (o instanceof InterfaceAttributes) {
2N/A InterfaceAttributes a = (InterfaceAttributes)o;
2N/A return ((nameStability == a.nameStability) &&
2N/A (dataStability == a.dataStability) &&
2N/A (dependencyClass == a.dependencyClass));
2N/A }
2N/A return false;
2N/A }
2N/A
2N/A /**
2N/A * Overridden to ensure that equal {@code InterfaceAttributes}
2N/A * instances have equal hashcodes.
2N/A */
2N/A @Override
2N/A public int
2N/A hashCode()
2N/A {
2N/A int hash = 17;
2N/A hash = (37 * hash) + nameStability.hashCode();
2N/A hash = (37 * hash) + dataStability.hashCode();
2N/A hash = (37 * hash) + dependencyClass.hashCode();
2N/A return hash;
2N/A }
2N/A
2N/A private void
2N/A readObject(ObjectInputStream s)
2N/A throws IOException, ClassNotFoundException
2N/A {
2N/A s.defaultReadObject();
2N/A // Check constructor invariants
2N/A try {
2N/A validate();
2N/A } catch (Exception e) {
2N/A InvalidObjectException x = new InvalidObjectException(
2N/A e.getMessage());
2N/A x.initCause(e);
2N/A throw x;
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Gets the string representation of this triplet of interface
2N/A * attributes. The format follows the convention described in the
2N/A * <a href=http://docs.sun.com/app/docs/doc/817-6223/6mlkidlnt?a=view>
2N/A * <b>Interface Attributes</b></a> section of the <b>Stability</b>
2N/A * chapter of the <i>Solaris Dynamic Tracing Guide</i>. The
2N/A * attributes appear in the following order, separated by slashes:
2N/A * <pre><code>
2N/A * <i>name-stability / data-stability / dependency-class</i>
2N/A * </code></pre>
2N/A */
2N/A public String
2N/A toString()
2N/A {
2N/A StringBuilder buf = new StringBuilder();
2N/A buf.append(nameStability);
2N/A buf.append(" / ");
2N/A buf.append(dataStability);
2N/A buf.append(" / ");
2N/A buf.append(dependencyClass);
2N/A return buf.toString();
2N/A }
2N/A}