Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Java 64-bit bug?

Empfohlene Antworten

Veröffentlicht

Kann mir jemand sagen, wieso die Runtime crasht wenn ich den folgenden Code in einer 64-Bit-Runtime laufen lasse? Unter 32-bit funktionierts Problemlos.

public class LegendreTable {

  // These are the Gauss-normalized associated Legendre functions -- that

  // is, they are normal Legendre functions multiplied by

  // (n-m)!/(2n-1)!! (where (2n-1)!! = 1*3*5*...*2n-1)

  public final float[][] mP;


  // Derivative of mP, with respect to theta.

  public final float[][] mPDeriv;


  /**

   * @param maxN

   *          The maximum n- and m-values to support

   * @param thetaRad

   *          Returned functions will be Gauss-normalized P_n^m(cos(thetaRad)), with thetaRad in radians.

   */

  public LegendreTable(int maxN, float thetaRad) {

    // Compute the table of Gauss-normalized associated Legendre

    // functions using standard recursion relations. Also compute the

    // table of derivatives using the derivative of the recursion

    // relations.

    float cos = (float) Math.cos(thetaRad);

    float sin = (float) Math.sin(thetaRad);


    mP = new float[maxN + 1][];

    mPDeriv = new float[maxN + 1][];

    mP[0] = new float[] { 1.0f };

    mPDeriv[0] = new float[] { 0.0f };

    for (int n = 1; n <= maxN; n++) {

      mP[n] = new float[n + 1];

      mPDeriv[n] = new float[n + 1];

      for (int m = 0; m <= n; m++) {

        if (n == m) {

          mP[n][m] = sin * mP[n - 1][m - 1];

          mPDeriv[n][m] = cos * mP[n - 1][m - 1] + sin * mPDeriv[n - 1][m - 1];

        } else if (n == 1 || m == n - 1) {

          mP[n][m] = cos * mP[n - 1][m];

          mPDeriv[n][m] = -sin * mP[n - 1][m] + cos * mPDeriv[n - 1][m];

        } else {

          assert n > 1 && m < n - 1;

          float k = ((n - 1) * (n - 1) - m * m) / (float) ((2 * n - 1) * (2 * n - 3));

          mP[n][m] = cos * mP[n - 1][m] - k * mP[n - 2][m];

          mPDeriv[n][m] = -sin * mP[n - 1][m] + cos * mPDeriv[n - 1][m] - k * mPDeriv[n - 2][m];

        }

      }

    }

  }


  public static void main(String[] args) {

    while (true) {

      System.out.println(new LegendreTable(5, 0.5f));

    }

  }

}

Unter Mac OS X:


Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11D50)

Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

stirbt es auch

LegendreTable@5c1428ea

Invalid memory access of location 0x0 rip=0x0

Segmentation fault: 11

Außer es wird mit java -d32 LegendreTable aufgerufen. Mehr kann ich dir leider gerade auch nicht sagen, hatte allerdings schon ein Threading Problem das z.B. zwischen verschiedenen Hostbetriebssysteme aufgetreten ist... Was mir noch aufgefallen ist mit: java -Xint -d64 LegendreTable funktioniert es auch wieder.

  -Xint               Operates in interpreted-only mode.  Compilation  to

                           native code is disabled, and all bytecodes are exe-

                           cuted by the interpreter.  The performance benefits

                           offered  by the Java HotSpot VMs' adaptive compiler

                           will not be present in this mode.

Ich würde sagen das du einen Bug in der jvm gefunden hast. Müsstest halt jetzt mal sehen was für Code wirklich erzeugt wird und welche Optimierungen dann noch laufen, vielleicht erfolgt eine HotSpot Optimierung der Schleife die ungültig ist...

Bearbeitet von Wodar Hospur

Nur zur Info, mit folgender Umstellung des Codes crasht es unter Win7 64bit nicht mehr:


public class LegendreTable {

  // These are the Gauss-normalized associated Legendre functions -- that

  // is, they are normal Legendre functions multiplied by

  // (n-m)!/(2n-1)!! (where (2n-1)!! = 1*3*5*...*2n-1)

  public final float[][] mP;


  // Derivative of mP, with respect to theta.

  public final float[][] mPDeriv;

  public final int maxN;

  public final float thetaRad;

  /**

   * @param maxN

   *          The maximum n- and m-values to support

   * @param thetaRad

   *          Returned functions will be Gauss-normalized P_n^m(cos(thetaRad)), with thetaRad in radians.

   */

  public LegendreTable(int maxN, float thetaRad) {

      this.maxN=maxN;

      this.thetaRad = thetaRad;

      mP = new float[maxN + 1][];

      mPDeriv = new float[maxN + 1][];

  }

  public void calc(){

    // Compute the table of Gauss-normalized associated Legendre

    // functions using standard recursion relations. Also compute the

    // table of derivatives using the derivative of the recursion

    // relations.

    float cos = (float) Math.cos(thetaRad);

    float sin = (float) Math.sin(thetaRad);



    mP[0] = new float[] { 1.0f };

    mPDeriv[0] = new float[] { 0.0f };

    for (int n = 1; n <= maxN; n++) {

      mP[n] = new float[n + 1];

      mPDeriv[n] = new float[n + 1];

      for (int m = 0; m <= n; m++) {

        if (n == m) {

          mP[n][m] = sin * mP[n - 1][m - 1];

          mPDeriv[n][m] = cos * mP[n - 1][m - 1] + sin * mPDeriv[n - 1][m - 1];

        } else if (n == 1 || m == n - 1) {

          mP[n][m] = cos * mP[n - 1][m];

          mPDeriv[n][m] = -sin * mP[n - 1][m] + cos * mPDeriv[n - 1][m];

        } else {

          assert n > 1 && m < n - 1;

          float k = ((n - 1) * (n - 1) - m * m) / (float) ((2 * n - 1) * (2 * n - 3));

          mP[n][m] = cos * mP[n - 1][m] - k * mP[n - 2][m];

          mPDeriv[n][m] = -sin * mP[n - 1][m] + cos * mPDeriv[n - 1][m] - k * mPDeriv[n - 2][m];

        }

      }

    }

  }


  public static void main(String[] args) {

    while(true){

      LegendreTable t = new LegendreTable(5,0.5f);

      System.out.println(t);

      t.calc();

    }

  }

Bin mir zwar auch nicht sicher, wo die eigentliche Ursache des Crashs liegt, aber es ist natürlich generell keine gute Idee, aufwändige Berechnungen im Konstruktor laufen zu lassen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.