Parallel marker for garbage collection with finger pointers and work-stealing
By identifying and pushing tasks that are not yet associated with the bitmap during garbage collection, and dynamically adjusting the threshold, the problem of finger pointer limiting task pushing is solved, and effective coordination of load balancing and job theft is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INTERNATIONAL BUSINESS MACHINE CORPORATION
- Filing Date
- 2021-08-09
- Publication Date
- 2026-05-29
Smart Images

Figure CN115943366B_ABST
Abstract
Description
Background Technology
[0001] This invention relates generally to the field of garbage collection, and more specifically to a method for maintaining load balancing for concurrent tagging of work during garbage collection.
[0002] The garbage collection (GC) process attempts to reclaim garbage or memory occupied by objects that are no longer in use. GC frees programmers from performing manual memory management, where programmers specify which objects are deallocated and returned to the memory system and when to do so.
[0003] Work-stealing is a scheduling strategy for multithreaded computer applications. In a work-stealing scheduler, each processor in a computer system has a queue of work items (computational tasks, threads) to be executed. Each work item consists of a series of instructions to be executed sequentially, but during its execution, a work item can also create new work items that can be executed in parallel with other work. When a processor finishes its work, it looks at the queues of other processors or threads and steals their work items.
[0004] Garbage-First Garbage Collection is described as “a server-style garbage collector for multiprocessors with large amounts of memory that satisfies soft real-time objectives with high probability while achieving high throughput.” (Abstract, Garbage-First Garbage Collection, David Detlefts et al., ISMM'04, October 24-25, 2004). Garbage-First Garbage Collection describes a “finger” pointer that iterates over marked bits. Objects above the finger are implicitly grayed out; gray objects below the finger are represented by the marked heap. (Section 2.5.2, Garbage-First Garbage Collection). As used in Garbage-First Garbage Collection, “gray” means “marked but not yet recursively scanned” objects. (Section 2.5.1).
[0005] The drawback of using the current garbage collection process based on the finger pointer is that the finger pointer prevents tasks from being pushed below the finger pointer (i.e., associated with bits at positions the finger pointer has not yet passed). Load balancing may occur when the work-stealing mechanism does not have enough stealable tasks. Summary of the Invention
[0006] According to embodiments of the present invention, a computer-implemented method, computer program product, and computer system are provided. The method includes popping a first task from a queue of a garbage collection thread. The method further includes identifying a second task from the popped first task, wherein the second task is associated with a bit in a bitmap, and the bit is located at a position within the bitmap that has not yet been passed by a finger pointer. The method further includes pushing the second task to the queue of the garbage collection thread. Such a method has the advantage of preventing load imbalance by adding tasks to the garbage collection queue, even if the task is associated with a bit located at a position within the bitmap that has not yet been passed by a finger pointer.
[0007] According to other embodiments of the present invention, a computer-implemented method, computer program product, and computer system are provided. The method includes popping a first task from a queue of a garbage collection thread. The method further includes identifying a second task and a third task from the popped first task, wherein the second task is associated with a first bit of a bitmap located at a first position within the bitmap that a finger pointer has not yet passed, and the third task is associated with a second bit of the bitmap located at a second position within the bitmap that the finger pointer has already passed. The method further includes pushing the third task into the queue of the garbage collection thread. The method further includes determining whether a first number of tasks in the queue of the garbage collection thread is equal to or less than a first threshold number of tasks.
[0008] Embodiments of the present invention may optionally include a method that determines a first number of tasks in a queue of a garbage collection thread that is equal to or less than a first threshold number of tasks, wherein, in response to determining that the first number of tasks in the queue of a garbage collection thread is equal to or less than the first threshold number of tasks, a second task is pushed to the queue of the garbage collection thread. Such a method has the advantage of maintaining load balancing when the number of remaining tasks in the garbage collection queue is small by pushing tasks to the garbage collection queue.
[0009] Embodiments of the invention may optionally include a method that calculates a difference between (i) a first number of tasks in the queue of the garbage collection thread after popping the first task and (ii) a second number of tasks in the queue of the garbage collection thread after popping the first task. The method may also optionally determine that the difference satisfies or exceeds a second threshold number of tasks. The method may also increase the first threshold number of tasks in response to the difference satisfying or exceeding the second threshold number of tasks. Such a method has the benefit of adjusting the threshold based on the load balancing of work-stealing by GC threads. Attached Figure Description
[0010] Figure 1 This is a functional block diagram illustrating a processing system according to an embodiment of the present invention.
[0011] Figure 2This is a block diagram illustrating a processor device according to an embodiment of the present invention.
[0012] Figure 3 It is a set of example objects including reference relationships and tag states according to embodiments of the present invention.
[0013] Figure 4 This is an example bitmap including a finger pointer according to an embodiment of the present invention.
[0014] Figure 5 This is a flowchart illustrating the operational steps of a method for adding a referenced object to a queue of a garbage collector thread according to an embodiment of the present invention. Detailed Implementation
[0015] Embodiments of the present invention recognize that load imbalance can occur in garbage-first garbage collection (G1GC) and other concurrent garbage collection (GC) methods that utilize finger pointers, due to the finger pointer limiting the pushable tasks available for work stealing. Embodiments of the present invention disclose a method that provides a sufficient number of tasks that can be stolen by threads even when the finger pointer limits pushable tasks. Embodiments of the present invention disclose a method in which worker threads push subtasks into their queues even when the number of remaining tasks is below a threshold number of tasks, even if the subtasks are below the finger pointer (i.e., at a position the finger pointer has not yet passed). Embodiments of the present invention also provide an autotuning threshold based on task reduction per unit time to maintain load balance during the GC process.
[0016] The invention will now be described in detail with reference to the accompanying drawings. Figure 1 A block diagram of components of a computing device 100 according to an illustrative embodiment of the present invention is shown. It should be understood that... Figure 1 This illustration provides only one possible implementation and does not imply any limitation regarding the environment in which different embodiments may be implemented. Many modifications can be made to the depicted environment.
[0017] The computing device 100 includes a communication structure 102 that provides communication between a cache 116, a memory 106, persistent storage 108, a communication unit 110, and an input / output (I / O) interface 112. The communication structure 102 can be implemented using any architecture designed to transfer data and / or control information between processors (such as microprocessors, communication and network processors), system memory, peripheral devices, and any other hardware components within the system. For example, the communication structure 102 can be implemented using one or more buses or crossbars.
[0018] Memory 106 and persistent storage 108 are computer-readable storage media. In this embodiment, memory 106 includes random access memory (RAM). Typically, memory 106 may include any suitable volatile or non-volatile computer-readable storage medium. Cache 116 is a fast memory that enhances the performance of computer processor 104 by retaining recently accessed data and data that is about to be accessed from memory 106.
[0019] Programs, applications, and / or other data may be stored in persistent storage 108 and memory 406 for execution and / or access by one or more of the respective computer processors 104 via cache 116. In one embodiment, persistent storage 108 includes a magnetic hard disk drive. Alternatively, or in addition to a magnetic hard disk drive, persistent storage 108 may include a solid-state drive, a semiconductor storage device, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), flash memory, or any other computer-readable storage medium capable of storing program instructions or digital information.
[0020] The media used in persistent storage 108 can also be removable. For example, a removable hard drive can be used for persistent storage 108. Other examples include optical discs and disks, thumb drives and smart cards, which are inserted into the drive to be transferred to another computer-readable storage medium (which is also part of persistent storage 108).
[0021] In these examples, communication unit 110 provides communication with other data processing systems or devices. In these examples, communication unit 110 includes one or more network interface cards. Communication unit 110 can provide communication using either or both of physical and wireless communication links. Programs, applications, and / or other data can be downloaded to persistent storage 108 via communication unit 110.
[0022] I / O interface 112 allows for the input and output of data to other devices that can be connected to computing device 100. For example, I / O interface 112 can provide connectivity to external device 118 (such as a keyboard, keypad, touchscreen, and / or other suitable input devices). External device 118 may also include portable computer-readable storage media, such as thumb drives, portable optical discs or disks, and memory cards. Software and data used to implement embodiments of the invention can be stored on such portable computer-readable storage media and loaded onto persistent storage 108 via I / O interface 112. I / O interface 112 is also connected to display 120.
[0023] The display 120 provides a means for displaying data to a user and may be, for example, a computer monitor.
[0024] The procedures described herein are identified based on their implementation in specific embodiments of the invention. However, it should be understood that any particular procedural terminology used herein is for convenience only, and therefore the invention should not be limited to use only in any particular application identified and / or implied by such terminology.
[0025] Figure 2 Depicting embodiments of the present invention as follows Figure 1 The processor 104 shown is, for example, a graphics processing unit (GPU), a dedicated instruction set processor (ASIP), a virtual CPU (vCPU), a digital signal processor (DSP), an image processor, a physical processing unit (PPU), or a central processing unit for a computer, server, tablet, internet-connected device, or telephone.
[0026] In one embodiment, processor 104 may include control unit 220, arithmetic logic unit 230, and memory / register 240. Control unit 220 of processor 104 controls processor 104 and which instructions processor 104 processes. Control unit 220 may include thread management process 222. Thread management process 222 may include rules for handling memory / register 240, cache 116, memory 106, or persistent storage device 108 occupied by objects no longer used by any thread 232. Thread management process 222 may manage thread 232 and any memory locations (e.g., memory / register 240, cache 116, memory 106, persistent storage device 108) utilized by thread 232. Management of thread 232 may include grouping threads 232 together to form thread clusters 233. Thread clusters 233 may be used to complete larger processes together.
[0027] Arithmetic logic unit 230 may contain thread 232. Thread 232 may process tasks running on processor 104. Thread 232 may be organized into thread cluster 233 by thread management process 222 or by arithmetic logic unit 230. Thread 232 or thread cluster 233 is capable of popping tasks from memory (e.g., memory / register 240) and processing tasks by copying objects from the tasks and modifying references to the objects. After processing a task, thread 232 or thread cluster 233 creates subtasks from the processed task by following the references to the copied objects. Thread 232 or thread cluster 233 pushes the created subtasks into memory (e.g., memory / register 240). After pushing all created subtasks into memory (e.g., memory / register 240), thread 232 or thread cluster 233 pops the next task for processing.
[0028] Memory / register 240 may include different segments containing queue 242. Queue 242 may be divided into different segments that can be accessed by different threads 232 or thread cluster 233.
[0029] The term "object" refers to a data structure represented in the memory of a computer system. Other terms sometimes used for the same concept are "record" and "structure." An object can be identified by a reference, which is a relatively small amount of information that can be used to access the object. A reference can be represented, for example, as a pointer or a machine address.
[0030] Programs running on systems such as computing device 100 use numerous processors 104 and dynamically create objects stored in a portion of memory called the heap. The heap is a shared memory managed by automatic garbage collection. The garbage collector has control and / or direct access to and / or knowledge of addresses, classes, roots, and other such details about objects created in computing device 100.
[0031] After an object is no longer needed, it is sometimes necessary to reclaim the memory allocated to the object (e.g., memory / register 240, cache 116, memory 106, persistent storage 108) to prevent the system from running out of memory as more and more temporary objects fill the heap. This memory reclamation is called garbage collection (GC).
[0032] Garbage collectors operate by reclaiming space that is no longer reachable. Statically allocated objects, represented by global variables in a program, are generally considered reachable throughout the program's lifetime. Such objects are typically not stored in the GC-managed memory space, but can contain references to dynamically allocated objects stored in the GC-managed memory space, and these dynamically allocated objects are also considered reachable. Objects referenced in the call stack of the executing thread are reachable, such as objects referenced by register contents. Furthermore, any object referenced by a reachable object is also reachable.
[0033] Using an automatic garbage collector is advantageous because, while a programmer working on a specific sequence of code can reliably perform his task in most respects with only local knowledge of the application at any given time, memory allocation and reclamation require global knowledge of the program. Specifically, a programmer working on a given sequence of code does tend to know whether a certain portion of memory is still in use by that code sequence, but it is quite difficult for them to know what the rest of the application is doing with that memory. Automatic garbage collectors acquire global knowledge methodically by tracking references to a concept from the root set (e.g., global variables, registers, and the call stack). By using a garbage collector, programmers no longer need to worry about the application's global state and can focus on local state issues, which are more manageable.
[0034] An object is considered reachable if it is referenced by a reference in the root. The root set includes, for example, reference values stored in the mutator thread's call stack, memory / register 240, and global variables outside the garbage-collected heap. An object is also reachable if it is referenced by another reachable object. Unreachable objects can no longer affect the program, so it is safe to reallocate the storage space occupied by these objects.
[0035] One method of garbage collection is to identify all reachable objects and reclaim any previously allocated memory that those reachable objects do not occupy. The GC identifies reachable objects by tracing objects pointed to from the root, objects pointed to by those reachable objects, and so on, until all referenced or pointed-to objects are found and retained. The last object discovered will then not have pointers to other untracked objects. In this way, unreachable objects are effectively discarded, and the associated memory space becomes free for replacement.
[0036] Figure 3 Examples of objects reachable by concurrent garbage collection processes (such as G1GC) are depicted, along with the types of objects identified as being during the marking process. The depicted examples illustrate the marking process over a period of time. During the garbage collection process, there are three categories of objects: (i) objects that have not yet been marked (see objects 301-304, without shading); (ii) objects that have been marked but whose direct descendants (i.e., referenced objects) have not yet been marked (see objects 301 and 302 shaded with the first pattern); and (iii) objects that have been marked and whose direct descendants have also been marked (see objects 301-304 shaded with the second pattern).
[0037] In this example, initially, no objects 301-304 were marked, and this was in Figure 3The image is depicted by the initial lack of shading of any one of objects 301-304.
[0038] The initial operation of concurrent garbage collectors such as G1GC is a root scan. A root scan requires a stop-the-world operation. During a stop-the-world garbage collector, the execution of the program is completely halted to run the collection cycle, thus guaranteeing that no new objects are allocated and that objects do not suddenly become unreachable while the collector is running. Concurrent garbage collectors (such as G1GC) typically do not halt program execution except briefly when scanning the program's execution stack. More specifically, in the current example, to shorten the stop-the-world pause, the GC thread (e.g., thread 232) sets bits for root objects in the bitmap. However, because pushing root objects (such as root object 301) to the GC thread can be slow, G1GC avoids pushing root objects during the root scan phase. Figure 3 In the example depicted, the GC thread (e.g., the thread in thread 232) sets a bit in the bitmap for root object 301 during root scan. As described above, this bit indicates that root object 301 has been marked, but its direct descendants (i.e., referenced objects) are not marked. Objects 302 and 303 are direct descendants of root object 301. As shown, referenced object 301 is shaded with the first pattern, while objects 302-304 remain unshaded.
[0039] Subsequently, during the marking phase, the GC thread (e.g., thread 232) identifies the marked bits in the bitmap and locates the corresponding objects from those marked bits. Figure 3 In this example, the marker bit (not shown) corresponds to object 301, which is shaded with the first pattern. When the GC thread finds such an object, it scans the referenced object and sets the corresponding bit in the bitmap. In the depicted example, the end result of this operation is to shade object 301 with a second pattern to indicate that object 301 is marked, and also to mark the direct descendants of object 301. Furthermore, objects 302 and 303 are marked in the bitmap. Figure 3 As depicted, object 302 has unmarked children and is shaded with a first pattern, while object 303 does not have unmarked children and is shaded with a second pattern. Therefore, embodiments of the invention recognize that two processes (i.e., the root scan phase and the marking phase) can produce two meanings for a bit in a bitmap. The two possible meanings of a marked bit are: (i) marking the object, but not yet marking the object's direct children (corresponding to the first pattern, see ibid.); (ii) marking the object and also marking the object's direct children (corresponding to the second pattern, see ibid.).
[0040] See also Figure 4As described in more detail below, G1GC uses finger pointers to distinguish the two possible meanings of the mark bits on the bitmap. As the marking phase continues, eventually all objects and their direct descendants will be scanned and marked, and the marking phase will be complete. Figure 3 As depicted in the example, after the marking phase is completed, all objects are shaded with a second pattern to indicate that each object and each object's direct descendants have been marked.
[0041] Figure 4 Depicting something similar to see Figure 3 Example bitmap 400 is described. Bitmap 400 is depicted at two time instances. First, bitmap 400-1 is a depiction of bitmap 400 after the initial marking phase performed by G1GC during the root scan process, as previously described. Each mark bit 420 corresponds to a root object. Thus, during the marking phase, G1GC will examine each mark bit and find the corresponding object, scan the referenced objects, and set any additional corresponding bits in the bitmap, as previously seen. Figure 3 As described. Finger pointer 410 is used to distinguish two meanings of the bit, as shown in the following figure. Figure 3 As described. The finger pointer 410 iterates over the marked bits, moving from one end (e.g., the start) of bitmap 400 to the other end (e.g., the end). In the depicted example, the finger pointer moves from left to right. As depicted, finger pointer 410 is at the beginning of bitmap 400-1 and moves to the right over time, as depicted in bitmap 400-2. The marked bits below pointer 410 (e.g., to the right of pointer 410 in the depicted example as pointer 410 moves to the right) are bits that still require GC threads (e.g., thread 232) to examine during the marking phase. The marked bits below pointer 410 (such as mark bit 420) correspond to objects that have been marked but whose direct descendants have not yet been marked (see [example of marked bits]). Figure 3 The first shadow plus the shadow object). Typically, a marker bit (such as marker bit 430) above the pointer (i.e., where pointer 410 has already passed) corresponds to: (i) an object that has already been marked and (ii) an object whose direct descendants have already been marked. However, during the marking phase, a GC thread (e.g., thread 232) may identify a reference object corresponding to a bit in a bitmap (e.g., bitmap 400) that is above the pointer (e.g., pointer 410) and corresponds to an object that has already been marked but whose direct descendants have not yet been marked. See below. Figure 5This describes how the GC thread (e.g., thread 232) handles such a situation during the marking phase. Once a marked bit (e.g., one of the marked bits 420) is picked up by the GC thread (e.g., thread 232), the pointer 410 moves to a position before the next marked bit. For example, the GC thread can move the pointer 410 to a position before the next marked bit. Once the pointer 410 moves to the end of the bitmap, the marking phase is complete.
[0042] Figure 5 A flowchart 500 depicts the operations of a first GC thread (such as thread 232) operating within the garbage collector described herein. More specifically, flowchart 500 describes the operations performed by the first GC thread during iterations of the marking phase of a G1-type garbage collector. Upon completion of the operations described in flowchart 500, the operations are performed again until no tasks remain in the queue of the first GC thread. The current flowchart description corresponds to a single GC thread within thread 232, described herein as the first GC thread. However, multiple GC threads (such as thread 232) can execute the operations described herein in parallel. Each thread 232 has its own queue and processes tasks on top of a work-stealing mechanism. When a single thread 232 becomes empty, the single thread 232 attempts to steal tasks from the queues of other threads. Embodiments of the invention describe a method that allows work-stealing to cooperate with finger pointer 410 and prevents load imbalance by allowing the stealing thread to have sufficient stealable tasks.
[0043] The first GC thread pops a task from its queue (505). The popped task corresponds to an object that has been marked in bitmap 400 and is to be scanned (see 530).
[0044] The first GC thread records the remaining tasks (510). More specifically, the first GC thread records the tasks that remain in the first GC thread's queue after a task has been popped (see 505).
[0045] The first GC thread calculates the difference between the number of remaining tasks and the previous number (i.e., the number of remaining tasks when the previous tasks were popped in the previous iteration), and records this difference as the reduction rate (515). The reduction rate is the number of tasks reduced per unit of time. The reduction rate indicates how frequently other GC threads steal tasks from the first GC thread according to the work-stealing mechanism of the garbage collection process. A small reduction rate indicates little or no work-stealing, while a large reduction rate indicates that work-stealing occurs more frequently.
[0046] The first GC thread determines whether the reduction rate meets or exceeds a first threshold number (520). The first threshold is a predefined parameter that can be changed. For example, the first threshold could be eight. In such an example, if the calculated reduction rate (see 515) is eight or more tasks, the first GC thread will determine whether the reduction rate meets or exceeds the first threshold. The management user can set the first threshold based on the hardware, software, and / or workload requirements of the computing device 100. Typically, when setting the first threshold, various factors can be considered, such as CPU type and the type of workload that typically runs on the system.
[0047] If the first GC thread determines that the reduction rate is less than the first threshold number (520, No branch), then the first GC thread scans the popped objects and obtains the existing referenced objects (see 530).
[0048] If the first GC thread determines that the reduction rate meets or exceeds a first threshold amount (520, which is a branch), then the first GC thread increases a second threshold amount (525). The second threshold amount is also a predefined parameter that can be changed. For example, the initial value of the second threshold amount can be two. The administrator can set the initial value of the second threshold amount. The second threshold amount indicates whether the number of remaining tasks in the queue of the first GC thread is considered small. If the number of remaining tasks in the queue of the first GC thread is equal to or lower than the second threshold, then for embodiments of the invention, the number of remaining tasks in the queue of the first GC thread is considered small. If the number of remaining tasks in the queue of the first GC thread is greater than the second threshold, then the number of remaining tasks in the queue of the first GC thread is not considered small. The amount by which the first GC thread increases the second threshold can be a predetermined number. For example, at each iteration, the first GC thread can increase the second threshold by one (520, which is a branch) after determining that the reduction rate meets or exceeds the first threshold amount.
[0049] The first GC thread scans the popped objects and obtains any existing referenced objects (530). For each identified referenced object, a subtask is created from the task that scans the popped objects by following the references of the popped objects. See previously. Figure 3-4 As described, during the marking phase, GC threads scan objects already marked in bitmap 400 and identify referenced objects. For example, if the first GC thread is to scan... Figure 3 If object 302 is popped, then the first GC thread will acquire referenced object 304. If the first GC thread scans the popped objects and identifies no existing referenced objects, the iteration is complete, and the first GC thread will pop another task, or if the queue is empty, it will attempt to steal a task from another GC thread. Assuming the first GC thread identifies at least one referenced object from the popped objects, the first GC thread proceeds to operation 535.
[0050] The first GC thread uses Compare-and-Swap (CAS) to mark the bitmap 400 (535) for identifying the first reference object from the scanned popped objects. CAS is an atomic instruction used in multithreaded environments to achieve synchronization. CAS compares the contents of a memory location with a given value and modifies the contents of that memory location to the new given value only if they are the same. CAS is performed as a single atomic operation, guaranteeing that the new value is computed based on the latest information. If another thread updates the value simultaneously, the write will fail. The result of the operation must indicate whether a substitution was performed, which can be done with a Boolean response or by returning the value read from the memory location. The identified first reference object may correspond to a bit located above or below the finger pointer 410 on bitmap 400.
[0051] The first GC thread determines whether the CAS operation was successful (540). The first GC thread determines the success of the CAS operation based on whether the write attempt to the bitmap to generate the flag corresponding to the first referenced object succeeded or failed. If the write attempt succeeds, the CAS operation succeeds. If the write attempt fails, the CAS operation fails.
[0052] If the first GC thread determines that the CAS operation failed (540, No branch), then the first GC thread determines whether any additional referenced objects exist (see 560).
[0053] If the first GC thread determines that the CAS was successful (540, is a branch), then the first GC thread determines whether the number of remaining tasks is equal to or lower than the second threshold (545). The first GC thread previously recorded the remaining tasks (see 510). Therefore, the first GC is able to determine whether the number of remaining tasks is equal to or lower than the second threshold by comparing the recorded number of remaining tasks with the second threshold.
[0054] If the number of remaining tasks is higher than the second threshold (545, no branch), then if the referenced object corresponds to the marker bit of bitmap 400 located above the pointer (i.e., at a position that the pointer has already passed in the path it is moving away from), the first GC thread pushes the referenced object task into the first GC thread's queue (550). If the referenced object corresponds to the marker bit below the pointer 410 (i.e., at a position that the pointer is moving towards but has not yet passed in the path it is moving towards), then the first GC thread will not push the referenced object task into the first GC thread's queue when the number of remaining tasks is higher than the second threshold.
[0055] If the number of remaining tasks is equal to or less than the second threshold (545, which is the branch), the first GC thread pushes the reference object task to the first GC thread's queue (555). When the number of remaining tasks is equal to or less than the second threshold, the first GC thread pushes the reference object task regardless of the position of the corresponding marker bit within bitmap 400. When the number of remaining tasks is equal to or less than the second threshold, if the marker bit is above or below the finger pointer 410, the first GC thread pushes the reference object to the first GC thread.
[0056] The first GC thread determines whether there are any additional reference objects identified during the scan (560).
[0057] If the first GC thread determines that there is an additional reference object (560, which is a branch), the first GC thread attempts to mark bitmap 400 (see 535) for one of the additional reference objects.
[0058] If the first GC thread determines that there are no more attached referenced objects, the iteration is complete. If there are tasks remaining in the queue of the first GC thread, a subsequent iteration will occur. If there are no more tasks in the queue of the first GC thread, the first GC thread may attempt to steal tasks from another GC thread.
[0059] Embodiments of the present invention recognize that the described method can allow for the existence of a number of stealable tasks that can contribute to an increase in the number of load imbalance problems. Embodiments of the present invention further recognize that such a method utilizes load balancing by paying the small overhead of additional scans when pushing tasks located below the pointer, as described herein, could result in additional scans targeting those pushed tasks. Compared to other load balancing methods, the small overhead of potential additional scans does not require any additional memory barriers or CAS. Furthermore, there is no additional overhead when checking the remaining tasks in the GC thread queue because the GC thread initially counts the remaining tasks whenever it pops a task.
[0060] This invention can be a system, method, and / or computer program product with any possible level of technical detail integration. The computer program product may include a computer-readable storage medium (or media) having computer-readable program instructions thereon for causing a processor to execute aspects of the invention.
[0061] Computer-readable storage media can be tangible means for retaining and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example, but not limited to, electronic storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of computer-readable storage media includes: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disk read-only memory (CD-ROM), digital universal disk (DVD), memory sticks, floppy disks, mechanical encoding devices such as punch cards or protrusions in slots having instructions recorded thereon, and any suitable combination of the foregoing. As used herein, computer-readable storage media should not be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses passing through fiber optic cables), or electrical signals transmitted through wires.
[0062] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to a suitable computing / processing device via a network (e.g., the Internet, a local area network, a wide area network, and / or a wireless network), or to an external computer or external storage device. The network may include copper cables, optical fibers, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to a computer-readable storage medium within the suitable computing / processing device.
[0063] Computer-readable program instructions used to perform the operations of this invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, integrated circuit configuration data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages (such as Smalltalk, C++, etc.) and procedural programming languages (such as the "C" programming language or similar programming languages). The computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as a standalone software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN)) or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs) may execute computer-readable program instructions by utilizing state information from the computer-readable program instructions to personalize the electronic circuitry in order to perform aspects of this invention.
[0064] The present invention will now be described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.
[0065] These computer-readable program instructions may be provided to a processor of a computer or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions / actions specified in one or more blocks of a flowchart and / or block diagram. These computer-readable program instructions may also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner, such that the computer-readable storage medium storing the instructions includes an article of manufacture containing instructions that implement aspects of the functions / actions specified in one or more blocks of a flowchart and / or block diagram.
[0066] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus, or other device to produce computer-implemented processing, such that the instructions executed on the computer, other programmable apparatus, or other device perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.
[0067] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, segment, or portion of instructions, including one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the figures. For example, two blocks shown consecutively may actually be completed as a single step, executed simultaneously, substantially simultaneously, or with partial or complete temporal overlap, or the blocks may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action or executes a combination of dedicated hardware and computer instructions.
[0068] Various embodiments of the invention have been described for illustrative purposes, but are not intended to be exhaustive or limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the invention. The terminology used herein has been chosen to best explain the principles of the embodiments, their practical application, or technical improvements over those found in the market, or to enable those skilled in the art to understand the embodiments disclosed herein.
Claims
1. A computer-implemented method, comprising: Pop the first task from the garbage collection thread's queue; Iterate over the finger pointer on the bitmap, where: The first task corresponds to the first bit at the first position that has been marked in the bitmap; The position that the finger pointer has not yet passed corresponds to a task that has been marked but whose direct descendants have not yet been marked; and The position that the finger pointer has passed corresponds to a task that has been marked and whose direct descendants have also been marked; The referenced object is identified by scanning the first task; In response to recognizing the referenced object, a second task is created from the pop-up first task, wherein: Creating the second task includes marking a second bit of the bitmap; The second task is associated with the second bit of the bitmap; and and The second bit is located at a second position within the bitmap that the finger pointer has not yet passed; and In response to identifying the bit at the second position within the bitmap that the finger pointer has not yet passed, the second task is pushed to the queue of the garbage collection thread.
2. The computer-implemented method according to claim 1, further comprising: Determine that the first number of tasks in the queue of the garbage collection thread is equal to or less than a first threshold number of tasks; as well as The second task is pushed to the queue of the garbage collection thread in response to determining that the first number of tasks in the queue of the garbage collection thread is equal to or less than the first threshold number of tasks.
3. The computer-implemented method according to claim 2, further comprising: Calculate the difference between (i) the first number of tasks in the queue of the garbage collection thread after popping the first task and (ii) the second number of tasks in the queue of the garbage collection thread after popping a task before popping the first task; Determine the number of differences that satisfy or exceed the second threshold of the task; and In response to the difference satisfying or exceeding the second threshold number of the task, the first threshold number of the task is increased.
4. The computer-implemented method according to claim 1, wherein, The first task is associated with a first object, and the second task is associated with the second object via a reference to a second object within the first object.
5. The computer-implemented method according to claim 1, further comprising: The bits of the bitmap are marked based on the identifier of the second task from the pop-up first task.
6. The computer-implemented method according to claim 1, wherein, The garbage collection threads are multiple garbage collection threads operating concurrently.
7. The computer-implemented method according to claim 1, wherein, The garbage collection thread is the garbage-first garbage collector G1GC.
8. A computer implementation method, comprising: Pop the first task from the garbage collection thread's queue; Iterate over the finger pointer on the bitmap, where: The first task corresponds to the first bit at the first position that has been marked in the bitmap; The position that the finger pointer has not yet passed corresponds to a task that has been marked but whose direct descendants have not yet been marked; and The position that the finger pointer has passed corresponds to a task that has been marked and whose direct descendants have also been marked; The referenced object is identified by scanning the first task; In response to recognizing the referenced object, a second task and a third task are created from the pop-up first task; The second bit of the second task for the bitmap and the third bit of the third task for the bitmap are marked, wherein: The second task is associated with the second bit of the bitmap; The second bit is located at a second position within the bitmap that has not yet been passed by the finger pointer; The third task is associated with the third bit of the bitmap; and The third position is located in the bitmap at the third position that has been passed by the finger pointer; The third task is pushed to the queue of the garbage collection thread; Determine that a first number of tasks in the queue of the garbage collection thread is equal to or less than a first threshold number of tasks; and In response to determining that the first number of tasks in the queue of the garbage collection thread is equal to or less than the first threshold number of tasks, the second task is pushed to the queue of the garbage collection thread.
9. A computer program product, comprising: Program instructions, the program instructions including: Program instructions used to pop the first task from the queue of the garbage collection thread; Program instructions for iterating over a finger pointer on a bitmap, wherein: The first task corresponds to the first bit at the first position that has been marked in the bitmap; The position that the finger pointer has not yet passed corresponds to a task that has been marked but whose direct descendants have not yet been marked; and The position that the finger pointer has passed corresponds to a task that has been marked and whose direct descendants have also been marked; Program instructions used to identify referenced objects by scanning the first task; Program instructions for creating a second task from the popped-up first task in response to recognizing the referenced object, wherein: The program instructions for creating the second task include program instructions for marking a second bit of the bitmap; The second task is associated with the second bit of the bitmap; and The second bit is located at a second position within the bitmap that the finger pointer has not yet passed; and Program instructions for pushing the second task to the queue of the garbage collection thread in response to recognizing the bit at the second position within the bitmap that the finger pointer has not yet passed.
10. The computer program product according to claim 9, further comprising: Program instructions are used to determine that a first number of tasks in the queue of the garbage collection thread is equal to or less than a first threshold number of tasks; as well as The program instructions for pushing the second task to the queue of the garbage collection thread are in response to determining that the first number of tasks in the queue of the garbage collection thread is equal to or less than the first threshold number of tasks.
11. The computer program product of claim 10, further comprising: Program instructions for calculating (i) the difference between (i) the first number of tasks in the queue of the garbage collection thread after popping the first task and (ii) the second number of tasks in the queue of the garbage collection thread after popping a task before popping the first task; Program instructions are used to determine the number of differences that satisfy or exceed a second threshold of the task; as well as A program instruction for increasing the first threshold number of the task in response to the difference satisfying or exceeding the second threshold number of the task.
12. The computer program product according to claim 9, wherein, The first task is associated with a first object, and the second task is associated with the second object via a reference to a second object within the first object.
13. The computer program product according to claim 9, further comprising: Program instructions for marking bits of the bitmap based on the identifier of the second task from the popped-up first task.
14. The computer program product of claim 9, wherein the garbage collection thread is a plurality of garbage collection threads operating concurrently.
15. The computer program product according to claim 9, wherein, The garbage collection thread is the garbage-first garbage collector G1GC.
16. A computer program product comprising: Program instructions, the program instructions including: Program instructions used to pop the first task from the queue of the garbage collection thread; Program instructions for iterating over a finger pointer on a bitmap, wherein: The first task corresponds to the first bit at the first position already marked in the bitmap; The position that the finger pointer has not yet passed corresponds to a task that has been marked but whose direct descendants have not yet been marked; and The position that the finger pointer has passed corresponds to a task that has been marked and whose direct descendants have also been marked; Program instructions used to identify referenced objects by scanning the first task; Program instructions for generating second and third tasks from the popped first task by scanning the first task for the referenced object in response to identifying the referenced object; Program instructions for marking the second bit of the second task for the bitmap and the third bit of the bitmap for the third task, wherein: The second task is associated with the second bit of the bitmap; The second bit is located at a second position within the bitmap that has not yet been passed by the finger pointer; The third task is associated with the third bit of the bitmap; and The third position is located in the bitmap at the third position that has been passed by the finger pointer; Program instructions for pushing the third task to the queue of the garbage collection thread; Program instructions for determining whether a first number of tasks in the queue of the garbage collection thread is equal to or less than a first threshold number of tasks; and A program instruction for pushing a second task to the queue of the garbage collection thread in response to determining that the first number of tasks in the queue of the garbage collection thread is equal to or less than the first threshold number of tasks.
17. A computer system, comprising: One or more computer processors, including one or more threads, one or more computer-readable storage media, and program instructions commonly stored on the one or more computer-readable storage media for execution by at least one of the one or more computer processors, the program instructions including: Program instructions used to pop the first task from the queue of the garbage collection thread; Program instructions for iterating over a finger pointer on a bitmap, wherein: The first task corresponds to the first bit at the first position that has been marked in the bitmap; The position that the finger pointer has not yet passed corresponds to a task that has been marked but whose direct descendants have not yet been marked; and The position that the finger pointer has passed corresponds to a task that has been marked and whose direct descendants have also been marked; Program instructions used to identify referenced objects by scanning the first task; Program instructions for creating a second task from the popped-up first task in response to recognizing the referenced object, wherein: The program instructions for creating the second task include program instructions for marking a second bit of the bitmap; The second task is associated with the second bit of the bitmap; and The second bit is located at a second position within the bitmap that the finger pointer has not yet passed; and Program instructions for pushing the second task to the queue of the garbage collection thread in response to recognizing the bit at the second position within the bitmap that the finger pointer has not yet passed.
18. The computer system of claim 17, further comprising: The program instructions, stored together on the one or more computer-readable storage media and executable by at least one of the one or more computer processors, are used to determine that a first number of tasks in the queue of the garbage collection thread is equal to or less than a first threshold number of tasks; as well as The program instructions for pushing the second task to the queue of the garbage collection thread are in response to determining that the first number of tasks in the queue of the garbage collection thread is equal to or less than the first threshold number of tasks.
19. The computer system of claim 18, further comprising: The program instructions, stored together on the one or more computer-readable storage media and executable by at least one of the one or more computer processors, are used to calculate (i) the difference between a first number of tasks in the queue of the garbage collection thread after the first task is popped and (ii) the second number of tasks in the queue of the garbage collection thread after the task is popped before the first task is popped. The program instructions, stored together on the one or more computer-readable storage media and executable by at least one of the one or more computer processors, are used to determine the number of times the difference satisfies or exceeds a second threshold of the task; as well as The program instructions, co-stored on the one or more computer-readable storage media and executable by at least one of the one or more computer processors, are used to increase the first threshold number of the task in response to the difference satisfying or exceeding the second threshold number of the task.
20. The computer system according to claim 17, wherein, The first task is associated with a first object, and the second task is associated with the second object via a reference to a second object within the first object.
21. The computer system of claim 17, further comprising: Program instructions, co-stored on the one or more computer-readable storage media and executable by at least one of the one or more computer processors, for marking bits of the bitmap based on an identifier of the second task from the popped-out first task.
22. The computer system according to claim 17, wherein, The garbage collection threads are multiple garbage collection threads operating concurrently.
23. The computer system according to claim 17, wherein, The garbage collection thread is the garbage-first garbage collector G1GC.