public final class MemoryManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
MemoryManager.Collector
http://blog.takipi.com/garbage-collectors-serial-vs-parallel-vs-cms-vs-the-g1-and-whats-new-in-java-8/
|
Modifier and Type | Field and Description |
---|---|
static MemoryManager.Collector |
COLLECTOR |
static java.lang.String |
ENV_MIN_INCREMENTAL_CLEAR_TIME
the min incremental clear time environment variable
|
static int |
OVERRIDE_OCCUPANCY_FRACTION
The initiating faction set from command line.
|
static java.lang.String |
TENURED_PERCENT
The minimum TENURED percent environment variable.
|
static java.lang.String |
TENURED_SIZE
The TENURED size environment variable.
|
Modifier and Type | Method and Description |
---|---|
static void |
addListener(MemoryListener listener)
Register a Memory listener.
|
static long |
calculatedTenuredThreshold()
the GC threshold
|
static long |
callFreeMemory(MemoryHandler handler,
double percentage)
To prevent a deadlock found on 25 Oct 2003 between freeMemory() and deregister()
|
static boolean |
callGC(int intervalSeconds,
java.lang.String[] logMsg)
Only call System.gc() if it has NOT been called in the last n seconds.
|
static long |
checkZone()
Are we in the safe zone ? if so clean up
|
static long |
clearMemory(MemoryHandler.Cost cost)
Clear memory ASAP
Steps Clear rainy day fund to give us some space to work Call each registered memory handler with the current clear level. |
static java.util.ArrayList |
collectStats()
Collect the stats of the memory handlers
|
static void |
deregister(MemoryHandler handler)
Removes the memory handler from the watch list.
|
static long |
estimateLevel(MemoryHandler.Cost cost)
The estimated size of the data held at this cost level
|
static boolean |
gc()
Call System.gc() regardless of when it has been called last.
|
static boolean |
gc(int intervalSeconds)
Only call System.gc() if it has NOT been called in the last n seconds.
|
static long |
getCollectionUsageThreshold()
Returns the collection usage threshold value of this memory pool in bytes.
|
static long |
getCountGC()
Number of times GC has been called.
|
static java.lang.String |
getDetails()
the memory details
|
static long |
getFreeMemory()
The free Memory, if we have defined the MAX_MEMORY to be more than what is
currently reserved then add this to the free memory.
|
static float |
getFreePercent()
The percentage free.
|
static long |
getGCtime()
Total GC time.
|
static MemoryHandler.Cost |
getHighWaterMark()
The maximum level cleared.
|
static long |
getHighWaterMarkTime()
Last time the maximum level was cleared.
|
static MemoryHandler.Cost |
getLastClearedLevel()
The last level cleared
|
static long |
getLastClearedTime()
The last time memory was cleared.
|
static long |
getPanicCount()
The panic count
|
static float |
getSafeUpperPercent()
The upper safety zone as a percentage 0-1
|
static int |
getSafeZoneLower()
What is the safe zone lower currently set to ?
|
static int |
getSafeZoneUpper()
At what percentage free will we say that we are full ?
|
static long |
getTenuredFreeMemory()
The tenured free memory in bytes.
|
static float |
getTenuredFreePercent()
The tenured percentage free.
|
static long |
getTenuredTotalMemory()
get the tenured size
|
static long |
getTenuredUsed()
The amount of tenured memory used
|
static int |
getTotalClearedCount()
How many times have the memory been cleared.
|
static long |
getTotalClearedTimeTaken()
how much time has been taken clearing memory.
|
static long |
getTotalMemory()
The total memory limited to the MAX_MEMORY defined by the command line.
|
static long |
getTotalUsed()
The amount of memory used
|
static boolean |
isFull()
Is the memory full ?
|
static int |
jvmG1HeapRegionSize()
0 - 4GB - 1MB
8GB - 2MB
16GB - 4MB
32GB - 8MB
64GB - 16MB
64GB+ - 32MB
https://stackoverflow.com/questions/46786601/how-to-know-region-size-used-of-g1-garbage-collector
|
static long |
jvmMaxMemory()
Get the JVM max memory ( when will we get a out of memory error)
|
static void |
lastError()
Check if there has been an issue.
|
static void |
lastError(java.lang.String msg,
java.lang.Throwable cause)
Record the an issue which has occurred by an background process.
|
static long |
lastTick()
Records the last time memory was checked (once a second or so)
|
static void |
logDetails(org.apache.commons.logging.Log logger)
Log the Memory Manager details.
|
static void |
makeRainyDay()
make sure we have ~1/2 meg to do some work
|
static void |
register(MemoryHandler handler)
Register a Memory Handler.
|
static void |
setMaxMemory(long maximum)
Manually set the maximum memory to use.
|
static void |
setMaxMemory(java.lang.String maximum)
Manually set the maximum memory to use.
|
static void |
setMinFreePercent(java.lang.String percentage)
Used to set the safe zone parameter from system properties
|
static void |
setSafeZoneLower(java.lang.String percentage)
Used to set the safe zone parameter from system properties
|
static void |
setSafeZoneUpper(java.lang.String percentage)
Used to set the safe zone parameter from system properties
|
static void |
setTenuredPercent(java.lang.String percentage)
Used to set the min tenured percentage from system properties.
|
static void |
setTenuredSize(long size)
set the tenured size
|
static void |
setTenuredSize(java.lang.String size)
Manually set the tenured size.
|
static long |
tick()
Records the last time memory was checked in seconds
|
public static final java.lang.String TENURED_PERCENT
public static final java.lang.String TENURED_SIZE
public static final MemoryManager.Collector COLLECTOR
public static final int OVERRIDE_OCCUPANCY_FRACTION
public static final java.lang.String ENV_MIN_INCREMENTAL_CLEAR_TIME
@CheckReturnValue public static boolean isFull()
public static void register(@Nonnull MemoryHandler handler)
handler
- The memory handler to watch.public static void addListener(@Nonnull MemoryListener listener)
listener
- The memory listener.public static void deregister(@Nonnull MemoryHandler handler)
handler
- The memory handler to remove@CheckReturnValue @Nonnull public static java.util.ArrayList collectStats() throws java.lang.InterruptedException
java.lang.InterruptedException
- the request was interrupted.@Nonnegative public static long callFreeMemory(@Nonnull MemoryHandler handler, @Nonnegative double percentage)
handler
- The memory handler to callpercentage
- The required amount to be freed@Nonnegative public static long clearMemory(@Nonnull MemoryHandler.Cost cost)
cost
- Clear memory to this cost level@CheckReturnValue @Nonnegative public static int jvmG1HeapRegionSize()
@CheckReturnValue @Nonnegative public static long jvmMaxMemory()
public static void setMaxMemory(@Nonnegative long maximum)
maximum
- The max memory.public static void setMaxMemory(@Nullable java.lang.String maximum)
maximum
- The max memory.public static void setSafeZoneLower(@Nullable java.lang.String percentage)
percentage
- The safe zone lower amountpublic static void setTenuredPercent(@Nullable java.lang.String percentage)
percentage
- The tenured percentage@CheckReturnValue @Nonnegative public static int getSafeZoneLower()
public static void setMinFreePercent(@Nullable java.lang.String percentage)
percentage
- The minimum amount to free.public static void setSafeZoneUpper(@Nullable java.lang.String percentage)
percentage
- The safe zone upper limit@CheckReturnValue @Nonnegative public static int getSafeZoneUpper()
@CheckReturnValue @Nonnegative public static long getCountGC()
@CheckReturnValue @Nonnegative public static long getGCtime()
@CheckReturnValue @Nonnegative public static long getTotalMemory()
@CheckReturnValue @Nonnegative public static float getFreePercent()
@CheckReturnValue @Nonnegative public static long getTenuredFreeMemory()
@CheckReturnValue @Nonnegative public static float getTenuredFreePercent()
@CheckReturnValue @Nonnegative public static float getSafeUpperPercent()
@CheckReturnValue @Nonnegative public static long getFreeMemory()
public static boolean gc()
public static boolean gc(@Nonnegative int intervalSeconds)
intervalSeconds
- Call system.gc() if not called within the last X seconds.public static boolean callGC(int intervalSeconds, java.lang.String[] logMsg)
intervalSeconds
- Call system.gc() if not called within the last X seconds.logMsg
- The message.@CheckReturnValue @Nonnegative public static long getTotalUsed()
@CheckReturnValue @Nonnegative public static long getTenuredUsed()
@CheckReturnValue @Nonnegative public static long lastTick()
@Nonnegative public static long tick()
@CheckReturnValue @Nonnull public static MemoryHandler.Cost getLastClearedLevel()
@CheckReturnValue @Nonnegative public static int getTotalClearedCount()
@CheckReturnValue @Nonnegative public static long getTotalClearedTimeTaken()
@CheckReturnValue @Nonnull public static MemoryHandler.Cost getHighWaterMark()
@CheckReturnValue @Nonnegative public static long getHighWaterMarkTime()
@CheckReturnValue @Nonnegative public static long getLastClearedTime()
public static void lastError() throws java.lang.Exception
java.lang.Exception
- if there has been an error since the last time this method was called.public static void lastError(java.lang.String msg, java.lang.Throwable cause)
msg
- the messagecause
- the cause.@CheckReturnValue @Nonnegative public static long estimateLevel(@Nonnull MemoryHandler.Cost cost) throws java.lang.InterruptedException
cost
- The cost leveljava.lang.InterruptedException
- the request was interrupted.@CheckReturnValue @Nonnull public static java.lang.String getDetails()
public static void logDetails(@Nonnull org.apache.commons.logging.Log logger)
logger
- The logger to write to.public static void setTenuredSize(@Nullable java.lang.String size)
size
- The tenured size.public static void setTenuredSize(long size)
size
- the size ( negative means use the default).@CheckReturnValue @Nonnegative public static long calculatedTenuredThreshold()
@CheckReturnValue @Nonnegative public static long getTenuredTotalMemory()
@CheckReturnValue @Nonnegative public static long getCollectionUsageThreshold()
@Nonnegative public static long checkZone() throws java.lang.InterruptedException
java.lang.InterruptedException
- request interrupted.@Nullable public static void makeRainyDay()
@CheckReturnValue @Nonnegative public static long getPanicCount()
stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.