participate


Java Virtual Machine (JVM) - Synchronized blocks in Merlin-beta3 break backward compatibility w/ JDK1.2
<<   Back to Forum  |   Give us Feedback
This topic has 2 replies on 1 page.
cgeraght
Posts:4
Registered: 1/20/99
Synchronized blocks in Merlin-beta3 break backward compatibility w/ JDK1.2   
Nov 30, 2001 4:00 PM

 
I discovered that using synchronized blocks in code compiled w/ SDK1.4 compiler generates byte code that won't run under JDK1.2. Specifically, 1.2 VM throws a java.lang.IllegalMonitorStateException and terminates execution of my program when it encounters a synchronized code block. . . YIKES!

Has anyone has had similar experience(s)? (Please post here) This is a real problem for my company since our products need to be binary compatibile back to JDK 1.2.x.

Chris
San Mateo, CA

PS -- I submitted this apparent bug to Sun yesterday.

========================
MY ENVIRONMENT
**1.4 environment** (compile code w/ javac.exe)
C:\jdk1.4.0\bin\java -version
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

**1.2 environment** (execute bytecode w/ java.exe)
C:\jdk1.2.2\bin\java -version
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)

========================
You can reproduce the behavior by compiling the code in Merlin's javac:

C:\jdk1.4.0\bin>javac C:\Test\TestSynchronizedBlock.java

and running the bytecode in JDK1.2:

C:\Test>C:\jdk1.2.2\bin\java TestSynchronizedBlock

Example source code:

============== BEGIN CODE ==============
public class TestSynchronizedBlock
{
 
  public TestSynchronizedBlock()
  {
    super();
    
    synchronized(this)
    {
      System.out.println("Hello World!");
    }
  }
  
  public static void main(java.lang.String[] args)
  {
    TestSynchronizedBlock test = new TestSynchronizedBlock();
  }
  }
============== END OF CODE ==============

Will result in output like this:
Hello World!
Exception in thread "main" java.lang.IllegalMonitorStateException: current thread not owner
        at TestSynchronizedBlock.main(TestSynchronizedBlock.java:16)


Workaround: You can use a static method instead, which seems to run ok -- try something like this:

============== BEGIN CODE ==============
public class TestSynchronizedBlock2
{
 
  public TestSynchronizedBlock2()
  {
    super();
    
    //synchronized(this)
    {
      // call synchronized method instead
      SynchronizedMethod();
    }
  }
 
  synchronized void SynchronizedMethod()
  {
    System.out.println("Hello World!");
  }
  
  public static void main(java.lang.String[] args)
  {
    TestSynchronizedBlock2 test = new TestSynchronizedBlock2();
  }
  }
============== END OF CODE ==============
 
cmccorvey
Posts:2,347
Registered: 12/07/98
Re: Synchronized blocks in Merlin-beta3 break backward compatibility w/ JDK1.2   
Dec 3, 2001 3:49 AM (reply 1 of 2)  (In reply to original post )

 
This works for me when I use the Symantec Java 1.2 runtime:
java version "1.2.2.Symc"
Classic VM (build 1.2.2.Symc, native threads, symantec gc, symcjit)

I don't have the 1.2.2 JDK installed, so I cannot verify it.

Did you try using -target 1.1 on the compiler?

Chuck
 
schapel
Posts:2,586
Registered: 6/22/99
Re: Synchronized blocks in Merlin-beta3 break backward compatibility w/ JDK   
Dec 3, 2001 7:59 AM (reply 2 of 2)  (In reply to #1 )

 
Hmmm... is there a specific reason that you should use -target 1.1 in order for the bytecode to be compatible with JRE 1.2? It seems to be you'd want to use -target 1.2.

Information about the -target option to javac is in the documentation for that command: Go to http://java.sun.com/docs/ then click on J2SDK 1.4 documentation, Tool Docs, javac.
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 27
  • Guests : 128

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums