[go: up one dir, main page]

CN109426601B - A method and device for stateless detection of programs - Google Patents

A method and device for stateless detection of programs Download PDF

Info

Publication number
CN109426601B
CN109426601B CN201710582689.7A CN201710582689A CN109426601B CN 109426601 B CN109426601 B CN 109426601B CN 201710582689 A CN201710582689 A CN 201710582689A CN 109426601 B CN109426601 B CN 109426601B
Authority
CN
China
Prior art keywords
variable
initial thread
target program
changed
belongs
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710582689.7A
Other languages
Chinese (zh)
Other versions
CN109426601A (en
Inventor
焦石
蒋启刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201710582689.7A priority Critical patent/CN109426601B/en
Publication of CN109426601A publication Critical patent/CN109426601A/en
Application granted granted Critical
Publication of CN109426601B publication Critical patent/CN109426601B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • G06F11/3624Debugging of software by performing operations on the source code, e.g. via a compiler
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • G06F11/3644Debugging of software by instrumenting at runtime
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

本公开是关于一种对程序进行无状态检测的方法和装置,属于软件编程技术领域。所述方法包括:当检测到针对目标程序进行无状态检测的触发操作后,执行所述目标程序;如果在执行所述目标程序的过程中,监测到所述目标程序的变量发生更改,且所述变量并非被执行所述目标程序所建立的初始线程所更改,则确定所述变量不符合无状态设计原则。通过本发明实施例提供的方法,在执行目标程序的过程中,如果监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。从根源对目标程序中不符合无状态设计原则的变量进行识别,无需人工进行检测,本发明实现了自动化检测的过程。

Figure 201710582689

The present disclosure relates to a method and device for stateless detection of a program, and belongs to the technical field of software programming. The method includes: executing the target program after a triggering operation for stateless detection of the target program is detected; if during the execution of the target program, it is detected that a variable of the target program is changed, and the target program is changed. If the variable is not changed by the initial thread established by executing the target program, it is determined that the variable does not conform to the stateless design principle. With the method provided by the embodiment of the present invention, in the process of executing the target program, if it is monitored that the variable of the target program is changed, and the variable is not changed by the initial thread established by executing the target program, it is determined that the variable does not conform to the stateless design in principle. The variables in the target program that do not conform to the stateless design principle are identified from the root cause without manual detection, and the invention realizes the process of automatic detection.

Figure 201710582689

Description

一种对程序进行无状态检测的方法和装置A method and device for stateless detection of programs

技术领域technical field

本公开是关于软件编程技术领域,尤其是关于一种对程序进行无状态检测的方法和装置。The present disclosure relates to the technical field of software programming, and in particular, to a method and apparatus for stateless detection of a program.

背景技术Background technique

在2000年Roy Fielding发表的博士论文《Architectural styles and thedesign of network-based software architectures(架构风格和基于网络的程序架构设计)》中,REST(Representational State Transfer,表征性状态转移)的概念被首次提出,REST是针对以网络服务为基础的程序所提出的,其中,以网络服务为基础的程序是指服务器为了响应客户端的请求所执行的程序。REST描述的是程序设计架构的约束条件和设计原则,如果一个程序的设计架构符合REST的约束条件和设计原则,那么该程序的设计架构就是RESTful架构。具有RESTful架构的程序比一般的程序更简洁,在客户端与服务器的交互过程中更易于实现缓存等机制。The concept of REST (Representational State Transfer) was first proposed in Roy Fielding's doctoral dissertation "Architectural styles and the design of network-based software architectures" in 2000. , REST is proposed for the program based on network service, wherein, the program based on network service refers to the program executed by the server in response to the request of the client. REST describes the constraints and design principles of the program design architecture. If the design architecture of a program conforms to the constraints and design principles of REST, then the design architecture of the program is a RESTful architecture. A program with a RESTful architecture is more concise than a general program, and it is easier to implement mechanisms such as caching in the interaction between the client and the server.

要实现RESTful架构就需要满足RESTful架构设计所需的五大约束条件和设计原则。在上述五大约束条件和设计原则中,最重要的一个约束条件和设计原则,也是本文讨论的重点,就是:所有在服务器中的操作都是无状态的。如果满足上述条件,也就满足了无状态设计原则。To implement a RESTful architecture, it is necessary to meet the five constraints and design principles required for RESTful architecture design. Among the above five constraints and design principles, the most important one, which is also the focus of this article, is that all operations in the server are stateless. If the above conditions are met, the stateless design principle is also met.

所谓无状态设计原则,是指服务器不能储存任何客户端的状态相关信息如用户名、密码信息。客户端向服务器发起的每次请求都是独立的,是不能依赖之前发起过的请求的。客户端向服务器发起的每次请求中应该包含服务器处理该请求所需要的全部信息。因此,所有客户端的状态相关信息都应该保存在客户端,在每次客户端向服务器发送请求时,都再发一次客户端的状态相关信息,服务器不需要保存任何客户端的状态相关信息。以此,可以节省服务器的内存空间,而且当一台服务器发生故障时,可以迅速以另一台备用服务器替换发生故障的服务器工作,同时客户端可以马上与备用服务器继续正常进行通信。通过以上可知,程序可以满足无状态设计原则的重要性非常高。The so-called stateless design principle means that the server cannot store any client state-related information such as user name and password information. Each request that the client initiates to the server is independent and cannot rely on previous requests. Each request from the client to the server should contain all the information the server needs to process the request. Therefore, all the state-related information of the client should be stored on the client. Each time the client sends a request to the server, the client's state-related information is sent again, and the server does not need to store any client's state-related information. In this way, the memory space of the server can be saved, and when a server fails, the failed server can be quickly replaced with another backup server, and the client can continue to communicate with the backup server normally. From the above, we can see that it is very important that the program can meet the principle of stateless design.

在实现本公开的过程中,发明人发现至少存在以下问题:In the process of realizing the present disclosure, the inventor found at least the following problems:

当程序员编写好一段程序之后,要怎么样进行程序的无状态检测呢?换句话说,要怎么样才能知道自己所编写的程序是不是满足无状态设计原则呢?或者,以前编写好的旧程序是不是满足无状态设计原则呢?在现有技术中,都是依靠人工对代码一行一行的去排查。然而对于规模庞大的程序代码,人为排查就显得不可靠了。After the programmer has written a program, how to perform stateless detection of the program? In other words, how do you know if your program meets the stateless design principles? Or, does the old program written in the past satisfy the principle of stateless design? In the prior art, the code is checked line by line manually. However, for large-scale program code, manual inspection is unreliable.

发明内容SUMMARY OF THE INVENTION

为了克服相关技术中存在的问题,本公开提供了以下技术方案:In order to overcome the problems existing in the related art, the present disclosure provides the following technical solutions:

第一方面,提供了一种对程序进行无状态检测的方法,该方法包括:当检测到针对目标程序进行无状态检测的触发操作后,执行目标程序;如果在执行目标程序的过程中,监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。A first aspect provides a method for stateless detection of a program, the method comprising: after detecting a trigger operation for stateless detection of a target program, executing the target program; if in the process of executing the target program, monitoring If the variable to the target program changes, and the variable is not changed by the initial thread established by executing the target program, it is determined that the variable does not conform to the stateless design principle.

通过本发明实施例提供的方法,在执行目标程序的过程中,如果监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。从根源对目标程序中不符合无状态设计原则的变量进行识别,无需人工进行检测,本发明实现了自动化检测的过程。With the method provided by the embodiment of the present invention, in the process of executing the target program, if it is monitored that the variables of the target program are changed, and the variables are not changed by the initial thread established by executing the target program, it is determined that the variables do not conform to the stateless design. in principle. The variables in the target program that do not conform to the stateless design principle are identified from the root cause without manual detection, and the invention realizes the process of automatic detection.

在一种可能的实现方式中,监测目标程序的变量是否发生更改,包括:通过JVMTI接口监测变量是否发生更改。In a possible implementation manner, monitoring whether the variables of the target program are changed includes: monitoring whether the variables are changed through the JVMTI interface.

可以通过JVMTI接口监测变量是否发生更改。JVMTI接口是Java虚拟机的native编程接口,如果使用JVMTI接口就要涉及Java虚拟机底层的C(一种编程语言)层以及JNI(Javanative interface,Java本地接口)接口的内容。在实际应用中,可以建立一个代理Agent方式来使用JVMTI接口,Agent方式可以使用JVMTI接口的函数,设置回调函数,并从Java虚拟机中得到当前线程的运行态信息,最后还可以对Java虚拟机的运行态进行操作。Variables can be monitored for changes through the JVMTI interface. The JVMTI interface is the native programming interface of the Java virtual machine. If the JVMTI interface is used, it involves the content of the C (a programming language) layer at the bottom of the Java virtual machine and the JNI (Javanative interface, Java native interface) interface. In practical applications, an agent agent method can be established to use the JVMTI interface. The agent method can use the functions of the JVMTI interface, set the callback function, and obtain the running state information of the current thread from the Java virtual machine. operation in the running state.

在一种可能的实现方式中,判断变量是否被执行目标程序所建立的初始线程所更改,包括:根据变量所属的变量类型,确定与变量对应的判断方式,并根据判断方式,判断变量是否被初始线程所更改,其中,判断方式是用于判断变量是否被初始线程所更改的方式。In a possible implementation manner, judging whether the variable is changed by the initial thread established by executing the target program includes: determining a judgment method corresponding to the variable according to the variable type to which the variable belongs, and judging whether the variable is changed according to the judgment method. Changed by the initial thread, wherein the judgment method is a method for judging whether the variable is changed by the initial thread.

根据变量的变量类型,确定与变量对应的判断变量是否被初始线程所更改的方式。According to the variable type of the variable, the method corresponding to the variable is determined to determine whether the variable has been changed by the initial thread.

在一种可能的实现方式中,变量类型包括静态变量和成员变量。In one possible implementation, the variable types include static variables and member variables.

在具体应用场景中,由于不同的变量类型对应的变量在使用中具有不同的特点,如静态变量可能会被全局程序修改,而成员变量只可能被对象修改,在对象应用完成之后会被销毁,成员变量也会被随之被销毁。所以,对于不同的变量要用不同的判断方式来判断变量是否被执行目标程序所建立的初始线程所更改。In specific application scenarios, because the variables corresponding to different variable types have different characteristics in use, for example, static variables may be modified by the global program, while member variables may only be modified by objects and will be destroyed after the object application is completed. Member variables will also be destroyed accordingly. Therefore, different judgment methods are used for different variables to judge whether the variables are changed by the initial thread established by the execution target program.

在一种可能的实现方式中,根据变量的变量类型,确定与变量对应的判断方式,并根据判断方式,判断变量是否被初始线程所更改,包括:如果变量属于静态变量,则确定与静态变量对应的判断方式为:如果静态变量所属的类未装载于初始线程中,则静态变量并非被初始线程所更改;如果变量属于成员变量,则确定与成员变量对应的判断方式为:如果成员变量所属的对象未在初始线程中生成,则成员变量并非被初始线程所更改。In a possible implementation manner, the judgment method corresponding to the variable is determined according to the variable type of the variable, and according to the judgment method, it is judged whether the variable is changed by the initial thread, including: if the variable belongs to a static variable, then determine whether the variable is changed with the static variable. The corresponding judgment method is: if the class to which the static variable belongs is not loaded in the initial thread, the static variable is not changed by the initial thread; if the variable belongs to a member variable, the judgment method corresponding to the member variable is determined as: if the member variable belongs to The object is not generated in the initial thread, the member variables are not changed by the initial thread.

根据变量的变量类型,确定使用与变量对应的判断变量是否被初始线程所更改。According to the variable type of the variable, it is determined whether the variable corresponding to the variable is used to determine whether the variable was changed by the initial thread.

在一种可能的实现方式中,如果静态变量所属的类未装载于初始线程中,则静态变量并非被初始线程所更改,包括:确定初始线程对应的堆栈;如果在堆栈中未查找到静态变量所属的类,则静态变量所属的类未装载于初始线程中,静态变量并非被初始线程所更改;如果成员变量所属的对象未在初始线程中生成,则成员变量并非被初始线程所更改,包括:确定成员变量所属的对象所绑定的标签,如果在初始线程附加的标签列表中不存在标签,则成员变量所属的对象未在初始线程中生成,成员变量并非被初始线程所更改。In a possible implementation, if the class to which the static variable belongs is not loaded in the initial thread, the static variable is not changed by the initial thread, including: determining the stack corresponding to the initial thread; if the static variable is not found in the stack If the class to which the static variable belongs, the class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread; if the object to which the member variable belongs is not generated in the initial thread, the member variable is not changed by the initial thread, including : Determine the label bound to the object to which the member variable belongs. If there is no label in the list of labels attached by the initial thread, the object to which the member variable belongs is not generated in the initial thread, and the member variable is not changed by the initial thread.

根据变量的变量类型,确定使用与变量对应的判断变量是否被初始线程所更改。对于静态变量,在执行目标函数时,静态变量所属的类是直接被装载于初始线程对应的堆栈中的,以准备被调用。因此,如果在初始线程对应的堆栈未查找到该静态变量的类,则该静态变量所属的类未装载于初始线程中,该静态变量并非被初始线程所更改。该静态变量很有可能是被客户端线程所更改的。对于成员变量,当监测到成员变量发生更改时,确定该成员变量所属的对象所绑定的标签,如果在初始线程附加的标签列表中不存在该标签,则成员变量所属的对象未在初始线程中生成,成员变量并非被初始线程所更改。在一种可能的实现方式中,标签列表存储于初始线程对应的局部存储器中。According to the variable type of the variable, it is determined whether the variable corresponding to the variable is used to determine whether the variable was changed by the initial thread. For static variables, when the target function is executed, the class to which the static variable belongs is directly loaded into the stack corresponding to the initial thread, ready to be called. Therefore, if the class of the static variable is not found on the stack corresponding to the initial thread, the class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread. It is very likely that the static variable was changed by the client thread. For member variables, when a change is detected in the member variable, the label bound to the object to which the member variable belongs is determined. If the label does not exist in the label list attached by the initial thread, the object to which the member variable belongs is not in the initial thread. , the member variables were not changed by the initial thread. In a possible implementation, the tag list is stored in the local memory corresponding to the initial thread.

为标签列表专门开辟一块空间进行存储。Dedicate a space for the label list to be stored.

在一种可能的实现方式中,该方法还包括:在开始执行目标程序的入口函数时,建立标签列表;当在执行目标程序的过程中,检测到发生对象创建事件时,将创建的对象绑定上标签;将标签存入标签列表中。In a possible implementation manner, the method further includes: when starting to execute the entry function of the target program, establishing a label list; when detecting that an object creation event occurs during the execution of the target program, binding the created object to Set a label; save the label to the label list.

提供了标签列表的建立方式,和标签的存储方式。可以监测是否有对象被创建,在目标程序中,如果执行到带有关键字“new”的语句,可能会创建一个新的对象。当监测到发生对象创建事件时,可以将该对象绑定上标签,并将标签存入标签列表中。Provides how to create a list of labels and how to store labels. It is possible to monitor whether an object is created. In the target program, if a statement with the keyword "new" is executed, a new object may be created. When an object creation event is detected, the object can be bound to a tag, and the tag can be stored in the tag list.

第二方面,提供了一种对程序进行无状态检测的装置,该装置包括至少一个模块,该至少一个模块用于实现上述第一方面所提供的执行任务的方法。In a second aspect, an apparatus for stateless detection of a program is provided. The apparatus includes at least one module, and the at least one module is used to implement the method for executing a task provided in the first aspect.

第三方面,提供了一种服务器,该服务器包括处理器、存储器,处理器被配置为执行存储器中存储的指令;处理器通过执行指令来实现上述第一方面所提供的执行任务的方法。In a third aspect, a server is provided, the server includes a processor and a memory, the processor is configured to execute instructions stored in the memory; the processor implements the method for executing a task provided in the first aspect by executing the instructions.

第四方面,提供了计算机可读存储介质,包括指令,当所述计算机可读存储介质在服务器上运行时,使得所述服务器执行上述第一方面所述的方法。In a fourth aspect, a computer-readable storage medium is provided, comprising instructions that, when the computer-readable storage medium runs on a server, cause the server to perform the method described in the first aspect.

第五方面,提供了一种包含指令的计算机程序产品,当所述计算机程序产品在服务器上运行时,使得所述服务器执行上述第一方面所述的方法。In a fifth aspect, there is provided a computer program product comprising instructions, which, when the computer program product is run on a server, cause the server to perform the method described in the first aspect above.

上述本发明实施例第二到第五方面所获得的技术效果与第一方面中对应的技术手段获得的技术效果近似,在这里不再赘述。The technical effects obtained by the second to fifth aspects of the above embodiments of the present invention are similar to the technical effects obtained by the corresponding technical means in the first aspect, and will not be repeated here.

本公开的实施例提供的技术方案可以包括以下有益效果:The technical solutions provided by the embodiments of the present disclosure may include the following beneficial effects:

通过本发明实施例提供的方法,在执行目标程序的过程中,如果监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。从根源对目标程序中不符合无状态设计原则的变量进行识别,无需人工进行检测,本发明实现了自动化检测的过程。With the method provided by the embodiment of the present invention, in the process of executing the target program, if it is monitored that the variables of the target program are changed, and the variables are not changed by the initial thread established by executing the target program, it is determined that the variables do not conform to the stateless design. in principle. The variables in the target program that do not conform to the stateless design principle are identified from the root cause without manual detection, and the invention realizes the process of automatic detection.

应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本公开。It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.

附图说明Description of drawings

此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本公开的实施例,并与说明书一起用于解释本公开的原理。在附图中:The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description serve to explain the principles of the disclosure. In the attached image:

图1是根据一示例性实施例示出的一种服务器的结构示意图;FIG. 1 is a schematic structural diagram of a server according to an exemplary embodiment;

图2是根据一示例性实施例示出的一种对程序进行无状态检测的方法的流程图;FIG. 2 is a flowchart of a method for performing stateless detection on a program according to an exemplary embodiment;

图3是根据一示例性实施例示出的一种对程序进行无状态检测的流程图示意图;3 is a schematic flowchart of a stateless detection of a program according to an exemplary embodiment;

图4是根据一示例性实施例示出的一种对程序进行无状态检测的应用示意图;FIG. 4 is a schematic diagram of an application for performing stateless detection on a program according to an exemplary embodiment;

图5是根据一示例性实施例示出的一种对程序进行无状态检测的装置的示意图;FIG. 5 is a schematic diagram of an apparatus for performing stateless detection on a program according to an exemplary embodiment;

图6是根据一示例性实施例示出的一种对程序进行无状态检测的装置的示意图。Fig. 6 is a schematic diagram of an apparatus for performing stateless detection on a program according to an exemplary embodiment.

通过上述附图,已示出本公开明确的实施例,后文中将有更详细的描述。这些附图和文字描述并不是为了通过任何方式限制本公开构思的范围,而是通过参考特定实施例为本领域技术人员说明本公开的概念。The above-mentioned drawings have shown clear embodiments of the present disclosure, and will be described in more detail hereinafter. These drawings and written descriptions are not intended to limit the scope of the disclosed concepts in any way, but rather to illustrate the disclosed concepts to those skilled in the art by referring to specific embodiments.

具体实施方式Detailed ways

这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本公开相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本公开的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. Where the following description refers to the drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the illustrative examples below are not intended to represent all implementations consistent with this disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as recited in the appended claims.

本发明实施例提供了一种对程序进行无状态检测的方法,该方法的执行主体可以为服务器。An embodiment of the present invention provides a method for stateless detection of a program, and the execution body of the method may be a server.

图1是根据一示例性实施例示出的服务器1900的框图。参照图1,服务器1900包括处理器1922,以及由存储器1932所代表的存储器资源,用于存储可由处理器1922的执行的指令,例如应用程序。存储器1932中存储的应用程序可以包括一个或一个以上的每一个对应于一组指令的模块。此外,处理器1922被配置为执行指令,以执行对程序进行无状态检测的方法。FIG. 1 is a block diagram of a server 1900 according to an exemplary embodiment. 1, the server 1900 includes a processor 1922, and memory resources, represented by memory 1932, for storing instructions executable by the processor 1922, such as application programs. An application program stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Additionally, the processor 1922 is configured to execute instructions to perform a method of stateless detection of a program.

服务器1900还可以包括一个电源组件1926被配置为执行服务器1900的电源管理,一个有线或无线网络接口1950被配置为将服务器1900连接到网络,和一个输入输出(I/O)接口1958。服务器1900可以操作基于存储在存储器1932的操作系统,例如WindowsServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM或类似。The server 1900 may also include a power supply assembly 1926 configured to perform power management of the server 1900, a wired or wireless network interface 1950 configured to connect the server 1900 to a network, and an input output (I/O) interface 1958. Server 1900 may operate based on an operating system stored in memory 1932, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.

服务器1900可以包括有存储器1932,以及一个或者一个以上的程序,其中一个或者一个以上程序存储于存储器1932中。Server 1900 may include memory 1932, and one or more programs, wherein one or more programs are stored in memory 1932.

本公开一示例性实施例提供了一种对程序进行无状态检测的方法,如图2所示,该方法的处理流程可以包括如下的步骤:An exemplary embodiment of the present disclosure provides a method for stateless detection of a program. As shown in FIG. 2 , the processing flow of the method may include the following steps:

步骤S210,当检测到针对目标程序进行无状态检测的触发操作后,执行目标程序。Step S210, after detecting a trigger operation for stateless detection of the target program, execute the target program.

其中,目标程序是指需要进行无状态检测的程序,目标程序一般是由Java(一种面向对象的编程语言)进行编程的。The target program refers to a program that needs to perform stateless detection, and the target program is generally programmed by Java (an object-oriented programming language).

在本发明实施例中,是使目标程序运行起来,在目标程序的运行过程中,监测目标程序的运行情况,来发现目标程序中违反无状态设计原则的相关代码。在运行完整个目标程序之后,将在目标程序运行过程中发现的问题一一输出在报告中,以提示程序员问题所在之处。在报告中,可以将产生问题的代码所在的文件、行号进行标识。In the embodiment of the present invention, the target program is run, and during the running process of the target program, the running status of the target program is monitored to find out the relevant code in the target program that violates the principle of stateless design. After running the entire target program, the problems found during the running of the target program will be output in the report one by one to prompt the programmer where the problem lies. In the report, you can identify the file and line number where the code that caused the problem is located.

步骤S220,如果在执行目标程序的过程中,监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。Step S220, if it is detected that the variable of the target program is changed during the execution of the target program, and the variable is not changed by the initial thread established by executing the target program, it is determined that the variable does not conform to the stateless design principle.

在服务器1900中,服务器1900在执行目标程序时,会建立相应的初始线程来执行目标程序。一台服务器1900一般会对应多个客户端,当每个客户端向服务器1900发送请求时,在服务器1900中会为每个请求专门建立一个客户端线程去处理这些请求。由于线程之间是可以交互的,因此客户端线程可以修改服务器1900的初始线程中的数据如目标程序运行中的变量。当服务器1900的程序的设计架构不满足无状态设计原则时,服务器1900需要将客户端的状态相关信息进行存储,那么客户端线程就要更改服务器1900的初始线程中的用于存储客户端的状态相关信息的变量,至此就会产生跨线程变量更改事件。故而,本发明实施例针对上述跨线程变量更改事件进行检测,以监测目标程序中不符合无状态设计原则的变量。In the server 1900, when the server 1900 executes the target program, it will establish a corresponding initial thread to execute the target program. A server 1900 generally corresponds to multiple clients. When each client sends a request to the server 1900, a client thread is specially established in the server 1900 for each request to process the requests. Since the threads can interact, the client thread can modify the data in the initial thread of the server 1900, such as the variables in the running of the target program. When the design architecture of the program of the server 1900 does not meet the stateless design principle, the server 1900 needs to store the state-related information of the client, then the client thread needs to change the state-related information used to store the client in the initial thread of the server 1900 variable, and a cross-thread variable change event will be generated. Therefore, the embodiments of the present invention detect the above-mentioned cross-thread variable change event to monitor variables in the target program that do not conform to the principle of stateless design.

在实施中,在开始执行目标程序的入口函数时,利用代码注入技术,在不改变原有目标程序的情况下,可以将本实施例所述方法对应的代码注入到目标程序中,以在目标程序边执行的同时,边对目标程序进行监测。In the implementation, when starting to execute the entry function of the target program, using the code injection technology, without changing the original target program, the code corresponding to the method described in this embodiment can be injected into the target program, so that the target program can be injected into the target program. While the program is executing, the target program is monitored.

可选地,监测目标程序的变量是否发生更改的步骤包括:通过JVMTI(JVM ToolInterface,Java虚拟机工具)接口监测变量是否发生更改。Optionally, the step of monitoring whether a variable of the target program changes includes: monitoring whether the variable changes through a JVMTI (JVM ToolInterface, Java Virtual Machine Tool) interface.

其中,JVMTI接口是Java虚拟机所提供的本地(native)编程接口,是JVMPI(JavaVirtual Machine Profiler Interface,Java虚拟机分析接口)和JVMDI(Java VirtualMachine Debug Interface,Java虚拟机调试接口)的更新版本。从JVMTI接口的发展历史轨迹中就可以知道,JVMTI接口提供了分析和调试Java程序的功能。与此同时,在Java第五版本中,JVMTI接口也增加了监听(Monitoring)、线程分析(Thread analysis)以及覆盖率分析(Coverage Analysis)等功能。JVMTI接口的强大功能使得一些Java调试器以及其它Java运行态测试与分析工具的实现。The JVMTI interface is a native programming interface provided by the Java virtual machine, and is an updated version of JVMPI (Java Virtual Machine Profiler Interface, Java Virtual Machine Analysis Interface) and JVMDI (Java Virtual Machine Debug Interface, Java Virtual Machine Debug Interface). It can be known from the development history of the JVMTI interface that the JVMTI interface provides the function of analyzing and debugging Java programs. At the same time, in the fifth version of Java, the JVMTI interface also adds functions such as Monitoring, Thread analysis, and Coverage Analysis. The power of the JVMTI interface enables the implementation of some Java debuggers and other Java runtime testing and analysis tools.

JVMTI接口是Java虚拟机的native编程接口,如果使用JVMTI接口就要涉及Java虚拟机底层的C层以及JNI接口的内容。在实际应用中,可以建立一个代理Agent方式来使用JVMTI接口,Agent方式可以使用JVMTI接口的函数,设置回调函数,并从Java虚拟机中得到当前线程的运行态信息,最后还可以对Java虚拟机的运行态进行操作。The JVMTI interface is the native programming interface of the Java virtual machine. If the JVMTI interface is used, the C layer at the bottom of the Java virtual machine and the content of the JNI interface are involved. In practical applications, an agent agent method can be established to use the JVMTI interface. The agent method can use the functions of the JVMTI interface, set the callback function, and obtain the running state information of the current thread from the Java virtual machine. operation in the running state.

在实施中,当执行目标程序时,会装载目标程序中的类,对于类中的变量,可以通过JVMTI接口进行监测。如图3所示,在Java层,目标程序从入口函数处开始执行。在C层,通过JVMTI接口实时监测目标程序中的变量是否发生更改。当监测到变量发生更改时,通过JVMTI接口将更改的变量发送到无状态检测识别引擎中的识别器中。在识别器中,可以判断更改的变量是否被执行目标程序所建立的初始线程所更改,确定该变量符不符合无状态设计原则。In the implementation, when the target program is executed, the classes in the target program are loaded, and the variables in the classes can be monitored through the JVMTI interface. As shown in Figure 3, in the Java layer, the target program starts to execute from the entry function. In the C layer, whether the variables in the target program are changed in real time is monitored through the JVMTI interface. When a variable is detected, the changed variable is sent to the recognizer in the stateless detection recognition engine through the JVMTI interface. In the identifier, it can be judged whether the changed variable is changed by the initial thread established by executing the target program, and it can be determined that the variable identifier does not conform to the principle of stateless design.

需要说明的是,在具体执行上述方法的过程中,服务器1900是先加载C层的内容,再去加载Java层的内容的。It should be noted that, during the specific execution of the above method, the server 1900 first loads the content of the C layer, and then loads the content of the Java layer.

可选地,变量存在多种,对于不同的变量类型应有不同的监测处理方式。相应地,判断变量是否被执行目标程序所建立的初始线程所更改的步骤包括:根据变量所属的变量类型,确定与变量对应的判断方式,并根据判断方式,判断变量是否被初始线程所更改,其中,判断方式是用于判断变量是否被初始线程所更改的方式。Optionally, there are multiple variables, and there should be different monitoring and processing methods for different variable types. Correspondingly, the step of judging whether the variable is changed by the initial thread established by the execution target program comprises: according to the variable type to which the variable belongs, determining a judgment method corresponding to the variable, and according to the judgment method, judging whether the variable is changed by the initial thread, Among them, the judgment method is a method for judging whether the variable is changed by the initial thread.

可选地,变量类型包括静态变量和成员变量。Optionally, variable types include static variables and member variables.

需要说明的是,在具体应用场景中,由于不同的变量类型对应的变量在使用中具有不同的特点,如静态变量可能会被全局程序修改,而成员变量只可能被对象修改,在对象应用完成之后会被销毁,成员变量也会被随之被销毁。所以,对于不同的变量要用不同的判断方式来判断变量是否被执行目标程序所建立的初始线程所更改。以下针对静态变量和成员变量这两种变量类型分别进行判断变量是否被执行目标程序所建立的初始线程所更改的方式的说明:It should be noted that, in specific application scenarios, the variables corresponding to different variable types have different characteristics in use. For example, static variables may be modified by the global program, while member variables may only be modified by objects. After that, it will be destroyed, and the member variable will also be destroyed. Therefore, different judgment methods are used for different variables to judge whether the variables are changed by the initial thread established by the execution target program. The following describes how to judge whether the variable is changed by the initial thread established by the execution target program for the two types of variables: static variable and member variable:

可选地,根据变量的变量类型,确定与变量对应的判断方式,并根据判断方式,判断变量是否被初始线程所更改的步骤包括:Optionally, according to the variable type of the variable, determine the judgment mode corresponding to the variable, and according to the judgment mode, the steps of judging whether the variable is changed by the initial thread include:

首先,如果变量属于静态变量,则确定与静态变量对应的判断方式为:如果静态变量所属的类未装载于初始线程中,则静态变量并非被初始线程所更改。First, if the variable is a static variable, the judgment method corresponding to the static variable is determined as follows: if the class to which the static variable belongs is not loaded in the initial thread, the static variable is not changed by the initial thread.

在实施中,当监测到变量发生更改,接下来就可以判断该更改的变量所述的变量类型,如果是静态变量,则判断静态变量所属的类是否装载于初始线程中。In implementation, when it is detected that the variable is changed, the variable type described by the changed variable can be determined next, and if it is a static variable, it is determined whether the class to which the static variable belongs is loaded in the initial thread.

其次,如果变量属于成员变量,则确定与成员变量对应的判断方式为:如果成员变量所属的对象未在初始线程中生成,则成员变量并非被初始线程所更改。Secondly, if the variable belongs to a member variable, the judgment method corresponding to the member variable is determined as follows: if the object to which the member variable belongs is not generated in the initial thread, the member variable is not changed by the initial thread.

在实施中,当监测到变量发生更改,依然判断该更改的变量所述的变量类型,如果是成员变量,则判断成员变量所属的对象是否在初始线程中生成。In the implementation, when a change of a variable is detected, the variable type described by the changed variable is still judged, and if it is a member variable, it is judged whether the object to which the member variable belongs is generated in the initial thread.

可选地,接下来提供的方法可以用于判断静态变量所属的类是否装载于初始线程中或者成员变量所属的对象是否在初始线程中生成。Optionally, the method provided next can be used to determine whether the class to which the static variable belongs is loaded in the initial thread or whether the object to which the member variable belongs is generated in the initial thread.

相应地,如果静态变量所属的类未装载于初始线程中,则静态变量并非被初始线程所更改的步骤包括:确定初始线程对应的堆栈;如果在堆栈中未查找到静态变量所属的类,则静态变量所属的类未装载于初始线程中,静态变量并非被初始线程所更改。Correspondingly, if the class to which the static variable belongs is not loaded in the initial thread, the steps that the static variable is not changed by the initial thread include: determining the stack corresponding to the initial thread; if the class to which the static variable belongs is not found in the stack, then The class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread.

在实施中,在执行目标函数时,静态变量所属的类是直接被装载于初始线程对应的堆栈中的,以准备被调用。因此,如果在初始线程对应的堆栈未查找到该静态变量的类,则该静态变量所属的类未装载于初始线程中,该静态变量并非被初始线程所更改。该静态变量很有可能是被客户端线程所更改的。在客户端线程更改该静态变量时,首先客户端线程会将该静态变量所属的类装载于自己的堆栈中。该静态变量则具有被不同线程读写的属性。进而,该静态变量不符合无状态设计原则,可以将该静态变量输出在检测报告中。需要说明的是,如果在堆栈中未查找到该静态变量的所属的类,则可以在检测报告中也将该静态变量作为低级别错误如WARNING报出来。因为,当静态变量所属的类未装载于初始线程中,可以确定该静态变量并非被初始线程所更改,此时可以将该静态变量作为高级别错误如ERROR报出来,而当静态变量所属的类装载于初始线程中,对于该静态变量是否是被初始线程所更改是不确定的。In implementation, when the target function is executed, the class to which the static variable belongs is directly loaded into the stack corresponding to the initial thread to prepare to be called. Therefore, if the class of the static variable is not found on the stack corresponding to the initial thread, the class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread. It is very likely that the static variable was changed by the client thread. When the client thread changes the static variable, first the client thread will load the class to which the static variable belongs to its own stack. The static variable has the property of being read and written by different threads. Furthermore, the static variable does not conform to the principle of stateless design, and the static variable can be output in the detection report. It should be noted that, if the class to which the static variable belongs is not found in the stack, the static variable may also be reported as a low-level error such as WARNING in the detection report. Because, when the class to which the static variable belongs is not loaded in the initial thread, it can be determined that the static variable is not changed by the initial thread. At this time, the static variable can be reported as a high-level error such as ERROR, and when the class to which the static variable belongs Loaded in the initial thread, it is not certain whether the static variable was changed by the initial thread.

如果成员变量所属的对象未在初始线程中生成,则成员变量并非被初始线程所更改的步骤包括:确定成员变量所属的对象所绑定的标签,如果在初始线程附加的标签列表中不存在标签,则成员变量所属的对象未在初始线程中生成,成员变量并非被初始线程所更改。If the object to which the member variable belongs is not generated in the initial thread, the member variables are not changed by the initial thread. , the object to which the member variable belongs is not generated in the initial thread, and the member variable is not changed by the initial thread.

可选地,标签列表存储于初始线程对应的局部存储器中。Optionally, the tag list is stored in the local memory corresponding to the initial thread.

可选地,本实施例提供的方法还包括在开始执行目标程序的入口函数时,建立标签列表;当在执行目标程序的过程中,检测到发生对象创建事件时,将创建的对象绑定上标签;将标签存入标签列表中。Optionally, the method provided by this embodiment also includes establishing a label list when starting to execute the entry function of the target program; when detecting that an object creation event occurs in the process of executing the target program, binding the created object to the target program. label; saves the label to the label list.

在实施中,在开始执行目标程序的入口函数时,声明一个标签列表。该标签列表可以使用Java提供的List、Set等数据结构进行声明。当声明好标签列表后,将该标签列表存储于初始线程对应的局部存储器中。该局部存储器是专门为该初始线程所开辟的一块内存空间,只为该初始线程所使用。因此,可以保障只有初始线程可以对标签列表进行操作,以防止其他线程对标签列表的更改。In implementation, a list of labels is declared when starting to execute the entry function of the target program. The tag list can be declared using data structures such as List and Set provided by Java. After the tag list is declared, the tag list is stored in the local memory corresponding to the initial thread. The local memory is a memory space specially opened up for the initial thread, and is only used by the initial thread. Therefore, it is guaranteed that only the initial thread can operate on the tag list, preventing changes to the tag list by other threads.

接着,可以监测是否有对象被创建,在目标程序中,如果执行到带有关键字“new”的语句,可能会创建一个新的对象。当监测到发生对象创建事件时,可以将该对象绑定上标签tag,并将tag存入标签列表中。需要说明的是,对象本身存在标识,但是该标识比较类似于指针,该指针指向于对象。因此,对象标识随着目标程序的运行,或者其他线程的运行,对象标识会从指向对象A变为指向对象B,或者直接消失,或者存在多个相同的对象标识。因此,如图3所示,为了在上述情况中,对对象进行唯一标识并进行追踪,在检测到有新的对象被创建时,通过JNI接口,将该对象从Java层传至C层的JVMTI接口,再由JVMTI接口将该对象传至无状态检测引擎中,以在标签生成器中将该对象绑定上tag。Next, it is possible to monitor whether an object is created. In the target program, if a statement with the keyword "new" is executed, a new object may be created. When an object creation event is detected, the object can be bound to a tag, and the tag can be stored in the tag list. It should be noted that the object itself has an identifier, but the identifier is similar to a pointer, and the pointer points to the object. Therefore, with the running of the target program or the running of other threads, the object identification will change from pointing to object A to pointing to object B, or disappear directly, or there are multiple identical object identifications. Therefore, as shown in Figure 3, in order to uniquely identify and track the object in the above situation, when a new object is detected to be created, the object is passed from the Java layer to the JVMTI of the C layer through the JNI interface. interface, and then pass the object to the stateless detection engine through the JVMTI interface to bind the object with a tag in the tag generator.

最后,当监测到成员变量发生更改时,确定该成员变量所属的对象所绑定的tag,如果在初始线程附加的标签列表中不存在该tag,则成员变量所属的对象未在初始线程中生成,成员变量并非被初始线程所更改。需要说明的是,标签列表是专用于记录初始线程所创建的对象的,当发现成员变量所属的对象不存在tag或者所绑定的tag不在初始线程附加的标签列表中,则证明该成员变量所属的对象不是由初始线程所创建的,那么极有可能是被客户端线程所创建的,进而,成员变量并非被初始线程所更改。Finally, when it is detected that the member variable changes, the tag bound to the object to which the member variable belongs is determined. If the tag does not exist in the list of tags attached by the initial thread, the object to which the member variable belongs is not generated in the initial thread. , member variables were not changed by the initial thread. It should be noted that the tag list is dedicated to recording the objects created by the initial thread. When it is found that the object to which the member variable belongs does not have a tag or the bound tag is not in the tag list attached by the initial thread, it is proved that the member variable belongs to The object is not created by the initial thread, then it is most likely created by the client thread, and further, the member variables are not changed by the initial thread.

在执行完毕步骤S220之后,可选地,可以判断是否执行完目标程序,如果还未执行完目标程序,则可以重复执行步骤S220,以将整个目标程序运行完,并检测目标程序中所有的变量。在执行完目标程序后,并检测出所有的不符合无状态设计原则的变量后,可以将检测到的问题以报告的形式输出出来,以展示给程序员。After step S220 is executed, optionally, it can be determined whether the target program has been executed. If the target program has not been executed, step S220 can be repeatedly executed to run the entire target program and detect all variables in the target program. . After the target program is executed and all variables that do not conform to the stateless design principle are detected, the detected problems can be output in the form of a report to be displayed to the programmer.

可选地,在建立标签列表时,为初始线程专门开辟了一块内存作为初始线程的局部存储器,该局部存储器不会在目标程序执行完毕之后,自动清空,而是需要人工在目标程序将要执行完毕之前,进行清空,否则会造成内存泄露的问题。Optionally, when establishing the label list, a piece of memory is specially opened for the initial thread as the local memory of the initial thread. The local memory will not be automatically emptied after the execution of the target program, but needs to be manually completed when the target program is about to be executed. Before clearing it, otherwise it will cause a memory leak problem.

如图4所示,服务器1900中运行的目标程序是Java程序,支撑Java程序的是Java模拟机,而Java模拟机对应的是底层的代码翻译处理操作,也就对应上面所述的C层。可以将人工输入的入口函数放入到Java模拟机中,以告诉Java模拟机从哪里开始进行无状态检测操作。通过本发明实施例提供的方法,可以得到一段在C层实现的代码,将该代码进行编译可以得到相应的动态链接库即.dll文件,和通过代码注入技术得到的jar(打包好的类文件)包。与此同时,将动态链接库以及jar包添加至服务器1900的启动参数中,以自动启用动态链接库以及jar包。在服务器1900运行目标程序时,本实施例提供的方法对应的代码也会自动运行,以在服务器1900运行的过程中,检测目标程序是否符合无状态设计原则,最后将检测报告输出出来。As shown in FIG. 4 , the target program running in the server 1900 is a Java program, and the Java simulator supports the Java program, and the Java simulator corresponds to the underlying code translation processing operation, which corresponds to the C layer described above. The entry function of manual input can be put into the Java simulator to tell the Java simulator where to start the stateless detection operation. Through the method provided by the embodiment of the present invention, a piece of code implemented in the C layer can be obtained, and by compiling the code, a corresponding dynamic link library, that is, a .dll file, and a jar (packaged class file) obtained through code injection technology can be obtained. )Bag. At the same time, the dynamic link library and the jar package are added to the startup parameters of the server 1900 to automatically enable the dynamic link library and the jar package. When the server 1900 runs the target program, the code corresponding to the method provided in this embodiment will also run automatically, so as to detect whether the target program conforms to the stateless design principle during the running of the server 1900, and finally output the detection report.

通过本发明实施例提供的方法,在执行目标程序的过程中,如果监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。从根源对目标程序中不符合无状态设计原则的变量进行识别,无需人工进行检测,本发明实现了自动化检测的过程。With the method provided by the embodiment of the present invention, in the process of executing the target program, if it is monitored that the variables of the target program are changed, and the variables are not changed by the initial thread established by executing the target program, it is determined that the variables do not conform to the stateless design. in principle. The variables in the target program that do not conform to the stateless design principle are identified from the root cause without manual detection, and the invention realizes the process of automatic detection.

基于相同的技术构思,本发明实施例还提供了一种对程序进行无状态检测的装置,如图5所示,该装置包括:Based on the same technical concept, an embodiment of the present invention also provides a device for stateless detection of a program, as shown in FIG. 5 , the device includes:

执行模块510,用于当检测到针对目标程序进行无状态检测的触发操作后,执行所述目标程序。The execution module 510 is configured to execute the target program after detecting a trigger operation for stateless detection of the target program.

执行模块510的具体实现方式,可以参见在本发明实施例中一种对程序进行无状态检测的方法中的步骤S210的具体描述。For a specific implementation manner of the execution module 510, reference may be made to the specific description of step S210 in a method for stateless detection of a program in an embodiment of the present invention.

