Revision: 5829 http://jnode.svn.sourceforge.net/jnode/?rev=5829&view=rev Author: lsantha Date: 2011-06-30 20:20:36 +0000 (Thu, 30 Jun 2011)
Log Message: ----------- JDIVirtualMachine for easier class hotswapping. Modified Paths: -------------- trunk/core/src/classpath/vm/gnu/classpath/jdwp/NativeVMVirtualMachine.java Added Paths: ----------- trunk/core/src/classpath/vm/gnu/classpath/jdwp/JDIVirtualMachine.java Added: trunk/core/src/classpath/vm/gnu/classpath/jdwp/JDIVirtualMachine.java =================================================================== --- trunk/core/src/classpath/vm/gnu/classpath/jdwp/JDIVirtualMachine.java (rev 0) +++ trunk/core/src/classpath/vm/gnu/classpath/jdwp/JDIVirtualMachine.java 2011-06-30 20:20:36 UTC (rev 5829) @@ -0,0 +1,266 @@ +package gnu.classpath.jdwp; + +import gnu.classpath.jdwp.event.EventRequest; +import gnu.classpath.jdwp.util.MethodResult; +import java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.security.ProtectionDomain; +import java.util.ArrayList; +import java.util.Iterator; +import org.jnode.annotation.NoInline; +import org.jnode.vm.BaseVmArchitecture; +import org.jnode.vm.VmSystem; +import org.jnode.vm.VmSystemClassLoader; +import org.jnode.vm.classmgr.ClassDecoder; +import org.jnode.vm.classmgr.VmByteCode; +import org.jnode.vm.classmgr.VmClassLoader; +import org.jnode.vm.classmgr.VmIsolatedStatics; +import org.jnode.vm.classmgr.VmMethod; +import org.jnode.vm.classmgr.VmStaticsIterator; +import org.jnode.vm.classmgr.VmType; +import org.jnode.vm.facade.VmUtils; +import org.jnode.vm.isolate.VmIsolate; + +/** + * User: lsantha + * Date: 6/26/11 10:53 AM + */ +public class JDIVirtualMachine { + @NoInline + static boolean debug() { + return false; + } + + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#suspendThread(java.lang.Thread) + */ + @NoInline + static void suspendThread(Thread arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.suspendThread()"); + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#resumeThread(java.lang.Thread) + */ + @NoInline + static void resumeThread(Thread arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.resumeThread()"); + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getSuspendCount(java.lang.Thread) + */ + @NoInline + static int getSuspendCount(Thread arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getSuspendCount()"); + return 0; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getAllLoadedClassesCount() + */ + @NoInline + static int getAllLoadedClassesCount() { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getAllLoadedClassesCount()"); + return 0; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getAllLoadedClasses() + */ + @NoInline + static Iterator getAllLoadedClasses() { + if(debug()) + System.out.println("NativeVMVirtualMachine.getAllLoadedClasses()"); + return new Iterator() { + private VmStaticsIterator iter = new VmStaticsIterator(VmUtils.getVm().getSharedStatics()); + private Iterator<VmIsolatedStatics> isolated = VmIsolate.staticsIterator(); + + public boolean hasNext() { + if (iter.hasNext()) + return true; + else { + while (isolated.hasNext()) { + iter = new VmStaticsIterator(isolated.next()); + if (iter.hasNext()) + return true; + } + } + return false; + } + + public Object next() { + return iter.next().asClass(); + } + + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getClassStatus(java.lang.Class) + */ + @NoInline + static int getClassStatus(Class arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getClassStatus()"); + return 0; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getAllClassMethods(java.lang.Class) + */ + @NoInline + static VMMethod[] getAllClassMethods(Class arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getAllClassMethods()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getClassMethod(java.lang.Class, long) + */ + @NoInline + static VMMethod getClassMethod(Class arg1, long arg2) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getClassMethod()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getFrames(java.lang.Thread, int, int) + */ + @NoInline + static ArrayList getFrames(Thread arg1, int arg2, int arg3) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getFrame()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getFrame(java.lang.Thread, java.nio.ByteBuffer) + */ + @NoInline + static VMFrame getFrame(Thread arg1, ByteBuffer arg2) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getFrame()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getFrameCount(java.lang.Thread) + */ + @NoInline + static int getFrameCount(Thread arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getFrameCount()"); + return 0; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getThreadStatus(java.lang.Thread) + */ + @NoInline + static int getThreadStatus(Thread thread) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getThreadStatus()"); + +// public static final int ZOMBIE = 0; +// public static final int RUNNING = 1; +// public static final int SLEEPING = 2; +// public static final int MONITOR = 3; +// public static final int WAIT = 4; + + return 0; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getLoadRequests(java.lang.ClassLoader) + */ + @NoInline + static ArrayList getLoadRequests(ClassLoader arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getLoadRequest()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#executeMethod(java.lang.Object, java.lang.Thread, java.lang.Class, java.lang.reflect.Method, java.lang.Object[], boolean) + */ + @NoInline + static MethodResult executeMethod(Object arg1, Thread arg2, Class arg3, Method arg4, Object[] arg5, boolean arg6) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.executeMethod()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#getSourceFile(java.lang.Class) + */ + @NoInline + static String getSourceFile(Class arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.getSourceFile()"); + return null; + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#registerEvent(gnu.classpath.jdwp.event.EventRequest) + */ + @NoInline + static void registerEvent(EventRequest arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.registerEvent() " + arg1.getId() + " " + arg1.getEventKind() + + " " + arg1.getSuspendPolicy() + " " + arg1.getFilters()); + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#unregisterEvent(gnu.classpath.jdwp.event.EventRequest) + */ + @NoInline + static void unregisterEvent(EventRequest arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.unregisterEvent()"); + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#clearEvents(byte) + */ + @NoInline + static void clearEvents(byte arg1) { + //todo implement it + if(debug()) + System.out.println("NativeVMVirtualMachine.clearEvents()"); + } + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#redefineClass(Class, byte[]) + */ + @NoInline + static void redefineClass(Class oldClass, byte[] classData){ + if(debug()) + System.out.println("NativeVMVirtualMachine.redefineClass()"); + + String name = oldClass.getName(); + VmType old_type = VmType.fromClass(oldClass); + VmClassLoader loader = VmType.fromClass(oldClass).getLoader(); + ProtectionDomain pd = oldClass.getProtectionDomain(); + VmType new_type = ClassDecoder.defineClass(name, ByteBuffer.wrap(classData), false, loader, pd); + for(int i = 0; i < old_type.getNoDeclaredMethods(); i++){ + VmMethod old_method = old_type.getDeclaredMethod(i); + if (!old_method.isNative()) { + VmMethod new_method = new_type.getDeclaredMethod(old_method.getName(), old_method.getSignature()); + if(new_method == null) continue; + + old_method.setBytecode(new_method.getBytecode()); + old_method.resetOptLevel(); + old_method.recompile(); + System.out.println("Redefined method: " + old_method.getFullName()); + } + } + } +} Modified: trunk/core/src/classpath/vm/gnu/classpath/jdwp/NativeVMVirtualMachine.java =================================================================== --- trunk/core/src/classpath/vm/gnu/classpath/jdwp/NativeVMVirtualMachine.java 2011-06-30 20:17:44 UTC (rev 5828) +++ trunk/core/src/classpath/vm/gnu/classpath/jdwp/NativeVMVirtualMachine.java 2011-06-30 20:20:36 UTC (rev 5829) @@ -42,211 +42,118 @@ * @author Levente S\u00e1ntha */ class NativeVMVirtualMachine { - @NoInline -// public static boolean debug() { -// return true; -// } - /** * @see gnu.classpath.jdwp.VMVirtualMachine#suspendThread(java.lang.Thread) */ private static void suspendThread(Thread arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.suspendThread()"); + JDIVirtualMachine.suspendThread(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#resumeThread(java.lang.Thread) */ private static void resumeThread(Thread arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.resumeThread()"); + JDIVirtualMachine.resumeThread(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getSuspendCount(java.lang.Thread) */ private static int getSuspendCount(Thread arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getSuspendCount()"); - return 0; + return JDIVirtualMachine.getSuspendCount(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getAllLoadedClassesCount() */ private static int getAllLoadedClassesCount() { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getAllLoadedClassesCount()"); - return 0; + return JDIVirtualMachine.getAllLoadedClassesCount(); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getAllLoadedClasses() */ private static Iterator getAllLoadedClasses() { -// if(debug()) - System.out.println("NativeVMVirtualMachine.getAllLoadedClasses()"); - return new Iterator() { - private VmStaticsIterator iter = new VmStaticsIterator(VmUtils.getVm().getSharedStatics()); - private Iterator<VmIsolatedStatics> isolated = VmIsolate.staticsIterator(); - - public boolean hasNext() { - if (iter.hasNext()) - return true; - else { - while (isolated.hasNext()) { - iter = new VmStaticsIterator(isolated.next()); - if (iter.hasNext()) - return true; - } - } - return false; - } - - public Object next() { - return iter.next().asClass(); - } - - public void remove() { - throw new UnsupportedOperationException(); - } - }; + return JDIVirtualMachine.getAllLoadedClasses(); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getClassStatus(java.lang.Class) */ private static int getClassStatus(Class arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getClassStatus()"); - return 0; + return JDIVirtualMachine.getClassStatus(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getAllClassMethods(java.lang.Class) */ private static VMMethod[] getAllClassMethods(Class arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getAllClassMethods()"); - return null; + return JDIVirtualMachine.getAllClassMethods(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getClassMethod(java.lang.Class, long) */ private static VMMethod getClassMethod(Class arg1, long arg2) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getClassMethod()"); - return null; + return JDIVirtualMachine.getClassMethod(arg1, arg2); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getFrames(java.lang.Thread, int, int) */ private static ArrayList getFrames(Thread arg1, int arg2, int arg3) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getFrame()"); - return null; + return JDIVirtualMachine.getFrames(arg1, arg2, arg3); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getFrame(java.lang.Thread, java.nio.ByteBuffer) */ private static VMFrame getFrame(Thread arg1, ByteBuffer arg2) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getFrame()"); - return null; + return JDIVirtualMachine.getFrame(arg1, arg2); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getFrameCount(java.lang.Thread) */ private static int getFrameCount(Thread arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getFrameCount()"); - return 0; + return JDIVirtualMachine.getFrameCount(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getThreadStatus(java.lang.Thread) */ private static int getThreadStatus(Thread arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getThreadStatus()"); - return 0; + return JDIVirtualMachine.getThreadStatus(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getLoadRequests(java.lang.ClassLoader) */ private static ArrayList getLoadRequests(ClassLoader arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getLoadRequest()"); - return null; + return JDIVirtualMachine.getLoadRequests(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#executeMethod(java.lang.Object, java.lang.Thread, java.lang.Class, java.lang.reflect.Method, java.lang.Object[], boolean) */ private static MethodResult executeMethod(Object arg1, Thread arg2, Class arg3, Method arg4, Object[] arg5, boolean arg6) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.executeMethod()"); - return null; + return JDIVirtualMachine.executeMethod(arg1, arg2, arg3, arg4, arg5, arg6); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#getSourceFile(java.lang.Class) */ private static String getSourceFile(Class arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.getSourceFile()"); - return null; + return JDIVirtualMachine.getSourceFile(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#registerEvent(gnu.classpath.jdwp.event.EventRequest) */ private static void registerEvent(EventRequest arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.registerEvent() " + arg1.getId() + " " + arg1.getEventKind() + - " " + arg1.getSuspendPolicy() + " " + arg1.getFilters()); + JDIVirtualMachine.registerEvent(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#unregisterEvent(gnu.classpath.jdwp.event.EventRequest) */ private static void unregisterEvent(EventRequest arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.unregisterEvent()"); + JDIVirtualMachine.unregisterEvent(arg1); } /** * @see gnu.classpath.jdwp.VMVirtualMachine#clearEvents(byte) */ private static void clearEvents(byte arg1) { - //todo implement it -// if(debug()) - System.out.println("NativeVMVirtualMachine.clearEvents()"); + JDIVirtualMachine.clearEvents(arg1); } - + /** + * @see gnu.classpath.jdwp.VMVirtualMachine#redefineClass(Class, byte[]) + */ public static void redefineClass(Class oldClass, byte[] classData){ -// if(debug()) - System.out.println("NativeVMVirtualMachine.redefineClass()"); - VmType old_type = VmType.fromClass(oldClass); - VmType new_type = ClassDecoder.defineClass(oldClass.getName(), - ByteBuffer.wrap(classData), false, - VmType.fromClass(oldClass).getLoader(), - oldClass.getProtectionDomain()); - for(int i = 0; i < old_type.getNoDeclaredMethods(); i++){ - VmMethod old_method = old_type.getDeclaredMethod(i); - if(!old_method.isNative()){ - VmMethod new_method = new_type.getDeclaredMethod(old_method.getName(), old_method.getSignature()); - if(new_method == null) continue; - old_method.setBytecode(new_method.getBytecode()); - old_method.resetOptLevel(); - old_method.recompile(); - System.out.println("Redefined: " + old_method); - } - } + JDIVirtualMachine.redefineClass(oldClass, classData); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Jnode-svn-commits mailing list Jnode-svn-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits