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,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;
}