确定模块520,用于在执行所述目标程序的过程中,监测到所述目标程序的变量发生更改,且所述变量并非被执行所述目标程序所建立的初始线程所更改,确定所述变量不符合无状态设计原则。The determining module 520 is configured to monitor that a variable of the target program is changed during the execution of the target program, and the variable is not changed by the initial thread established by executing the target program, and determine the variable Does not comply with stateless design principles.

确定模块520的具体实现方式,可以参见在本发明实施例中一种对程序进行无状态检测的方法中的步骤S220的具体描述。For a specific implementation manner of the determination module 520, reference may be made to the specific description of step S220 in a method for stateless detection of a program in the embodiment of the present invention.

可选地,所述确定模块520用于通过JVMTI接口监测所述变量是否发生更改。Optionally, the determining module 520 is configured to monitor whether the variable is changed through the JVMTI interface.

可选地,所述确定模块520用于根据所述变量所属的变量类型,确定与所述变量对应的判断方式,并根据所述判断方式,判断所述变量是否被所述初始线程所更改,其中,所述判断方式是用于判断所述变量是否被所述初始线程所更改的方式。Optionally, the determining module 520 is configured to determine a judgment mode corresponding to the variable according to the variable type to which the variable belongs, and determine whether the variable is changed by the initial thread according to the judgment mode, Wherein, the judging method is a method for judging whether the variable is changed by the initial thread.

可选地,所述变量类型包括静态变量和成员变量。Optionally, the variable types include static variables and member variables.

可选地,如图6所示,所述确定模块520包括:Optionally, as shown in FIG. 6 , the determining module 520 includes:

第一判断单元621,用于所述变量属于静态变量,确定与所述静态变量对应的判断方式为:如果所述静态变量所属的类未装载于所述初始线程中,则所述静态变量并非被所述初始线程所更改;The first judgment unit 621 is used to determine that the variable belongs to a static variable, and the judgment method corresponding to the static variable is: if the class to which the static variable belongs is not loaded in the initial thread, the static variable is not changed by the initial thread;

第二判断单元622,用于所述变量属于成员变量,确定与所述成员变量对应的判断方式为:如果所述成员变量所属的对象未在所述初始线程中生成,则所述成员变量并非被所述初始线程所更改。The second judging unit 622 is used to determine that the variable belongs to a member variable, and the judgment method corresponding to the member variable is: if the object to which the member variable belongs is not generated in the initial thread, the member variable is not changed by the initial thread.

可选地,所述第一判断单元621用于确定所述初始线程对应的堆栈;如果在所述堆栈中未查找到所述静态变量所属的类,则所述静态变量所属的类未装载于所述初始线程中,所述静态变量并非被所述初始线程所更改;Optionally, the first judgment unit 621 is used to determine the stack corresponding to the initial thread; if the class to which the static variable belongs is not found in the stack, the class to which the static variable belongs is not loaded in the stack. In the initial thread, the static variable is not changed by the initial thread;

所述第二判断单元用于622确定所述成员变量所属的对象所绑定的标签,如果在初始线程附加的标签列表中不存在所述标签,则所述成员变量所属的对象未在所述初始线程中生成,所述成员变量并非被所述初始线程所更改。The second judgment unit is used for 622 to determine the tag bound to the object to which the member variable belongs. If the tag does not exist in the tag list attached by the initial thread, the object to which the member variable belongs is not in the tag list. Generated in the initial thread, the member variable is not changed by the initial thread.

可选地,所述标签列表存储于所述初始线程对应的局部存储器中。Optionally, the tag list is stored in a local memory corresponding to the initial thread.

可选地,所述装置还包括:Optionally, the device further includes:

建立模块,用于在开始执行所述目标程序的入口函数时,建立所述标签列表;establishing a module for establishing the label list when starting to execute the entry function of the target program;

绑定模块,用于当在执行所述目标程序的过程中,检测到发生对象创建事件时,将创建的对象绑定上标签;a binding module, used to bind the created object with a label when an object creation event is detected in the process of executing the target program;

存入模块,用于将所述标签存入所述标签列表中。The storing module is used for storing the label in the label list.

需要说明的是,上述执行模块510、确定模块520可以由处理器1922实现,或者处理器1922配合存储器1932来实现,或者,处理器1922执行存储器1932中的程序指令来实现。It should be noted that the above execution module 510 and determination module 520 may be implemented by the processor 1922 , or the processor 1922 may cooperate with the memory 1932 to implement, or the processor 1922 may execute program instructions in the memory 1932 to implement.

