project report -memory monitor - jyoti

34
A Report On MEMORY MANAGEMENT BACHELOR OF ENGINEERING IN COMPUTER SCIENCE & ENGINEERING  Submitted By:- JYOTI POONIA Submitted To:- HEAD Mr. AJEET SINGH POONIA College of Engineering & Technology, Bikaner (An Autonomous Institute of Govt. of Rajasthan)

Upload: arvind-tilotia

Post on 08-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 1/34

A

Report

On

MEMORY MANAGEMENT

BACHELOR OF ENGINEERING

IN

COMPUTER SCIENCE & ENGINEERING

 Submitted By:-

JYOTI POONIA

Submitted To:-

HEAD

Mr. AJEET SINGH POONIA

College of Engineering & Technology, Bikaner 

(An Autonomous Institute of Govt. of Rajasthan)

Page 2: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 2/34

Acknowledgement

We express our sincere thanks to our project guide, Mr.Ajeetsingh Poonia. for guiding us right form the inception till the successful

completion of the project. We sincerely acknowledge him for extending

their valuable guidance, support for literature, critical reviews of project

and the report and above all the moral support they had provided us with

all stages of this project.

JYOTI POONIA

CSE IV year 

Page 3: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 3/34

Table of content

1.Definition

2. Tools For Monitoring

3.Getting started

4. Performance Metrics

5. Perceived Performance

6. Typical Development Process

7.Topics 

8.Agenda 

9. Theory

10. bibliography.

Page 4: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 4/34

Definition: Performance Monitoring

• An act of non-intrusively collecting or observing performancedata from an operating or running application.

• Typically a “preventative” or “proactive” type of action. But, couldbe an initial step in a reactive action.

• Can be performed in production, or qualification, or developmentenvironments.

• Helps identify or isolate potential issues without having a severeimpact on runtime responsiveness or throughput.

• Often times monitoring crosses over into trouble-shooting or service-ability.

• An act of collecting or observing performance data from anoperating or running application.

• Usually more intrusive than monitoring.

• Usually a narrower focus than monitoring.• Typically a reactive type of activity. Could be a proactive activity

in situations where performance is a well defined systemicquality or requirement for a target application.

• Seldom performed in production environments.• Commonly done in qualification, testing or development

environments.

• An act of changing tune-ables, source code and/or configurationattribute(s) for the purposes of improving applicationresponsiveness and/or application throughput.

• Usually results from monitoring and/or profiling activities.

Page 5: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 5/34

Agenda:

• Performance metrics

• Monitoring vs. Profiling

• Development process.

Getting started ::

• Performance tuning is largely an art.• There is no one approach that is always necessarily the right

approach.• And, there are performance issues which will require very specialized

expertise to identify the root cause, and / or be able to recommend a

solution.

Page 6: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 6/34

Performance Metrics:

• Throughput

• Runtime response time

• Footprint

• Perceived performance (for GUI applications)

• End-user experience on GUI applications:•

> Rarely measure performance with a stopwatch> How fast something feels, not how fast it is

• Ways to improve how fast your users feel without actually makinganything run faster 

> Changing the mouse cursor to a waiting cursor > Using multiple background threads> Showing the progress bar 

Page 7: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 7/34

Perceived Performance:

• Startup time:

> Lazy initialization is often useful.> Applets:

> Use Jar files to minimize requests.> Install on client system if possible.> Obfuscators and size reduction tools.> Run empty applet to get VM loaded.

> Applications:> Separate initialization thread.

Minimize dependencies for start screen

Page 8: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 8/34

Typical Development Process

Page 9: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 9/34

Topics

• What information to monitor• What tools to use• What level of the software stack to monitor

> Operating system level>  JVM level> Application level

• What to monitor is covered per component at a given level> Example. At OS level, monitor CPU usage

Tools For Monitoring

• Definition: An act of non-intrusively collecting or observing

performance data from an operating or running application.• What to monitor and where?

> Operating system: cpu utilization (kernel & user), networki/o, disk i/o, memory, processes and kernel (locks).

