aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--agent/src/main/java/META-INF/MANIFEST.MF4
-rw-r--r--agent/src/main/java/org/dcevm/agent/InstrumentationAgent.java18
-rw-r--r--build.cmd8
-rw-r--r--build.gradle223
-rw-r--r--framework/src/main/java/org/dcevm/ClassRedefinitionPolicy.java40
-rw-r--r--framework/src/main/java/org/dcevm/HotSwapTool.java233
-rw-r--r--framework/src/main/java/org/dcevm/InstrumentationRedefiner.java54
-rw-r--r--framework/src/main/java/org/dcevm/JDIRedefiner.java153
-rw-r--r--framework/src/main/java/org/dcevm/Redefiner.java37
-rw-r--r--framework/src/main/java/org/dcevm/TestClassAdapter.java101
-rw-r--r--gradle.properties28
-rw-r--r--gradle/wrapper/gradle-wrapper.jarbin0 -> 51106 bytes
-rw-r--r--gradle/wrapper/gradle-wrapper.properties6
-rwxr-xr-xgradlew164
-rw-r--r--gradlew.bat90
-rw-r--r--native/natives.c174
-rw-r--r--native/natives.h72
-rw-r--r--patches/dcevm-jdk8u5-b13.patch4251
-rw-r--r--settings.gradle1
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/LightTestSuite.java49
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/TestUtil.java86
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/ArrayTest.java98
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/BodyTestSuite.java53
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/ClassRenamingTestCase.java68
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/EMCPTest.java219
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/FacTest.java103
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/FibTest.java110
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/MultipleThreadsTest.java207
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/OldActivationTest.java158
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/RedefinePrivateMethodTest.java96
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/RefactorActiveMethodTest.java96
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/SimpleStaticTest.java128
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/StaticTest.java300
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/body/StressTest.java82
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/eval/AddingInterfaceTest.java122
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/eval/EvalTestSuite.java42
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/eval/FractionTest.java256
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/eval/GeometryScenario.java207
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/ComplexFieldTest.java104
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/EnumTest.java70
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/FieldAlignmentTest.java63
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/FieldChangedOrderTest.java184
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/FieldModificationTest.java278
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/FieldsTestSuite.java49
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/ObjectStressTest.java122
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/RedefinePrivateFieldTest.java97
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/StringFieldTest.java78
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/fields/YieldTest.java123
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/AddMethodTest.java166
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/AnnotationTest.java121
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectHashcodeTest.java92
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectSynchronizationTest.java79
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/ClassReflectionTest.java160
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/DeleteActiveMethodTest.java159
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/MethodReflectionTest.java152
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/MethodsTestSuite.java49
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/OverrideMethodTest.java247
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/SingleClassReflectionTest.java88
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/methods/SingleClassTest.java123
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/structural/AnonymousClassInMethodTest.java67
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/structural/InterfaceTest.java144
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/structural/RedefineClassClassTest.java71
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/structural/RedefineObjectClassTest.java149
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/structural/StructuralTestSuite.java45
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/structural/ThisTypeChange.java124
-rw-r--r--tests-java7/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java81
-rw-r--r--tests-java8/src/test/java/org/dcevm/test/methods/DefaultMethodsTest.java110
-rw-r--r--tests-java8/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java81
69 files changed, 11618 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..ef75b32a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+/.gradle
+/.idea
+/hotspot
+build
+*.iml
diff --git a/agent/src/main/java/META-INF/MANIFEST.MF b/agent/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..9a1b4b72
--- /dev/null
+++ b/agent/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Can-Redefine-Classes: true
+Agent-Class: org.dcevm.agent.InstrumentationAgent
+Premain-Class: org.dcevm.agent.InstrumentationAgent
diff --git a/agent/src/main/java/org/dcevm/agent/InstrumentationAgent.java b/agent/src/main/java/org/dcevm/agent/InstrumentationAgent.java
new file mode 100644
index 00000000..e3a129d5
--- /dev/null
+++ b/agent/src/main/java/org/dcevm/agent/InstrumentationAgent.java
@@ -0,0 +1,18 @@
+package org.dcevm.agent;
+
+import java.lang.instrument.Instrumentation;
+
+/**
+ * Simple agent to get access to the Instrumentation API.
+ */
+public class InstrumentationAgent {
+ public static Instrumentation INSTRUMENTATION;
+
+ public static void agentmain(String args, Instrumentation instr) {
+ INSTRUMENTATION = instr;
+ }
+
+ public static void premain(String args, Instrumentation instr) {
+ INSTRUMENTATION = instr;
+ }
+}
diff --git a/build.cmd b/build.cmd
new file mode 100644
index 00000000..53daf1cf
--- /dev/null
+++ b/build.cmd
@@ -0,0 +1,8 @@
+set WINDOWS_SDK=c:\Program Files\Microsoft SDKs\Windows\v7.1
+call "%WINDOWS_SDK%\bin\setenv.cmd" /%ARCH%
+
+echo Script arguments: %*
+set CYGWIN=C:\cygwin
+set SCRIPT=%~dp0
+set HOTSPOTWORKSPACE=.
+%CYGWIN%\bin\bash --login -c 'cd `/usr/bin/cygpath "$SCRIPT"/..` ; /usr/bin/pwd ; /usr/bin/make -C "make" %*'
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 00000000..12bd408a
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,223 @@
+// Global settings
+project.ext {
+ // Source JRE used for compilation, etc
+ if (!project.hasProperty('jre')) {
+ jre = System.getProperty('java.home')
+ }
+ os = Os.current()
+ arch = Arch.current()
+
+ if (!project.hasProperty('targetJre')) {
+ targetJre = jre
+ }
+}
+
+def targetJreFile = file(targetJre)
+def jreFile = file(jre)
+
+// HotSpot itself
+project('hotspot') {
+ task clean(type: InvokeMake) {
+ args 'clean'
+ }
+
+ task prepareJvm {
+ onlyIf { jreFile != targetJreFile }
+ doLast {
+ ant.copy(todir: targetJreFile) {
+ fileset(dir: jreFile)
+ }
+ ant.chmod(file: new File(targetJreFile, 'bin/java'), perm: '0755')
+ }
+ }
+
+ task clone(description: 'Clone HotSpot repository') {
+ onlyIf { !file('hotspot').exists() }
+ doLast {
+ exec {
+ workingDir '..'
+ executable 'hg'
+ args 'clone', hotspotRepository
+ }
+ }
+ }
+
+ task patch(description: 'Patch HotSpot sources', dependsOn: clone) << {
+ exec {
+ executable 'hg'
+ args 'pull'
+ }
+ exec {
+ executable 'hg'
+ args 'update', '-C', '-r', hotspotTag
+ }
+ new ByteArrayOutputStream().withStream { os ->
+ exec {
+ workingDir 'hotspot'
+ executable 'hg'
+ args 'status'
+ standardOutput os
+ }
+ def str = os.toString()
+ def matcher = str =~ /(?m)^\?\s+(.*)$/
+ matcher.each {
+ ant.delete(file: new File(file('hotspot'), it[1]))
+ }
+ }
+ ant.patch(patchfile: "../patches/dcevm-${hotspotTag}.patch", strip: 1)
+ }
+
+ task compileFastdebug(type: InvokeMake) {
+ args 'STRIP_POLICY=no_strip'
+ args 'ZIP_DEBUGINFO_FILES=0'
+ args 'ENABLE_FULL_DEBUG_SYMBOLS=1'
+ args 'fastdebug'
+ }
+
+ task compileProduct(type: InvokeMake) {
+ args 'ENABLE_FULL_DEBUG_SYMBOLS=0'
+ args 'product'
+ }
+
+ compileFastdebug.mustRunAfter patch
+ compileProduct.mustRunAfter patch
+
+ // Install given kind of DCEVM into destination JRE
+ ['Product', 'Fastdebug'].each { k ->
+ task("install${k}", dependsOn: [prepareJvm, "compile${k}"]) << {
+ def installPath = new File(new File(targetJreFile, arch == Arch.X86 ? os.installPath32 : os.installPath64), jvmName)
+
+ logger.info("Installing DCEVM runtime into JRE with JVM name '${jvmName}' and kind '${k.toLowerCase()}' at ${installPath}")
+ ant.copy(todir: installPath, overwrite: true) {
+ fileset(dir: "build/${os.buildPath}/${os.buildPath}_${arch.buildArch}_${compiler}/${k.toLowerCase()}",
+ includes: 'libjvm.so,libjsig.so,jvm.dll,jsig.dll,libjvm.dylib,libjsig.dylib')
+ }
+ }
+ }
+}
+
+// Java projects for testing DCEVM
+def setup(prjs, closure) {
+ prjs.each { prj ->
+ project(prj, closure)
+ }
+}
+
+setup(['agent', 'framework', 'tests-java7', 'tests-java8'], {
+ apply plugin: 'java'
+ apply plugin: 'idea'
+
+ repositories {
+ mavenCentral()
+ }
+})
+
+project('agent') {
+ jar {
+ manifest {
+ from "src/main/java/META-INF/MANIFEST.MF"
+ }
+ }
+}
+
+project('framework') {
+ dependencies {
+ compile project(':agent')
+ compile group: 'asm', name: 'asm-all', version: '3.3.+'
+ compile files(System.getProperty("java.home") + '/../lib/tools.jar')
+ }
+}
+
+project('tests-java8') {
+ sourceCompatibility = 1.8
+ targetCompatibility = 1.8
+}
+
+setup(['tests-java7', 'tests-java8'], {
+ dependencies {
+ compile project(':framework')
+ testCompile group: 'junit', name: 'junit', version: '4.11'
+ }
+
+ test {
+ executable new File(targetJreFile, 'bin/java')
+
+ jvmArgs "-XXaltjvm=${jvmName}"
+ jvmArgs '-javaagent:../agent/build/libs/agent.jar'
+ if (arch == Arch.X86_64) {
+ jvmArgs(project.oops == "compressed" ? '-XX:+UseCompressedOops' : "-XX:-UseCompressedOops")
+ }
+ jvmArgs "-XX:TraceRedefineClasses=${traceRedefinition}"
+
+ ignoreFailures = true
+ outputs.upToDateWhen { false }
+ }
+
+ test.dependsOn project(':hotspot').tasks[kind == 'fastdebug' ? 'installFastdebug' : 'installProduct']
+})
+
+
+enum Arch {
+ X86(["i386", "i486", "i586", "x86"], 'i486', 32),
+ X86_64(["x86_64", "x64", "amd64"], 'amd64', 64)
+
+ final List<String> names
+ final String buildArch
+ final int bits
+
+ Arch(List<String> names, String buildArch, int bits) {
+ this.names = names
+ this.buildArch = buildArch
+ this.bits = bits
+ }
+
+ static Arch find(String token) {
+ Arch res = values().find({ v -> v.names.contains(token) })
+ return res
+ }
+
+ static Arch current() {
+ return find(System.getProperty("os.arch"))
+ }
+}
+
+enum Os {
+ MAC('bsd', 'lib', 'lib'),
+ WINDOWS('windows', 'bin', 'bin'),
+ UNIX('linux', 'lib/i386', 'lib/amd64')
+
+ final String buildPath;
+ final String installPath32;
+ final String installPath64;
+
+ Os(String buildPath, String installPath32, String installPath64) {
+ this.buildPath = buildPath
+ this.installPath32 = installPath32
+ this.installPath64 = installPath64
+ }
+
+ static Os current() {
+ return values().find { os -> org.apache.tools.ant.taskdefs.condition.Os.isFamily(os.name().toLowerCase()) }
+ }
+}
+
+// Helper task to run make targets against hotspot
+class InvokeMake extends org.gradle.api.tasks.Exec {
+ InvokeMake() {
+ logging.captureStandardOutput LogLevel.INFO
+ if (project.rootProject.os != Os.WINDOWS) {
+ commandLine 'make', '-C', 'make'
+ } else {
+ // Using launcher script
+ commandLine 'cmd', '/c', '..\\build.cmd'
+ environment ARCH: project.rootProject.arch == Arch.X86 ? 'x86' : 'x64'
+ }
+ args 'OPENJDK=true'
+ args "HOTSPOT_BUILD_VERSION=dcevmlight-${project.rootProject.buildNumber}"
+ args "ARCH_DATA_MODEL=${project.rootProject.arch.bits}"
+ args "ALT_BOOTDIR=${project.rootProject.jre.replace('\\', '/')}/.."
+ // Replacing backslashes is essential for Windows!
+ args 'COMPILER_WARNINGS_FATAL=false' // Clang is very serious about warnings
+ args 'HOTSPOT_BUILD_JOBS=4'
+ }
+}
diff --git a/framework/src/main/java/org/dcevm/ClassRedefinitionPolicy.java b/framework/src/main/java/org/dcevm/ClassRedefinitionPolicy.java
new file mode 100644
index 00000000..32571863
--- /dev/null
+++ b/framework/src/main/java/org/dcevm/ClassRedefinitionPolicy.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author Kerstin Breiteneder
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface ClassRedefinitionPolicy {
+
+ // Default value if no alias is set.
+ public final static class NoClass {
+ }
+
+ Class<?> alias() default NoClass.class;
+}
diff --git a/framework/src/main/java/org/dcevm/HotSwapTool.java b/framework/src/main/java/org/dcevm/HotSwapTool.java
new file mode 100644
index 00000000..b622cba9
--- /dev/null
+++ b/framework/src/main/java/org/dcevm/HotSwapTool.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm;
+
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Type;
+
+import java.io.*;
+import java.lang.instrument.UnmodifiableClassException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+/**
+ * @author Thomas Wuerthinger
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+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 String IDENTIFIER = "___";
+ 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ 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...
+ }
+
+ /**
+ * 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) {
+ assert versionNumber >= 0;
+
+ if (versionNumber == getCurrentVersion(outerClass)) {
+ // Nothing to do!
+ return;
+ }
+
+ Map<String, File> files = findClassesWithVersion(outerClass, versionNumber);
+
+ 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);
+ }
+
+ private static Map<String, File> findClassesWithVersion(Class<?> baseClass, int version) {
+ Map<String, File> classes = new HashMap<String, File>();
+
+ 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 + "'");
+ }
+ File folder = new File(url.getFile());
+ for (File f : folder.listFiles(IsClassFile.INSTANCE)) {
+ String fileName = f.getName();
+ String simpleName = f.getName().substring(0, f.getName().length() - CLASS_FILE_SUFFIX.length());
+ String name = baseClass.getPackage().getName() + '.' + simpleName;
+
+ if (isInnerClass(name, baseClass) && parseClassVersion(fileName) == version) {
+ classes.put(name, f);
+ }
+ }
+ return classes;
+ }
+
+ private enum IsClassFile implements FilenameFilter {
+ INSTANCE;
+
+ @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 name) {
+ int index = name.indexOf(IDENTIFIER);
+ if (index == -1) {
+ return 0;
+ }
+ return Integer.valueOf(name.substring(index + IDENTIFIER.length(), name.length() - CLASS_FILE_SUFFIX.length()));
+ }
+
+ private static String stripVersion(String className) {
+ int index = className.indexOf(IDENTIFIER);
+ if (index == -1) {
+ return className;
+ }
+ return className.substring(0, index);
+ }
+
+ public static void resetTimings() {
+ redefinitionCount = 0;
+ totalTime = 0;
+ }
+
+ public static int getRedefinitionCount() {
+ return redefinitionCount;
+ }
+
+ public static long getTotalTime() {
+ return totalTime;
+ }
+}
diff --git a/framework/src/main/java/org/dcevm/InstrumentationRedefiner.java b/framework/src/main/java/org/dcevm/InstrumentationRedefiner.java
new file mode 100644
index 00000000..247fbb2e
--- /dev/null
+++ b/framework/src/main/java/org/dcevm/InstrumentationRedefiner.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm;
+
+
+import org.dcevm.agent.InstrumentationAgent;
+
+import java.io.IOException;
+import java.lang.instrument.ClassDefinition;
+import java.lang.instrument.Instrumentation;
+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);
+ }
+
+ @Override
+ public void close() throws IOException {
+ // Do nothing.
+ }
+}
diff --git a/framework/src/main/java/org/dcevm/JDIRedefiner.java b/framework/src/main/java/org/dcevm/JDIRedefiner.java
new file mode 100644
index 00000000..6fc742d4
--- /dev/null
+++ b/framework/src/main/java/org/dcevm/JDIRedefiner.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm;
+
+import com.sun.jdi.Bootstrap;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.VirtualMachine;
+import com.sun.jdi.VirtualMachineManager;
+import com.sun.jdi.connect.AttachingConnector;
+import com.sun.jdi.connect.Connector.Argument;
+import com.sun.jdi.connect.IllegalConnectorArgumentsException;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Utility class for performing class redefinition using JDI.
+ * </li>
+ * </ul>
+ *
+ * @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);
+ }
+
+ @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");
+ }
+
+ // 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);
+ }
+ }
+
+ public void disconnect() {
+ if (vm != null) {
+ vm.dispose();
+ vm = null;
+ }
+ }
+
+ 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);
+ }
+
+ /**
+ * 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 + "'" );
+ }
+}
diff --git a/framework/src/main/java/org/dcevm/Redefiner.java b/framework/src/main/java/org/dcevm/Redefiner.java
new file mode 100644
index 00000000..cd183fe3
--- /dev/null
+++ b/framework/src/main/java/org/dcevm/Redefiner.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm;
+
+import java.io.Closeable;
+import java.lang.instrument.UnmodifiableClassException;
+import java.util.Map;
+
+/**
+ * Interface to the class redefinition implementation (JDI-based, Instrumenattion API based)
+ *
+ * @author Ivan Dubrov
+ */
+public interface Redefiner extends Closeable {
+ void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException;
+}
diff --git a/framework/src/main/java/org/dcevm/TestClassAdapter.java b/framework/src/main/java/org/dcevm/TestClassAdapter.java
new file mode 100644
index 00000000..bd4b2daf
--- /dev/null
+++ b/framework/src/main/java/org/dcevm/TestClassAdapter.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm;
+
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.commons.Remapper;
+import org.objectweb.asm.commons.RemappingClassAdapter;
+import org.objectweb.asm.commons.RemappingMethodAdapter;
+
+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;
+ }
+ });
+ }
+
+ @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) {
+ if (name.equals("<init>") && isObject && owner.equals("java/lang/Object")) {
+ return;
+ }
+
+ super.visitMethodInsn(opcode, owner, stripMethodSuffix(name), desc);
+ }
+ };
+ }
+
+ private static String stripMethodSuffix(String name) {
+ int pos = name.indexOf(METHOD_SUFFIX);
+ return (pos != -1) ? name.substring(0, pos) : name;
+ }
+}
+
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 00000000..549e2521
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,28 @@
+# Default settings for DCEVM build/testing
+traceRedefinition=1
+
+# Which JVM kind to use for testing, fastdebug (produces better crash reports) or product (faster).
+kind=fastdebug
+
+# If should use compressed oops (-XX:+UseCompressedOops) or not for testing.
+oops=compressed
+
+# DCEVM build number
+buildNumber=dev
+
+# Name of JVM to install DCEVM to. Specifx -XXaltjvm=<jvmName> to run given JVM.
+jvmName=dcevm
+
+# Which flavor of compiler to use. Leave default value.
+compiler=compiler2
+
+# Path to install JRE.
+# Used when creating local version of JRE with DCEVM library installed.
+targetJre=build/jre
+
+# Tag to base DCEVM on
+hotspotTag=jdk8u5-b13
+
+# Repository to clone hotspot from
+hotspotRepository=http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot
+#hotspotRepository=http://hg.openjdk.java.net/jdk7u/jdk7u/hotspot \ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..3c7abdf1
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..2352d1a6
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Thu Apr 24 15:01:45 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 00000000..91a7e269
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 00000000..aec99730
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/native/natives.c b/native/natives.c
new file mode 100644
index 00000000..9c40f2c7
--- /dev/null
+++ b/native/natives.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <stdio.h>
+#include <jni.h>
+#include <string.h>
+#include <stdlib.h>
+#include "natives.h"
+
+JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value(JNIEnv *env, jclass c) {
+ return 1;
+}
+
+JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value2(JNIEnv *env, jclass c) {
+ return 2;
+}
+
+JNIEXPORT jclass JNICALL Java_at_ssw_hotswap_test_access_jni_JNIVMAccess_findClassNative(JNIEnv *env, jclass c, jstring s) {
+ const char* name = (*env)->GetStringUTFChars(env, s, 0);
+ jclass clazz = (*env)->FindClass(env, name);
+ (*env)->ReleaseStringUTFChars(env, s, name);
+ return clazz;
+}
+
+JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_findMethodNative(JNIEnv *env, jclass c, jclass cls, jstring methodName) {
+ const char *methodstr = (*env)->GetStringUTFChars(env, methodName, 0);
+
+ jclass jCls = (*env)->GetObjectClass(env, cls);
+
+ // Get Method ID of getMethods()
+ jmethodID midGetFields = (*env)->GetMethodID(env, jCls, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
+ (*env)->ExceptionDescribe(env);
+ jobjectArray jobjArray = (jobjectArray) (*env)->CallObjectMethod(env, cls, midGetFields);
+
+ jsize len = (*env)->GetArrayLength(env, jobjArray);
+ jsize i = 0;
+
+ for (i = 0; i < len; i++) {
+ jobject _strMethod = (*env)->GetObjectArrayElement(env, jobjArray, i);
+ jclass _methodClazz = (*env)->GetObjectClass(env, _strMethod);
+ jmethodID mid = (*env)->GetMethodID(env, _methodClazz, "getName", "()Ljava/lang/String;");
+ jstring _name = (jstring) (*env)->CallObjectMethod(env, _strMethod, mid);
+
+ const char *str = (*env)->GetStringUTFChars(env, _name, 0);
+
+ if (strcmp(str, methodstr) == 0) {
+ (*env)->ReleaseStringUTFChars(env, methodName, methodstr);
+ (*env)->ReleaseStringUTFChars(env, _name, str);
+ return _strMethod;
+ }
+ (*env)->ReleaseStringUTFChars(env, _name, str);
+ }
+
+ jclass exc = (*env)->FindClass(env, "java/lang/NoSuchMethodError");
+ (*env)->ThrowNew(env, exc, methodstr);
+ (*env)->ReleaseStringUTFChars(env, methodName, methodstr);
+
+}
+
+JNIEXPORT jobjectArray JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_getMethodsNative(JNIEnv *env, jclass c, jclass cls) {
+ jobjectArray array;
+
+ jclass jCls = (*env)->GetObjectClass(env, cls);
+
+ // Get Method ID of getMethods()
+ jmethodID midGetFields = (*env)->GetMethodID(env, jCls, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
+ (*env)->ExceptionDescribe(env);
+ jobjectArray jobjArray = (jobjectArray) (*env)->CallObjectMethod(env, cls, midGetFields);
+
+ jsize len = (*env)->GetArrayLength(env, jobjArray);
+ jsize i = 0;
+
+ array = (*env)->NewObjectArray(env, len, (*env)->FindClass(env, "java/lang/reflect/Method"), 0);
+
+ for (i = 0; i < len; i++) {
+ jobject _strMethod = (*env)->GetObjectArrayElement(env, jobjArray, i);
+ (*env)->SetObjectArrayElement(env, array, i, _strMethod);
+ }
+
+ return array;
+}
+
+jobject callVoidMethod(JNIEnv *env, jobject obj, jboolean staticValue, jmethodID methodID, jvalue *params) {
+ if (staticValue) {
+ (*env)->CallStaticVoidMethodA(env, obj, methodID, params);
+ } else {
+ (*env)->CallVoidMethodA(env, obj, methodID, params);
+ }
+ return (*env)->NewGlobalRef(env, NULL);
+}
+
+jobject callIntMethod(JNIEnv *env, jobject obj, jboolean staticValue, jmethodID methodID, jvalue *params) {
+ jint intValue;
+ if (staticValue) {
+ intValue = (*env)->CallStaticIntMethodA(env, obj, methodID, params);
+ } else {
+ intValue = (*env)->CallIntMethodA(env, obj, methodID, params);
+ }
+ jclass clazz = (*env)->FindClass(env, "Ljava/lang/Integer;");
+ jmethodID methodIDInteger = (*env)->GetMethodID(env, clazz, "<init>", "(I)V");
+ return (*env)->NewObject(env, clazz, methodIDInteger, intValue);
+}
+
+jobject callObjectMethod(JNIEnv *env, jobject obj, jboolean staticValue, jmethodID methodID, jvalue *params) {
+ if (staticValue) {
+ return (*env)->CallStaticObjectMethodA(env, obj, methodID, params);
+ } else {
+ return (*env)->CallObjectMethodA(env, obj, methodID, params);
+ }
+}
+
+JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIMethodAccess_invokeMethodNative(JNIEnv *env, jclass c, jclass cls, jobject obj, jstring methodName, jstring retValue, jboolean staticValue, jstring descriptor, jobjectArray params) {
+ const char *methodstr = (*env)->GetStringUTFChars(env, methodName, 0);
+ const char *descriptorstr = (*env)->GetStringUTFChars(env, descriptor, 0);
+ const char *retValuestr = (*env)->GetStringUTFChars(env, retValue, 0);
+
+ jmethodID methodID;
+ if (staticValue) {
+ methodID = (*env)->GetStaticMethodID(env, cls, methodstr, descriptorstr);
+ } else {
+ methodID = (*env)->GetMethodID(env, cls, methodstr, descriptorstr);
+ }
+
+ jsize len = (*env)->GetArrayLength(env, params);
+ jvalue *m = (jvalue*) malloc(sizeof (jvalue) * len);
+
+ jvalue *mm = m;
+ int i = 0;
+ for (i; i < len; i++) {
+ *mm = (jvalue)(*env)->GetObjectArrayElement(env, params, i);
+ mm += 1;
+ }
+
+ jobject object = (*env)->NewGlobalRef(env, NULL);
+
+ if (strcmp(retValuestr, "void") == 0) {
+ object = callVoidMethod(env, obj, staticValue, methodID, m);
+ } else if (strcmp(retValuestr, "int") == 0) {
+ object = callIntMethod(env, obj, staticValue, methodID, m);
+ } else if (strcmp(retValuestr, "java.lang.Object") == 0) {
+ object = callObjectMethod(env, obj, staticValue, methodID, m);
+ } else {
+ jclass exc = (*env)->FindClass(env, "java.lang.NotImplementedException");
+ (*env)->ThrowNew(env, exc, "required retValue: bool/int/object");
+ }
+
+ (*env)->ReleaseStringUTFChars(env, methodName, methodstr);
+ (*env)->ReleaseStringUTFChars(env, descriptor, descriptorstr);
+ (*env)->ReleaseStringUTFChars(env, retValue, retValuestr);
+
+ return object;
+}
+
diff --git a/native/natives.h b/native/natives.h
new file mode 100644
index 00000000..90fcf920
--- /dev/null
+++ b/native/natives.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include <jni.h>
+
+#ifndef NATIVES
+#define NATIVES
+
+/*
+ * Class: at_ssw_hotswap_test_natives_SimpleNativeTest_A
+ * Method: value
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value(JNIEnv *, jclass);
+
+/*
+ * Class: at_ssw_hotswap_test_natives_SimpleNativeTest_A
+ * Method: value2
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value2(JNIEnv *, jclass);
+
+/*
+ * Class: at_ssw_hotswap_test_access_jni_JNIVMAccess
+ * Method: findClass
+ * Signature: (String)Class
+ */
+JNIEXPORT jclass JNICALL Java_at_ssw_hotswap_test_access_jni_JNIVMAccess_findClassNative(JNIEnv *, jclass, jstring);
+
+/*
+ * Class: at_ssw_hotswap_test_access_jni_JNIClassAccess
+ * Method: findMethod
+ * Signature: (Class, String)Object
+ */
+JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_findMethodNative(JNIEnv *, jclass, jclass, jstring);
+
+/*
+ * Class: at_ssw_hotswap_test_access_jni_JNIClassAccess
+ * Method: getMethods
+ * Signature: (Class)Object[]
+ */
+JNIEXPORT jobjectArray JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_getMethodsNative(JNIEnv *, jclass, jclass);
+
+/*
+ * Class: at_ssw_hotswap_test_access_jni_JNIMethodAccess
+ * Method: invokeMethod
+ * Signature: (Class, String, Object)Value
+ */
+JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIMethodAccess_invokeMethod(JNIEnv *, jclass, jclass, jobject, jstring, jstring, jboolean, jstring);
+
+#endif
diff --git a/patches/dcevm-jdk8u5-b13.patch b/patches/dcevm-jdk8u5-b13.patch
new file mode 100644
index 00000000..07ca0a30
--- /dev/null
+++ b/patches/dcevm-jdk8u5-b13.patch
@@ -0,0 +1,4251 @@
+diff --git a/make/openjdk_distro b/make/openjdk_distro
+index 520b33d..ea7eff0 100644
+--- a/make/openjdk_distro
++++ b/make/openjdk_distro
+@@ -27,6 +27,6 @@
+ #
+
+ # Don't put quotes (fail windows build).
+-HOTSPOT_VM_DISTRO=OpenJDK
++HOTSPOT_VM_DISTRO=Dynamic Code Evolution
+ COMPANY_NAME=
+ PRODUCT_NAME=OpenJDK
+diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
+index d257e8a..6adcbbf 100644
+--- a/src/share/vm/ci/ciObjectFactory.cpp
++++ b/src/share/vm/ci/ciObjectFactory.cpp
+@@ -750,3 +750,27 @@ void ciObjectFactory::print() {
+ _unloaded_instances->length(),
+ _unloaded_klasses->length());
+ }
++
++int ciObjectFactory::compare_cimetadata(ciMetadata** a, ciMetadata** b) {
++ Metadata* am = (*a)->constant_encoding();
++ Metadata* bm = (*b)->constant_encoding();
++ return ((am > bm) ? 1 : ((am == bm) ? 0 : -1));
++}
++
++// (DCEVM) Resoring the ciObject arrays after class redefinition
++void ciObjectFactory::resort_shared_ci_metadata() {
++ if (_shared_ci_metadata == NULL) return;
++ _shared_ci_metadata->sort(ciObjectFactory::compare_cimetadata);
++
++#ifdef ASSERT
++ if (CIObjectFactoryVerify) {
++ Metadata* last = NULL;
++ for (int j = 0; j< _shared_ci_metadata->length(); j++) {
++ Metadata* o = _shared_ci_metadata->at(j)->constant_encoding();
++ assert(last < o, "out of order");
++ last = o;
++ }
++ }
++#endif // ASSERT
++}
++
+diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
+index c1baca0..dfe0adc 100644
+--- a/src/share/vm/ci/ciObjectFactory.hpp
++++ b/src/share/vm/ci/ciObjectFactory.hpp
+@@ -90,6 +90,7 @@ private:
+
+ ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
+
++ static int compare_cimetadata(ciMetadata** a, ciMetadata** b);
+ public:
+ static bool is_initialized() { return _initialized; }
+
+@@ -145,6 +146,8 @@ public:
+
+ void print_contents();
+ void print();
++
++ static void resort_shared_ci_metadata();
+ };
+
+ #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
+diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
+index 3b1d4d2..4d3ca85 100644
+--- a/src/share/vm/classfile/classFileParser.cpp
++++ b/src/share/vm/classfile/classFileParser.cpp
+@@ -759,6 +759,7 @@ bool put_after_lookup(Symbol* name, Symbol* sig, NameSigHash** table) {
+ Array<Klass*>* ClassFileParser::parse_interfaces(int length,
+ Handle protection_domain,
+ Symbol* class_name,
++ bool pick_newest,
+ bool* has_default_methods,
+ TRAPS) {
+ if (length == 0) {
+@@ -777,7 +778,11 @@ Array<Klass*>* ClassFileParser::parse_interfaces(int length,
+ "Interface name has bad constant pool index %u in class file %s",
+ interface_index, CHECK_NULL);
+ if (_cp->tag_at(interface_index).is_klass()) {
+- interf = KlassHandle(THREAD, _cp->resolved_klass_at(interface_index));
++ Klass* resolved_klass = _cp->resolved_klass_at(interface_index);
++ if (pick_newest) {
++ resolved_klass = resolved_klass->newest_version();
++ }
++ interf = KlassHandle(THREAD, resolved_klass);
+ } else {
+ Symbol* unresolved_klass = _cp->klass_name_at(interface_index);
+
+@@ -791,6 +796,9 @@ Array<Klass*>* ClassFileParser::parse_interfaces(int length,
+ Klass* k = SystemDictionary::resolve_super_or_fail(class_name,
+ unresolved_klass, class_loader, protection_domain,
+ false, CHECK_NULL);
++ if (pick_newest) {
++ k = k->newest_version();
++ }
+ interf = KlassHandle(THREAD, k);
+ }
+
+@@ -3093,6 +3101,7 @@ AnnotationArray* ClassFileParser::assemble_annotations(u1* runtime_visible_annot
+ }
+
+ instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index,
++ bool pick_newest,
+ TRAPS) {
+ instanceKlassHandle super_klass;
+ if (super_class_index == 0) {
+@@ -3109,7 +3118,11 @@ instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index,
+ // However, make sure it is not an array type.
+ bool is_array = false;
+ if (_cp->tag_at(super_class_index).is_klass()) {
+- super_klass = instanceKlassHandle(THREAD, _cp->resolved_klass_at(super_class_index));
++ Klass* resolved_klass = _cp->resolved_klass_at(super_class_index);
++ if (pick_newest) {
++ resolved_klass = resolved_klass->newest_version();
++ }
++ super_klass = instanceKlassHandle(THREAD, resolved_klass);
+ if (_need_verify)
+ is_array = super_klass->oop_is_array();
+ } else if (_need_verify) {
+@@ -3658,8 +3671,10 @@ void ClassFileParser::layout_fields(Handle class_loader,
+ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+ ClassLoaderData* loader_data,
+ Handle protection_domain,
++ KlassHandle old_klass,
+ KlassHandle host_klass,
+ GrowableArray<Handle>* cp_patches,
++ GrowableArray<Symbol*>* parsed_super_symbols,
+ TempNewSymbol& parsed_name,
+ bool verify,
+ TRAPS) {
+@@ -3672,6 +3687,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+ JvmtiCachedClassFileData *cached_class_file = NULL;
+ Handle class_loader(THREAD, loader_data->class_loader());
+ bool has_default_methods = false;
++ bool pick_newest = !old_klass.is_null();
+ ResourceMark rm(THREAD);
+
+ ClassFileStream* cfs = stream();
+@@ -3688,7 +3704,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+
+ init_parsed_class_attributes(loader_data);
+
+- if (JvmtiExport::should_post_class_file_load_hook()) {
++ if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
+ // Get the cached class file bytes (if any) from the class that
+ // is being redefined or retransformed. We use jvmti_thread_state()
+ // instead of JvmtiThreadState::state_for(jt) so we don't allocate
+@@ -3823,6 +3839,26 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+ CHECK_(nullHandle));
+ }
+
++ // (DCEVM) Do not parse full class file, only get super symbols and return.
++ if (parsed_super_symbols != NULL) {
++ u2 super_class_index = cfs->get_u2_fast();
++
++ if (super_class_index != 0) {
++ parsed_super_symbols->append(cp->klass_name_at(super_class_index));
++ }
++
++ // Interfaces
++ u2 itfs_len = cfs->get_u2_fast();
++ Array<Klass*>* local_interfaces =
++ parse_interfaces(itfs_len, protection_domain, _class_name, pick_newest, &has_default_methods, CHECK_NULL);
++
++ for (int i = 0; i < local_interfaces->length(); i++) {
++ Klass* o = local_interfaces->at(i);
++ parsed_super_symbols->append(o->name());
++ }
++ return NULL;
++ }
++
+ Klass* preserve_this_klass; // for storing result across HandleMark
+
+ // release all handles when parsing is done
+@@ -3849,13 +3885,14 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+
+ u2 super_class_index = cfs->get_u2_fast();
+ instanceKlassHandle super_klass = parse_super_class(super_class_index,
++ pick_newest,
+ CHECK_NULL);
+
+ // Interfaces
+ u2 itfs_len = cfs->get_u2_fast();
+ Array<Klass*>* local_interfaces =
+ parse_interfaces(itfs_len, protection_domain, _class_name,
+- &has_default_methods, CHECK_(nullHandle));
++ pick_newest, &has_default_methods, CHECK_(nullHandle));
+
+ u2 java_fields_count = 0;
+ // Fields (offsets are filled in later)
+@@ -3897,6 +3934,9 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+ true,
+ CHECK_(nullHandle));
+
++ if (pick_newest) {
++ k = k->newest_version();
++ }
+ KlassHandle kh (THREAD, k);
+ super_klass = instanceKlassHandle(THREAD, kh());
+ }
+@@ -4056,7 +4096,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
+ fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.nonstatic_oop_counts);
+
+ // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
+- set_precomputed_flags(this_klass);
++ set_precomputed_flags(this_klass, old_klass);
+
+ // reinitialize modifiers, using the InnerClasses attribute
+ int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
+@@ -4283,7 +4323,7 @@ void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
+ }
+
+
+-void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
++void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
+ Klass* super = k->super();
+
+ // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
+@@ -4291,7 +4331,9 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
+ if (!_has_empty_finalizer) {
+ if (_has_finalizer ||
+ (super != NULL && super->has_finalizer())) {
+- k->set_has_finalizer();
++ if (old_klass.is_null() || old_klass->has_finalizer()) {
++ k->set_has_finalizer();
++ }
+ }
+ }
+
+@@ -4307,7 +4349,7 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
+
+ // Check if this klass supports the java.lang.Cloneable interface
+ if (SystemDictionary::Cloneable_klass_loaded()) {
+- if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
++ if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->newest_version())) {
+ k->set_is_cloneable();
+ }
+ }
+diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
+index 02a4ce2..e5c6557 100644
+--- a/src/share/vm/classfile/classFileParser.hpp
++++ b/src/share/vm/classfile/classFileParser.hpp
+@@ -214,11 +214,12 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
+ Array<Klass*>* parse_interfaces(int length,
+ Handle protection_domain,
+ Symbol* class_name,
++ bool pick_newest,
+ bool* has_default_methods,
+ TRAPS);
+ void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS);
+
+- instanceKlassHandle parse_super_class(int super_class_index, TRAPS);
++ instanceKlassHandle parse_super_class(int super_class_index, bool pick_newest, TRAPS);
+ // Field parsing
+ void parse_field_attributes(u2 attributes_count,
+ bool is_static, u2 signature_index,
+@@ -299,7 +300,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
+ unsigned int nonstatic_oop_map_count,
+ int* nonstatic_oop_offsets,
+ unsigned int* nonstatic_oop_counts);
+- void set_precomputed_flags(instanceKlassHandle k);
++ void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
+ Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super,
+ Array<Klass*>* local_ifs, TRAPS);
+
+@@ -461,17 +462,20 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
+ instanceKlassHandle parseClassFile(Symbol* name,
+ ClassLoaderData* loader_data,
+ Handle protection_domain,
++ KlassHandle old_klass,
+ TempNewSymbol& parsed_name,
+ bool verify,
+ TRAPS) {
+ KlassHandle no_host_klass;
+- return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
++ return parseClassFile(name, loader_data, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
+ }
+ instanceKlassHandle parseClassFile(Symbol* name,
+ ClassLoaderData* loader_data,
+ Handle protection_domain,
++ KlassHandle old_klass,
+ KlassHandle host_klass,
+ GrowableArray<Handle>* cp_patches,
++ GrowableArray<Symbol*>* parsed_super_symbols,
+ TempNewSymbol& parsed_name,
+ bool verify,
+ TRAPS);
+diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
+index 0ab350d..3dba736 100644
+--- a/src/share/vm/classfile/classLoader.cpp
++++ b/src/share/vm/classfile/classLoader.cpp
+@@ -926,6 +926,7 @@ instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
+ instanceKlassHandle result = parser.parseClassFile(h_name,
+ loader_data,
+ protection_domain,
++ KlassHandle(),
+ parsed_name,
+ false,
+ CHECK_(h));
+diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
+index e308791..b2a5cc3 100644
+--- a/src/share/vm/classfile/dictionary.cpp
++++ b/src/share/vm/classfile/dictionary.cpp
+@@ -145,7 +145,7 @@ bool Dictionary::do_unloading() {
+ InstanceKlass* ik = InstanceKlass::cast(e);
+
+ // Non-unloadable classes were handled in always_strong_oops_do
+- if (!is_strongly_reachable(loader_data, e)) {
++ if (!ik->is_redefining() && !is_strongly_reachable(loader_data, e)) {
+ // Entry was not visited in phase1 (negated test from phase1)
+ assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader");
+ ClassLoaderData* k_def_class_loader_data = ik->class_loader_data();
+@@ -336,6 +336,32 @@ void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
+ add_entry(index, entry);
+ }
+
++// (DCEVM) Updates the klass entry to point to the new Klass*. Necessary only for class redefinition.
++bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class) {
++
++ // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
++ bool found = false;
++ for (int index = 0; index < table_size(); index++) {
++ for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
++ if (entry->klass() == old_class()) {
++ entry->set_literal(k());
++ found = true;
++ }
++ }
++ }
++ return found;
++}
++
++// (DCEVM) Undo previous updates to the system dictionary
++void Dictionary::rollback_redefinition() {
++ for (int index = 0; index < table_size(); index++) {
++ for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
++ if (entry->klass()->is_redefining()) {
++ entry->set_literal(entry->klass()->old_version());
++ }
++ }
++ }
++}
+
+ // This routine does not lock the system dictionary.
+ //
+@@ -366,7 +392,7 @@ Klass* Dictionary::find(int index, unsigned int hash, Symbol* name,
+ ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
+ DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
+ if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
+- return entry->klass();
++ return intercept_for_version(entry->klass());
+ } else {
+ return NULL;
+ }
+@@ -379,7 +405,7 @@ Klass* Dictionary::find_class(int index, unsigned int hash,
+ assert (index == index_for(name, loader_data), "incorrect index?");
+
+ DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
+- return (entry != NULL) ? entry->klass() : (Klass*)NULL;
++ return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
+ }
+
+
+@@ -391,7 +417,7 @@ Klass* Dictionary::find_shared_class(int index, unsigned int hash,
+ assert (index == index_for(name, NULL), "incorrect index?");
+
+ DictionaryEntry* entry = get_entry(index, hash, name, NULL);
+- return (entry != NULL) ? entry->klass() : (Klass*)NULL;
++ return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
+ }
+
+
+diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
+index 17d916f..7e47788 100644
+--- a/src/share/vm/classfile/dictionary.hpp
++++ b/src/share/vm/classfile/dictionary.hpp
+@@ -78,6 +78,10 @@ public:
+
+ void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
+
++ bool update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class);
++
++ void rollback_redefinition();
++
+ Klass* find_class(int index, unsigned int hash,
+ Symbol* name, ClassLoaderData* loader_data);
+
+@@ -107,6 +111,11 @@ public:
+ return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
+ }
+
++ // (DCEVM) During enhanced class redefinition we want old version if new is being redefined
++ static Klass* intercept_for_version(Klass* k) {
++ return (k != NULL && k->is_redefining()) ? k->old_version() : k;
++ }
++
+ // Unload (that is, break root links to) all unmarked classes and
+ // loaders. Returns "true" iff something was unloaded.
+ bool do_unloading();
+diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
+index 06e75ea..05dd8fe 100644
+--- a/src/share/vm/classfile/javaClasses.cpp
++++ b/src/share/vm/classfile/javaClasses.cpp
+@@ -1629,6 +1629,8 @@ void java_lang_Throwable::fill_in_stack_trace(Handle throwable, methodHandle met
+ skip_throwableInit_check = true;
+ }
+ }
++ // (DCEVM): Line numbers from newest version must be used for EMCP-swapped methods
++ method = method->newest_version();
+ if (method->is_hidden()) {
+ if (skip_hidden) continue;
+ }
+diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
+index 8d59c00..5651e6d 100644
+--- a/src/share/vm/classfile/loaderConstraints.cpp
++++ b/src/share/vm/classfile/loaderConstraints.cpp
+@@ -446,7 +446,7 @@ void LoaderConstraintTable::verify(Dictionary* dictionary,
+ if (k != NULL) {
+ // We found the class in the system dictionary, so we should
+ // make sure that the Klass* matches what we already have.
+- guarantee(k == probe->klass(), "klass should be in dictionary");
++ guarantee(k == probe->klass()->newest_version(), "klass should be in dictionary");
+ } else {
+ // If we don't find the class in the system dictionary, it
+ // has to be in the placeholders table.
+diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
+index f5c5c01..8b1fbcd 100644
+--- a/src/share/vm/classfile/systemDictionary.cpp
++++ b/src/share/vm/classfile/systemDictionary.cpp
+@@ -174,6 +174,7 @@ Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader
+ // can return a null klass
+ klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
+ }
++ assert(klass == NULL || klass->is_newest_version() || klass->newest_version()->is_redefining(), "must be");
+ return klass;
+ }
+
+@@ -216,7 +217,7 @@ Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
+ // Forwards to resolve_instance_class_or_null
+
+ Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
+- assert(!THREAD->is_Compiler_thread(),
++ assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
+ err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
+ class_name->as_C_string(),
+ class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
+@@ -1029,8 +1030,10 @@ Klass* SystemDictionary::parse_stream(Symbol* class_name,
+ instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
+ loader_data,
+ protection_domain,
++ KlassHandle(),
+ host_klass,
+ cp_patches,
++ NULL,
+ parsed_name,
+ true,
+ THREAD);
+@@ -1085,6 +1088,7 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
+ Handle protection_domain,
+ ClassFileStream* st,
+ bool verify,
++ KlassHandle old_class,
+ TRAPS) {
+
+ // Classloaders that support parallelism, e.g. bootstrap classloader,
+@@ -1112,9 +1116,15 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
+ instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
+ loader_data,
+ protection_domain,
++ old_class,
+ parsed_name,
+ verify,
+ THREAD);
++ // (DCEVM) During enhanced class redefinition, mark loaded class as being redefined
++ if (!old_class.is_null() && !k.is_null()) {
++ k->set_redefining(true);
++ k->set_old_version(old_class());
++ }
+
+ const char* pkg = "java/";
+ if (!HAS_PENDING_EXCEPTION &&
+@@ -1149,10 +1159,11 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
+ // Add class just loaded
+ // If a class loader supports parallel classloading handle parallel define requests
+ // find_or_define_instance_class may return a different InstanceKlass
+- if (is_parallelCapable(class_loader)) {
++ // (DCEVM) TODO: for class redefinition the parallel version does not work, check if this is a problem?
++ if (is_parallelCapable(class_loader) && old_class.is_null()) {
+ k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
+ } else {
+- define_instance_class(k, THREAD);
++ define_instance_class(k, old_class, THREAD);
+ }
+ }
+
+@@ -1166,7 +1177,7 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
+ MutexLocker mu(SystemDictionary_lock, THREAD);
+
+ Klass* check = find_class(parsed_name, loader_data);
+- assert(check == k(), "should be present in the dictionary");
++ assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
+
+ Klass* check2 = find_class(h_name, defining_loader_data);
+ assert(check == check2, "name inconsistancy in SystemDictionary");
+@@ -1386,7 +1397,11 @@ instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Ha
+ }
+ }
+
+-void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
++void SystemDictionary::rollback_redefinition() {
++ dictionary()->rollback_redefinition();
++}
++
++void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
+
+ ClassLoaderData* loader_data = k->class_loader_data();
+ Handle class_loader_h(THREAD, loader_data->class_loader());
+@@ -1416,7 +1431,17 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
+ Symbol* name_h = k->name();
+ unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
+ int d_index = dictionary()->hash_to_index(d_hash);
+- check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
++
++ // (DCEVM) Update version of the Klass* in the system dictionary
++ // TODO: Check for thread safety!
++ if (!old_class.is_null()) {
++ bool ok = dictionary()->update_klass(d_index, d_hash, name_h, loader_data, k, old_class);
++ assert (ok, "must have found old class and updated!");
++ }
++ check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
++
++ // FIXME: (DCEVM) clean this...
++ if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
+
+ // Register class just loaded with class loader (placed in Vector)
+ // Note we do this before updating the dictionary, as this can
+@@ -1449,8 +1474,9 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
+ }
+ k->eager_initialize(THREAD);
+
++ // (DCEVM) Only notify jvmti if not redefining a class.
+ // notify jvmti
+- if (JvmtiExport::should_post_class_load()) {
++ if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
+ assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
+ JvmtiExport::post_class_load((JavaThread *) THREAD, k());
+
+@@ -1524,7 +1550,7 @@ instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* clas
+ }
+ }
+
+- define_instance_class(k, THREAD);
++ define_instance_class(k, KlassHandle(), THREAD);
+
+ Handle linkage_exception = Handle(); // null handle
+
+@@ -1654,6 +1680,14 @@ void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
+ Universe::flush_dependents_on(k);
+ }
+
++// (DCEVM) Remove from hierarchy - Undo add_to_hierarchy.
++void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
++ assert(k.not_null(), "just checking");
++
++ // remove receiver from sibling list
++ k->remove_from_sibling_list();
++ // TODO (DCEVM): Remove from interfaces.
++}
+
+ // ----------------------------------------------------------------------------
+ // GC support
+@@ -2000,7 +2034,7 @@ void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
+ // also holds array classes
+
+ assert(check->oop_is_instance(), "noninstance in systemdictionary");
+- if ((defining == true) || (k() != check)) {
++ if ((defining == true) && ((k() != check) && k->old_version() != check)) {
+ linkage_error = "loader (instance of %s): attempted duplicate class "
+ "definition for name: \"%s\"";
+ } else {
+diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
+index b0e914f..8542985 100644
+--- a/src/share/vm/classfile/systemDictionary.hpp
++++ b/src/share/vm/classfile/systemDictionary.hpp
+@@ -269,7 +269,7 @@ public:
+ // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
+ static Klass* resolve_from_stream(Symbol* class_name, Handle class_loader,
+ Handle protection_domain,
+- ClassFileStream* st, bool verify, TRAPS);
++ ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
+
+ // Lookup an already loaded class. If not found NULL is returned.
+ static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
+@@ -339,6 +339,8 @@ public:
+ // System loader lock
+ static oop system_loader_lock() { return _system_loader_lock_obj; }
+
++ // (DCEVM) Remove link to hierarchy
++ static void remove_from_hierarchy(instanceKlassHandle k);
+ private:
+ // Extended Redefine classes support (tbi)
+ static void preloaded_classes_do(KlassClosure* f);
+@@ -408,6 +410,9 @@ public:
+ initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
+ }
+
++ // (DCEVM) rollback class redefinition
++ static void rollback_redefinition();
++
+ public:
+ #define WK_KLASS_DECLARE(name, symbol, option) \
+ static Klass* name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
+@@ -613,7 +618,7 @@ private:
+ // after waiting, but before reentering SystemDictionary_lock
+ // to preserve lock order semantics.
+ static void double_lock_wait(Handle lockObject, TRAPS);
+- static void define_instance_class(instanceKlassHandle k, TRAPS);
++ static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
+ static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
+ Handle class_loader,
+ instanceKlassHandle k, TRAPS);
+diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
+index 2e64747..d402d91 100644
+--- a/src/share/vm/classfile/verifier.cpp
++++ b/src/share/vm/classfile/verifier.cpp
+@@ -189,7 +189,7 @@ bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool shou
+ Symbol* name = klass->name();
+ Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
+
+- bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
++ bool is_reflect = refl_magic_klass != NULL && (klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->newest_version()));
+
+ return (should_verify_for(klass->class_loader(), should_verify_class) &&
+ // return if the class is a bootstrapping class
+@@ -518,7 +518,7 @@ void ErrorContext::stackmap_details(outputStream* ss, const Method* method) cons
+
+ ClassVerifier::ClassVerifier(
+ instanceKlassHandle klass, TRAPS)
+- : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
++ : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
+ _this_type = VerificationType::reference_type(klass->name());
+ // Create list to hold symbols in reference area.
+ _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
+@@ -548,7 +548,7 @@ void ClassVerifier::verify_class(TRAPS) {
+ _klass->external_name());
+ }
+
+- Array<Method*>* methods = _klass->methods();
++ Array<Method*>* methods = _klass_to_verify->methods();
+ int num_methods = methods->length();
+
+ for (int index = 0; index < num_methods; index++) {
+diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
+index 74143a6..002ef25 100644
+--- a/src/share/vm/classfile/verifier.hpp
++++ b/src/share/vm/classfile/verifier.hpp
+@@ -331,6 +331,7 @@ class ClassVerifier : public StackObj {
+
+ VerificationType object_type() const;
+
++ instanceKlassHandle _klass_to_verify;
+ instanceKlassHandle _klass; // the class being verified
+ methodHandle _method; // current method being verified
+ VerificationType _this_type; // the verification type of the current class
+diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
+index b87efd7..53738f4 100644
+--- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
++++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
+@@ -161,6 +161,12 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs,
+ }
+ }
+
++HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
++ CompactPoint* cp, HeapWord* compact_top) {
++ ShouldNotReachHere();
++ return NULL;
++}
++
+ // Like CompactibleSpace forward() but always calls cross_threshold() to
+ // update the block offset table. Removed initialize_threshold call because
+ // CFLS does not use a block offset array for contiguous spaces.
+@@ -2098,7 +2104,7 @@ bool CompactibleFreeListSpace::should_concurrent_collect() const {
+ // Support for compaction
+
+ void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) {
+- SCAN_AND_FORWARD(cp,end,block_is_obj,block_size);
++ SCAN_AND_FORWARD(cp,end,block_is_obj,block_size,false);
+ // prepare_for_compaction() uses the space between live objects
+ // so that later phase can skip dead space quickly. So verification
+ // of the free lists doesn't work after.
+@@ -2119,7 +2125,7 @@ void CompactibleFreeListSpace::adjust_pointers() {
+ }
+
+ void CompactibleFreeListSpace::compact() {
+- SCAN_AND_COMPACT(obj_size);
++ SCAN_AND_COMPACT(obj_size, false);
+ }
+
+ // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2]
+diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
+index e625d3a..4eb587f 100644
+--- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
++++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
+@@ -150,6 +150,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
+
+ // Support for compacting cms
+ HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
++ HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
+ HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
+
+ // Initialization helpers.
+diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
+index 1bc3ea4..15efb77 100644
+--- a/src/share/vm/gc_implementation/shared/markSweep.cpp
++++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
+@@ -32,6 +32,8 @@
+ #include "oops/objArrayKlass.inline.hpp"
+ #include "oops/oop.inline.hpp"
+
++GrowableArray<HeapWord*>* MarkSweep::_rescued_oops = NULL;
++
+ uint MarkSweep::_total_invocations = 0;
+
+ Stack<oop, mtGC> MarkSweep::_marking_stack;
+@@ -171,3 +173,100 @@ void MarkSweep::trace(const char* msg) {
+ }
+
+ #endif
++
++// (DCEVM) Copy the rescued objects to their destination address after compaction.
++void MarkSweep::copy_rescued_objects_back() {
++
++ if (_rescued_oops != NULL) {
++
++ for (int i=0; i<_rescued_oops->length(); i++) {
++ HeapWord* rescued_ptr = _rescued_oops->at(i);
++ oop rescued_obj = (oop) rescued_ptr;
++
++ int size = rescued_obj->size();
++ oop new_obj = rescued_obj->forwardee();
++
++ assert(rescued_obj->klass()->new_version() != NULL, "just checking");
++
++ if (rescued_obj->klass()->new_version()->update_information() != NULL) {
++ MarkSweep::update_fields(rescued_obj, new_obj);
++ } else {
++ rescued_obj->set_klass(rescued_obj->klass()->new_version());
++ Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
++ }
++
++ FREE_RESOURCE_ARRAY(HeapWord, rescued_ptr, size);
++
++ new_obj->init_mark();
++ assert(new_obj->is_oop(), "must be a valid oop");
++ }
++ _rescued_oops->clear();
++ _rescued_oops = NULL;
++ }
++}
++
++// (DCEVM) Update instances of a class whose fields changed.
++void MarkSweep::update_fields(oop q, oop new_location) {
++
++ assert(q->klass()->new_version() != NULL, "class of old object must have new version");
++
++ Klass* old_klass_oop = q->klass();
++ Klass* new_klass_oop = q->klass()->new_version();
++
++ InstanceKlass *old_klass = InstanceKlass::cast(old_klass_oop);
++ InstanceKlass *new_klass = InstanceKlass::cast(new_klass_oop);
++
++ int size = q->size_given_klass(old_klass);
++ int new_size = q->size_given_klass(new_klass);
++
++ HeapWord* tmp = NULL;
++ oop tmp_obj = q;
++
++ // Save object somewhere, there is an overlap in fields
++ if (new_klass_oop->is_copying_backwards()) {
++ if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
++ ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
++ tmp = NEW_RESOURCE_ARRAY(HeapWord, size);
++ q = (oop) tmp;
++ Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
++ }
++ }
++
++ q->set_klass(new_klass_oop);
++ int *cur = new_klass_oop->update_information();
++ assert(cur != NULL, "just checking");
++ MarkSweep::update_fields(new_location, q, cur);
++
++ if (tmp != NULL) {
++ FREE_RESOURCE_ARRAY(HeapWord, tmp, size);
++ }
++}
++
++void MarkSweep::update_fields(oop new_location, oop tmp_obj, int *cur) {
++ assert(cur != NULL, "just checking");
++ char* to = (char*)(HeapWord*)new_location;
++ while (*cur != 0) {
++ int size = *cur;
++ if (size > 0) {
++ cur++;
++ int offset = *cur;
++ HeapWord* from = (HeapWord*)(((char *)(HeapWord*)tmp_obj) + offset);
++ if (size == HeapWordSize) {
++ *((HeapWord*)to) = *from;
++ } else if (size == HeapWordSize * 2) {
++ *((HeapWord*)to) = *from;
++ *(((HeapWord*)to) + 1) = *(from + 1);
++ } else {
++ Copy::conjoint_jbytes(from, to, size);
++ }
++ to += size;
++ cur++;
++ } else {
++ assert(size < 0, "");
++ int skip = -*cur;
++ Copy::fill_to_bytes(to, skip, 0);
++ to += skip;
++ cur++;
++ }
++ }
++}
+diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
+index 38fc8e7..ce591ad 100644
+--- a/src/share/vm/gc_implementation/shared/markSweep.hpp
++++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
+@@ -107,8 +107,12 @@ class MarkSweep : AllStatic {
+ friend class AdjustPointerClosure;
+ friend class KeepAliveClosure;
+ friend class VM_MarkSweep;
++ friend class GenMarkSweep;
+ friend void marksweep_init();
+
++public:
++ static GrowableArray<HeapWord*>* _rescued_oops;
++
+ //
+ // Vars
+ //
+@@ -169,6 +173,9 @@ class MarkSweep : AllStatic {
+
+ static inline void push_objarray(oop obj, size_t index);
+
++ static void copy_rescued_objects_back();
++ static void update_fields(oop q, oop new_location);
++ static void update_fields(oop new_location, oop tmp_obj, int *cur);
+ static void follow_stack(); // Empty marking stack.
+
+ static void follow_klass(Klass* klass);
+diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
+index b63e03b..8c0a55e 100644
+--- a/src/share/vm/interpreter/linkResolver.cpp
++++ b/src/share/vm/interpreter/linkResolver.cpp
+@@ -215,8 +215,8 @@ void CallInfo::verify() {
+ // Klass resolution
+
+ void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
+- if (!Reflection::verify_class_access(ref_klass(),
+- sel_klass(),
++ if (!Reflection::verify_class_access(ref_klass()->newest_version(),
++ sel_klass()->newest_version(),
+ true)) {
+ ResourceMark rm(THREAD);
+ Exceptions::fthrow(
+@@ -444,7 +444,7 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass,
+ // We'll check for the method name first, as that's most likely
+ // to be false (so we'll short-circuit out of these tests).
+ if (sel_method->name() == vmSymbols::clone_name() &&
+- sel_klass() == SystemDictionary::Object_klass() &&
++ sel_klass()->newest_version() == SystemDictionary::Object_klass()->newest_version() &&
+ resolved_klass->oop_is_array()) {
+ // We need to change "protected" to "public".
+ assert(flags.is_protected(), "clone not protected?");
+@@ -802,7 +802,7 @@ void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass
+ }
+
+ // Final fields can only be accessed from its own class.
+- if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
++ if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass() && sel_klass() != current_klass()->active_version()) {
+ THROW(vmSymbols::java_lang_IllegalAccessError());
+ }
+
+@@ -1199,6 +1199,9 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
+ // recv_klass might be an arrayKlassOop but all vtables start at
+ // the same place. The cast is to avoid virtual call and assertion.
+ InstanceKlass* inst = (InstanceKlass*)recv_klass();
++
++ // (DCEVM) Check that the receiver is a subtype of the holder of the resolved method.
++ assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
+ selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
+ }
+ }
+diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
+index fdeba2a..fb207ed 100644
+--- a/src/share/vm/memory/genMarkSweep.cpp
++++ b/src/share/vm/memory/genMarkSweep.cpp
+@@ -334,11 +334,16 @@ void GenMarkSweep::mark_sweep_phase4() {
+ // in the same order in phase2, phase3 and phase4. We don't quite do that
+ // here (perm_gen first rather than last), so we tell the validate code
+ // to use a higher index (saved from phase2) when verifying perm_gen.
++ assert(_rescued_oops == NULL, "must be empty before processing");
+ GenCollectedHeap* gch = GenCollectedHeap::heap();
+
+ GCTraceTime tm("phase 4", PrintGC && Verbose, true, _gc_timer);
+ trace("4");
+
++ MarkSweep::copy_rescued_objects_back();
++
+ GenCompactClosure blk;
+ gch->generation_iterate(&blk, true);
++
++ MarkSweep::copy_rescued_objects_back();
+ }
+diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
+index 8f844df..81a5db3 100644
+--- a/src/share/vm/memory/space.cpp
++++ b/src/share/vm/memory/space.cpp
+@@ -379,9 +379,8 @@ void CompactibleSpace::clear(bool mangle_space) {
+ _compaction_top = bottom();
+ }
+
+-HeapWord* CompactibleSpace::forward(oop q, size_t size,
+- CompactPoint* cp, HeapWord* compact_top) {
+- // q is alive
++// (DCEVM) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
++HeapWord* CompactibleSpace::forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top) {
+ // First check if we should switch compaction space
+ assert(this == cp->space, "'this' should be current compaction space.");
+ size_t compaction_max_size = pointer_delta(end(), compact_top);
+@@ -401,8 +400,15 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
+ compaction_max_size = pointer_delta(cp->space->end(), compact_top);
+ }
+
++ return compact_top;
++}
++
++HeapWord* CompactibleSpace::forward(oop q, size_t size,
++ CompactPoint* cp, HeapWord* compact_top) {
++ compact_top = forward_compact_top(size, cp, compact_top);
++
+ // store the forwarding pointer into the mark word
+- if ((HeapWord*)q != compact_top) {
++ if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
+ q->forward_to(oop(compact_top));
+ assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
+ } else {
+@@ -423,6 +429,58 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
+ return compact_top;
+ }
+
++// Compute the forward sizes and leave out objects whose position could
++// possibly overlap other objects.
++HeapWord* CompactibleSpace::forward_with_rescue(HeapWord* q, size_t size,
++ CompactPoint* cp, HeapWord* compact_top) {
++ size_t forward_size = size;
++
++ // (DCEVM) There is a new version of the class of q => different size
++ if (oop(q)->klass()->new_version() != NULL && oop(q)->klass()->new_version()->update_information() != NULL) {
++
++ size_t new_size = oop(q)->size_given_klass(oop(q)->klass()->new_version());
++ assert(size != new_size, "instances without changed size have to be updated prior to GC run");
++ forward_size = new_size;
++ }
++
++ compact_top = forward_compact_top(forward_size, cp, compact_top);
++
++ if (must_rescue(oop(q), oop(compact_top))) {
++ if (MarkSweep::_rescued_oops == NULL) {
++ MarkSweep::_rescued_oops = new GrowableArray<HeapWord*>(128);
++ }
++ MarkSweep::_rescued_oops->append(q);
++ return compact_top;
++ }
++
++ return forward(oop(q), forward_size, cp, compact_top);
++}
++
++// Compute the forwarding addresses for the objects that need to be rescued.
++HeapWord* CompactibleSpace::forward_rescued(CompactPoint* cp, HeapWord* compact_top) {
++ // TODO: empty the _rescued_oops after ALL spaces are compacted!
++ if (MarkSweep::_rescued_oops != NULL) {
++ for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
++ HeapWord* q = MarkSweep::_rescued_oops->at(i);
++
++ /* size_t size = oop(q)->size(); changing this for cms for perm gen */
++ size_t size = block_size(q);
++
++ // (DCEVM) There is a new version of the class of q => different size
++ if (oop(q)->klass()->new_version() != NULL) {
++ size_t new_size = oop(q)->size_given_klass(oop(q)->klass()->new_version());
++ assert(size != new_size, "instances without changed size have to be updated prior to GC run");
++ size = new_size;
++ }
++
++ compact_top = cp->space->forward(oop(q), size, cp, compact_top);
++ assert(compact_top <= end(), "must not write over end of space!");
++ }
++ MarkSweep::_rescued_oops->clear();
++ MarkSweep::_rescued_oops = NULL;
++ }
++ return compact_top;
++}
+
+ bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
+ HeapWord* q, size_t deadlength) {
+@@ -444,12 +502,17 @@ bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
+ #define adjust_obj_size(s) s
+
+ void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
+- SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
++ SCAN_AND_FORWARD(cp, end, block_is_obj, block_size, false);
+ }
+
+ // Faster object search.
+ void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
+- SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
++ if (!Universe::is_redefining_gc_run()) {
++ SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, false);
++ } else {
++ // Redefinition run
++ SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, true);
++ }
+ }
+
+ void Space::adjust_pointers() {
+@@ -487,6 +550,111 @@ void Space::adjust_pointers() {
+ assert(q == t, "just checking");
+ }
+
++
++#ifdef ASSERT
++
++int CompactibleSpace::space_index(oop obj) {
++ GenCollectedHeap* heap = GenCollectedHeap::heap();
++
++ //if (heap->is_in_permanent(obj)) {
++ // return -1;
++ //}
++
++ int index = 0;
++ for (int i = heap->n_gens() - 1; i >= 0; i--) {
++ Generation* gen = heap->get_gen(i);
++ CompactibleSpace* space = gen->first_compaction_space();
++ while (space != NULL) {
++ if (space->is_in_reserved(obj)) {
++ return index;
++ }
++ space = space->next_compaction_space();
++ index++;
++ }
++ }
++
++ tty->print_cr("could not compute space_index for %08xh", (HeapWord*)obj);
++ index = 0;
++ for (int i = heap->n_gens() - 1; i >= 0; i--) {
++ Generation* gen = heap->get_gen(i);
++ tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
++
++ CompactibleSpace* space = gen->first_compaction_space();
++ while (space != NULL) {
++ tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
++ space = space->next_compaction_space();
++ index++;
++ }
++ }
++
++ ShouldNotReachHere();
++ return 0;
++}
++#endif
++
++bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
++ // Only redefined objects can have the need to be rescued.
++ if (oop(old_obj)->klass()->new_version() == NULL) return false;
++
++ //if (old_obj->is_perm()) {
++ // // This object is in perm gen: Always rescue to satisfy invariant obj->klass() <= obj.
++ // return true;
++ //}
++
++ int new_size = old_obj->size_given_klass(oop(old_obj)->klass()->new_version());
++ int original_size = old_obj->size();
++
++ Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
++ bool old_in_tenured = tenured_gen->is_in_reserved(old_obj);
++ bool new_in_tenured = tenured_gen->is_in_reserved(new_obj);
++ if (old_in_tenured == new_in_tenured) {
++ // Rescue if object may overlap with a higher memory address.
++ bool overlap = ((HeapWord*)old_obj + original_size < (HeapWord*)new_obj + new_size);
++ if (old_in_tenured) {
++ // Old and new address are in same space, so just compare the address.
++ // Must rescue if object moves towards the top of the space.
++ assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
++ } else {
++ // In the new generation, eden is located before the from space, so a
++ // simple pointer comparison is sufficient.
++ assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
++ assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
++ assert(overlap == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
++ }
++ return overlap;
++
++ } else {
++ assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
++ if (tenured_gen->is_in_reserved(new_obj)) {
++ // Must never rescue when moving from the new into the old generation.
++ assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
++ assert(space_index(old_obj) > space_index(new_obj), "must be");
++ return false;
++
++ } else /* if (tenured_gen->is_in_reserved(old_obj)) */ {
++ // Must always rescue when moving from the old into the new generation.
++ assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
++ assert(space_index(old_obj) < space_index(new_obj), "must be");
++ return true;
++ }
++ }
++}
++
++HeapWord* CompactibleSpace::rescue(HeapWord* old_obj) {
++ assert(must_rescue(oop(old_obj), oop(old_obj)->forwardee()), "do not call otherwise");
++
++ int size = oop(old_obj)->size();
++ HeapWord* rescued_obj = NEW_RESOURCE_ARRAY(HeapWord, size);
++ Copy::aligned_disjoint_words(old_obj, rescued_obj, size);
++
++ if (MarkSweep::_rescued_oops == NULL) {
++ MarkSweep::_rescued_oops = new GrowableArray<HeapWord*>(128);
++ }
++
++ MarkSweep::_rescued_oops->append(rescued_obj);
++ return rescued_obj;
++}
++
+ void CompactibleSpace::adjust_pointers() {
+ // Check first is there is any work to do.
+ if (used() == 0) {
+@@ -497,7 +665,12 @@ void CompactibleSpace::adjust_pointers() {
+ }
+
+ void CompactibleSpace::compact() {
+- SCAN_AND_COMPACT(obj_size);
++ if(!Universe::is_redefining_gc_run()) {
++ SCAN_AND_COMPACT(obj_size, false);
++ } else {
++ // Redefinition run
++ SCAN_AND_COMPACT(obj_size, true)
++ }
+ }
+
+ void Space::print_short() const { print_short_on(tty); }
+diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
+index 04efc7d..abd4b6b 100644
+--- a/src/share/vm/memory/space.hpp
++++ b/src/share/vm/memory/space.hpp
+@@ -450,6 +450,9 @@ public:
+ // indicates when the next such action should be taken.
+ virtual void prepare_for_compaction(CompactPoint* cp);
+ // MarkSweep support phase3
++ DEBUG_ONLY(int space_index(oop obj));
++ bool must_rescue(oop old_obj, oop new_obj);
++ HeapWord* rescue(HeapWord* old_obj);
+ virtual void adjust_pointers();
+ // MarkSweep support phase4
+ virtual void compact();
+@@ -479,6 +482,15 @@ public:
+ // accordingly".
+ virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
+ HeapWord* compact_top);
++ // (DCEVM) same as forwad, but can rescue objects. Invoked only during
++ // redefinition runs
++ HeapWord* forward_with_rescue(HeapWord* q, size_t size, CompactPoint* cp,
++ HeapWord* compact_top);
++
++ HeapWord* forward_rescued(CompactPoint* cp, HeapWord* compact_top);
++
++ // (tw) Compute new compact top without actually forwarding the object.
++ virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
+
+ // Return a size with adjusments as required of the space.
+ virtual size_t adjust_object_size_v(size_t size) const { return size; }
+@@ -509,7 +521,7 @@ protected:
+ size_t word_len);
+ };
+
+-#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
++#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size,redefinition_run) { \
+ /* Compute the new addresses for the live objects and store it in the mark \
+ * Used by universe::mark_sweep_phase2() \
+ */ \
+@@ -567,7 +579,17 @@ protected:
+ /* prefetch beyond q */ \
+ Prefetch::write(q, interval); \
+ size_t size = block_size(q); \
++ if (redefinition_run) { \
++ compact_top = cp->space->forward_with_rescue(q, size, \
++ cp, compact_top); \
++ if (q < first_dead && oop(q)->is_gc_marked()) { \
++ /* Was moved (otherwise, forward would reset mark), \
++ set first_dead to here */ \
++ first_dead = q; \
++ } \
++ } else { \
+ compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
++ } \
+ q += size; \
+ end_of_live = q; \
+ } else { \
+@@ -616,6 +638,8 @@ protected:
+ } \
+ } \
+ \
++ if (redefinition_run) { compact_top = forward_rescued(cp, compact_top); } \
++ \
+ assert(q == t, "just checking"); \
+ if (liveRange != NULL) { \
+ liveRange->set_end(q); \
+@@ -662,13 +686,8 @@ protected:
+ q += size; \
+ } \
+ \
+- if (_first_dead == t) { \
+- q = t; \
+- } else { \
+- /* $$$ This is funky. Using this to read the previously written \
+- * LiveRange. See also use below. */ \
+- q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
+- } \
++ /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
++ q = _first_dead; \
+ } \
+ \
+ const intx interval = PrefetchScanIntervalInBytes; \
+@@ -696,7 +715,7 @@ protected:
+ assert(q == t, "just checking"); \
+ }
+
+-#define SCAN_AND_COMPACT(obj_size) { \
++#define SCAN_AND_COMPACT(obj_size, redefinition_run) { \
+ /* Copy all live objects to their new location \
+ * Used by MarkSweep::mark_sweep_phase4() */ \
+ \
+@@ -721,13 +740,9 @@ protected:
+ } \
+ ) /* debug_only */ \
+ \
+- if (_first_dead == t) { \
+- q = t; \
+- } else { \
+- /* $$$ Funky */ \
+- q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
++ /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
++ q = _first_dead; \
+ } \
+- } \
+ \
+ const intx scan_interval = PrefetchScanIntervalInBytes; \
+ const intx copy_interval = PrefetchCopyIntervalInBytes; \
+@@ -745,11 +760,34 @@ protected:
+ size_t size = obj_size(q); \
+ HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
+ \
++ if (redefinition_run && must_rescue(oop(q), oop(q)->forwardee())) { \
++ rescue(q); \
++ debug_only(Copy::fill_to_words(q, size, 0)); \
++ q += size; \
++ continue; \
++ } \
++ \
+ /* prefetch beyond compaction_top */ \
+ Prefetch::write(compaction_top, copy_interval); \
+ \
+ /* copy object and reinit its mark */ \
+- assert(q != compaction_top, "everything in this pass should be moving"); \
++ assert(q != compaction_top || oop(q)->klass()->new_version() != NULL, \
++ "everything in this pass should be moving"); \
++ if (redefinition_run && oop(q)->klass()->new_version() != NULL) { \
++ Klass* new_version = oop(q)->klass()->new_version(); \
++ if (new_version->update_information() == NULL) { \
++ Copy::aligned_conjoint_words(q, compaction_top, size); \
++ oop(compaction_top)->set_klass(new_version); \
++ } else { \
++ MarkSweep::update_fields(oop(q), oop(compaction_top)); \
++ } \
++ oop(compaction_top)->init_mark(); \
++ assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
++ \
++ debug_only(prev_q = q); \
++ q += size; \
++ continue; \
++ } \
+ Copy::aligned_conjoint_words(q, compaction_top, size); \
+ oop(compaction_top)->init_mark(); \
+ assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
+diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
+index d022ae1..02dc63f 100644
+--- a/src/share/vm/memory/universe.cpp
++++ b/src/share/vm/memory/universe.cpp
+@@ -78,6 +78,8 @@
+ #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
+ #endif // INCLUDE_ALL_GCS
+
++bool Universe::_is_redefining_gc_run = false;
++
+ // Known objects
+ Klass* Universe::_boolArrayKlassObj = NULL;
+ Klass* Universe::_byteArrayKlassObj = NULL;
+@@ -157,6 +159,42 @@ void Universe::basic_type_classes_do(void f(Klass*)) {
+ f(doubleArrayKlassObj());
+ }
+
++// (DCEVM) This method should iterate all pointers that are not within heap objects.
++void Universe::root_oops_do(OopClosure *oopClosure) {
++
++ class AlwaysTrueClosure: public BoolObjectClosure {
++ public:
++ void do_object(oop p) { ShouldNotReachHere(); }
++ bool do_object_b(oop p) { return true; }
++ };
++ AlwaysTrueClosure always_true;
++
++ Universe::oops_do(oopClosure);
++// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
++ JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
++ Threads::oops_do(oopClosure, NULL, NULL);
++ ObjectSynchronizer::oops_do(oopClosure);
++ FlatProfiler::oops_do(oopClosure);
++ JvmtiExport::oops_do(oopClosure);
++
++ // Now adjust pointers in remaining weak roots. (All of which should
++ // have been cleared if they pointed to non-surviving objects.)
++ // Global (weak) JNI handles
++ JNIHandles::weak_oops_do(&always_true, oopClosure);
++
++ CodeCache::oops_do(oopClosure);
++ StringTable::oops_do(oopClosure);
++
++ // (DCEVM) TODO: Check if this is correct?
++ //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
++ //Management::oops_do(oopClosure);
++ //ref_processor()->weak_oops_do(&oopClosure);
++ //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
++
++ // SO_AllClasses
++ SystemDictionary::oops_do(oopClosure);
++}
++
+ void Universe::oops_do(OopClosure* f, bool do_all) {
+
+ f->do_oop((oop*) &_int_mirror);
+diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
+index ec3b59f..bf75fe0 100644
+--- a/src/share/vm/memory/universe.hpp
++++ b/src/share/vm/memory/universe.hpp
+@@ -248,7 +248,13 @@ class Universe: AllStatic {
+
+ static void compute_verify_oop_data();
+
++ static bool _is_redefining_gc_run;
++
+ public:
++
++ static bool is_redefining_gc_run() { return _is_redefining_gc_run; }
++ static void set_redefining_gc_run(bool b) { _is_redefining_gc_run = b; }
++
+ // Known classes in the VM
+ static Klass* boolArrayKlassObj() { return _boolArrayKlassObj; }
+ static Klass* byteArrayKlassObj() { return _byteArrayKlassObj; }
+@@ -401,6 +407,7 @@ class Universe: AllStatic {
+ static void run_finalizers_on_exit();
+
+ // Iteration
++ static void root_oops_do(OopClosure *f);
+
+ // Apply "f" to the addresses of all the direct heap pointers maintained
+ // as static fields of "Universe".
+diff --git a/src/share/vm/oops/cpCache.cpp b/src/share/vm/oops/cpCache.cpp
+index c9bbb5f..d27370a 100644
+--- a/src/share/vm/oops/cpCache.cpp
++++ b/src/share/vm/oops/cpCache.cpp
+@@ -532,6 +532,20 @@ bool ConstantPoolCacheEntry::is_interesting_method_entry(Klass* k) {
+ // the method is in the interesting class so the entry is interesting
+ return true;
+ }
++
++// Enhanced RedefineClasses() API support (DCEVM):
++// Clear cached entry, let it be re-resolved
++void ConstantPoolCacheEntry::clear_entry() {
++ // Clear entry during class redefinition. Note that we still keep flags.
++ _indices = constant_pool_index();
++ _f1 = NULL;
++ _f2 = 0;
++
++ // FIXME: (DCEVM) we want to clear flags, but it seems like they are referenced after clear_entry is called, but
++ // before they are reinitialized! So we are keeping them here for now...
++ // It's probably happening around prepare_invoke in template table.
++ //_flags = 0;
++}
+ #endif // INCLUDE_JVMTI
+
+ void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
+@@ -660,6 +674,14 @@ void ConstantPoolCache::dump_cache() {
+ }
+ }
+ }
++
++// Enhanced RedefineClasses() API support (DCEVM):
++// Clear all entries
++void ConstantPoolCache::clear_entries() {
++ for (int i = 0; i < length(); i++) {
++ entry_at(i)->clear_entry();
++ }
++}
+ #endif // INCLUDE_JVMTI
+
+
+diff --git a/src/share/vm/oops/cpCache.hpp b/src/share/vm/oops/cpCache.hpp
+index 26079fd..e3d593f 100644
+--- a/src/share/vm/oops/cpCache.hpp
++++ b/src/share/vm/oops/cpCache.hpp
+@@ -373,6 +373,10 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
+ bool * trace_name_printed);
+ bool check_no_old_or_obsolete_entries();
+ bool is_interesting_method_entry(Klass* k);
++
++ // Enhanced RedefineClasses() API support (DCEVM):
++ // Clear cached entry, let it be re-resolved
++ void clear_entry();
+ #endif // INCLUDE_JVMTI
+
+ // Debugging & Printing
+@@ -472,6 +476,10 @@ class ConstantPoolCache: public MetaspaceObj {
+ int methods_length, bool * trace_name_printed);
+ bool check_no_old_or_obsolete_entries();
+ void dump_cache();
++
++ // Enhanced RedefineClasses() API support (DCEVM):
++ // Clear all entries
++ void clear_entries();
+ #endif // INCLUDE_JVMTI
+
+ // Deallocate - no fields to deallocate
+diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
+index a6ca58c..33f944a 100644
+--- a/src/share/vm/oops/instanceKlass.cpp
++++ b/src/share/vm/oops/instanceKlass.cpp
+@@ -718,7 +718,8 @@ bool InstanceKlass::link_class_impl(
+ }
+ #endif
+ this_oop->set_init_state(linked);
+- if (JvmtiExport::should_post_class_prepare()) {
++ // (DCEVM) Must check for old version in order to prevent infinite loops.
++ if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
+ Thread *thread = THREAD;
+ assert(thread->is_Java_thread(), "thread->is_Java_thread()");
+ JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
+@@ -795,7 +796,9 @@ void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) {
+ // If we were to use wait() instead of waitInterruptibly() then
+ // we might end up throwing IE from link/symbol resolution sites
+ // that aren't expected to throw. This would wreak havoc. See 6320309.
+- while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
++ // (DCEVM) Wait also for the old class version to be fully initialized.
++ while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
++ || (this_oop->old_version() != NULL && InstanceKlass::cast(this_oop->old_version())->is_being_initialized())) {
+ wait = true;
+ ol.waitUninterruptibly(CHECK);
+ }
+@@ -1051,6 +1054,18 @@ bool InstanceKlass::implements_interface(Klass* k) const {
+ return false;
+ }
+
++bool InstanceKlass::implements_interface_any_version(Klass* k) const {
++ k = k->newest_version();
++ if (this->newest_version() == k) return true;
++ assert(k->is_interface(), "should be an interface class");
++ for (int i = 0; i < transitive_interfaces()->length(); i++) {
++ if (transitive_interfaces()->at(i)->newest_version() == k) {
++ return true;
++ }
++ }
++ return false;
++}
++
+ bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
+ // Verify direct super interface
+ if (this == k) return true;
+@@ -1314,6 +1329,18 @@ void InstanceKlass::methods_do(void f(Method* method)) {
+ }
+ }
+
++void InstanceKlass::store_update_information(GrowableArray<int> &values) {
++ int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
++ for (int i=0; i<values.length(); i++) {
++ arr[i] = values.at(i);
++ }
++ set_update_information(arr);
++}
++
++void InstanceKlass::clear_update_information() {
++ FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
++ set_update_information(NULL);
++}
+
+ void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
+ for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
+@@ -1797,6 +1824,18 @@ jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
+ return id;
+ }
+
++bool InstanceKlass::update_jmethod_id(Method* method, jmethodID newMethodID) {
++ size_t idnum = (size_t)method->method_idnum();
++ jmethodID* jmeths = methods_jmethod_ids_acquire();
++ size_t length; // length assigned as debugging crumb
++ jmethodID id = NULL;
++ if (jmeths != NULL && // If there is a cache
++ (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
++ jmeths[idnum+1] = newMethodID; // Set method id (may be NULL)
++ return true;
++ }
++ return false;
++}
+
+ //
+ // Walk the list of dependent nmethods searching for nmethods which
+@@ -1875,6 +1914,13 @@ void InstanceKlass::remove_dependent_nmethod(nmethod* nm) {
+ last = b;
+ b = b->next();
+ }
++
++ // (DCEVM) Hack as dependencies get wrong version of Klass*
++ if (this->old_version() != NULL) {
++ InstanceKlass::cast(this->old_version())->remove_dependent_nmethod(nm);
++ return;
++ }
++
+ #ifdef ASSERT
+ tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
+ nm->print();
+@@ -2884,6 +2930,24 @@ void InstanceKlass::print_on(outputStream* st) const {
+ assert(is_klass(), "must be klass");
+ Klass::print_on(st);
+
++ // (DCEVM) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
++ if (AllowEnhancedClassRedefinition) {
++ st->print(BULLET"revision: %d", revision_number());
++ if (new_version() != NULL) {
++ st->print(" (newer=%d)", new_version()->revision_number());
++ }
++ if (newest_version() != new_version() && newest_version() != this) {
++ st->print(" (newest=%d)", newest_version()->revision_number());
++ }
++ if (old_version() != NULL) {
++ st->print(" (old=%d)", old_version()->revision_number());
++ }
++ if (oldest_version() != old_version() && oldest_version() != this) {
++ st->print(" (oldest=%d)", oldest_version()->revision_number());
++ }
++ st->cr();
++ }
++
+ st->print(BULLET"instance size: %d", size_helper()); st->cr();
+ st->print(BULLET"klass size: %d", size()); st->cr();
+ st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
+@@ -3219,7 +3283,7 @@ void InstanceKlass::verify_on(outputStream* st, bool check_dictionary) {
+ }
+
+ guarantee(sib->is_klass(), "should be klass");
+- guarantee(sib->super() == super, "siblings should have same superklass");
++ guarantee(sib->super() == super || super->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
+ }
+
+ // Verify implementor fields
+@@ -3384,6 +3448,7 @@ void InstanceKlass::set_init_state(ClassState state) {
+
+ // Purge previous versions
+ static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) {
++ // FIXME: (DCEVM) Should we purge something?
+ if (ik->previous_versions() != NULL) {
+ // This klass has previous versions so see what we can cleanup
+ // while it is safe to do so.
+@@ -3621,7 +3686,7 @@ void InstanceKlass::add_previous_version(instanceKlassHandle ikh,
+
+ // Determine if InstanceKlass has a previous version.
+ bool InstanceKlass::has_previous_version() const {
+- return (_previous_versions != NULL && _previous_versions->length() > 0);
++ return _old_version != NULL || (_previous_versions != NULL && _previous_versions->length() > 0);
+ } // end has_previous_version()
+
+
+diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
+index 2b7a73a..9c10765 100644
+--- a/src/share/vm/oops/instanceKlass.hpp
++++ b/src/share/vm/oops/instanceKlass.hpp
+@@ -139,6 +139,7 @@ class InstanceKlass: public Klass {
+ friend class VMStructs;
+ friend class ClassFileParser;
+ friend class CompileReplay;
++ friend class VM_EnhancedRedefineClasses;
+
+ protected:
+ // Constructor
+@@ -637,7 +638,7 @@ class InstanceKlass: public Klass {
+ // If the _previous_versions array is non-NULL, then this klass
+ // has been redefined at least once even if we aren't currently
+ // tracking a previous version.
+- bool has_been_redefined() const { return _previous_versions != NULL; }
++ bool has_been_redefined() const { return _old_version != NULL || _previous_versions != NULL; }
+ bool has_previous_version() const;
+ void init_previous_versions() {
+ _previous_versions = NULL;
+@@ -711,6 +712,7 @@ class InstanceKlass: public Klass {
+ static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
+ size_t *length_p, jmethodID* id_p);
+ jmethodID jmethod_id_or_null(Method* method);
++ bool update_jmethod_id(Method* method, jmethodID newMethodID);
+
+ // annotations support
+ Annotations* annotations() const { return _annotations; }
+@@ -780,6 +782,7 @@ class InstanceKlass: public Klass {
+ // subclass/subinterface checks
+ bool implements_interface(Klass* k) const;
+ bool is_same_or_direct_interface(Klass* k) const;
++ bool implements_interface_any_version(Klass* k) const;
+
+ // Access to the implementor of an interface.
+ Klass* implementor() const
+@@ -831,6 +834,10 @@ class InstanceKlass: public Klass {
+ void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
+ void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
+
++ // (DCEVM) instance update information to be used in GC run
++ void store_update_information(GrowableArray<int> &values);
++ void clear_update_information();
++
+ void methods_do(void f(Method* method));
+ void array_klasses_do(void f(Klass* k));
+ void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
+diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
+index 22b570b..c7afba7 100644
+--- a/src/share/vm/oops/klass.cpp
++++ b/src/share/vm/oops/klass.cpp
+@@ -170,6 +170,13 @@ Klass::Klass() {
+ set_next_link(NULL);
+ TRACE_INIT_ID(this);
+
++ set_redefinition_flags(Klass::NoRedefinition);
++ set_redefining(false);
++ set_new_version(NULL);
++ set_old_version(NULL);
++ set_redefinition_index(-1);
++ set_revision_number(-1);
++
+ set_prototype_header(markOopDesc::prototype());
+ set_biased_lock_revocation_count(0);
+ set_last_biased_lock_bulk_revocation_time(0);
+@@ -375,6 +382,24 @@ void Klass::append_to_sibling_list() {
+ debug_only(verify();)
+ }
+
++// (DCEVM)
++void Klass::remove_from_sibling_list() {
++ debug_only(verify();)
++ // remove ourselves to superklass' subklass list
++ InstanceKlass* super = superklass();
++ assert(super != NULL, "should have super");
++ if (super->subklass() == this) {
++ // first subklass
++ super->set_subklass(next_sibling());
++ } else {
++ Klass* sib = super->subklass();
++ while (sib->next_sibling() != this) {
++ sib = sib->next_sibling();
++ };
++ sib->set_next_sibling(next_sibling());
++ }
++}
++
+ bool Klass::is_loader_alive(BoolObjectClosure* is_alive) {
+ assert(ClassLoaderDataGraph::contains((address)this), "is in the metaspace");
+
+diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
+index 9855fdd..c3e1f35 100644
+--- a/src/share/vm/oops/klass.hpp
++++ b/src/share/vm/oops/klass.hpp
+@@ -149,6 +149,10 @@ class Klass : public Metadata {
+ oop _java_mirror;
+ // Superclass
+ Klass* _super;
++ // Old class
++ Klass* _old_version;
++ // New class
++ Klass* _new_version;
+ // First subclass (NULL if none); _subklass->next_sibling() is next one
+ Klass* _subklass;
+ // Sibling link (or NULL); links all subklasses of a klass
+@@ -164,6 +168,16 @@ class Klass : public Metadata {
+ jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
+ AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
+
++ // (DCEVM) fields for enhanced class redefinition
++ jint _revision_number; // The revision number for redefined classes
++ jint _redefinition_index; // Index of this class when performing the redefinition
++ bool _subtype_changed;
++ int _redefinition_flags; // Level of class redefinition
++ bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
++ bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
++ int * _update_information; // Update information
++ bool _is_redefining;
++
+ // Biased locking implementation and statistics
+ // (the 64-bit chunk goes first, to avoid some fragmentation)
+ jlong _last_biased_lock_bulk_revocation_time;
+@@ -208,6 +222,53 @@ class Klass : public Metadata {
+ Array<Klass*>* secondary_supers() const { return _secondary_supers; }
+ void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
+
++ // BEGIN class redefinition utilities
++
++ // double links between new and old version of a class
++ Klass* old_version() const { return _old_version; }
++ void set_old_version(Klass* klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
++ Klass* new_version() const { return _new_version; }
++ void set_new_version(Klass* klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
++
++ // A subtype of this class is no longer a subtype
++ bool has_subtype_changed() const { return _subtype_changed; }
++ void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->is_newest_version(), "must be newest or second newest version");
++ _subtype_changed = b; }
++ // state of being redefined
++ int redefinition_index() const { return _redefinition_index; }
++ void set_redefinition_index(int index) { _redefinition_index = index; }
++ void set_redefining(bool b) { _is_redefining = b; }
++ bool is_redefining() const { return _is_redefining; }
++ int redefinition_flags() const { return _redefinition_flags; }
++ bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
++ void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
++ void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
++ void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
++ bool is_copying_backwards() const { return _is_copying_backwards; }
++ void set_copying_backwards(bool b) { _is_copying_backwards = b; }
++
++ // update information
++ int *update_information() const { return _update_information; }
++ void set_update_information(int *info) { _update_information = info; }
++
++ // Revision number for redefined classes, -1 for originally loaded classes
++ bool was_redefined() const { return _revision_number != -1; }
++ jint revision_number() const { return _revision_number; }
++ void set_revision_number(jint number) { _revision_number = number; }
++
++ const Klass* oldest_version() const { return _old_version == NULL ? this : _old_version->oldest_version(); }
++ Klass* oldest_version() { return _old_version == NULL ? this : _old_version->oldest_version(); }
++
++ const Klass* newest_version() const { return _new_version == NULL ? this : _new_version->newest_version(); }
++ Klass* newest_version() { return _new_version == NULL ? this : _new_version->newest_version(); }
++
++ const Klass* active_version() const { return _new_version == NULL || _new_version->is_redefining() ? this : _new_version->active_version(); }
++ Klass* active_version() { return _new_version == NULL || _new_version->is_redefining() ? this : _new_version->active_version(); }
++
++ bool is_newest_version() const { return _new_version == NULL; }
++
++ // END class redefinition utilities
++
+ // Return the element of the _super chain of the given depth.
+ // If there is no such element, return either NULL or this.
+ Klass* primary_super_of_depth(juint i) const {
+@@ -261,6 +322,7 @@ class Klass : public Metadata {
+ Klass* subklass() const;
+ Klass* next_sibling() const;
+ void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
++ void remove_from_sibling_list(); // (DCEVM) remove receiver from sibling list
+
+ void set_next_link(Klass* k) { _next_link = k; }
+ Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
+@@ -287,6 +349,16 @@ class Klass : public Metadata {
+ void set_next_sibling(Klass* s);
+
+ public:
++ // (DCEVM) Different class redefinition flags of code evolution.
++ enum RedefinitionFlags {
++ NoRedefinition, // This class is not redefined at all!
++ ModifyClass = 1, // There are changes to the class meta data.
++ ModifyClassSize = ModifyClass << 1, // The size of the class meta data changes.
++ ModifyInstances = ModifyClassSize << 1, // There are change to the instance format.
++ ModifyInstanceSize = ModifyInstances << 1, // The size of instances changes.
++ RemoveSuperType = ModifyInstanceSize << 1, // A super type of this class is removed.
++ MarkedAsAffected = RemoveSuperType << 1 // This class has been marked as an affected class.
++ };
+
+ // Compiler support
+ static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
+diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
+index a7fc062..94602c6 100644
+--- a/src/share/vm/oops/klassVtable.cpp
++++ b/src/share/vm/oops/klassVtable.cpp
+@@ -1409,6 +1409,8 @@ void klassVtable::verify(outputStream* st, bool forced) {
+
+ void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
+ vtableEntry* vte = &vt->table()[index];
++ // (DCEVM) FIXME-isd: do we need the following line?
++ if (vte->method() == NULL || table()[index].method() == NULL) return;
+ if (vte->method()->name() != table()[index].method()->name() ||
+ vte->method()->signature() != table()[index].method()->signature()) {
+ fatal("mismatched name/signature of vtable entries");
+@@ -1428,6 +1430,8 @@ void klassVtable::print() {
+
+ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
+ NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
++ // FIXME: (DCEVM) does not hold?
++ if (method() != NULL) {
+ assert(method() != NULL, "must have set method");
+ method()->verify();
+ // we sub_type, because it could be a miranda method
+@@ -1435,7 +1439,9 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
+ #ifndef PRODUCT
+ print();
+ #endif
+- fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
++ // (DCEVM) the following fatal does not work for old versions of classes
++ //fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
++ }
+ }
+ }
+
+diff --git a/src/share/vm/oops/method.cpp b/src/share/vm/oops/method.cpp
+index 7c292c3..cb53f20 100644
+--- a/src/share/vm/oops/method.cpp
++++ b/src/share/vm/oops/method.cpp
+@@ -1185,6 +1185,8 @@ methodHandle Method::clone_with_new_data(methodHandle m, u_char* new_code, int n
+
+ // Reset correct method/const method, method size, and parameter info
+ newm->set_constMethod(newcm);
++ newm->set_new_version(newm->new_version());
++ newm->set_old_version(newm->old_version());
+ newm->constMethod()->set_code_size(new_code_length);
+ newm->constMethod()->set_constMethod_size(new_const_method_size);
+ newm->set_method_size(new_method_size);
+@@ -1788,6 +1790,10 @@ Method* const JNIMethodBlock::_free_method = (Method*)55;
+
+ // Add a method id to the jmethod_ids
+ jmethodID Method::make_jmethod_id(ClassLoaderData* loader_data, Method* m) {
++ // FIXME: (DCEVM) ???
++ if (m != m->newest_version()) {
++ m = m->newest_version();
++ }
+ ClassLoaderData* cld = loader_data;
+
+ if (!SafepointSynchronize::is_at_safepoint()) {
+diff --git a/src/share/vm/oops/method.hpp b/src/share/vm/oops/method.hpp
+index 63705b3..51e01e3 100644
+--- a/src/share/vm/oops/method.hpp
++++ b/src/share/vm/oops/method.hpp
+@@ -105,6 +105,10 @@ class Method : public Metadata {
+ AccessFlags _access_flags; // Access flags
+ int _vtable_index; // vtable index of this method (see VtableIndexFlag)
+ // note: can have vtables with >2**16 elements (because of inheritance)
++ // (DCEVM) Newer version of method available?
++ Method* _new_version;
++ Method* _old_version;
++
+ #ifdef CC_INTERP
+ int _result_index; // C++ interpreter needs for converting results to/from stack
+ #endif
+@@ -175,6 +179,23 @@ class Method : public Metadata {
+ int name_index() const { return constMethod()->name_index(); }
+ void set_name_index(int index) { constMethod()->set_name_index(index); }
+
++ Method* new_version() const { return _new_version; }
++ void set_new_version(Method* m) { _new_version = m; }
++ Method* newest_version() { return (_new_version == NULL) ? this : _new_version->newest_version(); }
++
++ Method* old_version() const { return _old_version; }
++ void set_old_version(Method* m) {
++ /*if (m == NULL) {
++ _old_version = NULL;
++ return;
++ }*/
++
++ assert(_old_version == NULL, "may only be set once");
++ assert(this->code_size() == m->code_size(), "must have same code length");
++ _old_version = m;
++ }
++ const Method* oldest_version() const { return (_old_version == NULL) ? this : _old_version->oldest_version(); }
++
+ // signature
+ Symbol* signature() const { return constants()->symbol_at(signature_index()); }
+ int signature_index() const { return constMethod()->signature_index(); }
+diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
+index ab24446..b16a9f3 100644
+--- a/src/share/vm/prims/jni.cpp
++++ b/src/share/vm/prims/jni.cpp
+@@ -406,6 +406,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR
+ }
+ Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
+ Handle(), &st, true,
++ KlassHandle(),
+ CHECK_NULL);
+
+ if (TraceClassResolution && k != NULL) {
+diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
+index a757e19..77c3be2 100644
+--- a/src/share/vm/prims/jvm.cpp
++++ b/src/share/vm/prims/jvm.cpp
+@@ -904,6 +904,7 @@ static jclass jvm_define_class_common(JNIEnv *env, const char *name,
+ Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
+ protection_domain, &st,
+ verify != 0,
++ KlassHandle(),
+ CHECK_NULL);
+
+ if (TraceClassResolution && k != NULL) {
+diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
+index 318fe4e..f8fb12b 100644
+--- a/src/share/vm/prims/jvmtiEnv.cpp
++++ b/src/share/vm/prims/jvmtiEnv.cpp
+@@ -42,6 +42,7 @@
+ #include "prims/jvmtiManageCapabilities.hpp"
+ #include "prims/jvmtiRawMonitor.hpp"
+ #include "prims/jvmtiRedefineClasses.hpp"
++#include "prims/jvmtiRedefineClasses2.hpp"
+ #include "prims/jvmtiTagMap.hpp"
+ #include "prims/jvmtiThreadState.inline.hpp"
+ #include "prims/jvmtiUtil.hpp"
+@@ -206,8 +207,10 @@ JvmtiEnv::GetClassLoaderClasses(jobject initiating_loader, jint* class_count_ptr
+ // is_modifiable_class_ptr - pre-checked for NULL
+ jvmtiError
+ JvmtiEnv::IsModifiableClass(oop k_mirror, jboolean* is_modifiable_class_ptr) {
+- *is_modifiable_class_ptr = VM_RedefineClasses::is_modifiable_class(k_mirror)?
+- JNI_TRUE : JNI_FALSE;
++ bool is_modifiable_class = AllowEnhancedClassRedefinition ?
++ VM_EnhancedRedefineClasses::is_modifiable_class(k_mirror) :
++ VM_RedefineClasses::is_modifiable_class(k_mirror);
++ *is_modifiable_class_ptr = is_modifiable_class ? JNI_TRUE : JNI_FALSE;
+ return JVMTI_ERROR_NONE;
+ } /* end IsModifiableClass */
+
+@@ -276,6 +279,11 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
+ }
+ class_definitions[index].klass = jcls;
+ }
++ if (AllowEnhancedClassRedefinition) {
++ VM_EnhancedRedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
++ VMThread::execute(&op);
++ return (op.check_error());
++ }
+ VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
+ VMThread::execute(&op);
+ return (op.check_error());
+@@ -287,6 +295,11 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
+ jvmtiError
+ JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
+ //TODO: add locking
++ if (AllowEnhancedClassRedefinition) {
++ VM_EnhancedRedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
++ VMThread::execute(&op);
++ return (op.check_error());
++ }
+ VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
+ VMThread::execute(&op);
+ return (op.check_error());
+diff --git a/src/share/vm/prims/jvmtiExport.hpp b/src/share/vm/prims/jvmtiExport.hpp
+index d2a7dec..f27a8d4 100644
+--- a/src/share/vm/prims/jvmtiExport.hpp
++++ b/src/share/vm/prims/jvmtiExport.hpp
+@@ -188,6 +188,7 @@ class JvmtiExport : public AllStatic {
+ // systems as needed to relax invariant checks.
+ static bool _has_redefined_a_class;
+ friend class VM_RedefineClasses;
++ friend class VM_EnhancedRedefineClasses;
+ inline static void set_has_redefined_a_class() {
+ JVMTI_ONLY(_has_redefined_a_class = true;)
+ }
+diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
+index ad90eeb..8834ad3 100644
+--- a/src/share/vm/prims/jvmtiImpl.cpp
++++ b/src/share/vm/prims/jvmtiImpl.cpp
+@@ -289,6 +289,11 @@ void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
+ Symbol* m_name = _method->name();
+ Symbol* m_signature = _method->signature();
+
++ // (DCEVM) Go through old versions of method
++ for (Method* m = _method->old_version(); m != NULL; m = m->old_version()) {
++ (m->*meth_act)(_bci);
++ }
++
+ // search previous versions if they exist
+ PreviousVersionWalker pvw(thread, (InstanceKlass *)ikh());
+ for (PreviousVersionNode * pv_node = pvw.next_previous_version();
+diff --git a/src/share/vm/prims/jvmtiRedefineClasses2.cpp b/src/share/vm/prims/jvmtiRedefineClasses2.cpp
+new file mode 100644
+index 0000000..d96a103
+--- /dev/null
++++ b/src/share/vm/prims/jvmtiRedefineClasses2.cpp
+@@ -0,0 +1,2015 @@
++/*
++ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * This code is free software; you can redistribute it and/or modify it
++ * under the terms of the GNU General Public License version 2 only, as
++ * published by the Free Software Foundation.
++ *
++ * This code is distributed in the hope that it will be useful, but WITHOUT
++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
++ * version 2 for more details (a copy is included in the LICENSE file that
++ * accompanied this code).
++ *
++ * You should have received a copy of the GNU General Public License version
++ * 2 along with this work; if not, write to the Free Software Foundation,
++ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
++ *
++ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
++ * or visit www.oracle.com if you need additional information or have any
++ * questions.
++ *
++ */
++
++#include "precompiled.hpp"
++#include "classfile/systemDictionary.hpp"
++#include "classfile/verifier.hpp"
++#include "code/codeCache.hpp"
++#include "interpreter/oopMapCache.hpp"
++#include "interpreter/rewriter.hpp"
++#include "memory/gcLocker.hpp"
++#include "memory/universe.inline.hpp"
++#include "memory/metaspaceShared.hpp"
++#include "oops/fieldStreams.hpp"
++#include "oops/klassVtable.hpp"
++#include "prims/jvmtiImpl.hpp"
++#include "prims/jvmtiRedefineClasses2.hpp"
++#include "prims/methodComparator.hpp"
++#include "prims/jvmtiClassFileReconstituter.hpp"
++#include "runtime/deoptimization.hpp"
++#include "runtime/relocator.hpp"
++#include "utilities/bitMap.inline.hpp"
++#include "compiler/compileBroker.hpp"
++#include "oops/instanceMirrorKlass.hpp"
++#include "utilities/pair.hpp"
++
++
++Array<Method*>* VM_EnhancedRedefineClasses::_old_methods = NULL;
++Array<Method*>* VM_EnhancedRedefineClasses::_new_methods = NULL;
++int* VM_EnhancedRedefineClasses::_matching_old_methods = NULL;
++int* VM_EnhancedRedefineClasses::_matching_new_methods = NULL;
++int* VM_EnhancedRedefineClasses::_deleted_methods = NULL;
++int* VM_EnhancedRedefineClasses::_added_methods = NULL;
++int VM_EnhancedRedefineClasses::_matching_methods_length = 0;
++int VM_EnhancedRedefineClasses::_deleted_methods_length = 0;
++int VM_EnhancedRedefineClasses::_added_methods_length = 0;
++GrowableArray<instanceKlassHandle>* VM_EnhancedRedefineClasses::_affected_klasses = NULL;
++
++
++// Holds the revision number of the current class redefinition
++int VM_EnhancedRedefineClasses::_revision_number = -1;
++
++VM_EnhancedRedefineClasses::VM_EnhancedRedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
++ : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
++ RC_TIMER_START(_timer_total);
++ _class_count = class_count;
++ _class_defs = class_defs;
++ _class_load_kind = class_load_kind;
++ _result = JVMTI_ERROR_NONE;
++}
++
++VM_EnhancedRedefineClasses::~VM_EnhancedRedefineClasses() {
++ RC_TIMER_STOP(_timer_total);
++}
++
++void VM_EnhancedRedefineClasses::swap_all_method_annotations(ConstMethod* old_method, ConstMethod* new_method) {
++ return; // FIXME-isd: swap annotations!
++
++ AnnotationArray* save;
++
++ save = old_method->method_annotations();
++ old_method->set_method_annotations(new_method->method_annotations());
++ new_method->set_method_annotations(save);
++
++ save = old_method->parameter_annotations();
++ old_method->set_parameter_annotations(new_method->parameter_annotations());
++ new_method->set_parameter_annotations(save);
++
++ save = old_method->default_annotations();
++ old_method->set_default_annotations(new_method->default_annotations());
++ new_method->set_default_annotations(save);
++
++ save = old_method->type_annotations();
++ old_method->set_type_annotations(new_method->type_annotations());
++ new_method->set_type_annotations(save);
++}
++
++void VM_EnhancedRedefineClasses::add_affected_klasses( Klass* klass )
++{
++ assert(!_affected_klasses->contains(klass), "must not occur more than once!");
++ assert(klass->new_version() == NULL, "Only last version is valid entry in system dictionary");
++
++ Klass* k = klass;
++
++ if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
++ _affected_klasses->append(klass);
++ return;
++ }
++
++ for (juint i = 0; i < k->super_depth(); i++) {
++ Klass* primary = k->primary_super_of_depth(i);
++ // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
++ if (primary == NULL) break;
++ if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
++ RC_TRACE(0x00000001, ("Found affected class: %s", k->name()->as_C_string()));
++ k->set_redefinition_flag(Klass::MarkedAsAffected);
++ _affected_klasses->append(klass);
++ return;
++ }
++ }
++
++ // Check secondary supers
++ int cnt = k->secondary_supers()->length();
++ for (int i = 0; i < cnt; i++) {
++ Klass* secondary = k->secondary_supers()->at(i);
++ if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
++ RC_TRACE(0x00000001, ("Found affected class: %s", k->name()->as_C_string()));
++ k->set_redefinition_flag(Klass::MarkedAsAffected);
++ _affected_klasses->append(klass);
++ return;
++ }
++ }
++}
++
++
++// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
++jvmtiError VM_EnhancedRedefineClasses::find_sorted_affected_classes() {
++
++ assert(_affected_klasses, "");
++ for (int i = 0; i < _class_count; i++) {
++ oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
++ instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_Klass(mirror));
++ klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
++ assert(klass_handle->new_version() == NULL, "Must be new class");
++ }
++
++ // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
++ SystemDictionary::classes_do(VM_EnhancedRedefineClasses::add_affected_klasses);
++ RC_TRACE(0x00000001, ("%d classes affected", _affected_klasses->length()));
++
++ // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
++ jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
++ if (RC_TRACE_ENABLED(0x00000001)) {
++ RC_TRACE(0x00000001, ("Redefine order: "));
++ for (int i = 0; i < _affected_klasses->length(); i++) {
++ RC_TRACE(0x00000001, ("%s", _affected_klasses->at(i)->name()->as_C_string()));
++ }
++ }
++
++ return result;
++}
++
++// Searches for the class bytes of the given class and returns them as a byte array.
++jvmtiError VM_EnhancedRedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
++
++ *not_changed = false;
++
++ // Search for the index in the redefinition array that corresponds to the current class
++ int j;
++ for (j=0; j<_class_count; j++) {
++ oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
++ Klass* the_class_oop = java_lang_Class::as_Klass(mirror);
++ if (the_class_oop == the_class()) {
++ break;
++ }
++ }
++
++ if (j == _class_count) {
++
++ *not_changed = true;
++
++ // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
++ // so the user did not specify a different bytecode for that class.
++
++ if (the_class->get_cached_class_file_bytes() == NULL) {
++ // not cached, we need to reconstitute the class file from VM representation
++ constantPoolHandle constants(Thread::current(), the_class->constants());
++ MonitorLockerEx ml(constants->lock()); // lock constant pool while we query it
++ //ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
++
++ JvmtiClassFileReconstituter reconstituter(the_class);
++ if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
++ return reconstituter.get_error();
++ }
++
++ *class_byte_count = (jint)reconstituter.class_file_size();
++ *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
++ } else {
++
++ // it is cached, get it from the cache
++ *class_byte_count = the_class->get_cached_class_file_len();
++ *class_bytes = the_class->get_cached_class_file_bytes();
++ }
++
++ } else {
++
++ // Redefine with bytecodes at index j
++ *class_bytes = _class_defs[j].class_bytes;
++ *class_byte_count = _class_defs[j].class_byte_count;
++ }
++
++ return JVMTI_ERROR_NONE;
++ }
++
++// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
++bool VM_EnhancedRedefineClasses::doit_prologue() {
++
++ _revision_number++;
++ RC_TRACE(0x00000001,
++ ("Redefinition with revision number %d started!", _revision_number));
++
++ assert(Thread::current()->is_Java_thread(), "must be Java thread");
++ RC_TIMER_START(_timer_prologue);
++
++ if (!check_arguments()) {
++ RC_TIMER_STOP(_timer_prologue);
++ return false;
++ }
++
++ // We first load new class versions in the prologue, because somewhere down the
++ // call chain it is required that the current thread is a Java thread.
++ _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
++
++ assert(_affected_klasses == NULL, "");
++ _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
++
++ _result = load_new_class_versions(Thread::current());
++
++ RC_TRACE(0x00000001,
++ ("Loaded new class versions!"));
++ if (_result != JVMTI_ERROR_NONE) {
++ RC_TRACE(0x00000001,
++ ("error occured: %d!", _result));
++ delete _new_classes;
++ _new_classes = NULL;
++ delete _affected_klasses;
++ _affected_klasses = NULL;
++ RC_TIMER_STOP(_timer_prologue);
++ return false;
++ }
++
++ VM_GC_Operation::doit_prologue();
++ RC_TIMER_STOP(_timer_prologue);
++
++ RC_TRACE(0x00000001, ("doit_prologue finished!"));
++ return true;
++}
++
++// Checks basic properties of the arguments of the redefinition command.
++jvmtiError VM_EnhancedRedefineClasses::check_arguments_error() {
++ if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
++ for (int i = 0; i < _class_count; i++) {
++ if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
++ if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
++ if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
++ }
++ return JVMTI_ERROR_NONE;
++ }
++
++// Returns false and sets an result error code if the redefinition should be aborted.
++bool VM_EnhancedRedefineClasses::check_arguments() {
++ jvmtiError error = check_arguments_error();
++ if (error != JVMTI_ERROR_NONE || _class_count == 0) {
++ _result = error;
++ return false;
++ }
++ return true;
++}
++
++jvmtiError VM_EnhancedRedefineClasses::check_exception() const {
++ Thread* THREAD = Thread::current();
++ if (HAS_PENDING_EXCEPTION) {
++
++ Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
++ RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'", ex_name->as_C_string()));
++ CLEAR_PENDING_EXCEPTION;
++
++ if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
++ return JVMTI_ERROR_UNSUPPORTED_VERSION;
++ } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
++ return JVMTI_ERROR_INVALID_CLASS_FORMAT;
++ } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
++ return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
++ } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
++ // The message will be "XXX (wrong name: YYY)"
++ return JVMTI_ERROR_NAMES_DONT_MATCH;
++ } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
++ return JVMTI_ERROR_OUT_OF_MEMORY;
++ } else {
++ // Just in case more exceptions can be thrown..
++ return JVMTI_ERROR_FAILS_VERIFICATION;
++ }
++ }
++
++ return JVMTI_ERROR_NONE;
++}
++
++// Loads all new class versions and stores the InstanceKlass handles in an array.
++jvmtiError VM_EnhancedRedefineClasses::load_new_class_versions(TRAPS) {
++
++ ResourceMark rm(THREAD);
++
++ RC_TRACE(0x00000001,
++ ("loading new class versions (%d)", _class_count));
++
++ // Retrieve an array of all classes that need to be redefined
++ jvmtiError err = find_sorted_affected_classes();
++ if (err != JVMTI_ERROR_NONE) {
++ RC_TRACE(0x00000001,
++ ("Error finding sorted affected classes: %d", (int)err));
++ return err;
++ }
++
++
++ JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
++
++ _max_redefinition_flags = Klass::NoRedefinition;
++ jvmtiError result = JVMTI_ERROR_NONE;
++
++ for (int i = 0; i < _affected_klasses->length(); i++) {
++ instanceKlassHandle the_class = _affected_klasses->at(i);
++
++ RC_TRACE(0x00000001,
++ ("Processing affected class %s (%d of %d)",
++ the_class->name()->as_C_string(),
++ i + 1,
++ _affected_klasses->length()));
++
++ the_class->link_class(THREAD);
++ result = check_exception();
++ if (result != JVMTI_ERROR_NONE) break;
++
++ // Find new class bytes
++ const unsigned char* class_bytes;
++ jint class_byte_count;
++ jvmtiError error;
++ jboolean not_changed;
++ if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
++ RC_TRACE_WITH_THREAD(0x00000002, THREAD,
++ ("Error finding class bytes: %d", (int)error));
++ result = error;
++ break;
++ }
++ assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
++
++
++ // Set redefined class handle in JvmtiThreadState class.
++ // This redefined class is sent to agent event handler for class file
++ // load hook event.
++ state->set_class_being_redefined(&the_class, _class_load_kind);
++
++ RC_TIMER_STOP(_timer_prologue);
++ RC_TIMER_START(_timer_class_loading);
++
++ // Parse the stream.
++ Handle the_class_loader(THREAD, the_class->class_loader());
++ Handle protection_domain(THREAD, the_class->protection_domain());
++ ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_EhnancedRedefineClasses__");
++
++ Klass* klass =
++ SystemDictionary::resolve_from_stream(
++ the_class->name(),
++ the_class_loader,
++ protection_domain,
++ &st,
++ true,
++ the_class,
++ THREAD);
++ instanceKlassHandle new_class(THREAD, klass);
++
++ RC_TIMER_STOP(_timer_class_loading);
++ RC_TIMER_START(_timer_prologue);
++
++ // Clear class_being_redefined just to be sure.
++ state->clear_class_being_redefined();
++
++ result = check_exception();
++ if (result != JVMTI_ERROR_NONE) break;
++
++ not_changed = false;
++
++#ifdef ASSERT
++
++ assert(new_class() != NULL, "Class could not be loaded!");
++ assert(new_class() != the_class(), "must be different");
++ assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
++
++
++ Array<Klass*>* k_interfaces = new_class->local_interfaces();
++ for (int j = 0; j < k_interfaces->length(); j++) {
++ assert(k_interfaces->at(j)->is_newest_version(), "just checking");
++ }
++
++ if (!THREAD->is_Compiler_thread()) {
++ RC_TRACE(0x00000001, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT,
++ the_class->name()->as_C_string(),
++ (intptr_t) (oopDesc*) the_class->class_loader(),
++ (intptr_t) (oopDesc*) the_class->protection_domain()));
++ // If we are on the compiler thread, we must not try to resolve a class.
++ Klass* systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
++
++ if (systemLookup != NULL) {
++ assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
++ Klass *subklass = new_class()->subklass();
++ while (subklass != NULL) {
++ assert(subklass->new_version() == NULL, "Most recent version of class!");
++ subklass = subklass->next_sibling();
++ }
++ } else {
++ // This can happen for reflection generated classes.. ?
++ CLEAR_PENDING_EXCEPTION;
++ }
++ }
++
++#endif
++
++ if (RC_TRACE_ENABLED(0x00000001)) {
++ if (new_class->layout_helper() != the_class->layout_helper()) {
++ RC_TRACE(0x00000001,
++ ("Instance size change for class %s: new=%d old=%d",
++ new_class->name()->as_C_string(),
++ new_class->layout_helper(),
++ the_class->layout_helper()));
++ }
++ }
++
++ // Set the new version of the class
++ new_class->set_revision_number(_revision_number);
++ new_class->set_redefinition_index(i);
++ the_class->set_new_version(new_class());
++ _new_classes->append(new_class);
++
++ assert(new_class->new_version() == NULL, "");
++
++ int redefinition_flags = Klass::NoRedefinition;
++
++ if (not_changed) {
++ redefinition_flags = Klass::NoRedefinition;
++ } else {
++ redefinition_flags = calculate_redefinition_flags(new_class);
++ if (redefinition_flags >= Klass::RemoveSuperType) {
++ result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
++ break;
++ }
++ }
++
++ if (new_class->super() != NULL) {
++ redefinition_flags = redefinition_flags | new_class->super()->redefinition_flags();
++ }
++
++ for (int j = 0; j<new_class->local_interfaces()->length(); j++) {
++ redefinition_flags = redefinition_flags | (new_class->local_interfaces()->at(j))->redefinition_flags();
++ }
++
++ new_class->set_redefinition_flags(redefinition_flags);
++
++ _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
++
++ if ((redefinition_flags & Klass::ModifyInstances) != 0) {
++ // TODO: Check if watch access flags of static fields are updated correctly.
++ calculate_instance_update_information(_new_classes->at(i)());
++ } else {
++ // Fields were not changed, transfer special flags only
++ assert(new_class->layout_helper() >> 1 == new_class->old_version()->layout_helper() >> 1, "must be equal");
++ assert(new_class->fields()->length() == InstanceKlass::cast(new_class->old_version())->fields()->length(), "must be equal");
++
++ JavaFieldStream old_fs(the_class);
++ JavaFieldStream new_fs(new_class);
++ for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
++ AccessFlags flags = new_fs.access_flags();
++ flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
++ flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
++ new_fs.set_access_flags(flags);
++ }
++ }
++
++ if (RC_TRACE_ENABLED(0x00000001)) {
++ RC_TRACE(0x00000001,
++ ("Super class is %s", new_class->super()->name()->as_C_string()));
++ }
++
++#ifdef ASSERT
++ assert(new_class->super() == NULL || new_class->super()->new_version() == NULL, "Super klass must be newest version!");
++
++ the_class->vtable()->verify(tty);
++ new_class->vtable()->verify(tty);
++#endif
++
++ if (i == _affected_klasses->length() - 1) {
++ // This was the last class processed => check if additional classes have been loaded in the meantime
++ for (int j = 0; j<_affected_klasses->length(); j++) {
++
++ Klass* initial_klass = _affected_klasses->at(j)();
++ Klass *initial_subklass = initial_klass->subklass();
++ Klass *cur_klass = initial_subklass;
++ while(cur_klass != NULL) {
++
++ if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
++ instanceKlassHandle handle(THREAD, cur_klass);
++ if (!_affected_klasses->contains(handle)) {
++
++ int k = i + 1;
++ for (; k<_affected_klasses->length(); k++) {
++ if (_affected_klasses->at(k)->is_subtype_of(cur_klass)) {
++ break;
++ }
++ }
++ _affected_klasses->insert_before(k, handle);
++ RC_TRACE(0x00000001,
++ ("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string()));
++ }
++ }
++
++ cur_klass = cur_klass->next_sibling();
++ }
++ }
++
++ int new_count = _affected_klasses->length() - 1 - i;
++ if (new_count != 0) {
++ RC_TRACE(0x00000001,
++ ("Found new number of affected classes: %d", new_count));
++ }
++ }
++ }
++
++ if (result != JVMTI_ERROR_NONE) {
++ rollback();
++ return result;
++ }
++
++ RC_TIMER_STOP(_timer_prologue);
++ RC_TIMER_START(_timer_class_linking);
++ // Link and verify new classes _after_ all classes have been updated in the system dictionary!
++ for (int i=0; i<_affected_klasses->length(); i++) {
++ instanceKlassHandle the_class = _affected_klasses->at(i);
++ instanceKlassHandle new_class(the_class->new_version());
++
++ RC_TRACE(0x00000001,
++ ("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string()));
++ new_class->link_class(THREAD);
++
++ result = check_exception();
++ if (result != JVMTI_ERROR_NONE) break;
++ }
++ RC_TIMER_STOP(_timer_class_linking);
++ RC_TIMER_START(_timer_prologue);
++
++ if (result != JVMTI_ERROR_NONE) {
++ rollback();
++ return result;
++ }
++
++ RC_TRACE(0x00000001, ("All classes loaded!"));
++
++#ifdef ASSERT
++ for (int i=0; i<_affected_klasses->length(); i++) {
++ instanceKlassHandle the_class = _affected_klasses->at(i);
++ assert(the_class->new_version() != NULL, "Must have been redefined");
++ instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
++ assert(new_version->new_version() == NULL, "Must be newest version");
++
++ if (!(new_version->super() == NULL || new_version->super()->new_version() == NULL)) {
++ new_version()->print();
++ new_version->super()->print();
++ }
++ assert(new_version->super() == NULL || new_version->super()->new_version() == NULL, "Super class must be newest version");
++ }
++
++ SystemDictionary::classes_do(check_class, THREAD);
++
++#endif
++
++ RC_TRACE(0x00000001, ("Finished verification!"));
++ return JVMTI_ERROR_NONE;
++}
++
++int VM_EnhancedRedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
++
++ int result = Klass::NoRedefinition;
++ RC_TRACE(0x00000001,
++ ("Comparing different class versions of class %s", new_class->name()->as_C_string()));
++
++ assert(new_class->old_version() != NULL, "must have old version");
++ instanceKlassHandle the_class(new_class->old_version());
++
++ // Check whether class is in the error init state.
++ if (the_class->is_in_error_state()) {
++ // TBD #5057930: special error code is needed in 1.6
++ //result = Klass::union_redefinition_level(result, Klass::Invalid);
++ }
++
++ int i;
++
++ //////////////////////////////////////////////////////////////////////////////////////////////////////////
++ // Check superclasses
++ assert(new_class->super() == NULL || new_class->super()->is_newest_version(), "");
++ if (the_class->super() != new_class->super()) {
++ // Super class changed
++ Klass* cur_klass = the_class->super();
++ while (cur_klass != NULL) {
++ if (!new_class->is_subclass_of(cur_klass->newest_version())) {
++ RC_TRACE(0x00000001,
++ ("Removed super class %s", cur_klass->name()->as_C_string()));
++ result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
++
++ if (!cur_klass->has_subtype_changed()) {
++ RC_TRACE(0x00000001,
++ ("Subtype changed of class %s", cur_klass->name()->as_C_string()));
++ cur_klass->set_subtype_changed(true);
++ }
++ }
++
++ cur_klass = cur_klass->super();
++ }
++
++ cur_klass = new_class->super();
++ while (cur_klass != NULL) {
++ if (!the_class->is_subclass_of(cur_klass->old_version())) {
++ RC_TRACE(0x00000001,
++ ("Added super class %s", cur_klass->name()->as_C_string()));
++ result = result | Klass::ModifyClass | Klass::ModifyInstances;
++ }
++ cur_klass = cur_klass->super();
++ }
++ }
++
++ //////////////////////////////////////////////////////////////////////////////////////////////////////////
++ // Check interfaces
++
++ // Interfaces removed?
++ Array<Klass*>* old_interfaces = the_class->transitive_interfaces();
++ for (i = 0; i<old_interfaces->length(); i++) {
++ instanceKlassHandle old_interface(old_interfaces->at(i));
++ if (!new_class->implements_interface_any_version(old_interface())) {
++ result = result | Klass::RemoveSuperType | Klass::ModifyClass;
++ RC_TRACE(0x00000001,
++ ("Removed interface %s", old_interface->name()->as_C_string()));
++
++ if (!old_interface->has_subtype_changed()) {
++ RC_TRACE(0x00000001,
++ ("Subtype changed of interface %s", old_interface->name()->as_C_string()));
++ old_interface->set_subtype_changed(true);
++ }
++ }
++ }
++
++ // Interfaces added?
++ Array<Klass*>* new_interfaces = new_class->transitive_interfaces();
++ for (i = 0; i<new_interfaces->length(); i++) {
++ if (!the_class->implements_interface_any_version(new_interfaces->at(i))) {
++ result = result | Klass::ModifyClass;
++ RC_TRACE(0x00000001,
++ ("Added interface %s", new_interfaces->at(i)->name()->as_C_string()));
++ }
++ }
++
++
++ // Check whether class modifiers are the same.
++ jushort old_flags = (jushort) the_class->access_flags().get_flags();
++ jushort new_flags = (jushort) new_class->access_flags().get_flags();
++ if (old_flags != new_flags) {
++ // TODO Can this have any effects?
++ }
++
++ // Check if the number, names, types and order of fields declared in these classes
++ // are the same.
++ JavaFieldStream old_fs(the_class);
++ JavaFieldStream new_fs(new_class);
++ for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
++ // access
++ old_flags = old_fs.access_flags().as_short();
++ new_flags = new_fs.access_flags().as_short();
++ if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
++ // TODO can this have any effect?
++ }
++ // offset
++ if (old_fs.offset() != new_fs.offset()) {
++ result = result | Klass::ModifyInstances;
++ }
++ // name and signature
++ Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
++ Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
++ Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
++ Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
++ if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
++ result = result | Klass::ModifyInstances;
++ }
++ }
++
++ // If both streams aren't done then we have a differing number of
++ // fields.
++ if (!old_fs.done() || !new_fs.done()) {
++ result = result | Klass::ModifyInstances;
++ }
++
++ // Do a parallel walk through the old and new methods. Detect
++ // cases where they match (exist in both), have been added in
++ // the new methods, or have been deleted (exist only in the
++ // old methods). The class file parser places methods in order
++ // by method name, but does not order overloaded methods by
++ // signature. In order to determine what fate befell the methods,
++ // this code places the overloaded new methods that have matching
++ // old methods in the same order as the old methods and places
++ // new overloaded methods at the end of overloaded methods of
++ // that name. The code for this order normalization is adapted
++ // from the algorithm used in InstanceKlass::find_method().
++ // Since we are swapping out of order entries as we find them,
++ // we only have to search forward through the overloaded methods.
++ // Methods which are added and have the same name as an existing
++ // method (but different signature) will be put at the end of
++ // the methods with that name, and the name mismatch code will
++ // handle them.
++ Array<Method*>* k_old_methods(the_class->methods()); // FIXME-isd: handles???
++ Array<Method*>* k_new_methods(new_class->methods());
++ int n_old_methods = k_old_methods->length();
++ int n_new_methods = k_new_methods->length();
++
++ int ni = 0;
++ int oi = 0;
++ while (true) {
++ Method* k_old_method;
++ Method* k_new_method;
++ enum { matched, added, deleted, undetermined } method_was = undetermined;
++
++ if (oi >= n_old_methods) {
++ if (ni >= n_new_methods) {
++ break; // we've looked at everything, done
++ }
++ // New method at the end
++ k_new_method = k_new_methods->at(ni);
++ method_was = added;
++ } else if (ni >= n_new_methods) {
++ // Old method, at the end, is deleted
++ k_old_method = k_old_methods->at(oi);
++ method_was = deleted;
++ } else {
++ // There are more methods in both the old and new lists
++ k_old_method = k_old_methods->at(oi);
++ k_new_method = k_new_methods->at(ni);
++ if (k_old_method->name() != k_new_method->name()) {
++ // Methods are sorted by method name, so a mismatch means added
++ // or deleted
++ if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
++ method_was = added;
++ } else {
++ method_was = deleted;
++ }
++ } else if (k_old_method->signature() == k_new_method->signature()) {
++ // Both the name and signature match
++ method_was = matched;
++ } else {
++ // The name matches, but the signature doesn't, which means we have to
++ // search forward through the new overloaded methods.
++ int nj; // outside the loop for post-loop check
++ for (nj = ni + 1; nj < n_new_methods; nj++) {
++ Method* m = k_new_methods->at(nj);
++ if (k_old_method->name() != m->name()) {
++ // reached another method name so no more overloaded methods
++ method_was = deleted;
++ break;
++ }
++ if (k_old_method->signature() == m->signature()) {
++ // found a match so swap the methods
++ k_new_methods->at_put(ni, m);
++ k_new_methods->at_put(nj, k_new_method);
++ k_new_method = m;
++ method_was = matched;
++ break;
++ }
++ }
++
++ if (nj >= n_new_methods) {
++ // reached the end without a match; so method was deleted
++ method_was = deleted;
++ }
++ }
++ }
++
++ switch (method_was) {
++ case matched:
++ // methods match, be sure modifiers do too
++ old_flags = (jushort) k_old_method->access_flags().get_flags();
++ new_flags = (jushort) k_new_method->access_flags().get_flags();
++ if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
++ // TODO Can this have any effects? Probably yes on vtables?
++ result = result | Klass::ModifyClass;
++ }
++ {
++ u2 new_num = k_new_method->method_idnum();
++ u2 old_num = k_old_method->method_idnum();
++ if (new_num != old_num) {
++ Method* idnum_owner = new_class->method_with_idnum(old_num);
++ if (idnum_owner != NULL) {
++ // There is already a method assigned this idnum -- switch them
++ idnum_owner->set_method_idnum(new_num);
++ }
++ k_new_method->set_method_idnum(old_num);
++ RC_TRACE(0x00008000,
++ ("swapping idnum of new and old method %d / %d!", new_num, old_num);
++ swap_all_method_annotations(k_old_method->constMethod(), k_new_method->constMethod()));
++ }
++ }
++ RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
++ k_new_method->name_and_sig_as_C_string(), ni,
++ k_old_method->name_and_sig_as_C_string(), oi));
++ // advance to next pair of methods
++ ++oi;
++ ++ni;
++ break;
++ case added:
++ // method added, see if it is OK
++ new_flags = (jushort) k_new_method->access_flags().get_flags();
++ if ((new_flags & JVM_ACC_PRIVATE) == 0
++ // hack: private should be treated as final, but alas
++ || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0) {
++ // new methods must be private
++ result = result | Klass::ModifyClass;
++ }
++ {
++ u2 num = the_class->next_method_idnum();
++ if (num == ConstMethod::UNSET_IDNUM) {
++ // cannot add any more methods
++ result = result | Klass::ModifyClass;
++ }
++ u2 new_num = k_new_method->method_idnum();
++ Method* idnum_owner = new_class->method_with_idnum(num);
++ if (idnum_owner != NULL) {
++ // There is already a method assigned this idnum -- switch them
++ idnum_owner->set_method_idnum(new_num);
++ }
++ k_new_method->set_method_idnum(num);
++ swap_all_method_annotations(k_old_method->constMethod(), k_new_method->constMethod());
++ }
++ RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
++ k_new_method->name_and_sig_as_C_string(), ni));
++ ++ni; // advance to next new method
++ break;
++ case deleted:
++ // method deleted, see if it is OK
++ old_flags = (jushort) k_old_method->access_flags().get_flags();
++ if ((old_flags & JVM_ACC_PRIVATE) == 0
++ // hack: private should be treated as final, but alas
++ || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
++ ) {
++ // deleted methods must be private
++ result = result | Klass::ModifyClass;
++ }
++ RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
++ k_old_method->name_and_sig_as_C_string(), oi));
++ ++oi; // advance to next old method
++ break;
++ default:
++ ShouldNotReachHere();
++ }
++ }
++
++ if (new_class()->size() != new_class->old_version()->size()) {
++ result |= Klass::ModifyClassSize;
++ }
++
++ if (new_class->size_helper() != ((InstanceKlass*)(new_class->old_version()))->size_helper()) {
++ result |= Klass::ModifyInstanceSize;
++ }
++
++ // TODO Check method bodies to be able to return NoChange?
++ return result;
++}
++
++void VM_EnhancedRedefineClasses::calculate_instance_update_information(Klass* new_version) {
++
++ class CalculateFieldUpdates : public FieldClosure {
++
++ private:
++ InstanceKlass* _old_ik;
++ GrowableArray<int> _update_info;
++ int _position;
++ bool _copy_backwards;
++
++ public:
++
++ bool does_copy_backwards() {
++ return _copy_backwards;
++ }
++
++ CalculateFieldUpdates(InstanceKlass* old_ik) :
++ _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
++ _update_info.append(_position);
++ _update_info.append(0);
++ }
++
++ GrowableArray<int> &finish() {
++ _update_info.append(0);
++ return _update_info;
++ }
++
++ void do_field(fieldDescriptor* fd) {
++ int alignment = fd->offset() - _position;
++ if (alignment > 0) {
++ // This field was aligned, so we need to make sure that we fill the gap
++ fill(alignment);
++ }
++
++ assert(_position == fd->offset(), "must be correct offset!");
++
++ fieldDescriptor old_fd;
++ if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
++ // Found field in the old class, copy
++ copy(old_fd.offset(), type2aelembytes(fd->field_type()));
++
++ if (old_fd.offset() < fd->offset()) {
++ _copy_backwards = true;
++ }
++
++ // Transfer special flags
++ fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
++ fd->set_is_field_access_watched(old_fd.is_field_access_watched());
++ } else {
++ // New field, fill
++ fill(type2aelembytes(fd->field_type()));
++ }
++ }
++
++ private:
++
++ void fill(int size) {
++ if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
++ (*_update_info.adr_at(_update_info.length() - 1)) -= size;
++ } else {
++ _update_info.append(-size);
++ }
++ _position += size;
++ }
++
++ void copy(int offset, int size) {
++ int prev_end = -1;
++ if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
++ prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
++ }
++
++ if (prev_end == offset) {
++ (*_update_info.adr_at(_update_info.length() - 2)) += size;
++ } else {
++ _update_info.append(size);
++ _update_info.append(offset);
++ }
++
++ _position += size;
++ }
++ };
++
++ InstanceKlass* ik = InstanceKlass::cast(new_version);
++ InstanceKlass* old_ik = InstanceKlass::cast(new_version->old_version());
++ CalculateFieldUpdates cl(old_ik);
++ ik->do_nonstatic_fields(&cl);
++
++ GrowableArray<int> result = cl.finish();
++ ik->store_update_information(result);
++ ik->set_copying_backwards(cl.does_copy_backwards());
++
++
++ if (RC_TRACE_ENABLED(0x00000001)) {
++ RC_TRACE(0x00000001, ("Instance update information for %s:", new_version->name()->as_C_string()));
++ if (cl.does_copy_backwards()) {
++ RC_TRACE(0x00000001, ("\tDoes copy backwards!"));
++ }
++ for (int i=0; i<result.length(); i++) {
++ int curNum = result.at(i);
++ if (curNum < 0) {
++ RC_TRACE(0x00000001, ("\t%d CLEAN", curNum));
++ } else if (curNum > 0) {
++ RC_TRACE(0x00000001, ("\t%d COPY from %d", curNum, result.at(i + 1)));
++ i++;
++ } else {
++ RC_TRACE(0x00000001, ("\tEND"));
++ }
++ }
++ }
++}
++
++void VM_EnhancedRedefineClasses::rollback() {
++ RC_TRACE(0x00000001, ("Rolling back redefinition!"));
++ SystemDictionary::rollback_redefinition();
++
++ for (int i=0; i<_new_classes->length(); i++) {
++ SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
++ }
++
++ for (int i=0; i<_new_classes->length(); i++) {
++ instanceKlassHandle new_class = _new_classes->at(i);
++ new_class->set_redefining(false);
++ new_class->old_version()->set_new_version(NULL);
++ new_class->set_old_version(NULL);
++ }
++
++}
++
++void VM_EnhancedRedefineClasses::swap_marks(oop first, oop second) {
++ markOop first_mark = first->mark();
++ markOop second_mark = second->mark();
++ first->set_mark(second_mark);
++ second->set_mark(first_mark);
++}
++
++class FieldCopier : public FieldClosure {
++ public:
++ void do_field(fieldDescriptor* fd) {
++ InstanceKlass* cur = InstanceKlass::cast(fd->field_holder());
++ oop cur_oop = cur->java_mirror();
++
++ InstanceKlass* old = InstanceKlass::cast(cur->old_version());
++ oop old_oop = old->java_mirror();
++
++ fieldDescriptor result;
++ bool found = old->find_local_field(fd->name(), fd->signature(), &result);
++ if (found && result.is_static()) {
++ RC_TRACE(0x00000001, ("Copying static field value for field %s old_offset=%d new_offset=%d",
++ fd->name()->as_C_string(), result.offset(), fd->offset()));
++ memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
++ old_oop->obj_field_addr<HeapWord>(result.offset()),
++ type2aelembytes(fd->field_type()));
++
++ // Static fields may have references to java.lang.Class
++ if (fd->field_type() == T_OBJECT) {
++ oop oop = cur_oop->obj_field(fd->offset());
++ if (oop != NULL && oop->is_instanceMirror()) {
++ Klass* klass = java_lang_Class::as_Klass(oop);
++ if (klass != NULL && klass->oop_is_instance()) {
++ assert(oop == InstanceKlass::cast(klass)->java_mirror(), "just checking");
++ if (klass->new_version() != NULL) {
++ oop = InstanceKlass::cast(klass->new_version())->java_mirror();
++ cur_oop->obj_field_put(fd->offset(), oop);
++ }
++ }
++ }
++ }
++ }
++ }
++};
++
++void VM_EnhancedRedefineClasses::mark_as_scavengable(nmethod* nm) {
++ if (!nm->on_scavenge_root_list()) {
++ CodeCache::add_scavenge_root_nmethod(nm);
++ }
++}
++
++struct StoreBarrier {
++ template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
++};
++
++struct StoreNoBarrier {
++ template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
++};
++
++template <class S>
++class ChangePointersOopClosure : public ExtendedOopClosure {
++ // Forward pointers to InstanceKlass and mirror class to new versions
++ template <class T>
++ inline void do_oop_work(T* p) {
++ oop oop = oopDesc::load_decode_heap_oop(p);
++ if (oop == NULL) {
++ return;
++ }
++ if (oop->is_instanceMirror()) {
++ Klass* klass = java_lang_Class::as_Klass(oop);
++ if (klass != NULL && klass->oop_is_instance()) {
++ assert(oop == InstanceKlass::cast(klass)->java_mirror(), "just checking");
++ if (klass->new_version() != NULL) {
++ oop = InstanceKlass::cast(klass->new_version())->java_mirror();
++ S::oop_store(p, oop);
++ }
++ }
++ }
++ }
++
++ virtual void do_oop(oop* o) {
++ do_oop_work(o);
++ }
++
++ virtual void do_oop(narrowOop* o) {
++ do_oop_work(o);
++ }
++};
++
++void VM_EnhancedRedefineClasses::doit() {
++
++ Thread *thread = Thread::current();
++
++ assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
++
++ if (UseSharedSpaces) {
++ // Sharing is enabled so we remap the shared readonly space to
++ // shared readwrite, private just in case we need to redefine
++ // a shared class. We do the remap during the doit() phase of
++ // the safepoint to be safer.
++ if (!MetaspaceShared::remap_shared_readonly_as_readwrite()) {
++ RC_TRACE(0x00000001,
++ ("failed to remap shared readonly space to readwrite, private"));
++ _result = JVMTI_ERROR_INTERNAL;
++ return;
++ }
++ }
++
++ RC_TIMER_START(_timer_prepare_redefinition);
++ for (int i = 0; i < _new_classes->length(); i++) {
++ redefine_single_class(_new_classes->at(i), thread);
++ }
++
++ // Deoptimize all compiled code that depends on this class
++ flush_dependent_code(instanceKlassHandle(Thread::current(), (Klass*)NULL), Thread::current());
++
++ // Adjust constantpool caches and vtables for all classes
++ // that reference methods of the evolved class.
++ SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
++
++ RC_TIMER_STOP(_timer_prepare_redefinition);
++ RC_TIMER_START(_timer_heap_iteration);
++
++ class ChangePointersObjectClosure : public ObjectClosure {
++
++ private:
++
++ OopClosure *_closure;
++ bool _needs_instance_update;
++ oop _tmp_obj;
++ int _tmp_obj_size;
++
++ public:
++ ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
++
++ bool needs_instance_update() {
++ return _needs_instance_update;
++ }
++
++ void copy_to_tmp(oop o) {
++ int size = o->size();
++ if (_tmp_obj_size < size) {
++ _tmp_obj_size = size;
++ _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
++ }
++ Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
++ }
++
++ virtual void do_object(oop obj) {
++ // FIXME: if (obj->is_instanceKlass()) return;
++ if (obj->is_instanceMirror()) {
++ // static fields may have references to old java.lang.Class instances, update them
++ // at the same time, we don't want to update other oops in the java.lang.Class
++ // Causes SIGSEGV?
++ //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
++ } else {
++ obj->oop_iterate_no_header(_closure);
++ }
++
++ if (obj->klass()->new_version() != NULL) {
++ Klass* new_klass = obj->klass()->new_version();
++ /* FIXME: if (obj->is_perm()) {
++ _needs_instance_update = true;
++ } else */if(new_klass->update_information() != NULL) {
++ int size_diff = obj->size() - obj->size_given_klass(new_klass);
++
++ // Either new size is bigger or gap is to small to be filled
++ if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
++ // We need an instance update => set back to old klass
++ _needs_instance_update = true;
++ } else {
++ oop src = obj;
++ if (new_klass->is_copying_backwards()) {
++ copy_to_tmp(obj);
++ src = _tmp_obj;
++ }
++ src->set_klass(obj->klass()->new_version());
++ MarkSweep::update_fields(obj, src, new_klass->update_information());
++
++ if (size_diff > 0) {
++ HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
++ CollectedHeap::fill_with_object(dead_space, size_diff);
++ }
++ }
++ } else {
++ obj->set_klass(obj->klass()->new_version());
++ }
++ }
++ }
++ };
++
++ ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
++ ChangePointersOopClosure<StoreBarrier> oopClosure;
++ ChangePointersObjectClosure objectClosure(&oopClosure);
++
++ RC_TRACE(0x00000001, ("Before updating instances"));
++ {
++ // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
++ // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
++ // mark such nmethod's as "scavengable".
++ // For now, mark all nmethod's as scavengable that are not scavengable already
++ if (ScavengeRootsInCode) {
++ CodeCache::nmethods_do(mark_as_scavengable);
++ }
++
++ SharedHeap::heap()->gc_prologue(true);
++ Universe::heap()->object_iterate(&objectClosure);
++ Universe::root_oops_do(&oopClosureNoBarrier);
++ SharedHeap::heap()->gc_epilogue(false);
++ }
++ RC_TRACE(0x00000001, ("After updating instances"));
++
++ for (int i = 0; i < _new_classes->length(); i++) {
++ InstanceKlass* cur = InstanceKlass::cast(_new_classes->at(i)());
++ InstanceKlass* old = InstanceKlass::cast(cur->old_version());
++
++ // Swap marks to have same hashcodes
++ markOop cur_mark = cur->prototype_header();
++ markOop old_mark = old->prototype_header();
++ cur->set_prototype_header(old_mark);
++ old->set_prototype_header(cur_mark);
++
++ //swap_marks(cur, old);
++ swap_marks(cur->java_mirror(), old->java_mirror());
++
++ // Revert pool holder for old version of klass (it was updated by one of ours closure!)
++ old->constants()->set_pool_holder(old);
++
++ Klass* array_klasses = old->array_klasses();
++ if (array_klasses != NULL) {
++ assert(cur->array_klasses() == NULL, "just checking");
++
++ // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
++ // Also, set array klasses element klass.
++ cur->set_array_klasses(array_klasses);
++ ObjArrayKlass::cast(array_klasses)->set_element_klass(cur);
++ }
++
++ // Initialize the new class! Special static initialization that does not execute the
++ // static constructor but copies static field values from the old class if name
++ // and signature of a static field match.
++ FieldCopier copier;
++ cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
++ //java_lang_Class::set_klass(old->java_mirror(), cur); // FIXME-isd: is that correct?
++ //FIXME-isd: do we need this: ??? old->set_java_mirror(cur->java_mirror());
++
++ // Transfer init state
++ InstanceKlass::ClassState state = old->init_state();
++ if (state > InstanceKlass::linked) {
++ cur->set_init_state(state);
++ }
++ }
++
++ RC_TIMER_STOP(_timer_heap_iteration);
++ RC_TIMER_START(_timer_redefinition);
++ if (objectClosure.needs_instance_update()) {
++ // Do a full garbage collection to update the instance sizes accordingly
++ RC_TRACE(0x00000001, ("Before performing full GC!"));
++ Universe::set_redefining_gc_run(true);
++ notify_gc_begin(true);
++ Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
++ notify_gc_end();
++ Universe::set_redefining_gc_run(false);
++ RC_TRACE(0x00000001, ("GC done!"));
++ }
++
++ // Unmark Klass*s as "redefining"
++ for (int i=0; i<_new_classes->length(); i++) {
++ Klass* cur_klass = _new_classes->at(i)();
++ InstanceKlass* cur = (InstanceKlass*)cur_klass;
++ cur->set_redefining(false);
++ cur->clear_update_information();
++ }
++
++ // Disable any dependent concurrent compilations
++ SystemDictionary::notice_modification();
++
++ // Set flag indicating that some invariants are no longer true.
++ // See jvmtiExport.hpp for detailed explanation.
++ JvmtiExport::set_has_redefined_a_class();
++
++ // Clean up caches in the compiler interface and compiler threads
++ ciObjectFactory::resort_shared_ci_metadata();
++
++#ifdef ASSERT
++
++ // Universe::verify();
++ // JNIHandles::verify();
++
++ SystemDictionary::classes_do(check_class, thread);
++#endif
++
++ RC_TIMER_STOP(_timer_redefinition);
++
++ if (TraceRedefineClasses > 0) {
++ tty->flush();
++ }
++}
++
++void VM_EnhancedRedefineClasses::doit_epilogue() {
++
++ RC_TIMER_START(_timer_vm_op_epilogue);
++
++ ResourceMark mark;
++
++ VM_GC_Operation::doit_epilogue();
++ RC_TRACE(0x00000001, ("GC Operation epilogue finished!"));
++
++ // Free the array of scratch classes
++ delete _new_classes;
++ _new_classes = NULL;
++
++ // Free the array of affected classes
++ delete _affected_klasses;
++ _affected_klasses = NULL;
++
++ RC_TRACE(0x00000001, ("Redefinition finished!"));
++
++ RC_TIMER_STOP(_timer_vm_op_epilogue);
++}
++
++bool VM_EnhancedRedefineClasses::is_modifiable_class(oop klass_mirror) {
++ // classes for primitives cannot be redefined
++ if (java_lang_Class::is_primitive(klass_mirror)) {
++ return false;
++ }
++ Klass* klass = java_lang_Class::as_Klass(klass_mirror);
++ // classes for arrays cannot be redefined
++ if (klass == NULL || !klass->oop_is_instance()) {
++ return false;
++ }
++ return true;
++}
++
++#ifdef ASSERT
++
++void VM_EnhancedRedefineClasses::verify_classes(Klass* k_oop_latest, oop initiating_loader, TRAPS) {
++ Klass* k_oop = k_oop_latest;
++ while (k_oop != NULL) {
++
++ instanceKlassHandle k_handle(THREAD, k_oop);
++ Verifier::verify(k_handle, Verifier::ThrowException, true, THREAD);
++ k_oop = k_oop->old_version();
++ }
++}
++
++#endif
++
++// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
++// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
++// do that, they assume that cache entry is resolved already.
++void VM_EnhancedRedefineClasses::unpatch_bytecode(Method* method) {
++ RawBytecodeStream bcs(method);
++ Bytecodes::Code code;
++ Bytecodes::Code java_code;
++ while (!bcs.is_last_bytecode()) {
++ code = bcs.raw_next();
++ address bcp = bcs.bcp();
++
++ if (code == Bytecodes::_breakpoint) {
++ int bci = method->bci_from(bcp);
++ code = method->orig_bytecode_at(bci);
++ java_code = Bytecodes::java_code(code);
++ if (code != java_code &&
++ (java_code == Bytecodes::_getfield ||
++ java_code == Bytecodes::_putfield ||
++ java_code == Bytecodes::_aload_0)) {
++ // Let breakpoint table handling unpatch bytecode
++ method->set_orig_bytecode_at(bci, java_code);
++ }
++ } else {
++ java_code = Bytecodes::java_code(code);
++ if (code != java_code &&
++ (java_code == Bytecodes::_getfield ||
++ java_code == Bytecodes::_putfield ||
++ java_code == Bytecodes::_aload_0)) {
++ *bcp = java_code;
++ }
++ }
++
++ // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
++ if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
++ Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
++ assert(code2 == Bytecodes::_fast_igetfield ||
++ code2 == Bytecodes::_fast_agetfield ||
++ code2 == Bytecodes::_fast_fgetfield, "");
++ *(bcp + 1) = Bytecodes::java_code(code2);
++ }
++ }
++ }
++
++// Unevolving classes may point to old methods directly
++// from their constant pool caches, itables, and/or vtables. We
++// use the SystemDictionary::classes_do() facility and this helper
++// to fix up these pointers. Additional field offsets and vtable indices
++// in the constant pool cache entries are fixed.
++//
++// Note: We currently don't support updating the vtable in
++// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
++void VM_EnhancedRedefineClasses::adjust_cpool_cache(Klass* klass_latest, TRAPS) {
++ Klass* k = klass_latest;
++ while (k != NULL) {
++ if (k->oop_is_instance()) {
++ HandleMark hm(THREAD);
++ InstanceKlass *ik = InstanceKlass::cast(k);
++
++ constantPoolHandle other_cp;
++ ConstantPoolCache* cp_cache;
++ other_cp = constantPoolHandle(ik->constants());
++
++ for (int i = 0; i < other_cp->length(); i++) {
++ if (other_cp->tag_at(i).is_klass()) {
++ Klass* klass = other_cp->klass_at(i, THREAD);
++ if (klass->new_version() != NULL) {
++ // (DCEVM) TODO: check why/if this is necessary
++ other_cp->klass_at_put(i, klass->new_version());
++ }
++ klass = other_cp->klass_at(i, THREAD);
++ assert(klass->new_version() == NULL, "Must be new klass!");
++ }
++ }
++
++ cp_cache = other_cp->cache();
++
++ if (cp_cache != NULL) {
++ cp_cache->clear_entries();
++ }
++
++ // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
++ if (RewriteBytecodes) {
++ ik->methods_do(unpatch_bytecode);
++ }
++ }
++ k = k->old_version();
++ }
++}
++
++void VM_EnhancedRedefineClasses::update_jmethod_ids() {
++ for (int j = 0; j < _matching_methods_length; ++j) {
++ Method* old_method = _old_methods->at(_matching_old_methods[j]);
++ jmethodID jmid = old_method->find_jmethod_id_or_null();
++ RC_TRACE(0x00008000, ("matching method %s, jmid %d", old_method->name_and_sig_as_C_string(), jmid));
++ if (old_method->new_version() != NULL && jmid == NULL) {
++ // (DCEVM) Have to create jmethodID in this case
++ jmid = old_method->jmethod_id();
++ }
++
++ if (jmid != NULL) {
++ // There is a jmethodID, change it to point to the new method
++ methodHandle new_method_h(_new_methods->at(_matching_new_methods[j]));
++ if (old_method->new_version() == NULL) {
++ methodHandle old_method_h(_old_methods->at(_matching_old_methods[j]));
++ jmethodID new_jmethod_id = Method::make_jmethod_id(old_method_h->method_holder()->class_loader_data(), old_method_h());
++ bool result = InstanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
++ } else {
++ jmethodID mid = new_method_h->jmethod_id();
++ bool result = InstanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
++ }
++ Method::change_method_associated_with_jmethod_id(jmid, new_method_h());
++ assert(Method::resolve_jmethod_id(jmid) == _new_methods->at(_matching_new_methods[j]), "should be replaced");
++ jmethodID mid = (_new_methods->at(_matching_new_methods[j]))->jmethod_id();
++ //assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
++ }
++ }
++}
++
++
++// Deoptimize all compiled code that depends on this class.
++//
++// If the can_redefine_classes capability is obtained in the onload
++// phase then the compiler has recorded all dependencies from startup.
++// In that case we need only deoptimize and throw away all compiled code
++// that depends on the class.
++//
++// If can_redefine_classes is obtained sometime after the onload
++// phase then the dependency information may be incomplete. In that case
++// the first call to RedefineClasses causes all compiled code to be
++// thrown away. As can_redefine_classes has been obtained then
++// all future compilations will record dependencies so second and
++// subsequent calls to RedefineClasses need only throw away code
++// that depends on the class.
++//
++void VM_EnhancedRedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
++ assert_locked_or_safepoint(Compile_lock);
++
++ // All dependencies have been recorded from startup or this is a second or
++ // subsequent use of RedefineClasses
++
++ // For now deopt all
++ // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
++ if (0 && JvmtiExport::all_dependencies_are_recorded()) {
++ Universe::flush_evol_dependents_on(k_h);
++ } else {
++ CodeCache::mark_all_nmethods_for_deoptimization();
++
++ ResourceMark rm(THREAD);
++ DeoptimizationMarker dm;
++
++ // Deoptimize all activations depending on marked nmethods
++ Deoptimization::deoptimize_dependents();
++
++ // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
++ CodeCache::make_marked_nmethods_not_entrant();
++
++ // From now on we know that the dependency information is complete
++ JvmtiExport::set_all_dependencies_are_recorded(true);
++ }
++ }
++
++void VM_EnhancedRedefineClasses::compute_added_deleted_matching_methods() {
++ Method* old_method;
++ Method* new_method;
++
++ _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
++ _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
++ _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
++ _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
++
++ _matching_methods_length = 0;
++ _deleted_methods_length = 0;
++ _added_methods_length = 0;
++
++ int nj = 0;
++ int oj = 0;
++ while (true) {
++ if (oj >= _old_methods->length()) {
++ if (nj >= _new_methods->length()) {
++ break; // we've looked at everything, done
++ }
++ // New method at the end
++ new_method = _new_methods->at(nj);
++ _added_methods[_added_methods_length++] = nj;
++ ++nj;
++ } else if (nj >= _new_methods->length()) {
++ // Old method, at the end, is deleted
++ old_method = _old_methods->at(oj);
++ _deleted_methods[_deleted_methods_length++] = oj;
++ ++oj;
++ } else {
++ old_method = _old_methods->at(oj);
++ new_method = _new_methods->at(nj);
++ if (old_method->name() == new_method->name()) {
++ if (old_method->signature() == new_method->signature()) {
++ _matching_old_methods[_matching_methods_length] = oj;//old_method;
++ _matching_new_methods[_matching_methods_length] = nj;//new_method;
++ _matching_methods_length++;
++ ++nj;
++ ++oj;
++ } else {
++ // added overloaded have already been moved to the end,
++ // so this is a deleted overloaded method
++ _deleted_methods[_deleted_methods_length++] = oj;//old_method;
++ ++oj;
++ }
++ } else { // names don't match
++ if (old_method->name()->fast_compare(new_method->name()) > 0) {
++ // new method
++ _added_methods[_added_methods_length++] = nj;//new_method;
++ ++nj;
++ } else {
++ // deleted method
++ _deleted_methods[_deleted_methods_length++] = oj;//old_method;
++ ++oj;
++ }
++ }
++ }
++ }
++ assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
++ assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
++ RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
++ _matching_methods_length, _deleted_methods_length, _added_methods_length));
++}
++
++
++
++// Install the redefinition of a class:
++// - house keeping (flushing breakpoints and caches, deoptimizing
++// dependent compiled code)
++// - adjusting constant pool caches and vtables in other classes
++void VM_EnhancedRedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
++
++ ResourceMark rm(THREAD);
++
++ assert(the_new_class->old_version() != NULL, "Must not be null");
++ assert(the_new_class->old_version()->new_version() == the_new_class(), "Must equal");
++
++ instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
++
++#ifndef JVMTI_KERNEL
++ // Remove all breakpoints in methods of this class
++ JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
++ jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
++#endif // !JVMTI_KERNEL
++
++ /* FIXME
++ if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
++ // We are redefining java.lang.reflect.Method. Method.invoke() is
++ // cached and users of the cache care about each active version of
++ // the method so we have to track this previous version.
++ // Do this before methods get switched
++ Universe::reflect_invoke_cache()->add_previous_version(
++ the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
++ }*/
++
++ _old_methods = the_old_class->methods();
++ _new_methods = the_new_class->methods();
++ compute_added_deleted_matching_methods();
++
++ // track which methods are EMCP for add_previous_version() call below
++
++ // TODO: Check if we need the concept of EMCP?
++ BitMap emcp_methods(_old_methods->length());
++ int emcp_method_count = 0;
++ emcp_methods.clear(); // clears 0..(length() - 1)
++
++ // We need to mark methods as old!!
++ check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
++ update_jmethod_ids();
++
++ // TODO:
++ transfer_old_native_function_registrations(the_old_class);
++
++
++
++#ifdef ASSERT
++
++// Klass* systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
++// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
++
++ //JNIHandles::verify();
++
++// Klass* systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
++
++// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
++ assert(the_new_class->old_version() != NULL, "Must not be null");
++ assert(the_new_class->old_version()->new_version() == the_new_class(), "Must equal");
++
++ for (int i=0; i<the_new_class->methods()->length(); i++) {
++ assert((the_new_class->methods()->at(i))->method_holder() == the_new_class(), "method holder must match!");
++ }
++
++ // FIXME:
++ //_old_methods->verify();
++ //_new_methods->verify();
++
++ the_new_class->vtable()->verify(tty);
++ the_old_class->vtable()->verify(tty);
++
++#endif
++
++ // increment the classRedefinedCount field in the_class and in any
++ // direct and indirect subclasses of the_class
++ increment_class_counter((InstanceKlass *)the_old_class(), THREAD);
++
++ }
++
++
++void VM_EnhancedRedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
++ RC_TRACE(0x00000100, ("Checking matching methods for EMCP"));
++ *emcp_method_count_p = 0;
++ int obsolete_count = 0;
++ int old_index = 0;
++ for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
++ Method* old_method = _old_methods->at(_matching_old_methods[j]);
++ Method* new_method = _new_methods->at(_matching_new_methods[j]);
++ Method* old_array_method;
++
++ // Maintain an old_index into the _old_methods array by skipping
++ // deleted methods
++ while ((old_array_method = _old_methods->at(old_index)) != old_method) {
++ ++old_index;
++ }
++
++ if (MethodComparator::methods_EMCP(old_method, new_method)) {
++ // The EMCP definition from JSR-163 requires the bytecodes to be
++ // the same with the exception of constant pool indices which may
++ // differ. However, the constants referred to by those indices
++ // must be the same.
++ //
++ // We use methods_EMCP() for comparison since constant pool
++ // merging can remove duplicate constant pool entries that were
++ // present in the old method and removed from the rewritten new
++ // method. A faster binary comparison function would consider the
++ // old and new methods to be different when they are actually
++ // EMCP.
++
++ // track which methods are EMCP for add_previous_version() call
++ emcp_methods->set_bit(old_index);
++ (*emcp_method_count_p)++;
++
++ // An EMCP method is _not_ obsolete. An obsolete method has a
++ // different jmethodID than the current method. An EMCP method
++ // has the same jmethodID as the current method. Having the
++ // same jmethodID for all EMCP versions of a method allows for
++ // a consistent view of the EMCP methods regardless of which
++ // EMCP method you happen to have in hand. For example, a
++ // breakpoint set in one EMCP method will work for all EMCP
++ // versions of the method including the current one.
++
++ old_method->set_new_version(new_method);
++ new_method->set_old_version(old_method);
++
++ RC_TRACE(0x00000100, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
++
++ // Transfer breakpoints
++ InstanceKlass *ik = InstanceKlass::cast(old_method->method_holder());
++ for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
++ RC_TRACE(0x00000100, ("Checking breakpoint: %d / %d",
++ bp->match(old_method), bp->match(new_method)));
++ if (bp->match(old_method)) {
++ assert(bp->match(new_method), "if old method is method, then new method must match too");
++ RC_TRACE(0x00000100, ("Found a breakpoint in an old EMCP method"));
++ new_method->set_breakpoint(bp->bci());
++ }
++ }
++ } else {
++ // mark obsolete methods as such
++ old_method->set_is_obsolete();
++ obsolete_count++;
++
++ // With tracing we try not to "yack" too much. The position of
++ // this trace assumes there are fewer obsolete methods than
++ // EMCP methods.
++ RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
++ old_method->name()->as_C_string(),
++ old_method->signature()->as_C_string()));
++ }
++ old_method->set_is_old();
++ }
++ for (int i = 0; i < _deleted_methods_length; ++i) {
++ Method* old_method = _old_methods->at(_deleted_methods[i]);
++
++ //assert(old_method->vtable_index() < 0,
++ // "cannot delete methods with vtable entries");;
++
++ // Mark all deleted methods as old and obsolete
++ old_method->set_is_old();
++ old_method->set_is_obsolete();
++ ++obsolete_count;
++ // With tracing we try not to "yack" too much. The position of
++ // this trace assumes there are fewer obsolete methods than
++ // EMCP methods.
++ RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
++ old_method->name()->as_C_string(),
++ old_method->signature()->as_C_string()));
++ }
++ //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
++ RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d !",
++ *emcp_method_count_p, obsolete_count));
++}
++
++// Increment the classRedefinedCount field in the specific InstanceKlass
++// and in all direct and indirect subclasses.
++void VM_EnhancedRedefineClasses::increment_class_counter(Klass* klass, TRAPS) {
++ oop class_mirror = klass->java_mirror();
++ int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
++ java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
++ RC_TRACE(0x00000008, ("updated count for class=%s to %d", klass->external_name(), new_count));
++}
++
++#ifndef PRODUCT
++void VM_EnhancedRedefineClasses::check_class(Klass* k_oop, TRAPS) {
++ Klass *k = k_oop;
++ if (k->oop_is_instance()) {
++ HandleMark hm(THREAD);
++ InstanceKlass *ik = (InstanceKlass *) k;
++ assert(ik->is_newest_version(), "must be latest version in system dictionary");
++
++ if (ik->vtable_length() > 0) {
++ ResourceMark rm(THREAD);
++ assert(ik->vtable()->check_no_old_or_obsolete_entries(), "old method found");
++ ik->vtable()->verify(tty, true);
++ }
++ }
++}
++
++#endif
++
++static bool match_second(void* value, Pair<Klass*, Klass*> elem) {
++ return elem.second == value;
++}
++
++jvmtiError VM_EnhancedRedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS) {
++ ResourceMark mark(THREAD);
++ GrowableArray<Pair<Klass*, Klass*> > links;
++
++ for (int i=0; i<class_count; i++) {
++
++ oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
++ instanceKlassHandle the_class(THREAD, java_lang_Class::as_Klass(mirror));
++ Handle the_class_loader(THREAD, the_class->class_loader());
++ Handle protection_domain(THREAD, the_class->protection_domain());
++
++ ClassFileStream st((u1*) class_defs[i].class_bytes,
++ class_defs[i].class_byte_count, (char *)"__VM_EnhancedRedefineClasses__");
++ ClassFileParser cfp(&st);
++
++
++
++ TempNewSymbol parsed_name;
++ GrowableArray<Symbol*>* super_symbols = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Symbol*>(0, true);
++ cfp.parseClassFile(the_class->name(),
++ the_class->class_loader_data(),
++ protection_domain,
++ the_class, KlassHandle(),
++ NULL,
++ super_symbols,
++ parsed_name,
++ false,
++ THREAD);
++
++ for (int j = 0; j < super_symbols->length(); j++) {
++ Symbol* sym = super_symbols->at(j);
++ Klass* super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
++ if (super_klass != NULL) {
++ instanceKlassHandle the_super_class(THREAD, super_klass);
++ if (_affected_klasses->contains(the_super_class)) {
++ links.append(Pair<Klass*, Klass*>(super_klass, the_class()));
++ }
++ }
++ }
++ delete super_symbols;
++
++ assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
++ the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
++ }
++
++ for (int i=0; i < _affected_klasses->length(); i++) {
++ instanceKlassHandle klass = _affected_klasses->at(i);
++
++ if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
++ klass->clear_redefinition_flag(Klass::MarkedAsAffected);
++ Klass* superKlass = klass->super();
++ if (_affected_klasses->contains(superKlass)) {
++ links.append(Pair<Klass*, Klass*>(superKlass, klass()));
++ }
++
++ Array<Klass*>* superInterfaces = klass->local_interfaces();
++ for (int j=0; j<superInterfaces->length(); j++) {
++ Klass* interfaceKlass = superInterfaces->at(j);
++ if (_affected_klasses->contains(interfaceKlass)) {
++ links.append(Pair<Klass*, Klass*>(interfaceKlass, klass()));
++ }
++ }
++ }
++ }
++
++ for (int i = 0; i < _affected_klasses->length(); i++) {
++ int j;
++ for (j = i; j < _affected_klasses->length(); j++) {
++ // Search for node with no incoming edges
++ Klass* oop = _affected_klasses->at(j)();
++ int k = links.find(oop, match_second);
++ if (k == -1) break;
++ }
++ if (j == _affected_klasses->length()) {
++ return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
++ }
++
++ // Remove all links from this node
++ Klass* oop = _affected_klasses->at(j)();
++ int k = 0;
++ while (k < links.length()) {
++ if (links.adr_at(k)->first == oop) {
++ links.delete_at(k);
++ } else {
++ k++;
++ }
++ }
++
++ // Swap node
++ instanceKlassHandle tmp = _affected_klasses->at(j);
++ _affected_klasses->at_put(j, _affected_klasses->at(i));
++ _affected_klasses->at_put(i, tmp);
++ }
++
++ return JVMTI_ERROR_NONE;
++}
++
++// This internal class transfers the native function registration from old methods
++// to new methods. It is designed to handle both the simple case of unchanged
++// native methods and the complex cases of native method prefixes being added and/or
++// removed.
++// It expects only to be used during the VM_EnhancedRedefineClasses op (a safepoint).
++//
++// This class is used after the new methods have been installed in "the_class".
++//
++// So, for example, the following must be handled. Where 'm' is a method and
++// a number followed by an underscore is a prefix.
++//
++// Old Name New Name
++// Simple transfer to new method m -> m
++// Add prefix m -> 1_m
++// Remove prefix 1_m -> m
++// Simultaneous add of prefixes m -> 3_2_1_m
++// Simultaneous removal of prefixes 3_2_1_m -> m
++// Simultaneous add and remove 1_m -> 2_m
++// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
++//
++class TransferNativeFunctionRegistration {
++ private:
++ instanceKlassHandle the_class;
++ int prefix_count;
++ char** prefixes;
++
++ // Recursively search the binary tree of possibly prefixed method names.
++ // Iteration could be used if all agents were well behaved. Full tree walk is
++ // more resilent to agents not cleaning up intermediate methods.
++ // Branch at each depth in the binary tree is:
++ // (1) without the prefix.
++ // (2) with the prefix.
++ // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
++ Method* search_prefix_name_space(int depth, char* name_str, size_t name_len,
++ Symbol* signature) {
++ Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
++ if (name_symbol != NULL) {
++ Method* method = the_class()->new_version()->lookup_method(name_symbol, signature);
++ if (method != NULL) {
++ // Even if prefixed, intermediate methods must exist.
++ if (method->is_native()) {
++ // Wahoo, we found a (possibly prefixed) version of the method, return it.
++ return method;
++ }
++ if (depth < prefix_count) {
++ // Try applying further prefixes (other than this one).
++ method = search_prefix_name_space(depth+1, name_str, name_len, signature);
++ if (method != NULL) {
++ return method; // found
++ }
++
++ // Try adding this prefix to the method name and see if it matches
++ // another method name.
++ char* prefix = prefixes[depth];
++ size_t prefix_len = strlen(prefix);
++ size_t trial_len = name_len + prefix_len;
++ char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
++ strcpy(trial_name_str, prefix);
++ strcat(trial_name_str, name_str);
++ method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
++ signature);
++ if (method != NULL) {
++ // If found along this branch, it was prefixed, mark as such
++ method->set_is_prefixed_native();
++ return method; // found
++ }
++ }
++ }
++ }
++ return NULL; // This whole branch bore nothing
++ }
++
++ // Return the method name with old prefixes stripped away.
++ char* method_name_without_prefixes(Method* method) {
++ Symbol* name = method->name();
++ char* name_str = name->as_utf8();
++
++ // Old prefixing may be defunct, strip prefixes, if any.
++ for (int i = prefix_count-1; i >= 0; i--) {
++ char* prefix = prefixes[i];
++ size_t prefix_len = strlen(prefix);
++ if (strncmp(prefix, name_str, prefix_len) == 0) {
++ name_str += prefix_len;
++ }
++ }
++ return name_str;
++ }
++
++ // Strip any prefixes off the old native method, then try to find a
++ // (possibly prefixed) new native that matches it.
++ Method* strip_and_search_for_new_native(Method* method) {
++ ResourceMark rm;
++ char* name_str = method_name_without_prefixes(method);
++ return search_prefix_name_space(0, name_str, strlen(name_str),
++ method->signature());
++ }
++
++ public:
++
++ // Construct a native method transfer processor for this class.
++ TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
++ assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
++
++ the_class = _the_class;
++ prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
++ }
++
++ // Attempt to transfer any of the old or deleted methods that are native
++ void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
++ for (int j = 0; j < methods_length; j++) {
++ Method* old_method = old_klass->methods()->at(old_methods[j]);
++
++ if (old_method->is_native() && old_method->has_native_function()) {
++ Method* new_method = strip_and_search_for_new_native(old_method);
++ if (new_method != NULL) {
++ // Actually set the native function in the new method.
++ // Redefine does not send events (except CFLH), certainly not this
++ // behind the scenes re-registration.
++ new_method->set_native_function(old_method->native_function(),
++ !Method::native_bind_event_is_interesting);
++ }
++ }
++ }
++ }
++};
++
++// Don't lose the association between a native method and its JNI function.
++void VM_EnhancedRedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
++ TransferNativeFunctionRegistration transfer(old_klass);
++ transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
++ transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
++}
+diff --git a/src/share/vm/prims/jvmtiRedefineClasses2.hpp b/src/share/vm/prims/jvmtiRedefineClasses2.hpp
+new file mode 100644
+index 0000000..06f9a35
+--- /dev/null
++++ b/src/share/vm/prims/jvmtiRedefineClasses2.hpp
+@@ -0,0 +1,156 @@
++/*
++ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * This code is free software; you can redistribute it and/or modify it
++ * under the terms of the GNU General Public License version 2 only, as
++ * published by the Free Software Foundation.
++ *
++ * This code is distributed in the hope that it will be useful, but WITHOUT
++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
++ * version 2 for more details (a copy is included in the LICENSE file that
++ * accompanied this code).
++ *
++ * You should have received a copy of the GNU General Public License version
++ * 2 along with this work; if not, write to the Free Software Foundation,
++ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
++ *
++ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
++ * or visit www.oracle.com if you need additional information or have any
++ * questions.
++ *
++ */
++
++#ifndef SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
++#define SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
++
++#include "jvmtifiles/jvmtiEnv.hpp"
++#include "memory/oopFactory.hpp"
++#include "memory/resourceArea.hpp"
++#include "oops/objArrayKlass.hpp"
++#include "oops/objArrayOop.hpp"
++#include "oops/fieldStreams.hpp"
++#include "prims/jvmtiRedefineClassesTrace.hpp"
++#include "gc_implementation/shared/vmGCOperations.hpp"
++
++// New version that allows arbitrary changes to already loaded classes.
++class VM_EnhancedRedefineClasses: public VM_GC_Operation {
++ private:
++
++ // These static fields are needed by SystemDictionary::classes_do()
++ // facility and the adjust_cpool_cache_and_vtable() helper:
++ static Array<Method*>* _old_methods;
++ static Array<Method*>* _new_methods;
++ static int* _matching_old_methods;
++ static int* _matching_new_methods;
++ static int* _deleted_methods;
++ static int* _added_methods;
++ static int _matching_methods_length;
++ static int _deleted_methods_length;
++ static int _added_methods_length;
++
++ static int _revision_number;
++
++ static GrowableArray<instanceKlassHandle>* _affected_klasses;
++
++ // The instance fields are used to pass information from
++ // doit_prologue() to doit() and doit_epilogue().
++ jint _class_count;
++ const jvmtiClassDefinition *_class_defs; // ptr to _class_count defs
++
++ // This operation is used by both RedefineClasses and
++ // RetransformClasses. Indicate which.
++ JvmtiClassLoadKind _class_load_kind;
++
++ GrowableArray<instanceKlassHandle>* _new_classes;
++ jvmtiError _result;
++ int _max_redefinition_flags;
++
++ // Performance measurement support. These timers do not cover all
++ // the work done for JVM/TI RedefineClasses() but they do cover
++ // the heavy lifting.
++ elapsedTimer _timer_total;
++ elapsedTimer _timer_prologue;
++ elapsedTimer _timer_class_linking;
++ elapsedTimer _timer_class_loading;
++ elapsedTimer _timer_prepare_redefinition;
++ elapsedTimer _timer_heap_iteration;
++ elapsedTimer _timer_redefinition;
++ elapsedTimer _timer_vm_op_epilogue;
++
++ jvmtiError find_sorted_affected_classes( );
++ jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
++ jvmtiError load_new_class_versions(TRAPS);
++
++ // Figure out which new methods match old methods in name and signature,
++ // which methods have been added, and which are no longer present
++ void compute_added_deleted_matching_methods();
++
++ // Change jmethodIDs to point to the new methods
++ void update_jmethod_ids();
++
++ void swap_all_method_annotations(ConstMethod* old_method, ConstMethod* new_method);
++
++ static void add_affected_klasses( Klass* obj );
++
++ static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
++
++ // Install the redefinition of a class
++ void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
++
++ // Increment the classRedefinedCount field in the specific instanceKlass
++ // and in all direct and indirect subclasses.
++ void increment_class_counter(Klass* klass, TRAPS);
++
++
++ void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
++
++ static void check_class(Klass* k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
++
++ static void adjust_cpool_cache(Klass* k_oop, TRAPS);
++
++ static void unpatch_bytecode(Method* method);
++
++#ifdef ASSERT
++ static void verify_classes(Klass* k_oop, oop initiating_loader, TRAPS);
++#endif
++
++ int calculate_redefinition_flags(instanceKlassHandle new_version);
++ void calculate_instance_update_information(Klass* new_version);
++ void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
++ static void mark_as_scavengable(nmethod* nm);
++
++ bool check_arguments();
++ jvmtiError check_arguments_error();
++
++ public:
++ VM_EnhancedRedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
++ virtual ~VM_EnhancedRedefineClasses();
++
++ bool doit_prologue();
++ void doit();
++ void doit_epilogue();
++ void rollback();
++
++ jvmtiError check_exception() const;
++ VMOp_Type type() const { return VMOp_RedefineClasses; }
++ bool skip_operation() const { return false; }
++ bool allow_nested_vm_operations() const { return true; }
++ jvmtiError check_error() { return _result; }
++
++ // Modifiable test must be shared between IsModifiableClass query
++ // and redefine implementation
++ static bool is_modifiable_class(oop klass_mirror);
++
++ // Utility methods for transfering field access flags
++
++ static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
++ static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
++
++ void transfer_old_native_function_registrations(instanceKlassHandle the_class);
++
++ static void swap_marks(oop first, oop second);
++};
++
++#endif // SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
+diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
+index 5a8ea0d..22c6afe 100644
+--- a/src/share/vm/runtime/arguments.cpp
++++ b/src/share/vm/runtime/arguments.cpp
+@@ -59,8 +59,8 @@
+ #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
+ #endif // INCLUDE_ALL_GCS
+
+-// Note: This is a special bug reporting site for the JVM
+-#define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
++// (DCEVM) The DCE VM has its own JIRA bug tracking system.
++#define DEFAULT_VENDOR_URL_BUG "https://github.com/Guidewire/DCEVM/issues"
+ #define DEFAULT_JAVA_LAUNCHER "generic"
+
+ // Disable options not supported in this release, with a warning if they
+@@ -1507,6 +1507,10 @@ void Arguments::set_conservative_max_heap_alignment() {
+
+ void Arguments::set_ergonomics_flags() {
+
++ if (AllowEnhancedClassRedefinition) {
++ // (DCEVM) enforces serial GC
++ FLAG_SET_ERGO(bool, UseSerialGC, true);
++ }
+ if (os::is_server_class_machine()) {
+ // If no other collector is requested explicitly,
+ // let the VM select the collector based on
+@@ -1948,6 +1952,17 @@ bool Arguments::check_gc_consistency() {
+ if (UseConcMarkSweepGC || UseParNewGC) i++;
+ if (UseParallelGC || UseParallelOldGC) i++;
+ if (UseG1GC) i++;
++
++ if (AllowEnhancedClassRedefinition) {
++ // (DCEVM) Must use serial GC. This limitation applies because the instance size changing GC modifications
++ // are only built into the mark and compact algorithm.
++ if (!UseSerialGC && i >= 1) {
++ jio_fprintf(defaultStream::error_stream(),
++ "Must use the serial GC in the DCEVM\n");
++ status = false;
++ }
++ }
++
+ if (i > 1) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Conflicting collector combinations in option list; "
+diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
+index 4967ead..040e281 100644
+--- a/src/share/vm/runtime/globals.hpp
++++ b/src/share/vm/runtime/globals.hpp
+@@ -1273,6 +1273,9 @@ class CommandLineFlags {
+ product(intx, TraceRedefineClasses, 0, \
+ "Trace level for JVMTI RedefineClasses") \
+ \
++ product(bool, AllowEnhancedClassRedefinition, true, \
++ "Allow enhanced class redefinition beyond swapping method bodies")\
++ \
+ develop(bool, StressMethodComparator, false, \
+ "Run the MethodComparator on all loaded methods") \
+ \
+diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
+index a8d24fa..c9496c0 100644
+--- a/src/share/vm/runtime/reflection.cpp
++++ b/src/share/vm/runtime/reflection.cpp
+@@ -519,6 +519,12 @@ bool Reflection::verify_field_access(Klass* current_class,
+ AccessFlags access,
+ bool classloader_only,
+ bool protected_restriction) {
++
++ // (DCEVM) Decide accessibility based on active version
++ if (current_class != NULL) {
++ current_class = current_class->active_version();
++ }
++
+ // Verify that current_class can access a field of field_class, where that
+ // field's access bits are "access". We assume that we've already verified
+ // that current_class can access field_class.
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 00000000..e9a6d91a
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include 'agent', 'framework', 'tests-java7', 'tests-java8', 'hotspot' \ No newline at end of file
diff --git a/tests-java7/src/test/java/org/dcevm/test/LightTestSuite.java b/tests-java7/src/test/java/org/dcevm/test/LightTestSuite.java
new file mode 100644
index 00000000..b5a2af02
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/LightTestSuite.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test;
+
+import org.dcevm.test.body.BodyTestSuite;
+import org.dcevm.test.eval.EvalTestSuite;
+import org.dcevm.test.fields.FieldsTestSuite;
+import org.dcevm.test.methods.MethodsTestSuite;
+import org.dcevm.test.structural.StructuralTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Summarizes all available test suites.
+ *
+ * @author Thomas Wuerthinger
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ BodyTestSuite.class,
+ EvalTestSuite.class,
+ MethodsTestSuite.class,
+ FieldsTestSuite.class,
+ StructuralTestSuite.class
+})
+public class LightTestSuite {
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/TestUtil.java b/tests-java7/src/test/java/org/dcevm/test/TestUtil.java
new file mode 100644
index 00000000..7876dac5
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/TestUtil.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test;
+
+import junit.framework.Assert;
+import org.dcevm.HotSwapTool;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+
+/**
+ * Utility methods for unit testing.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class TestUtil {
+
+ public static final boolean LIGHT = true;
+
+ 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;
+ }
+
+ public static int assertUnsupportedWithLight(Runnable run) {
+ if (TestUtil.LIGHT) {
+ return assertUnsupported(run);
+ }
+ run.run();
+ return -1;
+ }
+
+ public static int assertUnsupported(Runnable run) {
+ return assertException(UnsupportedOperationException.class, run);
+ }
+
+ public static void assertUnsupportedToVersion(final Class clazz, final int version) {
+ TestUtil.assertUnsupported(new Runnable() {
+ @Override
+ public void run() {
+ HotSwapTool.toVersion(clazz, version);
+ }
+ });
+ }
+
+ public static void assertUnsupportedToVersionWithLight(final Class clazz, final int version) {
+ TestUtil.assertUnsupportedWithLight(new Runnable() {
+ @Override
+ public void run() {
+ HotSwapTool.toVersion(clazz, version);
+ }
+ });
+ }
+
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/ArrayTest.java b/tests-java7/src/test/java/org/dcevm/test/body/ArrayTest.java
new file mode 100644
index 00000000..d82f5010
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/ArrayTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Array;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Ivan Dubrov
+ */
+public class ArrayTest {
+
+ public class A {
+ }
+
+ public class A___1 {
+ }
+
+ public class B extends A {
+ }
+
+ public class B___1 extends A {
+ }
+
+ @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][];
+
+ __toVersion__(1);
+
+ 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(arr3 instanceof B[][]);
+ assertTrue(arr3 instanceof A[][]);
+ assertTrue(arr3 instanceof Object[][]);
+ assertEquals(arr3.getClass(), Array.newInstance(B[].class, 0).getClass());
+
+ __toVersion__(0);
+
+ 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(arr3 instanceof B[][]);
+ assertTrue(arr3 instanceof A[][]);
+ assertTrue(arr3 instanceof Object[][]);
+ assertEquals(arr3.getClass(), Array.newInstance(B[].class, 0).getClass());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/BodyTestSuite.java b/tests-java7/src/test/java/org/dcevm/test/body/BodyTestSuite.java
new file mode 100644
index 00000000..37426aab
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/BodyTestSuite.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Class redefinition tests that swap only method bodies and change nothing else. This test cases should also
+ * run with the current version of HotSpot.
+ *
+ * @author Thomas Wuerthinger
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses(
+ {
+ StaticTest.class,
+ SimpleStaticTest.class,
+ MultipleThreadsTest.class,
+ OldActivationTest.class,
+ RefactorActiveMethodTest.class,
+ StressTest.class,
+ FacTest.class,
+ FibTest.class,
+ RedefinePrivateMethodTest.class,
+ ClassRenamingTestCase.class,
+ EMCPTest.class,
+ ArrayTest.class
+ })
+public class BodyTestSuite {
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/ClassRenamingTestCase.java b/tests-java7/src/test/java/org/dcevm/test/body/ClassRenamingTestCase.java
new file mode 100644
index 00000000..84488815
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/ClassRenamingTestCase.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.body;
+
+import org.dcevm.ClassRedefinitionPolicy;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ */
+public class ClassRenamingTestCase {
+
+ public static class B {
+
+ public int a() {
+ return 1;
+ }
+ }
+
+ @ClassRedefinitionPolicy(alias = B.class)
+ public static class A___1 {
+
+ public int a() {
+ return 2;
+ }
+ }
+
+ @Test
+ public void testRenaming() {
+ __toVersion__(0);
+
+ B b = new B();
+ assertEquals(1, b.a());
+
+ __toVersion__(1);
+
+ assertEquals(2, b.a());
+
+ __toVersion__(0);
+
+ assertEquals(1, b.a());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/EMCPTest.java b/tests-java7/src/test/java/org/dcevm/test/body/EMCPTest.java
new file mode 100644
index 00000000..0d28d6fe
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/EMCPTest.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.body;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Test;
+
+import java.io.PrintStream;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * EMCP (Equivalent modulo Constant Pool) tests.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class EMCPTest {
+
+ public static class A {
+
+ public static int EMCPReturn() {
+ change();
+ PrintStream s = System.out;
+ return 1;
+ }
+ }
+
+ public static class B {
+
+ public static int b() {
+ change();
+ throw new RuntimeException();
+ }
+ }
+
+ public static class C {
+
+ public static int c() {
+ changeAndThrow();
+ return 0;
+ }
+ }
+
+ public static class D {
+
+ private static int value = 1;
+
+ public static int EMCPReturn() {
+ change3();
+ return value;
+ }
+ }
+
+ public static class A___1 {
+
+ public static int EMCPReturn() {
+ change();
+ PrintStream s = System.out;
+ return 1;
+ }
+ }
+
+ public static class B___1 {
+
+ public static int b() {
+ change();
+ throw new RuntimeException();
+ }
+ }
+
+ public static class C___1 {
+
+ public static int c() {
+ changeAndThrow();
+ return 0;
+ }
+ }
+
+ public static class D___1 {
+ private static int value = 1;
+
+ public static int EMCPReturn() {
+ change3();
+ return value;
+ }
+ }
+
+ public static class D___2 {
+ private static int value = 1;
+
+ public static int EMCPReturn() {
+ change3();
+ return value;
+ }
+ }
+
+ public static class D___3 {
+ private static int value = 1;
+
+ public static int EMCPReturn() {
+ change3();
+ return value;
+ }
+ }
+
+ public static void change() {
+
+ __toVersion__(1);
+ }
+
+ public static void change3() {
+
+ __toVersion__(1);
+ __toVersion__(2);
+ __toVersion__(3);
+ }
+
+ public static void changeAndThrow() {
+
+ __toVersion__(1);
+
+ throw new RuntimeException();
+ }
+
+
+ @Test
+ public void testEMCPReturn() {
+ __toVersion__(0);
+
+ assertEquals(1, A.EMCPReturn());
+
+ __toVersion__(0);
+
+ assertEquals(1, A.EMCPReturn());
+
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testEMCPMultiChangeReturn() {
+ __toVersion__(0);
+
+ assertEquals(1, D.EMCPReturn());
+
+ __toVersion__(0);
+
+ assertEquals(1, D.EMCPReturn());
+
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testEMCPException() {
+ __toVersion__(0);
+
+ TestUtil.assertException(RuntimeException.class, new Runnable() {
+ @Override
+ public void run() {
+ B.b();
+ }
+ });
+
+ __toVersion__(0);
+
+ TestUtil.assertException(RuntimeException.class, new Runnable() {
+ @Override
+ public void run() {
+ B.b();
+ }
+ });
+
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testEMCPExceptionInCallee() {
+ __toVersion__(0);
+
+ TestUtil.assertException(RuntimeException.class, new Runnable() {
+ @Override
+ public void run() {
+ C.c();
+ }
+ });
+
+ __toVersion__(0);
+
+ TestUtil.assertException(RuntimeException.class, new Runnable() {
+ @Override
+ public void run() {
+ C.c();
+ }
+ });
+
+ __toVersion__(0);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/FacTest.java b/tests-java7/src/test/java/org/dcevm/test/body/FacTest.java
new file mode 100644
index 00000000..832ea7a8
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/FacTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Recursive implementation of the factorial function using class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+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 class Factorial extends Base {
+
+ @Override
+ protected int calc(int n) {
+ return n * calcAt(n - 1);
+ }
+ }
+
+ public static class Factorial___1 extends Base {
+
+ @Override
+ protected int calc() {
+ return 1;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testFac() {
+
+ assert __version__() == 0;
+ Factorial f = new Factorial();
+
+ assertEquals(1, f.calcAt(1));
+
+ assert __version__() == 0;
+ assertEquals(2, f.calcAt(2));
+
+ assert __version__() == 0;
+ assertEquals(6, f.calcAt(3));
+
+ assert __version__() == 0;
+ assertEquals(24, f.calcAt(4));
+
+ assert __version__() == 0;
+ assertEquals(120, f.calcAt(5));
+
+ assert __version__() == 0;
+ assertEquals(479001600, f.calcAt(12));
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/FibTest.java b/tests-java7/src/test/java/org/dcevm/test/body/FibTest.java
new file mode 100644
index 00000000..c95f2de5
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/FibTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Recursive implementation of the fibonacci function using class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+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 class Fib extends Base {
+
+ @Override
+ protected int calc(int n) {
+ return calcAt(n - 1) + calcAt(n - 2);
+ }
+ }
+
+ public static class Fib___1 extends Base {
+
+ @Override
+ protected int calc() {
+ return 1;
+ }
+ }
+
+ public static class Fib___2 extends Base {
+
+ @Override
+ protected int calc() {
+ return 2;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testFib() {
+
+ // 0 1 2 3 4 5
+ // 1 1 2 3 5 8
+ assert __version__() == 0;
+ Fib f = new Fib();
+
+ assertEquals(1, f.calcAt(1));
+
+ assert __version__() == 0;
+ assertEquals(2, f.calcAt(2));
+
+ assert __version__() == 0;
+ assertEquals(3, f.calcAt(3));
+
+ assert __version__() == 0;
+ assertEquals(5, f.calcAt(4));
+
+ assert __version__() == 0;
+ assertEquals(8, f.calcAt(5));
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/MultipleThreadsTest.java b/tests-java7/src/test/java/org/dcevm/test/body/MultipleThreadsTest.java
new file mode 100644
index 00000000..4966a2fc
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/MultipleThreadsTest.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Class for testing redefining methods of classes that extend the Thread class. In the test setup the run method
+ * calls the doit method in a loop until this methods returns false.
+ *
+ * @author Thomas Wuerthinger
+ */
+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) {
+ }
+
+ value++;
+ return true;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public int getValue2() {
+ return value2;
+ }
+ }
+
+ // Version 1
+ public static class A___1 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) {
+ }
+
+ value2++;
+ return true;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public int getValue2() {
+ return value2;
+ }
+ }
+
+ // Version 2
+ public static class A___2 extends Thread {
+
+ private int value;
+ private int value2;
+ private boolean flag = false;
+
+ @Override
+ public void run() {
+ while (doit()) {
+ flag = false;
+ }
+ }
+
+ public boolean doit() {
+ return false;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public int getValue2() {
+ return value2;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testOneThread() {
+ test(1);
+ }
+
+ @Test
+ public void testThreads() {
+ test(COUNT);
+ }
+
+ private void test(int count) {
+
+ assert __version__() == 0;
+
+ 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) {
+ }
+
+ for (int i = 0; i < count; i++) {
+ //assertTrue(arr[i].getValue() > 0);
+ }
+
+ __toVersion__(1);
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+
+ for (int i = 0; i < count; i++) {
+ assertTrue(arr[i].getValue2() > 0);
+ }
+
+ __toVersion__(2);
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+
+
+ for (int i = 0; i < count; i++) {
+ assertFalse(arr[i].isAlive());
+ }
+
+ __toVersion__(0);
+
+
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/OldActivationTest.java b/tests-java7/src/test/java/org/dcevm/test/body/OldActivationTest.java
new file mode 100644
index 00000000..3ad7f400
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/OldActivationTest.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Stress test for the number of old activations on the stack. In the test setup 10 different versions of the method A.value will be on the stack.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class OldActivationTest {
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ __toVersion__(1);
+ return 1 + this.value();
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ __toVersion__(2);
+ return 2 + this.value();
+ }
+ }
+
+ // Version 2
+ public static class A___2 {
+
+ public int value() {
+ __toVersion__(3);
+ return 3 + this.value();
+ }
+ }
+
+ // Version 3
+ public static class A___3 {
+
+ public int value() {
+ __toVersion__(4);
+ return 4 + this.value();
+ }
+ }
+
+ // Version 4
+ public static class A___4 {
+
+ public int value() {
+ __toVersion__(5);
+ return 5 + this.value();
+ }
+ }
+
+ // Version 5
+ public static class A___5 {
+
+ public int value() {
+ __toVersion__(6);
+ return 6 + this.value();
+ }
+ }
+
+ // Version 6
+ public static class A___6 {
+
+ public int value() {
+ __toVersion__(7);
+ return 7 + this.value();
+ }
+ }
+
+ // Version 7
+ public static class A___7 {
+
+ public int value() {
+ __toVersion__(8);
+ return 8 + this.value();
+ }
+ }
+
+ // Version 8
+ public static class A___8 {
+
+ public int value() {
+ __toVersion__(9);
+ return 9 + this.value();
+ }
+ }
+
+ // Version 9
+ public static class A___9 {
+
+ public int value() {
+ __toVersion__(0);
+ return 10;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testOldActivationTest() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ 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__(8);
+ assertEquals(9 + 10, a.value());
+ assert __version__() == 0;
+
+ __toVersion__(4);
+ assertEquals(5 + 6 + 7 + 8 + 9 + 10, a.value());
+ assert __version__() == 0;
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/RedefinePrivateMethodTest.java b/tests-java7/src/test/java/org/dcevm/test/body/RedefinePrivateMethodTest.java
new file mode 100644
index 00000000..935907fa
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/RedefinePrivateMethodTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests redefinition of a class such that old code still accesses a redefined private method.
+ *
+ * @author Thomas Wuerthinger
+ */
+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 1
+ public static class A___1 {
+
+ public int foo() {
+ return -1;
+ }
+
+ private int bar() {
+ return 2;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testRedefinePrivateMethod() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(3, a.foo());
+
+ assert __version__() == 1;
+
+ assertEquals(-1, a.foo());
+
+ __toVersion__(0);
+
+ assertEquals(3, a.foo());
+
+ assert __version__() == 1;
+
+ assertEquals(-1, a.foo());
+
+ __toVersion__(0);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/RefactorActiveMethodTest.java b/tests-java7/src/test/java/org/dcevm/test/body/RefactorActiveMethodTest.java
new file mode 100644
index 00000000..4dd433ce
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/RefactorActiveMethodTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+public class RefactorActiveMethodTest {
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ __toVersion__(1);
+ return 5;
+ }
+
+ public int secondValue() {
+ return 1;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return secondValue() * 2;
+ }
+
+ public int secondValue() {
+ return 2;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testActiveMethodReplacement() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(5, a.value());
+
+ assert __version__() == 1;
+
+ assertEquals(2, a.secondValue());
+ assertEquals(4, a.value());
+ assertEquals(2, a.secondValue());
+
+ assert __version__() == 1;
+
+ __toVersion__(0);
+
+ assertEquals(1, a.secondValue());
+ assertEquals(5, a.value());
+ assertEquals(4, a.value());
+
+ __toVersion__(0);
+
+ assertEquals(1, a.secondValue());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/SimpleStaticTest.java b/tests-java7/src/test/java/org/dcevm/test/body/SimpleStaticTest.java
new file mode 100644
index 00000000..a456381d
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/SimpleStaticTest.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+public class SimpleStaticTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+
+ // E and Helper must be loaded and initialized
+ E e = new E();
+ Helper h = new Helper();
+ }
+
+ // Version 0
+
+ public static class Helper {
+ public static int getIntegerField() {
+ return E.integerField;
+ }
+
+ public static void setIntegerField(int x) {
+ E.integerField = x;
+ }
+
+ public static int getFinalIntegerField() {
+ return E.finalIntegerField;
+ }
+ }
+
+ public static class E {
+ public static int integerField = 10;
+
+ public static E self = new E();
+
+ // 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();
+ }
+
+ // 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;
+ }
+
+ @Test
+ public void testSimpleNewStaticField() {
+
+ assert __version__() == 0;
+
+ __toVersion__(1);
+
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+ @Override
+ public void run() {
+ Helper.getIntegerField();
+ }
+ });
+
+ __toVersion__(2);
+
+ assertEquals(0, Helper.getIntegerField());
+ assertEquals(7, Helper.getFinalIntegerField());
+ Helper.setIntegerField(1000);
+ assertEquals(1000, Helper.getIntegerField());
+
+ __toVersion__(1);
+
+ TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
+ @Override
+ public void run() {
+ Helper.getIntegerField();
+ }
+ });
+
+ __toVersion__(2);
+
+ assertEquals(0, Helper.getIntegerField());
+ assertEquals(7, Helper.getFinalIntegerField());
+ Helper.setIntegerField(1000);
+ assertEquals(1000, Helper.getIntegerField());
+
+ __toVersion__(0);
+
+ assertEquals(7, Helper.getFinalIntegerField());
+ assertEquals(1000, Helper.getIntegerField());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/body/StaticTest.java b/tests-java7/src/test/java/org/dcevm/test/body/StaticTest.java
new file mode 100644
index 00000000..b4369b77
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/StaticTest.java
@@ -0,0 +1,300 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.assertNull;
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+public class StaticTest {
+
+ @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 A {
+
+ public static int value() {
+ return 1;
+ }
+ }
+
+ public static class B {
+
+ public static int value() {
+ return 2;
+ }
+ }
+
+ public static class C {
+ static {
+ System.out.println("Static initializer of C");
+ }
+
+ 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 2
+ public static class B___2 {
+
+ public static int value() {
+ return 3;
+ }
+ }
+
+ // Version 3
+ public static class A___3 {
+
+ public static int value() {
+ return 5;
+ }
+ }
+
+ public static class B___3 {
+
+ public static int value() {
+ return A.value() * 2;
+ }
+ }
+
+ // Version 4
+ public static class C___4 {
+
+ static {
+ System.out.println("Static initializer of C-4");
+ }
+
+ public static int value = 6;
+ }
+
+ public static class Helper___5 {
+ public static int getAdditionalField() {
+ return D___5.additionalField;
+ }
+
+ public static void setAdditionalField(int x) {
+ D___5.additionalField = x;
+ }
+ }
+
+ 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/tests-java7/src/test/java/org/dcevm/test/body/StressTest.java b/tests-java7/src/test/java/org/dcevm/test/body/StressTest.java
new file mode 100644
index 00000000..3d955810
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/body/StressTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.body;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+public class StressTest {
+
+ public final static int COUNT = 10;
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 1;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return 2;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testStressSwap() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ for (int i = 0; i < COUNT; i++) {
+
+ assertEquals(1, a.value());
+
+ __toVersion__(1);
+
+ assertEquals(2, a.value());
+
+ __toVersion__(0);
+ }
+
+ assertEquals(1, a.value());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/eval/AddingInterfaceTest.java b/tests-java7/src/test/java/org/dcevm/test/eval/AddingInterfaceTest.java
new file mode 100644
index 00000000..a3bec93d
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/eval/AddingInterfaceTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.eval;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Adds an implemented interface to a class and tests whether an instance of this class can then really be treated as an instance of the interface.
+ * Additionally, performs performance measurements of a call to this interface compared to a proxy object.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class AddingInterfaceTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ assert __version__() == 0;
+ }
+
+ public static class A {
+
+ public int getValue() {
+ return 1;
+ }
+ }
+
+ public static interface I {
+
+ public int getValue();
+ }
+
+ public static class A___1 implements I {
+
+ @Override
+ public int getValue() {
+ return 1;
+ }
+ }
+
+ public static class Proxy implements I {
+
+ private A a;
+
+ public Proxy(A a) {
+ this.a = a;
+ }
+
+ @Override
+ public int getValue() {
+ return a.getValue();
+ }
+ }
+
+ @Test
+ public void testAddInterface() {
+
+ A a = new A();
+ Proxy p = new Proxy(a);
+
+ final int N = 100000;
+ final int Z = 1;
+
+
+ __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);
+
+ // Must set to null, otherwise local variable i would violate type safety
+ i = null;
+
+ 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);
+ }
+
+ 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/tests-java7/src/test/java/org/dcevm/test/eval/EvalTestSuite.java b/tests-java7/src/test/java/org/dcevm/test/eval/EvalTestSuite.java
new file mode 100644
index 00000000..f9baf6c9
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/eval/EvalTestSuite.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.eval;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Tests used for evaluation purposes (especially performance measurements).
+ *
+ * @author Thomas Wuerthinger
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ FractionTest.class,
+ GeometryScenario.class,
+ AddingInterfaceTest.class
+})
+public class EvalTestSuite {
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/eval/FractionTest.java b/tests-java7/src/test/java/org/dcevm/test/eval/FractionTest.java
new file mode 100644
index 00000000..37ed44f6
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/eval/FractionTest.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.eval;
+
+import org.dcevm.HotSwapTool;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+public class FractionTest {
+
+ @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++;
+ }
+ }
+
+ 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();
+ }
+}
+
+abstract class MicroBenchmark {
+
+ public void init(int count) {
+ }
+
+ 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);
+ }
+}
+
+class IncreaseMicroBenchmark extends MicroBenchmark {
+
+ @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());
+ }
+}
+
+class ReorderMicroBenchmark extends MicroBenchmark {
+
+ @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());
+ }
+}
+
+class BigDecreaseMicroBenchmark extends MicroBenchmark {
+
+ @Override
+ public void doit(int count, List<Long> measurements) {
+ HotSwapTool.resetTimings();
+ __toVersion__(5);
+ measurements.add(HotSwapTool.getTotalTime());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/eval/GeometryScenario.java b/tests-java7/src/test/java/org/dcevm/test/eval/GeometryScenario.java
new file mode 100644
index 00000000..f671b6ca
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/eval/GeometryScenario.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.eval;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * A small geometry example application including a Point and a Rectangle class.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class GeometryScenario {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class Point {
+
+ private int x;
+ private int 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 isTopLeftOf(Point p) {
+ return p.x <= x && p.y <= y;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+ }
+
+ public static interface IFigure {
+
+ public boolean isHitAt(Point p);
+ }
+
+ public static class Rectangle {
+
+ private Point topLeft;
+ private Point bottomRight;
+
+ public Rectangle(Point p1, Point p2) {
+ topLeft = p1;
+ bottomRight = p2;
+ }
+
+ public boolean isHitAt(Point p) {
+ return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight);
+ }
+
+ public Point getTopLeft() {
+ return topLeft;
+ }
+
+ public Point getBottomRight() {
+ return bottomRight;
+ }
+
+ public static Rectangle create(Point p) {
+ return (Rectangle) (Object) (new Rectangle___1(p));
+ }
+ }
+
+ // Version 1
+ public static class Rectangle___1 implements IFigure {
+
+ private Point topLeft;
+ private Point center;
+ private Point bottomRight;
+
+ public Point getCenter() {
+ return center;
+ }
+
+ public Rectangle___1(Point p) {
+ topLeft = p;
+ bottomRight = p;
+ }
+
+ @Override
+ public boolean isHitAt(Point p) {
+ return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight);
+ }
+
+ public Point getTopLeft() {
+ return topLeft;
+ }
+
+ public Point getBottomRight() {
+ return bottomRight;
+ }
+
+ public static Rectangle create(Point p) {
+ return (Rectangle) (Object) (new Rectangle___1(p));
+ }
+ }
+
+ public static class Point___1 {
+
+ private char x1;
+ private int y;
+ private char x2;
+
+ 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 int getY() {
+ return y;
+ }
+
+ public int getX() {
+ return x1;
+ }
+
+ public char getX2() {
+ return x2;
+ }
+ }
+
+ @Test
+ public void testContructorChange() {
+
+ assert __version__() == 0;
+
+ 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());
+
+ __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());
+
+ 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/tests-java7/src/test/java/org/dcevm/test/fields/ComplexFieldTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/ComplexFieldTest.java
new file mode 100644
index 00000000..e7562349
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/ComplexFieldTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Complex field test.
+ *
+ * @author Thomas Wuerthinger
+ */
+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 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";
+ }
+
+ @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);
+ }
+
+ @Test
+ public void testComplexFieldChange() {
+ assert __version__() == 0;
+ A a = new A();
+ assertObjectOK(a);
+ __toVersion__(1);
+ assertObjectOK(a);
+ __toVersion__(0);
+ assertObjectOK(a);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/EnumTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/EnumTest.java
new file mode 100644
index 00000000..a5443bef
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/EnumTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @author Ivan Dubrov
+ */
+public class EnumTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ static enum A {
+ FIRST,
+ SECOND;
+ }
+
+ 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]);
+
+ __toVersion__(1);
+
+ assertEquals(3, A.values().length);
+ assertNotNull(A.values()[0]);
+ assertNotNull(A.values()[1]);
+ assertNotNull(A.values()[2]);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/FieldAlignmentTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/FieldAlignmentTest.java
new file mode 100644
index 00000000..ebd47771
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/FieldAlignmentTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Complex field test.
+ *
+ * @author Ivan Dubrov
+ */
+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);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/FieldChangedOrderTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/FieldChangedOrderTest.java
new file mode 100644
index 00000000..99f03afa
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/FieldChangedOrderTest.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test that changes the order of two int fields.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class FieldChangedOrderTest {
+
+ // Version 0
+ public static class A {
+
+ public int value1;
+ public int value2;
+
+ public A() {
+ value1 = 1;
+ value2 = 2;
+ }
+
+ public int getValue1() {
+ return value1;
+ }
+
+ public int getValue2() {
+ return value2;
+ }
+ }
+
+ public static class B {
+
+ public static int getStaticValue1(A a) {
+ return a.value1;
+ }
+
+ public static int getStaticValue2(A a) {
+ return a.value2;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value2;
+ public int value1;
+
+ public int getValue1() {
+ return value1;
+ }
+
+ public int getValue2() {
+ return value2;
+ }
+ }
+
+ public static class B___1 {
+
+ public static int getStaticValue1(A a) {
+ return a.value1;
+ }
+
+ public static int getStaticValue2(A a) {
+ return a.value2;
+ }
+ }
+
+ // Version 2
+ public static class A___2 {
+
+ public int tmp1;
+ public int value2;
+ public int tmp2;
+ public int value1;
+ public int tmp3;
+
+ public int getValue1() {
+ return value1;
+ }
+
+ public int getValue2() {
+ return value2;
+ }
+ }
+
+ // Version 3
+ public static class A___3 {
+
+ public int tmp1;
+ public int value2;
+
+ public int getValue1() {
+ return tmp1;
+ }
+
+ 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/tests-java7/src/test/java/org/dcevm/test/fields/FieldModificationTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/FieldModificationTest.java
new file mode 100644
index 00000000..3529e6ad
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/FieldModificationTest.java
@@ -0,0 +1,278 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+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 1
+ public static class A___1 {
+
+ public int val0;
+
+ public void increaseAllByOne() {
+ val0++;
+ }
+
+ public int sum() {
+ return val0;
+ }
+ }
+
+ // 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 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/tests-java7/src/test/java/org/dcevm/test/fields/FieldsTestSuite.java b/tests-java7/src/test/java/org/dcevm/test/fields/FieldsTestSuite.java
new file mode 100644
index 00000000..55ce5941
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/FieldsTestSuite.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Class redefinition tests that may change the methods and fields of class, but do not change the superklass or the implemented
+ * interface.
+ *
+ * @author Thomas Wuerthinger
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ FieldChangedOrderTest.class,
+ FieldModificationTest.class,
+ ObjectStressTest.class,
+ YieldTest.class,
+ ComplexFieldTest.class,
+ FieldAlignmentTest.class,
+ StringFieldTest.class,
+ RedefinePrivateFieldTest.class,
+ EnumTest.class
+})
+public class FieldsTestSuite {
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/ObjectStressTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/ObjectStressTest.java
new file mode 100644
index 00000000..5109fb9b
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/ObjectStressTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Thomas Wuerthinger
+ */
+public class ObjectStressTest {
+
+ 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 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;
+ }
+
+
+ __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]);
+ }
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/RedefinePrivateFieldTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/RedefinePrivateFieldTest.java
new file mode 100644
index 00000000..c2ea1dea
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/RedefinePrivateFieldTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests redefinition of a class such that old code still accesses a redefined private field.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class RedefinePrivateFieldTest {
+
+ // Version 0
+ public static class A {
+
+ private int f1;
+
+ public A() {
+ f1 = 5;
+ }
+
+ public int foo() {
+ int result = f1;
+ __toVersion__(1);
+ result += f1;
+ return result;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ int f0;
+ int f1;
+
+ public int foo() {
+ return -1;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testRedefinePrivateField() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(10, a.foo());
+
+ assert __version__() == 1;
+
+ assertEquals(-1, a.foo());
+
+ __toVersion__(0);
+
+ assertEquals(10, a.foo());
+
+ assert __version__() == 1;
+
+ assertEquals(-1, a.foo());
+
+ __toVersion__(0);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/StringFieldTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/StringFieldTest.java
new file mode 100644
index 00000000..2bf7167a
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/StringFieldTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Complex field test.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class StringFieldTest {
+
+ // 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";
+ }
+
+ @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);
+ }
+
+ @Test
+ public void testComplexFieldChange() {
+ assert __version__() == 0;
+ A a = new A();
+ assertObjectOK(a);
+ __toVersion__(1);
+ assertObjectOK(a);
+ __toVersion__(0);
+ assertObjectOK(a);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/fields/YieldTest.java b/tests-java7/src/test/java/org/dcevm/test/fields/YieldTest.java
new file mode 100644
index 00000000..0f5dc40c
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/fields/YieldTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.fields;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test case that produces a list of integer values recursively.
+ * The recursive function does not contain a conditional statement.
+ * The recursion is stopped by swapping the recursive method with a different non-recursive implementation.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class YieldTest {
+
+ // Version 0
+ public static class Base {
+
+ protected List<Integer> arr = new ArrayList<Integer>();
+
+ public void reset() {
+ __toVersion__(0);
+ }
+
+ public void next() {
+ __toVersion__(__version__() + 1);
+ }
+ }
+
+ public static abstract class A extends Base {
+
+ public List<Integer> gen() {
+ arr.add(produce());
+ next();
+ return gen();
+ }
+
+ public abstract int produce();
+ }
+
+ public static class B extends A {
+
+ @Override
+ public int produce() {
+ return 1;
+ }
+ }
+
+ public static class B___10 extends A {
+
+ @Override
+ public int produce() {
+ return 2;
+ }
+ }
+
+ public static class B___20 extends A {
+
+ private int x;
+
+ @Override
+ public int produce() {
+ return ++x;
+ }
+ }
+
+ public static class A___30 extends Base {
+
+ public List<Integer> gen() {
+ reset();
+ return arr;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testYield() {
+
+ 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/tests-java7/src/test/java/org/dcevm/test/methods/AddMethodTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/AddMethodTest.java
new file mode 100644
index 00000000..7a56b577
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/AddMethodTest.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.methods;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for adding / removing methods in a single class.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class AddMethodTest {
+
+ // 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 {
+
+ 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;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ 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);
+ }
+
+ @Test
+ public void testAddMethodToKlassWithEMCPExceptionMethod() {
+
+ assert __version__() == 0;
+
+ final A a = new A();
+
+ assertEquals(1, a.value(1));
+
+ __toVersion__(1);
+
+ int firstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
+ @Override
+ public void run() {
+ assertEquals(4, a.value(1));
+ }
+ });
+
+ int secondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
+ @Override
+ public void run() {
+ assertEquals(4, a.value(2));
+ }
+ });
+
+ checkLineNumbers(firstLineNumber, secondLineNumber);
+
+ assert __version__() == 2;
+
+ int newFirstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
+ @Override
+ public void run() {
+ assertEquals(4, a.value(2));
+ }
+ });
+
+ 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/tests-java7/src/test/java/org/dcevm/test/methods/AnnotationTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/AnnotationTest.java
new file mode 100644
index 00000000..bb25162f
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/AnnotationTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.annotation.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for adding / removing annotations on methods, fields and classes.
+ *
+ * @author Thomas Wuerthinger
+ * @author Jiri Bubnik
+ */
+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 TestAnnotation2 {
+ }
+
+
+ // Version 0
+ public static class A {
+ public int testField;
+
+ public void testMethod() {
+ }
+ }
+
+ // Version 1
+ @TestAnnotation
+ public static class A___1 {
+ @TestAnnotation
+ public int testField;
+
+ @TestAnnotation
+ public void testMethod() {
+ }
+ }
+
+ // Version 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);
+ }
+
+ 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/tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectHashcodeTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectHashcodeTest.java
new file mode 100644
index 00000000..846c86e4
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectHashcodeTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Redefines a class and tests that the identity hashcode of the
+ * java.lang.Class object is retained. Also tests the combination of
+ * locking and retrieving the hashcode.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class ClassObjectHashcodeTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 1;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ 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());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectSynchronizationTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectSynchronizationTest.java
new file mode 100644
index 00000000..8bf5eab5
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/ClassObjectSynchronizationTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Redefines a class and tests that the lock on the java.lang.Class object
+ * is retained. Also tests that the object identity of the java.lang.Class
+ * object is not changed.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class ClassObjectSynchronizationTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 1;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ 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);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/methods/ClassReflectionTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/ClassReflectionTest.java
new file mode 100644
index 00000000..75fc38b4
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/ClassReflectionTest.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import junit.framework.Assert;
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.ref.SoftReference;
+import java.lang.reflect.Method;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testing correct reflection functionality after class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class ClassReflectionTest {
+
+ @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 {
+
+ @Override
+ public int value() {
+ return 2;
+ }
+ }
+
+ public static class C extends A {
+
+ @Override
+ public int value() {
+ return 3;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return 1;
+ }
+
+ public int value2() {
+ return 2;
+ }
+ }
+
+ // Version 2
+ public static class C___2 extends B {
+
+ @Override
+ public int value() {
+ return super.value();
+ }
+ }
+
+ private void assertIsSuper(Class<?> s, Class<?> c) {
+ assertEquals(s, c.getSuperclass());
+ }
+
+ private void assertIsNotSuper(Class<?> s, Class<?> c) {
+ Assert.assertFalse(s.equals(c.getSuperclass()));
+ }
+
+ @Test
+ public void testClassReflection() {
+
+ checkWeakReference();
+ assert __version__() == 0;
+
+ final A a = new A();
+ final B b = new B();
+ final C c = new C();
+
+ 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);
+
+ assertIsSuper(A.class, B.class);
+ assertIsSuper(B.class, C.class);
+ assertIsNotSuper(A.class, C.class);
+
+ 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/tests-java7/src/test/java/org/dcevm/test/methods/DeleteActiveMethodTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/DeleteActiveMethodTest.java
new file mode 100644
index 00000000..da957093
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/DeleteActiveMethodTest.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import junit.framework.Assert;
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test cases that delete a method that is currently active on the stack.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class DeleteActiveMethodTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ boolean firstCall;
+
+ public int value() {
+ firstCall = true;
+ return helperValue();
+ }
+
+ public int helperValue() {
+
+ if (!firstCall) {
+ return -1;
+ }
+ firstCall = false;
+
+ Thread t = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ __toVersion__(1);
+ }
+ });
+ t.start();
+
+ try {
+ do {
+ this.helperValue();
+ } while (t.isAlive());
+ this.helperValue();
+ Assert.fail("Exception expected!");
+ } catch (NoSuchMethodError e) {
+ }
+
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ }
+
+ return 1;
+ }
+ }
+
+ public static class B {
+
+ public int fac(int x) {
+ if (x == 0) {
+ __toVersion__(1);
+ }
+
+ return x * fac(x - 1);
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ boolean firstCall;
+
+ public int value() {
+ __toVersion__(0);
+ return 2;
+ }
+ }
+
+ public static class B___1 {
+ }
+
+ @Test
+ public void testDeleteActiveMethodSimple() {
+ assert __version__() == 0;
+
+ final B b = new B();
+ TestUtil.assertException(NoSuchMethodError.class, new Runnable() {
+ @Override
+ public void run() {
+ b.fac(5);
+ }
+ });
+
+ assert __version__() == 1;
+
+ __toVersion__(0);
+ assert __version__() == 0;
+ }
+
+ @Test
+ public void testDeleteActiveMethod() {
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(1, a.value());
+ assert __version__() == 1;
+
+ assertEquals(2, a.value());
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assert __version__() == 1;
+
+ assertEquals(2, a.value());
+ assert __version__() == 0;
+
+ assertEquals(1, a.value());
+ assert __version__() == 1;
+
+ assertEquals(2, a.value());
+ assert __version__() == 0;
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/methods/MethodReflectionTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/MethodReflectionTest.java
new file mode 100644
index 00000000..7c1eaaf7
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/MethodReflectionTest.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Method;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testing correct reflection functionality after class redefinition.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class MethodReflectionTest {
+
+ @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 {
+
+ @Override
+ public int value() {
+ return 2;
+ }
+ }
+
+ public static class C extends A {
+
+ @Override
+ public int value() {
+ return 3;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return 1;
+ }
+
+ public int value2() {
+ return 2;
+ }
+ }
+
+ // Version 2
+ public static class C___2 extends B {
+
+ @Override
+ public int value() {
+ return super.value();
+ }
+ }
+
+ @Test
+ public void testMethodReflection() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+ B b = new B();
+ C c = new C();
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(3, c.value());
+
+ assertContainsMethod(A.class, "value");
+ assertDoesNotContainMethod(A.class, "value2");
+
+ __toVersion__(1);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(3, c.value());
+
+ assertContainsMethod(A.class, "value");
+ assertContainsMethod(A.class, "value2");
+
+ __toVersion__(0);
+
+ assertEquals(1, a.value());
+ assertEquals(2, b.value());
+ assertEquals(3, c.value());
+
+ 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 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/tests-java7/src/test/java/org/dcevm/test/methods/MethodsTestSuite.java b/tests-java7/src/test/java/org/dcevm/test/methods/MethodsTestSuite.java
new file mode 100644
index 00000000..20888623
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/MethodsTestSuite.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Class redefinition tests that perform adding/removing/changing the methods of a class.
+ *
+ * @author Thomas Wuerthinger
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ AddMethodTest.class,
+ DeleteActiveMethodTest.class,
+ ClassReflectionTest.class,
+ MethodReflectionTest.class,
+ ClassObjectSynchronizationTest.class,
+ ClassObjectHashcodeTest.class,
+ OverrideMethodTest.class,
+ SingleClassTest.class,
+ SingleClassReflectionTest.class,
+ AnnotationTest.class
+})
+public class MethodsTestSuite {
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/methods/OverrideMethodTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/OverrideMethodTest.java
new file mode 100644
index 00000000..dc98d608
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/OverrideMethodTest.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for the class relationship A<B<C with adding / removing methods.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class OverrideMethodTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 5;
+ }
+ }
+
+ public static class B extends A {
+
+ public int doubled() {
+ return value() * 2;
+ }
+ }
+
+ public static class C extends B {
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return 10;
+ }
+ }
+
+ // Version 2
+ public static class B___2 extends A {
+
+ public int doubled() {
+ return value() * 3;
+ }
+ }
+
+ // Version 3
+ public static class C___3 extends B {
+
+ @Override
+ public int value() {
+ return 1;
+ }
+ }
+
+ // Verison 4
+ public static class A___4 {
+
+ public int value() {
+ return baseValue();
+ }
+
+ public int baseValue() {
+ return 20;
+ }
+ }
+
+ public static class B___4 extends A {
+
+ public int doubled() {
+ return value() * 2;
+ }
+ }
+
+ public static class C___4 extends B {
+ }
+
+ // Verison 5
+ public static class A___5 {
+
+ public int value() {
+ return baseValue();
+ }
+
+ 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/tests-java7/src/test/java/org/dcevm/test/methods/SingleClassReflectionTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/SingleClassReflectionTest.java
new file mode 100644
index 00000000..61d3d31a
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/SingleClassReflectionTest.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testing correct behaviour of the class object after class redefinition (with respect to the identity hash code and synchronization).
+ *
+ * @author Thomas Wuerthinger
+ */
+public class SingleClassReflectionTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public static synchronized void staticSynchronized() {
+ __toVersion__(1);
+ }
+ }
+
+
+ // Version 1
+ public static class A___1 {
+ public static synchronized void staticSynchronized() {
+ }
+ }
+
+
+ @Test
+ public void testHashcode() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ int hashcode = a.getClass().hashCode();
+
+ __toVersion__(1);
+
+ assertEquals(hashcode, a.getClass().hashCode());
+
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testStaticSynchronized() {
+
+ A.staticSynchronized();
+
+ assertEquals(1, __version__());
+
+ __toVersion__(0);
+ }
+
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/methods/SingleClassTest.java b/tests-java7/src/test/java/org/dcevm/test/methods/SingleClassTest.java
new file mode 100644
index 00000000..4e12bc26
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/methods/SingleClassTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for adding / removing methods in a single class.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class SingleClassTest {
+
+ // Version 0
+ public static class A {
+
+ public int value() {
+ return 5;
+ }
+ }
+
+ // Version 3
+ public static class A___3 {
+
+ public int value() {
+ return 5;
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ public int value() {
+ return 6;
+ }
+
+ public int testValue() {
+ return 1;
+
+ }
+ }
+
+ // Version 2
+ public static class A___2 {
+
+ public int value() {
+ return baseValue() * 2;
+ }
+
+ public int baseValue() {
+ return 10;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testSimpleReplacement() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+
+ assertEquals(5, a.value());
+
+ __toVersion__(1);
+
+ assertEquals(6, a.value());
+
+ __toVersion__(3);
+
+ assertEquals(5, a.value());
+
+ __toVersion__(0);
+
+ assertEquals(5, a.value());
+ }
+
+ @Test
+ public void testAddMethod() {
+
+ assert __version__() == 0;
+
+ A a = new A();
+ assertEquals(a.value(), 5);
+
+ __toVersion__(2);
+ assertEquals(a.value(), 20);
+
+ __toVersion__(0);
+ assertEquals(a.value(), 5);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/structural/AnonymousClassInMethodTest.java b/tests-java7/src/test/java/org/dcevm/test/structural/AnonymousClassInMethodTest.java
new file mode 100644
index 00000000..5f923110
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/structural/AnonymousClassInMethodTest.java
@@ -0,0 +1,67 @@
+package org.dcevm.test.structural;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Test insertion and swap of anonymous classes.
+ */
+public class AnonymousClassInMethodTest {
+
+ 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();
+ }
+ }
+
+ // 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();
+ }
+ }
+
+
+ @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());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/structural/InterfaceTest.java b/tests-java7/src/test/java/org/dcevm/test/structural/InterfaceTest.java
new file mode 100644
index 00000000..1a089965
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/structural/InterfaceTest.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.structural;
+
+import org.dcevm.test.TestUtil;
+import org.junit.*;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.*;
+
+/**
+ * Tests for adding an interface to a class and for changing the methods of an interface.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class InterfaceTest {
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ public static interface A {
+
+ int giveMeFive();
+ }
+
+ public static class AImpl {
+
+ public int giveMeFive() {
+ return 5;
+ }
+ }
+
+ public static class BImpl implements A {
+
+ @Override
+ public int giveMeFive() {
+ return 5;
+ }
+
+ public int giveMeTen() {
+ return 10;
+ }
+ }
+
+ public static class AImpl___1 implements A {
+
+ @Override
+ public int giveMeFive() {
+ return 5;
+ }
+ }
+
+ public static interface A___2 {
+
+ int giveMeTen();
+ }
+
+ public static class Helper {
+
+ public int giveMeTenA2(A a) {
+ return 3;
+ }
+ }
+
+ public static class Helper___2 {
+
+ public int giveMeTenA2(A a) {
+ return ((A___2) a).giveMeTen();
+ }
+ }
+
+ @Test
+ public void testAddInterface() {
+
+ modifyInterface();
+ assert __version__() == 0;
+
+ 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());
+
+ TestUtil.assertUnsupportedToVersionWithLight(InterfaceTest.class, 0);
+ }
+
+ public void modifyInterface() {
+
+ assert __version__() == 0;
+
+ BImpl b = new BImpl();
+ assertTrue(b instanceof A);
+
+ __toVersion__(2);
+
+ assertEquals(10, new Helper().giveMeTenA2(b));
+
+ __toVersion__(0);
+ assertEquals(5, ((A) b).giveMeFive());
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/structural/RedefineClassClassTest.java b/tests-java7/src/test/java/org/dcevm/test/structural/RedefineClassClassTest.java
new file mode 100644
index 00000000..e0da9002
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/structural/RedefineClassClassTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.structural;
+
+import org.dcevm.ClassRedefinitionPolicy;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Smallest test case for redefining the interface java/lang/reflect/Type (causes java/lang/Class being redefined)
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class RedefineClassClassTest {
+
+ // Version 0
+ public interface Type {
+ }
+
+ // Version 1
+ @ClassRedefinitionPolicy(alias = java.lang.reflect.Type.class)
+ public interface Type___1 {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testRedefineClass() {
+
+ assert __version__() == 0;
+
+ __toVersion__(1);
+
+ __toVersion__(0);
+
+ __toVersion__(1);
+
+ __toVersion__(0);
+
+
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/structural/RedefineObjectClassTest.java b/tests-java7/src/test/java/org/dcevm/test/structural/RedefineObjectClassTest.java
new file mode 100644
index 00000000..7dd22fa9
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/structural/RedefineObjectClassTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.structural;
+
+import org.dcevm.ClassRedefinitionPolicy;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Smallest test case for redefining java/lang/Object, without changing the number of virtual methods.
+ *
+ * @author Thomas Wuerthinger
+ */
+@Ignore
+public class RedefineObjectClassTest {
+
+ // Version 0
+ public static class Helper {
+ public static String access(Object o) {
+ return "";
+ }
+ }
+
+ // Version 1
+
+ public static class Helper___1 {
+ public static String access(Object o) {
+ return ((A___1) o).myTestFunction___();
+ }
+ }
+
+ @ClassRedefinitionPolicy(alias = java.lang.Object.class)
+ public static class A___1 {
+
+ public final native Class<? extends Object> getClass___();
+
+ @Override
+ public native int hashCode();
+
+ @Override
+ public boolean equals(Object obj) {
+ return (this == obj);
+ }
+
+ public static int x;
+ public static int x1;
+ public static int x2;
+ public static int x3;
+ public static int x4;
+ public static int x5;
+
+ @Override
+ protected native Object clone() throws CloneNotSupportedException;
+
+ @Override
+ public String toString() {
+ System.out.println("x=" + (x++));
+ return getClass().getName() + "@" + Integer.toHexString(hashCode());// myTestFunction___();
+ }
+
+ public final String myTestFunction___() {
+ return "test";
+ }
+
+ public final native void notify___();
+
+ public final native void notifyAll___();
+
+ public final native void wait___(long timeout) throws InterruptedException;
+
+ public final void wait___(long timeout, int nanos) throws InterruptedException {
+
+
+ if (timeout < 0) {
+ throw new IllegalArgumentException("timeout value is negative");
+ }
+
+ if (nanos < 0 || nanos > 999999) {
+ throw new IllegalArgumentException(
+ "nanosecond timeout value out of range");
+ }
+
+ if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
+ timeout++;
+ }
+
+ wait(timeout);
+ }
+
+ public final void wait___() throws InterruptedException {
+ wait(0);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testRedefineObject() {
+
+ assert __version__() == 0;
+
+ Object o = new Object();
+ __toVersion__(1);
+
+ System.out.println(this.toString());
+ System.out.println(o.toString());
+ System.out.println(this.toString());
+
+
+ //assertEquals("test", o.toString());
+ assertEquals("test", Helper.access(o));
+ __toVersion__(0);
+ __toVersion__(1);
+ __toVersion__(0);
+ }
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/structural/StructuralTestSuite.java b/tests-java7/src/test/java/org/dcevm/test/structural/StructuralTestSuite.java
new file mode 100644
index 00000000..633ba059
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/structural/StructuralTestSuite.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.structural;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Class redefinition tests that do arbitrary structural changes.
+ * <p/>
+ * TODO: Add a test where redefinition triggers classloading (e.g. because a super type is not yet loaded).
+ *
+ * @author Thomas Wuerthinger
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ RedefineClassClassTest.class,
+ RedefineObjectClassTest.class,
+ InterfaceTest.class,
+ ThisTypeChange.class
+})
+public class StructuralTestSuite {
+}
diff --git a/tests-java7/src/test/java/org/dcevm/test/structural/ThisTypeChange.java b/tests-java7/src/test/java/org/dcevm/test/structural/ThisTypeChange.java
new file mode 100644
index 00000000..9cfde217
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/structural/ThisTypeChange.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.structural;
+
+import org.dcevm.test.TestUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+
+/**
+ * Tests that change the type of the object references by the Java this pointer.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class ThisTypeChange {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static class A {
+
+ public int valueOK() {
+ return 1;
+ }
+
+ public int value() {
+ __toVersion__(1);
+ return 1;
+ }
+ }
+
+ public static class B extends A {
+
+ @Override
+ public int value() {
+ return super.value();
+ }
+
+
+ @Override
+ public int valueOK() {
+ __toVersion__(1);
+ return super.valueOK();
+ }
+ }
+
+ // Version 1
+ public static class A___1 {
+
+ 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/tests-java7/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java b/tests-java7/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java
new file mode 100644
index 00000000..5ecbd83e
--- /dev/null
+++ b/tests-java7/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.util;
+
+import org.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));
+ }
+
+ /**
+ * 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) {
+ HotSwapTool.toVersion(determineOuter(0), versionNumber);
+ }
+
+ /**
+ * 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/tests-java8/src/test/java/org/dcevm/test/methods/DefaultMethodsTest.java b/tests-java8/src/test/java/org/dcevm/test/methods/DefaultMethodsTest.java
new file mode 100644
index 00000000..de6b3c64
--- /dev/null
+++ b/tests-java8/src/test/java/org/dcevm/test/methods/DefaultMethodsTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package org.dcevm.test.methods;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.dcevm.test.util.HotSwapTestHelper.__toVersion__;
+import static org.dcevm.test.util.HotSwapTestHelper.__version__;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for the class relationship A<B<C with adding / removing methods.
+ *
+ * @author Thomas Wuerthinger
+ */
+public class DefaultMethodsTest {
+
+ @Before
+ public void setUp() throws Exception {
+ __toVersion__(0);
+ }
+
+ // Version 0
+ public static interface A {
+ default int value() {
+ __toVersion__(1);
+ return 1 + value();
+ }
+ }
+
+ public static class B implements A {
+ }
+
+ public static interface C {
+ int value();
+ }
+
+ public static class D implements C {
+ @Override
+ public int value() {
+ __toVersion__(2);
+ return 3 + value();
+ }
+ }
+
+ // Version 1
+ public static interface A___1 {
+ int value();
+ }
+
+
+ public static class B___1 implements A {
+ public int value() {
+ return 2;
+ }
+ }
+
+ // Version 2
+ public static interface C___2 {
+ default int value() {
+ return 5;
+ }
+ }
+
+ public static class D___2 implements C___2 {
+ }
+
+ @Test
+ public void testDefaultMethodReplacedWithInstance() {
+ assert __version__() == 0;
+
+ A a = new B();
+ assertEquals(3, a.value());
+
+ __toVersion__(0);
+ }
+
+ @Test
+ public void testInstanceMethodReplacedWithDefault() {
+ assert __version__() == 0;
+
+ C c = new D();
+ assertEquals(8, c.value());
+
+ __toVersion__(0);
+ }
+}
diff --git a/tests-java8/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java b/tests-java8/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java
new file mode 100644
index 00000000..5ecbd83e
--- /dev/null
+++ b/tests-java8/src/test/java/org/dcevm/test/util/HotSwapTestHelper.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package org.dcevm.test.util;
+
+import org.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));
+ }
+
+ /**
+ * 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) {
+ HotSwapTool.toVersion(determineOuter(0), versionNumber);
+ }
+
+ /**
+ * 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);
+ }
+ }
+}