Class Reflect
- Author:
- gmt2001
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddumpHeap()Dumps the Java heap to an hprof filestatic voidDumps the Java heap to an hprof filestatic voidDumps all threads to a filestatic voiddumpThreads(String filePath) Dumps all threads to a fileGets a list ofClassthat are in the local cache as a result of calls toloadPackageRecursive(String, List)static StringAttempts to retrieve the full, real, absolute path to the directory in which PhantomBot.jar is locatedstatic MemoryUsageGets aMemoryUsagecontaining information about the current memory usage of the heapstatic MemoryUsageGets aMemoryUsagecontaining information about the current non-heap memory usagegetSubTypesOf(Class<T> type) Gets a list of non-abstractClassthat are in the local cache as a result of calls toloadPackageRecursive(String, List)which are assignable from the specified typestatic Reflectinstance()Returns an instance ofReflectLoads all classes visible to the defaultClassLoaderwhich have the specified package prefix into the local cacheloadPackageRecursive(String pkg, List<String> exclude) Loads all classes visible to the defaultClassLoaderwhich have the specified package prefix into the local cacheloadPackageRecursive(URL jarFile, String pkg, List<String> exclude) Loads all classes visible to the defaultClassLoaderin the specified jar file which have the specified package prefix into the local cachestatic longpid()Attempts to retrieve the PID of the running process from theRuntimeMXBeanof the JVM process
-
Method Details
-
instance
Returns an instance ofReflect- Returns:
- an instance of
Reflect
-
loadPackageRecursive
Loads all classes visible to the defaultClassLoaderwhich have the specified package prefix into the local cacheThis process also triggers static initializers in matching classes
pkgis matched usingString.startsWith(String)The classes are enumerated from the main jar file
- Parameters:
pkg- the package or package prefix to load- Returns:
this
-
loadPackageRecursive
Loads all classes visible to the defaultClassLoaderwhich have the specified package prefix into the local cacheIf any paths return
trueon aString.contains(CharSequence)of any entry inexclude, the class will be excluded from loadingThis process also triggers static initializers in matching classes
pkgis matched usingString.startsWith(String).excludeis matched usingString.contains(CharSequence)The classes are enumerated from the main jar file
- Parameters:
pkg- the package or package prefix to loadexclude- a list of partial path names to exclude- Returns:
this
-
loadPackageRecursive
Loads all classes visible to the defaultClassLoaderin the specified jar file which have the specified package prefix into the local cacheIf any paths return
trueon aString.contains(CharSequence)of any entry inexclude, the class will be excluded from loadingThis process also triggers static initializers in matching classes
pkgis matched usingString.startsWith(String).excludeis matched usingString.contains(CharSequence)- Parameters:
jarFile- theURLrepresenting the path to the jar file which will be searched;nullto search the main jar filepkg- the package or package prefix to load;""(empty string) to load the entire jar fileexclude- a list of partial path names to exclude- Returns:
this
-
getClasses
Gets a list ofClassthat are in the local cache as a result of calls toloadPackageRecursive(String, List)- Returns:
- a list of
Class
-
getSubTypesOf
Gets a list of non-abstractClassthat are in the local cache as a result of calls toloadPackageRecursive(String, List)which are assignable from the specified type- Type Parameters:
T- the parent class or interface- Parameters:
type- the parent class or interface- Returns:
- a list of sub-classes
-
dumpHeap
public static void dumpHeap()Dumps the Java heap to an hprof fileThis method tries to generate a filename of
java_pid##.TIMESTAMP.hprofwhere##is the PID of the running process andTIMESTAMPis the timestamp when the method was called inyyyy-MM-dd_HH-mm-ssformatThis method calls
dumpHeap(String, boolean)with theliveparameter set totrue -
dumpHeap
public static void dumpHeap(String filePath, boolean live) throws IOException, IllegalArgumentException Dumps the Java heap to an hprof file- Parameters:
filePath- the path to where the heap dump should be writtenlive-trueto only dump live objects (objects which are referenced by others)- Throws:
IOException- iffilePathalready exists, cannot be created, opened, or written toIllegalArgumentException- iffilePathdoes not end with the.hprofextension
-
dumpThreads
public static void dumpThreads()Dumps all threads to a fileThis method tries to generate a filename of
java_pid##.TIMESTAMP.threads.txtwhere##is the PID of the running process andTIMESTAMPis the timestamp when the method was called inyyyy-MM-dd_HH-mm-ssformat -
dumpThreads
Dumps all threads to a file- Parameters:
filePath- the path to where the thread dump should be written- Throws:
IOException- iffilePathalready exists, cannot be created, opened, or written to
-
pid
Attempts to retrieve the PID of the running process from theRuntimeMXBeanof the JVM process- Returns:
- the PID
- Throws:
NumberFormatException
-
getHeapMemoryUsage
Gets aMemoryUsagecontaining information about the current memory usage of the heap- Returns:
- a
MemoryUsagefor the heap
-
getNonHeapMemoryUsage
Gets aMemoryUsagecontaining information about the current non-heap memory usage- Returns:
- a
MemoryUsagefor non-heap memory
-
GetExecutionPath
Attempts to retrieve the full, real, absolute path to the directory in which PhantomBot.jar is located- Returns:
.on failure; otherwise, the path
-