Following test passes without jit but fails with jit.
Jit'ed code does not throw ArithmeticException for "division by zero".
Sadhana
$ javac X.java
$ jitc *.class
$ java X
Test c0211141 Passed
$ java -Djava.compiler=JIT X
Error at err_1 :: gi = 5 :: expected value 15
Error at err_2 :: gi = 5 :: expected value 15
Error at err_3 :: gi = 5 :: expected value 15
Error at err_4 :: gi = 5 :: expected value 15
Test c0211141 Failed
$ cat X.java
/**
** JAVATEST : The Modena JAVA Test Suite, Version 1.0, June 1996
** Copyright (c) 1996 Modena Software (I) Pvt. Ltd., All Rights Reserved
**/
/**
* Section: 2.1.1
*
* Filename: c0211141.java
*
* Purpose: Positive test for section 2.1.1, last para:
*
* "Java throws an ArithmeticException if the right-hand operand
* to an integer divide operator / or integer remainder operator
* % is zero; this is the only case where an exception is
* generated by an operator on integral types."
*
* Language Specification: October 30, 1995
*/
import Chk;
class X
{
static int gi = 0;
X() { }
byte b = 0;
short s = 0;
int i = 0;
long l = 0;
public static void chkExceptions()
{
X ox = new X();
gi = 5;
try { int j = ox.i / ox.s; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_1", "gi", gi, 15);
gi = 5;
try { long l = ox.l / ox.s; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_2", "gi", gi, 15);
gi = 5;
try { int j = ox.b % ox.s; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_3", "gi", gi, 15);
gi = 5;
try { long l = ox.b % ox.l; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_4", "gi", gi, 15);
}
public static void main(String argv[])
{ chkExceptions();
Chk.endTest("c0211141");
}
}
$ cat Chk.java
public class Chk {
Chk(){}
public static boolean ErrorFlag = false;
public static void chkByteVal(String errStr, String varName, byte val, byte expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkShortVal(String errStr, String varName, short val, short expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkCharVal(String errStr, String varName, char val, char expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkIntVal(String errStr, String varName, int val, int expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkLongVal(String errStr, String varName, long val, long expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkFloatVal(String errStr, String varName, float val, float expectedVal)
{
if(((val-expectedVal) > 0.000001) | (expectedVal-val) > 0.000001) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkDoubleVal(String errStr, String varName, double val, double expectedVal)
{
if(((val-expectedVal) > 0.000001) | (expectedVal-val) > 0.000001) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkStringVal(String errStr, String varName, String val, String expectedVal)
{
if(!val.equals(expectedVal)) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkBooleanVal(String errStr, String varName, boolean val, boolean expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkCond(String errStr, boolean cond)
{
if(!cond) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: Boolean Expr FALSE : expected TRUE");
}
}
public static void endTest(String fname)
{
if (ErrorFlag) {
System.out.println("Test "+fname+" Failed");
System.exit(1);
}
else {
System.out.println("Test "+fname+" Passed");
System.exit(0);
}
}
}
Jit'ed code does not throw ArithmeticException for "division by zero".
Sadhana
$ javac X.java
$ jitc *.class
$ java X
Test c0211141 Passed
$ java -Djava.compiler=JIT X
Error at err_1 :: gi = 5 :: expected value 15
Error at err_2 :: gi = 5 :: expected value 15
Error at err_3 :: gi = 5 :: expected value 15
Error at err_4 :: gi = 5 :: expected value 15
Test c0211141 Failed
$ cat X.java
/**
** JAVATEST : The Modena JAVA Test Suite, Version 1.0, June 1996
** Copyright (c) 1996 Modena Software (I) Pvt. Ltd., All Rights Reserved
**/
/**
* Section: 2.1.1
*
* Filename: c0211141.java
*
* Purpose: Positive test for section 2.1.1, last para:
*
* "Java throws an ArithmeticException if the right-hand operand
* to an integer divide operator / or integer remainder operator
* % is zero; this is the only case where an exception is
* generated by an operator on integral types."
*
* Language Specification: October 30, 1995
*/
import Chk;
class X
{
static int gi = 0;
X() { }
byte b = 0;
short s = 0;
int i = 0;
long l = 0;
public static void chkExceptions()
{
X ox = new X();
gi = 5;
try { int j = ox.i / ox.s; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_1", "gi", gi, 15);
gi = 5;
try { long l = ox.l / ox.s; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_2", "gi", gi, 15);
gi = 5;
try { int j = ox.b % ox.s; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_3", "gi", gi, 15);
gi = 5;
try { long l = ox.b % ox.l; }
catch (ArithmeticException a) { gi = 15; }
Chk.chkIntVal("err_4", "gi", gi, 15);
}
public static void main(String argv[])
{ chkExceptions();
Chk.endTest("c0211141");
}
}
$ cat Chk.java
public class Chk {
Chk(){}
public static boolean ErrorFlag = false;
public static void chkByteVal(String errStr, String varName, byte val, byte expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkShortVal(String errStr, String varName, short val, short expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkCharVal(String errStr, String varName, char val, char expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkIntVal(String errStr, String varName, int val, int expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkLongVal(String errStr, String varName, long val, long expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkFloatVal(String errStr, String varName, float val, float expectedVal)
{
if(((val-expectedVal) > 0.000001) | (expectedVal-val) > 0.000001) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkDoubleVal(String errStr, String varName, double val, double expectedVal)
{
if(((val-expectedVal) > 0.000001) | (expectedVal-val) > 0.000001) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkStringVal(String errStr, String varName, String val, String expectedVal)
{
if(!val.equals(expectedVal)) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkBooleanVal(String errStr, String varName, boolean val, boolean expectedVal)
{
if(val!=expectedVal) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
}
}
public static void chkCond(String errStr, boolean cond)
{
if(!cond) {
ErrorFlag=true;
System.out.println("Error at " + errStr + " :: Boolean Expr FALSE : expected TRUE");
}
}
public static void endTest(String fname)
{
if (ErrorFlag) {
System.out.println("Test "+fname+" Failed");
System.exit(1);
}
else {
System.out.println("Test "+fname+" Passed");
System.exit(0);
}
}
}