diff options
author | Ivan Dubrov <idubrov@guidewire.com> | 2016-03-02 13:17:05 -0800 |
---|---|---|
committer | Ivan Dubrov <idubrov@guidewire.com> | 2016-03-02 13:17:05 -0800 |
commit | dc59f725304bddd9f27d9fced9e883fd9d481b19 (patch) | |
tree | 7ede2e6af9d9eb00aaff895fcc2964cb75895b81 /dcevm | |
parent | 90b64b510803301d92a3c66e07ff78c9e81617ef (diff) | |
download | dcevm-dc59f725304bddd9f27d9fced9e883fd9d481b19.tar.gz dcevm-dc59f725304bddd9f27d9fced9e883fd9d481b19.zip |
Reformatting the source code
Diffstat (limited to 'dcevm')
71 files changed, 4461 insertions, 4461 deletions
diff --git a/dcevm/src/main/java/com/github/dcevm/ClassRedefinitionPolicy.java b/dcevm/src/main/java/com/github/dcevm/ClassRedefinitionPolicy.java index 4fd1be8a..8c7b67fe 100644 --- a/dcevm/src/main/java/com/github/dcevm/ClassRedefinitionPolicy.java +++ b/dcevm/src/main/java/com/github/dcevm/ClassRedefinitionPolicy.java @@ -32,9 +32,9 @@ import java.lang.annotation.RetentionPolicy; @Retention(value = RetentionPolicy.RUNTIME) public @interface ClassRedefinitionPolicy { - // Default value if no alias is set. - public final static class NoClass { - } + // Default value if no alias is set. + public final static class NoClass { + } - Class<?> alias() default NoClass.class; + Class<?> alias() default NoClass.class; } diff --git a/dcevm/src/main/java/com/github/dcevm/FieldRedefinitionPolicy.java b/dcevm/src/main/java/com/github/dcevm/FieldRedefinitionPolicy.java index cf3733c9..1c2d2cf3 100644 --- a/dcevm/src/main/java/com/github/dcevm/FieldRedefinitionPolicy.java +++ b/dcevm/src/main/java/com/github/dcevm/FieldRedefinitionPolicy.java @@ -27,11 +27,10 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** - * * @author Thomas Wuerthinger */ @Retention(RetentionPolicy.CLASS) public @interface FieldRedefinitionPolicy { - RedefinitionPolicy value(); + RedefinitionPolicy value(); } diff --git a/dcevm/src/main/java/com/github/dcevm/HotSwapTool.java b/dcevm/src/main/java/com/github/dcevm/HotSwapTool.java index 568124af..391554a9 100644 --- a/dcevm/src/main/java/com/github/dcevm/HotSwapTool.java +++ b/dcevm/src/main/java/com/github/dcevm/HotSwapTool.java @@ -44,197 +44,197 @@ import java.util.regex.Pattern; */ public class HotSwapTool { - /** - * Prefix for the version number in the class name. The class bytes are modified that this string including - * the following number is removed. This means that e.g. A___2 is treated as A anywhere in the source code. This is introduced - * to make the IDE not complain about multiple defined classes. - */ - public static final Pattern VERSION_PATTERN = Pattern.compile("___([0-9]+)"); - private static final String CLASS_FILE_SUFFIX = ".class"; - private static Map<Class<?>, Integer> currentVersion = new Hashtable<Class<?>, Integer>(); - private static Redefiner redefiner; - private static int redefinitionCount; - private static long totalTime; - - static { - try { - //redefiner = new JDIRedefiner(4000); - redefiner = new InstrumentationRedefiner(); - } catch (Exception e) { - throw new IllegalStateException(e); - } + /** + * Prefix for the version number in the class name. The class bytes are modified that this string including + * the following number is removed. This means that e.g. A___2 is treated as A anywhere in the source code. This is introduced + * to make the IDE not complain about multiple defined classes. + */ + public static final Pattern VERSION_PATTERN = Pattern.compile("___([0-9]+)"); + private static final String CLASS_FILE_SUFFIX = ".class"; + private static Map<Class<?>, Integer> currentVersion = new Hashtable<Class<?>, Integer>(); + private static Redefiner redefiner; + private static int redefinitionCount; + private static long totalTime; + + static { + try { + //redefiner = new JDIRedefiner(4000); + redefiner = new InstrumentationRedefiner(); + } catch (Exception e) { + throw new IllegalStateException(e); } - - /** - * Returns the current version of the inner classes of a specified outer class. - * - * @param baseClass the outer class whose version is queried - * @return the version of the inner classes of the specified outer class - */ - public static int getCurrentVersion(Class<?> baseClass) { - if (!currentVersion.containsKey(baseClass)) { - currentVersion.put(baseClass, 0); - } - return currentVersion.get(baseClass); + } + + /** + * Returns the current version of the inner classes of a specified outer class. + * + * @param baseClass the outer class whose version is queried + * @return the version of the inner classes of the specified outer class + */ + public static int getCurrentVersion(Class<?> baseClass) { + if (!currentVersion.containsKey(baseClass)) { + currentVersion.put(baseClass, 0); } + return currentVersion.get(baseClass); + } + + /** + * Performs an explicit shutdown and disconnects from the VM. + */ + public static void shutdown() throws IOException { + redefiner.close(); + redefiner = null; + } + + private static Map<Class<?>, byte[]> buildRedefinitionMap(Map<String, File> classes) throws IOException, ClassNotFoundException { + // Collect rename rules + // Also, makes sure all classes are loaded in the VM, before they are redefined + final Map<String, String> typeMappings = new HashMap<String, String>(); + for (String name : classes.keySet()) { + Class<?> clazz = Class.forName(name); // FIXME: classloader? + ClassRedefinitionPolicy policy = clazz.getAnnotation(ClassRedefinitionPolicy.class); + Class<?> replacement = (policy != null && policy.alias() != ClassRedefinitionPolicy.NoClass.class) ? + policy.alias() : clazz; + typeMappings.put(Type.getInternalName(clazz), stripVersion(Type.getInternalName(replacement))); - /** - * Performs an explicit shutdown and disconnects from the VM. - */ - public static void shutdown() throws IOException { - redefiner.close(); - redefiner = null; } - private static Map<Class<?>, byte[]> buildRedefinitionMap(Map<String, File> classes) throws IOException, ClassNotFoundException { - // Collect rename rules - // Also, makes sure all classes are loaded in the VM, before they are redefined - final Map<String, String> typeMappings = new HashMap<String, String>(); - for (String name : classes.keySet()) { - Class<?> clazz = Class.forName(name); // FIXME: classloader? - ClassRedefinitionPolicy policy = clazz.getAnnotation(ClassRedefinitionPolicy.class); - Class<?> replacement = (policy != null && policy.alias() != ClassRedefinitionPolicy.NoClass.class) ? - policy.alias() : clazz; - typeMappings.put(Type.getInternalName(clazz), stripVersion(Type.getInternalName(replacement))); - - } - - Map<Class<?>, byte[]> classesMap = new HashMap<Class<?>, byte[]>(); - for (File file : classes.values()) { - loadAdaptedClass(file, typeMappings, classesMap); - } - return classesMap; + Map<Class<?>, byte[]> classesMap = new HashMap<Class<?>, byte[]>(); + for (File file : classes.values()) { + loadAdaptedClass(file, typeMappings, classesMap); } - - private static void loadAdaptedClass(File file, Map<String, String> typeMappnigs, Map<Class<?>, byte[]> result) throws IOException, ClassNotFoundException { - - ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - TestClassAdapter adapter = new TestClassAdapter(writer, typeMappnigs); - - InputStream in = new FileInputStream(file); - try { - new ClassReader(in).accept(adapter, ClassReader.EXPAND_FRAMES); - } finally { - try { - in.close(); - } catch (IOException e) { - // Ignore. - } - } - byte[] bytes = writer.toByteArray(); - String className = adapter.getClassName().replace('/', '.'); - result.put(Class.forName(className), bytes); // FIXME: ClassLoader... + return classesMap; + } + + private static void loadAdaptedClass(File file, Map<String, String> typeMappnigs, Map<Class<?>, byte[]> result) throws IOException, ClassNotFoundException { + + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + TestClassAdapter adapter = new TestClassAdapter(writer, typeMappnigs); + + InputStream in = new FileInputStream(file); + try { + new ClassReader(in).accept(adapter, ClassReader.EXPAND_FRAMES); + } finally { + try { + in.close(); + } catch (IOException e) { + // Ignore. + } } - - /** - * Redefines all inner classes of a outer class to a specified version. Inner classes who do not have a particular - * representation for a version remain unchanged. - * - * @param outerClass the outer class whose inner classes should be redefined - * @param versionNumber the target version number - */ - public static void toVersion(Class<?> outerClass, int versionNumber, Class<?>... extraClasses) { - assert versionNumber >= 0; - - if (versionNumber == getCurrentVersion(outerClass)) { - // Nothing to do! - return; - } - - Map<String, File> files = findClassesWithVersion(outerClass, versionNumber); - - for (Class<?> extra : extraClasses) { - if (parseClassVersion(extra.getSimpleName()) == versionNumber) { - String packageName = extra.getPackage().getName().replace('.', '/'); - URL url = extra.getClassLoader().getResource(packageName); - if (url == null) { - throw new IllegalArgumentException("Cannot find URL corresponding to the package '" + packageName + "'"); - } - File file = new File(url.getFile(), extra.getSimpleName() + ".class"); - files.put(extra.getName(), file); - } - } - - try { - Map<Class<?>, byte[]> map = buildRedefinitionMap(files); - - long startTime = System.currentTimeMillis(); - redefiner.redefineClasses(map); - long curTime = System.currentTimeMillis() - startTime; - totalTime += curTime; - redefinitionCount++; - - } catch (UnmodifiableClassException e) { - throw new UnsupportedOperationException(e); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Cannot redefine classes", e); - } catch (IOException e) { - throw new RuntimeException("Cannot redefine classes", e); - } - - setCurrentVersion(outerClass, versionNumber); + byte[] bytes = writer.toByteArray(); + String className = adapter.getClassName().replace('/', '.'); + result.put(Class.forName(className), bytes); // FIXME: ClassLoader... + } + + /** + * Redefines all inner classes of a outer class to a specified version. Inner classes who do not have a particular + * representation for a version remain unchanged. + * + * @param outerClass the outer class whose inner classes should be redefined + * @param versionNumber the target version number + */ + public static void toVersion(Class<?> outerClass, int versionNumber, Class<?>... extraClasses) { + assert versionNumber >= 0; + + if (versionNumber == getCurrentVersion(outerClass)) { + // Nothing to do! + return; } - private static Map<String, File> findClassesWithVersion(Class<?> baseClass, int version) { - Map<String, File> classes = new HashMap<String, File>(); + Map<String, File> files = findClassesWithVersion(outerClass, versionNumber); - String packageName = baseClass.getPackage().getName().replace('.', '/'); - URL url = baseClass.getClassLoader().getResource(packageName); + for (Class<?> extra : extraClasses) { + if (parseClassVersion(extra.getSimpleName()) == versionNumber) { + String packageName = extra.getPackage().getName().replace('.', '/'); + URL url = extra.getClassLoader().getResource(packageName); if (url == null) { - throw new IllegalArgumentException("Cannot find URL corresponding to the package '" + packageName + "'"); + throw new IllegalArgumentException("Cannot find URL corresponding to the package '" + packageName + "'"); } - File folder = new File(url.getFile()); - for (File f : folder.listFiles(IsClassFile.INSTANCE)) { - String simpleName = f.getName().substring(0, f.getName().length() - CLASS_FILE_SUFFIX.length()); - String name = baseClass.getPackage().getName() + '.' + simpleName; - - if (isInnerClass(name, baseClass) && parseClassVersion(simpleName) == version) { - classes.put(name, f); - } - } - return classes; + File file = new File(url.getFile(), extra.getSimpleName() + ".class"); + files.put(extra.getName(), file); + } } - private enum IsClassFile implements FilenameFilter { - INSTANCE; - - @Override - public boolean accept(File dir, String name) { - return name.endsWith(CLASS_FILE_SUFFIX); - } + try { + Map<Class<?>, byte[]> map = buildRedefinitionMap(files); + + long startTime = System.currentTimeMillis(); + redefiner.redefineClasses(map); + long curTime = System.currentTimeMillis() - startTime; + totalTime += curTime; + redefinitionCount++; + + } catch (UnmodifiableClassException e) { + throw new UnsupportedOperationException(e); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Cannot redefine classes", e); + } catch (IOException e) { + throw new RuntimeException("Cannot redefine classes", e); } - private static boolean isInnerClass(String name, Class<?> baseClass) { - return name.startsWith(baseClass.getName() + "$"); - } - - private static void setCurrentVersion(Class<?> baseClass, int value) { - currentVersion.put(baseClass, value); - } + setCurrentVersion(outerClass, versionNumber); + } - /** - * Parse version of the class from the class name. Classes are named in the form of [Name]___[Version] - */ - private static int parseClassVersion(String simpleName) { - Matcher m = VERSION_PATTERN.matcher(simpleName); - return m.find() ? Integer.valueOf(m.group(1)) : 0; - } + private static Map<String, File> findClassesWithVersion(Class<?> baseClass, int version) { + Map<String, File> classes = new HashMap<String, File>(); - private static String stripVersion(String className) { - Matcher m = VERSION_PATTERN.matcher(className); - return m.replaceAll(""); + String packageName = baseClass.getPackage().getName().replace('.', '/'); + URL url = baseClass.getClassLoader().getResource(packageName); + if (url == null) { + throw new IllegalArgumentException("Cannot find URL corresponding to the package '" + packageName + "'"); } - - public static void resetTimings() { - redefinitionCount = 0; - totalTime = 0; + File folder = new File(url.getFile()); + for (File f : folder.listFiles(IsClassFile.INSTANCE)) { + String simpleName = f.getName().substring(0, f.getName().length() - CLASS_FILE_SUFFIX.length()); + String name = baseClass.getPackage().getName() + '.' + simpleName; + + if (isInnerClass(name, baseClass) && parseClassVersion(simpleName) == version) { + classes.put(name, f); + } } + return classes; + } - public static int getRedefinitionCount() { - return redefinitionCount; - } + private enum IsClassFile implements FilenameFilter { + INSTANCE; - public static long getTotalTime() { - return totalTime; + @Override + public boolean accept(File dir, String name) { + return name.endsWith(CLASS_FILE_SUFFIX); } + } + + private static boolean isInnerClass(String name, Class<?> baseClass) { + return name.startsWith(baseClass.getName() + "$"); + } + + private static void setCurrentVersion(Class<?> baseClass, int value) { + currentVersion.put(baseClass, value); + } + + /** + * Parse version of the class from the class name. Classes are named in the form of [Name]___[Version] + */ + private static int parseClassVersion(String simpleName) { + Matcher m = VERSION_PATTERN.matcher(simpleName); + return m.find() ? Integer.valueOf(m.group(1)) : 0; + } + + private static String stripVersion(String className) { + Matcher m = VERSION_PATTERN.matcher(className); + return m.replaceAll(""); + } + + public static void resetTimings() { + redefinitionCount = 0; + totalTime = 0; + } + + public static int getRedefinitionCount() { + return redefinitionCount; + } + + public static long getTotalTime() { + return totalTime; + } } diff --git a/dcevm/src/main/java/com/github/dcevm/InstrumentationRedefiner.java b/dcevm/src/main/java/com/github/dcevm/InstrumentationRedefiner.java index 42215435..5c4a4253 100644 --- a/dcevm/src/main/java/com/github/dcevm/InstrumentationRedefiner.java +++ b/dcevm/src/main/java/com/github/dcevm/InstrumentationRedefiner.java @@ -10,22 +10,22 @@ import java.lang.instrument.UnmodifiableClassException; import java.util.Map; public class InstrumentationRedefiner implements Redefiner { - public void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException { - Instrumentation instrumentation = InstrumentationAgent.INSTRUMENTATION; - if (instrumentation == null) { - throw new IllegalStateException("Instrumentation agent is not properly installed!"); - } - - ClassDefinition[] definitions = new ClassDefinition[classes.size()]; - int i = 0; - for (Map.Entry<Class<?>, byte[]> entry : classes.entrySet()) { - definitions[i++] = new ClassDefinition(entry.getKey(), entry.getValue()); - } - instrumentation.redefineClasses(definitions); + public void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException { + Instrumentation instrumentation = InstrumentationAgent.INSTRUMENTATION; + if (instrumentation == null) { + throw new IllegalStateException("Instrumentation agent is not properly installed!"); } - @Override - public void close() throws IOException { - // Do nothing. + ClassDefinition[] definitions = new ClassDefinition[classes.size()]; + int i = 0; + for (Map.Entry<Class<?>, byte[]> entry : classes.entrySet()) { + definitions[i++] = new ClassDefinition(entry.getKey(), entry.getValue()); } + instrumentation.redefineClasses(definitions); + } + + @Override + public void close() throws IOException { + // Do nothing. + } } diff --git a/dcevm/src/main/java/com/github/dcevm/JDIRedefiner.java b/dcevm/src/main/java/com/github/dcevm/JDIRedefiner.java index a28444bc..7d1b014a 100644 --- a/dcevm/src/main/java/com/github/dcevm/JDIRedefiner.java +++ b/dcevm/src/main/java/com/github/dcevm/JDIRedefiner.java @@ -47,107 +47,108 @@ import java.util.logging.Logger; * @author Thomas Wuerthinger * @author Kerstin Breiteneder * @author Christoph Wimberger - * */ public class JDIRedefiner implements Redefiner { - private static final String PORT_ARGUMENT_NAME = "port"; - private static final String TRANSPORT_NAME = "dt_socket"; - - private VirtualMachine vm; - - - /** Port at which to connect to the agent of the VM. **/ - public static final int PORT = 4000; - - public JDIRedefiner(int port) throws IOException { - vm = connect(port); + private static final String PORT_ARGUMENT_NAME = "port"; + private static final String TRANSPORT_NAME = "dt_socket"; + + private VirtualMachine vm; + + + /** + * Port at which to connect to the agent of the VM. + **/ + public static final int PORT = 4000; + + public JDIRedefiner(int port) throws IOException { + vm = connect(port); + } + + @Override + public void close() throws IOException { + disconnect(); + } + + private VirtualMachine connect(int port) throws IOException { + VirtualMachineManager manager = Bootstrap.virtualMachineManager(); + + // Find appropiate connector + List<AttachingConnector> connectors = manager.attachingConnectors(); + AttachingConnector chosenConnector = null; + for (AttachingConnector c : connectors) { + if (c.transport().name().equals(TRANSPORT_NAME)) { + chosenConnector = c; + break; + } + } + if (chosenConnector == null) { + throw new IllegalStateException("Could not find socket connector"); } - @Override - public void close() throws IOException { - disconnect(); + // Set port argument + AttachingConnector connector = chosenConnector; + Map<String, Argument> defaults = connector.defaultArguments(); + Argument arg = defaults.get(PORT_ARGUMENT_NAME); + if (arg == null) { + throw new IllegalStateException("Could not find port argument"); } + arg.setValue(Integer.toString(port)); - private VirtualMachine connect(int port) throws IOException { - VirtualMachineManager manager = Bootstrap.virtualMachineManager(); - - // Find appropiate connector - List<AttachingConnector> connectors = manager.attachingConnectors(); - AttachingConnector chosenConnector = null; - for (AttachingConnector c : connectors) { - if (c.transport().name().equals(TRANSPORT_NAME)) { - chosenConnector = c; - break; - } - } - if (chosenConnector == null) { - throw new IllegalStateException("Could not find socket connector"); - } - - // Set port argument - AttachingConnector connector = chosenConnector; - Map<String, Argument> defaults = connector.defaultArguments(); - Argument arg = defaults.get(PORT_ARGUMENT_NAME); - if (arg == null) { - throw new IllegalStateException("Could not find port argument"); - } - arg.setValue(Integer.toString(port)); - - // Attach - try { - System.out.println("Connector arguments: " + defaults); - return connector.attach(defaults); - } catch (IllegalConnectorArgumentsException e) { - throw new IllegalArgumentException("Illegal connector arguments", e); - } + // Attach + try { + System.out.println("Connector arguments: " + defaults); + return connector.attach(defaults); + } catch (IllegalConnectorArgumentsException e) { + throw new IllegalArgumentException("Illegal connector arguments", e); } + } - public void disconnect() { - if (vm != null) { - vm.dispose(); - vm = null; - } + public void disconnect() { + if (vm != null) { + vm.dispose(); + vm = null; } + } - public void redefineClasses(Map<Class<?>, byte[]> classes) { - refreshAllClasses(); - List<ReferenceType> references = vm.allClasses(); + public void redefineClasses(Map<Class<?>, byte[]> classes) { + refreshAllClasses(); + List<ReferenceType> references = vm.allClasses(); - Map<ReferenceType, byte[]> map = new HashMap<ReferenceType, byte[]>(classes.size()); - for (Map.Entry<Class<?>, byte[]> entry : classes.entrySet()) { - map.put(findReference(references, entry.getKey().getName()), entry.getValue()); - } - vm.redefineClasses(map); + Map<ReferenceType, byte[]> map = new HashMap<ReferenceType, byte[]>(classes.size()); + for (Map.Entry<Class<?>, byte[]> entry : classes.entrySet()) { + map.put(findReference(references, entry.getKey().getName()), entry.getValue()); } + vm.redefineClasses(map); + } - /** - * Call this method before calling allClasses() in order to refresh the JDI state of loaded classes. - * This is necessary because the JDI map of all loaded classes is only updated based on events received over JDWP (network connection) - * and therefore it is not necessarily up-to-date with the real state within the VM. - */ - private void refreshAllClasses() { - try { - Field f = vm.getClass().getDeclaredField("retrievedAllTypes"); - f.setAccessible(true); - f.set(vm, false); - } catch (IllegalArgumentException ex) { - Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); - } catch (NoSuchFieldException ex) { - Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); - } catch (SecurityException ex) { - Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); - } + /** + * Call this method before calling allClasses() in order to refresh the JDI state of loaded classes. + * This is necessary because the JDI map of all loaded classes is only updated based on events received over JDWP (network connection) + * and therefore it is not necessarily up-to-date with the real state within the VM. + */ + private void refreshAllClasses() { + try { + Field f = vm.getClass().getDeclaredField("retrievedAllTypes"); + f.setAccessible(true); + f.set(vm, false); + } catch (IllegalArgumentException ex) { + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex); } + } - private static ReferenceType findReference(List<ReferenceType> list, String name) { - for (ReferenceType ref : list) { - if (ref.name().equals(name)) { - return ref; - } - } - throw new IllegalArgumentException("Cannot find corresponding reference for class name '" + name + "'" ); + private static ReferenceType findReference(List<ReferenceType> list, String name) { + for (ReferenceType ref : list) { + if (ref.name().equals(name)) { + return ref; + } } + throw new IllegalArgumentException("Cannot find corresponding reference for class name '" + name + "'"); + } } diff --git a/dcevm/src/main/java/com/github/dcevm/MethodRedefinitionPolicy.java b/dcevm/src/main/java/com/github/dcevm/MethodRedefinitionPolicy.java index 01d17c22..260f7cc9 100644 --- a/dcevm/src/main/java/com/github/dcevm/MethodRedefinitionPolicy.java +++ b/dcevm/src/main/java/com/github/dcevm/MethodRedefinitionPolicy.java @@ -28,11 +28,10 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** - * * @author Thomas Wuerthinger */ @Retention(RetentionPolicy.CLASS) public @interface MethodRedefinitionPolicy { - RedefinitionPolicy value(); + RedefinitionPolicy value(); } diff --git a/dcevm/src/main/java/com/github/dcevm/Redefiner.java b/dcevm/src/main/java/com/github/dcevm/Redefiner.java index 620ab263..18ff437c 100644 --- a/dcevm/src/main/java/com/github/dcevm/Redefiner.java +++ b/dcevm/src/main/java/com/github/dcevm/Redefiner.java @@ -33,5 +33,5 @@ import java.util.Map; * @author Ivan Dubrov */ public interface Redefiner extends Closeable { - void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException; + void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException; } diff --git a/dcevm/src/main/java/com/github/dcevm/RedefinitionPolicy.java b/dcevm/src/main/java/com/github/dcevm/RedefinitionPolicy.java index f56ba80a..82b7d6e2 100644 --- a/dcevm/src/main/java/com/github/dcevm/RedefinitionPolicy.java +++ b/dcevm/src/main/java/com/github/dcevm/RedefinitionPolicy.java @@ -25,12 +25,11 @@ package com.github.dcevm; /** - * * @author Thomas Wuerthinger */ public enum RedefinitionPolicy { - StaticCheck, - DynamicCheck, - AccessDeletedMembers, - AccessOldMembers + StaticCheck, + DynamicCheck, + AccessDeletedMembers, + AccessOldMembers } diff --git a/dcevm/src/main/java/com/github/dcevm/TestClassAdapter.java b/dcevm/src/main/java/com/github/dcevm/TestClassAdapter.java index e8639df1..8ea89b6d 100644 --- a/dcevm/src/main/java/com/github/dcevm/TestClassAdapter.java +++ b/dcevm/src/main/java/com/github/dcevm/TestClassAdapter.java @@ -35,101 +35,101 @@ import java.util.Map; * @author Ivan Dubrov */ public class TestClassAdapter extends RemappingClassAdapter { - /** - * This suffix is automatically removed from the method. - */ - private final static String METHOD_SUFFIX = "___"; - - private boolean isObject; - - public TestClassAdapter(ClassVisitor cv, final Map<String, String> typeMappings) { - super(cv, new Remapper() { - @Override - public String map(String type) { - return typeMappings.containsKey(type) ? typeMappings.get(type) : type; - } - }); + /** + * This suffix is automatically removed from the method. + */ + private final static String METHOD_SUFFIX = "___"; + + private boolean isObject; + + public TestClassAdapter(ClassVisitor cv, final Map<String, String> typeMappings) { + super(cv, new Remapper() { + @Override + public String map(String type) { + return typeMappings.containsKey(type) ? typeMappings.get(type) : type; + } + }); + } + + @Override + public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { + // For java/lang/Object redefinition + String newName = remapper.mapType(name); + if (newName.equals("java/lang/Object")) { + superName = null; + isObject = true; } - - @Override - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - // For java/lang/Object redefinition - String newName = remapper.mapType(name); - if (newName.equals("java/lang/Object")) { - superName = null; - isObject = true; + super.visit(version, access, name, signature, superName, interfaces); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + return super.visitMethod(access, stripMethodSuffix(name), desc, signature, exceptions); + } + + /** + * Get renamed class name. + * + * @return + */ + public String getClassName() { + return remapper.mapType(className); + } + + protected MethodVisitor createRemappingMethodAdapter( + int access, + String newDesc, + MethodVisitor mv) { + return new RemappingMethodAdapter(access, newDesc, mv, remapper) { + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { + if (name.equals("<init>") && isObject && owner.equals("java/lang/Object")) { + return; } - super.visit(version, access, name, signature, superName, interfaces); - } - @Override - public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - return super.visitMethod(access, stripMethodSuffix(name), desc, signature, exceptions); - } + super.visitMethodInsn(opcode, owner, stripMethodSuffix(name), desc, itf); + } + }; + } + + private static String stripMethodSuffix(String name) { + 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); + } + }; + } - /** - * Get renamed class name. - * - * @return - */ - public String getClassName() { - return remapper.mapType(className); - } + private static class SingleByteAttribute extends Attribute { + private byte value; - protected MethodVisitor createRemappingMethodAdapter( - int access, - String newDesc, - MethodVisitor mv) { - return new RemappingMethodAdapter(access, newDesc, mv, remapper) { - @Override - public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { - if (name.equals("<init>") && isObject && owner.equals("java/lang/Object")) { - return; - } - - super.visitMethodInsn(opcode, owner, stripMethodSuffix(name), desc, itf); - } - }; - } - - private static String stripMethodSuffix(String name) { - int pos = name.indexOf(METHOD_SUFFIX); - return (pos != -1) ? name.substring(0, pos) : name; + public SingleByteAttribute(String name, byte value) { + super(name); + this.value = value; } @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); - } + protected ByteVector write(ClassWriter writer, byte[] code, int len, int maxStack, int maxLocals) { + return new ByteVector().putByte(value); } + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/TestUtil.java b/dcevm/src/test/java7/com/github/dcevm/test/TestUtil.java index 41dda642..7208af20 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/TestUtil.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/TestUtil.java @@ -33,42 +33,42 @@ import org.junit.Assert; * @author Thomas Wuerthinger */ public class TestUtil { - public static final boolean LIGHT = Boolean.getBoolean("dcevm.test.light"); + public static final boolean LIGHT = Boolean.getBoolean("dcevm.test.light"); - public static int assertException(Class exceptionClass, Runnable run) { + public static int assertException(Class exceptionClass, Runnable run) { - try { - run.run(); - } catch (Throwable t) { - if (t.getClass().equals(exceptionClass)) { - return t.getStackTrace()[0].getLineNumber(); - } - Assert.assertTrue("An exception of type " + t.getClass().getSimpleName() + " instead of " + exceptionClass.getSimpleName() + " has been thrown!", false); - } - - Assert.assertTrue("No exception has been thrown!", false); - return -1; + try { + run.run(); + } catch (Throwable t) { + if (t.getClass().equals(exceptionClass)) { + return t.getStackTrace()[0].getLineNumber(); + } + Assert.assertTrue("An exception of type " + t.getClass().getSimpleName() + " instead of " + exceptionClass.getSimpleName() + " has been thrown!", false); } - public static int assertUnsupportedWithLight(Runnable run) { - if (TestUtil.LIGHT) { - return assertUnsupported(run); - } - run.run(); - return -1; - } + Assert.assertTrue("No exception has been thrown!", false); + return -1; + } - public static int assertUnsupported(Runnable run) { - return assertException(UnsupportedOperationException.class, run); + public static int assertUnsupportedWithLight(Runnable run) { + if (TestUtil.LIGHT) { + return assertUnsupported(run); } + run.run(); + return -1; + } - public static void assertUnsupportedToVersionWithLight(final Class clazz, final int version) { - TestUtil.assertUnsupportedWithLight(new Runnable() { - @Override - public void run() { - HotSwapTool.toVersion(clazz, version); - } - }); - } + public static int assertUnsupported(Runnable run) { + return assertException(UnsupportedOperationException.class, run); + } + + public static void assertUnsupportedToVersionWithLight(final Class clazz, final int version) { + TestUtil.assertUnsupportedWithLight(new Runnable() { + @Override + public void run() { + HotSwapTool.toVersion(clazz, version); + } + }); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/ArrayTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/ArrayTest.java index 96552556..1c2ecb2b 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/ArrayTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/ArrayTest.java @@ -38,59 +38,59 @@ import static org.junit.Assert.assertTrue; */ public class ArrayTest { - public class A { - } + public class A { + } - public class A___1 { - } + public class A___1 { + } - public class B extends A { - } + public class B extends A { + } - public class B___1 extends A { - } + public class B___1 extends A { + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testArray() { - Object[] arr = new A[] { new A(), new A() }; - A[] arr2 = new B[] { new B(), new B() }; - A[][] arr3 = new B[10][]; + @Test + public void testArray() { + Object[] arr = new A[]{new A(), new A()}; + A[] arr2 = new B[]{new B(), new B()}; + A[][] arr3 = new B[10][]; - __toVersion__(1); + __toVersion__(1); - assertTrue(arr instanceof A[]); - assertTrue(arr instanceof Object[]); - assertEquals(arr.getClass(), Array.newInstance(A.class, 0).getClass()); + assertTrue(arr instanceof A[]); + assertTrue(arr instanceof Object[]); + assertEquals(arr.getClass(), Array.newInstance(A.class, 0).getClass()); - assertTrue(arr2 instanceof B[]); - assertTrue(arr2 instanceof A[]); - assertTrue(arr2 instanceof Object[]); - assertEquals(arr2.getClass(), Array.newInstance(B.class, 0).getClass()); + assertTrue(arr2 instanceof B[]); + assertTrue(arr2 instanceof A[]); + assertTrue(arr2 instanceof Object[]); + assertEquals(arr2.getClass(), Array.newInstance(B.class, 0).getClass()); - assertTrue(arr3 instanceof B[][]); - assertTrue(arr3 instanceof A[][]); - assertTrue(arr3 instanceof Object[][]); - assertEquals(arr3.getClass(), Array.newInstance(B[].class, 0).getClass()); + assertTrue(arr3 instanceof B[][]); + assertTrue(arr3 instanceof A[][]); + assertTrue(arr3 instanceof Object[][]); + assertEquals(arr3.getClass(), Array.newInstance(B[].class, 0).getClass()); - __toVersion__(0); + __toVersion__(0); - assertTrue(arr instanceof A[]); - assertTrue(arr instanceof Object[]); - assertEquals(arr.getClass(), Array.newInstance(A.class, 0).getClass()); + assertTrue(arr instanceof A[]); + assertTrue(arr instanceof Object[]); + assertEquals(arr.getClass(), Array.newInstance(A.class, 0).getClass()); - assertTrue(arr2 instanceof B[]); - assertTrue(arr2 instanceof A[]); - assertTrue(arr2 instanceof Object[]); - assertEquals(arr2.getClass(), Array.newInstance(B.class, 0).getClass()); + assertTrue(arr2 instanceof B[]); + assertTrue(arr2 instanceof A[]); + assertTrue(arr2 instanceof Object[]); + assertEquals(arr2.getClass(), Array.newInstance(B.class, 0).getClass()); - assertTrue(arr3 instanceof B[][]); - assertTrue(arr3 instanceof A[][]); - assertTrue(arr3 instanceof Object[][]); - assertEquals(arr3.getClass(), Array.newInstance(B[].class, 0).getClass()); - } + assertTrue(arr3 instanceof B[][]); + assertTrue(arr3 instanceof A[][]); + assertTrue(arr3 instanceof Object[][]); + assertEquals(arr3.getClass(), Array.newInstance(B[].class, 0).getClass()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/ClassRenamingTestCase.java b/dcevm/src/test/java7/com/github/dcevm/test/body/ClassRenamingTestCase.java index ec390522..29d95b21 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/ClassRenamingTestCase.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/ClassRenamingTestCase.java @@ -35,34 +35,34 @@ import static org.junit.Assert.assertEquals; */ public class ClassRenamingTestCase { - public static class B { + public static class B { - public int a() { - return 1; - } + public int a() { + return 1; } + } - @ClassRedefinitionPolicy(alias = B.class) - public static class A___1 { + @ClassRedefinitionPolicy(alias = B.class) + public static class A___1 { - public int a() { - return 2; - } + public int a() { + return 2; } + } - @Test - public void testRenaming() { - __toVersion__(0); + @Test + public void testRenaming() { + __toVersion__(0); - B b = new B(); - assertEquals(1, b.a()); + B b = new B(); + assertEquals(1, b.a()); - __toVersion__(1); + __toVersion__(1); - assertEquals(2, b.a()); + assertEquals(2, b.a()); - __toVersion__(0); + __toVersion__(0); - assertEquals(1, b.a()); - } + assertEquals(1, b.a()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/EMCPTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/EMCPTest.java index 1e82d6f3..d7e40624 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/EMCPTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/EMCPTest.java @@ -38,182 +38,182 @@ import static org.junit.Assert.assertEquals; */ public class EMCPTest { - public static class A { + public static class A { - public static int EMCPReturn() { - change(); - PrintStream s = System.out; - return 1; - } + public static int EMCPReturn() { + change(); + PrintStream s = System.out; + return 1; } + } - public static class B { + public static class B { - public static int b() { - change(); - throw new RuntimeException(); - } + public static int b() { + change(); + throw new RuntimeException(); } + } - public static class C { + public static class C { - public static int c() { - changeAndThrow(); - return 0; - } + public static int c() { + changeAndThrow(); + return 0; } + } - public static class D { + public static class D { - private static int value = 1; + private static int value = 1; - public static int EMCPReturn() { - change3(); - return value; - } + public static int EMCPReturn() { + change3(); + return value; } + } - public static class A___1 { + public static class A___1 { - public static int EMCPReturn() { - change(); - PrintStream s = System.out; - return 1; - } + public static int EMCPReturn() { + change(); + PrintStream s = System.out; + return 1; } + } - public static class B___1 { + public static class B___1 { - public static int b() { - change(); - throw new RuntimeException(); - } + public static int b() { + change(); + throw new RuntimeException(); } + } - public static class C___1 { + public static class C___1 { - public static int c() { - changeAndThrow(); - return 0; - } + public static int c() { + changeAndThrow(); + return 0; } + } - public static class D___1 { - private static int value = 1; + public static class D___1 { + private static int value = 1; - public static int EMCPReturn() { - change3(); - return value; - } + public static int EMCPReturn() { + change3(); + return value; } + } - public static class D___2 { - private static int value = 1; + public static class D___2 { + private static int value = 1; - public static int EMCPReturn() { - change3(); - return value; - } + public static int EMCPReturn() { + change3(); + return value; } + } - public static class D___3 { - private static int value = 1; + public static class D___3 { + private static int value = 1; - public static int EMCPReturn() { - change3(); - return value; - } + public static int EMCPReturn() { + change3(); + return value; } + } - public static void change() { + public static void change() { - __toVersion__(1); - } + __toVersion__(1); + } - public static void change3() { + public static void change3() { - __toVersion__(1); - __toVersion__(2); - __toVersion__(3); - } + __toVersion__(1); + __toVersion__(2); + __toVersion__(3); + } - public static void changeAndThrow() { + public static void changeAndThrow() { - __toVersion__(1); + __toVersion__(1); - throw new RuntimeException(); - } + throw new RuntimeException(); + } - @Test - public void testEMCPReturn() { - __toVersion__(0); + @Test + public void testEMCPReturn() { + __toVersion__(0); - assertEquals(1, A.EMCPReturn()); + assertEquals(1, A.EMCPReturn()); - __toVersion__(0); + __toVersion__(0); - assertEquals(1, A.EMCPReturn()); + assertEquals(1, A.EMCPReturn()); - __toVersion__(0); - } + __toVersion__(0); + } - @Test - public void testEMCPMultiChangeReturn() { - __toVersion__(0); + @Test + public void testEMCPMultiChangeReturn() { + __toVersion__(0); - assertEquals(1, D.EMCPReturn()); + assertEquals(1, D.EMCPReturn()); - __toVersion__(0); + __toVersion__(0); - assertEquals(1, D.EMCPReturn()); + assertEquals(1, D.EMCPReturn()); - __toVersion__(0); - } + __toVersion__(0); + } - @Test - public void testEMCPException() { - __toVersion__(0); + @Test + public void testEMCPException() { + __toVersion__(0); - TestUtil.assertException(RuntimeException.class, new Runnable() { - @Override - public void run() { - B.b(); - } - }); + TestUtil.assertException(RuntimeException.class, new Runnable() { + @Override + public void run() { + B.b(); + } + }); - __toVersion__(0); + __toVersion__(0); - TestUtil.assertException(RuntimeException.class, new Runnable() { - @Override - public void run() { - B.b(); - } - }); + TestUtil.assertException(RuntimeException.class, new Runnable() { + @Override + public void run() { + B.b(); + } + }); - __toVersion__(0); - } + __toVersion__(0); + } - @Test - public void testEMCPExceptionInCallee() { - __toVersion__(0); + @Test + public void testEMCPExceptionInCallee() { + __toVersion__(0); - TestUtil.assertException(RuntimeException.class, new Runnable() { - @Override - public void run() { - C.c(); - } - }); + TestUtil.assertException(RuntimeException.class, new Runnable() { + @Override + public void run() { + C.c(); + } + }); - __toVersion__(0); + __toVersion__(0); - TestUtil.assertException(RuntimeException.class, new Runnable() { - @Override - public void run() { - C.c(); - } - }); + TestUtil.assertException(RuntimeException.class, new Runnable() { + @Override + public void run() { + C.c(); + } + }); - __toVersion__(0); - } + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/FacTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/FacTest.java index caf9e3e2..99a0e121 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/FacTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/FacTest.java @@ -38,66 +38,66 @@ import static org.junit.Assert.assertEquals; */ public class FacTest { - public static abstract class Base { - - protected int calc() { - return calc(__version__()); - } - - public int calcAt(int version) { - __toVersion__(version); - int result = calc(); - __toVersion__(0); - return result; - } - - protected int calc(int version) { - return calc(); - } + public static abstract class Base { + + protected int calc() { + return calc(__version__()); } - public static class Factorial extends Base { + public int calcAt(int version) { + __toVersion__(version); + int result = calc(); + __toVersion__(0); + return result; + } - @Override - protected int calc(int n) { - return n * calcAt(n - 1); - } + protected int calc(int version) { + return calc(); } + } - public static class Factorial___1 extends Base { + public static class Factorial extends Base { - @Override - protected int calc() { - return 1; - } + @Override + protected int calc(int n) { + return n * calcAt(n - 1); } + } + + public static class Factorial___1 extends Base { - @Before - public void setUp() throws Exception { - __toVersion__(0); + @Override + protected int calc() { + return 1; } + } - @Test - public void testFac() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; - Factorial f = new Factorial(); + @Test + public void testFac() { - assertEquals(1, f.calcAt(1)); + assert __version__() == 0; + Factorial f = new Factorial(); - assert __version__() == 0; - assertEquals(2, f.calcAt(2)); + assertEquals(1, f.calcAt(1)); - assert __version__() == 0; - assertEquals(6, f.calcAt(3)); + assert __version__() == 0; + assertEquals(2, f.calcAt(2)); - assert __version__() == 0; - assertEquals(24, f.calcAt(4)); + assert __version__() == 0; + assertEquals(6, f.calcAt(3)); - assert __version__() == 0; - assertEquals(120, f.calcAt(5)); + assert __version__() == 0; + assertEquals(24, f.calcAt(4)); - assert __version__() == 0; - assertEquals(479001600, f.calcAt(12)); - } + assert __version__() == 0; + assertEquals(120, f.calcAt(5)); + + assert __version__() == 0; + assertEquals(479001600, f.calcAt(12)); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/FibTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/FibTest.java index bd449e7d..c4540c77 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/FibTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/FibTest.java @@ -38,73 +38,73 @@ import static org.junit.Assert.assertEquals; */ public class FibTest { - public static abstract class Base { - - protected int calc() { - return calc(__version__()); - } - - public int calcAt(int version) { - __toVersion__(version); - int result = calc(); - __toVersion__(0); - return result; - } - - protected int calc(int version) { - return calc(); - } + public static abstract class Base { + + protected int calc() { + return calc(__version__()); } - public static class Fib extends Base { + public int calcAt(int version) { + __toVersion__(version); + int result = calc(); + __toVersion__(0); + return result; + } - @Override - protected int calc(int n) { - return calcAt(n - 1) + calcAt(n - 2); - } + protected int calc(int version) { + return calc(); } + } - public static class Fib___1 extends Base { + public static class Fib extends Base { - @Override - protected int calc() { - return 1; - } + @Override + protected int calc(int n) { + return calcAt(n - 1) + calcAt(n - 2); } + } - public static class Fib___2 extends Base { + public static class Fib___1 extends Base { - @Override - protected int calc() { - return 2; - } + @Override + protected int calc() { + return 1; } + } + + public static class Fib___2 extends Base { - @Before - public void setUp() throws Exception { - __toVersion__(0); + @Override + protected int calc() { + return 2; } + } - @Test - public void testFib() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // 0 1 2 3 4 5 - // 1 1 2 3 5 8 - assert __version__() == 0; - Fib f = new Fib(); + @Test + public void testFib() { - assertEquals(1, f.calcAt(1)); + // 0 1 2 3 4 5 + // 1 1 2 3 5 8 + assert __version__() == 0; + Fib f = new Fib(); - assert __version__() == 0; - assertEquals(2, f.calcAt(2)); + assertEquals(1, f.calcAt(1)); - assert __version__() == 0; - assertEquals(3, f.calcAt(3)); + assert __version__() == 0; + assertEquals(2, f.calcAt(2)); - assert __version__() == 0; - assertEquals(5, f.calcAt(4)); + assert __version__() == 0; + assertEquals(3, f.calcAt(3)); - assert __version__() == 0; - assertEquals(8, f.calcAt(5)); - } + assert __version__() == 0; + assertEquals(5, f.calcAt(4)); + + assert __version__() == 0; + assertEquals(8, f.calcAt(5)); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/MultipleThreadsTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/MultipleThreadsTest.java index d6b8913e..8e0e51c3 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/MultipleThreadsTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/MultipleThreadsTest.java @@ -40,168 +40,168 @@ import static org.junit.Assert.assertTrue; */ public class MultipleThreadsTest { - public static final int COUNT = 10; - - // Version 0 - public static class A extends Thread { - - private int value; - private int value2; - private boolean flag = false; - - @Override - public void run() { - while (doit()) { - flag = false; - } - } - - public boolean doit() { - if (flag) { - throw new RuntimeException("Must not reach here"); - } - flag = true; - try { - Thread.sleep(1); - } catch (InterruptedException e) { - } + public static final int COUNT = 10; - value++; - return true; - } + // Version 0 + public static class A extends Thread { - public int getValue() { - return value; - } + private int value; + private int value2; + private boolean flag = false; - public int getValue2() { - return value2; - } + @Override + public void run() { + while (doit()) { + flag = false; + } } - // Version 1 - public static class A___1 extends Thread { - - private int value; - private int value2; - private boolean flag = false; + public boolean doit() { + if (flag) { + throw new RuntimeException("Must not reach here"); + } + flag = true; + try { + Thread.sleep(1); + } catch (InterruptedException e) { + } + + value++; + return true; + } - @Override - public void run() { - while (doit()) { - flag = false; - } - } + public int getValue() { + return value; + } - public boolean doit() { - if (flag) { - throw new RuntimeException("Must not reach here"); - } - flag = true; - try { - Thread.sleep(1); - } catch (InterruptedException e) { - } + public int getValue2() { + return value2; + } + } - value2++; - return true; - } + // Version 1 + public static class A___1 extends Thread { - public int getValue() { - return value; - } + private int value; + private int value2; + private boolean flag = false; - public int getValue2() { - return value2; - } + @Override + public void run() { + while (doit()) { + flag = false; + } } - // Version 2 - public static class A___2 extends Thread { + public boolean doit() { + if (flag) { + throw new RuntimeException("Must not reach here"); + } + flag = true; + try { + Thread.sleep(1); + } catch (InterruptedException e) { + } + + value2++; + return true; + } - private int value; - private int value2; - private boolean flag = false; + public int getValue() { + return value; + } - @Override - public void run() { - while (doit()) { - flag = false; - } - } + public int getValue2() { + return value2; + } + } - public boolean doit() { - return false; - } + // Version 2 + public static class A___2 extends Thread { - public int getValue() { - return value; - } + private int value; + private int value2; + private boolean flag = false; - public int getValue2() { - return value2; - } + @Override + public void run() { + while (doit()) { + flag = false; + } } - @Before - public void setUp() throws Exception { - __toVersion__(0); + public boolean doit() { + return false; } - @Test - public void testOneThread() { - test(1); + public int getValue() { + return value; } - @Test - public void testThreads() { - test(COUNT); + public int getValue2() { + return value2; } + } - private void test(int count) { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; + @Test + public void testOneThread() { + test(1); + } - A[] arr = new A[count]; - for (int i = 0; i < count; i++) { - arr[i] = new A(); - arr[i].start(); - } + @Test + public void testThreads() { + test(COUNT); + } - try { - Thread.sleep(500); - } catch (InterruptedException e) { - } + private void test(int count) { - for (int i = 0; i < count; i++) { - //assertTrue(arr[i].getValue() > 0); - } + assert __version__() == 0; - __toVersion__(1); + A[] arr = new A[count]; + for (int i = 0; i < count; i++) { + arr[i] = new A(); + arr[i].start(); + } - try { - Thread.sleep(500); - } catch (InterruptedException e) { - } + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } - for (int i = 0; i < count; i++) { - assertTrue(arr[i].getValue2() > 0); - } + for (int i = 0; i < count; i++) { + //assertTrue(arr[i].getValue() > 0); + } - __toVersion__(2); + __toVersion__(1); - try { - Thread.sleep(500); - } catch (InterruptedException e) { - } + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + for (int i = 0; i < count; i++) { + assertTrue(arr[i].getValue2() > 0); + } - for (int i = 0; i < count; i++) { - assertFalse(arr[i].isAlive()); - } + __toVersion__(2); - __toVersion__(0); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + for (int i = 0; i < count; i++) { + assertFalse(arr[i].isAlive()); } + + __toVersion__(0); + + + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/OldActivationTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/OldActivationTest.java index 5533a497..e67f537b 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/OldActivationTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/OldActivationTest.java @@ -38,121 +38,121 @@ import static org.junit.Assert.assertEquals; */ public class OldActivationTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - __toVersion__(1); - return 1 + this.value(); - } + public int value() { + __toVersion__(1); + return 1 + this.value(); } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - __toVersion__(2); - return 2 + this.value(); - } + public int value() { + __toVersion__(2); + return 2 + this.value(); } + } - // Version 2 - public static class A___2 { + // Version 2 + public static class A___2 { - public int value() { - __toVersion__(3); - return 3 + this.value(); - } + public int value() { + __toVersion__(3); + return 3 + this.value(); } + } - // Version 3 - public static class A___3 { + // Version 3 + public static class A___3 { - public int value() { - __toVersion__(4); - return 4 + this.value(); - } + public int value() { + __toVersion__(4); + return 4 + this.value(); } + } - // Version 4 - public static class A___4 { + // Version 4 + public static class A___4 { - public int value() { - __toVersion__(5); - return 5 + this.value(); - } + public int value() { + __toVersion__(5); + return 5 + this.value(); } + } - // Version 5 - public static class A___5 { + // Version 5 + public static class A___5 { - public int value() { - __toVersion__(6); - return 6 + this.value(); - } + public int value() { + __toVersion__(6); + return 6 + this.value(); } + } - // Version 6 - public static class A___6 { + // Version 6 + public static class A___6 { - public int value() { - __toVersion__(7); - return 7 + this.value(); - } + public int value() { + __toVersion__(7); + return 7 + this.value(); } + } - // Version 7 - public static class A___7 { + // Version 7 + public static class A___7 { - public int value() { - __toVersion__(8); - return 8 + this.value(); - } + public int value() { + __toVersion__(8); + return 8 + this.value(); } + } - // Version 8 - public static class A___8 { + // Version 8 + public static class A___8 { - public int value() { - __toVersion__(9); - return 9 + this.value(); - } + public int value() { + __toVersion__(9); + return 9 + this.value(); } + } - // Version 9 - public static class A___9 { + // Version 9 + public static class A___9 { - public int value() { - __toVersion__(0); - return 10; - } + public int value() { + __toVersion__(0); + return 10; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testOldActivationTest() { + @Test + public void testOldActivationTest() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); + A a = new A(); - assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, a.value()); - assert __version__() == 0; + assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, a.value()); + assert __version__() == 0; - __toVersion__(1); - assertEquals(2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, a.value()); - assert __version__() == 0; + __toVersion__(1); + assertEquals(2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, a.value()); + assert __version__() == 0; - __toVersion__(8); - assertEquals(9 + 10, a.value()); - assert __version__() == 0; + __toVersion__(8); + assertEquals(9 + 10, a.value()); + assert __version__() == 0; - __toVersion__(4); - assertEquals(5 + 6 + 7 + 8 + 9 + 10, a.value()); - assert __version__() == 0; - } + __toVersion__(4); + assertEquals(5 + 6 + 7 + 8 + 9 + 10, a.value()); + assert __version__() == 0; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/RedefinePrivateMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/RedefinePrivateMethodTest.java index cd448cc4..a51c496e 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/RedefinePrivateMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/RedefinePrivateMethodTest.java @@ -38,59 +38,59 @@ import static org.junit.Assert.assertEquals; */ public class RedefinePrivateMethodTest { - // Version 0 - public static class A { - - public int foo() { - int result = bar(); - __toVersion__(1); - result += bar(); - return result; - } - - private int bar() { - return 1; - } + // Version 0 + public static class A { + + public int foo() { + int result = bar(); + __toVersion__(1); + result += bar(); + return result; } - // Version 1 - public static class A___1 { + private int bar() { + return 1; + } + } - public int foo() { - return -1; - } + // Version 1 + public static class A___1 { - private int bar() { - return 2; - } + public int foo() { + return -1; } - @Before - public void setUp() throws Exception { - __toVersion__(0); + private int bar() { + return 2; } + } - @Test - public void testRedefinePrivateMethod() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; + @Test + public void testRedefinePrivateMethod() { - A a = new A(); + assert __version__() == 0; - assertEquals(3, a.foo()); + A a = new A(); - assert __version__() == 1; + assertEquals(3, a.foo()); - assertEquals(-1, a.foo()); + assert __version__() == 1; - __toVersion__(0); + assertEquals(-1, a.foo()); - assertEquals(3, a.foo()); + __toVersion__(0); - assert __version__() == 1; + assertEquals(3, a.foo()); - assertEquals(-1, a.foo()); + assert __version__() == 1; - __toVersion__(0); - } + assertEquals(-1, a.foo()); + + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/RefactorActiveMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/RefactorActiveMethodTest.java index 15ddf8e3..5d54df41 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/RefactorActiveMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/RefactorActiveMethodTest.java @@ -36,61 +36,61 @@ import static org.junit.Assert.assertEquals; */ public class RefactorActiveMethodTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - __toVersion__(1); - return 5; - } - - public int secondValue() { - return 1; - } + public int value() { + __toVersion__(1); + return 5; } - // Version 1 - public static class A___1 { + public int secondValue() { + return 1; + } + } - public int value() { - return secondValue() * 2; - } + // Version 1 + public static class A___1 { - public int secondValue() { - return 2; - } + public int value() { + return secondValue() * 2; } - @Before - public void setUp() throws Exception { - __toVersion__(0); + public int secondValue() { + return 2; } + } - @Test - public void testActiveMethodReplacement() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; + @Test + public void testActiveMethodReplacement() { - A a = new A(); + assert __version__() == 0; - assertEquals(5, a.value()); + A a = new A(); - assert __version__() == 1; + assertEquals(5, a.value()); - assertEquals(2, a.secondValue()); - assertEquals(4, a.value()); - assertEquals(2, a.secondValue()); + assert __version__() == 1; - assert __version__() == 1; + assertEquals(2, a.secondValue()); + assertEquals(4, a.value()); + assertEquals(2, a.secondValue()); - __toVersion__(0); + assert __version__() == 1; - assertEquals(1, a.secondValue()); - assertEquals(5, a.value()); - assertEquals(4, a.value()); + __toVersion__(0); - __toVersion__(0); + assertEquals(1, a.secondValue()); + assertEquals(5, a.value()); + assertEquals(4, a.value()); - assertEquals(1, a.secondValue()); - } + __toVersion__(0); + + assertEquals(1, a.secondValue()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/SimpleStaticTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/SimpleStaticTest.java index 65438c9f..11916dda 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/SimpleStaticTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/SimpleStaticTest.java @@ -37,92 +37,92 @@ import static org.junit.Assert.assertEquals; */ public class SimpleStaticTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); + @Before + public void setUp() throws Exception { + __toVersion__(0); - // E and Helper must be loaded and initialized - E e = new E(); - Helper h = new Helper(); - } + // E and Helper must be loaded and initialized + E e = new E(); + Helper h = new Helper(); + } - // Version 0 + // Version 0 - public static class Helper { - public static int getIntegerField() { - return E.integerField; - } + public static class Helper { + public static int getIntegerField() { + return E.integerField; + } - public static void setIntegerField(int x) { - E.integerField = x; - } + public static void setIntegerField(int x) { + E.integerField = x; + } - public static int getFinalIntegerField() { - return E.finalIntegerField; - } + public static int getFinalIntegerField() { + return E.finalIntegerField; } + } - public static class E { - public static int integerField = 10; + public static class E { + public static int integerField = 10; - public static E self = new E(); + public static E self = new E(); - // javac will generate "ConstantValue" attribute for this field! - public static final int finalIntegerField = 7; - } + // javac will generate "ConstantValue" attribute for this field! + public static final int finalIntegerField = 7; + } - public static class E___1 { - public static E___1 self = new E___1(); - } + public static class E___1 { + public static E___1 self = new E___1(); + } - // Version 1 - public static class E___2 { - public static int integerField = 10; + // Version 1 + public static class E___2 { + public static int integerField = 10; - // javac will generate "ConstantValue" attribute for this field! - public static final int finalIntegerField = 7; - } + // javac will generate "ConstantValue" attribute for this field! + public static final int finalIntegerField = 7; + } - @Test - public void testSimpleNewStaticField() { + @Test + public void testSimpleNewStaticField() { - assert __version__() == 0; + assert __version__() == 0; - __toVersion__(1); + __toVersion__(1); - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - @Override - public void run() { - Helper.getIntegerField(); - } - }); + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + @Override + public void run() { + Helper.getIntegerField(); + } + }); - __toVersion__(2); + __toVersion__(2); - assertEquals(0, Helper.getIntegerField()); - assertEquals(7, Helper.getFinalIntegerField()); - Helper.setIntegerField(1000); - assertEquals(1000, Helper.getIntegerField()); + assertEquals(0, Helper.getIntegerField()); + assertEquals(7, Helper.getFinalIntegerField()); + Helper.setIntegerField(1000); + assertEquals(1000, Helper.getIntegerField()); - __toVersion__(1); + __toVersion__(1); - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - @Override - public void run() { - Helper.getIntegerField(); - } - }); + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + @Override + public void run() { + Helper.getIntegerField(); + } + }); - __toVersion__(2); + __toVersion__(2); - assertEquals(0, Helper.getIntegerField()); - assertEquals(7, Helper.getFinalIntegerField()); - Helper.setIntegerField(1000); - assertEquals(1000, Helper.getIntegerField()); + assertEquals(0, Helper.getIntegerField()); + assertEquals(7, Helper.getFinalIntegerField()); + Helper.setIntegerField(1000); + assertEquals(1000, Helper.getIntegerField()); - __toVersion__(0); + __toVersion__(0); - assertEquals(7, Helper.getFinalIntegerField()); - assertEquals(1000, Helper.getIntegerField()); - } + assertEquals(7, Helper.getFinalIntegerField()); + assertEquals(1000, Helper.getIntegerField()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/StaticTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/StaticTest.java index 7b46c971..22add245 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/StaticTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/StaticTest.java @@ -39,260 +39,260 @@ import static org.junit.Assert.*; */ public class StaticTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } - - // Version 0 + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + // Version 0 - public static class Helper { - public static int getAdditionalField() { - return -1; - } - public static void setAdditionalField(int x) { - - } + public static class Helper { + public static int getAdditionalField() { + return -1; } - public static class A { + public static void setAdditionalField(int x) { - public static int value() { - return 1; - } } + } - public static class B { + public static class A { - public static int value() { - return 2; - } + public static int value() { + return 1; } + } - public static class C { - static { - System.out.println("Static initializer of C"); - } - - public static int value = 5; - } + public static class B { - public static class D { - public static List objectField = new ArrayList(); - public static int[] arrayField = new int[10]; - public static int integerField = 5; - public static char characterField = 6; - public static short shortField = 7; - public static double doubleField = 1.0; - public static float floatField = 2.0f; - public static long longField = 8; - public static boolean booleanField = true; + public static int value() { + return 2; } + } - // Version 1 - public static class A___1 { - - public static int value() { - return B.value() * 2; - } + public static class C { + static { + System.out.println("Static initializer of C"); } - // Version 2 - public static class B___2 { - - public static int value() { - return 3; - } + public static int value = 5; + } + + public static class D { + public static List objectField = new ArrayList(); + public static int[] arrayField = new int[10]; + public static int integerField = 5; + public static char characterField = 6; + public static short shortField = 7; + public static double doubleField = 1.0; + public static float floatField = 2.0f; + public static long longField = 8; + public static boolean booleanField = true; + } + + // Version 1 + public static class A___1 { + + public static int value() { + return B.value() * 2; } + } - // Version 3 - public static class A___3 { + // Version 2 + public static class B___2 { - public static int value() { - return 5; - } + public static int value() { + return 3; } + } - public static class B___3 { + // Version 3 + public static class A___3 { - public static int value() { - return A.value() * 2; - } + public static int value() { + return 5; } + } - // Version 4 - public static class C___4 { - - static { - System.out.println("Static initializer of C-4"); - } + public static class B___3 { - public static int value = 6; + public static int value() { + return A.value() * 2; } + } - public static class Helper___5 { - public static int getAdditionalField() { - return D___5.additionalField; - } + // Version 4 + public static class C___4 { - public static void setAdditionalField(int x) { - D___5.additionalField = x; - } + static { + System.out.println("Static initializer of C-4"); } - public static class D___5 { - public static int additionalField; - - public static List objectField; - public static long longField; - public static short shortField = 10; - public static float floatField; - public static int[] arrayField; - public static int integerField; - public static char characterField; - public static double doubleField; - public static boolean booleanField; - } + public static int value = 6; + } - public static class E { - public static Class<?> eClass = E.class; - public static Class<?> eClassArr = E[].class; - public static Class<?> eClassNull; - public static Class<?> eClassPrim = Integer.TYPE; + public static class Helper___5 { + public static int getAdditionalField() { + return D___5.additionalField; } - public static class E___6 { - public static Class<?> eClass; - public static Class<?> eClassArr; - public static Class<?> eClassNull; - public static Class<?> eClassPrim; + public static void setAdditionalField(int x) { + D___5.additionalField = x; } + } - @Test - public void testBase() { - - assert __version__() == 0; - - - assertEquals(1, A.value()); - assertEquals(2, B.value()); - - __toVersion__(1); - - assertEquals(4, A.value()); - assertEquals(2, B.value()); - - __toVersion__(2); - - assertEquals(6, A.value()); - assertEquals(3, B.value()); - - __toVersion__(3); - - assertEquals(5, A.value()); - assertEquals(10, B.value()); - - __toVersion__(0); - - assertEquals(1, A.value()); - assertEquals(2, B.value()); - } - - @Test - public void testStaticField() { - - assert __version__() == 0; - assertEquals(5, C.value); - - __toVersion__(4); - assertEquals(5, C.value); - - __toVersion__(0); - assertEquals(5, C.value); - } - - @Test - public void testStaticFieldUpdated() { - assert __version__() == 0; - assertEquals(E.class, E.eClass); - assertNull(E.eClassNull); - assertEquals(E[].class, E.eClassArr); - - __toVersion__(6); - assertEquals(E.class, E.eClass); - assertNull(E.eClassNull); - assertEquals(E[].class, E.eClassArr); - } - - @Test - public void testManyStaticFields() { - - assert __version__() == 0; - assertTrue(D.objectField != null); - assertTrue(D.arrayField != null); - assertEquals(5, D.integerField); - assertEquals(6, D.characterField); - assertEquals(7, D.shortField); - assertEquals(1.0, D.doubleField, 0.0); - assertEquals(2.0f, D.floatField, 0.0); - assertEquals(8, D.longField); - assertEquals(true, D.booleanField); - - __toVersion__(5); - assertTrue(D.objectField != null); - assertTrue(D.arrayField != null); - assertEquals(5, D.integerField); - assertEquals(6, D.characterField); - assertEquals(7, D.shortField); - assertEquals(1.0, D.doubleField, 0.0); - assertEquals(2.0f, D.floatField, 0.0); - assertEquals(8, D.longField); - assertEquals(true, D.booleanField); - - assertEquals(0, Helper.getAdditionalField()); - Helper.setAdditionalField(1000); - assertEquals(1000, Helper.getAdditionalField()); - - - __toVersion__(0); - - assertTrue(D.objectField != null); - assertTrue(D.arrayField != null); - assertEquals(5, D.integerField); - assertEquals(6, D.characterField); - assertEquals(7, D.shortField); - assertEquals(1.0, D.doubleField, 0.0); - assertEquals(2.0f, D.floatField, 0.0); - assertEquals(8, D.longField); - assertEquals(true, D.booleanField); - - __toVersion__(5); - assertTrue(D.objectField != null); - assertTrue(D.arrayField != null); - assertEquals(5, D.integerField); - assertEquals(6, D.characterField); - assertEquals(7, D.shortField); - assertEquals(1.0, D.doubleField, 0.0); - assertEquals(2.0f, D.floatField, 0.0); - assertEquals(8, D.longField); - assertEquals(true, D.booleanField); - - assertEquals(0, Helper.getAdditionalField()); - - __toVersion__(0); - assertTrue(D.objectField != null); - assertTrue(D.arrayField != null); - assertEquals(5, D.integerField); - assertEquals(6, D.characterField); - assertEquals(7, D.shortField); - assertEquals(1.0, D.doubleField, 0.0); - assertEquals(2.0f, D.floatField, 0.0); - assertEquals(8, D.longField); - assertEquals(true, D.booleanField); - - } + public static class D___5 { + public static int additionalField; + + public static List objectField; + public static long longField; + public static short shortField = 10; + public static float floatField; + public static int[] arrayField; + public static int integerField; + public static char characterField; + public static double doubleField; + public static boolean booleanField; + } + + public static class E { + public static Class<?> eClass = E.class; + public static Class<?> eClassArr = E[].class; + public static Class<?> eClassNull; + public static Class<?> eClassPrim = Integer.TYPE; + } + + public static class E___6 { + public static Class<?> eClass; + public static Class<?> eClassArr; + public static Class<?> eClassNull; + public static Class<?> eClassPrim; + } + + @Test + public void testBase() { + + assert __version__() == 0; + + + assertEquals(1, A.value()); + assertEquals(2, B.value()); + + __toVersion__(1); + + assertEquals(4, A.value()); + assertEquals(2, B.value()); + + __toVersion__(2); + + assertEquals(6, A.value()); + assertEquals(3, B.value()); + + __toVersion__(3); + + assertEquals(5, A.value()); + assertEquals(10, B.value()); + + __toVersion__(0); + + assertEquals(1, A.value()); + assertEquals(2, B.value()); + } + + @Test + public void testStaticField() { + + assert __version__() == 0; + assertEquals(5, C.value); + + __toVersion__(4); + assertEquals(5, C.value); + + __toVersion__(0); + assertEquals(5, C.value); + } + + @Test + public void testStaticFieldUpdated() { + assert __version__() == 0; + assertEquals(E.class, E.eClass); + assertNull(E.eClassNull); + assertEquals(E[].class, E.eClassArr); + + __toVersion__(6); + assertEquals(E.class, E.eClass); + assertNull(E.eClassNull); + assertEquals(E[].class, E.eClassArr); + } + + @Test + public void testManyStaticFields() { + + assert __version__() == 0; + assertTrue(D.objectField != null); + assertTrue(D.arrayField != null); + assertEquals(5, D.integerField); + assertEquals(6, D.characterField); + assertEquals(7, D.shortField); + assertEquals(1.0, D.doubleField, 0.0); + assertEquals(2.0f, D.floatField, 0.0); + assertEquals(8, D.longField); + assertEquals(true, D.booleanField); + + __toVersion__(5); + assertTrue(D.objectField != null); + assertTrue(D.arrayField != null); + assertEquals(5, D.integerField); + assertEquals(6, D.characterField); + assertEquals(7, D.shortField); + assertEquals(1.0, D.doubleField, 0.0); + assertEquals(2.0f, D.floatField, 0.0); + assertEquals(8, D.longField); + assertEquals(true, D.booleanField); + + assertEquals(0, Helper.getAdditionalField()); + Helper.setAdditionalField(1000); + assertEquals(1000, Helper.getAdditionalField()); + + + __toVersion__(0); + + assertTrue(D.objectField != null); + assertTrue(D.arrayField != null); + assertEquals(5, D.integerField); + assertEquals(6, D.characterField); + assertEquals(7, D.shortField); + assertEquals(1.0, D.doubleField, 0.0); + assertEquals(2.0f, D.floatField, 0.0); + assertEquals(8, D.longField); + assertEquals(true, D.booleanField); + + __toVersion__(5); + assertTrue(D.objectField != null); + assertTrue(D.arrayField != null); + assertEquals(5, D.integerField); + assertEquals(6, D.characterField); + assertEquals(7, D.shortField); + assertEquals(1.0, D.doubleField, 0.0); + assertEquals(2.0f, D.floatField, 0.0); + assertEquals(8, D.longField); + assertEquals(true, D.booleanField); + + assertEquals(0, Helper.getAdditionalField()); + + __toVersion__(0); + assertTrue(D.objectField != null); + assertTrue(D.arrayField != null); + assertEquals(5, D.integerField); + assertEquals(6, D.characterField); + assertEquals(7, D.shortField); + assertEquals(1.0, D.doubleField, 0.0); + assertEquals(2.0f, D.floatField, 0.0); + assertEquals(8, D.longField); + assertEquals(true, D.booleanField); + + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/body/StressTest.java b/dcevm/src/test/java7/com/github/dcevm/test/body/StressTest.java index 21cae9f4..e7e043a0 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/body/StressTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/body/StressTest.java @@ -36,47 +36,47 @@ import static org.junit.Assert.assertEquals; */ public class StressTest { - public final static int COUNT = 10; + public final static int COUNT = 10; - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 1; - } + public int value() { + return 1; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 2; - } + public int value() { + return 2; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } - - @Test - public void testStressSwap() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; + @Test + public void testStressSwap() { - A a = new A(); + assert __version__() == 0; - for (int i = 0; i < COUNT; i++) { + A a = new A(); - assertEquals(1, a.value()); + for (int i = 0; i < COUNT; i++) { - __toVersion__(1); + assertEquals(1, a.value()); - assertEquals(2, a.value()); + __toVersion__(1); - __toVersion__(0); - } + assertEquals(2, a.value()); - assertEquals(1, a.value()); + __toVersion__(0); } + + assertEquals(1, a.value()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/eval/AddingInterfaceTest.java b/dcevm/src/test/java7/com/github/dcevm/test/eval/AddingInterfaceTest.java index 223073c3..155e1145 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/eval/AddingInterfaceTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/eval/AddingInterfaceTest.java @@ -39,84 +39,84 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; */ public class AddingInterfaceTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - assert __version__() == 0; - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + assert __version__() == 0; + } - public static class A { + public static class A { - public int getValue() { - return 1; - } + public int getValue() { + return 1; } + } - public static interface I { + public static interface I { - public int getValue(); - } + public int getValue(); + } - public static class A___1 implements I { + public static class A___1 implements I { - @Override - public int getValue() { - return 1; - } + @Override + public int getValue() { + return 1; } + } - public static class Proxy implements I { + public static class Proxy implements I { - private A a; + private A a; - public Proxy(A a) { - this.a = a; - } + public Proxy(A a) { + this.a = a; + } - @Override - public int getValue() { - return a.getValue(); - } + @Override + public int getValue() { + return a.getValue(); } + } - @Test - public void testAddInterface() { + @Test + public void testAddInterface() { - A a = new A(); - Proxy p = new Proxy(a); + A a = new A(); + Proxy p = new Proxy(a); - final int N = 100000; - final int Z = 1; + final int N = 100000; + final int Z = 1; - __toVersion__(1); - I i = (I) a; + __toVersion__(1); + I i = (I) a; - long startTime = System.currentTimeMillis(); - for (int j = 0; j < Z; j++) { - calculateSum(N, i); - } - long time = System.currentTimeMillis() - startTime; - System.out.println(time); + long startTime = System.currentTimeMillis(); + for (int j = 0; j < Z; j++) { + calculateSum(N, i); + } + long time = System.currentTimeMillis() - startTime; + System.out.println(time); - // Must set to null, otherwise local variable i would violate type safety - i = null; + // Must set to null, otherwise local variable i would violate type safety + i = null; - TestUtil.assertUnsupportedToVersionWithLight(AddingInterfaceTest.class, 0); + TestUtil.assertUnsupportedToVersionWithLight(AddingInterfaceTest.class, 0); - startTime = System.currentTimeMillis(); - for (int j = 0; j < Z; j++) { - calculateSum(N, p); - } - time = System.currentTimeMillis() - startTime; - System.out.println(time); + startTime = System.currentTimeMillis(); + for (int j = 0; j < Z; j++) { + calculateSum(N, p); } - - public int calculateSum(int n, I i) { - int sum = 0; - for (int j = 0; j < n; j++) { - sum += i.getValue(); - } - return sum; + time = System.currentTimeMillis() - startTime; + System.out.println(time); + } + + public int calculateSum(int n, I i) { + int sum = 0; + for (int j = 0; j < n; j++) { + sum += i.getValue(); } + return sum; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/eval/FractionTest.java b/dcevm/src/test/java7/com/github/dcevm/test/eval/FractionTest.java index 24460ffc..e7283f60 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/eval/FractionTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/eval/FractionTest.java @@ -39,218 +39,218 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; */ public class FractionTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - assert __version__() == 0; + @Before + public void setUp() throws Exception { + __toVersion__(0); + assert __version__() == 0; + } + + // Version 0 + public static class NoChange { + + int i1; + int i2; + int i3; + Object o1; + Object o2; + Object o3; + } + + public static class Change { + + int i1; + int i2; + int i3; + Object o1; + Object o2; + Object o3; + } + + // Version 1 + public static class Change___1 { + + int i1; + int i2; + int i3; + Object o1; + Object o2; + Object o3; + Object o4; + } + + // Version 2 + public static class Change___2 { + + int i1; + int i2; + int i3; + Object o1; + } + + // Version 3 + public static class Change___3 { + + int i3; + int i1; + int i2; + Object o3; + Object o1; + Object o2; + } + + // Version 3 + public static class Change___4 { + + int i1; + int i2; + int i3; + Object o1; + Object o2; + Object o3; + } + + // Version 2 + public static class Change___5 { + + } + + private static List<Long> measurements = new ArrayList<Long>(); + private final int BASE = 10; + private Object[] objects; + + private void clear() { + objects = null; + System.gc(); + System.gc(); + __toVersion__(0); + System.gc(); + System.gc(); + + } + + private void init(int count, int percent) { + objects = new Object[count]; + int changed = 0; + int unchanged = 0; + for (int k = 0; k < count; k++) { + if ((count / BASE) * percent <= k/* && k >= 200000*/) { + objects[k] = new NoChange(); + unchanged++; + } else { + objects[k] = new Change(); + changed++; + } } - // Version 0 - public static class NoChange { + System.gc(); - int i1; - int i2; - int i3; - Object o1; - Object o2; - Object o3; - } - - public static class Change { - - int i1; - int i2; - int i3; - Object o1; - Object o2; - Object o3; - } - - // Version 1 - public static class Change___1 { - - int i1; - int i2; - int i3; - Object o1; - Object o2; - Object o3; - Object o4; - } - - // Version 2 - public static class Change___2 { - - int i1; - int i2; - int i3; - Object o1; - } - - // Version 3 - public static class Change___3 { - - int i3; - int i1; - int i2; - Object o3; - Object o1; - Object o2; - } - - // Version 3 - public static class Change___4 { - - int i1; - int i2; - int i3; - Object o1; - Object o2; - Object o3; - } + System.out.println(changed + " changed objects allocated"); + } - // Version 2 - public static class Change___5 { + @Test + public void testBase() { - } + assert __version__() == 0; - private static List<Long> measurements = new ArrayList<Long>(); - private final int BASE = 10; - private Object[] objects; + final int N = 1; + final int INC = 4; + final int SIZE = 4000; - private void clear() { - objects = null; - System.gc(); - System.gc(); - __toVersion__(0); - System.gc(); - System.gc(); + int[] benchmarking = new int[]{SIZE}; + int base = BASE; + int start = 0; - } + MicroBenchmark[] benchmarks = new MicroBenchmark[]{new GCMicroBenchmark(), new IncreaseMicroBenchmark(), new DecreaseMicroBenchmark(), new ReorderMicroBenchmark(), new NoRealChangeMicroBenchmark(), new BigDecreaseMicroBenchmark()}; - private void init(int count, int percent) { - objects = new Object[count]; - int changed = 0; - int unchanged = 0; - for (int k = 0; k < count; k++) { - if ((count / BASE) * percent <= k/* && k >= 200000*/) { - objects[k] = new NoChange(); - unchanged++; - } else { - objects[k] = new Change(); - changed++; - } + clear(); + for (int k = 0; k < N; k++) { + for (MicroBenchmark m : benchmarks) { + for (int i : benchmarking) { + System.out.println(m.getClass().getName() + " with " + i + " objects"); + for (int j = start; j <= base; j += INC) { + System.out.println(j); + m.init(i); + init(i, j); + m.doit(i, measurements); + clear(); + } } - - System.gc(); - - System.out.println(changed + " changed objects allocated"); + } } - @Test - public void testBase() { - - assert __version__() == 0; - - final int N = 1; - final int INC = 4; - final int SIZE = 4000; - - int[] benchmarking = new int[]{SIZE}; - int base = BASE; - int start = 0; - - MicroBenchmark[] benchmarks = new MicroBenchmark[]{new GCMicroBenchmark(), new IncreaseMicroBenchmark(), new DecreaseMicroBenchmark(), new ReorderMicroBenchmark(), new NoRealChangeMicroBenchmark(), new BigDecreaseMicroBenchmark()}; - - clear(); - for (int k = 0; k < N; k++) { - for (MicroBenchmark m : benchmarks) { - for (int i : benchmarking) { - System.out.println(m.getClass().getName() + " with " + i + " objects"); - for (int j = start; j <= base; j += INC) { - System.out.println(j); - m.init(i); - init(i, j); - m.doit(i, measurements); - clear(); - } - } - } - } - - System.out.println("Results:"); - for (long l : measurements) { - System.out.println(l); - } - measurements.clear(); + System.out.println("Results:"); + for (long l : measurements) { + System.out.println(l); } + measurements.clear(); + } } abstract class MicroBenchmark { - public void init(int count) { - } + public void init(int count) { + } - public abstract void doit(int count, List<Long> measurements); + public abstract void doit(int count, List<Long> measurements); } class GCMicroBenchmark extends MicroBenchmark { - @Override - public void doit(int count, List<Long> measurements) { - long startTime = System.currentTimeMillis(); - System.gc(); - long curTime = System.currentTimeMillis() - startTime; - measurements.add(curTime); - } + @Override + public void doit(int count, List<Long> measurements) { + long startTime = System.currentTimeMillis(); + System.gc(); + long curTime = System.currentTimeMillis() - startTime; + measurements.add(curTime); + } } class IncreaseMicroBenchmark extends MicroBenchmark { - @Override - public void doit(int count, List<Long> measurements) { - HotSwapTool.resetTimings(); - __toVersion__(1); - measurements.add(HotSwapTool.getTotalTime()); - } + @Override + public void doit(int count, List<Long> measurements) { + HotSwapTool.resetTimings(); + __toVersion__(1); + measurements.add(HotSwapTool.getTotalTime()); + } } class DecreaseMicroBenchmark extends MicroBenchmark { - @Override - public void doit(int count, List<Long> measurements) { - HotSwapTool.resetTimings(); - __toVersion__(2); - measurements.add(HotSwapTool.getTotalTime()); - } + @Override + public void doit(int count, List<Long> measurements) { + HotSwapTool.resetTimings(); + __toVersion__(2); + measurements.add(HotSwapTool.getTotalTime()); + } } class ReorderMicroBenchmark extends MicroBenchmark { - @Override - public void doit(int count, List<Long> measurements) { - HotSwapTool.resetTimings(); - __toVersion__(3); - measurements.add(HotSwapTool.getTotalTime()); - } + @Override + public void doit(int count, List<Long> measurements) { + HotSwapTool.resetTimings(); + __toVersion__(3); + measurements.add(HotSwapTool.getTotalTime()); + } } class NoRealChangeMicroBenchmark extends MicroBenchmark { - @Override - public void doit(int count, List<Long> measurements) { - HotSwapTool.resetTimings(); - __toVersion__(4); - measurements.add(HotSwapTool.getTotalTime()); - } + @Override + public void doit(int count, List<Long> measurements) { + HotSwapTool.resetTimings(); + __toVersion__(4); + measurements.add(HotSwapTool.getTotalTime()); + } } class BigDecreaseMicroBenchmark extends MicroBenchmark { - @Override - public void doit(int count, List<Long> measurements) { - HotSwapTool.resetTimings(); - __toVersion__(5); - measurements.add(HotSwapTool.getTotalTime()); - } + @Override + public void doit(int count, List<Long> measurements) { + HotSwapTool.resetTimings(); + __toVersion__(5); + measurements.add(HotSwapTool.getTotalTime()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/eval/GeometryScenario.java b/dcevm/src/test/java7/com/github/dcevm/test/eval/GeometryScenario.java index f50ad95f..92970b8f 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/eval/GeometryScenario.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/eval/GeometryScenario.java @@ -38,170 +38,170 @@ import static org.junit.Assert.assertEquals; */ public class GeometryScenario { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class Point { + // Version 0 + public static class Point { - private int x; - private int y; + private int x; + private int y; - public Point(int x, int y) { - this.x = x; - this.y = y; - } + public Point(int x, int y) { + this.x = x; + this.y = y; + } - public boolean isBottomRightOf(Point p) { - return p.x >= x && p.y >= y; - } + public boolean isBottomRightOf(Point p) { + return p.x >= x && p.y >= y; + } - public boolean isTopLeftOf(Point p) { - return p.x <= x && p.y <= y; - } + public boolean isTopLeftOf(Point p) { + return p.x <= x && p.y <= y; + } - public int getX() { - return x; - } + public int getX() { + return x; + } - public int getY() { - return y; - } + public int getY() { + return y; } + } - public static interface IFigure { + public static interface IFigure { - public boolean isHitAt(Point p); - } + public boolean isHitAt(Point p); + } - public static class Rectangle { + public static class Rectangle { - private Point topLeft; - private Point bottomRight; + private Point topLeft; + private Point bottomRight; - public Rectangle(Point p1, Point p2) { - topLeft = p1; - bottomRight = p2; - } + public Rectangle(Point p1, Point p2) { + topLeft = p1; + bottomRight = p2; + } - public boolean isHitAt(Point p) { - return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight); - } + public boolean isHitAt(Point p) { + return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight); + } - public Point getTopLeft() { - return topLeft; - } + public Point getTopLeft() { + return topLeft; + } - public Point getBottomRight() { - return bottomRight; - } + public Point getBottomRight() { + return bottomRight; + } - public static Rectangle create(Point p) { - return (Rectangle) (Object) (new Rectangle___1(p)); - } + public static Rectangle create(Point p) { + return (Rectangle) (Object) (new Rectangle___1(p)); } + } - // Version 1 - public static class Rectangle___1 implements IFigure { + // Version 1 + public static class Rectangle___1 implements IFigure { - private Point topLeft; - private Point center; - private Point bottomRight; + private Point topLeft; + private Point center; + private Point bottomRight; - public Point getCenter() { - return center; - } + public Point getCenter() { + return center; + } - public Rectangle___1(Point p) { - topLeft = p; - bottomRight = p; - } + public Rectangle___1(Point p) { + topLeft = p; + bottomRight = p; + } - @Override - public boolean isHitAt(Point p) { - return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight); - } + @Override + public boolean isHitAt(Point p) { + return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight); + } - public Point getTopLeft() { - return topLeft; - } + public Point getTopLeft() { + return topLeft; + } - public Point getBottomRight() { - return bottomRight; - } + public Point getBottomRight() { + return bottomRight; + } - public static Rectangle create(Point p) { - return (Rectangle) (Object) (new Rectangle___1(p)); - } + public static Rectangle create(Point p) { + return (Rectangle) (Object) (new Rectangle___1(p)); } + } - public static class Point___1 { + public static class Point___1 { - private char x1; - private int y; - private char x2; + private char x1; + private int y; + private char x2; - public boolean isBottomRightOf(Point p) { - return p.x >= x1 && p.y >= y; - } + public boolean isBottomRightOf(Point p) { + return p.x >= x1 && p.y >= y; + } - public boolean isTopLeftOf(Point p) { - return p.x <= x1 && p.y <= y; - } + public boolean isTopLeftOf(Point p) { + return p.x <= x1 && p.y <= y; + } - public int getY() { - return y; - } + public int getY() { + return y; + } - public int getX() { - return x1; - } + public int getX() { + return x1; + } - public char getX2() { - return x2; - } + public char getX2() { + return x2; } + } - @Test - public void testContructorChange() { + @Test + public void testContructorChange() { - assert __version__() == 0; + assert __version__() == 0; - final Point p1 = new Point(1, 2); - final Point p2 = new Point(3, 4); - final Rectangle r1 = new Rectangle(p1, p2); + final Point p1 = new Point(1, 2); + final Point p2 = new Point(3, 4); + final Rectangle r1 = new Rectangle(p1, p2); - assertEquals(1, p1.getX()); - assertEquals(2, p1.getY()); - assertEquals(3, p2.getX()); - assertEquals(4, p2.getY()); - assertEquals(p1, r1.getTopLeft()); - assertEquals(p2, r1.getBottomRight()); + assertEquals(1, p1.getX()); + assertEquals(2, p1.getY()); + assertEquals(3, p2.getX()); + assertEquals(4, p2.getY()); + assertEquals(p1, r1.getTopLeft()); + assertEquals(p2, r1.getBottomRight()); + + __toVersion__(1); - __toVersion__(1); + final Rectangle r4 = Rectangle.create(p1); + assertEquals(0, p1.getX()); + assertEquals(2, p1.getY()); + assertEquals(0, p2.getX()); + assertEquals(4, p2.getY()); + assertEquals(p1, r4.getTopLeft()); + assertEquals(p1, r4.getBottomRight()); - final Rectangle r4 = Rectangle.create(p1); + TestUtil.assertUnsupportedWithLight(new Runnable() { + + @Override + public void run() { + __toVersion__(0); assertEquals(0, p1.getX()); assertEquals(2, p1.getY()); assertEquals(0, p2.getX()); assertEquals(4, p2.getY()); assertEquals(p1, r4.getTopLeft()); assertEquals(p1, r4.getBottomRight()); - - TestUtil.assertUnsupportedWithLight(new Runnable() { - - @Override - public void run() { - __toVersion__(0); - assertEquals(0, p1.getX()); - assertEquals(2, p1.getY()); - assertEquals(0, p2.getX()); - assertEquals(4, p2.getY()); - assertEquals(p1, r4.getTopLeft()); - assertEquals(p1, r4.getBottomRight()); - } - }); - } + } + }); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedFieldTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedFieldTest.java index dee249d5..59eeb905 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedFieldTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedFieldTest.java @@ -41,157 +41,157 @@ import static org.junit.Assert.assertEquals; */ public class AccessDeletedFieldTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int x; + public int x; - int getFieldInOldCode() { - - __toVersion__(1); + int getFieldInOldCode() { - // This field does no longer exist - return x; - } - } + __toVersion__(1); - public static class B extends A { + // This field does no longer exist + return x; } + } - // Version 1 - public static class A___1 { - } + public static class B extends A { + } - // Version 2 - public static class B___2 { - } + // Version 1 + public static class A___1 { + } - // Method to enforce cast (otherwise bytecodes become invalid in version 2) - public static A convertBtoA(Object b) { - return (A) b; - } + // Version 2 + public static class B___2 { + } - @Test - public void testOldCodeAccessesDeletedField() { + // Method to enforce cast (otherwise bytecodes become invalid in version 2) + public static A convertBtoA(Object b) { + return (A) b; + } - assert __version__() == 0; + @Test + public void testOldCodeAccessesDeletedField() { - final A a = new A(); - a.x = 1; + assert __version__() == 0; - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - @Override - public void run() { - assertEquals(0, a.getFieldInOldCode()); - } - }); + final A a = new A(); + a.x = 1; - assert __version__() == 1; - __toVersion__(0); - assertEquals(0, a.x); - } + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + @Override + public void run() { + assertEquals(0, a.getFieldInOldCode()); + } + }); - @Test - public void testAccessDeletedField() { + assert __version__() == 1; + __toVersion__(0); + assertEquals(0, a.x); + } - assert __version__() == 0; + @Test + public void testAccessDeletedField() { - final A a = new A(); - a.x = 1; + assert __version__() == 0; - assertEquals(1, a.x); + final A a = new A(); + a.x = 1; - __toVersion__(1); + assertEquals(1, a.x); - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - @Override - public void run() { - System.out.println(a.x); - } - }); + __toVersion__(1); - __toVersion__(0); - assertEquals(0, a.x); - } + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + @Override + public void run() { + System.out.println(a.x); + } + }); - @Test - @Category(Full.class) - public void testAccessDeleteBaseClassFieldNormal() { + __toVersion__(0); + assertEquals(0, a.x); + } - __toVersion__(0); - assert __version__() == 0; - final B b = new B(); - b.x = 1; - final A a = new A(); - a.x = 2; + @Test + @Category(Full.class) + public void testAccessDeleteBaseClassFieldNormal() { - assertEquals(1, b.x); - assertEquals(2, a.x); + __toVersion__(0); + assert __version__() == 0; + final B b = new B(); + b.x = 1; + final A a = new A(); + a.x = 2; - __toVersion__(2); + assertEquals(1, b.x); + assertEquals(2, a.x); - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + __toVersion__(2); - @Override - public void run() { - System.out.println(b.x); - } - }); + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - assertEquals(2, a.x); + @Override + public void run() { + System.out.println(b.x); + } + }); - __toVersion__(0); - assertEquals(0, b.x); - } + assertEquals(2, a.x); - @Test - @Category(Full.class) - public void testAccessDeleteBaseClassFieldInvalid() { + __toVersion__(0); + assertEquals(0, b.x); + } - __toVersion__(0); - assert __version__() == 0; - final B b = new B(); - final A a1 = new A(); - a1.x = 1; - b.x = 1; + @Test + @Category(Full.class) + public void testAccessDeleteBaseClassFieldInvalid() { - __toVersion__(2); + __toVersion__(0); + assert __version__() == 0; + final B b = new B(); + final A a1 = new A(); + a1.x = 1; + b.x = 1; - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + __toVersion__(2); - @Override - public void run() { - System.out.println(b.x); - } - }); + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - assertEquals(1, a1.x); + @Override + public void run() { + System.out.println(b.x); + } + }); - __toVersion__(0); - assertEquals(0, b.x); - assertEquals(1, a1.x); + assertEquals(1, a1.x); - A a = convertBtoA(b); + __toVersion__(0); + assertEquals(0, b.x); + assertEquals(1, a1.x); - assertEquals(0, b.x); + A a = convertBtoA(b); - // Must fail, because now an instance of B is in a local variable of type A! - TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { + assertEquals(0, b.x); - @Override - public void run() { - __toVersion__(2); - } - }); + // Must fail, because now an instance of B is in a local variable of type A! + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { - assertEquals(0, a.x); + @Override + public void run() { + __toVersion__(2); + } + }); - // Still at version 0 - assert __version__() == 0; - } + assertEquals(0, a.x); + + // Still at version 0 + assert __version__() == 0; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedStaticFieldTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedStaticFieldTest.java index 32fe5829..d52de01f 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedStaticFieldTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/AccessDeletedStaticFieldTest.java @@ -40,87 +40,87 @@ import static org.junit.Assert.assertEquals; */ public class AccessDeletedStaticFieldTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public static int x; + public static int x; - static int getFieldInOldCode() { - - __toVersion__(1); + static int getFieldInOldCode() { - newMethodFromOldCode(); + __toVersion__(1); - // This field does no longer exist - return x; - } + newMethodFromOldCode(); - static int getFieldEMCPMethod() { - __toVersion__(2); - return A.x; - } + // This field does no longer exist + return x; } - // Version 1 - public static class A___1 { + static int getFieldEMCPMethod() { + __toVersion__(2); + return A.x; } + } - // Version 2 + // Version 1 + public static class A___1 { + } - public static class A___2 { + // Version 2 - // EMCP to method in version 0 - static int getFieldEMCPMethod() { - __toVersion__(2); - return A.x; - } - } + public static class A___2 { - private static void newMethodFromOldCode() { - TestUtil.assertException(NoSuchFieldError.class, new Runnable() { - @Override - public void run() { - System.out.println(A.x); - } - }); + // EMCP to method in version 0 + static int getFieldEMCPMethod() { + __toVersion__(2); + return A.x; } + } - @Test - @Category(Full.class) - public void testAccessDeletedStaticField() { + private static void newMethodFromOldCode() { + TestUtil.assertException(NoSuchFieldError.class, new Runnable() { + @Override + public void run() { + System.out.println(A.x); + } + }); + } - assert __version__() == 0; + @Test + @Category(Full.class) + public void testAccessDeletedStaticField() { - A.x = 1; - assertEquals(1, A.getFieldInOldCode()); + assert __version__() == 0; - assert __version__() == 1; - __toVersion__(0); - assertEquals(0, A.x); - - assert __version__() == 0; - } + A.x = 1; + assertEquals(1, A.getFieldInOldCode()); + assert __version__() == 1; + __toVersion__(0); + assertEquals(0, A.x); - @Test - public void testAccessDeletedStaticFieldFromEMCPMethod() { + assert __version__() == 0; + } - 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; - } + @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; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/ComplexFieldTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/ComplexFieldTest.java index f0f7dfa9..61f9564a 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/ComplexFieldTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/ComplexFieldTest.java @@ -38,67 +38,67 @@ import static org.junit.Assert.assertEquals; */ public class ComplexFieldTest { - // Version 0 - public static class A { - public byte byteFld = 10; - public short shortFld = 20; - public int intFld = 30; - public long longFld = 40L; - public float floatFld = 50.2F; - public double doubleFld = 60.3D; - public char charFld = 'b'; - public boolean booleanFld = true; - public String stringFld = "OLD"; - } + // Version 0 + public static class A { + public byte byteFld = 10; + public short shortFld = 20; + public int intFld = 30; + public long longFld = 40L; + public float floatFld = 50.2F; + public double doubleFld = 60.3D; + public char charFld = 'b'; + public boolean booleanFld = true; + public String stringFld = "OLD"; + } - // Version 1 - public static class A___1 { - public byte byteFld = 11; - public short shortFld = 22; - public int intFld = 33; - public long longFld = 44L; - public float floatFld = 55.5F; - public double doubleFld = 66.6D; - public char charFld = 'c'; - public boolean booleanFld = false; - public String stringFld = "NEW"; + // Version 1 + public static class A___1 { + public byte byteFld = 11; + public short shortFld = 22; + public int intFld = 33; + public long longFld = 44L; + public float floatFld = 55.5F; + public double doubleFld = 66.6D; + public char charFld = 'c'; + public boolean booleanFld = false; + public String stringFld = "NEW"; - // completely new instance fields are below - public int intComplNewFld = 333; - public long longComplNewFld = 444L; - public String stringComplNewFld = "completely new String field"; - } + // completely new instance fields are below + public int intComplNewFld = 333; + public long longComplNewFld = 444L; + public String stringComplNewFld = "completely new String field"; + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - /** - * Checks that the given object is unmodified (i.e. the values of the fields are correct) - * - * @param a the object to be checked - */ - private void assertObjectOK(A a) { - assertEquals(10, a.byteFld); - assertEquals(20, a.shortFld); - assertEquals(30, a.intFld); - assertEquals(40L, a.longFld); - assertEquals(50.2F, a.floatFld, 0.01); - assertEquals(60.3D, a.doubleFld, 0.01); - assertEquals('b', a.charFld); - assertEquals(true, a.booleanFld); - assertEquals("OLD", a.stringFld); - } + /** + * Checks that the given object is unmodified (i.e. the values of the fields are correct) + * + * @param a the object to be checked + */ + private void assertObjectOK(A a) { + assertEquals(10, a.byteFld); + assertEquals(20, a.shortFld); + assertEquals(30, a.intFld); + assertEquals(40L, a.longFld); + assertEquals(50.2F, a.floatFld, 0.01); + assertEquals(60.3D, a.doubleFld, 0.01); + assertEquals('b', a.charFld); + assertEquals(true, a.booleanFld); + assertEquals("OLD", a.stringFld); + } - @Test - public void testComplexFieldChange() { - assert __version__() == 0; - A a = new A(); - assertObjectOK(a); - __toVersion__(1); - assertObjectOK(a); - __toVersion__(0); - assertObjectOK(a); - } + @Test + public void testComplexFieldChange() { + assert __version__() == 0; + A a = new A(); + assertObjectOK(a); + __toVersion__(1); + assertObjectOK(a); + __toVersion__(0); + assertObjectOK(a); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/EnumTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/EnumTest.java index 24836c4d..24d41a79 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/EnumTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/EnumTest.java @@ -37,34 +37,34 @@ import static org.junit.Assert.assertNotNull; */ public class EnumTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - static enum A { - FIRST, - SECOND; - } + static enum A { + FIRST, + SECOND; + } - static enum A___1 { - SECOND, - THIRD, - FOURTH; - } + static enum A___1 { + SECOND, + THIRD, + FOURTH; + } - @Test - @Ignore - public void testEnumFields() throws Exception { - assertEquals(2, A.values().length); - assertNotNull(A.values()[0]); - assertNotNull(A.values()[1]); + @Test + @Ignore + public void testEnumFields() throws Exception { + assertEquals(2, A.values().length); + assertNotNull(A.values()[0]); + assertNotNull(A.values()[1]); - __toVersion__(1); + __toVersion__(1); - assertEquals(3, A.values().length); - assertNotNull(A.values()[0]); - assertNotNull(A.values()[1]); - assertNotNull(A.values()[2]); - } + assertEquals(3, A.values().length); + assertNotNull(A.values()[0]); + assertNotNull(A.values()[1]); + assertNotNull(A.values()[2]); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldAlignmentTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldAlignmentTest.java index ee287224..7492d908 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldAlignmentTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldAlignmentTest.java @@ -37,27 +37,27 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; */ public class FieldAlignmentTest { - // Version 0 - public static class A { - } - - // Version 1 - public static class A___1 { - public boolean booleanFld; // note: gap betweer booleanFld and stringFld, should be properly filled. - public String stringFld = "NEW"; - } - - @Before - public void setUp() throws Exception { - __toVersion__(0); - } - - @Test - public void testComplexFieldChange() { - assert __version__() == 0; - A a = new A(); - __toVersion__(1); - System.gc(); // induce GC to verify that gap is properly filled - __toVersion__(0); - } + // Version 0 + public static class A { + } + + // Version 1 + public static class A___1 { + public boolean booleanFld; // note: gap betweer booleanFld and stringFld, should be properly filled. + public String stringFld = "NEW"; + } + + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + @Test + public void testComplexFieldChange() { + assert __version__() == 0; + A a = new A(); + __toVersion__(1); + System.gc(); // induce GC to verify that gap is properly filled + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldChangedOrderTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldChangedOrderTest.java index 1c98f6a2..1e50c311 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldChangedOrderTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldChangedOrderTest.java @@ -38,147 +38,147 @@ import static org.junit.Assert.assertEquals; */ public class FieldChangedOrderTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value1; - public int value2; + public int value1; + public int value2; - public A() { - value1 = 1; - value2 = 2; - } - - public int getValue1() { - return value1; - } - - public int getValue2() { - return value2; - } + public A() { + value1 = 1; + value2 = 2; } - public static class B { - - public static int getStaticValue1(A a) { - return a.value1; - } - - public static int getStaticValue2(A a) { - return a.value2; - } + public int getValue1() { + return value1; } - // Version 1 - public static class A___1 { + public int getValue2() { + return value2; + } + } - public int value2; - public int value1; + public static class B { - public int getValue1() { - return value1; - } + public static int getStaticValue1(A a) { + return a.value1; + } - public int getValue2() { - return value2; - } + public static int getStaticValue2(A a) { + return a.value2; } + } - public static class B___1 { + // Version 1 + public static class A___1 { - public static int getStaticValue1(A a) { - return a.value1; - } + public int value2; + public int value1; - public static int getStaticValue2(A a) { - return a.value2; - } + public int getValue1() { + return value1; } - // Version 2 - public static class A___2 { - - public int tmp1; - public int value2; - public int tmp2; - public int value1; - public int tmp3; + public int getValue2() { + return value2; + } + } - public int getValue1() { - return value1; - } + public static class B___1 { - public int getValue2() { - return value2; - } + public static int getStaticValue1(A a) { + return a.value1; } - // Version 3 - public static class A___3 { + public static int getStaticValue2(A a) { + return a.value2; + } + } - public int tmp1; - public int value2; + // Version 2 + public static class A___2 { - public int getValue1() { - return tmp1; - } + public int tmp1; + public int value2; + public int tmp2; + public int value1; + public int tmp3; - public int getValue2() { - return value2; - } + public int getValue1() { + return value1; } - @Before - public void setUp() throws Exception { - __toVersion__(0); + public int getValue2() { + return value2; } + } - @Test - public void testRenameField() { - assert __version__() == 0; - A a = new A(); - assertObjectOK(a); - __toVersion__(3); - assertEquals(0, a.getValue1()); - assertEquals(2, a.getValue2()); - __toVersion__(0); - assertEquals(0, a.getValue1()); - assertEquals(2, a.getValue2()); - } + // Version 3 + public static class A___3 { - @Test - public void testSimpleOrderChange() { - assert __version__() == 0; - A a = new A(); - assertObjectOK(a); - __toVersion__(1); - assertObjectOK(a); - __toVersion__(0); - assertObjectOK(a); - } + public int tmp1; + public int value2; - /** - * Checks that the given object is unmodified (i.e. the values of the fields are correct) - * - * @param a the object to be checked - */ - private void assertObjectOK(A a) { - assertEquals(1, a.getValue1()); - assertEquals(2, a.getValue2()); - assertEquals(1, B.getStaticValue1(a)); - assertEquals(2, B.getStaticValue2(a)); - assertEquals(1, a.value1); - assertEquals(2, a.value2); + public int getValue1() { + return tmp1; } - @Test - public void testSimpleOrderChangeWithNewTempFields() { - assert __version__() == 0; - A a = new A(); - assertObjectOK(a); - __toVersion__(2); - assertObjectOK(a); - __toVersion__(0); - assertObjectOK(a); + public int getValue2() { + return value2; } + } + + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + @Test + public void testRenameField() { + assert __version__() == 0; + A a = new A(); + assertObjectOK(a); + __toVersion__(3); + assertEquals(0, a.getValue1()); + assertEquals(2, a.getValue2()); + __toVersion__(0); + assertEquals(0, a.getValue1()); + assertEquals(2, a.getValue2()); + } + + @Test + public void testSimpleOrderChange() { + assert __version__() == 0; + A a = new A(); + assertObjectOK(a); + __toVersion__(1); + assertObjectOK(a); + __toVersion__(0); + assertObjectOK(a); + } + + /** + * Checks that the given object is unmodified (i.e. the values of the fields are correct) + * + * @param a the object to be checked + */ + private void assertObjectOK(A a) { + assertEquals(1, a.getValue1()); + assertEquals(2, a.getValue2()); + assertEquals(1, B.getStaticValue1(a)); + assertEquals(2, B.getStaticValue2(a)); + assertEquals(1, a.value1); + assertEquals(2, a.value2); + } + + @Test + public void testSimpleOrderChangeWithNewTempFields() { + assert __version__() == 0; + A a = new A(); + assertObjectOK(a); + __toVersion__(2); + assertObjectOK(a); + __toVersion__(0); + assertObjectOK(a); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldModificationTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldModificationTest.java index 8dd9dfcc..08705cb3 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldModificationTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/FieldModificationTest.java @@ -36,243 +36,243 @@ import static org.junit.Assert.assertEquals; */ public class FieldModificationTest { - // Version 0 - public static class A { - - public int val0; - public int val1; - public int val2; - public int val3; - public int val4; - public int val5; - public int val6; - public int val7; - - public void increaseAllByOne() { - val0++; - val1++; - val2++; - val3++; - val4++; - val5++; - val6++; - val7++; - } - - public int sum() { - return val0 + val1 + val2 + val3 + val4 + val5 + val6 + val7; - } + // Version 0 + public static class A { + + public int val0; + public int val1; + public int val2; + public int val3; + public int val4; + public int val5; + public int val6; + public int val7; + + public void increaseAllByOne() { + val0++; + val1++; + val2++; + val3++; + val4++; + val5++; + val6++; + val7++; } - // Version 1 - public static class A___1 { - - public int val0; - - public void increaseAllByOne() { - val0++; - } - - public int sum() { - return val0; - } + public int sum() { + return val0 + val1 + val2 + val3 + val4 + val5 + val6 + val7; } + } - // Version 2 - public static class A___2 { - - public int val0; - public int val1; - public int val2; - public int val3; - public int val4; - public int val5; - public int val6; - public int val7; - public int val8; - public int val9; - public int val10; - public int val11; - public int val12; - public int val13; - public int val14; - public int val15; - - public int sum() { - return val0 + val1 + val2 + val3 + val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11 + val12 + val13 + val14 + val15; - } - - public void increaseAllByOne() { - val0++; - val1++; - val2++; - val3++; - val4++; - val5++; - val6++; - val7++; - val8++; - val9++; - val10++; - val11++; - val12++; - val13++; - val14++; - val15++; - } - } + // Version 1 + public static class A___1 { - // Version 3 - public static class A___3 { - - public int val6; - public int val0; - public int val7; - public int val1; - public int val2; - public int val5; - public int val3; - public int val4; - } + public int val0; - @Before - public void setUp() throws Exception { - __toVersion__(0); + public void increaseAllByOne() { + val0++; } - @Test - public void testReorder() { - - A a = new A(); - - a.val0 = 0; - a.val1 = 1; - a.val2 = 2; - a.val3 = 3; - a.val4 = 4; - a.val5 = 5; - a.val6 = 6; - a.val7 = 7; + public int sum() { + return val0; } - - @Test - public void testIncreaseFirst() { - - A a = new A(); - - a.val0 = 0; - a.val1 = 1; - a.val2 = 2; - a.val3 = 3; - a.val4 = 4; - a.val5 = 5; - a.val6 = 6; - a.val7 = 7; - - assertEquals(0, a.val0); - assertEquals(1, a.val1); - assertEquals(2, a.val2); - assertEquals(3, a.val3); - assertEquals(4, a.val4); - assertEquals(5, a.val5); - assertEquals(6, a.val6); - assertEquals(7, a.val7); - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a.sum()); - - __toVersion__(2); - - assertEquals(0, a.val0); - assertEquals(1, a.val1); - assertEquals(2, a.val2); - assertEquals(3, a.val3); - assertEquals(4, a.val4); - assertEquals(5, a.val5); - assertEquals(6, a.val6); - assertEquals(7, a.val7); - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a.sum()); - - a.increaseAllByOne(); - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 16, a.sum()); - - __toVersion__(0); - - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a.sum()); - assertEquals(1, a.val0); - assertEquals(2, a.val1); - assertEquals(3, a.val2); - assertEquals(4, a.val3); - assertEquals(5, a.val4); - assertEquals(6, a.val5); - assertEquals(7, a.val6); - assertEquals(8, a.val7); - - __toVersion__(2); - - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a.sum()); - assertEquals(1, a.val0); - assertEquals(2, a.val1); - assertEquals(3, a.val2); - assertEquals(4, a.val3); - assertEquals(5, a.val4); - assertEquals(6, a.val5); - assertEquals(7, a.val6); - assertEquals(8, a.val7); - - a.increaseAllByOne(); - - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 16, a.sum()); - assertEquals(2, a.val0); - assertEquals(3, a.val1); - assertEquals(4, a.val2); - assertEquals(5, a.val3); - assertEquals(6, a.val4); - assertEquals(7, a.val5); - assertEquals(8, a.val6); - assertEquals(9, a.val7); - __toVersion__(0); - - assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 16, a.sum()); - assertEquals(2, a.val0); - assertEquals(3, a.val1); - assertEquals(4, a.val2); - assertEquals(5, a.val3); - assertEquals(6, a.val4); - assertEquals(7, a.val5); - assertEquals(8, a.val6); - assertEquals(9, a.val7); + } + + // Version 2 + public static class A___2 { + + public int val0; + public int val1; + public int val2; + public int val3; + public int val4; + public int val5; + public int val6; + public int val7; + public int val8; + public int val9; + public int val10; + public int val11; + public int val12; + public int val13; + public int val14; + public int val15; + + public int sum() { + return val0 + val1 + val2 + val3 + val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11 + val12 + val13 + val14 + val15; } - @Test - public void testAddRemoveField() { - - assert __version__() == 0; - - A a = new A(); - - assertEquals(0, a.val0); - assertEquals(0, a.val1); - - __toVersion__(1); - - a.val0 = 1234; - - __toVersion__(0); - - assertEquals(1234, a.val0); - assertEquals(0, a.val1); - - a.val1 = 1234; - - assertEquals(1234, a.val0); - assertEquals(1234, a.val1); - - __toVersion__(1); - - assertEquals(1234, a.val0); - - __toVersion__(0); - - assertEquals(1234, a.val0); - assertEquals(0, a.val1); + public void increaseAllByOne() { + val0++; + val1++; + val2++; + val3++; + val4++; + val5++; + val6++; + val7++; + val8++; + val9++; + val10++; + val11++; + val12++; + val13++; + val14++; + val15++; } + } + + // Version 3 + public static class A___3 { + + public int val6; + public int val0; + public int val7; + public int val1; + public int val2; + public int val5; + public int val3; + public int val4; + } + + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + @Test + public void testReorder() { + + A a = new A(); + + a.val0 = 0; + a.val1 = 1; + a.val2 = 2; + a.val3 = 3; + a.val4 = 4; + a.val5 = 5; + a.val6 = 6; + a.val7 = 7; + } + + @Test + public void testIncreaseFirst() { + + A a = new A(); + + a.val0 = 0; + a.val1 = 1; + a.val2 = 2; + a.val3 = 3; + a.val4 = 4; + a.val5 = 5; + a.val6 = 6; + a.val7 = 7; + + assertEquals(0, a.val0); + assertEquals(1, a.val1); + assertEquals(2, a.val2); + assertEquals(3, a.val3); + assertEquals(4, a.val4); + assertEquals(5, a.val5); + assertEquals(6, a.val6); + assertEquals(7, a.val7); + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a.sum()); + + __toVersion__(2); + + assertEquals(0, a.val0); + assertEquals(1, a.val1); + assertEquals(2, a.val2); + assertEquals(3, a.val3); + assertEquals(4, a.val4); + assertEquals(5, a.val5); + assertEquals(6, a.val6); + assertEquals(7, a.val7); + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a.sum()); + + a.increaseAllByOne(); + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 16, a.sum()); + + __toVersion__(0); + + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a.sum()); + assertEquals(1, a.val0); + assertEquals(2, a.val1); + assertEquals(3, a.val2); + assertEquals(4, a.val3); + assertEquals(5, a.val4); + assertEquals(6, a.val5); + assertEquals(7, a.val6); + assertEquals(8, a.val7); + + __toVersion__(2); + + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a.sum()); + assertEquals(1, a.val0); + assertEquals(2, a.val1); + assertEquals(3, a.val2); + assertEquals(4, a.val3); + assertEquals(5, a.val4); + assertEquals(6, a.val5); + assertEquals(7, a.val6); + assertEquals(8, a.val7); + + a.increaseAllByOne(); + + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 16, a.sum()); + assertEquals(2, a.val0); + assertEquals(3, a.val1); + assertEquals(4, a.val2); + assertEquals(5, a.val3); + assertEquals(6, a.val4); + assertEquals(7, a.val5); + assertEquals(8, a.val6); + assertEquals(9, a.val7); + __toVersion__(0); + + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 16, a.sum()); + assertEquals(2, a.val0); + assertEquals(3, a.val1); + assertEquals(4, a.val2); + assertEquals(5, a.val3); + assertEquals(6, a.val4); + assertEquals(7, a.val5); + assertEquals(8, a.val6); + assertEquals(9, a.val7); + } + + @Test + public void testAddRemoveField() { + + assert __version__() == 0; + + A a = new A(); + + assertEquals(0, a.val0); + assertEquals(0, a.val1); + + __toVersion__(1); + + a.val0 = 1234; + + __toVersion__(0); + + assertEquals(1234, a.val0); + assertEquals(0, a.val1); + + a.val1 = 1234; + + assertEquals(1234, a.val0); + assertEquals(1234, a.val1); + + __toVersion__(1); + + assertEquals(1234, a.val0); + + __toVersion__(0); + + assertEquals(1234, a.val0); + assertEquals(0, a.val1); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/InstanceFieldHandleTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/InstanceFieldHandleTest.java index a47ce5c5..a0ac3bdb 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/InstanceFieldHandleTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/InstanceFieldHandleTest.java @@ -36,7 +36,7 @@ import static org.junit.Assert.assertEquals; /** * Test for replacing field with MethodHandle pointing to it. - * + * <p> * Technically, should work for Java 7, but currently is not supported in Java 7. * * @author Ivan Dubrov diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/ObjectStressTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/ObjectStressTest.java index 9bd4ccf3..12df397b 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/ObjectStressTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/ObjectStressTest.java @@ -36,87 +36,87 @@ import static org.junit.Assert.assertEquals; */ public class ObjectStressTest { - private final int COUNT = 10000; - - @Before - public void setUp() throws Exception { - __toVersion__(0); + private final int COUNT = 10000; + + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + // Version 0 + public static class A { + + public A thisPointer; + public int i1; + public int i2; + public int i3; + public int i4; + public int i5; + public int i6; + public int i7; + public int i8; + public int i9; + public int i10; + + public int sum() { + return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10; } - - // Version 0 - public static class A { - - public A thisPointer; - public int i1; - public int i2; - public int i3; - public int i4; - public int i5; - public int i6; - public int i7; - public int i8; - public int i9; - public int i10; - - public int sum() { - return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10; - } + } + + // Version 1 + public static class A___1 { + + public int i1; + public int i2; + public int i8; + public int i3; + public int i4; + public int i10; + public int i5; + public int i6; + public int i7; + public int i9; + public A thisPointer; + + public int sum() { + return i1 * i2 * i3 * i4 * i5 * i6 * i7 * i8 * i9 * i10; + } + } + + @Test + public void testLotsOfObjects() { + + assert __version__() == 0; + + A[] arr = new A[COUNT]; + for (int i = 0; i < arr.length; i++) { + arr[i] = new A(); + arr[i].thisPointer = arr[i]; + arr[i].i1 = 1; + arr[i].i2 = 2; + arr[i].i3 = 3; + arr[i].i4 = 4; + arr[i].i5 = 5; + arr[i].i6 = 6; + arr[i].i7 = 7; + arr[i].i8 = 8; + arr[i].i9 = 9; + arr[i].i10 = 10; } - // Version 1 - public static class A___1 { - - public int i1; - public int i2; - public int i8; - public int i3; - public int i4; - public int i10; - public int i5; - public int i6; - public int i7; - public int i9; - public A thisPointer; - - public int sum() { - return i1 * i2 * i3 * i4 * i5 * i6 * i7 * i8 * i9 * i10; - } + + __toVersion__(1); + + for (int i = 0; i < arr.length; i++) { + assertEquals(1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10, arr[i].sum()); + assertEquals(arr[i].thisPointer, arr[i]); } - @Test - public void testLotsOfObjects() { - - assert __version__() == 0; - - A[] arr = new A[COUNT]; - for (int i = 0; i < arr.length; i++) { - arr[i] = new A(); - arr[i].thisPointer = arr[i]; - arr[i].i1 = 1; - arr[i].i2 = 2; - arr[i].i3 = 3; - arr[i].i4 = 4; - arr[i].i5 = 5; - arr[i].i6 = 6; - arr[i].i7 = 7; - arr[i].i8 = 8; - arr[i].i9 = 9; - arr[i].i10 = 10; - } - - - __toVersion__(1); - - for (int i = 0; i < arr.length; i++) { - assertEquals(1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10, arr[i].sum()); - assertEquals(arr[i].thisPointer, arr[i]); - } - - __toVersion__(0); - - for (int i = 0; i < arr.length; i++) { - assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, arr[i].sum()); - assertEquals(arr[i].thisPointer, arr[i]); - } + __toVersion__(0); + + for (int i = 0; i < arr.length; i++) { + assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, arr[i].sum()); + assertEquals(arr[i].thisPointer, arr[i]); } + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/RedefinePrivateFieldTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/RedefinePrivateFieldTest.java index 2256f930..191219ea 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/RedefinePrivateFieldTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/RedefinePrivateFieldTest.java @@ -38,60 +38,60 @@ import static org.junit.Assert.assertEquals; */ public class RedefinePrivateFieldTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - private int f1; + private int f1; - public A() { - f1 = 5; - } + public A() { + f1 = 5; + } - public int foo() { - int result = f1; - __toVersion__(1); - result += f1; - return result; - } + public int foo() { + int result = f1; + __toVersion__(1); + result += f1; + return result; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - int f0; - int f1; + int f0; + int f1; - public int foo() { - return -1; - } + public int foo() { + return -1; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testRedefinePrivateField() { + @Test + public void testRedefinePrivateField() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); + A a = new A(); - assertEquals(10, a.foo()); + assertEquals(10, a.foo()); - assert __version__() == 1; + assert __version__() == 1; - assertEquals(-1, a.foo()); + assertEquals(-1, a.foo()); - __toVersion__(0); + __toVersion__(0); - assertEquals(10, a.foo()); + assertEquals(10, a.foo()); - assert __version__() == 1; + assert __version__() == 1; - assertEquals(-1, a.foo()); + assertEquals(-1, a.foo()); - __toVersion__(0); - } + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/StaticFieldHandleTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/StaticFieldHandleTest.java index ee669917..a7db7592 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/StaticFieldHandleTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/StaticFieldHandleTest.java @@ -36,7 +36,7 @@ import static org.junit.Assert.assertEquals; /** * Test for replacing field with MethodHandle pointing to it. - * + * <p> * Technically, should work for Java 7, but currently is not supported in Java 7. * * @author Ivan Dubrov diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/StringFieldTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/StringFieldTest.java index e668ea7f..209aa6d9 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/StringFieldTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/StringFieldTest.java @@ -38,41 +38,41 @@ import static org.junit.Assert.assertEquals; */ public class StringFieldTest { - // Version 0 - public static class A { - public String stringFld = "OLD"; - } + // Version 0 + public static class A { + public String stringFld = "OLD"; + } - // Version 1 - public static class A___1 { - public String stringFld = "NEW"; - public int intComplNewFld = 333; - public long longComplNewFld = 444L; - public String stringComplNewFld = "completely new String field"; - } + // Version 1 + public static class A___1 { + public String stringFld = "NEW"; + public int intComplNewFld = 333; + public long longComplNewFld = 444L; + public String stringComplNewFld = "completely new String field"; + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - /** - * Checks that the given object is unmodified (i.e. the values of the fields are correct) - * - * @param a the object to be checked - */ - private void assertObjectOK(A a) { - assertEquals("OLD", a.stringFld); - } + /** + * Checks that the given object is unmodified (i.e. the values of the fields are correct) + * + * @param a the object to be checked + */ + private void assertObjectOK(A a) { + assertEquals("OLD", a.stringFld); + } - @Test - public void testComplexFieldChange() { - assert __version__() == 0; - A a = new A(); - assertObjectOK(a); - __toVersion__(1); - assertObjectOK(a); - __toVersion__(0); - assertObjectOK(a); - } + @Test + public void testComplexFieldChange() { + assert __version__() == 0; + A a = new A(); + assertObjectOK(a); + __toVersion__(1); + assertObjectOK(a); + __toVersion__(0); + assertObjectOK(a); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/fields/YieldTest.java b/dcevm/src/test/java7/com/github/dcevm/test/fields/YieldTest.java index aa7f3b43..6eb0926c 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/fields/YieldTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/fields/YieldTest.java @@ -44,80 +44,80 @@ import static org.junit.Assert.assertEquals; */ public class YieldTest { - // Version 0 - public static class Base { + // Version 0 + public static class Base { - protected List<Integer> arr = new ArrayList<Integer>(); + protected List<Integer> arr = new ArrayList<Integer>(); - public void reset() { - __toVersion__(0); - } - - public void next() { - __toVersion__(__version__() + 1); - } + public void reset() { + __toVersion__(0); } - public static abstract class A extends Base { + public void next() { + __toVersion__(__version__() + 1); + } + } - public List<Integer> gen() { - arr.add(produce()); - next(); - return gen(); - } + public static abstract class A extends Base { - public abstract int produce(); + public List<Integer> gen() { + arr.add(produce()); + next(); + return gen(); } - public static class B extends A { + public abstract int produce(); + } + + public static class B extends A { - @Override - public int produce() { - return 1; - } + @Override + public int produce() { + return 1; } + } - public static class B___10 extends A { + public static class B___10 extends A { - @Override - public int produce() { - return 2; - } + @Override + public int produce() { + return 2; } + } - public static class B___20 extends A { + public static class B___20 extends A { - private int x; + private int x; - @Override - public int produce() { - return ++x; - } + @Override + public int produce() { + return ++x; } + } - public static class A___30 extends Base { + public static class A___30 extends Base { - public List<Integer> gen() { - reset(); - return arr; - } + public List<Integer> gen() { + reset(); + return arr; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testYield() { + @Test + public void testYield() { - assert __version__() == 0; + assert __version__() == 0; - B b = new B(); - assertEquals(Arrays.asList( - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), b.gen()); - assert __version__() == 0; - } + B b = new B(); + assertEquals(Arrays.asList( + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), b.gen()); + assert __version__() == 0; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/AddMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/AddMethodTest.java index cfb328ff..39a537dc 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/AddMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/AddMethodTest.java @@ -39,128 +39,128 @@ import static org.junit.Assert.assertTrue; */ public class AddMethodTest { - // Version 0 - public static class A { - public int value(int newVersion) { - return newVersion; - } + // Version 0 + public static class A { + public int value(int newVersion) { + return newVersion; } + } + + // Version 1 + public static class A___1 { + + public int value(int newVersion) { + + int x = 1; + try { + x = 2; + } catch (NumberFormatException e) { + x = 3; + } catch (Exception e) { + x = 4; + } finally { + x = x * 2; + } + __toVersion__(newVersion); + throw new IllegalArgumentException(); + } + } + + // Version 2 + public static class A___2 { - // Version 1 - public static class A___1 { - - public int value(int newVersion) { - - int x = 1; - try { - x = 2; - } catch (NumberFormatException e) { - x = 3; - } catch (Exception e) { - x = 4; - } finally { - x = x * 2; - } - __toVersion__(newVersion); - throw new IllegalArgumentException(); - } + public int value2() { + return 2; } - // Version 2 - public static class A___2 { - - public int value2() { - return 2; - } - - public int value(int newVersion) { - - int x = 1; - try { - x = 2; - } catch (NumberFormatException e) { - x = 3; - } catch (Exception e) { - x = 4; - } finally { - x = x * 2; - } - __toVersion__(newVersion); - throw new IllegalArgumentException(); - } - - public int value3() { - return 3; - } - - public int value4() { - return 4; - } - - public int value5() { - return 5; - } + public int value(int newVersion) { + + int x = 1; + try { + x = 2; + } catch (NumberFormatException e) { + x = 3; + } catch (Exception e) { + x = 4; + } finally { + x = x * 2; + } + __toVersion__(newVersion); + throw new IllegalArgumentException(); } - @Before - public void setUp() throws Exception { - __toVersion__(0); + public int value3() { + return 3; } - private void checkLineNumbers(int first, int second) { - assertTrue("Must have different line numbers (A.value is an EMCP method and therefore execution has to be transferred). Exception line numbers: " + first + " and " + second, first != second); + public int value4() { + return 4; } - @Test - public void testAddMethodToKlassWithEMCPExceptionMethod() { + public int value5() { + return 5; + } + } - assert __version__() == 0; + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - final A a = new A(); + private void checkLineNumbers(int first, int second) { + assertTrue("Must have different line numbers (A.value is an EMCP method and therefore execution has to be transferred). Exception line numbers: " + first + " and " + second, first != second); + } - assertEquals(1, a.value(1)); + @Test + public void testAddMethodToKlassWithEMCPExceptionMethod() { - __toVersion__(1); + assert __version__() == 0; - int firstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { - @Override - public void run() { - assertEquals(4, a.value(1)); - } - }); + final A a = new A(); - int secondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { - @Override - public void run() { - assertEquals(4, a.value(2)); - } - }); + assertEquals(1, a.value(1)); - checkLineNumbers(firstLineNumber, secondLineNumber); + __toVersion__(1); - assert __version__() == 2; + int firstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { + @Override + public void run() { + assertEquals(4, a.value(1)); + } + }); - int newFirstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { - @Override - public void run() { - assertEquals(4, a.value(2)); - } - }); + int secondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { + @Override + public void run() { + assertEquals(4, a.value(2)); + } + }); - assertEquals(secondLineNumber, newFirstLineNumber); + checkLineNumbers(firstLineNumber, secondLineNumber); - int newSecondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { - @Override - public void run() { - assertEquals(4, a.value(1)); - } - }); + assert __version__() == 2; - assertEquals(newSecondLineNumber, firstLineNumber); - checkLineNumbers(firstLineNumber, secondLineNumber); + int newFirstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { + @Override + public void run() { + assertEquals(4, a.value(2)); + } + }); - __toVersion__(0); - assertEquals(1, a.value(1)); - assert __version__() == 0; - } + assertEquals(secondLineNumber, newFirstLineNumber); + + int newSecondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() { + @Override + public void run() { + assertEquals(4, a.value(1)); + } + }); + + assertEquals(newSecondLineNumber, firstLineNumber); + checkLineNumbers(firstLineNumber, secondLineNumber); + + __toVersion__(0); + assertEquals(1, a.value(1)); + assert __version__() == 0; + } }
\ No newline at end of file diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/AnnotationTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/AnnotationTest.java index 3c4d6697..856f30ae 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/AnnotationTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/AnnotationTest.java @@ -26,11 +26,7 @@ package com.github.dcevm.test.methods; import org.junit.Before; import org.junit.Test; -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.annotation.*; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -46,80 +42,80 @@ import static org.junit.Assert.assertEquals; */ public class AnnotationTest { - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) - public @interface TestAnnotation { - } + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) + public @interface TestAnnotation { + } - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) - public @interface TestAnnotation2 { - } + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) + public @interface TestAnnotation2 { + } - // Version 0 - public static class A { - public int testField; + // Version 0 + public static class A { + public int testField; - public void testMethod() { - } + public void testMethod() { } + } - // Version 1 + // Version 1 + @TestAnnotation + public static class A___1 { @TestAnnotation - public static class A___1 { - @TestAnnotation - public int testField; + public int testField; - @TestAnnotation - public void testMethod() { - } + @TestAnnotation + public void testMethod() { } + } - // Version 2 + // Version 2 + @TestAnnotation2 + public static class A___2 { @TestAnnotation2 - public static class A___2 { - @TestAnnotation2 - public int testField; - - @TestAnnotation2 - public void testMethod() { - } - } - - @Before - public void setUp() throws Exception { - __toVersion__(0); - } - - private void checkAnnotation(Class<?> c, Class<? extends Annotation> expectedAnnotation) throws NoSuchMethodException, NoSuchFieldException { - Class<? extends Annotation> annotation = c.getAnnotation(expectedAnnotation).annotationType(); - assertEquals(expectedAnnotation, annotation); - Method m = c.getMethod("testMethod"); - annotation = m.getAnnotation(expectedAnnotation).annotationType(); - assertEquals(expectedAnnotation, annotation); - Field f = c.getField("testField"); - annotation = f.getAnnotation(expectedAnnotation).annotationType(); - assertEquals(expectedAnnotation, annotation); - } + public int testField; - private void checkAnnotationMissing(Class<A> c) throws NoSuchMethodException, NoSuchFieldException { - assertEquals(0, c.getAnnotations().length); - assertEquals(0, c.getField("testField").getAnnotations().length); - assertEquals(0, c.getMethod("testMethod").getAnnotations().length); - } - - @Test - public void testAddMethodToKlassWithEMCPExceptionMethod() throws NoSuchMethodException, NoSuchFieldException { - - assert __version__() == 0; - checkAnnotationMissing(A.class); - __toVersion__(1); - checkAnnotation(A.class, TestAnnotation.class); - __toVersion__(2); - checkAnnotation(A.class, TestAnnotation2.class); - __toVersion__(0); - checkAnnotationMissing(A.class); + @TestAnnotation2 + public void testMethod() { } + } + + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + private void checkAnnotation(Class<?> c, Class<? extends Annotation> expectedAnnotation) throws NoSuchMethodException, NoSuchFieldException { + Class<? extends Annotation> annotation = c.getAnnotation(expectedAnnotation).annotationType(); + assertEquals(expectedAnnotation, annotation); + Method m = c.getMethod("testMethod"); + annotation = m.getAnnotation(expectedAnnotation).annotationType(); + assertEquals(expectedAnnotation, annotation); + Field f = c.getField("testField"); + annotation = f.getAnnotation(expectedAnnotation).annotationType(); + assertEquals(expectedAnnotation, annotation); + } + + private void checkAnnotationMissing(Class<A> c) throws NoSuchMethodException, NoSuchFieldException { + assertEquals(0, c.getAnnotations().length); + assertEquals(0, c.getField("testField").getAnnotations().length); + assertEquals(0, c.getMethod("testMethod").getAnnotations().length); + } + + @Test + public void testAddMethodToKlassWithEMCPExceptionMethod() throws NoSuchMethodException, NoSuchFieldException { + + assert __version__() == 0; + checkAnnotationMissing(A.class); + __toVersion__(1); + checkAnnotation(A.class, TestAnnotation.class); + __toVersion__(2); + checkAnnotation(A.class, TestAnnotation2.class); + __toVersion__(0); + checkAnnotationMissing(A.class); + } }
\ No newline at end of file diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedInterfaceMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedInterfaceMethodTest.java index ff0ed08f..38968743 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedInterfaceMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedInterfaceMethodTest.java @@ -41,57 +41,57 @@ import static org.junit.Assert.assertEquals; @Category(Full.class) public class CallDeletedInterfaceMethodTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); + @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; } + } - // Version 0 - public static interface I { - public int foo(); + public static class Helper { + public static int process(I i) { + __toVersion__(1); + return i.foo(); } + } - public static class A implements I { - @Override - public int foo() { - return 1; - } - } + // Version 1 + public static interface I___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; } + } - public static class Helper___1 { - public static int process(I i) { - return 2; - } - } + @Test + public void testOldCodeCallsDeletedInterfaceMethod() { - @Test - public void testOldCodeCallsDeletedInterfaceMethod() { + assert __version__() == 0; + A a = new A(); - assert __version__() == 0; - A a = new A(); + assertEquals(1, Helper.process(a)); + assert __version__() == 1; + assertEquals(2, Helper.process(a)); - assertEquals(1, Helper.process(a)); - assert __version__() == 1; - assertEquals(2, Helper.process(a)); + __toVersion__(0); - __toVersion__(0); + assertEquals(1, Helper.process(a)); + assert __version__() == 1; + assertEquals(2, Helper.process(a)); - assertEquals(1, Helper.process(a)); - assert __version__() == 1; - assertEquals(2, Helper.process(a)); - - __toVersion__(0); - } + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedMethodTest.java index 794f945d..836c22d6 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/CallDeletedMethodTest.java @@ -44,74 +44,74 @@ import static org.junit.Assert.assertEquals; @Category(Full.class) public class CallDeletedMethodTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 5; - } + public int value() { + return 5; + } - public int oldMethod() { - __toVersion__(1); - return deletedMethod(); - } + public int oldMethod() { + __toVersion__(1); + return deletedMethod(); + } - public int deletedMethod() { - return 1; - } + public int deletedMethod() { + return 1; } + } - // Version 1 - @MethodRedefinitionPolicy(RedefinitionPolicy.AccessDeletedMembers) - public static class A___1 { + // Version 1 + @MethodRedefinitionPolicy(RedefinitionPolicy.AccessDeletedMembers) + public static class A___1 { - public int oldMethod() { - return 2; - } + public int oldMethod() { + return 2; } + } - @Test - public void testOldCodeCallsDeletedMethod() { + @Test + public void testOldCodeCallsDeletedMethod() { - assert __version__() == 0; - A a = new A(); + assert __version__() == 0; + A a = new A(); - assertEquals(1, a.oldMethod()); - assert __version__() == 1; - assertEquals(2, a.oldMethod()); + assertEquals(1, a.oldMethod()); + assert __version__() == 1; + assertEquals(2, a.oldMethod()); - __toVersion__(0); + __toVersion__(0); - assertEquals(1, a.oldMethod()); - assert __version__() == 1; - assertEquals(2, a.oldMethod()); + assertEquals(1, a.oldMethod()); + assert __version__() == 1; + assertEquals(2, a.oldMethod()); - __toVersion__(0); - } + __toVersion__(0); + } - @Test - public void testNewCodeCallsDeletedMethod() { + @Test + public void testNewCodeCallsDeletedMethod() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); - assertEquals(5, a.value()); - - __toVersion__(1); + A a = new A(); + assertEquals(5, a.value()); - try { - a.value(); - Assert.fail("NoSuchMethodError exception must be thrown!"); - } catch (NoSuchMethodError e) { - // Expected exception - } + __toVersion__(1); - __toVersion__(0); - assertEquals(5, a.value()); + try { + a.value(); + Assert.fail("NoSuchMethodError exception must be thrown!"); + } catch (NoSuchMethodError e) { + // Expected exception } + + __toVersion__(0); + assertEquals(5, a.value()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectHashcodeTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectHashcodeTest.java index 8c0f0c0e..2ab45f11 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectHashcodeTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectHashcodeTest.java @@ -39,54 +39,54 @@ import static org.junit.Assert.assertTrue; */ public class ClassObjectHashcodeTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 1; - } + public int value() { + return 1; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 2; - } + public int value() { + return 2; } + } - @Test - public void testClassObjectHashcode() { - A a = new A(); - Class clazz = a.getClass(); - int hashCode = clazz.hashCode(); - assertEquals(1, a.value()); - __toVersion__(1); - assertEquals(2, a.value()); - assertEquals(hashCode, clazz.hashCode()); - assertEquals(hashCode, a.getClass().hashCode()); - __toVersion__(0); - synchronized (clazz) { - assertEquals(1, a.value()); - assertEquals(hashCode, clazz.hashCode()); - assertEquals(hashCode, a.getClass().hashCode()); - __toVersion__(1); - assertEquals(2, a.value()); - assertTrue(a.getClass() == clazz); - assertTrue(a.getClass() == ClassObjectHashcodeTest.A.class); - assertEquals(hashCode, clazz.hashCode()); - assertEquals(hashCode, a.getClass().hashCode()); - } - assertEquals(2, a.value()); - assertTrue(a.getClass() == clazz); - __toVersion__(0); - assertTrue(a.getClass() == clazz); - assertEquals(hashCode, clazz.hashCode()); - assertEquals(hashCode, a.getClass().hashCode()); + @Test + public void testClassObjectHashcode() { + A a = new A(); + Class clazz = a.getClass(); + int hashCode = clazz.hashCode(); + assertEquals(1, a.value()); + __toVersion__(1); + assertEquals(2, a.value()); + assertEquals(hashCode, clazz.hashCode()); + assertEquals(hashCode, a.getClass().hashCode()); + __toVersion__(0); + synchronized (clazz) { + assertEquals(1, a.value()); + assertEquals(hashCode, clazz.hashCode()); + assertEquals(hashCode, a.getClass().hashCode()); + __toVersion__(1); + assertEquals(2, a.value()); + assertTrue(a.getClass() == clazz); + assertTrue(a.getClass() == ClassObjectHashcodeTest.A.class); + assertEquals(hashCode, clazz.hashCode()); + assertEquals(hashCode, a.getClass().hashCode()); } + assertEquals(2, a.value()); + assertTrue(a.getClass() == clazz); + __toVersion__(0); + assertTrue(a.getClass() == clazz); + assertEquals(hashCode, clazz.hashCode()); + assertEquals(hashCode, a.getClass().hashCode()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectSynchronizationTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectSynchronizationTest.java index 4ff340e2..d5649cfe 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectSynchronizationTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassObjectSynchronizationTest.java @@ -39,41 +39,41 @@ import static org.junit.Assert.assertTrue; */ public class ClassObjectSynchronizationTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 1; - } + public int value() { + return 1; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 2; - } + public int value() { + return 2; } + } - @Test - public void testClassObjectSynchronization() { - A a = new A(); - Class clazz = a.getClass(); - synchronized (clazz) { - assertEquals(1, a.value()); - __toVersion__(1); - assertEquals(2, a.value()); - assertTrue(a.getClass() == clazz); - assertTrue(a.getClass() == ClassObjectSynchronizationTest.A.class); - } - assertEquals(2, a.value()); - assertTrue(a.getClass() == clazz); - __toVersion__(0); - assertTrue(a.getClass() == clazz); + @Test + public void testClassObjectSynchronization() { + A a = new A(); + Class clazz = a.getClass(); + synchronized (clazz) { + assertEquals(1, a.value()); + __toVersion__(1); + assertEquals(2, a.value()); + assertTrue(a.getClass() == clazz); + assertTrue(a.getClass() == ClassObjectSynchronizationTest.A.class); } + assertEquals(2, a.value()); + assertTrue(a.getClass() == clazz); + __toVersion__(0); + assertTrue(a.getClass() == clazz); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassReflectionTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassReflectionTest.java index 04541cbb..796e2f5c 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassReflectionTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/ClassReflectionTest.java @@ -42,118 +42,118 @@ import static org.junit.Assert.assertEquals; */ public class ClassReflectionTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 1; - } + public int value() { + return 1; } + } - public static class B extends A { + public static class B extends A { - @Override - public int value() { - return 2; - } + @Override + public int value() { + return 2; } + } - public static class C extends A { + public static class C extends A { - @Override - public int value() { - return 3; - } + @Override + public int value() { + return 3; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 1; - } - - public int value2() { - return 2; - } + public int value() { + return 1; } - // Version 2 - public static class C___2 extends B { - - @Override - public int value() { - return super.value(); - } + public int value2() { + return 2; } + } - private void assertIsSuper(Class<?> s, Class<?> c) { - assertEquals(s, c.getSuperclass()); - } + // Version 2 + public static class C___2 extends B { - private void assertIsNotSuper(Class<?> s, Class<?> c) { - Assert.assertFalse(s.equals(c.getSuperclass())); + @Override + public int value() { + return super.value(); } + } - @Test - public void testClassReflection() { + private void assertIsSuper(Class<?> s, Class<?> c) { + assertEquals(s, c.getSuperclass()); + } - checkWeakReference(); - assert __version__() == 0; + private void assertIsNotSuper(Class<?> s, Class<?> c) { + Assert.assertFalse(s.equals(c.getSuperclass())); + } - final A a = new A(); - final B b = new B(); - final C c = new C(); + @Test + public void testClassReflection() { - assertIsSuper(A.class, B.class); - assertIsSuper(A.class, C.class); - assertIsNotSuper(B.class, C.class); + checkWeakReference(); + assert __version__() == 0; - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(3, c.value()); + final A a = new A(); + final B b = new B(); + final C c = new C(); - __toVersion__(2); + assertIsSuper(A.class, B.class); + assertIsSuper(A.class, C.class); + assertIsNotSuper(B.class, C.class); - assertIsSuper(A.class, B.class); - assertIsSuper(B.class, C.class); - assertIsNotSuper(A.class, C.class); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(3, c.value()); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(2, c.value()); - - TestUtil.assertUnsupportedWithLight(new Runnable() { - @Override - public void run() { - __toVersion__(0); - - assertIsSuper(A.class, B.class); - assertIsSuper(A.class, C.class); - assertIsNotSuper(B.class, C.class); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(3, c.value()); - } - }); - } + __toVersion__(2); - public void checkWeakReference() { - A a = new A(); - Class<?> strongRef = a.getClass(); - SoftReference<Class<?>> softRef = new SoftReference<Class<?>>(a.getClass()); + assertIsSuper(A.class, B.class); + assertIsSuper(B.class, C.class); + assertIsNotSuper(A.class, C.class); - assertEquals(1, a.value()); - __toVersion__(1); - assertEquals(1, a.value()); - Assert.assertTrue(strongRef == softRef.get()); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(2, c.value()); + TestUtil.assertUnsupportedWithLight(new Runnable() { + @Override + public void run() { __toVersion__(0); - } + + assertIsSuper(A.class, B.class); + assertIsSuper(A.class, C.class); + assertIsNotSuper(B.class, C.class); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(3, c.value()); + } + }); + } + + public void checkWeakReference() { + A a = new A(); + Class<?> strongRef = a.getClass(); + SoftReference<Class<?>> softRef = new SoftReference<Class<?>>(a.getClass()); + + assertEquals(1, a.value()); + __toVersion__(1); + assertEquals(1, a.value()); + Assert.assertTrue(strongRef == softRef.get()); + + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/DeleteActiveMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/DeleteActiveMethodTest.java index baf10730..34d906cb 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/DeleteActiveMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/DeleteActiveMethodTest.java @@ -42,126 +42,126 @@ import static org.junit.Assert.assertEquals; */ public class DeleteActiveMethodTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + // Version 0 + public static class A { + + boolean firstCall; + + public int value() { + firstCall = true; + return helperValue(); } - // Version 0 - public static class A { + public int helperValue() { - boolean firstCall; + if (!firstCall) { + return -1; + } + firstCall = false; - public int value() { - firstCall = true; - return helperValue(); - } + Thread t = new Thread(new Runnable() { - public int helperValue() { - - if (!firstCall) { - return -1; - } - firstCall = false; - - Thread t = new Thread(new Runnable() { - - @Override - public void run() { - __toVersion__(1); - } - }); - t.start(); - - try { - while (t.isAlive()) { - try { - this.helperValue(); - Thread.sleep(500); - } catch (InterruptedException e) { - } - helperValue(); - } - Assert.fail("Exception expected!"); - } catch (NoSuchMethodError e) { - } - - try { - t.join(); - } catch (InterruptedException e) { - } - - return 1; + @Override + public void run() { + __toVersion__(1); } + }); + t.start(); + + try { + while (t.isAlive()) { + try { + this.helperValue(); + Thread.sleep(500); + } catch (InterruptedException e) { + } + helperValue(); + } + Assert.fail("Exception expected!"); + } catch (NoSuchMethodError e) { + } + + try { + t.join(); + } catch (InterruptedException e) { + } + + return 1; } + } - public static class B { + public static class B { - public int fac(int x) { - if (x == 0) { - __toVersion__(1); - } + public int fac(int x) { + if (x == 0) { + __toVersion__(1); + } - return x * fac(x - 1); - } + return x * fac(x - 1); } + } - // Version 1 - @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck) - public static class A___1 { + // Version 1 + @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck) + public static class A___1 { - boolean firstCall; + boolean firstCall; - public int value() { - __toVersion__(0); - return 2; - } + public int value() { + __toVersion__(0); + return 2; } + } - @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck) - public static class B___1 { - } + @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck) + 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 testDeleteActiveMethodSimple() { + assert __version__() == 0; - @Test - public void testDeleteActiveMethod() { - assert __version__() == 0; + final B b = new B(); + TestUtil.assertException(NoSuchMethodError.class, new Runnable() { + @Override + public void run() { + b.fac(5); + } + }); - A a = new A(); + assert __version__() == 1; - assertEquals(1, a.value()); - assert __version__() == 1; + __toVersion__(0); + assert __version__() == 0; + } - assertEquals(2, a.value()); - assert __version__() == 0; + @Test + public void testDeleteActiveMethod() { + assert __version__() == 0; - assertEquals(1, a.value()); - assert __version__() == 1; + A a = new A(); - assertEquals(2, a.value()); - assert __version__() == 0; + assertEquals(1, a.value()); + assert __version__() == 1; - assertEquals(1, a.value()); - assert __version__() == 1; + assertEquals(2, a.value()); + assert __version__() == 0; - 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; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodHandleTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodHandleTest.java index 53f4a256..fdd99820 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodHandleTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodHandleTest.java @@ -36,7 +36,7 @@ import static org.junit.Assert.assertEquals; /** * Test for replacing method with MethodHandle pointing to it. - * + * <p> * FIXME: add tests for case when we change type of the method (like static -> non-static). If that happens, * MemberName should be somehow marked as invalid... * @@ -47,6 +47,7 @@ public class MethodHandleTest { // Version 0 public static class A { public int field; + public A(int value) { field = value; } @@ -71,6 +72,7 @@ public class MethodHandleTest { // Version 1 public static class A___1 { public int field; + public A___1(int value) { field = value * 10; } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodReflectionTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodReflectionTest.java index de9cc159..a5304734 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodReflectionTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/MethodReflectionTest.java @@ -41,112 +41,112 @@ import static org.junit.Assert.assertEquals; */ public class MethodReflectionTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 1; - } + public int value() { + return 1; } + } - public static class B extends A { + public static class B extends A { - @Override - public int value() { - return 2; - } + @Override + public int value() { + return 2; } + } - public static class C extends A { + public static class C extends A { - @Override - public int value() { - return 3; - } + @Override + public int value() { + return 3; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 1; - } + public int value() { + return 1; + } - public int value2() { - return 2; - } + public int value2() { + return 2; } + } - // Version 2 - public static class C___2 extends B { + // Version 2 + public static class C___2 extends B { - @Override - public int value() { - return super.value(); - } + @Override + public int value() { + return super.value(); } + } - @Test - public void testMethodReflection() { + @Test + public void testMethodReflection() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); - B b = new B(); - C c = new C(); + A a = new A(); + B b = new B(); + C c = new C(); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(3, c.value()); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(3, c.value()); - assertContainsMethod(A.class, "value"); - assertDoesNotContainMethod(A.class, "value2"); + assertContainsMethod(A.class, "value"); + assertDoesNotContainMethod(A.class, "value2"); - __toVersion__(1); + __toVersion__(1); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(3, c.value()); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(3, c.value()); - assertContainsMethod(A.class, "value"); - assertContainsMethod(A.class, "value2"); + assertContainsMethod(A.class, "value"); + assertContainsMethod(A.class, "value2"); - __toVersion__(0); + __toVersion__(0); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(3, c.value()); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(3, c.value()); - assertContainsMethod(A.class, "value"); - assertDoesNotContainMethod(A.class, "value2"); - } + assertContainsMethod(A.class, "value"); + assertDoesNotContainMethod(A.class, "value2"); + } - private void assertContainsMethod(Class<?> c, String methodName) { - boolean found = false; - for (Method m : c.getDeclaredMethods()) { - if (m.getName().equals(methodName)) { - found = true; - break; - } - } - - Assert.assertTrue(found); + private void assertContainsMethod(Class<?> c, String methodName) { + boolean found = false; + for (Method m : c.getDeclaredMethods()) { + if (m.getName().equals(methodName)) { + found = true; + break; + } } - private void assertDoesNotContainMethod(Class<?> c, String methodName) { - boolean found = false; - for (Method m : c.getDeclaredMethods()) { - if (m.getName().equals(methodName)) { - found = true; - break; - } - } + Assert.assertTrue(found); + } - Assert.assertFalse(found); + private void assertDoesNotContainMethod(Class<?> c, String methodName) { + boolean found = false; + for (Method m : c.getDeclaredMethods()) { + if (m.getName().equals(methodName)) { + found = true; + break; + } } + + Assert.assertFalse(found); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/OldCodeNonOSRTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/OldCodeNonOSRTest.java index c40717db..f7df6468 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/OldCodeNonOSRTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/OldCodeNonOSRTest.java @@ -41,86 +41,86 @@ import static org.junit.Assert.assertEquals; @Category(Full.class) 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; + // 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); + @Before + public void setUp() throws Exception { + __toVersion__(0); + } + + // Version 0 + public static class A { + + public int value() { + return 5; } - // 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; - } + public int oldMethod() { + __toVersion__(1); + int sum = 0; + for (int i = 0; i < N; i++) { + sum += i; + } + return (sum & deletedMethod()) | 1; } - // Version 1 - public static class A___1 { + public int oldMethod2() { + int sum = 0; + for (int i = 0; i < N; i++) { + sum += i; + } + __toVersion__(1); + return (sum & deletedMethod()) | 1; + } - public int oldMethod() { - return 2; - } + 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; } - @Test - public void testOldCodeNonOSR() { + public int deletedMethod() { + return 1; + } + } - assert __version__() == 0; - A a = new A(); + // Version 1 + public static class A___1 { - assertEquals(1, a.oldMethod()); - assert __version__() == 1; - assertEquals(2, a.oldMethod()); + public int oldMethod() { + return 2; + } + } - __toVersion__(0); + @Test + public void testOldCodeNonOSR() { - assertEquals(1, a.oldMethod2()); - assert __version__() == 1; - assertEquals(2, a.oldMethod()); + assert __version__() == 0; + A a = new A(); - __toVersion__(0); + assertEquals(1, a.oldMethod()); + assert __version__() == 1; + assertEquals(2, a.oldMethod()); - assertEquals(1, a.oldMethod3()); - assert __version__() == 1; - assertEquals(2, a.oldMethod()); + __toVersion__(0); - __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); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/OverrideMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/OverrideMethodTest.java index 9c974ec4..5dd1ce28 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/OverrideMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/OverrideMethodTest.java @@ -38,210 +38,210 @@ import static org.junit.Assert.assertEquals; */ public class OverrideMethodTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 5; - } + public int value() { + return 5; } + } - public static class B extends A { + public static class B extends A { - public int doubled() { - return value() * 2; - } + public int doubled() { + return value() * 2; } + } - public static class C extends B { - } + public static class C extends B { + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 10; - } + public int value() { + return 10; } + } - // Version 2 - public static class B___2 extends A { + // Version 2 + public static class B___2 extends A { - public int doubled() { - return value() * 3; - } + public int doubled() { + return value() * 3; } + } - // Version 3 - public static class C___3 extends B { + // Version 3 + public static class C___3 extends B { - @Override - public int value() { - return 1; - } + @Override + public int value() { + return 1; } + } - // Verison 4 - public static class A___4 { - - public int value() { - return baseValue(); - } + // Verison 4 + public static class A___4 { - public int baseValue() { - return 20; - } + public int value() { + return baseValue(); } - public static class B___4 extends A { - - public int doubled() { - return value() * 2; - } + public int baseValue() { + return 20; } + } - public static class C___4 extends B { - } + public static class B___4 extends A { - // Verison 5 - public static class A___5 { - - public int value() { - return baseValue(); - } - - public int baseValue() { - return 20; - } + public int doubled() { + return value() * 2; } + } - @Test - public void testSimple() { - - assert __version__() == 0; - - A a = new A(); - B b = new B(); - C c = new C(); - - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); - - __toVersion__(1); - assertEquals(10, a.value()); - assertEquals(10, b.value()); - assertEquals(20, b.doubled()); - assertEquals(10, c.value()); - assertEquals(20, c.doubled()); - - __toVersion__(2); - assertEquals(10, a.value()); - assertEquals(10, b.value()); - assertEquals(30, b.doubled()); - assertEquals(10, c.value()); - assertEquals(30, c.doubled()); - - __toVersion__(0); - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); - } + public static class C___4 extends B { + } - @Test - public void testMethodAdd() { - - assert __version__() == 0; - A a = new A(); - B b = new B(); - C c = new C(); - - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); - - __toVersion__(4); - assertEquals(20, a.value()); - assertEquals(40, b.doubled()); - assertEquals(20, b.value()); - assertEquals(20, c.value()); - assertEquals(40, c.doubled()); - - __toVersion__(0); - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); - } + // Verison 5 + public static class A___5 { - @Test - public void testOverride() { - - assert __version__() == 0; - - A a = new A(); - B b = new B(); - C c = new C(); - - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); - - __toVersion__(3); - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(1, c.value()); - assertEquals(2, c.doubled()); - - __toVersion__(0); - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); + public int value() { + return baseValue(); } - @Test - public void testMethodAddAdvanced() { - - assert __version__() == 0; - A a = new A(); - B b = new B(); - C c = new C(); - - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); - - __toVersion__(5); - assertEquals(20, a.value()); - assertEquals(20, b.value()); - assertEquals(40, b.doubled()); - assertEquals(20, c.value()); - assertEquals(40, c.doubled()); - - __toVersion__(0); - assertEquals(5, a.value()); - assertEquals(5, b.value()); - assertEquals(10, b.doubled()); - assertEquals(5, c.value()); - assertEquals(10, c.doubled()); + public int baseValue() { + return 20; } + } + + @Test + public void testSimple() { + + assert __version__() == 0; + + A a = new A(); + B b = new B(); + C c = new C(); + + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + + __toVersion__(1); + assertEquals(10, a.value()); + assertEquals(10, b.value()); + assertEquals(20, b.doubled()); + assertEquals(10, c.value()); + assertEquals(20, c.doubled()); + + __toVersion__(2); + assertEquals(10, a.value()); + assertEquals(10, b.value()); + assertEquals(30, b.doubled()); + assertEquals(10, c.value()); + assertEquals(30, c.doubled()); + + __toVersion__(0); + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + } + + @Test + public void testMethodAdd() { + + assert __version__() == 0; + A a = new A(); + B b = new B(); + C c = new C(); + + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + + __toVersion__(4); + assertEquals(20, a.value()); + assertEquals(40, b.doubled()); + assertEquals(20, b.value()); + assertEquals(20, c.value()); + assertEquals(40, c.doubled()); + + __toVersion__(0); + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + } + + @Test + public void testOverride() { + + assert __version__() == 0; + + A a = new A(); + B b = new B(); + C c = new C(); + + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + + __toVersion__(3); + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(1, c.value()); + assertEquals(2, c.doubled()); + + __toVersion__(0); + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + } + + @Test + public void testMethodAddAdvanced() { + + assert __version__() == 0; + A a = new A(); + B b = new B(); + C c = new C(); + + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + + __toVersion__(5); + assertEquals(20, a.value()); + assertEquals(20, b.value()); + assertEquals(40, b.doubled()); + assertEquals(20, c.value()); + assertEquals(40, c.doubled()); + + __toVersion__(0); + assertEquals(5, a.value()); + assertEquals(5, b.value()); + assertEquals(10, b.doubled()); + assertEquals(5, c.value()); + assertEquals(10, c.doubled()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassReflectionTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassReflectionTest.java index 5b8bb830..0629ffc9 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassReflectionTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassReflectionTest.java @@ -38,51 +38,51 @@ import static org.junit.Assert.assertEquals; */ public class SingleClassReflectionTest { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // Version 0 - public static class A { + // Version 0 + public static class A { - public static synchronized void staticSynchronized() { - __toVersion__(1); - } + public static synchronized void staticSynchronized() { + __toVersion__(1); } + } - // Version 1 - public static class A___1 { - public static synchronized void staticSynchronized() { - } + // Version 1 + public static class A___1 { + public static synchronized void staticSynchronized() { } + } - @Test - public void testHashcode() { + @Test + public void testHashcode() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); + A a = new A(); - int hashcode = a.getClass().hashCode(); + int hashcode = a.getClass().hashCode(); - __toVersion__(1); + __toVersion__(1); - assertEquals(hashcode, a.getClass().hashCode()); + assertEquals(hashcode, a.getClass().hashCode()); - __toVersion__(0); - } + __toVersion__(0); + } - @Test - public void testStaticSynchronized() { + @Test + public void testStaticSynchronized() { - A.staticSynchronized(); + A.staticSynchronized(); - assertEquals(1, __version__()); + assertEquals(1, __version__()); - __toVersion__(0); - } + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassTest.java b/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassTest.java index a9b30b0b..ad8464cf 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/methods/SingleClassTest.java @@ -38,86 +38,86 @@ import static org.junit.Assert.assertEquals; */ public class SingleClassTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 5; - } + public int value() { + return 5; } + } - // Version 3 - public static class A___3 { + // Version 3 + public static class A___3 { - public int value() { - return 5; - } + public int value() { + return 5; } + } - // Version 1 - public static class A___1 { + // Version 1 + public static class A___1 { - public int value() { - return 6; - } + public int value() { + return 6; + } - public int testValue() { - return 1; + public int testValue() { + return 1; - } } + } - // Version 2 - public static class A___2 { - - public int value() { - return baseValue() * 2; - } + // Version 2 + public static class A___2 { - public int baseValue() { - return 10; - } + public int value() { + return baseValue() * 2; } - @Before - public void setUp() throws Exception { - __toVersion__(0); + public int baseValue() { + return 10; } + } - @Test - public void testSimpleReplacement() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; + @Test + public void testSimpleReplacement() { - A a = new A(); + assert __version__() == 0; - assertEquals(5, a.value()); + A a = new A(); - __toVersion__(1); + assertEquals(5, a.value()); - assertEquals(6, a.value()); + __toVersion__(1); - __toVersion__(3); + assertEquals(6, a.value()); - assertEquals(5, a.value()); + __toVersion__(3); - __toVersion__(0); + assertEquals(5, a.value()); - assertEquals(5, a.value()); - } + __toVersion__(0); - @Test - public void testAddMethod() { + assertEquals(5, a.value()); + } - assert __version__() == 0; + @Test + public void testAddMethod() { - A a = new A(); - assertEquals(a.value(), 5); + assert __version__() == 0; - __toVersion__(2); - assertEquals(a.value(), 20); + A a = new A(); + assertEquals(a.value(), 5); - __toVersion__(0); - assertEquals(a.value(), 5); - } + __toVersion__(2); + assertEquals(a.value(), 20); + + __toVersion__(0); + assertEquals(a.value(), 5); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/natives/SimpleNativeTest.java b/dcevm/src/test/java7/com/github/dcevm/test/natives/SimpleNativeTest.java index 23619837..3b069e57 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/natives/SimpleNativeTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/natives/SimpleNativeTest.java @@ -37,52 +37,52 @@ import static org.junit.Assert.assertEquals; * @author Thomas Wuerthinger */ public class SimpleNativeTest { - static { - System.loadLibrary("natives"); - } - - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + static { + System.loadLibrary("natives"); + } - // Version 0 - public static class A { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - public static int get() { - return value(); - } + // Version 0 + public static class A { - public static native int value(); + public static int get() { + return value(); } - // Version 1 - public static class A___1 { - - public static int get() { - return value() + value2(); - } + public static native int value(); + } - public static native int value(); + // Version 1 + public static class A___1 { - public static native int value2(); + public static int get() { + return value() + value2(); } - @Test - public void testSimpleNativeCalls() { - assert __version__() == 0; + public static native int value(); + public static native int value2(); + } - assertEquals(1, A.get()); + @Test + public void testSimpleNativeCalls() { + assert __version__() == 0; - __toVersion__(1); - assertEquals(3, A.get()); + assertEquals(1, A.get()); - __toVersion__(0); + __toVersion__(1); - assertEquals(1, A.get()); + assertEquals(3, A.get()); - } + __toVersion__(0); + + assertEquals(1, A.get()); + + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/AnonymousClassInMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/AnonymousClassInMethodTest.java index 10caeba2..3e99138b 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/AnonymousClassInMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/AnonymousClassInMethodTest.java @@ -11,56 +11,62 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; */ public class AnonymousClassInMethodTest { - public static interface I { - public boolean m(); - }; + public static interface I { + public boolean m(); + } - public static interface I2 {}; + ; - // Version 0 - public static class A { - public boolean test() { - I anonymous = new I() { - @Override - public boolean m() { - return true; - } - }; - return anonymous.m(); + public static interface I2 { + } + + ; + + // Version 0 + public static class A { + public boolean test() { + I anonymous = new I() { + @Override + public boolean m() { + return true; } + }; + return anonymous.m(); } + } - // Version 1 - public static class A___1 { - public boolean test() { - I2 insertedAnonymous = new I2() {}; + // Version 1 + public static class A___1 { + public boolean test() { + I2 insertedAnonymous = new I2() { + }; - I anonymous = new I() { - @Override - public boolean m() { - return false; - } - }; - return anonymous.m(); + I anonymous = new I() { + @Override + public boolean m() { + return false; } + }; + return anonymous.m(); } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - // TODO this test fails, because conent of A$1 is now interface I2 instead of interface I (not compatible change) - // HotswapAgent plugin AnonymousClassPatch solves this on Java instrumentation level by exchanging content of class files. - // @see https://github.com/HotswapProjects/HotswapAgent/tree/master/HotswapAgent/src/main/java/org/hotswap/agent/plugin/jvm - //@Test - public void testAnonymous() { - assert __version__() == 0; - Assert.assertTrue(new A().test()); - __toVersion__(1); - Assert.assertFalse(new A().test()); - __toVersion__(0); - Assert.assertTrue(new A().test()); - } + // TODO this test fails, because conent of A$1 is now interface I2 instead of interface I (not compatible change) + // HotswapAgent plugin AnonymousClassPatch solves this on Java instrumentation level by exchanging content of class files. + // @see https://github.com/HotswapProjects/HotswapAgent/tree/master/HotswapAgent/src/main/java/org/hotswap/agent/plugin/jvm + //@Test + public void testAnonymous() { + assert __version__() == 0; + Assert.assertTrue(new A().test()); + __toVersion__(1); + Assert.assertFalse(new A().test()); + __toVersion__(0); + Assert.assertTrue(new A().test()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/HierarchySwapTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/HierarchySwapTest.java index bd606640..05d918d0 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/HierarchySwapTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/HierarchySwapTest.java @@ -40,358 +40,358 @@ import static org.junit.Assert.*; @Ignore public class HierarchySwapTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int value() { - return 1; - } + public int value() { + return 1; } + } - public static class B extends A { + public static class B extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class C { + public static class C { - public boolean doInstanceCheckA(Object o) { - return o instanceof A; - } + public boolean doInstanceCheckA(Object o) { + return o instanceof A; + } - public boolean doInstanceCheckB(Object o) { - return o instanceof B; - } + public boolean doInstanceCheckB(Object o) { + return o instanceof B; } + } - public static class Base { + public static class Base { - public String className() { - return "Base"; - } + public String className() { + return "Base"; } + } - public static class D extends Base { + public static class D extends Base { - @Override - public String className() { - return "D"; - } + @Override + public String className() { + return "D"; + } - public String superClassName() { - return super.className(); - } + public String superClassName() { + return super.className(); } + } - public static class E extends Base { + public static class E extends Base { - @Override - public String className() { - return "E"; - } + @Override + public String className() { + return "E"; + } - public String superClassName() { - return super.className(); - } + public String superClassName() { + return super.className(); } + } - public static class F extends Base { + public static class F extends Base { - @Override - public String className() { - return "F"; - } + @Override + public String className() { + return "F"; + } - public String superClassName() { - return super.className(); - } + public String superClassName() { + return super.className(); } + } - // Version 1 - public static class A___1 extends B___1 { + // Version 1 + public static class A___1 extends B___1 { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class B___1 { + public static class B___1 { - public int value() { - return 4; - } + public int value() { + return 4; } + } - public static class C___1 { - - public boolean doInstanceCheckA(Object o) { - return o instanceof A; - } + public static class C___1 { - public boolean doInstanceCheckB(Object o) { - return o instanceof B; - } + public boolean doInstanceCheckA(Object o) { + return o instanceof A; } - // Version 2 - public static class D___2 extends Base { + public boolean doInstanceCheckB(Object o) { + return o instanceof B; + } + } - @Override - public String className() { - return "D"; - } + // Version 2 + public static class D___2 extends Base { - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "D"; } - public static class E___2 extends D { + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "E"; - } + public static class E___2 extends D { - @Override - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "E"; } - public static class F___2 extends E { + @Override + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "F"; - } + public static class F___2 extends E { - @Override - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "F"; } - // Version 3 - public static class D___3 extends E { + @Override + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "D"; - } + // Version 3 + public static class D___3 extends E { - @Override - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "D"; } - public static class E___3 extends F { + @Override + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "E"; - } + public static class E___3 extends F { - @Override - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "E"; } - public static class F___3 extends Base { + @Override + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "F"; - } + public static class F___3 extends Base { - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "F"; } - // Version 4 - public static class D___4 extends E { + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "D"; - } + // Version 4 + public static class D___4 extends E { - @Override - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "D"; } - public static class E___4 extends Base { + @Override + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "E"; - } + public static class E___4 extends Base { - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "E"; } - public static class F___4 extends E { + public String superClassName() { + return super.className(); + } + } - @Override - public String className() { - return "F"; - } + public static class F___4 extends E { - @Override - public String superClassName() { - return super.className(); - } + @Override + public String className() { + return "F"; } - @Before - public void setUp() throws Exception { - __toVersion__(0); + @Override + public String superClassName() { + return super.className(); } + } - @Test - public void testHierarchySwap() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - assert __version__() == 0; + @Test + public void testHierarchySwap() { - A a = new A(); - B b = new B(); + assert __version__() == 0; - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertTrue(b.getClass().getSuperclass().equals(A.class)); - assertFalse(a.getClass().getSuperclass().equals(B.class)); + A a = new A(); + B b = new B(); - __toVersion__(1); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertTrue(b.getClass().getSuperclass().equals(A.class)); + assertFalse(a.getClass().getSuperclass().equals(B.class)); - assertEquals(8, a.value()); - assertEquals(4, b.value()); - assertFalse(b.getClass().getSuperclass().equals(A.class)); - assertTrue(a.getClass().getSuperclass().equals(B.class)); + __toVersion__(1); - __toVersion__(0); + assertEquals(8, a.value()); + assertEquals(4, b.value()); + assertFalse(b.getClass().getSuperclass().equals(A.class)); + assertTrue(a.getClass().getSuperclass().equals(B.class)); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertTrue(b.getClass().getSuperclass().equals(A.class)); - assertFalse(a.getClass().getSuperclass().equals(B.class)); - } + __toVersion__(0); - @Test - public void testHierarchySwapWithInstanceOfTest() { + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertTrue(b.getClass().getSuperclass().equals(A.class)); + assertFalse(a.getClass().getSuperclass().equals(B.class)); + } - assert __version__() == 0; + @Test + public void testHierarchySwapWithInstanceOfTest() { - A a = new A(); - B b = new B(); - C c = new C(); + assert __version__() == 0; - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertTrue(c.doInstanceCheckA(b)); - assertFalse(c.doInstanceCheckB(a)); + A a = new A(); + B b = new B(); + C c = new C(); - __toVersion__(1); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertTrue(c.doInstanceCheckA(b)); + assertFalse(c.doInstanceCheckB(a)); - assertEquals(8, a.value()); - assertEquals(4, b.value()); - assertFalse(c.doInstanceCheckA(b)); - assertTrue(c.doInstanceCheckB(a)); + __toVersion__(1); - __toVersion__(0); + assertEquals(8, a.value()); + assertEquals(4, b.value()); + assertFalse(c.doInstanceCheckA(b)); + assertTrue(c.doInstanceCheckB(a)); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertTrue(c.doInstanceCheckA(b)); - assertFalse(c.doInstanceCheckB(a)); - } + __toVersion__(0); - @Test - public void testHierarchySwapWithInstanceOf() { + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertTrue(c.doInstanceCheckA(b)); + assertFalse(c.doInstanceCheckB(a)); + } - assert __version__() == 0; + @Test + public void testHierarchySwapWithInstanceOf() { - A a = new A(); - B b = new B(); + assert __version__() == 0; - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertTrue(b instanceof A); - assertFalse(a instanceof B); + A a = new A(); + B b = new B(); - __toVersion__(1); + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertTrue(b instanceof A); + assertFalse(a instanceof B); - assertEquals(8, a.value()); - assertEquals(4, b.value()); - assertFalse(b instanceof A); - assertTrue(a instanceof B); + __toVersion__(1); - __toVersion__(0); + assertEquals(8, a.value()); + assertEquals(4, b.value()); + assertFalse(b instanceof A); + assertTrue(a instanceof B); - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertTrue(b instanceof A); - assertFalse(a instanceof B); - } + __toVersion__(0); - @Test - public void testTripleSwap() { + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertTrue(b instanceof A); + assertFalse(a instanceof B); + } + @Test + public void testTripleSwap() { - assert __version__() == 0; - D d = new D(); - E e = new E(); - F f = new F(); + assert __version__() == 0; - assertEquals(d.superClassName(), "Base"); - assertEquals(e.superClassName(), "Base"); - assertEquals(f.superClassName(), "Base"); + D d = new D(); + E e = new E(); + F f = new F(); - __toVersion__(2); + assertEquals(d.superClassName(), "Base"); + assertEquals(e.superClassName(), "Base"); + assertEquals(f.superClassName(), "Base"); - assertEquals(d.superClassName(), "Base"); - assertEquals(e.superClassName(), "D"); - assertEquals(f.superClassName(), "E"); + __toVersion__(2); - __toVersion__(3); + assertEquals(d.superClassName(), "Base"); + assertEquals(e.superClassName(), "D"); + assertEquals(f.superClassName(), "E"); - assertEquals(d.superClassName(), "E"); - assertEquals(e.superClassName(), "F"); - assertEquals(f.superClassName(), "Base"); + __toVersion__(3); - __toVersion__(4); + assertEquals(d.superClassName(), "E"); + assertEquals(e.superClassName(), "F"); + assertEquals(f.superClassName(), "Base"); - assertEquals(d.superClassName(), "E"); - assertEquals(e.superClassName(), "Base"); - assertEquals(f.superClassName(), "E"); + __toVersion__(4); - __toVersion__(3); + assertEquals(d.superClassName(), "E"); + assertEquals(e.superClassName(), "Base"); + assertEquals(f.superClassName(), "E"); - assertEquals(d.superClassName(), "E"); - assertEquals(e.superClassName(), "F"); - assertEquals(f.superClassName(), "Base"); + __toVersion__(3); - __toVersion__(2); + assertEquals(d.superClassName(), "E"); + assertEquals(e.superClassName(), "F"); + assertEquals(f.superClassName(), "Base"); - assertEquals(d.superClassName(), "Base"); - assertEquals(e.superClassName(), "D"); - assertEquals(f.superClassName(), "E"); + __toVersion__(2); - __toVersion__(0); + assertEquals(d.superClassName(), "Base"); + assertEquals(e.superClassName(), "D"); + assertEquals(f.superClassName(), "E"); - assertEquals(d.superClassName(), "Base"); - assertEquals(e.superClassName(), "Base"); - assertEquals(f.superClassName(), "Base"); - } + __toVersion__(0); + + assertEquals(d.superClassName(), "Base"); + assertEquals(e.superClassName(), "Base"); + assertEquals(f.superClassName(), "Base"); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/InterfaceTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/InterfaceTest.java index 7df37490..3454b720 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/InterfaceTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/InterfaceTest.java @@ -25,11 +25,7 @@ package com.github.dcevm.test.structural; import com.github.dcevm.test.TestUtil; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__; import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; @@ -42,107 +38,107 @@ import static org.junit.Assert.*; */ public class InterfaceTest { - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } - @AfterClass - public static void tearDownAfterClass() throws Exception { - } + @AfterClass + public static void tearDownAfterClass() throws Exception { + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @After - public void tearDown() throws Exception { - } + @After + public void tearDown() throws Exception { + } - public static interface A { + public static interface A { - int giveMeFive(); - } + int giveMeFive(); + } - public static class AImpl { + public static class AImpl { - public int giveMeFive() { - return 5; - } + public int giveMeFive() { + return 5; } + } - public static class BImpl implements A { + public static class BImpl implements A { - @Override - public int giveMeFive() { - return 5; - } + @Override + public int giveMeFive() { + return 5; + } - public int giveMeTen() { - return 10; - } + public int giveMeTen() { + return 10; } + } - public static class AImpl___1 implements A { + public static class AImpl___1 implements A { - @Override - public int giveMeFive() { - return 5; - } + @Override + public int giveMeFive() { + return 5; } + } - public static interface A___2 { + public static interface A___2 { - int giveMeTen(); - } + int giveMeTen(); + } - public static class Helper { + public static class Helper { - public int giveMeTenA2(A a) { - return 3; - } + public int giveMeTenA2(A a) { + return 3; } + } - public static class Helper___2 { + public static class Helper___2 { - public int giveMeTenA2(A a) { - return ((A___2) a).giveMeTen(); - } + public int giveMeTenA2(A a) { + return ((A___2) a).giveMeTen(); } + } - @Test - public void testAddInterface() { + @Test + public void testAddInterface() { - modifyInterface(); - assert __version__() == 0; + modifyInterface(); + assert __version__() == 0; - AImpl a = new AImpl(); - assertFalse(a instanceof A); - try { - int val = (((A) a).giveMeFive()); - fail(); - } catch (ClassCastException e) { - } + AImpl a = new AImpl(); + assertFalse(a instanceof A); + try { + int val = (((A) a).giveMeFive()); + fail(); + } catch (ClassCastException e) { + } - __toVersion__(1); - assertTrue(a instanceof A); - assertEquals(5, ((A) a).giveMeFive()); + __toVersion__(1); + assertTrue(a instanceof A); + assertEquals(5, ((A) a).giveMeFive()); - TestUtil.assertUnsupportedToVersionWithLight(InterfaceTest.class, 0); - } + TestUtil.assertUnsupportedToVersionWithLight(InterfaceTest.class, 0); + } - public void modifyInterface() { + public void modifyInterface() { - assert __version__() == 0; + assert __version__() == 0; - BImpl b = new BImpl(); - assertTrue(b instanceof A); + BImpl b = new BImpl(); + assertTrue(b instanceof A); - __toVersion__(2); + __toVersion__(2); - assertEquals(10, new Helper().giveMeTenA2(b)); + assertEquals(10, new Helper().giveMeTenA2(b)); - __toVersion__(0); - assertEquals(5, ((A) b).giveMeFive()); - } + __toVersion__(0); + assertEquals(5, ((A) b).giveMeFive()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/LargeHierarchyTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/LargeHierarchyTest.java index 5f1d1ef3..801366b7 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/LargeHierarchyTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/LargeHierarchyTest.java @@ -35,262 +35,262 @@ import static org.junit.Assert.assertEquals; /** * Tests that modify a large class hierarchy with the classes A, B, C, D, E, and F. - * + * * @author Thomas Wuerthinger */ @Category(Full.class) public class LargeHierarchyTest { - private A a = new A(); - private B b = new B(); - private C c = new C(); - private D d = new D(); - private E e = new E(); - private F f = new F(); - - @Before - public void setUp() throws Exception { - __toVersion__(0); - } - - // Version 0 - public static class A { - - public int value() { - return 1; - } - } - - public static class B extends A { + private A a = new A(); + private B b = new B(); + private C c = new C(); + private D d = new D(); + private E e = new E(); + private F f = new F(); - @Override - public int value() { - return super.value() * 2; - } - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - public static class C extends B { + // Version 0 + public static class A { - @Override - public int value() { - return super.value() * 2; - } + public int value() { + return 1; } + } - public static class D extends C { + public static class B extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class E extends D { + public static class C extends B { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class F extends E { + public static class D extends C { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - // Version 1 - public static class A___1 { + public static class E extends D { - public int value() { - return 2; - } + @Override + public int value() { + return super.value() * 2; } + } - // Version 2 - // D - E - F - // / - // A - B - C - public static class D___2 extends A { + public static class F extends E { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - // Version 3 - // D - // / - // A - B - C - E - F - public static class D___3 extends A { + // Version 1 + public static class A___1 { - @Override - public int value() { - return super.value() * 2; - } + public int value() { + return 2; } + } - public static class E___3 extends A { + // Version 2 + // D - E - F + // / + // A - B - C + public static class D___2 extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - // Version 4 - // Completely flat - public static class C___4 extends A { + // Version 3 + // D + // / + // A - B - C - E - F + public static class D___3 extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class D___4 extends A { + public static class E___3 extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class E___4 extends A { + // Version 4 + // Completely flat + public static class C___4 extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - public static class F___4 extends A { + public static class D___4 extends A { - @Override - public int value() { - return super.value() * 2; - } + @Override + public int value() { + return super.value() * 2; } + } - // Version 5 - public static class F___5 extends E { + public static class E___4 extends A { - @Override - public int value() { - return 0; - } + @Override + public int value() { + return super.value() * 2; } + } - @Test - public void testChangeBaseClass() { - - assert __version__() == 0; - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(32, f.value()); - - __toVersion__(1); + public static class F___4 extends A { - assertEquals(2, a.value()); - assertEquals(4, b.value()); - assertEquals(8, c.value()); - assertEquals(16, d.value()); - assertEquals(32, e.value()); - assertEquals(64, f.value()); - - __toVersion__(0); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(32, f.value()); + @Override + public int value() { + return super.value() * 2; } + } - @Test - public void testChangeSubClass() { - assert __version__() == 0; - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(32, f.value()); - - __toVersion__(5); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(0, f.value()); - - __toVersion__(0); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(32, f.value()); - } + // Version 5 + public static class F___5 extends E { - @Test - public void testChangeHierarchy() { - - assert __version__() == 0; - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(32, f.value()); - - __toVersion__(2); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(2, d.value()); - assertEquals(4, e.value()); - assertEquals(8, f.value()); - - __toVersion__(3); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(2, d.value()); - assertEquals(2, e.value()); - assertEquals(4, f.value()); - - __toVersion__(4); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(2, c.value()); - assertEquals(2, d.value()); - assertEquals(2, e.value()); - assertEquals(2, f.value()); - - __toVersion__(0); - - assertEquals(1, a.value()); - assertEquals(2, b.value()); - assertEquals(4, c.value()); - assertEquals(8, d.value()); - assertEquals(16, e.value()); - assertEquals(32, f.value()); + @Override + public int value() { + return 0; } + } + + @Test + public void testChangeBaseClass() { + + assert __version__() == 0; + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(32, f.value()); + + __toVersion__(1); + + assertEquals(2, a.value()); + assertEquals(4, b.value()); + assertEquals(8, c.value()); + assertEquals(16, d.value()); + assertEquals(32, e.value()); + assertEquals(64, f.value()); + + __toVersion__(0); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(32, f.value()); + } + + @Test + public void testChangeSubClass() { + assert __version__() == 0; + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(32, f.value()); + + __toVersion__(5); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(0, f.value()); + + __toVersion__(0); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(32, f.value()); + } + + @Test + public void testChangeHierarchy() { + + assert __version__() == 0; + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(32, f.value()); + + __toVersion__(2); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(2, d.value()); + assertEquals(4, e.value()); + assertEquals(8, f.value()); + + __toVersion__(3); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(2, d.value()); + assertEquals(2, e.value()); + assertEquals(4, f.value()); + + __toVersion__(4); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(2, c.value()); + assertEquals(2, d.value()); + assertEquals(2, e.value()); + assertEquals(2, f.value()); + + __toVersion__(0); + + assertEquals(1, a.value()); + assertEquals(2, b.value()); + assertEquals(4, c.value()); + assertEquals(8, d.value()); + assertEquals(16, e.value()); + assertEquals(32, f.value()); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/RedefineClassClassTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/RedefineClassClassTest.java index f3ffb74a..fe484f67 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/RedefineClassClassTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/RedefineClassClassTest.java @@ -42,33 +42,33 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; @Ignore public class RedefineClassClassTest { - // Version 0 - public interface Type { - } + // Version 0 + public interface Type { + } - // Version 1 - @ClassRedefinitionPolicy(alias = java.lang.reflect.Type.class) - public interface Type___1 { - } + // Version 1 + @ClassRedefinitionPolicy(alias = java.lang.reflect.Type.class) + public interface Type___1 { + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testRedefineClass() { + @Test + public void testRedefineClass() { - assert __version__() == 0; + assert __version__() == 0; - __toVersion__(1); + __toVersion__(1); - __toVersion__(0); + __toVersion__(0); - __toVersion__(1); + __toVersion__(1); - __toVersion__(0); + __toVersion__(0); - } + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/ThisTypeChange.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/ThisTypeChange.java index aaed2e6c..617c57d7 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/ThisTypeChange.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/ThisTypeChange.java @@ -41,87 +41,87 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; @Category(Light.class) public class ThisTypeChange { - @Before - public void setUp() throws Exception { - __toVersion__(0); - } - - // Version 0 - public static class A { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - public int valueOK() { - return 1; - } + // Version 0 + public static class A { - public int value() { - __toVersion__(1); - return 1; - } + public int valueOK() { + return 1; } - public static class B extends A { - - @Override - public int value() { - return super.value(); - } - - - @Override - public int valueOK() { - __toVersion__(1); - return super.valueOK(); - } + public int value() { + __toVersion__(1); + return 1; } + } - // Version 1 - public static class A___1 { + public static class B extends A { - public int valueOK() { - return 2; - } + @Override + public int value() { + return super.value(); } - // Version 1 - public static class B___1 { - } - // Method to enforce cast (otherwise bytecodes become invalid in version 2) - public static A convertBtoA(Object b) { - return (A) b; + @Override + public int valueOK() { + __toVersion__(1); + return super.valueOK(); } + } - @Test - public void testThisTypeChange() { - - assert __version__() == 0; - - final B b = new B(); - TestUtil.assertUnsupported(new Runnable() { - @Override - public void run() { - b.value(); - } - }); - - assert __version__() == 0; - - TestUtil.assertUnsupported(new Runnable() { - @Override - public void run() { - b.valueOK(); - } - }); - - assert __version__() == 0; - - TestUtil.assertUnsupported(new Runnable() { - @Override - public void run() { - b.valueOK(); - } - }); + // Version 1 + public static class A___1 { - assert __version__() == 0; + public int valueOK() { + return 2; } + } + + // Version 1 + public static class B___1 { + } + + // Method to enforce cast (otherwise bytecodes become invalid in version 2) + public static A convertBtoA(Object b) { + return (A) b; + } + + @Test + public void testThisTypeChange() { + + assert __version__() == 0; + + final B b = new B(); + TestUtil.assertUnsupported(new Runnable() { + @Override + public void run() { + b.value(); + } + }); + + assert __version__() == 0; + + TestUtil.assertUnsupported(new Runnable() { + @Override + public void run() { + b.valueOK(); + } + }); + + assert __version__() == 0; + + TestUtil.assertUnsupported(new Runnable() { + @Override + public void run() { + b.valueOK(); + } + }); + + assert __version__() == 0; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingHeapTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingHeapTest.java index e2287a46..52d0560d 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingHeapTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingHeapTest.java @@ -42,142 +42,142 @@ import static org.junit.Assert.assertEquals; @Category(Full.class) public class TypeNarrowingHeapTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - int x = 1; - int y = 2; - int z = 3; + int x = 1; + int y = 2; + int z = 3; - public int value() { - return x; - } + public int value() { + return x; } + } - public static class C { - private A a; + public static class C { + private A a; - public C(A a) { - this.a = a; - } + public C(A a) { + this.a = a; } + } - public static class B extends A { + public static class B extends A { - } + } - // Version 1 - public static class B___1 { - } + // Version 1 + public static class B___1 { + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - A a = new A(); - B b = new B(); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + A a = new A(); + B b = new B(); + } - @Test - public void testSimpleTypeNarrowing() { + @Test + public void testSimpleTypeNarrowing() { - assert __version__() == 0; + assert __version__() == 0; - A a = convertBtoA(new B()); + A a = convertBtoA(new B()); - assertEquals(1, a.value()); + assertEquals(1, a.value()); - // Cannot do conversion if A object is on the stack! - a = null; + // Cannot do conversion if A object is on the stack! + a = null; - __toVersion__(1); + __toVersion__(1); - TestUtil.assertException(NoSuchMethodError.class, new Runnable() { - @Override - public void run() { - B b = new B(); - b.value(); - } - }); + TestUtil.assertException(NoSuchMethodError.class, new Runnable() { + @Override + public void run() { + B b = new B(); + b.value(); + } + }); - __toVersion__(0); - assert __version__() == 0; - } + __toVersion__(0); + assert __version__() == 0; + } - @Test - public void testTypeNarrowingWithField() { - C c = new C(new A()); + @Test + public void testTypeNarrowingWithField() { + C c = new C(new A()); - __toVersion__(1); + __toVersion__(1); - __toVersion__(0); + __toVersion__(0); - c = new C(convertBtoA(new B())); + c = new C(convertBtoA(new B())); - TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { - @Override - public void run() { - __toVersion__(1); - } - }); + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { + @Override + public void run() { + __toVersion__(1); + } + }); - assert __version__() == 0; + assert __version__() == 0; - c.a = null; + c.a = null; - __toVersion__(1); + __toVersion__(1); - __toVersion__(0); - } + __toVersion__(0); + } - // Method to enforce cast (otherwise bytecodes become invalid in version 2) - public static A convertBtoA(Object b) { - return (A)b; - } + // 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(); + @Test + public void testTypeNarrowingWithArray() { + final B b = new B(); + final A[] arr = new A[3]; + arr[0] = new A(); - assert b instanceof A; + assert b instanceof A; - __toVersion__(1); + __toVersion__(1); - assert !(b instanceof A); + assert !(b instanceof A); - TestUtil.assertException(ArrayStoreException.class, new Runnable() { - @Override - public void run() { - arr[1] = b; - } - }); + TestUtil.assertException(ArrayStoreException.class, new Runnable() { + @Override + public void run() { + arr[1] = b; + } + }); - __toVersion__(0); + __toVersion__(0); - arr[1] = new B(); + arr[1] = new B(); - TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { - @Override - public void run() { - __toVersion__(1); - } - }); + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { + @Override + public void run() { + __toVersion__(1); + } + }); - assert __version__() == 0; + assert __version__() == 0; - assert b instanceof A; + assert b instanceof A; - arr[1] = new A(); + arr[1] = new A(); - __toVersion__(1); + __toVersion__(1); - assert !(b instanceof A); + assert !(b instanceof A); - __toVersion__(0); + __toVersion__(0); - assert b instanceof A; - } + assert b instanceof A; + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest.java index 47d83e6f..05b830e5 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest.java @@ -40,74 +40,74 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; @Ignore public class TypeNarrowingMethodTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - int x = 1; - int y = 2; - int z = 3; + 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 int value() { + return x; } - public static class B extends A { - + 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 { + // Version 1 + public static class B___1 { + } - int x = 1; - int y = 2; - int z = 3; + // Version 2 + public static class A___2 { - public int value() { - return x; - } + int x = 1; + int y = 2; + int z = 3; - public static int badMethod(B b) { - return 5; - } + public int value() { + return x; } - public static class B___2 { + 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(); - } + @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); - } - }); + @Test + public void testTypeNarrowingWithViolatingMethod() { - assert __version__() == 0; + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { + @Override + public void run() { + __toVersion__(1); + } + }); - __toVersion__(2); + assert __version__() == 0; - __toVersion__(0); - } + __toVersion__(2); + + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest2.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest2.java index 177b2a7a..0b2fe751 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest2.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest2.java @@ -40,79 +40,79 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; @Ignore public class TypeNarrowingMethodTest2 { - // Version 0 - public static class A { + // Version 0 + public static class A { - int x = 1; - int y = 2; - int z = 3; + 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 int value() { + return x; } - public static class B extends A { - + 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 { + // Version 1 + public static class B___1 { + } - int x = 1; - int y = 2; - int z = 3; + // Version 2 + public static class A___2 { - public int value() { - return x; - } + int x = 1; + int y = 2; + int z = 3; - public static int badMethod(B b) { - return 5; - } + public int value() { + return x; } - public static class B___2 { + 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(); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + A a = new A(); + B b = new B(); + } - @Test - public void testTypeNarrowingWithViolatingMethod() { - final A a = new A(); + public static B indirectionMethod() { + return new B(); + } - TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { - @Override - public void run() { - __toVersion__(1); - System.out.println(a.badMethod()); - } - }); + @Test + public void testTypeNarrowingWithViolatingMethod() { + final A a = new A(); - assert __version__() == 0; + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { + @Override + public void run() { + __toVersion__(1); + System.out.println(a.badMethod()); + } + }); - __toVersion__(2); + assert __version__() == 0; - __toVersion__(0); - } + __toVersion__(2); + + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest3.java b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest3.java index bf746717..c79717dc 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest3.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/structural/TypeNarrowingMethodTest3.java @@ -40,78 +40,78 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; @Ignore public class TypeNarrowingMethodTest3 { - // Version 0 - public static class A { + // Version 0 + public static class A { - int x = 1; - int y = 2; - int z = 3; + 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 int value() { + return x; } - public static class B extends A { - + public static int badMethod() { + A a = indirectionMethod()[0]; + return a.y; } + } - // Version 1 - public static class B___1 { - } + public static class B extends A { + + } - // Version 2 - public static class A___2 { + // Version 1 + public static class B___1 { + } - int x = 1; - int y = 2; - int z = 3; + // Version 2 + public static class A___2 { - public int value() { - return x; - } + int x = 1; + int y = 2; + int z = 3; - public static int badMethod(B b) { - return 5; - } + public int value() { + return x; } - public static class B___2 { + 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() }; - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + A a = new A(); + B b = new B(); + } - @Test - public void testTypeNarrowingWithViolatingMethod() { - final A a = new A(); + public static B[] indirectionMethod() { + return new B[]{new B()}; + } - TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { - @Override - public void run() { - __toVersion__(1); - System.out.println(a.badMethod()); - } - }); + @Test + public void testTypeNarrowingWithViolatingMethod() { + final A a = new A(); - assert __version__() == 0; + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() { + @Override + public void run() { + __toVersion__(1); + System.out.println(a.badMethod()); + } + }); - __toVersion__(2); + assert __version__() == 0; - __toVersion__(0); - } + __toVersion__(2); + + __toVersion__(0); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/transformer/BaseClassTransformerTest.java b/dcevm/src/test/java7/com/github/dcevm/test/transformer/BaseClassTransformerTest.java index 27560dcd..f2678980 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/transformer/BaseClassTransformerTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/transformer/BaseClassTransformerTest.java @@ -34,13 +34,13 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; import static org.junit.Assert.assertEquals; class BaseClass { - public void $transformer() { - transformerExecuted(); - } + public void $transformer() { + transformerExecuted(); + } - public void transformerExecuted() { - - } + public void transformerExecuted() { + + } } /** @@ -51,53 +51,53 @@ class BaseClass { @Category(Full.class) public class BaseClassTransformerTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int x = 2; - } + public int x = 2; + } - // Version 3 - public static class A___1 extends BaseClass { + // Version 3 + public static class A___1 extends BaseClass { - public int x; + public int x; - @Override - public void transformerExecuted() { - System.out.println("Transformer of A executing..."); - x = x * 2; - } + @Override + public void transformerExecuted() { + System.out.println("Transformer of A executing..."); + x = x * 2; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testSimpleTransformer() { + @Test + public void testSimpleTransformer() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); + A a = new A(); - assertEquals(2, a.x); + assertEquals(2, a.x); - __toVersion__(1); + __toVersion__(1); - assertEquals(4, a.x); + assertEquals(4, a.x); - __toVersion__(0); + __toVersion__(0); - assertEquals(4, a.x); + assertEquals(4, a.x); - __toVersion__(1); + __toVersion__(1); - assertEquals(8, a.x); + assertEquals(8, a.x); - __toVersion__(0); + __toVersion__(0); - assertEquals(8, a.x); - } + assertEquals(8, a.x); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/transformer/SimpleTransformerTest.java b/dcevm/src/test/java7/com/github/dcevm/test/transformer/SimpleTransformerTest.java index fdebefa5..e560cfc2 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/transformer/SimpleTransformerTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/transformer/SimpleTransformerTest.java @@ -41,52 +41,52 @@ import static org.junit.Assert.assertEquals; @Category(Full.class) public class SimpleTransformerTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public int x = 2; - } + public int x = 2; + } - // Version 3 - public static class A___1 { + // Version 3 + public static class A___1 { - public int x; + public int x; - public void $transformer() { - System.out.println("Transformer of A executing..."); - x = x * 2; - } + public void $transformer() { + System.out.println("Transformer of A executing..."); + x = x * 2; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testSimpleTransformer() { + @Test + public void testSimpleTransformer() { - assert __version__() == 0; + assert __version__() == 0; - A a = new A(); + A a = new A(); - assertEquals(2, a.x); + assertEquals(2, a.x); - __toVersion__(1); + __toVersion__(1); - assertEquals(4, a.x); + assertEquals(4, a.x); - __toVersion__(0); + __toVersion__(0); - assertEquals(4, a.x); + assertEquals(4, a.x); - __toVersion__(1); + __toVersion__(1); - assertEquals(8, a.x); + assertEquals(8, a.x); - __toVersion__(0); + __toVersion__(0); - assertEquals(8, a.x); - } + assertEquals(8, a.x); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticConstructorTransformerTest.java b/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticConstructorTransformerTest.java index e255156c..1ecc128e 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticConstructorTransformerTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticConstructorTransformerTest.java @@ -35,54 +35,54 @@ import static com.github.dcevm.test.util.HotSwapTestHelper.__version__; */ public class StaticConstructorTransformerTest { - //Version 0 - public static class Static_TestClass { + //Version 0 + public static class Static_TestClass { - // remove static --> no fatal error occurs - public static int x = 0; - //public int x = 0; + // remove static --> no fatal error occurs + public static int x = 0; + //public int x = 0; - static { - System.out.println("Start Static_TestClass Version 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"); - } + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + } + System.out.println("End Static_TestClass Version 0"); } + } - //Version 1 - public static class Static_TestClass___1 { + //Version 1 + public static class Static_TestClass___1 { - public int version = 1; + public int version = 1; - static { - System.out.println("Static_TestClass Version 1"); - } - - public void $transformer() { - System.out.println(":::::::::transformerExecuted:::::::::::"); - } + static { + System.out.println("Static_TestClass Version 1"); } - @Before - public void setUp() throws Exception { - __toVersion__(0); + public void $transformer() { + System.out.println(":::::::::transformerExecuted:::::::::::"); } + } - @Test - public void testStaticConstructorTransformerTest() { + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - 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(); + @Test + public void testStaticConstructorTransformerTest() { - __toVersion__(1); + 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); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticTransformerTest.java b/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticTransformerTest.java index 8641785c..98099834 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticTransformerTest.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/transformer/StaticTransformerTest.java @@ -41,50 +41,50 @@ import static org.junit.Assert.assertEquals; @Category(Full.class) public class StaticTransformerTest { - // Version 0 - public static class A { + // Version 0 + public static class A { - public static int x = 2; - } + public static int x = 2; + } - // Version 3 - public static class A___1 { + // Version 3 + public static class A___1 { - public static int x; + public static int x; - public static void $staticTransformer() { - System.out.println("Static transformer of A executing..."); - x = x * 2; - } + public static void $staticTransformer() { + System.out.println("Static transformer of A executing..."); + x = x * 2; } + } - @Before - public void setUp() throws Exception { - __toVersion__(0); - } + @Before + public void setUp() throws Exception { + __toVersion__(0); + } - @Test - public void testStaticTransformer() { + @Test + public void testStaticTransformer() { - assert __version__() == 0; + assert __version__() == 0; - assertEquals(2, A.x); + assertEquals(2, A.x); - __toVersion__(1); + __toVersion__(1); - assertEquals(4, A.x); + assertEquals(4, A.x); - __toVersion__(0); + __toVersion__(0); - assertEquals(4, A.x); + assertEquals(4, A.x); - __toVersion__(1); + __toVersion__(1); - assertEquals(8, A.x); + assertEquals(8, A.x); - __toVersion__(0); + __toVersion__(0); - assertEquals(8, A.x); - } + assertEquals(8, A.x); + } } diff --git a/dcevm/src/test/java7/com/github/dcevm/test/util/HotSwapTestHelper.java b/dcevm/src/test/java7/com/github/dcevm/test/util/HotSwapTestHelper.java index 8ba4217b..30d6bd43 100644 --- a/dcevm/src/test/java7/com/github/dcevm/test/util/HotSwapTestHelper.java +++ b/dcevm/src/test/java7/com/github/dcevm/test/util/HotSwapTestHelper.java @@ -27,55 +27,56 @@ import com.github.dcevm.HotSwapTool; /** * Shortcut methods for testing. Methods are named this way to make them more visible in the test code. + * * @author Ivan Dubrov */ public class HotSwapTestHelper { - /** - * Returns the current version of the inner classes of an outer class. - * <p/> - * Caller class is used as an outer class. - * - * @return the version of the inner classes of the outer class - */ - public static int __version__() { - return HotSwapTool.getCurrentVersion(determineOuter(0)); - } + /** + * Returns the current version of the inner classes of an outer class. + * <p> + * Caller class is used as an outer class. + * + * @return the version of the inner classes of the outer class + */ + public static int __version__() { + return HotSwapTool.getCurrentVersion(determineOuter(0)); + } - /** - * Redefines all inner classes of a outer class to a specified version. Inner classes who do not have a particular - * representation for a version remain unchanged. - * <p/> - * Caller class is used as an outer class. - * - * @param versionNumber the target version number - */ - public static void __toVersion__(int versionNumber, Class<?>... extra) { - HotSwapTool.toVersion(determineOuter(0), versionNumber, extra); - } + /** + * Redefines all inner classes of a outer class to a specified version. Inner classes who do not have a particular + * representation for a version remain unchanged. + * <p> + * Caller class is used as an outer class. + * + * @param versionNumber the target version number + */ + public static void __toVersion__(int versionNumber, Class<?>... extra) { + HotSwapTool.toVersion(determineOuter(0), versionNumber, extra); + } - /** - * Helper method to determine caller outer class. - * <p/> - * Takes caller class and finds its top enclosing class (which is supposed to be test class). - * - * @param level on which level this call is being made. 0 - call is made immediately in the method of HotSwapTool. - * @return outer class reference - */ - private static Class<?> determineOuter(int level) { - StackTraceElement[] stack = Thread.currentThread().getStackTrace(); - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - // one for Thread#getStackTrace - // one for #determineOuter - // one for the caller - String callerName = stack[level + 3].getClassName(); - try { - Class<?> clazz = cl.loadClass(callerName); - while (clazz.getEnclosingClass() != null) { - clazz = clazz.getEnclosingClass(); - } - return clazz; - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Cannot find caller class: " + callerName, e); - } + /** + * Helper method to determine caller outer class. + * <p> + * Takes caller class and finds its top enclosing class (which is supposed to be test class). + * + * @param level on which level this call is being made. 0 - call is made immediately in the method of HotSwapTool. + * @return outer class reference + */ + private static Class<?> determineOuter(int level) { + StackTraceElement[] stack = Thread.currentThread().getStackTrace(); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + // one for Thread#getStackTrace + // one for #determineOuter + // one for the caller + String callerName = stack[level + 3].getClassName(); + try { + Class<?> clazz = cl.loadClass(callerName); + while (clazz.getEnclosingClass() != null) { + clazz = clazz.getEnclosingClass(); + } + return clazz; + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Cannot find caller class: " + callerName, e); } + } } diff --git a/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA.java b/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA.java index 758a796a..a07ff9ef 100644 --- a/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA.java +++ b/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA.java @@ -1,14 +1,13 @@ package com.github.dcevm.test.lambdas; import java.io.Serializable; -import java.util.concurrent.Callable; public class LambdaA implements Serializable { - public SerializableCallable<Integer> createLambda() { - return () -> 10; - } + public SerializableCallable<Integer> createLambda() { + return () -> 10; + } - public SerializableCallable<Integer> createLambda2() { - return () -> 20; - } + public SerializableCallable<Integer> createLambda2() { + return () -> 20; + } } diff --git a/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA___1.java b/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA___1.java index 03f5d018..1b3e5492 100644 --- a/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA___1.java +++ b/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaA___1.java @@ -1,15 +1,14 @@ package com.github.dcevm.test.lambdas; import java.io.Serializable; -import java.util.concurrent.Callable; public class LambdaA___1 implements Serializable { - public SerializableCallable<Integer> createLambda() { - return () -> 30; - } + public SerializableCallable<Integer> createLambda() { + return () -> 30; + } - public SerializableCallable<Integer> createLambda2() { - return () -> 40; - } + public SerializableCallable<Integer> createLambda2() { + return () -> 40; + } } diff --git a/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaTest.java b/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaTest.java index 90134954..f99e1e18 100644 --- a/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaTest.java +++ b/dcevm/src/test/java8/com/github/dcevm/test/lambdas/LambdaTest.java @@ -24,7 +24,10 @@ package com.github.dcevm.test.lambdas; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import java.util.concurrent.Callable; import java.util.function.Consumer; @@ -36,7 +39,7 @@ import static org.junit.Assert.fail; /** * Tests for lambda expressions. - * + * <p> * These lambdas are sneaky. First, it seems like generated lambda method names are arbitrary and depend * on the compilation order. However, for redefinition test we want to make sure that generated method names would * actually match in old and new versions, so we have keep classes being redefined outside of this inner class. |