Memory management method and apparatus, restricted device, terminal, storage medium and program
By dividing the memory region managed by the virtual machine into different regions and allocating memory space on demand, the problem of low memory utilization efficiency of resource-constrained devices is solved, and the stability and compatibility of the system are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING TONGFANG MICROELECTRONICS
- Filing Date
- 2024-08-29
- Publication Date
- 2026-05-05
AI Technical Summary
Resource-constrained devices have limited memory resources, which existing technologies cannot utilize efficiently, resulting in insufficient system stability and compatibility.
The memory area managed by the virtual machine is divided into a first memory area, a buffer common area, and a second memory area, which are used to store the virtual machine stack, the indirect access variable stack, and the application RAM data, respectively. Memory space is allocated on demand to optimize memory utilization.
It improves memory utilization on resource-constrained device operating systems, enhancing system stability and compatibility.
Smart Images

Figure CN119088560B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of virtual machine memory management technology, and in particular to a memory management method, apparatus, restricted device, terminal, storage medium and program. Background Technology
[0002] WebAssembly (Wasm for short) is a method for running non-JavaScript (a lightweight, interpreted or just-in-time compiled programming language with function-first logic) code in a browser. This code can be C, C++, or Rust (a modern systems programming language focused on security, speed, and concurrency), and it can run at near-native speeds after being loaded into the client browser. Resource-constrained devices (referred to as restricted devices) have limited RAM resources. Applying Wasm technology to resource-constrained devices such as smart card security chips requires efficient utilization of limited memory resources to provide customers with more available memory, thereby improving product compatibility. Summary of the Invention
[0003] This invention provides a memory management method, apparatus, restricted device, terminal, storage medium, and program that can improve the memory utilization of the operating system of a resource-constrained device.
[0004] According to one aspect of the present invention, a memory management method is provided, applied to a resource-constrained device, comprising:
[0005] The memory region managed by the virtual machine is divided into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already in use; the buffer common area is the middle of the memory region managed by the virtual machine that is not in use; the first memory region and the second memory region allocate memory space from the buffer common area as needed;
[0006] The first memory region stores and manages the virtual machine stack and the indirect access variable stack; wherein, the virtual machine stack is used to store function call parameters, local variables, operands, and call function stack frame information; the indirect access variable stack is used to store the elements of the function's local array variables, local structures, and union variables; memory space for the indirect access variable stack is allocated for the function in the virtual machine stack;
[0007] The second memory region stores and manages application RAM data.
[0008] According to another aspect of the present invention, a memory management device is provided, configured in a resource-constrained device, comprising:
[0009] A memory region partitioning module is used to divide the memory region managed by the virtual machine into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already used; the buffer common area is the middle unused memory region of the memory region managed by the virtual machine; the first memory region and the second memory region allocate memory space from the buffer common area as needed;
[0010] The first memory region storage management module is used to manage the virtual machine stack and the indirect access variable stack through the first memory region storage; wherein, the virtual machine stack is used to store function call parameters, local variables, operands, and call function stack frame information; the indirect access variable stack is used to store the elements of the function's local array variables, local structures, and union variables; and memory space for the indirect access variable stack is allocated for the function in the virtual machine stack;
[0011] The second memory region storage management module is used to manage application RAM data through the second memory region storage.
[0012] According to another aspect of the present invention, a restricted device is provided, wherein an operating system is installed on the restricted device, and a runtime environment is executed in the operating system, the restricted device comprising:
[0013] At least one processor; and
[0014] A memory communicatively connected to the at least one processor; wherein,
[0015] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the memory management method according to any embodiment of the present invention.
[0016] According to another aspect of the present invention, a terminal is provided, including the restricted device described in any one of the embodiments of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the memory management method described in any embodiment of the present invention.
[0018] According to another aspect of the present invention, a computer program product is also provided, comprising a computer program that, when executed by a processor, implements the memory management method described in any embodiment of the present invention.
[0019] This invention divides the memory region managed by the virtual machine on a resource-constrained device into a first memory region, a buffer common area, and a second memory region. The first and second memory regions are the two ends of the virtual machine-managed memory region that are already in use; the buffer common area is the middle unused memory region of the virtual machine-managed memory region. The first and second memory regions allocate memory space from the buffer common area as needed. Furthermore, the first memory region stores and manages the virtual machine stack and indirect access variable stack, while the second memory region stores and manages application RAM data, effectively improving the memory utilization of the operating system on the resource-constrained device.
[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart of a memory management method provided in an embodiment of the present invention;
[0023] Figure 2 This is a schematic diagram of the structure of a virtual machine-managed memory region provided in an embodiment of the present invention;
[0024] Figure 3 This is a flowchart of a memory management method provided in an embodiment of the present invention;
[0025] Figure 4 This is a schematic diagram of the structure of a virtual machine-managed memory region provided in an embodiment of the present invention;
[0026] Figure 5 This is a flowchart of a memory management method provided in an embodiment of the present invention;
[0027] Figure 6 This is a flowchart illustrating a memory management method provided in an embodiment of the present invention;
[0028] Figure 7 This is a schematic diagram of a memory management device provided in an embodiment of the present invention;
[0029] Figure 8 A schematic diagram of a restricted device provided in an embodiment of the present invention;
[0030] Figure 9 This is a structural diagram of a terminal provided according to an embodiment of the present invention. Detailed Implementation
[0031] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0033] Figure 1 This is a flowchart of a memory management method provided by an embodiment of the present invention. This embodiment is applicable to resource-constrained devices that manage memory by dividing the memory region managed by the virtual machine into different regions. This method can be executed by a memory management device, which can be implemented in software and / or hardware, and is generally integrated into the resource-constrained device. This resource-constrained device can be integrated into a terminal device. The present invention does not limit the specific device type of the resource-constrained device. Optionally, a Multi-Application Smartcard Operation System (AOS) can be installed on the resource-constrained device. AOS refers to an operating system that supports multiple applications, is downloaded later, and runs on a resource-constrained security chip. Optionally, the resource-constrained device can include, but is not limited to, smart cards, USB keys (hardware devices with USB interfaces), ESAM (Embedded Secure Access Module), and SE (Secure Element), etc. Correspondingly, such as Figure 1 As shown, the method includes the following operations:
[0034] S110. Divide the memory region managed by the virtual machine into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already used memory regions; the buffer common area is the middle unused memory region of the memory region managed by the virtual machine; the first memory region and the second memory region allocate memory space from the buffer common area as needed.
[0035] For resource-constrained devices, the memory region managed by the virtual machine can be a RAM (Random Access Memory) memory region. The first memory region can be an used memory region at one end of the virtual machine-managed memory region, and the second memory region can be an used memory region at the other end of the virtual machine-managed memory region. Correspondingly, the buffer common area can be an unused memory region in the middle of the virtual machine-managed memory region.
[0036] It is understood that the first memory region and the second memory region are respectively the starting memory address of the memory region managed by the virtual machine and the memory region consisting of a contiguous memory distribution space. Optionally, the first memory region may correspond to a memory region starting from the starting memory address of the memory region managed by the virtual machine, and the second memory region may correspond to a memory region starting from the ending memory address of the memory region managed by the virtual machine. Alternatively, the first memory region may correspond to a memory region starting from the ending memory address of the memory region managed by the virtual machine, and the second memory region may correspond to a memory region starting from the starting memory address of the memory region managed by the virtual machine. This embodiment of the invention does not limit the relative positions of the first memory region and the second memory region within the memory region managed by the virtual machine.
[0037] Figure 2 This is a schematic diagram of the structure of a virtual machine-managed memory region provided in an embodiment of the present invention. In a specific example, such as... Figure 2 As shown, the complete memory region managed by the virtual machine can be obtained by sequentially connecting the first memory region, the buffer common area, and the second memory region, or by sequentially connecting the second memory region, the buffer common area, and the first memory region.
[0038] S120, The virtual machine stack and the indirect access variable stack are stored in the first memory area.
[0039] In this embodiment of the invention, the virtual machine employs a stack-based storage management structure for the virtual machine stack. The virtual machine stack stores stack frames, which contain function call parameters, local variables, operands, and stack frame information of the calling function. When the virtual machine executes a function call instruction, it creates a stack frame for the function. When the virtual machine executes a function return instruction, it destroys the corresponding stack frame.
[0040] The indirect access variable stack can be a local structure type data area of the currently running function, used to store elements of the function's local array variables, local structures, and union variables.
[0041] In the virtual machine stack, the indirect access variable stack memory space is allocated for the function.
[0042] S130, manage application RAM data through the second memory area.
[0043] The application RAM data can be any data type that an application needs to store in RAM. For example, in this embodiment of the invention, the application RAM data may include, but is not limited to, temporary static variable data, temporary dynamic variable data, and module global data.
[0044] Accordingly, after dividing the memory area managed by the virtual machine into a first memory area, a buffer common area, and a second memory area, the first memory area is used to store and manage the virtual machine stack and the indirect access variable stack, while the second memory area is used to store and manage application RAM data.
[0045] In other words, this embodiment of the invention divides the RAM memory managed by the virtual machine into two contiguous memory areas to manage the corresponding data. One memory area centrally stores and manages the virtual machine stack and indirect access variable stack, while the other memory area centrally stores and manages application RAM data. The first and second memory areas are allocated from both ends of the RAM memory managed by the virtual machine towards the middle, with the middle part serving as a buffer common area. This maximizes the utilization of the limited RAM resources of resource-constrained devices. Only when the newly allocated memory space in the first memory area exceeds the buffer common area memory space, or when the newly allocated memory space in the second memory area exceeds the buffer common area memory space, will the system be unable to continue running due to insufficient buffer common area memory space. This reduces the probability of system failure due to insufficient space in a certain type of fixed memory allocation, thus improving the robustness of the operating system. Therefore, the above-described memory management method applied to resource-constrained devices can maximize the utilization of RAM resources and improve product compatibility.
[0046] This invention improves the memory utilization of the operating system on resource-constrained devices by dividing the memory region managed by the virtual machine on a resource-constrained device into a first memory region, a buffer common area, and a second memory region. The first and second memory regions are the two ends of the virtual machine-managed memory region that are already in use; the buffer common area is the middle unused memory region of the virtual machine-managed memory region. The first and second memory regions allocate memory space from the buffer common area as needed. Furthermore, the first memory region stores and manages the virtual machine stack and indirect access variable stack, while the second memory region stores and manages application RAM data, thereby improving the memory utilization of the operating system on resource-constrained devices.
[0047] Figure 3 This is a flowchart of a memory management method provided by an embodiment of the present invention. This embodiment is a specific embodiment based on the above embodiment. In this embodiment, temporary static variable data and temporary dynamic variable data are used as application RAM data, and specific optional implementation methods for storing and managing temporary static variable data and temporary dynamic variable data through a second memory region are given. Correspondingly, as Figure 3 As shown, the method in this embodiment may include:
[0048] S210. Divide the memory area managed by the virtual machine into the first memory area, the buffer common area, and the second memory area.
[0049] Wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already used; the buffer common area is the middle unused memory region of the memory region managed by the virtual machine; the first memory region and the second memory region allocate memory space from the buffer common area as needed.
[0050] S220. The virtual machine stack and the indirect access variable stack are stored in the first memory area.
[0051] Figure 4 This is a schematic diagram of the structure of a virtual machine-managed memory region provided in an embodiment of the present invention. In a specific example, such as... Figure 4 As shown, the region at end A of the virtual machine-managed memory area can be used as the first memory area, and the region at end B of the virtual machine-managed memory area can be used as the second memory area. Correspondingly, the virtual machine stack and the indirect access variable stack can be allocated and used as a contiguous block of memory from end A of the virtual machine-managed memory to end B. Module global data, temporary dynamic variable data, and temporary static variable data can be allocated as a contiguous block of memory from end B of the virtual machine-managed memory to end A. The unallocated portion of the middle area of the virtual machine-managed memory serves as a buffer common area.
[0052] In an optional embodiment of the present invention, the application RAM data may include temporary static variable data and temporary dynamic variable data, and correspondingly, the above method may include the following operations:
[0053] S230. After the system starts running, starting from the second memory region and moving towards the first memory region, obtain the newly added second memory region from the buffer common area.
[0054] The newly added second memory region can be a memory region obtained from the buffer common area near the start position of the second memory region.
[0055] S240. The newly added second memory region is used as the memory space for temporary static variable data of all applications and initialized.
[0056] Among them, temporary static variable data (AOS Static Transient Resource, ASR) belongs only to the application itself, and the allocated data storage space is exclusively used by the application. When the RTE (Runtime Environment) is reset or loses power, the temporary static variable data is reset to 0.
[0057] In this embodiment of the invention, after the program starts running in the resource-constrained device, memory space in the newly added second memory region can be allocated and initialized from the second memory region of the RAM memory managed by the virtual machine toward the first memory region for all application temporary static variable data.
[0058] In a specific example, such as Figure 4 As shown, after a program starts running on a resource-constrained device, it can allocate and initialize memory space for all application temporary static variable data from the virtual machine's memory management end B towards end A, based on the sum of the memory space occupied by all application temporary static variable data.
[0059] S250. When an application is first selected on a logical channel, a first starting position for allocating temporary dynamic variable data memory space for the selected application is determined at a location in the buffer common area near the second memory area.
[0060] In this context, a logical channel can refer to a concept used to establish a communication connection with a smart card. It allows the host and smart card to establish multiple independent communication channels simultaneously, each with its own command and response stream, and these channels are isolated from each other. The selected application can be an application that has already been selected. Temporary dynamic variable data (AOSDynamictransient Resource, ADR) belongs to the application, but its data space allocation is only performed when the application is selected. When the last application of the same module on multiple logical channels is deselected, the space occupied by the application's temporary dynamic variable data is reclaimed, and the RTE clears the module's temporary dynamic variable data. After a reset or power failure, if the application is not selected, the temporary dynamic variable data does not exist. After an application is selected, even if the space occupied by the application's temporary dynamic variable data is zero, it is assumed that the virtual machine-managed application RAM data already contains the temporary dynamic variable data. The first starting location can be the starting location in the virtual machine-managed RAM memory where memory space is allocated for the temporary dynamic variable data.
[0061] For resource-constrained devices, when the RTE receives an application selection command, if the command content matches the application AID (Application Identifier), the application is explicitly selected, and the RTE should activate this application as the selected application. When a logical channel is opened via the MANAGE CHANNEL command (used to open a new logical channel from one logical channel or close a specified logical channel from another logical channel), after receiving the open logical channel command, the RTE, in addition to performing necessary logical channel management, should also check whether an implicitly selected application exists on the new logical channel. If it exists, the implicitly selected application should be activated by default, i.e., implicitly selected application. Once the application is activated, the RTE should distribute subsequent received commands to the currently activated application for processing.
[0062] S260. Allocate and initialize the temporary dynamic variable data memory space for the selected application from the first starting position toward the first memory region.
[0063] In this embodiment of the invention, when an application is selected for the first time on a logical channel, a first starting position for allocating temporary dynamic variable data memory space for the selected application can be determined at a position in the buffer common area near the second memory area. That is, the position of the temporary static variable data memory area near the first memory area is taken as the first starting position, and temporary dynamic variable data memory space is allocated and initialized for the selected application in the direction of the first memory area.
[0064] In an optional embodiment of the present invention, determining the first starting position for allocating temporary dynamic variable data memory space for the selected application at the location of the buffer common area near the second memory region may include: if it is determined that there is no temporary dynamic variable data memory space, taking the memory position of the temporary static variable data memory space in the direction of the first memory region as the first starting position; if it is determined that there is a temporary dynamic variable data memory space and a module global data memory space, moving the existing module global data memory space as a whole towards the first memory region; and taking the memory position of the existing temporary dynamic variable data memory space in the direction of the first memory region as the first starting position.
[0065] Module Global Resource (MGR) can be global data that is visible to the entire module and can be modified by applications within the module. For example, module global data can be application global data and the application global variable heap.
[0066] In a specific example, continue to refer to Figure 4 The example illustrates that when an application is first selected on a logical channel, temporary dynamic variable data is allocated to it. Specifically, if the virtual machine managed memory (VMM) does not yet have temporary dynamic variable data, the position of the temporary static variable data memory area closest to VMM A can be used as the first starting position. Starting from this first starting position, temporary dynamic variable data memory space is allocated and initialized for the selected application towards VMM A. If temporary dynamic variable data memory space and module global data memory space already exist in VMM, the existing module global data memory area can be moved entirely to VMM A. The position of the existing temporary dynamic variable data memory area closest to VMM A can be used as the first starting position. Starting from this first starting position, temporary dynamic variable data memory space is allocated for the selected application towards VMM A. It should be noted that when moving the existing module global data memory area entirely to VMM A, the continuity between the module global data memory area and the temporarily dynamic variable data memory area after this allocation must be maintained. After allocating temporary dynamic variable data memory space for the selected application, this allocated temporary dynamic variable data memory space is then initialized.
[0067] The above technical solution divides the memory area managed by the virtual machine on a resource-constrained device into a first memory area, a buffer common area, and a second memory area. Furthermore, the first memory area stores and manages the virtual machine stack and indirect access variable stack, while the second memory area stores and manages application RAM data. When managing application RAM data through the second memory area, memory spaces corresponding to temporary static variable data and temporary dynamic variable data can be allocated and stored sequentially and contiguously. This maximizes the utilization of the limited RAM resources on the resource-constrained device, reduces the probability of system failure due to insufficient space allocated for a certain type of memory, and thus improves the memory utilization and robustness of the operating system on the resource-constrained device.
[0068] Figure 5 This is a flowchart of a memory management method provided by an embodiment of the present invention. This embodiment is based on the above embodiment and is further specified. In this embodiment, temporary static variable data, temporary dynamic variable data, and module global data are simultaneously used as application RAM data, and specific optional implementation methods for storing and managing temporary static variable data, temporary dynamic variable data, and module global data through a second memory region are given. Correspondingly, as... Figure 5 As shown, the method in this embodiment may include:
[0069] S310. Divide the memory area managed by the virtual machine into the first memory area, the buffer common area, and the second memory area.
[0070] Wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already used; the buffer common area is the middle unused memory region of the memory region managed by the virtual machine; the first memory region and the second memory region allocate memory space from the buffer common area as needed.
[0071] S320. The virtual machine stack and the indirect access variable stack are stored in the first memory area.
[0072] S330. After the system starts running, starting from the second memory region and moving towards the first memory region, obtain the newly added second memory region from the buffer common area.
[0073] S340. The newly added second memory region is used as the memory space for temporary static variable data of all applications and initialized.
[0074] S350. When an application is first selected on a logical channel, a first starting position for allocating temporary dynamic variable data memory space for the selected application is determined at a location in the buffer common area near the second memory area.
[0075] S360. Allocate and initialize the temporary dynamic variable data memory space for the selected application from the first starting position toward the first memory region.
[0076] S370. On any logical channel, when the virtual machine first calls the module program of the application module corresponding to the application, a second starting position is determined at the location of the buffer common area near the second memory area to allocate the memory space of module global data and module global data management information for the called application module.
[0077] S380. Allocate and initialize the module global data and module global data management information memory space for the called application module from the second starting position toward the first memory region.
[0078] Application modules refer to independent modules that implement specific application functions or services and have an application entry function. These modules are usually divided according to function or business logic, and applications can be created within application modules. Module programs belong to module assemblies, which can be collections used to store all program code information or module program data within a specific module. The called application module is the application module called by the virtual machine. The module global data management information space can manage the system overhead of the module's global data, used to record the space of the corresponding module's global data, the module it belongs to, and the logical channel information it belongs to. The second starting location can be the starting location in the RAM memory managed by the virtual machine used to allocate the memory space for module global data and module global data management information.
[0079] In this embodiment of the invention, when the virtual machine first calls the module program of the application module corresponding to the application on any logical channel, it can determine the second starting position for allocating the module global data and module global data management information memory space to the called application module at the position of the buffer common area near the second memory area. That is, the position of the temporary dynamic variable data memory area near the first memory area can be used as the second starting position, and the module global data and module global data management information memory space can be allocated and initialized to the called application module in the direction of the first memory area.
[0080] In an optional embodiment of the present invention, determining the second starting position for allocating memory space for module global data and module global data management information to the called application module at a location near the second memory region in the buffer common area may include: if it is determined that there is no memory space for module global data, taking the memory location of the temporary dynamic variable data in the direction of the first memory region as the second starting position; if it is determined that there is already memory space for module global data, taking the memory location of the memory space of the already existing module global data in the direction of the first memory region as the second starting position.
[0081] In a specific example, continue to refer to Figure 4 The example illustrates that when an application is selected for the first time on a logical channel, including the module program that executes the application module corresponding to that application, module global data needs to be allocated for that application. Specifically, if the virtual machine-managed memory does not yet have module global data memory, then starting from the temporary dynamic variable data memory area near the virtual machine-managed memory A end, memory space for module global data and module global data management information can be allocated and initialized for the called application module in the direction of virtual machine-managed memory A. If memory space for module global data already exists, then starting from the existing module global data memory area near the virtual machine-managed memory A end, memory space for module global data and module global data management information can be allocated and initialized for the called application module in the direction of virtual machine-managed memory A.
[0082] In an optional embodiment of the present invention, the first invocation of the module program of the application module corresponding to the application by the virtual machine may include: the application being selected for the first time on a logical channel, and the module program of the selected application module being invoked through function call related bytecode; or, on any logical channel, the module program of the application module corresponding to the application being invoked for the first time through function call related bytecode.
[0083] Optionally, the first time the virtual machine calls the module program of the application corresponding to the application module refers to the first time the module program of the application module is called through the bytecode related to the function call. This can include two scenarios: First, when the application is selected for the first time on a logical channel and the module program of the selected application module is called through the bytecode related to the function call, a second starting position for allocating the module global data and module global data management information memory space for the called application module can be determined at a location near the second memory region in the buffer common area. Then, the module global data and module global data management information memory space for the called application module is allocated and initialized from the second starting position towards the first memory region. Second, when the module program of the application corresponding to the application module is called for the first time on any logical channel through the bytecode related to the function call, module global data is allocated for the application. In this case, a second starting position for allocating the module global data and module global data management information memory space for the called application module can be determined at a location near the second memory region in the buffer common area. Then, the module global data and module global data management information memory space for the called application module is allocated and initialized from the second starting position towards the first memory region.
[0084] In an optional embodiment of the present invention, the memory management method may further include: when applying a selection on any logical channel, while maintaining the continuity of the memory of all remaining module global data and module global data management information, and maintaining the continuity of the module global data memory space and the temporary dynamic variable data memory space, reclaiming the memory space of all module global data and module global data management information that match the current logical channel.
[0085] Application deselection, also known as application cancellation, refers to the process of deactivating an already activated application before activating it in the RTE. When a logical channel is closed via the MANAGE CHANNEL command, the RTE should perform application deselection.
[0086] Understandably, when an application selects a channel, it needs to reclaim the memory space of all module global data and module global data management information matching the current logical channel. During this reclamation process, it's crucial to maintain the continuity of all remaining module global data and module global data management information memory, while also ensuring the continuity between the module global data memory space and the temporary dynamic variable data memory space.
[0087] In an optional embodiment of the present invention, the memory management method may further include: when the application is last deselected on the logical channel, while maintaining the continuity of all remaining temporary dynamic variable data memory, maintaining the continuity of the module global data memory area and the temporary dynamic variable data memory area, and maintaining the continuity of the temporary dynamic variable data memory area and the temporary static variable data memory area, the memory space of the temporary dynamic variable data of the deselected application is reclaimed.
[0088] The application being selected can be the application that performs the application selection process.
[0089] Understandably, when an application is last deselected on a logical channel—that is, when the last application of the same module on multiple logical channels is deselected—it is necessary to reclaim the temporary dynamic variable data memory space of the deselected application. During this reclamation process, it is necessary to maintain the continuity of all remaining temporary dynamic variable data memory, the continuity between the module's global data memory area and the temporary dynamic variable data memory area, and the continuity between the temporary dynamic variable data memory area and the temporary static variable data memory area.
[0090] To more clearly illustrate the technical solutions provided by the embodiments of the present invention, the memory management method provided by the embodiments of the present invention will be described below with reference to specific examples. Figure 6This is a flowchart illustrating a memory management method provided in an embodiment of the present invention. In a specific example, such as... Figure 6 As shown, after the system starts running, temporary static variable data for the application can be allocated at the starting position of the B end of the virtual machine managed memory. If application 1, belonging to module 1, is selected on logical channel 0, the system can first execute the application selection process. At this time, starting from the position of the temporary static variable data memory area near the A end of the virtual machine managed memory, temporary dynamic variable data memory space (ADR-C0M1A1) is allocated to the selected application in the direction of the A end of the virtual machine managed memory. Then, the system calls the module 1 module program. At this time, starting from the position of the temporary dynamic variable data memory area near the A end of the virtual machine managed memory, i.e., ADR-C0M1A1 near the A end of the virtual machine managed memory, the system can allocate module global data memory and its management information memory space (MGR-C0M1A1) to the called application module in the direction of the A end of the virtual machine managed memory. The MGR-C0M1A1 memory is initialized, and its space, belonging module, and belonging logical channel information are recorded in the management information memory.
[0091] Furthermore, such as Figure 6 As shown, if application 1, belonging to module 2, is selected on logical channel 1, the system first executes the application selection process. At this point, starting from the existing temporary dynamic variable data memory area near the virtual machine management memory A end (i.e., ADR-C0M1A1 near the virtual machine management memory A end), temporary dynamic variable data memory space can be allocated to the selected application towards the virtual machine management memory A end. The existing module global data memory area MGR-C0M1A1 can be moved entirely to the virtual machine management memory A end. During the move, the continuity between the module global data memory area and the temporarily dynamic variable data memory area after this allocation must be maintained. Therefore, the capacity of the moved memory space can be the capacity of the temporary dynamic variable data memory space allocated to the selected application. After the move is completed, the required memory area between MGR-C0M1A1 and ADR-C0M1A1 is obtained: ADR-C1M2A1. Then, the temporarily dynamic variable data memory space ADR-C1M2A1 allocated this time is initialized. Subsequently, the system calls module 2 program. At this time, starting from the position of the existing module global data memory area near the virtual machine management memory A end, that is, the position of MGR-C0M1A1 near the virtual machine management memory A end, the system allocates module global data memory and its management information memory space: MGR-C1M2A1 for the called application module in the direction of virtual machine management memory A end. The system initializes the memory of MGR-C1M2A1 and records its space, its module, and its logical channel information in the management information memory.
[0092] Furthermore, logical channel 0 has selected the application 1 belonging to module 1 to access the module program interface function of application 1 of module 3 during its operation. On logical channel 0, when the module program of the application module corresponding to application 1 of module 3 is called for the first time, it is necessary to allocate module global data and module global data management information memory space for the called application module. At this time, starting from the position of the existing module global data memory area near the virtual machine management memory A end, that is, the position of module global data memory MGR-C1M2A1 near the virtual machine management memory A end, module global data memory and its management information memory space: MGR-C0M3A1 are allocated to the called application module in the direction of virtual machine management memory A end. The memory of MGR-C0M3A1 is initialized, and its space, the module to which it belongs, and the logical channel information to which it belongs are recorded in the management information memory.
[0093] Furthermore, logical channel 1 selects application 1 to which module 2 belongs. At this point, the module global data memory and its management information memory space MGR-C1M2A1 of application 1 to which module 2 belongs can be reclaimed first. The module global data memory and its management information memory MGR-C0M3A1 are then moved as a whole to the virtual machine management memory B, maintaining the continuity between the module global data memory and its management information memory MGR-C0M3A1 and the module global data memory and its management information memory MGR-C0M1A1 during the move. Subsequently, the temporary dynamic variable data memory space ADR-C1M2A1 of application 1 to which module 2 belongs is reclaimed. The entire module global data memory area, i.e., the module global data memory and its management information memory MGR-C0M3A1 and the module global data memory and its management information memory MGR-C0M1A1, is moved as a whole to the virtual machine management memory B, maintaining the continuity between the module global data memory area and the temporary dynamic variable data memory area during the move.
[0094] Furthermore, for logical channel 0 to select application 1 belonging to module 2, the system first executes the process of selecting application 1 belonging to module 1, and reclaims all module global data memory and its management information memory space with the attribute of logical channel 0, that is, reclaims module global data memory and its management information memory MGR-C0M3A1 and module global data memory and its management information memory MGR-C0M1A1. Further, it reclaims the temporary dynamic variable data memory space ADR-C0M1A1 of application 1 belonging to module 1. Afterwards, the system executes the process of selecting application 1 belonging to module 2, starting from the position of the temporary static variable data memory area closest to the virtual machine management memory A end, and allocates temporary dynamic variable data memory space ADR-C0M2A1 towards the virtual machine management memory A end for the selected application. Finally, the system calls module 2 program. At this time, starting from the location of the temporary dynamic variable data memory area near the virtual machine management memory A end, that is, ADR-C0M2A1 near the virtual machine management memory A end, the system allocates module global data memory and its management information memory space: MGR-C0M2A1 to the called application module in the direction of virtual machine management memory A end.
[0095] The above technical solution can integrate module global data, temporary dynamic variable data, and temporary static variable data into a contiguous memory block. The probability of change for these three types of memory decreases from high to low. Therefore, placing the more likely to change memory near the buffer common area reduces the space and frequency of RAM memory relocation when certain types of memory space change. Simultaneously, this technical solution improves the efficiency of module global data memory management for multiple applications on a single logical channel by contiguously allocating module global data management information with module global data memory.
[0096] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information in this technical solution comply with relevant laws and regulations and do not violate public order and good morals.
[0097] It should be noted that any arrangement or combination of the technical features in the above embodiments also falls within the protection scope of this invention.
[0098] Figure 7 This is a schematic diagram of a memory management device provided in an embodiment of the present invention. This memory management device is configured in a resource-constrained device, such as... Figure 7 As shown, the device includes: a memory region partitioning module 410, a first memory region storage management module 420, and a second memory region storage management module 430, wherein:
[0099] The memory region partitioning module 410 is used to divide the memory region managed by the virtual machine into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already used; the buffer common area is the middle unused memory region of the memory region managed by the virtual machine; the first memory region and the second memory region allocate memory space from the buffer common area as needed;
[0100] The first memory region storage management module 420 is used to manage the virtual machine stack and the indirect access variable stack through the first memory region storage;
[0101] The second memory region storage management module 430 is used to manage application RAM data through the second memory region storage.
[0102] This invention divides the memory region managed by the virtual machine on a resource-constrained device into a first memory region, a buffer common area, and a second memory region. The first and second memory regions are the two ends of the virtual machine-managed memory region that are already in use; the buffer common area is the middle unused memory region of the virtual machine-managed memory region. The first and second memory regions allocate memory space from the buffer common area as needed. Furthermore, the first memory region stores and manages the virtual machine stack and indirect access variable stack, while the second memory region stores and manages application RAM data, effectively improving the memory utilization of the operating system on the resource-constrained device.
[0103] Optionally, the application RAM data includes module global data, and the second memory region storage management module 430 is further configured to: on any logical channel, when the virtual machine first calls the module program of the application corresponding to the application module, determine a second starting position for allocating module global data and module global data management information memory space to the called application module at a position near the second memory region in the buffer common area; allocate and initialize the module global data and module global data management information memory space to the called application module from the second starting position toward the first memory region.
[0104] Optionally, the second memory region storage management module 430 is further configured to: if it is determined that there is no memory space for module global data, take the memory location of the temporary dynamic variable data in the direction of the first memory region as the second starting position; if it is determined that there is memory space for module global data, take the memory location of the memory space for the existing module global data in the direction of the first memory region as the second starting position.
[0105] Optionally, the virtual machine's first invocation of the module program of the application module corresponding to the application includes: the application being selected for the first time on a logical channel, and the module program of the selected application module being invoked through function call-related bytecode; or, on any logical channel, the module program of the application module corresponding to the application being invoked for the first time through function call-related bytecode.
[0106] Optionally, the application RAM data includes temporary static variable data, and the second memory region storage management module 430 is further configured to: after the system starts running, obtain a newly added second memory region from the buffer common area starting from the second memory region and moving towards the first memory region; and initialize the newly added second memory region as the memory space for temporary static variable data of all applications.
[0107] Optionally, the second memory region storage management module 430 is further configured to: when an application is first selected on a logical channel, determine a first starting position for allocating temporary dynamic variable data memory space for the selected application at a location near the second memory region in the buffer common area; allocate and initialize the temporary dynamic variable data memory space for the selected application from the first starting position toward the first memory region.
[0108] Optionally, the second memory region storage management module 430 is further configured to: when it is determined that there is no temporary dynamic variable data memory space, take the memory position of the temporary static variable data memory space closer to the first memory region as the first starting position; when it is determined that there is a temporary dynamic variable data memory space and a module global data memory space, move the existing module global data memory space as a whole towards the first memory region; and take the memory position of the existing temporary dynamic variable data memory space closer to the first memory region as the first starting position.
[0109] Optionally, the above memory management method may further include a first memory space reclamation module, used to: when an application selects on any logical channel, while maintaining the continuity of the memory of all remaining module global data and module global data management information, and maintaining the continuity of the module global data memory space and the temporary dynamic variable data memory space, reclaim the memory space of all module global data and module global data management information that match the current logical channel.
[0110] Optionally, the above memory management method may further include a second memory space reclamation module, used to: when the application is last deselected on the logical channel, reclaim the memory space of the deselected application's temporary dynamic variable data, while maintaining the continuity of all remaining temporary dynamic variable data memory, the continuity of the module's global data memory area and the temporary dynamic variable data memory area, and the continuity of the temporary dynamic variable data memory area and the temporary static variable data memory area.
[0111] The memory management device described above can execute the memory management method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the method. Technical details not described in detail in this embodiment can be found in the memory management method provided in any embodiment of the present invention.
[0112] Since the memory management device described above is capable of executing the memory management method in the embodiments of the present invention, those skilled in the art can understand the specific implementation and various variations of the memory management device in this embodiment based on the memory management method described in the embodiments of the present invention. Therefore, how the memory management device implements the memory management method in the embodiments of the present invention will not be described in detail here. Any device used by those skilled in the art to implement the memory management method in the embodiments of the present invention falls within the scope of protection of this application.
[0113] Figure 8 A schematic diagram of the structure of a limited device 10 that can be used to implement an embodiment of the present invention is shown.
[0114] like Figure 8 As shown, the restricted device 10 includes at least one processor 11 and a memory, such as non-volatile memory (NVM) 12, random access memory (RAM) 13, etc., communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the NVM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the restricted device 10. The processor 11, NVM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0115] The I / O interface 15 in the restricted device 10 may include: ISO7816, ISO14443, eSPI (Enhanced Serial Peripheral Interface), and SPI (Serial Peripheral Interface), etc.
[0116] Processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, central processing unit (CPU), graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, for example, performing a memory management method as described in various embodiments of the present invention, executed by a runtime environment in an embedded operating system installed in a restricted device, the method comprising:
[0117] The memory region managed by the virtual machine is divided into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already in use; the buffer common area is the middle of the memory region managed by the virtual machine that is not in use; the first memory region and the second memory region allocate memory space from the buffer common area as needed;
[0118] The virtual machine stack and indirect access variable stack are stored and managed through the first memory region;
[0119] The second memory region stores and manages application RAM data.
[0120] In some embodiments, a memory management method as described in the various embodiments of the present invention may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the restricted device 10 via NVM 12. When processor 11 executes a computer program stored in NVM 12 or a computer program loaded into random access memory (RAM) 13 by storage unit 18, it may perform one or more steps of a memory management method as described above in the various embodiments of the present invention. Alternatively, in other embodiments, processor 11 may be configured to execute a memory management method as described in the various embodiments of the present invention by any other suitable means (e.g., by means of firmware).
[0121] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0122] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0123] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0124] Figure 9 This is a structural diagram of a terminal provided according to an embodiment of the present invention. Figure 9 The terminal includes the restricted device 1010 as described in any embodiment of the present invention.
[0125] The restricted device 1010 can be an embedded secure element, a smart card, a SE, or an embedded device.
[0126] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0127] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A memory management method, characterized in that, Applied to resource-constrained devices, including: The memory region managed by the virtual machine is divided into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already in use; the buffer common area is the middle of the memory region managed by the virtual machine that is not in use; the first memory region and the second memory region allocate memory space from the buffer common area as needed; The first memory region stores and manages the virtual machine stack and the indirect access variable stack; wherein, the virtual machine stack is used to store function call parameters, local variables, operands, and call function stack frame information; the indirect access variable stack is used to store the elements of the function's local array variables, local structures, and union variables; memory space for the indirect access variable stack is allocated for the function in the virtual machine stack; The second memory region stores and manages application volatile storage medium RAM data.
2. The method according to claim 1, characterized in that, The application RAM data includes module global data, and the process of storing and managing the application RAM data through the second memory region includes: On any logical channel, when the virtual machine first calls the module program of the application module corresponding to the application, a second starting position is determined at the location of the buffer common area near the second memory area to allocate the memory space of module global data and module global data management information for the called application module. From the second starting position toward the first memory region, allocate and initialize the memory space for the module global data and module global data management information of the called application module.
3. The method according to claim 1, characterized in that, The application RAM data includes temporary static variable data, and the process of storing and managing the application RAM data through the second memory region includes: After the system starts running, starting from the second memory region and moving towards the first memory region, a new second memory region is obtained from the buffer common area; The newly added second memory region is used as the memory space for temporary static variable data of all applications and is initialized.
4. The method according to claim 3, characterized in that, The application RAM data includes temporary dynamic variable data. After initializing the newly added second memory region as the memory space for temporary static variable data of all applications, it also includes: When an application is first selected on a logical channel, a first starting position for allocating temporary dynamic variable data memory space for the selected application is determined at a location in the buffer common area near the second memory region. The temporary dynamic variable data memory space is allocated and initialized for the selected application from the first starting position toward the first memory region.
5. The method according to any one of claims 1-4, characterized in that, Also includes: When applying selection on any logical channel, while maintaining the continuity of memory for all remaining module global data and module global data management information, and maintaining the continuity of memory space for module global data and temporary dynamic variable data, the memory space for all module global data and module global data management information matching the current logical channel is reclaimed.
6. A memory management device, characterized in that, Configured on resource-constrained devices, including: A memory region partitioning module is used to divide the memory region managed by the virtual machine into a first memory region, a buffer common area, and a second memory region; wherein, the first memory region and the second memory region are the two ends of the memory region managed by the virtual machine that are already used; the buffer common area is the middle unused memory region of the memory region managed by the virtual machine; the first memory region and the second memory region allocate memory space from the buffer common area as needed; The first memory region storage management module is used to manage the virtual machine stack and the indirect access variable stack through the first memory region storage; wherein, the virtual machine stack is used to store function call parameters, local variables, operands, and call function stack frame information; the indirect access variable stack is used to store the elements of the function's local array variables, local structures, and union variables; and memory space for the indirect access variable stack is allocated for the function in the virtual machine stack; The second memory region storage management module is used to manage application RAM data through the second memory region storage.
7. A restricted device, characterized in that, The restricted device is equipped with an operating system, which executes a runtime environment. The restricted device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the memory management method of any one of claims 1-5.
8. A terminal, characterized in that, Includes the restricted device as described in claim 7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the memory management method of any one of claims 1-5.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the memory management method according to any one of claims 1-5.
Citation Information
Patent Citations
Management method and device for indirect access variable stack
CN116541132A
Memory management method and system, desktop computer and computer storage medium
CN118312320A