--- a/hotspot/test/compiler/arraycopy/TestInstanceCloneAsLoadsStores.java Mon May 11 09:44:07 2015 +0200
+++ b/hotspot/test/compiler/arraycopy/TestInstanceCloneAsLoadsStores.java Tue May 12 10:27:50 2015 +0200
@@ -25,200 +25,13 @@
* @test
* @bug 6700100
* @summary small instance clone as loads/stores
+ * @compile TestInstanceCloneAsLoadsStores.java TestInstanceCloneUtils.java
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,TestInstanceCloneAsLoadsStores::m* TestInstanceCloneAsLoadsStores
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,TestInstanceCloneAsLoadsStores::m* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressArrayCopyMacroNode TestInstanceCloneAsLoadsStores
*
*/
-import java.lang.reflect.*;
-import java.util.*;
-
-public class TestInstanceCloneAsLoadsStores {
- static class Base implements Cloneable {
- void initialize(Class c, int i) {
- for (Field f : c.getDeclaredFields()) {
- setVal(f, i);
- i++;
- }
- if (c != Base.class) {
- initialize(c.getSuperclass(), i);
- }
- }
-
- Base() {
- initialize(getClass(), 0);
- }
-
- void setVal(Field f, int i) {
- try {
- if (f.getType() == int.class) {
- f.setInt(this, i);
- return;
- } else if (f.getType() == short.class) {
- f.setShort(this, (short)i);
- return;
- } else if (f.getType() == byte.class) {
- f.setByte(this, (byte)i);
- return;
- } else if (f.getType() == long.class) {
- f.setLong(this, i);
- return;
- }
- } catch(IllegalAccessException iae) {
- throw new RuntimeException("Getting fields failed");
- }
- throw new RuntimeException("unexpected field type");
- }
-
- int getVal(Field f) {
- try {
- if (f.getType() == int.class) {
- return f.getInt(this);
- } else if (f.getType() == short.class) {
- return (int)f.getShort(this);
- } else if (f.getType() == byte.class) {
- return (int)f.getByte(this);
- } else if (f.getType() == long.class) {
- return (int)f.getLong(this);
- }
- } catch(IllegalAccessException iae) {
- throw new RuntimeException("Setting fields failed");
- }
- throw new RuntimeException("unexpected field type");
- }
-
- boolean fields_equal(Class c, Base o) {
- for (Field f : c.getDeclaredFields()) {
- if (getVal(f) != o.getVal(f)) {
- return false;
- }
- }
- if (c != Base.class) {
- return fields_equal(c.getSuperclass(), o);
- }
- return true;
- }
-
- public boolean equals(Object obj) {
- return fields_equal(getClass(), (Base)obj);
- }
-
- String print_fields(Class c, String s) {
- for (Field f : c.getDeclaredFields()) {
- if (s != "") {
- s += "\n";
- }
- s = s + f + " = " + getVal(f);
- }
- if (c != Base.class) {
- return print_fields(c.getSuperclass(), s);
- }
- return s;
- }
-
- public String toString() {
- return print_fields(getClass(), "");
- }
-
- int fields_sum(Class c, int s) {
- for (Field f : c.getDeclaredFields()) {
- s += getVal(f);
- }
- if (c != Base.class) {
- return fields_sum(c.getSuperclass(), s);
- }
- return s;
- }
-
- public int sum() {
- return fields_sum(getClass(), 0);
- }
-
- }
-
- static class A extends Base {
- int i1;
- int i2;
- int i3;
- int i4;
- int i5;
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- static class B extends A {
- int i6;
- }
-
- static final class D extends Base {
- byte i1;
- short i2;
- long i3;
- int i4;
- int i5;
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- static final class E extends Base {
- int i1;
- int i2;
- int i3;
- int i4;
- int i5;
- int i6;
- int i7;
- int i8;
- int i9;
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- static final class F extends Base {
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- static class G extends Base {
- int i1;
- int i2;
- int i3;
-
- public Object myclone() throws CloneNotSupportedException {
- return clone();
- }
- }
-
- static class H extends G {
- int i4;
- int i5;
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- static class J extends Base {
- int i1;
- int i2;
- int i3;
-
- public Object myclone() throws CloneNotSupportedException {
- return clone();
- }
- }
-
- static class K extends J {
- int i4;
- int i5;
- }
+public class TestInstanceCloneAsLoadsStores extends TestInstanceCloneUtils {
// Should be compiled as loads/stores
static Object m1(D src) throws CloneNotSupportedException {
@@ -269,62 +82,10 @@
return (J)src.myclone();
}
- final HashMap<String,Method> tests = new HashMap<>();
- {
- for (Method m : this.getClass().getDeclaredMethods()) {
- if (m.getName().matches("m[0-9]+")) {
- assert(Modifier.isStatic(m.getModifiers())) : m;
- tests.put(m.getName(), m);
- }
- }
- }
-
- boolean success = true;
-
- void doTest(Base src, String name) throws Exception {
- Method m = tests.get(name);
-
- for (int i = 0; i < 20000; i++) {
- boolean failure = false;
- Base res = null;
- int s = 0;
- if (m.getReturnType().isPrimitive()) {
- s = (int)m.invoke(null, src);
- failure = (s != src.sum());
- } else {
- res = (Base)m.invoke(null, src);
- failure = !res.equals(src);
- }
- if (failure) {
- System.out.println("Test " + name + " failed");
- System.out.println("source: ");
- System.out.println(src);
- System.out.println("result: ");
- if (m.getReturnType().isPrimitive()) {
- System.out.println(s);
- } else {
- System.out.println(res);
- }
- success = false;
- break;
- }
- }
- }
-
public static void main(String[] args) throws Exception {
TestInstanceCloneAsLoadsStores test = new TestInstanceCloneAsLoadsStores();
- A a = new A();
- B b = new B();
- D d = new D();
- E e = new E();
- F f = new F();
- G g = new G();
- H h = new H();
- J j = new J();
- K k = new K();
-
test.doTest(d, "m1");
test.doTest(d, "m2");
test.doTest(e, "m3");