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 * A value generated by the DTrace {@code mod()}, {@code func()}, or
2N/A * {@code sym()} action used to lookup the symbol associated with a
2N/A * kernel address.
2N/A * <p>
2N/A * Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
2N/A *
2N/A * @author Tom Erickson
2N/A */
2N/Apublic final class KernelSymbolRecord implements SymbolValueRecord,
2N/A Serializable, Comparable <KernelSymbolRecord>
2N/A{
2N/A static final long serialVersionUID = -7156627773519296848L;
2N/A
2N/A static {
2N/A try {
2N/A BeanInfo info = Introspector.getBeanInfo(KernelSymbolRecord.class);
2N/A PersistenceDelegate persistenceDelegate =
2N/A new DefaultPersistenceDelegate(
2N/A new String[] {"symbol", "address"})
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 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 String symbol; // set natively after creation; treat as final
2N/A /** @serial */
2N/A private final long address;
2N/A
2N/A /**
2N/A * Called by native code.
2N/A */
2N/A private
2N/A KernelSymbolRecord(long addressValue)
2N/A {
2N/A address = addressValue;
2N/A }
2N/A
2N/A /**
2N/A * Creates a {@code KernelSymbolRecord} with the given symbol lookup
2N/A * and kernel address converted in probe context as a result of the
2N/A * DTrace {@code mod()}, {@code func()}, or {@code sym()} action.
2N/A * <p>
2N/A * Supports XML persistence.
2N/A *
2N/A * @param addressValue symbol address
2N/A * @param lookupValue the result in the native DTrace library of
2N/A * looking up the symbol associated with the given kernel address
2N/A * @throws NullPointerException if the given lookup value is {@code null}
2N/A */
2N/A public
2N/A KernelSymbolRecord(String lookupValue, long addressValue)
2N/A {
2N/A symbol = lookupValue;
2N/A address = addressValue;
2N/A validate();
2N/A }
2N/A
2N/A private final void
2N/A validate()
2N/A {
2N/A if (symbol == null) {
2N/A throw new NullPointerException("symbol is null");
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Gets the result of the address lookup in the same form returned
2N/A * by {@link Consumer#lookupKernelFunction(long address)}.
2N/A *
2N/A * @return non-null address lookup in the format defined by the
2N/A * native DTrace library
2N/A */
2N/A public String
2N/A getSymbol()
2N/A {
2N/A return symbol;
2N/A }
2N/A
2N/A /**
2N/A * Called by native code and ProbeData addSymbolRecord()
2N/A */
2N/A void
2N/A setSymbol(String lookupValue)
2N/A {
2N/A symbol = lookupValue;
2N/A validate();
2N/A }
2N/A
2N/A /**
2N/A * Gets the symbol's kernel address.
2N/A *
2N/A * @return the symbol's kernel address
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 symbol's kernel address. The value is used in {@link
2N/A * #equals(Object o) equals()} and {@link
2N/A * #compareTo(KernelSymbolRecord r) compareTo()} to test equality
2N/A * and to determine the natural ordering of {@code
2N/A * KernelSymbolRecord} instances.
2N/A *
2N/A * @return non-null value of the symbol's kernel address
2N/A */
2N/A public Long
2N/A getValue()
2N/A {
2N/A return address;
2N/A }
2N/A
2N/A /**
2N/A * Compares the specified object with this {@code KernelSymbolRecord}
2N/A * for equality. Returns {@code true} if and only if the specified
2N/A * object is also a {@code KernelSymbolRecord} and both records have
2N/A * the same address.
2N/A *
2N/A * @return {@code true} if and only if the specified object is also
2N/A * a {@code KernelSymbolRecord} and both records have the same
2N/A * address
2N/A */
2N/A @Override
2N/A public boolean
2N/A equals(Object o)
2N/A {
2N/A if (o instanceof KernelSymbolRecord) {
2N/A KernelSymbolRecord r = (KernelSymbolRecord)o;
2N/A return (address == r.address);
2N/A }
2N/A return false;
2N/A }
2N/A
2N/A /**
2N/A * Overridden to ensure that equal instances have equal hash codes.
2N/A */
2N/A @Override
2N/A public int
2N/A hashCode()
2N/A {
2N/A return (int)(address ^ (address >>> 32));
2N/A }
2N/A
2N/A /**
2N/A * Compares this record with the given kernel symbol lookup and
2N/A * orders by address. The comparison treats addresses as unsigned
2N/A * values so the ordering is consistent with that defined in the
2N/A * native DTrace library. The {@code compareTo()} method is
2N/A * compatible with {@link #equals(Object o) equals()}.
2N/A *
2N/A * @return -1, 0, or 1 as this record's address is less than, equal
2N/A * to, or greater than the given record's address
2N/A */
2N/A public int
2N/A compareTo(KernelSymbolRecord r)
2N/A {
2N/A return ProbeData.compareUnsigned(address, r.address);
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 the result of this symbol lookup. The format is defined in
2N/A * the native DTrace library and is as stable as that library
2N/A * definition.
2N/A *
2N/A * @return {@link #getSymbol()}
2N/A */
2N/A @Override
2N/A public String
2N/A toString()
2N/A {
2N/A return symbol;
2N/A }
2N/A}