InfoQ
<https://mp.weixin.qq.com/s?__biz=MjM5MDE0Mjc4MA==&mid=2651000740&idx=1&sn=bf71c1fb052800600b881b733a14bc50&chksm=bdbef7f78ac97ee1070beb72494ec63af87de24c9be49945b4ab1c565f3bff7c3b31fbfd4898&scene=0#%23>
original   Xu Dongchen  
<https://mp.weixin.qq.com/s?__biz=MjM5MDE0Mjc4MA==&mid=2651000740&idx=1&sn=bf71c1fb052800600b881b733a14bc50&chksm=bdbef7f78ac97ee1070beb72494ec63af87de24c9be49945b4ab1c565f3bff7c3b31fbfd4898&scene=0#%23>

Write in front

With the expansion of software deployment scale , Refinement of system functions , Increasing coupling and link complexity between systems . To maintain the stability of the current scale system , Need to realize and improve the monitoring system , Fault location analysis , Traffic recording and playback , Strong and weak dependence detection , Support tool platform such as fault drill . For consideration of server size and business stability , These supporting tool platforms should be non intrusive to the target application , Effective in real time , Dynamic pluggable features .


To achieve this , More or less we'll touch a piece of underlying technology —— Dynamic bytecode enhancement . If each tool implements its own set of bytecode enhancement logic , The threshold of early realization and high cost of later maintenance , And the interaction between different tools results in unpredictable risks . How to shield the high threshold of bytecode enhancement technology , Reduce R & D and operation cost , At the same time, it can support the rapid realization and dynamic management of the functions of multiple upper tool platforms , Become the target of Alibaba Group . Since last year, I have been devoting myself to cultivation , A real-time and non intrusive byte code enhancement framework has been developed .

therefore JVM-Sandbox Born !
Application scenario JVM-Sandbox Target group of
*
Btrace So powerful , I also wanted to make it more convenient , More suitable problem location tool , It supports online link monitoring and troubleshooting , It can also support the problem location of stand-alone version .

*
Sometimes a question comes back , Need input parameter to complete positioning , But there are no logs , Even in someone else's code , I really want to develop a tool to dynamically add logs as needed , It's better to follow the business
ID Filter .

*
There are many tools that can be used for exception simulation between systems , But what about the abnormal simulation in the system , Add switch or use AOP
Implementation in development system , I really want to develop a more elegant exception simulation tool , It can simulate the abnormality between systems , It can also simulate the abnormality in the system .

*
I really want to get line call link data , It can be used to identify scenes , Coverage statistics, etc , Coverage statistics tools cannot be natively supported , Inaccurate statistical link data . Want to develop a tool to get the data of the line link .

*

I want to develop recording playback , fault simulation , Dynamic log , Line link acquisition and other tools , Even if I'm finished , The underlying implementation principles of these tools are the same , Simultaneous use , How to eliminate the influence between these tools , How to ensure the dynamic loading of these tools , How to ensure dynamic loading
/ Uninstall will not affect other tools , How to ensure that when there is a problem with the tools , Quickly eliminate impact , Code restore .

If you have any of the above , So you are JVM-Sandbox Potential customers of .JVM-Sandbox
Provide dynamic enhancement class the class you specify , Get the parameters and line information you want ; Provide dynamic pluggable containers , Management based on JVM-Sandbox Module of .
JVM-Sandbox What can be done ?
stay JVM-Sandbox( Hereinafter referred to as sandbox ) In the world view of , Any one Java Method calls can be decomposed into BEFORE,RETURN and THROWS
Three links , The event detection and process control mechanism of corresponding links are extended in three links . Not only that, but also LINE event , Can complete code line recording .
// BEFORE-EVENT try {   /*    * do something...    */    //LINE-EVENT    a();
   // RETURN-EVENT    return; } catch (Throwable cause) {    // THROWS-EVENT }



be based on BEFORE,RETURN and THROWS Three link events and LINE event , Many classes can be completed AOP Operation of .

*
The input parameters of method call can be sensed and changed

*
You can sense and change the return value of a method call and the exception it throws

*
You can sense which rows a request executes in order

*
Can change the process of method execution

