WO2023177446A1 - Reducing reference count updates for stack variables - Google Patents

Reducing reference count updates for stack variables Download PDF

Info

Publication number
WO2023177446A1
WO2023177446A1 PCT/US2022/071138 US2022071138W WO2023177446A1 WO 2023177446 A1 WO2023177446 A1 WO 2023177446A1 US 2022071138 W US2022071138 W US 2022071138W WO 2023177446 A1 WO2023177446 A1 WO 2023177446A1
Authority
WO
WIPO (PCT)
Prior art keywords
flag
stack
heap
incr
function
Prior art date
Application number
PCT/US2022/071138
Other languages
French (fr)
Inventor
Jun Wang
Yan Zhang
Original Assignee
Futurewei Technologies, Inc.
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Futurewei Technologies, Inc. filed Critical Futurewei Technologies, Inc.
Priority to PCT/US2022/071138 priority Critical patent/WO2023177446A1/en
Publication of WO2023177446A1 publication Critical patent/WO2023177446A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • G06F12/0261Garbage collection, i.e. reclamation of unreferenced memory using reference counting

Definitions

  • the present disclosure is related to runtime systems for programming languages and, in particular, to methods and apparatus for reducing reference count updates for stack variables for automatic memory management.
  • garbage collection algorithms can be classified into two categories: reference counting and tracing.
  • tracing the approach is to determine which objects of a program should be garbage collected by tracing which objects are reachable by a chain of references from certain root objects. The remaining objects that are not reachable are taken to be garbage and the remaining objects can be collected such that the memory allocations for these remaining objects are then reclaimed as free for reuse.
  • garbage collection a number of different algorithms can be implemented for garbage collection, where the different algorithms can vary widely in complexity and performance characteristics.
  • each object maintains a count of direct references to it from other objects. This count is referred to as the object’s reference count (RC).
  • RC reference count
  • the RC of an object can change dynamically. When the RC becomes zero, the program cannot access the object anymore. Therefore, at that point, the object becomes garbage and its memory can be reclaimed.
  • reference counting Because of its simplicity, reference counting has enjoyed widespread use.
  • One key advantage of reference counting is that the overhead of memory management is evenly spread throughout program execution, whereas, in tracing, garbage collection occurs from time to time and often results in the actual program being put on hold to perform the tracing. This characteristic of reference counting allows the program to run more smoothly throughout, which is particularly desirable in applications where program responsiveness is important.
  • Another major advantage of reference counting is that garbage can be collected as soon as it becomes garbage, unlike in tracing where garbage has to wait until the next tracing to be collected.
  • reference counting also has its disadvantages.
  • a RC count in reference counting has to be accurate (otherwise, live objects may be mistaken for garbage, or vice versa)
  • the number of RC updates can be very large, since, theoretically, every time a pointer is updated, the RC for the old object is to be decremented and the RC for the new object is to be incremented. This is exacerbated by the fact that RC increment or decrement operations are not trivial. It is often the case that the RC has a maximum value. Once the maximum value is reached, no increment or decrement can be done, and the object’s RC is treated specially. Therefore, a RC increment is checked to determine if the maximum has been reached. For a RC decrement, the RC is also checked to determine if the RC is already at its maximum value.
  • the RC decrement is also checked to see if the decrement would cause the RC to become zero, and if that is the case, the object’s memory is to be recycled.
  • Such architectures and methodologies can be used in runtime systems for programming languages that use reference counting for automatic memory management.
  • Associated with objects for a function stored in heap memory are variables for the objects, where the variables can be stored in a stack frame.
  • a stack-decr-flag can be associated with a slot of a stack frame for the function, where the stack-decr-flag is used in decrementing or in skipping decrementing a reference count for an object associated with the slot.
  • a heap-incr-flag can be associated with the object, where the heap-incr-flag is used in incrementing or in skipping incrementing the reference count for the object.
  • the stack-decr-flag and the heap-incr- flag can be used to control RC updates for the object associated with updates to stack variables for the object.
  • a data structure can be implemented with both the stack-decr-flag and the heap-incr-flag structured as flags (including one-bit flags).
  • the stack-decr-flag can be implemented as a bit in a location associated with a slot of the stack frame for a function and a heap-incr-flag can be implemented as a bit in the object associated with the slot.
  • a computing system comprising a memory storing instructions and at least one processor in communication with the memory, the at least one processor configured, upon execution of the instructions to perform the steps of: associate a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function.
  • the stack-decr-flag controls a decrementing of a reference count (RC) for an object associated with the slot.
  • the instructions also include instructions to associate a heap-incr-flag with the object.
  • the heap-incr-flag controls an incrementing of the reference count for the object.
  • the stack-decr-flag or the heap-incr-flag is used for updating the reference count for the object.
  • the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, with the bit location being in addition to bit locations of the slot.
  • the stack-decr-flag is assigned to a bit location in the slot.
  • the heap-incr-flag is assigned to a bit location in a header of the object.
  • the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
  • the at least one processor is operable to associate a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
  • the at least one processor is operable to reset the heap-incr-flag of all the objects in the buffer and then empty the buffer in response to the function exiting operation.
  • the at least one processor executes the instructions to perform write-to- stack operations including: decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
  • the at least one processor executes the instructions to perform operations for the function to create a new object.
  • the operations include: generating the new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr-flag for the new object, the set heap-incr-flag indicating an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • the at least one processor executes the instructions to perform operations in response to receiving a return value for the function.
  • the operations include: handling of the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • the at least one processor executes the instructions to perform operations in response to the function exiting.
  • the operations include clearing stack-decr- flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • a computer-implemented method of updating a reference count of an object for a function comprises associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, a stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot, associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count for the object, and updating the reference count for the object using the stack-decr-flag or the heap-incr-flag.
  • RC reference count
  • the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, the bit location being in addition to bit locations of the slot.
  • the stack-decr-flag is assigned to a bit location in the slot.
  • the heap-incr-flag is assigned to a bit location in a header of the object.
  • the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
  • the computer-implemented method includes associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr- flag.
  • the computer-implemented method includes resetting the heap-incr-flag of all the objects in the buffer and then emptying the buffer in response to the function exiting operation.
  • the computer-implemented method includes: decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and, after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
  • the computer-implemented method includes: generating a new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr- flag for the new object, the set heap-incr-flag indicating an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • the computer-implemented method includes treating a return value for the function as an object of the function by handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • the computer-implemented method includes, in response to the function exiting, clearing stack-decr-flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr- flag.
  • a non-transitory computer-readable medium storing instructions for processing data, which, when executed by at least one processor, cause the at least one processor to perform operations comprising associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot.
  • RC reference count
  • the operations further comprise associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count.
  • the heap-incr-flag When the heap-incr-flag is set, the heap-incr-flag indicates the incrementing of the reference count will be skipped.
  • the operations include controlling an update of the reference count for the object using the stack-decr-flag or the heap- incr-flag.
  • the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, with the bit location being in addition to bit locations of the slot.
  • the stack-decr-flag is assigned to a bit location in the slot.
  • the heap-incr-flag is assigned to a bit location in a header of the object.
  • the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
  • the operations include associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
  • the operations include resetting the heap-incr-flag of all the objects in the buffer and then emptying the buffer in response to the function exiting operation.
  • the operations include decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and, after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
  • the operations include: generating a new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr-flag for the new object, the set heap-incr-flag indicating an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • the operations include treating a return value for the function as an object of the function by: handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • the operations include, in response to the function exiting, clearing stack-decr-flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • Figure 1 is a data structure for a stack-decr-flag, according to an example embodiment.
  • Figure 2 is a data structure for an heap-incr-flag for a heap object, according to an example embodiment.
  • Figure 3 is a flow diagram of a write stack procedure with respect to a given object and given slot of a stack frame for a function, according to an example embodiment.
  • Figure 4 is a flow diagram of an object creation for a function, according to an example embodiment.
  • Figure 5 is a flow diagram of for a method of return of a value by a function call, according to an example embodiment.
  • Figure 6 is a flow diagram of an updating method of a reference count of an object for a function, according to an example embodiment.
  • Figure 7 is a diagram illustrating components of a computing system that can implement algorithms and perform methods structured to reduce reference count updates for objects with respect to operations on stack variables for automatic memory management, according to an example embodiment.
  • the functions or algorithms described herein may be implemented in software in an embodiment.
  • the software may comprise computer-executable instructions stored on computer-readable media or computer-readable storage device such as one or more non-transitory memories or other type of hardwarebased storage devices, either local or networked.
  • modules which may be software, hardware, firmware, or any combination thereof. Multiple functions may be performed in one or more modules as desired, and the embodiments described are merely examples.
  • the software may be executed on a digital signal processor, application-specific integrated circuit (ASIC), a microprocessor, or other type of processor operating on a computer system, such as a personal computer (PC), server, or other computer system, turning such computer system into a specifically programmed machine.
  • ASIC application-specific integrated circuit
  • microprocessor or other type of processor operating on a computer system, such as a personal computer (PC), server, or other computer system, turning such computer system into a specifically programmed machine.
  • Computer-readable non-transitory media includes all types of computer-readable media, including magnetic storage media, optical storage media, and solid-state storage media and specifically excludes signals.
  • the software can be installed in and sold with the devices that handle reference counts for stack variables as taught herein.
  • the software can be obtained and loaded into such devices, including obtaining the software via a disc medium or from any manner of network or distribution system, including, for example, from a server owned by the software creator or from a server not owned but used by the software creator.
  • the software can be stored on a server for distribution over the Internet, for example.
  • a source program is basically a set of functions constructed together, according to the language used.
  • a compiler which is software, operates on the source program to compile the source code into binary machine code to run on a computing system.
  • the compiler determines the number of registers to hold the variables for the function. This transformation process is called register allocation. Because the number of registers is small, some local variables of a function cannot be allocated to registers. Memory space is provided for such variables. This memory space is called stack memory.
  • a stack is a segment of memory for storing an ordered collection of data items, where the addition of new items and the removal of existing items always takes place at the top of the stack. New items are stored by being "pushed" onto the top of the stack. An item stored at the base of the stack can only be removed (or “popped") when all other items have been removed from the stack. Therefore, items stored at or near the base of the stack have been in the stack the longest. This ordering principle is called LIFO, or last-in first-out.
  • the computing system allocates some stack memory for the function.
  • This piece of stack memory is known as the stack frame for the function. Its size is fixed and pre-determined by the compiler.
  • the stack frame for the function is deallocated, in which case all local variables of this function become invalid.
  • the allocation and deallocation of the stack frame is automatically performed.
  • the variables allocated on the stack frame are called stack variables. Each stack variable is assigned to a location called a slot in the stack frame.
  • a stack frame is also known as an activation frame or activation record.
  • Memory space is allocated during the execution of instructions of a program, where this memory space is effectively a pile of memory space available to programmers to allocate and de-allocate. This pile is referred to as a heap space or a heap. Heap space is used for the dynamic memory allocation at runtime. New objects are always created in heap space and the references to these objects are stored in stack memory. These objects can have global access and can be accessed from anywhere in the program. Herein, these objects can also be referred to as objects or heap objects.
  • the stack is a place in the memory of the computing system where the variables that are declared and initialized before runtime are stored.
  • the heap is the section of the memory of the computing system where the objects referenced by the variables are created or initialized at runtime are stored.
  • garbage is collected. During the garbage collection, objects that are no longer used are cleared, thus making space for new objects. This garbage collection operation can be performed as needed, or on a schedule. Without garbage collection operations being performed, an allocated heap space could become cluttered up with old, unused objects.
  • a pointer pl is assigned to object x.
  • Reference counting can be categorized herein as stack reference counting operations and heap reference counting operations.
  • Stack reference counting operations are defined to be reference counting operations in which there is a RC incrementing or RC decrementing, when variables for an object (i.e., pointers) are written to a stack slot.
  • Heap reference counting operations comprise all RC incrementing or RC decrementing operations other than stack reference counting operations.
  • An example of a heap reference counting operation can be based on a heap object pointing to another heap object.
  • object y has a member p, also known as a field, wherein the member p is a pointer. Initially, the member p is a null pointer in that it does not point to any object.
  • RC(x) is incremented by 1. If object y is later updated such that the pointer p then points to a different object, RC(x) is decremented by 1.
  • these reference counting operations are other than stack reference counting operations.
  • deferred reference counting is a scheme that only counts heap references as a reference count. In other words, it excludes references from or by stack variables or static variables. Obviously, this changes the semantics of reference counting.
  • RC coalescing is a variation of deferred reference counting. It reduces RC updates on the heap. It is motivated by the observation that in a sequence of updates to a heap slot, e.g., aO — > al — > a2 ... — > an, it requires a series of RC updates. If a heap slot goes through a sequence of updates: aO — > al — > a2 — > an, the 2n updates to the RC, for example, are made: a decrement to RC(aO), an increment to RC(al), a decrement to RC(al) , an increment to RC(a2), ...
  • Figure 1 is a data structure for a stack-decr-flag (i.e., stack decrement flag, stack flag, or d-flag).
  • the stack-decr-flag is associated with a stack and is used in the embodiments herein to control the decrementing of the RC.
  • the decrementing will generally comprise reducing the RC by an integer value of one.
  • the data structure includes a stack frame 102.
  • the stack frame 102 in the example shown has four slots 102A, 102B, 102C, and 102D.
  • Associated with slot 102A in this example is a bit location 103 A for a first a stack-decr-flag.
  • Associated with slot 102B is a bit location 103B for a second stack-decr-flag.
  • Associated with slot 102C is a bit location 103C for a third stack-decr-flag.
  • Associated with slot 102C is a bit location 103C for a fourth stack-decr-flag.
  • four slots and four stack-decr-flag bit locations are shown, it should be understood that the stack frame 102 can have more or less than four slots (with corresponding stack-decr-flag bit locations).
  • the slots 102A, 102B, 102C, and 102D contain a pointer 1 for a first object of the function, a pointer 2 for a second object of the function, a pointer 3 for a third object of the function, and a pointer 4 for a fourth object of the function, respectively.
  • the stack-decr-flags in bit locations 103 A, 103B, 103C, and 103D are extra bits relative to the stack variables.
  • the RC is to be decremented.
  • Stack frame 102 (and all the stack- decr-flag bits associated with stack frame 102) are discarded when the function exits.
  • a stack-decr-flag can be stored in the stack variable itself, wherein the stack variable is stored in the slot and the stack variable is associated with an object for the function.
  • a procedure can be implemented to reduce reference count updates for objects with respect to operations on stack variables for the objects. Such procedures can be implemented without affecting the reference counting on the heap.
  • reductions of RC updates for stack variables can be realized using flags to indicate that stack reference counting operations can be skipped.
  • a flag is a value that acts as a signal. Typically, the value of the flag is used to determine the next step of a program.
  • Flags can be structured binary flags, such as a one-bit flag having a value of “0”or “1,” which contain a Boolean value (true or false). Alternatively, the flags can be different from binary flags.
  • Data structures can be generated wherein a stack-decr-flag is associated with a stack slot and a heap-incr-flag is associated with a heap object.
  • the stack-decr-flag i.e., a stack decrement flag, stack flag, or d-flag
  • the stack-decr-flag indicates the decrementing of the RC will be skipped.
  • the stack-decr-flag indicates the RC will be decremented.
  • the decrementing of the RC will occur when either the slot is being overwritten with a new value, or when the function exits. If the function exits, the stack-decr-flags for the object will be discarded.
  • the heap-incr-flag (i.e., a heap increment flag, heap flag, or i-flag) controls an incrementing of the RC for the object.
  • the heap-incr-flag flag indicates the incrementing of the RC will be skipped.
  • the heap-incr-flag indicates the RC will be incremented.
  • Algorithms can be implemented that set, use, and clear the flags. Together, stack-decr-flags and heap-incr-flags can reduce a significant proportion of RC updates for the heap object associated with updates to stack variables for the heap object. In this approach, the combined overhead of setting the flags, checking the flags, and clearing the flags can, in general, be less than the overhead of RC incrementing/decrementing operations that are omitted as a result of using the scheme.
  • Reduction of processing of RC updates for stack variables can use two binary flags to indicate that stack reference counting operations can be skipped. These flags can be set in certain situations and cleared when certain conditions are attained. The flags in some embodiments can be allocated as one-bit flags.
  • the heap-incr-flag of a heap object can be located in the header of the heap object. Reduction of processing of RC updates for stack variables can be divided into operations for RC decrementing using stack-decr-flags, and for RC incrementing using heap-incr-flags.
  • the set status for the stack-decr-flag and the heap-incr-flag can be a “1” value for set and can be a “0” value for a non-set status. In other embodiments, depending on the logic employed, the stack-decr-flag and the heap-incr-flag can be a “0” for set and a “1” for non-set. Additional components of a computing system can include one or more buffers that can be used in procedures with stack-decr-flags and heap-incr-flags for reducing RC updates for stack variables. For each function of a program, a buffer holding object pointers can be associated with the function.
  • Figure 2 is a data structure for an heap-incr-flag for a heap object 215.
  • Heap object 215 can include a header 220 for an object proper 225.
  • a bit location 230 in header 220 can be used to store an heap-incr-flag.
  • an unused least significant bit (LSB) or unused most significant bit (MSB) can be used. The unused LSB or unused MSB can be used as a bit location for a heap-incr-flag if a bit location 230 in header 220 is unavailable to hold an heap- incr-flag.
  • LSB least significant bit
  • MSB unused most significant bit
  • Header 220 for heap object 215 can be used for storing runtime information such as, but not limited to, type information, synchronization, and a reference count.
  • the heap-incr-flag can comprise an extra bit with respect to conventional runtime information in a header of a heap object, but will normally not use extra storage.
  • a buffer can be used to hold heap objects whose heap-incr- flag is set in the function. When the function exits, heap-incr-flags in all heap objects in the buffer can be cleared.
  • a RC decrementing is performed for an old object and a RC incrementing is performed for a new object in a basic reference counting algorithm
  • a RC decrementing is performed for the old object only if the stack-decr-flag is clear, and a RC incrementing for the new object is performed only if the heap-incr-flag is not set.
  • the stack-decr-flag is set according to the heap-incr-flag.
  • Figure 3 is a flow diagram of a write stack procedure 300 with respect to a given object and given slot of a stack frame for a function.
  • the slot of the write_stack procedure 300 is the current stack slot under consideration and an old object is considered as the occupant of the current stack slot.
  • a determination is made as to whether the old object and the given object are the same.
  • a determination is made as to whether an heap-incr-flag of the object equals a one, indicating a set status.
  • write_stack procedure 300 ends at 370.
  • the RC for the old object is decremented.
  • a variable for the given object is written to the given slot of the write_stack procedure 300.
  • the variable can be a pointer to the given object or can be an address for the object.
  • write_stack procedure 300 ends at 370.
  • FIG 4 is a flow diagram of an object creation for a function with respect to an heap-incr-flag and stack-decr-flag approach.
  • an object is created from the heap for the function. This creation can be conducted according to conventional practices for creating an object from the heap.
  • a call is made to a write_stack (object, slot) operation that uses stack-decr-flags and heap-incr-flags similar to or identical to write_stack procedure 300 of Figure 3.
  • the object is added to a buffer associated with the function.
  • the buffer can be structured to contain objects having heap-incr-flags in the set status.
  • the RC for the new object is 1, which is performed in write_stack() operation; the stack-decr-flag for the corresponding stack slot is 0, which is performed in write_stack() operation; the heap-incr-flag for the object is 1, which is set after the call of write_stack(); and the object is added to the buffer for the function.
  • a decrementing of the RC for the object is allowed to be performed on a new object in the function where it is created to allow the object to become garbage if the creation is inside a loop. In this case, the next iteration will make the object created in the previous iteration become garbage. Therefore, the heap-incr-flag in the object itself is used with the stack-decr-flag for the stack slot.
  • Figure 5 is a flow diagram of a method of return of a value by a function call with respect to stack-decr-flags and heap-incr-flags.
  • a callee returns a value as an object.
  • a determination is made as to whether the RC of this object is greater than zero.
  • the procedure for a new object is followed, similar to or identical to the new object procedure of Figure 4.
  • a determination is made as to whether the heap-incr-flag of the object equals one.
  • the object is added to the function’s buffer that contains objects having heap-incr-flags in the set status.
  • the write_stack (object, slot) operation that uses stack- decr-flags and heap-incr-flags, similar to or identical to the write_stack procedure 300 of Figure 3, is called to write the variable corresponding to the returned value to the stack frame.
  • FIG. 6 is a flow diagram of a method 600 of updating of a RC of an object for a function.
  • Computer-implemented method 600 can be performed using at least one processor executing stored instructions.
  • a stack-decr-flag can be associated with a slot of a stack frame for a function, where the stack frame can have one or more slots for the function.
  • the stack- decr-flag controls a decrementing of the RC for an object associated with the slot.
  • a heap-incr-flag is associated with the object to control an incrementing of the reference count for the object.
  • the heap-incr-flag indicates the incrementing of the reference count will be skipped.
  • the stack-decr-flag and the heap-incr-flag are related, wherein the determination to not skip an incrementing is to make or enable an incrementing. Separate flags are therefore used for incrementing and decrementing a RC for an object.
  • an update of the RC for the object is controlled using the stack-decr-flag or the heap-incr-flag.
  • Variations of method 600 or methods similar to method 600 can include a number of different embodiments that may be combined depending on the application of such methods and/or the architecture of devices or systems in which such methods are implemented. Variations of such methods can include variations of the format for the stack-decr-flag or variations of the format for the heap-incr-flag.
  • the stack-decr-flag can be a flag assigned to a bit location in the slot.
  • the stack-decr-flag can be a flag assigned to a bit location corresponding to the slot of the stack frame, where the bit location is in addition to bit locations of the slot.
  • the heap-incr-flag can be a flag assigned to a bit location in a header of the object.
  • the heap-incr-flag can be a flag assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
  • the flags controlling decrementing the RC and incrementing the RC can be flags structured with more than one bit each.
  • Variations of method 600 or methods similar to method 600 can include associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. Objects with a heap-incr- flag with a non-set status can be with respect to placing such objects in the buffer.
  • the computer-implemented method can include clearing all objects in the buffer in response to the function exiting operation.
  • Variations of method 600 or methods similar to method 600 can include operations to perform write-to-stack operations for a function, to perform operations to create a new object for a function, to perform operations in response to receiving a return value for the function, to perform operations in response to the function exiting operation, and other function operations.
  • Performing write-to-stack operations can include decrementing a RC for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is set and therefore indicates the decrementing of the RC will be skipped.
  • a RC for a new object associated with the given slot of the stack frame can be incremented in response to a determination that a heap-incr-flag for the new object is not set, indicating the RC will be incremented.
  • the stack-decr-flag for the slot can be set according to the heap-incr-flag of the new object.
  • Creating a new object for a function can include generating a new object from a heap memory and performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object.
  • a heap-incr-flag for the new object can be placed to a set status to skip an incrementing of the RC for the new object.
  • the new object can be added to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a heap-incr-flag with a set status.
  • a return value for the function can be treated as an object of the function in a number of ways.
  • the return value can be handled as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value, and a heap-incr-flag can be generated in the return value, in response to a RC for the return value being equal to zero.
  • a stack-decr-flag can be marked for a slot in stack frame of the function associated with the return value to a set status
  • a heap-incr-flag in the return value can be marked to a set status
  • the return value can be added to a buffer for the function.
  • the buffer can be configured to hold, for the function, one or more objects having a heap-incr-flag with a set status.
  • a number of operations can be performed in response to the function exiting operation.
  • the operations can include clearing stack-decr-flags for all slots of the stack frame for the function and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a heap-incr-flag with a set status.
  • a non-transitory machine-readable storage device such as computer-readable non-transitory medium
  • the physical structures of such instructions can be operated on by at least one processor.
  • executing these physical structures can cause the machine to perform operations comprising associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack- decr-flag controlling a decrementing or skipping a decrementing of a reference count for an object associated with the slot, and associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing or skipping an incrementing of the reference count for the object.
  • An updating of the RC for the object can be performed using the stack-decr-flag or the heap-incr-flag.
  • the stack-decr-flag can be a flag assigned to a bit location corresponding to the slot of the stack frame, where the bit location is in addition to bit locations of the slot or the bit location is assigned to a bit location in the slot.
  • the heap-incr-flag can be a flag assigned to a bit location in a header of the object or assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
  • Variations of operations, from instructions of the non-transitory machine-readable storage device executed by the at least one processor, can include associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
  • the operations can exclude objects having a non-set heap-incr-flag. All objects in the buffer can be cleared in response to exiting of the function from operation. In response to the function exiting operation, the heap-incr-flag of all the objects in the buffer can be reset and the buffer can be emptied.
  • Activities to execute write -to -stack operations for a function can include decrementing a RC for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set. For a new object associated with the given slot of the stack frame, in response to a determination that a heap-incr-flag for the new object is not set, incrementing a reference count for the new object. Operations after overwriting the new object to the slot can include setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
  • Activities to execute operations to create a new object for a function can include generating a new object from a heap memory and performing write- to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object.
  • the operations can include setting a heap- incr-flag for the new object, the set heap-incr-flag indicating skipping incrementing of the RC for the new object.
  • the operations can include adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • Activities to execute operations in response to receiving a return value for the function can include handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a RC for the return value being equal to zero; or setting a stack-decr-flag for a slot in the stack frame of the function associated with the return value, setting a heap- incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • Activities to execute operations in response to the function exiting operation can include clearing stack-decr-flags for all slots of the stack frame for the function and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • a computing system operable to use reference counting for automatic memory management can comprise a memory storing instructions and at least one processor in communication with the memory, where the at least one processor executes the instructions.
  • the at least one processor executes the instructions to associate a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function.
  • the stack-decr-flag controls a decrementing or skipping a decrementing of a reference count for an object associated with the slot.
  • the at least one processor also executes the instructions to associate a heap-incr-flag with the object to control an incrementing or skipping an incrementing of a reference count for the object.
  • the at least one processor can perform updating the RC for the object using the stack-decr-flag or the heap-incr-flag.
  • the stack- decr-flag and the heap-incr-flag can be used to indicate that stack RC operations can be skipped, where these flags are set in certain situations and cleared according to the activity for the function.
  • Variations of such a computing system or similar computing systems can include a number of different embodiments that may or may not be combined depending on the application of such computing systems and/or the architecture of computing systems in which methods, as taught herein, are implemented.
  • the at least one processor can be structured to be operable to execute operations associated with reference counting directed to automatic memory reclamation.
  • Variations can include the format for the stack-decr-flag or the format for the heap-incr-flag.
  • the stack- decr-flag can be a flag assigned to a bit location in the slot.
  • the stack-decr-flag can be a flag assigned to a bit location corresponding to the slot of the stack frame, where the bit location is in addition to bit locations of the slot.
  • the heap- incr-flag can be a flag assigned to a bit location in a header of the object.
  • the heap-incr-flag can be a flag assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
  • the flags controlling decrementing the RC and incrementing the RC can be flags structured with more than one bit each.
  • Variations of such a computing system or similar computing systems can include one or more buffers that can be associated with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
  • the at least one processor of such a computing system or similar computing systems can be structured to execute the association of a selected buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. Objects having a non-set heap-incr-flag can be excluded from being assigned to the one or more buffers.
  • the processor can clear all objects in the buffer in response to the function exiting operation.
  • the processor of such a computing system can execute instructions to perform write-to-stack operations, perform new object creation operations, perform return value operations, perform function exiting operations, and perform other function operations.
  • Write-to-stack operations of the computing system can include decrementing a RC for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set, indicating the RC can be decremented.
  • the write-to- stack operations can include incrementing a RC for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr- flag for the new object is not set, indicating the RC can be incremented. After overwriting the new object to the slot, the stack-decr-flag for the slot can be set according to the heap-incr-flag of the new object.
  • New object creation operations of such a computing system can include generation of the new object from a heap memory and performance of write-to- stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object.
  • the new object creation operations can include placement of a heap-incr-flag for the new object to a status to skip an incrementing of the RC for the new object to a set status and addition of the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • Return value operations of such a computing system can include handling of the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value, in response to a RC for the return value being equal to zero or marking a stack-decr-flag for a slot in stack frame of the function associated with the return value to a set status, marking a heap-incr- flag in the return value to a set status, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • Function exiting operations can include clearing stack-decr-flags for all slots of the stack frame for the function and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
  • each activity of a function can be associated with an individual buffer for the activity. Such activities can include but are not limited to write-to- stack operations for a function, operations to create a new object for a function, operations in response to receiving a return value for the function, operations in response to the function exiting operation, and other function operations
  • FIG. 7 is a diagram illustrating components of a computing system 700 that can implement algorithms and perform methods structured to reduce RC updates for objects with respect to operations on stack variables for automatic memory management. All components need not be used in various embodiments.
  • Computing system 700 can include a processor 702, memory 703, removable storage 711, non-removable storage 722, and a cache 707.
  • Processor 702 can be implemented as multiple processors.
  • Computing system 700 can be structured in different forms in different embodiments.
  • the storage can also or alternatively include cloud-based storage accessible via a network, such as the Internet or remote server-based storage.
  • a solid state drive SSD
  • Memory 703 can include volatile memory 714 and/or non-volatile memory 708.
  • Computing system 700 can include or have access to a computing environment that includes a variety of computer-readable media, such as volatile memory 714, non-volatile memory 708, removable storage 711 and/or nonremovable storage 722.
  • Computer storage can include random-access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD ROM), Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium capable of storing computer-readable instructions.
  • RAM random-access memory
  • ROM read-only memory
  • EPROM erasable programmable read-only memory
  • EEPROM electrically erasable programmable read-only memory
  • flash memory or other memory technologies
  • Computing system 700 can include or have access to a computing environment that includes input interface 726, output interface 724, and a communication interface 716.
  • Output interface 724 can include a display device, such as a touchscreen, that also can serve as an input device.
  • the input interface 726 can include one or more of a touchscreen, touchpad, mouse, keyboard, camera, one or more device -specific buttons, one or more sensors integrated within or coupled via wired or wireless data connections to the computing system 700, and other input devices.
  • the communication interface 716 can exchange communications with external device and networks.
  • the computing system 700 can operate in a networked environment using a communication connection to connect to one or more remote computers, such as one or more remote compute nodes.
  • the remote computer can include a PC, a server, a router, a network PC, a peer device or other common data flow network switch, or the like.
  • the communication connection can include a Local Area Network (LAN), a Wide Area Network (WAN), cellular, Wi-Fi, Bluetooth, or other networks.
  • LAN Local Area Network
  • WAN Wide Area Network
  • Wi-Fi Wireless Fidelity
  • Bluetooth Wireless Fidelity
  • the various components of computing system 700 are connected with a system bus 720.
  • Computer-readable instructions stored on a computer-readable medium are executable by the processor 702 of the computing system 700.
  • the program 718 can be performed using heap memory and stack memory that may be allocated in memory 703 and used in conjunction with the two flag architecture for reducing RC updates for objects with respect to operations on stack variables for the objects.
  • a hard drive, CD-ROM, and RAM are some examples of articles including a non-transitory computer-readable medium, such as a storage device.
  • the terms computer-readable medium and storage device do not include carrier waves to the extent carrier waves are deemed too transitory.
  • Storage can also include networked storage, such as a storage area network (SAN).
  • Program 718 of computing system 700 can be used to cause processor 702 to perform one or more methods or algorithms described herein.
  • the components of the illustrative devices, systems, and methods employed in accordance with the illustrated embodiments can be implemented, at least in part, in digital electronic circuitry, analog electronic circuitry, or in computer hardware, firmware, software, or in combinations of them. These components can be implemented, for example, as a computer program product such as a computer program, program code or computer instructions tangibly embodied in a machine-readable storage device, for execution by, or to control the operation of, data processing apparatus such as a programmable processor, a computer, or multiple computers.
  • DSP digital signal processor
  • ASIC application-specific integrated circuit
  • FPGA field-programmable gate array
  • a general-purpose processor may be a microprocessor, but in the alternative, the processor may be any conventional processor, controller, microcontroller, or state machine.
  • a processor may also be implemented as a combination of computing devices, e.g., a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a DSP core, or any other such configuration.
  • processors suitable for the execution of a computer program include, by way of example, both general and special purpose microprocessors, and processors of any kind of digital computer.
  • a processor will receive instructions and data from a read-only memory or a random-access memory or both.
  • the elements of a computer include a processor for executing instructions and one or more memory devices for storing instructions and data.
  • a computer will also include, or be operatively coupled to receive data from or transfer data to, or both, one or more mass storage devices for storing data, e.g., magnetic, magneto-optical disks, or optical disks.
  • Information carriers suitable for embodying computer program instructions and data include all forms of nonvolatile memory, including by way of example, semiconductor memory devices, e.g., electrically programmable read-only memory or ROM (EPROM), EEPROM, flash memory devices, and/or data storage disks (e.g., magnetic disks, internal hard disks, or removable disks, magneto-optical disks, CD-ROM, or DVD-ROM disks).
  • semiconductor memory devices e.g., electrically programmable read-only memory or ROM (EPROM), EEPROM, flash memory devices, and/or data storage disks (e.g., magnetic disks, internal hard disks, or removable disks, magneto-optical disks, CD-ROM, or DVD-ROM disks).
  • EPROM electrically programmable read-only memory
  • EEPROM electrically programmable read-only memory
  • flash memory devices e.g., electrically programmable read-only memory or ROM (EPROM), EEPROM, flash memory devices, and/or data
  • reducing RC updates for stack variables can be attained using procedures for skipping RC incrementing or RC decrementing operations for the stack variables.
  • the two flag approach using a stack-decr- flag with respect to RC decrementing and a heap-incr-flag with respect to RC incrementing, can provide for an optimization of a basic RC algorithm where root set references are counted. This two flag approach does not require tracing and is suitable for systems where tracing-induced delays are not desirable. Compared with other approaches, this two flag approach can significantly reduce the overall number of RC operations without using deferred reference counting.
  • this method reduces the number of RC operations not by excluding stack references, but by setting flags in the stack slots and the objects, thereby allowing unnecessary RC operations to be skipped.
  • this two flag approach allows objects to be reclaimed as soon as they become garbage.
  • this two flag approach does not require tracing, therefore does not have tracing- induced delays.
  • the two flag approach using a stack-decr-flag and a heap-incr-flag has a wide range of applications because many programming languages use garbage collection and such programming languages are used in the whole spectrum of computing platforms, from the Internet of Things (loT) devices to data centers.
  • the two flag approach using a stack-decr-flag and a heap-incr-flag can be particularly beneficial to systems where memory capacity is limited and thus immediate reclamation of garbage is highly desirable and to systems that are designed for garbage collection-induced delays to be as low as possible.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Executing Machine-Instructions (AREA)

Abstract

A computing system is provided, comprising a memory storing instructions and at least one processor in communication with the memory. The at least one processor is configured, upon execution of the instructions, to perform the following steps: associate a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot, associate a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count for the object, and updating the reference count for the object using the stack-decr-flag or the heap-incr-flag.

Description

REDUCING REFERENCE COUNT UPDATES FOR STACK VARIABLES
TECHNICAL FIELD
[0001] The present disclosure is related to runtime systems for programming languages and, in particular, to methods and apparatus for reducing reference count updates for stack variables for automatic memory management.
BACKGROUND
[0002] Many programming languages adopt automatic memory management to relieve programmers of the burden of explicit memory management at the program -level. Memory management is implemented to dynamically allocate memory to a program upon request and reallocate the provided memory for reuse when no longer used by the requesting program. Automatic memory management to reallocate memory resources is commonly referred to as garbage collection. Broadly speaking, garbage collection algorithms can be classified into two categories: reference counting and tracing.
[0003] In tracing, the approach is to determine which objects of a program should be garbage collected by tracing which objects are reachable by a chain of references from certain root objects. The remaining objects that are not reachable are taken to be garbage and the remaining objects can be collected such that the memory allocations for these remaining objects are then reclaimed as free for reuse. However, a number of different algorithms can be implemented for garbage collection, where the different algorithms can vary widely in complexity and performance characteristics.
[0004] In reference counting with respect to objects of a program, each object maintains a count of direct references to it from other objects. This count is referred to as the object’s reference count (RC). Clearly, as a program proceeds, the RC of an object can change dynamically. When the RC becomes zero, the program cannot access the object anymore. Therefore, at that point, the object becomes garbage and its memory can be reclaimed.
[0005] Because of its simplicity, reference counting has enjoyed widespread use. One key advantage of reference counting is that the overhead of memory management is evenly spread throughout program execution, whereas, in tracing, garbage collection occurs from time to time and often results in the actual program being put on hold to perform the tracing. This characteristic of reference counting allows the program to run more smoothly throughout, which is particularly desirable in applications where program responsiveness is important. Another major advantage of reference counting is that garbage can be collected as soon as it becomes garbage, unlike in tracing where garbage has to wait until the next tracing to be collected.
[0006] However, reference counting also has its disadvantages. First, because a RC count in reference counting has to be accurate (otherwise, live objects may be mistaken for garbage, or vice versa), the number of RC updates can be very large, since, theoretically, every time a pointer is updated, the RC for the old object is to be decremented and the RC for the new object is to be incremented. This is exacerbated by the fact that RC increment or decrement operations are not trivial. It is often the case that the RC has a maximum value. Once the maximum value is reached, no increment or decrement can be done, and the object’s RC is treated specially. Therefore, a RC increment is checked to determine if the maximum has been reached. For a RC decrement, the RC is also checked to determine if the RC is already at its maximum value.
Additionally, the RC decrement is also checked to see if the decrement would cause the RC to become zero, and if that is the case, the object’s memory is to be recycled.
SUMMARY
[0007] It is an object of various embodiments to provide an efficient architecture and methodology for reducing the number of times that reference counts of objects for functions of a program are updated. Such architectures and methodologies can be used in runtime systems for programming languages that use reference counting for automatic memory management. Associated with objects for a function stored in heap memory are variables for the objects, where the variables can be stored in a stack frame. A stack-decr-flag can be associated with a slot of a stack frame for the function, where the stack-decr-flag is used in decrementing or in skipping decrementing a reference count for an object associated with the slot. A heap-incr-flag can be associated with the object, where the heap-incr-flag is used in incrementing or in skipping incrementing the reference count for the object. Together, the stack-decr-flag and the heap-incr- flag can be used to control RC updates for the object associated with updates to stack variables for the object. A data structure can be implemented with both the stack-decr-flag and the heap-incr-flag structured as flags (including one-bit flags). The stack-decr-flag can be implemented as a bit in a location associated with a slot of the stack frame for a function and a heap-incr-flag can be implemented as a bit in the object associated with the slot. These flags can be set in certain situations and cleared when certain conditions are attained to reduce the total RC updates made for the object.
[0008] According to a first aspect of the present disclosure, there is provided a computing system comprising a memory storing instructions and at least one processor in communication with the memory, the at least one processor configured, upon execution of the instructions to perform the steps of: associate a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function. The stack-decr-flag controls a decrementing of a reference count (RC) for an object associated with the slot. The instructions also include instructions to associate a heap-incr-flag with the object. The heap-incr-flag controls an incrementing of the reference count for the object. The stack-decr-flag or the heap-incr-flag is used for updating the reference count for the object.
[0009] In a first implementation form of the computing system according to the first aspect as such, the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, with the bit location being in addition to bit locations of the slot.
[0010] In a second implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the stack-decr-flag is assigned to a bit location in the slot.
[0011] In a third implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the heap-incr-flag is assigned to a bit location in a header of the object.
[0012] In a fourth implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
[0013] In a fifth implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the at least one processor is operable to associate a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. [0014] In a sixth implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the at least one processor is operable to reset the heap-incr-flag of all the objects in the buffer and then empty the buffer in response to the function exiting operation.
[0015] In a seventh implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the at least one processor executes the instructions to perform write-to- stack operations including: decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
[0016] In an eighth implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the at least one processor executes the instructions to perform operations for the function to create a new object. The operations include: generating the new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr-flag for the new object, the set heap-incr-flag indicating an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0017] In a ninth implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the at least one processor executes the instructions to perform operations in response to receiving a return value for the function. The operations include: handling of the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0018] In a tenth implementation form of the computing system according to the first aspect as such or any preceding implementation form of the first aspect, the at least one processor executes the instructions to perform operations in response to the function exiting. The operations include clearing stack-decr- flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0019] According to a second aspect of the present disclosure, there is provided a computer-implemented method of updating a reference count of an object for a function. The computer-implemented method comprises associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, a stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot, associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count for the object, and updating the reference count for the object using the stack-decr-flag or the heap-incr-flag.
[0020] In a first implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such, the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, the bit location being in addition to bit locations of the slot.
[0021] In a second implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the stack-decr-flag is assigned to a bit location in the slot.
[0022] In a third implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the heap-incr-flag is assigned to a bit location in a header of the object.
[0023] In a fourth implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
[0024] In a fifth implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the computer-implemented method includes associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr- flag.
[0025] In a sixth implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the computer-implemented method includes resetting the heap-incr-flag of all the objects in the buffer and then emptying the buffer in response to the function exiting operation.
[0026] In a seventh implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the computer-implemented method includes: decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and, after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
[0027] In an eighth implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the computer-implemented method includes: generating a new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr- flag for the new object, the set heap-incr-flag indicating an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0028] In a ninth implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the computer-implemented method includes treating a return value for the function as an object of the function by handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0029] In a tenth implementation form of the computer-implemented method of updating a reference count of an object for a function according to the second aspect as such or any preceding implementation form of the second aspect, the computer-implemented method includes, in response to the function exiting, clearing stack-decr-flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr- flag.
[0030] According to a third aspect of the present disclosure, there is provided a non-transitory computer-readable medium storing instructions for processing data, which, when executed by at least one processor, cause the at least one processor to perform operations comprising associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot. When the stack-decr-flag is set, the stack-decr-flag indicates the decrementing of the reference count will be skipped. The operations further comprise associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count. When the heap-incr-flag is set, the heap-incr-flag indicates the incrementing of the reference count will be skipped. The operations include controlling an update of the reference count for the object using the stack-decr-flag or the heap- incr-flag.
[0031] In a first implementation form of the non-transitory computer-readable medium according to the third aspect as such, the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, with the bit location being in addition to bit locations of the slot.
[0032] In a second implementation form of the non-transitory computer- readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the stack-decr-flag is assigned to a bit location in the slot.
[0033] In a third implementation form of the non-transitory computer-readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the heap-incr-flag is assigned to a bit location in a header of the object.
[0034] In a fourth implementation form of the non-transitory computer- readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
[0035] In a fifth implementation form of the non-transitory computer-readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the operations include associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
[0036] In a sixth implementation form of the non-transitory computer-readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the operations include resetting the heap-incr-flag of all the objects in the buffer and then emptying the buffer in response to the function exiting operation.
[0037] In a seventh implementation form of the non-transitory computer- readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the operations include decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and, after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
[0038] In an eighth implementation form of the non-transitory computer- readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the operations include: generating a new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr-flag for the new object, the set heap-incr-flag indicating an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0039] In a ninth implementation form of the non-transitory computer-readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the operations include treating a return value for the function as an object of the function by: handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0040] In a tenth implementation form of the non-transitory computer-readable medium according to the third aspect as such or any preceding implementation form of the third aspect, the operations include, in response to the function exiting, clearing stack-decr-flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0041] Any one of the foregoing examples may be combined with any one or more of the other foregoing examples to create a new embodiment in accordance with the present disclosure.
BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The drawings illustrate generally, by way of example, but not by way of limitation, various embodiments discussed in the present document.
[0043] Figure 1 is a data structure for a stack-decr-flag, according to an example embodiment.
[0044] Figure 2 is a data structure for an heap-incr-flag for a heap object, according to an example embodiment.
[0045] Figure 3 is a flow diagram of a write stack procedure with respect to a given object and given slot of a stack frame for a function, according to an example embodiment.
[0046] Figure 4 is a flow diagram of an object creation for a function, according to an example embodiment.
[0047] Figure 5 is a flow diagram of for a method of return of a value by a function call, according to an example embodiment.
[0048] Figure 6 is a flow diagram of an updating method of a reference count of an object for a function, according to an example embodiment.
[0049] Figure 7 is a diagram illustrating components of a computing system that can implement algorithms and perform methods structured to reduce reference count updates for objects with respect to operations on stack variables for automatic memory management, according to an example embodiment.
DETAILED DESCRIPTION
[0050] In the following description, reference is made to the accompanying drawings that form a part hereof, and in which is shown by way of illustration specific embodiments which may be practiced. These embodiments are described in sufficient detail to enable those skilled in the art to practice the embodiments, and it is to be understood that other embodiments may be utilized, and that structural, logical, mechanical, and electrical changes may be made. The following description of example embodiments is, therefore, not to be taken in a limited sense.
[0051] The functions or algorithms described herein may be implemented in software in an embodiment. The software may comprise computer-executable instructions stored on computer-readable media or computer-readable storage device such as one or more non-transitory memories or other type of hardwarebased storage devices, either local or networked. Further, such functions correspond to modules, which may be software, hardware, firmware, or any combination thereof. Multiple functions may be performed in one or more modules as desired, and the embodiments described are merely examples. The software may be executed on a digital signal processor, application-specific integrated circuit (ASIC), a microprocessor, or other type of processor operating on a computer system, such as a personal computer (PC), server, or other computer system, turning such computer system into a specifically programmed machine.
[0052] Computer-readable non-transitory media includes all types of computer-readable media, including magnetic storage media, optical storage media, and solid-state storage media and specifically excludes signals. It should be understood that the software can be installed in and sold with the devices that handle reference counts for stack variables as taught herein. Alternatively, the software can be obtained and loaded into such devices, including obtaining the software via a disc medium or from any manner of network or distribution system, including, for example, from a server owned by the software creator or from a server not owned but used by the software creator. The software can be stored on a server for distribution over the Internet, for example.
[0053] When a program is written for a computing system, it is generated as a source program. A source program is basically a set of functions constructed together, according to the language used. After the source program has been generated, a compiler, which is software, operates on the source program to compile the source code into binary machine code to run on a computing system. In the transformation process, for each function of the program, the compiler determines the number of registers to hold the variables for the function. This transformation process is called register allocation. Because the number of registers is small, some local variables of a function cannot be allocated to registers. Memory space is provided for such variables. This memory space is called stack memory. A stack is a segment of memory for storing an ordered collection of data items, where the addition of new items and the removal of existing items always takes place at the top of the stack. New items are stored by being "pushed" onto the top of the stack. An item stored at the base of the stack can only be removed (or "popped") when all other items have been removed from the stack. Therefore, items stored at or near the base of the stack have been in the stack the longest. This ordering principle is called LIFO, or last-in first-out.
[0054] Each time that a function is called, the computing system allocates some stack memory for the function. This piece of stack memory is known as the stack frame for the function. Its size is fixed and pre-determined by the compiler. After the function exits operation, the stack frame for the function is deallocated, in which case all local variables of this function become invalid. The allocation and deallocation of the stack frame is automatically performed. The variables allocated on the stack frame are called stack variables. Each stack variable is assigned to a location called a slot in the stack frame. A stack frame is also known as an activation frame or activation record.
[0055] Memory space is allocated during the execution of instructions of a program, where this memory space is effectively a pile of memory space available to programmers to allocate and de-allocate. This pile is referred to as a heap space or a heap. Heap space is used for the dynamic memory allocation at runtime. New objects are always created in heap space and the references to these objects are stored in stack memory. These objects can have global access and can be accessed from anywhere in the program. Herein, these objects can also be referred to as objects or heap objects.
[0056] The stack is a place in the memory of the computing system where the variables that are declared and initialized before runtime are stored. The heap is the section of the memory of the computing system where the objects referenced by the variables are created or initialized at runtime are stored. When the heap becomes full, garbage is collected. During the garbage collection, objects that are no longer used are cleared, thus making space for new objects. This garbage collection operation can be performed as needed, or on a schedule. Without garbage collection operations being performed, an allocated heap space could become cluttered up with old, unused objects.
[0057] In a basic reference counting process for garbage collection, when an object x is created on the heap, a pointer pl is assigned to object x. Initially, a reference count (RC) of the object x is RC(x) = 0. Then, with pl given an address, an RC incrementing is performed, resulting in RC(x) = 1. When another pointer p2 is assigned to object x, an RC incrementing is performed, resulting in RC(x) = 2. When pl is subsequently updated to point to another object, an RC decrementing is performed, resulting in RC(x) = 1 (and the pointer pl is added to this other object). When p2 is updated to point to something else, after pl has been updated to point to another object, another RC decrementing is performed, resulting in RC(x) = 0 for object x, which means that no pointer points to object x. Object x is now garbage, and the memory that object x occupies on the heap can be reclaimed.
[0058] Reference counting can be categorized herein as stack reference counting operations and heap reference counting operations. Stack reference counting operations are defined to be reference counting operations in which there is a RC incrementing or RC decrementing, when variables for an object (i.e., pointers) are written to a stack slot. Heap reference counting operations comprise all RC incrementing or RC decrementing operations other than stack reference counting operations.
[0059] An example of a heap reference counting operation can be based on a heap object pointing to another heap object. Consider object x and object y on the heap. In this example, object y has a member p, also known as a field, wherein the member p is a pointer. Initially, the member p is a null pointer in that it does not point to any object. When the pointer p is changed to point to the object x, RC(x) is incremented by 1. If object y is later updated such that the pointer p then points to a different object, RC(x) is decremented by 1. With the object y being a heap object, these reference counting operations are other than stack reference counting operations.
[0060] In the technical literature, a number of optimizations have been proposed for reference counting. One optimization is known as deferred reference counting, which is a scheme that only counts heap references as a reference count. In other words, it excludes references from or by stack variables or static variables. Obviously, this changes the semantics of reference counting. In this process, a count of zero (RC=0) does not necessarily mean the object is garbage. Therefore, from time to time, live objects are traced and real garbage is collected. In short, this optimization eliminates RC updates on the stack at the cost of resorting to performing tracing operations before being able to collect garbage.
[0061] Another optimization known as RC coalescing is a variation of deferred reference counting. It reduces RC updates on the heap. It is motivated by the observation that in a sequence of updates to a heap slot, e.g., aO — > al — > a2 ... — > an, it requires a series of RC updates. If a heap slot goes through a sequence of updates: aO — > al — > a2 — > an, the 2n updates to the RC, for example, are made: a decrement to RC(aO), an increment to RC(al), a decrement to RC(al) , an increment to RC(a2), ... , an increment to RC(an), but only the first and the last are necessary. The scheme therefore tries to eliminate the intermediate updates by taking a snapshot of the heap at each tracing. With coalescing, to avoid intermediate updates, buffers are used to track which objects should have a decremented RC and which heap slots should have an incremented RC.
[0062] Another optimization has been proposed as a variation of RC coalescing. This technique involves optimization regarding new objects to further reduce RC operations.
[0063] Figure 1 is a data structure for a stack-decr-flag (i.e., stack decrement flag, stack flag, or d-flag). The stack-decr-flag is associated with a stack and is used in the embodiments herein to control the decrementing of the RC. The decrementing will generally comprise reducing the RC by an integer value of one. The data structure includes a stack frame 102. The stack frame 102 in the example shown has four slots 102A, 102B, 102C, and 102D. Associated with slot 102A in this example is a bit location 103 A for a first a stack-decr-flag. Associated with slot 102B is a bit location 103B for a second stack-decr-flag. Associated with slot 102C is a bit location 103C for a third stack-decr-flag. Associated with slot 102C is a bit location 103C for a fourth stack-decr-flag. Although four slots and four stack-decr-flag bit locations are shown, it should be understood that the stack frame 102 can have more or less than four slots (with corresponding stack-decr-flag bit locations). In this example of the stack frame 102 for a function, the slots 102A, 102B, 102C, and 102D contain a pointer 1 for a first object of the function, a pointer 2 for a second object of the function, a pointer 3 for a third object of the function, and a pointer 4 for a fourth object of the function, respectively. For each slot 102A, 102B, 102C, and 102D of the stack frame 102 for a function, the stack-decr-flags in bit locations 103 A, 103B, 103C, and 103D are extra bits relative to the stack variables. If the stack-decr- flag bit associated with a given slot is not set (d=0), then the RC is to be decremented. The RC decrementing can be made, for example, when the current function exits and when the given slot is being overwritten with a new value. If the stack-decr-flag associated with a given slot is set (d= 1), then a RC decrementing is skipped and not performed. Stack frame 102 (and all the stack- decr-flag bits associated with stack frame 102) are discarded when the function exits.
[0064] In various embodiments, a stack-decr-flag can be stored in the stack variable itself, wherein the stack variable is stored in the slot and the stack variable is associated with an object for the function. As a result, with the stack- decr-flag stored in a slot of stack frame 102, the stack-decr-flag is cleared when the slot is overwritten or when the function exits (and the stack-decr-flag does not need to be separately cleared).
[0065] Because values are pushed onto and popped off of the stack during operation, a significantly large number of reference counting operations can be performed. It has been observed that a significant proportion (in some cases over 90%) of the total RC updates happen to stack variables. In various embodiments, a procedure can be implemented to reduce reference count updates for objects with respect to operations on stack variables for the objects. Such procedures can be implemented without affecting the reference counting on the heap.
[0066] In various embodiments, reductions of RC updates for stack variables can be realized using flags to indicate that stack reference counting operations can be skipped. A flag is a value that acts as a signal. Typically, the value of the flag is used to determine the next step of a program. Flags can be structured binary flags, such as a one-bit flag having a value of “0”or “1,” which contain a Boolean value (true or false). Alternatively, the flags can be different from binary flags.
[0067] Data structures can be generated wherein a stack-decr-flag is associated with a stack slot and a heap-incr-flag is associated with a heap object. The stack-decr-flag (i.e., a stack decrement flag, stack flag, or d-flag) controls a decrementing of the RC for an object associated with the slot. When the stack- decr-flag is set, the stack-decr-flag indicates the decrementing of the RC will be skipped. Correspondingly, when the stack-decr-flag is not set, the stack-decr- flag indicates the RC will be decremented. The decrementing of the RC will occur when either the slot is being overwritten with a new value, or when the function exits. If the function exits, the stack-decr-flags for the object will be discarded.
[0068] The heap-incr-flag (i.e., a heap increment flag, heap flag, or i-flag) controls an incrementing of the RC for the object. When the heap-incr-flag is set, the heap-incr-flag flag indicates the incrementing of the RC will be skipped. When the heap-incr-flag is not set, then the heap-incr-flag indicates the RC will be incremented.
[0069] Algorithms can be implemented that set, use, and clear the flags. Together, stack-decr-flags and heap-incr-flags can reduce a significant proportion of RC updates for the heap object associated with updates to stack variables for the heap object. In this approach, the combined overhead of setting the flags, checking the flags, and clearing the flags can, in general, be less than the overhead of RC incrementing/decrementing operations that are omitted as a result of using the scheme.
[0070] Reduction of processing of RC updates for stack variables can use two binary flags to indicate that stack reference counting operations can be skipped. These flags can be set in certain situations and cleared when certain conditions are attained. The flags in some embodiments can be allocated as one-bit flags. The heap-incr-flag of a heap object can be located in the header of the heap object. Reduction of processing of RC updates for stack variables can be divided into operations for RC decrementing using stack-decr-flags, and for RC incrementing using heap-incr-flags.
[0071] The set status for the stack-decr-flag and the heap-incr-flag can be a “1” value for set and can be a “0” value for a non-set status. In other embodiments, depending on the logic employed, the stack-decr-flag and the heap-incr-flag can be a “0” for set and a “1” for non-set. Additional components of a computing system can include one or more buffers that can be used in procedures with stack-decr-flags and heap-incr-flags for reducing RC updates for stack variables. For each function of a program, a buffer holding object pointers can be associated with the function. Various algorithms can be implemented with respect to when and how stack-decr-flags and heap-incr-flags are set, how stack-decr-flags and heap-incr-flags are used to reduce RC operations, and when stack-decr-flags and heap-incr-flags are cleared.
[0072] Figure 2 is a data structure for an heap-incr-flag for a heap object 215. Heap object 215 can include a header 220 for an object proper 225. A bit location 230 in header 220 can be used to store an heap-incr-flag. Alternatively, an unused least significant bit (LSB) or unused most significant bit (MSB) can be used. The unused LSB or unused MSB can be used as a bit location for a heap-incr-flag if a bit location 230 in header 220 is unavailable to hold an heap- incr-flag.
[0073] If the heap-incr-flag is set (i.e., i= 1) when a stack variable for heap object 215 is written to stack frame 102 of Figure 1, the RC of heap object 215 is not incremented, that is, an RC incrementing operation is to be skipped. Header 220 for heap object 215 can be used for storing runtime information such as, but not limited to, type information, synchronization, and a reference count. The heap-incr-flag can comprise an extra bit with respect to conventional runtime information in a header of a heap object, but will normally not use extra storage. For each function, a buffer can be used to hold heap objects whose heap-incr- flag is set in the function. When the function exits, heap-incr-flags in all heap objects in the buffer can be cleared.
[0074] With the use of stack-decr-flags and heap-incr-flags, various algorithms associated with operation of stack memory and heap memory can be modified from conventional approaches. Using an heap-incr-flag and stack-decr-flag approach, an algorithm for writing a value to a slot of a stack frame, such as stack frame 102 of Figure 1, with respect to an object can be implemented in the following manner (using "i-bit" instead of the heap-incr-flag and using "d-flag" instead of the stack-decr-flag): write_stack(obj, slot) old obj := current occupant of slot
IF old obj = obj THEN
IF i bit(obj) = 0 THEN d_flag(slot) := 0
ELSE d_flag(slot) := 1
ENDIF
ELSE
IF d flag(slot) = 0 THEN
— RC(old obj)
ENDIF
Write obj to slot
IF i bit(obj) = 0 THEN
++RC(obj) d_flag(slot) := 0
ELSE d_flag(slot) := 1
ENDIF
ENDIF
[0075] While a RC decrementing is performed for an old object and a RC incrementing is performed for a new object in a basic reference counting algorithm, in the above approach a RC decrementing is performed for the old object only if the stack-decr-flag is clear, and a RC incrementing for the new object is performed only if the heap-incr-flag is not set. The stack-decr-flag is set according to the heap-incr-flag.
[0076] Figure 3 is a flow diagram of a write stack procedure 300 with respect to a given object and given slot of a stack frame for a function. At operation 310, the slot of the write_stack procedure 300 is the current stack slot under consideration and an old object is considered as the occupant of the current stack slot. At operation 315, a determination is made as to whether the old object and the given object are the same. At operation 320, in response to the determination at operation 315 being in the affirmative, a determination is made as to whether an heap-incr-flag of the object equals a one, indicating a set status. At operation 325, in response to the determination at operation 320 being that the heap-incr- flag equals one, the stack-decr-flag for the given slot is set (d=l). At operation 330, in response to the determination at operation 320 being that the heap-incr- flag does not equal one (i=0), the stack-decr-flag for the given slot is cleared, which is a not set status (d=0) . At completing operation 325 or operation 330, both of which places the stack-decr-flag in a status based on the status of the heap-incr-flag, write_stack procedure 300 ends at 370.
[0077] At operation 335, in response to the determination at 315 being in the negative, a determination is made as to whether the stack-decr-flag for the given slot equals one, which is the set status. At operation 340, in response to the determination at 335 being in the negative, the RC for the old object is decremented. At operation 345, in response to the determination at 335 being in the affirmative or after completing operation 340, a variable for the given object is written to the given slot of the write_stack procedure 300. The variable can be a pointer to the given object or can be an address for the object. At operation 350, after completing operation 345, a determination is made as to whether the heap-incr-flag of the given object equals one, which is a set status. At operation 355, in response to determination 350 being in the affirmative, the stack-decr- flag for the given slot is set (d= 1 ) . At operation 360, in response to determination 350 being in the negative, the RC for the given object of the write_stack procedure 300 is incremented and the stack-decr-flag for the given slot is cleared (d=0). At completing operation 355 or operation 360, both of which place the stack-decr-flag in a status based on the status of the heap-incr- flag, write_stack procedure 300 ends at 370.
[0078] Using an heap-incr-flag and stack-decr-flag approach, an algorithm for a function of a program to create a new object can be implemented in the following manner:
// runtime function for creating new object obj := normal heap object creation write_stack(obj, slot) // note: heap-incr-flag not set Set heap-incr-flag of obj Add obj to buffer associated with f()
Because the heap-incr-flag is not set when calling write_stack (), the stack-decr- flag for the stack-decr-flag will be cleared.
[0079] Figure 4 is a flow diagram of an object creation for a function with respect to an heap-incr-flag and stack-decr-flag approach. At 410, an object is created from the heap for the function. This creation can be conducted according to conventional practices for creating an object from the heap. At 420, a call is made to a write_stack (object, slot) operation that uses stack-decr-flags and heap-incr-flags similar to or identical to write_stack procedure 300 of Figure 3. At 430, following completion of the call to the write_stack (object, slot) operation, the heap-incr-flag for the object given in the argument of these operations is set (i= 1 ) . At 440, the object is added to a buffer associated with the function. The buffer can be structured to contain objects having heap-incr-flags in the set status.
[0080] At the end of the creation process, the RC for the new object is 1, which is performed in write_stack() operation; the stack-decr-flag for the corresponding stack slot is 0, which is performed in write_stack() operation; the heap-incr-flag for the object is 1, which is set after the call of write_stack(); and the object is added to the buffer for the function. A decrementing of the RC for the object is allowed to be performed on a new object in the function where it is created to allow the object to become garbage if the creation is inside a loop. In this case, the next iteration will make the object created in the previous iteration become garbage. Therefore, the heap-incr-flag in the object itself is used with the stack-decr-flag for the stack slot.
[0081] Using an heap-incr-flag and stack-decr-flag approach, an algorithm for when a function call returns a heap object can be implemented in the following manner (using "i-bit" instead of the heap-incr-flag and using "d-flag" instead of the stack-decr-flag):
// Refer to the return value as obj
IF RC(obj) > 0 THEN
IF i bit(obj) not set THEN Set heap-incr-flag of obj Add obj to buffer associated with f() ENDIF write_stack(obj, slot) ELSE // RC(obj) = 0 follow procedure for new object ENDIF [0082] With respect to RC(obj) > 0, depending on implementation, the condition may be different. Basically, this differentiates whether the returned object can be treated as a new object created in the caller. With respect to write_stack(obj, slot), the heap-incr-flag is set (i= 1) such that an incrementing of the RC is skipped and a future decrementing of the RC will be skipped.
[0083] Figure 5 is a flow diagram of a method of return of a value by a function call with respect to stack-decr-flags and heap-incr-flags. At 510, a callee returns a value as an object. At 520, a determination is made as to whether the RC of this object is greater than zero. At 530, in response to a negative determination at 520, the procedure for a new object is followed, similar to or identical to the new object procedure of Figure 4. At 540, a determination is made as to whether the heap-incr-flag of the object equals one. At 550, in response to a negative determination at 540, the heap-incr-flag for the object is set (i=l). At 560, the object is added to the function’s buffer that contains objects having heap-incr-flags in the set status. At 570, in response to adding the object to the function’s buffer or in response to a positive determination at 540, the write_stack (object, slot) operation that uses stack- decr-flags and heap-incr-flags, similar to or identical to the write_stack procedure 300 of Figure 3, is called to write the variable corresponding to the returned value to the stack frame.
[0084] At the end of handling the function call that returns heap object, if the RC of the object is zero at the time of return, the return object is treated as a new object created in the function. Otherwise, the RC remains the same with an incrementing of the RC for the object skipped and the stack-decr-flag for the stack slot is set (d= 1), which prevents a future decrementing of the RC when the slot is overwritten. The heap-incr-flag for object is also set (i= 1) . If heap-incr- flag is set at this point, the object is added to the buffer for the function.
[0085] Using an heap-incr-flag and stack-decr-flag approach, an algorithm for when a function exits operation can be implemented in the following manner (using "i-bit" instead of the heap-incr-flag and using "d-flag" instead of the stack-decr-flag):
Function_exits()
FOR EACH slot in the stack frame DO IF d flag(slot) not set THEN --RC(obj)
ENDIF
FOR EACH obj in buffer DO Clear heap-incr-flag of obj // stack-decr-flags are associated with the stack frame, therefore automatically discarded; if not, they need to be explicitly cleared [0086] Figure 6 is a flow diagram of a method 600 of updating of a RC of an object for a function. Computer-implemented method 600 can be performed using at least one processor executing stored instructions. At operation 610, a stack-decr-flag can be associated with a slot of a stack frame for a function, where the stack frame can have one or more slots for the function. The stack- decr-flag controls a decrementing of the RC for an object associated with the slot. When the stack-decr-flag is set, the stack-decr-flag indicates the decrementing of the RC will be skipped. Correspondingly, when the stack-decr- flag is not set, the stack-decr-flag indicates the RC will be decremented. At operation 620, a heap-incr-flag is associated with the object to control an incrementing of the reference count for the object. When the heap-incr-flag is set, the heap-incr-flag indicates the incrementing of the reference count will be skipped. The stack-decr-flag and the heap-incr-flag are related, wherein the determination to not skip an incrementing is to make or enable an incrementing. Separate flags are therefore used for incrementing and decrementing a RC for an object. At operation 630, an update of the RC for the object is controlled using the stack-decr-flag or the heap-incr-flag.
[0087] Variations of method 600 or methods similar to method 600 can include a number of different embodiments that may be combined depending on the application of such methods and/or the architecture of devices or systems in which such methods are implemented. Variations of such methods can include variations of the format for the stack-decr-flag or variations of the format for the heap-incr-flag. The stack-decr-flag can be a flag assigned to a bit location in the slot. The stack-decr-flag can be a flag assigned to a bit location corresponding to the slot of the stack frame, where the bit location is in addition to bit locations of the slot. The heap-incr-flag can be a flag assigned to a bit location in a header of the object. The heap-incr-flag can be a flag assigned to an unused least significant bit of the object or to an unused most significant bit of the object. In other embodiments, the flags controlling decrementing the RC and incrementing the RC can be flags structured with more than one bit each.
[0088] Variations of method 600 or methods similar to method 600 can include associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. Objects with a heap-incr- flag with a non-set status can be with respect to placing such objects in the buffer. The computer-implemented method can include clearing all objects in the buffer in response to the function exiting operation.
[0089] Variations of method 600 or methods similar to method 600 can include operations to perform write-to-stack operations for a function, to perform operations to create a new object for a function, to perform operations in response to receiving a return value for the function, to perform operations in response to the function exiting operation, and other function operations. Performing write-to-stack operations can include decrementing a RC for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is set and therefore indicates the decrementing of the RC will be skipped. A RC for a new object associated with the given slot of the stack frame can be incremented in response to a determination that a heap-incr-flag for the new object is not set, indicating the RC will be incremented. After overwriting the new object to the slot, the stack-decr-flag for the slot can be set according to the heap-incr-flag of the new object.
[0090] Creating a new object for a function can include generating a new object from a heap memory and performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object. A heap-incr-flag for the new object can be placed to a set status to skip an incrementing of the RC for the new object. The new object can be added to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a heap-incr-flag with a set status.
[0091] A return value for the function can be treated as an object of the function in a number of ways. The return value can be handled as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value, and a heap-incr-flag can be generated in the return value, in response to a RC for the return value being equal to zero. Alternatively, a stack-decr-flag can be marked for a slot in stack frame of the function associated with the return value to a set status, a heap-incr-flag in the return value can be marked to a set status, and the return value can be added to a buffer for the function. The buffer can be configured to hold, for the function, one or more objects having a heap-incr-flag with a set status.
[0092] A number of operations can be performed in response to the function exiting operation. The operations can include clearing stack-decr-flags for all slots of the stack frame for the function and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a heap-incr-flag with a set status.
[0093] In various embodiments, a non-transitory machine-readable storage device, such as computer-readable non-transitory medium, can comprise instructions stored thereon, which, when performed by a machine, cause the machine to perform operations, where the operations comprise one or more features similar to or identical to features of methods and techniques described with respect to method 600, variations thereof, and/or features of other methods taught herein such as associated with Figures 1-7. The physical structures of such instructions can be operated on by at least one processor. For example, executing these physical structures can cause the machine to perform operations comprising associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack- decr-flag controlling a decrementing or skipping a decrementing of a reference count for an object associated with the slot, and associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing or skipping an incrementing of the reference count for the object. An updating of the RC for the object can be performed using the stack-decr-flag or the heap-incr-flag.
[0094] The stack-decr-flag can be a flag assigned to a bit location corresponding to the slot of the stack frame, where the bit location is in addition to bit locations of the slot or the bit location is assigned to a bit location in the slot. The heap-incr-flag can be a flag assigned to a bit location in a header of the object or assigned to an unused least significant bit of the object or to an unused most significant bit of the object. [0095] Variations of operations, from instructions of the non-transitory machine-readable storage device executed by the at least one processor, can include associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. The operations can exclude objects having a non-set heap-incr-flag. All objects in the buffer can be cleared in response to exiting of the function from operation. In response to the function exiting operation, the heap-incr-flag of all the objects in the buffer can be reset and the buffer can be emptied.
[0096] From instructions of the non-transitory machine-readable storage device, operations of a number of activities can be executed by the at least one processor. Activities to execute write -to -stack operations for a function can include decrementing a RC for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set. For a new object associated with the given slot of the stack frame, in response to a determination that a heap-incr-flag for the new object is not set, incrementing a reference count for the new object. Operations after overwriting the new object to the slot can include setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
[0097] Activities to execute operations to create a new object for a function can include generating a new object from a heap memory and performing write- to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object. The operations can include setting a heap- incr-flag for the new object, the set heap-incr-flag indicating skipping incrementing of the RC for the new object. The operations can include adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0098] Activities to execute operations in response to receiving a return value for the function can include handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a RC for the return value being equal to zero; or setting a stack-decr-flag for a slot in the stack frame of the function associated with the return value, setting a heap- incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0099] Activities to execute operations in response to the function exiting operation can include clearing stack-decr-flags for all slots of the stack frame for the function and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0100] In various embodiments, a computing system operable to use reference counting for automatic memory management can comprise a memory storing instructions and at least one processor in communication with the memory, where the at least one processor executes the instructions. The at least one processor executes the instructions to associate a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function. The stack-decr-flag controls a decrementing or skipping a decrementing of a reference count for an object associated with the slot. The at least one processor also executes the instructions to associate a heap-incr-flag with the object to control an incrementing or skipping an incrementing of a reference count for the object. The at least one processor can perform updating the RC for the object using the stack-decr-flag or the heap-incr-flag. The stack- decr-flag and the heap-incr-flag can be used to indicate that stack RC operations can be skipped, where these flags are set in certain situations and cleared according to the activity for the function.
[0101] Variations of such a computing system or similar computing systems can include a number of different embodiments that may or may not be combined depending on the application of such computing systems and/or the architecture of computing systems in which methods, as taught herein, are implemented. In such a computing system, the at least one processor can be structured to be operable to execute operations associated with reference counting directed to automatic memory reclamation. Variations can include the format for the stack-decr-flag or the format for the heap-incr-flag. The stack- decr-flag can be a flag assigned to a bit location in the slot. The stack-decr-flag can be a flag assigned to a bit location corresponding to the slot of the stack frame, where the bit location is in addition to bit locations of the slot. The heap- incr-flag can be a flag assigned to a bit location in a header of the object. The heap-incr-flag can be a flag assigned to an unused least significant bit of the object or to an unused most significant bit of the object. In other embodiments, the flags controlling decrementing the RC and incrementing the RC can be flags structured with more than one bit each.
[0102] Variations of such a computing system or similar computing systems can include one or more buffers that can be associated with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. The at least one processor of such a computing system or similar computing systems can be structured to execute the association of a selected buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag. Objects having a non-set heap-incr-flag can be excluded from being assigned to the one or more buffers. The processor can clear all objects in the buffer in response to the function exiting operation.
[0103] The processor of such a computing system can execute instructions to perform write-to-stack operations, perform new object creation operations, perform return value operations, perform function exiting operations, and perform other function operations. Write-to-stack operations of the computing system can include decrementing a RC for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set, indicating the RC can be decremented. The write-to- stack operations can include incrementing a RC for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr- flag for the new object is not set, indicating the RC can be incremented. After overwriting the new object to the slot, the stack-decr-flag for the slot can be set according to the heap-incr-flag of the new object.
[0104] New object creation operations of such a computing system can include generation of the new object from a heap memory and performance of write-to- stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object. The new object creation operations can include placement of a heap-incr-flag for the new object to a status to skip an incrementing of the RC for the new object to a set status and addition of the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0105] Return value operations of such a computing system can include handling of the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value, in response to a RC for the return value being equal to zero or marking a stack-decr-flag for a slot in stack frame of the function associated with the return value to a set status, marking a heap-incr- flag in the return value to a set status, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0106] Function exiting operations can include clearing stack-decr-flags for all slots of the stack frame for the function and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
[0107] For the various operations that use a buffer configured to hold, for the function, one or more objects having a set heap-incr-flag, a single buffer can be implemented. Alternatively, multiple buffers can be implemented to realize the task of holding of one or more objects having a set heap-incr-flag. In some embodiments, each activity of a function can be associated with an individual buffer for the activity. Such activities can include but are not limited to write-to- stack operations for a function, operations to create a new object for a function, operations in response to receiving a return value for the function, operations in response to the function exiting operation, and other function operations
[0108] Figure 7 is a diagram illustrating components of a computing system 700 that can implement algorithms and perform methods structured to reduce RC updates for objects with respect to operations on stack variables for automatic memory management. All components need not be used in various embodiments. Computing system 700 can include a processor 702, memory 703, removable storage 711, non-removable storage 722, and a cache 707. Processor 702 can be implemented as multiple processors. Computing system 700 can be structured in different forms in different embodiments.
[0109] Although the various data storage elements are illustrated as part of the computing system 700, the storage can also or alternatively include cloud-based storage accessible via a network, such as the Internet or remote server-based storage. Note also that a solid state drive (SSD) can include a processor on which a parser can be run, allowing transfer of parsed, fdtered data through input/output (I/O) channels between the SSD and main memory.
[0110] Memory 703 can include volatile memory 714 and/or non-volatile memory 708. Computing system 700 can include or have access to a computing environment that includes a variety of computer-readable media, such as volatile memory 714, non-volatile memory 708, removable storage 711 and/or nonremovable storage 722. Computer storage can include random-access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD ROM), Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium capable of storing computer-readable instructions.
[0111] Computing system 700 can include or have access to a computing environment that includes input interface 726, output interface 724, and a communication interface 716. Output interface 724 can include a display device, such as a touchscreen, that also can serve as an input device. The input interface 726 can include one or more of a touchscreen, touchpad, mouse, keyboard, camera, one or more device -specific buttons, one or more sensors integrated within or coupled via wired or wireless data connections to the computing system 700, and other input devices. The communication interface 716 can exchange communications with external device and networks. The computing system 700 can operate in a networked environment using a communication connection to connect to one or more remote computers, such as one or more remote compute nodes. The remote computer can include a PC, a server, a router, a network PC, a peer device or other common data flow network switch, or the like. The communication connection can include a Local Area Network (LAN), a Wide Area Network (WAN), cellular, Wi-Fi, Bluetooth, or other networks. According to one embodiment, the various components of computing system 700 are connected with a system bus 720.
[0112] Computer-readable instructions stored on a computer-readable medium, such as a program 718, are executable by the processor 702 of the computing system 700. The program 718 can be performed using heap memory and stack memory that may be allocated in memory 703 and used in conjunction with the two flag architecture for reducing RC updates for objects with respect to operations on stack variables for the objects. A hard drive, CD-ROM, and RAM are some examples of articles including a non-transitory computer-readable medium, such as a storage device. The terms computer-readable medium and storage device do not include carrier waves to the extent carrier waves are deemed too transitory. Storage can also include networked storage, such as a storage area network (SAN). Program 718 of computing system 700 can be used to cause processor 702 to perform one or more methods or algorithms described herein.
[0113] The components of the illustrative devices, systems, and methods employed in accordance with the illustrated embodiments can be implemented, at least in part, in digital electronic circuitry, analog electronic circuitry, or in computer hardware, firmware, software, or in combinations of them. These components can be implemented, for example, as a computer program product such as a computer program, program code or computer instructions tangibly embodied in a machine-readable storage device, for execution by, or to control the operation of, data processing apparatus such as a programmable processor, a computer, or multiple computers.
[0114] The various illustrative logical blocks, modules, and circuits described in connection with the embodiments disclosed herein may be implemented or performed with a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general-purpose processor may be a microprocessor, but in the alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. A processor may also be implemented as a combination of computing devices, e.g., a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a DSP core, or any other such configuration.
[0115] Processors suitable for the execution of a computer program include, by way of example, both general and special purpose microprocessors, and processors of any kind of digital computer. Generally, a processor will receive instructions and data from a read-only memory or a random-access memory or both. The elements of a computer include a processor for executing instructions and one or more memory devices for storing instructions and data. Generally, a computer will also include, or be operatively coupled to receive data from or transfer data to, or both, one or more mass storage devices for storing data, e.g., magnetic, magneto-optical disks, or optical disks. Information carriers suitable for embodying computer program instructions and data include all forms of nonvolatile memory, including by way of example, semiconductor memory devices, e.g., electrically programmable read-only memory or ROM (EPROM), EEPROM, flash memory devices, and/or data storage disks (e.g., magnetic disks, internal hard disks, or removable disks, magneto-optical disks, CD-ROM, or DVD-ROM disks). The processor and the memory can be supplemented by or incorporated in special purpose logic circuitry.
[0116] In various embodiments, reducing RC updates for stack variables can be attained using procedures for skipping RC incrementing or RC decrementing operations for the stack variables. The two flag approach, using a stack-decr- flag with respect to RC decrementing and a heap-incr-flag with respect to RC incrementing, can provide for an optimization of a basic RC algorithm where root set references are counted. This two flag approach does not require tracing and is suitable for systems where tracing-induced delays are not desirable. Compared with other approaches, this two flag approach can significantly reduce the overall number of RC operations without using deferred reference counting. Unlike deferred reference counting, this method reduces the number of RC operations not by excluding stack references, but by setting flags in the stack slots and the objects, thereby allowing unnecessary RC operations to be skipped. Compared with other approaches, this two flag approach allows objects to be reclaimed as soon as they become garbage. Compared with other approaches, this two flag approach does not require tracing, therefore does not have tracing- induced delays.
[0117] The two flag approach using a stack-decr-flag and a heap-incr-flag has a wide range of applications because many programming languages use garbage collection and such programming languages are used in the whole spectrum of computing platforms, from the Internet of Things (loT) devices to data centers. The two flag approach using a stack-decr-flag and a heap-incr-flag can be particularly beneficial to systems where memory capacity is limited and thus immediate reclamation of garbage is highly desirable and to systems that are designed for garbage collection-induced delays to be as low as possible.
[0118] Although specific embodiments have been illustrated and described herein, it will be appreciated by those of ordinary skill in the art that any arrangement that is calculated to achieve the same purpose may be substituted for the specific embodiments shown. Various embodiments use permutations and/or combinations of embodiments described herein. It is to be understood that the above description is intended to be illustrative, and not restrictive, and that the phraseology or terminology employed herein is for the purpose of description. Combinations of the above embodiments and other embodiments will be apparent to those of skill in the art upon studying the above description.

Claims

CLAIMS What is claimed is:
1. A computing system comprising: a memory storing instructions; and at least one processor in communication with the memory, the at least one processor configured, upon execution of the instructions, to perform the following steps: associate a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot; associate a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count for the object; and updating the reference count for the object using the stack-decr- flag or the heap-incr-flag.
2. The computing system of claim 1, wherein the stack-decr-flag is assigned to a bit location corresponding to the slot of the stack frame, the bit location being in addition to bit locations of the slot.
3. The computing system of any one of the preceding claims, wherein the stack-decr-flag is assigned to a bit location in the slot.
4. The computing system of any one of the preceding claims, wherein the heap-incr-flag is assigned to a bit location in a header of the object.
5. The computing system of any one of the preceding claims, wherein the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
6. The computing system of any one of the preceding claims, wherein the at least one processor is operable to associate a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
7. The computing system of claim 6, wherein the at least one processor is operable to reset the heap-incr-flag of all the objects in the buffer and empty the buffer in response to the function exiting operation.
8. The computing system of any one of the preceding claims, wherein the at least one processor executes the instructions to perform write-to-stack operations including: decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that the stack-decr- flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
9. The computing system of any one of the preceding claims, wherein the at least one processor executes the instructions to perform operations for the function to create a new object, the operations including: generating the new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr-flag for the new object, the set heap-incr-flag indicating skipping an incrementing of the reference count for the new object; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr- flag.
10. The computing system of any one of the preceding claims, wherein the at least one processor executes the instructions to perform operations in response to receiving a return value for the function, the operations including: handling of the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting the stack-decr-flag for the slot in the stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
11. The computing system of any one of the preceding claims, wherein the at least one processor executes the instructions to perform operations in response to the function exiting, the operations including: clearing stack-decr-flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
12. A computer-implemented method of updating a reference count of an object for a function, the computer-implemented method comprising: associating a stack-decr-flag with a slot of a stack frame for a function, the stack frame having one or more slots for the function, the stack-decr-flag controlling a decrementing of a reference count (RC) for an object associated with the slot; associating a heap-incr-flag with the object, the heap-incr-flag controlling an incrementing of the reference count for the object; and updating the reference count for the object using the stack-decr-flag or the heap-incr-flag.
13. The computer-implemented method of claim 12, wherein the stack-decr- flag is assigned to a bit location corresponding to the slot of the stack frame, the bit location being in addition to bit locations of the slot.
14. The computer-implemented method of any one of the preceding claims 12-13, wherein the stack-decr-flag is assigned to a bit location in the slot.
15. The computer-implemented method of any one of the preceding claims 12-14, wherein the heap-incr-flag is assigned to a bit location in a header of the object.
16. The computer-implemented method of any one of the preceding claims 12-15, wherein the heap-incr-flag is assigned to an unused least significant bit of the object or to an unused most significant bit of the object.
17. The computer-implemented method of any one of the preceding claims 12-16, wherein the computer-implemented method includes associating a buffer with the function, the buffer being configured to hold one or more objects having a set heap-incr-flag.
18. The computer-implemented method of claim 17, wherein the computer- implemented method includes resetting the heap-incr-flag of all the objects in the buffer and emptying the buffer in response to the function exiting operation.
19. The computer-implemented method of any one of the preceding claims 12-18, wherein the computer-implemented method includes: decrementing a reference count for an existing object associated with a given slot of the stack frame in response to a determination that a stack-decr-flag for the given slot is not set; incrementing a reference count for a new object associated with the given slot of the stack frame in response to a determination that a heap-incr-flag for the new object is not set; and after overwriting the new object to the slot, setting the stack-decr-flag for the slot according to the heap-incr-flag of the new object.
20. The computer-implemented method of any one of the preceding claims 12-19, wherein the computer-implemented method includes: generating a new object from a heap memory; performing write-to-stack operations with respect to the new object to make the new object available for automatic memory reclamation upon determination that the generation of the new object is part of an iteration of a loop execution after initial generation of the new object; setting a heap-incr-flag for the new object, the set heap-incr-flag indicating skipping an incrementing of the reference count for the new object will be skipped; and adding the new object to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr- flag.
21. The computer-implemented method of any one of the preceding claims 12-20, wherein the computer-implemented method includes treating a return value for the function as an object of the function by: handling the return value as a new object to generate a stack-decr-flag for a slot in the stack frame for the function associated with the return value and generate a heap-incr-flag in the return value in response to a reference count for the return value being equal to zero; or setting a stack-decr-flag for a slot in stack frame of the function associated with the return value, setting a heap-incr-flag in the return value, and adding the return value to a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
22. The computer-implemented method of any one of the preceding claims 12-21, wherein the computer-implemented method includes, in response to the function exiting: clearing stack-decr-flags for all slots of the stack frame for the function; and clearing heap-incr-flags of all objects in a buffer for the function, with the buffer configured to hold, for the function, one or more objects having a set heap-incr-flag.
23. A non-transitory computer-readable storage medium storing instructions, that when executed by at least one processor, cause the at least one processor to perform operations comprising any one of the methods of claims 12-22.
PCT/US2022/071138 2022-03-14 2022-03-14 Reducing reference count updates for stack variables WO2023177446A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/US2022/071138 WO2023177446A1 (en) 2022-03-14 2022-03-14 Reducing reference count updates for stack variables

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/US2022/071138 WO2023177446A1 (en) 2022-03-14 2022-03-14 Reducing reference count updates for stack variables

Publications (1)

Publication Number Publication Date
WO2023177446A1 true WO2023177446A1 (en) 2023-09-21

Family

ID=80999235

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/US2022/071138 WO2023177446A1 (en) 2022-03-14 2022-03-14 Reducing reference count updates for stack variables

Country Status (1)

Country Link
WO (1) WO2023177446A1 (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170300694A1 (en) * 2015-10-28 2017-10-19 Hrl Laboratories, Llc System and method for maintaining security tags and reference counts for objects in computer memory

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170300694A1 (en) * 2015-10-28 2017-10-19 Hrl Laboratories, Llc System and method for maintaining security tags and reference counts for objects in computer memory

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
ANDERSON DANIEL DLANDERS@CS CMU EDU ET AL: "Concurrent deferred reference counting with constant-time overhead", PROCEEDINGS OF THE 42ND ACM SIGPLAN INTERNATIONAL CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION, ACMPUB27, NEW YORK, NY, USA, 19 June 2021 (2021-06-19), pages 526 - 541, XP058759085, ISBN: 978-1-4503-8434-6, DOI: 10.1145/3453483.3454060 *
HAREL PAZ ET AL: "An efficient on-the-fly cycle collection", ACM TRANSACTIONS ON PROGRAMMING LANGUAGE AND SYSTEMS, ACM, NEW YORK, NY, vol. 29, no. 4, 1 August 2007 (2007-08-01), pages 20 - es, XP058319328, ISSN: 0164-0925, DOI: 10.1145/1255450.1255453 *
RIFAT SHAHRIYAR ET AL: "Down for the count? Getting reference counting back in the ring", PLDI 09 : PROCEEDINGS OF THE 2009 ACM SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION ; JUNE 15 - 20, 2009, DUBLIN, IRELAND; [SIGPLAN NOTICES : A MONTHLY PUBLICATION OF THE SPECIAL INTEREST GROUP ON PROGRAMMING LANGUAGES OF THE, vol. 47, no. 11, 15 June 2012 (2012-06-15), pages 73 - 84, XP058030487, ISBN: 978-1-60558-392-1, DOI: 10.1145/2426642.2259008 *

Similar Documents

Publication Publication Date Title
JP5868429B2 (en) Method, computer program product, and apparatus for progressively unloading classes using a region-based garbage collector
JP4571710B2 (en) Method and apparatus for dispatch table structure
CN110325969B (en) Multi-stage garbage collector
US8510710B2 (en) System and method of using pooled thread-local character arrays
US8615635B2 (en) Database management methodology
US6701520B1 (en) Preventing garbage collection of objects in object oriented computer programming languages
CN110291508B (en) Garbage collector
US7386843B2 (en) Method and system for register allocation
JPH113269A (en) System and method for assisting accurate garbage collection by separating contents of stack into sub-stacks
US20020194210A1 (en) Method for using non-temporal stores to improve garbage collection algorithm
EP2341441B1 (en) Methods and apparatus to perform adaptive pre-fetch operations in managed runtime environments
US20120011166A1 (en) Skip list generation
US7620943B1 (en) Using class properties to segregate objects in a generation managed by the train algorithm
US8082399B2 (en) Cache bounded reference counting
WO2023177446A1 (en) Reducing reference count updates for stack variables
US20080034022A1 (en) System and method for updating references when incrementally compacting a heap
JPH0830562A (en) Multiprocessor system
US20220066816A1 (en) Work stealing for concurrent marking garbage collection with finger pointer
Ægidius Mogensen Memory Management
Gabbrielli et al. Memory Management

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22714100

Country of ref document: EP

Kind code of ref document: A1