Original  Xu Dong Chen 

Written 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, Real time entry into force, 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 scenarioJVM-Sandbox Target group of
Btrace Very 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 Filtering.

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 is based on JVM-Sandbox Module.
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 intoBEFORE,RETURN andTHROWS
Three links, The event detection and process control mechanism of corresponding links are extended in three links. Not only that, but alsoLINE Event, Can complete code line recording.
// BEFORE-EVENT try {   /*    * do something...    */    //LINE-EVENT    a();
   // RETURN-EVENT    return; } catch (Throwable cause) {    // THROWS-EVENT }

Be based onBEFORE,RETURN andTHROWS Three link events andLINE Event, Many classes can be completed AOP Operation.

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, Versatility, All based 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 Promoted 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 and weakness analysis, Dependency scan, 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 realized. 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, Take 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 regression

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 Year in JVM-Sandbox On the basis of, 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: Cover Taobao, Tmall, Business platform, Green hand, Flying Pig,ICBU,CBU etc. 7 individual BU,240+ One application;

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 One application;

Recording and playback of server: Covering, Nail 2 individual BU;

Precise regression: Covering, Business platform, Nail 3 individual BU.

Through the case above, You must be right JVM-Sandbox
What's this, 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
Fault drill, Strong and weak dependence detection, Recording and playback, Precise regression, 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. Commonly used AOP There are two solutions to the framework:proxy 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, That is to solve JVM The problem of class isolation

Based on the above requirements, We developed JVM-Sandbox.
JVM-Sandbox Core functions of
JVM-Sandbox By pure Java Coding completed, 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

Sandbox through customSandboxClassLoader 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 sandboxModuleClassLoader Achieve their own independence, Between modules, Between module and sandbox, No interference between modules and Applications.


By way of Bootstrap ClassLoader Injection in Spy class, Complete observation application and JVM-Sandbox Communication

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.

with BeforeEvent take as an example, Show code weaving.

Overall framework

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 Protocol 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.Github address:

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

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

Sum up,JVM-Sandbox It's pure. java Compiling AOP
Solution. It provides a platform for developers to quickly implement bytecode enhancement tools. Its module management function can maximize the reuse of modules, Cooperation and cooperation, Reduce repeated investment.

along with JVM-Sandbox Open source, 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, More development, 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.

Author introduction

Xu Dong Chen
, Hua Luan Jia, 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 participation6 Double eleven, In terms of server stability, Experienced, have a unique view.

original text

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