/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/*
*/
/**
* Demo code which plots the memory usage by all memory pools.
* The memory usage is sampled at some time interval using
* java.lang.management API. This demo code is modified based
* java2d MemoryMonitor demo.
*/
boolean doControls;
// Get memory pools.
// Total number of memory pools.
public MemoryMonitor() {
setLayout(new BorderLayout());
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
removeAll();
if ((doControls = !doControls)) {
} else {
try {
}
validate();
repaint();
}
});
}
private int w, h;
private int columnInc;
private float usedMem[][];
private int ptNum[];
public Surface() {
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
}
});
usedMemMax = new float[numPools];
for (int i = 0; i < numPools; i++) {
}
}
return getPreferredSize();
}
return getPreferredSize();
}
}
return;
}
w = w / 2;
int k=0; // index of memory pool.
for (int i=0; i < 2;i++) {
plotMemoryUsage(w*i,h*j,w,h,k);
if (++k >= numPools) {
i = 3;
break;
}
}
}
}
}
}
// .. Draw allocated and used strings ..
// Print Max memory allocated for this memory pool.
big.drawString(String.valueOf((int)totalMemory/1024) + "K Max ", x1+4.0f, (float) y1 + ascent+0.5f);
// Print the memory pool name.
// Print the memory used by this memory pool.
+ "K used";
// Calculate remaining size
float blockWidth = 20.0f;
// .. Memory Free ..
int i = 0;
for ( ; i < MemUsage ; i++) {
}
// .. Memory Used ..
for ( ; i < 10; i++) {
}
// .. Draw History Graph ..
int graphW = (int) remainingWidth;
int graphH = (int) remainingHeight;
// .. Draw row ..
}
// .. Draw animated column movement ..
if (columnInc == 0) {
}
}
--columnInc;
// Plot memory usage by this memory pool.
}
// save memory usage history.
int w1; // width of memory usage history.
} else {
}
k++, j++) {
if (k != 0) {
} else {
}
}
}
// throw out oldest point
}
} else {
}
}
public void start() {
}
public synchronized void stop() {
notify();
}
public void run() {
try {
} catch (InterruptedException e) { return; }
}
w = d.width;
h = d.height;
}
repaint();
try {
} catch (InterruptedException e) { break; }
}
}
}
}
// Test thread to consume memory
Object y[];
public Memeater() {}
public void run() {
y = new Object[10000000];
int k =0;
while(true) {
if (k == 5000000) k=0;
y[k++] = new Object();
try {
} catch (Exception x){}
// to consume perm gen storage
try {
// the classes are small so we load 10 at a time
for (int i=0; i<10; i++) {
loadNext();
}
} catch (ClassNotFoundException x) {
// ignore exception
}
}
}
// public class TestNNNNNN extends java.lang.Object{
// public TestNNNNNN();
// Code:
// 0: aload_0
// 4: return
// }
int begin[] = {
0xca, 0xfe, 0xba, 0xbe, 0x00, 0x00, 0x00, 0x30,
0x00, 0x0a, 0x0a, 0x00, 0x03, 0x00, 0x07, 0x07,
0x00, 0x08, 0x07, 0x00, 0x09, 0x01, 0x00, 0x06,
0x3c, 0x69, 0x6e, 0x69, 0x74, 0x3e, 0x01, 0x00,
0x03, 0x28, 0x29, 0x56, 0x01, 0x00, 0x04, 0x43,
0x6f, 0x64, 0x65, 0x0c, 0x00, 0x04, 0x00, 0x05,
0x01, 0x00, 0x0a, 0x54, 0x65, 0x73, 0x74 };
int end [] = {
0x01, 0x00, 0x10,
0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e,
0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74,
0x00, 0x21, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x04,
0x00, 0x05, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00,
0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x00, 0x05, 0x2a, 0xb7, 0x00, 0x01, 0xb1, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00 };
// TestNNNNNN
byte value[];
try {
throw new Error();
}
// construct class file
byte b[] = new byte[len];
int pos=0;
for (int i: begin) {
b[pos++] = (byte) i;
}
for (byte v: value) {
b[pos++] = v;
}
for (int e: end) {
b[pos++] = (byte) e;
}
}
}
WindowListener l = new WindowAdapter() {
};
f.addWindowListener(l);
f.pack();
f.setVisible(true);
}
}