/hotspot
build
*.iml
+hs_err*
+core
test {
executable new File(targetJreFile, 'bin/java')
+ systemProperty 'dcevm.test.light', (flavor == 'light')
+
if (kind == 'fastdebug') {
jvmArgs '-XX:LogFile=build/hotspot.log'
}
ignoreFailures = true
outputs.upToDateWhen { false }
- exclude '**/*Suite.class'
+ useJUnit {
+ excludeCategories ('com.github.dcevm.test.category.' + (flavor == 'light' ? 'Full' : 'Light'))
+ }
}
test.dependsOn project(':hotspot').tasks[kind == 'fastdebug' ? 'installFastdebug' : 'installProduct']
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+@Retention(RetentionPolicy.CLASS)
+public @interface FieldRedefinitionPolicy {
+
+ RedefinitionPolicy value();
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+@Retention(RetentionPolicy.CLASS)
+public @interface MethodRedefinitionPolicy {
+ RedefinitionPolicy value();
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+public enum RedefinitionPolicy {
+ StaticCheck,
+ DynamicCheck,
+ AccessDeletedMembers,
+ AccessOldMembers
+}
*/
package com.github.dcevm;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.*;
import org.objectweb.asm.commons.Remapper;
+import org.objectweb.asm.commons.RemappingAnnotationAdapter;
import org.objectweb.asm.commons.RemappingClassAdapter;
import org.objectweb.asm.commons.RemappingMethodAdapter;
protected MethodVisitor createRemappingMethodAdapter(
int access,
String newDesc,
- MethodVisitor mv)
- {
+ MethodVisitor mv) {
return new RemappingMethodAdapter(access, newDesc, mv, remapper) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
int pos = name.indexOf(METHOD_SUFFIX);
return (pos != -1) ? name.substring(0, pos) : name;
}
+
+ @Override
+ public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
+ AnnotationVisitor av = super.visitAnnotation(remapper.mapDesc(desc), visible);
+ return av == null ? null : new RemappingAnnotationAdapter(av, remapper) {
+ @Override
+ public void visitEnum(String name, String enumDesc, String value) {
+ if (Type.getType(enumDesc).getClassName().equals(RedefinitionPolicy.class.getName())) {
+ RedefinitionPolicy valueAsEnum = RedefinitionPolicy.valueOf(value);
+ if (Type.getType(desc).getClassName().equals(FieldRedefinitionPolicy.class.getName())) {
+ cv.visitAttribute(new SingleByteAttribute(FieldRedefinitionPolicy.class.getSimpleName(), (byte) valueAsEnum.ordinal()));
+ }
+ if (Type.getType(desc).getClassName().equals(MethodRedefinitionPolicy.class.getName())) {
+ cv.visitAttribute(new SingleByteAttribute(MethodRedefinitionPolicy.class.getSimpleName(), (byte) valueAsEnum.ordinal()));
+ }
+ }
+ super.visitEnum(name, desc, value);
+ }
+ };
+ }
+
+ private static class SingleByteAttribute extends Attribute {
+ private byte value;
+
+ public SingleByteAttribute(String name, byte value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ protected ByteVector write(ClassWriter writer, byte[] code, int len, int maxStack, int maxLocals) {
+ return new ByteVector().putByte(value);
+ }
+ }
+
}
+++ /dev/null
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test;
-
-import com.github.dcevm.test.body.BodyTestSuite;
-import com.github.dcevm.test.eval.EvalTestSuite;
-import com.github.dcevm.test.fields.FieldsTestSuite;
-import com.github.dcevm.test.methods.MethodsTestSuite;
-import com.github.dcevm.test.structural.StructuralTestSuite;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Summarizes all available test suites.
- *
- * @author Thomas Wuerthinger
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- BodyTestSuite.class,
- EvalTestSuite.class,
- MethodsTestSuite.class,
- FieldsTestSuite.class,
- StructuralTestSuite.class
-})
-public class LightTestSuite {
-}
* @author Thomas Wuerthinger
*/
public class TestUtil {
-
- public static final boolean LIGHT = true;
+ public static final boolean LIGHT = Boolean.getBoolean("dcevm.test.light");
public static int assertException(Class exceptionClass, Runnable run) {
return assertException(UnsupportedOperationException.class, run);
}
- public static void assertUnsupportedToVersion(final Class clazz, final int version) {
- TestUtil.assertUnsupported(new Runnable() {
- @Override
- public void run() {
- HotSwapTool.toVersion(clazz, version);
- }
- });
- }
-
public static void assertUnsupportedToVersionWithLight(final Class clazz, final int version) {
TestUtil.assertUnsupportedWithLight(new Runnable() {
@Override
+++ /dev/null
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test.body;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Class redefinition tests that swap only method bodies and change nothing else. This test cases should also
- * run with the current version of HotSpot.
- *
- * @author Thomas Wuerthinger
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses(
- {
- StaticTest.class,
- SimpleStaticTest.class,
- MultipleThreadsTest.class,
- OldActivationTest.class,
- RefactorActiveMethodTest.class,
- StressTest.class,
- FacTest.class,
- FibTest.class,
- RedefinePrivateMethodTest.class,
- ClassRenamingTestCase.class,
- EMCPTest.class,
- ArrayTest.class
- })
-public class BodyTestSuite {
-}
import java.util.ArrayList;
import java.util.List;
-import static junit.framework.Assert.assertNull;
import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
--- /dev/null
+package com.github.dcevm.test.category;
+
+/**
+ * Tests which are only supported by full flavor of DCEVM.
+ */
+public interface Full {
+}
--- /dev/null
+package com.github.dcevm.test.category;
+
+/**
+ * Tests which are only supported by light flavor of DCEVM (for example, tests verifying certain
+ * operation is prohibited on light flavor).
+ */
+public interface Light {
+}
+++ /dev/null
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test.eval;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Tests used for evaluation purposes (especially performance measurements).
- *
- * @author Thomas Wuerthinger
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- FractionTest.class,
- GeometryScenario.class,
- AddingInterfaceTest.class
-})
-public class EvalTestSuite {
-}
--- /dev/null
+/*\r
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
+ *\r
+ * This code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 only, as\r
+ * published by the Free Software Foundation.\r
+ *\r
+ * This code is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * version 2 for more details (a copy is included in the LICENSE file that\r
+ * accompanied this code).\r
+ *\r
+ * You should have received a copy of the GNU General Public License version\r
+ * 2 along with this work; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
+ * or visit www.oracle.com if you need additional information or have any\r
+ * questions.\r
+ *\r
+ */\r
+package com.github.dcevm.test.fields;\r
+\r
+import com.github.dcevm.test.TestUtil;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
+import static org.junit.Assert.assertEquals;\r
+\r
+/**\r
+ * Tests for accessing a deleted field. In the first scenario, the field is deleted from the class.\r
+ * In the second scenario, it is deleted because of a changed subtype relationship.\r
+ *\r
+ * @author Thomas Wuerthinger\r
+ */\r
+public class AccessDeletedFieldTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ __toVersion__(0);\r
+ }\r
+\r
+ // Version 0\r
+ public static class A {\r
+\r
+ public int x;\r
+\r
+ int getFieldInOldCode() {\r
+ \r
+ __toVersion__(1);\r
+\r
+ // This field does no longer exist\r
+ return x;\r
+ }\r
+ }\r
+\r
+ public static class B extends A {\r
+ }\r
+\r
+ // Version 1\r
+ public static class A___1 {\r
+ }\r
+\r
+ // Version 2\r
+ public static class B___2 {\r
+ }\r
+\r
+ // Method to enforce cast (otherwise bytecodes become invalid in version 2)\r
+ public static A convertBtoA(Object b) {\r
+ return (A) b;\r
+ }\r
+\r
+ @Test\r
+ public void testOldCodeAccessesDeletedField() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ final A a = new A();\r
+ a.x = 1;\r
+\r
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ assertEquals(0, a.getFieldInOldCode());\r
+ }\r
+ });\r
+\r
+ assert __version__() == 1;\r
+ __toVersion__(0);\r
+ assertEquals(0, a.x);\r
+ }\r
+\r
+ @Test\r
+ public void testAccessDeletedField() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ final A a = new A();\r
+ a.x = 1;\r
+\r
+ assertEquals(1, a.x);\r
+\r
+ __toVersion__(1);\r
+\r
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ System.out.println(a.x);\r
+ }\r
+ });\r
+\r
+ __toVersion__(0);\r
+ assertEquals(0, a.x);\r
+ }\r
+\r
+ @Test\r
+ public void testAccessDeleteBaseClassFieldNormal() {\r
+\r
+ __toVersion__(0);\r
+ assert __version__() == 0;\r
+ final B b = new B();\r
+ b.x = 1;\r
+ final A a = new A();\r
+ a.x = 2;\r
+\r
+ assertEquals(1, b.x);\r
+ assertEquals(2, a.x);\r
+\r
+ __toVersion__(2);\r
+\r
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ System.out.println(b.x);\r
+ }\r
+ });\r
+\r
+ assertEquals(2, a.x);\r
+\r
+ __toVersion__(0);\r
+ assertEquals(0, b.x);\r
+ }\r
+\r
+ @Test\r
+ public void testAccessDeleteBaseClassFieldInvalid() {\r
+\r
+ __toVersion__(0);\r
+ assert __version__() == 0;\r
+ final B b = new B();\r
+ final A a1 = new A();\r
+ a1.x = 1;\r
+ b.x = 1;\r
+\r
+ __toVersion__(2);\r
+\r
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ System.out.println(b.x);\r
+ }\r
+ });\r
+\r
+ assertEquals(1, a1.x);\r
+\r
+ __toVersion__(0);\r
+ assertEquals(0, b.x);\r
+ assertEquals(1, a1.x);\r
+\r
+ A a = convertBtoA(b);\r
+\r
+ assertEquals(0, b.x);\r
+\r
+ // Must fail, because now an instance of B is in a local variable of type A!\r
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ __toVersion__(2);\r
+ }\r
+ });\r
+\r
+ assertEquals(0, a.x);\r
+\r
+ // Still at version 0\r
+ assert __version__() == 0;\r
+ }\r
+}\r
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.test.fields;
+
+import com.github.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for accessing a deleted static field.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class AccessDeletedStaticFieldTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public static int x;
+
+ static int getFieldInOldCode() {
+
+ __toVersion__(1);
+
+ newMethodFromOldCode();
+
+ // This field does no longer exist
+ return x;
+ }
+
+ static int getFieldEMCPMethod() {
+ __toVersion__(2);
+ return A.x;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+ }
+
+ // Version 2
+
+ public static class A___2 {
+
+ // EMCP to method in version 0
+ static int getFieldEMCPMethod() {
+ __toVersion__(2);
+ return A.x;
+ }
+ }
+
+ private static void newMethodFromOldCode() {
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+ @Override
+ public void run() {
+ System.out.println(A.x);
+ }
+ });
+ }
+
+ @Test
+ public void testAccessDeletedStaticField() {
+
+ assert __version__() == 0;
+
+ A.x = 1;
+ assertEquals(1, A.getFieldInOldCode());
+
+ assert __version__() == 1;
+ __toVersion__(0);
+ assertEquals(0, A.x);
+
+ assert __version__() == 0;
+ }
+
+
+ @Test
+ public void testAccessDeletedStaticFieldFromEMCPMethod() {
+
+ assert __version__() == 0;
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+ @Override
+ public void run() {
+ System.out.println(A.getFieldEMCPMethod());
+ }
+ });
+
+ __toVersion__(0);
+ assertEquals(0, A.x);
+
+ assert __version__() == 0;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test.fields;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Class redefinition tests that may change the methods and fields of class, but do not change the superklass or the implemented
- * interface.
- *
- * @author Thomas Wuerthinger
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- FieldChangedOrderTest.class,
- FieldModificationTest.class,
- ObjectStressTest.class,
- YieldTest.class,
- ComplexFieldTest.class,
- FieldAlignmentTest.class,
- StringFieldTest.class,
- RedefinePrivateFieldTest.class,
- EnumTest.class
-})
-public class FieldsTestSuite {
-}
import org.junit.Before;
import org.junit.Test;
-import java.lang.annotation.*;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test case that calls an interface method that was deleted through class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class CallDeletedInterfaceMethodTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static interface I {
+ public int foo();
+ }
+
+ public static class A implements I {
+ @Override
+ public int foo() {
+ return 1;
+ }
+ }
+
+ public static class Helper {
+ public static int process(I i) {
+ __toVersion__(1);
+ return i.foo();
+ }
+ }
+
+ // Version 1
+ public static interface I___1 {
+
+ }
+
+ public static class Helper___1 {
+ public static int process(I i) {
+ return 2;
+ }
+ }
+
+ @Test
+ public void testOldCodeCallsDeletedInterfaceMethod() {
+
+ assert __version__() == 0;
+ A a = new A();
+
+ assertEquals(1, Helper.process(a));
+ assert __version__() == 1;
+ assertEquals(2, Helper.process(a));
+
+ __toVersion__(0);
+
+ assertEquals(1, Helper.process(a));
+ assert __version__() == 1;
+ assertEquals(2, Helper.process(a));
+
+ __toVersion__(0);
+ }
+}
--- /dev/null
+/*\r
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
+ *\r
+ * This code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 only, as\r
+ * published by the Free Software Foundation.\r
+ *\r
+ * This code is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * version 2 for more details (a copy is included in the LICENSE file that\r
+ * accompanied this code).\r
+ *\r
+ * You should have received a copy of the GNU General Public License version\r
+ * 2 along with this work; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
+ * or visit www.oracle.com if you need additional information or have any\r
+ * questions.\r
+ *\r
+ */\r
+\r
+package com.github.dcevm.test.methods;\r
+\r
+import com.github.dcevm.MethodRedefinitionPolicy;\r
+import com.github.dcevm.RedefinitionPolicy;\r
+import junit.framework.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
+import static org.junit.Assert.assertEquals;\r
+\r
+/**\r
+ * Test case that calls a virtual method that was deleted through class redefinition.\r
+ *\r
+ * @author Thomas Wuerthinger\r
+ */\r
+public class CallDeletedMethodTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ __toVersion__(0);\r
+ }\r
+\r
+ // Version 0\r
+ public static class A {\r
+\r
+ public int value() {\r
+ return 5;\r
+ }\r
+\r
+ public int oldMethod() {\r
+ __toVersion__(1);\r
+ return deletedMethod();\r
+ }\r
+\r
+ public int deletedMethod() {\r
+ return 1;\r
+ }\r
+ }\r
+\r
+ // Version 1\r
+ @MethodRedefinitionPolicy(RedefinitionPolicy.AccessDeletedMembers)\r
+ public static class A___1 {\r
+\r
+ public int oldMethod() {\r
+ return 2;\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testOldCodeCallsDeletedMethod() {\r
+\r
+ assert __version__() == 0;\r
+ A a = new A();\r
+\r
+ assertEquals(1, a.oldMethod());\r
+ assert __version__() == 1;\r
+ assertEquals(2, a.oldMethod());\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.oldMethod());\r
+ assert __version__() == 1;\r
+ assertEquals(2, a.oldMethod());\r
+\r
+ __toVersion__(0);\r
+ }\r
+\r
+ @Test\r
+ public void testNewCodeCallsDeletedMethod() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ A a = new A();\r
+ assertEquals(5, a.value());\r
+ \r
+ __toVersion__(1);\r
+\r
+ try {\r
+ a.value();\r
+ Assert.fail("NoSuchMethodError exception must be thrown!");\r
+ } catch (NoSuchMethodError e) {\r
+ // Expected exception\r
+ }\r
+\r
+ __toVersion__(0);\r
+ assertEquals(5, a.value());\r
+ }\r
+}\r
package com.github.dcevm.test.methods;
-import junit.framework.Assert;
import com.github.dcevm.test.TestUtil;
+import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test.methods;
-
-import junit.framework.Assert;
-import com.github.dcevm.test.TestUtil;
-import org.junit.Before;
-import org.junit.Test;
-
-import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
-import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
-import static org.junit.Assert.assertEquals;
-
-/**
- * Test cases that delete a method that is currently active on the stack.
- *
- * @author Thomas Wuerthinger
- */
-public class DeleteActiveMethodTest {
-
- @Before
- public void setUp() throws Exception {
- __toVersion__(0);
- }
-
- // Version 0
- public static class A {
-
- boolean firstCall;
-
- public int value() {
- firstCall = true;
- return helperValue();
- }
-
- public int helperValue() {
-
- if (!firstCall) {
- return -1;
- }
- firstCall = false;
-
- Thread t = new Thread(new Runnable() {
-
- @Override
- public void run() {
- __toVersion__(1);
- }
- });
- t.start();
-
- try {
- do {
- this.helperValue();
- } while (t.isAlive());
- this.helperValue();
- Assert.fail("Exception expected!");
- } catch (NoSuchMethodError e) {
- }
-
- try {
- t.join();
- } catch (InterruptedException e) {
- }
-
- return 1;
- }
- }
-
- public static class B {
-
- public int fac(int x) {
- if (x == 0) {
- __toVersion__(1);
- }
-
- return x * fac(x - 1);
- }
- }
-
- // Version 1
- public static class A___1 {
-
- boolean firstCall;
-
- public int value() {
- __toVersion__(0);
- return 2;
- }
- }
-
- public static class B___1 {
- }
-
- @Test
- public void testDeleteActiveMethodSimple() {
- assert __version__() == 0;
-
- final B b = new B();
- TestUtil.assertException(NoSuchMethodError.class, new Runnable() {
- @Override
- public void run() {
- b.fac(5);
- }
- });
-
- assert __version__() == 1;
-
- __toVersion__(0);
- assert __version__() == 0;
- }
-
- @Test
- public void testDeleteActiveMethod() {
- assert __version__() == 0;
-
- A a = new A();
-
- assertEquals(1, a.value());
- assert __version__() == 1;
-
- assertEquals(2, a.value());
- assert __version__() == 0;
-
- assertEquals(1, a.value());
- assert __version__() == 1;
-
- assertEquals(2, a.value());
- assert __version__() == 0;
-
- assertEquals(1, a.value());
- assert __version__() == 1;
-
- assertEquals(2, a.value());
- assert __version__() == 0;
- }
-}
+/*\r
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
+ *\r
+ * This code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 only, as\r
+ * published by the Free Software Foundation.\r
+ *\r
+ * This code is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * version 2 for more details (a copy is included in the LICENSE file that\r
+ * accompanied this code).\r
+ *\r
+ * You should have received a copy of the GNU General Public License version\r
+ * 2 along with this work; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
+ * or visit www.oracle.com if you need additional information or have any\r
+ * questions.\r
+ *\r
+ */\r
+\r
+package com.github.dcevm.test.methods;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import com.github.dcevm.MethodRedefinitionPolicy;\r
+import com.github.dcevm.RedefinitionPolicy;\r
+import com.github.dcevm.test.TestUtil;\r
+import junit.framework.Assert;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
+\r
+/**\r
+ * Test cases that delete a method that is currently active on the stack.\r
+ *\r
+ * @author Thomas Wuerthinger\r
+ */\r
+public class DeleteActiveMethodTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ __toVersion__(0);\r
+ }\r
+\r
+ // Version 0\r
+ public static class A {\r
+\r
+ boolean firstCall;\r
+\r
+ public int value() {\r
+ firstCall = true;\r
+ return helperValue();\r
+ }\r
+\r
+ public int helperValue() {\r
+\r
+ if (!firstCall) {\r
+ return -1;\r
+ }\r
+ firstCall = false;\r
+\r
+ Thread t = new Thread(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ __toVersion__(1);\r
+ }\r
+ });\r
+ t.start();\r
+\r
+ try {\r
+ while (t.isAlive()) {\r
+ try {\r
+ this.helperValue();\r
+ Thread.sleep(500);\r
+ } catch (InterruptedException e) {\r
+ }\r
+ helperValue();\r
+ }\r
+ Assert.fail("Exception expected!");\r
+ } catch (NoSuchMethodError e) {\r
+ }\r
+\r
+ try {\r
+ t.join();\r
+ } catch (InterruptedException e) {\r
+ }\r
+\r
+ return 1;\r
+ }\r
+ }\r
+\r
+ public static class B {\r
+\r
+ public int fac(int x) {\r
+ if (x == 0) {\r
+ __toVersion__(1);\r
+ }\r
+\r
+ return x * fac(x - 1);\r
+ }\r
+ }\r
+\r
+ // Version 1\r
+ @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)\r
+ public static class A___1 {\r
+\r
+ boolean firstCall;\r
+\r
+ public int value() {\r
+ __toVersion__(0);\r
+ return 2;\r
+ }\r
+ }\r
+\r
+ @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)\r
+ public static class B___1 {\r
+ }\r
+\r
+ @Test\r
+ public void testDeleteActiveMethodSimple() {\r
+ assert __version__() == 0;\r
+\r
+ final B b = new B();\r
+ TestUtil.assertException(NoSuchMethodError.class, new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ b.fac(5);\r
+ }\r
+ });\r
+ \r
+ assert __version__() == 1;\r
+ \r
+ __toVersion__(0);\r
+ assert __version__() == 0;\r
+ }\r
+\r
+ @Test\r
+ public void testDeleteActiveMethod() {\r
+ assert __version__() == 0;\r
+\r
+ A a = new A();\r
+\r
+ assertEquals(1, a.value());\r
+ assert __version__() == 1;\r
+\r
+ assertEquals(2, a.value());\r
+ assert __version__() == 0;\r
+\r
+ assertEquals(1, a.value());\r
+ assert __version__() == 1;\r
+\r
+ assertEquals(2, a.value());\r
+ assert __version__() == 0;\r
+\r
+ assertEquals(1, a.value());\r
+ assert __version__() == 1;\r
+\r
+ assertEquals(2, a.value());\r
+ assert __version__() == 0;\r
+ }\r
+}\r
+++ /dev/null
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test.methods;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Class redefinition tests that perform adding/removing/changing the methods of a class.
- *
- * @author Thomas Wuerthinger
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- AddMethodTest.class,
- DeleteActiveMethodTest.class,
- ClassReflectionTest.class,
- MethodReflectionTest.class,
- ClassObjectSynchronizationTest.class,
- ClassObjectHashcodeTest.class,
- OverrideMethodTest.class,
- SingleClassTest.class,
- SingleClassReflectionTest.class,
- AnnotationTest.class
-})
-public class MethodsTestSuite {
-}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test case that makes sure that old code does not get on-stack-replaced.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class OldCodeNonOSRTest {
+
+ // Chose high enough to make sure method could get OSR (usually the OSR flag in the VM is set to about 15000)
+ private static final int N = 100000;
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 5;
+ }
+
+ public int oldMethod() {
+ __toVersion__(1);
+ int sum = 0;
+ for (int i=0; i<N; i++) {
+ sum += i;
+ }
+ return (sum & deletedMethod()) | 1;
+ }
+
+ public int oldMethod2() {
+ int sum = 0;
+ for (int i=0; i<N; i++) {
+ sum += i;
+ }
+ __toVersion__(1);
+ return (sum & deletedMethod()) | 1;
+ }
+
+ public int oldMethod3() {
+ int sum = 0;
+ for (int i=0; i<N; i++) {
+ sum += i;
+ }
+ __toVersion__(1);
+ for (int i=0; i<N; i++) {
+ sum += i;
+ }
+ return (sum & deletedMethod()) | 1;
+ }
+
+ public int deletedMethod() {
+ return 1;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int oldMethod() {
+ return 2;
+ }
+ }
+
+ @Test
+ public void testOldCodeNonOSR() {
+
+ assert __version__() == 0;
+ A a = new A();
+
+ assertEquals(1, a.oldMethod());
+ assert __version__() == 1;
+ assertEquals(2, a.oldMethod());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.oldMethod2());
+ assert __version__() == 1;
+ assertEquals(2, a.oldMethod());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.oldMethod3());
+ assert __version__() == 1;
+ assertEquals(2, a.oldMethod());
+
+ __toVersion__(0);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.natives;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testing correct resolving of a native method after class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class SimpleNativeTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public static int get() {
+ return value();
+ }
+
+ public static native int value();
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public static int get() {
+ return value() + value2();
+ }
+
+ public static native int value();
+
+ public static native int value2();
+ }
+
+ @Test
+ public void testSimpleNativeCalls() {
+
+ assert __version__() == 0;
+
+
+ assertEquals(1, A.get());
+
+ __toVersion__(1);
+
+ assertEquals(3, A.get());
+
+ __toVersion__(0);
+
+ assertEquals(1, A.get());
+
+ }
+
+}
--- /dev/null
+/*\r
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
+ *\r
+ * This code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 only, as\r
+ * published by the Free Software Foundation.\r
+ *\r
+ * This code is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * version 2 for more details (a copy is included in the LICENSE file that\r
+ * accompanied this code).\r
+ *\r
+ * You should have received a copy of the GNU General Public License version\r
+ * 2 along with this work; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
+ * or visit www.oracle.com if you need additional information or have any\r
+ * questions.\r
+ *\r
+ */\r
+\r
+package com.github.dcevm.test.structural;\r
+\r
+import org.junit.Before;\r
+import org.junit.Ignore;\r
+import org.junit.Test;\r
+\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
+import static org.junit.Assert.*;\r
+\r
+/**\r
+ * Smallest test case for a hierarchy swap. A<B is changed to B<A.\r
+ *\r
+ * @author Thomas Wuerthinger\r
+ */\r
+@Ignore\r
+public class HierarchySwapTest {\r
+\r
+ // Version 0\r
+ public static class A {\r
+\r
+ public int value() {\r
+ return 1;\r
+ }\r
+ }\r
+\r
+ public static class B extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class C {\r
+\r
+ public boolean doInstanceCheckA(Object o) {\r
+ return o instanceof A;\r
+ }\r
+\r
+ public boolean doInstanceCheckB(Object o) {\r
+ return o instanceof B;\r
+ }\r
+ }\r
+\r
+ public static class Base {\r
+\r
+ public String className() {\r
+ return "Base";\r
+ }\r
+ }\r
+\r
+ public static class D extends Base {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "D";\r
+ }\r
+\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class E extends Base {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "E";\r
+ }\r
+\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class F extends Base {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "F";\r
+ }\r
+\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ // Version 1\r
+ public static class A___1 extends B___1 {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class B___1 {\r
+\r
+ public int value() {\r
+ return 4;\r
+ }\r
+ }\r
+\r
+ public static class C___1 {\r
+\r
+ public boolean doInstanceCheckA(Object o) {\r
+ return o instanceof A;\r
+ }\r
+\r
+ public boolean doInstanceCheckB(Object o) {\r
+ return o instanceof B;\r
+ }\r
+ }\r
+\r
+ // Version 2\r
+ public static class D___2 extends Base {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "D";\r
+ }\r
+\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class E___2 extends D {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "E";\r
+ }\r
+\r
+ @Override\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class F___2 extends E {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "F";\r
+ }\r
+\r
+ @Override\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ // Version 3\r
+ public static class D___3 extends E {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "D";\r
+ }\r
+\r
+ @Override\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class E___3 extends F {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "E";\r
+ }\r
+\r
+ @Override\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class F___3 extends Base {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "F";\r
+ }\r
+\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ // Version 4\r
+ public static class D___4 extends E {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "D";\r
+ }\r
+\r
+ @Override\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class E___4 extends Base {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "E";\r
+ }\r
+\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ public static class F___4 extends E {\r
+\r
+ @Override\r
+ public String className() {\r
+ return "F";\r
+ }\r
+\r
+ @Override\r
+ public String superClassName() {\r
+ return super.className();\r
+ }\r
+ }\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ __toVersion__(0);\r
+ }\r
+\r
+ @Test\r
+ public void testHierarchySwap() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ A a = new A();\r
+ B b = new B();\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertTrue(b.getClass().getSuperclass().equals(A.class));\r
+ assertFalse(a.getClass().getSuperclass().equals(B.class));\r
+\r
+ __toVersion__(1);\r
+\r
+ assertEquals(8, a.value());\r
+ assertEquals(4, b.value());\r
+ assertFalse(b.getClass().getSuperclass().equals(A.class));\r
+ assertTrue(a.getClass().getSuperclass().equals(B.class));\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertTrue(b.getClass().getSuperclass().equals(A.class));\r
+ assertFalse(a.getClass().getSuperclass().equals(B.class));\r
+ }\r
+\r
+ @Test\r
+ public void testHierarchySwapWithInstanceOfTest() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ A a = new A();\r
+ B b = new B();\r
+ C c = new C();\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertTrue(c.doInstanceCheckA(b));\r
+ assertFalse(c.doInstanceCheckB(a));\r
+\r
+ __toVersion__(1);\r
+\r
+ assertEquals(8, a.value());\r
+ assertEquals(4, b.value());\r
+ assertFalse(c.doInstanceCheckA(b));\r
+ assertTrue(c.doInstanceCheckB(a));\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertTrue(c.doInstanceCheckA(b));\r
+ assertFalse(c.doInstanceCheckB(a));\r
+ }\r
+\r
+ @Test\r
+ public void testHierarchySwapWithInstanceOf() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ A a = new A();\r
+ B b = new B();\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertTrue(b instanceof A);\r
+ assertFalse(a instanceof B);\r
+\r
+ __toVersion__(1);\r
+\r
+ assertEquals(8, a.value());\r
+ assertEquals(4, b.value());\r
+ assertFalse(b instanceof A);\r
+ assertTrue(a instanceof B);\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertTrue(b instanceof A);\r
+ assertFalse(a instanceof B);\r
+ }\r
+\r
+ @Test\r
+ public void testTripleSwap() {\r
+\r
+\r
+ assert __version__() == 0;\r
+\r
+ D d = new D();\r
+ E e = new E();\r
+ F f = new F();\r
+\r
+ assertEquals(d.superClassName(), "Base");\r
+ assertEquals(e.superClassName(), "Base");\r
+ assertEquals(f.superClassName(), "Base");\r
+\r
+ __toVersion__(2);\r
+\r
+ assertEquals(d.superClassName(), "Base");\r
+ assertEquals(e.superClassName(), "D");\r
+ assertEquals(f.superClassName(), "E");\r
+\r
+ __toVersion__(3);\r
+\r
+ assertEquals(d.superClassName(), "E");\r
+ assertEquals(e.superClassName(), "F");\r
+ assertEquals(f.superClassName(), "Base");\r
+\r
+ __toVersion__(4);\r
+\r
+ assertEquals(d.superClassName(), "E");\r
+ assertEquals(e.superClassName(), "Base");\r
+ assertEquals(f.superClassName(), "E");\r
+\r
+ __toVersion__(3);\r
+\r
+ assertEquals(d.superClassName(), "E");\r
+ assertEquals(e.superClassName(), "F");\r
+ assertEquals(f.superClassName(), "Base");\r
+\r
+ __toVersion__(2);\r
+\r
+ assertEquals(d.superClassName(), "Base");\r
+ assertEquals(e.superClassName(), "D");\r
+ assertEquals(f.superClassName(), "E");\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(d.superClassName(), "Base");\r
+ assertEquals(e.superClassName(), "Base");\r
+ assertEquals(f.superClassName(), "Base");\r
+ }\r
+}\r
package com.github.dcevm.test.structural;
import com.github.dcevm.test.TestUtil;
-import org.junit.*;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
--- /dev/null
+/*\r
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
+ *\r
+ * This code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 only, as\r
+ * published by the Free Software Foundation.\r
+ *\r
+ * This code is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * version 2 for more details (a copy is included in the LICENSE file that\r
+ * accompanied this code).\r
+ *\r
+ * You should have received a copy of the GNU General Public License version\r
+ * 2 along with this work; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
+ * or visit www.oracle.com if you need additional information or have any\r
+ * questions.\r
+ *\r
+ */\r
+\r
+package com.github.dcevm.test.structural;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;\r
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;\r
+import static org.junit.Assert.assertEquals;\r
+\r
+/**\r
+ * Tests that modify a large class hierarchy with the classes A, B, C, D, E, and F.\r
+ * \r
+ * @author Thomas Wuerthinger\r
+ */\r
+public class LargeHierarchyTest {\r
+\r
+ private A a = new A();\r
+ private B b = new B();\r
+ private C c = new C();\r
+ private D d = new D();\r
+ private E e = new E();\r
+ private F f = new F();\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ __toVersion__(0);\r
+ }\r
+\r
+ // Version 0\r
+ public static class A {\r
+\r
+ public int value() {\r
+ return 1;\r
+ }\r
+ }\r
+\r
+ public static class B extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class C extends B {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class D extends C {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class E extends D {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class F extends E {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ // Version 1\r
+ public static class A___1 {\r
+\r
+ public int value() {\r
+ return 2;\r
+ }\r
+ }\r
+\r
+ // Version 2\r
+ // D - E - F\r
+ // /\r
+ // A - B - C\r
+ public static class D___2 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ // Version 3\r
+ // D\r
+ // /\r
+ // A - B - C - E - F\r
+ public static class D___3 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class E___3 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ // Version 4\r
+ // Completely flat\r
+ public static class C___4 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class D___4 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class E___4 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ public static class F___4 extends A {\r
+\r
+ @Override\r
+ public int value() {\r
+ return super.value() * 2;\r
+ }\r
+ }\r
+\r
+ // Version 5\r
+ public static class F___5 extends E {\r
+\r
+ @Override\r
+ public int value() {\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testChangeBaseClass() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(32, f.value());\r
+\r
+ __toVersion__(1);\r
+\r
+ assertEquals(2, a.value());\r
+ assertEquals(4, b.value());\r
+ assertEquals(8, c.value());\r
+ assertEquals(16, d.value());\r
+ assertEquals(32, e.value());\r
+ assertEquals(64, f.value());\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(32, f.value());\r
+ }\r
+\r
+ @Test\r
+ public void testChangeSubClass() {\r
+ assert __version__() == 0;\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(32, f.value());\r
+\r
+ __toVersion__(5);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(0, f.value());\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(32, f.value());\r
+ }\r
+\r
+ @Test\r
+ public void testChangeHierarchy() {\r
+\r
+ assert __version__() == 0;\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(32, f.value());\r
+\r
+ __toVersion__(2);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(2, d.value());\r
+ assertEquals(4, e.value());\r
+ assertEquals(8, f.value());\r
+\r
+ __toVersion__(3);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(2, d.value());\r
+ assertEquals(2, e.value());\r
+ assertEquals(4, f.value());\r
+\r
+ __toVersion__(4);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(2, c.value());\r
+ assertEquals(2, d.value());\r
+ assertEquals(2, e.value());\r
+ assertEquals(2, f.value());\r
+\r
+ __toVersion__(0);\r
+\r
+ assertEquals(1, a.value());\r
+ assertEquals(2, b.value());\r
+ assertEquals(4, c.value());\r
+ assertEquals(8, d.value());\r
+ assertEquals(16, e.value());\r
+ assertEquals(32, f.value());\r
+ }\r
+}\r
package com.github.dcevm.test.structural;
import com.github.dcevm.ClassRedefinitionPolicy;
+import com.github.dcevm.test.category.Full;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
*
* @author Thomas Wuerthinger
*/
+@Category(Full.class)
@Ignore
public class RedefineClassClassTest {
package com.github.dcevm.test.structural;
import com.github.dcevm.ClassRedefinitionPolicy;
+import com.github.dcevm.test.category.Full;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
*
* @author Thomas Wuerthinger
*/
+@Category(Full.class)
@Ignore
public class RedefineObjectClassTest {
- // Version 0
- public static class Helper {
- public static String access(Object o) {
- return "";
- }
+ // Version 0
+ public static class Helper {
+ public static String access(Object o) {
+ return "";
}
+ }
- // Version 1
+ // Version 1
- public static class Helper___1 {
- public static String access(Object o) {
- return ((A___1) o).myTestFunction___();
- }
+ public static class Helper___1 {
+ public static String access(Object o) {
+ return ((A___1) o).myTestFunction___();
}
+ }
- @ClassRedefinitionPolicy(alias = java.lang.Object.class)
- public static class A___1 {
+ @ClassRedefinitionPolicy(alias = java.lang.Object.class)
+ public static class A___1 {
- public final native Class<? extends Object> getClass___();
+ public final native Class<? extends Object> getClass___();
- @Override
- public native int hashCode();
+ public native int hashCode();
- @Override
- public boolean equals(Object obj) {
- return (this == obj);
- }
-
- public static int x;
- public static int x1;
- public static int x2;
- public static int x3;
- public static int x4;
- public static int x5;
+ public boolean equals(Object obj) {
+ return (this == obj);
+ }
- @Override
- protected native Object clone() throws CloneNotSupportedException;
+ public static int x;
+ public static int x1;
+ public static int x2;
+ public static int x3;
+ public static int x4;
+ public static int x5;
- @Override
- public String toString() {
- System.out.println("x=" + (x++));
- return getClass().getName() + "@" + Integer.toHexString(hashCode());// myTestFunction___();
- }
+ protected native Object clone() throws CloneNotSupportedException;
- public final String myTestFunction___() {
- return "com/github/dcevm/test";
- }
+ public String toString() {
+ System.out.println("x=" + (x++));
+ return getClass().getName() + "@" + Integer.toHexString(hashCode());// myTestFunction___();
+ }
- public final native void notify___();
+ public final String myTestFunction___() {
+ return "test";
+ }
- public final native void notifyAll___();
+ public final native void notify___();
- public final native void wait___(long timeout) throws InterruptedException;
+ public final native void notifyAll___();
- public final void wait___(long timeout, int nanos) throws InterruptedException {
+ public final native void wait___(long timeout) throws InterruptedException;
+ public final void wait___(long timeout, int nanos) throws InterruptedException {
- if (timeout < 0) {
- throw new IllegalArgumentException("timeout value is negative");
- }
- if (nanos < 0 || nanos > 999999) {
- throw new IllegalArgumentException(
- "nanosecond timeout value out of range");
- }
+ if (timeout < 0) {
+ throw new IllegalArgumentException("timeout value is negative");
+ }
- if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
- timeout++;
- }
+ if (nanos < 0 || nanos > 999999) {
+ throw new IllegalArgumentException(
+ "nanosecond timeout value out of range");
+ }
- wait(timeout);
- }
+ if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
+ timeout++;
+ }
- public final void wait___() throws InterruptedException {
- wait(0);
- }
+ wait(timeout);
+ }
- @Override
- protected void finalize() throws Throwable {
- }
+ public final void wait___() throws InterruptedException {
+ wait(0);
}
- @Before
- public void setUp() throws Exception {
- __toVersion__(0);
+ protected void finalize() throws Throwable {
}
+ }
- @Test
- public void testRedefineObject() {
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
- assert __version__() == 0;
+ @Test
+ public void testRedefineObject() {
- Object o = new Object();
- __toVersion__(1);
+ assert __version__() == 0;
- System.out.println(this.toString());
- System.out.println(o.toString());
- System.out.println(this.toString());
+ Object o = new Object();
+ __toVersion__(1);
+ System.out.println(this.toString());
+ System.out.println(o.toString());
+ System.out.println(this.toString());
- //assertEquals("test", o.toString());
- assertEquals("com/github/dcevm/test", Helper.access(o));
- __toVersion__(0);
- __toVersion__(1);
- __toVersion__(0);
- }
+
+ //assertEquals("test", o.toString());
+ assertEquals("test", Helper.access(o));
+ __toVersion__(0);
+ __toVersion__(1);
+ __toVersion__(0);
+ }
}
+++ /dev/null
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-package com.github.dcevm.test.structural;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Class redefinition tests that do arbitrary structural changes.
- * <p/>
- * TODO: Add a test where redefinition triggers classloading (e.g. because a super type is not yet loaded).
- *
- * @author Thomas Wuerthinger
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- RedefineClassClassTest.class,
- RedefineObjectClassTest.class,
- InterfaceTest.class,
- ThisTypeChange.class
-})
-public class StructuralTestSuite {
-}
package com.github.dcevm.test.structural;
import com.github.dcevm.test.TestUtil;
+import com.github.dcevm.test.category.Light;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
*
* @author Thomas Wuerthinger
*/
+@Category(Light.class)
public class ThisTypeChange {
@Before
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.structural;
+
+import com.github.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test case for type narrowing.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class TypeNarrowingHeapTest {
+
+ // Version 0
+ public static class A {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+ }
+
+ public static class C {
+ private A a;
+
+ public C(A a) {
+ this.a = a;
+ }
+ }
+
+ public static class B extends A {
+
+ }
+
+
+ // Version 1
+ public static class B___1 {
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ A a = new A();
+ B b = new B();
+ }
+
+ @Test
+ public void testSimpleTypeNarrowing() {
+
+ assert __version__() == 0;
+
+ A a = convertBtoA(new B());
+
+ assertEquals(1, a.value());
+
+ // Cannot do conversion if A object is on the stack!
+ a = null;
+
+ __toVersion__(1);
+
+ TestUtil.assertException(NoSuchMethodError.class, new Runnable() {
+ @Override
+ public void run() {
+ B b = new B();
+ b.value();
+ }
+ });
+
+ __toVersion__(0);
+ assert __version__() == 0;
+ }
+
+ @Test
+ public void testTypeNarrowingWithField() {
+ C c = new C(new A());
+
+ __toVersion__(1);
+
+ __toVersion__(0);
+
+ c = new C(convertBtoA(new B()));
+
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
+ @Override
+ public void run() {
+ __toVersion__(1);
+ }
+ });
+
+ assert __version__() == 0;
+
+ c.a = null;
+
+ __toVersion__(1);
+
+ __toVersion__(0);
+ }
+
+ // Method to enforce cast (otherwise bytecodes become invalid in version 2)
+ public static A convertBtoA(Object b) {
+ return (A)b;
+ }
+
+ @Test
+ public void testTypeNarrowingWithArray() {
+ final B b = new B();
+ final A[] arr = new A[3];
+ arr[0] = new A();
+
+ assert b instanceof A;
+
+ __toVersion__(1);
+
+ assert !(b instanceof A);
+
+ TestUtil.assertException(ArrayStoreException.class, new Runnable() {
+ @Override
+ public void run() {
+ arr[1] = b;
+ }
+ });
+
+ __toVersion__(0);
+
+ arr[1] = new B();
+
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
+ @Override
+ public void run() {
+ __toVersion__(1);
+ }
+ });
+
+ assert __version__() == 0;
+
+ assert b instanceof A;
+
+ arr[1] = new A();
+
+ __toVersion__(1);
+
+ assert !(b instanceof A);
+
+ __toVersion__(0);
+
+ assert b instanceof A;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.structural;
+
+import com.github.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Test case for type narrowing where a non-active method fails verification because of the new hierarchy.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class TypeNarrowingMethodTest {
+
+ // Version 0
+ public static class A {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+
+ public static int badMethod(B b) {
+ A a = b;
+ return a.y;
+ }
+ }
+
+ public static class B extends A {
+
+ }
+
+
+ // Version 1
+ public static class B___1 {
+ }
+
+ // Version 2
+ public static class A___2 {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+
+ public static int badMethod(B b) {
+ return 5;
+ }
+ }
+
+ public static class B___2 {
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ A a = new A();
+ B b = new B();
+ }
+
+
+ @Test
+ public void testTypeNarrowingWithViolatingMethod() {
+
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
+ @Override
+ public void run() {
+ __toVersion__(1);
+ }
+ });
+
+ assert __version__() == 0;
+
+ __toVersion__(2);
+
+ __toVersion__(0);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.structural;
+
+import com.github.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Test case for type narrowing where a non-active method fails verification because of the new hierarchy.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class TypeNarrowingMethodTest2 {
+
+ // Version 0
+ public static class A {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+
+ public static int badMethod() {
+ A a = indirectionMethod();
+ return a.y;
+ }
+ }
+
+ public static class B extends A {
+
+ }
+
+
+ // Version 1
+ public static class B___1 {
+ }
+
+ // Version 2
+ public static class A___2 {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+
+ public static int badMethod(B b) {
+ return 5;
+ }
+ }
+
+ public static class B___2 {
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ A a = new A();
+ B b = new B();
+ }
+
+ public static B indirectionMethod() {
+ return new B();
+ }
+
+ @Test
+ public void testTypeNarrowingWithViolatingMethod() {
+ final A a = new A();
+
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
+ @Override
+ public void run() {
+ __toVersion__(1);
+ System.out.println(a.badMethod());
+ }
+ });
+
+ assert __version__() == 0;
+
+ __toVersion__(2);
+
+ __toVersion__(0);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.structural;
+
+import com.github.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Test case for type narrowing where a non-active method fails verification because of the new hierarchy.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class TypeNarrowingMethodTest3 {
+
+ // Version 0
+ public static class A {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+
+ public static int badMethod() {
+ A a = indirectionMethod()[0];
+ return a.y;
+ }
+ }
+
+ public static class B extends A {
+
+ }
+
+ // Version 1
+ public static class B___1 {
+ }
+
+ // Version 2
+ public static class A___2 {
+
+ int x = 1;
+ int y = 2;
+ int z = 3;
+
+ public int value() {
+ return x;
+ }
+
+ public static int badMethod(B b) {
+ return 5;
+ }
+ }
+
+ public static class B___2 {
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ A a = new A();
+ B b = new B();
+ }
+
+ public static B[] indirectionMethod() {
+ return new B[]{ new B() };
+ }
+
+ @Test
+ public void testTypeNarrowingWithViolatingMethod() {
+ final A a = new A();
+
+ TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
+ @Override
+ public void run() {
+ __toVersion__(1);
+ System.out.println(a.badMethod());
+ }
+ });
+
+ assert __version__() == 0;
+
+ __toVersion__(2);
+
+ __toVersion__(0);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.transformer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+class BaseClass {
+ public void $transformer() {
+ transformerExecuted();
+ }
+
+ public void transformerExecuted() {
+
+ }
+}
+
+/**
+ * Tests for executing the transformer of a base class.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class BaseClassTransformerTest {
+
+ // Version 0
+ public static class A {
+
+ public int x = 2;
+ }
+
+ // Version 3
+ public static class A___1 extends BaseClass {
+
+ public int x;
+
+ @Override
+ public void transformerExecuted() {
+ System.out.println("Transformer of A executing...");
+ x = x * 2;
+ }
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testSimpleTransformer() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(2, a.x);
+
+ __toVersion__(1);
+
+ assertEquals(4, a.x);
+
+ __toVersion__(0);
+
+ assertEquals(4, a.x);
+
+ __toVersion__(1);
+
+ assertEquals(8, a.x);
+
+ __toVersion__(0);
+
+ assertEquals(8, a.x);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.transformer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for executing the transformer of a class.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class SimpleTransformerTest {
+
+ // Version 0
+ public static class A {
+
+ public int x = 2;
+ }
+
+ // Version 3
+ public static class A___1 {
+
+ public int x;
+
+ public void $transformer() {
+ System.out.println("Transformer of A executing...");
+ x = x * 2;
+ }
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testSimpleTransformer() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(2, a.x);
+
+ __toVersion__(1);
+
+ assertEquals(4, a.x);
+
+ __toVersion__(0);
+
+ assertEquals(4, a.x);
+
+ __toVersion__(1);
+
+ assertEquals(8, a.x);
+
+ __toVersion__(0);
+
+ assertEquals(8, a.x);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.test.transformer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ */
+public class StaticConstructorTransformerTest {
+
+ //Version 0
+ public static class Static_TestClass {
+
+ // remove static --> no fatal error occurs
+ public static int x = 0;
+ //public int x = 0;
+
+ static {
+ System.out.println("Start Static_TestClass Version 0");
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ }
+ System.out.println("End Static_TestClass Version 0");
+ }
+ }
+
+ //Version 1
+ public static class Static_TestClass___1 {
+
+ public int version = 1;
+
+ static {
+ System.out.println("Static_TestClass Version 1");
+ }
+
+ public void $transformer() {
+ System.out.println(":::::::::transformerExecuted:::::::::::");
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testStaticConstructorTransformerTest() {
+
+ assert __version__() == 0;
+ try {
+ Class.forName("at.ssw.hotswap.test.transformer.StaticConstructorTransformerTest$Static_TestClass");
+ } catch (ClassNotFoundException ex) {
+ ex.printStackTrace();
+ }
+ Static_TestClass clazz = new Static_TestClass();
+
+ __toVersion__(1);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package com.github.dcevm.test.transformer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for executing the transformer of a class.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class StaticTransformerTest {
+
+ // Version 0
+ public static class A {
+
+ public static int x = 2;
+ }
+
+ // Version 3
+ public static class A___1 {
+
+ public static int x;
+
+ public static void $staticTransformer() {
+ System.out.println("Static transformer of A executing...");
+ x = x * 2;
+ }
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testStaticTransformer() {
+
+ assert __version__() == 0;
+
+ assertEquals(2, A.x);
+
+ __toVersion__(1);
+
+ assertEquals(4, A.x);
+
+ __toVersion__(0);
+
+ assertEquals(4, A.x);
+
+ __toVersion__(1);
+
+ assertEquals(8, A.x);
+
+ __toVersion__(0);
+
+ assertEquals(8, A.x);
+ }
+}
package com.github.dcevm.test.util;
import com.github.dcevm.HotSwapTool;
+import sun.reflect.CallerSensitive;
/**
* Shortcut methods for testing. Methods are named this way to make them more visible in the test code.