>  JVM: garbage collection frequency and duration, heapusage, threads, lock contention, cpu usage

> Application: throughput, responsiveness

 Tools for monitoring :

• cpu> vmstat (Solaris & Linux)> mpstat (Solaris)> prstat (Solaris)> top (Linux, prefer prstat on Solaris)>  Task Manager (Windows)> Performance Monitor (Windows)

Page 10: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 10/34

> xosview (Linux)> cpubar (Solaris – Performance Tools CD)> iobar (Solaris – Performance Tools CD)> dtrace (Solaris)

vmstat :

• Virtual Memory Statistics• reports virtual memory statistics of process, virtual memory,

disk, trap, and CPU activity.• cpu (breakdown of percentage usage of CPU time. On

multiprocessors this is an a verage across all processors.)

> us - user time> sy - system time> id - idle time

• Idle cpu> On multi-threaded applications and multi-core systems, idle

cpu can be an indicator of an application's inability to scale.> Combination of high sys or kernel CPU utilization and idle

CPU could indicate shared resource contention as thescalability blocker.

Page 11: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 11/34

Swing and its Feature

Swing is a set of classes that provides more powerful and flexibleComponents than

Are possible with the AWT (Abstract Window Toolkit). It Supports buttons,Chekboxes, Lables, Tabbed Panes, Scroll Panes, Trees, Tables,DialogBox, EtcThat is, its Provides a large number of GUI Controls. Swingis Compatible with AWT and Swing Component can be usedinterchangeably with AWT Components. Swing Can Only be used with the

 jdk1.1 (And Above) event model. It doesn’t support the jdk1.0 event Model.

Line2D

This Line2D represents a line segment in (x,y) coordinate space. This class,like all of the Java 2D API, uses a default coordinate system called user space in which the y-axis values increase downward and x-axis valuesincrease to the right. For more information on the user space coordinatesystem, see the Coordinate Systems section of the Java 2D Programmer's

Guide.

This class is only the abstract superclass for all objects that store a 2D linesegment. The actual storage representation of the coordinates is left to thesubclass.

Page 12: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 12/34

our application, we must import the javax. Swing package as we done inour project. The package contains the classes and interface that supportand manage the GUI components. Swing Components are platform-independent and therefore are termed as lightweight.

 

The java.awt.event Package

The java.awt.event package defines classes and interfaces used for event handling in the

AWT and Swing. The members of this package fall into three categories:

 Events 

The classes with names ending in "Event" represent specific types of events, generated by

the AWT or by one of the AWT or Swing components.

 Listeners 

The interfaces in this package are all event listeners; their names end with "Listener".

These interfaces define the methods that must be implemented by any object that wants to

 be notified when a particular event occurs. Note that there is a Listener interface for 

each Event class.

 java.lang.management Provides the management interface for monitoring

and management of the Java virtual machine as well as the operating system

on which the Java virtual machine is running. It allows both local and remote

monitoring and management of the running Java virtual machine.

Platform MXBeans

 This package defines the management interface of the following

components:

Management Interface Description

{@link Class loading system

Page 13: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 13/34

java.lang.management.ClassLoadingMXBean} of the Java virtual

machine.

{@link java.lang.management.CompilationMXBean}

Compilation system of 

the Java virtual

machine.

{@link java.lang.management.MemoryMXBean} 

Memory system of 

the Java virtual

machine.

{@link java.lang.management.ThreadMXBean}  Threads system of the

 Java virtual machine.

{@link java.lang.management.RuntimeMXBean} 

Runtime system of 

the Java virtual

machine.

{@link

java.lang.management.OperatingSystemMXBean} 

Operating system on

which the Java virtual

machine is running.

{@link

java.lang.management.GarbageCollectorMXBean} 

Garbage collector in

the Java virtual

machine.

{@link

java.lang.management.MemoryManagerMXBean} 

Memory manager in

the Java virtual

machine.

{@link java.lang.management.MemoryPoolMXBean} Memory pool in the

 Java virtual machine.

A platform MXBean is a managed bean that defines the management interface for one

component for the platform and is specified in the ManagementFactory class.

An application can monitor the instrumentation of the Java virtual machine and manage certaincharacteristics in the following ways:

• Direct access to an MXBean interface a. Get the MXBean instance through the static factory method and

access the MXBean interface locally of the running virtualmachine.

Page 14: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 14/34

b. Construct an MXBean proxy instance that forwards the methodcalls to a given {@link javax.management.MBeanServerMBeanServer} by calling {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy ManagementFactory.newPlatformMXBeanProxy}. A proxy

is typically constructed to remotely access an MXBean of anotherrunning virtual machine.• Indirect access via {@link javax.management.MBeanServer 

MBeanServer} interface a. Go through the {@link

 java.lang.management.ManagementFactory#getPlatformMBeanServer platform MBeanServer} to access MXBeans locally or aspecific MBeanServerConnection to access MXBeans remotely. The attributes and operations of an MXBean use only JMX opentypes which include basic data types, {@link javax.management.openmbean.CompositeData

CompositeData}, and {@link javax.management.openmbean.TabularData TabularData}defined in {@link javax.management.openmbean.OpenTypeOpenType}.

import java.awt.*;

import java.awt.event.*;

import java.awt.image.BufferedImage;

import java.awt.geom.Line2D;

import java.awt.geom.Rectangle2D;

import java.util.Date;

import javax.swing.*;

Page 15: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 15/34

import javax.swing.border.EtchedBorder;

import javax.swing.border.TitledBorder;

import java.lang.management.*;

import java.util.*;

public class MemoryMonitor extends JPanel {

static JCheckBox dateStampCB = new JCheckBox("Output DateStamp");

public Surface surf;

JPanel controls;

boolean doControls;

JTextField tf;

// Get memory pools.

static java.util.List<MemoryPoolMXBean> mpools =

ManagementFactory.getMemoryPoolMXBeans();

// Total number of memory pools.

static int numPools = mpools.size();

public MemoryMonitor() {

setLayout(new BorderLayout());

setBorder(new TitledBorder(new EtchedBorder(), "MemoryMonitor"));

add(surf = new Surface());

Page 16: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 16/34

controls = new JPanel();

controls.setPreferredSize(new Dimension(135,80));

Font font = new Font("serif", Font.PLAIN, 10);

JLabel label = new JLabel("Sample Rate");

label.setFont(font);

label.setForeground(Color.red);

controls.add(label);

tf = new JTextField("1000");

tf.setPreferredSize(new Dimension(45,20));

controls.add(tf);

controls.add(label = new JLabel("ms"));

label.setFont(font);

label.setForeground(Color.red);

controls.add(dateStampCB);

dateStampCB.setFont(font);

addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

removeAll();

if ((doControls = !doControls)) {

surf.stop();

add(controls);

Page 17: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 17/34

} else {

try {

surf.sleepAmount = Long.parseLong(tf.getText().trim());

} catch (Exception ex) {}

surf.start();

add(surf);

}

validate();

repaint();

}

});

}

public class Surface extends JPanel implements Runnable {

public Thread thread;

public long sleepAmount = 1000;

public int usageHistCount = 20000;

private int w, h;

private BufferedImage bimg;

private Graphics2D big;

Page 18: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 18/34

Page 19: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 19/34

usedMem = new float[numPools][];

ptNum = new int[numPools];

}

public Dimension getMinimumSize() {

return getPreferredSize();

}

public Dimension getMaximumSize() {

return getPreferredSize();

}

public Dimension getPreferredSize() {

return new Dimension(135,80);}

 public void paint(Graphics g) {

if (big == null) {

return;

}

big.setBackground(getBackground());

big.clearRect(0,0,w,h);

h = h / ((numPools + numPools%2) / 2);

Page 20: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 20/34

w = w / 2;

int k=0; // index of memory pool.

for (int i=0; i < 2;i++) {

for (int j=0; j < (numPools + numPools%2)/ 2; j++) {

plotMemoryUsage(w*i,h*j,w,h,k);

if (++k >= numPools) {

i = 3;

j = (numPools + numPools%2)/ 2;

break;

}

}

}

g.drawImage(bimg, 0, 0, this);}

public void plotMemoryUsage(int x1, int y1, int x2, int y2, intnpool) {

MemoryPoolMXBean mp = mpools.get(npool);

float usedMemory = mp.getUsage().getUsed();

float totalMemory = mp.getUsage().getMax();

// .. Draw allocated and used strings ..

Page 21: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 21/34

big.setColor(Color.green);

// 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);

big.setColor(Color.yellow);

// Print the memory pool name.

big.drawString(mp.getName(), x1+x2/2, (float) y1 +ascent+0.5f);

// Print the memory used by this memory pool.

usedStr = String.valueOf((int)usedMemory/1024)

+ "K used";

big.setColor(Color.green);

big.drawString(usedStr, x1+4, y1+y2-descent);

// Calculate remaining size

float ssH = ascent + descent;

float remainingHeight = (float) (y2 - (ssH*2) - 0.5f);

float blockHeight = remainingHeight/10;

float blockWidth = 20.0f;

float remainingWidth = (float) (x2 - blockWidth - 10);

// .. Memory Free ..

Page 22: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 22/34

big.setColor(mfColor);

int MemUsage = (int) (((totalMemory - usedMemory) /totalMemory) * 10);

int i = 0;

for ( ; i < MemUsage ; i++) {

mfRect.setRect(x1+5,(float) y1+ssH+i*blockHeight,

blockWidth,(float) blockHeight-1);

big.fill(mfRect);

}

// .. Memory Used ..

big.setColor(Color.green);

for ( ; i < 10; i++) {

muRect.setRect(x1+5,(float) y1 + ssH+i*blockHeight,

blockWidth,(float) blockHeight-1);

big.fill(muRect);

}

// .. Draw History Graph ..

if (remainingWidth <= 30) remainingWidth = (float)30;

if (remainingHeight <= ssH) remainingHeight = (float)ssH;

big.setColor(graphColor);

Page 23: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 23/34

int graphX = x1+30;

int graphY = y1 + (int) ssH;

int graphW = (int) remainingWidth;

int graphH = (int) remainingHeight;

graphOutlineRect.setRect(graphX, graphY, graphW, graphH);

big.draw(graphOutlineRect);

int graphRow = graphH/10;

// .. Draw row ..

for (int j = graphY; j <= graphH+graphY; j += graphRow) {

graphLine.setLine(graphX,j,graphX+graphW,j);

big.draw(graphLine);

// .. Draw animated column movement ..

int graphColumn = graphW/15;

if (columnInc == 0) {

columnInc = graphColumn;

}

for (int j = graphX+columnInc; j < graphW+graphX; j+=graphColumn) {

graphLine.setLine(j,graphY,j,graphY+graphH);

Page 24: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 24/34

big.draw(graphLine);

}

--columnInc;

// Plot memory usage by this memory pool.

if (usedMem[npool] == null) {

usedMem[npool] = new float[usageHistCount];

ptNum[npool] = 0;

}

// save memory usage history.

usedMem[npool][ptNum[npool]] = usedMemory;

big.setColor(Color.yellow);

int w1; // width of memory usage history.

if (ptNum[npool] > graphW) {

w1 = graphW;

} else {

w1 = ptNum[npool];

}

for (int j=graphX+graphW-w1, k=ptNum[npool]-w1; k <ptNum[npool];

k++, j++) {

Page 25: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 25/34

if (k != 0) {

if (usedMem[npool][k] != usedMem[npool][k-1]) {

int h1 = (int)(graphY + graphH * ((totalMemory –

usedMem[npool][k-1])/totalMemory));

int h2 = (int)(graphY + graphH * ((totalMemory –

usedMem[npool][k])/totalMemory));

big.drawLine(j-1, h1, j, h2);

} else {

int h1 = (int)(graphY + graphH * ((totalMemory –

usedMem[npool][k])/totalMemory));

big.fillRect(j, h1, 1, 1);

}

}

}

if (ptNum[npool]+2 == usedMem[npool].length) {

// throw out oldest point

for (int j = 1;j < ptNum[npool]; j++) {

usedMem[npool][j-1] = usedMem[npool][j];

}

--ptNum[npool];

} else {

Page 26: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 26/34

ptNum[npool]++;

}

}

public void start() {

thread = new Thread(this);

thread.setPriority(Thread.MIN_PRIORITY);

thread.setName("MemoryMonitor");

thread.start();

}

public synchronized void stop() {

thread = null;

notify();

}

public void run() {

Thread me = Thread.currentThread();

while (thread == me && !isShowing() || getSize().width == 0) {

try {

thread.sleep(500);

} catch (InterruptedException e) { return; }

Page 27: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 27/34

}

while (thread == me && isShowing()) {

Dimension d = getSize();

if (d.width != w || d.height != h) {

w = d.width;

h = d.height;

bimg = (BufferedImage) createImage(w, h);

big = bimg.createGraphics();

big.setFont(font);

FontMetrics fm = big.getFontMetrics(font);

ascent = (int) fm.getAscent();

descent = (int) fm.getDescent();

}

repaint();

try {

thread.sleep(sleepAmount);

} catch (InterruptedException e) { break; }

if (MemoryMonitor.dateStampCB.isSelected()) {

System.out.println(new Date().toString() + " " + usedStr);}

}

Page 28: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 28/34

thread = null;

}

}

