1 /*
   2  * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef _Included_Trace
  27 #define _Included_Trace
  28 
  29 #include <jni.h>
  30 #include "jni_util.h"
  31 #include "debug_trace.h"
  32 
  33 #ifdef __cplusplus
  34 extern "C" {
  35 #endif /* __cplusplus */
  36 extern JavaVM *jvm;
  37 extern jint graphicsPrimitive_traceflags;
  38 
  39 /**
  40  * J2dTrace
  41  * Trace utility used throughout Java 2D code.  Uses a "level"
  42  * parameter that allows user to specify how much detail
  43  * they want traced at runtime.  Tracing is only enabled
  44  * in debug mode, to avoid overhead running release build.
  45  */
  46 
  47 #define J2D_TRACE_INVALID       -1
  48 #define J2D_TRACE_OFF           0
  49 #define J2D_TRACE_ERROR         1
  50 #define J2D_TRACE_WARNING       2
  51 #define J2D_TRACE_INFO          3
  52 #define J2D_TRACE_VERBOSE       4
  53 #define J2D_TRACE_VERBOSE2      5
  54 #define J2D_TRACE_MAX           (J2D_TRACE_VERBOSE2+1)
  55 
  56 JNIEXPORT void JNICALL
  57 J2dTraceImpl(int level, jboolean cr, const char *string, ...);
  58 JNIEXPORT void JNICALL
  59 J2dTraceInit();
  60 
  61 #ifndef DEBUG
  62 #define J2dTrace(level, string)
  63 #define J2dTrace1(level, string, arg1)
  64 #define J2dTrace2(level, string, arg1, arg2)
  65 #define J2dTrace3(level, string, arg1, arg2, arg3)
  66 #define J2dTrace4(level, string, arg1, arg2, arg3, arg4)
  67 #define J2dTrace5(level, string, arg1, arg2, arg3, arg4, arg5)
  68 #define J2dTrace6(level, string, arg1, arg2, arg3, arg4, arg5, arg6)
  69 #define J2dTrace7(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  70 #define J2dTrace8(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  71 #define J2dTraceLn(level, string)
  72 #define J2dTraceLn1(level, string, arg1)
  73 #define J2dTraceLn2(level, string, arg1, arg2)
  74 #define J2dTraceLn3(level, string, arg1, arg2, arg3)
  75 #define J2dTraceLn4(level, string, arg1, arg2, arg3, arg4)
  76 #define J2dTraceLn5(level, string, arg1, arg2, arg3, arg4, arg5)
  77 #define J2dTraceLn6(level, string, arg1, arg2, arg3, arg4, arg5, arg6)
  78 #define J2dTraceLn7(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  79 #define J2dTraceLn8(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  80 #else /* DEBUG */
  81 #define J2dTrace(level, string) { \
  82             J2dTraceImpl(level, JNI_FALSE, string); \
  83         }
  84 #define J2dTrace1(level, string, arg1) { \
  85             J2dTraceImpl(level, JNI_FALSE, string, arg1); \
  86         }
  87 #define J2dTrace2(level, string, arg1, arg2) { \
  88             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2); \
  89         }
  90 #define J2dTrace3(level, string, arg1, arg2, arg3) { \
  91             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3); \
  92         }
  93 #define J2dTrace4(level, string, arg1, arg2, arg3, arg4) { \
  94             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4); \
  95         }
  96 #define J2dTrace5(level, string, arg1, arg2, arg3, arg4, arg5) { \
  97             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4, arg5); \
  98         }
  99 #define J2dTrace6(level, string, arg1, arg2, arg3, arg4, arg5, arg6) { \
 100             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4, arg5, arg6); \
 101         }
 102 #define J2dTrace7(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { \
 103             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7); \
 104         }
 105 #define J2dTrace8(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { \
 106             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); \
 107         }
 108 #define J2dTraceLn(level, string) { \
 109             J2dTraceImpl(level, JNI_TRUE, string); \
 110         }
 111 #define J2dTraceLn1(level, string, arg1) { \
 112             J2dTraceImpl(level, JNI_TRUE, string, arg1); \
 113         }
 114 #define J2dTraceLn2(level, string, arg1, arg2) { \
 115             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2); \
 116         }
 117 #define J2dTraceLn3(level, string, arg1, arg2, arg3) { \
 118             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3); \
 119         }
 120 #define J2dTraceLn4(level, string, arg1, arg2, arg3, arg4) { \
 121             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4); \
 122         }
 123 #define J2dTraceLn5(level, string, arg1, arg2, arg3, arg4, arg5) { \
 124             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4, arg5); \
 125         }
 126 #define J2dTraceLn6(level, string, arg1, arg2, arg3, arg4, arg5, arg6) { \
 127             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4, arg5, arg6); \
 128         }
 129 #define J2dTraceLn7(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { \
 130             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7); \
 131         }
 132 #define J2dTraceLn8(level, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { \
 133             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); \
 134         }
 135 #endif /* DEBUG */
 136 
 137 
 138 /**
 139  * NOTE: Use the following RlsTrace calls very carefully; they are compiled
 140  * into the code and should thus not be put in any performance-sensitive
 141  * areas.
 142  */
 143 
 144 #define J2dRlsTrace(level, string) { \
 145             J2dTraceImpl(level, JNI_FALSE, string); \
 146         }
 147 #define J2dRlsTrace1(level, string, arg1) { \
 148             J2dTraceImpl(level, JNI_FALSE, string, arg1); \
 149         }
 150 #define J2dRlsTrace2(level, string, arg1, arg2) { \
 151             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2); \
 152         }
 153 #define J2dRlsTrace3(level, string, arg1, arg2, arg3) { \
 154             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3); \
 155         }
 156 #define J2dRlsTrace4(level, string, arg1, arg2, arg3, arg4) { \
 157             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4); \
 158         }
 159 #define J2dRlsTrace5(level, string, arg1, arg2, arg3, arg4, arg5) { \
 160             J2dTraceImpl(level, JNI_FALSE, string, arg1, arg2, arg3, arg4, arg5); \
 161         }
 162 #define J2dRlsTraceLn(level, string) { \
 163             J2dTraceImpl(level, JNI_TRUE, string); \
 164         }
 165 #define J2dRlsTraceLn1(level, string, arg1) { \
 166             J2dTraceImpl(level, JNI_TRUE, string, arg1); \
 167         }
 168 #define J2dRlsTraceLn2(level, string, arg1, arg2) { \
 169             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2); \
 170         }
 171 #define J2dRlsTraceLn3(level, string, arg1, arg2, arg3) { \
 172             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3); \
 173         }
 174 #define J2dRlsTraceLn4(level, string, arg1, arg2, arg3, arg4) { \
 175             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4); \
 176         }
 177 #define J2dRlsTraceLn5(level, string, arg1, arg2, arg3, arg4, arg5) { \
 178             J2dTraceImpl(level, JNI_TRUE, string, arg1, arg2, arg3, arg4, arg5); \
 179         }
 180 
 181 #define J2dTracePrimitive(string) { \
 182         if (graphicsPrimitive_traceflags && jvm) { \
 183             JNIEnv *env; \
 184             jstring jstr; \
 185             (*jvm)->AttachCurrentThreadAsDaemon(jvm, &env, NULL); \
 186             jstr = (*env)->NewStringUTF(env, string); \
 187             JNU_CallStaticMethodByName(env, NULL, "sun/java2d/loops/GraphicsPrimitive", \
 188                                        "tracePrimitive", "(Ljava/lang/Object;)V", jstr); \
 189             (*env)->DeleteLocalRef(env, jstr); \
 190         } \
 191     }
 192 
 193 #define J2dTraceNotImplPrimitive(prim) { \
 194         if (graphicsPrimitive_traceflags && jvm) { \
 195             char cbuf[255]; \
 196             JNIEnv *env; \
 197             jstring jprim; \
 198             jstring jmsg; \
 199             snprintf(cbuf, 255, "[NOT IMPL] at %s:%d", __FILE__, __LINE__); \
 200             (*jvm)->AttachCurrentThreadAsDaemon(jvm, &env, NULL); \
 201             jprim = (*env)->NewStringUTF(env, prim); \
 202             jmsg = (*env)->NewStringUTF(env, cbuf); \
 203             JNU_CallStaticMethodByName(env, NULL, \
 204                                        "sun/java2d/loops/GraphicsPrimitive", \
 205                                        "traceImplPrimitive", \
 206                                        "(Ljava/lang/Object;Ljava/lang/Object;)V", \
 207                                        jprim, jmsg); \
 208             (*env)->DeleteLocalRef(env, jprim); \
 209             (*env)->DeleteLocalRef(env, jmsg); \
 210         } \
 211     }
 212 
 213 #define J2dTraceImplPrimitive(prim, msg) { \
 214         if (graphicsPrimitive_traceflags && jvm) { \
 215             char cbuf[255]; \
 216             JNIEnv *env; \
 217             jstring jprim; \
 218             jstring jmsg; \
 219             snprintf(cbuf, 255, "%s at %s:%d", msg, __FILE__, __LINE__); \
 220             (*jvm)->AttachCurrentThreadAsDaemon(jvm, &env, NULL); \
 221             jprim = (*env)->NewStringUTF(env, prim); \
 222             jmsg = (*env)->NewStringUTF(env, cbuf); \
 223             JNU_CallStaticMethodByName(env, NULL, \
 224                                        "sun/java2d/loops/GraphicsPrimitive", \
 225                                        "traceImplPrimitive", \
 226                                        "(Ljava/lang/Object;Ljava/lang/Object;)V", \
 227                                        jprim, jmsg); \
 228             (*env)->DeleteLocalRef(env, jprim); \
 229             (*env)->DeleteLocalRef(env, jmsg); \
 230         } \
 231     }
 232 
 233 
 234 #ifdef __cplusplus
 235 };
 236 #endif /* __cplusplus */
 237 
 238 #endif /* _Included_Trace */