*
Return custom result object directly before method body execution , The original method code will not be executed

*
Reconstruct the new result object before the method body returns , It can even be changed to throw an exception

*
Rethrow the new exception after the method body throws it , It can even change to normal return
JVM-Sandbox What are the possible application scenarios
*
Online fault location

*
Online system flow control

*
Online fault simulation

*
Method request recording and result playback

*
Dynamic log printing

*
Safety information monitoring and desensitization

*
Line link calculation and coverage statistics

JVM Sandbox can also help you do a lot , It depends on how big your brain hole is .
JVM-Sandbox Application in Alibaba Group   Online fault drill
17 The annual fault drill platform JVM-Sandbox Time only 1
Complete system reconfiguration of fault injection in weeks . After reconstruction, the system has a significant improvement in Mount efficiency and mount success rate , Greatly shorten the time of fault drill , Dozens of times more efficient . be based on
JVM-Sandbox Reformed fault drill platform , Strong versatility , All based on JVM All systems started support , Greatly expanded the scope of fault drill , Failure drill has reached group level deployment .

And 16 Comparison of annual failure drill data ,17 Fault drill platform in , cover BU Improved 1.6 times , Coverage application improved 5 times , Coverage improved 37 times .
  Dependency detection
17 In, the strong and weak rely on the birth of automatic detection platform . It provides dependency detection , Strength analysis , Dependency scanning , Fault injection and other capabilities , The underlying capabilities are based on JVM-Sandbox stay 1
Complete function development within weeks . Using the characteristics of its module container , Mount and work together the modules developed by predecessors and new modules , Complete platform functions .

In the aspect of combing strong and weak dependence , It carries the sorting work of Taobao's systematic strong and weak dependence ,260+ Application one key access system , And achieved 0 Automation of labor cost , Intelligent combing .
  Recording isolation playback mechanism of server
stay JVM-Sandbox On the basis of the development of a SS modular , It's like a tape recorder + Playback machine , When invoking Middleware , Recorded our middleware requests in sequence ,
And store this ‘ magnetic tape ’ To server . When we need to isolate playback , Put this ‘ magnetic tape ’ find , And directly from ‘ magnetic tape ’ read , No need to actually request our Middleware ,
This ensures our reading , Write interface can also be reused , So as to realize the isolated playback of the server .


Online recording and isolated playback not only greatly shorten the time of business return , Free the business test students from the tedious data preparation and interface automation script writing process , And greatly expanded the coverage , Make the scope of regression closer to users , And more scenes .
  Precise return

After the birth of the recording isolation playback mechanism of the server , Although it effectively improves the coverage , Reduced manual input of automated scripts , But it also brings new problems . The scenes recorded online are massive , Single system can reach 10000 level , 100000 or even million level recording , In these recorded scenes , There are a lot of repetitive scenes , How to identify repetitive scenes , Effective implementation , Accurate playback , Become a new problem to be solved .

17 In JVM-Sandbox Based on , utilize LineEvnet Line link identification and marking are realized , Effectively improve the accuracy and efficiency of playback .

JVM-Sandbox Alibaba Group has realized the whole network deployment , Loading different modules on it realizes different functions , Each function according to BU And the application needs to be loaded :

*
Strong and weak dependence detection function : Covering Taobao , Tmall , Business platform , green hand , Flying Pig ,ICBU,CBU etc. 7 individual BU,240+ Apps ;

*
Online fault drill function : Covering group customer experience business group , TaoBao , Cloud retail business department , Tmall , Business platform , Flying Pig , green hand , Nail , Ali health ,CBU, Group security , Alipay, etc. 16 individual
BU,391 Apps ;

*
Recording and playback of server : Covering taobao.com , Nail 2 individual BU;

*
Precise return : Covering taobao.com , Business platform , Nail 3 individual BU.

Through the case above , You must be right JVM-Sandbox
What is it? , What are the core functions , What else can be done , And whether we can provide services for students other than Ali , Let's focus on this part .
JVM-Sandbox Technical background
Failure drill , Strong and weak dependence detection , Recording and playback , Precise return , The essence of solving these problems is how to complete them java The method of encircling control and the acquisition of runtime link , Namely AOP
Framework solution . Currently commonly used AOP There are two solutions to the framework :proxy And burying point .proxy The advantage is that the unified
API, Reduced repeat investment , But it doesn't work in real time , System compilation restart required . The advantage of buried point is high dynamic effective flexibility , But there is no unity API.

