Skip to content

Broker MemoryManager:On the loop condition of GC #396

@glassfishrobot

Description

@glassfishrobot

The following gc method compares the amount of free memory in the Java Virtual Machine before GC execution and after GC execution, If free memory is decreased by delta than before GC execution, the loop is exited.
Under this comparison condition, loops will be repeated even if free memory is increased by GC execution, is there a problem ?
As GC repeats, the load on the CPU increases, so there is concern about the delay in message broker processing.

com.sun.messaging.jmq.jmsserver.memory.MemoryManager:

protected void gc(int count, long delta) { 
    if (!NO_GC) { 
    	 logger.log(Logger.DEBUG,"calling Runtime.freeMemory()"); 
        long free = Runtime.getRuntime().freeMemory();  
        int i = 0; 
        for (i = 0; i < count; i ++) { 
            Runtime.getRuntime().gc(); 
            long newfree = Runtime.getRuntime().freeMemory(); 
/* => */    if (free - newfree > delta) {
                 // we freed enough memory 
                 break; 
            } 


        } 
    } 
    else{ 
    	// do nothing 
    	 
    } 
} 

Since this method is invoked when free memory decreases than before,
and because we have "we freed enough memory" in the comment,
I think that it is better to exit the loop if the free memory increases.

Using Open MQ version is 5.1.

Proposed fix

Correct the condition so that when the free memory in the Java virtual machine increases, it leaves the loop.

Previous fix

if (free - newfree > delta) {

After fix

if (newfree - free > delta) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions