hotspot/src/share/vm/prims/jvmtiTrace.cpp
changeset 37992 c7ec6a3275f7
parent 37248 11a660dbbb8e
equal deleted inserted replaced
37991:ce2e1e55f28f 37992:c7ec6a3275f7
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "jvmtifiles/jvmtiEnv.hpp"
    26 #include "jvmtifiles/jvmtiEnv.hpp"
       
    27 #include "logging/log.hpp"
       
    28 #include "logging/logConfiguration.hpp"
    27 #include "memory/resourceArea.hpp"
    29 #include "memory/resourceArea.hpp"
    28 #include "prims/jvmtiTrace.hpp"
    30 #include "prims/jvmtiTrace.hpp"
    29 
    31 
    30 //
    32 //
    31 // class JvmtiTrace
    33 // class JvmtiTrace
    78   if (TraceJVMTI != NULL) {
    80   if (TraceJVMTI != NULL) {
    79     curr = TraceJVMTI;
    81     curr = TraceJVMTI;
    80   } else {
    82   } else {
    81     curr = "";  // hack in fixed tracing here
    83     curr = "";  // hack in fixed tracing here
    82   }
    84   }
       
    85 
       
    86   // Enable UL for JVMTI tracing
       
    87   if (strlen(curr) > 0) {
       
    88     if (!log_is_enabled(Trace, jvmti)) {
       
    89       log_warning(arguments)("-XX:+TraceJVMTI specified, "
       
    90          "but no log output configured for the 'jvmti' tag on Trace level. "
       
    91          "Defaulting to -Xlog:jvmti=trace");
       
    92       LogConfiguration::configure_stdout(LogLevel::Trace, true, LOG_TAGS(jvmti));
       
    93     }
       
    94   }
       
    95 
    83   very_end = curr + strlen(curr);
    96   very_end = curr + strlen(curr);
    84   while (curr < very_end) {
    97   while (curr < very_end) {
    85     const char *curr_end = strchr(curr, ',');
    98     const char *curr_end = strchr(curr, ',');
    86     if (curr_end == NULL) {
    99     if (curr_end == NULL) {
    87       curr_end = very_end;
   100       curr_end = very_end;
   125         break;
   138         break;
   126       case 's':
   139       case 's':
   127         bits |= SHOW_EVENT_SENT;
   140         bits |= SHOW_EVENT_SENT;
   128         break;
   141         break;
   129       default:
   142       default:
   130         tty->print_cr("Invalid trace flag '%c'", *flags);
   143         log_warning(jvmti)("Invalid trace flag '%c'", *flags);
   131         break;
   144         break;
   132       }
   145       }
   133     }
   146     }
   134     const int FUNC = 1;
   147     const int FUNC = 1;
   135     const int EXCLUDE  = 2;
   148     const int EXCLUDE  = 2;
   150       domain = ALL_EVENT | EVENT;
   163       domain = ALL_EVENT | EVENT;
   151     } else if (len==5 && strncmp(curr, "event", 5)==0) {
   164     } else if (len==5 && strncmp(curr, "event", 5)==0) {
   152       domain = ALL_EVENT | EVENT;
   165       domain = ALL_EVENT | EVENT;
   153     } else if (len==2 && strncmp(curr, "ec", 2)==0) {
   166     } else if (len==2 && strncmp(curr, "ec", 2)==0) {
   154       _trace_event_controller = true;
   167       _trace_event_controller = true;
   155       tty->print_cr("JVMTI Tracing the event controller");
   168       log_trace(jvmti)("Tracing the event controller");
   156     } else {
   169     } else {
   157       domain = FUNC | EVENT;  // go searching
   170       domain = FUNC | EVENT;  // go searching
   158     }
   171     }
   159 
   172 
   160     int exclude_index = 0;
   173     int exclude_index = 0;
   161     if (domain & FUNC) {
   174     if (domain & FUNC) {
   162       if (domain & ALL_FUNC) {
   175       if (domain & ALL_FUNC) {
   163         if (domain & EXCLUDE) {
   176         if (domain & EXCLUDE) {
   164           tty->print("JVMTI Tracing all significant functions");
   177           log_trace(jvmti)("Tracing all significant functions");
   165         } else {
   178         } else {
   166           tty->print_cr("JVMTI Tracing all functions");
   179           log_trace(jvmti)("Tracing all functions");
   167         }
   180         }
   168       }
   181       }
   169       for (int i = 0; i <= _max_function_index; ++i) {
   182       for (int i = 0; i <= _max_function_index; ++i) {
   170         if (domain & EXCLUDE && i == _exclude_functions[exclude_index]) {
   183         if (domain & EXCLUDE && i == _exclude_functions[exclude_index]) {
   171           ++exclude_index;
   184           ++exclude_index;
   176           } else {
   189           } else {
   177             const char *fname = function_name(i);
   190             const char *fname = function_name(i);
   178             if (fname != NULL) {
   191             if (fname != NULL) {
   179               size_t fnlen = strlen(fname);
   192               size_t fnlen = strlen(fname);
   180               if (len==fnlen && strncmp(curr, fname, fnlen)==0) {
   193               if (len==fnlen && strncmp(curr, fname, fnlen)==0) {
   181                 tty->print_cr("JVMTI Tracing the function: %s", fname);
   194                 log_trace(jvmti)("Tracing the function: %s", fname);
   182                 do_op = true;
   195                 do_op = true;
   183               }
   196               }
   184             }
   197             }
   185           }
   198           }
   186           if (do_op) {
   199           if (do_op) {
   194         }
   207         }
   195       }
   208       }
   196     }
   209     }
   197     if (domain & EVENT) {
   210     if (domain & EVENT) {
   198       if (domain & ALL_EVENT) {
   211       if (domain & ALL_EVENT) {
   199         tty->print_cr("JVMTI Tracing all events");
   212         log_trace(jvmti)("Tracing all events");
   200       }
   213       }
   201       for (int i = 0; i <= _max_event_index; ++i) {
   214       for (int i = 0; i <= _max_event_index; ++i) {
   202         bool do_op = false;
   215         bool do_op = false;
   203         if (domain & ALL_EVENT) {
   216         if (domain & ALL_EVENT) {
   204           do_op = true;
   217           do_op = true;
   205         } else {
   218         } else {
   206           const char *ename = event_name(i);
   219           const char *ename = event_name(i);
   207           if (ename != NULL) {
   220           if (ename != NULL) {
   208             size_t evtlen = strlen(ename);
   221             size_t evtlen = strlen(ename);
   209             if (len==evtlen && strncmp(curr, ename, evtlen)==0) {
   222             if (len==evtlen && strncmp(curr, ename, evtlen)==0) {
   210               tty->print_cr("JVMTI Tracing the event: %s", ename);
   223               log_trace(jvmti)("Tracing the event: %s", ename);
   211               do_op = true;
   224               do_op = true;
   212             }
   225             }
   213           }
   226           }
   214         }
   227         }
   215         if (do_op) {
   228         if (do_op) {
   221           _on = true;
   234           _on = true;
   222         }
   235         }
   223       }
   236       }
   224     }
   237     }
   225     if (!_on && (domain & (FUNC|EVENT))) {
   238     if (!_on && (domain & (FUNC|EVENT))) {
   226       tty->print_cr("JVMTI Trace domain not found");
   239       log_warning(jvmti)("Trace domain not found");
   227     }
   240     }
   228     curr = curr_end + 1;
   241     curr = curr_end + 1;
   229   }
   242   }
   230   _initialized = true;
   243   _initialized = true;
   231 }
   244 }