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.util.*;
2N/Aimport java.io.*;
2N/Aimport java.beans.*;
2N/A
2N/A/**
2N/A * An error encountered in the native DTrace library while tracing probe
2N/A * data. Each of the fault name constants beginning with {@code
2N/A * DTRACEFLT_} identifies a specific fault with a name that is
2N/A * guaranteed not to change across API versions.
2N/A * <p>
2N/A * Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
2N/A *
2N/A * @see ConsumerListener#errorEncountered(ErrorEvent e)
2N/A *
2N/A * @author Tom Erickson
2N/A */
2N/Apublic final class Error implements Serializable {
2N/A static final long serialVersionUID = 5069931629562700614L;
2N/A
2N/A /**
2N/A * Invalid address.
2N/A */
2N/A public static final String DTRACEFLT_BADADDR = "DTRACEFLT_BADADDR";
2N/A /**
2N/A * Invalid alignment.
2N/A */
2N/A public static final String DTRACEFLT_BADALIGN = "DTRACEFLT_BADALIGN";
2N/A /**
2N/A * Illegal operation.
2N/A */
2N/A public static final String DTRACEFLT_ILLOP = "DTRACEFLT_ILLOP";
2N/A /**
2N/A * Divide-by-zero.
2N/A */
2N/A public static final String DTRACEFLT_DIVZERO = "DTRACEFLT_DIVZERO";
2N/A /**
2N/A * Out of scratch space.
2N/A */
2N/A public static final String DTRACEFLT_NOSCRATCH = "DTRACEFLT_NOSCRATCH";
2N/A /**
2N/A * Invalid kernel access.
2N/A */
2N/A public static final String DTRACEFLT_KPRIV = "DTRACEFLT_KPRIV";
2N/A /**
2N/A * Invalid user access.
2N/A */
2N/A public static final String DTRACEFLT_UPRIV = "DTRACEFLT_UPRIV";
2N/A /**
2N/A * Tuple stack overflow.
2N/A */
2N/A public static final String DTRACEFLT_TUPOFLOW = "DTRACEFLT_TUPOFLOW";
2N/A /**
2N/A * Library-level fault.
2N/A */
2N/A public static final String DTRACEFLT_LIBRARY = "DTRACEFLT_LIBRARY";
2N/A
2N/A static {
2N/A try {
2N/A BeanInfo info = Introspector.getBeanInfo(Error.class);
2N/A PersistenceDelegate persistenceDelegate =
2N/A new DefaultPersistenceDelegate(
2N/A new String[] {"probeDescription",
2N/A "enabledProbeID", "CPU", "action", "offset",
2N/A "fault", "address", "defaultMessage"});
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 /** @serial */
2N/A private final ProbeDescription probeDescription;
2N/A /** @serial */
2N/A private final int epid;
2N/A /** @serial */
2N/A private final int cpu;
2N/A /** @serial */
2N/A private final int action;
2N/A /** @serial */
2N/A private final int offset;
2N/A /** @serial */
2N/A private final String fault;
2N/A /** @serial */
2N/A private final long address;
2N/A /** @serial */
2N/A private final String defaultMessage;
2N/A
2N/A /**
2N/A * Creates a DTrace error with the given properties. Supports XML
2N/A * persistence.
2N/A *
2N/A * @param pdesc probe description that identifies the error-inducing
2N/A * probe among all the probes on the system
2N/A * @param enabledProbeID identifies the error-inducing probe among
2N/A * all probes enabled by the same {@link Consumer}
2N/A * @param errorCPU non-negative ID of the CPU where the error was
2N/A * encountered, or a negative number if the CPU is unknown
2N/A * @param errorAction integer that identifies the error-inducing
2N/A * action as the nth action (starting at one) in the error-inducing
2N/A * probe, or zero if the error is in the predicate rather than in an
2N/A * action
2N/A * @param errorOffset error offset in compiled DTrace Intermediate
2N/A * Format (DIF), or a negative number if the offset is not available
2N/A * @param faultName name of the specific fault, or {@code null}
2N/A * if the fault is unknown to the Java DTrace API
2N/A * @param faultAddress address of fault, or -1 if address is not
2N/A * applicable to the specific fault
2N/A * @param errorMessage default message from the native DTrace
2N/A * library preconstructed from the properties of this error
2N/A * @throws NullPointerException if the given probe description or
2N/A * default message is {@code null}
2N/A */
2N/A public
2N/A Error(ProbeDescription pdesc, int enabledProbeID, int errorCPU,
2N/A int errorAction, int errorOffset, String faultName,
2N/A long faultAddress, String errorMessage)
2N/A {
2N/A probeDescription = pdesc;
2N/A epid = enabledProbeID;
2N/A cpu = errorCPU;
2N/A action = errorAction;
2N/A offset = errorOffset;
2N/A fault = faultName;
2N/A address = faultAddress;
2N/A defaultMessage = errorMessage;
2N/A validate();
2N/A }
2N/A
2N/A private final void
2N/A validate()
2N/A {
2N/A if (probeDescription == null) {
2N/A throw new NullPointerException(
2N/A "enabled probe description is null");
2N/A }
2N/A if (defaultMessage == null) {
2N/A throw new NullPointerException("default message is null");
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Gets the probe description that identifies the error-inducing
2N/A * probe among all the probes on the system.
2N/A *
2N/A * @return non-null probe description
2N/A */
2N/A public ProbeDescription
2N/A getProbeDescription()
2N/A {
2N/A return probeDescription;
2N/A }
2N/A
2N/A /**
2N/A * Gets the enabled probe ID. The "epid" is different from {@link
2N/A * ProbeDescription#getID()} because it identifies a probe among all
2N/A * the probes enabled by a {@link Consumer}, rather than among all
2N/A * the probes on the system.
2N/A *
2N/A * @return the enabled probe ID
2N/A */
2N/A public int
2N/A getEnabledProbeID()
2N/A {
2N/A return epid;
2N/A }
2N/A
2N/A /**
2N/A * Gets the CPU that encountered the error.
2N/A *
2N/A * @return non-negative CPU ID, or a negative number if the CPU is
2N/A * unknown
2N/A */
2N/A public int
2N/A getCPU()
2N/A {
2N/A return cpu;
2N/A }
2N/A
2N/A /**
2N/A * Gets the error-inducing action as the <i>nth</i> action (starting
2N/A * at one) in the error-inducing probe, or zero if the error is in
2N/A * the predicate rather than in an action. Note that some actions
2N/A * in a D program consist of multiple actions internally within the
2N/A * DTrace library.
2N/A *
2N/A * @return zero if the error is in the probe predicate, otherwise
2N/A * the <i>nth</i> action (<i>n</i> starting at one) from the start
2N/A * of the probe that induced the error
2N/A */
2N/A public int
2N/A getAction()
2N/A {
2N/A return action;
2N/A }
2N/A
2N/A /**
2N/A * Gets the error offset in compiled DTrace Intermediate Format
2N/A * (DIF), or a negative number if the offset is not available.
2N/A *
2N/A * @return the error offset in compiled DTrace Intermediate Format
2N/A * (DIF), or a negative number if the offset is not available
2N/A */
2N/A public int
2N/A getOffset()
2N/A {
2N/A return offset;
2N/A }
2N/A
2N/A /**
2N/A * Gets the name identifying the specific fault. The names are
2N/A * guaranteed not to change across API versions as long as the fault
2N/A * cases they identify still exist.
2N/A *
2N/A * @return name of the specific fault or {@code null} if the
2N/A * fault is unknown to the Java DTrace API
2N/A */
2N/A public String
2N/A getFault()
2N/A {
2N/A return fault;
2N/A }
2N/A
2N/A /**
2N/A * Gets the address of the fault, if any.
2N/A *
2N/A * @return address of fault, or -1 if address is not applicable to
2N/A * the specific fault (the fault is not one of {@link
2N/A * #DTRACEFLT_BADADDR} or {@link #DTRACEFLT_BADALIGN})
2N/A */
2N/A public long
2N/A getAddress()
2N/A {
2N/A return address;
2N/A }
2N/A
2N/A /**
2N/A * Gets the default message from the native DTrace library
2N/A * preconstructed from the properties of this error.
2N/A *
2N/A * @return non-null preconstructed message
2N/A */
2N/A public String
2N/A getDefaultMessage()
2N/A {
2N/A return defaultMessage;
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 class 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 a string representation of this error useful for logging and
2N/A * not intended for display. The exact details of the
2N/A * representation are unspecified and subject to change, but the
2N/A * following format may be regarded as typical:
2N/A * <pre><code>
2N/A * class-name[property1 = value1, property2 = value2]
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(Error.class.getName());
2N/A buf.append("[probeDescription = ");
2N/A buf.append(probeDescription);
2N/A buf.append(", epid = ");
2N/A buf.append(epid);
2N/A buf.append(", cpu = ");
2N/A buf.append(cpu);
2N/A buf.append(", action = ");
2N/A buf.append(action);
2N/A buf.append(", offset = ");
2N/A buf.append(offset);
2N/A buf.append(", fault = ");
2N/A buf.append(fault);
2N/A buf.append(", address = ");
2N/A buf.append(address);
2N/A buf.append(", defaultMessage = ");
2N/A buf.append(defaultMessage);
2N/A buf.append(']');
2N/A return buf.toString();
2N/A }
2N/A}