通过本发明实施例提供的装置,在执行目标程序的过程中,如果监测到目标程序的变量发生更改,且变量并非被执行目标程序所建立的初始线程所更改,则确定变量不符合无状态设计原则。从根源对目标程序中不符合无状态设计原则的变量进行识别,无需人工进行检测,本发明实现了自动化检测的过程。With the device provided by the embodiment of the present invention, in the process of executing the target program, if it is monitored that the variables of the target program are changed, and the variables are not changed by the initial thread established by executing the target program, it is determined that the variables do not conform to the stateless design. in principle. The variables in the target program that do not conform to the stateless design principle are identified from the root cause without manual detection, and the invention realizes the process of automatic detection.

需要说明的是:上述实施例提供的对程序进行无状态检测的装置在执行任务时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将服务器1900的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的对程序进行无状态检测的装置与对程序进行无状态检测的方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。It should be noted that: when the device for performing stateless detection on a program provided by the above embodiment performs tasks, only the division of the above functional modules is used as an example for illustration. In practical applications, the above functions can be allocated by different The function module is completed, that is, the internal structure of the server 1900 is divided into different function modules, so as to complete all or part of the functions described above. In addition, the apparatus for stateless detection of a program provided in the above embodiments and the method embodiment for stateless detection of a program belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现,当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令,在服务器1900上加载和执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴光缆、光纤、数字用户线)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是服务器1900能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(如软盘、硬盘和磁带等),也可以是光介质(如数字视盘(DigitalVideo Disk,DVD)等),或者半导体介质(如固态硬盘等)。In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware or any combination thereof, and when implemented in software, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions, and when the computer program instructions are loaded and executed on the server 1900, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer instructions may be stored in or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions may be downloaded from a website site, computer, server or data center Transmission to another website site, computer, server, or data center by wire (eg, coaxial cable, optical fiber, digital subscriber line) or wireless (eg, infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by the server 1900 or a data storage device such as a server, a data center, or the like that includes an integration of one or more available media. The usable medium may be a magnetic medium (such as a floppy disk, a hard disk, and a magnetic tape, etc.), an optical medium (such as a digital video disk (Digital Video Disk, DVD), etc.), or a semiconductor medium (such as a solid-state disk, etc.).

以上所述仅为本发明一个实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。The above description is only one embodiment of the present invention, and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. Inside.

Claims (20)

1. A method for stateless detection of a program, the method comprising:
executing the target program after detecting the trigger operation of stateless detection aiming at the target program;
if the change of the variable of the target program is monitored in the process of executing the target program, and if the variable belongs to the member variable, if the object to which the member variable belongs is not generated in the initial thread established by executing the target program, the member variable is not changed by the initial thread, and the member variable is determined not to conform to the stateless design principle.
2. The method of claim 1, wherein monitoring whether a variable of the target program has changed comprises:
and monitoring whether the variable is changed or not through the JVMTI interface.
3. The method according to claim 1 or 2, characterized in that the method further comprises:
if the variable belongs to a static variable, determining a judgment mode corresponding to the static variable as follows: and if the class to which the static variable belongs is not loaded in the initial thread, the static variable is not changed by the initial thread, and the static variable is determined not to conform to a stateless design principle.
4. The method of claim 3,
if the class to which the static variable belongs is not loaded in the initial thread, the static variable is not changed by the initial thread, including:
determining a stack corresponding to the initial thread; if the class to which the static variable belongs is not found in the stack, the class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread;
if the object to which the member variable belongs is not generated in the initial thread, the member variable is not changed by the initial thread, including:
and determining the label bound by the object to which the member variable belongs, wherein if the label does not exist in a label list attached to the initial thread, the object to which the member variable belongs is not generated in the initial thread, and the member variable is not changed by the initial thread.
5. The method of claim 4, wherein the tag list is stored in a local memory corresponding to the initial thread.
6. The method of claim 4, further comprising:
when starting to execute the entry function of the target program, establishing the tag list;
when an object creating event is detected to occur in the process of executing the target program, the created object is bound with a tag;
and storing the label into the label list.
7. An apparatus for performing stateless detection on a program, the apparatus comprising an execution module and a determination module, the determination module comprising a first determination unit, wherein:
the execution module is used for executing the target program after detecting the trigger operation of the stateless detection aiming at the target program;
the first judging unit is configured to monitor that a variable of the target program is changed in a process of executing the target program, and if the variable belongs to a member variable, if an object to which the member variable belongs is not generated in an initial thread established by executing the target program, the member variable is not changed by the initial thread, and it is determined that the member variable does not conform to a stateless design principle.
8. The apparatus of claim 7, wherein the determining module is configured to monitor whether the variable is changed via a jvm ti interface.
9. The apparatus of claim 7 or 8, wherein the determining module further comprises:
a second determining unit, configured to, if the variable belongs to a static variable, if the class to which the static variable belongs is not loaded in the initial thread, determine that the static variable is not modified by the initial thread, and determine that the static variable does not conform to a stateless design rule.
10. The apparatus according to claim 9, wherein the first determining unit is configured to determine a stack corresponding to the initial thread; if the class to which the static variable belongs is not found in the stack, the class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread;
the second determination unit is configured to determine a tag bound to an object to which the member variable belongs, and if the tag does not exist in a tag list attached to an initial thread, the object to which the member variable belongs is not generated in the initial thread, and the member variable is not changed by the initial thread.
11. The apparatus of claim 10, wherein the tag list is stored in a local memory corresponding to the initial thread.
12. The apparatus of claim 10, further comprising:
the establishing module is used for establishing the label list when the entrance function of the target program starts to be executed;
the binding module is used for binding the created object with a label when detecting that an object creating event occurs in the process of executing the target program;
and the storing module is used for storing the label into the label list.
13. A server, the server comprising a processor:
the processor is used for executing the target program after detecting the trigger operation of the stateless detection aiming at the target program; if the change of the variable of the target program is monitored in the process of executing the target program, and if the variable belongs to the member variable, and if the object to which the member variable belongs is not generated in an initial thread established by executing the target program, the member variable is not changed by the initial thread, and the member variable is determined not to conform to a stateless design principle.
14. The server according to claim 13, wherein the processor is configured to monitor whether the variable has changed via a jvm ti interface.
15. The server according to claim 13 or 14, wherein the processor is configured to determine that the member variable does not comply with the stateless design rule if the class to which the static variable belongs is not loaded in the initial thread if the variable belongs to a static variable, and the static variable is not modified by the initial thread.
16. The server according to claim 15, wherein the processor is configured to determine a stack corresponding to the initial thread if the variable belongs to a static variable; if the class to which the static variable belongs is not found in the stack, the class to which the static variable belongs is not loaded in the initial thread, and the static variable is not changed by the initial thread; if the variable belongs to the member variable, determining the label bound by the object to which the member variable belongs, if the label does not exist in the label list attached to the initial thread, the object to which the member variable belongs is not generated in the initial thread, and the member variable is not changed by the initial thread.
17. The server according to claim 16, wherein the tag list is stored in a local memory corresponding to the initial thread.
18. The server according to claim 16, wherein the processor is further configured to establish the tag list when starting to execute an entry function of the target program; when an object creating event is detected to occur in the process of executing the target program, the created object is bound with a tag; and storing the label into the label list.
19. A computer-readable storage medium comprising instructions that, when executed on a server, cause the server to perform the method of any one of claims 1-6.
20. A computer program product comprising instructions for causing a server to perform the method of any one of claims 1 to 6 when the computer program product is run on the server.
CN201710582689.7A 2017-07-17 2017-07-17 A method and device for stateless detection of programs Active CN109426601B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710582689.7A CN109426601B (en) 2017-07-17 2017-07-17 A method and device for stateless detection of programs

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710582689.7A CN109426601B (en) 2017-07-17 2017-07-17 A method and device for stateless detection of programs

Publications (2)

Publication Number Publication Date
CN109426601A CN109426601A (en) 2019-03-05
CN109426601B true CN109426601B (en) 2022-05-10

Family

ID=65497177

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710582689.7A Active CN109426601B (en) 2017-07-17 2017-07-17 A method and device for stateless detection of programs

Country Status (1)

Country Link
CN (1) CN109426601B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1330785A (en) * 1998-11-05 2002-01-09 Bea系统公司 Clustered anterprise JAVATM in secure distributed processing system
CN101266542A (en) * 2008-02-01 2008-09-17 中国建设银行股份有限公司 Method and device for loading component in container
CN103425532A (en) * 2013-08-27 2013-12-04 北京京东尚科信息技术有限公司 JAVA stateless object management method and device
CN103577324A (en) * 2013-10-30 2014-02-12 北京邮电大学 Static detection method for privacy information disclosure in mobile applications

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6925638B1 (en) * 2000-09-21 2005-08-02 International Business Machines Corporation Mutability analysis in Java
JP2009157456A (en) * 2007-12-25 2009-07-16 Toshiba Corp Program verification device, program verification method and verification program
US9063778B2 (en) * 2008-01-09 2015-06-23 Microsoft Technology Licensing, Llc Fair stateless model checking
US10248561B2 (en) * 2015-06-18 2019-04-02 Oracle International Corporation Stateless detection of out-of-memory events in virtual machines
CN106610881B (en) * 2015-10-22 2019-05-07 阿里巴巴集团控股有限公司 The extracting method and device of function stack when extraction procedure occurs without response

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1330785A (en) * 1998-11-05 2002-01-09 Bea系统公司 Clustered anterprise JAVATM in secure distributed processing system
CN101266542A (en) * 2008-02-01 2008-09-17 中国建设银行股份有限公司 Method and device for loading component in container
CN103425532A (en) * 2013-08-27 2013-12-04 北京京东尚科信息技术有限公司 JAVA stateless object management method and device
CN103577324A (en) * 2013-10-30 2014-02-12 北京邮电大学 Static detection method for privacy information disclosure in mobile applications

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
聊聊程序设计(一)——有状态、无状态;weixin_30399797;《CSDN:https://blog.csdn.net/weixin_30399797/article/details/99330212》;20171123;第1-3页 *

Also Published As

Publication number Publication date
CN109426601A (en) 2019-03-05

Similar Documents

Publication Publication Date Title
US10417065B2 (en) Method and system for automated agent injection in container environments
US10380350B1 (en) Efficient and comprehensive source code fuzzing
CN108595329B (en) Application testing method and device and computer storage medium
US7908521B2 (en) Process reflection
US10824404B2 (en) Methods and systems for uploading a program based on a target network platform
US8756572B2 (en) Debugger-set identifying breakpoints after coroutine yield points
US20170255545A1 (en) Methods and systems of function-specific tracing
US10545852B2 (en) Diagnostics of state transitions
CN111026601A (en) Monitoring method and device for Java application system, electronic equipment and storage medium
US10289536B2 (en) Distinguishing public and private code in testing environments
US9588872B2 (en) Discovery of code paths
KR102118236B1 (en) Operating system support for contracts
US9417988B2 (en) Tracking subclasses of and operations performed by generic objects in a computer system
US10713145B2 (en) Automated debugging with combined static and dynamic analysis
US9841960B2 (en) Dynamic provision of debuggable program code
CN113127329B (en) Script debugging method, device and computer storage medium
US10216620B2 (en) Static code testing of active code
CN108197020A (en) Plug-in unit method of calibration, electronic equipment and computer storage media
US20170091076A1 (en) Debugging remote vertex code on test machine
US11599342B2 (en) Pathname independent probing of binaries
CN109426601B (en) A method and device for stateless detection of programs
US11687362B2 (en) Storage and reuse of computing-task outputs using system-call interception
US11321218B1 (en) Automated generation of source code models from machine code for code analysis
KR101976993B1 (en) Interactive Dynamic Binary Instrumentation Code Extraction Apparatus for Automatic Analysis of Mobile Code and method thereof
CN119149099A (en) Unused dependency identification method and related device in java application

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20200210

Address after: 518129 Bantian HUAWEI headquarters office building, Longgang District, Guangdong, Shenzhen

Applicant after: HUAWEI TECHNOLOGIES Co.,Ltd.

Address before: 210000 HUAWEI Nanjing base, 101 software Avenue, Yuhuatai District, Jiangsu, Nanjing

Applicant before: Huawei Technologies Co.,Ltd.

GR01 Patent grant
GR01 Patent grant