// Test thread to consume memory

static class Memeater extends ClassLoader implements Runnable {

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 {

Thread.sleep(20);

} 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++) {

Page 29: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 29/34

loadNext();

}

} catch (ClassNotFoundException x) {

// ignore exception

}

}

}

Class loadNext() throws ClassNotFoundException {

// public class TestNNNNNN extends java.lang.Object{

// public TestNNNNNN();

// Code:

// 0: aload_0

// 1: invokespecial #1; //Method java/lang/Object."<init>":()V

// 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,

Page 30: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 30/34

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

String name = "Test" + Integer.toString(count++);

byte value[];

try {

Page 31: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 31/34

value = name.substring(4).getBytes("UTF-8");

} catch (java.io.UnsupportedEncodingException x) {

throw new Error();

}

// construct class file

int len = begin.length + value.length + end.length;

byte b[] = new byte[len];

int i, pos=0;

for (i=0; i<begin.length; i++) {

b[pos++] = (byte)begin[i];

}

for (i=0; i<value.length; i++) {

b[pos++] = value[i];

}

for (i=0; i<end.length; i++) {

b[pos++] = (byte)end[i];

}

return defineClass(name, b, 0, b.length);

Page 32: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 32/34

}

static int count = 100000;

}

public static void main(String s[]) {

final MemoryMonitor demo = new MemoryMonitor();

WindowListener l = new WindowAdapter() {

public void windowClosing(WindowEvent e) {System.exit(0);}

public void windowDeiconified(WindowEvent e){ demo.surf.start(); }

public void windowIconified(WindowEvent e)

{ demo.surf.stop(); }

};

JFrame f = new JFrame("MemoryMonitor");

f.addWindowListener(l);

f.getContentPane().add("Center", demo);

f.pack();

f.setSize(new Dimension(400,500));

f.setVisible(true);

Page 33: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 33/34

demo.surf.start();

 Thread thr = new Thread(new Memeater());

thr.start();

}

Bibliography: -

JAVA:

The Complete reference Java 5

Herbert Schildt

JDBC Notes

Software Engineering:

Software Engineering

Roger S.Pressma

Page 34: Project Report -Memory Monitor - Jyoti

8/6/2019 Project Report -Memory Monitor - Jyoti

http://slidepdf.com/reader/full/project-report-memory-monitor-jyoti 34/34