To solve the above four problems quickly , What we need AOP The solution must have two characteristics :

*
Dynamic pluggable , That is to realize the unity of buried point mode API

*
Noninvasive , I.e. solution JVM The problem of class isolation

Based on the above requirements , We developed JVM-Sandbox.
JVM-Sandbox Core functions of
JVM-Sandbox From pure Java Coding complete , be based on JVMTI technical specifications , It provides a container of plug and play module interface for observing and changing code running results , Provide core functions :

*
Using buried point technology to provide unified API, To achieve a restart free AOP Solution

*
Complete with container JVM Class isolation , To solve invasive problems

*
Provide container management mechanism , To complete the management of various containers
JVM—Sandbox Core event model of
BEFORE,RETURN and THROWS Normal circulation and intervention circulation of three links of events





Isolation and communication
quarantine :

*
Sandbox through custom SandboxClassLoader Break the appointment of parents , Class isolation from observation application . So don't worry about the application pollution caused by loading sandbox , conflict .

*
Class passing between modules of sandbox ModuleClassLoader Achieve their own independence , Between modules , Between module and sandbox , No interference between modules and Applications .

communication

*
Through Bootstrap ClassLoader Middle injection Spy class , Complete observation application and JVM-Sandbox Communications for

*
JVM-Sandbox Events will be distributed to each Module, complete JVM-Sandbox And Module Communication between





Module dynamic management
*
Event monitoring table , Complete module management

*
trasform Method to change native bytecode





Code weaving
insert Spy Class to bytecode ,Spy Reflection call in method JVM-Sandbox Method of .

with BeforeEvent take as an example , Show code weaving .







Overall structure





Sandbox consists of three core functional components

*
Code weaving component

Responsible for rewriting and validation of preset code

*
Event handling distribution component

Responsible for the distribution of events and the implementation of method flow control

*
Module management component

Responsible for controlling and managing all modules of sandbox

The bottom of the sandbox provides a HTTP-SERVER(Jetty), adopt HTTP Agreement complete sandbox.sh Control interaction with sandbox , At the same time, it also provides the basis for each module
HttpServlet and WebSocket canonical API, Each module can reuse sandbox to complete the control and interaction of each module .
Open source and co construction
1, Open source , Seeking more students to improve together JVM-Sandbox Function of .Github address :

https://github.com/alibaba/JVM-Sandbox

2, I hope that some students will join us to improve JVM-Sandbox Function of ;

3, I hope more students can think of more application scenarios , And open source for everyone to use .

To sum up ,JVM-Sandbox It's a pure java Prepared by AOP
Solution . It provides a platform for developers to quickly implement bytecode enhancement tools . Its module management function can maximize the reuse of modules , Collaboration , Reduce repeated investment .

along with JVM-Sandbox Open source of , We expect more people to join in the expansion and optimization of functions , Make it adapt to more open source middleware and JVM.

Hope to have more students , Give full play to his intelligence , Develop more , Better upper module , For yourself and others . I also hope to make good use of the existing modules , Assemble a new tool platform and application scenario .

JVM-Sandbox Construction and application look forward to joint construction .

About the author

Xu Dongchen
, Flower name luanga , Alibaba test development expert ,2010 Joined Alibaba in , Successively responsible for commodity platform , trading platform , Test and development of mobile Taobao , Has been committed to using technology to solve various problems encountered in business testing , Improve test efficiency and system stability . Continuous participation 6 Double eleven , In terms of server stability , Experienced , have a unique view .

original text
<https://mp.weixin.qq.com/s?__biz=MjM5MDE0Mjc4MA==&mid=2651000740&idx=1&sn=bf71c1fb052800600b881b733a14bc50&chksm=bdbef7f78ac97ee1070beb72494ec63af87de24c9be49945b4ab1c565f3bff7c3b31fbfd4898&scene=0#rd>
 


Reprinted for learning and communication only , If you offend, please contact to delete ~