Skip to content

Commit

Permalink
HotSwap support
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@184 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
  • Loading branch information
chiba committed Jun 21, 2005
1 parent 5de7634 commit aa0900d
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 5 deletions.
29 changes: 29 additions & 0 deletions Readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,33 @@ <h3>7. sample/evolve/*.java</h3>
on the local host.
(Or, see <a href="sample/evolve/start.html">sample/evolve/start.html</a>.)

<h3>8. sample/hotswap/*.java</h3>

<p>This shows dynamic class reloading by the JPDA.
To run, first type the following commands:

<ul><pre>
% cd sample/hotswap
% javac *.java
% cd logging
% javac *.java
% cd ..
</pre></ul>

<p>If your Java is 1.4, then type:

<ul><pre>
% java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 Test
</pre></ul>

<p>If you are using Java 5, then type:

<ul><pre>
% java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 Test
</pre></ul>

<p>Note that the class path must include <code>JAVA_HOME/lib/tools.jar</code>.

<h2>Hints</h2>

<p>To know the version number, type this command:
Expand All @@ -258,6 +285,8 @@ <h2>Changes</h2>
<p>- version 3.1

<ul>
<li>javassist.tool.HotSwapper was added.
<li>javassist.Dump was moved to javassist.tool.Dump.
</ul>

<p>- version 3.0 in January 18, 2005
Expand Down
41 changes: 38 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<project name="javassist" default="jar" basedir=".">

<property name="dist-version" value="javassist-3.0"/>
<property name="dist-version" value="javassist-3.1"/>

<property environment="env"/>
<property name="target.jar" value="javassist.jar"/>
Expand Down Expand Up @@ -51,15 +51,33 @@
debug="on"
deprecation="on"
optimize="off"
includes="sample/**">
includes="sample/**"
excludes="sample/hotswap/**">
<classpath refid="classpath"/>
</javac>
<javac srcdir="${basedir}/sample/hotswap"
destdir="${build.classes.dir}"
debug="on"
deprecation="on"
optimize="off"
includes="*">
<classpath refid="classpath"/>
</javac>
<mkdir dir="${build.classes.dir}/logging"/>
<javac srcdir="${basedir}/sample/hotswap/logging"
destdir="${build.classes.dir}/logging"
debug="on"
deprecation="on"
optimize="off"
includes="*">
<classpath refid="classpath"/>
</javac>
<copy file="sample/vector/Test.j"
todir="${build.classes.dir}/sample/vector"/>
<copy todir="${build.classes.dir}/sample/evolve">
<fileset dir="sample/evolve"/>
</copy>
<echo>To run the sample programs, change the current directory
<echo>To run the sample programs without ant, change the current directory
to ${build.classes.dir}.</echo>
</target>

Expand Down Expand Up @@ -175,4 +193,21 @@ Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.</i>]]></bottom>
</java>
</target>

<!-- for JDK 1.4 -->
<target name = "sample-hotswap" depends="sample">
<echo>** JAVA_HOME/lib/tools.jar must be included in CLASS_PATH</echo>
<java fork="true" dir="${run.dir}" classname="Test">
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000" />
<classpath refid="classpath"/>
</java>
</target>

<!-- for Java 5 -->
<target name = "sample-hotswap5" depends="sample">
<echo>** JAVA_HOME/lib/tools.jar must be included in CLASS_PATH</echo>
<java fork="true" dir="${run.dir}" classname="Test">
<jvmarg line="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000" />
<classpath refid="classpath"/>
</java>
</target>
</project>
5 changes: 5 additions & 0 deletions sample/hotswap/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class HelloWorld {
public void print() {
System.out.println("hello world");
}
}
25 changes: 25 additions & 0 deletions sample/hotswap/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.io.*;
import javassist.tool.HotSwapper;

public class Test {
public static void main(String[] args) throws Exception {
HotSwapper hs = new HotSwapper(8000);
new HelloWorld().print();

File newfile = new File("logging/HelloWorld.class");
byte[] bytes = new byte[(int)newfile.length()];
new FileInputStream(newfile).read(bytes);
System.out.println("** reload a logging version");

hs.reload("HelloWorld", bytes);
new HelloWorld().print();

newfile = new File("HelloWorld.class");
bytes = new byte[(int)newfile.length()];
new FileInputStream(newfile).read(bytes);
System.out.println("** reload the original version");

hs.reload("HelloWorld", bytes);
new HelloWorld().print();
}
}
6 changes: 6 additions & 0 deletions sample/hotswap/logging/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class HelloWorld {
public void print() {
System.out.println("** HelloWorld.print()");
System.out.println("hello world");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* License.
*/

package javassist;
package javassist.tool;

import java.io.*;
import javassist.bytecode.ClassFile;
Expand All @@ -25,7 +25,7 @@
* the class file is broken.
*
* <p>For example,
* <ul><pre>% java javassist.Dump foo.class</pre></ul>
* <ul><pre>% java javassist.tool.Dump foo.class</pre></ul>
*
* <p>prints the contents of the constant pool and the list of methods
* and fields.
Expand Down
Loading

0 comments on commit aa0900d

Please sign in to comment.