Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4862677

calculation produces diffrent answers with same input using -server option

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • hotspot
    • x86
    • linux



      Name: rmT116609 Date: 05/12/2003


      FULL PRODUCT VERSION :
      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)


      FULL OS VERSION :
      Linux jupiter 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Linux version 2.4.20-8 (###@###.###) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 Thu Mar 13 17:54:28 EST 2003

      Memory: 479032k/491456k available (1347k kernel code, 9860k reserved, 999k data, 132k init, 0k highmem)

      CPU: Intel(R) Pentium(R) 4 CPU 2.00GHz stepping 04





      A DESCRIPTION OF THE PROBLEM :
      Before I provide more information I need to know if the following "problem" is really a quirk of the "-server" hotspot option or a genuine error - though hopefully I have already supplied enough!

      I am running an intensely computational task that creates an image based on the Mandlebrot using the java options "-Xms128m -Xmx256m -server" (the program actually uses less than 40 Meg according to "top").

      ==> QUESTION: Should a deterministic program (i.e. I have not included any
      ==> randomising code) always produce identical results for the same parameters
      ==> using the "-server" option?

      Because sometimes the maximum value of one calculation is "32.0382186036174" and sometimes it is "723.6530636747974" (this is the last number to be printed out prior to "Image Complete").

      Note that the images saved are different according to "diff", but I can't detect what the diffrences are.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program from within JBuilder6



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      18.384741910225674
      19.68011713159601
      20.217429056099167
      27.137319716862912
      27.974373653582617
      28.822405999778333
      32.0382186036174
      Image Complete
      ACTUAL -
      18.384741910225674
      19.68011713159601
      20.217429056099167
      27.137319716862912
      27.974373653582617
      28.822405999778333
      32.0382186036174
      723.6530636747974
      Image Complete

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no errors

      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

      ---------- BEGIN SOURCE ----------
      package gcf.graphic.mandlebrot;

      import java.awt.event.ActionEvent;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.Dimension;
      import java.awt.Toolkit;
      import javax.swing.AbstractAction;
      import javax.swing.Icon;
      import javax.swing.ImageIcon;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JComponent;
      import javax.swing.JMenuBar;
      import javax.swing.JPanel;

      public class AppMain
      {
        private final static int FRAME_WIDTH = 1280;
        private final static int FRAME_HEIGHT = 1024;

        private JFrame fJFrame = null;
        private AppMain fAppMain = null;

        private AppMain()
        {
          // the sizing of this should reflect actual area available to panel
          fJFrame = new MandImageFrame(FRAME_WIDTH, FRAME_HEIGHT);
          fJFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
          fJFrame.setJMenuBar(_makeMenuBar());
          fJFrame.addWindowListener(new MyWindowListener());
        }

        public static void main(String[] args)
        {
          AppMain appMain = new AppMain();
          appMain._go();
        }

        //
        //~~~~~~~~~~~~~~~~~~~~~ private methods ~~~~~~~~~~~~~~~~~~~~~
        //

        private void _go()
        {
          fJFrame.pack();

          Dimension vScreenSize = Toolkit.getDefaultToolkit().getScreenSize();

          int vX = (vScreenSize.width - FRAME_WIDTH) / 2;
          int vY = (vScreenSize.height - FRAME_HEIGHT) / 2;
          fJFrame.setBounds(vX, vY, FRAME_WIDTH, FRAME_HEIGHT);

          fJFrame.setVisible(true);
        }

        private JMenuBar _makeMenuBar()
        {
          JMenuBar vJMenuBar = new JMenuBar();
          vJMenuBar.add(_makeFileMenu());

          return vJMenuBar;
        }

        private JMenu _makeFileMenu()
        {
          JMenu vJMenu = new JMenu("File");
          vJMenu.add(new MyExitAction());

          return vJMenu;
        }

        private void _close()
        {
          fJFrame.dispose();
          System.exit(0);
        }

        //
        //~~~~~~~~~~~~~~~~~~~~~ inner classes ~~~~~~~~~~~~~~~~~~~~~
        //
        private class MyWindowListener
          extends WindowAdapter
        {
          public void windowClosing(WindowEvent e)
          {
            _close();
          }
        }

        private class MyExitAction
          extends AbstractAction
        {
          private MyExitAction()
          {
            super("Exit");
          }

          public void actionPerformed(ActionEvent e)
          {
            _close();
          }
        }
      }

      package gcf.graphic.mandlebrot;

      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.Image;
      import java.awt.image.BufferedImage;
      import java.awt.image.ImageObserver;
      import java.awt.image.MemoryImageSource;
      import java.awt.image.RenderedImage;
      import java.io.File;
      import java.io.IOException;
      import java.util.Random;
      import javax.imageio.ImageIO;
      import javax.swing.JFrame;


      public class MandImageFrame
        extends JFrame
        implements Runnable
      {
        private int fWidth;
        private int fHeight;
        private int fPixels[];

        private MemoryImageSource fSource;
        private Image fImage;

        private double fMaxNegativeLog = 0;

        public MandImageFrame(int pWidth, int pHeight)
        {
          super("Gavin's Mandlebrot");

          fWidth = pWidth;
          fHeight = pHeight;

          int size = fWidth * fHeight;
          fPixels = new int[size];

          int value = Color.BLACK.getRGB();

          for (int i = 0; i < size; i++)
          {
            fPixels[i] = value;
          }

          fSource = new MemoryImageSource(fWidth, fHeight, fPixels, 0, fWidth);
          Thread vThread = new Thread(this);
          vThread.start();
          fImage = createImage(fSource);
        }

        public void paint(Graphics g)
        {
          g.drawImage(fImage, 0, 0, this);

      // Graphics2D g2 = (Graphics2D) g;
      // g2.setColor(Color.CYAN);
      // Font vFont = new Font("Monospaced", Font.ITALIC, 20);
      // g2.setFont(vFont);
      // g2.drawString("gcf", 100, 200);
      }

        public boolean imageUpdate(Image img,
                                   int infoflags,
                                   int x,
                                   int y,
                                   int width,
                                   int height)
        {
          boolean vFlag = ((infoflags & ImageObserver.ALLBITS) == 0);

          if (vFlag)
          {
      // System.out.println("x: " + x + " y: " + y + " width: " + width
      // + " height: " + height);
          }
          else
          {
            System.out.println("Image Complete");

            saveImage(width, height);
          }

          repaint();

          return vFlag;
        }

        private void saveImage(int width, int height)
        {
          BufferedImage vBi = new BufferedImage(width, height,
                                                BufferedImage.TYPE_INT_RGB);

          Graphics g = vBi.getGraphics();
          g.drawImage(fImage, 0, 0, null);

          try
          {
            File vFile = new File("mandlbrot.png");
            ImageIO.write(vBi, "png", vFile);
          }
          catch (IOException ex)
          {
            ex.printStackTrace();
          }
        }

        public void run()
        {
          fSource.setAnimated(true);
          Thread thread = Thread.currentThread( );
          thread.setPriority(Thread.MIN_PRIORITY);

      // Random vRandom = new Random();

          int x = 0;
          int y = 0;
          int w = fWidth;
          int h = fHeight/2;

          // Modify the values in the pixels array at (x, y, w, h)
          for (int ii = y; ii < h; ii++)
          {
            int rowStartLo = (h + ii) * w;
            int rowStartHi = (h - ii) * w;

            for (int jj = x; jj < w; jj++)
            {
      // int pixel = vRandom.nextInt(0x01000000) | 0xFF000000;
              int pixel = calculatePixel(jj, ii);
              fPixels[rowStartLo + jj ] = pixel;
              fPixels[rowStartHi + jj ] = pixel;
            }

            // Send the new data to the interested ImageConsumers
            fSource.newPixels();
            thread.yield();
          }


          fSource.setAnimated(false);
        }

        private int calculatePixel(final int pI, final int pJ)
        {
          final double scale = 360;
          final double threshold = 4;
          final int alphaMask = 0xFF000000;
          final int rrrMask = 0x00FF0000;
          final int gggMask = 0x0000FF00;
          final int bbbMask = 0x000000FF;
          final int rgbMask = 0x00FFFFFF;
      // final double maxLogLogQ = 24.334506389032747;
          final double maxLogLogQ = 32.0382186036174;
          final double normalizer = rgbMask / maxLogLogQ;

          double x0 = (pI - 785)/scale;
          double y0 = pJ/scale;
          double xa = x0;
          double ya = y0;
          double minZSquared = threshold;

          for (int ii = 0; ii < 10000; ii++)
          {
            double xb = x0 + xa*xa - ya*ya;
            double yb = y0 + 2*xa*ya;
            xa = xb;
            ya = yb;

            double zSquared = xa*xa + ya*ya;

            if (zSquared > threshold)
            {
              break;
            }
            else if (zSquared < minZSquared)
            {
              minZSquared = zSquared;
            }
          }

          int pixel = rgbMask;


          if (minZSquared > 0)
          {
            double q = -Math.log(minZSquared/threshold);
            pixel = ((int)Math.round(normalizer*q) & rgbMask) | alphaMask;

            if (q > fMaxNegativeLog)
            {
              fMaxNegativeLog = q;
              System.out.println(q);
            }
          }

          /*
           * convert to gray scale
           */
      // int val = (pixel & rgbMask) >> 16;
      // pixel = ((val << 16) + (val << 8) + val) | alphaMask; // mainly black
      // pixel = (rgbMask - ((val << 16) + (val << 8) + val)) | alphaMask; // mainly white

          /*
           * convert to star colour scale
           * (blue is hottest, red is coldest)
           * consider the value of "q" the temperature
           * r -> b
           * g -> g
           * b -> r
           */
          int rrr = (pixel & rrrMask) >> 16;
          int ggg = (pixel & gggMask) >> 8;
          int bbb = (pixel & bbbMask);
          pixel = ((bbb << 16) + (ggg << 8) + rrr) | alphaMask;

          return pixel;
        }
      }
      ---------- END SOURCE ----------

      (Review ID: 185511)
      ======================================================================

            mpalecznsunw Michael Paleczny (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: