src/java.desktop/share/native/common/awt/debug/debug_trace.c
author simonis
Wed, 21 Nov 2018 15:22:28 +0100
changeset 52636 f52ea62d68cc
parent 47216 71c04702a3d5
child 54395 24d072f23933
permissions -rw-r--r--
8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms Reviewed-by: stuefe, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "debug_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
static void DTrace_PrintStdErr(const char *msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#if defined(DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    MAX_TRACES = 200,           /* max number of defined trace points allowed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    MAX_TRACE_BUFFER = 512,     /* maximum size of a given trace output */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    MAX_LINE = 100000,          /* reasonable upper limit on line number in source file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    MAX_ARGC = 8                /* maximum number of arguments to print functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
typedef enum dtrace_scope {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    DTRACE_FILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    DTRACE_LINE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
} dtrace_scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
typedef struct dtrace_info {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    char                file[FILENAME_MAX+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    int                 line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    int                 enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    dtrace_scope        scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
} dtrace_info, * p_dtrace_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static dtrace_info      DTraceInfo[MAX_TRACES];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static char             DTraceBuffer[MAX_TRACE_BUFFER*2+1]; /* double the buffer size to catch overruns */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static dmutex_t         DTraceMutex = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
static dbool_t          GlobalTracingEnabled = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
static int              NumTraces = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static DTRACE_OUTPUT_CALLBACK   PfnTraceCallback = DTrace_PrintStdErr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static p_dtrace_info DTrace_GetInfo(dtrace_id tid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    DASSERT(tid < MAX_TRACES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    return &DTraceInfo[tid];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
static dtrace_id DTrace_CreateTraceId(const char * file, int line, dtrace_scope scope) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    dtrace_id           tid = NumTraces++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    p_dtrace_info       info = &DTraceInfo[tid];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    DASSERT(NumTraces < MAX_TRACES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    strcpy(info->file, file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    info->line = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    info->enabled = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    info->scope = scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    return tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Compares the trailing characters in a filename to see if they match
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * e.g. "src\win32\foobar.c" and "foobar.c" would be considered equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * but "src\win32\foo.c" and "src\win32\bar.c" would not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
static dbool_t FileNamesSame(const char * fileOne, const char * fileTwo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    size_t      lengthOne = strlen(fileOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    size_t      lengthTwo = strlen(fileTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    size_t      numCompareChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    dbool_t     tailsEqual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (fileOne == fileTwo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    } else if (fileOne == NULL || fileTwo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /* compare the tail ends of the strings for equality */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    numCompareChars = lengthOne < lengthTwo ? lengthOne : lengthTwo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    tailsEqual = strcmp(fileOne + lengthOne - numCompareChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        fileTwo + lengthTwo - numCompareChars) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    return tailsEqual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Finds the trace id for a given file/line location or creates one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * if it doesn't exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
static dtrace_id DTrace_GetTraceId(const char * file, int line, dtrace_scope scope) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    dtrace_id           tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    p_dtrace_info       info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /* check to see if the trace point has already been created */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    for ( tid = 0; tid < NumTraces; tid++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        info = DTrace_GetInfo(tid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if ( info->scope == scope ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            dbool_t     sameFile = FileNamesSame(file, info->file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            dbool_t     sameLine = info->line == line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if ( (info->scope == DTRACE_FILE && sameFile) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                 (info->scope == DTRACE_LINE && sameFile && sameLine) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                goto Exit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /* trace point wasn't created, so force it's creation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    tid = DTrace_CreateTraceId(file, line, scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
Exit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    return tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
static dbool_t DTrace_IsEnabledAt(dtrace_id * pfileid, dtrace_id * plineid, const char * file, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    DASSERT(pfileid != NULL && plineid != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    if ( *pfileid == UNDEFINED_TRACE_ID ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /* first time calling the trace for this file, so obtain a trace id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         *pfileid = DTrace_GetTraceId(file, -1, DTRACE_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    if ( *plineid == UNDEFINED_TRACE_ID ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /* first time calling the trace for this line, so obtain a trace id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         *plineid = DTrace_GetTraceId(file, line, DTRACE_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    return GlobalTracingEnabled || DTraceInfo[*pfileid].enabled || DTraceInfo[*plineid].enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * Initialize trace functionality. This MUST BE CALLED before any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * tracing function is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
void DTrace_Initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    DTraceMutex = DMutex_Create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * Cleans up tracing system. Should be called when tracing functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * is no longer needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
void DTrace_Shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    DMutex_Destroy(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
void DTrace_DisableMutex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    DTraceMutex = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Enable tracing for all modules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
void DTrace_EnableAll(dbool_t enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    GlobalTracingEnabled = enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * Enable tracing for a specific module. Filename may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * be fully or partially qualified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * e.g. awt_Component.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *              or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *      src\win32\native\sun\windows\awt_Component.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
void DTrace_EnableFile(const char * file, dbool_t enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    dtrace_id tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    p_dtrace_info info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    DASSERT(file != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    tid = DTrace_GetTraceId(file, -1, DTRACE_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    info = DTrace_GetInfo(tid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    info->enabled = enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * Enable tracing for a specific line in a specific module.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * See comments above regarding filename argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
void DTrace_EnableLine(const char * file, int line, dbool_t enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    dtrace_id tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    p_dtrace_info info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    DASSERT(file != NULL && (line > 0 && line < MAX_LINE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    tid = DTrace_GetTraceId(file, line, DTRACE_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    info = DTrace_GetInfo(tid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    info->enabled = enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
static void DTrace_ClientPrint(const char * msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    DASSERT(msg != NULL && PfnTraceCallback != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    (*PfnTraceCallback)(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * Print implementation for the use of client defined trace macros. Unsynchronized so it must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * be used from within a DTRACE_PRINT_CALLBACK function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
void DTrace_VPrintImpl(const char * fmt, va_list arglist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    DASSERT(fmt != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /* format the trace message */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    vsprintf(DTraceBuffer, fmt, arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /* not a real great overflow check (memory would already be hammered) but better than nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    DASSERT(strlen(DTraceBuffer) < MAX_TRACE_BUFFER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /* output the trace message */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    DTrace_ClientPrint(DTraceBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * Print implementation for the use of client defined trace macros. Unsynchronized so it must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * be used from within a DTRACE_PRINT_CALLBACK function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
void DTrace_PrintImpl(const char * fmt, ...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    va_list     arglist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    va_start(arglist, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    DTrace_VPrintImpl(fmt, arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    va_end(arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * Called via DTRACE_PRINT macro. Outputs printf style formatted text.
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   240
 * JNIEXPORT because these functions are also called from libawt_xawt.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 */
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   242
JNIEXPORT void JNICALL
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   243
DTrace_VPrint( const char * file, int line, int argc, const char * fmt, va_list arglist ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    DASSERT(fmt != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    DTrace_VPrintImpl(fmt, arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * Called via DTRACE_PRINTLN macro. Outputs printf style formatted text with an automatic newline.
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   250
 * JNIEXPORT because these functions are also called from libawt_xawt.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 */
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   252
JNIEXPORT void JNICALL
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   253
DTrace_VPrintln( const char * file, int line, int argc, const char * fmt, va_list arglist ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    DTrace_VPrintImpl(fmt, arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    DTrace_PrintImpl("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * Called via DTRACE_ macros. If tracing is enabled at the given location, it enters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * the trace mutex and invokes the callback function to output the trace.
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   261
 * JNIEXPORT because these functions are also called from libawt_xawt.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 */
52636
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   263
JNIEXPORT void JNICALL
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   264
DTrace_PrintFunction( DTRACE_PRINT_CALLBACK pfn, dtrace_id * pFileTraceId, dtrace_id * pLineTraceId,
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   265
                      const char * file, int line,
f52ea62d68cc 8214120: [REDO] Fix sun.awt.nativedebug on X11 platforms
simonis
parents: 47216
diff changeset
   266
                      int argc, const char * fmt, ... ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    va_list     arglist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    DASSERT(file != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    DASSERT(line > 0 && line < MAX_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    DASSERT(argc <= MAX_ARGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    DASSERT(fmt != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if ( DTrace_IsEnabledAt(pFileTraceId, pLineTraceId, file, line) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        va_start(arglist, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        (*pfn)(file, line, argc, fmt, arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        va_end(arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * Sets a callback function to be used to output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * trace statements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
void DTrace_SetOutputCallback(DTRACE_OUTPUT_CALLBACK pfn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    DASSERT(pfn != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    PfnTraceCallback = pfn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
/**********************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * Support for Java tracing in release or debug mode builds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
static void DTrace_PrintStdErr(const char *msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    fprintf(stderr, "%s", msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    fflush(stderr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
static void DTrace_JavaPrint(const char * msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#if defined(DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    DTrace_ClientPrint(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    DTrace_PrintStdErr(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
static void DTrace_JavaPrintln(const char * msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
#if defined(DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    DMutex_Enter(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    DTrace_ClientPrint(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    DTrace_ClientPrint("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    DMutex_Exit(DTraceMutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    DTrace_PrintStdErr(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    DTrace_PrintStdErr("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
/*********************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * Native method implementations. Java print trace calls are functional in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * release builds, but functions to enable/disable native tracing are not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
/* Implementation of DebugSettings.setCTracingOn*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
Java_sun_awt_DebugSettings_setCTracingOn__Z(JNIEnv *env, jobject self, jboolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
#if defined(DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    DTrace_EnableAll(enabled == JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
/* Implementation of DebugSettings.setCTracingOn*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
Java_sun_awt_DebugSettings_setCTracingOn__ZLjava_lang_String_2(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    jboolean enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    jstring file ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
#if defined(DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    const char *        cfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    cfile = JNU_GetStringPlatformChars(env, file, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    if ( cfile == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    DTrace_EnableFile(cfile, enabled == JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    JNU_ReleaseStringPlatformChars(env, file, cfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
/* Implementation of DebugSettings.setCTracingOn*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
Java_sun_awt_DebugSettings_setCTracingOn__ZLjava_lang_String_2I(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    jboolean enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    jstring file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    jint line ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
#if defined(DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    const char *        cfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    cfile = JNU_GetStringPlatformChars(env, file, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    if ( cfile == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    DTrace_EnableLine(cfile, line, enabled == JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    JNU_ReleaseStringPlatformChars(env, file, cfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}