import jdk.test.lib.Asserts;

import java.lang.reflect.Method;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;

/*
 * @test
 * @summary Test C2 substitutability test
 * @library /testlibrary /test/lib
 * @run main/othervm/timeout=3000 -XX:TieredStopAtLevel=4 C2SubstitutabilityTest
 */

public class C2SubstitutabilityTest {
    public static final int ARRAY_SIZE = 1024 * 1024 * 10;
    
    static inline class Containee {
	float f;
	short s;

	Containee(float f, short s) {
	    this.f = f;
	    this.s = s;
	}
    }
    
    static inline class Container {
	double d;
	Containee c;
	byte b;

	Container(double d, Containee c, byte b) {
	    this.d = d ;
	    this.c = c;
	    this.b = b;
	}
    }

    public static void main(String[] args) {
	C2SubstitutabilityTest test = new C2SubstitutabilityTest();
	test.checkBehaviors();
    }

    void checkBehaviors() {
	Container[] array2 = new Container[ARRAY_SIZE];
	double d  = 1.23456789;
	float f = -987.654321f;
	short s = -512;
	byte b = 127;
	Containee c = new Containee(f,s);
	Container c2 = new Container(d, c, b);
	for (int i = 0; i < array2.length; i++) {
	    array2[i] = c2;
	}
	for (int i = 0; i < array2.length; i++) {
	    Asserts.assertEquals(array2[i], c2, "Incorrect value at index " + i);
	    Asserts.assertEquals(array2[i].d, d, "Incorrect d value at index " + i);
	    Asserts.assertEquals(array2[i].c.f, f, "Incorrect f value at index " + i);
	    Asserts.assertEquals(array2[i].c.s, s, "Incorrect s value at index " + i);
	    Asserts.assertEquals(array2[i].b, b, "Incorrect b value at inde " +i);
	}
    }
}
