Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/include/rastrace_external.h
5986 views
1
/*******************************************************************************
2
* Copyright (c) 2014, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#ifndef RASTRACE_EXTERNAL_H
24
#define RASTRACE_EXTERNAL_H
25
26
/* @ddr_namespace: default */
27
#include "ute_core.h"
28
#include "j9port.h"
29
30
#ifdef __cplusplus
31
extern "C" {
32
#endif
33
34
#define UT_THREAD_FROM_OMRVM_THREAD(thr) ((thr) ? &(thr)->_trace.uteThread : NULL)
35
36
/*
37
* =============================================================================
38
* Language interface - embedded in UtGlobalData
39
*
40
* This interface supplies callback functions for language-specific behaviour.
41
* A callback may be NULL. We will NULL-check each function pointer before invoking it.
42
* =============================================================================
43
*/
44
typedef omr_error_t (*SetLanguageTraceOptionFunc)(const OMR_VM *omr_vm, const char *optName, const char* optValue, BOOLEAN atRuntime);
45
typedef void (*ReportCommandLineErrorFunc)(J9PortLibrary* portLibrary, const char* detailStr, va_list args);
46
47
typedef struct OMRTraceLanguageInterface {
48
/**
49
* Attach the current thread to the language VM.
50
*
51
* The trace engine invokes this callback to attach internal threads to the VM.
52
* A sample implementation is omr_trc_defaultAttachCurrentThreadToLanguageVM().
53
* Attached threads will be detached using the DetachCurrentThreadFromLanguageVM() callback.
54
*
55
* @pre The current thread is completely unattached to the VM.
56
*
57
* @param[in] omrVM The OMR VM.
58
* @param[in] name The name of the current thread.
59
* @param[out] omrVMThread Location where a pointer to a new OMR VM thread should be stored. Must not be NULL.
60
*
61
* @return an OMR error code
62
*/
63
omr_error_t (*AttachCurrentThreadToLanguageVM)(OMR_VM *omrVM, const char *name, OMR_VMThread **omrVMThread);
64
65
/**
66
* Detach the current thread from the language VM.
67
*
68
* The trace engine invokes this callback to detach internal threads to the VM.
69
* A sample implementation is omr_trc_defaultDetachThreadFromLanguageVM().
70
* The current thread should have been attached using the AttachCurrentThreadToLanguageVM() callback.
71
*
72
* @pre The current thread is attached to the VM.
73
*
74
* @param[in,out] omrVMThread The OMR VM thread.
75
* @return an OMR error code
76
*/
77
omr_error_t (*DetachCurrentThreadFromLanguageVM)(OMR_VMThread *omrVMThread);
78
79
/**
80
* Pass unhandled trace options for implementer to handle.
81
*/
82
SetLanguageTraceOptionFunc SetLanguageTraceOption;
83
84
/**
85
* Report errors with trace options to the implementer's error stream.
86
*/
87
ReportCommandLineErrorFunc ReportCommandLineError;
88
} OMRTraceLanguageInterface;
89
90
/*
91
* =============================================================================
92
* Functions called by users of the trace library at initialisation/shutdown time.
93
* (Runtime functions are called vi UtInterface->UtServerInterface once initialized)
94
* =============================================================================
95
*/
96
97
/**
98
* @brief Fill in the interfaces the runtime will use to access trace functions.
99
*
100
* Fill in the interfaces the runtime will use to access trace functions.
101
* This function fills in the function tables that an application can use to access
102
* the trace engine functions.
103
*
104
* UtServerInterface contains the functions the application can use to access and control
105
* the trace engine.
106
*
107
* UtModuleInterface contains the functions used by a module (library) to initialize
108
* it's trace setup and to take trace points. These functions are usually accessed via
109
* the macros generated from the TDF files.
110
*
111
* @param[in,out] utIntf Will be returned a pointer to a newly initialized UtInterface structure.
112
* @param[in,out] utServerIntf
113
* @param[in,out] utModuleIntf
114
*
115
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
116
*/
117
omr_error_t fillInUTInterfaces(UtInterface **utIntf, UtServerInterface *utServerIntf, UtModuleInterface *utModuleIntf);
118
119
/**
120
* @brief Initialize the trace engine.
121
*
122
* Initialize the trace engine.
123
*
124
* The gbl pointer is intended to allow the trace global data structure
125
* to be linked to somewhere public so that it can be found by debugging
126
* tools, this allows them to do things like extract trace buffers from
127
* core files.
128
* It is not intended to give read/write access to the trace global data
129
* at runtime and is deliberately a void** for a structure that is not
130
* publicly defined.
131
*
132
* The opts field is used for the same purpose as the opts field in
133
* setOptions. See the documentation for that function for full details.
134
*
135
* The ignore field specifies options to ignore in the properties file.
136
*
137
* The function pointer types for the fields on OMRTraceLanguageInterface are
138
* documented with the function pointer definitions.
139
*
140
* @param[out] thr A UtThreadData pointer. *thr can point to NULL, initialize trace will initialize it.
141
* @param[in,out] gbl A pointer for the trace global data structure.
142
* @param[in] opts A NULL-terminated array of options to be passed to the trace engine.
143
* @param[in] vm The OMR_VM the trace engine will be running inside.
144
* @param[in] ignore Options to ignore in the properties file.
145
* @param[in] languageIntf A set of function pointers for accessing function in the OMR based runtime.
146
*
147
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
148
*/
149
omr_error_t initializeTrace(UtThreadData **thr, void **gbl,const char **opts, const OMR_VM *vm, const char **ignore, const OMRTraceLanguageInterface *languageIntf);
150
151
/**
152
* @brief Inform the trace engine the application has reached a point that trace can start it's own threads.
153
*
154
* Inform the trace engine the application has reached a point that trace can start it's own threads.
155
* The trace engine may (depending on the options it has been passed) start it's own internal threads
156
* at this point.
157
*
158
* @param[in] thr UtThreadData for the current thread.
159
*
160
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
161
*/
162
omr_error_t startTraceWorkerThread(UtThreadData **thr);
163
164
/**
165
* @brief Terminate the trace engine.
166
*
167
* Terminate the trace engine. This call will shut down the trace engine,
168
* waiting for all tracing threads to terminate and flush trace data to
169
* any subscribers.
170
*
171
* It will wait until all the threads not listed in daemonThreadNames have
172
* terminated or it's internal timeout has expired (1 second) before
173
* flushing the trace data to subscribers.
174
*
175
* @param[in] thr UtThreadData for the current thread.
176
* @param[in] daemonThreadNames A list of threads that should not be waited for before timing out.
177
*
178
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
179
*/
180
omr_error_t utTerminateTrace(UtThreadData **thr, char** daemonThreadNames);
181
182
/**
183
* @brief Free the trace engines internal data structures.
184
*
185
* This must only be called after utTerminateTrace and will free any remaining
186
* memory held by the trace engine.
187
*
188
* After calling this no further calls may be made to the trace engine.
189
*
190
* @param[in] thr UtThreadData for the current thread.
191
*
192
*/
193
void freeTrace(UtThreadData **thr);
194
195
/**
196
* @brief Notify trace that a new thread has started.
197
*
198
* Notify the trace engine that a new thread has started. Trace will
199
* allocate a new UtThreadData and store a pointer to it in the thr
200
* parameter.
201
*
202
* A thread *must not* attempt to take a trace point or invoke trace
203
* functions until this function has been called.
204
*
205
* Note that passing another threads UtThreadData when taking a
206
* trace point may work - but will lead to the event represented
207
* by that trace point appearing to have occurred on the other thread
208
* once the trace is formatted. This is extremely undesirable when
209
* using trace for problem determination.
210
*
211
* NOTE: Currently thrSynonym1 must be the omrthread_t for this thread and
212
* thrSynonym2 must be the OMR_VMThread.
213
*
214
* @param[out] thr The UtThreadData structure for this thread.
215
* @param[in] threadId The id of this thread. Must be unique. (The address of a per thread structure is recommended)
216
* @param[in] threadName A name for this thread. Will be displayed when trace data is formatted. May be NULL.
217
* @param[in] thrSynonym1 A synonym for this threads id to aid cross referencing in problem diagnosis.
218
* @param[in] thrSynonym2 A synonym for this threads id to aid cross referencing in problem diagnosis.
219
*
220
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
221
*/
222
omr_error_t threadStart(UtThreadData **thr, const void *threadId, const char *threadName, const void *thrSynonym1, const void *thrSynonym2);
223
224
/**
225
* @brief Notify trace that a thread has stopped.
226
*
227
* Inform the trace engine that the thread represented by this
228
* UtThreadData has terminated and free it's allocated UtThreadData.
229
*
230
* @param[in,out] thr The UtThreadData structure for this thread.
231
*
232
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
233
*/
234
omr_error_t threadStop(UtThreadData **thr);
235
236
/**
237
* @brief Set trace options
238
*
239
* Set trace options, options are supplied in an array of strings.
240
* For options that are key/value pairs (for example maximal=all)
241
* the key is passed in position n and the value in n+1:
242
* opts[n] = "maximal";
243
* opts[n+1] = "all";
244
* For simple flag options (for example nofatalassert) the flag is
245
* passed in opts[n] and opts[n+1] is null.
246
* opts[n] = "nofatalassert";
247
* opts[n+1] = NULL;
248
*
249
* The atRuntime flag is set to TRUE if trace startup is complete
250
* (startTraceWorkerThread has been called) and FALSE if it
251
* setOptions is called before that. Certain options may only be
252
* set during startup. If atRuntime is TRUE setOptions will not attempt
253
* to set those options.
254
*
255
* The SetOptions call available on UtServerInterface is identical but
256
* is only intended to be called once trace startup is complete and
257
* effectively is the same call with atRuntime set to TRUE.
258
*
259
* @param[in] thr The UtThreadData for the currently executing thread. Must not be NULL.
260
* @param[in] opts An array of options to be passed to the trace engine.
261
* @param[in] atRuntime A flag indicating whether trace startup is complete.
262
*
263
* @return The integer debug level the trace engine is using.
264
*/
265
omr_error_t setOptions(UtThreadData **thr, const char **opts, BOOLEAN atRuntime);
266
267
/**
268
* @brief Set the information to be included in the trace file header.
269
*
270
* Set the information to be included in the trace file header. This is
271
* information which will be included in the header of all binary trace
272
* files generated by this application and formatted into the header
273
* information when that trace file is formatted.
274
*
275
* Typically serviceInfo is the unique version string for the application
276
* and startupInfo is the formatted command line.
277
*
278
* The strings are copied so may be freed.
279
*
280
* @param[in] serviceInfo The service level of the application.
281
* @param[in] startupInfo The startup information for the application.
282
*
283
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
284
*/
285
omr_error_t setTraceHeaderInfo(const char * serviceInfo, const char * startupInfo);
286
287
/**
288
* @brief Obtain the debug level for the trace engine.
289
*
290
* Obtain the debug level for the trace engine. This is set by passing trace the
291
* option debug=N (where N is a positive integer).
292
*
293
* This function allows trace implementers to write statements of the form:
294
* if ( getDebugLevel > N ) {
295
* ReportCommandLineErrorFunc(....)
296
* }
297
* where ReportCommandLineErrorFunc is the same function (or the same underlying functionality)
298
* as passed to the trace engine in field OMRTraceLanguageInterface.ReportCommandLineError when trace
299
* was initialized. This allows trace implementers to integrate their own debugging messages
300
* with those from the trace engine without having to create a separate debugging mechanism.
301
*
302
* @return The integer debug level the trace engine is using.
303
*/
304
int32_t getDebugLevel(void);
305
306
/**
307
* @brief Creates a trace point
308
*
309
* Creates a trace point to record a trace event for the specified thread (generally the
310
* currently running thread). The trace point is in the module described by modInfo and
311
* has it's trace id masked with it's activation information. (This is generated as part
312
* of the trace macros and should simply be passed through.)
313
*
314
* The spec parameter describes the arguments to the trace point (and is also generated)
315
* and those arguments (if any) are contained in the va_list.
316
*
317
* This function exists to allow users to override the default implementation of
318
* UtModuleInterface.Trace(void *env, UtModuleInfo *modInfo, uint32_t traceId, const char *spec, ...);
319
* and pass in the var args arguments (since the use of var args prevents simply calling
320
* the original UtModuleInterface.Trace function). This allows trace implementers to
321
* map from a per thread env parameter that is convenient for their application to a
322
* UtThreadData. All the other parameters should be left unchanged.
323
*
324
* @param[in] thr The UtThreadData for the currently executing thread. Must not be NULL.
325
* @param[in] modInfo A pointer to the UtModuleInfo for the module this trace point belongs to.
326
* @param[in] traceId The trace point id for this trace point.
327
* @param[in] spec The trace point format specification for this trace point
328
* @param[in] varArgs The va_list of parameters for this trace point.
329
*/
330
void doTracePoint(UtThreadData **thr, UtModuleInfo *modInfo, uint32_t traceId, const char *spec, va_list varArgs);
331
332
/**
333
* @brief Walk the current trace configuration options.
334
*
335
* Returns each of the trace options that have been set and updates **cursor to
336
* track it's position. Passing *cursor = NULL begins a new walk.
337
*
338
* Cursor is updated during the walk and will be NULL when the end of the options
339
* is reached. The returned char* will also be NULL at the end of the walk.
340
*
341
* @param cursor A cursor to record the current walk position with.
342
*
343
* @return a pointer to an option string or NULL when there are no more options.
344
*/
345
const char* walkTraceConfig(void **cursor);
346
347
/*
348
* =============================================================================
349
* Keywords for trace command line options.
350
* =============================================================================
351
*/
352
353
#define UT_DEBUG_KEYWORD "DEBUG"
354
#define UT_FORMAT_KEYWORD "FORMAT"
355
#define UT_SUFFIX_KEYWORD "SUFFIX"
356
#define UT_LIBPATH_KEYWORD "LIBPATH"
357
#define UT_PROPERTIES_KEYWORD "PROPERTIES"
358
#define UT_BUFFERS_KEYWORD "BUFFERS"
359
#define UT_INIT_KEYWORD "INITIALIZATION"
360
#define UT_RESET_KEYWORD "RESETTABLE"
361
#define UT_MINIMAL_KEYWORD "MINIMAL"
362
#define UT_MAXIMAL_KEYWORD "MAXIMAL"
363
#define UT_COUNT_KEYWORD "COUNT"
364
#define UT_PRINT_KEYWORD "PRINT"
365
#define UT_IPRINT_KEYWORD "IPRINT"
366
#define UT_PLATFORM_KEYWORD "PLATFORM"
367
#define UT_EXTERNAL_KEYWORD "EXTERNAL"
368
#define UT_EXCEPTION_KEYWORD "EXCEPTION"
369
#define UT_EXCEPT_OUT_KEYWORD "EXCEPTION.OUTPUT"
370
#define UT_STATE_OUT_KEYWORD "STATE.OUTPUT"
371
#define UT_NONE_KEYWORD "NONE"
372
#define UT_OUTPUT_KEYWORD "OUTPUT"
373
#define UT_LEVEL_KEYWORD "LEVEL"
374
#define UT_TRIGGER_KEYWORD "TRIGGER"
375
#define UT_SUSPEND_KEYWORD "SUSPEND"
376
#define UT_RESUME_KEYWORD "RESUME"
377
#define UT_RESUME_COUNT_KEYWORD "RESUMECOUNT"
378
#define UT_SUSPEND_COUNT_KEYWORD "SUSPENDCOUNT"
379
#define UT_ALL "ALL"
380
#define UT_BACKTRACE "BACKTRACE"
381
#define UT_FATAL_ASSERT_KEYWORD "FATALASSERT"
382
#define UT_NO_FATAL_ASSERT_KEYWORD "NOFATALASSERT"
383
#define UT_SLEEPTIME_KEYWORD "SLEEPTIME"
384
385
/*
386
* =============================================================================
387
* Types for trace trigger functionality.
388
* =============================================================================
389
*/
390
391
/**
392
* When a trigger was fired - before or after a tracepoint
393
*/
394
typedef enum TriggerPhase {BEFORE_TRACEPOINT, AFTER_TRACEPOINT} TriggerPhase;
395
396
typedef void (*TriggerActionFunc)(OMR_VMThread *thr); /* Function to call when performing a trigger action */
397
398
typedef struct RasTriggerAction {
399
const char *name; /* String specified on the cmd-line to select this action */
400
TriggerPhase phase; /* When this trigger action should be fired */
401
TriggerActionFunc fn; /* Function to call when performing the action */
402
} RasTriggerAction;
403
404
typedef omr_error_t (*ParseTriggerTypeFunc)(OMR_VMThread *thr, char *opt, BOOLEAN atRuntime); /* Function to parse the options of a trigger type */
405
406
typedef struct RasTriggerType {
407
const char *name; /* String specified on the cmd-line to select this type */
408
ParseTriggerTypeFunc parse; /* Function to parse the options of this trigger type */
409
BOOLEAN runtimeModifiable; /* Whether this trigger type can be modified at runtime */
410
} RasTriggerType;
411
412
/**
413
* @brief Add a type of trace trigger
414
*
415
* Add a type of trace trigger. This allows additional trace trigger types
416
* (the base types are "group" and "tpnid") to be added to the trace engine
417
*
418
* The application can define it's own logic for triggering these new types
419
* of triggers and they can call any of the available trigger actions.
420
*
421
* @param[in] thr The UtThreadData for the currently executing thread.
422
* @param[in] newType The new trigger type to add.
423
*
424
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
425
*/
426
omr_error_t addTriggerType(OMR_VMThread *thr, const struct RasTriggerType *newType);
427
428
/**
429
* @brief Add a type of trace trigger action.
430
*
431
* Add a type of trace trigger. This allows additional trace trigger actions
432
* to be added to the trace engine These can be triggered by any trigger type.
433
*
434
* This allows the application to define additional actions or call backs that
435
* can occur when a trace point fires.
436
*
437
* @param[in] thr The UtThreadData for the currently executing thread.
438
* @param[in] newAction The new trigger action to add.
439
*
440
* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.
441
*/
442
omr_error_t addTriggerAction(OMR_VMThread *thr, const struct RasTriggerAction *newAction);
443
444
/**
445
* Convert the name of a trigger action into its entry in the rasTriggerActions array.
446
*
447
* @param thr
448
* @param name A trigger name string.
449
*
450
* @return Trigger action or NULL
451
*/
452
const struct RasTriggerAction *parseTriggerAction(OMR_VMThread *thr, const char *name, BOOLEAN atRuntime);
453
454
#ifdef __cplusplus
455
}
456
#endif
457
458
#endif /* !RASTRACE_EXTERNAL_H */
459
460