CN1321377C - Control method of smart card storage environment - Google Patents
Control method of smart card storage environment Download PDFInfo
- Publication number
- CN1321377C CN1321377C CNB2005100771594A CN200510077159A CN1321377C CN 1321377 C CN1321377 C CN 1321377C CN B2005100771594 A CNB2005100771594 A CN B2005100771594A CN 200510077159 A CN200510077159 A CN 200510077159A CN 1321377 C CN1321377 C CN 1321377C
- Authority
- CN
- China
- Prior art keywords
- space
- storage
- smart card
- piece
- temporary
- 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.)
- Expired - Fee Related
Links
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种智能卡存储环境的控制方法,智能卡存储环境由CPU、RAM存储器、ROM存储器、EEPROM存储器、逻辑运算模块、加密引擎模块、中断处理模块、CRC发生器、随机数发生器、定时器和外部接口构成,所述RAM存储器用于存储临时数据信息,所述ROM存储器和EEPROM存储器用于存储持久数据信息,在智能卡中对外部输入的数据信息首先进行存储类型分类,然后对所述不同的存储类型进行存储规则的控制,并将其存储于智能卡卡内。本发明的智能卡存储环境的控制方法有效节省智能卡平台有限的计算资源和存储资源,增强了空间分配和回收运行时的自适应性,提出了多应用运行环境下双向链表结构的持久空间的存储管理策略以及分段式的临时空间的存储管理策略,设计并实现了相应的存储分配和垃圾回收。
The invention discloses a method for controlling a smart card storage environment. The smart card storage environment consists of a CPU, a RAM memory, a ROM memory, an EEPROM memory, a logic operation module, an encryption engine module, an interrupt processing module, a CRC generator, a random number generator, a timer device and an external interface, the RAM memory is used to store temporary data information, the ROM memory and EEPROM memory are used to store persistent data information, in the smart card, the externally input data information is first classified into storage types, and then the Different storage types control the storage rules and store them in the smart card. The control method of the smart card storage environment of the present invention effectively saves the limited computing resources and storage resources of the smart card platform, enhances the adaptability of space allocation and recycling operation, and proposes the storage management of the persistent space of the bidirectional linked list structure under the multi-application operating environment Strategy and segmented temporary space storage management strategy, design and implement the corresponding storage allocation and garbage collection.
Description
技术领域technical field
本发明涉及一种对智能卡存储环境进行控制的方法,具体地说,是指一种Java智能卡的存储环境管理系统的控制方法。The invention relates to a method for controlling the storage environment of a smart card, in particular to a method for controlling a storage environment management system of a Java smart card.
背景技术Background technique
Java智能卡技术是Java虚拟机技术向有限资源设备平台的移植。Java智能卡的Applet经过编译和转换后生成虚拟机指令集的字节码程序。这些字节码再由卡上虚拟机来运行。Java虚拟机早期的运行技术主要是解释执行机制,即将字节码通过解释程序翻译为相应的本地执行代码来运行,它适合于在资源较少的设备中使用。而后,为了提高字节码的执行速度,又相继提出了编译为本地代码执行、动态编译和JIT编译执行、HotSpot技术及直接的专用硬件结构执行等运行技术。编译为本地代码的方法虽然显著地提高了速度,但却一定程度地影响了Java语言的安全机制和可移植性,这在高安全性要求的智能卡应用中显然并不适合。动态编译、JIT编译技术和HotSpot技术是在运行时将字节码编译为本地代码,这需要大量的运行时的存储资源,这在通常只有2K左右RAM的智能卡中也不具可行性。Java smart card technology is the transplantation of Java virtual machine technology to limited resource device platform. After compiling and converting, the Applet of the Java smart card generates a bytecode program of the virtual machine instruction set. These bytecodes are then run by the on-card virtual machine. The early operating technology of the Java virtual machine is mainly the interpretation and execution mechanism, that is, the bytecode is translated into the corresponding local execution code through the interpreter to run, and it is suitable for use in devices with fewer resources. Then, in order to improve the execution speed of bytecode, other operating technologies such as compiling to native code execution, dynamic compilation and JIT compilation and execution, HotSpot technology and direct dedicated hardware structure execution have been proposed. Although the method of compiling into local codes improves the speed significantly, it affects the security mechanism and portability of the Java language to a certain extent, which is obviously not suitable for smart card applications with high security requirements. Dynamic compilation, JIT compilation technology and HotSpot technology compile bytecode into local code at runtime, which requires a large amount of storage resources at runtime, which is not feasible in smart cards that usually only have about 2K of RAM.
目前也有的采用专用的智能卡硬件结构来运行字节码以提高速度,这带来的性能增益是非常显著的,但同时也成倍地提高了卡片的成本。专用的硬件结构也具有一定的局限性,如伪指令的扩展,并且在智能卡芯片和其它的有限资源设备领域目前并不存在大量的Java专用结构的CPU。At present, some smart card hardware structures are used to run bytecodes to increase the speed. The performance gain brought by this is very significant, but it also doubles the cost of the card. The dedicated hardware structure also has certain limitations, such as the expansion of pseudo-instructions, and currently there are not a large number of CPUs with a Java-specific structure in the field of smart card chips and other limited-resource devices.
内存空间的自动垃圾回收机制是Java语言的一大特点,也是Java语言安全性的保证。但由于EEPROM较慢的写速度和有限的读写次数,这使得垃圾回收在Java卡中的实现必然不同于PC平台。在存储管理方面已有的文献只是在Java Card 2.1规范的基础上,在单Applet实例运行的环境下对于临时空间管理的研究。The automatic garbage collection mechanism of the memory space is a major feature of the Java language, and it is also a guarantee of the security of the Java language. However, due to the slow write speed and limited read and write times of EEPROM, the implementation of garbage collection in the Java card must be different from that of the PC platform. The existing literature on storage management is only based on the Java Card 2.1 specification, and the research on temporary space management in the environment where a single Applet instance runs.
发明内容Contents of the invention
本发明的目的是提供一种智能卡存储环境的管理方法,该管理方法能够有效地节省智能卡平台有限的计算资源和存储资源,增强空间分配和回收运行时的自适应性。本发明提出了多应用运行环境下双向链表结构的持久空间的存储管理策略以及分段式的临时空间的存储管理策略,设计并实现了存储分配和垃圾回收管理。The purpose of the present invention is to provide a management method for the storage environment of the smart card, which can effectively save the limited computing resources and storage resources of the smart card platform, and enhance the adaptability of space allocation and recycling operation. The invention proposes a storage management strategy of a persistent space with a bidirectional linked list structure and a storage management strategy of a segmented temporary space under a multi-application operating environment, and designs and implements storage allocation and garbage collection management.
本发明的一种智能卡存储环境的控制方法,所述智能卡由CPU、RAM存储器、ROM存储器、EEPROM存储器、逻辑运算模块、加密引擎模块、中断处理模块、CRC发生器、随机数发生器、定时器和外部接口构成,所述RAM存储器用于存储临时数据信息,所述ROM存储器和EEPROM存储器用于存储持久数据信息,对外部输入的数据信息存储步骤有:A control method of a smart card storage environment of the present invention, the smart card is composed of CPU, RAM memory, ROM memory, EEPROM memory, logical operation module, encryption engine module, interrupt processing module, CRC generator, random number generator, timer Constituted with an external interface, the RAM memory is used to store temporary data information, the ROM memory and EEPROM memory are used to store persistent data information, and the steps for storing externally input data information include:
(A)对所述外部输入的数据信息进行存储类型分类,得到存储类型,(A) classify the storage type of the externally input data information to obtain the storage type,
所述存储类型有第一存储类型,用于实现持久空间的存储管理;和The storage type has a first storage type, which is used to implement storage management of persistent space; and
第二存储类型,用于实现CLEAR_ON_RESET属性的临时空间的存储管理;和A second storage type for storage management of the temporary space of the CLEAR_ON_RESET attribute; and
第三存储类型,用于实现CLEAR_ON_DESELECT属性的临时空间的存储管理;The third storage type is used to realize the storage management of the temporary space of the CLEAR_ON_DESELECT attribute;
(B)对经(A)存储分类处理后的所述存储类型按照存储规则进行存储控制,其第一存储类型存储于EEPROM存储器中;第二存储类型和第三存储类型存储于RAM存储器中,(B) carry out storage control according to the storage rules to the storage type after (A) storage classification processing, and its first storage type is stored in the EEPROM memory; the second storage type and the third storage type are stored in the RAM memory,
所述存储规则有第一存储规则,用于将所述第一存储类型按照双向链表结构进行存储以及回收,存储采用首次适配法,回收采用空间合并法;第二存储规则,用于将所述的第二存储类型按照从临时空间的高地址端开始向低地址进行存储,回收采用对象标记回收法;第三存储规则,用于将所述的第三存储类型按照从临时空间的低地址端开始向高地址进行存储,回收采用对象标记回收法。The storage rules include a first storage rule, which is used to store and recycle the first storage type according to the doubly linked list structure. The storage adopts the first adaptation method, and the recycle adopts the space combination method; the second storage rule is used to store all The second storage type described above is stored from the high address end of the temporary space to the low address, and the recovery adopts the object mark recovery method; the third storage rule is used to store the third storage type from the low address of the temporary space The end starts to store to the high address, and the recovery adopts the object mark recovery method.
本发明的优点:(一)双向链表结构的优点是通过调整连接指针,可以很容易插入或删除一个记录,节省了智能卡平台有限的计算资源和存储资源。同时方便地使检测指针向前驱和后驱方向移动,因此很容易进行实例化对象或对应用程序存储空间进行分配或删除操作。(二)分段式临时空间存储管理机制有效避免了传统控制方法中的地址冲突问题,运行时具有较强的自适应性,非常适合于智能卡的运行环境。Advantages of the present invention: (1) The advantage of the doubly linked list structure is that a record can be easily inserted or deleted by adjusting the connection pointer, which saves the limited computing resources and storage resources of the smart card platform. At the same time, it is convenient to make the detection pointer move forward and backward, so it is easy to instantiate the object or allocate or delete the storage space of the application program. (2) The segmented temporary space storage management mechanism effectively avoids the address conflict problem in the traditional control method, and has strong self-adaptability during operation, which is very suitable for the operating environment of smart cards.
附图说明Description of drawings
图1是智能卡的内部结构示意图。Figure 1 is a schematic diagram of the internal structure of a smart card.
图2是本发明持久空间的存储分配流程图。Fig. 2 is a flow chart of storage allocation of persistent space in the present invention.
图3是本发明持久空间的垃圾回收管理流程图。Fig. 3 is a flow chart of the garbage collection management of the persistent space of the present invention.
图4是本发明运行时的分段式临时空间存储分配。Fig. 4 is a segmented temporary space storage allocation when the present invention is running.
具体实施方式Detailed ways
下面将结合附图对本发明作进一步的详细说明。The present invention will be further described in detail below in conjunction with the accompanying drawings.
本发明是一种智能卡存储环境的控制方法,智能卡由CPU、RAM存储器、ROM存储器、EEPROM存储器、逻辑运算模块、加密引擎模块、中断处理模块、CRC发生器、随机数发生器、定时器和外部接口构成,所述RAM存储器用于存储临时数据信息,所述ROM存储器和EEPROM存储器用于存储持久数据信息,对外部输入的数据信息存储步骤有:The invention relates to a method for controlling the storage environment of a smart card. The smart card consists of a CPU, a RAM memory, a ROM memory, an EEPROM memory, a logical operation module, an encryption engine module, an interrupt processing module, a CRC generator, a random number generator, a timer and an external The interface is formed, the RAM memory is used to store temporary data information, the ROM memory and EEPROM memory are used to store persistent data information, and the steps for storing externally input data information include:
(A)对所述外部输入的数据信息进行存储类型分类,得到存储类型,(A) classify the storage type of the externally input data information to obtain the storage type,
所述存储类型有第一存储类型,用于实现持久空间的存储管理;和The storage type has a first storage type, which is used to implement storage management of persistent space; and
第二存储类型,用于实现CLEAR_ON_RESET属性的临时空间的存储管理;和A second storage type for storage management of the temporary space of the CLEAR_ON_RESET attribute; and
第三存储类型,用于实现CLEAR_ON_DESELECT属性的临时空间的存储管理;The third storage type is used to realize the storage management of the temporary space of the CLEAR_ON_DESELECT attribute;
(B)对经(A)存储分类处理后的所述存储类型按照存储规则进行存储控制,其第一存储类型存储于EEPROM存储器中;第二存储类型和第三存储类型存储于RAM存储器中,(B) carry out storage control according to the storage rules to the storage type after (A) storage classification processing, and its first storage type is stored in the EEPROM memory; the second storage type and the third storage type are stored in the RAM memory,
所述存储规则有第一存储规则,用于将所述第一存储类型按照双向链表结构进行存储以及回收,存储采用首次适配法,回收采用空间合并法;第二存储规则,用于将所述的第二存储类型按照从临时空间的高地址端开始向低地址进行存储,回收采用对象标记回收法;第三存储规则,用于将所述的第三存储类型按照从临时空间的低地址端开始向高地址进行存储,回收采用对象标记回收法。The storage rules include a first storage rule, which is used to store and recycle the first storage type according to the doubly linked list structure. The storage adopts the first adaptation method, and the recycle adopts the space combination method; the second storage rule is used to store all The second storage type described above is stored from the high address end of the temporary space to the low address, and the recovery adopts the object mark recovery method; the third storage rule is used to store the third storage type from the low address of the temporary space The end starts to store to the high address, and the recovery adopts the object mark recovery method.
在本发明中,采用双向链表结构的持久空间存储管理机制,其双向链表如下表所示,In the present invention, the persistent space storage management mechanism of the doubly linked list structure is adopted, and its doubly linked list is shown in the following table,
双向链表结构Doubly linked list structure
表中,HEADER项为该结构的头,包括以下四个域:Llink:指向其左节点的指针,占用2字节的存储空间。Tag:占用标记。当tag为1时,该块为占用块;tag为0时,该块为空闲块。Size:表示整个节点的大小,包括HEADER和FOOTER。Rlink:指向其右节点的指针。In the table, the HEADER item is the head of the structure, including the following four fields: Llink: a pointer pointing to its left node, occupying 2 bytes of storage space. Tag: occupancy mark. When the tag is 1, the block is an occupied block; when the tag is 0, the block is a free block. Size: Indicates the size of the entire node, including HEADER and FOOTER. Rlink: A pointer to its right node.
DATA项为一组地址连续的存储单元,是可以分配给用户使用的内存区域。The DATA item is a group of storage units with continuous addresses, which is a memory area that can be allocated to users.
FOOTER项为该结构的尾,包括以下两个域:Uplink:指向本节点头的指针,其值为当前节点的首地址。Tag:占用标志,同HEADER中的Tag域。The FOOTER item is the tail of the structure, including the following two fields: Uplink: a pointer pointing to the head of this node, whose value is the first address of the current node. Tag: occupancy flag, same as Tag field in HEADER.
在存储请求对象分配时,采用首次适配法。其工作方式为:在头指针(指向一空闲块,在对象分配时将从此空闲块开始向后搜索,因此该空闲块可看作为空闲链表的头)所指向的空闲链表中查找第一个满足要求的足够大的空间块,若该空闲块大小和所要分配的对象大小相同,则将此空闲块分配给该对象;否则将其分为两部分,一部分分配给对象,另一部分是未使用的存储区,将之作为一新的空闲块插入到空闲列表中,同时修改头指针,使之指向刚才所找到空闲块的下一空闲块,以便下次寻找空闲区时从上次结束的地方开始搜索,而不是每次都从头开始。同时考虑到当空闲空间仅比请求空间大几个字节时,此时再将该空闲块分割,则空闲链表中将会出现大量几字节的空闲块,而此空闲块将极少能被再分配,增加了存储区的外部碎片,同时减少了存储区的利用率,因此在这里我们设定一差额门限,为10字节,当空闲空间与请求空间的差额大于10字节时,将此空闲块分割;否则直接将此空闲块分配给对象,而不再做分割。分配算法的流程描述如图2所示。When storing request object allocations, the first-fit method is used. Its working method is as follows: in the free linked list pointed to by the head pointer (pointing to a free block, it will search backward from this free block when the object is allocated, so the free block can be regarded as the head of the free linked list) to find the first satisfying If the size of the free block is the same as the size of the object to be allocated, this free block is allocated to the object; otherwise, it is divided into two parts, one part is allocated to the object, and the other part is unused storage area, insert it into the free list as a new free block, and modify the head pointer at the same time to make it point to the next free block of the free block found just now, so that the next time you look for a free area, it will start from the place where it ended last time Search instead of starting from scratch every time. At the same time, considering that when the free space is only a few bytes larger than the requested space, and then divide the free block at this time, there will be a large number of free blocks of several bytes in the free list, and this free block will rarely be used. Redistribution increases the external fragmentation of the storage area and reduces the utilization rate of the storage area. Therefore, here we set a difference threshold of 10 bytes. When the difference between the free space and the requested space is greater than 10 bytes, the This free block is divided; otherwise, this free block is directly allocated to the object without further division. The flow description of the allocation algorithm is shown in Figure 2.
存储回收为对已给出存储首地址的要回收存储空间进行回收,可分以下四种情况:Storage reclamation is to reclaim the storage space to be reclaimed for the given storage first address, which can be divided into the following four situations:
1)给定块左块为空闲块,则将此给定块和左块合并,作为一个空闲块替代左块插入到空闲块队列中。1) If the left block of the given block is a free block, then the given block and the left block are merged, and inserted into the free block queue as a free block instead of the left block.
2)给定块右块为空闲块,则将此给定块和右块相合并,作为一个空闲块替代右块插入到空闲块队列中。2) If the right block of the given block is a free block, then the given block and the right block are combined, and inserted into the free block queue as a free block instead of the right block.
3)给定块左块和右块均为空闲块,则将此块和左块、右块相合并,替代左块插入到空闲块队列中,同时在空闲块队列中删除右块。3) If the left block and the right block of the given block are both free blocks, then this block is merged with the left block and the right block, and the left block is inserted into the free block queue instead of the left block, and the right block is deleted in the free block queue at the same time.
4)左块和右块均为占用块,则修改此块的占用标志为空闲,将其插入到空闲块队列中。4) If both the left block and the right block are occupied blocks, then modify the occupancy flag of this block to be free, and insert it into the free block queue.
将回收块和相邻的空闲块相合并后,修改空闲链表的头指针,使之指向刚合并的空闲块,则再分配时,从此回收块起向后搜索空闲区间。其流程图如图3所示。After merging the reclaimed block and the adjacent free block, modify the head pointer of the free list to point to the newly merged free block, and then search for free intervals backward from the reclaimed block when allocating. Its flow chart is shown in Figure 3.
多Applet运行环境下基于上下文和事件属性的分段式临时空间存储管理机制Segmented Temporary Space Storage Management Mechanism Based on Context and Event Attributes in Multi-Applet Runtime Environment
传统的存储分配方法在多Applet运行环境下对于CLEAR_ON_DESELECT存储空间的共享方案必然会产生地址冲突问题,同时由于静态分配CLEAR_ON_RESET空间,当卡上已安装的Applet用尽了已有的CLEAR_ON_RESET空间时,后续的Applet再无法下载安装到卡上。The traditional storage allocation method will inevitably cause address conflicts for the CLEAR_ON_DESELECT storage space sharing scheme in a multi-Applet operating environment. At the same time, due to the static allocation of CLEAR_ON_RESET space, when the installed Applets on the card use up the existing CLEAR_ON_RESET space, subsequent The Applet can no longer be downloaded and installed on the card.
为解决上述问题,本发明将同一上下文具有相同事件属性中的临时数组组织在同一存储段中并在持久存储空间中为每个段创建一个根节点并指向相应事件属性的数组句柄队列。实际上每个上下文中存在两个数组句柄队列,CLEAR_ON_RESET和CLEAR_ON_DESELECT事件属性队列。在运行时一个上下文也对应着相应的两个临时存储段。In order to solve the above problems, the present invention organizes the temporary arrays in the same context with the same event attribute in the same storage segment and creates a root node for each segment in the persistent storage space and points to the array handle queue of the corresponding event attribute. There are actually two array handle queues per context, the CLEAR_ON_RESET and CLEAR_ON_DESELECT event attribute queues. At runtime, a context also corresponds to two corresponding temporary storage segments.
本发明为每个存储段设置相应的段基址寄存器,数组句柄中的val_address元素存储地址为段内偏移量,实际的物理地址由基址加偏移量得到。此外,CLEAR_ON_RESET和CLEAR_ON_DESELECT存储段分别从临时空间的两端进行分配(高地址端和低地址端),其中CLEAR_ON_RESET段的生长方向为由高地址向低地址,而CLEAR_ON_DESELECT段的生长方向为由低地址向高地址,从而避免二者地址空间的重叠覆盖。The present invention sets a corresponding segment base address register for each storage segment, the storage address of the val_address element in the array handle is the offset in the segment, and the actual physical address is obtained by adding the offset to the base address. In addition, the CLEAR_ON_RESET and CLEAR_ON_DESELECT storage segments are allocated from both ends of the temporary space (high address end and low address end), where the growth direction of the CLEAR_ON_RESET segment is from high address to low address, and the growth direction of CLEAR_ON_DESELECT segment is from low address To the high address, so as to avoid the overlapping coverage of the two address spaces.
若当前请求分配的数组长度为length,数组类型为type,相应事件属性的数组句柄队列的根节点为root,则创建新的临时数组对象的过程描述如下:If the length of the array allocated by the current request is length, the array type is type, and the root node of the array handle queue of the corresponding event attribute is root, the process of creating a new temporary array object is described as follows:
Array_Handle*AllocateTransientObject()Array_Handle * AllocateTransientObject()
{{
pre_p=p=root;pre_p=p=root;
while(p<>null)while(p<>null)
{{
if((p->ref_tag==0)&&(p->length==length)&&if((p->ref_tag==0)&&(p->length==length)&&
(p->item_type==type))(p->item_type==type))
{{
//重用已有的未引用对象空间//Reuse the existing unreferenced object space
return p;return p;
}}
elseelse
{{
pre_p=p;pre_p=p;
p=p->next;p=p->next;
}}
}}
pre_p->next=new(Array_Handle);pre_p->next=new(Array_Handle);
pre_p->next->val_address=AllocateMemoryBlock(pre_p);pre_p->next->val_address=AllocateMemoryBlock(pre_p);
return pre->next;return pre->next;
}}
其中的new()函数用于在持久空间中分配Array_Handle结构并返回首地址,AllocateMemoryBlock()函数用于分配临时存储空间,入口参数指针p为当前队列的队尾指针,函数定义如下:The new() function is used to allocate the Array_Handle structure in the persistent space and return the first address. The AllocateMemoryBlock() function is used to allocate temporary storage space. The entry parameter pointer p is the tail pointer of the current queue. The function definition is as follows:
u2 AllocateMemoryBlock(Array_handle*p)u2 AllocateMemoryBlock(Array_handle * p)
{{
if(有足够的可用临时空间)if (enough temporary space available)
{{
address=p->val_address+p->length;Address=p->val_address+p->length;
return address;return address;
}}
elseelse
{{
调用临时空间垃圾回收进程;Invoke the temporary space garbage collection process;
if(有足够的可用临时空间)if (enough temporary space available)
{{
address=p->val_address+p->length;Address=p->val_address+p->length;
return address;return address;
}}
elseelse
{{
抛出临时空间内存溢出异常;Throw a temporary space memory overflow exception;
}}
}}
}}
在属于某一上下文的Applet被成功选择后,临时存储空间管理进程会根据当前的内存使用情况来为此上下文中的两个事件属性存储段确定段基址寄存器的值并遍历临时对象队列进行空间分配和初始化,同时考虑到运行时Applet的临时对象分配,在每个存储段中都根据当前的可用空间情况分配了一定的预留空间。为了存储这些与存储段相关的信息,系统在运行时为每个分配的段在RAM中维护一个段描述符(最多为8个)数据结构,其定义如下:After the Applet belonging to a certain context is successfully selected, the temporary storage space management process will determine the value of the segment base address register for the two event attribute storage segments in this context according to the current memory usage and traverse the temporary object queue for space Allocation and initialization, taking into account the temporary object allocation of Applet at runtime, a certain reserved space is allocated in each storage segment according to the current available space. In order to store these information related to storage segments, the system maintains a segment descriptor (up to 8) data structure in RAM for each allocated segment at runtime, which is defined as follows:
Segment_DescriptorSegment_Descriptor
{{
u2 Base /段基址寄存器u2 Base / segment base address register
u1 event_type //事件属性RESET或DESELECTu1 event_type //event attribute RESET or DESELECT
u2 Length //段长度u2 Length // segment length
u2 Reserve_length //预留空间长度u2 Reserve_length //Reserved space length
u1 context //对象上下文u1 context //object context
u1 Non_ref_length //未引用空间长度u1 Non_ref_length // Length of unreferenced space
}}
多Applet实例运行时的临时空间分配情况如图4所示。Figure 4 shows the temporary space allocation when multiple Applet instances are running.
当某一上下文context启动后系统分配临时空间存储段的过程描述如下:When a context is started, the process of the system allocating temporary space storage segments is described as follows:
void AllocateSegment(ulcontext)void AllocateSegment(ulcontext)
{{
s指向段描述符表中的第一个段描述符;s points to the first segment descriptor in the segment descriptor table;
while(s<>null)while(s<>null)
{{
if((s->context==0)&&(s->Length>请求长度))If((s->context==0)&&(s->Length>request length))
{{
s->context=context;s->context=context;
设置s->Reserve_length;Set s->Reserve_length;
设置s->Non_ref_length;Set s->Non_ref_length;
设置s->event_type;Set s->event_type;
return;return;
}}
s指向下一段描述符;s points to the next descriptor;
}}
以存储段为单位进行存储紧缩;Storage compaction in units of storage segments;
if(无足够的可用临时存储空间)if (not enough temporary storage available)
{{
抛出临时空间内存溢出异常;Throw a temporary space memory overflow exception;
}}
elseelse
{{
//设置相应的段描述符//Set the corresponding segment descriptor
s->context=context;s->context=context;
设置s->Length;Set s->Length;
设置s->Reserve_length;Set s->Reserve_length;
设置s->Non_ref_length;Set s->Non_ref_length;
设置s->event_type;Set s->event_type;
return;return;
}}
}}
垃圾回收管理garbage collection management
目前已有的一些垃圾回收管理机制不能完全适用于资源非常有限的智能卡环境,因此我们在综合考虑响应速度和有限资源的情况下给出了卡上临时存储空间的对象标记回收法。Some existing garbage collection management mechanisms are not fully applicable to the smart card environment with very limited resources. Therefore, we give an object mark recovery method for the temporary storage space on the card under the comprehensive consideration of response speed and limited resources.
系统最初创建的临时对象都被标记为未引用。对于被持久系统中变量所引用的对象不能被回收。因此在字节码解释器的设计中对于所有的对引用域进行赋值的指令都对被引用对象的类型进行判断并标记临时对象。若p为对象指针,则标记过程如下:Temporary objects initially created by the system are marked as unreferenced. Objects referenced by variables in the persistent system cannot be recycled. Therefore, in the design of the bytecode interpreter, for all instructions that assign values to the reference field, the type of the referenced object is judged and the temporary object is marked. If p is an object pointer, the marking process is as follows:
持久引用变量的赋值标记过程如下:The assignment marking process of persistent reference variables is as follows:
if(p->tag==00) //临时对象if(p->tag==00) //temporary object
p->ref_tag=02; //持久引用p->ref_tag=02; //persistent reference
局部引用变量的赋值标记过程如下:The assignment marking process of local reference variables is as follows:
if((p->tag==00) //临时对象if((p->tag==00) //temporary object
&&(p->ref_tag==00)) //未被引用&&(p->ref_tag==00)) //Not referenced
p->ref_tag=01; //局部变量引用p->ref_tag=01; //local variable reference
由于卡上的有限资源和实时响应特性的要求,因此在卡上依据Java栈中的局部变量来进行精确的垃圾回收是不可行的。所以我们将垃圾回收的标记点选择在Applet的select()、process()、deselect()方法返回后。此时的Java栈为空,所以只由局部变量所引用的对象均应被回收。因此在标记点处应重新标记root所指向队列中的对象,若相应的段描述符指针为s,标记过程如下:Due to the limited resources on the card and the requirements of real-time response characteristics, it is not feasible to perform precise garbage collection on the card according to the local variables in the Java stack. So we choose the mark point of garbage collection after the Applet's select (), process (), and deselect () methods return. At this time, the Java stack is empty, so objects only referenced by local variables should be recycled. Therefore, at the marking point, the object in the queue pointed to by root should be remarked. If the corresponding segment descriptor pointer is s, the marking process is as follows:
p=root;p = root;
while(p<>null)while(p<>null)
{{
if(p->ref_tag==01)if(p->ref_tag==01)
{{
//局部变量引用,标记为未引用并加到段描述符的未引用空间中//Local variable reference, marked as unreferenced and added to the unreferenced space of the segment descriptor
p->ref_tag=00;p->ref_tag=00;
s->Non_ref_length+=p->length;s->Non_ref_length+=p->length;
}}
elseelse
{{
p=p->next;p=p->next;
}}
}}
由于Applet下载到智能卡上后不会被更改并会多次重复运行,因此对于同一临时对象的多次运行引用概率非常高,所以对于局部变量引用的临时对象我们在标记过程中并不将其从队列中删除。这样在此上下文重新运行时此段RAM空间被预留出来,以利于临时对象的重用。Since the Applet will not be changed after being downloaded to the smart card and will run multiple times, the probability of multiple running references to the same temporary object is very high, so we do not remove it from the temporary object referenced by the local variable during the marking process. Deleted from the queue. In this way, this section of RAM space is reserved when the context is re-running, so as to facilitate the reuse of temporary objects.
当Applet请求分配临时对象而无可用的临时空间时,系统会启动垃圾回收进程。垃圾回收的策略步骤如下:When an applet requests to allocate a temporary object and no temporary space is available, the system starts the garbage collection process. The policy steps of garbage collection are as follows:
1)为了满足实时响应特性,采取了增量式垃圾回收的策略,当所需的存储空间可提供时即结束回收过程。1) In order to meet the real-time response characteristics, an incremental garbage collection strategy is adopted, and the recycling process ends when the required storage space is available.
2)在假设当前运行上下文中的临时对象具有较高重用率的前提下,优先垃圾回收当前未运行的上下文对应的存储段。2) On the premise that the temporary object in the current running context has a high reuse rate, the storage segment corresponding to the currently unrunning context is preferentially garbage collected.
3)优先回收预留的存储空间。3) Prioritize the recovery of reserved storage space.
4)优先垃圾回收当前运行上下文存储段的相邻存储段以减少数据移动量。4) The adjacent storage segments of the current running context storage segment are preferentially garbage collected to reduce the amount of data movement.
5)若上述操作完成后仍不能提供所需的存储空间,则对未运行上下文存储段中预留的未引用对象空间进行存储紧缩并进行回收。5) If the required storage space cannot be provided after the above operations are completed, the unreferenced object space reserved in the non-running context storage segment is compacted and reclaimed.
6)最后对运行上下文的存储段中预留的未引用对象空间进行存储紧缩并进行回收。6) Finally, perform storage compaction and reclaim the unreferenced object space reserved in the storage segment of the running context.
临时对象的垃圾回收过程描述如下:The garbage collection process of temporary objects is described as follows:
void GarbageCollection()void GarbageCollection()
{{
根据段描述符表中未运行上下文存储段的Reserve_length来判断预留空间是否满足需求;Determine whether the reserved space meets the requirements according to the Reserve_length of the unrunning context storage segment in the segment descriptor table;
if(预留空间满足需求)if (reserved space meets demand)
{{
回收未运行上下文存储段中的预留空间;Reclaim the reserved space in the non-running context storage segment;
移动相应的存储段并改变段基址寄存器;Move the corresponding storage segment and change the segment base address register;
return;return;
}}
根据段描述符表中未运行上下文存储段的Non_ref_length来判断未引用空间是否满足需求;According to the Non_ref_length of the non-running context storage segment in the segment descriptor table, it is judged whether the unreferenced space meets the requirement;
if(未引用空间满足需求)if (unreferenced space meets requirements)
{{
对未运行上下文存储段中预留的未引用对象空间进行存储紧缩并进行回Carry out storage compaction and reclaim the unreferenced object space reserved in the non-running context storage segment
收; receive;
移动相应的存储段并改变段基址寄存器;Move the corresponding storage segment and change the segment base address register;
return;return;
}}
根据段描述符表所有上下文存储段的Non_ref_length来判断未引用空间是否满足需求;According to the Non_ref_length of all context storage segments in the segment descriptor table, it is judged whether the unreferenced space meets the requirement;
if(未引用空间满足需求)if (unreferenced space meets requirements)
{{
对相应的上下文存储段中预留的未引用对象空间进行存储紧缩并进行回Carry out storage compaction and reclaim the unreferenced object space reserved in the corresponding context storage segment
收; receive;
return;return;
}}
if(上述二者的和满足需求)if (the sum of the above two meets the requirements)
{{
则分别进行上述的回收过程;The above-mentioned recycling process is carried out separately;
return;return;
}}
}}
若p、pre_p为数组句柄指针,root为队列根节点,s为段描述符指针,则对于预留的未引用对象空间进行存储紧缩的过程描述如下:If p and pre_p are array handle pointers, root is the queue root node, and s is a segment descriptor pointer, then the storage compaction process for the reserved unreferenced object space is described as follows:
void NonRefContraction()void NonRefContraction()
{{
pre_p=p=root;pre_p=p=root;
while(p<>null)while(p<>null)
{{
if(p->ref_tag==00)If(p->ref_tag==00)
{{
//未引用对象// Unreferenced object
s->Non_ref_length-=p->length; s->Non_ref_length-=p->length;
for(;队列中p的后续引用对象节点;)for(;subsequent reference object node of p in the queue;)
{{
val_address-=p->length; val_address-=p->length;
}}
p=p->next;p=p->next;
dispose(pre_p->next); dispose(pre_p->next);
pre_p->next=p;Pre_p->next=p;
}}
elseelse
{{
pre_p=p;pre_p=p;
p=p->next;p=p->next;
}}
}}
}}
当当前上下文退出运行环境时,它所对应的临时空间整个都应当被系统回收,即回收此上下文对应的全部存储段,若当前上下文为Current_context,s为段描述符指针,回收过程描述如下:When the current context exits the running environment, the entire temporary space corresponding to it should be reclaimed by the system, that is, all storage segments corresponding to this context are reclaimed. If the current context is Current_context, s is the segment descriptor pointer, and the reclaiming process is described as follows:
while(Current_context对应的段未回收完)while (the segment corresponding to Current_context has not been recycled)
{{
if(s->context==Current_context)if(s->context==Current_context)
{{
//context为0代表当前段描述符未使用//context is 0 means the current segment descriptor is not used
s->context=0;s->context=0;
}}
s指向下一段描述符;s points to the next descriptor;
}}
综上所述,本发明提供了一种智能卡存储环境的管理方法,该管理方法中采用双向链表结构进行持久空间管理,可以较为容易地插入或删除一个记录,同时方便地使检测指针向前驱和后驱方向移动,因此很容易进行实例化对象或对应用程序存储空间进行分配或删除操作。有效地节省智能卡平台有限的计算资源和存储资源。该管理方法中对临时空间采用分段式存储管理机制,有效避免了传统控制方法中的地址冲突问题,增强空间分配和回收运行时的自适应性,非常适合于智能卡的运行环境。To sum up, the present invention provides a management method for the storage environment of a smart card. In the management method, a two-way linked list structure is used for persistent space management, which can easily insert or delete a record, and at the same time conveniently make the detection pointer forward and Rear drive direction movement, so it is easy to instantiate objects or allocate or delete application storage space. Effectively save the limited computing resources and storage resources of the smart card platform. In this management method, a segmented storage management mechanism is adopted for the temporary space, which effectively avoids the address conflict problem in the traditional control method, and enhances the adaptability of space allocation and recycling operation, which is very suitable for the operating environment of smart cards.
Claims (9)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNB2005100771594A CN1321377C (en) | 2005-06-16 | 2005-06-16 | Control method of smart card storage environment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNB2005100771594A CN1321377C (en) | 2005-06-16 | 2005-06-16 | Control method of smart card storage environment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN1687904A CN1687904A (en) | 2005-10-26 |
CN1321377C true CN1321377C (en) | 2007-06-13 |
Family
ID=35305945
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CNB2005100771594A Expired - Fee Related CN1321377C (en) | 2005-06-16 | 2005-06-16 | Control method of smart card storage environment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN1321377C (en) |
Families Citing this family (13)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101344861B (en) * | 2007-07-10 | 2012-12-05 | 锐迪科微电子(上海)有限公司 | Smart card internal memory management method |
US8402217B2 (en) * | 2009-09-15 | 2013-03-19 | Marvell International Ltd. | Implementing RAID in solid state memory |
CN102053834A (en) * | 2010-12-29 | 2011-05-11 | 北京握奇数据系统有限公司 | Method and device for storing JAVA object |
CN102289411B (en) * | 2011-06-27 | 2014-03-26 | 北京握奇数据系统有限公司 | Intelligent card resource dispatching method and intelligent card |
CN102508788B (en) * | 2011-09-28 | 2014-12-10 | 华为数字技术(成都)有限公司 | SSD (solid state drive) and SSD garbage collection method and device |
CN103051869A (en) * | 2012-11-15 | 2013-04-17 | 山东中孚信息产业股份有限公司 | System and method for encrypting camera video in real time |
CN104484628B (en) * | 2014-12-17 | 2018-04-13 | 西安邮电大学 | It is a kind of that there is the multi-application smart card of encrypting and decrypting |
CN105404589B (en) * | 2015-10-29 | 2019-04-30 | 天脉聚源(北京)教育科技有限公司 | A kind of rubbish recovering method and device |
US10120655B2 (en) * | 2016-06-03 | 2018-11-06 | Microsoft Technology Licensing, Llc. | Seamless high performance interoperability between different type graphs that share a garbage collector |
CN108804339B (en) * | 2018-03-29 | 2019-07-16 | 北京白山耘科技有限公司 | A kind of memory rubbish recovering method and device |
CN109032960B (en) * | 2018-06-29 | 2023-10-10 | 北京中电华大电子设计有限责任公司 | Dynamic allocation method of smart card RAM and storage device of data structure |
KR102731127B1 (en) | 2018-09-05 | 2024-11-18 | 에스케이하이닉스 주식회사 | Memory controller and memory system having the same |
CN114610652A (en) * | 2022-03-25 | 2022-06-10 | 南京信息工程大学 | SD card data access method based on bidirectional linked list |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1289967A (en) * | 1999-09-24 | 2001-04-04 | 国际商业机器公司 | Dynamic memory administration for target data in small allied programme in Jave card |
US6220510B1 (en) * | 1997-05-15 | 2001-04-24 | Mondex International Limited | Multi-application IC card with delegation feature |
US6272607B1 (en) * | 1998-08-28 | 2001-08-07 | International Business Machines Corporation | Method and apparatus for transactional writing of data into a persistent memory |
CN1545072A (en) * | 1997-09-19 | 2004-11-10 | 施蓝姆伯格工业公司 | Smart card application-selection |
-
2005
- 2005-06-16 CN CNB2005100771594A patent/CN1321377C/en not_active Expired - Fee Related
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6220510B1 (en) * | 1997-05-15 | 2001-04-24 | Mondex International Limited | Multi-application IC card with delegation feature |
CN1545072A (en) * | 1997-09-19 | 2004-11-10 | 施蓝姆伯格工业公司 | Smart card application-selection |
US6272607B1 (en) * | 1998-08-28 | 2001-08-07 | International Business Machines Corporation | Method and apparatus for transactional writing of data into a persistent memory |
CN1289967A (en) * | 1999-09-24 | 2001-04-04 | 国际商业机器公司 | Dynamic memory administration for target data in small allied programme in Jave card |
Also Published As
Publication number | Publication date |
---|---|
CN1687904A (en) | 2005-10-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US6453403B1 (en) | System and method for memory management using contiguous fixed-size blocks | |
US6505283B1 (en) | Efficient memory allocator utilizing a dual free-list structure | |
US6594749B1 (en) | System and method for memory management using fixed-size blocks | |
US5848423A (en) | Garbage collection system and method for locating root set pointers in method activation records | |
US6510498B1 (en) | Method and apparatus for memory allocation in a multi-threaded virtual machine | |
JP3027845B2 (en) | Program control device and method | |
CN1321377C (en) | Control method of smart card storage environment | |
US7010555B2 (en) | System and method for compacting a computer system heap | |
US7480782B2 (en) | Reference-updating using per-chunk referenced-address ranges in a compacting garbage collector | |
US7136887B2 (en) | Method and mechanism for finding references in a card in time linear in the size of the card in a garbage-collected heap | |
US7043509B2 (en) | Parallel non-contiguous allocation and card parsing | |
CN1271524C (en) | Static internal storage management method | |
US6681306B1 (en) | Method and apparatus for increasing scavenging garbage collection effectiveness | |
US20090037501A1 (en) | Method and system for managing memory for a program using area | |
US8631051B2 (en) | Hybrid fragmenting real time garbage collection | |
US6219678B1 (en) | System and method for maintaining an association for an object | |
CN101295240A (en) | The Realization Method of SPM-Based Instruction Buffer in Embedded System | |
CN117785741A (en) | Heat-aware hybrid memory caching system and method | |
US7702663B2 (en) | Breaking read barrier to apply optimizations | |
US7792880B2 (en) | Method and apparatus for efficient implementation of discontiguous objects | |
Diwase et al. | Survey report on memory allocation strategies for real time operating system in context with embedded devices | |
US7058781B2 (en) | Parallel card table scanning and updating | |
JP2000099351A (en) | Program controller and memory allocation device and method | |
CN106293939B (en) | A Method for Dynamically Reusing Objects in Memory Garbage Collector | |
US20080034022A1 (en) | System and method for updating references when incrementally compacting a heap |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
C17 | Cessation of patent right | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20070613 Termination date: 20100616 |