-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
None
-
x86
-
generic
The following code produces an erroneous ArrayStoreException inside
java.awt.Cursor.getPredefinedCursor(int).
The command line I used was:
java AWTMemLeak -iteration 6
If I turn off the JIT by using,
java -Djava.compiler=foo AWTMemLeak -iteration 6
java_g AWTMemLeak -iteration 6
then no ArrayStoreException appears.
*** AWTMemLeak.java ***
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class AWTMemLeak extends Thread
{
public static void main (String args[])
{
boolean doFinalize = false;
boolean doGC = true;
int iteration = Integer.MAX_VALUE;
int priority = Thread.NORM_PRIORITY;
String klassName = "TestFrame";
for (int i=0; i<args.length; i++) {
if (args[i].equalsIgnoreCase("-threads"))
threads = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-priority"))
priority = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-iteration"))
iteration = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-class"))
klassName = args[++i];
else if (args[i].equalsIgnoreCase("-sleep"))
sleepTime = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-finalize"))
doFinalize = true;
else if (args[i].equalsIgnoreCase("-nogc"))
doGC = false;
else {
System.err.println ("");
System.err.println (" java MemoryLeak2 [Option]");
System.err.println ("");
System.err.println (" -threads <number> Number of threads to run
");
System.err.println (" -priority <number> Priority to assigned to
test threads");
System.err.println (" -iteration <number> Number of iterations to
run");
System.err.println (" -class <string> Class name to load - Mus
t extend AWT.Frame");
System.err.println (" -sleep <number> Length of time to sleep
- default 250");
System.err.println (" -finalize Call finalization on thr
eads when all sleeping");
System.err.println (" -nogc Do not call System.gc");
System.err.println ("");
System.exit (1);
}
}
try {
sklass = Class.forName(klassName);
}
catch (ClassNotFoundException cnfx) {
System.out.println ("No such class in class path");
System.exit (2);
}
// start a seperate thread to call System.runFinalizera and System.gc
FinalizerThread finalizeThread = new FinalizerThread(doGC, doFinalize);
finalizeThread.setPriority (Thread.MAX_PRIORITY);
finalizeThread.start();
for (int i=0; i<threads; i++) {
AWTMemLeak testThread = new AWTMemLeak(iteration, klassName);
testThread.setPriority(priority);
testThread.start();
}
}
public AWTMemLeak (int iter, String klassName)
{
this.iter = iter;
this.klassName = klassName;
}
public void run ()
{
int curr = iter;
while (--curr > 0) {
try {
Frame f = (Frame) sklass.newInstance();
f.setTitle("[ id: " + id + " iter: " + (iter - curr) + "]");
dosleep ();
f.dispose ();
}
catch (OutOfMemoryError oom) {
System.err.println (id + " ran out of memory after " + (iter - curr) +
" iterations");
oom.printStackTrace ();
break;
}
catch (Throwable t) {
System.err.println (id + " got an Exception " + t);
t.printStackTrace ();
break;
}
dosleep ();
}
System.out.println ("Thread: " + id + " Done.");
System.exit(0);
}
static void dosleep () {
synchronized (syncher) { ++sleepers; }
try { Thread.sleep(sleepTime); } catch(InterruptedException ix) {}
synchronized (syncher) { --sleepers; }
}
private int iter;
private int id = ++sID;
private String klassName;
private static int sID = 0;
private static Class sklass = null;
public static int threads = 20;
public static int sleepers = 0;
public static Object syncher = new Object();
public static int sleepTime = 250;
}
class FinalizerThread extends Thread {
public FinalizerThread(boolean callGC, boolean callFinalizers) {
this.callGC = callGC;
this.callFinalizers = callFinalizers;
}
public void run() {
while (true) {
try { Thread.sleep(250); } catch(InterruptedException ix) {}
if (callGC || callFinalizers) {
synchronized (AWTMemLeak.syncher) {
if (AWTMemLeak.sleepers == AWTMemLeak.threads) {
String s = "All threads sleeping:";
if (callFinalizers) {
s += " calling System.runFinilization";
System.runFinalization();
}
if (callGC) {
s += " calling System.gc";
System.gc();
}
System.out.println (s);
}
}
}
}
}
private boolean callGC;
private boolean callFinalizers;
}
*** TestFrame.java ***
import java.awt.*;
import java.awt.event.*;
/**
* This is the FrameTest.java. that is basic frame with a
* text field and a Cancel and OK Button, a label Field.
*
* @author Vanitha Venkatraman
*/
public class TestFrame extends Frame implements ActionListener
{
public final int CANCEL_BUTTON= 1;
public final int OK_BUTTON = 2;
public final int DATA_TXT = 3;
class TF_MouseListener extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
data.setText("VM_TESTS");
}
}
class TF_Terminate extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public TestFrame()
{
super();
setTitle("Simple Frame Test");
setFont(GraphicsEnvironment.getLocalGraphicsEnvironment().
getAllFonts()[0]);
setSize(400,400);
testpanel = new Panel();
this.add(testpanel);
data = new TextField("GO_JAVA_GO");
testpanel.add(data);
cancel = new Button("Cancel");
testpanel.add(cancel);
ok = new Button("OK");
testpanel.add(ok);
title = new Label("Enter some text in textfield");
testpanel.add(title);
this.pack();
this.show();
data.addMouseListener(new TF_MouseListener());
cancel.addActionListener(this);
ok.addActionListener(this);
this.addWindowListener(new TF_Terminate());
}
public TestFrame(String title)
{
super(title);
}
public void paint(Graphics g)
{
super.paint(g);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == "Cancel") {
this.setVisible(false);
}
else if (e.getActionCommand() == "OK") {
data.setText("Hi There");
}
}
public Component getCompType(int whichComp)
{
Component compy = null;
if (whichComp == CANCEL_BUTTON)
compy = cancel;
if (whichComp == OK_BUTTON)
compy = ok;
if (whichComp == DATA_TXT)
compy = data;
return compy;
}
public static void main(String argv[])
{
TestFrame f = new TestFrame();
}
TextField data;
Button cancel, ok;
Label title;
Panel testpanel;
}
java.awt.Cursor.getPredefinedCursor(int).
The command line I used was:
java AWTMemLeak -iteration 6
If I turn off the JIT by using,
java -Djava.compiler=foo AWTMemLeak -iteration 6
java_g AWTMemLeak -iteration 6
then no ArrayStoreException appears.
*** AWTMemLeak.java ***
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class AWTMemLeak extends Thread
{
public static void main (String args[])
{
boolean doFinalize = false;
boolean doGC = true;
int iteration = Integer.MAX_VALUE;
int priority = Thread.NORM_PRIORITY;
String klassName = "TestFrame";
for (int i=0; i<args.length; i++) {
if (args[i].equalsIgnoreCase("-threads"))
threads = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-priority"))
priority = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-iteration"))
iteration = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-class"))
klassName = args[++i];
else if (args[i].equalsIgnoreCase("-sleep"))
sleepTime = new Integer(args[++i]).intValue();
else if (args[i].equalsIgnoreCase("-finalize"))
doFinalize = true;
else if (args[i].equalsIgnoreCase("-nogc"))
doGC = false;
else {
System.err.println ("");
System.err.println (" java MemoryLeak2 [Option]");
System.err.println ("");
System.err.println (" -threads <number> Number of threads to run
");
System.err.println (" -priority <number> Priority to assigned to
test threads");
System.err.println (" -iteration <number> Number of iterations to
run");
System.err.println (" -class <string> Class name to load - Mus
t extend AWT.Frame");
System.err.println (" -sleep <number> Length of time to sleep
- default 250");
System.err.println (" -finalize Call finalization on thr
eads when all sleeping");
System.err.println (" -nogc Do not call System.gc");
System.err.println ("");
System.exit (1);
}
}
try {
sklass = Class.forName(klassName);
}
catch (ClassNotFoundException cnfx) {
System.out.println ("No such class in class path");
System.exit (2);
}
// start a seperate thread to call System.runFinalizera and System.gc
FinalizerThread finalizeThread = new FinalizerThread(doGC, doFinalize);
finalizeThread.setPriority (Thread.MAX_PRIORITY);
finalizeThread.start();
for (int i=0; i<threads; i++) {
AWTMemLeak testThread = new AWTMemLeak(iteration, klassName);
testThread.setPriority(priority);
testThread.start();
}
}
public AWTMemLeak (int iter, String klassName)
{
this.iter = iter;
this.klassName = klassName;
}
public void run ()
{
int curr = iter;
while (--curr > 0) {
try {
Frame f = (Frame) sklass.newInstance();
f.setTitle("[ id: " + id + " iter: " + (iter - curr) + "]");
dosleep ();
f.dispose ();
}
catch (OutOfMemoryError oom) {
System.err.println (id + " ran out of memory after " + (iter - curr) +
" iterations");
oom.printStackTrace ();
break;
}
catch (Throwable t) {
System.err.println (id + " got an Exception " + t);
t.printStackTrace ();
break;
}
dosleep ();
}
System.out.println ("Thread: " + id + " Done.");
System.exit(0);
}
static void dosleep () {
synchronized (syncher) { ++sleepers; }
try { Thread.sleep(sleepTime); } catch(InterruptedException ix) {}
synchronized (syncher) { --sleepers; }
}
private int iter;
private int id = ++sID;
private String klassName;
private static int sID = 0;
private static Class sklass = null;
public static int threads = 20;
public static int sleepers = 0;
public static Object syncher = new Object();
public static int sleepTime = 250;
}
class FinalizerThread extends Thread {
public FinalizerThread(boolean callGC, boolean callFinalizers) {
this.callGC = callGC;
this.callFinalizers = callFinalizers;
}
public void run() {
while (true) {
try { Thread.sleep(250); } catch(InterruptedException ix) {}
if (callGC || callFinalizers) {
synchronized (AWTMemLeak.syncher) {
if (AWTMemLeak.sleepers == AWTMemLeak.threads) {
String s = "All threads sleeping:";
if (callFinalizers) {
s += " calling System.runFinilization";
System.runFinalization();
}
if (callGC) {
s += " calling System.gc";
System.gc();
}
System.out.println (s);
}
}
}
}
}
private boolean callGC;
private boolean callFinalizers;
}
*** TestFrame.java ***
import java.awt.*;
import java.awt.event.*;
/**
* This is the FrameTest.java. that is basic frame with a
* text field and a Cancel and OK Button, a label Field.
*
* @author Vanitha Venkatraman
*/
public class TestFrame extends Frame implements ActionListener
{
public final int CANCEL_BUTTON= 1;
public final int OK_BUTTON = 2;
public final int DATA_TXT = 3;
class TF_MouseListener extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
data.setText("VM_TESTS");
}
}
class TF_Terminate extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public TestFrame()
{
super();
setTitle("Simple Frame Test");
setFont(GraphicsEnvironment.getLocalGraphicsEnvironment().
getAllFonts()[0]);
setSize(400,400);
testpanel = new Panel();
this.add(testpanel);
data = new TextField("GO_JAVA_GO");
testpanel.add(data);
cancel = new Button("Cancel");
testpanel.add(cancel);
ok = new Button("OK");
testpanel.add(ok);
title = new Label("Enter some text in textfield");
testpanel.add(title);
this.pack();
this.show();
data.addMouseListener(new TF_MouseListener());
cancel.addActionListener(this);
ok.addActionListener(this);
this.addWindowListener(new TF_Terminate());
}
public TestFrame(String title)
{
super(title);
}
public void paint(Graphics g)
{
super.paint(g);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == "Cancel") {
this.setVisible(false);
}
else if (e.getActionCommand() == "OK") {
data.setText("Hi There");
}
}
public Component getCompType(int whichComp)
{
Component compy = null;
if (whichComp == CANCEL_BUTTON)
compy = cancel;
if (whichComp == OK_BUTTON)
compy = ok;
if (whichComp == DATA_TXT)
compy = data;
return compy;
}
public static void main(String argv[])
{
TestFrame f = new TestFrame();
}
TextField data;
Button cancel, ok;
Label title;
Panel testpanel;
}
- duplicates
-
JDK-4089627 java.lang.OutOfMemoryError on WinNT with JDK1.2S build from concurrency awt test
-
- Closed
-