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

JAVA program hangs with XInitThreads call with JDK1.4, but works with JDK1.3.1

XMLWordPrintable

    • 05
    • x86, sparc
    • linux, solaris_8
    • Verified

        Name: pa48320 Date: 08/19/2003


        ==================================================================================
                                    List of Files
        ==================================================================================


        - readme.txt
        - jnitest.c
        - Test.java
        - TestDialog.java
        - ENV
        - build_NOUIHANG
        - build_UIHANG
        - jnitest.sh


        ==================================================================================
                              FILE : README
        ==================================================================================


        Environment settings to build and run the test case:
        ---------------------------------------------------

        - Edit and set the JAVA_HOME, MOTIF_HOME in the file ENV
        - Set the variable JAVA_HOME to where JDK 1.4.2 is installed
        - Set the varibale XWIN_HOME to where X11 library is present
          for ex: /usr/X11R6
        - Set the DISPLAY to where X-server is running on Linux platform

        How to build the testcase:
        -------------------------

        - Source the environment file ENV
        - run shell script build_UIHANG.sh to create a test case
          to reproduce the problem
        - run shell script build_NOUIHANG.sh, to create a test case
          which does not reproduce problem

        How to reprouce the problem:
        ---------------------------

        - Build the testcase using build_UIHANG.sh script
        - The run the testcase using following steps

        How to run the testcase:
        -------------------------

        - Source the environment file ENV
        - run shell script jnitest.sh to run the testcase
        - Click Ok , if JAVA UI comes up fine then
          problem does not reproduce, if JAVA UI comes
          up blank, and program hangs then problem reproduces
        - Click Exit to finish

        =================================================================================
                           FILE : ENV
        =================================================================================

        A) File ENV:
        -----------

        JAVA_HOME=/usr/local/java/j2sdk1.4.1_02; export JAVA_HOME
        XWIN_HOME=/usr/X11R6; export XWIN_HOME
        RMF="/bin/rm -f"; export RMF

        LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/i386/server:${JAVA_HOME}/jre/lib/i386/native_threads:${JAVA_HOME}/jre/lib/i386; export LD_LIBRARY_PATH

        CLASSPATH=.:$CLASSPATH; export CLASSPATH


        =================================================================================
                          FILE : build_UIHANG.sh
        =================================================================================

        #! /bin/sh

        if [ "x$JAVA_HOME" = 'x' ]
        then
        echo "JAVA_HOME is not set, please source the file ENV....."
        exit 1
        fi

        if [ -r $JAVA_HOME ]; then
          echo ""
        else
          echo "Error: Cannot read JAVA_HOME $JAVA_HOME exiting..."
          exit 1
        fi

        if [ "x$XWIN_HOME" = 'x' ]
        then
        echo "XWIN_HOME is not set, please source the file ENV....."
        exit 1
        fi

        if [ -r $XWIN_HOME ]; then
          echo ""
        else
          echo "Error: Cannot read XWIN_HOME $MOTIF_HOME exiting..."
          exit 1
        fi


        /bin/rm -f jnitest.o
        /bin/rm -f jnitest
        /bin/rm -f Test.class
        /bin/rm -f TestDialog.class

        /usr/bin/gcc -c jnitest.c -DUIHANG -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -I${XWIN_HOME}/include -I${XWIN_HOME}/include/X11

        /usr/bin/gcc -o jnitest jnitest.o -L${XWIN_HOME}/lib -lX11 -L${JAVA_HOME}/jre/lib/i386 -L${JAVA_HOME}/jre/lib/i386/server -L${JAVA_HOME}/jre/lib/i386/native_threads -ljvm -lhpi

        ${JAVA_HOME}/bin/javac Test.java

        ${JAVA_HOME}/bin/javac TestDialog.java


        =================================================================================
                          FILE : build_NOUIHANG.sh
        =================================================================================

        #! /bin/sh

        if [ "x$JAVA_HOME" = 'x' ]
        then
        echo "JAVA_HOME is not set, please source the file ENV....."
        exit 1
        fi

        if [ -r $JAVA_HOME ]; then
          echo ""
        else
          echo "Error: Cannot read JAVA_HOME $JAVA_HOME exiting..."
          exit 1
        fi

        if [ "x$XWIN_HOME" = 'x' ]
        then
        echo "XWIN_HOME is not set, please source the file ENV....."
        exit 1
        fi

        if [ -r $XWIN_HOME ]; then
          echo ""
        else
          echo "Error: Cannot read XWIN_HOME $MOTIF_HOME exiting..."
          exit 1
        fi


        /bin/rm -f jnitest.o
        /bin/rm -f jnitest
        /bin/rm -f Test.class
        /bin/rm -f TestDialog.class

        /usr/bin/gcc -c jnitest.c -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -I${XWIN_HOME}/include -I${XWIN_HOME}/include/X11

        /usr/bin/gcc -o jnitest jnitest.o -L${XWIN_HOME}/lib -lX11 -L${JAVA_HOME}/jre/lib/i386 -L${JAVA_HOME}/jre/lib/i386/server -L${JAVA_HOME}/jre/lib/i386/native_threads -ljvm -lhpi

        ${JAVA_HOME}/bin/javac Test.java

        ${JAVA_HOME}/bin/javac TestDialog.java


        =================================================================================
                          FILE : jnitest.sh
        =================================================================================

        #! /bin/sh

        . ./ENV

        ./jnitest


        ===================================================================================
                          FILE: jnitest.c (Test case Source code)
        ===================================================================================

        #include <jni.h>

        int main()
         {
        JavaVMOption options[2];
        JNIEnv *env;
        JavaVM *jvm;
        JavaVMInitArgs vm_args;
        long status;
        jclass cls;
        jmethodID mid;
        jint square;
        jboolean not;

        options[0].optionString = "-Djava.class.path=.";
           options[1].optionString = "-Xmx256M";
        memset(&vm_args, 0, sizeof(vm_args));
        vm_args.version = JNI_VERSION_1_2;

        vm_args.nOptions = 2;
        vm_args.options = options;

        #ifdef UIHANG
        XInitThreads();
        #endif /* UIHANG */

        status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
           printf("Starting...");

        if (status != JNI_ERR)
        {
             printf("Starting...1");
        cls = (*env)->FindClass(env, "Test");
        if(cls !=0)
        {
        //mid = (*env)->GetStaticMethodID(env, cls, "main", "(I)I");
               mid = (*env)->GetStaticMethodID(env, cls, "main", "(I)V");
               printf("MID IS %d",mid);
        if(mid !=0)
        {
        square = (*env)->CallStaticIntMethod(env, cls, mid, 5);
        printf("Result of intMethod: %d\n", square);
        }

        mid = (*env)->GetStaticMethodID(env, cls, "main", "(Z)Z");
        if(mid !=0)
        {
        not = (*env)->CallStaticBooleanMethod(env, cls, mid, 1);
        printf("Result of booleanMethod: %d\n", not);
        }
        }

        (*jvm)->DestroyJavaVM(jvm);
        return 0;
        }
        else
             printf("Java Error");
        return -1;
         }

        ===================================================================================
                          FILE: Test.java (Test case Source code)
        ===================================================================================

        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;

        public class Test extends JFrame implements ActionListener{


        public Test(){
        setSize(300,300);
        JLabel l = new JLabel();
        JButton b = new JButton("Ok");
        JButton c = new JButton("Exit");
        b.addActionListener(this);
        getContentPane().setLayout(new GridLayout(3,1));
        getContentPane().add(l);
        l.setText("Click OK to enter data, Exit to finish");
        getContentPane().add(b);
        c.addActionListener(this);
        getContentPane().add(c);
        setVisible(true);

        }

        public void actionPerformed(ActionEvent e){
                        if (e.getActionCommand().equals("Ok"))
                        {
        TestDialog t = new TestDialog(this);
                        }
                        else if(e.getActionCommand().equals("Exit"))
                        {
        System.exit(0);
                        }

        }
        public static void main(int i){
        new Test();

        }
        }



        ===================================================================================
                          FILE: TestDialog.java (Test case Source code)
        ===================================================================================


        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;

        public class TestDialog extends JDialog implements KeyListener{

        public void keyPressed(KeyEvent k){
        System.out.println("Key Pressed");
        }
        public void keyReleased(KeyEvent k){
        System.out.println("Key Released");
        }
        public void keyTyped(KeyEvent k){
        System.out.println("Key Typed");
        }
          public TestDialog(JFrame par){
        super(par,"TestDialog",true);
        addKeyListener(this);
        JPanel p = new JPanel();
        p.setLayout(new GridLayout(4,1));
        JTextField t1 = new JTextField();
        JTextField t2 = new JTextField();
        JTextField t3 = new JTextField();
        JButton b = new JButton("Ok");
        p.add(t1);
        p.add(t2);
        p.add(t3);
        p.add(b);
        getContentPane().add(p);
        setSize(300,300);
        setLocation(200,200);
        setVisible(true);

        }
        }
        (Incident Review ID: 199089)
        ======================================================================

              denis Denis Fokin (Inactive)
              pallenba Peter Allenbach (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: