ibmjvmti.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*******************************************************************************
  2. * Licensed Materials - Property of IBM
  3. * "Restricted Materials of IBM"
  4. *
  5. * (c) Copyright IBM Corp. 1991, 2015 All Rights Reserved
  6. *
  7. * US Government Users Restricted Rights - Use, duplication or disclosure
  8. * restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *******************************************************************************/
  10. #ifndef ibmjvmti_h
  11. #define ibmjvmti_h
  12. /*
  13. *-----------------------------------------------------------------------------
  14. * This file defines structures, constants, enums and other
  15. * definitions which can be used with IBM Corporation's
  16. * JVMTI extensions. These extensions are available through
  17. * the JVMTI extension mechanism.
  18. * See GetExtensionEvents(), GetExtensionFunctions() and
  19. * SetExtensionEventCallback()
  20. *-----------------------------------------------------------------------------
  21. */
  22. #include "jvmti.h"
  23. /*
  24. *-----------------------------------------------------------------------------
  25. * Extended JVMTI constants
  26. *-----------------------------------------------------------------------------
  27. */
  28. #define COM_IBM_GET_POTENTIAL_EXTENDED_CAPABILITIES "com.ibm.GetPotentialExtendedCapabilities"
  29. #define COM_IBM_ADD_EXTENDED_CAPABILITIES "com.ibm.AddExtendedCapabilities"
  30. #define COM_IBM_RELINQUISH_EXTENDED_CAPABILITIES "com.ibm.RelinquishExtendedCapabilities"
  31. #define COM_IBM_GET_EXTENDED_CAPABILITIES "com.ibm.GetExtendedCapabilities"
  32. #define COM_IBM_COMPILING_START "com.ibm.CompilingStart"
  33. #define COM_IBM_COMPILING_END "com.ibm.CompilingEnd"
  34. #define COM_IBM_METHOD_ENTRY_EXTENDED "com.ibm.MethodEntryExtended"
  35. #define COM_IBM_METHOD_EXIT_NO_RC "com.ibm.MethodExitNoRc"
  36. #define COM_IBM_INSTRUMENTABLE_OBJECT_ALLOC "com.ibm.InstrumentableObjectAlloc"
  37. #define COM_IBM_SET_VM_TRACE "com.ibm.SetVmTrace"
  38. #define COM_IBM_SET_VM_DUMP "com.ibm.SetVmDump"
  39. #define COM_IBM_RESET_VM_DUMP "com.ibm.ResetVmDump"
  40. #define COM_IBM_TRIGGER_VM_DUMP "com.ibm.TriggerVmDump"
  41. #define COM_IBM_VM_DUMP_START "com.ibm.VmDumpStart"
  42. #define COM_IBM_VM_DUMP_END "com.ibm.VmDumpEnd"
  43. #define COM_IBM_QUERY_VM_DUMP "com.ibm.QueryVmDump"
  44. #define COM_IBM_QUERY_VM_LOG_OPTIONS "com.ibm.QueryVmLogOptions"
  45. #define COM_IBM_SET_VM_LOG_OPTIONS "com.ibm.SetVmLogOptions"
  46. #define COM_IBM_SET_VM_JLM "com.ibm.SetVmJlm"
  47. #define COM_IBM_SET_VM_JLM_DUMP "com.ibm.SetVmJlmDump"
  48. #define COM_IBM_ALLOW_INLINING_WITH_METHOD_ENTER_EXIT "com.ibm.AllowMethodInliningWithMethodEnterExit"
  49. #define COM_IBM_ALLOW_DIRECT_JNI_WITH_METHOD_ENTER_EXIT "com.ibm.AllowDirectJNIWithMethodEnterExit"
  50. #define COM_IBM_SET_VM_AND_COMPILING_CONTROL_OPTIONS "com.ibm.SetVmAndCompilingControlOptions"
  51. #define COM_IBM_SET_METHOD_SELECTIVE_ENTRY_EXIT_NOTIFY "com.ibm.jvmtiSetMethodSelectiveEntryExitNotification"
  52. #define COM_IBM_SET_EXTENDED_EVENT_NOTIFICATION_MODE "com.ibm.jvmtiSetExtendedEventNotificationMode"
  53. #define COM_IBM_CLEAR_METHOD_SELECTIVE_ENTRY_EXIT_NOTIFY "com.ibm.jvmtiClearMethodSelectiveEntryExitNotification"
  54. #define COM_IBM_GET_OS_THREAD_ID "com.ibm.GetOSThreadID"
  55. #define COM_IBM_SIGNAL_ASYNC_EVENT "com.ibm.SignalAsyncEvent"
  56. #define COM_IBM_CANCEL_ASYNC_EVENT "com.ibm.CancelAsyncEvent"
  57. #define COM_IBM_ASYNC_EVENT "com.ibm.AsyncEvent"
  58. #define COM_IBM_GET_STACK_TRACE_EXTENDED "com.ibm.GetStackTraceExtended"
  59. #define COM_IBM_GET_ALL_STACK_TRACES_EXTENDED "com.ibm.GetAllStackTracesExtended"
  60. #define COM_IBM_GET_THREAD_LIST_STACK_TRACES_EXTENDED "com.ibm.GetThreadListStackTracesExtended"
  61. #define COM_IBM_GARBAGE_COLLECTION_CYCLE_START "com.ibm.GarbageCollectionCycleStart"
  62. #define COM_IBM_GARBAGE_COLLECTION_CYCLE_FINISH "com.ibm.GarbageCollectionCycleFinish"
  63. #define COM_IBM_GET_HEAP_FREE_MEMORY "com.ibm.GetHeapFreeMemory"
  64. #define COM_IBM_GET_HEAP_TOTAL_MEMORY "com.ibm.GetHeapTotalMemory"
  65. #define COM_IBM_ITERATE_SHARED_CACHES "com.ibm.IterateSharedCaches"
  66. #define COM_IBM_DESTROY_SHARED_CACHE "com.ibm.DestroySharedCache"
  67. #define COM_IBM_ADD_CAN_AUTO_TAG_OBJECTS_CAPABILITY "com.ibm.AddCanAutoTagObjectsCapability"
  68. #define COM_IBM_OBJECTS_RENAMED "com.ibm.ObjectsRenamed"
  69. #define COM_IBM_AUTOTAGGED_OBJECT_ALLOCATED "com.ibm.AutotaggedObjectAllocated"
  70. #define COM_IBM_ARRAY_CLASS_LOAD "com.ibm.ArrayClassLoad"
  71. #define COM_IBM_REMOVE_ALL_TAGS "com.ibm.RemoveAllTags"
  72. #define COM_IBM_REGISTER_TRACE_SUBSCRIBER "com.ibm.RegisterTraceSubscriber"
  73. #define COM_IBM_DEREGISTER_TRACE_SUBSCRIBER "com.ibm.DeregisterTraceSubscriber"
  74. #define COM_IBM_FLUSH_TRACE_DATA "com.ibm.FlushTraceData"
  75. #define COM_IBM_GET_TRACE_METADATA "com.ibm.GetTraceMetadata"
  76. #define COM_IBM_GET_METHOD_AND_CLASS_NAMES "com.ibm.GetMethodAndClassNames"
  77. #define COM_IBM_JLM_DUMP_STATS "com.ibm.JlmDumpStats"
  78. #define COM_IBM_GET_MEMORY_CATEGORIES "com.ibm.GetMemoryCategories"
  79. #define COM_IBM_REGISTER_VERBOSEGC_SUBSCRIBER "com.ibm.RegisterVerboseGCSubscriber"
  80. #define COM_IBM_DEREGISTER_VERBOSEGC_SUBSCRIBER "com.ibm.DeregisterVerboseGCSubscriber"
  81. #define COM_IBM_GET_J9VMTHREAD "com.ibm.GetJ9vmThread"
  82. #define COM_IBM_GET_J9METHOD "com.ibm.GetJ9method"
  83. #define COM_IBM_REGISTER_TRACEPOINT_SUBSCRIBER "com.ibm.RegisterTracePointSubscriber"
  84. #define COM_IBM_DEREGISTER_TRACEPOINT_SUBSCRIBER "com.ibm.DeregisterTracePointSubscriber"
  85. #define COM_IBM_SHARED_CACHE_MODLEVEL_JAVA5 1
  86. #define COM_IBM_SHARED_CACHE_MODLEVEL_JAVA6 2
  87. #define COM_IBM_SHARED_CACHE_MODLEVEL_JAVA7 3
  88. #define COM_IBM_SHARED_CACHE_MODLEVEL_JAVA8 4
  89. #define COM_IBM_SHARED_CACHE_ADDRMODE_32 32
  90. #define COM_IBM_SHARED_CACHE_ADDRMODE_64 64
  91. /*
  92. * Constants for flags field of COM_IBM_ITERATE_SHARED_CACHES.
  93. * Users should always pass one of the following values to the flags field of COM_IBM_ITERATE_SHARED_CACHES.
  94. */
  95. #define COM_IBM_ITERATE_SHARED_CACHES_NO_FLAGS 0
  96. /*
  97. *-----------------------------------------------------------------------------
  98. * Extended cacheType constants for COM_IBM_DESTROY_SHARED_CACHE
  99. *-----------------------------------------------------------------------------
  100. */
  101. #define COM_IBM_SHARED_CACHE_PERSISTENCE_DEFAULT 0
  102. #define COM_IBM_SHARED_CACHE_PERSISTENT 1
  103. #define COM_IBM_SHARED_CACHE_NONPERSISTENT 2
  104. #define COM_IBM_SHARED_CACHE_SNAPSHOT 5
  105. /*
  106. *-----------------------------------------------------------------------------
  107. * Return type for COM_IBM_DESTROY_SHARED_CACHE
  108. *-----------------------------------------------------------------------------
  109. */
  110. /* When no cache exists or successfully destroyed all caches. */
  111. #define COM_IBM_DESTROYED_ALL_CACHE 0
  112. /* When failed to destroy any cache. */
  113. #define COM_IBM_DESTROYED_NONE -1
  114. /* When failed to destroy cache of current generation. */
  115. #define COM_IBM_DESTROY_FAILED_CURRENT_GEN_CACHEE -2
  116. /* When failed to destroy one or more older generation cache and either current generation cache does not exists or is successfully destroyed */
  117. #define COM_IBM_DESTROY_FAILED_OLDER_GEN_CACHE -3
  118. /*
  119. *-----------------------------------------------------------------------------
  120. * Extended JVMTI enumerations
  121. *-----------------------------------------------------------------------------
  122. */
  123. enum {
  124. COM_IBM_METHOD_ENTRY_EXTENDED_INTERPRETED = 0,
  125. COM_IBM_METHOD_ENTRY_EXTENDED_COMPILED = 1,
  126. COM_IBM_METHOD_ENTRY_EXTENDED_NATIVE = 2,
  127. COM_IBM_METHOD_ENTRY_EXTENDED_PARTIAL_IN_LINE = 3,
  128. COM_IBM_METHOD_ENTRY_EXTENDED_IN_LINE = 4
  129. };
  130. enum {
  131. COM_IBM_JLM_START = 0,
  132. COM_IBM_JLM_START_TIME_STAMP = 1,
  133. COM_IBM_JLM_STOP = 2,
  134. COM_IBM_JLM_STOP_TIME_STAMP = 3
  135. };
  136. enum {
  137. COM_IBM_ENABLE_SELECTIVE_METHOD_ENTRY_EXIT_NOTIFICATION = 0
  138. };
  139. enum {
  140. COM_IBM_STACK_FRAME_EXTENDED_NOT_JITTED = 0,
  141. COM_IBM_STACK_FRAME_EXTENDED_JITTED = 1
  142. };
  143. /**
  144. * Bits used to select the type of data to be returned by the extended stack trace calls
  145. */
  146. enum {
  147. COM_IBM_GET_STACK_TRACE_PRUNE_UNREPORTED_METHODS = 1, /** Prunes methods for which method enter was not reported */
  148. COM_IBM_GET_STACK_TRACE_ENTRY_LOCAL_STORAGE = 2, /** Returns ELS pointers */
  149. COM_IBM_GET_STACK_TRACE_EXTRA_FRAME_INFO = 4 /** Returns jitted vs non-jitted data */
  150. };
  151. /**
  152. * JlmDumpStats format specifiers
  153. */
  154. enum {
  155. COM_IBM_JLM_DUMP_FORMAT_OBJECT_ID = 0,
  156. COM_IBM_JLM_DUMP_FORMAT_TAGS = 1
  157. };
  158. #define JVMTI_MONITOR_JAVA 0x01
  159. #define JVMTI_MONITOR_RAW 0x02
  160. /*
  161. *-----------------------------------------------------------------------------
  162. * Extended JVMTI function types
  163. *-----------------------------------------------------------------------------
  164. */
  165. /*
  166. *-----------------------------------------------------------------------------
  167. * Extended JVMTI structure types
  168. *-----------------------------------------------------------------------------
  169. */
  170. typedef struct jlm_dump {
  171. char * begin;
  172. char * end;
  173. } jlm_dump;
  174. /* JLM dump format
  175. *
  176. * All entries are in packed big endian format
  177. * u1 monitor type
  178. *
  179. * 1 Java monitor
  180. * jobjectID object
  181. * JNIEnv * owner thread
  182. * u4 entry count
  183. * u4 # of threads waiting to enter
  184. * [JNIEnv *]* threads waiting to enter
  185. * u4 # of threads waiting to be notified
  186. * [JNIEnv *]* threads waiting to be notified
  187. *
  188. * 2 raw monitor
  189. * char * name
  190. * RawMonitor raw monitor
  191. * JNIEnv * owner thread
  192. * u4 entry count
  193. * u4 # of threads waiting to enter
  194. * [JNIEnv *]* threads waiting to enter
  195. * u4 # of threads waiting to be notified
  196. * [JNIEnv *]* threads waiting to be notified
  197. */
  198. /**
  199. * struct jvmtiFrameInfoExtended
  200. * Has two additional fields, compared to struct jvmtiFrameInfo:
  201. * machinepc and type
  202. */
  203. typedef struct jvmtiFrameInfoExtended {
  204. jmethodID method;
  205. jlocation location;
  206. jlocation machinepc;
  207. jint type; /*!< frame type can be not jitted or jitted */
  208. void * nativeFrameAddress; /*!< address of the native frame */
  209. } jvmtiFrameInfoExtended;
  210. /**
  211. * struct jvmtiStackInfoExtended
  212. * frame buffer is a pointer to jvmtiFrameInfoExtended,
  213. * whereas frame buffer is pointer to jvmtiFrameInfo
  214. * in struct jvmtiStackInfo
  215. */
  216. typedef struct jvmtiStackInfoExtended {
  217. jthread thread;
  218. jint state;
  219. jvmtiFrameInfoExtended* frame_buffer;
  220. jint frame_count;
  221. } jvmtiStackInfoExtended;
  222. /**
  223. * Version information for the COM_IBM_ITERATE_SHARED_CACHES API. Users
  224. * should pass this value as the "version" parameter. If the jvmtiSharedCacheInfo
  225. * structure is expanded, IBM will increment this define.
  226. */
  227. #define COM_IBM_ITERATE_SHARED_CACHES_VERSION_1 1
  228. #define COM_IBM_ITERATE_SHARED_CACHES_VERSION_2 2
  229. /**
  230. * struct jvmtiSharedCacheInfo
  231. * name - the name of the cache
  232. * isCompatible - is the cache compatible with this JVM
  233. * isPersistent - true if the cache is persistent cache, false if the cache is non-persistent or cache snapshot
  234. * os_shmid - Operating System specific shared memory id
  235. * os_semid - Operating System specific semaphore id
  236. * modLevel - the modification level
  237. * addrMode - the address mode of the JVM
  238. * isCorrupt - true when the cache is found to be corrupt
  239. * cacheSize - the size of the cache
  240. * freeBytes - the size of free space in the cache
  241. * lastDetach - time from which last detach has happened
  242. * cacheType - the type of the cache. This is the new field included when COM_IBM_ITERATE_SHARED_CACHES_VERSION_2 is specified
  243. *
  244. * If IBM adds new information to this structure, it will be added
  245. * to the end to preserve backwards compability, and
  246. * COM_IBM_ITERATE_SHARED_CACHES_VERSION will be incremented.
  247. */
  248. typedef struct jvmtiSharedCacheInfo {
  249. const char *name;
  250. jboolean isCompatible;
  251. jboolean isPersistent;
  252. jint os_shmid;
  253. jint os_semid;
  254. jint modLevel;
  255. jint addrMode;
  256. jboolean isCorrupt;
  257. jlong cacheSize;
  258. jlong freeBytes;
  259. jlong lastDetach;
  260. jint cacheType;
  261. } jvmtiSharedCacheInfo;
  262. /**
  263. * Signature of callback function which must be provided to COM_IBM_ITERATE_SHARED_CACHES.
  264. *
  265. * When your callback is called you will be provided with:
  266. * env - the jvmtiEnv you supplied when calling COM_IBM_ITERATE_SHARED_CACHES
  267. * cache_info - a structure containing information about a shared cache
  268. * user_data - the user_data you provided to COM_IBM_ITERATE_SHARED_CACHES
  269. *
  270. * Return - JNI_OK on success, JNI_ERR on failure (no more callbacks will be sent).
  271. */
  272. typedef jint (JNICALL *jvmtiIterateSharedCachesCallback)(
  273. jvmtiEnv *env, jvmtiSharedCacheInfo *cache_info, void *user_data);
  274. /**
  275. * struct jvmtiObjectRenameInfo
  276. * oldAutoTag is the previous automatic tag.
  277. * newAutoTag is the new automatic tag.
  278. * The value 0 means that the object is deleted.
  279. */
  280. typedef struct jvmtiObjectRenameInfo {
  281. jlong oldAutoTag;
  282. jlong newAutoTag;
  283. } jvmtiObjectRenameInfo;
  284. /**
  285. * Signature of callback function which may be provided to the jvmtiAutotaggedObjectAlloc callback.
  286. * This function is callback-safe and it has the same parameters as VMObjectAlloc, plus a pointer to userData.
  287. *
  288. * JNIEnv - the JNI environment of the event (current) thread.
  289. * thread - thread allocating the object.
  290. * object - JNI local reference to the object that was allocated.
  291. * object_klass - JNI local reference to the class of the object.
  292. * size - size of the object (in bytes).
  293. * userData - pointer received in the jvmtiAutotaggedObjectAlloc callback
  294. */
  295. typedef void (JNICALL *jvmtiAutotaggedObjectAllocCallbackSafeFunction)(
  296. jvmtiEnv *jvmti_env,
  297. JNIEnv* jni_env,
  298. jthread thread,
  299. jobject object,
  300. jclass object_klass,
  301. jlong size,
  302. void *userData);
  303. /*
  304. * Trace subscriber callback function. This function will be passed records containing trace
  305. * data as they are processed. This provides a mechanism for a user defined transport and is
  306. * unrelated to actual formatting of the trace data.
  307. * env - the jvmti env supplied when the subscriber was registered
  308. * record - the record
  309. * length - the size of the record
  310. * userData - user data provided at registration
  311. * return:
  312. * JVMTI_ERROR_NONE - success
  313. * any other value - the subscriber is deregistered and will not receive any more data
  314. *
  315. */
  316. typedef jvmtiError (*jvmtiTraceSubscriber)(jvmtiEnv *env, void *record, jlong length, void *userData);
  317. /*
  318. * Alarm callback function that's executed if the subscriber returns an error or misbehaves.
  319. * env - the jvmti env supplied when the subscriber was registered
  320. * subscriptionID - the ID of the subscription that raised the alarm
  321. * userData - user data provided at registration
  322. */
  323. typedef void (*jvmtiTraceAlarm)(jvmtiEnv *env, void *subscriptionID, void *userData);
  324. /*
  325. * Return data for the jvmtiGetMethodClassPackageNames extension. Keeps track of class,
  326. * method and package name pointers copied into the user supplied buffer.
  327. */
  328. typedef struct jvmtiExtensionRamMethodData
  329. {
  330. jchar * className; /* ptr into ramMethodStrings, a null terminated class name string */
  331. jchar * methodName; /* ptr into ramMethodStrings, a null terminated method name string */
  332. jvmtiError reasonCode; /* error code indicating why this record has not been returned back
  333. (out of memory, invalid method or none) */
  334. } jvmtiExtensionRamMethodData;
  335. /**
  336. * Version information for the GetMemoryCategories API. Users
  337. * should pass this value as the "version" parameter. If the jvmtiMemoryCategory
  338. * structure is expanded, IBM will increment this define.
  339. */
  340. #define COM_IBM_GET_MEMORY_CATEGORIES_VERSION_1 1
  341. /*
  342. * Return data for the GetMemoryCategories API
  343. */
  344. typedef struct jvmtiMemoryCategory {
  345. /* Category name */
  346. const char * name;
  347. /* Bytes allocated under this category */
  348. jlong liveBytesShallow;
  349. /* Bytes allocated under this category and all child categories */
  350. jlong liveBytesDeep;
  351. /* Number of allocations under this category */
  352. jlong liveAllocationsShallow;
  353. /* Number of allocations under this category and all child categories */
  354. jlong liveAllocationsDeep;
  355. /* Pointer to the first child category (NULL if this node has no children) */
  356. struct jvmtiMemoryCategory * firstChild;
  357. /* Pointer to the next sibling category (NULL if this node has no next sibling)*/
  358. struct jvmtiMemoryCategory * nextSibling;
  359. /* Pointer to the parent category. (NULL if this node is a root) */
  360. struct jvmtiMemoryCategory * parent;
  361. } jvmtiMemoryCategory;
  362. /*
  363. * Verbose GC subscriber callback function. This function will be passed records containing verbose GC
  364. * data as it is processed. The data is in ASCII XML. The data is valid for the duration of the callback.
  365. * If the subscriber wishes to save the data, it must copy it elsewhere.
  366. *
  367. * Note that the callback is called while the VM is stopped, thus the callback must not use JNI functions
  368. * and must not use JVMTI functions except those which specifically allow such use.
  369. *
  370. * @param env[in] the jvmti env supplied when the subscriber was registered
  371. * @param record[in] the XML data
  372. * @param length[in] the size of the record, in bytes. Does not include any NUL terminator, if any.
  373. * @param userData[in] user data provided at registration
  374. * @return JVMTI_ERROR_NONE on success
  375. * If an error is returned, the alarm callback is called, the subscriber is deregistered, and no more data is sent
  376. */
  377. typedef jvmtiError (*jvmtiVerboseGCSubscriber)(jvmtiEnv *env, const char *record, jlong length, void *userData);
  378. /*
  379. * Alarm callback function that's executed if the subscriber returns an error or misbehaves.
  380. * @param env[in] the jvmti env supplied when the subscriber was registered
  381. * @param subscriptionID[in] the ID of the subscription that raised the alarm
  382. * @param userData[in] user data provided at registration
  383. */
  384. typedef void (*jvmtiVerboseGCAlarm)(jvmtiEnv *env, void *subscriptionID, void *userData);
  385. #endif /* ibmjvmti_h */