Giter VIP home page Giter VIP logo

jvmbyteswaptool's Introduction

JVM ByteSwap Tool

logo

actions

A tool that can hot swap the class byte code while jvm is running. Very suitable for SpringBoot framework.

Based on the jvm instrumentation tech, ASM, javassist and JVMTI.

Usage

Download the zip file from the release page.

Make sure you have a JDK >= 1.8.

$ java -jar swapper.jar

// All of the java processes will be listed in following
// Choose the pid you want to attach
// Then a web ui will be served at http://localhost:8000

Visit this url http://localhost:8000 then you will get the following Web UI.

image

Now you can enjoy the functionalities of swapper tool.

For example, Watch some methods. Trigger this method, and then the params and return value and execution time cost will be printed.

image

It's Watch one of the functions provided by swapper tool.

Get more functions and details from the wiki.

jvmbyteswaptool's People

Contributors

sunwu51 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jvmbyteswaptool's Issues

TypeNotPresentException

When computeAllFrames, there is a method in ClassWriter getCommonSuperClass, that will return the common super type of given types. Here, use current classloader to load the given type. It should be Global.getClassLoader

java.lang.TypeNotPresentException: Type XXXXX not present
	at wshade.org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1052)
	at wshade.org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1264)
	at wshade.org.objectweb.asm.Frame.merge(Frame.java:1311)
	at wshade.org.objectweb.asm.Frame.merge(Frame.java:1255)
	at wshade.org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1612)
	at wshade.org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1548)
	at wshade.org.objectweb.asm.MethodVisitor.visitMaxs(MethodVisitor.java:786)
	at wshade.org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(LocalVariablesSorter.java:147)
	at w.core.model.WatchTransformer$1$1.visitMaxs(WatchTransformer.java:114)
	at wshade.org.objectweb.asm.ClassReader.readCode(ClassReader.java:2664)
	at wshade.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1512)
	at wshade.org.objectweb.asm.ClassReader.accept(ClassReader.java:745)
	at wshade.org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
	at w.core.model.WatchTransformer.transform(WatchTransformer.java:52)
	at w.core.model.BaseClassTransformer.transform(BaseClassTransformer.java:48)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
	at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
	at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
	at w.Global.addActiveTransformer(Global.java:256)
	at w.core.Swapper.swap(Swapper.java:68)
	at w.web.Websocketd$1.dispatch(Websocketd.java:98)
	at w.web.Websocketd$1.onMessage(Websocketd.java:51)
	at fi.iki.elonen.NanoWSD$WebSocket.handleWebsocketFrame(NanoWSD.java:229)
	at fi.iki.elonen.NanoWSD$WebSocket.readWebsocket(NanoWSD.java:247)
	at fi.iki.elonen.NanoWSD$WebSocket.access$200(NanoWSD.java:65)
	at fi.iki.elonen.NanoWSD$WebSocket$1.send(NanoWSD.java:88)
	at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:852)
	at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:189)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.ClassNotFoundException: XXXXX
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at wshade.org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1050)
	... 29 more

TODO list

  • 日志信息整理,增加日志等级,并可以在前端过滤显示哪些信息。
  • 接口和抽象类不支持,目前会直接报错,改为提前校验并提示,可能的子类型。
    • 考虑打印提示信息,这是个接口无法直接增强,你可能增强的子类列表,然后标注哪个类是springBean
  • 考虑增加trace功能,打印函数内的每个调用其他函数的耗时。

下面ognl #root是springctx,用来过滤实现了某个接口的对象,的真实类名。

#root.getBeanDefinitionNames().{ #name=#this, #b=#root.getBean(#name), #b instanceof com.xxx.MyInterface ? #b : null}.{? #this != null}.{#this.class}

TUI support

Add tui for some situations that the web or network cannot connected directly.

工具类启动显示WindowsAttachProvider不能被初始化

按照b站教程,先启动了一个自定义的web的jar,然后启动swapper,但是java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider could not be instantiated,目录也没有显示任何在运行的java进程,不知道咋回事。(还有另外一个问题我想要请教一下,我的电脑的java.home设置的就是C:\Program Files\Java\jdk-1.8\jre,但是一启动swapper,java.home就会自动变成 C:\Program Files\Java\jre-1.8,导致启动报错,我只能去修改swapper的源代码了。)
Snipaste_2024-07-07_15-50-18
java-home-2
java-home-3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.