feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2003, 2004, 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.counter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
/**
*/
public abstract class AbstractCounter implements Counter {
String name;
Units units;
Variability variability;
int flags;
int vectorLength;
// Flags defined in hotspot implementation
class Flags {
static final int SUPPORTED = 0x1;
}
protected AbstractCounter(String name, Units units,
Variability variability, int flags,
int vectorLength) {
this.name = name;
this.units = units;
this.variability = variability;
this.flags = flags;
this.vectorLength = vectorLength;
}
protected AbstractCounter(String name, Units units,
Variability variability, int flags) {
this(name, units, variability, flags, 0);
}
/**
* Returns the name of the Performance Counter
*/
public String getName() {
return name;
}
/**
* Returns the Units for this Performance Counter
*/
public Units getUnits() {
return units;
}
/**
* Returns the Variability for this performance Object
*/
public Variability getVariability() {
return variability;
}
/**
* Return true if this performance counter is a vector
*/
public boolean isVector() {
return vectorLength > 0;
}
/**
* return the length of the vector
*/
public int getVectorLength() {
return vectorLength;
}
public boolean isInternal() {
return (flags & Flags.SUPPORTED) == 0;
}
/**
* return the flags associated with the counter.
*/
public int getFlags() {
return flags;
}
public abstract Object getValue();
public String toString() {
String result = getName() + ": " + getValue() + " " + getUnits();
if (isInternal()) {
return result + " [INTERNAL]";
} else {
return result;
}
}
private static final long serialVersionUID = 6992337162326171013L;
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2003, 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.counter;
/**
* Interface for performance counter wrapping <code>byte[]</code> objects.
*
* @author Brian Doherty
*/
public interface ByteArrayCounter extends Counter {
/**
* Get a copy of the elements of the ByteArrayCounter.
*/
public byte[] byteArrayValue();
/**
* Get the value of an element of the ByteArrayCounter object.
*/
public byte byteAt(int index);
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2003, 2004, 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.counter;
/**
* The base class for a performance counter.
*
* @author Brian Doherty
*/
public interface Counter extends java.io.Serializable {
/**
* Returns the name of this performance counter
*/
public String getName();
/**
* Returns the Units for this performance counter
*/
public Units getUnits();
/**
* Returns the Variability for this performance counter
*/
public Variability getVariability();
/**
* Returns true if this performance counter is a vector
*/
public boolean isVector();
/**
* Returns the length of the vector
*/
public int getVectorLength();
/**
* Returns an Object that encapsulates the data value of this counter
*/
public Object getValue();
/**
* Returns <tt>true</tt> if this counter is an internal counter.
*/
public boolean isInternal();
/**
* Return the flags associated with the counter.
*/
public int getFlags();
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2003, 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.counter;
/**
* Interface for performance counter wrapping <code>long[]</code> objects.
*
*/
public interface LongArrayCounter extends Counter {
/**
* Get a copy of the elements of the LongArrayCounter.
*/
public long[] longArrayValue();
/**
* Get the value of an element of the LongArrayCounter object.
*/
public long longAt(int index);
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2003, 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.counter;
/**
* Interface for a performance counter wrapping a
* <code>long</code> basic type.
*
* @author Brian Doherty
*/
public interface LongCounter extends Counter {
/**
* Get the value of this Long performance counter
*/
public long longValue();
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2003, 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.counter;
/**
* Interface for a performance counter wrapping a <code>String</code> object.
*
* @author Brian Doherty
*/
public interface StringCounter extends Counter {
/**
* Get a copy of the value of the StringCounter.
*/
public String stringValue();
}

View File

@@ -0,0 +1,128 @@
/*
* Copyright (c) 2003, 2004, 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.counter;
/**
* Provides a typesafe enumeration for describing units of measurement
* attribute for instrumentation objects.
*
* @author Brian Doherty
*/
public class Units implements java.io.Serializable {
/* The enumeration values for this typesafe enumeration must be
* kept in synchronization with the Units enum in the perfData.hpp file
* in the HotSpot source base.
*/
private static final int NUNITS=8;
private static Units[] map = new Units[NUNITS];
private final String name;
private final int value;
/**
* An Invalid Units value.
*/
public static final Units INVALID = new Units("Invalid", 0);
/**
* Units attribute representing unit-less quantities.
*/
public static final Units NONE = new Units("None", 1);
/**
* Units attribute representing Bytes.
*/
public static final Units BYTES = new Units("Bytes", 2);
/**
* Units attribute representing Ticks.
*/
public static final Units TICKS = new Units("Ticks", 3);
/**
* Units attribute representing a count of events.
*/
public static final Units EVENTS = new Units("Events", 4);
/**
* Units attribute representing String data. Although not really
* a unit of measure, this Units value serves to distinguish String
* instrumentation objects from instrumentation objects of other types.
*/
public static final Units STRING = new Units("String", 5);
/**
* Units attribute representing Hertz (frequency).
*/
public static final Units HERTZ = new Units("Hertz", 6);
/**
* Returns a string describing this Unit of measurement attribute
*
* @return String - a descriptive string for this enum.
*/
public String toString() {
return name;
}
/**
* Returns the integer representation of this Units attribute
*
* @return int - an integer representation of this Units attribute.
*/
public int intValue() {
return value;
}
/**
* Maps an integer value to its corresponding Units attribute.
* If the integer value does not have a corresponding Units enum
* value, then {@link Units#INVALID} is returned.
*
* @param value an integer representation of counter Units
* @return Units - the Units object for the given <code>value</code>
* or {@link Units#INVALID} if out of range.
*/
public static Units toUnits(int value) {
if (value < 0 || value >= map.length || map[value] == null) {
return INVALID;
}
return map[value];
}
private Units(String name, int value) {
this.name = name;
this.value = value;
map[value] = this;
}
private static final long serialVersionUID = 6992337162326171013L;
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2003, 2004, 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.counter;
/**
* Provides a typesafe enumeration for the Variability attribute for
* instrumentation objects.
*
* @author Brian Doherty
*/
public class Variability implements java.io.Serializable {
/* The enumeration values for this typesafe enumeration must be
* kept in synchronization with the Variability enum in the perfData.hpp file
* in the HotSpot source base.
*/
private static final int NATTRIBUTES = 4;
private static Variability[] map = new Variability[NATTRIBUTES];
private String name;
private int value;
/**
* An invalid Variablity value.
*/
public static final Variability INVALID = new Variability("Invalid",0);
/**
* Variability attribute representing Constant counters.
*/
public static final Variability CONSTANT = new Variability("Constant",1);
/**
* Variability attribute representing a Monotonically changing counters.
*/
public static final Variability MONOTONIC = new Variability("Monotonic",2);
/**
* Variability attribute representing Variable counters.
*/
public static final Variability VARIABLE = new Variability("Variable",3);
/**
* Returns a string describing this Variability attribute.
*
* @return String - a descriptive string for this enum.
*/
public String toString() {
return name;
}
/**
* Returns the integer representation of this Variability attribute.
*
* @return int - an integer representation of this Variability attribute.
*/
public int intValue() {
return value;
}
/**
* Maps an integer value its corresponding Variability attribute.
* If the integer value does not have a corresponding Variability enum
* value, the {@link Variability#INVALID} is returned
*
* @param value an integer representation of a Variability attribute
* @return Variability - The Variability object for the given
* <code>value</code> or {@link Variability#INVALID}
* if out of range.
*/
public static Variability toVariability(int value) {
if (value < 0 || value >= map.length || map[value] == null) {
return INVALID;
}
return map[value];
}
private Variability(String name, int value) {
this.name = name;
this.value = value;
map[value]=this;
}
private static final long serialVersionUID = 6992337162326171013L;
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2004, 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.counter.perf;
import sun.management.counter.*;
/**
* A snapshot of the perf counter for serialization.
*/
class ByteArrayCounterSnapshot extends AbstractCounter
implements ByteArrayCounter {
byte[] value;
// package private
ByteArrayCounterSnapshot(String name, Units u, Variability v, int flags,
int vectorLength, byte[] value) {
super(name, u, v, flags, vectorLength);
this.value = value;
}
public Object getValue() {
return value;
}
public byte[] byteArrayValue() {
return value;
}
public byte byteAt(int index) {
return value[index];
}
private static final long serialVersionUID = 1444793459838438979L;
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2003, 2013, 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.counter.perf;
public class InstrumentationException extends RuntimeException {
/**
* Constructs a <tt>InstrumentationException</tt> with no
* detail message.
*/
public InstrumentationException() {
}
/**
* Constructs a <tt>InstrumentationException</tt> with a specified
* detail message.
*
* @param message the detail message
*/
public InstrumentationException(String message) {
super(message);
}
private static final long serialVersionUID = 8060117844393922797L;
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2004, 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.counter.perf;
import sun.management.counter.*;
/**
* A snapshot of the perf counter for serialization.
*/
class LongArrayCounterSnapshot extends AbstractCounter
implements LongArrayCounter {
long[] value;
// package private
LongArrayCounterSnapshot(String name, Units u, Variability v, int flags,
int vectorLength, long[] value) {
super(name, u, v, flags, vectorLength);
this.value = value;
}
public Object getValue() {
return value;
}
public long[] longArrayValue() {
return value;
}
public long longAt(int index) {
return value[index];
}
private static final long serialVersionUID = 3585870271405924292L;
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2004, 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.counter.perf;
import sun.management.counter.*;
/**
* A snapshot of the perf counter for serialization.
*/
class LongCounterSnapshot extends AbstractCounter
implements LongCounter {
long value;
// package private
LongCounterSnapshot(String name, Units u, Variability v, int flags,
long value) {
super(name, u, v, flags);
this.value = value;
}
public Object getValue() {
return new Long(value);
}
/**
* Get the value of this Long performance counter
*/
public long longValue() {
return value;
}
private static final long serialVersionUID = 2054263861474565758L;
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2003, 2004, 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.counter.perf;
import sun.management.counter.*;
import java.nio.*;
public class PerfByteArrayCounter extends AbstractCounter
implements ByteArrayCounter {
ByteBuffer bb;
PerfByteArrayCounter(String name, Units u, Variability v,
int flags, int vectorLength,
ByteBuffer bb) {
super(name, u, v, flags, vectorLength);
this.bb = bb;
}
public Object getValue() {
return byteArrayValue();
}
/**
* Get a copy of the elements of the ByteArrayCounter.
*/
public byte[] byteArrayValue() {
bb.position(0);
byte[] b = new byte[bb.limit()];
// copy the bytes
bb.get(b);
return b;
}
/**
* Get the value of an element of the ByteArrayCounter object.
*/
public byte byteAt(int index) {
bb.position(index);
return bb.get();
}
public String toString() {
String result = getName() + ": " + new String(byteArrayValue()) +
" " + getUnits();
if (isInternal()) {
return result + " [INTERNAL]";
} else {
return result;
}
}
/**
* Serialize as a snapshot object.
*/
protected Object writeReplace() throws java.io.ObjectStreamException {
return new ByteArrayCounterSnapshot(getName(),
getUnits(),
getVariability(),
getFlags(),
getVectorLength(),
byteArrayValue());
}
private static final long serialVersionUID = 2545474036937279921L;
}

View File

@@ -0,0 +1,211 @@
/*
* Copyright (c) 2003, 2011, 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.counter.perf;
import sun.management.counter.*;
import java.nio.*;
import java.io.UnsupportedEncodingException;
class PerfDataEntry {
private class EntryFieldOffset {
private final static int SIZEOF_BYTE = 1;
private final static int SIZEOF_INT = 4;
private final static int SIZEOF_LONG = 8;
private final static int ENTRY_LENGTH_SIZE = SIZEOF_INT;
private final static int NAME_OFFSET_SIZE = SIZEOF_INT;
private final static int VECTOR_LENGTH_SIZE = SIZEOF_INT;
private final static int DATA_TYPE_SIZE = SIZEOF_BYTE;
private final static int FLAGS_SIZE = SIZEOF_BYTE;
private final static int DATA_UNIT_SIZE = SIZEOF_BYTE;
private final static int DATA_VAR_SIZE = SIZEOF_BYTE;
private final static int DATA_OFFSET_SIZE = SIZEOF_INT;
final static int ENTRY_LENGTH = 0;
final static int NAME_OFFSET = ENTRY_LENGTH + ENTRY_LENGTH_SIZE;
final static int VECTOR_LENGTH = NAME_OFFSET + NAME_OFFSET_SIZE;;
final static int DATA_TYPE = VECTOR_LENGTH + VECTOR_LENGTH_SIZE;
final static int FLAGS = DATA_TYPE + DATA_TYPE_SIZE;
final static int DATA_UNIT = FLAGS + FLAGS_SIZE;
final static int DATA_VAR = DATA_UNIT + DATA_UNIT_SIZE;
final static int DATA_OFFSET = DATA_VAR + DATA_VAR_SIZE;
}
private String name;
private int entryStart;
private int entryLength;
private int vectorLength;
private PerfDataType dataType;
private int flags;
private Units unit;
private Variability variability;
private int dataOffset;
private int dataSize;
private ByteBuffer data;
PerfDataEntry(ByteBuffer b) {
entryStart = b.position();
entryLength = b.getInt();
// check for valid entry length
if (entryLength <= 0 || entryLength > b.limit()) {
throw new InstrumentationException("Invalid entry length: " +
" entryLength = " + entryLength);
}
// check if last entry occurs before the eof.
if ((entryStart + entryLength) > b.limit()) {
throw new InstrumentationException("Entry extends beyond end of buffer: " +
" entryStart = " + entryStart +
" entryLength = " + entryLength +
" buffer limit = " + b.limit());
}
b.position(entryStart + EntryFieldOffset.NAME_OFFSET);
int nameOffset = b.getInt();
if ((entryStart + nameOffset) > b.limit()) {
throw new InstrumentationException("Invalid name offset: " +
" entryStart = " + entryStart +
" nameOffset = " + nameOffset +
" buffer limit = " + b.limit());
}
b.position(entryStart + EntryFieldOffset.VECTOR_LENGTH);
vectorLength = b.getInt();
b.position(entryStart + EntryFieldOffset.DATA_TYPE);
dataType = PerfDataType.toPerfDataType(b.get());
b.position(entryStart + EntryFieldOffset.FLAGS);
flags = b.get();
b.position(entryStart + EntryFieldOffset.DATA_UNIT);
unit = Units.toUnits(b.get());
b.position(entryStart + EntryFieldOffset.DATA_VAR);
variability = Variability.toVariability(b.get());
b.position(entryStart + EntryFieldOffset.DATA_OFFSET);
dataOffset = b.getInt();
// read in the perfData item name, casting bytes to chars. skip the
// null terminator
b.position(entryStart + nameOffset);
// calculate the length of the name
int nameLength = 0;
byte c;
for (; (c = b.get()) != (byte)0; nameLength++);
byte[] symbolBytes = new byte[nameLength];
b.position(entryStart + nameOffset);
for (int i = 0; i < nameLength; i++) {
symbolBytes[i] = b.get();
}
// convert name into a String
try {
name = new String(symbolBytes, "UTF-8");
}
catch (UnsupportedEncodingException e) {
// should not reach here
// "UTF-8" is always a known encoding
throw new InternalError(e.getMessage(), e);
}
if (variability == Variability.INVALID) {
throw new InstrumentationException("Invalid variability attribute:" +
" name = " + name);
}
if (unit == Units.INVALID) {
throw new InstrumentationException("Invalid units attribute: " +
" name = " + name);
}
if (vectorLength > 0) {
dataSize = vectorLength * dataType.size();
} else {
dataSize = dataType.size();
}
// check if data beyond the eof.
if ((entryStart + dataOffset + dataSize) > b.limit()) {
throw new InstrumentationException("Data extends beyond end of buffer: " +
" entryStart = " + entryStart +
" dataOffset = " + dataOffset+
" dataSize = " + dataSize +
" buffer limit = " + b.limit());
}
// Construct a ByteBuffer for the data
b.position(entryStart + dataOffset);
data = b.slice();
data.order(b.order());
data.limit(dataSize);
}
public int size() {
return entryLength;
}
public String name() {
return name;
}
public PerfDataType type() {
return dataType;
}
public Units units() {
return unit;
}
public int flags() {
return flags;
}
/**
* Returns the number of elements in the data.
*/
public int vectorLength() {
return vectorLength;
}
public Variability variability() {
return variability;
}
public ByteBuffer byteData() {
data.position(0);
assert data.remaining() == vectorLength();
return data.duplicate();
}
public LongBuffer longData() {
LongBuffer lb = data.asLongBuffer();
return lb;
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2003, 2013, 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.counter.perf;
import java.io.UnsupportedEncodingException;
/**
* A typesafe enumeration for the data types supported for
* performance data.
*
* <p> The enumeration values for this typesafe enumeration must be
* kept in synchronization with the PerfDataType enum in the
* globalsDefinitions.hpp file in the HotSpot source base.</p>
*
* @author Brian Doherty
*/
class PerfDataType {
private final String name;
private final byte value;
private final int size;
public static final PerfDataType BOOLEAN = new PerfDataType("boolean", "Z", 1);
public static final PerfDataType CHAR = new PerfDataType("char", "C", 1);
public static final PerfDataType FLOAT = new PerfDataType("float", "F", 8);
public static final PerfDataType DOUBLE = new PerfDataType("double", "D", 8);
public static final PerfDataType BYTE = new PerfDataType("byte", "B", 1);
public static final PerfDataType SHORT = new PerfDataType("short", "S", 2);
public static final PerfDataType INT = new PerfDataType("int", "I", 4);
public static final PerfDataType LONG = new PerfDataType("long", "J", 8);
public static final PerfDataType ILLEGAL = new PerfDataType("illegal", "X", 0);
private static PerfDataType basicTypes[] = {
LONG, BYTE, BOOLEAN, CHAR, FLOAT, DOUBLE, SHORT, INT
};
public String toString() {
return name;
}
public byte byteValue() {
return value;
}
public int size() {
return size;
}
/**
* Maps an integer PerfDataType value to its corresponding PerfDataType
* object.
*
* @param i an integer representation of a PerfDataType
* @return The PerfDataType object for <code>i</code>
*/
public static PerfDataType toPerfDataType(byte type) {
for (int j = 0; j < basicTypes.length; j++) {
if (basicTypes[j].byteValue() == type) {
return (basicTypes[j]);
}
}
return ILLEGAL;
}
private PerfDataType(String name, String c, int size) {
this.name = name;
this.size = size;
try {
byte[] b = c.getBytes("UTF-8");
this.value = b[0];
} catch (UnsupportedEncodingException e) {
// ignore, "UTF-8" is always a known encoding
throw new InternalError("Unknown encoding", e);
}
}
}

View File

@@ -0,0 +1,186 @@
/*
* Copyright (c) 2003, 2012, 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.counter.perf;
import sun.management.counter.*;
import java.nio.*;
import java.util.*;
import java.util.regex.*;
public class PerfInstrumentation {
private ByteBuffer buffer;
private Prologue prologue;
private long lastModificationTime;
private long lastUsed;
private int nextEntry;
private SortedMap<String, Counter> map;
public PerfInstrumentation(ByteBuffer b) {
prologue = new Prologue(b);
buffer = b;
buffer.order(prologue.getByteOrder());
// Check recognized versions
int major = getMajorVersion();
int minor = getMinorVersion();
// Support only 2.0 version
if (major < 2) {
throw new InstrumentationException("Unsupported version: " +
major + "." + minor);
}
rewind();
}
public int getMajorVersion() {
return prologue.getMajorVersion();
}
public int getMinorVersion() {
return prologue.getMinorVersion();
}
public long getModificationTimeStamp() {
return prologue.getModificationTimeStamp();
}
void rewind() {
// rewind to the first entry
buffer.rewind();
buffer.position(prologue.getEntryOffset());
nextEntry = buffer.position();
// rebuild all the counters
map = new TreeMap<>();
}
boolean hasNext() {
return (nextEntry < prologue.getUsed());
}
Counter getNextCounter() {
if (! hasNext()) {
return null;
}
if ((nextEntry % 4) != 0) {
// entries are always 4 byte aligned.
throw new InstrumentationException(
"Entry index not properly aligned: " + nextEntry);
}
if (nextEntry < 0 || nextEntry > buffer.limit()) {
// defensive check to protect against a corrupted shared memory region.
throw new InstrumentationException(
"Entry index out of bounds: nextEntry = " + nextEntry +
", limit = " + buffer.limit());
}
buffer.position(nextEntry);
PerfDataEntry entry = new PerfDataEntry(buffer);
nextEntry = nextEntry + entry.size();
Counter counter = null;
PerfDataType type = entry.type();
if (type == PerfDataType.BYTE) {
if (entry.units() == Units.STRING && entry.vectorLength() > 0) {
counter = new PerfStringCounter(entry.name(),
entry.variability(),
entry.flags(),
entry.vectorLength(),
entry.byteData());
} else if (entry.vectorLength() > 0) {
counter = new PerfByteArrayCounter(entry.name(),
entry.units(),
entry.variability(),
entry.flags(),
entry.vectorLength(),
entry.byteData());
} else {
// ByteArrayCounter must have vectorLength > 0
assert false;
}
}
else if (type == PerfDataType.LONG) {
if (entry.vectorLength() == 0) {
counter = new PerfLongCounter(entry.name(),
entry.units(),
entry.variability(),
entry.flags(),
entry.longData());
} else {
counter = new PerfLongArrayCounter(entry.name(),
entry.units(),
entry.variability(),
entry.flags(),
entry.vectorLength(),
entry.longData());
}
}
else {
// FIXME: Should we throw an exception for unsupported type?
// Currently skip such entry
assert false;
}
return counter;
}
public synchronized List<Counter> getAllCounters() {
while (hasNext()) {
Counter c = getNextCounter();
if (c != null) {
map.put(c.getName(), c);
}
}
return new ArrayList<>(map.values());
}
public synchronized List<Counter> findByPattern(String patternString) {
while (hasNext()) {
Counter c = getNextCounter();
if (c != null) {
map.put(c.getName(), c);
}
}
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher("");
List<Counter> matches = new ArrayList<>();
for (Map.Entry<String,Counter> me: map.entrySet()) {
String name = me.getKey();
// apply pattern to counter name
matcher.reset(name);
// if the pattern matches, then add Counter to list
if (matcher.lookingAt()) {
matches.add(me.getValue());
}
}
return matches;
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (c) 2003, 2004, 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.counter.perf;
import sun.management.counter.*;
import java.nio.LongBuffer;
import java.nio.ReadOnlyBufferException;
public class PerfLongArrayCounter extends AbstractCounter
implements LongArrayCounter {
LongBuffer lb;
PerfLongArrayCounter(String name, Units u, Variability v,
int flags, int vectorLength,
LongBuffer lb) {
super(name, u, v, flags, vectorLength);
this.lb = lb;
}
public Object getValue() {
return longArrayValue();
}
/**
* Get a copy of the elements of the LongArrayCounter.
*/
public long[] longArrayValue() {
lb.position(0);
long[] l = new long[lb.limit()];
// copy the bytes
lb.get(l);
return l;
}
/**
* Get the value of an element of the LongArrayCounter object.
*/
public long longAt(int index) {
lb.position(index);
return lb.get();
}
/**
* Serialize as a snapshot object.
*/
protected Object writeReplace() throws java.io.ObjectStreamException {
return new LongArrayCounterSnapshot(getName(),
getUnits(),
getVariability(),
getFlags(),
getVectorLength(),
longArrayValue());
}
private static final long serialVersionUID = -2733617913045487126L;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2003, 2004, 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.counter.perf;
import sun.management.counter.*;
import java.nio.LongBuffer;
import java.nio.ReadOnlyBufferException;
public class PerfLongCounter extends AbstractCounter
implements LongCounter {
LongBuffer lb;
// package private
PerfLongCounter(String name, Units u, Variability v, int flags,
LongBuffer lb) {
super(name, u, v, flags);
this.lb = lb;
}
public Object getValue() {
return new Long(lb.get(0));
}
/**
* Get the value of this Long performance counter
*/
public long longValue() {
return lb.get(0);
}
/**
* Serialize as a snapshot object.
*/
protected Object writeReplace() throws java.io.ObjectStreamException {
return new LongCounterSnapshot(getName(),
getUnits(),
getVariability(),
getFlags(),
longValue());
}
private static final long serialVersionUID = 857711729279242948L;
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright (c) 2003, 2006, 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.counter.perf;
import sun.management.counter.*;
import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import java.nio.charset.Charset;
public class PerfStringCounter extends PerfByteArrayCounter
implements StringCounter {
private static Charset defaultCharset = Charset.defaultCharset();
PerfStringCounter(String name, Variability v,
int flags, ByteBuffer bb) {
this(name, v, flags, bb.limit(), bb);
}
PerfStringCounter(String name, Variability v, int flags,
int maxLength, ByteBuffer bb) {
super(name, Units.STRING, v, flags, maxLength, bb);
}
// override isVector and getVectorLength in ByteArrayCounter
public boolean isVector() {
return false;
}
public int getVectorLength() {
return 0;
}
public Object getValue() {
return stringValue();
}
public String stringValue() {
String str = "";
byte[] b = byteArrayValue();
if (b == null || b.length <= 1) {
return str;
}
int i;
for (i = 0; i < b.length && b[i] != (byte)0; i++);
// convert byte array to string, using all bytes up to, but
// not including the first null byte.
return new String(b , 0, i, defaultCharset);
}
/**
* Serialize as a snapshot object.
*/
protected Object writeReplace() throws java.io.ObjectStreamException {
return new StringCounterSnapshot(getName(),
getUnits(),
getVariability(),
getFlags(),
stringValue());
}
private static final long serialVersionUID = 6802913433363692452L;
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2003, 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.counter.perf;
import sun.management.counter.*;
import java.nio.*;
class Prologue {
// these constants should match their #define counterparts in vmdata.hpp
private final static byte PERFDATA_BIG_ENDIAN = 0;
private final static byte PERFDATA_LITTLE_ENDIAN = 1;
private final static int PERFDATA_MAGIC = 0xcafec0c0;
private class PrologueFieldOffset {
private final static int SIZEOF_BYTE = 1;
private final static int SIZEOF_INT = 4;
private final static int SIZEOF_LONG = 8;
private final static int MAGIC_SIZE = SIZEOF_INT;
private final static int BYTE_ORDER_SIZE = SIZEOF_BYTE;
private final static int MAJOR_SIZE = SIZEOF_BYTE;
private final static int MINOR_SIZE = SIZEOF_BYTE;
private final static int ACCESSIBLE_SIZE = SIZEOF_BYTE;
private final static int USED_SIZE = SIZEOF_INT;
private final static int OVERFLOW_SIZE = SIZEOF_INT;
private final static int MOD_TIMESTAMP_SIZE = SIZEOF_LONG;
private final static int ENTRY_OFFSET_SIZE = SIZEOF_INT;
private final static int NUM_ENTRIES_SIZE = SIZEOF_INT;
// these constants must match the field offsets and sizes
// in the PerfDataPrologue structure in perfMemory.hpp
final static int MAGIC = 0;
final static int BYTE_ORDER = MAGIC + MAGIC_SIZE;
final static int MAJOR_VERSION = BYTE_ORDER + BYTE_ORDER_SIZE;
final static int MINOR_VERSION = MAJOR_VERSION + MAJOR_SIZE;
final static int ACCESSIBLE = MINOR_VERSION + MINOR_SIZE;
final static int USED = ACCESSIBLE + ACCESSIBLE_SIZE;
final static int OVERFLOW = USED + USED_SIZE;
final static int MOD_TIMESTAMP = OVERFLOW + OVERFLOW_SIZE;
final static int ENTRY_OFFSET = MOD_TIMESTAMP + MOD_TIMESTAMP_SIZE;
final static int NUM_ENTRIES = ENTRY_OFFSET + ENTRY_OFFSET_SIZE;
final static int PROLOGUE_2_0_SIZE = NUM_ENTRIES + NUM_ENTRIES_SIZE;
}
private ByteBuffer header;
private int magic;
Prologue(ByteBuffer b) {
this.header = b.duplicate();
// the magic number is always stored in big-endian format
// save and restore the buffer's initial byte order around
// the fetch of the data.
header.order(ByteOrder.BIG_ENDIAN);
header.position(PrologueFieldOffset.MAGIC);
magic = header.getInt();
// the magic number is always stored in big-endian format
if (magic != PERFDATA_MAGIC) {
throw new InstrumentationException("Bad Magic: " +
Integer.toHexString(getMagic()));
}
// set the buffer's byte order according to the value of its
// byte order field.
header.order(getByteOrder());
// Check version
int major = getMajorVersion();
int minor = getMinorVersion();
if (major < 2) {
throw new InstrumentationException("Unsupported version: " +
major + "." + minor);
}
// Currently, only support 2.0 version.
header.limit(PrologueFieldOffset.PROLOGUE_2_0_SIZE);
}
public int getMagic() {
return magic;
}
public int getMajorVersion() {
header.position(PrologueFieldOffset.MAJOR_VERSION);
return (int)header.get();
}
public int getMinorVersion() {
header.position(PrologueFieldOffset.MINOR_VERSION);
return (int)header.get();
}
public ByteOrder getByteOrder() {
header.position(PrologueFieldOffset.BYTE_ORDER);
byte byte_order = header.get();
if (byte_order == PERFDATA_BIG_ENDIAN) {
return ByteOrder.BIG_ENDIAN;
}
else {
return ByteOrder.LITTLE_ENDIAN;
}
}
public int getEntryOffset() {
header.position(PrologueFieldOffset.ENTRY_OFFSET);
return header.getInt();
}
// The following fields are updated asynchronously
// while they are accessed by these methods.
public int getUsed() {
header.position(PrologueFieldOffset.USED);
return header.getInt();
}
public int getOverflow() {
header.position(PrologueFieldOffset.OVERFLOW);
return header.getInt();
}
public long getModificationTimeStamp() {
header.position(PrologueFieldOffset.MOD_TIMESTAMP);
return header.getLong();
}
public int getNumEntries() {
header.position(PrologueFieldOffset.NUM_ENTRIES);
return header.getInt();
}
public boolean isAccessible() {
header.position(PrologueFieldOffset.ACCESSIBLE);
byte b = header.get();
return (b == 0 ? false : true);
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2004, 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.counter.perf;
import sun.management.counter.*;
/**
* A snapshot of the perf counter for serialization.
*/
class StringCounterSnapshot extends AbstractCounter
implements StringCounter {
String value;
// package private
StringCounterSnapshot(String name, Units u, Variability v, int flags,
String value) {
super(name, u, v, flags);
this.value = value;
}
public Object getValue() {
return value;
}
public String stringValue() {
return value;
}
private static final long serialVersionUID = 1132921539085572034L;
}